sphere widget implementation

pull/1453/head
ozantonkal 12 years ago
parent 3d3e3fd470
commit d80a965f97
  1. 6
      modules/viz/include/opencv2/viz/widgets.hpp
  2. 22
      modules/viz/src/simple_widgets.cpp
  3. 8
      modules/viz/test/test_viz3d.cpp

@ -49,6 +49,12 @@ namespace temp_viz
PlaneWidget(const Vec4f& coefs, const Color &color = Color::white()); PlaneWidget(const Vec4f& coefs, const Color &color = Color::white());
PlaneWidget(const Vec4f& coefs, const Point3f& pt, const Color &color = Color::white()); PlaneWidget(const Vec4f& coefs, const Point3f& pt, const Color &color = Color::white());
}; };
class CV_EXPORTS SphereWidget : public Widget
{
public:
SphereWidget(const cv::Point3f &center, float radius, int sphere_resolution = 10, const Color &color = Color::white());
};
} }

@ -66,5 +66,27 @@ temp_viz::PlaneWidget::PlaneWidget(const Vec4f& coefs, const Point3f& pt, const
vtkSmartPointer<vtkLODActor> actor = WidgetAccessor::getActor(*this); vtkSmartPointer<vtkLODActor> actor = WidgetAccessor::getActor(*this);
actor->SetMapper(mapper); actor->SetMapper(mapper);
setColor(color);
}
///////////////////////////////////////////////////////////////////////////////////////////////
/// sphere widget implementation
temp_viz::SphereWidget::SphereWidget(const cv::Point3f &center, float radius, int sphere_resolution, const Color &color)
{
vtkSmartPointer<vtkSphereSource> sphere = vtkSmartPointer<vtkSphereSource>::New ();
sphere->SetRadius (radius);
sphere->SetCenter (center.x, center.y, center.z);
sphere->SetPhiResolution (sphere_resolution);
sphere->SetThetaResolution (sphere_resolution);
sphere->LatLongTessellationOff ();
sphere->Update ();
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New ();
mapper->SetInput(sphere->GetOutput ());
vtkSmartPointer<vtkLODActor> actor = WidgetAccessor::getActor(*this);
actor->SetMapper(mapper);
setColor(color); setColor(color);
} }

@ -92,12 +92,14 @@ TEST(Viz_viz3d, accuracy)
int col_green = 0; int col_green = 0;
int col_red = 0; int col_red = 0;
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.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)); temp_viz::PlaneWidget pw(cv::Vec4f(0.0,1.0,2.0,3.0));
temp_viz::SphereWidget sw(cv::Point3f(0,0,0), 0.5);
v.showWidget("line", lw); v.showWidget("line", lw);
v.showWidget("plane", pw); v.showWidget("plane", pw);
v.showWidget("sphere", sw);
temp_viz::LineWidget lw2 = lw; temp_viz::LineWidget lw2 = lw;
@ -114,13 +116,15 @@ TEST(Viz_viz3d, accuracy)
// v.showCube("cube1", cv::Point3f(pos_x, pos_y, pos_z), cv::Point3f(pos_x+0.5, pos_y+0.5, pos_z+0.5), temp_viz::Color(255,150,50)); // v.showCube("cube1", cv::Point3f(pos_x, pos_y, pos_z), cv::Point3f(pos_x+0.5, pos_y+0.5, pos_z+0.5), temp_viz::Color(255,150,50));
// v.showCylinder("cylinder1", cv::Point3f(0,0,0), cv::Point3f(pos_x, 1.0, 1.0), 0.5, 5*pos_x+3, temp_viz::Color(0,255,0)); // v.showCylinder("cylinder1", cv::Point3f(0,0,0), cv::Point3f(pos_x, 1.0, 1.0), 0.5, 5*pos_x+3, temp_viz::Color(0,255,0));
v.setShapePose("circle1", cloudPosition); v.setShapePose("circle1", cloudPosition);
v.setShapePose("sphere1", cloudPosition);
v.setShapePose("arrow1", cloudPosition); v.setShapePose("arrow1", cloudPosition);
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)); pw.setColor(temp_viz::Color(col_blue, col_green, col_red));
sw.setPose(cloudPosition);
pw.setPose(cloudPosition);
angle_x += 0.1f; angle_x += 0.1f;
angle_y -= 0.1f; angle_y -= 0.1f;
angle_z += 0.1f; angle_z += 0.1f;

Loading…
Cancel
Save