Gazebo Common

API Reference

4.9.0
gz/common/SubMesh.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef IGNITION_COMMON_SUBMESH_HH_
18 #define IGNITION_COMMON_SUBMESH_HH_
19 
20 #include <memory>
21 #include <string>
22 #include <vector>
23 
24 #include <gz/math/Vector3.hh>
25 #include <gz/math/Vector2.hh>
26 
27 #include <ignition/utils/ImplPtr.hh>
28 
29 #include <gz/common/config.hh>
31 #include <gz/common/graphics/Export.hh>
33 
34 namespace ignition
35 {
36  namespace common
37  {
38  class Material;
39  class NodeAssignment;
40 
42  class IGNITION_COMMON_GRAPHICS_VISIBLE SubMesh
43  {
45  public: enum PrimitiveType
46  {
63  TRISTRIPS
64  };
65 
67  public: SubMesh();
68 
71  public: explicit SubMesh(const std::string &_name);
72 
74  public: virtual ~SubMesh();
75 
78  public: void SetName(const std::string &_name);
79 
82  public: std::string Name() const;
83 
86  public: void SetPrimitiveType(PrimitiveType _type);
87 
91 
94  public: void AddIndex(const unsigned int _index);
95 
98  public: void AddVertex(const ignition::math::Vector3d &_v);
99 
104  public: void AddVertex(const double _x, const double _y, const double _z);
105 
108  public: void AddNormal(const ignition::math::Vector3d &_n);
109 
114  public: void AddNormal(const double _x, const double _y, const double _z);
115 
123  public: void AddTexCoord(const double _u, const double _v);
124 
131  public: void AddTexCoord(const ignition::math::Vector2d &_uv);
132 
137  public: void AddTexCoordBySet(double _u, double _v,
138  unsigned int _setIndex);
139 
145  unsigned int _setIndex);
146 
151  public: void AddNodeAssignment(const unsigned int _vertex,
152  const unsigned int _node,
153  const float _weight);
159  public: ignition::math::Vector3d Vertex(const unsigned int _index) const;
160 
164  public: void SetVertex(const unsigned int _index,
165  const ignition::math::Vector3d &_v);
166 
172  public: ignition::math::Vector3d Normal(const unsigned int _index) const;
173 
177  public: void SetNormal(const unsigned int _index,
178  const ignition::math::Vector3d &_n);
179 
186  const unsigned int _index) const;
187 
196  unsigned int _index,
197  unsigned int _setIndex) const;
198 
205  public: void SetTexCoord(const unsigned int _index,
206  const ignition::math::Vector2d &_uv);
207 
212  public: void SetTexCoordBySet(unsigned int _index,
213  const ignition::math::Vector2d &_uv,
214  unsigned int _setIdex);
215 
219  public: int Index(const unsigned int _index) const;
220 
224  public: void SetIndex(const unsigned int _index,
225  const unsigned int _i);
226 
234  const unsigned int _index) const;
235 
238  public: ignition::math::Vector3d Max() const;
239 
242  public: ignition::math::Vector3d Min() const;
243 
246  public: unsigned int VertexCount() const;
247 
250  public: unsigned int NormalCount() const;
251 
254  public: unsigned int IndexCount() const;
255 
263  public: unsigned int TexCoordCount() const;
264 
269  public: unsigned int TexCoordCountBySet(unsigned int _setIndex) const;
270 
273  public: unsigned int TexCoordSetCount() const;
274 
277  public: unsigned int NodeAssignmentsCount() const;
278 
281  public: unsigned int MaxIndex() const;
282 
286  public: void SetMaterialIndex(const unsigned int _index);
287 
290  public: unsigned int MaterialIndex() const;
291 
295  public: bool HasVertex(const ignition::math::Vector3d &_v) const;
296 
302  public: bool HasVertex(const unsigned int _index) const;
303 
309  public: bool HasNormal(const unsigned int _index) const;
310 
321  public: bool HasTexCoord(const unsigned int _index) const;
322 
329  public: bool HasTexCoordBySet(unsigned int _index, unsigned int _setIndex)
330  const;
331 
337  public: bool HasNodeAssignment(const unsigned int _index) const;
338 
342  public: int IndexOfVertex(const ignition::math::Vector3d &_v) const;
343 
347  public: void FillArrays(double **_vertArr, int **_indexndArr) const;
348 
350  public: void RecalculateNormals();
351 
355  public: void GenSphericalTexCoord(
356  const ignition::math::Vector3d &_center);
357 
363  const ignition::math::Vector3d &_center,
364  unsigned int _setIndex);
365 
368  public: void Scale(const ignition::math::Vector3d &_factor);
369 
372  public: void Scale(const double &_factor);
373 
377  public: void Center(const ignition::math::Vector3d &_center =
379 
382  public: void Translate(const ignition::math::Vector3d &_vec);
383 
395  public: double Volume() const;
396 
407 
409  IGN_UTILS_IMPL_PTR(dataPtr)
410  };
411 
414  class IGNITION_COMMON_GRAPHICS_VISIBLE NodeAssignment
415  {
417  public: NodeAssignment();
418 
420  public: unsigned int vertexIndex;
421 
423  public: unsigned int nodeIndex;
424 
427  public: float weight;
428  };
429  }
430 }
431 
432 #endif
Vertex to node weighted assignement for skeleton animation visualization.
Definition: gz/common/SubMesh.hh:415
unsigned int nodeIndex
Node (or bone) index.
Definition: gz/common/SubMesh.hh:423
float weight
The weight (between 0 and 1). This determines how much the node (bone) affects the vertex in animatio...
Definition: gz/common/SubMesh.hh:427
unsigned int vertexIndex
Index of the vertex.
Definition: gz/common/SubMesh.hh:420
A child mesh.
Definition: gz/common/SubMesh.hh:43
void SetPrimitiveType(PrimitiveType _type)
Set the primitive type.
void Scale(const ignition::math::Vector3d &_factor)
Scale all vertices by _factor.
void GenSphericalTexCoordBySet(const ignition::math::Vector3d &_center, unsigned int _setIndex)
Generate texture coordinates for a texture coordinate set using spherical projection from center.
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 s...
void Translate(const ignition::math::Vector3d &_vec)
Move all vertices by _vec.
void AddVertex(const ignition::math::Vector3d &_v)
Add a vertex to the mesh.
unsigned int IndexCount() const
Return the number of indices.
void SetMaterialIndex(const unsigned int _index)
Set the material index. Relates to the parent mesh material list.
void SetName(const std::string &_name)
Set the name of this mesh.
void Center(const ignition::math::Vector3d &_center=ignition::math::Vector3d::Zero)
Move the center of the submesh to the given coordinate. This will move all the vertices.
int IndexOfVertex(const ignition::math::Vector3d &_v) const
Get the index of the vertex.
PrimitiveType
An enumeration of the geometric mesh primitives.
Definition: gz/common/SubMesh.hh:46
@ LINES
Line. 2 vertices per line.
Definition: gz/common/SubMesh.hh:50
@ LINESTRIPS
Connected lines. 2 vertices for the first line and every vertex specified afterwards creates a new li...
Definition: gz/common/SubMesh.hh:53
@ TRIFANS
Connected triangle in fan shape. 3 vertices for the first triangle and every vertex specified afterwa...
Definition: gz/common/SubMesh.hh:59
@ TRIANGLES
Triangle type. 3 vertices per triangle.
Definition: gz/common/SubMesh.hh:55
@ POINTS
Point. 1 vertex per point.
Definition: gz/common/SubMesh.hh:48
ignition::math::Vector3d Vertex(const unsigned int _index) const
Get a vertex.
bool HasVertex(const ignition::math::Vector3d &_v) const
Return true if this submesh has the vertex.
std::string Name() const
Get the name of this mesh.
void Scale(const double &_factor)
Scale all vertices by _factor.
unsigned int TexCoordCountBySet(unsigned int _setIndex) const
Return the number of texture coordinates for a texture coordinate set.
void FillArrays(double **_vertArr, int **_indexndArr) const
Put all the data into flat arrays.
SubMesh(const std::string &_name)
Constructor.
void SetNormal(const unsigned int _index, const ignition::math::Vector3d &_n)
Set a normal.
void RecalculateNormals()
Recalculate all the normals.
double Volume() const
Compute the volume of this submesh. The primitive type must be TRIANGLES.
void AddNodeAssignment(const unsigned int _vertex, const unsigned int _node, const float _weight)
Add a vertex - skeleton node assignment.
unsigned int MaxIndex() const
Get the highest value in the index array.
void SetVertex(const unsigned int _index, const ignition::math::Vector3d &_v)
Set a vertex.
ignition::math::Vector3d Normal(const unsigned int _index) const
Get a normal.
void AddTexCoordBySet(const ignition::math::Vector2d &_uv, unsigned int _setIndex)
Add a texture coord to a texture coordinate set of the mesh.
void AddVertex(const double _x, const double _y, const double _z)
Add a vertex to the mesh.
void SetIndex(const unsigned int _index, const unsigned int _i)
Set an index.
ignition::math::Vector3d Min() const
Get the minimum X, Y, Z values from all the vertices.
unsigned int NormalCount() const
Return the number of normals.
ignition::math::Vector3d Max() const
Get the maximum X, Y, Z values from all the vertices.
int Index(const unsigned int _index) const
Get an index value from the index array.
ignition::math::Vector2d TexCoord(const unsigned int _index) const
Get a texture coordinate.
void AddTexCoordBySet(double _u, double _v, unsigned int _setIndex)
Add a texture coord to a texture coordinate set of the mesh.
virtual ~SubMesh()
Destructor.
unsigned int TexCoordCount() const
Return the number of texture coordinates. If multiple texture coordinate sets exist,...
bool HasNormal(const unsigned int _index) const
Return true if this submesh has the normal with the given index.
void AddIndex(const unsigned int _index)
Add an index to the mesh.
ignition::math::Vector3d Centroid() const
Get the volumetric centroid of the submesh, the centre of the enclosed solid rather than the average ...
unsigned int TexCoordSetCount() const
Return the number of texture coordinate sets.
void SetTexCoord(const unsigned int _index, const ignition::math::Vector2d &_uv)
Set a texture coordinate. If multiple texture coordinate sets exist, this function sets the texture c...
void GenSphericalTexCoord(const ignition::math::Vector3d &_center)
Generate texture coordinates using spherical projection from center.
ignition::math::Vector2d TexCoordBySet(unsigned int _index, unsigned int _setIndex) const
Get a texture coordinate for a texture coordinate set.
unsigned int NodeAssignmentsCount() const
Get the number of vertex-skeleton node assignments.
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 ...
bool HasTexCoord(const unsigned int _index) const
Return true if this submesh has the texture coordinate with the given index. If multiple texture coor...
bool HasVertex(const unsigned int _index) const
Return true if this submesh has the vertex with the given index.
bool HasNodeAssignment(const unsigned int _index) const
Return true if this submesh has the node assignment with the given index.
void AddNormal(const ignition::math::Vector3d &_n)
Add a normal to the mesh.
unsigned int MaterialIndex() const
Get the material index.
void SetTexCoordBySet(unsigned int _index, const ignition::math::Vector2d &_uv, unsigned int _setIdex)
Set a texture coordinate for a texture coordinate set.
NodeAssignment NodeAssignmentByIndex(const unsigned int _index) const
Get a vertex - skeleton node assignment.
unsigned int VertexCount() const
Get the number of vertices.
void AddNormal(const double _x, const double _y, const double _z)
Add a normal to the mesh.
PrimitiveType SubMeshPrimitiveType() const
Get the primitive type.
void AddTexCoord(const ignition::math::Vector2d &_uv)
Add a texture coordinate to the mesh. If multiple texture coordinate sets exist, this function adds i...
static const Vector3 Zero
Forward declarations for the common classes.