remove cloudactormap, shapeactormap. only vtkProp is stored and view transformation can be obtained using GetUserMatrix of vtkProp3D

This commit is contained in:
ozantonkal 2013-08-24 12:52:34 +02:00 committed by Ozan Tonkal
parent f6e1a093cd
commit f98614ece0
5 changed files with 39 additions and 65 deletions

View File

@ -432,17 +432,17 @@ cv::viz::InteractorStyle::OnKeyDown ()
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;
@ -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));
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.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->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.viewpoint_transformation_->GetElement (0, 1),
actor.viewpoint_transformation_->GetElement (1, 1),
actor.viewpoint_transformation_->GetElement (2, 1));
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 ();

View File

@ -50,7 +50,7 @@ namespace cv
/** \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);
@ -73,8 +73,8 @@ namespace cv
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_;

View File

@ -11,8 +11,6 @@ vtkRenderWindowInteractor* vtkRenderWindowInteractorFixNew ()
/////////////////////////////////////////////////////////////////////////////////////////////
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)
{
@ -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<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;
@ -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<vtkCamera> 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<vtkMatrix4x4> 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<vtkMatrix4x4> 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<vtkMatrix4x4> matrix = actor->GetUserMatrix();

View File

@ -144,10 +144,10 @@ private:
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_;

View File

@ -6,29 +6,7 @@ namespace cv
{
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;
}
}