00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __freCompareHistogramMetricController_h
00023 #define __freCompareHistogramMetricController_h
00024
00025 #include "freHistogramMetricControllerBase.h"
00026 #include "freTransformControllerBase.h"
00027 #include "freInterpolatorControllerBase.h"
00028
00029 #include "itkCompareHistogramImageToImageMetric.h"
00030
00031 namespace FREE
00032 {
00033
00034 ParameterMacro(TrainHisto, "TrainingHistogram","Defines the training historgram that should be used for comparing.\nIf the training histogram is set, no other training parameters / components are required.");
00035 ParameterMacro(TrainFixed, "TrainingFixedImage","Training fixed image, which will be used to calculate the training historgram.\nOnly required if the histogram is not set directly.");
00036 ParameterMacro(TrainMoving, "TrainingMovingImage","Training moving image, which will be used to calculate the training historgram.\nOnly required if the histogram is not set directly.");
00037
00038 ComponentMacro(TrainTransform, "Transform used to calculate the training histogram.\nOnly required if the histogram is not set directly.");
00039 ComponentMacro(TrainInterpolator, "Interpolator used to calculate the training histogram.\nOnly required if the histogram is not set directly.");
00040
00051 freControllerIDMacro(CompareHistogramMetricControllerBase, "CompareHistogramMetricBase");
00052 template <class TControlledCompareHistogramMetric>
00053 class CompareHistogramMetricControllerBase : public HistogramMetricControllerBase< TControlledCompareHistogramMetric >
00054 {
00055 public:
00056 typedef typename TControlledCompareHistogramMetric ComponentType;
00057 typedef typename ComponentType::Pointer ComponentPointer;
00058 typedef HistogramMetricControllerBase<ComponentType> Superclass;
00059
00060 itkTypeMacro(CompareHistogramMetricControllerBase, HistogramMetricControllerBase);
00061
00062 virtual ~CompareHistogramMetricControllerBase()
00063 {
00064 };
00065
00066 protected:
00069 CompareHistogramMetricControllerBase()
00070 {
00071
00072 this->UpdateControllerID(ControllerID::CompareHistogramMetricControllerBase);
00073 this->m_Description = "A metric computes the similarity between the histogram produced by two images overlapping and a training histogram.";
00074
00075
00076 m_Profile->Parameters().AddParameter(cParam_TrainHisto,Parameter::PVTDouble,cParamDsc_TrainHisto,2,false,"",true);
00077 m_Profile->Parameters().AddParameter(cParam_MetricMinimize,Parameter::PVTBool,cParamDsc_MetricMinimize,1,true,"true");
00078
00079
00080 m_Profile->SubComponents().AddSubComponent(cComp_TrainTransform,2,csUndefinedController,cCompDsc_TrainTransform);
00081 m_Profile->SubComponents().AddSubComponent(cComp_TrainInterpolator,2,csUndefinedController,cCompDsc_TrainInterpolator);
00082
00083
00084 CtrlProfile::ProfileOption* pOption;
00085
00086 pOption = m_Profile->Requirements().AddRequirement(cComp_MainInterpolator)->AddProfileOption();
00087 pOption->Inheritance().AddAncestor(ControllerID::InterpolatorControllerBase);
00088 pOption->MediaMap().AddMedia("inputImage",ControllerID::ImageMediaControlerBase, DASet, ComponentType::ImageDimension,0,true);
00089 pOption->CheckForInheritance();
00090 pOption->CheckForIO();
00091
00092 pOption = m_Profile->Requirements().AddRequirement(cComp_MainTransform)->AddProfileOption();
00093 pOption->Inheritance().AddAncestor(ControllerID::TransformControllerBase);
00094 pOption->MediaMap().AddMedia("movingMedia",ControllerID::MediaControlerBase, DASet, ComponentType::ImageDimension,0,true);
00095 pOption->MediaMap().AddMedia("fixedMedia",ControllerID::MediaControlerBase, DASet, ComponentType::ImageDimension,0,true);
00096 pOption->CheckForInheritance();
00097 pOption->CheckForIO();
00098
00099
00100 std::string sControllerID = "Intensity Image 2D Media";
00101 if (TControlledCompareHistogramMetric::FixedImageType::GetImageDimension() == 3) sControllerID = "Intensity Image 3D Media";
00102
00103 m_Profile->MediaMap().AddMedia(cParam_TrainMoving,sControllerID,DASet,TControlledCompareHistogramMetric::FixedImageType::GetImageDimension(),2);
00104 m_Profile->MediaMap().AddMedia(cParam_TrainFixed,sControllerID,DASet,TControlledCompareHistogramMetric::FixedImageType::GetImageDimension(),2);
00105 };
00106
00107 virtual GenericComponentType* GetSubComponentCasted(ComponentType* pMainComponent, const ComponentID& compID,
00108 SessionComponentCache* pMainComponentCache) const
00109 {
00110 if (compID == cComp_TrainInterpolator) return pMainComponent->GetTrainingInterpolator ();
00111 if (compID == cComp_TrainTransform) return pMainComponent->GetTrainingTransform ();
00112
00113 return Superclass::GetSubComponentCasted(pMainComponent, compID, pMainComponentCache);
00114 };
00115
00116 virtual void SetSubComponentCasted(GenericComponentType* pSubComponent, ComponentType* pMainComponent,
00117 const ComponentID compID, SessionComponentCache* pMainComponentCache) const
00118 {
00119 if (compID == cComp_TrainInterpolator) pMainComponent->SetTrainingInterpolator( dynamic_cast< ComponentType::InterpolatorType* > (pSubComponent) );
00120 else if (compID == cComp_TrainTransform) pMainComponent->SetTrainingTransform( dynamic_cast< ComponentType::TransformType* > (pSubComponent) );
00121 else Superclass::SetSubComponentCasted(pSubComponent, pMainComponent, compID, pMainComponentCache);
00122 };
00123
00124 virtual void SetMediaCasted(const MediaID& mediaID, GenericMediaType* pMedia,
00125 ComponentType* pComponent,
00126 SessionComponentCache* pComponentCache,
00127 SessionInfo* pSessionInfo) const
00128 {
00129 if (mediaID == cParam_TrainMoving) pComponent->SetTrainingMovingImage(dynamic_cast<ComponentType::MovingMarkerImageType*>(pMedia));
00130 else if (mediaID == cParam_TrainFixed) pComponent->SetTrainingFixedImage(dynamic_cast<ComponentType::FixedMarkerImageType*>(pMedia));
00131 else Superclass::SetMediaCasted(mediaID, pMedia, pComponent, pComponentCache, pSessionInfo);
00132 };
00133
00134 virtual void ActualizeMainComponent(ComponentType* pMainComponent,
00135 SessionComponentCache* pComponentCache,
00136 SessionInfo* pSessionInfo,
00137 const unsigned int& iActLevel) const
00138 {
00139 Superclass::ActualizeMainComponent(pMainComponent,
00140 pComponentCache, pSessionInfo,
00141 iActLevel);
00142
00143 if (b1stTime)
00144 {
00145 Parameter* pParameter = pComponentSetup->Parameters().GetElement(cParam_TrainHisto);
00146 if (!pParameter) throwCtrlExceptionMacro("","Missing parameter: "<<cParam_TrainHisto<<". Please ensure correct initializiation of the setup");
00147
00148 if (pParameter->Size()!=0)
00149 {
00150 for (Parameter::LayerCountType index = 0; index < pParameter->LayerCount(); index++)
00151 {
00152 ComponentType::HistogramPointer::MeasurmentVectorType measure = Convert::ParameterLayerToFixedArray<ComponentType::HistogramPointer::MeasurmentVectorType>(pParameter->GetParameterLayer(index));
00153 pMainComponent->GetTrainingHistogram().SetFrequency(measure,1);
00154 }
00155 }
00156 else
00157 {
00158
00159
00160 if (!pMainComponent->GetTrainingTransform()) throwCtrlExceptionMacro("","Missing transform for calculation of histogram. No histogram set, hence histogram must be calculated. Please set histogram directly or set training components (transform, interpolator, and images)");
00161 if (!pMainComponent->GetTrainingInterpolator()) throwCtrlExceptionMacro("","Missing interpolator for calculation of histogram. No histogram set, hence histogram must be calculated. Please set histogram directly or set training components (transform, interpolator, and images)");
00162 if (!pMainComponent->GetTrainingMovingImage()) throwCtrlExceptionMacro("","Missing training moving image for calculation of histogram. No histogram set, hence histogram must be calculated. Please set histogram directly or set training components (transform, interpolator, and images)");
00163 if (!pMainComponent->GetTrainingFixedImage()) throwCtrlExceptionMacro("","Missing training fixed image for calculation of histogram. No histogram set, hence histogram must be calculated. Please set histogram directly or set training components (transform, interpolator, and images)");
00164
00165 pMainComponent->Initialize();
00166 }
00167 }
00168
00169
00170 };
00171 };
00172
00173 }
00174
00175 #endif