MSDM
 All Classes Namespaces Files Functions Variables Typedefs Pages
Classes | Functions
Utils Namespace Reference

Procedures to convert between MATLAB and CGAL mesh representations. More...

Classes

class  polyhedron_builder
 Builder class for a triangle surface mesh based on a list of facets and vertices. More...
 

Functions

std::unique_ptr< PolyhedronMATLAB2Polyhedron (const mxArray *mxV, const mxArray *mxF)
 Conversion from MATLAB mesh representation to CGAL polyhedron representation. More...
 
void Polyhedron2MATLAB (const Polyhedron &polyhedron, double *points, double *facets)
 Conversion from CGAL polyhedron to a MATLAB-compatible representation of the mesh. More...
 

Detailed Description

Procedures to convert between MATLAB and CGAL mesh representations.

MATLAB representations for meshes are based on pairs of arrays \((\mathbb{V},\mathbb{F})\), where \(\mathbb{V}\) is a 3-row array indicating the vertex locations, and \(\mathbb{F}\) is a 3-row array indicating the links between vertices that form facets. This representation is straightforwardly taken from the Object File Format, whereas CGAL uses a halfedge data structure http://doc.cgal.org/latest/HalfedgeDS/index.html.

This namespace provides 2 conversion routines:

  1. conversion from MATLAB arrays to CGAL polyhedron: Utils::MATLAB2Polyhedron;
  2. conversion from CGAL polyhedron to already allocated MATLAB arrays: Utils::Polyhedron2MATLAB.

Conversions from MATLAB to CGAL rely on a specialized polyhedron builder class http://doc.cgal.org/latest/Polyhedron/classCGAL_1_1Polyhedron__incremental__builder__3.html. The Polyhedron class is a prevously defined type inheriting from CGAL::Polyhedron_3<K> (see MatlabPolyhedron.h), a.k.a. a CGAL polyhedron.

Function Documentation

std::unique_ptr< Polyhedron > Utils::MATLAB2Polyhedron ( const mxArray *  mxV,
const mxArray *  mxF 
)

Conversion from MATLAB mesh representation to CGAL polyhedron representation.

Parameters
*mxVPointer to the array of vertex locations.
*mxFPointer to the array of facets.
Returns
A pointer to a CGAL polyhedron.

MATLAB mesh representation consists of two matrices listing the vertex locations and the facets. The return type must be a preset typedef. To avoid deallocation issues, the instance of the return object is wrapped in a unique_ptr (see http://www.cplusplus.com/reference/memory/unique_ptr/).

NB: MATLAB indices start at 1. Conversions automatically take care of the offset with C++.

void Utils::Polyhedron2MATLAB ( const Polyhedron polyhedron,
double *  points,
double *  facets 
)

Conversion from CGAL polyhedron to a MATLAB-compatible representation of the mesh.

Parameters
polyhedronCGAL polyhedron to be converted.
pointsPointer to an array already allocated where the vertex locations are stored.
facetsPointer to an array already allocated where the facets are stored.

Because MATLAB systematically uses double type, facet indices and vertex locations are expressed with double. Calls to this function are responsible for the allocation and destruction of both arrays filled. Use polyhedron member functions size_of_vertices() and size_of_facets(). For instance, using a pointer pP1 to a polyhedron object:

mxArray* Mpoints = mxCreateDoubleMatrix(3, pP1->size_of_vertices(), mxREAL);
mxArray* MFacets = mxCreateDoubleMatrix(3, pP1->size_of_facets(), mxREAL);
Utils::Polyhedron2MATLAB(*pP1, mxGetPr(Mpoints), mxGetPr(MFacets));

NB: MATLAB indices start at 1. Conversions automatically take care of the offset with C++.