Biorbd
Release_1.13.0
Toggle main menu visibility
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
9
using namespace
BIORBD_NAMESPACE;
10
11
rigidbody::Mesh::Mesh
()
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
19
rigidbody::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
27
rigidbody::Mesh::Mesh
(
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
37
rigidbody::Mesh
rigidbody::Mesh::DeepCopy
()
const
{
38
rigidbody::Mesh
copy;
39
copy.
DeepCopy
(*
this
);
40
return
copy;
41
}
42
43
void
rigidbody::Mesh::DeepCopy
(
const
rigidbody::Mesh
&other) {
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
58
void
rigidbody::Mesh::setColor
(
const
utils::Vector3d
&
color
) {
59
*
m_patchColor
=
color
;
60
}
61
62
utils::Vector3d
&
rigidbody::Mesh::color
()
const
{
return
*
m_patchColor
; }
63
64
bool
rigidbody::Mesh::hasMesh
()
const
{
return
m_vertex
->size() > 0; }
65
void
rigidbody::Mesh::addPoint
(
const
utils::Vector3d
&node) {
66
m_vertex
->push_back(node);
67
}
68
const
utils::Vector3d
&
rigidbody::Mesh::point
(
size_t
idx)
const
{
69
return
(*
m_vertex
)[idx];
70
}
71
size_t
rigidbody::Mesh::nbVertex
()
const
{
return
m_vertex
->size(); }
72
73
void
rigidbody::Mesh::rotate
(
const
utils::RotoTrans
&rt) {
74
*
m_rotation
= rt;
75
for
(
auto
&v : *
m_vertex
) {
76
v.applyRT(rt);
77
}
78
}
79
80
utils::RotoTrans
&
rigidbody::Mesh::getRotation
()
const
{
return
*
m_rotation
; }
81
82
void
rigidbody::Mesh::scale
(
const
utils::Vector3d
&scaler) {
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
91
utils::Vector3d
&
rigidbody::Mesh::getScale
()
const
{
return
*
m_scale
; }
92
93
size_t
rigidbody::Mesh::nbFaces
() {
return
m_faces
->size(); }
94
void
rigidbody::Mesh::addFace
(
const
rigidbody::MeshFace
&
face
) {
95
m_faces
->push_back(
face
);
96
}
97
void
rigidbody::Mesh::addFace
(
const
std::vector<int> &
face
) {
98
addFace
(
rigidbody::MeshFace
(
face
));
99
}
100
const
std::vector<rigidbody::MeshFace> &
rigidbody::Mesh::faces
()
const
{
101
return
*
m_faces
;
102
}
103
const
rigidbody::MeshFace
&
rigidbody::Mesh::face
(
size_t
idx)
const
{
104
return
(*
m_faces
)[idx];
105
}
106
107
void
rigidbody::Mesh::setPath
(
const
utils::Path
&
path
) { *
m_pathFile
=
path
; }
108
109
utils::Path
&
rigidbody::Mesh::path
() {
return
*
m_pathFile
; }
110
111
const
utils::Path
&
rigidbody::Mesh::path
()
const
{
return
*
m_pathFile
; }
BIORBD_NAMESPACE::rigidbody::MeshFace
The face of the mesh.
Definition
MeshFace.h:19
BIORBD_NAMESPACE::rigidbody::Mesh
A class that holds the geometry of a segment.
Definition
Mesh.h:22
BIORBD_NAMESPACE::rigidbody::Mesh::getRotation
utils::RotoTrans & getRotation() const
Get the rotation applied to the vertex.
Definition
Mesh.cpp:80
BIORBD_NAMESPACE::rigidbody::Mesh::m_scale
std::shared_ptr< utils::Vector3d > m_scale
The scale.
Definition
Mesh.h:173
BIORBD_NAMESPACE::rigidbody::Mesh::m_faces
std::shared_ptr< std::vector< MeshFace > > m_faces
The faces.
Definition
Mesh.h:170
BIORBD_NAMESPACE::rigidbody::Mesh::setColor
void setColor(const utils::Vector3d &color)
Set the patch color.
Definition
Mesh.cpp:58
BIORBD_NAMESPACE::rigidbody::Mesh::addFace
void addFace(const MeshFace &face)
Add a face patch to the mesh.
Definition
Mesh.cpp:94
BIORBD_NAMESPACE::rigidbody::Mesh::m_rotation
std::shared_ptr< utils::RotoTrans > m_rotation
The rotation.
Definition
Mesh.h:168
BIORBD_NAMESPACE::rigidbody::Mesh::nbVertex
size_t nbVertex() const
Returns the number of vertex.
Definition
Mesh.cpp:71
BIORBD_NAMESPACE::rigidbody::Mesh::point
const utils::Vector3d & point(size_t idx) const
Return the point of a specific index.
Definition
Mesh.cpp:68
BIORBD_NAMESPACE::rigidbody::Mesh::addPoint
void addPoint(const utils::Vector3d &node)
Add a point to the mesh.
Definition
Mesh.cpp:65
BIORBD_NAMESPACE::rigidbody::Mesh::scale
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
BIORBD_NAMESPACE::rigidbody::Mesh::rotate
void rotate(const utils::RotoTrans &rt)
rotateVertex Apply the RT to the vertex
Definition
Mesh.cpp:73
BIORBD_NAMESPACE::rigidbody::Mesh::face
const MeshFace & face(size_t idx) const
Return the face of the mesh of a specified idx.
Definition
Mesh.cpp:103
BIORBD_NAMESPACE::rigidbody::Mesh::m_vertex
std::shared_ptr< std::vector< utils::Vector3d > > m_vertex
The vertex.
Definition
Mesh.h:169
BIORBD_NAMESPACE::rigidbody::Mesh::color
utils::Vector3d & color() const
Get the patch color.
Definition
Mesh.cpp:62
BIORBD_NAMESPACE::rigidbody::Mesh::Mesh
Mesh()
Construct mesh.
Definition
Mesh.cpp:11
BIORBD_NAMESPACE::rigidbody::Mesh::setPath
void setPath(const utils::Path &path)
Set the path of the underlying mesh file.
Definition
Mesh.cpp:107
BIORBD_NAMESPACE::rigidbody::Mesh::m_pathFile
std::shared_ptr< utils::Path > m_pathFile
The path to the mesh file.
Definition
Mesh.h:171
BIORBD_NAMESPACE::rigidbody::Mesh::hasMesh
bool hasMesh() const
Return if there is a mesh.
Definition
Mesh.cpp:64
BIORBD_NAMESPACE::rigidbody::Mesh::faces
const std::vector< MeshFace > & faces() const
Return the faces of the mesh.
Definition
Mesh.cpp:100
BIORBD_NAMESPACE::rigidbody::Mesh::getScale
utils::Vector3d & getScale() const
Get the scaling applied to the vertex wrt to 0, 0, 0.
Definition
Mesh.cpp:91
BIORBD_NAMESPACE::rigidbody::Mesh::m_patchColor
std::shared_ptr< utils::Vector3d > m_patchColor
The color of faces.
Definition
Mesh.h:172
BIORBD_NAMESPACE::rigidbody::Mesh::path
utils::Path & path()
Return the path of the mesh file.
Definition
Mesh.cpp:109
BIORBD_NAMESPACE::rigidbody::Mesh::nbFaces
size_t nbFaces()
Return the number of faces.
Definition
Mesh.cpp:93
BIORBD_NAMESPACE::rigidbody::Mesh::DeepCopy
Mesh DeepCopy() const
Deep copy of the mesh.
Definition
Mesh.cpp:37
BIORBD_NAMESPACE::utils::Path
Collection of methods to manipulate path.
Definition
Path.h:16
BIORBD_NAMESPACE::utils::RotoTrans
Homogenous matrix to describe translations and rotations simultaneously.
Definition
RotoTrans.h:33
BIORBD_NAMESPACE::utils::Vector3d
Wrapper around Eigen Vector3d and attach it to a parent.
Definition
Vector3d.h:27
src
RigidBody
Mesh.cpp
Generated by
1.18.0