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< Polyhedron > | MATLAB2Polyhedron (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... | |
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:
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.
std::unique_ptr< Polyhedron > Utils::MATLAB2Polyhedron | ( | const mxArray * | mxV, |
const mxArray * | mxF | ||
) |
Conversion from MATLAB mesh representation to CGAL polyhedron representation.
*mxV | Pointer to the array of vertex locations. |
*mxF | Pointer to the array of facets. |
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.
polyhedron | CGAL polyhedron to be converted. |
points | Pointer to an array already allocated where the vertex locations are stored. |
facets | Pointer 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:
NB: MATLAB indices start at 1. Conversions automatically take care of the offset with C++.