00001 /** 00002 * @file SampleSet.h 00003 * 00004 * The file contains the definition of the class SampleSet and SampleSetProxy. 00005 * 00006 * @author <A href=mailto:roefer@tzi.de>Thomas Röfer</A> 00007 */ 00008 00009 #ifndef __SampleSet_h_ 00010 #define __SampleSet_h_ 00011 00012 #include "Tools/Math/Pose2D.h" 00013 00014 /** 00015 * The class represents a 2D sample. 00016 */ 00017 class Vector2Sample : public Vector2<double> 00018 { 00019 public: 00020 double probability; 00021 00022 /** 00023 * Constructor. 00024 */ 00025 Vector2Sample() {probability = 0.5;} 00026 Vector2Sample(const Vector2<double>& v) : Vector2<double>(v) {probability = 0.5;} 00027 }; 00028 00029 /** 00030 * The class represents a pose sample. 00031 */ 00032 class PoseSample : public Pose2D 00033 { 00034 public: 00035 double probability; 00036 00037 /** 00038 * Constructor. 00039 */ 00040 PoseSample() {probability = 0.5;} 00041 PoseSample(const Pose2D& pose) : Pose2D(pose) {probability = 0.5;} 00042 }; 00043 00044 /** 00045 * @class SampleSetProxyBase 00046 * The base of class SampleSetProxy. 00047 */ 00048 class SampleSetProxyBase 00049 { 00050 protected: 00051 const char* data; 00052 int numberOfSamples, 00053 sizeOfEntries; 00054 00055 public: 00056 /** 00057 * Constructor. 00058 */ 00059 SampleSetProxyBase() {numberOfSamples = 0;} 00060 00061 /** 00062 * The function returns the number of samples in the set. 00063 * @return The number of samples. 00064 */ 00065 int getNumberOfSamples() const {return numberOfSamples;} 00066 00067 /** 00068 * The function links the proxy to a sample set. 00069 */ 00070 void link(const char* start, int number, int size) 00071 { 00072 data = (const char*) start; 00073 numberOfSamples = number; 00074 sizeOfEntries = size; 00075 } 00076 }; 00077 00078 /** 00079 * @class SampleSetProxy 00080 * The SampleSetProxy can be linked to instances of the class SampleSet. 00081 */ 00082 template<class T> class SampleSetProxy : public SampleSetProxyBase 00083 { 00084 public: 00085 /** 00086 * Constant access operator. 00087 * @param index The index of the sample to access. 00088 */ 00089 const T& operator[](int index) const {return *(const T*) (data + index * sizeOfEntries);} 00090 }; 00091 00092 /** 00093 * @class SampleSet 00094 * A container for samples. Two independant sets are maintained. 00095 * As the sample set can be used by different modules that require 00096 * a different number of samples, the size of the set can be changed 00097 * at runtime. 00098 */ 00099 template<class T, int N> class SampleSet 00100 { 00101 private: 00102 T* current, /**< The actual sample set. */ 00103 * other; /**< The secondary sample set. */ 00104 00105 public: 00106 /** 00107 * Constructor. 00108 */ 00109 SampleSet() 00110 { 00111 current = new T[N]; 00112 other = new T[N]; 00113 } 00114 00115 /** 00116 * Destructor. 00117 */ 00118 ~SampleSet() 00119 { 00120 delete [] current; 00121 delete [] other; 00122 } 00123 00124 /** 00125 * The function links a proxy to this sample set. 00126 * @param sampleSetProxy The proxy. 00127 */ 00128 void link(SampleSetProxyBase& sampleSetProxy) const 00129 { 00130 sampleSetProxy.link((const char*) current, N, sizeof(T)); 00131 } 00132 00133 /** 00134 * The function returns the number of samples in the set. 00135 * @return The number of samples. 00136 */ 00137 int getNumberOfSamples() const {return N;} 00138 00139 /** 00140 * Access operator. 00141 * @param index The index of the sample to access. 00142 */ 00143 T& operator[](int index) {return current[index];} 00144 00145 /** 00146 * Constant access operator. 00147 * @param index The index of the sample to access. 00148 */ 00149 const T& operator[](int index) const {return current[index];} 00150 00151 /** 00152 * The function swaps the primary and secondary sample set. 00153 * @return The address of the previous sample set; 00154 */ 00155 T* swap() 00156 { 00157 T* temp = current; 00158 current = other; 00159 other = temp; 00160 return other; 00161 } 00162 }; 00163 00164 #endif //__SampleSet_h_ 00165 00166 /* 00167 * Change log : 00168 * 00169 * $Log: SampleSet.h,v $ 00170 * Revision 1.1.1.1 2004/05/22 17:25:16 cvsadm 00171 * created new repository GT2004_WM 00172 * 00173 * Revision 1.1 2003/10/07 10:07:01 cvsadm 00174 * Created GT2004 (M.J.) 00175 * 00176 * Revision 1.1.1.1 2003/07/02 09:40:22 cvsadm 00177 * created new repository for the competitions in Padova from the 00178 * tamara CVS (Tuesday 2:00 pm) 00179 * 00180 * removed unused solutions 00181 * 00182 * Revision 1.2 2003/06/21 11:59:09 roefer 00183 * SampleBallLocator added, does not work! 00184 * 00185 * Revision 1.1 2003/05/08 23:52:24 roefer 00186 * SampleSet and SampleSetProxy added 00187 * 00188 */