MRXT: The Multi-Robot eXploration Tool
Multi-Robot autonomous exploration and mapping simulator.
include/model/sensors/landmarksData.h
00001 /*
00002 *
00003 * Author: Miguel Julia <mjulia@umh.es> 
00004 * 
00005 * Date:   2008
00006 * 
00007 * Class landmarksData
00008 *
00009 *
00010 */
00011 #pragma once
00012 #ifndef __LANDMARKS__DATA__
00013 #define __LANDMARKS__DATA__
00014 
00015 #include "matFuns.h"
00016 
00017 /// Landmark struct
00018 typedef struct landmark{
00019         pos3d pos;
00020         matrix covariance;
00021         float* descriptor;
00022         unsigned short desclength;
00023         unsigned short repeated;
00024 
00025         landmark(): descriptor(0), desclength(0){};
00026         //landmark():pos(0.0f,0.0f,0.0f), sigma(3,3), repeated(0){};
00027         landmark(const pos3d& p, const matrix& s, const float* desc, unsigned short length, unsigned short r):
00028                 pos(p),covariance(s),desclength(length),repeated(r)
00029         {
00030                 descriptor = new float[desclength];
00031                 memcpy(descriptor,desc,desclength*sizeof(float));
00032         }
00033         landmark(const landmark& l): pos(l.pos),covariance(l.covariance),desclength(l.desclength),repeated(l.repeated){
00034                 descriptor = new float[desclength];
00035                 memcpy(descriptor,l.descriptor,desclength*sizeof(float));
00036         }
00037         landmark& operator=(const landmark& l){
00038                 pos = l.pos;
00039                 covariance = l.covariance;
00040                 repeated = l.repeated;
00041                 if (desclength != l.desclength){
00042                         desclength = l.desclength;
00043                         if (descriptor) delete[] descriptor;
00044                         descriptor = new float[desclength];     
00045                 }
00046                 memcpy(descriptor,l.descriptor,desclength*sizeof(float));
00047                 return *this;
00048         }
00049         virtual ~landmark(){ if (descriptor) delete[] descriptor;}
00050 }landmark;
00051 
00052 static landmark nulllandmark;
00053 
00054 /**
00055 * @brief Implements an array of landmarks returned by a sensor
00056 */
00057 class landmarksData{
00058 
00059 ///////////////////////////////////////////////////////////////////////
00060 //-------------------------  Attributes  ------------------------------
00061 ///////////////////////////////////////////////////////////////////////
00062 private:
00063         unsigned short nLandmarks;
00064         unsigned short marksReserved;
00065         landmark* landmarks;
00066 
00067         float distMAX;
00068         float distMIN;
00069         float gammaMAX;
00070 
00071 //--------------------------------------------------------------------- 
00072 ///////////////////////////////////////////////////////////////////////
00073 
00074 ///////////////////////////////////////////////////////////////////////
00075 //-------------------------  Methods  ---------------------------------
00076 ///////////////////////////////////////////////////////////////////////
00077 public:
00078         
00079         /// Default Constructor
00080         landmarksData();
00081         /// Builds the structure reserving space for nLandmarks
00082         landmarksData(int nLandmarks);
00083         /// Copy constructor
00084         landmarksData(const landmarksData&);
00085         /// Default destructor
00086         ~landmarksData();
00087         
00088         /// asignment operator
00089         landmarksData& operator= (const landmarksData &lmd); 
00090 
00091         /// sets the landmark n of the array
00092         void addLandmark(const landmark& lm);
00093         /// returns the landmark n of the array
00094         landmark& getLandmark(int n) const;
00095         /// returns a pointer to the data
00096         landmark* getLandmarks();
00097         /// clear the data
00098         void clear();
00099 
00100         /// returns the number of landmarks
00101         int getNLandmarks() const;
00102         /// resize the array to nLandmarks (this operation deletes the previous data)
00103         void reserve(int nLandmarks);
00104 
00105 //--------------------------------------------------------------------- 
00106 ///////////////////////////////////////////////////////////////////////
00107 };
00108 
00109 inline void landmarksData::addLandmark(const landmark& lm)                              {if (nLandmarks<marksReserved){landmarks[nLandmarks]=lm;nLandmarks++;}}
00110 inline landmark& landmarksData::getLandmark(int n) const                                {return (n<nLandmarks)? landmarks[n]: nulllandmark;}
00111 inline landmark* landmarksData::getLandmarks()                                                  {return landmarks;}
00112 inline int landmarksData::getNLandmarks() const                                                 {return nLandmarks;}
00113 inline void landmarksData::clear()                                                                              {nLandmarks = 0;}
00114 #endif
00115 
 All Classes Functions Variables Typedefs