diff --git a/source/RobotAPI/components/DebugDrawer/DebugDrawerComponent.cpp b/source/RobotAPI/components/DebugDrawer/DebugDrawerComponent.cpp index 3ecd6c2be19575b47bfcff1e21a334d3102d10aa..5e0d7f6a1d4a9c9d530ae31b8e345b843dfedd89 100644 --- a/source/RobotAPI/components/DebugDrawer/DebugDrawerComponent.cpp +++ b/source/RobotAPI/components/DebugDrawer/DebugDrawerComponent.cpp @@ -38,6 +38,7 @@ using namespace VirtualRobot; namespace armarx{ +static const std::string DEBUG_LAYER_NAME{"debug"}; DebugDrawerComponent::DebugDrawerComponent() { @@ -52,7 +53,7 @@ DebugDrawerComponent::DebugDrawerComponent() coinVisu->addChild(u); } -void DebugDrawerComponent::onInitComponent()//////////////////////////////////////////////// +void DebugDrawerComponent::onInitComponent() { usingTopic(getProperty<std::string>("DebugDrawerTopic").getValue()); @@ -68,27 +69,11 @@ void DebugDrawerComponent::onConnectComponent() void DebugDrawerComponent::onExitComponent() { ARMARX_DEBUG << "onExitComponent"; + layers.clear(); coinVisu->unref(); } -void DebugDrawerComponent::enableVisu(bool e)///////////////////////remove///////////////////////// -{ - ScopedRecursiveLockPtr lock = getScopedLock(); - enableLayerVisu("debug",e); - /* if (e) - { - if (coinVisu->findChild(debugVisu)<0) - coinVisu->addChild(debugVisu); - } else - { - if (coinVisu->findChild(debugVisu)>=0) - coinVisu->removeChild(debugVisu); - }*/ -} - - - void DebugDrawerComponent::drawCoordSystem(const std::string &layerName, const std::string &name, Eigen::Matrix4f &globalPose, float scale) { ScopedRecursiveLockPtr l = getScopedLock(); @@ -309,17 +294,27 @@ void DebugDrawerComponent::removeSphere(const std::string &layerName, const std: } -void DebugDrawerComponent::setPoseVisu(const std::string &layerName, const std::string &poseName, const PoseBasePtr &globalPose, const Ice::Current &) +void DebugDrawerComponent::setScaledPoseVisu(const std::string& layerName, const std::string& poseName, const ::armarx::PoseBasePtr& globalPose, const ::Ice::Float scale, const ::Ice::Current&) { + ARMARX_DEBUG << VAROUT(layerName) << VAROUT(poseName); Eigen::Matrix4f gp = PosePtr::dynamicCast(globalPose)->toEigen(); - drawCoordSystem(layerName,poseName,gp,1.0f); + drawCoordSystem(layerName,poseName,gp,scale); +} + +void DebugDrawerComponent::setScaledPoseDebugLayerVisu(const std::string& poseName, const ::armarx::PoseBasePtr& globalPose, const ::Ice::Float scale, const ::Ice::Current&) +{ + setScaledPoseVisu(DEBUG_LAYER_NAME,poseName,globalPose,scale); +} + +void DebugDrawerComponent::setPoseVisu(const std::string &layerName, const std::string &poseName, const PoseBasePtr &globalPose, const Ice::Current &) +{ + setScaledPoseVisu(layerName,poseName,globalPose,1.f); } void DebugDrawerComponent::setPoseDebugLayerVisu(const std::string &poseName, const PoseBasePtr &globalPose, const Ice::Current &) { - std::string d("debug"); - setPoseVisu(d,poseName,globalPose); + setScaledPoseVisu(DEBUG_LAYER_NAME,poseName,globalPose,1.f); } void DebugDrawerComponent::removePoseVisu(const std::string &layerName, const std::string &poseName, const Ice::Current &) @@ -330,8 +325,7 @@ void DebugDrawerComponent::removePoseVisu(const std::string &layerName, const st void DebugDrawerComponent::removePoseDebugLayerVisu(const std::string &poseName, const Ice::Current &) { - std::string d("debug"); - removePoseVisu(d,poseName); + removePoseVisu(DEBUG_LAYER_NAME,poseName); } void DebugDrawerComponent::setLineVisu(const std::string &layerName, const std::string &lineName, const Vector3BasePtr &globalPosition1, const Vector3BasePtr &globalPosition2, float lineWidth, const DrawColor &color, const Ice::Current &) @@ -344,7 +338,7 @@ void DebugDrawerComponent::setLineVisu(const std::string &layerName, const std:: void DebugDrawerComponent::setLineDebugLayerVisu(const std::string &lineName, const Vector3BasePtr &globalPosition1, const Vector3BasePtr &globalPosition2, float lineWidth, const DrawColor &color, const Ice::Current &) { - setLineVisu("debug",lineName,globalPosition1,globalPosition2, lineWidth, color); + setLineVisu(DEBUG_LAYER_NAME,lineName,globalPosition1,globalPosition2, lineWidth, color); } void DebugDrawerComponent::removeLineVisu(const std::string &layerName, const std::string &lineName, const Ice::Current &) @@ -354,7 +348,7 @@ void DebugDrawerComponent::removeLineVisu(const std::string &layerName, const st void DebugDrawerComponent::removeLineDebugLayerVisu(const std::string &lineName, const Ice::Current &) { - removeLineVisu("debug",lineName); + removeLineVisu(DEBUG_LAYER_NAME,lineName); } void DebugDrawerComponent::setBoxVisu(const std::string &layerName, const std::string &boxName, const PoseBasePtr &globalPose, const Vector3BasePtr &dimensions, const DrawColor &color, const Ice::Current &) @@ -367,7 +361,7 @@ void DebugDrawerComponent::setBoxVisu(const std::string &layerName, const std::s void DebugDrawerComponent::setBoxDebugLayerVisu(const std::string &boxName, const PoseBasePtr &globalPose, const Vector3BasePtr &dimensions, const DrawColor &color, const Ice::Current &) { - setBoxVisu("debug", boxName, globalPose, dimensions, color); + setBoxVisu(DEBUG_LAYER_NAME, boxName, globalPose, dimensions, color); } void DebugDrawerComponent::removeBoxVisu(const std::string &layerName, const std::string &boxName, const Ice::Current &) @@ -377,7 +371,7 @@ void DebugDrawerComponent::removeBoxVisu(const std::string &layerName, const std void DebugDrawerComponent::removeBoxDebugLayerVisu(const std::string &boxName, const Ice::Current &) { - removeBoxVisu("debug", boxName); + removeBoxVisu(DEBUG_LAYER_NAME, boxName); } void DebugDrawerComponent::setTextVisu(const std::string &layerName, const std::string &textName, const std::string &text, const Vector3BasePtr &globalPosition, const DrawColor &color, int size, const Ice::Current &) @@ -389,7 +383,7 @@ void DebugDrawerComponent::setTextVisu(const std::string &layerName, const std:: void DebugDrawerComponent::setTextDebugLayerVisu(const std::string &textName, const std::string &text, const Vector3BasePtr &globalPosition, const DrawColor &color, int size, const Ice::Current &) { - setTextVisu("debug", textName, text, globalPosition, color, size); + setTextVisu(DEBUG_LAYER_NAME, textName, text, globalPosition, color, size); } void DebugDrawerComponent::removeTextVisu(const std::string &layerName, const std::string &textName, const Ice::Current &) @@ -399,7 +393,7 @@ void DebugDrawerComponent::removeTextVisu(const std::string &layerName, const st void DebugDrawerComponent::removeTextDebugLayerVisu(const std::string &textName, const Ice::Current &) { - removeTextVisu("debug", textName); + removeTextVisu(DEBUG_LAYER_NAME, textName); } void DebugDrawerComponent::setSphereVisu(const std::string &layerName, const std::string &sphereName, const Vector3BasePtr &globalPosition, const DrawColor &color, float radius, const Ice::Current &) @@ -411,7 +405,7 @@ void DebugDrawerComponent::setSphereVisu(const std::string &layerName, const std void DebugDrawerComponent::setSphereDebugLayerVisu(const std::string &sphereName, const Vector3BasePtr &globalPosition, const DrawColor &color, float radius, const Ice::Current &) { - setSphereVisu("debug", sphereName, globalPosition, color, radius); + setSphereVisu(DEBUG_LAYER_NAME, sphereName, globalPosition, color, radius); } void DebugDrawerComponent::removeSphereVisu(const std::string &layerName, const std::string &sphereName, const Ice::Current &) @@ -421,10 +415,10 @@ void DebugDrawerComponent::removeSphereVisu(const std::string &layerName, const void DebugDrawerComponent::removeSphereDebugLayerVisu(const std::string &sphereName, const Ice::Current &) { - removeSphereVisu("debug", sphereName); + removeSphereVisu(DEBUG_LAYER_NAME, sphereName); } -void DebugDrawerComponent::clear(const std::string &layerName, const Ice::Current &) +void DebugDrawerComponent::clearLayer(const std::string &layerName, const Ice::Current &) { if(!hasLayer(layerName)) { @@ -439,7 +433,7 @@ void DebugDrawerComponent::clearDebugLayer(const Ice::Current &) { ARMARX_VERBOSE << "Clearing debug layer..."; - clear("debug"); + clearLayer(DEBUG_LAYER_NAME); } void DebugDrawerComponent::setMutex(boost::shared_ptr<boost::recursive_mutex> m) @@ -505,6 +499,7 @@ DebugDrawerComponent::Layer::~Layer() if(mainNode) { ScopedRecursiveLockPtr l = parent.getScopedLock(); + if (parent.coinVisu->findChild(mainNode)>=0) { parent.coinVisu->removeChild(mainNode); @@ -525,10 +520,9 @@ void DebugDrawerComponent::Layer::clear() mainNode->removeAllChildren(); } -bool DebugDrawerComponent::hasLayer(const std::string& layerName, const ::Ice::Current&)///////////////////////////////////// +bool DebugDrawerComponent::hasLayer(const std::string& layerName, const ::Ice::Current&) { ScopedRecursiveLockPtr l = getScopedLock(); - layers.find(std::string{layerName}); return layers.find(layerName)!=layers.end(); } @@ -566,6 +560,11 @@ void DebugDrawerComponent::enableLayerVisu(const std::string& layerName, bool vi } } +void DebugDrawerComponent::enableDebugLayerVisu(bool visible, const ::Ice::Current&) +{ + enableLayerVisu(DEBUG_LAYER_NAME,visible); +} + StringSequence DebugDrawerComponent::layerNames(const ::Ice::Current&) { ScopedRecursiveLockPtr l = getScopedLock(); @@ -577,7 +576,6 @@ StringSequence DebugDrawerComponent::layerNames(const ::Ice::Current&) return seq; } - ::armarx::LayerInformationSequence DebugDrawerComponent::layerInformation(const ::Ice::Current&) { ::armarx::LayerInformationSequence seq{}; @@ -594,5 +592,4 @@ StringSequence DebugDrawerComponent::layerNames(const ::Ice::Current&) } return seq; } - }//namespace armarx diff --git a/source/RobotAPI/components/DebugDrawer/DebugDrawerComponent.h b/source/RobotAPI/components/DebugDrawer/DebugDrawerComponent.h index dbd61808a8581df0b0b02c6edd9b46b3ca834583..54015e817e2b6e24233a853fe668bd9bb4d99b45 100644 --- a/source/RobotAPI/components/DebugDrawer/DebugDrawerComponent.h +++ b/source/RobotAPI/components/DebugDrawer/DebugDrawerComponent.h @@ -87,15 +87,11 @@ public: getConfigIdentifier())); } - /*! - * \brief Enable or disable debug layer visu - * \param e - */ - void enableVisu(bool e); - /* Inherited from DebugDrawerInterface. */ virtual void setPoseVisu(const std::string& layerName, const std::string& poseName, const ::armarx::PoseBasePtr& globalPose, const ::Ice::Current& = ::Ice::Current()); + virtual void setScaledPoseVisu(const std::string& layerName, const std::string& poseName, const ::armarx::PoseBasePtr& globalPose, const ::Ice::Float scale, const ::Ice::Current& = ::Ice::Current()); virtual void setPoseDebugLayerVisu(const std::string& poseName, const ::armarx::PoseBasePtr& globalPose, const ::Ice::Current& = ::Ice::Current()); + virtual void setScaledPoseDebugLayerVisu(const std::string& poseName, const ::armarx::PoseBasePtr& globalPose, const ::Ice::Float scale, const ::Ice::Current& = ::Ice::Current()); virtual void removePoseVisu(const std::string& layerName, const std::string& poseName, const ::Ice::Current& = ::Ice::Current()); virtual void removePoseDebugLayerVisu(const std::string& poseName, const ::Ice::Current& = ::Ice::Current()); @@ -119,15 +115,15 @@ public: virtual void removeSphereVisu(const std::string &layerName, const std::string &sphereName, const ::Ice::Current& = ::Ice::Current()); virtual void removeSphereDebugLayerVisu(const std::string& sphereName, const ::Ice::Current& = ::Ice::Current()); - - - virtual void clear(const std::string& layerName, const ::Ice::Current& = ::Ice::Current()); + virtual void clearLayer(const std::string& layerName, const ::Ice::Current& = ::Ice::Current()); virtual void clearDebugLayer(const ::Ice::Current& = ::Ice::Current()); - virtual bool hasLayer(const std::string& layerName, const ::Ice::Current& = ::Ice::Current()); virtual void removeLayer(const std::string& layerName, const ::Ice::Current& = ::Ice::Current()); + virtual void enableLayerVisu(const std::string& layerName, bool visible, const ::Ice::Current& = ::Ice::Current()); + virtual void enableDebugLayerVisu(bool visible, const ::Ice::Current& = ::Ice::Current()); + virtual ::armarx::StringSequence layerNames(const ::Ice::Current& = ::Ice::Current()); virtual ::armarx::LayerInformationSequence layerInformation(const ::Ice::Current& = ::Ice::Current()); @@ -190,9 +186,6 @@ protected: std::shared_ptr<Layer> requestLayer(const std::string& layerName); SoSeparator* coinVisu; - //SoSeparator* debugVisu; - - bool enable; std::map<const std::string, std::shared_ptr<Layer>> layers; diff --git a/source/RobotAPI/interface/visualization/DebugDrawerInterface.ice b/source/RobotAPI/interface/visualization/DebugDrawerInterface.ice index cd0af64087449314b8a725f94ccbf835b90a1974..c68a0d1ba3e7416ef0e9ea4c0f7af442b156d14a 100644 --- a/source/RobotAPI/interface/visualization/DebugDrawerInterface.ice +++ b/source/RobotAPI/interface/visualization/DebugDrawerInterface.ice @@ -71,6 +71,7 @@ module armarx * \param globalPose The pose in global coordinate syetem. */ void setPoseVisu(string layerName, string poseName, PoseBase globalPose); + void setScaledPoseVisu(string layerName, string poseName, PoseBase globalPose, float scale); void setLineVisu(string layerName, string lineName, Vector3Base globalPosition1, Vector3Base globalPosition2, float lineWidth, DrawColor color); void setBoxVisu(string layerName, string boxName, PoseBase globalPose, Vector3Base dimensions, DrawColor color); void setTextVisu(string layerName, string textName, string text, Vector3Base globalPosition, DrawColor color, int size); @@ -82,6 +83,7 @@ module armarx * \param globalPose */ void setPoseDebugLayerVisu(string poseName, PoseBase globalPose); + void setScaledPoseDebugLayerVisu(string poseName, PoseBase globalPose, float scale); void setLineDebugLayerVisu(string lineName, Vector3Base globalPosition1, Vector3Base globalPosition2, float lineWidth, DrawColor color); void setBoxDebugLayerVisu(string boxName, PoseBase globalPose, Vector3Base dimensions, DrawColor color); void setTextDebugLayerVisu(string textName, string text, Vector3Base globalPosition, DrawColor color, int size); @@ -111,7 +113,7 @@ module armarx * \brief clear removes all visualizations for the given layer * \param layerName The name identifies the layer. */ - void clear(string layerName); + void clearLayer(string layerName); /*! * \brief clearDebugLayer calls <code>clear("debug");</code> */ @@ -124,6 +126,8 @@ module armarx */ void enableLayerVisu(string layerName, bool visible); + void enableDebugLayerVisu(bool visible); + /*! * \brief Returns the names of all layers. * \return The names of all layers.