mesh_conv::MC_grid_3d_scalar_marching_cube Class Reference

helper to apply marching cube on a volume data More...

#include <MC_grid_3d_scalar_marching_cube.hpp>

List of all members.

Static Public Member Functions

static MC_mesh_index_vector marching_cube (const MC_grid_3d_scalar &values, const double &isovalue=0.0)
 apply marching cube on data

Static Private Member Functions

static void create_polygon (const std::vector< double > &cell_value, const int &type_of_cube, const MC_int_vector &x, MC_mesh_index_vector *mesh, std::map< MC_int_pair, unsigned int, MC_int_pair_less > *edge_to_vertex_index, const MC_grid_3d_scalar &potential)
 add polygons corresponding to the current cell in the mesh

Static Private Attributes

static int EdgeTable [256]
static int TriangulationTable [256][16]

Detailed Description

helper to apply marching cube on a volume data

Definition at line 16 of file MC_grid_3d_scalar_marching_cube.hpp.


Member Function Documentation

void mesh_conv::MC_grid_3d_scalar_marching_cube::create_polygon ( const std::vector< double > &  cell_value,
const int &  type_of_cube,
const MC_int_vector x,
MC_mesh_index_vector mesh,
std::map< MC_int_pair, unsigned int, MC_int_pair_less > *  edge_to_vertex_index,
const MC_grid_3d_scalar potential 
) [static, private]

add polygons corresponding to the current cell in the mesh

Definition at line 77 of file MC_grid_3d_scalar_marching_cube.cpp.

References mesh_conv::MC_int_vector_vector::add(), mesh_conv::MC_v3d_vector::add(), mesh_conv::MC_int_vector::add(), mesh_conv::MC_mesh_index_vector::connectivity(), mesh_conv::MC_grid_3d_scalar::convert_voxel_index_to_real(), EdgeTable, mesh_conv::MC_mesh_index_vector::point_set(), mesh_conv::MC_grid_3d_scalar::size(), TriangulationTable, and mesh_conv::MC_mesh_index_vector::vertex_number().

Referenced by marching_cube().

00078     {
00079 
00080         MC_int_vector dim=potential.size();
00081 
00082 
00083         MC_v3d X000=(x+MC_int_vector(0,0,0)).to_v3d();//0
00084         MC_v3d X001=(x+MC_int_vector(0,0,1)).to_v3d();//1
00085         MC_v3d X010=(x+MC_int_vector(0,1,0)).to_v3d();//2
00086         MC_v3d X011=(x+MC_int_vector(0,1,1)).to_v3d();//3
00087         MC_v3d X100=(x+MC_int_vector(1,0,0)).to_v3d();//4
00088         MC_v3d X101=(x+MC_int_vector(1,0,1)).to_v3d();//5
00089         MC_v3d X110=(x+MC_int_vector(1,1,0)).to_v3d();//6
00090         MC_v3d X111=(x+MC_int_vector(1,1,1)).to_v3d();//7
00091 
00092         //id of the vertex in the grid (+2 added because the grid is arbitrarily extended)
00093         std::vector <int> vertex_id(12);
00094         vertex_id[0]=(x[0]+0)+(dim[0]+2)*( (x[1]+0) + (dim[1]+2)*(x[2]+0) );
00095         vertex_id[1]=(x[0]+0)+(dim[0]+2)*( (x[1]+0) + (dim[1]+2)*(x[2]+1) );
00096         vertex_id[2]=(x[0]+0)+(dim[0]+2)*( (x[1]+1) + (dim[1]+2)*(x[2]+0) );
00097         vertex_id[3]=(x[0]+0)+(dim[0]+2)*( (x[1]+1) + (dim[1]+2)*(x[2]+1) );
00098         vertex_id[4]=(x[0]+1)+(dim[0]+2)*( (x[1]+0) + (dim[1]+2)*(x[2]+0) );
00099         vertex_id[5]=(x[0]+1)+(dim[0]+2)*( (x[1]+0) + (dim[1]+2)*(x[2]+1) );
00100         vertex_id[6]=(x[0]+1)+(dim[0]+2)*( (x[1]+1) + (dim[1]+2)*(x[2]+0) );
00101         vertex_id[7]=(x[0]+1)+(dim[0]+2)*( (x[1]+1) + (dim[1]+2)*(x[2]+1) );
00102 
00103         //convert EDGE_ID to PAIR OF VERTEX ID
00104         std::vector<MC_int_pair> Edge_to_vertex_id(12);
00105         Edge_to_vertex_id[ 0]=MC_int_pair(0,4);
00106         Edge_to_vertex_id[ 1]=MC_int_pair(4,5);
00107         Edge_to_vertex_id[ 2]=MC_int_pair(5,1);
00108         Edge_to_vertex_id[ 3]=MC_int_pair(1,0);
00109 
00110         Edge_to_vertex_id[ 4]=MC_int_pair(2,6);
00111         Edge_to_vertex_id[ 5]=MC_int_pair(6,7);
00112         Edge_to_vertex_id[ 6]=MC_int_pair(7,3);
00113         Edge_to_vertex_id[ 7]=MC_int_pair(3,2);
00114 
00115         Edge_to_vertex_id[ 8]=MC_int_pair(0,2);
00116         Edge_to_vertex_id[ 9]=MC_int_pair(4,6);
00117         Edge_to_vertex_id[10]=MC_int_pair(5,7);
00118         Edge_to_vertex_id[11]=MC_int_pair(1,3);
00119 
00120 
00121 
00122         //check every edge
00123         std::vector <MC_v3d> edge_position(12);
00124 
00125 
00126             // ******************************* //
00127             // TO DO: Mettre en place les interpolation linéaire (et non le point milieu)
00128             // ******************************* //
00129 
00130         if(EdgeTable[type_of_cube] & 0x001)
00131             edge_position[ 0] = (X000+X100)/2.0;
00132         if(EdgeTable[type_of_cube] & 0x002)
00133             edge_position[ 1] = (X100+X101)/2.0;
00134         if(EdgeTable[type_of_cube] & 0x004)
00135             edge_position[ 2] = (X101+X001)/2.0;
00136         if(EdgeTable[type_of_cube] & 0x008)
00137             edge_position[ 3] = (X001+X000)/2.0;
00138 
00139         if(EdgeTable[type_of_cube] & 0x010)
00140             edge_position[ 4] = (X010+X110)/2.0;
00141         if(EdgeTable[type_of_cube] & 0x020)
00142             edge_position[ 5] = (X110+X111)/2.0;
00143         if(EdgeTable[type_of_cube] & 0x040)
00144             edge_position[ 6] = (X111+X011)/2.0;
00145         if(EdgeTable[type_of_cube] & 0x080)
00146             edge_position[ 7] = (X011+X010)/2.0;
00147 
00148         if(EdgeTable[type_of_cube] & 0x100)
00149             edge_position[ 8] = (X000+X010)/2.0;
00150         if(EdgeTable[type_of_cube] & 0x200)
00151             edge_position[ 9] = (X100+X110)/2.0;
00152         if(EdgeTable[type_of_cube] & 0x400)
00153             edge_position[10] = (X101+X111)/2.0;
00154         if(EdgeTable[type_of_cube] & 0x800)
00155             edge_position[11] = (X001+X011)/2.0;
00156 
00157 
00158         // triangulation
00159         int triangulation_index=0;
00160         int k_vertex=0;
00161         for(triangulation_index=0;TriangulationTable[type_of_cube][triangulation_index]!=-1;triangulation_index+=3)
00162         {
00163             MC_int_vector index_polygon;
00164             for(k_vertex=0;k_vertex<3;k_vertex++)
00165             {
00166 
00167 
00168                 MC_int_pair local_edge=Edge_to_vertex_id[TriangulationTable[type_of_cube][triangulation_index+k_vertex]];
00169                 MC_int_pair current_edge_id=MC_int_pair(vertex_id[local_edge[0]],vertex_id[local_edge[1]]);
00170 
00171                 // ******************************* //
00172                 // TO DO: Eviter les duplicats de sommets
00173                 // si current_edge_id(i,j) existe deja dans le maillage, alors index_polygon.add(l'indice existant déjà)
00174                 //                                                       sinon index_polygon.add(nombre de sommet actuel) et mesh->point_setmesh->point_set().add(potential.convert_voxel_index_to_real(y));
00175                 // ******************************* //
00176                 index_polygon.add(mesh->vertex_number());
00177                 MC_v3d y=edge_position[TriangulationTable[type_of_cube][triangulation_index+k_vertex]];
00178                 mesh->point_set().add(potential.convert_voxel_index_to_real(y));
00179             }
00180             mesh->connectivity().add(index_polygon);
00181         }
00182 
00183     }

Here is the call graph for this function:

Here is the caller graph for this function:

MC_mesh_index_vector mesh_conv::MC_grid_3d_scalar_marching_cube::marching_cube ( const MC_grid_3d_scalar values,
const double &  isovalue = 0.0 
) [static]

apply marching cube on data

Definition at line 11 of file MC_grid_3d_scalar_marching_cube.cpp.

References create_polygon(), EdgeTable, mesh_conv::MC_grid_3d_scalar::get(), mesh_conv::MC_grid_3d_scalar::is_within_bound_voxel(), and mesh_conv::MC_grid_3d_scalar::size().

00012     {
00013 
00014         MC_mesh_index_vector mesh;
00015         std::map<MC_int_pair,unsigned int,MC_int_pair_less> edge_to_vertex_index;
00016 
00017         const MC_int_vector& dim=values.size();
00018 
00019         std::vector<double> current_cell_value(8);
00020 
00021         //loop over every cells
00022         for(int k_1=-1;k_1<dim[0];++k_1)
00023         {
00024             for(int k_2=-1;k_2<dim[1];++k_2)
00025             {
00026                 for(int k_3=-1;k_3<dim[2];++k_3)
00027                 {
00028                     //position of local cell
00029                     MC_int_vector X000=MC_int_vector(k_1+0,k_2+0,k_3+0);
00030                     MC_int_vector X001=MC_int_vector(k_1+0,k_2+0,k_3+1);
00031                     MC_int_vector X010=MC_int_vector(k_1+0,k_2+1,k_3+0);
00032                     MC_int_vector X011=MC_int_vector(k_1+0,k_2+1,k_3+1);
00033                     MC_int_vector X100=MC_int_vector(k_1+1,k_2+0,k_3+0);
00034                     MC_int_vector X101=MC_int_vector(k_1+1,k_2+0,k_3+1);
00035                     MC_int_vector X110=MC_int_vector(k_1+1,k_2+1,k_3+0);
00036                     MC_int_vector X111=MC_int_vector(k_1+1,k_2+1,k_3+1);
00037 
00038                     
00039                     //value of cell
00040                     current_cell_value[0]=values.is_within_bound_voxel(X000)?values.get(X000)-isovalue:-1;
00041                     current_cell_value[1]=values.is_within_bound_voxel(X001)?values.get(X001)-isovalue:-1;
00042                     current_cell_value[2]=values.is_within_bound_voxel(X010)?values.get(X010)-isovalue:-1;
00043                     current_cell_value[3]=values.is_within_bound_voxel(X011)?values.get(X011)-isovalue:-1;
00044                     current_cell_value[4]=values.is_within_bound_voxel(X100)?values.get(X100)-isovalue:-1;
00045                     current_cell_value[5]=values.is_within_bound_voxel(X101)?values.get(X101)-isovalue:-1;
00046                     current_cell_value[6]=values.is_within_bound_voxel(X110)?values.get(X110)-isovalue:-1;
00047                     current_cell_value[7]=values.is_within_bound_voxel(X111)?values.get(X111)-isovalue:-1;
00048 
00049 
00050 
00051 
00052                     //select the type of cube
00053                     int type_of_cube=0;
00054                     if(current_cell_value[0]<=0) type_of_cube |= 0x01;
00055                     if(current_cell_value[4]<=0) type_of_cube |= 0x02;
00056                     if(current_cell_value[5]<=0) type_of_cube |= 0x04;
00057                     if(current_cell_value[1]<=0) type_of_cube |= 0x08;
00058                     if(current_cell_value[2]<=0) type_of_cube |= 0x10;
00059                     if(current_cell_value[6]<=0) type_of_cube |= 0x20;
00060                     if(current_cell_value[7]<=0) type_of_cube |= 0x40;
00061                     if(current_cell_value[3]<=0) type_of_cube |= 0x80;
00062 
00063 
00064 
00065                     //look at the LUT to get the corresponding type
00066                     if(EdgeTable[type_of_cube]!=0)
00067                         create_polygon(current_cell_value,type_of_cube,X000,&mesh,&edge_to_vertex_index,values);
00068 
00069                 }
00070             }
00071         }
00072 
00073         return mesh;
00074 
00075     }

Here is the call graph for this function:


Member Data Documentation

/brief helper indexation for the marching cube

Definition at line 36 of file MC_grid_3d_scalar_marching_cube.hpp.

Referenced by create_polygon(), and marching_cube().

/brief helper indexation for the marching cube

Definition at line 38 of file MC_grid_3d_scalar_marching_cube.hpp.

Referenced by create_polygon().


The documentation for this class was generated from the following files:

Generated on Sun Apr 18 20:24:48 2010 by  doxygen 1.6.1