From: ozantonkal Date: Mon, 5 Aug 2013 13:37:08 +0000 (+0200) Subject: remove old camera, rename new camera X-Git-Tag: submit/tizen_ivi/20141117.190038~2^2~913^2~30^2~10 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=119d97f1f638f6f757dd66f23ceead10888730de;p=profile%2Fivi%2Fopencv.git remove old camera, rename new camera --- diff --git a/modules/viz/include/opencv2/viz/types.hpp b/modules/viz/include/opencv2/viz/types.hpp index 8dd6819..2ebca5d 100644 --- a/modules/viz/include/opencv2/viz/types.hpp +++ b/modules/viz/include/opencv2/viz/types.hpp @@ -94,12 +94,12 @@ namespace cv unsigned int key_state; }; - class CV_EXPORTS Camera2 + class CV_EXPORTS Camera { public: - Camera2(float f_x, float f_y, float c_x, float c_y, const Size &window_size); - Camera2(const Vec2f &fov, const Size &window_size); - Camera2(const cv::Mat &K, const Size &window_size); + Camera(float f_x, float f_y, float c_x, float c_y, const Size &window_size); + Camera(const Vec2f &fov, const Size &window_size); + Camera(const cv::Mat &K, const Size &window_size); inline const Vec2d & getClip() const { return clip_; } inline void setClip(const Vec2d &clip) { clip_ = clip; } diff --git a/modules/viz/include/opencv2/viz/viz3d.hpp b/modules/viz/include/opencv2/viz/viz3d.hpp index eff8ac0..921eb32 100644 --- a/modules/viz/include/opencv2/viz/viz3d.hpp +++ b/modules/viz/include/opencv2/viz/viz3d.hpp @@ -39,7 +39,8 @@ namespace cv void updateWidgetPose(const String &id, const Affine3f &pose); Affine3f getWidgetPose(const String &id) const; - void setCamera(const Camera2 &camera); + void setCamera(const Camera &camera); + Camera getCamera() const; Affine3f getViewerPose(); void setViewerPose(const Affine3f &pose); diff --git a/modules/viz/src/common.cpp b/modules/viz/src/common.cpp index 08da19b..3c40a00 100644 --- a/modules/viz/src/common.cpp +++ b/modules/viz/src/common.cpp @@ -263,48 +263,3 @@ int hull_vertex_table[43][7] = { // return (fabsf (float (sum * 0.5f))); //} - -///////////////////////////////////////////////////////////////////////////////////////////// -void cv::viz::Camera::computeViewMatrix (Affine3d& view_mat) const -{ - //constructs view matrix from camera pos, view up, and the point it is looking at - //this code is based off of gluLookAt http://www.opengl.org/wiki/GluLookAt_code - - Vec3d zAxis = normalized(focal - pos); - Vec3d xAxis = normalized(zAxis.cross(view_up)); - Vec3d yAxis = xAxis.cross (zAxis); - - Matx33d R; - - R(0, 0) = xAxis[0]; R(0, 1) = xAxis[1]; R(0, 2) = xAxis[2]; - R(1, 0) = yAxis[0]; R(1, 1) = yAxis[1]; R(1, 2) = yAxis[2]; - R(1, 0) = -zAxis[0]; R(2, 1) = -zAxis[1]; R(2, 2) = -zAxis[2]; - - Vec3d t = R * (-pos); - - view_mat = Affine3d(R, t); -} - -/////////////////////////////////////////////////////////////////////// -void cv::viz::Camera::computeProjectionMatrix (Matx44d& proj) const -{ - double top = clip[0] * tan (0.5 * fovy); - double left = -(top * window_size[0]) / window_size[1]; - double right = -left; - double bottom = -top; - - double temp1 = 2.0 * clip[0]; - double temp2 = 1.0 / (right - left); - double temp3 = 1.0 / (top - bottom); - double temp4 = 1.0 / clip[1] - clip[0]; - - proj = Matx44d::zeros(); - - proj(0,0) = temp1 * temp2; - proj(1,1) = temp1 * temp3; - proj(0,2) = (right + left) * temp2; - proj(1,2) = (top + bottom) * temp3; - proj(2,2) = (-clip[1] - clip[0]) * temp4; - proj(3,2) = -1.0; - proj(2,3) = (-temp1 * clip[1]) * temp4; -} diff --git a/modules/viz/src/common.h b/modules/viz/src/common.h index c19dd89..ea89334 100644 --- a/modules/viz/src/common.h +++ b/modules/viz/src/common.h @@ -48,79 +48,6 @@ namespace cv SHADING_PHONG }; - class CV_EXPORTS Camera - { - public: - /** Focal point or lookAt. The view direction can be obtained by (focal-pos).normalized () */ - Vec3d focal; - - /** \brief Position of the camera. */ - Vec3d pos; - - /** \brief Up vector of the camera. */ - Vec3d view_up; - - /** \brief Near/far clipping planes depths */ - Vec2d clip; - - /** \brief Field of view angle in y direction (radians). */ - double fovy; - - // the following variables are the actual position and size of the window on the screen and NOT the viewport! - // except for the size, which is the same the viewport is assumed to be centered and same size as the window. - Vec2i window_size; - Vec2i window_pos; - - /** \brief Computes View matrix for Camera (Based on gluLookAt) - * \param[out] view_mat the resultant matrix - */ - void computeViewMatrix(Affine3d& view_mat) const; - - /** \brief Computes Projection Matrix for Camera - * \param[out] proj the resultant matrix - */ - void computeProjectionMatrix(Matx44d& proj) const; - - /** \brief converts point to window coordiantes - * \param[in] pt xyz point to be converted - * \param[out] window_cord vector containing the pts' window X,Y, Z and 1 - * - * This function computes the projection and view matrix every time. - * It is very inefficient to use this for every point in the point cloud! - */ - void cvtWindowCoordinates (const cv::Point3f& pt, Vec4d& window_cord) const - { - Affine3d view; - computeViewMatrix (view); - - Matx44d proj; - computeProjectionMatrix (proj); - cvtWindowCoordinates (pt, proj * view.matrix, window_cord); - return; - } - - /** \brief converts point to window coordiantes - * \param[in] pt xyz point to be converted - * \param[out] window_cord vector containing the pts' window X,Y, Z and 1 - * \param[in] composite_mat composite transformation matrix (proj*view) - * - * Use this function to compute window coordinates with a precomputed - * transformation function. The typical composite matrix will be - * the projection matrix * the view matrix. However, additional - * matrices like a camera disortion matrix can also be added. - */ - void cvtWindowCoordinates (const Point3f& pt, const Matx44d& composite_mat, Vec4d& window_cord) const - { - Vec4d pte (pt.x, pt.y, pt.z, 1); - window_cord = composite_mat * pte; - window_cord = window_cord/window_cord[3]; - - window_cord[0] = (window_cord[0]+1.0) / 2.0*window_size[0]; - window_cord[1] = (window_cord[1]+1.0) / 2.0*window_size[1]; - window_cord[2] = (window_cord[2]+1.0) / 2.0; - } - }; - } } diff --git a/modules/viz/src/types.cpp b/modules/viz/src/types.cpp index ebaf9d3..a7ec893 100644 --- a/modules/viz/src/types.cpp +++ b/modules/viz/src/types.cpp @@ -146,7 +146,7 @@ cv::viz::Mesh3d cv::viz::Mesh3d::loadMesh(const String& file) //////////////////////////////////////////////////////////////////// /// Camera implementation -cv::viz::Camera2::Camera2(float f_x, float f_y, float c_x, float c_y, const Size &window_size) +cv::viz::Camera::Camera(float f_x, float f_y, float c_x, float c_y, const Size &window_size) { CV_Assert(window_size.width > 0 && window_size.height > 0); setClip(Vec2d(0.01, 1000.01));// Default clipping @@ -161,7 +161,7 @@ cv::viz::Camera2::Camera2(float f_x, float f_y, float c_x, float c_y, const Size focal_[1] = f_y; } -cv::viz::Camera2::Camera2(const Vec2f &fov, const Size &window_size) +cv::viz::Camera::Camera(const Vec2f &fov, const Size &window_size) { CV_Assert(window_size.width > 0 && window_size.height > 0); setClip(Vec2d(0.01, 1000.01)); // Default clipping @@ -171,7 +171,7 @@ cv::viz::Camera2::Camera2(const Vec2f &fov, const Size &window_size) setWindowSize(window_size); } -cv::viz::Camera2::Camera2(const cv::Mat & K, const Size &window_size) +cv::viz::Camera::Camera(const cv::Mat & K, const Size &window_size) { CV_Assert(K.rows == 3 && K.cols == 3); CV_Assert(window_size.width > 0 && window_size.height > 0); @@ -180,10 +180,10 @@ cv::viz::Camera2::Camera2(const cv::Mat & K, const Size &window_size) float f_y = K.at(1,1); float c_x = K.at(0,2); float c_y = K.at(1,2); - Camera2(f_x, f_y, c_x, c_y, window_size); + Camera(f_x, f_y, c_x, c_y, window_size); } -void cv::viz::Camera2::setWindowSize(const Size &window_size) +void cv::viz::Camera::setWindowSize(const Size &window_size) { CV_Assert(window_size.width > 0 && window_size.height > 0); @@ -199,7 +199,7 @@ void cv::viz::Camera2::setWindowSize(const Size &window_size) window_size_ = window_size; } -void cv::viz::Camera2::computeProjectionMatrix(Matx44f &proj) const +void cv::viz::Camera::computeProjectionMatrix(Matx44f &proj) const { double top = clip_[0] * tan (0.5 * fov_[1]); double left = -(top * window_size_.width) / window_size_.height; diff --git a/modules/viz/src/viz3d.cpp b/modules/viz/src/viz3d.cpp index 2c67025..9a65740 100644 --- a/modules/viz/src/viz3d.cpp +++ b/modules/viz/src/viz3d.cpp @@ -46,7 +46,8 @@ void cv::viz::Viz3d::setWidgetPose(const String &id, const Affine3f &pose) { imp void cv::viz::Viz3d::updateWidgetPose(const String &id, const Affine3f &pose) { impl_->updateWidgetPose(id, pose); } cv::Affine3f cv::viz::Viz3d::getWidgetPose(const String &id) const { return impl_->getWidgetPose(id); } -void cv::viz::Viz3d::setCamera(const Camera2 &camera) { impl_->setCamera(camera); } +void cv::viz::Viz3d::setCamera(const Camera &camera) { impl_->setCamera(camera); } +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(); } diff --git a/modules/viz/src/viz3d_impl.cpp b/modules/viz/src/viz3d_impl.cpp index ee59b94..6bddd02 100644 --- a/modules/viz/src/viz3d_impl.cpp +++ b/modules/viz/src/viz3d_impl.cpp @@ -545,7 +545,7 @@ void cv::viz::Viz3d::VizImpl::initCameraParameters () Vec2i window_size(window_->GetScreenSize()); window_size /= 2; - Camera2 camera_temp(Vec2f(0.0,0.8575), Size(window_size[0], window_size[1])); + Camera camera_temp(Vec2f(0.0,0.8575), Size(window_size[0], window_size[1])); setCamera(camera_temp); setViewerPose(makeCameraPose(Vec3f(0.0f,0.0f,0.0f), Vec3f(0.0f, 0.0f, 1.0f), Vec3f(0.0f, 1.0f, 0.0f))); } @@ -564,22 +564,7 @@ void cv::viz::Viz3d::VizImpl::updateCamera () } ///////////////////////////////////////////////////////////////////////////////////////////// -// void cv::viz::Viz3d::VizImpl::getCameras (cv::viz::Camera& camera) -// { -// vtkCamera* active_camera = renderer_->GetActiveCamera (); -// -// camera.pos = cv::Vec3d(active_camera->GetPosition()); -// camera.focal = cv::Vec3d(active_camera->GetFocalPoint()); -// camera.clip = cv::Vec2d(active_camera->GetClippingRange()); -// camera.view_up = cv::Vec3d(active_camera->GetViewUp()); -// -// camera.fovy = active_camera->GetViewAngle()/ 180.0 * CV_PI; -// camera.window_size = cv::Vec2i(renderer_->GetRenderWindow()->GetSize()); -// camera.window_pos = cv::Vec2d::all(0); -// } - -///////////////////////////////////////////////////////////////////////////////////////////// -void cv::viz::Viz3d::VizImpl::setCamera(const Camera2 &camera) +void cv::viz::Viz3d::VizImpl::setCamera(const Camera &camera) { vtkCamera& active_camera = *renderer_->GetActiveCamera(); @@ -591,7 +576,7 @@ void cv::viz::Viz3d::VizImpl::setCamera(const Camera2 &camera) } ///////////////////////////////////////////////////////////////////////////////////////////// -cv::viz::Camera2 cv::viz::Viz3d::VizImpl::getCamera() const +cv::viz::Camera cv::viz::Viz3d::VizImpl::getCamera() const { vtkCamera& active_camera = *renderer_->GetActiveCamera(); @@ -600,7 +585,7 @@ cv::viz::Camera2 cv::viz::Viz3d::VizImpl::getCamera() const Size window_size(renderer_->GetRenderWindow()->GetSize()[0], renderer_->GetRenderWindow()->GetSize()[1]); - Camera2 camera(fov, window_size); + Camera camera(fov, window_size); camera.setClip(clip); return camera; } diff --git a/modules/viz/src/viz3d_impl.hpp b/modules/viz/src/viz3d_impl.hpp index 86789c8..b0e87f0 100644 --- a/modules/viz/src/viz3d_impl.hpp +++ b/modules/viz/src/viz3d_impl.hpp @@ -110,8 +110,8 @@ public: // All camera methods to refactor into set/getViewwerPose, setCamera() // and 'Camera' class itself with various constructors/fields - void setCamera(const Camera2 &camera); - Camera2 getCamera() const; + void setCamera(const Camera &camera); + Camera getCamera() const; void initCameraParameters (); /** \brief Initialize camera parameters with some default values. */ bool cameraParamsSet () const; /** \brief Checks whether the camera parameters were manually loaded from file.*/