An Implementation of the Marching Cubes Algorithm
1.0
|
00001 00026 #ifndef SURFBUILDER_HPP 00027 #define SURFBUILDER_HPP 00028 00029 #include <list> // std::list 00030 #include <vector> // std::vector 00031 00032 #include "exceptionobject.hpp" // commonlib::ExceptionObject 00033 #include "3dvector.hpp" // commonlib::t3DVector 00034 #include "grid.hpp" // mc::grid 00035 00036 00053 namespace mc { 00054 00055 00056 using common::t3DVector ; 00057 using common::ExceptionObject ; 00058 00059 00071 class SurfBuilder { 00072 public: 00073 // --------------------------------------------------------------- 00074 // 00075 // Type definitions 00076 // 00077 // --------------------------------------------------------------- 00078 00084 enum FACES { L , R , B , T , N , F } ; 00085 00086 00092 enum EDGES { 00093 LB , LT , LN , LF , 00094 RB , RT , RN , RF , 00095 BN , BF , TN , TF 00096 } ; 00097 00098 00104 enum VERTS { LBN , LBF , LTN , LTF , RBN , RBF , RTN , RTF } ; 00105 00106 00114 typedef std::list< unsigned > TRAVERSAL ; 00115 00116 00124 typedef std::list< TRAVERSAL > TABLEENTRY ; 00125 00126 00135 typedef std::vector< TABLEENTRY > LOOKUPTABLE ; 00136 00137 00138 // --------------------------------------------------------------- 00139 // 00140 // Public methods 00141 // 00142 // --------------------------------------------------------------- 00143 00153 SurfBuilder( Grid* g ) : _grid( g ) 00154 { 00155 _cubetable.resize( 256 ) ; 00156 } 00157 00158 00164 ~SurfBuilder() 00165 {} 00166 00167 00175 void run() ; 00176 00177 00178 private: 00179 // --------------------------------------------------------------- 00180 // 00181 // Private methods 00182 // 00183 // --------------------------------------------------------------- 00184 00195 void make_lookup_table() ; 00196 00197 00210 bool compute_sign( 00211 unsigned n , 00212 unsigned i 00213 ) 00214 const 00215 { 00216 return ( ( ( n ) >> ( i ) ) & 1 ) == 1 ; 00217 } 00218 00219 00229 VERTS get_1st_vertex( EDGES e ) const ; 00230 00231 00241 VERTS get_2nd_vertex( EDGES e ) const ; 00242 00243 00255 FACES left_face( EDGES e ) const ; 00256 00257 00269 FACES right_face( EDGES e ) const ; 00270 00271 00287 EDGES next_cw_edge( EDGES e , FACES f ) const ; 00288 00289 00302 FACES change_face( EDGES e , FACES f ) const 00303 { 00304 FACES index = left_face( e ) ; 00305 00306 return ( f == index ) ? right_face( e ) : index ; 00307 } 00308 00309 00325 unsigned from_index_to_id( 00326 unsigned i , 00327 unsigned j , 00328 unsigned k 00329 ) 00330 const 00331 { 00332 unsigned sx = _grid->get_size_x() ; 00333 unsigned sy = _grid->get_size_y() ; 00334 00335 return i + ( j * sx ) + ( k * sx * sy ) ; 00336 } 00337 00338 00362 void compute_intersection( unsigned i , unsigned j , unsigned k , 00363 VERTS v1 , VERTS v2 , double f1 , double f2 , t3DVector& pt ) 00364 const throw( ExceptionObject ) ; 00365 00366 // --------------------------------------------------------------- 00367 // 00368 // Private attributes 00369 // 00370 // --------------------------------------------------------------- 00371 00372 Grid* _grid ; 00373 LOOKUPTABLE _cubetable ; 00374 00375 } ; 00376 00377 00378 } // end of namespace mc 00379 00380 //end of group class. 00382 00383 #endif // SURFBUILDER_HPP