Biorbd
PathModifiers.cpp
1 #define BIORBD_API_EXPORTS
2 #include "Muscles/PathModifiers.h"
3 
4 #include "Utils/Error.h"
5 #include "Utils/Vector3d.h"
6 #include "Muscles/ViaPoint.h"
7 #include "Muscles/WrappingSphere.h"
8 #include "Muscles/WrappingCylinder.h"
9 
11  m_obj(std::make_shared<std::vector<biorbd::utils::Vector3d>>()),
12  m_nbWraps(std::make_shared<unsigned int>(0)),
13  m_nbVia(std::make_shared<unsigned int>(0)),
14  m_totalObjects(std::make_shared<unsigned int>(0))
15 {
16 
17 }
18 
20 {
22  copy.DeepCopy(*this);
23  return copy;
24 }
25 
27 {
28  m_obj->resize(other.m_obj->size());
29  for (unsigned int i=0; i<other.m_obj->size(); ++i)
30  (*m_obj)[i] = (*other.m_obj)[i].DeepCopy();
31  *m_nbWraps = *other.m_nbWraps;
32  *m_nbVia = *other.m_nbVia;
33  *m_totalObjects = *other.m_totalObjects;
34 }
35 
36 // Private method to assing values
38  biorbd::utils::Vector3d &object){
39 
40  // Add a muscle to the pool of muscle depending on type
41  if (object.typeOfNode() == biorbd::utils::NODE_TYPE::WRAPPING_SPHERE){
42  biorbd::utils::Error::check(*m_nbVia == 0, "Cannot mix via points and wrapping objects yet");
43  m_obj->push_back(biorbd::muscles::WrappingSphere(static_cast<biorbd::muscles::WrappingSphere&> (object)));
44  ++*m_nbWraps;
45  }
46  else if (object.typeOfNode() == biorbd::utils::NODE_TYPE::WRAPPING_CYLINDER){
47  biorbd::utils::Error::check(*m_nbVia == 0, "Cannot mix via points and wrapping objects yet");
48  m_obj->push_back(biorbd::muscles::WrappingCylinder(dynamic_cast <biorbd::muscles::WrappingCylinder&> (object)));
49  ++*m_nbWraps;
50  }
51  else if (object.typeOfNode() == biorbd::utils::NODE_TYPE::VIA_POINT){
52  biorbd::utils::Error::check(*m_nbWraps == 0, "Cannot mix via points and wrapping objects yet");
53  m_obj->push_back(biorbd::muscles::ViaPoint(dynamic_cast <biorbd::muscles::ViaPoint&> (object)));
54  ++*m_nbVia;
55  }
56  else
57  biorbd::utils::Error::raise("Wrapping type not found");
58  ++*m_totalObjects;
59 }
60 
62  return *m_nbWraps;
63 }
64 
66 {
67  return *m_nbVia;
68 }
69 
71 {
72  return *m_totalObjects;
73 }
74 
76 {
77  biorbd::utils::Error::check(idx<nbObjects(), "Idx asked is higher than number of wrapping objects");
78  return (*m_obj)[idx];
79 }
80 
81 
83  biorbd::utils::Error::check(idx<nbObjects(), "Idx asked is higher than number of wrapping objects");
84  return (*m_obj)[idx];
85 }
86 
87 
88 
89 
biorbd::muscles::PathModifiers::m_obj
std::shared_ptr< std::vector< biorbd::utils::Vector3d > > m_obj
set of objects
Definition: PathModifiers.h:79
biorbd::muscles::PathModifiers::m_totalObjects
std::shared_ptr< unsigned int > m_totalObjects
Number of total objects in the set.
Definition: PathModifiers.h:82
biorbd::muscles::WrappingCylinder
Cylinder object that makes the muscle to wrap around.
Definition: WrappingCylinder.h:13
biorbd::muscles::PathModifiers::nbWraps
unsigned int nbWraps() const
Return the total number of wrapping objects in the set.
Definition: PathModifiers.cpp:61
biorbd::muscles::WrappingSphere
Sphere object that makes the muscle to wrap around.
Definition: WrappingSphere.h:13
biorbd::utils::Vector3d
Wrapper around Eigen Vector3d and attach it to a parent.
Definition: Vector3d.h:24
biorbd::muscles::PathModifiers::nbObjects
unsigned int nbObjects() const
Return the total number of path modifier objects in the set.
Definition: PathModifiers.cpp:70
biorbd::muscles::PathModifiers::m_nbVia
std::shared_ptr< unsigned int > m_nbVia
Number of via points in the set.
Definition: PathModifiers.h:81
biorbd::muscles::ViaPoint
Via point of a muscle.
Definition: ViaPoint.h:16
biorbd::utils::Error::raise
static void raise(const biorbd::utils::String &message)
Throw an error message.
Definition: Error.cpp:4
biorbd::muscles::PathModifiers::addPathChanger
void addPathChanger(biorbd::utils::Vector3d &object)
Add a wrapping or a via point to the set of path modifiers.
Definition: PathModifiers.cpp:37
biorbd::muscles::PathModifiers::nbVia
unsigned int nbVia() const
Return the total number of via points in the set.
Definition: PathModifiers.cpp:65
biorbd::muscles::PathModifiers::DeepCopy
biorbd::muscles::PathModifiers DeepCopy() const
Deep copy of path changers.
Definition: PathModifiers.cpp:19
biorbd::muscles::PathModifiers::PathModifiers
PathModifiers()
Construct path changers.
Definition: PathModifiers.cpp:10
biorbd::muscles::PathModifiers
Holder of all the path modifiers of a muscle.
Definition: PathModifiers.h:18
biorbd::muscles::PathModifiers::object
biorbd::utils::Vector3d & object(unsigned int idx)
Return the object at a specific index in the set.
Definition: PathModifiers.cpp:75
biorbd::muscles::PathModifiers::m_nbWraps
std::shared_ptr< unsigned int > m_nbWraps
Number of wrapping object in the set.
Definition: PathModifiers.h:80
biorbd::utils::Error::check
static void check(bool cond, const biorbd::utils::String &message)
Assert that raises the error message if false.
Definition: Error.cpp:10