Fundamental.cxx
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "Fundamental.hxx"
00023 #include "ProcessingDataPlugin.hxx"
00024
00025
00026 namespace CLAM
00027 {
00028
00029 namespace Hidden
00030 {
00031 static ProcessingDataPlugin::Registrator<Fundamental> dataRegistrator("sandybrown");
00032 }
00034
00035
00036
00038
00039 void Fundamental::DefaultInit()
00040 {
00041
00042 AddCandidatesFreq();
00043 AddCandidatesErr();
00044 UpdateData();
00045
00046
00047 SetnMaxCandidates(1);
00048 SetnCandidates(0);
00049 }
00050
00051
00052 TData Fundamental::GetFreq(TIndex pos) const
00053 {
00054
00055 CLAM_DEBUG_ASSERT(HasCandidatesFreq(),"Fundamental::GetFreq(): Fundamental not initialized");
00056 if (pos < GetnCandidates())
00057 {
00058 return GetCandidatesFreq()[pos];
00059 }
00060 else
00061 {
00062 return 0.f;
00063 }
00064 }
00065
00066 TData Fundamental::GetErr(TIndex pos) const
00067 {
00068
00069 CLAM_DEBUG_ASSERT(HasCandidatesFreq(),"Fundamental::GetErr(): Fundamental not initialized");
00070 return GetCandidatesErr()[pos];
00071 }
00072
00073 void Fundamental::SetFreq(TIndex pos,TData freq)
00074 {
00075
00076 CLAM_DEBUG_ASSERT(HasCandidatesFreq(),"Fundamental::SetFreq(): Fundamental not initialized");
00077 CLAM_DEBUG_ASSERT(pos<GetnCandidates(),"Fundamental::SetFreq(): You are trying to set a candidate that does not exist");
00078 GetCandidatesFreq()[pos]=freq;
00079 }
00080
00081 void Fundamental::SetErr(TIndex pos,TData err)
00082 {
00083
00084 CLAM_DEBUG_ASSERT(HasCandidatesFreq(),"Fundamental::SetErr(): Fundamental not initialized");
00085 CLAM_DEBUG_ASSERT(pos<GetnCandidates(),"Fundamental::SetFreq(): You are trying to set a candidate that does not exist");
00086 GetCandidatesErr()[pos]=err;
00087 }
00088
00089
00090 void Fundamental::AddElem (TData freq, TData err)
00091 {
00092 CLAM_DEBUG_ASSERT(HasCandidatesFreq(),"Fundamental::AddElem(): Fundamental not initialized");
00093
00094
00095
00096 GetCandidatesFreq().AddElem(freq);
00097 GetCandidatesErr().AddElem(err);
00098
00099 }
00100
00101 void Fundamental::InsertElem (TIndex pos, TData freq, TData err)
00102 {
00103 CLAM_DEBUG_ASSERT(HasCandidatesFreq(),"Fundamental::InsertElem(): Fundamental not initialized");
00104 CLAM_ASSERT(GetnCandidates()<GetnMaxCandidates(),
00105 "Fundamental::InsertElem(): Number of Candidates exceeds maximum");
00106 GetCandidatesFreq().InsertElem(pos,freq);
00107 GetCandidatesErr().InsertElem(pos,err);
00108
00109 }
00110
00111 void Fundamental::DeleteElem (TIndex pos)
00112 {
00113 CLAM_DEBUG_ASSERT(HasCandidatesFreq(),"Fundamental::DeleteElem(): Fundamental not initialized");
00114 CLAM_ASSERT(pos<GetnCandidates()&&pos>=0,
00115 "Fundamental::DeleteElem(): Wrong index, element does not exist");
00116 GetCandidatesFreq().DeleteElem(pos);
00117 GetCandidatesErr().DeleteElem(pos);
00118
00119 }
00120
00121 void Fundamental::SortByFrequency()
00122 {
00123
00124
00125
00126 DataArray & errors = GetCandidatesErr();
00127 DataArray & freqs = GetCandidatesFreq();
00128 const int nCandidates = GetnCandidates();
00129 for (int i=0; i<nCandidates; i++)
00130 for (int j=i+1; j<nCandidates; j++)
00131 {
00132 if (freqs[i] <= freqs[j]) continue;
00133 std::swap(errors[i],errors[j]);
00134 std::swap(freqs[i],freqs[j]);
00135 }
00136 }
00137
00138 void Fundamental::SortByError()
00139 {
00140
00141
00142
00143 DataArray & errors = GetCandidatesErr();
00144 DataArray & freqs = GetCandidatesFreq();
00145 const int nCandidates = GetnCandidates();
00146 for (int i=0; i<nCandidates; i++)
00147 for (int j=i+1; j<nCandidates; j++)
00148 {
00149 if (errors[i] <= errors[j]) continue;
00150 std::swap(errors[i],errors[j]);
00151 std::swap(freqs[i],freqs[j]);
00152 }
00153 }
00154
00155 }
00156