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 #ifdef HASH_HAS_ERASE
00028
00029
00030
00031
00033 class LeafOctree
00034
00035 {
00036
00037 public:
00038 class geom_cell ;
00039 class leaf_iterator ;
00040
00041
00042 protected:
00044 typedef Hash<real> HashField ;
00045
00047 HashField _hash ;
00048
00050 uint _level_dist[MAX_LEVEL+1] ;
00051
00053 Level _opt_level ;
00054
00056 real _max_field ;
00057
00059 MarchingCubes _mc ;
00060
00062 MC_Draw _mc_draw ;
00063
00064 private:
00066 typedef Hash<Level> HashVerts ;
00068 HashVerts _verts ;
00069
00070
00071
00072
00073 public:
00075 LeafOctree() { init() ; }
00076
00078 ~LeafOctree() { clear() ; }
00079
00080
00082 void init() ;
00083
00085 void clear() { clear_octree() ; _mc.clean_all() ; }
00086
00088 void clear_octree() ;
00089
00091 void compute_opt_level() ;
00092
00094 bool check () ;
00095
00097 void stats() const ;
00098
00099
00101 Level max_level() const { Level lv = MAX_LEVEL ; while( lv > 0 && !_level_dist[lv] ) --lv ; return lv ; }
00102
00104 Level opt_level() const { return _opt_level ; }
00105
00107 Level &opt_level() { return _opt_level ; }
00108
00110 real max_field() const { return _max_field ; }
00111
00113 MarchingCubes &mc() { return _mc ; }
00114
00116 MC_Draw &mc_draw() { return _mc_draw ; }
00117
00119 bool set_impl( data_access *ref = NULL ) ;
00120
00122 bool refine( data_access *ref = NULL ) ;
00123
00125 bool adapt( data_access *ref = NULL ) ;
00126
00128 bool draw_wire() ;
00129
00131 bool draw_centers() ;
00132
00134 typedef bool leaf_dual_walker( LeafOctree &fo, Key *keys ) ;
00135
00137 bool compute_primal_verts() ;
00138
00140 bool dual_cubes_walk( leaf_dual_walker &walker ) ;
00141
00143 bool build_isosurface( data_access *ref = NULL ) ;
00144
00146 bool direct_draw_isosurface( data_access *ref = NULL ) ;
00147
00149 bool draw_dual() ;
00150
00152 bool dual_timing() ;
00153
00154
00155
00156 public:
00158 inline leaf_iterator leaves_begin() { return leaf_iterator( *this ) ; }
00159
00160
00161
00162 public:
00164 bool find_leaf( Key k, Level o_lv, geom_cell &cell ) const ;
00165 bool find_leaf( Key k, geom_cell &cell ) const { return find_leaf( k, opt_level(), cell ) ; }
00166 bool find_leaf( real x, real y, real z, geom_cell &cell ) const { return find_leaf( cube2key( Cube(x,y,z,MAX_LEVEL) ), opt_level(), cell ) ; }
00167
00169 bool find_radius( real x, real y, real z, real r, List<geom_cell> &cells ) const ;
00170
00172 bool adjacent( Key k, List<geom_cell> &cells ) const ;
00173 bool adjacent( const geom_cell &cell, List<geom_cell> &cells ) const { return adjacent( cell.key(), cells ) ; }
00174
00176 bool node_exists( Key k, HashField::KeyData &kd ) const { kd = _hash[k] ; return kd.key != KEY_INV ; }
00177
00178
00179
00180 public:
00181
00183 void draw_plane ( real nx, real ny, real nz, real d ) ;
00184
00186 void draw_slice ( real nx, real ny, real nz, real d, float alpha ) ;
00187
00189 void draw_iso () { _mc.draw_surf() ; }
00190
00191
00192
00193 public :
00195 class geom_cell : public Cube
00196
00197 {
00198 friend class LeafOctree ;
00199
00200 protected:
00201 Key _key ;
00202 real _field ;
00203
00204
00205
00206 public:
00208 geom_cell( Key key_ = KEY_INV, real field_ = R_INV ) : Cube(key2cube(key_)), _key(key_), _field(field_) {}
00209
00211 geom_cell( HashField::KeyData kd ) : Cube(key2cube(kd.key)), _key(kd.key), _field(kd.data) {}
00212
00214 ~geom_cell() {}
00215
00217 geom_cell( const geom_cell &i ) : Cube(i), _key(i._key), _field(i._field) {}
00218
00220 geom_cell &operator = ( const geom_cell &i )
00221 { Cube::operator=(i) ; _key = i._key ; _field = i._field ; return *this; }
00222
00223
00224
00225
00226 public :
00228 inline Key key() const { return _key ; }
00230 inline Key &key() { return _key ; }
00231
00233 inline real operator*() const { return _field ; }
00234
00235
00236
00237 public :
00239 inline bool operator ==( const geom_cell &i ) const { return key() == i.key() ; }
00240
00242 inline bool operator !=( const geom_cell &i ) const { return key() != i.key() ; }
00243
00245 inline bool operator ()() const { return key() != KEY_INV ; }
00246 };
00247
00248 const geom_cell geom_root() const { const Key root_key = 1 ; return geom_cell( root_key, _hash[root_key].data ) ; }
00249 const geom_cell geom_key ( Key k ) const { return geom_cell( k, _hash[k].data ) ; }
00250
00251
00252
00253
00254
00255 public :
00257 class leaf_iterator
00258
00259 {
00260 friend class LeafOctree ;
00261
00262 protected:
00264 HashField::iterator _it ;
00265
00266
00267
00268 public:
00270 leaf_iterator( LeafOctree &o ) : _it( o._hash.begin() ) {}
00271
00273 ~leaf_iterator() {}
00274
00276 leaf_iterator( const leaf_iterator &i ) : _it(i._it) {}
00277
00279 leaf_iterator &operator = ( const leaf_iterator &i )
00280 { _it = i._it; return *this; }
00281
00282
00283
00284 public :
00286 inline bool operator ==( const leaf_iterator &i ) const { return _it == i._it ; }
00287
00289 inline bool operator !=( const leaf_iterator &i ) const { return _it != i._it ; }
00290
00292 inline bool operator ()() const { return _it() ; }
00293
00295 inline leaf_iterator &operator ++() { ++_it ; return *this ; }
00296
00297
00298
00299 public :
00300
00301 inline geom_cell top() const { return geom_cell( key(), *_it ) ; }
00302
00304 inline real &operator*() { return *_it ; }
00305
00307 inline Level lv() { return key_level(_it.key()) ; }
00308
00310 inline real sz() { return Cube(0,0,0,lv()).sz() ; }
00311
00313 inline Key key() const { return _it.key() ; }
00314
00316 inline bool is_leaf() const { return !is_inv(*_it) ; }
00317
00319 void draw_wire () const { top().draw_wire () ; }
00320
00321 };
00322 } ;
00323
00324
00325
00326 #else // HASH_HAS_ERASE
00327
00328 #include "opt_octree.h"
00329 typedef OptOctree LeafOctree ;
00330
00331 #endif // HASH_HAS_ERASE
00332