From d3dee3a2fe541bd0424f08cd2aa62e454ef82333 Mon Sep 17 00:00:00 2001 From: ozantonkal Date: Wed, 10 Jul 2013 09:55:42 +0200 Subject: [PATCH] explicit casting among widgets, removed implicit casting --- modules/viz/include/opencv2/viz/widgets.hpp | 35 ++++++----------- modules/viz/src/simple_widgets.cpp | 60 ++++++++++++++--------------- modules/viz/src/widget.cpp | 43 +++++---------------- 3 files changed, 51 insertions(+), 87 deletions(-) diff --git a/modules/viz/include/opencv2/viz/widgets.hpp b/modules/viz/include/opencv2/viz/widgets.hpp index c61b5a7..cf265ac 100644 --- a/modules/viz/include/opencv2/viz/widgets.hpp +++ b/modules/viz/include/opencv2/viz/widgets.hpp @@ -32,8 +32,6 @@ namespace temp_viz { public: Widget3D() {} - Widget3D(const Widget& other); - Widget3D& operator =(const Widget &other); void setPose(const Affine3f &pose); void updatePose(const Affine3f &pose); @@ -52,8 +50,6 @@ namespace temp_viz { public: Widget2D() {} - Widget2D(const Widget &other); - Widget2D& operator=(const Widget &other); void setColor(const Color &color); }; @@ -72,64 +68,48 @@ namespace temp_viz public: PlaneWidget(const Vec4f& coefs, double size = 1.0, const Color &color = Color::white()); PlaneWidget(const Vec4f& coefs, const Point3f& pt, double size = 1.0, const Color &color = Color::white()); - PlaneWidget(const Widget& other) : Widget3D(other) {} - PlaneWidget& operator=(const Widget& other); }; class CV_EXPORTS SphereWidget : public Widget3D { public: SphereWidget(const cv::Point3f ¢er, float radius, int sphere_resolution = 10, const Color &color = Color::white()); - SphereWidget(const Widget &other) : Widget3D(other) {} - SphereWidget& operator=(const Widget &other); }; class CV_EXPORTS ArrowWidget : public Widget3D { public: ArrowWidget(const Point3f& pt1, const Point3f& pt2, const Color &color = Color::white()); - ArrowWidget(const Widget &other) : Widget3D(other) {} - ArrowWidget& operator=(const Widget &other); }; class CV_EXPORTS CircleWidget : public Widget3D { public: CircleWidget(const Point3f& pt, double radius, double thickness = 0.01, const Color &color = Color::white()); - CircleWidget(const Widget& other) : Widget3D(other) {} - CircleWidget& operator=(const Widget &other); }; class CV_EXPORTS CylinderWidget : public Widget3D { public: CylinderWidget(const Point3f& pt_on_axis, const Point3f& axis_direction, double radius, int numsides = 30, const Color &color = Color::white()); - CylinderWidget(const Widget& other) : Widget3D(other) {} - CylinderWidget& operator=(const Widget &other); }; class CV_EXPORTS CubeWidget : public Widget3D { public: CubeWidget(const Point3f& pt_min, const Point3f& pt_max, bool wire_frame = true, const Color &color = Color::white()); - CubeWidget(const Widget& other) : Widget3D(other) {} - CubeWidget& operator=(const Widget &other); }; class CV_EXPORTS CoordinateSystemWidget : public Widget3D { public: CoordinateSystemWidget(double scale, const Affine3f& affine); - CoordinateSystemWidget(const Widget &other) : Widget3D(other) {} - CoordinateSystemWidget& operator=(const Widget &other); }; class CV_EXPORTS TextWidget : public Widget2D { public: TextWidget(const String &text, const Point2i &pos, int font_size = 10, const Color &color = Color::white()); - TextWidget(const Widget& other) : Widget2D(other) {} - TextWidget& operator=(const Widget &other); void setText(const String &text); String getText() const; @@ -140,8 +120,6 @@ namespace temp_viz public: CloudWidget(InputArray _cloud, InputArray _colors); CloudWidget(InputArray _cloud, const Color &color = Color::white()); - CloudWidget(const Widget &other) : Widget3D(other) {} - CloudWidget& operator=(const Widget &other); private: struct CreateCloudWidget; @@ -151,15 +129,24 @@ namespace temp_viz { public: CloudNormalsWidget(InputArray _cloud, InputArray _normals, int level = 100, float scale = 0.02f, const Color &color = Color::white()); - CloudNormalsWidget(const Widget &other) : Widget3D(other) {} - CloudNormalsWidget& operator=(const Widget &other); private: struct ApplyCloudNormals; }; + template<> CV_EXPORTS Widget2D Widget::cast(); template<> CV_EXPORTS Widget3D Widget::cast(); template<> CV_EXPORTS LineWidget Widget::cast(); + template<> CV_EXPORTS PlaneWidget Widget::cast(); + template<> CV_EXPORTS SphereWidget Widget::cast(); + template<> CV_EXPORTS CylinderWidget Widget::cast(); + template<> CV_EXPORTS ArrowWidget Widget::cast(); + template<> CV_EXPORTS CircleWidget Widget::cast(); + template<> CV_EXPORTS CubeWidget Widget::cast(); + template<> CV_EXPORTS CoordinateSystemWidget Widget::cast(); + template<> CV_EXPORTS TextWidget Widget::cast(); + template<> CV_EXPORTS CloudWidget Widget::cast(); + template<> CV_EXPORTS CloudNormalsWidget Widget::cast(); } diff --git a/modules/viz/src/simple_widgets.cpp b/modules/viz/src/simple_widgets.cpp index 1d5b0a9..db27884 100644 --- a/modules/viz/src/simple_widgets.cpp +++ b/modules/viz/src/simple_widgets.cpp @@ -87,10 +87,10 @@ temp_viz::PlaneWidget::PlaneWidget(const Vec4f& coefs, const Point3f& pt, double setColor(color); } -temp_viz::PlaneWidget& temp_viz::PlaneWidget::operator=(const Widget& other) +template<> temp_viz::PlaneWidget temp_viz::Widget::cast() { - Widget3D::operator=(other); - return *this; + Widget3D widget = this->cast(); + return static_cast(widget); } /////////////////////////////////////////////////////////////////////////////////////////////// @@ -116,10 +116,10 @@ temp_viz::SphereWidget::SphereWidget(const cv::Point3f ¢er, float radius, in setColor(color); } -temp_viz::SphereWidget& temp_viz::SphereWidget::operator=(const Widget &other) +template<> temp_viz::SphereWidget temp_viz::Widget::cast() { - Widget3D::operator=(other); - return *this; + Widget3D widget = this->cast(); + return static_cast(widget); } /////////////////////////////////////////////////////////////////////////////////////////////// @@ -185,10 +185,10 @@ temp_viz::ArrowWidget::ArrowWidget(const Point3f& pt1, const Point3f& pt2, const setColor(color); } -temp_viz::ArrowWidget& temp_viz::ArrowWidget::operator=(const Widget &other) +template<> temp_viz::ArrowWidget temp_viz::Widget::cast() { - Widget3D::operator=(other); - return *this; + Widget3D widget = this->cast(); + return static_cast(widget); } /////////////////////////////////////////////////////////////////////////////////////////////// @@ -221,10 +221,10 @@ temp_viz::CircleWidget::CircleWidget(const temp_viz::Point3f& pt, double radius, setColor(color); } -temp_viz::CircleWidget& temp_viz::CircleWidget::operator=(const Widget &other) +template<> temp_viz::CircleWidget temp_viz::Widget::cast() { - Widget3D::operator=(other); - return *this; + Widget3D widget = this->cast(); + return static_cast(widget); } /////////////////////////////////////////////////////////////////////////////////////////////// @@ -252,10 +252,10 @@ temp_viz::CylinderWidget::CylinderWidget(const Point3f& pt_on_axis, const Point3 setColor(color); } -temp_viz::CylinderWidget& temp_viz::CylinderWidget::operator=(const Widget &other) +template<> temp_viz::CylinderWidget temp_viz::Widget::cast() { - Widget3D::operator=(other); - return *this; + Widget3D widget = this->cast(); + return static_cast(widget); } /////////////////////////////////////////////////////////////////////////////////////////////// @@ -279,10 +279,10 @@ temp_viz::CubeWidget::CubeWidget(const Point3f& pt_min, const Point3f& pt_max, b setColor(color); } -temp_viz::CubeWidget& temp_viz::CubeWidget::operator=(const Widget &other) +template<> temp_viz::CubeWidget temp_viz::Widget::cast() { - Widget3D::operator=(other); - return *this; + Widget3D widget = this->cast(); + return static_cast(widget); } /////////////////////////////////////////////////////////////////////////////////////////////// @@ -336,10 +336,10 @@ temp_viz::CoordinateSystemWidget::CoordinateSystemWidget(double scale, const Aff WidgetAccessor::setProp(*this, actor); } -temp_viz::CoordinateSystemWidget& temp_viz::CoordinateSystemWidget::operator=(const Widget &other) +template<> temp_viz::CoordinateSystemWidget temp_viz::Widget::cast() { - Widget3D::operator=(other); - return *this; + Widget3D widget = this->cast(); + return static_cast(widget); } /////////////////////////////////////////////////////////////////////////////////////////////// @@ -363,10 +363,10 @@ temp_viz::TextWidget::TextWidget(const String &text, const Point2i &pos, int fon WidgetAccessor::setProp(*this, actor); } -temp_viz::TextWidget& temp_viz::TextWidget::operator=(const Widget &other) +template<> temp_viz::TextWidget temp_viz::Widget::cast() { - Widget2D::operator=(other); - return *this; + Widget2D widget = this->cast(); + return static_cast(widget); } void temp_viz::TextWidget::setText(const String &text) @@ -548,10 +548,10 @@ temp_viz::CloudWidget::CloudWidget(InputArray _cloud, const Color &color) setColor(color); } -temp_viz::CloudWidget& temp_viz::CloudWidget::operator=(const Widget &other) +template<> temp_viz::CloudWidget temp_viz::Widget::cast() { - Widget3D::operator=(other); - return *this; + Widget3D widget = this->cast(); + return static_cast(widget); } /////////////////////////////////////////////////////////////////////////////////////////////// @@ -686,8 +686,8 @@ temp_viz::CloudNormalsWidget::CloudNormalsWidget(InputArray _cloud, InputArray _ setColor(color); } -temp_viz::CloudNormalsWidget& temp_viz::CloudNormalsWidget::operator=(const Widget &other) +template<> temp_viz::CloudNormalsWidget temp_viz::Widget::cast() { - Widget3D::operator=(other); - return *this; + Widget3D widget = this->cast(); + return static_cast(widget); } diff --git a/modules/viz/src/widget.cpp b/modules/viz/src/widget.cpp index cb415ce..7978d7a 100644 --- a/modules/viz/src/widget.cpp +++ b/modules/viz/src/widget.cpp @@ -91,23 +91,6 @@ struct temp_viz::Widget3D::MatrixConverter } }; -temp_viz::Widget3D::Widget3D(const Widget& other) : Widget(other) -{ - // Check if other's actor is castable to vtkProp3D - vtkProp3D *actor = vtkProp3D::SafeDownCast(WidgetAccessor::getProp(other)); - CV_Assert(actor); -} - -temp_viz::Widget3D& temp_viz::Widget3D::operator =(const Widget &other) -{ - // Check if other's actor is castable to vtkProp3D - vtkProp3D *actor = vtkProp3D::SafeDownCast(WidgetAccessor::getProp(other)); - CV_Assert(actor); - - Widget::operator=(other); - return *this; -} - void temp_viz::Widget3D::setPose(const Affine3f &pose) { vtkProp3D *actor = vtkProp3D::SafeDownCast(WidgetAccessor::getProp(*this)); @@ -178,22 +161,6 @@ template<> temp_viz::Widget3D temp_viz::Widget::cast() /////////////////////////////////////////////////////////////////////////////////////////////// /// widget2D implementation -temp_viz::Widget2D::Widget2D(const Widget &other) : Widget(other) -{ - // Check if other's actor is castable to vtkActor2D - vtkActor2D *actor = vtkActor2D::SafeDownCast(WidgetAccessor::getProp(other)); - CV_Assert(actor); -} - -temp_viz::Widget2D& temp_viz::Widget2D::operator=(const Widget &other) -{ - // Check if other's actor is castable to vtkActor2D - vtkActor2D *actor = vtkActor2D::SafeDownCast(WidgetAccessor::getProp(other)); - CV_Assert(actor); - Widget::operator=(other); - return *this; -} - void temp_viz::Widget2D::setColor(const Color &color) { vtkActor2D *actor = vtkActor2D::SafeDownCast(WidgetAccessor::getProp(*this)); @@ -202,3 +169,13 @@ void temp_viz::Widget2D::setColor(const Color &color) actor->GetProperty ()->SetColor (c.val); actor->Modified (); } + +template<> temp_viz::Widget2D temp_viz::Widget::cast() +{ + vtkActor2D *actor = vtkActor2D::SafeDownCast(WidgetAccessor::getProp(*this)); + CV_Assert(actor); + + Widget2D widget; + WidgetAccessor::setProp(widget, actor); + return widget; +} -- 2.7.4