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