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