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