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.
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;
// 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
{
}
// 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 ();
/** \brief Initialization routine. Must be called before anything else. */
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 registerMouseCallback(void (*callback)(const MouseEvent&, void*), void* cookie = 0);
void registerKeyboardCallback(void (*callback)(const KeyboardEvent&, void*), void * cookie = 0);
vtkSmartPointer<vtkRenderer> renderer_;
/** \brief Actor map stored internally. */
- cv::Ptr<CloudActorMap> actors_;
-
+ cv::Ptr<WidgetActorMap> widget_actor_map_;
+
/** \brief The current window width/height. */
Vec2i win_size_;
/////////////////////////////////////////////////////////////////////////////////////////////
cv::viz::Viz3d::VizImpl::VizImpl (const std::string &name)
: style_ (vtkSmartPointer<cv::viz::InteractorStyle>::New ())
- , cloud_actor_map_ (new CloudActorMap)
- , shape_actor_map_ (new ShapeActorMap)
, widget_actor_map_ (new WidgetActorMap)
, s_lastDone_(0.0)
{
// Create the interactor style
style_->Initialize ();
style_->setRenderer (renderer_);
- style_->setCloudActorMap (cloud_actor_map_);
+ style_->setWidgetActorMap (widget_actor_map_);
style_->UseTimersOn ();
/////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
void cv::viz::Viz3d::VizImpl::resetCameraViewpoint (const std::string &id)
{
- // TODO Cloud actor is not used
vtkSmartPointer<vtkMatrix4x4> 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;
if (!camera_pose)
return;
- // set all renderer to this viewpoint
- //rens_->InitTraversal ();
-
-
vtkSmartPointer<vtkCamera> cam = renderer_->GetActiveCamera ();
cam->SetPosition (camera_pose->GetElement (0, 3),
camera_pose->GetElement (1, 3),
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));
}
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)
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);
}
CV_Assert(exists);
Widget widget;
- WidgetAccessor::setProp(widget, wam_itr->second.actor);
+ WidgetAccessor::setProp(widget, wam_itr->second);
return widget;
}
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<vtkMatrix4x4> matrix = convertToVtkMatrix(pose.matrix);
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<vtkMatrix4x4> matrix = actor->GetUserMatrix();
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<vtkMatrix4x4> matrix = actor->GetUserMatrix();
vtkSmartPointer<InteractorStyle> style_;
/** \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. */
- 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 */
cv::Ptr<WidgetActorMap> widget_actor_map_;
{
namespace viz
{
- struct CV_EXPORTS CloudActor
- {
- /** \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;
+ typedef std::map<std::string, vtkSmartPointer<vtkProp> > WidgetActorMap;
}
}