Biorbd Release_1.13.0
Loading...
Searching...
No Matches
NodeSegment.cpp
1#define BIORBD_API_EXPORTS
2#include "RigidBody/NodeSegment.h"
3
4#include "Utils/Error.h"
5
6using namespace BIORBD_NAMESPACE;
7
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
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
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
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,
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)) {
58}
59
61 const utils::Vector3d& node,
62 const utils::String& name,
63 const utils::String& parentName,
64 bool isTechnical,
65 bool isAnatomical,
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)) {
75}
76
79 copy.DeepCopy(*this);
80 return copy;
81}
82
91
93 (*this)[0] = other[0];
94 (*this)[1] = other[1];
95 (*this)[2] = other[2];
96}
97
99
101
103
104const std::vector<bool>& rigidbody::NodeSegment::axesToRemove() const {
105 return *m_axesRemoved;
106}
107
108const 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
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
127 return (*m_axesRemoved)[i];
128}
129
131 return !isAxisRemoved(i);
132}
133
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
145
147 if (axisNumber > 2) {
148 utils::Error::raise("Axis must be 0 (\"x\"), 1 (\"y\") or 2 (\"z\")");
149 }
150 (*m_axesRemoved)[axisNumber] = true;
152}
153
155 for (size_t i = 0; i < s.length(); ++i) {
156 if (!s(i).compare("x")) {
158 } else if (!s(i).compare("y")) {
160 } else if (!s(i).compare("z")) {
162 } else {
163 utils::Error::raise("Axis must be 0 (\"x\"), 1 (\"y\") or 2 (\"z\")");
164 }
165 }
166}
167
168void rigidbody::NodeSegment::addAxesToRemove(const std::vector<size_t>& axes) {
169 for (size_t i = 0; i < axes.size(); ++i) {
171 }
172}
173
175 const std::vector<utils::String>& axes) {
176 for (size_t i = 0; i < axes.size(); ++i) {
178 }
179}
180
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
196 *m_typeOfNode = utils::NODE_TYPE::BONE_POINT;
197}
A point attached to a segment, generally speaking a skin marker.
Definition NodeSegment.h:20
NodeSegment()
Construct a segment node.
std::shared_ptr< bool > m_technical
If a marker is a technical marker.
utils::String axesToRemoveAsString() const
Return the axes to removed.
const std::vector< bool > & axesToRemove() const
Accessor to axes to remove.
bool isAxisKept(size_t i) const
Check if axis is kept.
const std::vector< bool > axes() const
A vector of bool which is the opposite of axesToRemove.
NodeSegment DeepCopy() const
Deep copy of the segment node.
bool isTechnical() const
Return if node is technical.
void setType()
Set the type of the segment node.
void setValues(const NodeSegment &values)
Set internal values of the node without changing other parameters.
NodeSegment removeAxes() const
To remove axis.
std::shared_ptr< int > m_nbAxesToRemove
std::vector< int > availableAxesIndices() const
Get all the indices of the axes to keep (X=0, Y=1, Z=2).
int parentId() const
Return the parent index.
void addAxesToRemove(size_t axisNumber)
Add an axis to remove.
bool isAnatomical() const
Return if node is anatomical.
int nbAxesToRemove() const
Return the number of axes to remove.
std::shared_ptr< bool > m_anatomical
It marker is a anatomical marker.
std::shared_ptr< std::vector< bool > > m_axesRemoved
The axes to remove.
bool isAxisRemoved(size_t i) const
Check if axis is removed.
std::shared_ptr< int > m_id
The parent identification.
static void raise(const String &message)
Throw an error message.
Definition Error.cpp:6
const String & name() const
Return the name of the node.
Definition Node.cpp:43
std::shared_ptr< NODE_TYPE > m_typeOfNode
The type of the node.
Definition Node.h:92
void DeepCopy(const Node &other)
Deep copy of the node in another node.
Definition Node.cpp:35
Wrapper around the std::string class with augmented functionality.
Definition String.h:18
Wrapper around Eigen Vector3d and attach it to a parent.
Definition Vector3d.h:27
Vector3d()
Construct 3D vector.
Definition Vector3d.cpp:9