ScoreAACubeTreeStrategy.h
Go to the documentation of this file.
1#ifndef SCOREAACUBETREESTRATEGY_HEADER
2#define SCOREAACUBETREESTRATEGY_HEADER
3#include "basic.h"
4#include <GfxTL/NullClass.h>
6#include <MiscLib/Random.h>
7#include <MiscLib/Vector.h>
8
9template <unsigned int DimT, class InheritedStrategyT>
11{
12 typedef typename InheritedStrategyT::value_type value_type;
13
14 class CellData : public InheritedStrategyT::CellData
15 {
16 public:
18
19 const ScalarType
20 Radius() const
21 {
22 return m_radius;
23 }
24
27 {
28 return m_radius;
29 }
30
31 //size_t GlobalSize() const { return m_globalSize; }
32 //void GlobalSize(size_t globalSize) { m_globalSize = globalSize; }
33
34 private:
35 ScalarType m_radius;
36 //size_t m_globalSize;
37 };
38
39 template <class BaseT>
40 class StrategyBase : public InheritedStrategyT::template StrategyBase<BaseT>
41 {
42 public:
43 typedef typename InheritedStrategyT::template StrategyBase<BaseT> BaseType;
44 typedef typename BaseType::CellType CellType;
46
47 template <class ShapeT, class ScoreT>
48 void
49 Score(const ShapeT& shape, /*size_t maxCellSize,*/
50 ScoreT* score) const
51 {
52 typedef typename BaseType::template TraversalInformationBase<GfxTL::NullClass> tibT;
53 typedef typename BaseType::template CellCenterTraversalInformation<tibT>
54 TraversalInformation;
55 TraversalInformation ti;
56 this->InitRootTraversalInformation(*BaseType::Root(), &ti);
57 Score(*BaseType::Root(), ti, shape, /*maxCellSize,*/ score);
58 }
59
60 protected:
61 template <class BuildInformationT>
62 void
63 InitRoot(const BuildInformationT& bi, CellType* root)
64 {
65 BaseType::InitRoot(bi, root);
66 root->Radius() = bi.Cube().DiagLength() / 2;
67 }
68
69 template <class BuildInformationT>
70 void
71 InitCell(const CellType& parent,
72 const BuildInformationT& pbi,
73 unsigned int child,
74 const BuildInformationT& bi,
75 CellType* cell)
76 {
77 BaseType::InitCell(parent, pbi, child, bi, cell);
78 cell->Radius() = bi.Cube().DiagLength() / 2;
79 }
80
81 private:
82 template <class TraversalInformationT, class ShapeT, class ScoreT>
83 void
84 Score(const CellType& cell,
85 const TraversalInformationT& ti,
86 const ShapeT& shape,
87 /*size_t maxCellSize,*/ ScoreT* score) const
88 {
89 if (/*cell.Size() <= maxCellSize ||*/ this->IsLeaf(cell))
90 {
91 //score->UpperBound() += cell.GlobalSize();
92 //score->SampledPoints() += cell.Size();
93 //typename BaseType::CellRange range;
94 //BaseType::GetCellRange(cell, ti, &range);
95 //if(maxCellSize > 1)
96 //{
97 // size_t r = MiscLib::rn_rand() % cell.Size();
98 // (*score)(shape, *this, Dereference(range.first + r));
99 //}
100 //else
101 //{
102 for (typename BaseType::HandleType h = cell.Range().first; h != cell.Range().second;
103 ++h)
104 {
105 (*score)(shape, *this, this->Dereference(h));
106 }
107 //}
108 return;
109 }
110 for (unsigned int i = 0; i < CellType::NChildren; ++i)
111 {
112 if (!this->ExistChild(cell, i))
113 {
114 continue;
115 }
116 TraversalInformationT cti;
117 this->InitTraversalInformation(cell, ti, i, &cti);
118 //typename BaseType::CellCenterType center;
119 //CellCenter(cell[i], cti, &center);
120 ScalarType dist = shape.Distance(*((const Vec3f*)&cell[i].Center() /*center*/));
121 if (dist < cell[i].Radius() + score->Epsilon())
122 {
123 Score(cell[i], cti, shape, /*maxCellSize,*/ score);
124 }
125 }
126 }
127 };
128};
129
130#endif
GfxTL::ScalarTypeDeferer< value_type >::ScalarType ScalarType
GfxTL::ScalarTypeDeferer< value_type >::ScalarType ScalarType
void InitCell(const CellType &parent, const BuildInformationT &pbi, unsigned int child, const BuildInformationT &bi, CellType *cell)
void InitRoot(const BuildInformationT &bi, CellType *root)
InheritedStrategyT::template StrategyBase< BaseT > BaseType
void Score(const ShapeT &shape, ScoreT *score) const
PointT::value_type ScalarType
InheritedStrategyT::value_type value_type