Simox  2.3.50
VirtualRobot::TriMeshModel Class Reference

Data Structures

struct  triangle
 

Public Member Functions

EIGEN_MAKE_ALIGNED_OPERATOR_NEW TriMeshModel ()
 
 TriMeshModel (std::vector< triangle > &triangles)
 
void addTriangleWithFace (Eigen::Vector3f &vertex1, Eigen::Vector3f &vertex2, Eigen::Vector3f &vertex3)
 
void addTriangleWithFace (Eigen::Vector3f &vertex1, Eigen::Vector3f &vertex2, Eigen::Vector3f &vertex3, Eigen::Vector3f &normal, VisualizationFactory::Color color1=VisualizationFactory::Color::Gray(), VisualizationFactory::Color color2=VisualizationFactory::Color::Gray(), VisualizationFactory::Color color3=VisualizationFactory::Color::Gray())
 
void addTriangleWithFace (Eigen::Vector3f &vertex1, Eigen::Vector3f &vertex2, Eigen::Vector3f &vertex3, Eigen::Vector4f &vertexColor1, Eigen::Vector4f &vertexColor2, Eigen::Vector4f &vertexColor3)
 
void addFace (const MathTools::TriangleFace &face)
 
int addVertex (const Eigen::Vector3f &vertex)
 
int addNormal (const Eigen::Vector3f &normal)
 
int addColor (const VisualizationFactory::Color &color)
 
int addColor (const Eigen::Vector4f &color)
 
int addMaterial (const VisualizationFactory::PhongMaterial &material)
 
void addFace (unsigned int id0, unsigned int id1, unsigned int id2)
 
void clear ()
 
void flipVertexOrientations ()
 
void mergeVertices (float mergeThreshold=0.0001, bool removeVertices=true)
 Merges vertices that are close together (mergeThreshold). Usually, vertices that are close together should be one vertex. Otherwise the mesh could consist of many individual triangles. All vertex ids stored in faces are updated. This function is quite efficient due to a kd-tree and an inverted face-vertex mapping. More...
 
void fattenShrink (float offset)
 fatten or shrink this trimesh. Done by moving a vertex along a normal calculated from the normals of all the faces the vertex is used in. More...
 
size_t removeUnusedVertices ()
 removeUnusedVertices Checks if vertices are used by faces. May rearrange vertices vector! More...
 
void setColor (VisualizationFactory::Color color)
 
void print ()
 
void printNormals ()
 
void printVertices ()
 
void printFaces ()
 
Eigen::Vector3f getCOM ()
 
bool getSize (Eigen::Vector3f &storeMinSize, Eigen::Vector3f &storeMaxSize)
 
bool checkFacesHaveSameEdge (const MathTools::TriangleFace &face1, const MathTools::TriangleFace &face2, std::vector< std::pair< int, int > > &commonVertexIds) const
 
unsigned int checkAndCorrectNormals (bool inverted)
 
virtual void scale (Eigen::Vector3f &scaleFactor)
 
TriMeshModelPtr clone () const
 
TriMeshModelPtr clone (Eigen::Vector3f &scaleFactor) const
 

Static Public Member Functions

static Eigen::Vector3f CreateNormal (Eigen::Vector3f &vertex1, Eigen::Vector3f &vertex2, Eigen::Vector3f &vertex3)
 

Data Fields

std::vector< Eigen::Vector3f > normals
 
std::vector< Eigen::Vector3f > vertices
 
std::vector< VisualizationFactory::Colorcolors
 
std::vector< MathTools::TriangleFacefaces
 
std::vector< VisualizationFactory::PhongMaterialmaterials
 
BoundingBox boundingBox
 

Constructor & Destructor Documentation

VirtualRobot::TriMeshModel::TriMeshModel ( )
VirtualRobot::TriMeshModel::TriMeshModel ( std::vector< triangle > &  triangles)

Member Function Documentation

int VirtualRobot::TriMeshModel::addColor ( const VisualizationFactory::Color color)

This method adds a color to the internal data structure TriMeshModel::colors

int VirtualRobot::TriMeshModel::addColor ( const Eigen::Vector4f &  color)

This method converts and adds a color to the internal data structure TriMeshModel::colors

void VirtualRobot::TriMeshModel::addFace ( const MathTools::TriangleFace face)

This method adds a face to the internal data structure TriMeshModel::faces.

void VirtualRobot::TriMeshModel::addFace ( unsigned int  id0,
unsigned int  id1,
unsigned int  id2 
)
int VirtualRobot::TriMeshModel::addMaterial ( const VisualizationFactory::PhongMaterial material)

This method converts and adds a color to the internal data structure TriMeshModel::materials

int VirtualRobot::TriMeshModel::addNormal ( const Eigen::Vector3f &  normal)

This method adds a normal to the internal data structure TriMeshModel::normals.

void VirtualRobot::TriMeshModel::addTriangleWithFace ( Eigen::Vector3f &  vertex1,
Eigen::Vector3f &  vertex2,
Eigen::Vector3f &  vertex3 
)

This method adds the vertices vertex1, vertex2 and vertex3 to TriMeshModel::vertices and creates a new TriangleFace instance which is added to TriMeshModel::faces.

Parameters
vertex1first vertex to use in the calculation
vertex2second vertex to use in the calculation
vertex3third vertex to use in the calculation
void VirtualRobot::TriMeshModel::addTriangleWithFace ( Eigen::Vector3f &  vertex1,
Eigen::Vector3f &  vertex2,
Eigen::Vector3f &  vertex3,
Eigen::Vector3f &  normal,
VisualizationFactory::Color  color1 = VisualizationFactory::Color::Gray(),
VisualizationFactory::Color  color2 = VisualizationFactory::Color::Gray(),
VisualizationFactory::Color  color3 = VisualizationFactory::Color::Gray() 
)
void VirtualRobot::TriMeshModel::addTriangleWithFace ( Eigen::Vector3f &  vertex1,
Eigen::Vector3f &  vertex2,
Eigen::Vector3f &  vertex3,
Eigen::Vector4f &  vertexColor1,
Eigen::Vector4f &  vertexColor2,
Eigen::Vector4f &  vertexColor3 
)
int VirtualRobot::TriMeshModel::addVertex ( const Eigen::Vector3f &  vertex)

This method adds a vertex to the internal data structure TriMeshModel::vertices.

unsigned int VirtualRobot::TriMeshModel::checkAndCorrectNormals ( bool  inverted)

This method checks if all normals of the model point inwards or outwards and flippes the faces which have a wrong orientation.

Parameters
invertedinverts the check if set to true
Returns
the number of flipped faces
bool VirtualRobot::TriMeshModel::checkFacesHaveSameEdge ( const MathTools::TriangleFace face1,
const MathTools::TriangleFace face2,
std::vector< std::pair< int, int > > &  commonVertexIds 
) const

This method checks if the faces face1 and face2 share one common edge.

Parameters
face1first TriangleFace to use in comparison
face2second TriangleFace to use in comparison
commonVertexIdscontains a list of
Returns
true if both faces share the same edge and false if not
void VirtualRobot::TriMeshModel::clear ( )

This method clears the internal data structures TriMeshModel::faces and TriMeshModel::vertices.

VirtualRobot::TriMeshModelPtr VirtualRobot::TriMeshModel::clone ( ) const
VirtualRobot::TriMeshModelPtr VirtualRobot::TriMeshModel::clone ( Eigen::Vector3f &  scaleFactor) const
Eigen::Vector3f VirtualRobot::TriMeshModel::CreateNormal ( Eigen::Vector3f &  vertex1,
Eigen::Vector3f &  vertex2,
Eigen::Vector3f &  vertex3 
)
static

This method creates the normal belonging to the vertices vertex1, vertex2 and vertex3.

Parameters
vertex1first vertex to use in the calculation
vertex2second vertex to use in the calculation
vertex3third vertex to use in the calculation
Returns
normal vector
void VirtualRobot::TriMeshModel::fattenShrink ( float  offset)

fatten or shrink this trimesh. Done by moving a vertex along a normal calculated from the normals of all the faces the vertex is used in.

Parameters
offsetAll vertexes are moved about this offset in mm.
void VirtualRobot::TriMeshModel::flipVertexOrientations ( )

This method calls TriangleFace::flipOrientation() on each entry in TriMeshModel::faces.

Eigen::Vector3f VirtualRobot::TriMeshModel::getCOM ( )

This method calculates the center of mass by accumulating all vertices and dividing the sum by the number of vertices.

bool VirtualRobot::TriMeshModel::getSize ( Eigen::Vector3f &  storeMinSize,
Eigen::Vector3f &  storeMaxSize 
)
void VirtualRobot::TriMeshModel::mergeVertices ( float  mergeThreshold = 0.0001,
bool  removeVertices = true 
)

Merges vertices that are close together (mergeThreshold). Usually, vertices that are close together should be one vertex. Otherwise the mesh could consist of many individual triangles. All vertex ids stored in faces are updated. This function is quite efficient due to a kd-tree and an inverted face-vertex mapping.

Parameters
mergeThresholdIf squared Euclidan distance of two points is belong this threshold, two vertices are merged.
removeVerticesIf set, the vertex vextor is chekced for unused vertices. May result in a reassembled vertex vector.
void VirtualRobot::TriMeshModel::print ( )
void VirtualRobot::TriMeshModel::printFaces ( )
void VirtualRobot::TriMeshModel::printNormals ( )
void VirtualRobot::TriMeshModel::printVertices ( )
size_t VirtualRobot::TriMeshModel::removeUnusedVertices ( )

removeUnusedVertices Checks if vertices are used by faces. May rearrange vertices vector!

Returns
Number of removed vertices
void VirtualRobot::TriMeshModel::scale ( Eigen::Vector3f &  scaleFactor)
virtual
void VirtualRobot::TriMeshModel::setColor ( VisualizationFactory::Color  color)

Field Documentation

BoundingBox VirtualRobot::TriMeshModel::boundingBox
std::vector<VisualizationFactory::Color> VirtualRobot::TriMeshModel::colors
std::vector<MathTools::TriangleFace> VirtualRobot::TriMeshModel::faces
std::vector<VisualizationFactory::PhongMaterial> VirtualRobot::TriMeshModel::materials
std::vector<Eigen::Vector3f> VirtualRobot::TriMeshModel::normals
std::vector<Eigen::Vector3f> VirtualRobot::TriMeshModel::vertices