Biorbd
Mesh.cpp
1 #define BIORBD_API_EXPORTS
2 #include "RigidBody/Mesh.h"
3 
4 #include "Utils/Path.h"
5 #include "Utils/Vector3d.h"
6 #include "RigidBody/MeshFace.h"
7 
9  m_vertex(std::make_shared<std::vector<biorbd::utils::Vector3d>>()),
10  m_faces(std::make_shared<std::vector<biorbd::rigidbody::MeshFace>>()),
11  m_pathFile(std::make_shared<biorbd::utils::Path>())
12 {
13 
14 }
15 
16 biorbd::rigidbody::Mesh::Mesh(const std::vector<biorbd::utils::Vector3d> &other) :
17  m_vertex(std::make_shared<std::vector<biorbd::utils::Vector3d>>(other)),
18  m_faces(std::make_shared<std::vector<biorbd::rigidbody::MeshFace>>()),
19  m_pathFile(std::make_shared<biorbd::utils::Path>())
20 {
21 
22 }
23 
24 biorbd::rigidbody::Mesh::Mesh(const std::vector<biorbd::utils::Vector3d> &vertex,
25  const std::vector<biorbd::rigidbody::MeshFace> & faces) :
26  m_vertex(std::make_shared<std::vector<biorbd::utils::Vector3d>>(vertex)),
27  m_faces(std::make_shared<std::vector<biorbd::rigidbody::MeshFace>>(faces)),
28  m_pathFile(std::make_shared<biorbd::utils::Path>())
29 {
30 
31 }
32 
34 {
36  copy.DeepCopy(*this);
37  return copy;
38 }
39 
41 {
42  m_vertex->resize(other.m_vertex->size());
43  for (unsigned int i=0; i<other.m_vertex->size(); ++i)
44  (*m_vertex)[i] = (*other.m_vertex)[i].DeepCopy();
45  m_faces->resize(other.m_faces->size());
46  for (unsigned int i=0; i<other.m_faces->size(); ++i)
47  (*m_faces)[i] = (*other.m_faces)[i].DeepCopy();
48  *m_pathFile = other.m_pathFile->DeepCopy();
49 }
50 
52 {
53  m_vertex->push_back(node);
54 }
56 {
57  return (*m_vertex)[idx];
58 }
60 {
61  return static_cast<unsigned int>(m_vertex->size());
62 }
63 
65 {
66  return static_cast<unsigned int>(m_faces->size());
67 }
69 {
70  m_faces->push_back(face);
71 }
72 void biorbd::rigidbody::Mesh::addFace(const std::vector<int> & face)
73 {
74  addFace(biorbd::rigidbody::MeshFace(face));
75 }
76 const std::vector<biorbd::rigidbody::MeshFace>& biorbd::rigidbody::Mesh::faces() const
77 {
78  return *m_faces;
79 }
81  unsigned int idx) const
82 {
83  return (*m_faces)[idx];
84 }
85 
87 {
88  *m_pathFile = path;
89 }
90 
92 {
93  return *m_pathFile;
94 }
biorbd::rigidbody::Mesh::point
const biorbd::utils::Vector3d & point(unsigned int idx) const
Return the point of a specific index.
Definition: Mesh.cpp:55
biorbd::utils::Vector3d
Wrapper around Eigen Vector3d and attach it to a parent.
Definition: Vector3d.h:24
biorbd::rigidbody::MeshFace
The face of the mesh.
Definition: MeshFace.h:19
biorbd::rigidbody::Mesh::Mesh
Mesh()
Construct mesh.
Definition: Mesh.cpp:8
biorbd::rigidbody::Mesh::m_faces
std::shared_ptr< std::vector< biorbd::rigidbody::MeshFace > > m_faces
The faces.
Definition: Mesh.h:126
biorbd::rigidbody::Mesh
A class that holds the geometry of a segment.
Definition: Mesh.h:21
biorbd::rigidbody::Mesh::addPoint
void addPoint(const biorbd::utils::Vector3d &node)
Add a point to the mesh.
Definition: Mesh.cpp:51
biorbd::rigidbody::Mesh::nbFaces
unsigned int nbFaces()
Return the number of faces.
Definition: Mesh.cpp:64
biorbd::rigidbody::Mesh::path
const biorbd::utils::Path & path() const
Return the path of the mesh file.
Definition: Mesh.cpp:91
biorbd::rigidbody::Mesh::DeepCopy
biorbd::rigidbody::Mesh DeepCopy() const
Deep copy of the mesh.
Definition: Mesh.cpp:33
biorbd::rigidbody::Mesh::m_vertex
std::shared_ptr< std::vector< biorbd::utils::Vector3d > > m_vertex
The vertex.
Definition: Mesh.h:125
biorbd::rigidbody::Mesh::faces
const std::vector< biorbd::rigidbody::MeshFace > & faces() const
Return the faces of the mesh.
Definition: Mesh.cpp:76
biorbd::rigidbody::Mesh::nbVertex
unsigned int nbVertex() const
Returns the number of vertex.
Definition: Mesh.cpp:59
biorbd::rigidbody::Mesh::setPath
void setPath(const biorbd::utils::Path &path)
Set the path of the underlying mesh file.
Definition: Mesh.cpp:86
biorbd::rigidbody::Mesh::addFace
void addFace(const biorbd::rigidbody::MeshFace &face)
Add a face patch to the mesh.
Definition: Mesh.cpp:68
biorbd::rigidbody::Mesh::face
const biorbd::rigidbody::MeshFace & face(unsigned int idx) const
Return the face of the mesh of a specified idx.
Definition: Mesh.cpp:80
biorbd::utils::Path
Collection of methods to manipulate path.
Definition: Path.h:17
biorbd::rigidbody::Mesh::m_pathFile
std::shared_ptr< biorbd::utils::Path > m_pathFile
The path to the mesh file.
Definition: Mesh.h:127