typedef cv::Matx33d Matx33d;
typedef cv::Affine3f Affine3f;
typedef cv::Affine3d Affine3d;
+ typedef cv::Point2i Point2i;
typedef cv::Point3f Point3f;
typedef cv::Point3d Point3d;
typedef cv::Matx44d Matx44d;
//It is indended for those users who want to develop own widgets system using VTK library API.
struct CV_EXPORTS WidgetAccessor
{
- static vtkSmartPointer<vtkLODActor> getActor(const Widget &widget);
+ static vtkSmartPointer<vtkProp> getActor(const Widget &widget);
};
}
void setPose(const Affine3f &pose);
void updatePose(const Affine3f &pose);
Affine3f getPose() const;
-
+
+ protected:
+ Widget(bool text_widget);
+
private:
class Impl;
Impl* impl_;
void create();
void release();
+ void create(bool text_widget);
friend struct WidgetAccessor;
};
public:
CoordinateSystemWidget(double scale, const Affine3f& affine);
};
-
+
+ class CV_EXPORTS TextWidget : public Widget
+ {
+ public:
+ TextWidget(const String &text, const Point2i &pos, int font_size = 10, const Color &color = Color::white());
+
+ // TODO Overload setColor method, and hide setPose, updatePose, getPose methods
+ };
}
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New ();
mapper->SetInput(line->GetOutput ());
- vtkSmartPointer<vtkLODActor> actor = WidgetAccessor::getActor(*this);
+ vtkSmartPointer<vtkLODActor> actor = vtkLODActor::SafeDownCast(WidgetAccessor::getActor(*this));
actor->SetMapper(mapper);
setColor(color);
void temp_viz::LineWidget::setLineWidth(float line_width)
{
- vtkSmartPointer<vtkLODActor> actor = WidgetAccessor::getActor(*this);
+ vtkSmartPointer<vtkLODActor> actor = vtkLODActor::SafeDownCast(WidgetAccessor::getActor(*this));
actor->GetProperty()->SetLineWidth(line_width);
}
float temp_viz::LineWidget::getLineWidth()
{
- vtkSmartPointer<vtkLODActor> actor = WidgetAccessor::getActor(*this);
+ vtkSmartPointer<vtkLODActor> actor = vtkLODActor::SafeDownCast(WidgetAccessor::getActor(*this));
return actor->GetProperty()->GetLineWidth();
}
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New ();
mapper->SetInput(plane->GetOutput ());
- vtkSmartPointer<vtkLODActor> actor = WidgetAccessor::getActor(*this);
+ vtkSmartPointer<vtkLODActor> actor = vtkLODActor::SafeDownCast(WidgetAccessor::getActor(*this));
actor->SetMapper(mapper);
actor->SetScale(size);
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New ();
mapper->SetInput(plane->GetOutput ());
- vtkSmartPointer<vtkLODActor> actor = WidgetAccessor::getActor(*this);
+ vtkSmartPointer<vtkLODActor> actor = vtkLODActor::SafeDownCast(WidgetAccessor::getActor(*this));
actor->SetMapper(mapper);
actor->SetScale(size);
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New ();
mapper->SetInput(sphere->GetOutput ());
- vtkSmartPointer<vtkLODActor> actor = WidgetAccessor::getActor(*this);
+ vtkSmartPointer<vtkLODActor> actor = vtkLODActor::SafeDownCast(WidgetAccessor::getActor(*this));
actor->SetMapper(mapper);
setColor(color);
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New ();
mapper->SetInput(transformPD->GetOutput ());
- vtkSmartPointer<vtkLODActor> actor = WidgetAccessor::getActor(*this);
+ vtkSmartPointer<vtkLODActor> actor = vtkLODActor::SafeDownCast(WidgetAccessor::getActor(*this));
actor->SetMapper(mapper);
setColor(color);
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New ();
mapper->SetInput(tf->GetOutput ());
- vtkSmartPointer<vtkLODActor> actor = WidgetAccessor::getActor(*this);
+ vtkSmartPointer<vtkLODActor> actor = vtkLODActor::SafeDownCast(WidgetAccessor::getActor(*this));
actor->SetMapper(mapper);
setColor(color);
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New ();
mapper->SetInput(tuber->GetOutput ());
- vtkSmartPointer<vtkLODActor> actor = WidgetAccessor::getActor(*this);
+ vtkSmartPointer<vtkLODActor> actor = vtkLODActor::SafeDownCast(WidgetAccessor::getActor(*this));
actor->SetMapper(mapper);
setColor(color);
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New ();
mapper->SetInput(cube->GetOutput ());
- vtkSmartPointer<vtkLODActor> actor = WidgetAccessor::getActor(*this);
+ vtkSmartPointer<vtkLODActor> actor = vtkLODActor::SafeDownCast(WidgetAccessor::getActor(*this));
actor->SetMapper(mapper);
setColor(color);
mapper->SetScalarModeToUsePointData ();
mapper->SetInput(axes_tubes->GetOutput ());
- vtkSmartPointer<vtkLODActor> actor = WidgetAccessor::getActor(*this);
+ vtkSmartPointer<vtkLODActor> actor = vtkLODActor::SafeDownCast(WidgetAccessor::getActor(*this));
actor->SetMapper(mapper);
cv::Vec3d t = affine.translation();
actor->SetOrientation(0,0,0);
actor->RotateWXYZ(r_angle*180/CV_PI,rvec[0], rvec[1], rvec[2]);
}
+
+temp_viz::TextWidget::TextWidget(const String &text, const Point2i &pos, int font_size, const Color &color) : Widget(true)
+{
+ vtkSmartPointer<vtkTextActor> actor = vtkTextActor::SafeDownCast(WidgetAccessor::getActor(*this));
+ actor->SetPosition (pos.x, pos.y);
+ actor->SetInput (text.c_str ());
+
+ vtkSmartPointer<vtkTextProperty> tprop = actor->GetTextProperty ();
+ tprop->SetFontSize (font_size);
+ tprop->SetFontFamilyToArial ();
+ tprop->SetJustificationToLeft ();
+ tprop->BoldOn ();
+
+ Color c = vtkcolor(color);
+ tprop->SetColor (c.val);
+}
removeActorFromRenderer(wam_itr->second.actor);
}
// Get the actor and set the user matrix
- vtkSmartPointer<vtkLODActor> actor = vtkLODActor::SafeDownCast(WidgetAccessor::getActor(widget));
- vtkSmartPointer<vtkMatrix4x4> matrix = convertToVtkMatrix(pose.matrix);
- actor->SetUserMatrix (matrix);
- actor->Modified();
- renderer_->AddActor(actor);
- (*widget_actor_map_)[id].actor = actor;
+ vtkSmartPointer<vtkLODActor> actor;
+ if (actor = vtkLODActor::SafeDownCast(WidgetAccessor::getActor(widget)))
+ {
+ vtkSmartPointer<vtkMatrix4x4> matrix = convertToVtkMatrix(pose.matrix);
+ actor->SetUserMatrix (matrix);
+ actor->Modified();
+ }
+ renderer_->AddActor(WidgetAccessor::getActor(widget));
+ (*widget_actor_map_)[id].actor = WidgetAccessor::getActor(widget);
}
bool temp_viz::Viz3d::VizImpl::removeWidget(const String &id)
class temp_viz::Widget::Impl
{
public:
- vtkSmartPointer<vtkLODActor> actor;
+ vtkSmartPointer<vtkProp> actor;
int ref_counter;
Impl() : actor(vtkSmartPointer<vtkLODActor>::New()) {}
+
+ Impl(bool text_widget)
+ {
+ if (text_widget)
+ actor = vtkSmartPointer<vtkTextActor>::New();
+ else
+ actor = vtkSmartPointer<vtkLeaderActor2D>::New();
+ }
void setColor(const Color& color)
{
+ vtkSmartPointer<vtkLODActor> lod_actor = vtkLODActor::SafeDownCast(actor);
Color c = vtkcolor(color);
- actor->GetMapper ()->ScalarVisibilityOff ();
- actor->GetProperty ()->SetColor (c.val);
- actor->GetProperty ()->SetEdgeColor (c.val);
- actor->GetProperty ()->SetAmbient (0.8);
- actor->GetProperty ()->SetDiffuse (0.8);
- actor->GetProperty ()->SetSpecular (0.8);
- actor->GetProperty ()->SetLighting (0);
- actor->Modified ();
+ lod_actor->GetMapper ()->ScalarVisibilityOff ();
+ lod_actor->GetProperty ()->SetColor (c.val);
+ lod_actor->GetProperty ()->SetEdgeColor (c.val);
+ lod_actor->GetProperty ()->SetAmbient (0.8);
+ lod_actor->GetProperty ()->SetDiffuse (0.8);
+ lod_actor->GetProperty ()->SetSpecular (0.8);
+ lod_actor->GetProperty ()->SetLighting (0);
+ lod_actor->Modified ();
}
void setPose(const Affine3f& pose)
{
+ vtkSmartPointer<vtkLODActor> lod_actor = vtkLODActor::SafeDownCast(actor);
vtkSmartPointer<vtkMatrix4x4> matrix = convertToVtkMatrix(pose.matrix);
- actor->SetUserMatrix (matrix);
- actor->Modified ();
+ lod_actor->SetUserMatrix (matrix);
+ lod_actor->Modified ();
}
void updatePose(const Affine3f& pose)
{
- vtkSmartPointer<vtkMatrix4x4> matrix = actor->GetUserMatrix();
+ vtkSmartPointer<vtkLODActor> lod_actor = vtkLODActor::SafeDownCast(actor);
+ vtkSmartPointer<vtkMatrix4x4> matrix = lod_actor->GetUserMatrix();
if (!matrix)
{
setPose(pose);
Affine3f updated_pose = pose * Affine3f(matrix_cv);
matrix = convertToVtkMatrix(updated_pose.matrix);
- actor->SetUserMatrix (matrix);
- actor->Modified ();
+ lod_actor->SetUserMatrix (matrix);
+ lod_actor->Modified ();
}
Affine3f getPose() const
{
- vtkSmartPointer<vtkMatrix4x4> matrix = actor->GetUserMatrix();
+ vtkSmartPointer<vtkLODActor> lod_actor = vtkLODActor::SafeDownCast(actor);
+ vtkSmartPointer<vtkMatrix4x4> matrix = lod_actor->GetUserMatrix();
Matx44f matrix_cv = convertToMatx(matrix);
return Affine3f(matrix_cv);
}
///////////////////////////////////////////////////////////////////////////////////////////////
/// stream accessor implementaion
-vtkSmartPointer<vtkLODActor> temp_viz::WidgetAccessor::getActor(const Widget& widget)
+vtkSmartPointer<vtkProp> temp_viz::WidgetAccessor::getActor(const Widget& widget)
{
return widget.impl_->actor;
}
create();
}
+temp_viz::Widget::Widget(bool text_widget) : impl_(0)
+{
+ create(text_widget);
+}
+
temp_viz::Widget::Widget(const Widget& other) : impl_(other.impl_)
{
if (impl_)
}
}
+void temp_viz::Widget::create(bool text_widget)
+{
+ if (impl_)
+ release();
+ impl_ = new Impl(text_widget);
+ impl_->ref_counter = 1;
+}
+
temp_viz::CylinderWidget cyw(cv::Point3f(0,0,0), cv::Point3f(-1,-1,-1), 0.5, 30, temp_viz::Color(0,255,0));
temp_viz::CubeWidget cuw(cv::Point3f(-2,-2,-2), cv::Point3f(-1,-1,-1), temp_viz::Color(0,0,255));
temp_viz::CoordinateSystemWidget csw(1.0f, cv::Affine3f::Identity());
+ temp_viz::TextWidget tw("TEST", cv::Point2i(100,100), 20);
// v.showWidget("line", lw);
v.showWidget("plane", pw);
// v.showWidget("cylinder", cyw);
// v.showWidget("cube", cuw);
v.showWidget("coordinateSystem", csw);
+ v.showWidget("text",tw);
temp_viz::LineWidget lw2 = lw;