Go to the documentation of this file.00001
00010
00011
00012
00013 #pragma once
00014
00015 #if !defined(WIN32) || defined(__CYGWIN__)
00016 #pragma interface
00017 #endif // WIN32
00018
00019 #include <map>
00020 #include "morton.h"
00021 #include "point.h"
00022 #include "data_access.h"
00023
00024
00025
00033 typedef struct
00034 {
00035 int v1,v2,v3 ;
00036 } Triangle ;
00037
00038
00039
00040
00041
00046 class MarchingCubes
00047
00048 {
00049
00050 public :
00055 MarchingCubes () ;
00057 ~MarchingCubes() ;
00058
00059
00060
00061 public :
00063 inline const int nverts() const { return _nverts ; }
00065 inline const int ntrigs() const { return _ntrigs ; }
00067 inline Point * vert( const int i ) const { if( i < 0 || i >= _nverts ) return ( Point *)NULL ; return _vertices + i ; }
00069 inline Triangle * trig( const int i ) const { if( i < 0 || i >= _ntrigs ) return (Triangle*)NULL ; return _triangles + i ; }
00070
00072 inline Point *vertices () { return _vertices ; }
00074 inline Triangle *triangles() { return _triangles ; }
00075
00080 inline void set_method ( const bool originalMC = false ) { _originalMC = originalMC ; }
00081
00082
00084 void init_all () ;
00086 void clean_temps() ;
00088 void clean_all () ;
00089
00090
00091
00092
00093 public :
00098 void writeOFF( const char *fn ) ;
00099
00100
00101
00102
00103 public :
00105 real *cube () { return _cube ; }
00107 Point *space () { return _space; }
00109 Key *indexes() { return _indexes; }
00111 data_access *&dat_access() { return _dat_access ; }
00116 bool tesselate_cube( real iso ) ;
00117
00118 protected :
00120 bool process_cube () ;
00122 bool test_face ( schar face ) ;
00124 bool test_interior( schar s ) ;
00125
00126
00127
00128
00129 protected :
00131 bool compute_intersection_points() ;
00132
00139 void add_triangle ( const char* trig, char n, int v12 = -1 ) ;
00140
00142 void test_vertex_addition() ;
00144 bool add_vertex( char i, char j ) ;
00146 int get_vertex( char i, char j ) { std::map< std::pair< Key,Key >, int >::const_iterator it = _stored_vertices.find( std::make_pair( _indexes[i],_indexes[j] ) ) ; if( it == _stored_vertices.end() ) return -1 ; else return it->second ; }
00148 int add_c_vertex() ;
00149
00151 void print_cube() ;
00152
00153 public:
00155 void draw_surf() { Triangle *ptr = _triangles ; for( int i = 0 ; i < _ntrigs ; ++i, ++ptr ) { _vertices[ptr->v1].draw() ; _vertices[ptr->v2].draw() ; _vertices[ptr->v3].draw() ; } }
00156
00157
00158
00159 protected :
00160 bool _originalMC ;
00162 int _nverts ;
00163 int _ntrigs ;
00164 int _Nverts ;
00165 int _Ntrigs ;
00166 Point *_vertices ;
00167 Triangle *_triangles ;
00169 std::map< std::pair< Key,Key >, int > _stored_vertices ;
00170
00171 real _cube[8] ;
00172 Point _space[8] ;
00173 Key _indexes[8] ;
00174 uchar _lut_entry ;
00175 uchar _case ;
00176 uchar _config ;
00177 uchar _subconfig ;
00178 data_access *_dat_access ;
00179 };
00180
00181
00182