Biorbd Release_1.13.0
Loading...
Searching...
No Matches
Mesh.cpp
1#define BIORBD_API_EXPORTS
2#include "RigidBody/Mesh.h"
3
4#include "RigidBody/MeshFace.h"
5#include "Utils/Path.h"
6#include "Utils/RotoTrans.h"
7#include "Utils/Vector3d.h"
8
9using namespace BIORBD_NAMESPACE;
10
12 : m_rotation(std::make_shared<utils::RotoTrans>()),
13 m_vertex(std::make_shared<std::vector<utils::Vector3d>>()),
14 m_faces(std::make_shared<std::vector<rigidbody::MeshFace>>()),
15 m_pathFile(std::make_shared<utils::Path>()),
16 m_patchColor(std::make_shared<utils::Vector3d>(0.89, 0.855, 0.788)),
17 m_scale(std::make_shared<utils::Vector3d>(1.0, 1.0, 1.0)) {}
18
19rigidbody::Mesh::Mesh(const std::vector<utils::Vector3d> &other)
20 : m_rotation(std::make_shared<utils::RotoTrans>()),
21 m_vertex(std::make_shared<std::vector<utils::Vector3d>>(other)),
22 m_faces(std::make_shared<std::vector<rigidbody::MeshFace>>()),
23 m_pathFile(std::make_shared<utils::Path>()),
24 m_patchColor(std::make_shared<utils::Vector3d>(0.89, 0.855, 0.788)),
25 m_scale(std::make_shared<utils::Vector3d>(1.0, 1.0, 1.0)) {}
26
28 const std::vector<utils::Vector3d> &vertex,
29 const std::vector<MeshFace> &faces)
30 : m_rotation(std::make_shared<utils::RotoTrans>()),
31 m_vertex(std::make_shared<std::vector<utils::Vector3d>>(vertex)),
32 m_faces(std::make_shared<std::vector<rigidbody::MeshFace>>(faces)),
33 m_pathFile(std::make_shared<utils::Path>()),
34 m_patchColor(std::make_shared<utils::Vector3d>(0.89, 0.855, 0.788)),
35 m_scale(std::make_shared<utils::Vector3d>(1.0, 1.0, 1.0)) {}
36
38 rigidbody::Mesh copy;
39 copy.DeepCopy(*this);
40 return copy;
41}
42
44 m_vertex->resize(other.m_vertex->size());
45 for (size_t i = 0; i < other.m_vertex->size(); ++i) {
46 (*m_vertex)[i] = (*other.m_vertex)[i].DeepCopy();
47 }
48 m_faces->resize(other.m_faces->size());
49 for (size_t i = 0; i < other.m_faces->size(); ++i) {
50 (*m_faces)[i] = (*other.m_faces)[i].DeepCopy();
51 }
52 *m_pathFile = other.m_pathFile->DeepCopy();
53 *m_patchColor = other.m_patchColor->DeepCopy();
54 *m_rotation = *other.m_rotation;
55 *m_rotation = *other.m_rotation;
56}
57
61
63
64bool rigidbody::Mesh::hasMesh() const { return m_vertex->size() > 0; }
66 m_vertex->push_back(node);
67}
68const utils::Vector3d &rigidbody::Mesh::point(size_t idx) const {
69 return (*m_vertex)[idx];
70}
71size_t rigidbody::Mesh::nbVertex() const { return m_vertex->size(); }
72
74 *m_rotation = rt;
75 for (auto &v : *m_vertex) {
76 v.applyRT(rt);
77 }
78}
79
81
83 *m_scale = scaler;
84 for (auto &v : *m_vertex) {
85 v(0) *= scaler(0);
86 v(1) *= scaler(1);
87 v(2) *= scaler(2);
88 }
89}
90
92
93size_t rigidbody::Mesh::nbFaces() { return m_faces->size(); }
97void rigidbody::Mesh::addFace(const std::vector<int> &face) {
99}
100const std::vector<rigidbody::MeshFace> &rigidbody::Mesh::faces() const {
101 return *m_faces;
102}
104 return (*m_faces)[idx];
105}
106
108
110
A class that holds the geometry of a segment.
Definition Mesh.h:22
utils::RotoTrans & getRotation() const
Get the rotation applied to the vertex.
Definition Mesh.cpp:80
std::shared_ptr< utils::Vector3d > m_scale
The scale.
Definition Mesh.h:173
std::shared_ptr< std::vector< MeshFace > > m_faces
The faces.
Definition Mesh.h:170
void setColor(const utils::Vector3d &color)
Set the patch color.
Definition Mesh.cpp:58
void addFace(const MeshFace &face)
Add a face patch to the mesh.
Definition Mesh.cpp:94
std::shared_ptr< utils::RotoTrans > m_rotation
The rotation.
Definition Mesh.h:168
size_t nbVertex() const
Returns the number of vertex.
Definition Mesh.cpp:71
const utils::Vector3d & point(size_t idx) const
Return the point of a specific index.
Definition Mesh.cpp:68
void addPoint(const utils::Vector3d &node)
Add a point to the mesh.
Definition Mesh.cpp:65
void scale(const utils::Vector3d &scaler)
Scale the vertex wrt to 0, 0, 0. Warnign, this function is applied when called, meaning that if it is...
Definition Mesh.cpp:82
void rotate(const utils::RotoTrans &rt)
rotateVertex Apply the RT to the vertex
Definition Mesh.cpp:73
const MeshFace & face(size_t idx) const
Return the face of the mesh of a specified idx.
Definition Mesh.cpp:103
std::shared_ptr< std::vector< utils::Vector3d > > m_vertex
The vertex.
Definition Mesh.h:169
utils::Vector3d & color() const
Get the patch color.
Definition Mesh.cpp:62
void setPath(const utils::Path &path)
Set the path of the underlying mesh file.
Definition Mesh.cpp:107
std::shared_ptr< utils::Path > m_pathFile
The path to the mesh file.
Definition Mesh.h:171
bool hasMesh() const
Return if there is a mesh.
Definition Mesh.cpp:64
const std::vector< MeshFace > & faces() const
Return the faces of the mesh.
Definition Mesh.cpp:100
utils::Vector3d & getScale() const
Get the scaling applied to the vertex wrt to 0, 0, 0.
Definition Mesh.cpp:91
std::shared_ptr< utils::Vector3d > m_patchColor
The color of faces.
Definition Mesh.h:172
utils::Path & path()
Return the path of the mesh file.
Definition Mesh.cpp:109
size_t nbFaces()
Return the number of faces.
Definition Mesh.cpp:93
Mesh DeepCopy() const
Deep copy of the mesh.
Definition Mesh.cpp:37
Collection of methods to manipulate path.
Definition Path.h:16
Homogenous matrix to describe translations and rotations simultaneously.
Definition RotoTrans.h:33
Wrapper around Eigen Vector3d and attach it to a parent.
Definition Vector3d.h:27