f2040a8f |
1 | #include "TKDInterpolator.h" |
a3408ed3 |
2 | #include "TKDNodeInfo.h" |
f2040a8f |
3 | |
b273c7cb |
4 | #include "TError.h" |
a3408ed3 |
5 | #include "TClonesArray.h" |
f2040a8f |
6 | |
f2040a8f |
7 | ClassImp(TKDInterpolator) |
8 | |
f2040a8f |
9 | |
5f38a39d |
10 | |
117c62ab |
11 | //_________________________________________________________________ |
a3408ed3 |
12 | TKDInterpolator::TKDInterpolator() : |
b273c7cb |
13 | TKDInterpolatorBase() |
f2040a8f |
14 | { |
df84bc73 |
15 | // Default constructor. To be used with care since in this case building |
16 | // of data structure is completly left to the user responsability. |
f2040a8f |
17 | } |
18 | |
19 | //_________________________________________________________________ |
a3408ed3 |
20 | TKDInterpolator::TKDInterpolator(Int_t ndim, Int_t npoints) : |
b273c7cb |
21 | TKDInterpolatorBase(ndim) |
f2040a8f |
22 | { |
117c62ab |
23 | // Wrapper constructor for the TKDTree. |
24 | |
b273c7cb |
25 | if(npoints) TKDInterpolatorBase::Build(npoints); |
f2040a8f |
26 | } |
27 | |
28 | |
f2040a8f |
29 | //_________________________________________________________________ |
30 | TKDInterpolator::~TKDInterpolator() |
31 | { |
f2040a8f |
32 | } |
33 | |
34 | //_________________________________________________________________ |
a3408ed3 |
35 | void TKDInterpolator::AddNode(const TKDNodeInfo &node) |
f2040a8f |
36 | { |
afb669c1 |
37 | if(!fNodes){ |
b273c7cb |
38 | Warning("TKDInterpolator::SetNode()", "Node array not defined."); |
39 | return; |
40 | } |
316a7f5a |
41 | |
afb669c1 |
42 | Int_t n(GetNTNodes()); |
43 | new((*fNodes)[n++]) TKDNodeInfo(node); |
f2040a8f |
44 | } |
45 | |
f2040a8f |
46 | //_________________________________________________________________ |
afb669c1 |
47 | Bool_t TKDInterpolator::Build(Int_t npoints, Int_t ndim) |
f2040a8f |
48 | { |
b273c7cb |
49 | fNSize = ndim; |
afb669c1 |
50 | return TKDInterpolatorBase::Build(npoints); |
f2040a8f |
51 | } |
52 | |
53 | //_________________________________________________________________ |
a3408ed3 |
54 | Int_t TKDInterpolator::GetNodeIndex(const Float_t *p) |
55 | { |
b273c7cb |
56 | // printf("TKDInterpolator::GetNodeIndex() ...\n"); |
57 | // printf("Looking for p["); |
58 | // for(int i=0; i<fNSize; i++) printf("%f ", p[i]); |
59 | // printf("] ...\n"); |
60 | |
afb669c1 |
61 | for(Int_t i=GetNTNodes(); i--;) |
62 | if(((TKDNodeInfo*)(*fNodes)[i])->Has(p)) return i; |
b273c7cb |
63 | |
64 | printf("Point p["); |
65 | for(int i=0; i<fNSize; i++) printf("%f ", p[i]); |
66 | printf("] outside range.\n"); |
67 | return -1; |
316a7f5a |
68 | } |
69 | |
70 | |
71 | //_________________________________________________________________ |
1a439134 |
72 | Bool_t TKDInterpolator::SetNode(Int_t inode, const TKDNodeInfo &ref) |
316a7f5a |
73 | { |
afb669c1 |
74 | if(!fNodes){ |
b273c7cb |
75 | Warning("TKDInterpolator::SetNode()", "Node array not defined."); |
76 | return kFALSE; |
77 | } |
afb669c1 |
78 | if(inode >= GetNTNodes()){ |
eb8908e3 |
79 | Warning("TKDInterpolator::SetNode()", "Node array defined up to %d.", GetNTNodes()); |
b273c7cb |
80 | return kFALSE; |
81 | } |
afb669c1 |
82 | TKDNodeInfo *node = (TKDNodeInfo*)(*fNodes)[inode]; |
b273c7cb |
83 | (*node) = ref; |
84 | return kTRUE; |
316a7f5a |
85 | } |
86 | |