diff --git a/source/RobotAPI/components/ArViz/Client/elements/ElementOps.h b/source/RobotAPI/components/ArViz/Client/elements/ElementOps.h index e7b8f0542fecdb99ec55599c9fdf4a371a3c4065..4f7c222f5c8ebb3f6a5f65062033218e058a8ddb 100644 --- a/source/RobotAPI/components/ArViz/Client/elements/ElementOps.h +++ b/source/RobotAPI/components/ArViz/Client/elements/ElementOps.h @@ -140,6 +140,33 @@ namespace armarx::viz return *static_cast<DerivedT*>(this); } + DerivedT& hide() + { + data_->flags |= data::ElementFlags::HIDDEN; + + return *static_cast<DerivedT*>(this); + } + + DerivedT& show() + { + data_->flags &= ~data::ElementFlags::HIDDEN; + + return *static_cast<DerivedT*>(this); + } + + DerivedT& visible(bool visible) + { + if (visible) + { + return show(); + } + else + { + return hide(); + } + } + + IceInternal::Handle<ElementT> data_; }; diff --git a/source/RobotAPI/components/ArViz/Coin/ElementVisualizer.h b/source/RobotAPI/components/ArViz/Coin/ElementVisualizer.h index 8c3f524fb4baa5faca577eb0651d561bc302ac58..9be0fa5b5c44d5256ae0adb4cc0c6a74d5dfe619 100644 --- a/source/RobotAPI/components/ArViz/Coin/ElementVisualizer.h +++ b/source/RobotAPI/components/ArViz/Coin/ElementVisualizer.h @@ -7,6 +7,8 @@ #include <memory> +#include <RobotAPI/interface/ArViz/Elements.h> + namespace armarx::viz::data { class Element; @@ -27,6 +29,7 @@ namespace armarx::viz::coin SoTransform* transform; SoMaterial* material; bool wasUpdated = true; + bool visible = true; }; class ElementVisualizer @@ -50,6 +53,12 @@ namespace armarx::viz::coin TypedElementVisualization() { node = new NodeType; + node->ref(); + } + + ~TypedElementVisualization() + { + node->unref(); } NodeType* node; @@ -62,6 +71,7 @@ namespace armarx::viz::coin using DataType = DataT; using ElementType = typename DataType::ElementType; + DataType* createDerived() final { DataType* result = new DataType; @@ -73,8 +83,24 @@ namespace armarx::viz::coin { auto const& element = static_cast<ElementType const&>(element_); auto* data = dynamic_cast<DataType*>(data_); + if (data) { + bool hidden = (element.flags & armarx::viz::data::ElementFlags::HIDDEN); + if (hidden) + { + if (data->visible) + { + data->separator->removeChild(data->node); + data->visible = false; + } + } + else if (!data->visible) + { + data->visible = true; + data->separator->addChild(data->node); + } + // We want to call update with the correctly downcasted arguments return data->update(element); } diff --git a/source/RobotAPI/components/ArViz/Example/ArVizExample.cpp b/source/RobotAPI/components/ArViz/Example/ArVizExample.cpp index 9043aa8ae83977c97f64cc5bf4ac1978e9e06aeb..6cb09640398b08c7bae7202b9db8843ed908e83d 100644 --- a/source/RobotAPI/components/ArViz/Example/ArVizExample.cpp +++ b/source/RobotAPI/components/ArViz/Example/ArVizExample.cpp @@ -69,6 +69,9 @@ namespace armarx .color(viz::Color::red()) .size(Eigen::Vector3f(100.0f, 100.0f, 100.0f)); + bool toggleVisibility = (static_cast<int>(timeInSeconds) % 2 == 0); + box.visible(toggleVisibility); + layer.add(box); } { @@ -125,6 +128,7 @@ namespace armarx Eigen::Vector3f direction = dirRot * Eigen::Vector3f::UnitX(); arrow.direction(direction); + Eigen::Vector3f pos = Eigen::Vector3f::Zero(); pos.z() = +300.0f; pos.x() = -500.0f; @@ -133,6 +137,8 @@ namespace armarx layer.add(arrow); } + + } diff --git a/source/RobotAPI/interface/ArViz/Elements.ice b/source/RobotAPI/interface/ArViz/Elements.ice index 03440c043481e7d38beefbb58853f7ac5a4c9e5a..ac8a70dfe449caf56c9b38e36c3d8c6748f0fea3 100644 --- a/source/RobotAPI/interface/ArViz/Elements.ice +++ b/source/RobotAPI/interface/ArViz/Elements.ice @@ -34,6 +34,7 @@ module data { const int NONE = 0; const int OVERRIDE_MATERIAL = 1; + const int INVISIBLE = 2; }; class Element