Core 1.0
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
MeshStack Class Reference

A framework for creating an object incrementally. More...

#include <mesh.h>

Inheritance diagram for MeshStack:
Mesh

Public Member Functions

 MeshStack ()
 Create an empty object. More...
 
 MeshStack (const Mesh &)
 Create a geometry stack from a given object. More...
 
 ~MeshStack ()
 Empty.
 
void Push ()
 Push the current geometry generation state. More...
 
void Pop ()
 Pop a previously pushed geometry generation state. More...
 
void PopAll ()
 Pop all previously pushed geometry generation states and resets to original frame.
 
void Transform (const FrameScaled &)
 Apply a given transformation to the next geometric operations. More...
 
void Translate (const Vector &)
 Apply a given translation to the next geometric operations. More...
 
void Rotate (const Vector &)
 Apply a given Euler rotation to the next geometric operations. More...
 
void Scale (const Vector &)
 Apply a given scale to the next geometric operations. More...
 
void AddTriangle (const Vector &, const Vector &, const Vector &)
 Add a triangle to the geometry. More...
 
void AddQuadrangle (const Vector &, const Vector &, const Vector &, const Vector &)
 Add a quadrangle to the geometry. More...
 
void AddGeometry (const Mesh &)
 Add a given mesh to the shape. More...
 
FrameScaled GetFrame () const
 Get the current building frame.
 
- Public Member Functions inherited from Mesh
 Mesh ()
 Initialize the mesh to empty.
 
 Mesh (const Mesh2 &)
 Initialize the structure from a two dimensional mesh. More...
 
 Mesh (const QVector< Vector > &)
 Create a mesh from a set of vertices. More...
 
 Mesh (const QVector< Vector > &, const QVector< int > &, bool=true)
 Create a mesh from a set of vertices and a set of triangle indexes. More...
 
 Mesh (const QVector< Vector > &, const QVector< Vector > &, const QVector< int > &, const QVector< int > &)
 Create the mesh. More...
 
 ~Mesh ()
 Empty.
 
void Reserve (int, int, int, int)
 Reserve memory for arrays. More...
 
Triangle GetTriangle (int) const
 Get a triangle. More...
 
const Vector Vertex (int) const
 Get a vertex. More...
 
VectorVertex (int)
 Acces to a vertex. More...
 
Vector Vertex (int, int) const
 Get a vertex from a specific triangle. More...
 
Vector Normal (int) const
 Get a normal. More...
 
int Triangles () const
 Get the number of triangles.
 
int Vertexes () const
 Get the number of vertices in the geometry. More...
 
bool Manifold () const
 Check if a mesh is manifold.
 
void Append (const Mesh &)
 Merge two meshes into a single one. More...
 
QVector< VectorGetVertices () const
 Get the array of vertices.
 
QVector< VectorGetNormals () const
 Get the array of normals.
 
QVector< int > VertexIndexes () const
 Return the set of vertex indexes.
 
QVector< int > NormalIndexes () const
 Return the set of normal indexes.
 
QVector< TriangleGetTriangles () const
 Returns the geometry as a set of triangles.
 
int VertexIndex (int, int) const
 Get the vertex index of a given triangle. More...
 
int NormalIndex (int, int) const
 Get the normal index of a given triangle. More...
 
Vector operator[] (int) const
 Get a vertex. More...
 
double R (const Vector &) const
 Compute the squared distance to the mesh. More...
 
double Signed (const Vector &) const
 Compute the signed distance to the mesh. More...
 
bool Intersect (const Ray &, double &, int &) const
 Compute the intersection between a ray and the mesh. More...
 
int Intersections (const Ray &) const
 Compute the number of intersections between a ray and the mesh. More...
 
bool Inside (const Vector &) const
 Check if a point is inside or outside of the object. More...
 
Box GetBox () const
 Compute the bounding box of the object.
 
Sphere GetSphere () const
 Compute the bounding sphere of the object.
 
double AverageEdgeLength () const
 Compute the average edge length.
 
void EdgeLengthRange (double &, double &) const
 Compute the range of edge lengths. More...
 
QVector< int > AspectRatios (int=4) const
 Compute the histogram of the aspect ratio of the triangles of the mesh. More...
 
void EdgeCollapse (const double &)
 Run a simple edge collapse algorithm over a triangle mesh. More...
 
void Transform (const FrameScaled &)
 Transforms the mesh given a transformation. More...
 
Mesh Transformed (const FrameScaled &) const
 Transforms the mesh given a transformation. More...
 
void InverseTransform (const FrameScaled &)
 Inverse transform. More...
 
void Symmetry (const Plane &)
 Apply a planar symmetry to the object. More...
 
void Rotate (const Matrix &)
 Rotate the mesh. More...
 
void Translate (const Vector &)
 Translate the mesh. More...
 
void Scale (const Vector &)
 Scale the mesh. More...
 
void Scale (const double &)
 Scale the mesh. More...
 
void SmoothNormals ()
 Smooth the normals of the mesh. More...
 
int IsSmooth (int) const
 Check if the ith triangle in the mesh is a flat or smooth triangle. More...
 
 Mesh (const Capsule &, int, int=2)
 Creates a capsule. More...
 
 Mesh (const Quadrangle &, int, int)
 Generate a grid geometry over an input quadrangle. More...
 
 Mesh (const Quadrangle &)
 Generate a quadrangle. More...
 
 Mesh (const Octahedron &)
 Creates the mesh of an octaedron. More...
 
 Mesh (const Box &)
 Creates an axis aligned box. More...
 
 Mesh (const Triangle &)
 Creates a triangle. More...
 
 Mesh (const Sphere &, int)
 Creates a sphere, using polar coordinates. More...
 
 Mesh (const SphereSet &, int)
 Creates a set of spheres. More...
 
 Mesh (const Cylinder &, int, bool=true, bool=true)
 Creates a cylinder. More...
 
 Mesh (const Disc &, int)
 Creates a disc. More...
 
 Mesh (const Dodecahedron &)
 This function creates the mesh of a dodecahedron. More...
 
 Mesh (const Icosahedron &)
 Create the mesh of an icosahedron. More...
 
 Mesh (const QVector< Vector > &, const QVector< Vector > &, const Vector &, const Vector &)
 Create a generalized cylinder with star-shaped contours. More...
 
 Mesh (const Torus &, int, int, int=-1, int=-1)
 Create the mesh of an torus. More...
 
 Mesh (const Cuboctahedron &)
 Create the mesh of a cuboctahedron. More...
 
 Mesh (const Icosidodecahedron &)
 Create the mesh of an icosidodecahedron. More...
 
 Mesh (const Hexagonal &)
 Create the mesh of a hexagonal prism. More...
 
 Mesh (const Cone &, int)
 Creates the mesh of a cone. More...
 
 Mesh (const Rectangles &, int, int)
 Generate a grid geometry over an input rectangle. More...
 
 Mesh (const Cuboid &)
 Creates the mesh of a cuboid. More...
 
 Mesh (const QuadricSurface &, const Box2 &, int, int)
 Generate a grid geometry and polygonize the quadric surface. More...
 
 Mesh (const QuadricCurve &, const double &, int, int)
 Create a swept-sphere along a quadric curve. More...
 
 Mesh (const CubicCurveSet &, const double &, int, int)
 Create a swept-sphere along a cubic curve. More...
 
 Mesh (const QuadricCurveSet &, const double &, int, int=2)
 Create a swept-sphere along a set of quadric curves. More...
 
Mesh ShrinkedTriangles (const double &) const
 Scales (shrinks) all the triangles of the model. More...
 
void Load (const QString &)
 Import a mesh from an .obj file. More...
 
void SaveObj (const QString &, const QString &=QString("mesh")) const
 Save the mesh in .obj format, with vertices and normals. More...
 

Protected Member Functions

void Reserve (int, int, int)
 Reserves some space for the vertex, normal and triangle arrays. More...
 
- Protected Member Functions inherited from Mesh
void AddTriangle (int, int, int, int)
 Add a triangle to the geometry. More...
 
void AddSmoothTriangle (int, int, int, int, int, int)
 Add a smooth triangle to the geometry. More...
 
void AddSmoothQuadrangle (int, int, int, int, int, int, int, int)
 Add a smmoth quadrangle to the geometry. More...
 
void AddQuadrangle (int, int, int, int)
 Add a quadrangle to the geometry. More...
 
void AddQuadrangle (int, int, int, int, int)
 Add a quadrangle to the geometry. More...
 
void AddPentagon (int, int, int, int, int, int)
 Add a pentagon to the geometry. More...
 
int NextIndex (int) const
 Compute the next index of an edge in a triangle. More...
 
int PrevIndex (int) const
 Compute the previous index of an edge in a triangle. More...
 
int BaseIndex (int) const
 Compute the base index of a triangle given an edge index. More...
 

Protected Attributes

FrameScaled frame
 Current transformation.
 
QVector< FrameScaledstackframe
 Stack of frames.
 
- Protected Attributes inherited from Mesh
QVector< Vectorvertices
 Vertices.
 
QVector< Vectornormals
 Normals.
 
QVector< int > varray
 Vertex indexes.
 
QVector< int > narray
 Normal indexes.
 

Friends

MeshStackoperator<< (MeshStack &, const Mesh &)
 Add a given mesh to the geometry. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from Mesh
static Mesh Hull (const QVector< Vector > &)
 Compute the convex hull. More...
 
static Mesh Extrusion (const PointCurve &, const PointCurve2 &)
 Extrude a contour along a point curve. More...
 
static Mesh Extrusion (const PointCurve &, const QVector< PointCurve2 > &)
 Extrude a set of contour along a point curve. More...
 
static Mesh Arrow (const Vector &, const Vector &, const double &, const double &, const double &, int)
 Creates an arrow. The object has 3n+2 vertices, 2n+2 normals and 6n triangles. More...
 

Detailed Description

A framework for creating an object incrementally.

The geometry can be created by using low level specific member functions adding triangles or quadrangles to the object. Higher level primitives such as box, cylinders, or surfaces of revolution are provided.

Constructor & Destructor Documentation

◆ MeshStack() [1/2]

MeshStack::MeshStack ( )

Create an empty object.

This function initializes the transformation to identity and the transformation stack is empty.

◆ MeshStack() [2/2]

MeshStack::MeshStack ( const Mesh geometry)

Create a geometry stack from a given object.

The starting geometry is retrieved from the argument object. This function initializes the vertex and normal transforms to identity.

Parameters
geometryInput geometry.

Member Function Documentation

◆ AddGeometry()

void MeshStack::AddGeometry ( const Mesh geometry)

Add a given mesh to the shape.

Parameters
geometryArgument mesh.

◆ AddQuadrangle()

void MeshStack::AddQuadrangle ( const Vector a,
const Vector b,
const Vector c,
const Vector d 
)

Add a quadrangle to the geometry.

This function is more efficient than adding two triangles using MeshStack::AddTriangle since the two common vertices are shared in the index array.

Parameters
a,b,c,dFour vertices.
See also
MeshStack::AddTriangle

◆ AddTriangle()

void MeshStack::AddTriangle ( const Vector a,
const Vector b,
const Vector c 
)

Add a triangle to the geometry.

Parameters
a,b,cVertices.

◆ Pop()

void MeshStack::Pop ( )

Pop a previously pushed geometry generation state.

In theory, there should be as many Pop calls as Push calls. If too many Pop() are made, the system will not crash however and the transformation state will be identity.

◆ Push()

void MeshStack::Push ( )

Push the current geometry generation state.

This function pushes the transformation matrix.

◆ Reserve()

void MeshStack::Reserve ( int  v,
int  n,
int  t 
)
protected

Reserves some space for the vertex, normal and triangle arrays.

Parameters
vVertex array size.
nNormal array size.
tTriangle array size (which should be multiplied by 6).

◆ Rotate()

void MeshStack::Rotate ( const Vector r)

Apply a given Euler rotation to the next geometric operations.

Parameters
rRotation vector.

◆ Scale()

void MeshStack::Scale ( const Vector s)

Apply a given scale to the next geometric operations.

Parameters
sScaling vector.

◆ Transform()

void MeshStack::Transform ( const FrameScaled t)

Apply a given transformation to the next geometric operations.

Parameters
tTransformation.

◆ Translate()

void MeshStack::Translate ( const Vector t)

Apply a given translation to the next geometric operations.

Parameters
tTranslation vector.

Friends And Related Function Documentation

◆ operator<<

MeshStack & operator<< ( MeshStack meshstack,
const Mesh mesh 
)
friend

Add a given mesh to the geometry.

See also
MeshStack::AddGeometry(const Mesh&);.
Parameters
meshstackConstructed mesh.
geometryArgument mesh.