Commit 3d3e3fd4 authored by ozantonkal's avatar ozantonkal

plane widget implementation

parent ba89a6a3
...@@ -42,6 +42,13 @@ namespace temp_viz ...@@ -42,6 +42,13 @@ namespace temp_viz
void setLineWidth(float line_width); void setLineWidth(float line_width);
float getLineWidth(); float getLineWidth();
}; };
class CV_EXPORTS PlaneWidget : public Widget
{
public:
PlaneWidget(const Vec4f& coefs, const Color &color = Color::white());
PlaneWidget(const Vec4f& coefs, const Point3f& pt, const Color &color = Color::white());
};
} }
#include "precomp.hpp" #include "precomp.hpp"
///////////////////////////////////////////////////////////////////////////////////////////////
/// line widget implementation
temp_viz::LineWidget::LineWidget(const Point3f &pt1, const Point3f &pt2, const Color &color) temp_viz::LineWidget::LineWidget(const Point3f &pt1, const Point3f &pt2, const Color &color)
{ {
vtkSmartPointer<vtkLineSource> line = vtkSmartPointer<vtkLineSource>::New(); vtkSmartPointer<vtkLineSource> line = vtkSmartPointer<vtkLineSource>::New();
...@@ -27,4 +28,43 @@ float temp_viz::LineWidget::getLineWidth() ...@@ -27,4 +28,43 @@ float temp_viz::LineWidget::getLineWidth()
{ {
vtkSmartPointer<vtkLODActor> actor = WidgetAccessor::getActor(*this); vtkSmartPointer<vtkLODActor> actor = WidgetAccessor::getActor(*this);
return actor->GetProperty()->GetLineWidth(); return actor->GetProperty()->GetLineWidth();
}
///////////////////////////////////////////////////////////////////////////////////////////////
/// plane widget implementation
temp_viz::PlaneWidget::PlaneWidget(const Vec4f& coefs, const Color &color)
{
vtkSmartPointer<vtkPlaneSource> plane = vtkSmartPointer<vtkPlaneSource>::New ();
plane->SetNormal (coefs[0], coefs[1], coefs[2]);
double norm = cv::norm(cv::Vec3f(coefs.val));
plane->Push (-coefs[3] / norm);
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New ();
mapper->SetInput(plane->GetOutput ());
vtkSmartPointer<vtkLODActor> actor = WidgetAccessor::getActor(*this);
actor->SetMapper(mapper);
setColor(color);
}
temp_viz::PlaneWidget::PlaneWidget(const Vec4f& coefs, const Point3f& pt, const Color &color)
{
vtkSmartPointer<vtkPlaneSource> plane = vtkSmartPointer<vtkPlaneSource>::New ();
cv::Point3f coefs3(coefs[0], coefs[1], coefs[2]);
double norm_sqr = 1.0 / coefs3.dot (coefs3);
plane->SetNormal(coefs[0], coefs[1], coefs[2]);
double t = coefs3.dot(pt) + coefs[3];
cv::Vec3f p_center = pt - coefs3 * t * norm_sqr;
plane->SetCenter (p_center[0], p_center[1], p_center[2]);
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New ();
mapper->SetInput(plane->GetOutput ());
vtkSmartPointer<vtkLODActor> actor = WidgetAccessor::getActor(*this);
actor->SetMapper(mapper);
setColor(color);
} }
\ No newline at end of file
...@@ -95,7 +95,9 @@ TEST(Viz_viz3d, accuracy) ...@@ -95,7 +95,9 @@ TEST(Viz_viz3d, accuracy)
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)); 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));
temp_viz::PlaneWidget pw(cv::Vec4f(0.0,1.0,2.0,3.0));
v.showWidget("line", lw); v.showWidget("line", lw);
v.showWidget("plane", pw);
temp_viz::LineWidget lw2 = lw; temp_viz::LineWidget lw2 = lw;
...@@ -117,6 +119,8 @@ TEST(Viz_viz3d, accuracy) ...@@ -117,6 +119,8 @@ TEST(Viz_viz3d, accuracy)
lw2.setColor(temp_viz::Color(col_blue, col_green, col_red)); lw2.setColor(temp_viz::Color(col_blue, col_green, col_red));
lw.setLineWidth(lw.getLineWidth()+pos_x * 10); lw.setLineWidth(lw.getLineWidth()+pos_x * 10);
pw.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;
angle_z += 0.1f; angle_z += 0.1f;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment