Go to the documentation of this file.00001
00009
00010
00011
00012 #pragma once
00013
00014 #ifndef WIN32
00015 #pragma interface
00016 #endif // WIN32
00017
00018
00019 #include "mlist.h"
00020 #include "cube.h"
00021 #include "hash.h"
00022 #include "MarchingCubes.h"
00023 #include "mc_draw.h"
00024 #include "data_access.h"
00025
00026
00027
00028
00029
00031 class HashOctree
00032
00033 {
00034
00035 public:
00036 class geom_cell ;
00037 class cell_iterator ;
00038 class leaf_iterator ;
00039
00040
00041 protected:
00043 typedef Hash<real> HashField ;
00044
00046 HashField _hash ;
00047
00049 Level _max_level ;
00050
00052 real _max_field ;
00053
00055 MarchingCubes _mc ;
00056
00058 MC_Draw _mc_draw ;
00059
00061 uint _dual_temp_memory ;
00062
00063
00064
00065 public:
00067 HashOctree() { init() ; }
00068
00070 ~HashOctree() { clear() ; }
00071
00072
00074 void init() ;
00075
00077 void clear() { clear_octree() ; _mc.clean_all() ; }
00078
00080 void clear_octree() ;
00081
00083 bool check () ;
00084
00086 void stats() ;
00087
00088
00090 Level max_level() const { return _max_level ; }
00091
00093 real max_field() const { return _max_field ; }
00094
00096 MarchingCubes &mc() { return _mc ; }
00097
00099 MC_Draw &mc_draw() { return _mc_draw ; }
00100
00102 bool set_impl( data_access *ref = NULL ) ;
00103
00105 bool refine( data_access *ref = NULL ) ;
00106
00108 bool adapt( data_access *ref = NULL ) ;
00109
00111 bool draw_wire() ;
00112
00114 bool draw_centers() ;
00115
00117 typedef bool hash_dual_walker( HashOctree &fo, Key *keys ) ;
00118
00120 bool dual_cubes_walk( hash_dual_walker &walker ) ;
00121
00123 bool build_isosurface( data_access *ref = NULL ) ;
00124
00126 bool direct_draw_isosurface( data_access *ref = NULL ) ;
00127
00129 bool draw_dual() ;
00130
00132 bool dual_timing() ;
00133
00134
00135
00136 public:
00138 inline cell_iterator cells_begin() { return cell_iterator( *this ) ; }
00139
00141 inline leaf_iterator leaves_begin() { return leaf_iterator( *this ) ; }
00142
00143
00144
00145 public:
00147 bool find_leaf( real x, real y, real z, geom_cell &cell ) const ;
00148
00150 bool find_radius( real x, real y, real z, real r, List<geom_cell> &cells ) const ;
00151
00153 bool adjacent( const geom_cell &cell, List<geom_cell> &cells ) const ;
00154
00156 bool is_leaf( Key k ) const { return !is_inv( _hash[k].data ) ; }
00157
00158
00159
00160 public:
00161
00163 void draw_plane ( real nx, real ny, real nz, real d ) ;
00164
00166 void draw_slice ( real nx, real ny, real nz, real d, float alpha ) ;
00167
00169 void draw_iso () { _mc.draw_surf() ; }
00170
00171
00172
00173 public :
00175 class geom_cell : public Cube
00176
00177 {
00178 friend class HashOctree ;
00179
00180 protected:
00181 Key _key ;
00182 real _field ;
00183
00184
00185
00186 public:
00188 geom_cell( Key key_ = KEY_INV, real field_ = R_INV ) : Cube(key2cube(key_)), _key(key_), _field(field_) {}
00189
00191 ~geom_cell() {}
00192
00194 geom_cell( const geom_cell &i ) : Cube(i), _key(i._key), _field(i._field) {}
00195
00197 geom_cell &operator = ( const geom_cell &i )
00198 { Cube::operator=(i) ; _key = i._key ; _field = i._field ; return *this; }
00199
00200
00201
00202
00203 public :
00205 inline Key key() const { return _key ; }
00207 inline Key &key() { return _key ; }
00208
00210 inline real operator*() const { return _field ; }
00211
00212
00213
00214 public :
00216 inline bool operator ==( const geom_cell &i ) const { return key() == i.key() ; }
00217
00219 inline bool operator !=( const geom_cell &i ) const { return key() != i.key() ; }
00220
00222 inline bool is_leaf() const { return !is_inv(*(*this)) ; }
00223
00225 inline bool operator ()() const { return key() != KEY_INV ; }
00226
00227
00228
00229 public :
00231 inline bool sons( geom_cell *s , const HashField &hash )
00232 {
00233 if( is_leaf() ) return false ;
00234
00235 Key k = _key << 3 ;
00236 for( int i = 0 ; i < 8 ; ++i )
00237 {
00238 s[i]._key = k | i ;
00239 s[i]._field = hash[k|i].data ;
00240 (Cube&)s[i] = key2cube(s[i]._key) ;
00241 }
00242 return true ;
00243 }
00244
00246 inline bool son( int i , geom_cell &s, const HashField &hash )
00247 {
00248 if( is_leaf() ) return false ;
00249 s._key = (key() << 3) | i ;
00250 s._field = hash[s._key].data ;
00251 (Cube&)s = key2cube(s._key) ;
00252 return true ;
00253 }
00254 };
00255
00256 const geom_cell geom_root() const { const Key root_key = 1 ; return geom_cell( root_key, _hash[root_key].data ) ; }
00257 const geom_cell geom_key ( Key k ) const { return geom_cell( k, _hash[k].data ) ; }
00258
00259
00260
00261
00262
00263 public :
00265 class cell_iterator
00266
00267 {
00268 friend class HashOctree ;
00269
00270 protected:
00272 HashField::iterator _it ;
00273
00274
00275
00276 public:
00278 cell_iterator( HashOctree &o ) : _it( o._hash.begin() ) {}
00279
00281 ~cell_iterator() {}
00282
00284 cell_iterator( const cell_iterator &i ) : _it(i._it) {}
00285
00287 cell_iterator &operator = ( const cell_iterator &i )
00288 { _it = i._it; return *this; }
00289
00290
00291
00292 public :
00294 inline bool operator ==( const cell_iterator &i ) const { return _it == i._it ; }
00295
00297 inline bool operator !=( const cell_iterator &i ) const { return _it != i._it ; }
00298
00300 inline bool operator ()() const { return _it() ; }
00301
00303 inline cell_iterator &operator ++() { ++_it ; return *this ; }
00304
00305
00306
00307 public :
00308
00309 inline geom_cell top() const { return geom_cell( key(), *_it ) ; }
00310
00312 inline real &operator*() { return *_it ; }
00313
00315 inline Level lv() { return key_level(_it.key()) ; }
00316
00318 inline real sz() { return Cube(0,0,0,lv()).sz() ; }
00319
00321 inline Key key() const { return _it.key() ; }
00322
00324 inline bool is_leaf() const { return !is_inv(*_it) ; }
00325
00327 void draw_wire () const { top().draw_wire () ; }
00328
00329 };
00330
00331
00333 class leaf_iterator : public cell_iterator
00334
00335 {
00336 public :
00337 leaf_iterator( HashOctree &o ) : cell_iterator( o )
00338 { if( (*this)() && !this->is_leaf() ) ++(*this) ; }
00339
00340
00342 inline leaf_iterator &operator ++()
00343 {
00344 cell_iterator &it = *this ;
00345 do ++it ; while ( it() && !it.is_leaf() ) ;
00346 return *this ;
00347 }
00348 } ;
00349 } ;
00350
00351
00352