From aa2594c06c3183131afa6e7cba30ae08b893292d Mon Sep 17 00:00:00 2001 From: ozantonkal Date: Thu, 25 Jul 2013 10:23:24 +0200 Subject: [PATCH] fix aspect_ratio computation from fovs, add casting for camerapositionwidget, trajectorywidget --- modules/viz/include/opencv2/viz/widgets.hpp | 2 ++ modules/viz/src/shape_widgets.cpp | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/modules/viz/include/opencv2/viz/widgets.hpp b/modules/viz/include/opencv2/viz/widgets.hpp index ba601ca86..a7b9b3546 100644 --- a/modules/viz/include/opencv2/viz/widgets.hpp +++ b/modules/viz/include/opencv2/viz/widgets.hpp @@ -231,6 +231,8 @@ namespace cv template<> CV_EXPORTS TextWidget Widget::cast(); template<> CV_EXPORTS ImageOverlayWidget Widget::cast(); template<> CV_EXPORTS Image3DWidget Widget::cast(); + template<> CV_EXPORTS CameraPositionWidget Widget::cast(); + template<> CV_EXPORTS TrajectoryWidget Widget::cast(); template<> CV_EXPORTS CloudWidget Widget::cast(); template<> CV_EXPORTS CloudNormalsWidget Widget::cast(); template<> CV_EXPORTS MeshWidget Widget::cast(); diff --git a/modules/viz/src/shape_widgets.cpp b/modules/viz/src/shape_widgets.cpp index 4fee4072a..64d05360f 100644 --- a/modules/viz/src/shape_widgets.cpp +++ b/modules/viz/src/shape_widgets.cpp @@ -1003,9 +1003,10 @@ cv::viz::CameraPositionWidget::CameraPositionWidget(const Vec2f &fov, double sca camera->SetFocalPoint(0.0,0.0,1.0); camera->SetClippingRange(0.01, scale); + double aspect_ratio = tan(fov[0] * 0.5) / tan(fov[1] * 0.5); + double planesArray[24]; - // Default aspect ratio = 1.0? fovx/fovy? - camera->GetFrustumPlanes(1.0, planesArray); + camera->GetFrustumPlanes(aspect_ratio, planesArray); vtkSmartPointer planes = vtkSmartPointer::New(); planes->SetFrustumPlanes(planesArray); @@ -1122,6 +1123,12 @@ cv::viz::CameraPositionWidget::CameraPositionWidget(const Matx33f &K, const Mat WidgetAccessor::setProp(*this, actor); } +template<> cv::viz::CameraPositionWidget cv::viz::Widget::cast() +{ + Widget3D widget = this->cast(); + return static_cast(widget); +} + /////////////////////////////////////////////////////////////////////////////////////////////// /// trajectory widget implementation @@ -1279,3 +1286,9 @@ cv::viz::TrajectoryWidget::TrajectoryWidget(const std::vector &path, c WidgetAccessor::setProp(*this, actor); setColor(color); } + +template<> cv::viz::TrajectoryWidget cv::viz::Widget::cast() +{ + Widget3D widget = this->cast(); + return static_cast(widget); +} \ No newline at end of file