1 #ifndef GfxTL_BASETREE_HEADER__
2 #define GfxTL_BASETREE_HEADER__
39 template <
class ScalarT>
57 return &(cell[0]) == NULL;
77 m_root =
new Cell(*bt.m_root);
104 template <
class Cell>
111 m_root =
new Cell(*bt.m_root);
116 template <
class Cell>
124 size_t numLeaves = 0;
125 std::vector<const CellType*> stack;
126 stack.push_back(Root());
136 for (
unsigned int i = 0; i < CellType::NChildren; ++i)
137 if (ExistChild(*
c, i))
139 stack.push_back(&((*
c)[i]));
145 template <
class Cell>
153 typedef std::pair<const CellType*, size_t> Pair;
155 std::vector<Pair> stack;
156 stack.push_back(Pair(Root(), 0));
159 Pair p = stack.back();
161 if (p.second == level)
166 else if (IsLeaf(*p.first))
171 for (
unsigned int i = 0; i < CellType::NChildren; ++i)
172 if (ExistChild(*p.first, i))
174 stack.push_back(Pair(&((*p.first)[i]), p.second + 1));
180 template <
class Cell>
189 typedef std::pair<const CellType*, size_t> Pair;
190 std::vector<Pair> stack;
191 stack.push_back(Pair(Root(), 0));
194 Pair p = stack.back();
196 if (p.second > maxLevel)
200 if (IsLeaf(*p.first))
205 for (
unsigned int i = 0; i < CellType::NChildren; ++i)
206 if (ExistChild(*p.first, i))
208 stack.push_back(Pair(&((*p.first)[i]), p.second + 1));
214 template <
class Cell>
223 size_t leaveCount = 0;
224 typedef std::pair<const CellType*, size_t> Pair;
225 std::vector<Pair> stack;
226 stack.push_back(Pair(Root(), 0));
229 Pair p = stack.back();
231 if (IsLeaf(*p.first))
233 levelSum += p.second;
238 for (
unsigned int i = 0; i < CellType::NChildren; ++i)
239 if (ExistChild(*p.first, i))
241 stack.push_back(Pair(&((*p.first)[i]), p.second + 1));
244 return double(levelSum) / double(leaveCount);
247 template <
class Cell>
248 template <
class ScalarT>
252 typedef ScalarT ScalarType;
259 ScalarType avgDepth = 0;
260 std::vector<std::pair<const CellType*, size_t>> stack;
261 stack.push_back(std::make_pair(Root(),
size_t(0)));
264 std::pair<const CellType*, size_t>
c = stack.back();
266 if (IsLeaf(*
c.first))
269 avgDepth += (ScalarType)
c.second;
272 for (
unsigned int i = 0; i < Cell::NChildren; ++i)
273 if (ExistChild(*
c.first, i))
275 stack.push_back(std::make_pair(&((*
c.first)[i]),
c.second + 1));
278 avgDepth /= ScalarType(*numLeaves);
280 stack.push_back(std::make_pair(Root(),
size_t(0)));
283 std::pair<const CellType*, size_t>
c = stack.back();
285 if (IsLeaf(*
c.first))
287 ScalarType t = ScalarType(
c.second) - avgDepth;
291 for (
unsigned int i = 0; i < Cell::NChildren; ++i)
292 if (ExistChild(*
c.first, i))
294 stack.push_back(std::make_pair(&((*
c.first)[i]),
c.second + 1));
297 *variance /= ScalarType(*numLeaves);