Biorbd
Release_1.13.0
Toggle main menu visibility
Loading...
Searching...
No Matches
NodeSegment.cpp
1
#define BIORBD_API_EXPORTS
2
#include "RigidBody/NodeSegment.h"
3
4
#include "Utils/Error.h"
5
6
using namespace
BIORBD_NAMESPACE;
7
8
rigidbody::NodeSegment::NodeSegment
()
9
: utils::
Vector3d
(0, 0, 0),
10
m_axesRemoved
(std::make_shared<std::vector<bool>>(3)),
11
m_nbAxesToRemove
(std::make_shared<int>(0)),
12
m_technical
(std::make_shared<bool>(true)),
13
m_anatomical
(std::make_shared<bool>(false)),
14
m_id
(std::make_shared<int>(-1)) {
15
setType
();
16
}
17
18
rigidbody::NodeSegment::NodeSegment
(
19
const
utils::Scalar& x,
20
const
utils::Scalar& y,
21
const
utils::Scalar& z)
22
: utils::
Vector3d
(x, y, z),
23
m_axesRemoved
(std::make_shared<std::vector<bool>>(3)),
24
m_nbAxesToRemove
(std::make_shared<int>(0)),
25
m_technical
(std::make_shared<bool>(true)),
26
m_anatomical
(std::make_shared<bool>(false)),
27
m_id
(std::make_shared<int>(-1)) {
28
setType
();
29
}
30
31
rigidbody::NodeSegment::NodeSegment
(
const
utils::Vector3d
& other)
32
: utils::
Vector3d
(other),
33
m_axesRemoved
(std::make_shared<std::vector<bool>>(3)),
34
m_nbAxesToRemove
(std::make_shared<int>(0)),
35
m_technical
(std::make_shared<bool>(true)),
36
m_anatomical
(std::make_shared<bool>(false)),
37
m_id
(std::make_shared<int>(-1)) {
38
setType
();
39
}
40
41
rigidbody::NodeSegment::NodeSegment
(
42
const
utils::Scalar& x,
43
const
utils::Scalar& y,
44
const
utils::Scalar& z,
45
const
utils::String
&
name
,
46
const
utils::String
& parentName,
47
bool
isTechnical
,
48
bool
isAnatomical
,
49
const
utils::String
&
axesToRemove
,
50
int
parentID)
51
: utils::
Vector3d
(x, y, z,
name
, parentName),
52
m_axesRemoved
(std::make_shared<std::vector<bool>>(3)),
53
m_nbAxesToRemove
(std::make_shared<int>(0)),
54
m_technical
(std::make_shared<bool>(
isTechnical
)),
55
m_anatomical
(std::make_shared<bool>(
isAnatomical
)),
56
m_id
(std::make_shared<int>(parentID)) {
57
addAxesToRemove
(
axesToRemove
);
58
}
59
60
rigidbody::NodeSegment::NodeSegment
(
61
const
utils::Vector3d
& node,
62
const
utils::String
&
name
,
63
const
utils::String
& parentName,
64
bool
isTechnical
,
65
bool
isAnatomical
,
66
const
utils::String
&
axesToRemove
,
67
int
parentID)
68
: utils::
Vector3d
(node,
name
, parentName),
69
m_axesRemoved
(std::make_shared<std::vector<bool>>(3)),
70
m_nbAxesToRemove
(std::make_shared<int>(0)),
71
m_technical
(std::make_shared<bool>(
isTechnical
)),
72
m_anatomical
(std::make_shared<bool>(
isAnatomical
)),
73
m_id
(std::make_shared<int>(parentID)) {
74
addAxesToRemove
(
axesToRemove
);
75
}
76
77
rigidbody::NodeSegment
rigidbody::NodeSegment::DeepCopy
()
const
{
78
rigidbody::NodeSegment
copy;
79
copy.
DeepCopy
(*
this
);
80
return
copy;
81
}
82
83
void
rigidbody::NodeSegment::DeepCopy
(
const
rigidbody::NodeSegment
& other) {
84
utils::Node::DeepCopy
(other);
85
*
m_axesRemoved
= *other.
m_axesRemoved
;
86
*
m_nbAxesToRemove
= *other.
m_nbAxesToRemove
;
87
*
m_technical
= *other.
m_technical
;
88
*
m_anatomical
= *other.
m_anatomical
;
89
*
m_id
= *other.
m_id
;
90
}
91
92
void
rigidbody::NodeSegment::setValues
(
const
rigidbody::NodeSegment
& other) {
93
(*this)[0] = other[0];
94
(*this)[1] = other[1];
95
(*this)[2] = other[2];
96
}
97
98
bool
rigidbody::NodeSegment::isAnatomical
()
const
{
return
*
m_anatomical
; }
99
100
bool
rigidbody::NodeSegment::isTechnical
()
const
{
return
*
m_technical
; }
101
102
int
rigidbody::NodeSegment::parentId
()
const
{
return
*
m_id
; }
103
104
const
std::vector<bool>&
rigidbody::NodeSegment::axesToRemove
()
const
{
105
return
*
m_axesRemoved
;
106
}
107
108
const
std::vector<bool>
rigidbody::NodeSegment::axes
()
const
{
109
std::vector<bool> out = std::vector<bool>();
110
for
(
int
i = 0; i < static_cast<int>(
m_axesRemoved
->size()); i++) {
111
out.push_back(!
axesToRemove
()[i]);
112
}
113
return
out;
114
}
115
116
rigidbody::NodeSegment
rigidbody::NodeSegment::removeAxes
()
const
{
117
rigidbody::NodeSegment
out(*
this
);
118
for
(
size_t
i = 0; i <
m_axesRemoved
->size(); ++i) {
119
if
(
isAxisRemoved
(i)) {
120
out(
static_cast<
unsigned
int
>
(i)) = 0;
121
}
122
}
123
return
out;
124
}
125
126
bool
rigidbody::NodeSegment::isAxisRemoved
(
size_t
i)
const
{
127
return
(*
m_axesRemoved
)[i];
128
}
129
130
bool
rigidbody::NodeSegment::isAxisKept
(
size_t
i)
const
{
131
return
!
isAxisRemoved
(i);
132
}
133
134
std::vector<int>
rigidbody::NodeSegment::availableAxesIndices
()
const
{
135
std::vector<int> list;
136
for
(
size_t
i = 0; i < 3; ++i) {
137
if
(
isAxisKept
(i)) {
138
list.push_back(
static_cast<
int
>
(i));
139
}
140
}
141
return
list;
142
}
143
144
int
rigidbody::NodeSegment::nbAxesToRemove
()
const
{
return
*
m_nbAxesToRemove
; }
145
146
void
rigidbody::NodeSegment::addAxesToRemove
(
size_t
axisNumber) {
147
if
(axisNumber > 2) {
148
utils::Error::raise
(
"Axis must be 0 (\"x\"), 1 (\"y\") or 2 (\"z\")"
);
149
}
150
(*m_axesRemoved)[axisNumber] =
true
;
151
++*
m_nbAxesToRemove
;
152
}
153
154
void
rigidbody::NodeSegment::addAxesToRemove
(
const
utils::String
& s) {
155
for
(
size_t
i = 0; i < s.length(); ++i) {
156
if
(!s(i).compare(
"x"
)) {
157
addAxesToRemove
(0);
158
}
else
if
(!s(i).compare(
"y"
)) {
159
addAxesToRemove
(1);
160
}
else
if
(!s(i).compare(
"z"
)) {
161
addAxesToRemove
(2);
162
}
else
{
163
utils::Error::raise
(
"Axis must be 0 (\"x\"), 1 (\"y\") or 2 (\"z\")"
);
164
}
165
}
166
}
167
168
void
rigidbody::NodeSegment::addAxesToRemove
(
const
std::vector<size_t>&
axes
) {
169
for
(
size_t
i = 0; i <
axes
.size(); ++i) {
170
addAxesToRemove
(
axes
[i]);
171
}
172
}
173
174
void
rigidbody::NodeSegment::addAxesToRemove
(
175
const
std::vector<utils::String>&
axes
) {
176
for
(
size_t
i = 0; i <
axes
.size(); ++i) {
177
addAxesToRemove
(
axes
[i]);
178
}
179
}
180
181
utils::String
rigidbody::NodeSegment::axesToRemoveAsString
()
const
{
182
utils::String
axes
;
183
if
(
isAxisRemoved
(0)) {
184
axes
+=
"x"
;
185
}
186
if
(
isAxisRemoved
(1)) {
187
axes
+=
"y"
;
188
}
189
if
(
isAxisRemoved
(2)) {
190
axes
+=
"z"
;
191
}
192
return
axes
;
193
}
194
195
void
rigidbody::NodeSegment::setType
() {
196
*
m_typeOfNode
= utils::NODE_TYPE::BONE_POINT;
197
}
BIORBD_NAMESPACE::rigidbody::NodeSegment
A point attached to a segment, generally speaking a skin marker.
Definition
NodeSegment.h:20
BIORBD_NAMESPACE::rigidbody::NodeSegment::NodeSegment
NodeSegment()
Construct a segment node.
Definition
NodeSegment.cpp:8
BIORBD_NAMESPACE::rigidbody::NodeSegment::m_technical
std::shared_ptr< bool > m_technical
If a marker is a technical marker.
Definition
NodeSegment.h:226
BIORBD_NAMESPACE::rigidbody::NodeSegment::axesToRemoveAsString
utils::String axesToRemoveAsString() const
Return the axes to removed.
Definition
NodeSegment.cpp:181
BIORBD_NAMESPACE::rigidbody::NodeSegment::axesToRemove
const std::vector< bool > & axesToRemove() const
Accessor to axes to remove.
Definition
NodeSegment.cpp:104
BIORBD_NAMESPACE::rigidbody::NodeSegment::isAxisKept
bool isAxisKept(size_t i) const
Check if axis is kept.
Definition
NodeSegment.cpp:130
BIORBD_NAMESPACE::rigidbody::NodeSegment::axes
const std::vector< bool > axes() const
A vector of bool which is the opposite of axesToRemove.
Definition
NodeSegment.cpp:108
BIORBD_NAMESPACE::rigidbody::NodeSegment::DeepCopy
NodeSegment DeepCopy() const
Deep copy of the segment node.
Definition
NodeSegment.cpp:77
BIORBD_NAMESPACE::rigidbody::NodeSegment::isTechnical
bool isTechnical() const
Return if node is technical.
Definition
NodeSegment.cpp:100
BIORBD_NAMESPACE::rigidbody::NodeSegment::setType
void setType()
Set the type of the segment node.
Definition
NodeSegment.cpp:195
BIORBD_NAMESPACE::rigidbody::NodeSegment::setValues
void setValues(const NodeSegment &values)
Set internal values of the node without changing other parameters.
Definition
NodeSegment.cpp:92
BIORBD_NAMESPACE::rigidbody::NodeSegment::removeAxes
NodeSegment removeAxes() const
To remove axis.
Definition
NodeSegment.cpp:116
BIORBD_NAMESPACE::rigidbody::NodeSegment::m_nbAxesToRemove
std::shared_ptr< int > m_nbAxesToRemove
Definition
NodeSegment.h:223
BIORBD_NAMESPACE::rigidbody::NodeSegment::availableAxesIndices
std::vector< int > availableAxesIndices() const
Get all the indices of the axes to keep (X=0, Y=1, Z=2).
Definition
NodeSegment.cpp:134
BIORBD_NAMESPACE::rigidbody::NodeSegment::parentId
int parentId() const
Return the parent index.
Definition
NodeSegment.cpp:102
BIORBD_NAMESPACE::rigidbody::NodeSegment::addAxesToRemove
void addAxesToRemove(size_t axisNumber)
Add an axis to remove.
Definition
NodeSegment.cpp:146
BIORBD_NAMESPACE::rigidbody::NodeSegment::isAnatomical
bool isAnatomical() const
Return if node is anatomical.
Definition
NodeSegment.cpp:98
BIORBD_NAMESPACE::rigidbody::NodeSegment::nbAxesToRemove
int nbAxesToRemove() const
Return the number of axes to remove.
Definition
NodeSegment.cpp:144
BIORBD_NAMESPACE::rigidbody::NodeSegment::m_anatomical
std::shared_ptr< bool > m_anatomical
It marker is a anatomical marker.
Definition
NodeSegment.h:227
BIORBD_NAMESPACE::rigidbody::NodeSegment::m_axesRemoved
std::shared_ptr< std::vector< bool > > m_axesRemoved
The axes to remove.
Definition
NodeSegment.h:221
BIORBD_NAMESPACE::rigidbody::NodeSegment::isAxisRemoved
bool isAxisRemoved(size_t i) const
Check if axis is removed.
Definition
NodeSegment.cpp:126
BIORBD_NAMESPACE::rigidbody::NodeSegment::m_id
std::shared_ptr< int > m_id
The parent identification.
Definition
NodeSegment.h:228
BIORBD_NAMESPACE::utils::Error::raise
static void raise(const String &message)
Throw an error message.
Definition
Error.cpp:6
BIORBD_NAMESPACE::utils::Node::name
const String & name() const
Return the name of the node.
Definition
Node.cpp:43
BIORBD_NAMESPACE::utils::Node::m_typeOfNode
std::shared_ptr< NODE_TYPE > m_typeOfNode
The type of the node.
Definition
Node.h:92
BIORBD_NAMESPACE::utils::Node::DeepCopy
void DeepCopy(const Node &other)
Deep copy of the node in another node.
Definition
Node.cpp:35
BIORBD_NAMESPACE::utils::String
Wrapper around the std::string class with augmented functionality.
Definition
String.h:18
BIORBD_NAMESPACE::utils::Vector3d
Wrapper around Eigen Vector3d and attach it to a parent.
Definition
Vector3d.h:27
BIORBD_NAMESPACE::utils::Vector3d::Vector3d
Vector3d()
Construct 3D vector.
Definition
Vector3d.cpp:9
src
RigidBody
NodeSegment.cpp
Generated by
1.18.0