Core 1.0
|
Core triangle mesh class. More...
#include <mesh.h>
Public Member Functions | |
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... | |
Vector & | Vertex (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< Vector > | GetVertices () const |
Get the array of vertices. | |
QVector< Vector > | GetNormals () 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< Triangle > | GetTriangles () 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... | |
Static Public Member Functions | |
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... | |
Protected Member Functions | |
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 | |
QVector< Vector > | vertices |
Vertices. | |
QVector< Vector > | normals |
Normals. | |
QVector< int > | varray |
Vertex indexes. | |
QVector< int > | narray |
Normal indexes. | |
Friends | |
class | MeshStack |
std::ostream & | operator<< (std::ostream &, const Mesh &) |
Overloaded. More... | |
Core triangle mesh class.
|
explicit |
Initialize the structure from a two dimensional mesh.
mesh | Planar mesh. |
|
explicit |
Create a mesh from a set of vertices.
The set defines the 3n vertexes of n triangles. The array of triangle indexes is generated internally.
vertices | List of vertices. |
|
explicit |
Create a mesh from a set of vertices and a set of triangle indexes.
Indices must have a size multiple of three. Normals are computed to define flat triangles.
vertices | List of vertices. |
indices | List of vertex indexes. |
flat | Boolean, set to true if face should be flat, set to false to generate smooth normals. |
|
explicit |
Creates a capsule.
The mesh has 2n(n-1)+2 vertices, 2n(n-1)+2 normals and 4n(n-1) triangles.
c | Capsule. |
n | Number of points on circle, the number of slices on a half sphere will be E(n/4). |
m | Number of slices on the cylinder part (should be 2 at least). |
|
explicit |
Generate a grid geometry over an input quadrangle.
quad | Quadrangle. |
nx,ny | Number of points in the subdivision. |
|
explicit |
Generate a quadrangle.
quad | Quadrangle, should be flat. |
|
explicit |
Creates the mesh of an octaedron.
octa | Octahedron. |
|
explicit |
Creates an axis aligned box.
The object has 8 vertices, 6 normals and 12 triangles.
box | The box. |
|
explicit |
Creates a triangle.
t | The triangle. |
|
explicit |
Creates a sphere, using polar coordinates.
The object has (2 n) (n - 1) + 2 vertices, (2 n) (n - 1) + 2 normals and 4n(n-1) triangles.
sphere | Sphere. |
n | Discretization parameter. |
|
explicit |
Creates a set of spheres.
set | Set of spheres. |
n | Discretization parameter. |
|
explicit |
Creates a cylinder.
The cylinder with caps has 2n+2 vertices, n+2 normals and 4n triangles.
cylinder | Cylinder. |
ca,cb | Booleans defining whether the cylinder should have caps. |
n | Discretization. |
|
explicit |
Creates a disc.
The disc with has n+1 vertices.
disc | Disc. |
n | Discretization. |
|
explicit |
This function creates the mesh of a dodecahedron.
The object has 20 vertices, 12 normals and 36 triangles
dodecahedron | Dodecahedron. |
|
explicit |
Create the mesh of an icosahedron.
icosahedron | Icosahedron. |
|
explicit |
Create a generalized cylinder with star-shaped contours.
ca,cb | Star-shaped contours, they should have the same size. |
a,b | Centers of the two contours. |
|
explicit |
Create the mesh of an torus.
t | Torus. |
n,p | Discretization of the generating circles. |
ia,ib | Starting and ending indexes of the sections of the torus |
|
explicit |
Create the mesh of a cuboctahedron.
c | Cuboctahedron. |
|
explicit |
Create the mesh of an icosidodecahedron.
icosi | Icosidodecahedron. |
|
explicit |
Create the mesh of a hexagonal prism.
hexa | Hexagonal prism. |
|
explicit |
Creates the mesh of a cone.
A truncated cone has 2n+2 vertices, n+2 normals and 4n triangles.
A real cone has n+2 vertices, n+2 normals and 2n triangles.
cone | The cone. |
n | Discretization parameter. |
|
explicit |
Generate a grid geometry over an input rectangle.
rect | Rectangle. |
nx,ny | Number of points in the subdivision. |
|
explicit |
Creates the mesh of a cuboid.
cuboid | The cuboid. |
|
explicit |
Generate a grid geometry and polygonize the quadric surface.
s | The quadric surface. |
box | The box. |
nx,ny | Number of points in the subdivision. |
|
explicit |
Create a swept-sphere along a quadric curve.
c | Quadric curve |
r | Radius. |
n | Number of points on circle. |
m | Number of slices on the curve (should be 2 at least). |
|
explicit |
Create a swept-sphere along a cubic curve.
c | Set of cubic curves |
r | Radius. |
n | Number of points on circle. |
m | Number of slices on the curve (should be 2 at least). |
|
explicit |
Create a swept-sphere along a set of quadric curves.
c | Set of quadric curves |
r | Radius. |
n | Number of points on circle. |
m | Number of slices on the curve (should be 2 at least). |
|
protected |
Add a pentagon to the geometry.
It creates three triangles abc, acd and ade.
a,b,c,d,e | Index of the vertices. |
n | Index of the normal shared by all vertices. |
|
protected |
Add a quadrangle to the geometry.
a,b,c,d | Index of the vertices and normals. |
|
protected |
Add a quadrangle to the geometry.
a,b,c,d | Index of the vertexes. |
n | Index of the (shared) normal. |
|
protected |
Add a smmoth quadrangle to the geometry.
Creates two smooth triangles abc and acd.
a,b,c,d | Index of the vertexes. |
na,nb,nc,nd | Indexes of the normals for the vertexes. |
|
protected |
Add a smooth triangle to the geometry.
a,b,c | Index of the vertices. |
na,nb,nc | Index of the normals. |
|
protected |
Add a triangle to the geometry.
a,b,c | Index of the vertices. |
n | Index of the normal. |
void Mesh::Append | ( | const Mesh & | mesh | ) |
Merge two meshes into a single one.
mesh | Argument mesh. |
|
static |
Creates an arrow. The object has 3n+2 vertices, 2n+2 normals and 6n triangles.
Note that this shape is more efficient in terms of storage than a cylinder and a cone.
a,b | End vertices. |
r,R | Cylinder and cone radii. |
l | Length of the cylinder, the size of the cone will be derived from the distance b-a minus this length. |
n | Discretization. |
QVector< int > Mesh::AspectRatios | ( | int | n = 4 | ) | const |
Compute the histogram of the aspect ratio of the triangles of the mesh.
n | Number of classes. |
|
inlineprotected |
Compute the base index of a triangle given an edge index.
i | Edge index. |
void Mesh::EdgeCollapse | ( | const double & | epsilon | ) |
Run a simple edge collapse algorithm over a triangle mesh.
This algorithm runs in O(n2) where n denotes the number of triangles in the mesh.
epsilon | Threshold length for collapsing an edge. |
void Mesh::EdgeLengthRange | ( | double & | a, |
double & | b | ||
) | const |
Compute the range of edge lengths.
a,b | Range. |
|
static |
Extrude a contour along a point curve.
curve | Curve. |
profile | Contour. |
|
static |
Extrude a set of contour along a point curve.
The curve and the set of contours should have the same size.
curve% | Curve. |
profile | Contour. |
|
inline |
Get a triangle.
i | Index. |
Compute the convex hull.
p | Set of points. |
bool Mesh::Inside | ( | const Vector & | p | ) | const |
Check if a point is inside or outside of the object.
This is a brute force algorithm, that computes all the intersections between the ray and the triangles of the object.
The mesh should be closed, i.e. without holes.
p | Point. |
bool Mesh::Intersect | ( | const Ray & | ray, |
double & | depth, | ||
int & | index | ||
) | const |
Compute the intersection between a ray and the mesh.
Very computationally intensive function: compute all the ray-triangle intersections.
ray | The ray. |
depth | Intersection depth. |
index | Index of the intersected triangle. |
int Mesh::Intersections | ( | const Ray & | ray | ) | const |
Compute the number of intersections between a ray and the mesh.
Very computationally intensive function: compute all the ray-triangle intersections.
ray | The ray. |
void Mesh::InverseTransform | ( | const FrameScaled & | frame | ) |
int Mesh::IsSmooth | ( | int | i | ) | const |
Check if the ith triangle in the mesh is a flat or smooth triangle.
This is performed by comparing the indexes of the normals, not the normals themselves. Therefore, should the normal indexes be different but the normal vector equal, the function will return that the triangle is a smooth one anyway.
i | Index of the triangle. |
void Mesh::Load | ( | const QString & | filename | ) |
Import a mesh from an .obj file.
filename | File name. |
|
inlineprotected |
Compute the next index of an edge in a triangle.
i | Index of the starting vertex of an edge. |
|
inline |
Get a normal.
i | Index of the wanted normal. |
|
inline |
Get the normal index of a given triangle.
t | Triangle index. |
i | Normal index. |
|
inline |
Get a vertex.
i | The index of the wanted vertex. |
|
inlineprotected |
Compute the previous index of an edge in a triangle.
i | Index of the starting vertex of an edge. |
double Mesh::R | ( | const Vector & | p | ) | const |
Compute the squared distance to the mesh.
This function computes the squared distance to the surface, not the squared distance to the solid object.
p | Point. |
void Mesh::Reserve | ( | int | nv, |
int | nn, | ||
int | nvi, | ||
int | nvn | ||
) |
Reserve memory for arrays.
nv,nn,nvi,nvn | Number of vertices, normals, vertex indexes and vertex normals. |
void Mesh::Rotate | ( | const Matrix & | r | ) |
Rotate the mesh.
r | Rotation matrix. |
void Mesh::SaveObj | ( | const QString & | url, |
const QString & | meshName = QString("mesh") |
||
) | const |
Save the mesh in .obj format, with vertices and normals.
url | Filename. |
meshName | Mesh name in .obj file. |
void Mesh::Scale | ( | const double & | s | ) |
Scale the mesh.
s | Scaling factor. |
void Mesh::Scale | ( | const Vector & | s | ) |
Scale the mesh.
s | Scaling vector, terms should be >0. |
Mesh Mesh::ShrinkedTriangles | ( | const double & | e | ) | const |
Scales (shrinks) all the triangles of the model.
It should be possible to look into the geometry as holes will appear at the edges and vertices of the model.
e | Erosion. |
double Mesh::Signed | ( | const Vector & | p | ) | const |
Compute the signed distance to the mesh.
The mesh should be closed.
p | Point. |
void Mesh::SmoothNormals | ( | ) |
Smooth the normals of the mesh.
This function weights the normals of the faces by their corresponding area.
void Mesh::Symmetry | ( | const Plane & | plane | ) |
Apply a planar symmetry to the object.
plane | Plane. |
void Mesh::Transform | ( | const FrameScaled & | frame | ) |
Transforms the mesh given a transformation.
frame | Transformation. |
Mesh Mesh::Transformed | ( | const FrameScaled & | frame | ) | const |
Transforms the mesh given a transformation.
frame | Transformation. |
void Mesh::Translate | ( | const Vector & | t | ) |
Translate the mesh.
t | Translation vector. |
|
inline |
Acces to a vertex.
i | The index of the vertex. |
|
inline |
Get a vertex.
i | The index of the vertex. |
|
inline |
Get a vertex from a specific triangle.
t | The number of the triangle wich contain the wanted vertex. |
v | The triangle vertex: 0, 1, or 2. |
|
inline |
Get the number of vertices in the geometry.
|
inline |
Get the vertex index of a given triangle.
t | Triangle index. |
i | Vertex index. |
|
friend |
Overloaded.
s | Stream. |
mesh | The mesh. |