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