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