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 : 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
GfxTL::ScalarTypeDeferer
Definition: ScalarTypeDeferer.h:13
GfxTL::SlidingMidpointSplittingKdTreeStrategy::StrategyBase::BaseType
InheritedStrategyT::template StrategyBase< BaseT > BaseType
Definition: SlidingMidpointSplittingKdTreeStrategy.h:21
GfxTL::SlidingMidpointSplittingKdTreeStrategy::StrategyBase::ComputeSplit
void ComputeSplit(unsigned int axis, const BuildInformationT &bi, CellType *cell)
Definition: SlidingMidpointSplittingKdTreeStrategy.h:62
GfxTL::SlidingMidpointSplittingKdTreeStrategy::CellData
Definition: SlidingMidpointSplittingKdTreeStrategy.h:13
GfxTL::SlidingMidpointSplittingKdTreeStrategy::StrategyBase::ComputeSplit
void ComputeSplit(const BuildInformationT &bi, CellType *cell)
Definition: SlidingMidpointSplittingKdTreeStrategy.h:30
ScalarTypeConversion.h
GfxTL::SlidingMidpointSplittingKdTreeStrategy
Definition: SlidingMidpointSplittingKdTreeStrategy.h:9
GfxTL::SlidingMidpointSplittingKdTreeStrategy::StrategyBase::DiffScalarType
ScalarTypeConversion< ScalarType, ScalarType >::DifferenceType DiffScalarType
Definition: SlidingMidpointSplittingKdTreeStrategy.h:25
GfxTL::SlidingMidpointSplittingKdTreeStrategy::StrategyBase::CellType
BaseType::CellType CellType
Definition: SlidingMidpointSplittingKdTreeStrategy.h:22
GfxTL
Definition: AABox.h:9
GfxTL::ScalarTypeConversion
Definition: ScalarTypeConversion.h:7
GfxTL::SlidingMidpointSplittingKdTreeStrategy::value_type
InheritedStrategyT::value_type value_type
Definition: SlidingMidpointSplittingKdTreeStrategy.h:11
GfxTL::SlidingMidpointSplittingKdTreeStrategy::StrategyBase
Definition: SlidingMidpointSplittingKdTreeStrategy.h:18
ScalarTypeDeferer.h
GfxTL::SlidingMidpointSplittingKdTreeStrategy::StrategyBase::ScalarType
ScalarTypeDeferer< value_type >::ScalarType ScalarType
Definition: SlidingMidpointSplittingKdTreeStrategy.h:23
GfxTL::SlidingMidpointSplittingKdTreeStrategy::StrategyBase::AlternateSplit
bool AlternateSplit(const BuildInformationT &bi, CellType *cell)
Definition: SlidingMidpointSplittingKdTreeStrategy.h:84