CLAM-Development  1.4.0
ArrayToBPFCnv.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 #ifndef _ArrayToBPFCnv_
23 #define _ArrayToBPFCnv_
24 
25 #include "BPF.hxx"
26 #include "DataTypes.hxx"
27 
28 namespace CLAM {
29 
30 /*Conversion Routines*/
31 
32  //Convert values array (supposed to be equidistant) to BPF
33  template <class TX, class TY>
34  void ConvertToBPF(BPFTmpl<TX,TY>& newBPF,const Array<TY>& originalArray)
35  {
36  CLAM_ASSERT(originalArray.Size()>=1, "Zero lenght array.");
37  CLAM_ASSERT(originalArray.Size()==newBPF.Size(), "Different array dimensions");
38 
39  for(int i=0;i<originalArray.Size();i++)
40  {
41  newBPF.SetXValue( i, (TX)i );
42  newBPF.SetValue( i,originalArray[i]);
43  }
44  }
45 
46  template <class TX, class TY>
47  void ConvertToBPF( BPFTmpl<TX,TY>& newBPF, TX X0, TX deltaX, const Array<TY>& originalArray )
48  {
49  CLAM_ASSERT( originalArray.Size() >= 1,
50  "ArrayToBPFCnv::ConvertToBPF(): Array to be converted into a BPF must have a positive non-zero length!" );
51 
52  CLAM_ASSERT(originalArray.Size()==newBPF.Size(), "Different array dimensions on write");
53 
54  TX currentX = X0;
55 
56  for ( int i = 0; i < originalArray.Size(); i++ )
57  {
58  newBPF.SetXValue( i, currentX );
59  newBPF.SetValue( i, originalArray[i] );
60  currentX += deltaX;
61  }
62 
63  }
64 
65  //Convert X and Y values arrays to BPF
66  template <class TX, class TY>
67  void ConvertToBPF(BPFTmpl<TX,TY>& newBPF,const Array<TX>& originalXArray,
68  const Array<TY>& originalYArray)
69  {
70  CLAM_ASSERT(originalXArray.Size()>=1, "Zero lenght X array.");
71  CLAM_ASSERT(originalYArray.Size()>=1, "Zero lenght Y array.");
72  CLAM_ASSERT(originalXArray.Size()==originalYArray.Size(), "Different array dimensions for X and Y");
73  CLAM_ASSERT(originalXArray.Size()==newBPF.Size(), "Different array dimensions on write");
74 
75  for(int i=0;i<originalXArray.Size();i++)
76  {
77  newBPF.SetValue(i,originalYArray[i]);
78  newBPF.SetXValue(i,originalXArray[i]);
79  }
80  }
81 
82  //Convert BPF to X and Y values arrays
83  template <class TX, class TY>
84  void ConvertToArray(const BPFTmpl<TX,TY>& originalBPF,Array<TX>&
85  newXArray,Array<TY>& newYArray)
86  {
87  for(int i=0;i<originalBPF.Size();i++)
88  {
89  newXArray.AddElem(originalBPF.GetXValue(i));
90  newYArray.AddElem(originalBPF.GetValueFromIndex(i));
91  }
92  }
93 
94  /*Convert BPF to values array (points are supposed to be equidistant in the
95  X axis)*/
96  template <class TX, class TY>
97  void ConvertToArray(const BPFTmpl<TX,TY>& originalBPF,
98  Array<TY>& newArray)
99  {
100  for(int i=0;i<originalBPF.Size();i++)
101  {
102  newArray.AddElem(originalBPF.GetValueFromIndex(i));
103  }
104  }
105 
106 
107 }
108 
109 #endif
110