MaxIntervalSplittingKdTreeStrategy.h
Go to the documentation of this file.
1#ifndef GfxTL__MAXINTERVALSPLITTINGKDTREESTRATEGY_HEADER__
2#define GfxTL__MAXINTERVALSPLITTINGKDTREESTRATEGY_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* diff = new DiffScalarType[BaseType::m_dim];
33 this->Sub(bi.BBox()[1], bi.BBox()[0], &diff);
34 unsigned int axis = 0;
35 DiffScalarType length = diff[0];
36 for (unsigned int j = 1; j < BaseType::m_dim; ++j)
37 {
38 if (diff[j] > length)
39 {
40 axis = j;
41 length = diff[j];
42 }
43 }
44 cell->SplitAxis() = axis;
45 cell->SplitValue() = (bi.BBox()[0][axis] + bi.BBox()[1][axis]) / 2;
46 delete[] diff;
47 }
48
49 template <class BuildInformationT>
50 void
51 ComputeSplit(unsigned int axis, const BuildInformationT& bi, CellType* cell)
52 {
53 DiffScalarType* diff = new DiffScalarType[BaseType::m_dim];
54 Sub(bi.BBox()[1], bi.BBox()[0], &diff);
55 cell->SplitAxis() = axis;
56 cell->SplitValue() = (bi.BBox()[0][axis] + bi.BBox()[1][axis]) / 2;
57 delete[] diff;
58 }
59
60 template <class BuildInformationT>
61 bool
62 AlternateSplit(const BuildInformationT& bi, CellType* cell)
63 {
64 unsigned int axis = (cell->SplitAxis() + 1) % BaseType::m_dim;
65 cell->SplitAxis() = axis;
66 cell->SplitValue() = (bi.BBox()[1][axis] + bi.BBox()[0][axis]) / 2;
67 return true;
68 }
69 };
70 };
71}; // namespace GfxTL
72
73#endif
bool AlternateSplit(const BuildInformationT &bi, CellType *cell)
void ComputeSplit(const BuildInformationT &bi, CellType *cell)
InheritedStrategyT::template StrategyBase< BaseT > BaseType
void ComputeSplit(unsigned int axis, const BuildInformationT &bi, CellType *cell)
ScalarTypeConversion< ScalarType, ScalarType >::DifferenceType DiffScalarType
Definition AABox.h:10
PointT::value_type ScalarType