00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __frePointSupportedMetricController_h
00023 #define __frePointSupportedMetricController_h
00024
00025 #include "freImageToImageMetricControllerBase.h"
00026 #include "frePointSetMediaController.h"
00027
00028 #include "freIntensityImageMediaController.h"
00029 #include "frePointSupportedImageToImageMetric.h"
00030
00031 namespace FREE
00032 {
00033
00043 freControllerIDMacro(PointSupportedMetricControllerBase, "PointSupportedMetricBase");
00044 template <class TImageType, class TPointSet>
00045 class PointSupportedMetricControllerBase : public ImageToImageMetricControllerBase< itk::PointSupportedImageToImageMetric<TImageType,TImageType,TPointSet,TPointSet> >
00046 {
00047 public:
00048 typedef itk::PointSupportedImageToImageMetric<TImageType,TImageType,TPointSet,TPointSet> ComponentType;
00049 typedef ImageToImageMetricControllerBase<ComponentType> Superclass;
00050 typedef PointSupportedMetricControllerBase<TImageType,TPointSet> Self;
00051 typedef typename Superclass::GenericComponentType GenericComponentType;
00052 typedef typename Superclass::GenericComponentPointer GenericComponentPointer;
00053 typedef typename Superclass::GenericMediaPointer GenericMediaPointer;
00054
00055 itkTypeMacro(PointSupportedMetricControllerBase, ImageToImageMetricControllerBase);
00056
00057 DeclareParameterMacro(Alpha);
00058 DeclareParameterMacro(DetailedStats);
00059
00060 DeclareMediaIDMacro(fixedPointSet);
00061 DeclareMediaIDMacro(movingPointSet);
00062
00063 Parameter::Pointer GetParameter(const SessionComponentCache* pComponentCache,
00064 const std::string& sParameterName) const
00065 {
00066 if (sParameterName == cParam_MetricMinimize)
00067 {
00068
00069 Parameter::Pointer smpParam;
00070
00071 try
00072 {
00073 smpParam = pComponentCache->Setup()->Parameters().GetParameter(sParameterName);
00074 }
00075 catchAllNPassMacro("Error while retrieving parameter values.");
00076
00077 return smpParam;
00078 }
00079
00080 return Superclass::GetParameter(pComponentCache,sParameterName);
00081 };
00082
00083 protected:
00086 PointSupportedMetricControllerBase()
00087 {
00088
00089 this->UpdateControllerID(ControllerID::PointSupportedMetricControllerBase);
00090 this->m_Description = "Controls a point supported image to image metric.";
00091 };
00092
00093 virtual void GenerateProfile(CtrlProfile::ControllerProfile& profile,
00094 const SessionComponentCache* pComponentCache,
00095 bool bRegardOldSetup) const
00096 {
00097 Superclass::GenerateProfile(profile,pComponentCache,bRegardOldSetup);
00098
00099
00100 profile.Parameters().AddParameter(cParam_Alpha,Parameter::PVTDouble,cParamDsc_Alpha,1,"1.0",-1,true);
00101 profile.Parameters().AddParameter(cParam_DetailedStats,Parameter::PVTDouble,cParamDsc_DetailedStats,1,"false");
00102 profile.Parameters().AddParameter(cParam_MetricMinimize,Parameter::PVTBool,cParamDsc_MetricMinimize,1,"true");
00103
00104
00105 profile.MediaMap().AddMedia(MediaID_fixedPointSet,ControllerID::PointSetMediaControllerBase,DASet,TImageType::GetImageDimension(),2);
00106 profile.MediaMap().AddMedia(MediaID_movingPointSet,ControllerID::PointSetMediaControllerBase,DASet,TImageType::GetImageDimension(),2);
00107
00108
00109 profile.SubComponents().AddSubComponent("ImageMetric",1,csUndefinedController,"Image metric which will be supported via the point distance");
00110
00111
00112 CtrlProfile::ProfileOption* pOption;
00113
00114 pOption = profile.Requirements().AddRequirement("ImageMetric")->AddProfileOption();
00115 pOption->Inheritance().AddAncestor(ControllerID::ImageToImageMetricControllerBase);
00116 pOption->MediaMap().AddMedia(Superclass::MediaID_movingImage,ControllerID::IntensityImageMediaControllerBase, DASet, ComponentType::MovingImageType::GetImageDimension(),1,true);
00117 pOption->MediaMap().AddMedia(Superclass::MediaID_fixedImage,ControllerID::IntensityImageMediaControllerBase, DASet, ComponentType::FixedImageType::GetImageDimension(),1,true);
00118 pOption->CheckForInheritance();
00119 pOption->CheckForIO();
00120 };
00121
00122 virtual void ActualizeMainComponent(ComponentType* pMainComponent,
00123 SessionComponentCache* pComponentCache,
00124 SessionInfo* pSessionInfo,
00125 const unsigned int& iActLevel) const
00126 {
00127 double dAlpha;
00128
00129 try
00130 {
00131 SessionAccessor::GetParameterValue(pComponentCache,cParam_Alpha,dAlpha,0,iActLevel,true);
00132 }
00133 catchAllNPassMacro("Error while retrieving parameter values.");
00134
00135 pMainComponent->SetAlpha( dAlpha );
00136 };
00137
00138 virtual GenericMediaPointer GetMediaCasted(const MediaID& mediaID,
00139 ComponentType* pComponent,
00140 SessionComponentCache* pComponentCache,
00141 SessionInfo* pSessionInfo) const
00142 {
00143
00144
00145 return Superclass::GetMediaCasted(mediaID, pComponent, pComponentCache, pSessionInfo);
00146 };
00147
00148 virtual void SetSubComponentCasted(GenericComponentType* pSubComponent, ComponentType* pMainComponent,
00149 const ComponentID compID, SessionComponentCache* pMainComponentCache) const
00150 {
00151 if (compID == "ImageMetric") pMainComponent->SetImageMetric(dynamic_cast<typename ComponentType::ImageMetricType*>(pSubComponent));
00152 else Superclass::SetSubComponentCasted(pSubComponent, pMainComponent, compID, pMainComponentCache);
00153 };
00154
00155 virtual GenericComponentType* GetSubComponentCasted(ComponentType* pMainComponent,
00156 const ComponentID& compID,
00157 SessionComponentCache* pMainComponentCache) const
00158 {
00159 if (compID == "ImageMetric") return pMainComponent->GetImageMetric();
00160
00161 return Superclass::GetSubComponentCasted(pMainComponent, compID, pMainComponentCache);
00162 };
00163
00164 virtual void SetMediaCasted(const MediaID& mediaID, GenericMediaType* pMedia, ComponentType* pComponent, SessionComponentCache* pComponentCache,
00165 SessionInfo* pSessionInfo) const
00166 {
00167 if (mediaID == MediaID_movingPointSet) pComponent->SetMovingPointSet(dynamic_cast<typename ComponentType::MovingPointSetType*>(pMedia));
00168 else if (mediaID == MediaID_fixedPointSet) pComponent->SetFixedPointSet(dynamic_cast<typename ComponentType::FixedPointSetType*>(pMedia));
00169 else Superclass::SetMediaCasted(mediaID, pMedia, pComponent, pComponentCache, pSessionInfo);
00170 };
00171
00172 virtual void SetStatisticEntryMainComponent(StatisticEntry& rStatisticEntry,
00173 ComponentType* pMainComponent,
00174 SessionComponentCache* pMainComponentCache,
00175 SessionInfo* pSessionInfo,
00176 StatisticDictionary& rDictionary) const
00177 {
00178 Superclass::SetStatisticEntryMainComponent(rStatisticEntry,pMainComponent,
00179 pMainComponentCache,pSessionInfo,
00180 rDictionary);
00181
00182 bool bDetailedStats = false;
00183
00184 try
00185 {
00186 SessionAccessor::GetParameterValue(pMainComponentCache,cParam_DetailedStats,bDetailedStats);
00187 }
00188 catchAllNPassMacro("Error while retrieving parameter values.");
00189
00190 std::string sIDPath = pMainComponentCache->GetIDPath();
00191 StatisticValueDefinition* pImageEntry = rDictionary.GetValueDefinitionByName(sIDPath, "ImageMetricMeasure");
00192 StatisticValueDefinition* pPointEntry = rDictionary.GetValueDefinitionByName(sIDPath, "PointMetricMeasure");
00193
00194 typename ComponentType::DerivativeType imageDerivative;
00195 typename ComponentType::DerivativeType pointDerivative;
00196
00197 if (bDetailedStats)
00198 {
00199 imageDerivative = pMainComponent->GetLastImageDerivative();
00200 pointDerivative = pMainComponent->GetLastPointDerivative();
00201 }
00202
00203 if (!pImageEntry)
00204 {
00205 pImageEntry = rDictionary.AddValueDefinition(sIDPath,"ImageMetricMeasure","Value of the image measure.");
00206
00207 if (bDetailedStats)
00208 {
00209 for (unsigned int i = 0; i<imageDerivative.size(); i++)
00210 {
00211 rDictionary.AddValueDefinition(sIDPath,"i d "+Convert::ToStr(i), "derivative of the image metric");
00212 }
00213 }
00214 }
00215
00216 if (!pPointEntry)
00217 {
00218 pPointEntry = rDictionary.AddValueDefinition(sIDPath,"PointMetricMeasure","Value of the image measure.");
00219
00220 if (bDetailedStats)
00221 {
00222 for (unsigned int i = 0; i<pointDerivative.size(); i++)
00223 {
00224 rDictionary.AddValueDefinition(sIDPath,"p d "+Convert::ToStr(i), "derivative of the image metric");
00225 }
00226 }
00227 }
00228
00229 rStatisticEntry.AddValue(Convert::ToStr(pMainComponent->GetLastImageMetricValue()),pImageEntry->GetRefID());
00230 if (bDetailedStats)
00231 {
00232 for (unsigned int i = 0; i<imageDerivative.size(); i++)
00233 {
00234 rStatisticEntry.AddValue(Convert::ToStr(imageDerivative[i]),pImageEntry->GetRefID()+i+1);
00235 }
00236 }
00237
00238 rStatisticEntry.AddValue(Convert::ToStr(pMainComponent->GetLastPointMetricValue()),pPointEntry->GetRefID());
00239 if (bDetailedStats)
00240 {
00241 for (unsigned int i = 0; i<pointDerivative.size(); i++)
00242 {
00243 rStatisticEntry.AddValue(Convert::ToStr(pointDerivative[i]),pPointEntry->GetRefID()+i+1);
00244 }
00245 }
00246
00247 };
00248
00249 void ResetSubComponents(SessionComponentCache* pComponentCache,
00250 SessionInfo* pSessionInfo) const
00251 {
00252 if (!pComponentCache) throwCtrlExceptionMacro("","Error while resetting sub components; invalid parent component cache (null pointer).");
00253 if (!pSessionInfo) throwCtrlExceptionMacro("","Error while resetting sub components; invalid session info (null pointer).");
00254
00255 Superclass::ResetSubComponents(pComponentCache,pSessionInfo);
00256
00257
00258 try
00259 {
00260 SessionComponentCache* pMetricCache = pComponentCache->SubCaches().GetElement("ImageMetric");
00261 if (pMetricCache->ComponentIsAssigned())
00262 {
00263 SetSubComponent(pComponentCache,pMetricCache->Component(),"ImageMetric");
00264 }
00265 }
00266 catchAllNPassMacro("Error while resetting metric.");
00267 };
00268
00269 };
00270
00271 template <class TImageType, class TPointSet>
00272 const char* const PointSupportedMetricControllerBase<TImageType,TPointSet> :: cParam_Alpha = "Alpha";
00273 template <class TImageType, class TPointSet>
00274 const char* const PointSupportedMetricControllerBase<TImageType,TPointSet> :: cParamDsc_Alpha = "Factor for the selective costfunction part.";
00275 template <class TImageType, class TPointSet>
00276 const char* const PointSupportedMetricControllerBase<TImageType,TPointSet> :: cParam_DetailedStats = "DetailedStats";
00277 template <class TImageType, class TPointSet>
00278 const char* const PointSupportedMetricControllerBase<TImageType,TPointSet> :: cParamDsc_DetailedStats = "Indicates if the metric should also log the derivatives in the statistic.";
00279 template <class TImageType, class TPointSet>
00280 const char* const PointSupportedMetricControllerBase<TImageType,TPointSet> :: MediaID_movingPointSet = "movingPointSet";
00281 template <class TImageType, class TPointSet>
00282 const char* const PointSupportedMetricControllerBase<TImageType,TPointSet> :: MediaIDDsc_movingPointSet = "Moving point set that should be used to expand the image metric measure by reference point distances.";
00283 template <class TImageType, class TPointSet>
00284 const char* const PointSupportedMetricControllerBase<TImageType,TPointSet> :: MediaID_fixedPointSet = "fixedPointSet";
00285 template <class TImageType, class TPointSet>
00286 const char* const PointSupportedMetricControllerBase<TImageType,TPointSet> :: MediaIDDsc_fixedPointSet = "Fixed point set that should be used to expand the image metric measure by reference point distances.";
00287
00293 freControllerIDMacro(PointSupported2DMetricController, "Point Supported 2D Metric");
00294 class PointSupported2DMetricController : public PointSupportedMetricControllerBase< InternalImage2DType, ImageTypes<2>::PointSetType >
00295 {
00296 public:
00297 typedef PointSupportedMetricControllerBase<InternalImage2DType, ImageTypes<2>::PointSetType> Superclass;
00298 typedef Superclass::ComponentType ComponentType;
00299
00300 itkTypeMacro(PointSupported2DMetricController, PointSupportedMetricControllerBase);
00301
00302 PointSupported2DMetricController();
00303 };
00304
00310 freControllerIDMacro(PointSupported3DMetricController, "Point Supported 3D Metric");
00311 class PointSupported3DMetricController : public PointSupportedMetricControllerBase< InternalImage3DType, ImageTypes<3>::PointSetType >
00312 {
00313 public:
00314 typedef PointSupportedMetricControllerBase<InternalImage3DType, ImageTypes<3>::PointSetType> Superclass;
00315 typedef Superclass::ComponentType ComponentType;
00316
00317 itkTypeMacro(PointSupported3DMetricController, PointSupportedMetricControllerBase);
00318
00319 PointSupported3DMetricController();
00320 };
00321
00322 }
00323
00324 #endif