{
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);
+ };
}
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&);
#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);
};
}
\ No newline at end of file
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_;
/** \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_;
/** \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;
}
{
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);
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));
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)
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);
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);
+}
\ No newline at end of file
bool temp_viz::Viz3d::wasStopped() const { return impl_->wasStopped(); }
+void temp_viz::Viz3d::showWidget(const String &id, const Widget &widget)
+{
+ impl_->showWidget(id, widget);
+}
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);
+}
: 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 ();
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())
{
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;