diff --git a/awviz_common/include/awviz_common/display.hpp b/awviz_common/include/awviz_common/display.hpp index 0140f43..93599b7 100644 --- a/awviz_common/include/awviz_common/display.hpp +++ b/awviz_common/include/awviz_common/display.hpp @@ -47,11 +47,11 @@ class Display rclcpp::Node::SharedPtr node, std::shared_ptr stream) = 0; /** - * @brief Set status of attributes. + * @brief Set attributes of property. * @param topic Name of topic. * @param entity Entity path of the record. */ - virtual void setStatus( + virtual void set_property( const std::string & topic, const std::shared_ptr> entity_roots) = 0; @@ -69,7 +69,7 @@ class Display * @brief Return true if the initialization is completed. * @return bool Return the value of the private member named `is_initialized_`. */ - virtual bool isInitialized() const { return is_initialized_; } + virtual bool is_initialized() const { return is_initialized_; } protected: rclcpp::Node::SharedPtr node_; //!< Node shared pointer. @@ -90,7 +90,7 @@ class RosTopicDisplay : public Display RosTopicDisplay() { const auto msg_type = rosidl_generator_traits::name(); - property_.setType(msg_type); + property_.set_type(msg_type); } /** @@ -116,12 +116,12 @@ class RosTopicDisplay : public Display * @param topic Name of topic. * @param entity Entity path of the record. */ - void setStatus( + void set_property( const std::string & topic, const std::shared_ptr> entity_roots) override { - property_.setTopic(topic); - property_.setEntityRoots(entity_roots); + property_.set_topic(topic); + property_.set_entity_roots(entity_roots); } /** @@ -134,7 +134,7 @@ class RosTopicDisplay : public Display */ void end() override { unsubscribe(); } - bool isInitialized() const override { return is_initialized_ && property_.isInitialized(); } + bool is_initialized() const override { return is_initialized_ && property_.is_initialized(); } protected: static constexpr const char * TIMELINE_NAME = "timestamp"; //!< Entity name of timeline record. @@ -145,14 +145,14 @@ class RosTopicDisplay : public Display */ virtual void subscribe() { - if (!isInitialized()) { + if (!is_initialized()) { return; } // TODO(ktro2828): QoS setting subscription_ = node_->create_subscription( property_.topic(), rclcpp::SensorDataQoS{}, - [this](const typename MsgType::ConstSharedPtr msg) { logToStream(msg); }); + [this](const typename MsgType::ConstSharedPtr msg) { log_message(msg); }); }; /** @@ -165,7 +165,7 @@ class RosTopicDisplay : public Display * @param msg Constant shared pointer of ROS message. * @note Currently, if the corresponding entity path doesn't exist this just logs warning as text. */ - virtual void logToStream(typename MsgType::ConstSharedPtr msg) = 0; + virtual void log_message(typename MsgType::ConstSharedPtr msg) = 0; protected: typename rclcpp::Subscription::SharedPtr subscription_; //!< Subscription of the topic. diff --git a/awviz_common/include/awviz_common/display_factory.hpp b/awviz_common/include/awviz_common/display_factory.hpp index fdc281e..80a872a 100644 --- a/awviz_common/include/awviz_common/display_factory.hpp +++ b/awviz_common/include/awviz_common/display_factory.hpp @@ -44,16 +44,16 @@ class DisplayFactory : public PluginFactory * @param lookup_name Lookup name of the class. * @return Set of declared message types. */ - const std::set & getMessageTypes(const std::string & lookup_name); + const std::set & get_message_types(const std::string & lookup_name); /** * @brief Get the Class Id of the corresponding message type. * * @param msg_type ROS message type. * @return Return a string of lookup name if the specified type has been declared, otherwise - * returns nullptr. + * returns `nullptr`. */ - std::optional getClassLookupName(const std::string & msg_type) const; + std::optional get_class_lookup_name(const std::string & msg_type) const; public: static constexpr const char * LIBRARY_TAG = "library"; //!< XML tag of library. @@ -68,34 +68,34 @@ class DisplayFactory : public PluginFactory * @param element Parsed XML element. * @return Return true if the element has the root node. */ - bool hasRootNode(const tinyxml2::XMLElement * element) const; + bool has_root_node(const tinyxml2::XMLElement * element) const; /** * @brief Check whether xml element has a library root. * @param element Parsed XML element. * @return Return true if the element has the library root. */ - bool hasLibraryRoot(const tinyxml2::XMLElement * element) const; + bool has_library_root(const tinyxml2::XMLElement * element) const; /** * @brief Cache all classes associated with the library. * @param library Parsed XML element for library. */ - void cacheAllClassElements(const tinyxml2::XMLElement * library); + void cache_classes(const tinyxml2::XMLElement * library); /** * @brief Parse ROS message types from XML elements. * @param element Root XML element. * @return Set of message types. */ - std::set parseMsgTypes(const tinyxml2::XMLElement * element) const; + std::set parse_message_types(const tinyxml2::XMLElement * element) const; /** * @brief Lookup derived class name. * @param element Parsed XML element. * @return Class name if the element has a `type` key, otherwise returns empty string. */ - std::string lookupDerivedClass(const tinyxml2::XMLElement * element) const; + std::string lookup_derived_class(const tinyxml2::XMLElement * element) const; /** * @brief Lookup the class id. @@ -103,7 +103,7 @@ class DisplayFactory : public PluginFactory * @param derived Name of derived class. * @return Class id if the element has `name` key, otherwise returns derived name. */ - std::string lookupClassId( + std::string lookup_class_id( const tinyxml2::XMLElement * element, const std::string & derived) const; private: diff --git a/awviz_common/include/awviz_common/factory/plugin_factory.hpp b/awviz_common/include/awviz_common/factory/plugin_factory.hpp index a180488..3b90f06 100644 --- a/awviz_common/include/awviz_common/factory/plugin_factory.hpp +++ b/awviz_common/include/awviz_common/factory/plugin_factory.hpp @@ -59,7 +59,7 @@ class PluginFactory * @param lookup_name Lookup name of the class. * @return The path of the associated plugin manifest. */ - std::string getPluginManifestPath(const std::string & lookup_name) const + std::string get_plugin_manifest_path(const std::string & lookup_name) const { return class_loader_->getPluginManifestPath(lookup_name); } @@ -67,9 +67,9 @@ class PluginFactory /** * @brief Return plugin information. * @param lookup_name Lookup name of the class. - * @return PluginInfo instance. + * @return `PluginInfo` object. */ - PluginInfo getPluginInfo(const std::string & lookup_name) const + PluginInfo get_plugin_info(const std::string & lookup_name) const { auto name = class_loader_->getName(lookup_name); auto type = class_loader_->getClassType(lookup_name); @@ -81,9 +81,10 @@ class PluginFactory /** * @brief Create a instance of the plugin. * @param lookup_name Lookup name of the class. - * @return Instance of plugin. Returns `nullptr` if exception occurred. + * @return Shared pointer of a plugin. Returns `nullptr` if `pluginlib::PluginlibException` + * occurred. */ - virtual std::shared_ptr createInstance(const std::string & lookup_name) const + virtual std::shared_ptr create_instance(const std::string & lookup_name) const { try { return class_loader_->createSharedInstance(lookup_name); @@ -98,7 +99,7 @@ class PluginFactory * * @return std::vector */ - std::vector getDeclaredClasses() const + std::vector get_declared_classes() const { return class_loader_->getDeclaredClasses(); } diff --git a/awviz_common/include/awviz_common/property.hpp b/awviz_common/include/awviz_common/property.hpp index 095fc46..9a95e27 100644 --- a/awviz_common/include/awviz_common/property.hpp +++ b/awviz_common/include/awviz_common/property.hpp @@ -47,19 +47,19 @@ class RosTopicProperty * @brief Set ROS message type name. * @param type Name of ROS message type. */ - void setType(const std::string & type) { type_ = type; } + void set_type(const std::string & type) { type_ = type; } /** * @brief Set ROS topic name. * @param topic Name of topic. */ - void setTopic(const std::string & topic) { topic_ = topic; } + void set_topic(const std::string & topic) { topic_ = topic; } /** * @brief Set entity path of record. * @param entity Entity path of record. */ - void setEntityRoots( + void set_entity_roots( const std::shared_ptr> entity_roots) { entity_roots_ = entity_roots; @@ -99,7 +99,7 @@ class RosTopicProperty } } - bool isInitialized() const { return !type_.empty() && !topic_.empty() && entity_roots_; } + bool is_initialized() const { return !type_.empty() && !topic_.empty() && entity_roots_; } private: std::string type_; //!< Type of ROS message. diff --git a/awviz_common/include/awviz_common/visualization_manager.hpp b/awviz_common/include/awviz_common/visualization_manager.hpp index df1150d..99595c2 100644 --- a/awviz_common/include/awviz_common/visualization_manager.hpp +++ b/awviz_common/include/awviz_common/visualization_manager.hpp @@ -63,7 +63,7 @@ class VisualizationManager /** * @brief Parse topics and create new ROS subscriptions every time. */ - void createSubscriptions(); + void create_subscriptions(); }; } // namespace awviz_common #endif // AWVIZ_COMMON__VISUALIZATION_MANAGER_HPP_ diff --git a/awviz_common/src/display_factory.cpp b/awviz_common/src/display_factory.cpp index 3278ac6..2ccd0e9 100644 --- a/awviz_common/src/display_factory.cpp +++ b/awviz_common/src/display_factory.cpp @@ -18,28 +18,28 @@ namespace awviz_common { DisplayFactory::DisplayFactory() : PluginFactory("awviz_common", "awviz_common::Display") { - for (const auto & lookup_name : getDeclaredClasses()) { - auto xml_path = getPluginManifestPath(lookup_name); + for (const auto & lookup_name : get_declared_classes()) { + auto xml_path = get_plugin_manifest_path(lookup_name); // Initialize cache as empty. msg_type_buffer_[lookup_name] = std::set(); if (!xml_path.empty()) { tinyxml2::XMLDocument document; document.LoadFile(xml_path.c_str()); auto * config = document.RootElement(); - if (!hasRootNode(config) || !hasLibraryRoot(config)) { + if (!has_root_node(config) || !has_library_root(config)) { continue; } auto * library = config; while (library) { - cacheAllClassElements(library); + cache_classes(library); library = library->NextSiblingElement(LIBRARY_TAG); } } } } -const std::set & DisplayFactory::getMessageTypes(const std::string & lookup_name) +const std::set & DisplayFactory::get_message_types(const std::string & lookup_name) { if (msg_type_buffer_.find(lookup_name) != msg_type_buffer_.cend()) { return msg_type_buffer_[lookup_name]; @@ -49,7 +49,7 @@ const std::set & DisplayFactory::getMessageTypes(const std::string return msg_type_buffer_[lookup_name]; } -std::optional DisplayFactory::getClassLookupName(const std::string & msg_type) const +std::optional DisplayFactory::get_class_lookup_name(const std::string & msg_type) const { for (const auto & [class_id, msg_types] : msg_type_buffer_) { if (msg_types.find(msg_type) != msg_types.cend()) { @@ -59,31 +59,32 @@ std::optional DisplayFactory::getClassLookupName(const std::string return {}; } -bool DisplayFactory::hasRootNode(const tinyxml2::XMLElement * element) const +bool DisplayFactory::has_root_node(const tinyxml2::XMLElement * element) const { return element != nullptr; } -bool DisplayFactory::hasLibraryRoot(const tinyxml2::XMLElement * element) const +bool DisplayFactory::has_library_root(const tinyxml2::XMLElement * element) const { return strcmp(element->Value(), LIBRARY_TAG) == 0; } -void DisplayFactory::cacheAllClassElements(const tinyxml2::XMLElement * library) +void DisplayFactory::cache_classes(const tinyxml2::XMLElement * library) { auto element = library->FirstChildElement(); while (element) { - const auto derived = lookupDerivedClass(element); - const auto current = lookupClassId(element, derived); + const auto derived = lookup_derived_class(element); + const auto current = lookup_class_id(element, derived); - msg_type_buffer_[current] = parseMsgTypes(element); + msg_type_buffer_[current] = parse_message_types(element); // search child element element = element->NextSiblingElement(CLASS_TAG); } } -std::set DisplayFactory::parseMsgTypes(const tinyxml2::XMLElement * element) const +std::set DisplayFactory::parse_message_types( + const tinyxml2::XMLElement * element) const { std::set output; @@ -102,12 +103,12 @@ std::set DisplayFactory::parseMsgTypes(const tinyxml2::XMLElement * return output; } -std::string DisplayFactory::lookupDerivedClass(const tinyxml2::XMLElement * element) const +std::string DisplayFactory::lookup_derived_class(const tinyxml2::XMLElement * element) const { return element->Attribute(TYPE_ATTRIBUTE) ? element->Attribute(TYPE_ATTRIBUTE) : ""; } -std::string DisplayFactory::lookupClassId( +std::string DisplayFactory::lookup_class_id( const tinyxml2::XMLElement * element, const std::string & derived) const { return element->Attribute(NAME_ATTRIBUTE) ? element->Attribute(NAME_ATTRIBUTE) : derived; diff --git a/awviz_common/src/visualization_manager.cpp b/awviz_common/src/visualization_manager.cpp index f848fc5..5069a02 100644 --- a/awviz_common/src/visualization_manager.cpp +++ b/awviz_common/src/visualization_manager.cpp @@ -32,7 +32,7 @@ VisualizationManager::VisualizationManager( parallel_callback_group_ = node_->create_callback_group(rclcpp::CallbackGroupType::Reentrant); callback_timer_ = node_->create_wall_timer( - 100ms, [&]() { createSubscriptions(); }, parallel_callback_group_); + 100ms, [&]() { create_subscriptions(); }, parallel_callback_group_); } VisualizationManager::~VisualizationManager() @@ -44,7 +44,7 @@ VisualizationManager::~VisualizationManager() } } -void VisualizationManager::createSubscriptions() +void VisualizationManager::create_subscriptions() { for (const auto & [topic_name, topic_types] : node_->get_topic_names_and_types()) { if (display_group_.find(topic_name) != display_group_.cend()) { @@ -52,15 +52,15 @@ void VisualizationManager::createSubscriptions() } const auto & topic_type = topic_types.front(); - const auto lookup_name = display_factory_->getClassLookupName(topic_type); + const auto lookup_name = display_factory_->get_class_lookup_name(topic_type); if (lookup_name) { - auto display = display_factory_->createInstance(lookup_name.value()); + auto display = display_factory_->create_instance(lookup_name.value()); if (display) { display->initialize(node_, stream_); - display->setStatus(topic_name, tf_manager_->entities()); + display->set_property(topic_name, tf_manager_->entities()); display->start(); } diff --git a/awviz_plugin/include/awviz_plugin/autoware_perception/detected_objects_display.hpp b/awviz_plugin/include/awviz_plugin/autoware_perception/detected_objects_display.hpp index 455b2df..90d5f03 100644 --- a/awviz_plugin/include/awviz_plugin/autoware_perception/detected_objects_display.hpp +++ b/awviz_plugin/include/awviz_plugin/autoware_perception/detected_objects_display.hpp @@ -31,7 +31,7 @@ class DetectedObjectsDisplay DetectedObjectsDisplay(); protected: - void logToStream(autoware_perception_msgs::msg::DetectedObjects::ConstSharedPtr msg) override; + void log_message(autoware_perception_msgs::msg::DetectedObjects::ConstSharedPtr msg) override; }; } // namespace awviz_plugin diff --git a/awviz_plugin/include/awviz_plugin/image/collection_adapter.hpp b/awviz_plugin/include/awviz_plugin/image/collection_adapter.hpp index 416e49f..7267a47 100644 --- a/awviz_plugin/include/awviz_plugin/image/collection_adapter.hpp +++ b/awviz_plugin/include/awviz_plugin/image/collection_adapter.hpp @@ -56,7 +56,7 @@ namespace awviz_plugin * @param img Input image. * @return Tensor shape as collection. */ -inline rerun::Collection tensorShape(const cv::Mat & img) +inline rerun::Collection tensor_shape(const cv::Mat & img) { return { static_cast(img.rows), static_cast(img.cols), diff --git a/awviz_plugin/include/awviz_plugin/image/compressed_image_display.hpp b/awviz_plugin/include/awviz_plugin/image/compressed_image_display.hpp index 98b40a3..3469303 100644 --- a/awviz_plugin/include/awviz_plugin/image/compressed_image_display.hpp +++ b/awviz_plugin/include/awviz_plugin/image/compressed_image_display.hpp @@ -34,7 +34,7 @@ class CompressedImageDisplay CompressedImageDisplay(); protected: - void logToStream(sensor_msgs::msg::CompressedImage::ConstSharedPtr msg) override; + void log_message(sensor_msgs::msg::CompressedImage::ConstSharedPtr msg) override; }; } // namespace awviz_plugin diff --git a/awviz_plugin/include/awviz_plugin/image/image_display.hpp b/awviz_plugin/include/awviz_plugin/image/image_display.hpp index 3c57f10..fdcfe3a 100644 --- a/awviz_plugin/include/awviz_plugin/image/image_display.hpp +++ b/awviz_plugin/include/awviz_plugin/image/image_display.hpp @@ -33,7 +33,7 @@ class ImageDisplay : public awviz_common::RosTopicDisplayset_time_seconds( diff --git a/awviz_plugin/src/image/compressed_image_display.cpp b/awviz_plugin/src/image/compressed_image_display.cpp index 0024dcb..31d52bf 100644 --- a/awviz_plugin/src/image/compressed_image_display.cpp +++ b/awviz_plugin/src/image/compressed_image_display.cpp @@ -27,7 +27,7 @@ CompressedImageDisplay::CompressedImageDisplay() { } -void CompressedImageDisplay::logToStream(sensor_msgs::msg::CompressedImage::ConstSharedPtr msg) +void CompressedImageDisplay::log_message(sensor_msgs::msg::CompressedImage::ConstSharedPtr msg) { stream_->set_time_seconds( TIMELINE_NAME, rclcpp::Time(msg->header.stamp.sec, msg->header.stamp.nanosec).seconds()); @@ -42,7 +42,8 @@ void CompressedImageDisplay::logToStream(sensor_msgs::msg::CompressedImage::Cons auto img = cv::imdecode(cv::Mat(msg->data), cv::IMREAD_COLOR); cv::cvtColor(img, img, cv::COLOR_BGR2RGB); - stream_->log(entity_path.value(), rerun::Image(tensorShape(img), rerun::TensorBuffer::u8(img))); + stream_->log( + entity_path.value(), rerun::Image(tensor_shape(img), rerun::TensorBuffer::u8(img))); } else { auto img = cv::imdecode(cv::Mat(msg->data), cv::IMREAD_COLOR); cv::Mat depth; diff --git a/awviz_plugin/src/image/image_display.cpp b/awviz_plugin/src/image/image_display.cpp index 6cdff35..37b80d4 100644 --- a/awviz_plugin/src/image/image_display.cpp +++ b/awviz_plugin/src/image/image_display.cpp @@ -26,7 +26,7 @@ ImageDisplay::ImageDisplay() : awviz_common::RosTopicDisplayset_time_seconds( TIMELINE_NAME, rclcpp::Time(msg->header.stamp.sec, msg->header.stamp.nanosec).seconds()); @@ -55,7 +55,8 @@ void ImageDisplay::logToStream(sensor_msgs::msg::Image::ConstSharedPtr msg) } else { auto img = cv_bridge::toCvCopy(msg, "rgb8")->image; - stream_->log(entity_path.value(), rerun::Image(tensorShape(img), rerun::TensorBuffer::u8(img))); + stream_->log( + entity_path.value(), rerun::Image(tensor_shape(img), rerun::TensorBuffer::u8(img))); } } } // namespace awviz_plugin diff --git a/awviz_plugin/src/pointcloud/pointcloud2_display.cpp b/awviz_plugin/src/pointcloud/pointcloud2_display.cpp index 57e360c..774d768 100644 --- a/awviz_plugin/src/pointcloud/pointcloud2_display.cpp +++ b/awviz_plugin/src/pointcloud/pointcloud2_display.cpp @@ -30,7 +30,7 @@ PointCloud2Display::PointCloud2Display() { } -void PointCloud2Display::logToStream(sensor_msgs::msg::PointCloud2::ConstSharedPtr msg) +void PointCloud2Display::log_message(sensor_msgs::msg::PointCloud2::ConstSharedPtr msg) { stream_->set_time_seconds( TIMELINE_NAME, rclcpp::Time(msg->header.stamp.sec, msg->header.stamp.nanosec).seconds()); diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index 568fecc..be792cb 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -65,14 +65,18 @@ Here's the process: 6. **Submit a pull request** to the main repository. Please describe your changes in detail, linking to any relevant issues. -### 3. Code Style +### 3. Coding Rules To maintain a clean and consistent codebase, please follow these guidelines: -- Follow the [Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html). -- We recommend to use [clangd](https://clangd.llvm.org/) that features like code completion, navigation (e.g. go to definition, find references), refactoring, and diagnostics. -- Write clear, concise, and well-documented code. - - For the code documentation, follow the [Doxygen C++ Document Style](https://www.doxygen.nl/manual/index.html). +- **Code Style** + - Follow the [Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html) for general style conventions. + - Use `snake_case` for function names. For example, `void set_name(const std::string & name);`. +- **Code Formatting** + - We recommend using [clangd](https://clangd.llvm.org/) that features like code completion, navigation (e.g. go to definition, find references), refactoring, and diagnostics. +- **Code Documentation** + - Ensure your code is well-documented code with clear and concise comments. + - Follow the [Doxygen C++ Document Style](https://www.doxygen.nl/manual/index.html) for writing code documentation. ### 4. Testing diff --git a/docs/PLUGIN.md b/docs/PLUGIN.md index ba4117c..28ae1e1 100644 --- a/docs/PLUGIN.md +++ b/docs/PLUGIN.md @@ -73,7 +73,7 @@ namespace my_custom_display protected: // Callback to log subscribed message to the recording stream. - void logToStream(my_custom_msgs::msg::Foo::ConstSharedPtr msg) override; + void log_message(my_custom_msgs::msg::Foo::ConstSharedPtr msg) override; }; } // namespace my_custom_display @@ -91,7 +91,7 @@ Foo::Foo() : awviz_common::RosTopicDisplay() { } -void Foo::logToStream(my_custom_msgs::msg::Foo::ConstSharedPtr msg) +void Foo::log_message(my_custom_msgs::msg::Foo::ConstSharedPtr msg) { stream_->set_time_seconds( TIMELINE_NAME, rclcpp::Time(msg->stamp.sec, msg->stamp.nanosec).seconds());