IndexedTreeDataStrategy.h
Go to the documentation of this file.
1 #ifndef __GfxTL_INDEXEDTREEDATASTRATEGY_HEADER__
2 #define __GfxTL_INDEXEDTREEDATASTRATEGY_HEADER__
3 
4 #include <list>
5 #include <vector>
6 
7 namespace GfxTL
8 {
9 
10  template <class InheritedStrategy, class Data>
12  {
13  private:
14  template <class Data>
15  class IndexedTreeDataCore
16  {
17  public:
18  typedef Data DataType;
19  typedef typename Data::PointType PointType;
20  typedef typename PointType::ScalarType ScalarType;
21 
22  Data&
23  ContainedData()
24  {
25  return _data;
26  }
27 
28  const Data&
29  ContainedData() const
30  {
31  return _data;
32  }
33 
34  PointType&
35  PointTranslated(size_t i)
36  {
37  return _data.Point(i);
38  }
39 
40  const PointType
41  PointTranslated(size_t i) const
42  {
43  return _data.Point(i);
44  }
45 
46  PointType&
47  operator[](size_t i)
48  {
49  return _data.Point(i);
50  }
51 
52  const PointType
53  operator[](size_t i) const
54  {
55  return _data.Point(i);
56  }
57 
58  private:
59  Data _data;
60  };
61 
62  template <class Data>
63  class IndexedTreeDataCore<const Data>
64  {
65  public:
66  typedef const Data DataType;
67  typedef typename Data::PointType PointType;
68  typedef typename PointType::ScalarType ScalarType;
69 
70  Data&
71  NonConstContainedData()
72  {
73  return _data;
74  }
75 
76  const Data&
77  ContainedData() const
78  {
79  return _data;
80  }
81 
82  const PointType
83  PointTranslated(size_t i) const
84  {
85  return _data.Point(i);
86  }
87 
88  const PointType
89  operator[](size_t i) const
90  {
91  return _data.Point(i);
92  }
93 
94  private:
95  Data _data;
96  };
97 
98  template <class Data>
99  class IndexedTreeDataCore<Data*>
100  {
101  public:
102  typedef Data DataType;
103  typedef typename Data::PointType PointType;
104  typedef typename PointType::ScalarType ScalarType;
105 
106  IndexedTreeDataCore() : _data(NULL)
107  {
108  }
109 
110  Data&
111  ContainedData()
112  {
113  return *_data;
114  }
115 
116  const Data&
117  ContainedData() const
118  {
119  return *_data;
120  }
121 
122  void
123  ContainedDataPtr(Data* data)
124  {
125  _data = data;
126  }
127 
128  PointType&
129  PointTranslated(size_t i)
130  {
131  return _data->Point(i);
132  }
133 
134  const PointType
135  PointTranslated(size_t i) const
136  {
137  return _data->Point(i);
138  }
139 
140  PointType&
141  operator[](size_t i)
142  {
143  return _data->Point(i);
144  }
145 
146  const PointType
147  operator[](size_t i) const
148  {
149  return _data->Point(i);
150  }
151 
152  private:
153  Data* _data;
154  };
155 
156  template <class Data>
157  class IndexedTreeDataCore<const Data*>
158  {
159  public:
160  typedef const Data DataType;
161  typedef typename Data::PointType PointType;
162  typedef typename PointType::ScalarType ScalarType;
163 
164  const Data&
165  ContainedData() const
166  {
167  return *_data;
168  }
169 
170  void
171  ContainedDataPtr(const Data* data)
172  {
173  _data = data;
174  }
175 
176  const PointType
177  PointTranslated(size_t i) const
178  {
179  return _data->Point(i);
180  }
181 
182  const PointType
183  operator[](size_t i) const
184  {
185  return _data->Point(i);
186  }
187 
188  private:
189  const Data* _data;
190  };
191 
192  public:
193  typedef size_t HandleType;
194  typedef std::vector<HandleType> IndicesType;
195  typedef size_t CellIndicesType;
196  typedef typename IndexedTreeDataCore<Data>::DataType DataType;
197  typedef typename DataType::PointType PointType;
198  typedef typename PointType::ScalarType ScalarType;
199 
200  template <class Point>
201  class CellData : public InheritedStrategy::CellData<Point>
202  {
203  public:
205 
206  CellData() : _size(0)
207  {
208  }
209 
210  CellData(const CellIndicesType& indices, size_t size) : _indices(indices), _size(size)
211  {
212  }
213 
214  size_t
215  Size() const
216  {
217  return _size;
218  }
219 
220  void
221  Size(size_t size)
222  {
223  _size = size;
224  }
225 
226  const CellIndicesType
227  Points() const
228  {
229  return _indices;
230  }
231 
232  const CellIndicesType
233  Normals() const
234  {
235  return _indices;
236  }
237 
238  void
239  Data(const CellIndicesType indices, size_t size)
240  {
241  _indices = indices;
242  _size = size;
243  }
244 
245  void
246  Data(const ThisType& c)
247  {
248  _indices = c._indices;
249  _size = c._size;
250  }
251 
253  Indices() const
254  {
255  return _indices;
256  }
257 
258  void
260  {
261  _indices = indices;
262  }
263 
264  private:
265  CellIndicesType _indices;
266  size_t _size;
267  };
268 
269  template <class Base>
270  class StrategyBase :
271  public InheritedStrategy::StrategyBase<Base>,
272  public IndexedTreeDataCore<Data>
273  {
274  public:
275  typedef typename Base::CellType CellType;
276  typedef typename IndexedTreeDataCore<Data>::DataType DataType;
277  typedef typename DataType::PointType PointType;
278  typedef typename PointType::ScalarType ScalarType;
279  typedef
281  typedef
283  typedef typename InheritedStrategy::StrategyBase<Base> StrategyBaseType;
284 
286  {
287  }
288 
289  void
291  {
292  StrategyBaseType::Clear();
293  _indices.clear();
294  }
295 
296  size_t
298  {
299  return _indices[i];
300  }
301 
302  size_t
303  Size() const
304  {
305  return ContainedData().Size();
306  }
307 
308  void
309  PointsInCell(const CellType& cell, std::vector<size_t>* points) const
310  {
311  points->clear();
312  for (size_t i = 0; i < cell.Size(); ++i)
313  {
314  points->push_back(Translate(cell.Points() + i));
315  }
316  }
317 
318  void
320  {
321  cube->Bound(*this, Size());
322  }
323 
324  template <class BV>
325  void
327  {
328  bv->Bound(*this, Size());
329  }
330 
331  void
332  Add(const DataType& data)
333  {
334  ContainedData().Add(data);
336  bc.Bound(data.Points(), data.Size());
338  }
339 
340  template <class T>
341  void
342  Transform(const T& t)
343  {
344  ContainedData().Transform(t);
345  AACube<PointType> bc; // is infinite
347  }
348 
349  template <class T>
350  void
351  Transform(size_t i, const T& t)
352  {
353  ContainedData().Transform(i, t);
354  AACube<PointType> bc; // is infinite
356  }
357 
358  void
359  Translate(const PointType& translation)
360  {
361  ContainedData().Translate(translation);
362  AACube<PointType> bc; // is infinite
364  }
365 
366  template <class TFunc>
367  void
368  TransformFunc(TFunc tfunc)
369  {
370  ContainedData().TransformFunc(tfunc);
371  AACube<PointType> bc; // is infinite
373  }
374 
375  template <class BoundingVolume>
376  void
378  {
379  ContainedData().Remove(bv);
380  AACube<PointType> bc; // is infinite
382  }
383 
384  virtual void
386  {
387  if (_indices.size() != ContainedData().Size())
388  {
389  size_t oldSize = _indices.size();
390  _indices.resize(ContainedData().Size());
391  for (size_t i = oldSize; i < _indices.size(); ++i)
392  {
393  _indices[i] = i;
394  }
395  }
396  }
397 
398  protected:
399  template <class BoundingVolume>
400  void
402  {
403  _indices.resize(ContainedData().Size());
404  for (size_t i = 0; i < ContainedData().Size(); ++i)
405  {
406  _indices[i] = i;
407  }
408  IndicesType::iterator j = _indices.begin();
409  IndicesType::iterator k = _indices.begin() + _indices.size() - 1;
410  for (; j <= k;)
411  {
412  if (!bv.IsInside(ContainedData().Point(*j)))
413  {
414  HandleType q = *k;
415  *k = *j;
416  *j = q;
417  --k;
418  }
419  else
420  {
421  ++j;
422  }
423  }
424  cell->Data(0, j - _indices.begin());
425  }
426 
427  void
429  unsigned int axis,
430  ScalarType s,
431  CellType* left,
432  CellType* right)
433  {
434  if (cell.Size() == 0)
435  {
436  right->Data(cell);
437  left->Data(cell);
438  return;
439  }
440  IndicesType::iterator j = _indices.begin() + cell.Indices();
441  IndicesType::iterator k = _indices.begin() + cell.Indices() + cell.Size() - 1;
442  for (; j <= k;)
443  {
444  if (ContainedData().Point(*j)[axis] > s)
445  {
446  HandleType q = *k;
447  *k = *j;
448  *j = q;
449  --k;
450  }
451  else
452  {
453  ++j;
454  }
455  }
456  left->Indices(cell.Indices());
457  left->Size(j - (_indices.begin() + cell.Indices()));
458  right->Indices(cell.Indices() + left->Size());
459  right->Size((cell.Indices() + cell.Size()) - right->Indices());
460  }
461 
462  void
464  {
465  cube->BoundingCube(IndexPoints(data, data.Indices(), data.Size()), data.Size());
466  }
467 
468  private:
469  IndicesType _indices;
470  };
471  };
472 
473 }; // namespace GfxTL
474 
475 #endif
GfxTL::IndexedTreeDataStrategy::CellData::ThisType
CellData< Point > ThisType
Definition: IndexedTreeDataStrategy.h:204
GfxTL::AACube
Definition: AACube.h:11
armarx::view_selection::skills::direction::state::right
state::Type right(state::Type previous)
Definition: LookDirection.cpp:264
GfxTL::IndexedTreeDataStrategy::CellData::Data
void Data(const CellIndicesType indices, size_t size)
Definition: IndexedTreeDataStrategy.h:239
GfxTL::IndexedTreeDataStrategy::CellData::Indices
void Indices(CellIndicesType indices)
Definition: IndexedTreeDataStrategy.h:259
visionx::armem::pointcloud::PointType
PointType
Definition: constants.h:78
GfxTL::IndexedTreeDataStrategy::StrategyBase::CellType
Base::CellType CellType
Definition: IndexedTreeDataStrategy.h:275
GfxTL::IndexedTreeDataStrategy::StrategyBase::Translate
size_t Translate(HandleType i) const
Definition: IndexedTreeDataStrategy.h:297
GfxTL::IndexedTreeDataStrategy::StrategyBase::Add
void Add(const DataType &data)
Definition: IndexedTreeDataStrategy.h:332
GfxTL::IndexedTreeDataStrategy::StrategyBase::Transform
void Transform(const T &t)
Definition: IndexedTreeDataStrategy.h:342
GfxTL::IndexedTreeDataStrategy::DataType
IndexedTreeDataCore< Data >::DataType DataType
Definition: IndexedTreeDataStrategy.h:196
GfxTL::IndexedTreeDataStrategy::IndicesType
std::vector< HandleType > IndicesType
Definition: IndexedTreeDataStrategy.h:194
GfxTL::IndexedTreeDataStrategy::StrategyBase::Size
size_t Size() const
Definition: IndexedTreeDataStrategy.h:303
GfxTL::IndexedTreeDataStrategy::StrategyBase::DataType
IndexedTreeDataCore< Data >::DataType DataType
Definition: IndexedTreeDataStrategy.h:276
GfxTL::IndexedTreeDataStrategy::StrategyBase::TransformFunc
void TransformFunc(TFunc tfunc)
Definition: IndexedTreeDataStrategy.h:368
GfxTL::IndexedTreeDataStrategy::StrategyBase::Remove
void Remove(const BoundingVolume &bv)
Definition: IndexedTreeDataStrategy.h:377
GfxTL::IndexedTreeDataStrategy
Definition: IndexedTreeDataStrategy.h:11
GfxTL::IndexedTreeDataStrategy::StrategyBase::StrategyBaseType
InheritedStrategy::StrategyBase< Base > StrategyBaseType
Definition: IndexedTreeDataStrategy.h:283
GfxTL::AACube::Bound
void Bound(const Points &points, size_t size)
Definition: AACube.h:86
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
GfxTL::IndexedTreeDataStrategy::CellData::Size
void Size(size_t size)
Definition: IndexedTreeDataStrategy.h:221
GfxTL::IndexedTreeDataStrategy::StrategyBase::IndicesType
IndexedTreeDataStrategy< InheritedStrategy, Data >::IndicesType IndicesType
Definition: IndexedTreeDataStrategy.h:282
GfxTL::IndexedTreeDataStrategy::StrategyBase::Clear
void Clear()
Definition: IndexedTreeDataStrategy.h:290
GfxTL::IndexedTreeDataStrategy::StrategyBase::BoundingCube
void BoundingCube(AACube< PointType > *cube)
Definition: IndexedTreeDataStrategy.h:319
GfxTL::IndexedTreeDataStrategy::StrategyBase::BoundingCube
void BoundingCube(const CellType &data, AACube< PointType > *cube)
Definition: IndexedTreeDataStrategy.h:463
GfxTL::IndexedTreeDataStrategy::StrategyBase::HandleType
IndexedTreeDataStrategy< InheritedStrategy, Data >::HandleType HandleType
Definition: IndexedTreeDataStrategy.h:280
GfxTL::IndexedTreeDataStrategy::HandleType
size_t HandleType
Definition: IndexedTreeDataStrategy.h:193
GfxTL::IndexedTreeDataStrategy::StrategyBase::PointType
DataType::PointType PointType
Definition: IndexedTreeDataStrategy.h:277
GfxTL::IndexedTreeDataStrategy::StrategyBase::StrategyBase
StrategyBase()
Definition: IndexedTreeDataStrategy.h:285
GfxTL::IndexedTreeDataStrategy::StrategyBase
Definition: IndexedTreeDataStrategy.h:270
pcl::graph::indices
pcl::PointIndices::Ptr indices(const PCG &g)
Retrieve the indices of the points of the point cloud stored in a point cloud graph that actually bel...
Definition: point_cloud_graph.h:717
GfxTL::IndexedTreeDataStrategy::StrategyBase::SplitAlongAxis
void SplitAlongAxis(const CellType &cell, unsigned int axis, ScalarType s, CellType *left, CellType *right)
Definition: IndexedTreeDataStrategy.h:428
GfxTL::IndexedTreeDataStrategy::CellData::Normals
const CellIndicesType Normals() const
Definition: IndexedTreeDataStrategy.h:233
GfxTL::IndexedTreeDataStrategy::CellData::CellData
CellData()
Definition: IndexedTreeDataStrategy.h:206
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
GfxTL::IndexedTreeDataStrategy::CellData::Points
const CellIndicesType Points() const
Definition: IndexedTreeDataStrategy.h:227
visionx::Point
Eigen::Vector3f Point
Definition: ObjectShapeClassification.h:70
GfxTL::IndexedTreeDataStrategy::StrategyBase::ScalarType
PointType::ScalarType ScalarType
Definition: IndexedTreeDataStrategy.h:278
GfxTL::IndexedTreeDataStrategy::StrategyBase::RefreshWithNewTreeData
virtual void RefreshWithNewTreeData(const AACube< PointType > &bc)
Definition: IndexedTreeDataStrategy.h:385
GfxTL::IndexedTreeDataStrategy::StrategyBase::PointsInCell
void PointsInCell(const CellType &cell, std::vector< size_t > *points) const
Definition: IndexedTreeDataStrategy.h:309
GfxTL::IndexedTreeDataStrategy::StrategyBase::RootCellData
void RootCellData(const BoundingVolume &bv, CellType *cell)
Definition: IndexedTreeDataStrategy.h:401
q
#define q
GfxTL
Definition: AABox.h:9
GfxTL::IndexedTreeDataStrategy::StrategyBase::Translate
void Translate(const PointType &translation)
Definition: IndexedTreeDataStrategy.h:359
GfxTL::IndexedTreeDataStrategy::StrategyBase::BoundingVolume
void BoundingVolume(BV *bv)
Definition: IndexedTreeDataStrategy.h:326
GfxTL::IndexedTreeDataStrategy::PointType
DataType::PointType PointType
Definition: IndexedTreeDataStrategy.h:197
GfxTL::IndexedTreeDataStrategy::CellData::Data
void Data(const ThisType &c)
Definition: IndexedTreeDataStrategy.h:246
GfxTL::IndexedTreeDataStrategy::CellData::Indices
CellIndicesType Indices() const
Definition: IndexedTreeDataStrategy.h:253
GfxTL::IndexedTreeDataStrategy::CellData::CellData
CellData(const CellIndicesType &indices, size_t size)
Definition: IndexedTreeDataStrategy.h:210
GfxTL::IndexedTreeDataStrategy::CellIndicesType
size_t CellIndicesType
Definition: IndexedTreeDataStrategy.h:195
GfxTL::IndexedTreeDataStrategy::StrategyBase::Transform
void Transform(size_t i, const T &t)
Definition: IndexedTreeDataStrategy.h:351
GfxTL::IndexedTreeDataStrategy::CellData
Definition: IndexedTreeDataStrategy.h:201
armarx::view_selection::skills::direction::state::left
state::Type left(state::Type previous)
Definition: LookDirection.cpp:258
T
float T
Definition: UnscentedKalmanFilterTest.cpp:38
GfxTL::IndexedTreeDataStrategy::ScalarType
PointType::ScalarType ScalarType
Definition: IndexedTreeDataStrategy.h:198
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33
GfxTL::IndexedTreeDataStrategy::CellData::Size
size_t Size() const
Definition: IndexedTreeDataStrategy.h:215