CLAM-Development  1.4.0
BPFTmplDec.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
3  * UNIVERSITAT POMPEU FABRA
4  *
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */
21 
22 
23 #ifndef _BPFTmplDec_
24 #define _BPFTmplDec_
25 
26 #include <iosfwd>
27 
28 #include "PointTmpl.hxx" // for point functionality
29 #include "Err.hxx"//for Exception handling
30 #include "Array.hxx" // array functionality
31 #include "SearchArray.hxx" //array searches
32 #include "Enum.hxx"
33 #include "Component.hxx"
34 #include "GlobalEnums.hxx"
35 
36 namespace CLAM
37 {
38  class EInterpolation;
39 
40  template <class TX,class TY> class BPFTmpl:public Component
41  {
42  static const TData Infinity;
43 
44  public:
48  BPFTmpl();
49 
54  BPFTmpl(const EInterpolation& eInterpolation);
55 
63  BPFTmpl(TSize size);
64 
65  BPFTmpl(TSize size,
66  const EInterpolation& eInterpolation);
67 
72  BPFTmpl(const BPFTmpl<TX,TY>& orig);
73 
78  void Init();
79 
83  const char * GetClassName() const {return "BPF";}
84 
90  TSize AllocatedSize(void) const {return mArray.AllocatedSize();}
91 
98  TSize Size(void) const {return mArray.Size();}
99 
107  void SetSize (TSize newSize){mArray.SetSize(newSize);}
108 
116  void Resize (TSize newSize){mArray.Resize(newSize);}
117 
124  TIndex Insert(const PointTmpl<TX,TY> &point);
125 
134  TIndex Insert(const TX &x,const TX &y);
135 
140  void DeleteIndex(TIndex index);
141 
146  void DeleteThroughXValue(const TX& x);
147 
153  void DeleteBetweenIndex(TIndex leftIndex,TIndex rightIndex);
154 
160  void DeleteBetweenXValues(const TX& leftX,const TX& rightX);
161 
167  void SetValue(TIndex index,const TY &y)
168  {
169  mArray[index].SetY(y);
170  mIsSplineUpdated=false;
171  }
172 
173  void SetXValue(TIndex index,const TX &x){
174  mArray[index].SetX(x);
175  mIsSplineUpdated=false;
176  }
177 
183  void SetIntpType(const EInterpolation& eInterpolation);
184 
190  void SetStep(TSize step){mArray.SetStep(step);}
196  TSize GetStep() {return mArray.GetStep();}
197 
203  TY GetValueFromIndex(TIndex index) const {
204  return mArray[index].GetY();
205  }
206 
214  TY GetValue(const TX& x) const {
215  return GetValue(x,meInterpolation);
216  }
217 
225  TY GetValue (const TX& x,const EInterpolation& eInterpolation) const;
226 
232  const TX& GetXValue(TIndex index) const
233  {
234  return mArray[index].GetX();
235  }
236 
242  TIndex GetPosition(const TX& x) const;
243 
244 
254  void GetnClosest(TIndex foundIndex) const;
255 
259  BPFTmpl<TX, TY>& operator=(const BPFTmpl<TX, TY> &originalBPF);
260 
264  void UpdateSplineTable();
265 
269  void SetLeftDerivative(TData val);
270  void UnsetLeftDerivative(void);
271  void SetRightDerivative(TData val);
272  void UnsetRightDerivative(void);
273 
278  return meInterpolation;
279  }
280 
285  return mArray;
286  }
287 
288 protected:
289  /*Member variables*/
308  SearchArray<PointTmpl<TX,TY> > mSearch;//search functionality for array
318  mutable Array<TY> mc,md;
323  int mOrder; //interpolation order for polynomic interp.
328  mutable TIndex mLastIndex;
333  mutable TX mLastX;
334 
345 
354 
363 
368  TY BPFPolInt(const TX& x,const Array<TIndex>& closestPointsIndex,
369  TData &errorEstimate) const;
370  void CreateSplineTable();
371  TY BPFSplineInt(const TX& x) const;
372  void StoreOn(Storage & storage) const;
373  void LoadFrom(Storage & storage);
374 
375  };
376 
377 } // namespace CLAM
378 
379 #endif // _BPFTmplDec_
380