diff --git a/modules/viz/include/opencv2/viz/viz3d.hpp b/modules/viz/include/opencv2/viz/viz3d.hpp index a80fd3748..a54493611 100644 --- a/modules/viz/include/opencv2/viz/viz3d.hpp +++ b/modules/viz/include/opencv2/viz/viz3d.hpp @@ -38,6 +38,9 @@ namespace cv Affine3f getViewerPose(); void setViewerPose(const Affine3f &pose); + void resetCameraViewpoint (const String &id); + void resetCamera(); + void convertToWindowCoordinates(const Point3d &pt, Point3d &window_coord); void converTo3DRay(const Point3d &window_coord, Point3d &origin, Vec3d &direction); diff --git a/modules/viz/src/viz3d.cpp b/modules/viz/src/viz3d.cpp index 48f6ea304..61911ca42 100644 --- a/modules/viz/src/viz3d.cpp +++ b/modules/viz/src/viz3d.cpp @@ -67,6 +67,9 @@ cv::viz::Camera cv::viz::Viz3d::getCamera() const { return impl_->getCamera(); } void cv::viz::Viz3d::setViewerPose(const Affine3f &pose) { impl_->setViewerPose(pose); } cv::Affine3f cv::viz::Viz3d::getViewerPose() { return impl_->getViewerPose(); } +void cv::viz::Viz3d::resetCameraViewpoint (const String &id) { impl_->resetCameraViewpoint(id); } +void cv::viz::Viz3d::resetCamera() { impl_->resetCamera(); } + void cv::viz::Viz3d::convertToWindowCoordinates(const Point3d &pt, Point3d &window_coord) { impl_->convertToWindowCoordinates(pt, window_coord); } void cv::viz::Viz3d::converTo3DRay(const Point3d &window_coord, Point3d &origin, Vec3d &direction) { impl_->converTo3DRay(window_coord, origin, direction); } diff --git a/modules/viz/src/viz3d_impl.cpp b/modules/viz/src/viz3d_impl.cpp index 7a1518c2c..00a5cae78 100644 --- a/modules/viz/src/viz3d_impl.cpp +++ b/modules/viz/src/viz3d_impl.cpp @@ -421,21 +421,21 @@ void cv::viz::Viz3d::VizImpl::converTo3DRay(const Point3d &window_coord, Point3d } ///////////////////////////////////////////////////////////////////////////////////////////// -void cv::viz::Viz3d::VizImpl::resetCameraViewpoint (const std::string &id) +void cv::viz::Viz3d::VizImpl::resetCameraViewpoint (const String &id) { vtkSmartPointer camera_pose; static WidgetActorMap::iterator it = widget_actor_map_->find (id); if (it != widget_actor_map_->end ()) { vtkProp3D *actor = vtkProp3D::SafeDownCast(it->second); + CV_Assert("Widget is not 3D." && actor); camera_pose = actor->GetUserMatrix(); } else return; // Prevent a segfault - if (!camera_pose) - return; + if (!camera_pose) return; vtkSmartPointer cam = renderer_->GetActiveCamera (); cam->SetPosition (camera_pose->GetElement (0, 3), @@ -455,6 +455,12 @@ void cv::viz::Viz3d::VizImpl::resetCameraViewpoint (const std::string &id) renderer_->Render (); } +/////////////////////////////////////////////////////////////////////////////////// +void cv::viz::Viz3d::VizImpl::resetCamera() +{ + renderer_->ResetCamera(); +} + /////////////////////////////////////////////////////////////////////////////////// void cv::viz::Viz3d::VizImpl::setRepresentationToSurface() { diff --git a/modules/viz/src/viz3d_impl.hpp b/modules/viz/src/viz3d_impl.hpp index b2339c40c..0eab85bc5 100644 --- a/modules/viz/src/viz3d_impl.hpp +++ b/modules/viz/src/viz3d_impl.hpp @@ -49,18 +49,14 @@ public: void setRepresentationToSurface(); void setRepresentationToPoints(); void setRepresentationToWireframe(); - - - // //////////////////////////////////////////////////////////////////////////////////// - // All camera methods to refactor into set/getViewwerPose, setCamera() - // and 'Camera' class itself with various constructors/fields void setCamera(const Camera &camera); Camera getCamera() const; /** \brief Reset the camera direction from {0, 0, 0} to the center_{x, y, z} of a given dataset. * \param[in] id the point cloud object id (default: cloud) */ - void resetCameraViewpoint (const String& id = "cloud"); + void resetCameraViewpoint(const String& id); + void resetCamera(); void setViewerPose(const Affine3f &pose); Affine3f getViewerPose();