00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://www.mrpt.org/ | 00005 | | 00006 | Copyright (C) 2005-2011 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 CWeightedPointsMap_H 00029 #define CWeightedPointsMap_H 00030 00031 #include <mrpt/slam/CPointsMap.h> 00032 #include <mrpt/slam/CObservation2DRangeScan.h> 00033 #include <mrpt/slam/CObservation3DRangeScan.h> 00034 #include <mrpt/utils/CSerializable.h> 00035 #include <mrpt/math/CMatrix.h> 00036 00037 #include <mrpt/maps/link_pragmas.h> 00038 00039 namespace mrpt 00040 { 00041 namespace slam 00042 { 00043 00044 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CWeightedPointsMap , CPointsMap, MAPS_IMPEXP ) 00045 00046 /** A cloud of points in 2D or 3D, which can be built from a sequence of laser scans. 00047 * This class stores the coordinates (x,y,z) and a "weight", or counter of how many times that point has been seen, used only if points fusion is enabled in the options structure. 00048 * \sa CMetricMap, CPoint, mrpt::utils::CSerializable, CSimplePointsMap 00049 * \ingroup mrpt_maps_grp 00050 */ 00051 class MAPS_IMPEXP CWeightedPointsMap : public CPointsMap 00052 { 00053 // This must be added to any CSerializable derived class: 00054 DEFINE_SERIALIZABLE( CWeightedPointsMap ) 00055 00056 public: 00057 CWeightedPointsMap(); //!< Default constructor 00058 virtual ~CWeightedPointsMap(); //!< Destructor 00059 00060 // -------------------------------------------- 00061 /** @name Pure virtual interfaces to be implemented by any class derived from CPointsMap 00062 @{ */ 00063 00064 /** Reserves memory for a given number of points: the size of the map does not change, it only reserves the memory. 00065 * This is useful for situations where it is approximately known the final size of the map. This method is more 00066 * efficient than constantly increasing the size of the buffers. Refer to the STL C++ library's "reserve" methods. 00067 */ 00068 virtual void reserve(size_t newLength); 00069 00070 /** Resizes all point buffers so they can hold the given number of points: newly created points are set to default values, 00071 * and old contents are not changed. 00072 * \sa reserve, setPoint, setPointFast, setSize 00073 */ 00074 virtual void resize(size_t newLength); 00075 00076 /** Resizes all point buffers so they can hold the given number of points, *erasing* all previous contents 00077 * and leaving all points to default values. 00078 * \sa reserve, setPoint, setPointFast, setSize 00079 */ 00080 virtual void setSize(size_t newLength); 00081 00082 /** Changes the coordinates of the given point (0-based index), *without* checking for out-of-bounds and *without* calling mark_as_modified() \sa setPoint */ 00083 virtual void setPointFast(size_t index,float x, float y, float z); 00084 00085 /** The virtual method for \a insertPoint() *without* calling mark_as_modified() */ 00086 virtual void insertPointFast( float x, float y, float z = 0 ); 00087 00088 /** Virtual assignment operator, to be implemented in derived classes. 00089 */ 00090 virtual void copyFrom(const CPointsMap &obj); 00091 00092 /** Get all the data fields for one point as a vector: [X Y Z WEIGHT] 00093 * Unlike getPointAllFields(), this method does not check for index out of bounds 00094 * \sa getPointAllFields, setPointAllFields, setPointAllFieldsFast 00095 */ 00096 virtual void getPointAllFieldsFast( const size_t index, std::vector<float> & point_data ) const { 00097 point_data.resize(4); 00098 point_data[0] = x[index]; 00099 point_data[1] = y[index]; 00100 point_data[2] = z[index]; 00101 point_data[3] = pointWeight[index]; 00102 } 00103 00104 /** Set all the data fields for one point as a vector: [X Y Z WEIGHT] 00105 * Unlike setPointAllFields(), this method does not check for index out of bounds 00106 * \sa setPointAllFields, getPointAllFields, getPointAllFieldsFast 00107 */ 00108 virtual void setPointAllFieldsFast( const size_t index, const std::vector<float> & point_data ) { 00109 ASSERTDEB_(point_data.size()==4) 00110 x[index] = point_data[0]; 00111 y[index] = point_data[1]; 00112 z[index] = point_data[2]; 00113 pointWeight[index] = point_data[3]; 00114 } 00115 00116 /** See CPointsMap::loadFromRangeScan() */ 00117 virtual void loadFromRangeScan( 00118 const CObservation2DRangeScan &rangeScan, 00119 const CPose3D *robotPose = NULL ); 00120 00121 /** See CPointsMap::loadFromRangeScan() */ 00122 virtual void loadFromRangeScan( 00123 const CObservation3DRangeScan &rangeScan, 00124 const CPose3D *robotPose = NULL ); 00125 00126 protected: 00127 00128 /** Auxiliary method called from within \a addFrom() automatically, to finish the copying of class-specific data */ 00129 virtual void addFrom_classSpecific(const CPointsMap &anotherMap, const size_t nPreviousPoints); 00130 00131 // Friend methods: 00132 template <class Derived> friend struct detail::loadFromRangeImpl; 00133 template <class Derived> friend struct detail::pointmap_traits; 00134 00135 public: 00136 00137 /** @} */ 00138 // -------------------------------------------- 00139 00140 /// Sets the point weight, which is ignored in all classes but those which actually store that field (Note: No checks are done for out-of-bounds index). \sa getPointWeight 00141 virtual void setPointWeight(size_t index,unsigned long w) { pointWeight[index]=w; } 00142 /// Gets the point weight, which is ignored in all classes (defaults to 1) but in those which actually store that field (Note: No checks are done for out-of-bounds index). \sa setPointWeight 00143 virtual unsigned int getPointWeight(size_t index) const { return pointWeight[index]; } 00144 00145 protected: 00146 std::vector<uint32_t> pointWeight; //!< The points weights 00147 00148 /** Clear the map, erasing all the points. 00149 */ 00150 virtual void internal_clear(); 00151 00152 protected: 00153 /** @name PLY Import virtual methods to implement in base classes 00154 @{ */ 00155 /** In a base class, reserve memory to prepare subsequent calls to PLY_import_set_vertex */ 00156 virtual void PLY_import_set_vertex_count(const size_t N); 00157 /** @} */ 00158 00159 }; // End of class def. 00160 00161 } // End of namespace 00162 } // End of namespace 00163 00164 #endif
| Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011 |