fix field of view formula in camera class, implement get camera
authorozantonkal <ozantonkal@gmail.com>
Sun, 4 Aug 2013 15:01:41 +0000 (17:01 +0200)
committerozantonkal <ozantonkal@gmail.com>
Sun, 4 Aug 2013 15:01:41 +0000 (17:01 +0200)
modules/viz/src/types.cpp
modules/viz/src/viz3d_impl.cpp
modules/viz/src/viz3d_impl.hpp

index e95f67e..827b8b3 100644 (file)
@@ -192,7 +192,7 @@ void cv::viz::Camera2::setWindowSize(const Size &window_size)
     float aspect_ratio_new = window_size.width / window_size.height;
     
     if (principal_point_[0] < 0.0f)
-        fov_[0] = 2 * atan2(tan(fov_[0] * 0.5), aspect_ratio_new); // This assumes that the lens is symmetric!
+        fov_[0] = 2 * atan2(tan(fov_[1] * 0.5), aspect_ratio_new); // This assumes that the lens is symmetric!
     else
         fov_[0] = (atan2(principal_point_[0],focal_[0]) + atan2(window_size.width-principal_point_[0],focal_[0])) * 180 / CV_PI;
 }
index 78c1441..f764c77 100644 (file)
@@ -604,6 +604,16 @@ void cv::viz::Viz3d::VizImpl::setCamera(const Camera2 &camera)
 }
 
 /////////////////////////////////////////////////////////////////////////////////////////////
+void cv::viz::Viz3d::VizImpl::getCamera(viz::Camera2 &camera)
+{
+    vtkCamera& active_camera = *renderer_->GetActiveCamera();
+    camera.setFov(Vec2f(0.0, active_camera.GetViewAngle() * CV_PI / 180.0f));
+    camera.setClip(Vec2d(active_camera.GetClippingRange()));
+    camera.setWindowSize(Size(renderer_->GetRenderWindow()->GetSize()[0],
+                              renderer_->GetRenderWindow()->GetSize()[1]));
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////////
 void cv::viz::Viz3d::VizImpl::setViewerPose(const Affine3f &pose)
 {
     vtkCamera& camera = *renderer_->GetActiveCamera ();
index 26bafd3..5bd4ebd 100644 (file)
@@ -111,6 +111,7 @@ public:
     // and 'Camera' class itself with various constructors/fields
     
     void setCamera(const Camera2 &camera);
+    void getCamera(Camera2 &camera);
 
     void initCameraParameters (); /** \brief Initialize camera parameters with some default values. */
     bool cameraParamsSet () const; /** \brief Checks whether the camera parameters were manually loaded from file.*/