SlidingMidpointSplittingKdTreeStrategy.h
Go to the documentation of this file.
1#ifndef GfxTL__SLIDINGMIDPOINTSPLITTINGKDTREESTRATEGY_HEADER__
2#define GfxTL__SLIDINGMIDPOINTSPLITTINGKDTREESTRATEGY_HEADER__
5
6namespace GfxTL
7{
8 template <class InheritedStrategyT>
10 {
11 typedef typename InheritedStrategyT::value_type value_type;
12
13 struct CellData : public InheritedStrategyT::CellData
14 {
15 };
16
17 template <class BaseT>
18 class StrategyBase : public InheritedStrategyT::template StrategyBase<BaseT>
19 {
20 public:
21 typedef typename InheritedStrategyT::template StrategyBase<BaseT> BaseType;
22 typedef typename BaseType::CellType CellType;
26
27 protected:
28 template <class BuildInformationT>
29 void
30 ComputeSplit(const BuildInformationT& bi, CellType* cell)
31 {
32 DiffScalarType* cellDiff = new DiffScalarType[BaseType::m_dim];
33 Sub(bi.CellBBox()[1], bi.CellBBox()[0], &cellDiff);
34 DiffScalarType* diff = new DiffScalarType[BaseType::m_dim];
35 Sub(bi.BBox()[1], bi.BBox()[0], &diff);
36 unsigned int axis = 0;
37 DiffScalarType length = cellDiff[0];
38 DiffScalarType spread = diff[0];
39 for (unsigned int j = 1; j < BaseType::m_dim; ++j)
40 {
41 if ((cellDiff[j] > length && spread < 2 * diff[j]) ||
42 (cellDiff[j] == length && diff[j] > spread) || diff[j] > 2 * spread)
43 {
44 axis = j;
45 length = cellDiff[j];
46 spread = diff[j];
47 }
48 }
49 cell->SplitAxis() = axis;
50 cell->SplitValue() = (bi.CellBBox()[0][axis] + bi.CellBBox()[1][axis]) / 2;
51 if (cell->SplitValue() < bi.BBox()[0][axis] ||
52 cell->SplitValue() > bi.BBox()[1][axis])
53 {
54 cell->SplitValue() = (bi.BBox()[1][axis] + bi.BBox()[0][axis]) / 2;
55 }
56 delete[] cellDiff;
57 delete[] diff;
58 }
59
60 template <class BuildInformationT>
61 void
62 ComputeSplit(unsigned int axis, const BuildInformationT& bi, CellType* cell)
63 {
64 DiffScalarType* cellDiff = new DiffScalarType[BaseType::m_dim];
65 Sub(bi.CellBBox()[1], bi.CellBBox()[0], &cellDiff);
66 DiffScalarType* diff = new DiffScalarType[BaseType::m_dim];
67 Sub(bi.BBox()[1], bi.BBox()[0], &diff);
68 cell->SplitAxis() = axis;
69 cell->SplitValue() = (bi.CellBBox()[0][axis] + bi.CellBBox()[1][axis]) / 2;
70 if (cell->SplitValue() < bi.BBox()[0][axis])
71 {
72 cell->SplitValue() = bi.BBox()[0][axis];
73 }
74 else if (cell->SplitValue() > bi.BBox()[1][axis])
75 {
76 cell->SplitValue() = bi.BBox()[1][axis];
77 }
78 delete[] cellDiff;
79 delete[] diff;
80 }
81
82 template <class BuildInformationT>
83 bool
84 AlternateSplit(const BuildInformationT& bi, CellType* cell)
85 {
86 unsigned int axis = (cell->SplitAxis() + 1) % BaseType::m_dim;
87 cell->SplitAxis() = axis;
88 cell->SplitValue() = (bi.CellBBox()[1][axis] + bi.CellBBox()[0][axis]) / 2;
89 if (cell->SplitValue() < bi.BBox()[0][axis])
90 {
91 cell->SplitValue() = bi.BBox()[0][axis];
92 }
93 else if (cell->SplitValue() > bi.BBox()[1][axis])
94 {
95 cell->SplitValue() = bi.BBox()[1][axis];
96 }
97 return true;
98 }
99 };
100 };
101}; // namespace GfxTL
102
103#endif
void ComputeSplit(unsigned int axis, const BuildInformationT &bi, CellType *cell)
ScalarTypeConversion< ScalarType, ScalarType >::DifferenceType DiffScalarType
Definition AABox.h:10
PointT::value_type ScalarType