Commit f98614ec authored by ozantonkal's avatar ozantonkal Committed by Ozan Tonkal

remove cloudactormap, shapeactormap. only vtkProp is stored and view…

remove cloudactormap, shapeactormap. only vtkProp is stored and view transformation can be obtained using GetUserMatrix of vtkProp3D
parent f6e1a093
...@@ -432,17 +432,17 @@ cv::viz::InteractorStyle::OnKeyDown () ...@@ -432,17 +432,17 @@ cv::viz::InteractorStyle::OnKeyDown ()
vtkSmartPointer<vtkCamera> cam = CurrentRenderer->GetActiveCamera (); vtkSmartPointer<vtkCamera> 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. // 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; 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 ()) if (it == widget_actor_map_->end ())
it = actors_->begin (); it = widget_actor_map_->begin ();
const CloudActor& actor = it->second; vtkProp3D * actor = vtkProp3D::SafeDownCast(it->second);
if (actor.viewpoint_transformation_.GetPointer ()) if (actor && actor->GetUserMatrix())
{ {
found_transformation = true; found_transformation = true;
break; break;
...@@ -452,18 +452,18 @@ cv::viz::InteractorStyle::OnKeyDown () ...@@ -452,18 +452,18 @@ cv::viz::InteractorStyle::OnKeyDown ()
// if a valid transformation was found, use it otherwise fall back to default view point. // if a valid transformation was found, use it otherwise fall back to default view point.
if (found_transformation) if (found_transformation)
{ {
const CloudActor& actor = it->second; vtkProp3D * actor = vtkProp3D::SafeDownCast(it->second);
cam->SetPosition (actor.viewpoint_transformation_->GetElement (0, 3), cam->SetPosition (actor->GetUserMatrix()->GetElement (0, 3),
actor.viewpoint_transformation_->GetElement (1, 3), actor->GetUserMatrix()->GetElement (1, 3),
actor.viewpoint_transformation_->GetElement (2, 3)); actor->GetUserMatrix()->GetElement (2, 3));
cam->SetFocalPoint (actor.viewpoint_transformation_->GetElement (0, 3) - actor.viewpoint_transformation_->GetElement (0, 2), cam->SetFocalPoint (actor->GetUserMatrix()->GetElement (0, 3) - actor->GetUserMatrix()->GetElement (0, 2),
actor.viewpoint_transformation_->GetElement (1, 3) - actor.viewpoint_transformation_->GetElement (1, 2), actor->GetUserMatrix()->GetElement (1, 3) - actor->GetUserMatrix()->GetElement (1, 2),
actor.viewpoint_transformation_->GetElement (2, 3) - actor.viewpoint_transformation_->GetElement (2, 2)); actor->GetUserMatrix()->GetElement (2, 3) - actor->GetUserMatrix()->GetElement (2, 2));
cam->SetViewUp (actor.viewpoint_transformation_->GetElement (0, 1), cam->SetViewUp (actor->GetUserMatrix()->GetElement (0, 1),
actor.viewpoint_transformation_->GetElement (1, 1), actor->GetUserMatrix()->GetElement (1, 1),
actor.viewpoint_transformation_->GetElement (2, 1)); actor->GetUserMatrix()->GetElement (2, 1));
} }
else else
{ {
...@@ -473,10 +473,10 @@ cv::viz::InteractorStyle::OnKeyDown () ...@@ -473,10 +473,10 @@ cv::viz::InteractorStyle::OnKeyDown ()
} }
// go to the next actor for the next key-press event. // go to the next actor for the next key-press event.
if (it != actors_->end ()) if (it != widget_actor_map_->end ())
++it; ++it;
else else
it = actors_->begin (); it = widget_actor_map_->begin ();
CurrentRenderer->SetActiveCamera (cam); CurrentRenderer->SetActiveCamera (cam);
CurrentRenderer->ResetCameraClippingRange (); CurrentRenderer->ResetCameraClippingRange ();
......
...@@ -50,7 +50,7 @@ namespace cv ...@@ -50,7 +50,7 @@ namespace cv
/** \brief Initialization routine. Must be called before anything else. */ /** \brief Initialization routine. Must be called before anything else. */
virtual void Initialize (); virtual void Initialize ();
inline void setCloudActorMap (const Ptr<CloudActorMap>& actors) { actors_ = actors; } inline void setWidgetActorMap (const Ptr<WidgetActorMap>& actors) { widget_actor_map_ = actors; }
void setRenderer (vtkSmartPointer<vtkRenderer>& ren) { renderer_ = ren; } void setRenderer (vtkSmartPointer<vtkRenderer>& ren) { renderer_ = ren; }
void registerMouseCallback(void (*callback)(const MouseEvent&, void*), void* cookie = 0); void registerMouseCallback(void (*callback)(const MouseEvent&, void*), void* cookie = 0);
void registerKeyboardCallback(void (*callback)(const KeyboardEvent&, void*), void * cookie = 0); void registerKeyboardCallback(void (*callback)(const KeyboardEvent&, void*), void * cookie = 0);
...@@ -73,8 +73,8 @@ namespace cv ...@@ -73,8 +73,8 @@ namespace cv
vtkSmartPointer<vtkRenderer> renderer_; vtkSmartPointer<vtkRenderer> renderer_;
/** \brief Actor map stored internally. */ /** \brief Actor map stored internally. */
cv::Ptr<CloudActorMap> actors_; cv::Ptr<WidgetActorMap> widget_actor_map_;
/** \brief The current window width/height. */ /** \brief The current window width/height. */
Vec2i win_size_; Vec2i win_size_;
......
...@@ -11,8 +11,6 @@ vtkRenderWindowInteractor* vtkRenderWindowInteractorFixNew () ...@@ -11,8 +11,6 @@ vtkRenderWindowInteractor* vtkRenderWindowInteractorFixNew ()
///////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////
cv::viz::Viz3d::VizImpl::VizImpl (const std::string &name) cv::viz::Viz3d::VizImpl::VizImpl (const std::string &name)
: style_ (vtkSmartPointer<cv::viz::InteractorStyle>::New ()) : style_ (vtkSmartPointer<cv::viz::InteractorStyle>::New ())
, cloud_actor_map_ (new CloudActorMap)
, shape_actor_map_ (new ShapeActorMap)
, widget_actor_map_ (new WidgetActorMap) , widget_actor_map_ (new WidgetActorMap)
, s_lastDone_(0.0) , s_lastDone_(0.0)
{ {
...@@ -30,7 +28,7 @@ cv::viz::Viz3d::VizImpl::VizImpl (const std::string &name) ...@@ -30,7 +28,7 @@ cv::viz::Viz3d::VizImpl::VizImpl (const std::string &name)
// Create the interactor style // Create the interactor style
style_->Initialize (); style_->Initialize ();
style_->setRenderer (renderer_); style_->setRenderer (renderer_);
style_->setCloudActorMap (cloud_actor_map_); style_->setWidgetActorMap (widget_actor_map_);
style_->UseTimersOn (); style_->UseTimersOn ();
///////////////////////////////////////////////// /////////////////////////////////////////////////
...@@ -358,11 +356,13 @@ void cv::viz::Viz3d::VizImpl::converTo3DRay(const Point3d &window_coord, Point3d ...@@ -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) void cv::viz::Viz3d::VizImpl::resetCameraViewpoint (const std::string &id)
{ {
// TODO Cloud actor is not used
vtkSmartPointer<vtkMatrix4x4> camera_pose; vtkSmartPointer<vtkMatrix4x4> camera_pose;
static CloudActorMap::iterator it = cloud_actor_map_->find (id); static WidgetActorMap::iterator it = widget_actor_map_->find (id);
if (it != cloud_actor_map_->end ()) if (it != widget_actor_map_->end ())
camera_pose = it->second.viewpoint_transformation_; {
vtkProp3D *actor = vtkProp3D::SafeDownCast(it->second);
camera_pose = actor->GetUserMatrix();
}
else else
return; return;
...@@ -370,10 +370,6 @@ void cv::viz::Viz3d::VizImpl::resetCameraViewpoint (const std::string &id) ...@@ -370,10 +370,6 @@ void cv::viz::Viz3d::VizImpl::resetCameraViewpoint (const std::string &id)
if (!camera_pose) if (!camera_pose)
return; return;
// set all renderer to this viewpoint
//rens_->InitTraversal ();
vtkSmartPointer<vtkCamera> cam = renderer_->GetActiveCamera (); vtkSmartPointer<vtkCamera> cam = renderer_->GetActiveCamera ();
cam->SetPosition (camera_pose->GetElement (0, 3), cam->SetPosition (camera_pose->GetElement (0, 3),
camera_pose->GetElement (1, 3), camera_pose->GetElement (1, 3),
...@@ -522,7 +518,7 @@ void cv::viz::Viz3d::VizImpl::showWidget(const String &id, const Widget &widget, ...@@ -522,7 +518,7 @@ void cv::viz::Viz3d::VizImpl::showWidget(const String &id, const Widget &widget,
if (exists) if (exists)
{ {
// Remove it if it exists and add it again // 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 // Get the actor and set the user matrix
vtkProp3D *actor = vtkProp3D::SafeDownCast(WidgetAccessor::getProp(widget)); vtkProp3D *actor = vtkProp3D::SafeDownCast(WidgetAccessor::getProp(widget));
...@@ -541,7 +537,7 @@ void cv::viz::Viz3d::VizImpl::showWidget(const String &id, const Widget &widget, ...@@ -541,7 +537,7 @@ void cv::viz::Viz3d::VizImpl::showWidget(const String &id, const Widget &widget,
} }
renderer_->AddActor(WidgetAccessor::getProp(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) void cv::viz::Viz3d::VizImpl::removeWidget(const String &id)
...@@ -549,7 +545,7 @@ 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); WidgetActorMap::iterator wam_itr = widget_actor_map_->find(id);
bool exists = wam_itr != widget_actor_map_->end(); bool exists = wam_itr != widget_actor_map_->end();
CV_Assert(exists); CV_Assert(exists);
CV_Assert(removeActorFromRenderer (wam_itr->second.actor)); CV_Assert(removeActorFromRenderer (wam_itr->second));
widget_actor_map_->erase(wam_itr); widget_actor_map_->erase(wam_itr);
} }
...@@ -560,7 +556,7 @@ cv::viz::Widget cv::viz::Viz3d::VizImpl::getWidget(const String &id) const ...@@ -560,7 +556,7 @@ cv::viz::Widget cv::viz::Viz3d::VizImpl::getWidget(const String &id) const
CV_Assert(exists); CV_Assert(exists);
Widget widget; Widget widget;
WidgetAccessor::setProp(widget, wam_itr->second.actor); WidgetAccessor::setProp(widget, wam_itr->second);
return widget; return widget;
} }
...@@ -570,7 +566,7 @@ void cv::viz::Viz3d::VizImpl::setWidgetPose(const String &id, const Affine3f &po ...@@ -570,7 +566,7 @@ void cv::viz::Viz3d::VizImpl::setWidgetPose(const String &id, const Affine3f &po
bool exists = wam_itr != widget_actor_map_->end(); bool exists = wam_itr != widget_actor_map_->end();
CV_Assert(exists); CV_Assert(exists);
vtkProp3D *actor = vtkProp3D::SafeDownCast(wam_itr->second.actor); vtkProp3D *actor = vtkProp3D::SafeDownCast(wam_itr->second);
CV_Assert(actor); CV_Assert(actor);
vtkSmartPointer<vtkMatrix4x4> matrix = convertToVtkMatrix(pose.matrix); vtkSmartPointer<vtkMatrix4x4> matrix = convertToVtkMatrix(pose.matrix);
...@@ -584,7 +580,7 @@ void cv::viz::Viz3d::VizImpl::updateWidgetPose(const String &id, const Affine3f ...@@ -584,7 +580,7 @@ void cv::viz::Viz3d::VizImpl::updateWidgetPose(const String &id, const Affine3f
bool exists = wam_itr != widget_actor_map_->end(); bool exists = wam_itr != widget_actor_map_->end();
CV_Assert(exists); CV_Assert(exists);
vtkProp3D *actor = vtkProp3D::SafeDownCast(wam_itr->second.actor); vtkProp3D *actor = vtkProp3D::SafeDownCast(wam_itr->second);
CV_Assert(actor); CV_Assert(actor);
vtkSmartPointer<vtkMatrix4x4> matrix = actor->GetUserMatrix(); vtkSmartPointer<vtkMatrix4x4> matrix = actor->GetUserMatrix();
...@@ -607,7 +603,7 @@ cv::Affine3f cv::viz::Viz3d::VizImpl::getWidgetPose(const String &id) const ...@@ -607,7 +603,7 @@ cv::Affine3f cv::viz::Viz3d::VizImpl::getWidgetPose(const String &id) const
bool exists = wam_itr != widget_actor_map_->end(); bool exists = wam_itr != widget_actor_map_->end();
CV_Assert(exists); CV_Assert(exists);
vtkProp3D *actor = vtkProp3D::SafeDownCast(wam_itr->second.actor); vtkProp3D *actor = vtkProp3D::SafeDownCast(wam_itr->second);
CV_Assert(actor); CV_Assert(actor);
vtkSmartPointer<vtkMatrix4x4> matrix = actor->GetUserMatrix(); vtkSmartPointer<vtkMatrix4x4> matrix = actor->GetUserMatrix();
......
...@@ -144,10 +144,10 @@ private: ...@@ -144,10 +144,10 @@ private:
vtkSmartPointer<InteractorStyle> style_; vtkSmartPointer<InteractorStyle> style_;
/** \brief Internal list with actor pointers and name IDs for point clouds. */ /** \brief Internal list with actor pointers and name IDs for point clouds. */
cv::Ptr<CloudActorMap> cloud_actor_map_; // cv::Ptr<CloudActorMap> cloud_actor_map_;
/** \brief Internal list with actor pointers and name IDs for shapes. */ /** \brief Internal list with actor pointers and name IDs for shapes. */
cv::Ptr<ShapeActorMap> shape_actor_map_; // cv::Ptr<ShapeActorMap> shape_actor_map_;
/** \brief Internal list with actor pointers and name IDs for all widget actors */ /** \brief Internal list with actor pointers and name IDs for all widget actors */
cv::Ptr<WidgetActorMap> widget_actor_map_; cv::Ptr<WidgetActorMap> widget_actor_map_;
......
...@@ -6,29 +6,7 @@ namespace cv ...@@ -6,29 +6,7 @@ namespace cv
{ {
namespace viz namespace viz
{ {
struct CV_EXPORTS CloudActor typedef std::map<std::string, vtkSmartPointer<vtkProp> > WidgetActorMap;
{
/** \brief The actor holding the data to render. */
vtkSmartPointer<vtkLODActor> actor;
/** \brief The viewpoint transformation matrix. */
vtkSmartPointer<vtkMatrix4x4> viewpoint_transformation_;
/** \brief Internal cell array. Used for optimizing updatePointCloud. */
vtkSmartPointer<vtkIdTypeArray> cells;
};
// TODO This will be used to contain both cloud and shape actors
struct CV_EXPORTS WidgetActor
{
vtkSmartPointer<vtkProp> actor;
vtkSmartPointer<vtkMatrix4x4> viewpoint_transformation_;
vtkSmartPointer<vtkIdTypeArray> cells;
};
typedef std::map<std::string, CloudActor> CloudActorMap;
typedef std::map<std::string, vtkSmartPointer<vtkProp> > ShapeActorMap;
typedef std::map<std::string, WidgetActor> WidgetActorMap;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment