random_racer/src/ControlPointContainer.h

Go to the documentation of this file.
00001 #ifndef _RR_CONTROLPOINTCONTAINER_H_
00002 #define _RR_CONTROLPOINTCONTAINER_H_
00003 
00004 #include <vrs/callback.h>
00005 #include <vrs/so.h>
00006 #include <vrs/vector.h>
00007 
00008 #include <ext/hash_map>
00009 #include <vector>
00010 
00011 
00012 namespace random_racer
00013 {
00014 
00015 class ControlPointContainerTests;
00016 
00028 class ControlPointContainer : public VRS::SharedObj
00029 {
00032     
00037     typedef __gnu_cxx::hash_map<int, std::vector<unsigned char> *> InnerHashMap;
00038     typedef __gnu_cxx::hash_map<int, InnerHashMap * > HashMap;
00039     
00040     HashMap m_hashMap;
00041     
00046     unsigned int m_numControlPoints, m_blocksize;
00047 
00048     // because the UnitTest needs access to the mapToKey Function
00049     friend class ControlPointContainerTests;
00050 
00054     int mapToKey(double value);
00055     
00060     int getOffset(int key);
00061     
00065     int m_minY, m_maxY;
00066     
00070     unsigned int m_absHeight;
00071     
00076     unsigned char mapToHashMapHeight(double height);
00077     
00081     double mapHeightBack(unsigned char height);
00082     
00087     bool m_calcMinus;
00088     
00092     unsigned int calculateAbsHeight(int minHeight, int maxHeight);
00093     
00094     
00099     int m_blockList[8];
00100     
00105     void getFourBlocks(double valueX, double valueZ, int* blockList);
00106     
00110     void generateBlock(int valueX, int valueZ);
00111     
00112     // Maps the index of a two Dim. Array to an one Dim. Array.
00113     inline unsigned int mapsIndex(double valueX, double valueZ)
00114     {
00115         return ((unsigned int)valueX * m_numControlPoints ) + 
00116                (unsigned int)valueZ;
00117     }
00118 
00119     // Maps the index back to the x-value
00120     unsigned int mapsIndexBackToX(unsigned int index);
00121     
00122     //Maps the index back to the z-Value, requires the before calculated X-Value
00123     unsigned int mapsIndexBackToZ(unsigned int p_index, unsigned int p_valueX);
00124 
00130     VRS::SO<VRS::Callback1<std::vector<VRS::Vector>* > > m_callback;
00131         
00135     std::vector<VRS::Vector> m_genPointCache;
00136 
00137 public:
00145     ControlPointContainer(unsigned int numControlPoints, unsigned int blocksize,
00146         VRS::SO<VRS::Callback1<std::vector<VRS::Vector>* > > genPointCallback,
00147         int minY, int maxY);
00148     
00149     virtual ~ControlPointContainer();
00150     
00157     template <class T>
00158     void getPoints(double valueX, double valueZ, T* target);
00159     
00168     template <class T>
00169     void getPoints(double beginX, double beginZ, double endX, double endZ, 
00170                                                                 T* target);
00171     
00172     // Returns the minimal Height, given by the Ctor
00173     inline int minHeight()
00174     {
00175         return m_minY;
00176     }
00177     
00178     // Returns the maximal Height, given by the Ctor
00179     inline int maxHeight()
00180     {
00181         return m_maxY;
00182     }
00183 };
00184 
00185 } // namespace random_racer
00186 
00187 #include "ControlPointContainer.tcc"
00188 
00189 #endif /* _RR_CONTROLPOINTCONTAINER_H_ */

Generated on Fri May 11 21:01:57 2007 for Random Racer by  doxygen 1.5.1