diff --git a/modules/viz/include/opencv2/viz/viz3d.hpp b/modules/viz/include/opencv2/viz/viz3d.hpp index f4adcd8355..96f999bed8 100644 --- a/modules/viz/include/opencv2/viz/viz3d.hpp +++ b/modules/viz/include/opencv2/viz/viz3d.hpp @@ -37,6 +37,7 @@ namespace cv void showWidget(const String &id, const Widget &widget, const Affine3f &pose = Affine3f::Identity()); void removeWidget(const String &id); Widget getWidget(const String &id) const; + void removeAllWidgets(); void setWidgetPose(const String &id, const Affine3f &pose); void updateWidgetPose(const String &id, const Affine3f &pose); diff --git a/modules/viz/src/viz3d.cpp b/modules/viz/src/viz3d.cpp index 583ece096b..bb88e1337d 100644 --- a/modules/viz/src/viz3d.cpp +++ b/modules/viz/src/viz3d.cpp @@ -79,6 +79,7 @@ void cv::viz::Viz3d::registerMouseCallback(MouseCallback callback, void* cookie) void cv::viz::Viz3d::showWidget(const String &id, const Widget &widget, const Affine3f &pose) { impl_->showWidget(id, widget, pose); } void cv::viz::Viz3d::removeWidget(const String &id) { impl_->removeWidget(id); } cv::viz::Widget cv::viz::Viz3d::getWidget(const String &id) const { return impl_->getWidget(id); } +void cv::viz::Viz3d::removeAllWidgets() { impl_->removeAllWidgets(); } void cv::viz::Viz3d::setWidgetPose(const String &id, const Affine3f &pose) { impl_->setWidgetPose(id, pose); } void cv::viz::Viz3d::updateWidgetPose(const String &id, const Affine3f &pose) { impl_->updateWidgetPose(id, pose); } cv::Affine3f cv::viz::Viz3d::getWidgetPose(const String &id) const { return impl_->getWidgetPose(id); } diff --git a/modules/viz/src/viz3d_impl.cpp b/modules/viz/src/viz3d_impl.cpp index 4b7d1271f0..12a3de15f5 100644 --- a/modules/viz/src/viz3d_impl.cpp +++ b/modules/viz/src/viz3d_impl.cpp @@ -128,104 +128,13 @@ void cv::viz::Viz3d::VizImpl::spinOnce (int time, bool force_redraw) } } -///////////////////////////////////////////////////////////////////////////////////////////// -bool cv::viz::Viz3d::VizImpl::removePointCloud (const std::string &id) +////////////////////////////////////////////////////////////////////////////////////////// +void cv::viz::Viz3d::VizImpl::removeAllWidgets() { - CloudActorMap::iterator am_it = cloud_actor_map_->find (id); - if (am_it == cloud_actor_map_->end ()) - return false; - - if (removeActorFromRenderer (am_it->second.actor)) - return cloud_actor_map_->erase (am_it), true; - - return false; + widget_actor_map_->clear(); + renderer_->RemoveAllViewProps(); } -///////////////////////////////////////////////////////////////////////////////////////////// -bool cv::viz::Viz3d::VizImpl::removeShape (const std::string &id) -{ - // Check to see if the given ID entry exists - ShapeActorMap::iterator am_it = shape_actor_map_->find (id); - // Extra step: check if there is a cloud with the same ID - CloudActorMap::iterator ca_it = cloud_actor_map_->find (id); - - bool shape = true; - // Try to find a shape first - if (am_it == shape_actor_map_->end ()) - { - // There is no cloud or shape with this ID, so just exit - if (ca_it == cloud_actor_map_->end ()) - return false; - // Cloud found, set shape to false - shape = false; - } - - // Remove the pointer/ID pair to the global actor map - if (shape) - { - if (removeActorFromRenderer (am_it->second)) - { - shape_actor_map_->erase (am_it); - return (true); - } - } - else - { - if (removeActorFromRenderer (ca_it->second.actor)) - { - cloud_actor_map_->erase (ca_it); - return true; - } - } - return false; -} - -///////////////////////////////////////////////////////////////////////////////////////////// -bool cv::viz::Viz3d::VizImpl::removeText3D (const std::string &id) -{ - // Check to see if the given ID entry exists - ShapeActorMap::iterator am_it = shape_actor_map_->find (id); - if (am_it == shape_actor_map_->end ()) - return false; - - // Remove it from all renderers - if (removeActorFromRenderer (am_it->second)) - return shape_actor_map_->erase (am_it), true; - - return false; -} - -///////////////////////////////////////////////////////////////////////////////////////////// -bool cv::viz::Viz3d::VizImpl::removeAllPointClouds () -{ - // Check to see if the given ID entry exists - CloudActorMap::iterator am_it = cloud_actor_map_->begin (); - while (am_it != cloud_actor_map_->end () ) - { - if (removePointCloud (am_it->first)) - am_it = cloud_actor_map_->begin (); - else - ++am_it; - } - return (true); -} - -///////////////////////////////////////////////////////////////////////////////////////////// -bool cv::viz::Viz3d::VizImpl::removeAllShapes () -{ - // Check to see if the given ID entry exists - ShapeActorMap::iterator am_it = shape_actor_map_->begin (); - while (am_it != shape_actor_map_->end ()) - { - if (removeShape (am_it->first)) - am_it = shape_actor_map_->begin (); - else - ++am_it; - } - return (true); -} - - ////////////////////////////////////////////////////////////////////////////////////////// bool cv::viz::Viz3d::VizImpl::removeActorFromRenderer (const vtkSmartPointer &actor) { diff --git a/modules/viz/src/viz3d_impl.hpp b/modules/viz/src/viz3d_impl.hpp index ef23cc1b90..83e41e4996 100644 --- a/modules/viz/src/viz3d_impl.hpp +++ b/modules/viz/src/viz3d_impl.hpp @@ -17,23 +17,7 @@ public: VizImpl (const String &name); virtual ~VizImpl (); - - - - - - - - - //to refactor - bool removePointCloud (const String& id = "cloud"); - inline bool removePolygonMesh (const String& id = "polygon") { return removePointCloud (id); } - bool removeShape (const String& id = "cloud"); - bool removeText3D (const String& id = "cloud"); - bool removeAllPointClouds (); - - //create Viz3d::removeAllWidgets() - bool removeAllShapes (); + void removeAllWidgets(); //to refactor bool addPolygonMesh (const Mesh3d& mesh, const cv::Mat& mask, const String& id = "polygon");