fix vtkActor to vtkLODActor, initial implementation LineWidget, showWidget

pull/1453/head
ozantonkal 12 years ago
parent 54c7dfab83
commit c8d2b5ff44
  1. 9
      modules/viz/include/opencv2/viz/types.hpp
  2. 2
      modules/viz/include/opencv2/viz/viz3d.hpp
  3. 5
      modules/viz/include/opencv2/viz/widget_accessor.hpp
  4. 6
      modules/viz/src/q/viz3d_impl.hpp
  5. 9
      modules/viz/src/q/viz_types.h
  6. 55
      modules/viz/src/types.cpp
  7. 4
      modules/viz/src/viz3d.cpp
  8. 15
      modules/viz/src/viz3d_impl.cpp
  9. 1
      modules/viz/src/viz_main.cpp
  10. 3
      modules/viz/test/test_viz3d.cpp

@ -118,17 +118,22 @@ namespace temp_viz
{ {
public: public:
Widget(); Widget();
Widget(const String &id);
Widget(const Widget &other); Widget(const Widget &other);
void setId(const String &id);
void setColor(const Color &color); void setColor(const Color &color);
void setPose(const Affine3f &pose); void setPose(const Affine3f &pose);
void updatePose(const Affine3f &pose); void updatePose(const Affine3f &pose);
Affine3f getPose() const; Affine3f getPose() const;
private: private:
class Impl; class Impl;
cv::Ptr<Impl> impl_; cv::Ptr<Impl> impl_;
friend struct WidgetAccessor; 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); void registerMouseCallback(void (*callback)(const MouseEvent&, void*), void* cookie = 0);
bool wasStopped() const; bool wasStopped() const;
void showWidget(const String &id, const Widget &widget);
private: private:
Viz3d(const Viz3d&); Viz3d(const Viz3d&);
Viz3d& operator=(const Viz3d&); Viz3d& operator=(const Viz3d&);

@ -1,12 +1,11 @@
#pragma once #pragma once
#include "precomp.hpp" #include <opencv2/viz/types.hpp>
#include "types.hpp"
namespace temp_viz namespace temp_viz
{ {
struct WidgetAccessor 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 setPosition (int x, int y);
void setSize (int xw, int yw); void setSize (int xw, int yw);
void showWidget(const String &id, const Widget &widget);
void all_data();
private: private:
vtkSmartPointer<vtkRenderWindowInteractor> interactor_; vtkSmartPointer<vtkRenderWindowInteractor> interactor_;
@ -311,6 +314,9 @@ private:
/** \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 */
cv::Ptr<WidgetActorMap> widget_actor_map_;
/** \brief Boolean that holds whether or not the camera parameters were manually initialized*/ /** \brief Boolean that holds whether or not the camera parameters were manually initialized*/
bool camera_set_; bool camera_set_;

@ -15,8 +15,17 @@ namespace temp_viz
/** \brief Internal cell array. Used for optimizing updatePointCloud. */ /** \brief Internal cell array. Used for optimizing updatePointCloud. */
vtkSmartPointer<vtkIdTypeArray> cells; 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, CloudActor> CloudActorMap;
typedef std::map<std::string, vtkSmartPointer<vtkProp> > ShapeActorMap; 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: public:
String id; String id;
vtkSmartPointer<vtkActor> actor; vtkSmartPointer<vtkLODActor> actor;
Impl() Impl()
{ {
actor = vtkSmartPointer<vtkActor>:: New(); actor = vtkSmartPointer<vtkLODActor>::New ();
} }
vtkSmartPointer<vtkActor> getActor() vtkSmartPointer<vtkLODActor> getActor()
{ {
return actor; return actor;
} }
void setId(const String &id)
{
this->id = id;
}
const temp_viz::String & getString() const
{
return id;
}
void setColor(const Color & color) void setColor(const Color & color)
{ {
Color c = vtkcolor(color); Color c = vtkcolor(color);
@ -85,11 +75,22 @@ public:
return Affine3f(matrix_cv); 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: protected:
vtkSmartPointer<vtkMatrix4x4> convertToVtkMatrix (const cv::Matx44f &m) const 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 i = 0; i < 4; i++)
for (int k = 0; k < 4; k++) for (int k = 0; k < 4; k++)
vtk_matrix->SetElement(i, k, m(i, k)); vtk_matrix->SetElement(i, k, m(i, k));
@ -101,20 +102,12 @@ protected:
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
for (int k = 0; k < 4; k++) for (int k = 0; k < 4; k++)
m(i,k) = vtk_matrix->GetElement (i, k); m(i,k) = vtk_matrix->GetElement (i, k);
} }
}; };
temp_viz::Widget::Widget() temp_viz::Widget::Widget()
{ {
impl_ = new Impl(); 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) temp_viz::Widget::Widget(const Widget &other)
@ -122,11 +115,6 @@ temp_viz::Widget::Widget(const Widget &other)
impl_ = other.impl_; impl_ = other.impl_;
} }
void temp_viz::Widget::setId(const String &id)
{
impl_->setId(id);
}
void temp_viz::Widget::setColor(const Color &color) void temp_viz::Widget::setColor(const Color &color)
{ {
impl_->setColor(color); impl_->setColor(color);
@ -147,11 +135,18 @@ temp_viz::Affine3f temp_viz::Widget::getPose() const
return impl_->getPose(); return impl_->getPose();
} }
// TODO Check if HAVE_VTK
#include "opencv2/viz/widget_accessor.hpp" #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; 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(); } 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); 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 ()) : style_ (vtkSmartPointer<temp_viz::InteractorStyle>::New ())
, cloud_actor_map_ (new CloudActorMap) , cloud_actor_map_ (new CloudActorMap)
, shape_actor_map_ (new ShapeActorMap) , shape_actor_map_ (new ShapeActorMap)
, widget_actor_map_ (new WidgetActorMap)
, s_lastDone_(0.0) , s_lastDone_(0.0)
{ {
renderer_ = vtkSmartPointer<vtkRenderer>::New (); 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.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.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)); 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()) while(!v.wasStopped())
{ {
@ -110,6 +112,7 @@ TEST(Viz_viz3d, accuracy)
v.setShapePose("circle1", cloudPosition); v.setShapePose("circle1", cloudPosition);
v.setShapePose("sphere1", cloudPosition); v.setShapePose("sphere1", cloudPosition);
v.setShapePose("arrow1", cloudPosition); v.setShapePose("arrow1", cloudPosition);
lw.setColor(temp_viz::Color(col_blue, col_green, col_red));
angle_x += 0.1f; angle_x += 0.1f;
angle_y -= 0.1f; angle_y -= 0.1f;

Loading…
Cancel
Save