pinocchio  3.2.0
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
broadphase-manager.hpp
1 //
2 // Copyright (c) 2022 INRIA
3 //
4 
5 #ifndef __pinocchio_collision_pool_broadphase_manager_hpp__
6 #define __pinocchio_collision_pool_broadphase_manager_hpp__
7 
8 #include <omp.h>
9 
10 #include "pinocchio/multibody/pool/geometry.hpp"
11 #include "pinocchio/collision/broadphase-manager.hpp"
12 
13 namespace pinocchio
14 {
15 
16  template<
17  typename _BroadPhaseManagerDerived,
18  typename _Scalar,
19  int _Options,
20  template<typename, int>
21  class JointCollectionTpl>
22  class BroadPhaseManagerPoolBase : public GeometryPoolTpl<_Scalar, _Options, JointCollectionTpl>
23  {
24  public:
25  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
26 
27  typedef _BroadPhaseManagerDerived BroadPhaseManager;
29  typedef _Scalar Scalar;
30  enum
31  {
32  Options = _Options
33  };
34 
35  typedef typename Base::Model Model;
36  typedef typename Base::Data Data;
37  typedef typename Base::DataVector DataVector;
38  typedef typename Base::GeometryModel GeometryModel;
39  typedef typename Base::GeometryData GeometryData;
40 
41  // typedef std::vector<BroadPhaseManager,Eigen::aligned_allocator<BroadPhaseManager> >
42  // BroadPhaseManagerVector;
43 
44  typedef std::vector<BroadPhaseManager> BroadPhaseManagerVector;
45 
53  const Model & model,
54  const GeometryModel & geometry_model,
55  const size_t pool_size = (size_t)omp_get_max_threads())
56  : Base(model, geometry_model, pool_size)
57  {
58  init();
59  }
60 
66  : Base(other)
67  , m_managers(other.m_managers)
68  {
69  }
70 
72  const BroadPhaseManager & getBroadPhaseManager(const size_t index) const
73  {
74  PINOCCHIO_CHECK_INPUT_ARGUMENT(
75  index < m_managers.size(), "Index greater than the size of the manager vector.");
76  return m_managers[index];
77  }
78 
80  BroadPhaseManager & getBroadPhaseManager(const size_t index)
81  {
82  PINOCCHIO_CHECK_INPUT_ARGUMENT(
83  index < m_managers.size(), "Index greater than the size of the manager vector.");
84  return m_managers[index];
85  }
86 
88  const BroadPhaseManagerVector & getBroadPhaseManagers() const
89  {
90  return m_managers;
91  }
92 
94  BroadPhaseManagerVector & getBroadPhaseManagers()
95  {
96  return m_managers;
97  }
98 
99  using Base::getData;
100  using Base::getDatas;
101  using Base::getGeometryData;
105  using Base::getModel;
106  using Base::getModels;
107  using Base::size;
108  using Base::update;
109 
115  virtual void update(const GeometryData & geometry_data)
116  {
117  Base::update(geometry_data);
118 
119  for (size_t i = 0; i < size(); ++i)
120  {
121  m_managers[i].update(&getGeometryData(i));
122  }
123  }
124 
126  bool check() const
127  {
128  for (size_t i = 0; i < size(); ++i)
129  {
130  const BroadPhaseManager & manager = m_managers[i];
131  bool res = true;
132  res &= (&manager.getModel() == &getModel(i));
133  res &= (&manager.getGeometryData() == &getGeometryData(i));
134 
135  res &= (&manager.getGeometryModel() == &getGeometryModel(i));
136  res &= manager.check();
137 
138  if (!res)
139  return false;
140  }
141 
142  return true;
143  }
144 
147 
148  protected:
149  void init()
150  {
151  m_managers.reserve(size());
152  for (size_t i = 0; i < size(); ++i)
153  {
154  m_managers.push_back(
155  BroadPhaseManager(&getModel(i), &getGeometryModel(i), &getGeometryData(i)));
156  }
157  }
158 
160  BroadPhaseManagerVector m_managers;
161 
163  virtual void doResize(const size_t new_size)
164  {
165  m_managers.resize(new_size);
166  if (size() < new_size)
167  {
168  typename BroadPhaseManagerVector::iterator it = m_managers.begin();
169  std::advance(it, (long)(new_size - size()));
170  std::fill(it, m_managers.end(), m_managers[0]);
171  }
172  }
173  };
174 } // namespace pinocchio
175 
176 #endif // ifndef __pinocchio_collision_pool_broadphase_manager_hpp__
virtual void update(const GeometryData &geometry_data)
Update the geometry datas with the new value.
bool check() const
Check the validity of the current broadphase.
BroadPhaseManager & getBroadPhaseManager(const size_t index)
Returns the geometry_data at index.
const GeometryData & getGeometryData(const size_t index) const
Returns the geometry_data at given index.
Definition: geometry.hpp:99
const GeometryModel & getGeometryModel(const size_t index) const
Returns the geometry_model at given index.
Definition: geometry.hpp:81
const BroadPhaseManagerVector & getBroadPhaseManagers() const
Access to the vector of broad phase managers.
BroadPhaseManagerPoolBase(const Model &model, const GeometryModel &geometry_model, const size_t pool_size=(size_t) omp_get_max_threads())
Default constructor from a model and a pool size.
BroadPhaseManagerVector m_managers
Broad phase managers associated to the pool.
BroadPhaseManagerPoolBase(const BroadPhaseManagerPoolBase &other)
Copy constructor from an other BroadPhaseManagerPoolTpl.
virtual void doResize(const size_t new_size)
&#160;
const BroadPhaseManager & getBroadPhaseManager(const size_t index) const
Returns the geometry_data at index.
BroadPhaseManagerVector & getBroadPhaseManagers()
Access to the vector of broad phase managers.
const GeometryDataVector & getGeometryDatas() const
Returns the vector of Geometry Data.
Definition: geometry.hpp:117
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 GeometryModelVector & getGeometryModels() const
Returns the vector of Geometry Model.
Definition: geometry.hpp:129
const GeometryData & getGeometryData(const size_t index) const
Returns the geometry_data at given index.
Definition: geometry.hpp:99
const GeometryModel & getGeometryModel(const size_t index) const
Returns the geometry_model at given index.
Definition: geometry.hpp:81
const Data & getData(const size_t index) const
Return a specific data.
Definition: model.hpp:135
const DataVector & getDatas() const
Returns the data vector.
Definition: model.hpp:123
const ModelVector & getModels() const
Returns the vector of models.
Definition: model.hpp:95
const Model & getModel(const size_t index) const
Return a specific model.
Definition: model.hpp:107
Main pinocchio namespace.
Definition: treeview.dox:11