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