00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __freConsistencyRegistrationMetric_txx
00023 #define __freConsistencyRegistrationMetric_txx
00024
00025 #include "freConsistencySOMetric.h"
00026 #include "freGenericSetupToImageAdaptor.h"
00027 #include "freVectorToNormImageFilter.h"
00028 #include "freImageSampleCharacteristicsCalculator.h"
00029 #include "freImageAdaptationInverter.h"
00030
00031 #include "itkNumericTraits.h"
00032 #include "itkAddImageFilter.h"
00033 #include "itkImageAdaptor.h"
00034 #include "itkPointSet.h"
00035 #include "itkListSample.h"
00036
00037 namespace FREE
00038 {
00039
00040 template <unsigned int VImageDimension>
00041 typename ConsistencyRegistrationMetric<VImageDimension>::DecomposedMeasureType
00042 ConsistencyRegistrationMetric<VImageDimension>::
00043 ComputeDecomposedValue( const ParametersType & parameters ) const
00044 {
00045 if (this->m_smpAdaptations.IsNull()) throwExceptionMacro("Error. Cannot calculate metric value, adaptiation list is null.");
00046 if (this->m_Transform.IsNull()) throwExceptionMacro("Error. Cannot calculate metric value, no setup transform set.");
00047
00048 if (this->m_Transform->GetNumberOfParameters() != parameters.size()) throwExceptionMacro("Error. Cannot calculate metric value, number of passed parameters is not equal to the parameter size of the transform. Passed parameter count: "<< parameters.size());
00049
00050 m_dMinError = itk::NumericTraits< double >::max();
00051 m_dMaxError = 0.0;
00052 m_lFailedRegistrations = 0;
00053 m_lActAdaptation = 0;
00054 m_dErrorMean = 0.0;
00055 m_dErrorVar = 0.0;
00056
00057 m_Errors.clear();
00058 m_Vars.clear();
00059 m_Samplesize.clear();
00060
00061 m_Transform->SetParameters(parameters);
00062 m_smpSetup = m_Transform->GenerateTransformedSetup();
00063
00064 for (unsigned int iAdaptID = 0; iAdaptID<m_smpAdaptations->Size(); iAdaptID++)
00065 {
00066 if (this->fnOnNextAdaptation.IsNotNull()) this->fnOnNextAdaptation->Execute(iAdaptID,"",(void*)this);
00067 this->InvokeEvent( NextAdaptationObserverEvent() );
00068
00069 Adaptation::Adaptation* pAdaptation = m_smpAdaptations->GetElement(iAdaptID);
00070 Adaptation::Adaptation::Pointer smpReverseAdaptation = ImageAdaptationInverter::InvertAdaptation(*pAdaptation);
00071
00072 Setup::Pointer smpSetup = Setup::New();
00073 Setup::Pointer smpReverseSetup = Setup::New();
00074 smpSetup->operator =(*m_smpSetup);
00075 smpReverseSetup->operator =(*m_smpSetup);
00076
00077 GenericSetupToImageAdaptor::AdaptSetup(*pAdaptation, *smpSetup);
00078 GenericSetupToImageAdaptor::AdaptSetup(*(smpReverseAdaptation.GetPointer()), *smpReverseSetup);
00079
00080 ComputeRegistrations(smpSetup, smpReverseSetup);
00081
00082 if (fnOnEvaluationDone.IsNotNull()) fnOnEvaluationDone->Execute(iAdaptID,"",(void*)this);
00083 this->InvokeEvent( EvaluationDoneObserverEvent() );
00084 };
00085
00086 unsigned long lTotalSamples = 0;
00087 for (unsigned int iIndex=0; iIndex<m_Errors.size(); iIndex++)
00088 {
00089 m_dErrorMean += m_Errors[iIndex] * m_Samplesize[iIndex];
00090 m_dErrorVar += m_Vars[iIndex] * (m_Samplesize[iIndex]-1);
00091 lTotalSamples += m_Samplesize[iIndex];
00092 }
00093
00094 if (lTotalSamples>0) m_dErrorMean /= lTotalSamples;
00095 if (lTotalSamples>1) m_dErrorVar /= lTotalSamples-1;
00096
00097 DecomposedMeasureType results(5);
00098 results.SetElement(0,m_dErrorMean);
00099 results.SetElement(1,std::sqrt(m_dErrorVar));
00100 results.SetElement(2,m_dMinError);
00101 results.SetElement(3,m_dMaxError);
00102 results.SetElement(4,m_lFailedRegistrations);
00103
00104 return results;
00105 };
00106
00107 template <unsigned int VImageDimension>
00108 ConsistencyRegistrationMetric<VImageDimension>::
00109 ConsistencyRegistrationMetric()
00110 {
00111
00112 };
00113
00114 template <unsigned int VImageDimension>
00115 void
00116 ConsistencyRegistrationMetric<VImageDimension>::
00117 OnNextIteration(const long lIteration, Statistics* pStatistic, void* pSender)
00118 {
00119
00120
00121 }
00122
00123 template <unsigned int VImageDimension>
00124 void
00125 ConsistencyRegistrationMetric<VImageDimension>::
00126 ComputeRegistrations(Setup* pSetup, Setup* pReverseSetup) const
00127 {
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209 };
00210
00211 }
00212
00213 #endif