CellBBoxBuildInformationKdTreeStrategy.h
Go to the documentation of this file.
1#ifndef GfxTL__CELLBBOXBUILDINFORMATIONKDTREESTRATEGY_HEADER__
2#define GfxTL__CELLBBOXBUILDINFORMATIONKDTREESTRATEGY_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 };
14
15 template <class BaseT>
16 class StrategyBase : public InheritedStrategyT::template StrategyBase<BaseT>
17 {
18 public:
19 typedef typename InheritedStrategyT::template StrategyBase<BaseT> BaseType;
20 typedef typename BaseType::CellType CellType;
24
26 {
27 m_bbox[0] = NULL;
28 m_bbox[1] = NULL;
29 }
30
32 {
33 delete[] m_bbox[0];
34 delete[] m_bbox[1];
35 }
36
37 const ScalarType* const*
39 {
40 return m_bbox;
41 }
42
43 protected:
44 class BuildInformation : public BaseType::BuildInformation
45 {
46 public:
49 {
50 return m_oldBound;
51 }
52
53 const ScalarType
54 OldBound() const
55 {
56 return m_oldBound;
57 }
58
59 const ScalarType* const*
60 CellBBox() const
61 {
62 return m_cellBbox;
63 }
64
65 void
66 CellBBox(ScalarType** cellBbox)
67 {
68 m_cellBbox = cellBbox;
69 }
70
71 private:
72 ScalarType m_oldBound;
73 ScalarType** m_cellBbox;
74 };
75
76 template <class BuildInformationT>
77 void
78 InitRootBuildInformation(BuildInformationT* bi)
79 {
80 BaseType::InitRootBuildInformation(bi);
81 delete[] m_bbox[0]; // delete because dimension could have changed
82 delete[] m_bbox[1];
83 // init bbox
84 m_bbox[0] = new ScalarType[BaseType::m_dim];
85 m_bbox[1] = new ScalarType[BaseType::m_dim];
86 // init the values (box of zero volume)
87 typename BaseType::HandleType i = bi->Range().first;
88 this->AssignAsAABoxMin(this->at(this->Dereference(i)), &m_bbox[0]);
89 this->AssignAsAABoxMax(this->at(this->Dereference(i)), &m_bbox[1]);
90 for (++i; i != bi->Range().second; ++i)
91 {
92 this->IncludeInAABox(this->at(this->Dereference(i)), m_bbox);
93 }
94 bi->CellBBox(m_bbox);
95 }
96
97 template <class BuildInformationT>
98 void
100 const BuildInformationT& parentInfo,
101 unsigned int childIdx,
102 BuildInformationT* bi)
103 {
104 BaseType::InitBuildInformation(parent, parentInfo, childIdx, bi);
105 bi->CellBBox(m_bbox);
106 }
107
108 template <class BuildInformationT>
109 void
110 EnterGlobalBuildInformation(const CellType& cell, BuildInformationT* bi)
111 {
112 BaseType::EnterGlobalBuildInformation(cell, bi);
113 if (bi->CreateChild() == 0)
114 {
115 bi->OldBound() = m_bbox[1][cell.SplitAxis()];
116 m_bbox[1][cell.SplitAxis()] = cell.SplitValue();
117 }
118 else
119 {
120 bi->OldBound() = m_bbox[0][cell.SplitAxis()];
121 m_bbox[0][cell.SplitAxis()] = cell.SplitValue();
122 }
123 }
124
125 template <class BuildInformationT>
126 void
127 LeaveGlobalBuildInformation(const CellType& cell, const BuildInformationT& bi)
128 {
129 BaseType::LeaveGlobalBuildInformation(cell, bi);
130 if (bi.CreateChild() == 1)
131 {
132 m_bbox[1][cell.SplitAxis()] = bi.OldBound();
133 }
134 else
135 {
136 m_bbox[0][cell.SplitAxis()] = bi.OldBound();
137 }
138 }
139
140 private:
141 ScalarType* m_bbox[2];
142 };
143 };
144}; // namespace GfxTL
145
146#endif
void InitBuildInformation(const CellType &parent, const BuildInformationT &parentInfo, unsigned int childIdx, BuildInformationT *bi)
void EnterGlobalBuildInformation(const CellType &cell, BuildInformationT *bi)
void LeaveGlobalBuildInformation(const CellType &cell, const BuildInformationT &bi)
ScalarTypeConversion< ScalarType, ScalarType >::DifferenceType DiffScalarType
Definition AABox.h:10
PointT::value_type ScalarType