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