Class MarchingCubes

Class Documentation

class MarchingCubes

Marching Cubes algorithm.

Marching Cubes algorithm wrapper

Public Functions

MarchingCubes(const int size_x = -1, const int size_y = -1, const int size_z = -1)

constructor

Main and default constructor

Parameters
  • size_x – width of the grid

  • size_y – depth of the grid

  • size_z – height of the grid

MarchingCubes(puma::Matrix<float> *workspace, std::vector<puma::Triangle<float>> *tris)
~MarchingCubes()

Destructor

inline Vertex *vert(const int i) const

accesses the number of vertices of the generated mesh accesses the number of triangles of the generated mesh accesses a specific vertex of the generated mesh

inline Triangle *triangles()

accesses a specific triangle of the generated mesh accesses the vertex buffer of the generated mesh accesses the triangle buffer of the generated mesh

inline void set_resolution(const int size_x, const int size_y, const int size_z)

accesses the width of the grid accesses the depth of the grid accesses the height of the grid changes the size of the grid

Parameters
  • size_x – width of the grid

  • size_y – depth of the grid

  • size_z – height of the grid

inline const real_mc get_data(const int i, const int j, const int k) const

selects wether the algorithm will use the enhanced topologically controlled lookup table or the original MarchingCubes

Parameters
  • originalMC – true for the original Marching Cubes selects to use data from another class

  • data – is the pointer to the external data, allocated as a size_x*size_y*size_z vector running in x first selects to allocate data accesses a specific cube of the grid

  • i – abscisse of the cube

  • j – ordinate of the cube

  • k – height of the cube

void init_temps()

sets a specific cube of the grid

Parameters
  • val – new value for the cube

  • i – abscisse of the cube

  • j – ordinate of the cube

  • k – height of the cube inits temporary structures (must set sizes before call) : the grid and the vertex index per cube

void init_all()

inits all structures (must set sizes before call) : the temporary structures and the mesh buffers

void clean_temps()

clears temporary structures : the grid and the main

void clean_all()

clears all structures : the temporary structures and the mesh buffers

void run(real_mc iso = (real_mc)0.0)

PLY exportation of the generated mesh

Parameters
  • fn – name of the PLY file to create

  • bin – if true, the PLY will be written in binary mode PLY importation of a mesh

  • fn – name of the PLY file to read from VRML / Open Inventor exportation of the generated mesh

  • fn – name of the IV file to create ISO exportation of the input grid

  • fn – name of the ISO file to create Main algorithm : must be called after init_all

  • iso – isovalue

Protected Functions

void process_cube()

tesselates one cube

bool test_face(schar face)

tests if the components of the tesselation of the cube should be connected by the interior of an ambiguous face

bool test_interior(schar s)

tests if the components of the tesselation of the cube should be connected through the interior of the cube

void convertToPuMA()
void compute_intersection_points(real_mc iso)

computes almost all the vertices of the mesh by interpolation along the cubes edges

Parameters

iso – isovalue

void add_triangle(const char *trig, char n, int v12 = -1)

routine to add a triangle to the mesh

Parameters
  • trig – the code for the triangle as a sequence of edges index

  • n – the number of triangles to produce

  • v12 – the index of the interior vertex to use, if necessary

void test_vertex_addition()

tests and eventually doubles the vertex buffer capacity for a new vertex insertion

int add_x_vertex()

adds a vertex on the current horizontal edge

int add_y_vertex()

adds a vertex on the current longitudinal edge

int add_z_vertex()

adds a vertex on the current vertical edge

int add_c_vertex()

adds a vertex inside the current cube

real_mc get_x_grad(const int i, const int j, const int k) const

interpolates the horizontal gradient of the implicit function at the lower vertex of the specified cube

Parameters
  • i – abscisse of the cube

  • j – ordinate of the cube

  • k – height of the cube

real_mc get_y_grad(const int i, const int j, const int k) const

interpolates the longitudinal gradient of the implicit function at the lower vertex of the specified cube

Parameters
  • i – abscisse of the cube

  • j – ordinate of the cube

  • k – height of the cube

real_mc get_z_grad(const int i, const int j, const int k) const

interpolates the vertical gradient of the implicit function at the lower vertex of the specified cube

Parameters
  • i – abscisse of the cube

  • j – ordinate of the cube

  • k – height of the cube

inline int get_x_vert(const int i, const int j, const int k) const

accesses the pre-computed vertex index on the lower horizontal edge of a specific cube

Parameters
  • i – abscisse of the cube

  • j – ordinate of the cube

  • k – height of the cube

inline int get_y_vert(const int i, const int j, const int k) const

accesses the pre-computed vertex index on the lower longitudinal edge of a specific cube

Parameters
  • i – abscisse of the cube

  • j – ordinate of the cube

  • k – height of the cube

inline int get_z_vert(const int i, const int j, const int k) const

accesses the pre-computed vertex index on the lower vertical edge of a specific cube

Parameters
  • i – abscisse of the cube

  • j – ordinate of the cube

  • k – height of the cube

inline void set_x_vert(const int val, const int i, const int j, const int k)

sets the pre-computed vertex index on the lower horizontal edge of a specific cube

Parameters
  • val – the index of the new vertex

  • i – abscisse of the cube

  • j – ordinate of the cube

  • k – height of the cube

inline void set_y_vert(const int val, const int i, const int j, const int k)

sets the pre-computed vertex index on the lower longitudinal edge of a specific cube

Parameters
  • val – the index of the new vertex

  • i – abscisse of the cube

  • j – ordinate of the cube

  • k – height of the cube

inline void set_z_vert(const int val, const int i, const int j, const int k)

sets the pre-computed vertex index on the lower vertical edge of a specific cube

Parameters
  • val – the index of the new vertex

  • i – abscisse of the cube

  • j – ordinate of the cube

  • k – height of the cube

void print_cube()

prints cube for debug

Protected Attributes

bool _originalMC

selects wether the algorithm will use the enhanced topologically controlled lookup table or the original MarchingCubes

bool _ext_data

selects wether to allocate data or use data from another class

int _size_x

width of the grid

int _size_y

depth of the grid

int _size_z

height of the grid

real_mc *_data

implicit function values sampled on the grid

int *_x_verts

pre-computed vertex indices on the lower horizontal edge of each cube

int *_y_verts

pre-computed vertex indices on the lower longitudinal edge of each cube

int *_z_verts

pre-computed vertex indices on the lower vertical edge of each cube

int _nverts

number of allocated vertices in the vertex buffer

int _ntrigs

number of allocated triangles in the triangle buffer

int _Nverts

size of the vertex buffer

int _Ntrigs

size of the triangle buffer

Vertex *_vertices

vertex buffer

Triangle *_triangles

triangle buffer

int _i = {}

abscisse of the active cube

int _j = {}

height of the active cube

int _k = {}

ordinate of the active cube

real_mc _cube[8] = {}

values of the implicit function on the active cube

uchar _lut_entry = {}

cube sign representation in [0..255]

uchar _case = {}

case of the active cube in [0..15]

uchar _config = {}

configuration of the active cube

uchar _subconfig = {}

subconfiguration of the active cube

puma::Matrix<float> *workspace = {}
std::vector<puma::Triangle<float>> *tris = {}