IncrementalDistanceKdTreeStrategy.h
Go to the documentation of this file.
1#ifndef GfxTL__INCREMENTALDISTANCEKDTREESTRATEGY_HEADER__
2#define GfxTL__INCREMENTALDISTANCEKDTREESTRATEGY_HEADER__
3
4namespace GfxTL
5{
6 template <class InheritedStrategyT>
8 {
9 typedef typename InheritedStrategyT::value_type value_type;
10
11 class CellData : public InheritedStrategyT::CellData
12 {
13 public:
14 typedef typename InheritedStrategyT::CellData BaseType;
15 typedef typename BaseType::value_type value_type;
17
20 {
21 return m_bdim;
22 }
23
24 const ScalarType*
26 {
27 return m_bdim;
28 }
29
30 private:
31 ScalarType m_bdim[2];
32 };
33
34 template <class BaseT>
35 class StrategyBase : public InheritedStrategyT::template StrategyBase<BaseT>
36 {
37 public:
38 typedef typename InheritedStrategyT::template StrategyBase<BaseT> BaseType;
39 typedef typename BaseType::CellType CellType;
43
44 protected:
45 template <class BuildInformationT>
46 void
47 ComputeSplit(const BuildInformationT& bi, CellType* cell)
48 {
49 BaseType::ComputeSplit(bi, cell);
50 cell->AxisInterval()[0] = bi.CellBBox()[0][cell->SplitAxis()];
51 cell->AxisInterval()[1] = bi.CellBBox()[1][cell->SplitAxis()];
52 }
53
54 template <class BuildInformationT>
55 bool
56 AlternateSplit(const BuildInformationT& bi, CellType* cell)
57 {
58 bool retVal = BaseType::AlternateSplit(bi, cell);
59 if (retVal)
60 {
61 cell->AxisInterval()[0] = bi.CellBBox()[0][cell->SplitAxis()];
62 cell->AxisInterval()[1] = bi.CellBBox()[1][cell->SplitAxis()];
63 }
64 return retVal;
65 }
66
67 template <class BaseTraversalT>
69 public BaseType::template TraversalInformation<BaseTraversalT>
70 {
71 public:
72 typedef typename BaseType::template DistanceType<
74 typename ScalarTypeDeferer<typename BaseType::template TraversalInformation<
75 BaseTraversalT>::GlobalType::PointType>::ScalarType>::Type DistScalarType;
76
79 {
80 return m_boxSqrDist;
81 }
82
83 const DistScalarType&
84 BoxSqrDist() const
85 {
86 return m_boxSqrDist;
87 }
88
89 private:
90 DistScalarType m_boxSqrDist;
91 };
92
93 template <class TraversalInformationT>
94 void
95 InitRootTraversalInformation(const CellType& root, TraversalInformationT* ti) const
96 {
97 BaseType::InitRootTraversalInformation(root, ti);
98 ti->BoxSqrDist() = BaseType::BoxSqrDistance(
99 ti->Global().Point(), BaseType::RootCellBBox()[0], BaseType::RootCellBBox()[1]);
100 }
101
102 template <class TraversalInformationT>
103 void
105 const TraversalInformationT& pTi,
106 unsigned int childIdx,
107 TraversalInformationT* ti) const
108 {
109 BaseType::InitTraversalInformation(parent, pTi, childIdx, ti);
110 // do incremental distance update
111 DiffScalarType boxDiff = 0;
112 if (pTi.Global().Point()[parent.SplitAxis()] < parent.AxisInterval()[0])
113 boxDiff = parent.AxisInterval()[0] - pTi.Global().Point()[parent.SplitAxis()];
114 else if (pTi.Global().Point()[parent.SplitAxis()] > parent.AxisInterval()[1])
115 boxDiff = pTi.Global().Point()[parent.SplitAxis()] - parent.AxisInterval()[1];
116 DiffScalarType cutDiff = 0;
117 if (childIdx == 0)
118 {
119 if (pTi.Global().Point()[parent.SplitAxis()] < parent.AxisInterval()[0])
120 cutDiff =
121 parent.AxisInterval()[0] - pTi.Global().Point()[parent.SplitAxis()];
122 else if (pTi.Global().Point()[parent.SplitAxis()] > parent.SplitValue())
123 cutDiff = pTi.Global().Point()[parent.SplitAxis()] - parent.SplitValue();
124 }
125 else
126 {
127 if (pTi.Global().Point()[parent.SplitAxis()] < parent.SplitValue())
128 cutDiff = parent.SplitValue() - pTi.Global().Point()[parent.SplitAxis()];
129 else if (pTi.Global().Point()[parent.SplitAxis()] > parent.AxisInterval()[1])
130 cutDiff =
131 pTi.Global().Point()[parent.SplitAxis()] - parent.AxisInterval()[1];
132 }
133 ti->BoxSqrDist() =
134 BaseType::IncrementalBoxSqrDistance(pTi.BoxSqrDist(), boxDiff, cutDiff);
135 //// do incremental distance update
136 //// compute previous distance
137 //DiffScalarType cutDiff = pTi.Global().Point()[parent.SplitAxis()] -
138 // parent.SplitValue();
139 //DiffScalarType boxDiff;
140 //if(childIdx == 0)
141 //{
142 // if(cutDiff <= 0) // inside
143 // {
144 // ti->BoxSqrDist() = pTi.BoxSqrDist();
145 // return;
146 // }
147 // boxDiff = pTi.Global().Point()[parent.SplitAxis()] -
148 // parent.AxisInterval()[1];
149 //}
150 //else
151 //{
152 // if(cutDiff >= 0) // inside
153 // {
154 // ti->BoxSqrDist() = pTi.BoxSqrDist();
155 // return;
156 // }
157 // boxDiff = parent.AxisInterval()[0] -
158 // pTi.Global().Point()[parent.SplitAxis()];
159 //}
160 //if(boxDiff < 0)
161 // boxDiff = 0;
162 //ti->BoxSqrDist() = BaseType::IncrementalBoxSqrDistance(
163 // pTi.BoxSqrDist(), boxDiff, cutDiff);
164 }
165
166 template <class TraversalInformationT>
167 typename TraversalInformationT::DistScalarType
168 CellSqrDistance(const CellType& cell, const TraversalInformationT& ti) const
169 {
170 return ti.BoxSqrDist();
171 }
172 };
173 };
174}; // namespace GfxTL
175
176#endif
BaseType::template DistanceType< typenameScalarTypeDeferer< value_type >::ScalarType, typenameScalarTypeDeferer< typenameBaseType::templateTraversalInformation< BaseTraversalT >::GlobalType::PointType >::ScalarType >::Type DistScalarType
TraversalInformationT::DistScalarType CellSqrDistance(const CellType &cell, const TraversalInformationT &ti) const
bool AlternateSplit(const BuildInformationT &bi, CellType *cell)
void InitRootTraversalInformation(const CellType &root, TraversalInformationT *ti) const
void ComputeSplit(const BuildInformationT &bi, CellType *cell)
InheritedStrategyT::template StrategyBase< BaseT > BaseType
ScalarTypeConversion< ScalarType, ScalarType >::DifferenceType DiffScalarType
void InitTraversalInformation(const CellType &parent, const TraversalInformationT &pTi, unsigned int childIdx, TraversalInformationT *ti) const
Definition AABox.h:10
PointT::value_type ScalarType