refactored circle

pull/2173/head
Anatoly Baksheev 11 years ago
parent dac27c9913
commit c0cc551228
  1. 27
      modules/viz/doc/widget.rst
  2. 6
      modules/viz/include/opencv2/viz/widgets.hpp
  3. 6
      modules/viz/src/precomp.hpp
  4. 43
      modules/viz/src/shapes.cpp
  5. 4
      modules/viz/test/tests_simple.cpp

@ -349,23 +349,38 @@ viz::WCircle
This 3D Widget defines a circle. ::
class CV_EXPORTS WCircle : public Widget3D
class CV_EXPORTS WCircle : public Widget3D
{
public:
WCircle(const Point3f& pt, double radius, double thickness = 0.01, const Color &color = Color::white());
//! creates default planar circle centred at origin with plane normal along z-axis
WCircle(double radius, double thickness = 0.01, const Color &color = Color::white());
//! creates repositioned circle
WCircle(double radius, const Point3d& center, const Vec3d& normal, double thickness = 0.01, const Color &color = Color::white());
};
viz::WCircle::WCircle
-------------------------------
Constructs a WCircle.
Constructs default planar circle centred at origin with plane normal along z-axis
.. ocv:function:: WCircle(const Point3f& pt, double radius, double thickness = 0.01, const Color &color = Color::white())
.. ocv:function:: WCircle(double radius, double thickness = 0.01, const Color &color = Color::white());
:param pt: Center of the circle.
:param radius: Radius of the circle.
:param radius: Radius of the circle.
:param thickness: Thickness of the circle.
:param color: :ocv:class:`Color` of the circle.
viz::WCircle::WCircle
-------------------------------
Constructs repositioned planar circle.
.. ocv:function:: WCircle(double radius, const Point3d& center, const Vec3d& normal, double thickness = 0.01, const Color &color = Color::white());
:param radius: Radius of the circle.
:param center: Center of the circle.
:param normal: Normal of the plane in which the circle lies.
:param thickness: Thickness of the circle.
:param color: :ocv:class:`Color` of the circle.
viz::WCylinder
--------------
.. ocv:class:: WCylinder

@ -164,7 +164,11 @@ namespace cv
class CV_EXPORTS WCircle : public Widget3D
{
public:
WCircle(const Point3d& pt, double radius, double thickness = 0.01, const Color &color = Color::white());
//! creates default circle centred at origin with normal along z-axis
WCircle(double radius, double thickness = 0.01, const Color &color = Color::white());
//! creates repositioned circle
WCircle(double radius, const Point3d& center, const Vec3d& normal, double thickness = 0.01, const Color &color = Color::white());
};
class CV_EXPORTS WCylinder : public Widget3D

@ -209,6 +209,12 @@ namespace cv
return scaled_color;
}
inline Vec3d get_random_vec(double from = -10.0, double to = 10.0)
{
RNG& rng = theRNG();
return Vec3d(rng.uniform(from, to), rng.uniform(from, to), rng.uniform(from, to));
}
struct VtkUtils
{
template<class Filter>

@ -182,18 +182,17 @@ cv::viz::WArrow::WArrow(const Point3d& pt1, const Point3d& pt2, double thickness
arrow_source->SetTipRadius(thickness * 3.0);
arrow_source->SetTipLength(thickness * 10.0);
RNG rng = theRNG();
Vec3d arbitrary(rng.uniform(-10.0, 10.0), rng.uniform(-10.0, 10.0), rng.uniform(-10.0, 10.0));
Vec3d startPoint(pt1.x, pt1.y, pt1.z), endPoint(pt2.x, pt2.y, pt2.z);
Vec3d arbitrary = get_random_vec();
Vec3d start_point(pt1.x, pt1.y, pt1.z), end_point(pt2.x, pt2.y, pt2.z);
double length = norm(endPoint - startPoint);
double length = norm(end_point - start_point);
Vec3d xvec = normalized(endPoint - startPoint);
Vec3d xvec = normalized(end_point - start_point);
Vec3d zvec = normalized(xvec.cross(arbitrary));
Vec3d yvec = zvec.cross(xvec);
Matx33d R = makeTransformToGlobal(xvec, yvec, zvec).rotation();
Affine3d transform_with_scale(R * length, startPoint);
Affine3d transform_with_scale(R * length, start_point);
vtkSmartPointer<vtkPolyData> polydata = VtkUtils::TransformPolydata(arrow_source->GetOutputPort(), transform_with_scale);
@ -216,32 +215,36 @@ template<> cv::viz::WArrow cv::viz::Widget::cast<cv::viz::WArrow>()
///////////////////////////////////////////////////////////////////////////////////////////////
/// circle widget implementation
cv::viz::WCircle::WCircle(const Point3d& pt, double radius, double thickness, const Color& color)
cv::viz::WCircle::WCircle(double radius, double thickness, const Color &color)
{
vtkSmartPointer<vtkDiskSource> disk = vtkSmartPointer<vtkDiskSource>::New();
// Maybe the resolution should be lower e.g. 50 or 25
disk->SetCircumferentialResolution(50);
disk->SetCircumferentialResolution(30);
disk->SetInnerRadius(radius - thickness);
disk->SetOuterRadius(radius + thickness);
// Set the circle origin
vtkSmartPointer<vtkTransform> t = vtkSmartPointer<vtkTransform>::New();
t->Identity();
t->Translate(pt.x, pt.y, pt.z);
vtkSmartPointer<vtkTransformPolyDataFilter> tf = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
tf->SetTransform(t);
tf->SetInputConnection(disk->GetOutputPort());
tf->Update();
disk->Update();
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
VtkUtils::SetInputData(mapper, tf->GetOutput());
VtkUtils::SetInputData(mapper, disk->GetOutput());
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->GetProperty()->LightingOff();
actor->SetMapper(mapper);
WidgetAccessor::setProp(*this, actor);
setColor(color);
}
cv::viz::WCircle::WCircle(double radius, const Point3d& center, const Vec3d& normal, double thickness, const Color &color)
{
Vec3d arbitrary = get_random_vec();
Vec3d zvec = normalized(normal);
Vec3d xvec = normalized(zvec.cross(arbitrary));
Vec3d yvec = zvec.cross(xvec);
WCircle circle(radius, thickness, color);
circle.applyTransform(makeTransformToGlobal(xvec, yvec, zvec, center));
*this = circle;
}
template<> cv::viz::WCircle cv::viz::Widget::cast<cv::viz::WCircle>()

@ -293,7 +293,9 @@ TEST(Viz, show_simple_widgets)
Viz3d viz("show_simple_widgets");
viz.showWidget("coos", WCoordinateSystem());
viz.showWidget("cube", WCube());
viz.showWidget("arr3", WArrow(Vec3d::all(-0.5), Vec3d::all(0.5), 0.009, Color::raspberry()));
viz.showWidget("arro", WArrow(Vec3d::all(-0.5), Vec3d::all(0.5), 0.009, Color::raspberry()));
viz.showWidget("cir1", WCircle(0.5, 0.01, Color::bluberry()));
viz.showWidget("cir2", WCircle(0.5, Point3d(0.5, 0.0, 0.0), Vec3d(1.0, 0.0, 0.0), 0.01, Color::apricot()));
viz.spin();
}

Loading…
Cancel
Save