1 #ifndef GfxTL__CELLRANGEDATATREESTRATEGY_HEADER__
2 #define GfxTL__CELLRANGEDATATREESTRATEGY_HEADER__
7 template<
class InheritedStrategyT,
class KernelT >
13 :
public InheritedStrategyT::CellData
18 typedef std::pair< HandleType, HandleType >
CellRange;
34 template<
class BaseT >
36 :
public InheritedStrategyT::template
StrategyBase< BaseT >
45 typedef std::pair< HandleType, HandleType >
CellRange;
66 template<
class BaseTraversalT >
68 :
public BaseTraversalT
71 template<
class BaseTraversalT >
73 :
public BaseTraversalT
76 template<
class BaseTraversalT >
78 :
public BaseTraversalT
81 template<
class BuildInformationT >
84 bi->Range() =
CellRange(KernelT::BeginHandle(),
85 KernelT::EndHandle());
88 template<
class BuildInformationT >
90 const BuildInformationT& parentInfo,
unsigned int childIdx,
91 BuildInformationT* bi)
const
93 bi->Range() = parent[childIdx].Range();
96 template<
class BuildInformationT >
99 cell->m_range.first = KernelT::BeginHandle();
100 cell->m_range.second = KernelT::EndHandle();
103 template<
class BuildInformationT >
105 const BuildInformationT& parentInfo,
unsigned int childIdx,
106 const BuildInformationT& bi,
CellType* cell)
108 cell->Range() = bi.Range();
111 template<
class TraversalInformationT >
113 TraversalInformationT* ti)
const
116 template<
class TraversalInformationT >
120 *range = cell.Range();
123 template<
class TraversalInformationT >
125 const TraversalInformationT& pTi,
unsigned int childIdx,
126 TraversalInformationT* ti)
const
129 template<
class SplitterT,
class BuildInformationT >
131 const BuildInformationT&,
CellType* left,
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];
142 template<
class SplitterT,
class BuildInformationT >
144 const BuildInformationT&,
CellType* left, BuildInformationT* leftBi,
145 CellType* right, BuildInformationT* rightBi)
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];
155 template<
class SplitterT,
class BuildInformationT >
157 const unsigned int numSplitters,
const CellType& parent,
158 const BuildInformationT& parentInfo,
CellType** cells)
160 size_t* sizes =
new size_t[size_t(1u) << numSplitters];
161 SplitData(splitters, numSplitters, parentInfo.Range(),
163 unsigned int childCount = 0;
165 for (
unsigned int i = 0; i < (1u << numSplitters); ++i)
169 cells[i]->m_range.first = begin;
170 cells[i]->m_range.second = begin + sizes[i];
171 begin = cells[i]->m_range.second;
178 if (!cells[0] && childCount)
185 template<
class SplitterT >
187 const unsigned int numSplitters,
190 const unsigned int numChildren = 1 << numSplitters;
191 SplitData(splitters[0], range, &(sizes[0]),
192 &(sizes[numChildren >> 1]));
193 if (numSplitters == 1)
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));
204 template<
class SplitterT >
206 const CellRange& range,
size_t* left,
size_t* right)
208 if (range.second - range.first == 0)
218 while (j <= k &&
split(this->at(this->Dereference(j))))
222 while (j < k && !
split(this->at(this->Dereference(k))))
228 this->SwapHandles(k, j);
237 *left = j - range.first;
238 *right = (range.second - range.first)
243 const std::vector< size_t >& clusterid,
244 const std::vector< size_t >& clusterCount,
247 std::vector< size_t > clusterPositions(clusterCount.size());
248 clusterPositions[0] = 0;
250 range.first + clusterCount[0]);
251 for (
size_t i = 1; i < clusterCount.size(); ++i)
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]);
257 std::vector< size_t > partitioning(clusterid.size());
258 for (
size_t i = 0; i < clusterid.size(); ++i)
260 partitioning[i] = clusterPositions[clusterid[i]]++;
262 for (
size_t i = 0; i < partitioning.size(); ++i)
263 while (i != partitioning[i])
265 KernelT::SwapHandles(range.first + i,
266 range.first + partitioning[i]);
267 std::swap(partitioning[i], partitioning[partitioning[i]]);