- extend user interface
[u/mrichter/AliRoot.git] / STAT / TKDInterpolator.cxx
1 #include "TKDInterpolator.h"
2 #include "TKDNodeInfo.h"
3
4 #include "TError.h"
5 #include "TClonesArray.h"
6
7 ClassImp(TKDInterpolator)
8
9
10
11 //_________________________________________________________________
12 TKDInterpolator::TKDInterpolator() :
13   TKDInterpolatorBase()
14 {
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 }
18
19 //_________________________________________________________________
20 TKDInterpolator::TKDInterpolator(Int_t ndim, Int_t npoints) :
21   TKDInterpolatorBase(ndim)
22 {
23 // Wrapper constructor for the TKDTree.
24
25   if(npoints) TKDInterpolatorBase::Build(npoints);
26 }
27
28
29 //_________________________________________________________________
30 TKDInterpolator::~TKDInterpolator()
31 {
32 }
33
34 //_________________________________________________________________
35 void TKDInterpolator::AddNode(const TKDNodeInfo &node)
36 {
37   if(!fTNodes){
38     Warning("TKDInterpolator::SetNode()", "Node array not defined.");
39     return;
40   }
41
42   new((*fTNodes)[fNTNodes++]) TKDNodeInfo(node);
43 }
44
45 //_________________________________________________________________
46 void TKDInterpolator::Build(Int_t npoints, Int_t ndim)
47 {
48   fNSize = ndim;
49   TKDInterpolatorBase::Build(npoints);
50 }
51
52 //_________________________________________________________________
53 Int_t TKDInterpolator::GetNodeIndex(const Float_t *p)
54 {
55 //      printf("TKDInterpolator::GetNodeIndex() ...\n");
56 //   printf("Looking for p[");
57 //   for(int i=0; i<fNSize; i++) printf("%f ", p[i]);
58 //   printf("] ...\n");
59
60   for(Int_t i=fNTNodes; i--;)
61     if(((TKDNodeInfo*)(*fTNodes)[i])->Has(p)) return i;
62   
63   printf("Point p[");
64   for(int i=0; i<fNSize; i++) printf("%f ", p[i]);
65   printf("] outside range.\n");
66   return -1;
67 }
68
69
70 //_________________________________________________________________
71 Bool_t TKDInterpolator::SetNode(Int_t inode, const TKDNodeInfo &ref)
72 {
73   if(!fTNodes){
74     Warning("TKDInterpolator::SetNode()", "Node array not defined.");
75     return kFALSE;
76   }
77   if(inode >= fNTNodes){
78     Warning("TKDInterpolator::SetNode()", Form("Node array defined up to %d.", fNTNodes));
79     return kFALSE;
80   }
81   TKDNodeInfo *node = (TKDNodeInfo*)(*fTNodes)[inode];
82   (*node) = ref;
83   return kTRUE;
84 }
85