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