ArrayToBPFCnv.hxx

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
00003  *                         UNIVERSITAT POMPEU FABRA
00004  *
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 
00022 #ifndef _ArrayToBPFCnv_
00023 #define _ArrayToBPFCnv_
00024 
00025 #include "BPF.hxx"
00026 #include "DataTypes.hxx"
00027 
00028 namespace CLAM {
00029 
00030 /*Conversion Routines*/
00031 
00032         //Convert values array (supposed to be equidistant) to BPF
00033         template <class TX, class TY> 
00034         void ConvertToBPF(BPFTmpl<TX,TY>& newBPF,const Array<TY>& originalArray)
00035         {
00036                 CLAM_ASSERT(originalArray.Size()>=1, "Zero lenght array.");
00037                 CLAM_ASSERT(originalArray.Size()==newBPF.Size(), "Different array dimensions");
00038 
00039                 for(int i=0;i<originalArray.Size();i++)
00040                 {
00041                         newBPF.SetXValue( i, (TX)i );
00042                         newBPF.SetValue( i,originalArray[i]);
00043                 }
00044         }
00045 
00046         template <class TX, class TY> 
00047         void ConvertToBPF( BPFTmpl<TX,TY>& newBPF, TX X0, TX deltaX, const Array<TY>& originalArray )
00048         {
00049                 CLAM_ASSERT( originalArray.Size() >= 1, 
00050                              "ArrayToBPFCnv::ConvertToBPF(): Array to be converted into a BPF must have a positive non-zero length!" );
00051 
00052                 CLAM_ASSERT(originalArray.Size()==newBPF.Size(), "Different array dimensions on write");
00053                 
00054                 TX currentX = X0;
00055 
00056                 for ( int i = 0; i < originalArray.Size(); i++ )
00057                 {
00058                         newBPF.SetXValue( i, currentX );
00059                         newBPF.SetValue( i, originalArray[i] );
00060                         currentX += deltaX;
00061                 }
00062 
00063         }
00064 
00065         //Convert X and Y values arrays to BPF
00066         template <class TX, class TY> 
00067         void ConvertToBPF(BPFTmpl<TX,TY>& newBPF,const Array<TX>& originalXArray,
00068                 const Array<TY>& originalYArray)
00069         {
00070                 CLAM_ASSERT(originalXArray.Size()>=1, "Zero lenght X array.");
00071                 CLAM_ASSERT(originalYArray.Size()>=1, "Zero lenght Y array.");
00072                 CLAM_ASSERT(originalXArray.Size()==originalYArray.Size(), "Different array dimensions for X and Y");
00073                 CLAM_ASSERT(originalXArray.Size()==newBPF.Size(), "Different array dimensions on write");
00074 
00075                 for(int i=0;i<originalXArray.Size();i++)
00076                 {       
00077                         newBPF.SetValue(i,originalYArray[i]);
00078                         newBPF.SetXValue(i,originalXArray[i]);
00079                 }
00080         }
00081         
00082         //Convert BPF to X and Y values arrays
00083         template <class TX, class TY> 
00084         void ConvertToArray(const BPFTmpl<TX,TY>& originalBPF,Array<TX>& 
00085                 newXArray,Array<TY>& newYArray)
00086         {
00087                 for(int i=0;i<originalBPF.Size();i++)
00088                 {
00089                         newXArray.AddElem(originalBPF.GetXValue(i));
00090                         newYArray.AddElem(originalBPF.GetValueFromIndex(i));
00091                 }
00092         }
00093         
00094         /*Convert BPF to values array (points are supposed to be equidistant in the 
00095         X axis)*/
00096         template <class TX, class TY> 
00097         void ConvertToArray(const BPFTmpl<TX,TY>& originalBPF,
00098                 Array<TY>& newArray)
00099         {
00100                 for(int i=0;i<originalBPF.Size();i++)
00101                 {
00102                          newArray.AddElem(originalBPF.GetValueFromIndex(i));
00103                 }
00104         }
00105 
00106 
00107 }
00108 
00109 #endif
00110 
Generated by  doxygen 1.6.3