pinocchio  3.7.0
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
 
Loading...
Searching...
No Matches
model.hpp
1//
2// Copyright (c) 2021-2022 INRIA
3//
4
5#ifndef __pinocchio_multibody_pool_model_hpp__
6#define __pinocchio_multibody_pool_model_hpp__
7
8#include <algorithm>
9
10#include "pinocchio/multibody/pool/fwd.hpp"
11#include "pinocchio/multibody/model.hpp"
12#include "pinocchio/multibody/data.hpp"
13
14#include "pinocchio/utils/openmp.hpp"
15
16namespace pinocchio
17{
18 template<typename _Scalar, int _Options, template<typename, int> class JointCollectionTpl>
20 {
21 public:
23
24 typedef _Scalar Scalar;
25 enum
26 {
27 Options = _Options
28 };
29
32
33 typedef std::vector<Model, Eigen::aligned_allocator<Model>> ModelVector;
34 typedef std::vector<Data, Eigen::aligned_allocator<Data>> DataVector;
35
41 explicit ModelPoolTpl(
42 const Model & model, const size_t pool_size = (size_t)omp_get_max_threads())
43 : m_models(pool_size, model)
44 , m_datas(pool_size, Data(model))
45 {
46 }
47
57
62 void update(const Data & data)
63 {
64 std::fill(m_datas.begin(), m_datas.end(), data);
65 }
66
68 size_t size() const
69 {
70 return m_datas.size();
71 }
72
74 void resize(const size_t new_size)
75 {
76 const size_t size = m_datas.size();
77 m_models.resize((size_t)new_size);
78 m_datas.resize((size_t)new_size);
79
80 if (size < new_size)
81 {
82 typename ModelVector::iterator model_it = m_models.begin();
83 std::advance(model_it, (long)(new_size - size));
84 std::fill(model_it, m_models.end(), m_models[0]);
85
86 typename DataVector::iterator data_it = m_datas.begin();
87 std::advance(data_it, (long)(new_size - size));
88 std::fill(data_it, m_datas.end(), m_datas[0]);
89 }
90
91 doResize(new_size); // call Derived::doResize();
92 }
93
95 const ModelVector & getModels() const
96 {
97 return m_models;
98 }
99
101 ModelVector & getModels()
102 {
103 return m_models;
104 }
105
107 const Model & getModel(const size_t index) const
108 {
109 PINOCCHIO_CHECK_INPUT_ARGUMENT(
110 index < m_models.size(), "Index greater than the size of the model vector.");
111 return m_models[index];
112 }
113
115 Model & getModel(const size_t index)
116 {
117 PINOCCHIO_CHECK_INPUT_ARGUMENT(
118 index < m_models.size(), "Index greater than the size of the model vector.");
119 return m_models[index];
120 }
121
123 const DataVector & getDatas() const
124 {
125 return m_datas;
126 }
127
129 DataVector & getDatas()
130 {
131 return m_datas;
132 }
133
135 const Data & getData(const size_t index) const
136 {
137 PINOCCHIO_CHECK_INPUT_ARGUMENT(
138 index < m_datas.size(), "Index greater than the size of the datas vector.");
139 return m_datas[index];
140 }
141
143 Data & getData(const size_t index)
144 {
145 PINOCCHIO_CHECK_INPUT_ARGUMENT(
146 index < m_datas.size(), "Index greater than the size of the datas vector.");
147 return m_datas[index];
148 }
149
151 virtual ~ModelPoolTpl() {};
152
153 protected:
155 ModelVector m_models;
156
158 DataVector m_datas;
159
161 virtual void doResize(const size_t new_size)
162 {
163 PINOCCHIO_UNUSED_VARIABLE(new_size);
164 }
165 };
166
167} // namespace pinocchio
168
169#endif // ifndef __pinocchio_multibody_pool_model_hpp__
DataVector & getDatas()
Returns the data vector.
Definition model.hpp:129
size_t size() const
Returns the size of the pool.
Definition model.hpp:68
void update(const Data &data)
Update all the datas with the input data value.
Definition model.hpp:62
const Model & getModel(const size_t index) const
Return a specific model.
Definition model.hpp:107
const DataVector & getDatas() const
Returns the data vector.
Definition model.hpp:123
DataVector m_datas
&#160;
Definition model.hpp:158
const ModelVector & getModels() const
Returns the vector of models.
Definition model.hpp:95
ModelVector & getModels()
Returns the vector of models.
Definition model.hpp:101
Model & getModel(const size_t index)
Returns a specific model.
Definition model.hpp:115
ModelVector m_models
&#160;
Definition model.hpp:155
void resize(const size_t new_size)
Set the size of the pool and perform the appropriate resize.
Definition model.hpp:74
const Data & getData(const size_t index) const
Return a specific data.
Definition model.hpp:135
Data & getData(const size_t index)
Returns a specific data.
Definition model.hpp:143
virtual void doResize(const size_t new_size)
&#160;
Definition model.hpp:161
ModelPoolTpl(const Model &model, const size_t pool_size=(size_t) omp_get_max_threads())
Default constructor from a model and a pool size.
Definition model.hpp:41
ModelPoolTpl(const ModelPoolTpl &pool)
Copy constructor from an other PoolModel.
Definition model.hpp:52
virtual ~ModelPoolTpl()
&#160;
Definition model.hpp:151
Main pinocchio namespace.
Definition treeview.dox:11