Public Types | Public Member Functions | Static Public Member Functions
sal3d::Mesh Class Reference

Structure defining a surface composed of vertices and triangles. More...

#include <Mesh.hpp>

List of all members.

Public Types

typedef sal3d_mesh_triangle Triangle
 A triangle belonging to a Mesh.
typedef sal3d_mesh_vertex Vertex
 A vertex of a Mesh.
typedef Array1D< TriangleTriangles
 An array of Triangles in a Mesh.
typedef Array1D< VertexVertices
 An array of Vertices in a Mesh.

Public Member Functions

 Mesh (int numVertices=0, int numTriangles=0)
 Default constructor. Creates an empty Mesh, with the given number of vertices and triangles.
 Mesh (const sal3d::COP &cop)
 Constructor from COP. Creates a Mesh with the COP surface.
 Mesh (const Mesh &mesh)
 Copy constructor.
 Mesh (sal3d_mesh mesh)
 Constructor from a C sal3d_mesh. Creates a new C++ object that holds it.
 Mesh (const Mesh &mesh, const Movement3D &movement)
 Constructor from a moved Mesh.
 ~Mesh ()
 Destructor.
void clear ()
 Clear the Mesh.
bool isEmpty ()
 Checks if the Mesh is empty.
void mergeMesh (const Mesh &mesh)
 Merge the passed Mesh to the current one.
int getNumTriangles () const
 Get the number of Triangles of the Mesh.
int getNumVertices () const
 Get the number of Vertices of the Mesh.
void addTriangles (const std::vector< Vertex > &vertices, const std::vector< Triangle > &triangles)
 Add the list of Vertices and Triangles to the Mesh.
void addTriangles (const Vertices &vertices, const Triangles &triangles)
 Add the list of Vertices and Triangles to the Mesh.
const Triangles getTriangles () const
 Get the array of Triangles that define the Mesh.
Triangles getTriangles ()
 Get the array of Triangles that define the Mesh.
const Vertices getVertices () const
 Get the array of Vertices that comprise the Mesh.
Vertices getVertices ()
 Get the array of Vertices that comprise the Mesh.
void exportToBinaryPLY (const std::string &filename) const
 Export the Mesh to a PLY binary file.
void exportToASCIIPLY (const std::string &filename) const
 Export the Mesh to a PLY ASCII file.
void exportToBinarySTL (const std::string &filename, const std::string &header=std::string("")) const
 Export the Mesh to a STL binary file.
void exportToASCIISTL (const std::string &filename) const
 Export the Mesh to a STL ASCII file.
Meshoperator= (const Mesh &aMesh)
 Assignment operator.
sal3d_mesh c_mesh () const
 Returns the pointer to the internal C mesh.
void glPaintPoints () const
 Issue gl instructions to paint the Mesh as points.
void glPaintRandomPoints (int num_points) const
 Paints numberPoints random points of the Mesh.
void glPaintPolygons () const
 Issue gl instructions to paint the Mesh as polygons.
Mesh copy () const
 Get a deep copy of the Mesh.
void cropGL (const Projection2D &projection, const Polygon2D &polygon2d, bool keepInsidePoints=true)
 Crop the Mesh as defined by a Polygon2D.
void cropGL (const std::vector< Projection2D > &projections, const std::vector< Polygon2D > &polygons, bool keepInsidePoints=true)
 Crop the Mesh as defined by a set of Polygon2D objects.

Static Public Member Functions

static Mesh MeshFromPLY (const std::string &filename)
 Creates a Mesh from a PLY file.
static Mesh MeshFromSTL (const std::string &filename)
 Creates a Mesh from a STL file.

Detailed Description

Structure defining a surface composed of vertices and triangles.

This class requires linking with core3d.lib (import library for core3d.dll).

A Mesh is a structure that defines a surface composed of a series of points and triangles.

In sal3d, a Mesh is the result of using the Integrator tool. This objects can then be exported to both PLY and STL file formats, to be read in many of the common programs that deal with 3D structures.

It is also possible to get the Vertices and Triangles of a Mesh through the appropriate methods, and to add more Vertices and Triangles with the use of addTriangles.


Constructor & Destructor Documentation

sal3d::Mesh::Mesh ( int  numVertices = 0,
int  numTriangles = 0 
) [inline]

Default constructor. Creates an empty Mesh, with the given number of vertices and triangles.

Exceptions:
sal3d::ErrorOn error

Referenced by copy(), MeshFromPLY(), and MeshFromSTL().

sal3d::Mesh::Mesh ( const sal3d::COP cop) [inline]

Constructor from COP. Creates a Mesh with the COP surface.

Exceptions:
sal3d::ErrorOn error

References sal3d::COP::c_cop().

sal3d::Mesh::Mesh ( const Mesh mesh) [inline]

Copy constructor.

Exceptions:
sal3d::ErrorOn error
sal3d::Mesh::Mesh ( sal3d_mesh  mesh) [inline, explicit]

Constructor from a C sal3d_mesh. Creates a new C++ object that holds it.

Warning:
The new C++ Mesh object will get the ownership of the mesh. That means that you should not call sal3d_mesh_release() on this mesh, otherwise it would be called twice.
Parameters:
[in]meshThe C sal3d_mesh used to create this object.
Exceptions:
sal3d::ErrorOn error
sal3d::Mesh::Mesh ( const Mesh mesh,
const Movement3D movement 
) [inline]

Constructor from a moved Mesh.

Parameters:
[in]meshThe original Mesh to be moved.
[in]movementThe Movement3D matrix that specifies the transformation to be applied to the mesh.
Exceptions:
sal3d::ErrorOn error

References c_mesh(), and sal3d::Movement3D::c_movement_3d().

sal3d::Mesh::~Mesh ( ) [inline]

Destructor.

If the reference counter reaches zero, the object is destroyed and its memory released.


Member Function Documentation

void sal3d::Mesh::addTriangles ( const std::vector< Vertex > &  vertices,
const std::vector< Triangle > &  triangles 
) [inline]

Add the list of Vertices and Triangles to the Mesh.

Parameters:
[in]verticesThe vector of vertices to add to the Mesh.
[in]trianglesThe vector of triangles to add to the Mesh.
Exceptions:
sal3d::ErrorOn error

Referenced by mergeMesh().

void sal3d::Mesh::addTriangles ( const Vertices vertices,
const Triangles triangles 
) [inline]

Add the list of Vertices and Triangles to the Mesh.

Parameters:
[in]verticesThe list of vertices to add to the Mesh.
[in]trianglesThe list of triangles to add to the Mesh.
Exceptions:
sal3d::ErrorOn error

References sal3d::Array1D< T >::length().

sal3d_mesh sal3d::Mesh::c_mesh ( ) const [inline]

Returns the pointer to the internal C mesh.

Warning:
Never ever call sal3d_mesh_release() with the pointer returned by this function or the application will fail.
Returns:
The pointer to sal3d's mesh C interface.

Referenced by Mesh().

void sal3d::Mesh::clear ( ) [inline]

Clear the Mesh.

All the Vertices and Triangles of the Mesh are dropped, so the result is an empty Mesh with no Vertices or Triangles.

Mesh sal3d::Mesh::copy ( ) const [inline]

Get a deep copy of the Mesh.

This means that the object and its memory is duplicated. More information about this can be fount at Memory management: reference counting.

Returns:
A Mesh which is a deep copy of this Mesh.
Exceptions:
sal3d::ErrorOn error

References Mesh().

void sal3d::Mesh::cropGL ( const Projection2D projection,
const Polygon2D polygon2d,
bool  keepInsidePoints = true 
) [inline]

Crop the Mesh as defined by a Polygon2D.

This function is mainly targeted for use with 2D viewports, the usual case being a GL 2D viewport, with the polygon defined in pixel units. The Mesh is projected to the viewport and what falls outside (when keepInsidePoints is true) the polygon is removed, and vice versa.

Parameters:
[in]projectionThe projection matrix used to project the Mesh to 2D.
[in]polygon2dThe polygon to define the desired region.
[in]keepInsidePointsIf true (default), the points that fall outside the polygon are removed, if false they are the ones that are kept.
Exceptions:
sal3d::ErrorOn error
void sal3d::Mesh::cropGL ( const std::vector< Projection2D > &  projections,
const std::vector< Polygon2D > &  polygons,
bool  keepInsidePoints = true 
) [inline]

Crop the Mesh as defined by a set of Polygon2D objects.

This function is mainly targeted for use with 2D viewports, the usual case being a GL 2D viewport, with the polygons defined in pixel units. The Mesh is projected to the viewport and what falls outside (when keepInsidePoints is true) the polygons is removed, and vice versa.

Parameters:
[in]projectionsThe vector of projection matrices used to project the Mesh to 2D.
[in]polygonsThe polygons to define the desired region.
[in]keepInsidePointsIf true (default), the points that fall outside the polygons are removed, if false they are the ones that are kept.
Exceptions:
sal3d::ErrorOn error
void sal3d::Mesh::exportToASCIIPLY ( const std::string &  filename) const [inline]

Export the Mesh to a PLY ASCII file.

Parameters:
[in]filenameThe file name to save the Mesh.
Exceptions:
sal3d::ErrorOn error
void sal3d::Mesh::exportToASCIISTL ( const std::string &  filename) const [inline]

Export the Mesh to a STL ASCII file.

Parameters:
[in]filenameThe file name to save the Mesh.
Exceptions:
sal3d::ErrorOn error
void sal3d::Mesh::exportToBinaryPLY ( const std::string &  filename) const [inline]

Export the Mesh to a PLY binary file.

Parameters:
[in]filenameThe file name to save the Mesh.
Exceptions:
sal3d::ErrorOn error
void sal3d::Mesh::exportToBinarySTL ( const std::string &  filename,
const std::string &  header = std::string("") 
) const [inline]

Export the Mesh to a STL binary file.

Parameters:
[in]filenameThe file name to save the Mesh.
[in]headerA text that will be written as the header of the STL
Exceptions:
sal3d::ErrorOn error
int sal3d::Mesh::getNumTriangles ( ) const [inline]

Get the number of Triangles of the Mesh.

Returns:
The number of Triangles in the Mesh.
Exceptions:
sal3d::ErrorOn error

Referenced by getTriangles(), and isEmpty().

int sal3d::Mesh::getNumVertices ( ) const [inline]

Get the number of Vertices of the Mesh.

Returns:
The number of Vertices in the Mesh.
Exceptions:
sal3d::ErrorOn error

Referenced by getVertices(), and isEmpty().

const Triangles sal3d::Mesh::getTriangles ( ) const [inline]

Get the array of Triangles that define the Mesh.

Returns:
The Triangles array that defines the Mesh.
Exceptions:
sal3d::ErrorOn error

References getNumTriangles().

Referenced by getTriangles(), and mergeMesh().

Get the array of Triangles that define the Mesh.

Returns:
The Triangles array that defines the Mesh.
Exceptions:
sal3d::ErrorOn error

References getTriangles().

const Vertices sal3d::Mesh::getVertices ( ) const [inline]

Get the array of Vertices that comprise the Mesh.

Returns:
The Vertices array with all the points in the Mesh.
Exceptions:
sal3d::ErrorOn error

References getNumVertices().

Referenced by getVertices(), and mergeMesh().

Get the array of Vertices that comprise the Mesh.

Returns:
The Vertices array with all the points in the Mesh.
Exceptions:
sal3d::ErrorOn error

References getVertices().

void sal3d::Mesh::glPaintPoints ( ) const [inline]

Issue gl instructions to paint the Mesh as points.

Exceptions:
sal3d::ErrorOn error
void sal3d::Mesh::glPaintPolygons ( ) const [inline]

Issue gl instructions to paint the Mesh as polygons.

Exceptions:
sal3d::ErrorOn error
void sal3d::Mesh::glPaintRandomPoints ( int  num_points) const [inline]

Paints numberPoints random points of the Mesh.

Useful in an sceneario where you wish to paint quick simplified version of the Mesh. In fast painting while moving it by the mouse, for example.

Exceptions:
sal3d::ErrorOn error
bool sal3d::Mesh::isEmpty ( ) [inline]

Checks if the Mesh is empty.

Returns:
True if the Mesh is empty, false otherwise.

References getNumTriangles(), and getNumVertices().

void sal3d::Mesh::mergeMesh ( const Mesh mesh) [inline]

Merge the passed Mesh to the current one.

All the Vertices and Triangles of the Mesh passed to the method are added to the Mesh.

References addTriangles(), getTriangles(), and getVertices().

Mesh& sal3d::Mesh::operator= ( const Mesh aMesh) [inline]

Assignment operator.

Parameters:
[in]aMeshThe Mesh to copy to this object.
Returns:
The reference to this object.

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