From e4c3416f5885d44ae69e2e022279ffbc96c636ae Mon Sep 17 00:00:00 2001 From: Anatoly Baksheev Date: Tue, 9 Jul 2013 20:02:43 +0400 Subject: [PATCH] experimental widget casting functionality --- modules/viz/include/opencv2/viz/widgets.hpp | 13 +++++++++---- modules/viz/src/simple_widgets.cpp | 14 +++++++------- modules/viz/src/widget.cpp | 10 ++++++++++ 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/modules/viz/include/opencv2/viz/widgets.hpp b/modules/viz/include/opencv2/viz/widgets.hpp index 2114838..c61b5a7 100644 --- a/modules/viz/include/opencv2/viz/widgets.hpp +++ b/modules/viz/include/opencv2/viz/widgets.hpp @@ -15,6 +15,8 @@ namespace temp_viz Widget& operator =(const Widget &other); ~Widget(); + + template _W cast(); private: class Impl; Impl *impl_; @@ -56,18 +58,15 @@ namespace temp_viz void setColor(const Color &color); }; - class CV_EXPORTS LineWidget : public Widget3D { public: LineWidget(const Point3f &pt1, const Point3f &pt2, const Color &color = Color::white()); - LineWidget(const Widget &other) : Widget3D(other) {} - LineWidget& operator=(const Widget &other); void setLineWidth(float line_width); float getLineWidth(); }; - + class CV_EXPORTS PlaneWidget : public Widget3D { public: @@ -158,4 +157,10 @@ namespace temp_viz private: struct ApplyCloudNormals; }; + + template<> CV_EXPORTS Widget3D Widget::cast(); + template<> CV_EXPORTS LineWidget Widget::cast(); } + + + diff --git a/modules/viz/src/simple_widgets.cpp b/modules/viz/src/simple_widgets.cpp index d1fab75..1d5b0a9 100644 --- a/modules/viz/src/simple_widgets.cpp +++ b/modules/viz/src/simple_widgets.cpp @@ -24,12 +24,6 @@ temp_viz::LineWidget::LineWidget(const Point3f &pt1, const Point3f &pt2, const C setColor(color); } -temp_viz::LineWidget& temp_viz::LineWidget::operator=(const Widget &other) -{ - Widget3D::operator=(other); - return *this; -} - void temp_viz::LineWidget::setLineWidth(float line_width) { vtkLODActor *actor = vtkLODActor::SafeDownCast(WidgetAccessor::getProp(*this)); @@ -44,6 +38,12 @@ float temp_viz::LineWidget::getLineWidth() return actor->GetProperty()->GetLineWidth(); } +template<> temp_viz::LineWidget temp_viz::Widget::cast() +{ + Widget3D widget = this->cast(); + return static_cast(widget); +} + /////////////////////////////////////////////////////////////////////////////////////////////// /// plane widget implementation @@ -690,4 +690,4 @@ temp_viz::CloudNormalsWidget& temp_viz::CloudNormalsWidget::operator=(const Widg { Widget3D::operator=(other); return *this; -} \ No newline at end of file +} diff --git a/modules/viz/src/widget.cpp b/modules/viz/src/widget.cpp index 450e766..cb415ce 100644 --- a/modules/viz/src/widget.cpp +++ b/modules/viz/src/widget.cpp @@ -165,6 +165,16 @@ void temp_viz::Widget3D::setColor(const Color &color) actor->Modified (); } +template<> temp_viz::Widget3D temp_viz::Widget::cast() +{ + vtkProp3D *actor = vtkProp3D::SafeDownCast(WidgetAccessor::getProp(*this)); + CV_Assert(actor); + + Widget3D widget; + WidgetAccessor::setProp(widget, actor); + return widget; +} + /////////////////////////////////////////////////////////////////////////////////////////////// /// widget2D implementation -- 2.7.4