00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __freConstrainedImageDifferenceSOMetricController_h
00023 #define __freConstrainedImageDifferenceSOMetricController_h
00024
00025 #include "freImageDifferenceSOMetricController.h"
00026
00027 #include "freConstrainedImageDifferenceSOMetric.h"
00028
00029 namespace FREE
00030 {
00031
00040 freControllerIDMacro(ConstrainedImageDifferenceSOMetricControllerBase, "ConstrainedImageDifferenceSOMetricBase");
00041 template <class TControlledMetric>
00042 class ConstrainedImageDifferenceSOMetricControllerBase : public ImageDifferenceSOMetricControllerBase<TControlledMetric>
00043 {
00044 public:
00045 DeclareParameterMacro(MaxConstraintPenalty);
00046 DeclareParameterMacro(FailureThreshold);
00047 DeclareParameterMacro(Constraints);
00048
00049 typedef TControlledMetric ComponentType;
00050 typedef ImageDifferenceSOMetricControllerBase<ComponentType> Superclass;
00051
00052 itkTypeMacro(ConstrainedImageDifferenceSOMetricControllerBase, ImageDifferenceSOMetricControllerBase);
00053
00054 protected:
00055 ConstrainedImageDifferenceSOMetricControllerBase()
00056 {
00057
00058 this->UpdateControllerID(ControllerID::ConstrainedSetupOptimizationMetricControllerBase);
00059 this->UpdateControllerID(ControllerID::ImageDifferenceSOMetricControllerBase);
00060 this->UpdateControllerID(ControllerID::ConstrainedImageDifferenceSOMetricControllerBase);
00061 this->m_Description = "Base class for image difference setup optimization metric which supports constraints.";
00062 };
00063
00064 virtual void GenerateProfile(CtrlProfile::ControllerProfile& profile,
00065 const SessionComponentCache* pComponentCache,
00066 bool bRegardOldSetup) const
00067 {
00068 Superclass::GenerateProfile(profile,pComponentCache,bRegardOldSetup);
00069
00070
00071 profile.Parameters().AddParameter(cParam_Constraints,CtrlProfile::Parameter::PVTString,cParamDsc_Constraints,4,"",-1);
00072 profile.Parameters().AddParameter(cParam_MaxConstraintPenalty,CtrlProfile::Parameter::PVTDouble,cParamDsc_MaxConstraintPenalty,1,"0");
00073 profile.Parameters().AddParameter(cParam_FailureThreshold,CtrlProfile::Parameter::PVTDouble,cParamDsc_FailureThreshold,1,"0.0");
00074 };
00075
00076 virtual void ActualizeMainComponent(ComponentType* pMainComponent,
00077 SessionComponentCache* pComponentCache,
00078 SessionInfo* pSessionInfo,
00079 const unsigned int& iActLevel) const
00080 {
00081 Superclass::ActualizeMainComponent(pMainComponent, pComponentCache,
00082 pSessionInfo, iActLevel);
00083
00084 double dMaxPenalty;
00085 double dThreshold;
00086
00087 Parameter::Pointer smpConstraints = SessionAccessor::GetParameter(pComponentCache,cParam_Constraints);
00088 if (smpConstraints.IsNull()) throwExceptionMacro("Missing parameter: " << cParam_Constraints);
00089
00090 for (unsigned int index = 0; index < smpConstraints->LayerCount(); index++)
00091 {
00092 int iParamID;
00093 std::string sRelationType;
00094 std::string sTerm;
00095 double dBarrierSize;
00096
00097 if (!smpConstraints->GetParameterValue(iParamID,0,index)) throwExceptionMacro("Faulty parameter; cannot retrieve parameter id. constraint #: " << index);
00098 if (!smpConstraints->GetParameterValue(sRelationType,1,index)) throwExceptionMacro("Faulty parameter; cannot retrieve relation type. constraint #: " << index);
00099 if (!smpConstraints->GetParameterValue(sTerm,2,index)) throwExceptionMacro("Faulty parameter; cannot retrieve constraint term. constraint #: " << index);
00100 if (!smpConstraints->GetParameterValue(dBarrierSize,3,index)) throwExceptionMacro("Faulty parameter; cannot retrieve barrier size. constraint #: " << index);
00101
00102 SetupParameterConstraint::Pointer smpNewCnstr = SetupParameterConstraint::New(iParamID,Convert::ToRelationType(sRelationType),sTerm);
00103 pMainComponent->AddConstraint(*(smpNewCnstr.GetPointer()),dBarrierSize);
00104 }
00105
00106 try
00107 {
00108 SessionAccessor::GetParameterValue(pComponentCache,cParam_MaxConstraintPenalty,dMaxPenalty);
00109 SessionAccessor::GetParameterValue(pComponentCache,cParam_FailureThreshold,dThreshold);
00110 }
00111 catchAllNPassMacro("Error while retrieving parameter values.");
00112
00113 pMainComponent->SetMaxConstraintPenalty(dMaxPenalty);
00114 pMainComponent->SetFailureThreshold(dThreshold);
00115 };
00116
00117 void
00118 SetStatisticEntryMainComponent(StatisticEntry& rStatisticEntry,
00119 ComponentType* pMainComponent,
00120 SessionComponentCache* pMainComponentCache,
00121 SessionInfo* pSessionInfo,
00122 StatisticDictionary& rDictionary) const
00123 {
00124 typename ComponentType::DecomposedMeasureType values = pMainComponent->GetCurrentDecomposedValue();
00125
00126 std::string sIDPath = pMainComponentCache->GetIDPath();
00127 StatisticValueDefinition* pEntry = rDictionary.GetValueDefinitionByName(sIDPath,"mean error");
00128
00129 if (!pEntry)
00130 {
00131 pEntry = rDictionary.AddValueDefinition(sIDPath,"mean error", "mean pixel difference");
00132 rDictionary.AddValueDefinition(sIDPath,"std error", "standard deviation of the pixel difference.");
00133 rDictionary.AddValueDefinition(sIDPath,"min error", "minimum pixel difference");
00134 rDictionary.AddValueDefinition(sIDPath,"max error", "maximum pixel difference");
00135 rDictionary.AddValueDefinition(sIDPath,"mean image error", "mean sum of differences in images)");
00136 rDictionary.AddValueDefinition(sIDPath,"std image error", "standard deviation of the image difference");
00137 rDictionary.AddValueDefinition(sIDPath,"min image error", "minimum image difference");
00138 rDictionary.AddValueDefinition(sIDPath,"max image error", "maximum image difference");
00139 rDictionary.AddValueDefinition(sIDPath,"failure", "number of failed evaluations");
00140 rDictionary.AddValueDefinition(sIDPath,"mean duration", "mean duration of an evaluation (tenth of a second).");
00141 rDictionary.AddValueDefinition(sIDPath,"std duration", "standard deviation of an evaluation (tenth of a second).");
00142 rDictionary.AddValueDefinition(sIDPath,"min duration", "minimum duration of an evaluation (tenth of a second).");
00143 rDictionary.AddValueDefinition(sIDPath,"max duration", "maximum duration of an evaluation (tenth of a second).");
00144
00145 for (unsigned int i = 0; i<values.Size()-13; i++)
00146 {
00147 rDictionary.AddValueDefinition(sIDPath,"constraint penalty #"+Convert::ToStr(i), "penalty of the constraint #"+Convert::ToStr(i));
00148 }
00149 }
00150
00151 for (unsigned int i = 0; i<values.Size(); i++)
00152 {
00153 rStatisticEntry.AddValue(Convert::ToStr(values[i]),pEntry->GetRefID()+i);
00154 }
00155 };
00156
00157 };
00158
00159 template <class TControlledMetric>
00160 const char* const ConstrainedImageDifferenceSOMetricControllerBase<TControlledMetric>::cParam_Constraints = "Constraints";
00161 template <class TControlledMetric>
00162 const char* const ConstrainedImageDifferenceSOMetricControllerBase<TControlledMetric>::cParamDsc_Constraints = "The constraints of the metric. First element is the ID of the constrained parameter, second value indicates the type of relation (0: equal; 1: lesser or equal; 2: greater or equal). The third value is the constraint term. The fourth value is the barrier size.\nParameter IDs, if used in the term have an underscore as prefix.\nExample: 1 | 2 | (_2 * 4) + _3\nBy this constrained parameter 1 should be greater or equal four times parameter 2 + parameter 3.";
00163
00164 template <class TControlledMetric>
00165 const char* const ConstrainedImageDifferenceSOMetricControllerBase<TControlledMetric>::cParam_MaxConstraintPenalty = "MaxConstraintPenalty";
00166 template <class TControlledMetric>
00167 const char* const ConstrainedImageDifferenceSOMetricControllerBase<TControlledMetric>::cParamDsc_MaxConstraintPenalty = "Maximum penalty the barrier function of a constraint can return. This value will be scaled be metric scales, if there is any defined for a constrained.";
00168
00169 template <class TControlledMetric>
00170 const char* const ConstrainedImageDifferenceSOMetricControllerBase<TControlledMetric>::cParam_FailureThreshold = "FailureThreshold";
00171 template <class TControlledMetric>
00172 const char* const ConstrainedImageDifferenceSOMetricControllerBase<TControlledMetric>::cParamDsc_FailureThreshold = "Threshold for the penalty computation, if the penalty is equal or above this threshold, the computation will be accounted as a failure. No evaluations of the adaptations will be done. A value of 0.0 or less deactivates the threshold.";
00173
00174
00183 freControllerIDMacro(ConstrainedImageDifference2DSOMetricController, "Constrained Image Difference 2D SO Metric");
00184 class ConstrainedImageDifference2DSOMetricController : public ConstrainedImageDifferenceSOMetricControllerBase< ConstrainedImageDifferenceSOMetric<2> >
00185 {
00186 public:
00187 typedef ConstrainedImageDifferenceSOMetric<2> ComponentType;
00188 typedef ConstrainedImageDifferenceSOMetricControllerBase<ComponentType> Superclass;
00189
00190 itkTypeMacro(ConstrainedConstrainedImageDifference2DSOMetricController, ConstrainedImageDifferenceSOMetricControllerBase);
00191
00192 ConstrainedImageDifference2DSOMetricController();
00193
00194 };
00195
00204 freControllerIDMacro(ConstrainedImageDifference3DSOMetricController, "Constrained Image Difference 3D SO Metric");
00205 class ConstrainedImageDifference3DSOMetricController : public ConstrainedImageDifferenceSOMetricControllerBase< ConstrainedImageDifferenceSOMetric<3> >
00206 {
00207 public:
00208 typedef ConstrainedImageDifferenceSOMetric<3> ComponentType;
00209 typedef ConstrainedImageDifferenceSOMetricControllerBase<ComponentType> Superclass;
00210
00211 itkTypeMacro(ConstrainedConstrainedImageDifference3DSOMetricController, ConstrainedImageDifferenceSOMetricControllerBase);
00212
00213 ConstrainedImageDifference3DSOMetricController();
00214
00215 };
00216
00217 }
00218
00219 #endif