fix vtkActor to vtkLODActor, initial implementation LineWidget, showWidget
This commit is contained in:
parent
54c7dfab83
commit
c8d2b5ff44
@ -118,17 +118,22 @@ namespace temp_viz
|
||||
{
|
||||
public:
|
||||
Widget();
|
||||
Widget(const String &id);
|
||||
Widget(const Widget &other);
|
||||
|
||||
void setId(const String &id);
|
||||
void setColor(const Color &color);
|
||||
void setPose(const Affine3f &pose);
|
||||
void updatePose(const Affine3f &pose);
|
||||
Affine3f getPose() const;
|
||||
|
||||
private:
|
||||
class Impl;
|
||||
cv::Ptr<Impl> impl_;
|
||||
friend struct WidgetAccessor;
|
||||
};
|
||||
|
||||
class LineWidget : public Widget
|
||||
{
|
||||
public:
|
||||
LineWidget(const Point3f &pt1, const Point3f &pt2, const Color &color);
|
||||
};
|
||||
}
|
||||
|
@ -69,6 +69,8 @@ namespace temp_viz
|
||||
void registerMouseCallback(void (*callback)(const MouseEvent&, void*), void* cookie = 0);
|
||||
|
||||
bool wasStopped() const;
|
||||
|
||||
void showWidget(const String &id, const Widget &widget);
|
||||
private:
|
||||
Viz3d(const Viz3d&);
|
||||
Viz3d& operator=(const Viz3d&);
|
||||
|
@ -1,12 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "precomp.hpp"
|
||||
#include "types.hpp"
|
||||
#include <opencv2/viz/types.hpp>
|
||||
|
||||
namespace temp_viz
|
||||
{
|
||||
struct WidgetAccessor
|
||||
{
|
||||
static CV_EXPORTS vtkSmartPointer<vtkActor> getActor(const Widget &widget);
|
||||
static CV_EXPORTS vtkSmartPointer<vtkLODActor> getActor(const Widget &widget);
|
||||
};
|
||||
}
|
@ -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 ();
|
||||
|
@ -94,6 +94,8 @@ TEST(Viz_viz3d, accuracy)
|
||||
v.showCircle("circle1", cv::Point3f(0,0,0), 1.0, temp_viz::Color(0,255,0));
|
||||
v.showSphere("sphere1", cv::Point3f(0,0,0), 0.5, temp_viz::Color(0,0,255));
|
||||
v.showArrow("arrow1", cv::Point3f(0,0,0), cv::Point3f(1,1,1), temp_viz::Color(255,0,0));
|
||||
temp_viz::LineWidget lw(cv::Point3f(0.0,0.0,0.0), cv::Point3f(1.0,1.0,1.0), temp_viz::Color(0,255,0));
|
||||
v.showWidget("line", lw);
|
||||
|
||||
while(!v.wasStopped())
|
||||
{
|
||||
@ -110,6 +112,7 @@ TEST(Viz_viz3d, accuracy)
|
||||
v.setShapePose("circle1", cloudPosition);
|
||||
v.setShapePose("sphere1", cloudPosition);
|
||||
v.setShapePose("arrow1", cloudPosition);
|
||||
lw.setColor(temp_viz::Color(col_blue, col_green, col_red));
|
||||
|
||||
angle_x += 0.1f;
|
||||
angle_y -= 0.1f;
|
||||
|
Loading…
x
Reference in New Issue
Block a user