1 #ifndef GfxTL_BASETREE_HEADER__
2 #define GfxTL_BASETREE_HEADER__
34 template<
class ScalarT >
47 template<
class Cell >
50 return &(cell[0]) == NULL;
53 template<
class Cell >
60 template<
class Cell >
65 template<
class Cell >
71 m_root =
new Cell(*bt.m_root);
75 template<
class Cell >
81 template<
class Cell >
91 template<
class Cell >
95 template<
class Cell >
101 m_root =
new Cell(*bt.m_root);
106 template<
class Cell >
113 size_t numLeaves = 0;
114 std::vector< const CellType* > stack;
115 stack.push_back(Root());
125 for (
unsigned int i = 0; i < CellType::NChildren; ++i)
126 if (ExistChild(*
c, i))
128 stack.push_back(&((*
c)[i]));
134 template<
class Cell >
141 typedef std::pair< const CellType*, size_t > Pair;
143 std::vector< Pair > stack;
144 stack.push_back(Pair(Root(), 0));
147 Pair p = stack.back();
149 if (p.second == level)
154 else if (IsLeaf(*p.first))
159 for (
unsigned int i = 0; i < CellType::NChildren; ++i)
160 if (ExistChild(*p.first, i))
162 stack.push_back(Pair(&((*p.first)[i]), p.second + 1));
168 template<
class Cell >
176 typedef std::pair< const CellType*, size_t > Pair;
177 std::vector< Pair > stack;
178 stack.push_back(Pair(Root(), 0));
181 Pair p = stack.back();
183 if (p.second > maxLevel)
187 if (IsLeaf(*p.first))
192 for (
unsigned int i = 0; i < CellType::NChildren; ++i)
193 if (ExistChild(*p.first, i))
195 stack.push_back(Pair(&((*p.first)[i]), p.second + 1));
201 template<
class Cell >
209 size_t leaveCount = 0;
210 typedef std::pair< const CellType*, size_t > Pair;
211 std::vector< Pair > stack;
212 stack.push_back(Pair(Root(), 0));
215 Pair p = stack.back();
217 if (IsLeaf(*p.first))
219 levelSum += p.second;
224 for (
unsigned int i = 0; i < CellType::NChildren; ++i)
225 if (ExistChild(*p.first, i))
227 stack.push_back(Pair(&((*p.first)[i]), p.second + 1));
230 return double(levelSum) / double(leaveCount);
233 template<
class Cell >
234 template<
class ScalarT >
237 typedef ScalarT ScalarType;
244 ScalarType avgDepth = 0;
245 std::vector< std::pair< const CellType*, size_t > > stack;
246 stack.push_back(std::make_pair(Root(),
size_t(0)));
249 std::pair< const CellType*, size_t >
c = stack.back();
251 if (IsLeaf(*
c.first))
254 avgDepth += (ScalarType)
c.second;
257 for (
unsigned int i = 0; i < Cell::NChildren; ++i)
258 if (ExistChild(*
c.first, i))
260 stack.push_back(std::make_pair(&((*
c.first)[i]),
c.second + 1));
263 avgDepth /= ScalarType(*numLeaves);
265 stack.push_back(std::make_pair(Root(),
size_t(0)));
268 std::pair< const CellType*, size_t >
c = stack.back();
270 if (IsLeaf(*
c.first))
272 ScalarType t = ScalarType(
c.second) - avgDepth;
276 for (
unsigned int i = 0; i < Cell::NChildren; ++i)
277 if (ExistChild(*
c.first, i))
279 stack.push_back(std::make_pair(&((*
c.first)[i]),
c.second + 1));
282 *variance /= ScalarType(*numLeaves);