fix vtkActor to vtkLODActor, initial implementation LineWidget, showWidget
This commit is contained in:
@@ -245,6 +245,9 @@ public:
|
||||
|
||||
void setPosition (int x, int y);
|
||||
void setSize (int xw, int yw);
|
||||
|
||||
void showWidget(const String &id, const Widget &widget);
|
||||
void all_data();
|
||||
|
||||
private:
|
||||
vtkSmartPointer<vtkRenderWindowInteractor> interactor_;
|
||||
@@ -311,6 +314,9 @@ private:
|
||||
|
||||
/** \brief Internal list with actor pointers and name IDs for shapes. */
|
||||
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_;
|
||||
|
||||
/** \brief Boolean that holds whether or not the camera parameters were manually initialized*/
|
||||
bool camera_set_;
|
||||
|
||||
@@ -15,8 +15,17 @@ namespace temp_viz
|
||||
/** \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;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,28 +24,18 @@ class temp_viz::Widget::Impl
|
||||
{
|
||||
public:
|
||||
String id;
|
||||
vtkSmartPointer<vtkActor> actor;
|
||||
vtkSmartPointer<vtkLODActor> actor;
|
||||
|
||||
Impl()
|
||||
{
|
||||
actor = vtkSmartPointer<vtkActor>:: New();
|
||||
actor = vtkSmartPointer<vtkLODActor>::New ();
|
||||
}
|
||||
|
||||
vtkSmartPointer<vtkActor> getActor()
|
||||
vtkSmartPointer<vtkLODActor> getActor()
|
||||
{
|
||||
return actor;
|
||||
}
|
||||
|
||||
void setId(const String &id)
|
||||
{
|
||||
this->id = id;
|
||||
}
|
||||
|
||||
const temp_viz::String & getString() const
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
void setColor(const Color & color)
|
||||
{
|
||||
Color c = vtkcolor(color);
|
||||
@@ -85,11 +75,22 @@ public:
|
||||
return Affine3f(matrix_cv);
|
||||
}
|
||||
|
||||
void setActorMapperInput(const vtkSmartPointer<vtkDataSet> &data)
|
||||
{
|
||||
vtkSmartPointer<vtkDataSetMapper> mapper = reinterpret_cast<vtkDataSetMapper*>(actor->GetMapper ());
|
||||
if (mapper == 0)
|
||||
{
|
||||
mapper = vtkSmartPointer<vtkDataSetMapper>::New ();
|
||||
actor->SetMapper(mapper);
|
||||
}
|
||||
mapper->SetInput (data);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
vtkSmartPointer<vtkMatrix4x4> convertToVtkMatrix (const cv::Matx44f &m) const
|
||||
{
|
||||
vtkSmartPointer<vtkMatrix4x4> vtk_matrix = vtkSmartPointer<vtkMatrix4x4>::New();
|
||||
vtkSmartPointer<vtkMatrix4x4> vtk_matrix = vtkSmartPointer<vtkMatrix4x4>::New ();
|
||||
for (int i = 0; i < 4; i++)
|
||||
for (int k = 0; k < 4; k++)
|
||||
vtk_matrix->SetElement(i, k, m(i, k));
|
||||
@@ -101,20 +102,12 @@ protected:
|
||||
for (int i = 0; i < 4; i++)
|
||||
for (int k = 0; k < 4; k++)
|
||||
m(i,k) = vtk_matrix->GetElement (i, k);
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
temp_viz::Widget::Widget()
|
||||
{
|
||||
impl_ = new Impl();
|
||||
impl_->setId("id");
|
||||
}
|
||||
|
||||
temp_viz::Widget::Widget(const String &id)
|
||||
{
|
||||
impl_ = new Impl();
|
||||
impl_->setId("id");
|
||||
}
|
||||
|
||||
temp_viz::Widget::Widget(const Widget &other)
|
||||
@@ -122,11 +115,6 @@ temp_viz::Widget::Widget(const Widget &other)
|
||||
impl_ = other.impl_;
|
||||
}
|
||||
|
||||
void temp_viz::Widget::setId(const String &id)
|
||||
{
|
||||
impl_->setId(id);
|
||||
}
|
||||
|
||||
void temp_viz::Widget::setColor(const Color &color)
|
||||
{
|
||||
impl_->setColor(color);
|
||||
@@ -147,11 +135,18 @@ temp_viz::Affine3f temp_viz::Widget::getPose() const
|
||||
return impl_->getPose();
|
||||
}
|
||||
|
||||
// TODO Check if HAVE_VTK
|
||||
#include "opencv2/viz/widget_accessor.hpp"
|
||||
|
||||
vtkSmartPointer<vtkActor> temp_viz::WidgetAccessor::getActor(const temp_viz::Widget &widget)
|
||||
vtkSmartPointer<vtkLODActor> temp_viz::WidgetAccessor::getActor(const temp_viz::Widget &widget)
|
||||
{
|
||||
return widget.impl_->actor;
|
||||
}
|
||||
|
||||
temp_viz::LineWidget::LineWidget(const Point3f &pt1, const Point3f &pt2, const Color &color) : Widget()
|
||||
{
|
||||
// Create the line and set actor's data
|
||||
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New ();
|
||||
mapper->SetInput(createLine(pt1,pt2));
|
||||
temp_viz::WidgetAccessor::getActor(*this)->SetMapper(mapper);
|
||||
setColor(color);
|
||||
}
|
||||
@@ -139,3 +139,7 @@ void temp_viz::Viz3d::registerMouseCallback(void (*callback)(const MouseEvent&,
|
||||
|
||||
bool temp_viz::Viz3d::wasStopped() const { return impl_->wasStopped(); }
|
||||
|
||||
void temp_viz::Viz3d::showWidget(const String &id, const Widget &widget)
|
||||
{
|
||||
impl_->showWidget(id, widget);
|
||||
}
|
||||
|
||||
@@ -1168,3 +1168,18 @@ bool temp_viz::Viz3d::VizImpl::addPolygon (const cv::Mat& cloud, const Color& co
|
||||
|
||||
return (true);
|
||||
}
|
||||
|
||||
#include "opencv2/viz/widget_accessor.hpp"
|
||||
|
||||
void temp_viz::Viz3d::VizImpl::showWidget(const String &id, const Widget &widget)
|
||||
{
|
||||
WidgetActorMap::iterator wam_itr = widget_actor_map_->find(id);
|
||||
bool exists = !(wam_itr == widget_actor_map_->end());
|
||||
if (exists)
|
||||
{
|
||||
// Remove it if it exists and add it again
|
||||
removeActorFromRenderer(wam_itr->second.actor);
|
||||
}
|
||||
renderer_->AddActor(WidgetAccessor::getActor(widget));
|
||||
(*widget_actor_map_)[id].actor = WidgetAccessor::getActor(widget);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ temp_viz::Viz3d::VizImpl::VizImpl (const std::string &name)
|
||||
: style_ (vtkSmartPointer<temp_viz::InteractorStyle>::New ())
|
||||
, cloud_actor_map_ (new CloudActorMap)
|
||||
, shape_actor_map_ (new ShapeActorMap)
|
||||
, widget_actor_map_ (new WidgetActorMap)
|
||||
, s_lastDone_(0.0)
|
||||
{
|
||||
renderer_ = vtkSmartPointer<vtkRenderer>::New ();
|
||||
|
||||
Reference in New Issue
Block a user