CellSizeDataTreeStrategy.h
Go to the documentation of this file.
1 #ifndef GfxTL__CELLSIZEDATATREESTRATEGY_HEADER__
2 #define GfxTL__CELLSIZEDATATREESTRATEGY_HEADER__
3 
4 namespace GfxTL
5 {
6  template< class InheritedStrategyT, class KernelT >
8  {
9  typedef typename KernelT::value_type value_type;
10 
11  class CellData
12  : public InheritedStrategyT::CellData
13  {
14  public:
15  typedef typename KernelT::value_type value_type;
16  typedef unsigned int size_type;
17  size_type Size() const
18  {
19  return m_size;
20  }
21  void Size(unsigned int s)
22  {
23  m_size = s;
24  }
25 
27  };
28 
29  template< class BaseT >
31  : public InheritedStrategyT::template StrategyBase< BaseT >
32  , public KernelT
33  {
34 public:
35  typedef typename InheritedStrategyT::template StrategyBase< BaseT >
37  typedef typename BaseT::CellType CellType;
38  typedef typename KernelT::HandleType HandleType;
39  typedef typename KernelT::DereferencedType DereferencedType;
40  typedef std::pair< HandleType, HandleType > CellRange;
41  typedef typename KernelT::value_type value_type;
43 
44 protected:
46  {
47  public:
49  {
50  return m_range;
51  }
52  const CellRange& Range() const
53  {
54  return m_range;
55  }
56 
57  private:
58  CellRange m_range;
59  };
60 
61  template< class BaseTraversalT >
63  : public BaseTraversalT
64  {};
65 
66  template< class BaseTraversalT >
68  : public BaseTraversalT
69  {
70  public:
72  {
73  return m_range;
74  }
75  const CellRange& Range() const
76  {
77  return m_range;
78  }
79 
80  private:
81  CellRange m_range;
82  };
83 
84  template< class BuildInformationT >
85  void InitRootBuildInformation(BuildInformationT* bi) const
86  {
87  RootRange(&bi->Range());
88  }
89 
90  template< class BuildInformationT >
91  void InitBuildInformation(const CellType& parent,
92  const BuildInformationT& parentInfo, unsigned int childIdx,
93  BuildInformationT* bi) const
94  {
95  Range(parent, parentInfo.Range(), childIdx, &bi->Range());
96  }
97 
98  template< class BuildInformationT >
99  void InitRoot(const BuildInformationT& bi, CellType* cell)
100  {
101  cell->m_size = bi.Range().second - bi.Range().first;
102  }
103 
104  template< class BuildInformationT >
105  void InitCell(const CellType& parent,
106  const BuildInformationT& parentInfo, unsigned int childIdx,
107  const BuildInformationT& bi, CellType* cell)
108  {
109  cell->m_size = bi.Range().second - bi.Range().first;
110  }
111 
112  template< class TraversalInformationT >
114  TraversalInformationT* ti) const
115  {
116  RootRange(&ti->Range());
117  }
118 
119  template< class TraversalInformationT >
120  void InitTraversalInformation(const CellType& parent,
121  const TraversalInformationT& pTi, unsigned int childIdx,
122  TraversalInformationT* ti) const
123  {
124  Range(parent, pTi.Range(), childIdx, &ti->Range());
125  }
126 
127  void RootRange(CellRange* r) const
128  {
129  r->first = KernelT::BeginHandle();
130  r->second = KernelT::EndHandle();
131  }
132 
133  void Range(const CellType& parent,
134  const CellRange& parentRange, unsigned int child,
135  CellRange* r) const
136  {
137  r->first = parentRange.first;
138  for (unsigned int i = 0; i < child; ++i)
139  if (&(parent[i]) > (CellType*)1)
140  {
141  r->first += parent[i].m_size;
142  }
143  r->second = r->first + parent[child].m_size;
144  }
145 
146  template< class TraversalInformationT >
147  void GetCellRange(const CellType& cell, const TraversalInformationT& ti,
148  CellRange* range) const
149  {
150  *range = ti.Range();
151  }
152 
153  template< class SplitterT, class BuildInformationT >
154  void SplitData(const SplitterT& split, const CellType&,
155  const BuildInformationT& parentInfo, CellType* left,
156  CellType* right)
157  {
158  unsigned int sizes[2];
159  SplitData(split, parentInfo.Range(), &sizes[0], &sizes[1]);
160  left->m_size = sizes[0];
161  right->m_size = sizes[1];
162  }
163 
164  template< class SplitterT, class BuildInformationT >
165  void SplitData(const SplitterT* splitters,
166  const unsigned int numSplitters, const CellType&,
167  const BuildInformationT& parentInfo, CellType** cells)
168  {
169  unsigned int* sizes = new unsigned int[1 << numSplitters];
170  SplitData(splitters, numSplitters, parentInfo.Range(),
171  sizes);
172  unsigned int childCount = 0;
173  for (unsigned int i = 0;
174  i < (unsigned)(1 << numSplitters); ++i)
175  if (sizes[i])
176  {
177  cells[i] = new CellType;
178  cells[i]->m_size = sizes[i];
179  ++childCount;
180  }
181  else
182  {
183  cells[i] = NULL;
184  }
185  if (!cells[0] && childCount)
186  {
187  cells[0] = (CellType*)0x1;
188  }
189  delete sizes;
190  }
191 
192  template< class SplitterT >
193  void SplitData(const SplitterT* splitters,
194  const unsigned int numSplitters,
195  const CellRange& range, unsigned int* sizes)
196  {
197  const unsigned int numChildren = 1 << numSplitters;
198  SplitData(splitters[0], range, &(sizes[0]),
199  &(sizes[numChildren >> 1]));
200  if (numSplitters == 1)
201  {
202  return;
203  }
204  CellRange leftRange(range.first,
205  range.first + sizes[0]),
206  rightRange(leftRange.second, range.second);
207  SplitData(splitters + 1, numSplitters - 1, leftRange,
208  sizes);
209  SplitData(splitters + 1, numSplitters - 1, rightRange,
210  sizes + (numChildren >> 1));
211  }
212 
213  template< class SplitterT >
214  void SplitData(const SplitterT& split,
215  const CellRange& range, unsigned int* left, unsigned int* right)
216  {
217  if (range.second - range.first == 0)
218  {
219  *left = 0;
220  *right = 0;
221  return;
222  }
223  HandleType j = range.first;
224  HandleType k = range.second - 1;
225  while (1)
226  {
227  while (j <= k && split(at(Dereference(j))))
228  {
229  ++j;
230  }
231  while (j < k && !split(at(Dereference(k))))
232  {
233  --k;
234  }
235  if (j < k)
236  {
237  SwapHandles(k, j);
238  ++j;
239  --k;
240  }
241  else
242  {
243  break;
244  }
245  }
246  *left = j - range.first;
247  *right = (range.second - range.first)
248  - *left;
249  }
250 
251  template< class SplitterT >
252  bool SplitAndInsert(const SplitterT& split,
253  CellRange parentRange, CellType* left, CellType* right)
254  {
255  if (split(KernelT::back()))
256  {
257  ++(left->m_size);
258  return true;
259  }
260  else
261  {
262  ++(right->m_size);
263  return false;
264  }
265  }
266 
267  void InsertBack(const CellRange& range, CellType*)
268  {
269  KernelT::InsertBack(range.second - 1);
270  }
271 
273  {
274  if (cell(at(s)))
275  {
276  --cell[0].m_size;
277  return true;
278  }
279  else
280  {
281  --cell[1].m_size;
282  return false;
283  }
284  }
285 
287  {
288  KernelT::Remove(s);
289  }
290  };
291  };
292 };
293 
294 #endif
GfxTL::CellSizeDataTreeStrategy::CellData::value_type
KernelT::value_type value_type
Definition: CellSizeDataTreeStrategy.h:15
GfxTL::CellSizeDataTreeStrategy::StrategyBase::ThisType
StrategyBase< BaseT > ThisType
Definition: CellSizeDataTreeStrategy.h:42
GfxTL::CellSizeDataTreeStrategy::StrategyBase::InitRoot
void InitRoot(const BuildInformationT &bi, CellType *cell)
Definition: CellSizeDataTreeStrategy.h:99
GfxTL::CellSizeDataTreeStrategy::value_type
KernelT::value_type value_type
Definition: CellSizeDataTreeStrategy.h:9
GfxTL::CellSizeDataTreeStrategy::StrategyBase::InitRootBuildInformation
void InitRootBuildInformation(BuildInformationT *bi) const
Definition: CellSizeDataTreeStrategy.h:85
GfxTL::CellSizeDataTreeStrategy::StrategyBase::SplitAndInsert
bool SplitAndInsert(const SplitterT &split, CellRange parentRange, CellType *left, CellType *right)
Definition: CellSizeDataTreeStrategy.h:252
GfxTL::CellSizeDataTreeStrategy::CellData::size_type
unsigned int size_type
Definition: CellSizeDataTreeStrategy.h:16
GfxTL::CellSizeDataTreeStrategy::StrategyBase::GlobalTraversalInformation
Definition: CellSizeDataTreeStrategy.h:62
GfxTL::CellSizeDataTreeStrategy::StrategyBase::Range
void Range(const CellType &parent, const CellRange &parentRange, unsigned int child, CellRange *r) const
Definition: CellSizeDataTreeStrategy.h:133
GfxTL::CellSizeDataTreeStrategy::StrategyBase::InsertBack
void InsertBack(const CellRange &range, CellType *)
Definition: CellSizeDataTreeStrategy.h:267
GfxTL::CellSizeDataTreeStrategy::StrategyBase::CellRange
std::pair< HandleType, HandleType > CellRange
Definition: CellSizeDataTreeStrategy.h:40
GfxTL::CellSizeDataTreeStrategy::StrategyBase::TraversalInformation::Range
CellRange & Range()
Definition: CellSizeDataTreeStrategy.h:71
GfxTL::CellSizeDataTreeStrategy::StrategyBase::BuildInformation::Range
CellRange & Range()
Definition: CellSizeDataTreeStrategy.h:48
GfxTL::CellSizeDataTreeStrategy::StrategyBase::TraversalInformation::Range
const CellRange & Range() const
Definition: CellSizeDataTreeStrategy.h:75
GfxTL::CellSizeDataTreeStrategy::CellData::Size
size_type Size() const
Definition: CellSizeDataTreeStrategy.h:17
GfxTL::CellSizeDataTreeStrategy::StrategyBase::SplitData
void SplitData(const SplitterT *splitters, const unsigned int numSplitters, const CellType &, const BuildInformationT &parentInfo, CellType **cells)
Definition: CellSizeDataTreeStrategy.h:165
GfxTL::CellSizeDataTreeStrategy::StrategyBase::InitTraversalInformation
void InitTraversalInformation(const CellType &parent, const TraversalInformationT &pTi, unsigned int childIdx, TraversalInformationT *ti) const
Definition: CellSizeDataTreeStrategy.h:120
GfxTL::CellSizeDataTreeStrategy::StrategyBase::InitBuildInformation
void InitBuildInformation(const CellType &parent, const BuildInformationT &parentInfo, unsigned int childIdx, BuildInformationT *bi) const
Definition: CellSizeDataTreeStrategy.h:91
GfxTL::CellSizeDataTreeStrategy::StrategyBase::Remove
void Remove(DereferencedType s, CellType *)
Definition: CellSizeDataTreeStrategy.h:286
GfxTL::CellSizeDataTreeStrategy::StrategyBase::BuildInformation::Range
const CellRange & Range() const
Definition: CellSizeDataTreeStrategy.h:52
GfxTL::CellSizeDataTreeStrategy::StrategyBase::DereferencedType
KernelT::DereferencedType DereferencedType
Definition: CellSizeDataTreeStrategy.h:39
GfxTL
Definition: AABox.h:8
GfxTL::CellSizeDataTreeStrategy::StrategyBase::SplitData
void SplitData(const SplitterT *splitters, const unsigned int numSplitters, const CellRange &range, unsigned int *sizes)
Definition: CellSizeDataTreeStrategy.h:193
GfxTL::CellSizeDataTreeStrategy
Definition: CellSizeDataTreeStrategy.h:7
GfxTL::CellSizeDataTreeStrategy::StrategyBase::value_type
KernelT::value_type value_type
Definition: CellSizeDataTreeStrategy.h:41
GfxTL::CellSizeDataTreeStrategy::StrategyBase::TraversalInformation
Definition: CellSizeDataTreeStrategy.h:67
GfxTL::CellSizeDataTreeStrategy::StrategyBase::GetCellRange
void GetCellRange(const CellType &cell, const TraversalInformationT &ti, CellRange *range) const
Definition: CellSizeDataTreeStrategy.h:147
GfxTL::CellSizeDataTreeStrategy::StrategyBase::SplitData
void SplitData(const SplitterT &split, const CellType &, const BuildInformationT &parentInfo, CellType *left, CellType *right)
Definition: CellSizeDataTreeStrategy.h:154
GfxTL::CellSizeDataTreeStrategy::StrategyBase::RootRange
void RootRange(CellRange *r) const
Definition: CellSizeDataTreeStrategy.h:127
GfxTL::CellSizeDataTreeStrategy::CellData::m_size
size_type m_size
Definition: CellSizeDataTreeStrategy.h:26
GfxTL::CellSizeDataTreeStrategy::StrategyBase::CellType
BaseT::CellType CellType
Definition: CellSizeDataTreeStrategy.h:37
GfxTL::CellSizeDataTreeStrategy::StrategyBase::InitRootTraversalInformation
void InitRootTraversalInformation(const CellType &root, TraversalInformationT *ti) const
Definition: CellSizeDataTreeStrategy.h:113
GfxTL::CellSizeDataTreeStrategy::StrategyBase::HandleType
KernelT::HandleType HandleType
Definition: CellSizeDataTreeStrategy.h:38
GfxTL::CellSizeDataTreeStrategy::StrategyBase::BuildInformation
Definition: CellSizeDataTreeStrategy.h:45
GfxTL::CellSizeDataTreeStrategy::StrategyBase::Remove
bool Remove(CellType &cell, DereferencedType s)
Definition: CellSizeDataTreeStrategy.h:272
GfxTL::CellSizeDataTreeStrategy::CellData
Definition: CellSizeDataTreeStrategy.h:11
GfxTL::CellSizeDataTreeStrategy::StrategyBase::BaseType
InheritedStrategyT::template StrategyBase< BaseT > BaseType
Definition: CellSizeDataTreeStrategy.h:36
GfxTL::CellSizeDataTreeStrategy::StrategyBase::InitCell
void InitCell(const CellType &parent, const BuildInformationT &parentInfo, unsigned int childIdx, const BuildInformationT &bi, CellType *cell)
Definition: CellSizeDataTreeStrategy.h:105
GfxTL::CellSizeDataTreeStrategy::CellData::Size
void Size(unsigned int s)
Definition: CellSizeDataTreeStrategy.h:21
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33
GfxTL::CellSizeDataTreeStrategy::StrategyBase
Definition: CellSizeDataTreeStrategy.h:30
armarx::split
std::vector< std::string > split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
Definition: StringHelpers.cpp:36
GfxTL::CellSizeDataTreeStrategy::StrategyBase::SplitData
void SplitData(const SplitterT &split, const CellRange &range, unsigned int *left, unsigned int *right)
Definition: CellSizeDataTreeStrategy.h:214