HilbertCoordinateMapper.h

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 2007  A.N. Yzelman
00003  *  Released under LGPL, see license.txt
00004  *
00005  *  Last modified at 23th of May, 2007, by A.N. Yzelman
00006  *
00007  *  HilbertCoordinateMapper.h: utility functions for calculating hilbert curve coordinates.
00008  *
00009  */
00010 
00011 
00012 #ifndef _H_HilbertCoordinateMapper
00013 #define _H_HilbertCoordinateMapper
00014 
00019 #define RECURSE_LEVEL 3
00020 
00021 #include <cmath>
00022 #include <vector>
00023 #include "boost/multi_array.hpp"
00024 #include "boost/array.hpp"
00025 
00026 using namespace std;
00027 using namespace boost;
00028 
00032 class HilbertCoordinateMapper {
00033    public:
00035         HilbertCoordinateMapper(){};
00036 
00037 
00038    private:
00039    
00041     static void makeVec( const double x, const double y, vector< double > *where );
00042 
00044     static void makeVec( const double x, const double y, const double z, vector< double > *where );
00045    
00053         static void mid( const vector< double > *x, const vector< double > *y, vector< double > *to );
00054 
00062         static void mid3D( unsigned int pos, unsigned int i, unsigned int j );
00063 
00064         static double dist( const vector< double > *x, const vector< double > *y, const unsigned int dim );
00065 
00066         static double dist3D( const vector< double > *x, const unsigned int i );
00067 
00068         static unsigned int closestTo( const vector< double > *coor, const vector< vector< double > > *corners, const unsigned int dim );
00069 
00070         static unsigned int closestTo3D( const vector< double > *coor );
00071 
00072         static void refineCoors2D( vector< vector< double > > *corners, const unsigned int cell );
00073         
00074         static void refineCoors3D( const unsigned int cell );
00075 
00076         static double base8_to_base10( const vector< unsigned int > *digits ) {
00077                 return base_n_to_base10< 8 >( digits );
00078         }
00079         
00080         static double base4_to_base10( const vector< unsigned int > *digits ) {
00081                 return base_n_to_base10< 4 >( digits );
00082         }
00083 
00084         template< const unsigned int base >
00085         static double base_n_to_base10( const vector< unsigned int > *digits ) {
00086                 const unsigned int numdigits = digits->size();
00087                 double ret = 0;
00088                 unsigned int deler = 1;
00089                 //unsigned int multiplicant = 1;
00090         
00091                 for( unsigned int i = 0; i < numdigits; i++ ) {
00092                         const unsigned int noemer = (*digits)[ i ];
00093                         //ret += ( ( double ) noemer ) * ( ( double ) multiplicant );
00094                         //multiplicant *= ( unsigned int )base;
00095                         deler *= ( unsigned int )base;
00096                         ret += ( ( double ) noemer ) / ( ( double ) deler );
00097                 }
00098         
00099                 return ret;
00100         }
00101 
00102    protected:
00103         typedef boost::multi_array<double, 2 > array_type;   
00104     static array_type Box_3D;
00105     static array_type Box_3Dtemp;
00106         static array_type pattern;
00107 
00108         static array_type makePattern() {
00109                 double pattern[8][3] = {        {0,0,0}, 
00110                                                                         {1,0,0},
00111                                                                         {1,0,1},
00112                                                                         {0,0,1},
00113                                                                         {0,1,1},
00114                                                                         {1,1,1},
00115                                                                         {1,1,0},
00116                                                                         {0,1,0}
00117                                                                 };
00118 
00119                 array_type ret(extents[8][3]);
00120                 for( unsigned int i=0; i<8; i++ )
00121                         for( unsigned int j=0; j<3; j++ )
00122                                 ret[i][j] = pattern[i][j];
00123 
00124                 return ret;
00125         }
00126 
00127 
00128    public:
00129 
00130         static double toHilbert2D( const vector< double > *coordinates );
00131 
00132         static double toHilbert3D( const vector< double > *coordinates );
00133 
00134 };
00135 
00136 #endif

Generated on Sat Oct 13 17:34:42 2007 for R-Tree by  doxygen 1.5.2