00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://mrpt.sourceforge.net/ | 00005 | | 00006 | Copyright (C) 2005-2010 University of Malaga | 00007 | | 00008 | This software was written by the Machine Perception and Intelligent | 00009 | Robotics Lab, University of Malaga (Spain). | 00010 | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> | 00011 | | 00012 | This file is part of the MRPT project. | 00013 | | 00014 | MRPT is free software: you can redistribute it and/or modify | 00015 | it under the terms of the GNU General Public License as published by | 00016 | the Free Software Foundation, either version 3 of the License, or | 00017 | (at your option) any later version. | 00018 | | 00019 | MRPT is distributed in the hope that it will be useful, | 00020 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 00021 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 00022 | GNU General Public License for more details. | 00023 | | 00024 | You should have received a copy of the GNU General Public License | 00025 | along with MRPT. If not, see <http://www.gnu.org/licenses/>. | 00026 | | 00027 +---------------------------------------------------------------------------+ */ 00028 #ifndef CObservation3DRangeScan_H 00029 #define CObservation3DRangeScan_H 00030 00031 #include <mrpt/utils/CSerializable.h> 00032 #include <mrpt/slam/CObservation.h> 00033 #include <mrpt/poses/CPose3D.h> 00034 #include <mrpt/poses/CPose2D.h> 00035 00036 #include <mrpt/math/CPolygon.h> 00037 00038 00039 namespace mrpt 00040 { 00041 namespace slam 00042 { 00043 00044 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CObservation3DRangeScan, CObservation,OBS_IMPEXP ) 00045 00046 /** Declares a class derived from "CObservation" that 00047 * encapsules a 3D range scan measurement (e.g. from a time of flight range camera). 00048 * This kind of observations can carry one or more of these data fields: 00049 * - 3D point cloud (as float's instead of double's to save storage space - precision is not a problem in this case). 00050 * - 2D range image (as a matrix): Each entry in the matrix "rangeImage(x,y)" contains the distance of the pixel (x,y), in meters. 00051 * - 2D intensity image (as a CImage): A logarithmic A-law compression is used to convert the original 16bit intensity to a more standard 8bit graylevel. 00052 * - 2D confidence image (as a CImage): For each pixel, a 0x00 and a 0xFF mean the lowest and highest confidence levels, respectively. 00053 * 00054 * The coordinates of the 3D point cloud are in meters with respect to the front face of the camera (i.e. a small offset ~1cm in front of the physical focal point), 00055 * with the +X axis pointing forward, +Y pointing left-hand and +Z pointing up. 00056 * 00057 * The 2D images and matrices are stored as common images, with an up->down rows order and left->right, as usual. 00058 * Optionally, the intensity and confidence channels can be set to delayed-load images for off-rawlog storage so it saves 00059 * memory by having loaded in memory just the needed images. See the methods load() and unload(). 00060 * Due to the intensive storage requirements of this kind of observations, this observation is the only one in MRPT 00061 * for which it's recommended to always call "load()" and "unload()" before and after using the observation, *ONLY* when 00062 * the observation was read from a rawlog dataset, in order to make sure that all the externally stored data fields are 00063 * loaded and ready in memory. 00064 * 00065 * A class that grabs observations of this type is mrpt::hwdrivers::CSwissRanger3DCamera 00066 * 00067 * \note Starting at serialization version 2 (MRPT 0.9.1+), the confidence channel is stored as an image instead of a matrix to optimize memory and disk space. 00068 * \note Starting at serialization version 3 (MRPT 0.9.1+), the 3D point cloud and the rangeImage can both be stored externally to save rawlog space. 00069 * 00070 * \sa mrpt::hwdrivers::CSwissRanger3DCamera, CObservation 00071 */ 00072 class OBS_IMPEXP CObservation3DRangeScan : public CObservation 00073 { 00074 // This must be added to any CSerializable derived class: 00075 DEFINE_SERIALIZABLE( CObservation3DRangeScan ) 00076 00077 protected: 00078 bool m_points3D_external_stored; //!< If set to true, m_points3D_external_file is valid. 00079 std::string m_points3D_external_file; //!< 3D points are in CImage::IMAGES_PATH_BASE+<this_file_name> 00080 00081 bool m_rangeImage_external_stored; //!< If set to true, m_rangeImage_external_file is valid. 00082 std::string m_rangeImage_external_file; //!< rangeImage is in CImage::IMAGES_PATH_BASE+<this_file_name> 00083 00084 public: 00085 CObservation3DRangeScan( ); //!< Default constructor 00086 virtual ~CObservation3DRangeScan( ); //!< Destructor 00087 00088 /** @name Delayed-load manual control methods. 00089 @{ */ 00090 /** Makes sure all images and other fields which may be externally stored are loaded in memory. 00091 * Note that for all CImages, calling load() is not required since the images will be automatically loaded upon first access, so load() shouldn't be needed to be called in normal cases by the user. 00092 * If all the data were alredy loaded or this object has no externally stored data fields, calling this method has no effects. 00093 * \sa unload 00094 */ 00095 virtual void load() const; 00096 /** Unload all images, for the case they being delayed-load images stored in external files (othewise, has no effect). 00097 * \sa load 00098 */ 00099 virtual void unload(); 00100 /** @} */ 00101 00102 00103 bool hasPoints3D; //!< true means the field points3D contains valid data. 00104 vector_float points3D_x; //!< If hasPoints3D=true, the X coordinates of the 3D point cloud detected by the camera. 00105 vector_float points3D_y; //!< If hasPoints3D=true, the Y coordinates of the 3D point cloud detected by the camera. 00106 vector_float points3D_z; //!< If hasPoints3D=true, the Z coordinates of the 3D point cloud detected by the camera. 00107 00108 // 3D points external storage functions --------- 00109 inline bool points3D_isExternallyStored() const { return m_points3D_external_stored; } 00110 inline std::string points3D_getExternalStorageFile() const { return m_points3D_external_file; } 00111 void points3D_getExternalStorageFileAbsolutePath(std::string &out_path) const; 00112 inline std::string points3D_getExternalStorageFileAbsolutePath() const { 00113 std::string tmp; 00114 points3D_getExternalStorageFileAbsolutePath(tmp); 00115 return tmp; 00116 } 00117 void points3D_convertToExternalStorage( const std::string &fileName, const std::string &use_this_base_dir ); //!< Users won't normally want to call this, it's only used from internal MRPT programs. 00118 // --------- 00119 00120 bool hasRangeImage; //!< true means the field rangeImage contains valid data 00121 mrpt::math::CMatrix rangeImage; //!< If hasRangeImage=true, a matrix of floats with the range data as captured by the camera (in meters). 00122 00123 // Range Matrix external storage functions --------- 00124 inline bool rangeImage_isExternallyStored() const { return m_rangeImage_external_stored; } 00125 inline std::string rangeImage_getExternalStorageFile() const { return m_rangeImage_external_file; } 00126 void rangeImage_getExternalStorageFileAbsolutePath(std::string &out_path) const; 00127 inline std::string rangeImage_getExternalStorageFileAbsolutePath() const { 00128 std::string tmp; 00129 rangeImage_getExternalStorageFileAbsolutePath(tmp); 00130 return tmp; 00131 } 00132 void rangeImage_convertToExternalStorage( const std::string &fileName, const std::string &use_this_base_dir ); //!< Users won't normally want to call this, it's only used from internal MRPT programs. 00133 // --------- 00134 00135 bool hasIntensityImage; //!< true means the field intensityImage contains valid data 00136 mrpt::utils::CImage intensityImage; //!< If hasIntensityImage=true, a gray-level intensity image of the same size than "rangeImage" 00137 00138 bool hasConfidenceImage; //!< true means the field confidenceImage contains valid data 00139 mrpt::utils::CImage confidenceImage; //!< If hasConfidenceImage=true, an image with the "confidence" value [range 0-255] as estimated by the capture drivers. 00140 00141 mrpt::utils::TCamera cameraParams; //!< Projection parameters of the camera. 00142 00143 00144 float maxRange; //!< The maximum range allowed by the device, in meters (e.g. 8.0m, 5.0m,...) 00145 CPose3D sensorPose; //!< The 6D pose of the sensor on the robot. 00146 float stdError; //!< The "sigma" error of the device in meters, used while inserting the scan in an occupancy grid. 00147 00148 00149 /** A general method to retrieve the sensor pose on the robot. 00150 * Note that most sensors will return a full (6D) CPose3D, but see the derived classes for more details or special cases. 00151 * \sa setSensorPose 00152 */ 00153 void getSensorPose( CPose3D &out_sensorPose ) const { out_sensorPose = sensorPose; } 00154 00155 /** A general method to change the sensor pose on the robot. 00156 * Note that most sensors will use the full (6D) CPose3D, but see the derived classes for more details or special cases. 00157 * \sa getSensorPose 00158 */ 00159 void setSensorPose( const CPose3D &newSensorPose ) { sensorPose = newSensorPose; } 00160 00161 void swap(CObservation3DRangeScan &o); //!< Very efficient method to swap the contents of two observations. 00162 00163 void getZoneAsObs( CObservation3DRangeScan &obs, const unsigned int &r1, const unsigned int &r2, const unsigned int &c1, const unsigned int &c2 ); 00164 00165 /** A Levenberg-Marquart-based optimizer to recover the calibration parameters of a 3D camera given a range (depth) image and the corresponding 3D point cloud. 00166 * \param camera_offset The offset (in meters) in the +X direction of the point cloud. It's 1cm for SwissRanger SR4000. 00167 * \return The final average reprojection error per pixel (typ <0.05 px) 00168 */ 00169 static double recoverCameraCalibrationParameters( 00170 const CObservation3DRangeScan &in_obs, 00171 mrpt::utils::TCamera &out_camParams, 00172 const double camera_offset = 0.01 ); 00173 00174 00175 }; // End of class def. 00176 00177 00178 } // End of namespace 00179 00180 namespace utils 00181 { 00182 using namespace ::mrpt::slam; 00183 // Specialization must occur in the same namespace 00184 MRPT_DECLARE_TTYPENAME_PTR(CObservation3DRangeScan) 00185 } 00186 00187 } // End of namespace 00188 00189 #endif
| Page generated by Doxygen 1.7.1 for MRPT 0.9.1 SVN:exported at Fri Aug 6 10:31:35 UTC 2010 |
