DataUtil.cxx
Go to the documentation of this file.00001 #include "DataUtil.hxx"
00002 #include <iostream>
00003
00004 namespace CLAM
00005 {
00006
00007 void DataUtil::CopyFrameMembers(Frame& sourceFrame,
00008 Frame& targetFrame)
00009 {
00010 targetFrame.SetCenterTime(sourceFrame.GetCenterTime());
00011
00012
00013 SpectralPeakArray& sourceSpectralPeaks = sourceFrame.GetSpectralPeakArray();
00014 SpectralPeakArray& targetSpectralPeaks = targetFrame.GetSpectralPeakArray();
00015 CopySpectralPeakArraysMembers(sourceSpectralPeaks, targetSpectralPeaks);
00016
00017
00018
00019
00020
00021 Spectrum& sourceResidualSpectrum = sourceFrame.GetResidualSpec();
00022 Spectrum& targetResidualSpectrum = targetFrame.GetResidualSpec();
00023 CopyResidualSpectrumsMembers(sourceResidualSpectrum, targetResidualSpectrum);
00024
00025 }
00026
00027 void DataUtil::CopySpectralPeakArraysMembers(SpectralPeakArray& sourceSpectralPeaks,
00028 SpectralPeakArray& targetSpectralPeaks )
00029 {
00030 targetSpectralPeaks.AddAll();
00031 targetSpectralPeaks.UpdateData();
00032
00033 targetSpectralPeaks.CopyMembers(sourceSpectralPeaks);
00034 }
00035
00036 void DataUtil::CopyResidualSpectrumsMembers(Spectrum& sourceResidualSpectrum,
00037 Spectrum& targetResidualSpectrum)
00038 {
00039 targetResidualSpectrum.AddAll();
00040 targetResidualSpectrum.UpdateData();
00041
00042 int size = sourceResidualSpectrum.GetSize();
00043 targetResidualSpectrum.SetSize( size );
00044 Array<Complex>& srcComplexBuffer = sourceResidualSpectrum.GetComplexArray();
00045 Array<Complex>& targetComplexBuffer = targetResidualSpectrum.GetComplexArray();
00046 for (int r=0; r < size; r++)
00047 {
00048 targetComplexBuffer[r] = srcComplexBuffer[r];
00049 }
00050 }
00051
00052 bool DataUtil::CheckMembers(Frame& sourceFrame,
00053 Frame& targetFrame)
00054 {
00055
00056 SpectralPeakArray& sourceSpectralPeaks = sourceFrame.GetSpectralPeakArray();
00057 SpectralPeakArray& targetSpectralPeaks = targetFrame.GetSpectralPeakArray();
00058
00059
00060 DataArray& srcFreqBuffer = sourceSpectralPeaks.GetFreqBuffer();
00061 DataArray& srcMagBuffer = sourceSpectralPeaks.GetMagBuffer();
00062 DataArray& srcPhaseBuffer = sourceSpectralPeaks.GetPhaseBuffer();
00063 DataArray& srcBinPosBuffer = sourceSpectralPeaks.GetBinPosBuffer();
00064 DataArray& srcBinWidthBuffer = sourceSpectralPeaks.GetBinWidthBuffer();
00065 IndexArray& srcIndexArray = sourceSpectralPeaks.GetIndexArray();
00066
00067 DataArray& targetFreqBuffer = targetSpectralPeaks.GetFreqBuffer();
00068 DataArray& targetMagBuffer = targetSpectralPeaks.GetMagBuffer();
00069 DataArray& targetPhaseBuffer = targetSpectralPeaks.GetPhaseBuffer();
00070 DataArray& targetBinPosBuffer = targetSpectralPeaks.GetBinPosBuffer();
00071 DataArray& targetBinWidthBuffer = targetSpectralPeaks.GetBinWidthBuffer();
00072 IndexArray& targetIndexArray = targetSpectralPeaks.GetIndexArray();
00073
00074 int numberOfPeaks = sourceSpectralPeaks.GetnPeaks();
00075 for (int r=0; r < numberOfPeaks;r++)
00076 {
00077
00078 if (targetFreqBuffer[r] != srcFreqBuffer[r] ||
00079 targetMagBuffer[r] != srcMagBuffer[r] ||
00080 targetPhaseBuffer[r] != srcPhaseBuffer[r] ||
00081 targetBinPosBuffer[r] != srcBinPosBuffer[r] ||
00082 targetBinWidthBuffer[r] != srcBinWidthBuffer[r] ||
00083 targetIndexArray[r] != srcIndexArray[r])
00084 return false;
00085 }
00086
00087
00088
00089
00090
00091 Spectrum& sourceResidualSpectrum = sourceFrame.GetResidualSpec();
00092 Spectrum& targetResidualSpectrum = targetFrame.GetResidualSpec();
00093 int size = sourceResidualSpectrum.GetSize();
00094 targetResidualSpectrum.SetSize( size );
00095 Array<Complex>& srcComplexBuffer = sourceResidualSpectrum.GetComplexArray();
00096 Array<Complex>& targetComplexBuffer = targetResidualSpectrum.GetComplexArray();
00097 for (int r=0; r < size; r++)
00098 {
00099 if (targetComplexBuffer[r] != srcComplexBuffer[r])
00100 return false;
00101 }
00102
00103 return true;
00104 }
00105
00106 void DataUtil::PrintSpectralPeakArray(SpectralPeakArray& sourceSpectralPeaks)
00107 {
00108 DataArray& srcFreqBuffer = sourceSpectralPeaks.GetFreqBuffer();
00109 DataArray& srcMagBuffer = sourceSpectralPeaks.GetMagBuffer();
00110
00111 int numberOfPeaks = sourceSpectralPeaks.GetnPeaks();
00112 std::cout << "Printing out the contents of the spectral peak array." << std::endl;
00113 for (int r=0; r < numberOfPeaks;r++)
00114 {
00115
00116 std::cout << "Frequency: " << srcFreqBuffer[r];
00117 std::cout << ", Magnitude: " << srcMagBuffer[r] << std::endl;
00118 }
00119 std::cout << "Done." << std::endl;
00120 }
00121
00122 }
00123
00124