1 /*M/////////////////////////////////////////////////////////////////////////////////////// 2 // 3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 // 5 // By downloading, copying, installing or using the software you agree to this license. 6 // If you do not agree to this license, do not download, install, 7 // copy or use the software. 8 // 9 // 10 // License Agreement 11 // For Open Source Computer Vision Library 12 // 13 // Copyright (C) 2013, OpenCV Foundation, all rights reserved. 14 // Third party copyrights are property of their respective owners. 15 // 16 // Redistribution and use in source and binary forms, with or without modification, 17 // are permitted provided that the following conditions are met: 18 // 19 // * Redistribution's of source code must retain the above copyright notice, 20 // this list of conditions and the following disclaimer. 21 // 22 // * Redistribution's in binary form must reproduce the above copyright notice, 23 // this list of conditions and the following disclaimer in the documentation 24 // and/or other materials provided with the distribution. 25 // 26 // * The name of the copyright holders may not be used to endorse or promote products 27 // derived from this software without specific prior written permission. 28 // 29 // This software is provided by the copyright holders and contributors "as is" and 30 // any express or implied warranties, including, but not limited to, the implied 31 // warranties of merchantability and fitness for a particular purpose are disclaimed. 32 // In no event shall the Intel Corporation or contributors be liable for any direct, 33 // indirect, incidental, special, exemplary, or consequential damages 34 // (including, but not limited to, procurement of substitute goods or services; 35 // loss of use, data, or profits; or business interruption) however caused 36 // and on any theory of liability, whether in contract, strict liability, 37 // or tort (including negligence or otherwise) arising in any way out of 38 // the use of this software, even if advised of the possibility of such damage. 39 // 40 // Authors: 41 // * Ozan Tonkal, ozantonkal@gmail.com 42 // * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com 43 // 44 //M*/ 45 46 #ifndef __OPENCV_VIZCORE_HPP__ 47 #define __OPENCV_VIZCORE_HPP__ 48 49 #include <opencv2/viz/types.hpp> 50 #include <opencv2/viz/widgets.hpp> 51 #include <opencv2/viz/viz3d.hpp> 52 53 namespace cv 54 { 55 namespace viz 56 { 57 58 //! @addtogroup viz 59 //! @{ 60 61 /** @brief Takes coordinate frame data and builds transform to global coordinate frame. 62 63 @param axis_x X axis vector in global coordinate frame. @param axis_y Y axis vector in global 64 coordinate frame. @param axis_z Z axis vector in global coordinate frame. @param origin Origin of 65 the coordinate frame in global coordinate frame. 66 67 This function returns affine transform that describes transformation between global coordinate frame 68 and a given coordinate frame. 69 */ 70 CV_EXPORTS Affine3d makeTransformToGlobal(const Vec3d& axis_x, const Vec3d& axis_y, const Vec3d& axis_z, const Vec3d& origin = Vec3d::all(0)); 71 72 /** @brief Constructs camera pose from position, focal_point and up_vector (see gluLookAt() for more 73 infromation). 74 75 @param position Position of the camera in global coordinate frame. @param focal_point Focal point 76 of the camera in global coordinate frame. @param y_dir Up vector of the camera in global 77 coordinate frame. 78 79 This function returns pose of the camera in global coordinate frame. 80 */ 81 CV_EXPORTS Affine3d makeCameraPose(const Vec3d& position, const Vec3d& focal_point, const Vec3d& y_dir); 82 83 /** @brief Retrieves a window by its name. 84 85 @param window_name Name of the window that is to be retrieved. 86 87 This function returns a Viz3d object with the given name. 88 89 @note If the window with that name already exists, that window is returned. Otherwise, new window is 90 created with the given name, and it is returned. 91 92 @note Window names are automatically prefixed by "Viz - " if it is not done by the user. 93 @code 94 /// window and window_2 are the same windows. 95 viz::Viz3d window = viz::getWindowByName("myWindow"); 96 viz::Viz3d window_2 = viz::getWindowByName("Viz - myWindow"); 97 @endcode 98 */ 99 CV_EXPORTS Viz3d getWindowByName(const String &window_name); 100 101 //! Unregisters all Viz windows from internal database. After it 'getWindowByName()' will create new windows instead getting existing from the database. 102 CV_EXPORTS void unregisterAllWindows(); 103 104 //! Displays image in specified window 105 CV_EXPORTS Viz3d imshow(const String& window_name, InputArray image, const Size& window_size = Size(-1, -1)); 106 107 /** @brief Checks **float/double** value for nan. 108 109 @param x return true if nan. 110 */ isNan(float x)111 inline bool isNan(float x) 112 { 113 unsigned int *u = reinterpret_cast<unsigned int *>(&x); 114 return ((u[0] & 0x7f800000) == 0x7f800000) && (u[0] & 0x007fffff); 115 } 116 117 /** @brief Checks **float/double** value for nan. 118 119 @param x return true if nan. 120 */ isNan(double x)121 inline bool isNan(double x) 122 { 123 unsigned int *u = reinterpret_cast<unsigned int *>(&x); 124 return (u[1] & 0x7ff00000) == 0x7ff00000 && (u[0] != 0 || (u[1] & 0x000fffff) != 0); 125 } 126 127 /** @brief Checks **float/double** value for nan. 128 129 @param v return true if **any** of the elements of the vector is *nan*. 130 */ isNan(const Vec<_Tp,cn> & v)131 template<typename _Tp, int cn> inline bool isNan(const Vec<_Tp, cn>& v) 132 { return isNan(v.val[0]) || isNan(v.val[1]) || isNan(v.val[2]); } 133 134 /** @brief Checks **float/double** value for nan. 135 136 @param p return true if **any** of the elements of the point is *nan*. 137 */ isNan(const Point3_<_Tp> & p)138 template<typename _Tp> inline bool isNan(const Point3_<_Tp>& p) 139 { return isNan(p.x) || isNan(p.y) || isNan(p.z); } 140 141 142 /////////////////////////////////////////////////////////////////////////////////////////////// 143 /// Read/write clouds. Supported formats: ply, xyz, obj and stl (readonly) 144 145 CV_EXPORTS void writeCloud(const String& file, InputArray cloud, InputArray colors = noArray(), InputArray normals = noArray(), bool binary = false); 146 CV_EXPORTS Mat readCloud (const String& file, OutputArray colors = noArray(), OutputArray normals = noArray()); 147 148 /////////////////////////////////////////////////////////////////////////////////////////////// 149 /// Reads mesh. Only ply format is supported now and no texture load support 150 151 CV_EXPORTS Mesh readMesh(const String& file); 152 153 /////////////////////////////////////////////////////////////////////////////////////////////// 154 /// Read/write poses and trajectories 155 156 CV_EXPORTS bool readPose(const String& file, Affine3d& pose, const String& tag = "pose"); 157 CV_EXPORTS void writePose(const String& file, const Affine3d& pose, const String& tag = "pose"); 158 159 //! takes vector<Affine3<T>> with T = float/dobule and writes to a sequence of files with given filename format 160 CV_EXPORTS void writeTrajectory(InputArray traj, const String& files_format = "pose%05d.xml", int start = 0, const String& tag = "pose"); 161 162 //! takes vector<Affine3<T>> with T = float/dobule and loads poses from sequence of files 163 CV_EXPORTS void readTrajectory(OutputArray traj, const String& files_format = "pose%05d.xml", int start = 0, int end = INT_MAX, const String& tag = "pose"); 164 165 166 /////////////////////////////////////////////////////////////////////////////////////////////// 167 /// Computing normals for mesh 168 169 CV_EXPORTS void computeNormals(const Mesh& mesh, OutputArray normals); 170 171 //! @} 172 173 } /* namespace viz */ 174 } /* namespace cv */ 175 176 #endif /* __OPENCV_VIZCORE_HPP__ */ 177