25 #ifndef WTRIANGLEMESH_H
26 #define WTRIANGLEMESH_H
35 #include "../common/WAssert.h"
36 #include "../common/WColor.h"
37 #include "../common/WTransferable.h"
38 #include "../common/math/linearAlgebra/WPosition.h"
39 #include "../common/math/linearAlgebra/WVectorFixed.h"
55 typedef std::shared_ptr< WTriangleMesh >
SPtr;
60 typedef std::shared_ptr< const WTriangleMesh >
ConstSPtr;
76 WTriangleMesh( osg::ref_ptr< osg::Vec3Array > vertices,
const std::vector< size_t >& triangles );
95 virtual const std::string
getName()
const;
121 size_t addVertex(
float x,
float y,
float z );
154 void addTriangle(
size_t vert0,
size_t vert1,
size_t vert2 );
163 void addTriangle( osg::Vec3 vert0, osg::Vec3 vert1, osg::Vec3 vert2 );
171 void setVertex(
size_t index, osg::Vec3 vert );
304 osg::Vec3
getVertex(
size_t index )
const;
321 osg::Vec3
getTriVert(
size_t triId,
size_t vertNum );
383 void addMesh( std::shared_ptr<WTriangleMesh> mesh,
float xOff = 0.,
float yOff = 0.,
float zOff = 0. );
554 osg::Vec3
calcNormal( osg::Vec3 vert0, osg::Vec3 vert1, osg::Vec3 vert2 );
575 size_t getNeighbor(
const size_t coVert1,
const size_t coVert2,
const size_t triangleNum );
617 void loopSetTriangle(
size_t triId,
size_t vertId1,
size_t vertId2,
size_t vertId3 );
658 size_t loopCalcEdgeVert(
size_t triId,
size_t edgeV1,
size_t edgeV2,
size_t V3 );
684 size_t loopGetThirdVert(
size_t coVert1,
size_t coVert2,
size_t triangleNum );
854 ( *m_vertColors )[
m_countVerts ] = osg::Vec4( 1.0, 1.0, 1.0, 1.0 );
862 ( *m_verts )[index] = vert;
863 ( *m_vertNormals )[index] = osg::Vec3( 1.0, 1.0, 1.0 );
871 return "WTriangleMesh";
876 return "Triangle mesh data structure allowing for convenient access of the elements.";
881 WAssert( triId <
m_countTriangles,
"set tri vert 0: triangle id out of range" );
882 WAssert( vertId <
m_countVerts,
"vertex id out of range" );
888 WAssert( triId <
m_countTriangles,
"set tri vert 1: triangle id out of range" );
889 WAssert( vertId <
m_countVerts,
"vertex id out of range" );
895 WAssert( triId <
m_countTriangles,
"set tri vert 2: triangle id out of range" );
896 WAssert( vertId <
m_countVerts,
"vertex id out of range" );
908 WAssert( triId <
m_countTriangles,
"get tri vert id 0: triangle id out of range" );
914 WAssert( triId <
m_countTriangles,
"get tri vert id 1: triangle id out of range" );
920 WAssert( triId <
m_countTriangles,
"get tri vert id 2: triangle id out of range" );
926 ( *m_verts )[index] = vert;
This only is a 3d double vector.
Class building the interface for classes that might be transferred using WModuleConnector.
Testing the WTriangleMesh class.
Triangle mesh data structure allowing for convenient access of the elements.
std::shared_ptr< const WTriangleMesh > ConstSPtr
Const shared pointer.
void setVertexNormal(size_t index, osg::Vec3 normal)
sets the normal for a given vertex
size_t getNeighbor(const size_t coVert1, const size_t coVert2, const size_t triangleNum)
returns the triangle index of a triangle neighboring a given edge of a vertex
osg::Vec3 getVertex(size_t index) const
getter
bool m_curvatureCalculated
Indicates whether the curvature and its principal directions have been calculated.
bool operator==(const WTriangleMesh &rhs) const
Checks if two meshes are exactly the same.
size_t getTriVertId1(size_t triId) const
returns the id of the second vertex of a triangle
osg::Vec3 getTriVert(size_t triId, size_t vertNum)
getter
osg::ref_ptr< osg::Vec3Array > m_secondaryCurvaturePrincipalDirection
Stores the second principal curvature direction for each vertex.
osg::ref_ptr< osg::Vec3Array > m_mainCurvaturePrincipalDirection
Stores the first principal curvature direction for each vertex.
void zoomMesh(float zoom)
multiplies the vertex vectors of the mesh with a given number
virtual const std::string getName() const
Gets the name of this prototype.
void setTriVert2(size_t triId, size_t vertId)
higher level access function to the triangle vector, sets the third vertex of a triangle to a given v...
osg::ref_ptr< osg::Vec3Array > m_triangleNormals
array containing the triangle normals
size_t getTriVertId0(size_t triId) const
returns the id of the first vertex of a triangle
void updateVertsInTriangles()
updates the list for which vertexes appear in which triangle
bool m_autoNormal
flag denoting whether normals should be calculated automatically.
osg::ref_ptr< osg::Vec3Array > getTextureCoordinateArray()
Returns a reference pointer to the texture coordinate array.
void setTriVert1(size_t triId, size_t vertId)
higher level access function to the triangle vector, sets the second vertex of a triangle to a given ...
osg::ref_ptr< osg::Vec3Array > m_verts
array containing the vertices
void setVertexColor(size_t index, osg::Vec4 color)
sets the color for a given vertex
std::vector< size_t > m_triangles
array containing the triangles
osg::ref_ptr< osg::Vec3Array > getMainPrincipalCurvatureDirectionArray()
Retreive the array of principal directions e.g.
osg::Vec3 getCurvatureMainPrincipalDirection(std::size_t vtxId) const
Retreive the 3d principal direction of curvature of a vertex.
osg::ref_ptr< osg::Vec3Array > getVertexNormalArray(bool forceRecalc=false)
Get normal array containing smooth normals for each vertex.
osg::ref_ptr< osg::Vec3Array > getVertexArray()
getter
float calcTriangleArea(std::size_t triIdx) const
Calculates the area of a triangle.
void loopSetTriangle(size_t triId, size_t vertId1, size_t vertId2, size_t vertId3)
changes the vertex ids of a triangle
osg::Vec3 calcNormal(osg::Vec3 vert0, osg::Vec3 vert1, osg::Vec3 vert2)
calculates a normal from the 3 points in space
void performFeaturePreservingSmoothing(float sigmaDistance, float sigmaInfluence)
Implements the feature-preserving mesh smoothing algorithm of Jones et al.
osg::ref_ptr< osg::Vec3Array > m_textureCoordinates
array containing the texture coordinates
size_t getTriVertId2(size_t triId) const
return the id of the third vertex of a triangle
void performFeaturePreservingSmoothingVertexPass(float sigmaDistance, float sigmaInfluence)
Performs the second pass of the feature-preserving smoothing.
osg::Vec3 calcTriangleCenter(std::size_t triIdx) const
Calculates the center position of a triangle.
void addMesh(std::shared_ptr< WTriangleMesh > mesh, float xOff=0., float yOff=0., float zOff=0.)
adds a mesh to the existing, no check for duplicate vertexes is performed, an additional vector may b...
osg::Vec4 getVertColor(size_t index) const
getter
void loopInsertCornerTriangles(size_t triId)
inserts the 3 corner triangles in a given triangle
std::shared_ptr< WTriangleMesh > SPtr
Shared pointer.
double loopGetAlpha(int n)
loop helper function
double calcAngleBetweenNormalizedVectors(osg::Vec3 const &v1, osg::Vec3 const &v2)
Calculates the angle between two NORMALIZED vectors.
size_t triangleSize() const
getter
void calcNeighbors()
calculates neighbor information for triangles
void doLoopSubD()
performs a loop subdivision on the triangle mesh
void setTriVert0(size_t triId, size_t vertId)
higher level access function to the triangle vector, sets the first vertex of a triangle to a given v...
osg::Vec3 estimateSmoothedVertexPosition(std::size_t vtx, float sigmaDistance, float sigmaInfluence, bool mollify)
Calculates Eq.
osg::Vec3 getCurvatureSecondaryPrincipalDirection(std::size_t vtxId) const
Retreive the 3d principal direction of curvature for the minimum normal curvature of a vertex.
void addTriangle(size_t vert0, size_t vert1, size_t vert2)
adds a tringle to the mesh
bool m_neighborsCalculated
flag indicating whether the neighbor information has been calculated yet
size_t m_countVerts
number of vertexes in the mesh
osg::ref_ptr< osg::Vec3Array > m_vertNormals
array containing the vertex normals
void setTextureCoord(std::size_t index, osg::Vec3 texCoord)
Set a texture coordinate.
osg::ref_ptr< osg::Vec4Array > getVertexColorArray()
Color array with a color for each vertex.
std::shared_ptr< std::vector< float > > const & getMainCurvatures() const
Get the vector of main curvature values.
osg::ref_ptr< osg::Vec3Array > getTriangleNormalArray(bool forceRecalc=false)
Normal per triangle.
double getSecondaryCurvature(std::size_t vtxId) const
Retreive the secondary (minimum) curvature of a vertex.
size_t vertSize() const
getter
osg::Vec3 calcTriangleNormal(size_t triangle)
calculates a normal from the 3 points in space defining a triangle
osg::ref_ptr< osg::Vec4Array > getTriangleColors() const
Return triangle colors.
void addTextureCoordinate(osg::Vec3 texCoord)
Adds a texture coordinate for the vertex.
std::shared_ptr< std::vector< float > > const & getSecondaryCurvatures() const
Get the vector of secondary curvature values.
void translateMesh(float xOff, float yOff, float zOff)
moves the entire mesh to a new postion
size_t m_numTriFaces
stores the number of triangles before the loop subdivion is run, needed by the loop algorithm
double getMainCurvature(std::size_t vtxId) const
Retreive the main (maximum) curvature of a vertex.
std::vector< std::vector< size_t > > m_triangleNeighbors
edge neighbors for each triangle
size_t loopGetNextVertex(size_t triNum, size_t vertNum)
returns the id of the next vertex int he triangle
osg::ref_ptr< osg::Vec3Array > getSecondaryPrincipalCurvatureDirectionArray()
Retreive the array of principal directions e.g.
osg::ref_ptr< osg::Vec4Array > m_triangleColors
array containing the triangle colors
void loopEraseTriangleFromVertex(size_t triId, size_t vertId)
erases a triangle from the vertexe's list of triangles it is part of
virtual ~WTriangleMesh()
destructor
osg::Vec3 loopCalcNewPosition(size_t vertId)
calculates the new position of a vertex depending on it's location in the grid and number of neighbor...
void rescaleVertexColors()
Rescale the vertex colors so that the maximum of all r, g and b values is 1.
bool m_meshDirty
flag indicating a change took place which requires a recalculation of components
void setTriangleColor(size_t index, osg::Vec4 color)
sets the color for a given triangle
std::shared_ptr< std::vector< float > > m_secondaryNormalCurvature
Stores the minimum normal curvature (for the second principal direction) for each vertex.
WTriangleMesh()
we don't allow the standard constructor
void loopInsertCenterTriangle(size_t triId)
inserts the center triangle in a given triangle,
size_t loopGetThirdVert(size_t coVert1, size_t coVert2, size_t triangleNum)
returns the id of the third vertex of a triangle for two given vertexes
void estimateCurvature()
Estimates the normal curvatures and their principal directions for every vertex using the algorithm o...
static std::shared_ptr< WPrototyped > m_prototype
The prototype as singleton.
std::vector< std::vector< size_t > > m_vertexIsInTriangle
for each vertex, list of triangles it is part of
virtual const std::string getDescription() const
Gets the description for this prototype.
void setAutoRecalcNormals(bool autoRecalc=true)
Set this to true to force automatic normal calculation.
size_t m_countTriangles
number of triangles in the mesh
osg::ref_ptr< osg::Vec3Array > m_vertFlatNormals
array containing the flat vertex normals
const std::vector< size_t > & getTriangles() const
Returns a const reference to the vertex ids of the triangles.
void setVertex(size_t index, osg::Vec3 vert)
sets a vertex to a new position
size_t addVertex(osg::Vec3 vert)
adds a vertex position to the mesh
size_t m_numTriVerts
stores the number of vertexes before the loop subdivion is run, needed by the loop algorithm
void performFeaturePreservingSmoothingMollificationPass(float sigmaDistance, float sigmaInfluence)
Performs the first pass of the feature-preserving smoothing, only changing the triangle normals.
osg::ref_ptr< osg::Vec4Array > m_vertColors
array containing vertex colors
static std::shared_ptr< WPrototyped > getPrototype()
Returns a prototype instantiated with the true type of the deriving class.
WVector3d getNormal(size_t index)
getter
osg::ref_ptr< osg::Vec3Array > getVertexFlatNormalArray(bool forceRecalc=false)
Get the normal array with flat normals for each vertex.
size_t loopCalcEdgeVert(size_t triId, size_t edgeV1, size_t edgeV2, size_t V3)
calculates the vertex id for a given edge, inserts a new vertex of none exists yet
void removeTriangle(size_t index)
removes a triangle from the mesh
void removeVertex(size_t index)
removes a vertex from the vertex array, if any triangles still index that vertex they will be removed...
std::shared_ptr< std::vector< float > > m_mainNormalCurvature
Stores the maximum normal curvature (for the first principal direction) for each vertex.
void recalcVertNormals()
recalculates the vertex normals
std::ostream & operator<<(std::ostream &os, const WTriangleMesh &rhs)
Prints for each mesh #vertices and #triangles, as well as each triangle with its positions.
std::shared_ptr< std::list< std::shared_ptr< WTriangleMesh > > > componentDecomposition(const WTriangleMesh &mesh)
Decompose the given mesh into connected components.