Simox  2.3.74.0
VirtualRobot::TriMeshModel Class Reference

Data Structures

struct  triangle
 

Public Member Functions

 TriMeshModel ()
 Constructor. More...
 
 TriMeshModel (TriMeshModel &&)=default
 
 TriMeshModel (const TriMeshModel &)=default
 
TriMeshModeloperator= (TriMeshModel &&)=default
 
TriMeshModeloperator= (const TriMeshModel &)=default
 
 TriMeshModel (const std::vector< triangle > &triangles)
 Construct from vector of triangles. More...
 
 TriMeshModel (const MathTools::ConvexHull3D &ch)
 
virtual ~TriMeshModel ()=default
 Virtual destructor. More...
 
template<typename T >
Eigen::Vector3f nonUniformSampleSurface (T &gen) const
 
void addTriangleWithFace (const Eigen::Vector3f &vertex1, const Eigen::Vector3f &vertex2, const Eigen::Vector3f &vertex3)
 
void addTriangleWithFace (const Eigen::Vector3f &vertex1, const Eigen::Vector3f &vertex2, const Eigen::Vector3f &vertex3, Eigen::Vector3f normal, const VisualizationFactory::Color &color1=VisualizationFactory::Color::Gray(), const VisualizationFactory::Color &color2=VisualizationFactory::Color::Gray(), const VisualizationFactory::Color &color3=VisualizationFactory::Color::Gray())
 
void addTriangleWithFace (const Eigen::Vector3f &vertex1, const Eigen::Vector3f &vertex2, const Eigen::Vector3f &vertex3, const Eigen::Vector4f &vertexColor1, const Eigen::Vector4f &vertexColor2, const Eigen::Vector4f &vertexColor3)
 
void addMesh (const TriMeshModel &mesh)
 
void addFace (const MathTools::TriangleFace &face)
 
int addVertex (const Eigen::Vector3f &vertex)
 
int addVertex (float x, float y, float z)
 
unsigned int addNormal (const Eigen::Vector3f &normal)
 
unsigned int addNormal (float x, float y, float z)
 
unsigned int addColor (const VisualizationFactory::Color &color)
 
unsigned int addColor (const Eigen::Vector4f &color)
 
unsigned int addColor (float r, float g, float b, float a)
 
unsigned int addMaterial (const VisualizationFactory::PhongMaterial &material)
 
void addFace (unsigned int id0, unsigned int id1, unsigned int id2)
 
void clear ()
 
unsigned int addMissingNormals ()
 Checks all faces for existence of normals. Creates the normals in case they are missing. More...
 
unsigned int addMissingColors (const VisualizationFactory::Color &color=VisualizationFactory::Color::Gray())
 Checks all faces for existence of colors. First, mergeVertices() is called. Then, if no color is found, a face with the same vertex is searched and that color is used (if available). Otherwise sets color to the given color. More...
 
void smoothNormalSurface ()
 Smoothes the normal surface by calculating the average of all face-normals of one vertex. Calls first mergeVertices(). More...
 
void flipVertexOrientations ()
 
void mergeVertices (float mergeThreshold=0.0001f, 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, bool updateNormals=false)
 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...
 
std::vector< float > getFaceAreas () const
 Get the areas of all faces. More...
 
float getVolume () const
 Computes the volume of the mesh. Works only for closed meshes. More...
 
void rotate (const Eigen::Matrix3f &mx)
 
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)
 
Eigen::Vector3f getNormalOfFace (std::size_t faceId) const
 
virtual void scale (const Eigen::Vector3f &scaleFactor)
 
virtual void scale (float scaleFactor)
 
TriMeshModelPtr clone () const
 
TriMeshModelPtr clone (const Eigen::Vector3f &scaleFactor) const
 
TriMeshModelPtr clone (float x, float y, float z) const
 

Static Public Member Functions

static EIGEN_MAKE_ALIGNED_OPERATOR_NEW TriMeshModelPtr FromFile (const std::string &str)
 
static TriMeshModel MakeBox (float a, float b, float c)
 
static TriMeshModel MakePoint (float x, float y, float z)
 
static TriMeshModelPtr MakePointPtr (float x, float y, float z)
 
static TriMeshModelPtr MakePointPtr (const Eigen::Vector3f &p)
 
static Eigen::Vector3f CreateNormal (const Eigen::Vector3f &vertex1, const Eigen::Vector3f &vertex2, const 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

◆ TriMeshModel() [1/5]

VirtualRobot::TriMeshModel::TriMeshModel ( )
default

Constructor.

◆ TriMeshModel() [2/5]

VirtualRobot::TriMeshModel::TriMeshModel ( TriMeshModel &&  )
default

◆ TriMeshModel() [3/5]

VirtualRobot::TriMeshModel::TriMeshModel ( const TriMeshModel )
default

◆ TriMeshModel() [4/5]

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

Construct from vector of triangles.

◆ TriMeshModel() [5/5]

VirtualRobot::TriMeshModel::TriMeshModel ( const MathTools::ConvexHull3D ch)

◆ ~TriMeshModel()

virtual VirtualRobot::TriMeshModel::~TriMeshModel ( )
virtualdefault

Virtual destructor.

Member Function Documentation

◆ addColor() [1/3]

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

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

◆ addColor() [2/3]

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

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

◆ addColor() [3/3]

unsigned int VirtualRobot::TriMeshModel::addColor ( float  r,
float  g,
float  b,
float  a 
)
inline

◆ addFace() [1/2]

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

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

◆ addFace() [2/2]

void VirtualRobot::TriMeshModel::addFace ( unsigned int  id0,
unsigned int  id1,
unsigned int  id2 
)

◆ addMaterial()

unsigned int VirtualRobot::TriMeshModel::addMaterial ( const VisualizationFactory::PhongMaterial material)

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

◆ addMesh()

void VirtualRobot::TriMeshModel::addMesh ( const TriMeshModel mesh)

◆ addMissingColors()

unsigned int VirtualRobot::TriMeshModel::addMissingColors ( const VisualizationFactory::Color color = VisualizationFactory::Color::Gray())

Checks all faces for existence of colors. First, mergeVertices() is called. Then, if no color is found, a face with the same vertex is searched and that color is used (if available). Otherwise sets color to the given color.

Parameters
colorDefault Color
Returns
Number of created colors entries

◆ addMissingNormals()

unsigned int VirtualRobot::TriMeshModel::addMissingNormals ( )

Checks all faces for existence of normals. Creates the normals in case they are missing.

Returns
Number of created normals

◆ addNormal() [1/2]

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

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

◆ addNormal() [2/2]

unsigned int VirtualRobot::TriMeshModel::addNormal ( float  x,
float  y,
float  z 
)
inline

◆ addTriangleWithFace() [1/3]

void VirtualRobot::TriMeshModel::addTriangleWithFace ( const Eigen::Vector3f &  vertex1,
const Eigen::Vector3f &  vertex2,
const 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

◆ addTriangleWithFace() [2/3]

void VirtualRobot::TriMeshModel::addTriangleWithFace ( const Eigen::Vector3f &  vertex1,
const Eigen::Vector3f &  vertex2,
const Eigen::Vector3f &  vertex3,
Eigen::Vector3f  normal,
const VisualizationFactory::Color color1 = VisualizationFactory::Color::Gray(),
const VisualizationFactory::Color color2 = VisualizationFactory::Color::Gray(),
const VisualizationFactory::Color color3 = VisualizationFactory::Color::Gray() 
)

◆ addTriangleWithFace() [3/3]

void VirtualRobot::TriMeshModel::addTriangleWithFace ( const Eigen::Vector3f &  vertex1,
const Eigen::Vector3f &  vertex2,
const Eigen::Vector3f &  vertex3,
const Eigen::Vector4f &  vertexColor1,
const Eigen::Vector4f &  vertexColor2,
const Eigen::Vector4f &  vertexColor3 
)

◆ addVertex() [1/2]

int VirtualRobot::TriMeshModel::addVertex ( const Eigen::Vector3f &  vertex)

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

◆ addVertex() [2/2]

int VirtualRobot::TriMeshModel::addVertex ( float  x,
float  y,
float  z 
)
inline

◆ checkAndCorrectNormals()

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

◆ checkFacesHaveSameEdge()

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

◆ clear()

void VirtualRobot::TriMeshModel::clear ( )

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

◆ clone() [1/3]

TriMeshModelPtr VirtualRobot::TriMeshModel::clone ( ) const

◆ clone() [2/3]

TriMeshModelPtr VirtualRobot::TriMeshModel::clone ( const Eigen::Vector3f &  scaleFactor) const

◆ clone() [3/3]

TriMeshModelPtr VirtualRobot::TriMeshModel::clone ( float  x,
float  y,
float  z 
) const

◆ CreateNormal()

Eigen::Vector3f VirtualRobot::TriMeshModel::CreateNormal ( const Eigen::Vector3f &  vertex1,
const Eigen::Vector3f &  vertex2,
const 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

◆ fattenShrink()

void VirtualRobot::TriMeshModel::fattenShrink ( float  offset,
bool  updateNormals = false 
)

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.
updateNormalsIf true, all normals will be updated with the average normal of all normals beloning to one vertex (from multiple faces)

◆ flipVertexOrientations()

void VirtualRobot::TriMeshModel::flipVertexOrientations ( )

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

◆ FromFile()

TriMeshModelPtr VirtualRobot::TriMeshModel::FromFile ( const std::string &  str)
static

◆ getCOM()

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.

◆ getFaceAreas()

std::vector< float > VirtualRobot::TriMeshModel::getFaceAreas ( ) const

Get the areas of all faces.

◆ getNormalOfFace()

Eigen::Vector3f VirtualRobot::TriMeshModel::getNormalOfFace ( std::size_t  faceId) const

◆ getSize()

bool VirtualRobot::TriMeshModel::getSize ( Eigen::Vector3f &  storeMinSize,
Eigen::Vector3f &  storeMaxSize 
)

◆ getVolume()

float VirtualRobot::TriMeshModel::getVolume ( ) const

Computes the volume of the mesh. Works only for closed meshes.

◆ MakeBox()

TriMeshModel VirtualRobot::TriMeshModel::MakeBox ( float  a,
float  b,
float  c 
)
static

◆ MakePoint()

TriMeshModel VirtualRobot::TriMeshModel::MakePoint ( float  x,
float  y,
float  z 
)
static

◆ MakePointPtr() [1/2]

TriMeshModelPtr VirtualRobot::TriMeshModel::MakePointPtr ( float  x,
float  y,
float  z 
)
static

◆ MakePointPtr() [2/2]

TriMeshModelPtr VirtualRobot::TriMeshModel::MakePointPtr ( const Eigen::Vector3f &  p)
static

◆ mergeVertices()

void VirtualRobot::TriMeshModel::mergeVertices ( float  mergeThreshold = 0.0001f,
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.

◆ nonUniformSampleSurface()

template<typename T >
Eigen::Vector3f VirtualRobot::TriMeshModel::nonUniformSampleSurface ( T &  gen) const
inline

◆ operator=() [1/2]

TriMeshModel& VirtualRobot::TriMeshModel::operator= ( TriMeshModel &&  )
default

◆ operator=() [2/2]

TriMeshModel& VirtualRobot::TriMeshModel::operator= ( const TriMeshModel )
default

◆ print()

void VirtualRobot::TriMeshModel::print ( )

◆ printFaces()

void VirtualRobot::TriMeshModel::printFaces ( )

◆ printNormals()

void VirtualRobot::TriMeshModel::printNormals ( )

◆ printVertices()

void VirtualRobot::TriMeshModel::printVertices ( )

◆ removeUnusedVertices()

size_t VirtualRobot::TriMeshModel::removeUnusedVertices ( )

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

Returns
Number of removed vertices

◆ rotate()

void VirtualRobot::TriMeshModel::rotate ( const Eigen::Matrix3f &  mx)

◆ scale() [1/2]

void VirtualRobot::TriMeshModel::scale ( const Eigen::Vector3f &  scaleFactor)
virtual

◆ scale() [2/2]

void VirtualRobot::TriMeshModel::scale ( float  scaleFactor)
virtual

◆ setColor()

void VirtualRobot::TriMeshModel::setColor ( VisualizationFactory::Color  color)

◆ smoothNormalSurface()

void VirtualRobot::TriMeshModel::smoothNormalSurface ( )

Smoothes the normal surface by calculating the average of all face-normals of one vertex. Calls first mergeVertices().

Field Documentation

◆ boundingBox

BoundingBox VirtualRobot::TriMeshModel::boundingBox

◆ colors

std::vector<VisualizationFactory::Color> VirtualRobot::TriMeshModel::colors

◆ faces

std::vector<MathTools::TriangleFace> VirtualRobot::TriMeshModel::faces

◆ materials

std::vector<VisualizationFactory::PhongMaterial> VirtualRobot::TriMeshModel::materials

◆ normals

std::vector<Eigen::Vector3f> VirtualRobot::TriMeshModel::normals

◆ vertices

std::vector<Eigen::Vector3f> VirtualRobot::TriMeshModel::vertices