Gazebo Common

API Reference

5.7.0

A child mesh. More...

#include <SubMesh.hh>

Public Types

enum  PrimitiveType {
  POINTS, LINES, LINESTRIPS, TRIANGLES,
  TRIFANS, TRISTRIPS
}
 An enumeration of the geometric mesh primitives. More...
 

Public Member Functions

 SubMesh ()
 Constructor. More...
 
 SubMesh (const std::string &_name)
 Constructor. More...
 
virtual ~SubMesh ()
 Destructor. More...
 
void AddIndex (const unsigned int _index)
 Add an index to the mesh. More...
 
void AddNodeAssignment (const unsigned int _vertex, const unsigned int _node, const float _weight)
 Add a vertex - skeleton node assignment. More...
 
void AddNormal (const double _x, const double _y, const double _z)
 Add a normal to the mesh. More...
 
void AddNormal (const gz::math::Vector3d &_n)
 Add a normal to the mesh. More...
 
void AddTexCoord (const double _u, const double _v)
 Add a texture coord to the mesh. If multiple texture coordinate sets exist, this function adds it to the first texture coordinate set in the submesh. If no previous texture coordinates exist, it is added to set 0. More...
 
void AddTexCoord (const gz::math::Vector2d &_uv)
 Add a texture coordinate to the mesh. If multiple texture coordinate sets exist, this function adds it to the first texture coordinate set in the submesh. If no previous texture coordinates exist, it is added to set 0. More...
 
void AddTexCoordBySet (const gz::math::Vector2d &_uv, unsigned int _setIndex)
 Add a texture coord to a texture coordinate set of the mesh. More...
 
void AddTexCoordBySet (double _u, double _v, unsigned int _setIndex)
 Add a texture coord to a texture coordinate set of the mesh. More...
 
void AddVertex (const double _x, const double _y, const double _z)
 Add a vertex to the mesh. More...
 
void AddVertex (const gz::math::Vector3d &_v)
 Add a vertex to the mesh. More...
 
void Center (const gz::math::Vector3d &_center=gz::math::Vector3d::Zero)
 Move the center of the submesh to the given coordinate. This will move all the vertices. More...
 
void FillArrays (double **_vertArr, int **_indexndArr) const
 Put all the data into flat arrays. More...
 
void GenSphericalTexCoord (const gz::math::Vector3d &_center)
 Generate texture coordinates using spherical projection from center. More...
 
void GenSphericalTexCoordBySet (const gz::math::Vector3d &_center, unsigned int _setIndex)
 Generate texture coordinates for a texture coordinate set using spherical projection from center. More...
 
std::optional< unsigned int > GetMaterialIndex () const
 Get the material index. More...
 
bool HasNodeAssignment (const unsigned int _index) const
 Return true if this submesh has the node assignment with the given index. More...
 
bool HasNormal (const unsigned int _index) const
 Return true if this submesh has the normal with the given index. More...
 
bool HasTexCoord (const unsigned int _index) const
 Return true if this submesh has the texture coordinate with the given index. If multiple texture coordinate sets exist, this function checks the first texture coordinate set in the submesh, which by default is set 0 unless AddTexCoordBySet is called with a different set index number the first time a texture coordinate is added. More...
 
bool HasTexCoordBySet (unsigned int _index, unsigned int _setIndex) const
 Return true if this submesh has the texture coordinate with the given index in a texture coordinate set. More...
 
bool HasVertex (const gz::math::Vector3d &_v) const
 Return true if this submesh has the vertex. More...
 
bool HasVertex (const unsigned int _index) const
 Return true if this submesh has the vertex with the given index. More...
 
int Index (const unsigned int _index) const
 Get an index value from the index array. More...
 
unsigned int IndexCount () const
 Return the number of indices. More...
 
int IndexOfVertex (const gz::math::Vector3d &_v) const
 Get the index of the vertex. More...
 
const unsigned int * IndexPtr () const
 Get the raw index pointer. This is unsafe, it is the caller's responsibility to ensure it's not indexed out of bounds. The valid range is [0; IndexCount()) More...
 
unsigned int MaterialIndex () const
 Get the material index. More...
 
gz::math::Vector3d Max () const
 Get the maximum X, Y, Z values from all the vertices. More...
 
unsigned int MaxIndex () const
 Get the highest value in the index array. More...
 
gz::math::Vector3d Min () const
 Get the minimum X, Y, Z values from all the vertices. More...
 
std::string Name () const
 Get the name of this mesh. More...
 
NodeAssignment NodeAssignmentByIndex (const unsigned int _index) const
 Get a vertex - skeleton node assignment. More...
 
unsigned int NodeAssignmentsCount () const
 Get the number of vertex-skeleton node assignments. More...
 
gz::math::Vector3d Normal (const unsigned int _index) const
 Get a normal. More...
 
unsigned int NormalCount () const
 Return the number of normals. More...
 
void RecalculateNormals ()
 Recalculate all the normals. More...
 
void Scale (const double &_factor)
 Scale all vertices by _factor. More...
 
void Scale (const gz::math::Vector3d &_factor)
 Scale all vertices by _factor. More...
 
void SetIndex (const unsigned int _index, const unsigned int _i)
 Set an index. More...
 
void SetMaterialIndex (const unsigned int _index)
 Set the material index. Relates to the parent mesh material list. More...
 
void SetName (const std::string &_name)
 Set the name of this mesh. More...
 
void SetNormal (const unsigned int _index, const gz::math::Vector3d &_n)
 Set a normal. More...
 
void SetPrimitiveType (PrimitiveType _type)
 Set the primitive type. More...
 
void SetTexCoord (const unsigned int _index, const gz::math::Vector2d &_uv)
 Set a texture coordinate. If multiple texture coordinate sets exist, this function sets the texture coordinate in the first texture coordinate set in the submesh. More...
 
void SetTexCoordBySet (unsigned int _index, const gz::math::Vector2d &_uv, unsigned int _setIdex)
 Set a texture coordinate for a texture coordinate set. More...
 
void SetVertex (const unsigned int _index, const gz::math::Vector3d &_v)
 Set a vertex. More...
 
PrimitiveType SubMeshPrimitiveType () const
 Get the primitive type. More...
 
gz::math::Vector2d TexCoord (const unsigned int _index) const
 Get a texture coordinate. More...
 
gz::math::Vector2d TexCoordBySet (unsigned int _index, unsigned int _setIndex) const
 Get a texture coordinate for a texture coordinate set. More...
 
unsigned int TexCoordCount () const
 Return the number of texture coordinates. If multiple texture coordinate sets exist, this function checks the first texture coordinate set in the submesh, which by default is set 0, unless AddTexCoordBySet is called with a different set index number the first time a texture coordinate is added. More...
 
unsigned int TexCoordCountBySet (unsigned int _setIndex) const
 Return the number of texture coordinates for a texture coordinate set. More...
 
unsigned int TexCoordSetCount () const
 Return the number of texture coordinate sets. More...
 
void Translate (const gz::math::Vector3d &_vec)
 Move all vertices by _vec. More...
 
gz::math::Vector3d Vertex (const unsigned int _index) const
 Get a vertex. More...
 
unsigned int VertexCount () const
 Get the number of vertices. More...
 
const gz::math::Vector3dVertexPtr () const
 Get the raw vertex pointer. This is unsafe, it is the caller's responsibility to ensure it's not indexed out of bounds. The valid range is [0; VertexCount()) More...
 
double Volume () const
 Compute the volume of this submesh. The primitive type must be TRIANGLES. More...
 

Detailed Description

A child mesh.

Member Enumeration Documentation

◆ PrimitiveType

An enumeration of the geometric mesh primitives.

Enumerator
POINTS 

Point. 1 vertex per point.

LINES 

Line. 2 vertices per line.

LINESTRIPS 

Connected lines. 2 vertices for the first line and every vertex specified afterwards creates a new line.

TRIANGLES 

Triangle type. 3 vertices per triangle.

TRIFANS 

Connected triangle in fan shape. 3 vertices for the first triangle and every vertex specified afterwards creates a new triangle.

TRISTRIPS 

Connected triangle. 3 vertices for the first triangle and every vertex specified afterwards creates a new triangle.

Constructor & Destructor Documentation

◆ SubMesh() [1/2]

SubMesh ( )

Constructor.

◆ SubMesh() [2/2]

SubMesh ( const std::string _name)
explicit

Constructor.

Parameters
_nameName of the submesh.

◆ ~SubMesh()

virtual ~SubMesh ( )
virtual

Destructor.

Member Function Documentation

◆ AddIndex()

void AddIndex ( const unsigned int  _index)

Add an index to the mesh.

Parameters
[in]_indexThe new vertex index

◆ AddNodeAssignment()

void AddNodeAssignment ( const unsigned int  _vertex,
const unsigned int  _node,
const float  _weight 
)

Add a vertex - skeleton node assignment.

Parameters
[in]_vertexThe vertex index
[in]_nodeThe node index
[in]_weightThe weight (between 0 and 1)

◆ AddNormal() [1/2]

void AddNormal ( const double  _x,
const double  _y,
const double  _z 
)

Add a normal to the mesh.

Parameters
[in]_xPosition along x
[in]_yPosition along y
[in]_zPosition along z

◆ AddNormal() [2/2]

void AddNormal ( const gz::math::Vector3d _n)

Add a normal to the mesh.

Parameters
[in]_nThe normal

◆ AddTexCoord() [1/2]

void AddTexCoord ( const double  _u,
const double  _v 
)

Add a texture coord to the mesh. If multiple texture coordinate sets exist, this function adds it to the first texture coordinate set in the submesh. If no previous texture coordinates exist, it is added to set 0.

Parameters
[in]_uPosition along u
[in]_vPosition along v
See also
AddTexCoordBySet

◆ AddTexCoord() [2/2]

void AddTexCoord ( const gz::math::Vector2d _uv)

Add a texture coordinate to the mesh. If multiple texture coordinate sets exist, this function adds it to the first texture coordinate set in the submesh. If no previous texture coordinates exist, it is added to set 0.

Parameters
[in]_uvThe texture coordinate
See also
AddTexCoordBySet

◆ AddTexCoordBySet() [1/2]

void AddTexCoordBySet ( const gz::math::Vector2d _uv,
unsigned int  _setIndex 
)

Add a texture coord to a texture coordinate set of the mesh.

Parameters
[in]_uPosition along u
[in]_vPosition along v
[in]_setIndexTexture coordinate set index

◆ AddTexCoordBySet() [2/2]

void AddTexCoordBySet ( double  _u,
double  _v,
unsigned int  _setIndex 
)

Add a texture coord to a texture coordinate set of the mesh.

Parameters
[in]_uPosition along u
[in]_vPosition along v
[in]_setIndexTexture coordinate set index

◆ AddVertex() [1/2]

void AddVertex ( const double  _x,
const double  _y,
const double  _z 
)

Add a vertex to the mesh.

Parameters
[in]_xPosition along x
[in]_yPosition along y
[in]_zPosition along z

◆ AddVertex() [2/2]

void AddVertex ( const gz::math::Vector3d _v)

Add a vertex to the mesh.

Parameters
[in]_vThe new position

◆ Center()

void Center ( const gz::math::Vector3d _center = gz::math::Vector3d::Zero)

Move the center of the submesh to the given coordinate. This will move all the vertices.

Parameters
[in]_centerLocation of the mesh center.

◆ FillArrays()

void FillArrays ( double **  _vertArr,
int **  _indexndArr 
) const

Put all the data into flat arrays.

Parameters
[in]_verArrThe vertex array to be filled.
[in]_indexndArrThe index array to be filled.

◆ GenSphericalTexCoord()

void GenSphericalTexCoord ( const gz::math::Vector3d _center)

Generate texture coordinates using spherical projection from center.

Parameters
[in]_centerCenter of the projection.

◆ GenSphericalTexCoordBySet()

void GenSphericalTexCoordBySet ( const gz::math::Vector3d _center,
unsigned int  _setIndex 
)

Generate texture coordinates for a texture coordinate set using spherical projection from center.

Parameters
[in]_centerCenter of the projection.
[in]_setIndexTexture coordinate set index

◆ GetMaterialIndex()

std::optional<unsigned int> GetMaterialIndex ( ) const

Get the material index.

Returns
The assigned material index. Nullopt is returned if the submesh has no assigned material index

◆ HasNodeAssignment()

bool HasNodeAssignment ( const unsigned int  _index) const

Return true if this submesh has the node assignment with the given index.

Parameters
[in]_indexNode assignment index
Returns
Return true if this submesh has the node assignment with the given _index.

◆ HasNormal()

bool HasNormal ( const unsigned int  _index) const

Return true if this submesh has the normal with the given index.

Parameters
[in]_indexNormal index
Returns
Return true if this submesh has the normal with the given _index.

◆ HasTexCoord()

bool HasTexCoord ( const unsigned int  _index) const

Return true if this submesh has the texture coordinate with the given index. If multiple texture coordinate sets exist, this function checks the first texture coordinate set in the submesh, which by default is set 0 unless AddTexCoordBySet is called with a different set index number the first time a texture coordinate is added.

Parameters
[in]_indexTexture coordinate index
Returns
Return true if this submesh has the texture coordinate with the given _index.
See also
HasTexCoordBySet

◆ HasTexCoordBySet()

bool HasTexCoordBySet ( unsigned int  _index,
unsigned int  _setIndex 
) const

Return true if this submesh has the texture coordinate with the given index in a texture coordinate set.

Parameters
[in]_indexTexture coordinate index
[in]_setIndexTexture coordinate set index
Returns
Return true if this submesh has the texture coordinate with the given _index.

◆ HasVertex() [1/2]

bool HasVertex ( const gz::math::Vector3d _v) const

Return true if this submesh has the vertex.

Parameters
[in]_vVertex coordinate
Returns
Return true if this submesh has the vertex

◆ HasVertex() [2/2]

bool HasVertex ( const unsigned int  _index) const

Return true if this submesh has the vertex with the given index.

Parameters
[in]_indexVertex index
Returns
Return true if this submesh has the vertex with the given _index.

◆ Index()

int Index ( const unsigned int  _index) const

Get an index value from the index array.

Parameters
[in]_indexArray index.
Returns
The index, or -1 if the _index is out of bounds.

◆ IndexCount()

unsigned int IndexCount ( ) const

Return the number of indices.

Returns
The number of indices.

◆ IndexOfVertex()

int IndexOfVertex ( const gz::math::Vector3d _v) const

Get the index of the vertex.

Parameters
[in]_vVertex to check
Returns
Index of the vertex that matches _v.

◆ IndexPtr()

const unsigned int* IndexPtr ( ) const

Get the raw index pointer. This is unsafe, it is the caller's responsibility to ensure it's not indexed out of bounds. The valid range is [0; IndexCount())

Returns
Raw indices

◆ MaterialIndex()

unsigned int MaterialIndex ( ) const

Get the material index.

Returns
The assigned material index. If no material index is assigned to this submesh, std::numeric_limits<unsigned int>::max() is returned.
Note
This method is deprecated, use GetMaterialIndex instead

◆ Max()

gz::math::Vector3d Max ( ) const

Get the maximum X, Y, Z values from all the vertices.

Returns
Max X,Y,Z values from all vertices in submesh

◆ MaxIndex()

unsigned int MaxIndex ( ) const

Get the highest value in the index array.

Returns
The highest index value.

◆ Min()

gz::math::Vector3d Min ( ) const

Get the minimum X, Y, Z values from all the vertices.

Returns
Min X,Y,Z values from all vertices in submesh

◆ Name()

std::string Name ( ) const

Get the name of this mesh.

Returns
The name

◆ NodeAssignmentByIndex()

NodeAssignment NodeAssignmentByIndex ( const unsigned int  _index) const

Get a vertex - skeleton node assignment.

Parameters
[in]_indexThe index of the assignment
Returns
The skeleton node assignment, or a default constructed skeleton node assignment when _index is invalid.
See also
bool HasNodeAssignment(const unsigned int _index) const;

◆ NodeAssignmentsCount()

unsigned int NodeAssignmentsCount ( ) const

Get the number of vertex-skeleton node assignments.

Returns
The number of vertex-skeleton node assignments

◆ Normal()

gz::math::Vector3d Normal ( const unsigned int  _index) const

Get a normal.

Parameters
[in]_indexThe normal index
Returns
The normal direction or gz::math::Vector3d::Zero if index is out of bounds.
See also
bool HasNormal(const unsigned int _index);

◆ NormalCount()

unsigned int NormalCount ( ) const

Return the number of normals.

Returns
The number of normals.

◆ RecalculateNormals()

void RecalculateNormals ( )

Recalculate all the normals.

◆ Scale() [1/2]

void Scale ( const double &  _factor)

Scale all vertices by _factor.

Parameters
[in]_factorScaling factor

◆ Scale() [2/2]

void Scale ( const gz::math::Vector3d _factor)

Scale all vertices by _factor.

Parameters
[in]_factorScaling factor

◆ SetIndex()

void SetIndex ( const unsigned int  _index,
const unsigned int  _i 
)

Set an index.

Parameters
[in]_indexIndex of the indices
[in]_iThe new index value to set to

◆ SetMaterialIndex()

void SetMaterialIndex ( const unsigned int  _index)

Set the material index. Relates to the parent mesh material list.

Parameters
[in]_indexIndex to set the material to.

◆ SetName()

void SetName ( const std::string _name)

Set the name of this mesh.

Parameters
[in]_nThe name to set

◆ SetNormal()

void SetNormal ( const unsigned int  _index,
const gz::math::Vector3d _n 
)

Set a normal.

Parameters
[in]_indexIndex of the normal that will be set.
[in]_nThe new normal direction

◆ SetPrimitiveType()

void SetPrimitiveType ( PrimitiveType  _type)

Set the primitive type.

Parameters
[in]_typeThe primitive type

◆ SetTexCoord()

void SetTexCoord ( const unsigned int  _index,
const gz::math::Vector2d _uv 
)

Set a texture coordinate. If multiple texture coordinate sets exist, this function sets the texture coordinate in the first texture coordinate set in the submesh.

Parameters
[in]_indexIndex of the texture coordinate that will be set.
[in]_uvThe new texture coordinate
See also
SetTexCoordBySet

◆ SetTexCoordBySet()

void SetTexCoordBySet ( unsigned int  _index,
const gz::math::Vector2d _uv,
unsigned int  _setIdex 
)

Set a texture coordinate for a texture coordinate set.

Parameters
[in]_indexIndex of the texture coordinate that will be set.
[in]_uvThe new texture coordinate
[in]_setIndexTexture coordinate set index

◆ SetVertex()

void SetVertex ( const unsigned int  _index,
const gz::math::Vector3d _v 
)

Set a vertex.

Parameters
[in]_indexIndex of the vertex
[in]_vThe new vertex coordinate

◆ SubMeshPrimitiveType()

PrimitiveType SubMeshPrimitiveType ( ) const

Get the primitive type.

Returns
The primitive type

◆ TexCoord()

gz::math::Vector2d TexCoord ( const unsigned int  _index) const

Get a texture coordinate.

Parameters
[in]_indexthe texture index
Returns
The texture coordinate or gz::math::Vector2d::Zero if index is out of bounds.
See also
bool HasTexCoord(const unsigned int _index) const

◆ TexCoordBySet()

gz::math::Vector2d TexCoordBySet ( unsigned int  _index,
unsigned int  _setIndex 
) const

Get a texture coordinate for a texture coordinate set.

Parameters
[in]_indexthe texture index
Returns
The texture coordinate or gz::math::Vector2d::Zero if index is out of bounds.
Parameters
[in]_setIndexTexture coordinate set index
See also
bool HasTexCoordBySet(unsigned int _index, unsigned int _setIndex) const

◆ TexCoordCount()

unsigned int TexCoordCount ( ) const

Return the number of texture coordinates. If multiple texture coordinate sets exist, this function checks the first texture coordinate set in the submesh, which by default is set 0, unless AddTexCoordBySet is called with a different set index number the first time a texture coordinate is added.

Returns
The number of texture coordinates.
See also
TexCoordCountBySet

◆ TexCoordCountBySet()

unsigned int TexCoordCountBySet ( unsigned int  _setIndex) const

Return the number of texture coordinates for a texture coordinate set.

Parameters
[in]_setIndexTexture coordinate set index
Returns
The number of texture coordinates.

◆ TexCoordSetCount()

unsigned int TexCoordSetCount ( ) const

Return the number of texture coordinate sets.

Returns
The number of texture coordinates sets.

◆ Translate()

void Translate ( const gz::math::Vector3d _vec)

Move all vertices by _vec.

Parameters
[in]_vecAmount to translate vertices.

◆ Vertex()

gz::math::Vector3d Vertex ( const unsigned int  _index) const

Get a vertex.

Parameters
[in]_indexIndex of the vertex
Returns
Coordinates of the vertex or gz::math::Vector3d::Zero if the index is out of bounds.
See also
bool HasVertex(const unsigned int) const

◆ VertexCount()

unsigned int VertexCount ( ) const

Get the number of vertices.

Returns
The number of vertices.

◆ VertexPtr()

const gz::math::Vector3d* VertexPtr ( ) const

Get the raw vertex pointer. This is unsafe, it is the caller's responsibility to ensure it's not indexed out of bounds. The valid range is [0; VertexCount())

Returns
Raw vertices

◆ Volume()

double Volume ( ) const

Compute the volume of this submesh. The primitive type must be TRIANGLES.

This function utilizes the mesh volume formula from "Efficient feature extraction for 2d/3d objects in mesh representation" by Cha Zhang and Tsuhan Chen. Link: http://chenlab.ece.cornell.edu/Publication/Cha/icip01_Cha.pdf. The formula does not check for a closed (water tight) mesh.

Returns
The submesh's volume. The volume can be zero if the primitive type is not TRIANGLES, or there are no triangles.

The documentation for this class was generated from the following file: