forked from alisw/AliRoot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TKDInterpolator.cxx
86 lines (68 loc) · 2.19 KB
/
TKDInterpolator.cxx
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
#include "TKDInterpolator.h"
#include "TKDNodeInfo.h"
#include "TError.h"
#include "TClonesArray.h"
ClassImp(TKDInterpolator)
//_________________________________________________________________
TKDInterpolator::TKDInterpolator() :
TKDInterpolatorBase()
{
// Default constructor. To be used with care since in this case building
// of data structure is completly left to the user responsability.
}
//_________________________________________________________________
TKDInterpolator::TKDInterpolator(Int_t ndim, Int_t npoints) :
TKDInterpolatorBase(ndim)
{
// Wrapper constructor for the TKDTree.
if(npoints) TKDInterpolatorBase::Build(npoints);
}
//_________________________________________________________________
TKDInterpolator::~TKDInterpolator()
{
}
//_________________________________________________________________
void TKDInterpolator::AddNode(const TKDNodeInfo &node)
{
if(!fNodes){
Warning("TKDInterpolator::SetNode()", "Node array not defined.");
return;
}
Int_t n(GetNTNodes());
new((*fNodes)[n++]) TKDNodeInfo(node);
}
//_________________________________________________________________
Bool_t TKDInterpolator::Build(Int_t npoints, Int_t ndim)
{
fNSize = ndim;
return TKDInterpolatorBase::Build(npoints);
}
//_________________________________________________________________
Int_t TKDInterpolator::GetNodeIndex(const Float_t *p)
{
// printf("TKDInterpolator::GetNodeIndex() ...\n");
// printf("Looking for p[");
// for(int i=0; i<fNSize; i++) printf("%f ", p[i]);
// printf("] ...\n");
for(Int_t i=GetNTNodes(); i--;)
if(((TKDNodeInfo*)(*fNodes)[i])->Has(p)) return i;
printf("Point p[");
for(int i=0; i<fNSize; i++) printf("%f ", p[i]);
printf("] outside range.\n");
return -1;
}
//_________________________________________________________________
Bool_t TKDInterpolator::SetNode(Int_t inode, const TKDNodeInfo &ref)
{
if(!fNodes){
Warning("TKDInterpolator::SetNode()", "Node array not defined.");
return kFALSE;
}
if(inode >= GetNTNodes()){
Warning("TKDInterpolator::SetNode()", "Node array defined up to %d.", GetNTNodes());
return kFALSE;
}
TKDNodeInfo *node = (TKDNodeInfo*)(*fNodes)[inode];
(*node) = ref;
return kTRUE;
}