From d29c7560f248623b634391e24688b068709ec48f Mon Sep 17 00:00:00 2001 From: Rainer Kartmann <rainer.kartmann@kit.edu> Date: Fri, 26 Nov 2021 16:28:20 +0100 Subject: [PATCH] Add documentation to ArViz example --- .../components/ArViz/Example/ArVizExample.cpp | 60 +++++++++++----- .../components/ArViz/Example/ArVizExample.h | 72 ++++++++++--------- 2 files changed, 81 insertions(+), 51 deletions(-) diff --git a/source/RobotAPI/components/ArViz/Example/ArVizExample.cpp b/source/RobotAPI/components/ArViz/Example/ArVizExample.cpp index a24c17c37..4d2be3924 100644 --- a/source/RobotAPI/components/ArViz/Example/ArVizExample.cpp +++ b/source/RobotAPI/components/ArViz/Example/ArVizExample.cpp @@ -22,42 +22,75 @@ #include "ArVizExample.h" - - #include <Eigen/Eigen> #include <SimoxUtility/color/cmaps.h> #include <ArmarXCore/core/time/CycleUtil.h> -#include <ArmarXCore/libraries/DecoupledSingleComponent/Decoupled.h> #include <ArmarXCore/core/time/TimeUtil.h> +#include <ArmarXCore/libraries/DecoupledSingleComponent/Decoupled.h> #include <RobotAPI/components/ArViz/Client/Client.h> namespace armarx { - ARMARX_DECOUPLED_REGISTER_COMPONENT(ArVizExample); + + armarx::PropertyDefinitionsPtr ArVizExample::createPropertyDefinitions() + { + armarx::PropertyDefinitionsPtr defs(new ComponentPropertyDefinitions(getConfigIdentifier())); + + // In this example, this is automatically done by deriving the component + // from armarx::ArVizComponentPluginUser. + if (false) + { + defs->defineOptionalProperty<std::string>("ArVizTopicName", "ArVizTopic", "Layer updates are sent over this topic."); + } + + defs->optional(properties.manyLayers, "layers.ManyElements", + "Show a layer with a lot of elements (used for testing, may impact performance)."); + + return defs; + } + + + std::string ArVizExample::getDefaultName() const + { + return "ArVizExample"; + } + void ArVizExample::onInitComponent() { - offeringTopicFromProperty("ArVizTopicName"); + // In this example, this is automatically done by deriving the component + // from armarx::ArVizComponentPluginUser. + if (false) + { + offeringTopicFromProperty("ArVizTopicName"); + } } + void ArVizExample::onConnectComponent() { - task = new RunningTask<ArVizExample>(this, &ArVizExample::update); + task = new RunningTask<ArVizExample>(this, &ArVizExample::run); task->start(); } void ArVizExample::onDisconnectComponent() { - task->stop(); + const bool join = true; + task->stop(join); task = nullptr; } + void ArVizExample::onExitComponent() + { + } + + void fillTestLayer(viz::Layer& layer, double timeInSeconds) { { @@ -140,6 +173,7 @@ namespace armarx } + void fillRobotHandsLayer(viz::Layer& layer) { Eigen::Vector3f pos = Eigen::Vector3f::Zero(); @@ -429,6 +463,7 @@ namespace armarx } } + void fillColorMapsLayer(viz::Layer& layer, double timeInSeconds) { (void) timeInSeconds; @@ -466,7 +501,7 @@ namespace armarx } - void ArVizExample::update() + void ArVizExample::run() { // This example uses the member `arviz` provided by armarx::ArVizComponentPluginUser. { @@ -539,15 +574,8 @@ namespace armarx } } - void ArVizExample::onExitComponent() - { - } + ARMARX_DECOUPLED_REGISTER_COMPONENT(ArVizExample); - armarx::PropertyDefinitionsPtr ArVizExample::createPropertyDefinitions() - { - return armarx::PropertyDefinitionsPtr(new ArVizExamplePropertyDefinitions( - getConfigIdentifier())); - } } diff --git a/source/RobotAPI/components/ArViz/Example/ArVizExample.h b/source/RobotAPI/components/ArViz/Example/ArVizExample.h index 09c59505e..a3f6848d7 100644 --- a/source/RobotAPI/components/ArViz/Example/ArVizExample.h +++ b/source/RobotAPI/components/ArViz/Example/ArVizExample.h @@ -22,8 +22,6 @@ #pragma once -#include <RobotAPI/interface/ArViz.h> - #include <ArmarXCore/core/Component.h> #include <ArmarXCore/core/services/tasks/RunningTask.h> @@ -33,53 +31,48 @@ namespace armarx { - /** - * @class ArVizExamplePropertyDefinitions - */ - class ArVizExamplePropertyDefinitions : - public armarx::ComponentPropertyDefinitions - { - public: - ArVizExamplePropertyDefinitions(std::string prefix) : - armarx::ComponentPropertyDefinitions(prefix) - { - // In this example, this is automatically done by deriving the component - // from armarx::ArVizComponentPluginUser. - if (false) - { - defineOptionalProperty<std::string>("ArVizTopicName", "ArVizTopic", "Layer updates are sent over this topic."); - } - - - defineOptionalProperty<bool>("layers.ManyElements", false, - "Show a layer with a lot of elements (used for testing, may impact performance)."); - } - }; /** * @defgroup Component-ArVizExample ArVizExample * @ingroup RobotAPI-Components - * A description of the component ArVizExample. + * + * An example for how to visualize 3D elements via the 3D visualization + * framework ArViz. + * + * * * @class ArVizExample * @ingroup Component-ArVizExample * @brief Brief description of class ArVizExample. * - * Detailed description of class ArVizExample. + * A component which wants to visualize data via ArViz should inherit from + * the `armarx::ArVizComponentPluginUser`. + * This adds the necessary properties (e.g. the topic name) and provides a + * ready-to-use ArViz client called `arviz`. + * The ArViz client can be used to create layers and commit them to the + * ArViz topic. + * + * The example creates several layers, fills them with visualization + * elements, and commits them to ArViz. + * + * To see the result: + * \li Start the component `ArVizStorage` + * \li Open the gui plugin `ArViz` + * \li Start the component `ArVizExample` + * + * The scenario `ArVizExample` starts the necessary components including + * the example component.s */ class ArVizExample : virtual public armarx::Component, - // Deriving from armarx::ArVizComponentPluginUser adds necessary properties - // and provides a ready-to-use ArViz client. + // Deriving from armarx::ArVizComponentPluginUser adds necessary properties + // and provides a ready-to-use ArViz client called `arviz`. virtual public armarx::ArVizComponentPluginUser { public: - /// @see armarx::ManagedIceObject::getDefaultName() - std::string getDefaultName() const override - { - return "ArVizExample"; - } + std::string getDefaultName() const override; + armarx::PropertyDefinitionsPtr createPropertyDefinitions() override; void onInitComponent() override; void onConnectComponent() override; @@ -87,12 +80,21 @@ namespace armarx void onDisconnectComponent() override; void onExitComponent() override; - armarx::PropertyDefinitionsPtr createPropertyDefinitions() override; private: - void update(); + + void run(); + private: + RunningTask<ArVizExample>::pointer_type task; + + struct Properties + { + bool manyLayers = false; + }; + Properties properties; + }; } -- GitLab