00001 // 00002 // Scan.hpp 00003 // 00004 // A simple data structure for scan data. 00005 // 00006 00007 #ifndef SCAN_HPP 00008 #define SCAN_HPP 00009 00010 #include <vector> 00011 #include "ScannerInfo.hpp" 00012 #include "ScanPoint.hpp" 00013 #include "../BasicDatatypes.hpp" 00014 00015 namespace datatypes 00016 { 00017 00018 // 00019 // Sehr einfacher Container fuer Scandaten. 00020 // 00021 // Ein Objekt dieser Klasse repraesentiert einen Einzelscan eines 00022 // Laserscanners. 00023 // 00024 class Scan : public BasicData 00025 { 00026 public: 00027 // Type of the scan point list 00028 typedef std::vector<ScanPoint> PointList; 00029 00030 // Type of the scan point list 00031 typedef std::vector<ScannerInfo> ScannerInfoVector; 00032 00033 // Type of a reference to an element 00034 typedef ScanPoint& reference; 00035 00037 typedef const ScanPoint& const_reference; 00038 00039 // Type of container size 00040 typedef PointList::size_type size_type; 00041 00042 // Type of constant iterator 00043 typedef PointList::const_iterator const_iterator; 00044 00045 // Type of iterator 00046 typedef PointList::iterator iterator; 00047 00048 // Property flags 00049 enum ScanFlags 00050 { 00051 FlagVehicleCoordinates = 0x00000800 00052 }; 00053 00054 // Estimate the memory usage of this object 00055 virtual const UINT32 getUsedMemory() const; 00056 00057 protected: 00058 // Properties of this scan. 00059 // See ScanFlags for a list of available property flags. 00060 UINT32 m_flags; 00061 00062 // Consecutive scan number 00063 UINT16 m_scanNumber; 00064 00065 // The list of scan points 00066 // 00067 // At Scan creation, enough points are reserved in this vector in 00068 // order to avoid memory re-allocations during runtime. This is 00069 // now all handled by std::vector<> directly. 00070 PointList m_points; 00071 00073 ScannerInfoVector m_scannerInfos; 00074 00075 // WATCH OUT: If you add more member variables here, you MUST also 00076 // adapt the method Scan::copy(), addScan() and add the variables there. 00077 00078 // //////////////////////////////////////////////////////////// 00079 00080 public: 00081 00082 // Constructor 00083 Scan (size_type maxPoints = 5280); // 5280 = Maxpoints with 1/8deg resolution, for 50- -60deg 00084 00087 Scan (const Scan&); 00088 00089 // Copy the given right hand side object into this object. An 00090 // alias for copy(). 00091 Scan& operator= (const Scan&); 00092 00093 // Copy the given right hand side object into this object. 00094 Scan& copy(const Scan&); 00095 00097 ~Scan(); 00098 00100 void clear (); 00101 00102 00103 // Equality predicate 00104 // bool operator==(const Scan& other) const; 00105 00106 // Returns the number of points in this scan. The same number can be retrieved by size(). 00107 UINT16 getNumPoints() const { return size(); } 00108 00109 // Returns the number of points in the scan. An alias for getNumPoints(). 00110 size_type size() const { return m_points.size(); } 00111 00112 // Returns true if this scan contains no points. 00113 bool empty() const { return m_points.empty(); } 00114 00130 void resize(size_type new_size, const ScanPoint& default_point = ScanPoint()); 00131 00132 // Returns the size of the memory (in number of points) allocated. 00133 // 00134 // Note: This is probably not the number of currently available 00135 // scan points! See size() or getNumPoints() for this. 00136 // 00137 size_type capacity() const { return m_points.capacity(); } 00138 00147 void reserve(size_type new_capacity); 00148 00149 00150 00151 // Returns the consecutive number of this scan. 00152 // Intended to detect missing scans. 00153 UINT16 getScanNumber() const { return (UINT16)m_scanNumber; } 00154 00155 // Set the consecutive number of this scan. 00156 void setScanNumber (UINT16 val) { m_scanNumber = val; } 00157 00158 00159 // Returns the total size of the current scan object, in [bytes]. This value is the actual memory 00160 // usage, including all sub-structures. Intended usage: Find out how much memory will be used when 00161 // storing this object in a buffer. 00162 // 00163 // Note that the returned value is an estimation that may not match up to the last byte... 00164 UINT32 getTotalObjectSize(); 00165 00166 // Returns all property flags of this scan in one number 00167 // isGroundLabeled(), isDirtLabeled(), isRainLabeled() etc. 00168 UINT32 getFlags() const { return m_flags; } 00169 00170 // Returns true if the ground detection ran on this scan. 00171 // bool isGroundLabeled() const { return ((m_flags & FlagGroundLabeled) != 0); } 00172 00173 // Returns true if the dirt detection ran on this scan. 00174 // bool isDirtLabeled() const { return ((m_flags & FlagDirtLabeled) != 0); } 00175 00176 // Returns true if the background detection ran on this scan. 00177 // bool isBackgroundLabeled() const { return ((m_flags & FlagBackgroundLabeled) != 0); } 00178 00179 // Returns true if the scan points are given in vehicle coordinates, or false if the scan points are given in the Laserscanner coordinate system. 00180 // bool isVehicleCoordinates() const { return ((m_flags & FlagVehicleCoordinates) != 0); } 00181 00182 // Set all flags in one number 00183 void setFlags (UINT32 val) { m_flags = val; } 00184 00185 // Clears the given processing flag in the scan. 00186 // 00187 // Note: This only changes the flags of the Scan object, not the 00188 // flags in the individual scan points! The flags in the 00189 // individual points are unchanged and must be modified in a 00190 // manual iteration loop. 00191 void clearLabelFlag(Scan::ScanFlags scanFlag); 00192 00193 // void setGroundLabeled(bool isGroundLabeled = true); ///< Set the Scan has ground labeled. 00194 // void setDirtLabeled(bool isDirtLabeled = true); ///< Set the Scan has dirt labeled. 00195 // void setRainLabeled(bool isRainLabeled = true); ///< Set the Scan has rain labeled. 00196 // void setCoverageLabeled(bool isCoverageLabeled = true); ///< Set the Scan has coverage labeled. 00197 // void setBackgroundLabeled(bool isBackgroundLabeled = true); ///< Set the Scan has background labeled. 00198 // void setReflectorLabeled(bool isReflectorLabeled = true); ///< Set the Scan has reflector labeled. 00199 00201 void setVehicleCoordinates(bool inVehicleCoordinates); 00202 00203 00204 // Returns the list of scan points (read only) 00205 const PointList& getPointList() const { return m_points; } 00206 // Returns the list of scan points (read/write) 00207 PointList& getPointList() { return m_points; } 00208 00209 // Returns the iterator of the first scan point (read only) 00210 PointList::const_iterator getPointListBegin() const { return m_points.begin(); } 00211 // Returns the iterator of the first scan point (read/write) 00212 PointList::iterator getPointListBegin() { return m_points.begin(); } 00213 00214 // Returns the iterator of one behind the last scan point (read only) 00215 PointList::const_iterator getPointListEnd() const { return m_points.end(); } 00216 00217 // Returns the iterator of one behind the last scan point (read/write) 00218 PointList::iterator getPointListEnd() { return m_points.end(); } 00219 00220 // Returns the iterator of the first scan point (read only) 00221 const_iterator begin() const { return m_points.begin(); } 00222 00223 // Returns the iterator of the first scan point (read/write) 00224 iterator begin() { return m_points.begin(); } 00225 00226 // Returns the iterator of one behind the last scan point (read only) 00227 const_iterator end() const { return m_points.end(); } 00228 00229 // Returns the iterator of one behind the last scan point (read/write) 00230 iterator end() { return m_points.end(); } 00231 00232 // Returns the n-th scan point (read/write). No range checking to avoid runtime costs. 00233 reference operator[](size_type n) { return m_points[n]; } 00234 00235 // Returns the n-th scan point (read only). No range checking to avoid runtime costs. 00236 const_reference operator[](size_type n) const { return m_points[n]; } 00237 00238 // Returns the n-th scan point (read/write) with range checking. 00239 reference at(size_type n) { return m_points.at(n); } 00240 00242 const_reference at(size_type n) const { return m_points.at(n); } 00243 00244 // Returns the n-th scan point (read only). No range checking to avoid runtime costs. 00245 const ScanPoint& getPoint (UINT16 n) const { return m_points[n]; } 00246 // Returns the n-th scan point (read/write). No range checking to avoid runtime costs. 00247 ScanPoint& getPoint (UINT16 n) { return m_points[n]; } 00248 00249 // Adds a new point to the list of scan points 00250 ScanPoint& addNewPoint(); 00251 00252 00253 // Returns the ScannerInfo collection. 00254 // 00255 // If this Scan contains points on 8 Layers (because of the 00256 // interlaced fusion of an 8-Layer scanner), the returned list 00257 // contains two ScannerInfo objects with the same deviceID. In all 00258 // other cases there will be only one ScannerInfo object for each 00259 // deviceID. 00260 // 00261 const ScannerInfoVector& getScannerInfos() const { return m_scannerInfos; } 00262 ScannerInfoVector& getScannerInfos(); 00263 const ScannerInfo* getScannerInfoByDeviceId(UINT8 id) const; 00264 00265 // Sets the ScannerInfo collection. 00266 void setScannerInfos(const ScannerInfoVector& v); 00267 00268 00269 // 00270 // Sorts the scan points of this scan by angle in descending 00271 // order. (Angles from high to low.) 00272 // 00273 // The first scan point will be the one with the largest 00274 // (leftmost) angle. The last scan point will be the one with 00275 // smallest (rightmost) angle, most probably a negative value. 00276 // 00277 // (Is used for the scan fusion.) 00278 // 00279 void sort(); 00280 00281 00282 // 00283 // Coordinate system transformations 00284 // 00285 00286 void addCartesianOffset(double offsetX, double offsetY, double offsetZ); 00287 void addPolarOffset(double distOffset, double hAngleOffset, double vAngleOffset); 00288 00289 00291 00303 bool transformToVehicleCoordinates(); 00304 00306 00316 bool transformToVehicleCoordinatesUnsorted(); 00317 00318 00319 private: 00320 00321 bool m_beVerbose; 00322 }; 00323 00324 } // namespace datatypes 00325 00326 00327 #endif // SCAN_HPP