From f98614ece0de86c26ea59ee3d2a47c9c212503ec Mon Sep 17 00:00:00 2001 From: ozantonkal Date: Sat, 24 Aug 2013 12:52:34 +0200 Subject: [PATCH] remove cloudactormap, shapeactormap. only vtkProp is stored and view transformation can be obtained using GetUserMatrix of vtkProp3D --- modules/viz/src/interactor_style.cpp | 42 ++++++++++++++++++------------------ modules/viz/src/interactor_style.h | 6 +++--- modules/viz/src/viz3d_impl.cpp | 32 ++++++++++++--------------- modules/viz/src/viz3d_impl.hpp | 4 ++-- modules/viz/src/viz_types.h | 24 +-------------------- 5 files changed, 41 insertions(+), 67 deletions(-) diff --git a/modules/viz/src/interactor_style.cpp b/modules/viz/src/interactor_style.cpp index 2daec81..db3d979 100644 --- a/modules/viz/src/interactor_style.cpp +++ b/modules/viz/src/interactor_style.cpp @@ -432,17 +432,17 @@ cv::viz::InteractorStyle::OnKeyDown () vtkSmartPointer cam = CurrentRenderer->GetActiveCamera (); - static CloudActorMap::iterator it = actors_->begin (); + static WidgetActorMap::iterator it = widget_actor_map_->begin (); // it might be that some actors don't have a valid transformation set -> we skip them to avoid a seg fault. bool found_transformation = false; - for (size_t idx = 0; idx < actors_->size (); ++idx, ++it) + for (size_t idx = 0; idx < widget_actor_map_->size (); ++idx, ++it) { - if (it == actors_->end ()) - it = actors_->begin (); - - const CloudActor& actor = it->second; - if (actor.viewpoint_transformation_.GetPointer ()) + if (it == widget_actor_map_->end ()) + it = widget_actor_map_->begin (); + + vtkProp3D * actor = vtkProp3D::SafeDownCast(it->second); + if (actor && actor->GetUserMatrix()) { found_transformation = true; break; @@ -452,18 +452,18 @@ cv::viz::InteractorStyle::OnKeyDown () // if a valid transformation was found, use it otherwise fall back to default view point. if (found_transformation) { - const CloudActor& actor = it->second; - cam->SetPosition (actor.viewpoint_transformation_->GetElement (0, 3), - actor.viewpoint_transformation_->GetElement (1, 3), - actor.viewpoint_transformation_->GetElement (2, 3)); - - cam->SetFocalPoint (actor.viewpoint_transformation_->GetElement (0, 3) - actor.viewpoint_transformation_->GetElement (0, 2), - actor.viewpoint_transformation_->GetElement (1, 3) - actor.viewpoint_transformation_->GetElement (1, 2), - actor.viewpoint_transformation_->GetElement (2, 3) - actor.viewpoint_transformation_->GetElement (2, 2)); - - cam->SetViewUp (actor.viewpoint_transformation_->GetElement (0, 1), - actor.viewpoint_transformation_->GetElement (1, 1), - actor.viewpoint_transformation_->GetElement (2, 1)); + vtkProp3D * actor = vtkProp3D::SafeDownCast(it->second); + cam->SetPosition (actor->GetUserMatrix()->GetElement (0, 3), + actor->GetUserMatrix()->GetElement (1, 3), + actor->GetUserMatrix()->GetElement (2, 3)); + + cam->SetFocalPoint (actor->GetUserMatrix()->GetElement (0, 3) - actor->GetUserMatrix()->GetElement (0, 2), + actor->GetUserMatrix()->GetElement (1, 3) - actor->GetUserMatrix()->GetElement (1, 2), + actor->GetUserMatrix()->GetElement (2, 3) - actor->GetUserMatrix()->GetElement (2, 2)); + + cam->SetViewUp (actor->GetUserMatrix()->GetElement (0, 1), + actor->GetUserMatrix()->GetElement (1, 1), + actor->GetUserMatrix()->GetElement (2, 1)); } else { @@ -473,10 +473,10 @@ cv::viz::InteractorStyle::OnKeyDown () } // go to the next actor for the next key-press event. - if (it != actors_->end ()) + if (it != widget_actor_map_->end ()) ++it; else - it = actors_->begin (); + it = widget_actor_map_->begin (); CurrentRenderer->SetActiveCamera (cam); CurrentRenderer->ResetCameraClippingRange (); diff --git a/modules/viz/src/interactor_style.h b/modules/viz/src/interactor_style.h index db20a1a..aba03a3 100644 --- a/modules/viz/src/interactor_style.h +++ b/modules/viz/src/interactor_style.h @@ -50,7 +50,7 @@ namespace cv /** \brief Initialization routine. Must be called before anything else. */ virtual void Initialize (); - inline void setCloudActorMap (const Ptr& actors) { actors_ = actors; } + inline void setWidgetActorMap (const Ptr& actors) { widget_actor_map_ = actors; } void setRenderer (vtkSmartPointer& ren) { renderer_ = ren; } void registerMouseCallback(void (*callback)(const MouseEvent&, void*), void* cookie = 0); void registerKeyboardCallback(void (*callback)(const KeyboardEvent&, void*), void * cookie = 0); @@ -73,8 +73,8 @@ namespace cv vtkSmartPointer renderer_; /** \brief Actor map stored internally. */ - cv::Ptr actors_; - + cv::Ptr widget_actor_map_; + /** \brief The current window width/height. */ Vec2i win_size_; diff --git a/modules/viz/src/viz3d_impl.cpp b/modules/viz/src/viz3d_impl.cpp index 1c35216..6e91338 100644 --- a/modules/viz/src/viz3d_impl.cpp +++ b/modules/viz/src/viz3d_impl.cpp @@ -11,8 +11,6 @@ vtkRenderWindowInteractor* vtkRenderWindowInteractorFixNew () ///////////////////////////////////////////////////////////////////////////////////////////// cv::viz::Viz3d::VizImpl::VizImpl (const std::string &name) : style_ (vtkSmartPointer::New ()) - , cloud_actor_map_ (new CloudActorMap) - , shape_actor_map_ (new ShapeActorMap) , widget_actor_map_ (new WidgetActorMap) , s_lastDone_(0.0) { @@ -30,7 +28,7 @@ cv::viz::Viz3d::VizImpl::VizImpl (const std::string &name) // Create the interactor style style_->Initialize (); style_->setRenderer (renderer_); - style_->setCloudActorMap (cloud_actor_map_); + style_->setWidgetActorMap (widget_actor_map_); style_->UseTimersOn (); ///////////////////////////////////////////////// @@ -358,11 +356,13 @@ void cv::viz::Viz3d::VizImpl::converTo3DRay(const Point3d &window_coord, Point3d ///////////////////////////////////////////////////////////////////////////////////////////// void cv::viz::Viz3d::VizImpl::resetCameraViewpoint (const std::string &id) { - // TODO Cloud actor is not used vtkSmartPointer camera_pose; - static CloudActorMap::iterator it = cloud_actor_map_->find (id); - if (it != cloud_actor_map_->end ()) - camera_pose = it->second.viewpoint_transformation_; + static WidgetActorMap::iterator it = widget_actor_map_->find (id); + if (it != widget_actor_map_->end ()) + { + vtkProp3D *actor = vtkProp3D::SafeDownCast(it->second); + camera_pose = actor->GetUserMatrix(); + } else return; @@ -370,10 +370,6 @@ void cv::viz::Viz3d::VizImpl::resetCameraViewpoint (const std::string &id) if (!camera_pose) return; - // set all renderer to this viewpoint - //rens_->InitTraversal (); - - vtkSmartPointer cam = renderer_->GetActiveCamera (); cam->SetPosition (camera_pose->GetElement (0, 3), camera_pose->GetElement (1, 3), @@ -522,7 +518,7 @@ void cv::viz::Viz3d::VizImpl::showWidget(const String &id, const Widget &widget, if (exists) { // Remove it if it exists and add it again - removeActorFromRenderer(wam_itr->second.actor); + removeActorFromRenderer(wam_itr->second); } // Get the actor and set the user matrix vtkProp3D *actor = vtkProp3D::SafeDownCast(WidgetAccessor::getProp(widget)); @@ -541,7 +537,7 @@ void cv::viz::Viz3d::VizImpl::showWidget(const String &id, const Widget &widget, } renderer_->AddActor(WidgetAccessor::getProp(widget)); - (*widget_actor_map_)[id].actor = WidgetAccessor::getProp(widget); + (*widget_actor_map_)[id] = WidgetAccessor::getProp(widget); } void cv::viz::Viz3d::VizImpl::removeWidget(const String &id) @@ -549,7 +545,7 @@ void cv::viz::Viz3d::VizImpl::removeWidget(const String &id) WidgetActorMap::iterator wam_itr = widget_actor_map_->find(id); bool exists = wam_itr != widget_actor_map_->end(); CV_Assert(exists); - CV_Assert(removeActorFromRenderer (wam_itr->second.actor)); + CV_Assert(removeActorFromRenderer (wam_itr->second)); widget_actor_map_->erase(wam_itr); } @@ -560,7 +556,7 @@ cv::viz::Widget cv::viz::Viz3d::VizImpl::getWidget(const String &id) const CV_Assert(exists); Widget widget; - WidgetAccessor::setProp(widget, wam_itr->second.actor); + WidgetAccessor::setProp(widget, wam_itr->second); return widget; } @@ -570,7 +566,7 @@ void cv::viz::Viz3d::VizImpl::setWidgetPose(const String &id, const Affine3f &po bool exists = wam_itr != widget_actor_map_->end(); CV_Assert(exists); - vtkProp3D *actor = vtkProp3D::SafeDownCast(wam_itr->second.actor); + vtkProp3D *actor = vtkProp3D::SafeDownCast(wam_itr->second); CV_Assert(actor); vtkSmartPointer matrix = convertToVtkMatrix(pose.matrix); @@ -584,7 +580,7 @@ void cv::viz::Viz3d::VizImpl::updateWidgetPose(const String &id, const Affine3f bool exists = wam_itr != widget_actor_map_->end(); CV_Assert(exists); - vtkProp3D *actor = vtkProp3D::SafeDownCast(wam_itr->second.actor); + vtkProp3D *actor = vtkProp3D::SafeDownCast(wam_itr->second); CV_Assert(actor); vtkSmartPointer matrix = actor->GetUserMatrix(); @@ -607,7 +603,7 @@ cv::Affine3f cv::viz::Viz3d::VizImpl::getWidgetPose(const String &id) const bool exists = wam_itr != widget_actor_map_->end(); CV_Assert(exists); - vtkProp3D *actor = vtkProp3D::SafeDownCast(wam_itr->second.actor); + vtkProp3D *actor = vtkProp3D::SafeDownCast(wam_itr->second); CV_Assert(actor); vtkSmartPointer matrix = actor->GetUserMatrix(); diff --git a/modules/viz/src/viz3d_impl.hpp b/modules/viz/src/viz3d_impl.hpp index 67f7c27..988b732 100644 --- a/modules/viz/src/viz3d_impl.hpp +++ b/modules/viz/src/viz3d_impl.hpp @@ -144,10 +144,10 @@ private: vtkSmartPointer style_; /** \brief Internal list with actor pointers and name IDs for point clouds. */ - cv::Ptr cloud_actor_map_; +// cv::Ptr cloud_actor_map_; /** \brief Internal list with actor pointers and name IDs for shapes. */ - cv::Ptr shape_actor_map_; +// cv::Ptr shape_actor_map_; /** \brief Internal list with actor pointers and name IDs for all widget actors */ cv::Ptr widget_actor_map_; diff --git a/modules/viz/src/viz_types.h b/modules/viz/src/viz_types.h index 9d47a0c..33de56a 100644 --- a/modules/viz/src/viz_types.h +++ b/modules/viz/src/viz_types.h @@ -6,29 +6,7 @@ namespace cv { namespace viz { - struct CV_EXPORTS CloudActor - { - /** \brief The actor holding the data to render. */ - vtkSmartPointer actor; - - /** \brief The viewpoint transformation matrix. */ - vtkSmartPointer viewpoint_transformation_; - - /** \brief Internal cell array. Used for optimizing updatePointCloud. */ - vtkSmartPointer cells; - }; - - // TODO This will be used to contain both cloud and shape actors - struct CV_EXPORTS WidgetActor - { - vtkSmartPointer actor; - vtkSmartPointer viewpoint_transformation_; - vtkSmartPointer cells; - }; - - typedef std::map CloudActorMap; - typedef std::map > ShapeActorMap; - typedef std::map WidgetActorMap; + typedef std::map > WidgetActorMap; } } -- 2.7.4