00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00023
00025
00026
00027
00028
00029
00030
00031
00032
00033
00035
00036
00037
00038 #ifndef _SpectralPeakArray_
00039 #define _SpectralPeakArray_
00040
00041 #include "DynamicType.hxx"
00042 #include "Array.hxx"
00043 #include "IndexArray.hxx"
00044 #include "DataTypes.hxx"
00045 #include "OSDefines.hxx"
00046 #include "Err.hxx"
00047 #include "ProcessingData.hxx"
00048 #include "SpectralPeak.hxx"
00049
00050
00051
00052 namespace CLAM{
00053
00054
00068 class SpectralPeakArray : public ProcessingData
00069 {
00070 public:
00071 DYNAMIC_TYPE_USING_INTERFACE (SpectralPeakArray, 8, ProcessingData);
00072 DYN_ATTRIBUTE (0, public, EScale, Scale);
00073 DYN_ATTRIBUTE (1, public, DataArray, MagBuffer);
00074 DYN_ATTRIBUTE (2, public, DataArray, FreqBuffer);
00075 DYN_ATTRIBUTE (3, public, DataArray, PhaseBuffer);
00076 DYN_ATTRIBUTE (4, public, DataArray, BinPosBuffer);
00077 DYN_ATTRIBUTE (5, public, DataArray, BinWidthBuffer);
00078 DYN_ATTRIBUTE (6, public, IndexArray, IndexArray);
00079 DYN_ATTRIBUTE (7, public, bool, MinimizeResizes);
00080
00081 protected:
00082 void DefaultInit();
00083 public:
00084
00090 SpectralPeakArray(const SpectralPeak& prototype);
00091
00097 void InitFromPrototype(const SpectralPeak& spectralPeak);
00098
00104 void InitPeak(SpectralPeak& spectralPeak) const;
00105
00106
00111 TData GetMag(TIndex pos) const{return GetMagBuffer()[pos];}
00116 TData GetFreq(TIndex pos)const{return GetFreqBuffer()[pos];}
00121 TData GetPhase(TIndex pos)const{return GetPhaseBuffer()[pos];}
00126 TData GetBinPos(TIndex pos)const{return GetBinPosBuffer()[pos];}
00131 int GetBinWidth(TIndex pos)const{return int(GetBinWidthBuffer()[pos]);}
00136 void SetMag(TIndex pos,TData newMag){GetMagBuffer()[pos]=newMag;}
00141 void SetFreq(TIndex pos,TData newFreq){GetFreqBuffer()[pos]=newFreq;}
00146 void SetPhase(TIndex pos,TData newPhase){GetPhaseBuffer()[pos]=newPhase;}
00151 void SetBinPos(TIndex pos,TData newBinPos){GetBinPosBuffer()[pos]=newBinPos;}
00156 void SetBinWidth(TIndex pos,int newBinWidth){GetBinWidthBuffer()[pos]=TData(newBinWidth);}
00157
00161 TIndex GetMaxMagPos() const;
00162
00166 TIndex GetMaxMagIndex() const;
00167
00168
00175 void InitSpectralPeak(SpectralPeak& spectralPeak) const;
00181 bool IsCorrectPrototype(const SpectralPeak& spectralPeak) const;
00187 SpectralPeak GetSpectralPeak(TIndex pos) const;
00193 SpectralPeak GetThruIndexSpectralPeak(TIndex pos) const;
00200 void SetSpectralPeak(TIndex pos,const SpectralPeak& spectralPeak,TIndex index=-1);
00210 void InsertSpectralPeak(TIndex pos,const SpectralPeak& spectralPeak,
00211 bool insertIndex=false,TIndex index=-1);
00219 void AddSpectralPeak(const SpectralPeak& spectralPeak,bool addIndex=false,TIndex index=-1);
00226 void DeleteSpectralPeak(TIndex pos,bool deleteIndex=false);
00227
00228
00229
00230
00231
00235 int GetnIndexedPeaks() const;
00236
00241 TIndex GetPositionFromIndex(TIndex index) const;
00242
00247 void SetIndex(TIndex pos,TIndex index){GetIndexArray()[pos]=index;};
00252 TIndex GetIndex(TIndex pos) const {return GetIndexArray()[pos];}
00256 void DeleteIndex (TIndex index);
00261 void ResetIndices();
00266 void InitIndices();
00271 void SetIndicesTo(TIndex val);
00275 void AddIndex(TIndex index);
00276
00282 TIndex GetFirstNonValidIndexPosition(TIndex beginAt) const;
00287 bool IsValidIndex(TIndex position) const;
00292 TIndex IsIndexExisting(TIndex index) const;
00296 TIndex GetMaxIndex() const;
00297
00298
00299
00305 TSize GetnPeaks() const
00306 {
00307 if(HasMagBuffer()) return GetMagBuffer().Size();
00308 if(HasFreqBuffer()) return GetFreqBuffer().Size();
00309 if(HasPhaseBuffer()) return GetPhaseBuffer().Size();
00310 if(HasBinPosBuffer()) return GetBinPosBuffer().Size();
00311 if(HasBinWidthBuffer()) return GetBinWidthBuffer().Size();
00312 else return 0;
00313 }
00314
00319
00320
00321 void SetnPeaks(TSize npeaks)
00322 {
00323 if (npeaks>GetnMaxPeaks()) SetnMaxPeaks(npeaks);
00324 if(HasMagBuffer()) {
00325 GetMagBuffer().Resize(npeaks);
00326 GetMagBuffer().SetSize(npeaks);}
00327 if(HasFreqBuffer()) {
00328 GetFreqBuffer().Resize(npeaks);
00329 GetFreqBuffer().SetSize(npeaks);}
00330 if(HasPhaseBuffer()){
00331 GetPhaseBuffer().Resize(npeaks);
00332 GetPhaseBuffer().SetSize(npeaks);}
00333 if(HasBinPosBuffer()) {
00334 GetBinPosBuffer().Resize(npeaks);
00335 GetBinPosBuffer().SetSize(npeaks);}
00336 if(HasBinWidthBuffer()) {
00337 GetBinWidthBuffer().Resize(npeaks);
00338 GetBinWidthBuffer().SetSize(npeaks);}
00339 if(HasIndexArray()) {
00340 GetIndexArray().Resize(npeaks);
00341 GetIndexArray().SetSize(npeaks);}
00342
00343
00344 }
00345
00349 void SetnMaxPeaks(TSize npeaks)
00350 {
00351 if(HasMagBuffer()){
00352 GetMagBuffer().Resize(npeaks);
00353 if(GetMinimizeResizes())
00354 GetMagBuffer().SetStep(npeaks);}
00355 if(HasFreqBuffer()){
00356 GetFreqBuffer().Resize(npeaks);
00357 if(GetMinimizeResizes())
00358 GetFreqBuffer().SetStep(npeaks);}
00359 if(HasPhaseBuffer()){
00360 GetPhaseBuffer().Resize(npeaks);
00361 if(GetMinimizeResizes())
00362 GetPhaseBuffer().SetStep(npeaks);}
00363 if(HasBinPosBuffer()){
00364 GetBinPosBuffer().Resize(npeaks);
00365 if(GetMinimizeResizes())
00366 GetBinPosBuffer().SetStep(npeaks);}
00367 if(HasBinWidthBuffer()){
00368 GetBinWidthBuffer().Resize(npeaks);
00369 if(GetMinimizeResizes())
00370 GetBinWidthBuffer().SetStep(npeaks);}
00371 if(HasIndexArray()){
00372 GetIndexArray().Resize(npeaks);
00373 if(GetMinimizeResizes())
00374 GetIndexArray().SetStep(npeaks);}
00375 }
00376
00382 TSize GetnMaxPeaks() const
00383 {
00384 if(HasMagBuffer()) return GetMagBuffer().AllocatedSize();
00385 if(HasFreqBuffer()) return GetFreqBuffer().AllocatedSize();
00386 if(HasPhaseBuffer()) return GetPhaseBuffer().AllocatedSize();
00387 if(HasBinPosBuffer()) return GetBinPosBuffer().AllocatedSize();
00388 if(HasBinWidthBuffer()) return GetBinWidthBuffer().AllocatedSize();
00389 else return 0;
00390 }
00391
00392
00393 double GetThruIndexFreq(TIndex pos) const;
00394 double GetThruIndexMag(TIndex pos) const;
00395 double GetThruIndexPhase(TIndex pos) const;
00396 double GetThruIndexBinPos(TIndex pos) const;
00397 TSize GetThruIndexBinWidth(TIndex pos) const;
00398 void SetThruIndexFreq(TIndex pos,double freq);
00399 void SetThruIndexMag(TIndex pos,double mag) ;
00400 void SetThruIndexPhase(TIndex pos,double phase) ;
00401 void SetThruIndexBinPos(TIndex pos,double binPos);
00402 void SetThruIndexBinWidth(TIndex pos,TSize binWidth);
00403 void SetThruIndexSpectralPeak(TIndex pos,SpectralPeak& peak);
00404
00405 void SetIsIndexUpToDate(bool isUpToDate)
00406 {
00407 mIsIndexUpToDate = isUpToDate;
00408 }
00409
00411 void TodB();
00413 void ToLinear();
00414
00420 void CopyMembers(SpectralPeakArray& sourceSpectralPeakArray);
00421
00422 SpectralPeakArray operator+(const SpectralPeakArray& in);
00423 private:
00424 bool mIsIndexUpToDate;
00425
00426 };
00427
00428 };
00429
00430 #endif
00431