diff --git a/Modules/ModelFit/include/mitkMVConstrainedCostFunctionDecorator.h b/Modules/ModelFit/include/mitkMVConstrainedCostFunctionDecorator.h index 71749c771a..db66410105 100644 --- a/Modules/ModelFit/include/mitkMVConstrainedCostFunctionDecorator.h +++ b/Modules/ModelFit/include/mitkMVConstrainedCostFunctionDecorator.h @@ -1,104 +1,104 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MV_CONSTRAINED_COST_FUNCTION_DECORATOR_H #define MV_CONSTRAINED_COST_FUNCTION_DECORATOR_H #include #include #include "MitkModelFitExports.h" namespace mitk { /** \class MVConstrainedCostFunctionDecorator * \brief This class is used to add constraints to any multi valued model fit cost function. * * MVConstrainedCostFunctionDecorator is used to extend a given cost function * with the functionality to regard given constraints for the measure. * To add this functionality to a cost function, instantiate the decorator, set * the wrapped cost function (that will be extended) and set a constraint checker * that defines the type of constraints.\n * The decorator has a failure threshold. An evaluation * can always be accounted as a failure if the sum of penalties given by the checker * is greater or equal to the threshold. If the evaluation is a failure the wrapped cost function * will not be evaluated. Otherwise the penalty will be added to every measure of the cost function. */ class MITKMODELFIT_EXPORT MVConstrainedCostFunctionDecorator : public mitk::MVModelFitCostFunction { public: typedef MVConstrainedCostFunctionDecorator Self; typedef mitk::MVModelFitCostFunction Superclass; typedef itk::SmartPointer< Self > Pointer; typedef itk::SmartPointer< const Self > ConstPointer; itkNewMacro(Self); typedef Superclass::SignalType SignalType; typedef ConstraintCheckerBase::PenaltyValueType PenaltyValueType; itkSetConstObjectMacro(WrappedCostFunction, MVModelFitCostFunction); itkGetConstObjectMacro(WrappedCostFunction, MVModelFitCostFunction); itkSetConstObjectMacro(ConstraintChecker, ConstraintCheckerBase); itkGetConstObjectMacro(ConstraintChecker, ConstraintCheckerBase); itkSetMacro(FailureThreshold, PenaltyValueType); itkGetConstMacro(FailureThreshold, PenaltyValueType); itkSetMacro(ActivateFailureThreshold, bool); itkGetConstMacro(ActivateFailureThreshold, bool); /**Returns the number of evaluations done by the cost function instance since creation.*/ itkGetConstMacro(EvaluationCount, unsigned int); /**Returns the ration between evaluations that were penaltized and all evaluation since creation of the instance. 0.0 means no evaluation was penalized; 1.0 all evaluations were. (evaluations that hit the failure threshold count as penalized too.)*/ double GetPenaltyRatio() const; /**Returns the ration between evaluations that where beyond the failure thershold and all evaluation since creation of the instance. 0.0 means no evaluation was a failure (but some may be penalized); 1.0 all evaluations were failures.*/ double GetFailureRatio() const; /**Returns the index of the first (in terms of index position) failed parameter in the last failed evaluation.*/ ParametersType::size_type GetFailedParameter() const; protected: virtual MeasureType CalcMeasure(const ParametersType ¶meters, const SignalType& signal) const; - MVConstrainedCostFunctionDecorator() : m_FailureThreshold(1e6), m_ActivateFailureThreshold(true), + MVConstrainedCostFunctionDecorator() : m_FailureThreshold(1e15), m_ActivateFailureThreshold(true), m_EvaluationCount(0), m_PenaltyCount(0), m_FailureCount(0), m_LastFailedParameter(-1) { } ~MVConstrainedCostFunctionDecorator(){} ConstraintCheckerBase::ConstPointer m_ConstraintChecker; MVModelFitCostFunction::ConstPointer m_WrappedCostFunction; PenaltyValueType m_FailureThreshold; bool m_ActivateFailureThreshold; mutable unsigned int m_EvaluationCount; mutable unsigned int m_PenaltyCount; mutable unsigned int m_FailureCount; mutable ParametersType::size_type m_LastFailedParameter; }; } #endif diff --git a/Modules/ModelFit/test/mitkMVConstrainedCostFunctionDecoratorTest.cpp b/Modules/ModelFit/test/mitkMVConstrainedCostFunctionDecoratorTest.cpp index ff4c43076c..f4c9251178 100644 --- a/Modules/ModelFit/test/mitkMVConstrainedCostFunctionDecoratorTest.cpp +++ b/Modules/ModelFit/test/mitkMVConstrainedCostFunctionDecoratorTest.cpp @@ -1,155 +1,157 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include #include "mitkTestingMacros.h" #include "mitkSimpleBarrierConstraintChecker.h" #include "mitkMVConstrainedCostFunctionDecorator.h" #include "mitkLinearModel.h" class TestCostFunction : public mitk::MVModelFitCostFunction { public: typedef TestCostFunction Self; typedef mitk::MVModelFitCostFunction Superclass; typedef itk::SmartPointer< Self > Pointer; typedef itk::SmartPointer< const Self > ConstPointer; itkNewMacro(Self); typedef Superclass::SignalType SignalType; mutable unsigned int m_calls; protected: virtual MeasureType CalcMeasure(const ParametersType ¶meters, const SignalType& signal) const { MeasureType result = signal; result[0] = parameters[0]; result[1] = parameters[1]; ++m_calls; return result; }; TestCostFunction() { m_calls = 0; } ~TestCostFunction(){} }; int mitkMVConstrainedCostFunctionDecoratorTest(int /*argc*/, char*[] /*argv[]*/) { MITK_TEST_BEGIN("mitkMVConstrainedCostFunctionDecoratorTest") mitk::SimpleBarrierConstraintChecker::Pointer checker = mitk::SimpleBarrierConstraintChecker::New(); mitk::MVConstrainedCostFunctionDecorator::Pointer decorator = mitk::MVConstrainedCostFunctionDecorator::New(); TestCostFunction::Pointer innerCF = TestCostFunction::New(); mitk::LinearModel::Pointer model = mitk::LinearModel::New(); decorator->SetModel(model); innerCF->SetModel(model); mitk::MVModelFitCostFunction::SignalType signal(5); signal.Fill(0.0); decorator->SetSample(signal); innerCF->SetSample(signal); mitk::LinearModel::TimeGridType grid(5); grid[0] = 0; grid[1] = 1; grid[2] = 2; grid[3] = 3; grid[4] = 4; model->SetTimeGrid(grid); mitk::SimpleBarrierConstraintChecker::ParametersType p1(2); p1[0] = 0; p1[1] = 50; mitk::SimpleBarrierConstraintChecker::ParametersType p2(2); p2[0] = 10; p2[1] = 50; mitk::SimpleBarrierConstraintChecker::ParametersType p3(2); p3[0] = 100; p3[1] = 50; mitk::SimpleBarrierConstraintChecker::ParametersType p4(2); p4[0] = 2; p4[1] = 50; checker->SetLowerBarrier(0,1,4); checker->SetUpperBarrier(0,100); + double defaultMaxPenalty = 1e15; + /////////////////////// //Tests //check freshly created checker; MITK_TEST_CONDITION_REQUIRED(decorator->GetWrappedCostFunction() == NULL, "Testing GetWrappedCostFunction for new decorator."); MITK_TEST_CONDITION_REQUIRED(decorator->GetConstraintChecker() == NULL, "Testing GetWrappedCostFunction for new decorator."); - MITK_TEST_CONDITION_REQUIRED(decorator->GetFailureThreshold() == 1e6, + MITK_TEST_CONDITION_REQUIRED(decorator->GetFailureThreshold() == defaultMaxPenalty, "Testing GetWrappedCostFunction for new decorator."); MITK_TEST_FOR_EXCEPTION(mitk::Exception, decorator->GetValue(p1)); decorator->SetWrappedCostFunction(innerCF); MITK_TEST_FOR_EXCEPTION(mitk::Exception, decorator->GetValue(p1)); decorator->SetWrappedCostFunction(NULL); decorator->SetConstraintChecker(checker); MITK_TEST_FOR_EXCEPTION(mitk::Exception, decorator->GetValue(p1)); decorator->SetWrappedCostFunction(innerCF); mitk::MVModelFitCostFunction::MeasureType measure = decorator->GetValue(p1); - MITK_TEST_CONDITION_REQUIRED(measure[0] == 1e6, "Testing measure 1 with parameters p1."); - MITK_TEST_CONDITION_REQUIRED(measure[1] == 1e6, "Testing measure 2 with parameters p1."); - MITK_TEST_CONDITION_REQUIRED(measure[2] == 1e6, "Testing measure 3 with parameters p1."); - MITK_TEST_CONDITION_REQUIRED(measure[3] == 1e6, "Testing measure 3 with parameters p1."); - MITK_TEST_CONDITION_REQUIRED(measure[4] == 1e6, "Testing measure 3 with parameters p1."); + MITK_TEST_CONDITION_REQUIRED(measure[0] == defaultMaxPenalty, "Testing measure 1 with parameters p1."); + MITK_TEST_CONDITION_REQUIRED(measure[1] == defaultMaxPenalty, "Testing measure 2 with parameters p1."); + MITK_TEST_CONDITION_REQUIRED(measure[2] == defaultMaxPenalty, "Testing measure 3 with parameters p1."); + MITK_TEST_CONDITION_REQUIRED(measure[3] == defaultMaxPenalty, "Testing measure 3 with parameters p1."); + MITK_TEST_CONDITION_REQUIRED(measure[4] == defaultMaxPenalty, "Testing measure 3 with parameters p1."); MITK_TEST_CONDITION_REQUIRED(innerCF->m_calls == 0, "Checking calls with parameters p1."); measure = decorator->GetValue(p2); MITK_TEST_CONDITION_REQUIRED(measure[0] == 10, "Testing measure 1 with parameters p2."); MITK_TEST_CONDITION_REQUIRED(measure[1] == 50, "Testing measure 2 with parameters p2."); MITK_TEST_CONDITION_REQUIRED(measure[2] == 70, "Testing measure 3 with parameters p2."); MITK_TEST_CONDITION_REQUIRED(innerCF->m_calls == 1, "Checking calls with parameters p2."); measure = decorator->GetValue(p3); - MITK_TEST_CONDITION_REQUIRED(measure[0] == 1e6, "Testing measure 1 with parameters p3."); - MITK_TEST_CONDITION_REQUIRED(measure[1] == 1e6, "Testing measure 2 with parameters p3."); - MITK_TEST_CONDITION_REQUIRED(measure[2] == 1e6, "Testing measure 3 with parameters p3."); + MITK_TEST_CONDITION_REQUIRED(measure[0] == defaultMaxPenalty, "Testing measure 1 with parameters p3."); + MITK_TEST_CONDITION_REQUIRED(measure[1] == defaultMaxPenalty, "Testing measure 2 with parameters p3."); + MITK_TEST_CONDITION_REQUIRED(measure[2] == defaultMaxPenalty, "Testing measure 3 with parameters p3."); MITK_TEST_CONDITION_REQUIRED(innerCF->m_calls == 1, "Checking calls with parameters p3."); decorator->SetActivateFailureThreshold(false); measure = decorator->GetValue(p3); - MITK_TEST_CONDITION_REQUIRED(measure[0] == 100+1e6, "Testing measure 1 with parameters p3 (deactiveated threshold)."); - MITK_TEST_CONDITION_REQUIRED(measure[1] == 50+1e6, "Testing measure 2 with parameters p3 (deactiveated threshold)."); - MITK_TEST_CONDITION_REQUIRED(measure[2] == 250+1e6, "Testing measure 3 with parameters p3 (deactiveated threshold)."); + MITK_TEST_CONDITION_REQUIRED(measure[0] == 100+defaultMaxPenalty, "Testing measure 1 with parameters p3 (deactiveated threshold)."); + MITK_TEST_CONDITION_REQUIRED(measure[1] == 50+defaultMaxPenalty, "Testing measure 2 with parameters p3 (deactiveated threshold)."); + MITK_TEST_CONDITION_REQUIRED(measure[2] == 250+defaultMaxPenalty, "Testing measure 3 with parameters p3 (deactiveated threshold)."); MITK_TEST_CONDITION_REQUIRED(innerCF->m_calls ==2, "Checking calls with parameters p3 (deactiveated threshold)."); decorator->SetActivateFailureThreshold(true); measure = decorator->GetValue(p4); MITK_TEST_CONDITION_REQUIRED(measure[0] == 2+(-1*log(1/4.)), "Testing measure 1 with parameters p4."); MITK_TEST_CONDITION_REQUIRED(measure[1] == 50+(-1*log(1/4.)), "Testing measure 2 with parameters p4."); MITK_TEST_CONDITION_REQUIRED(measure[2] == 54+(-1*log(1/4.)), "Testing measure 3 with parameters p4."); MITK_TEST_CONDITION_REQUIRED(innerCF->m_calls == 3, "Checking calls with parameters p4."); MITK_TEST_END() } diff --git a/Modules/ModelFit/test/mitkModelFitInfoTest.cpp b/Modules/ModelFit/test/mitkModelFitInfoTest.cpp index f1ccbe3d6b..8dd0c2c646 100644 --- a/Modules/ModelFit/test/mitkModelFitInfoTest.cpp +++ b/Modules/ModelFit/test/mitkModelFitInfoTest.cpp @@ -1,262 +1,266 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include #include "mitkTestingMacros.h" #include "mitkProperties.h" #include "mitkStandaloneDataStorage.h" #include "mitkModelFitInfo.h" #include "mitkModelFitConstants.h" #include "mitkModelFitException.h" mitk::DataNode::Pointer generateModelFitTestNode() { mitk::DataNode::Pointer node = mitk::DataNode::New(); node->SetName("Param1"); - node->SetStringProperty("modelfit.testEmpty", ""); - node->SetStringProperty("modelfit.testValid", "test"); - + auto testImage = mitk::Image::New(); + node->SetData(testImage); + testImage->SetProperty("modelfit.testEmpty", mitk::StringProperty::New("")); + testImage->SetProperty("modelfit.testValid", mitk::StringProperty::New("test")); mitk::EnsureModelFitUID(node); - node->SetStringProperty(mitk::ModelFitConstants::FIT_UID_PROPERTY_NAME().c_str(),"Fit1"); - node->SetStringProperty(mitk::ModelFitConstants::FIT_TYPE_PROPERTY_NAME().c_str(),mitk::ModelFitConstants::FIT_TYPE_VALUE_PIXELBASED().c_str()); - node->SetStringProperty(mitk::ModelFitConstants::FIT_INPUT_IMAGEUID_PROPERTY_NAME().c_str(),"input UID"); - node->SetStringProperty(mitk::ModelFitConstants::MODEL_TYPE_PROPERTY_NAME().c_str(),"TestModels"); - node->SetStringProperty(mitk::ModelFitConstants::MODEL_NAME_PROPERTY_NAME().c_str(),"TestModel_1"); - node->SetStringProperty(mitk::ModelFitConstants::MODEL_FUNCTION_PROPERTY_NAME().c_str(),""); - node->SetStringProperty(mitk::ModelFitConstants::MODEL_FUNCTION_CLASS_PROPERTY_NAME().c_str(),"ModelClass"); - node->SetStringProperty(mitk::ModelFitConstants::MODEL_X_PROPERTY_NAME().c_str(),"myX"); + testImage->SetProperty(mitk::ModelFitConstants::FIT_UID_PROPERTY_NAME().c_str(), mitk::StringProperty::New("Fit1")); + testImage->SetProperty(mitk::ModelFitConstants::FIT_TYPE_PROPERTY_NAME().c_str(), mitk::StringProperty::New(mitk::ModelFitConstants::FIT_TYPE_VALUE_PIXELBASED().c_str())); + testImage->SetProperty(mitk::ModelFitConstants::FIT_INPUT_IMAGEUID_PROPERTY_NAME().c_str(), mitk::StringProperty::New("input UID")); + + testImage->SetProperty(mitk::ModelFitConstants::MODEL_TYPE_PROPERTY_NAME().c_str(), mitk::StringProperty::New("TestModels")); + testImage->SetProperty(mitk::ModelFitConstants::MODEL_NAME_PROPERTY_NAME().c_str(), mitk::StringProperty::New("TestModel_1")); + testImage->SetProperty(mitk::ModelFitConstants::MODEL_FUNCTION_PROPERTY_NAME().c_str(), mitk::StringProperty::New("")); + testImage->SetProperty(mitk::ModelFitConstants::MODEL_FUNCTION_CLASS_PROPERTY_NAME().c_str(), mitk::StringProperty::New("ModelClass")); + testImage->SetProperty(mitk::ModelFitConstants::MODEL_X_PROPERTY_NAME().c_str(), mitk::StringProperty::New("myX")); - node->SetStringProperty(mitk::ModelFitConstants::XAXIS_NAME_PROPERTY_NAME().c_str(),mitk::ModelFitConstants::XAXIS_NAME_VALUE_DEFAULT().c_str()); - node->SetStringProperty(mitk::ModelFitConstants::XAXIS_UNIT_PROPERTY_NAME().c_str(),"h"); - node->SetStringProperty(mitk::ModelFitConstants::YAXIS_NAME_PROPERTY_NAME().c_str(),mitk::ModelFitConstants::YAXIS_NAME_VALUE_DEFAULT().c_str()); - node->SetStringProperty(mitk::ModelFitConstants::YAXIS_UNIT_PROPERTY_NAME().c_str(),"kg"); + testImage->SetProperty(mitk::ModelFitConstants::XAXIS_NAME_PROPERTY_NAME().c_str(), mitk::StringProperty::New(mitk::ModelFitConstants::XAXIS_NAME_VALUE_DEFAULT().c_str())); + testImage->SetProperty(mitk::ModelFitConstants::XAXIS_UNIT_PROPERTY_NAME().c_str(), mitk::StringProperty::New("h")); + testImage->SetProperty(mitk::ModelFitConstants::YAXIS_NAME_PROPERTY_NAME().c_str(), mitk::StringProperty::New(mitk::ModelFitConstants::YAXIS_NAME_VALUE_DEFAULT().c_str())); + testImage->SetProperty(mitk::ModelFitConstants::YAXIS_UNIT_PROPERTY_NAME().c_str(), mitk::StringProperty::New("kg")); return node; } mitk::StandaloneDataStorage::Pointer generateModelFitTestStorage() { mitk::StandaloneDataStorage::Pointer storage = mitk::StandaloneDataStorage::New(); //create input node mitk::DataNode::Pointer inputNode = mitk::DataNode::New(); inputNode->SetName("Input"); mitk::Image::Pointer image = mitk::Image::New(); inputNode->SetData(image); mitk::NodeUIDType inputUID = mitk::EnsureModelFitUID(inputNode); storage->Add(inputNode); mitk::DataStorage::SetOfObjects::Pointer parents = mitk::DataStorage::SetOfObjects::New(); parents->push_back(inputNode); //create first result for Fit1 mitk::DataNode::Pointer node1 = mitk::DataNode::New(); mitk::Image::Pointer paramImage = mitk::Image::New(); node1->SetData(paramImage); node1->SetName("Param1"); mitk::EnsureModelFitUID(node1); - node1->SetStringProperty(mitk::ModelFitConstants::FIT_UID_PROPERTY_NAME().c_str(),"Fit1"); - node1->SetStringProperty(mitk::ModelFitConstants::FIT_TYPE_PROPERTY_NAME().c_str(),mitk::ModelFitConstants::FIT_TYPE_VALUE_PIXELBASED().c_str()); - node1->SetStringProperty(mitk::ModelFitConstants::FIT_INPUT_IMAGEUID_PROPERTY_NAME().c_str(),inputUID.c_str()); + paramImage->SetProperty(mitk::ModelFitConstants::FIT_UID_PROPERTY_NAME().c_str(), mitk::StringProperty::New("Fit1")); + paramImage->SetProperty(mitk::ModelFitConstants::FIT_TYPE_PROPERTY_NAME().c_str(), mitk::StringProperty::New(mitk::ModelFitConstants::FIT_TYPE_VALUE_PIXELBASED().c_str())); + paramImage->SetProperty(mitk::ModelFitConstants::FIT_INPUT_IMAGEUID_PROPERTY_NAME().c_str(), mitk::StringProperty::New(inputUID.c_str())); - node1->SetStringProperty(mitk::ModelFitConstants::MODEL_TYPE_PROPERTY_NAME().c_str(),"TestModels"); - node1->SetStringProperty(mitk::ModelFitConstants::MODEL_NAME_PROPERTY_NAME().c_str(),"TestModel_1"); - node1->SetStringProperty(mitk::ModelFitConstants::MODEL_FUNCTION_PROPERTY_NAME().c_str(),""); - node1->SetStringProperty(mitk::ModelFitConstants::MODEL_FUNCTION_CLASS_PROPERTY_NAME().c_str(),"ModelClass"); - node1->SetStringProperty(mitk::ModelFitConstants::MODEL_X_PROPERTY_NAME().c_str(),"myX"); + paramImage->SetProperty(mitk::ModelFitConstants::MODEL_TYPE_PROPERTY_NAME().c_str(), mitk::StringProperty::New("TestModels")); + paramImage->SetProperty(mitk::ModelFitConstants::MODEL_NAME_PROPERTY_NAME().c_str(), mitk::StringProperty::New("TestModel_1")); + paramImage->SetProperty(mitk::ModelFitConstants::MODEL_FUNCTION_PROPERTY_NAME().c_str(), mitk::StringProperty::New("")); + paramImage->SetProperty(mitk::ModelFitConstants::MODEL_FUNCTION_CLASS_PROPERTY_NAME().c_str(), mitk::StringProperty::New("ModelClass")); + paramImage->SetProperty(mitk::ModelFitConstants::MODEL_X_PROPERTY_NAME().c_str(), mitk::StringProperty::New("myX")); - node1->SetStringProperty(mitk::ModelFitConstants::XAXIS_NAME_PROPERTY_NAME().c_str(),mitk::ModelFitConstants::XAXIS_NAME_VALUE_DEFAULT().c_str()); - node1->SetStringProperty(mitk::ModelFitConstants::XAXIS_UNIT_PROPERTY_NAME().c_str(),"h"); - node1->SetStringProperty(mitk::ModelFitConstants::YAXIS_NAME_PROPERTY_NAME().c_str(),mitk::ModelFitConstants::YAXIS_NAME_VALUE_DEFAULT().c_str()); - node1->SetStringProperty(mitk::ModelFitConstants::YAXIS_UNIT_PROPERTY_NAME().c_str(),"kg"); + paramImage->SetProperty(mitk::ModelFitConstants::XAXIS_NAME_PROPERTY_NAME().c_str(), mitk::StringProperty::New(mitk::ModelFitConstants::XAXIS_NAME_VALUE_DEFAULT().c_str())); + paramImage->SetProperty(mitk::ModelFitConstants::XAXIS_UNIT_PROPERTY_NAME().c_str(), mitk::StringProperty::New("h")); + paramImage->SetProperty(mitk::ModelFitConstants::YAXIS_NAME_PROPERTY_NAME().c_str(), mitk::StringProperty::New(mitk::ModelFitConstants::YAXIS_NAME_VALUE_DEFAULT().c_str())); + paramImage->SetProperty(mitk::ModelFitConstants::YAXIS_UNIT_PROPERTY_NAME().c_str(), mitk::StringProperty::New("kg")); - node1->SetStringProperty(mitk::ModelFitConstants::PARAMETER_NAME_PROPERTY_NAME().c_str(),"Param1"); - node1->SetStringProperty(mitk::ModelFitConstants::PARAMETER_UNIT_PROPERTY_NAME().c_str(),"b"); - node1->SetStringProperty(mitk::ModelFitConstants::PARAMETER_TYPE_PROPERTY_NAME().c_str(),mitk::ModelFitConstants::PARAMETER_TYPE_VALUE_PARAMETER().c_str()); + paramImage->SetProperty(mitk::ModelFitConstants::PARAMETER_NAME_PROPERTY_NAME().c_str(), mitk::StringProperty::New("Param1")); + paramImage->SetProperty(mitk::ModelFitConstants::PARAMETER_UNIT_PROPERTY_NAME().c_str(), mitk::StringProperty::New("b")); + paramImage->SetProperty(mitk::ModelFitConstants::PARAMETER_TYPE_PROPERTY_NAME().c_str(), mitk::StringProperty::New(mitk::ModelFitConstants::PARAMETER_TYPE_VALUE_PARAMETER().c_str())); storage->Add(node1,parents); //create second result for Fit1 mitk::DataNode::Pointer node2 = mitk::DataNode::New(); node2->SetName("Param2"); mitk::Image::Pointer paramImage2 = mitk::Image::New(); node2->SetData(paramImage2); mitk::EnsureModelFitUID(node2); - node2->SetStringProperty(mitk::ModelFitConstants::FIT_UID_PROPERTY_NAME().c_str(),"Fit1"); - node2->SetStringProperty(mitk::ModelFitConstants::FIT_TYPE_PROPERTY_NAME().c_str(),mitk::ModelFitConstants::FIT_TYPE_VALUE_PIXELBASED().c_str()); - node2->SetStringProperty(mitk::ModelFitConstants::FIT_INPUT_IMAGEUID_PROPERTY_NAME().c_str(),inputUID.c_str()); + paramImage2->SetProperty(mitk::ModelFitConstants::FIT_UID_PROPERTY_NAME().c_str(), mitk::StringProperty::New("Fit1")); + paramImage2->SetProperty(mitk::ModelFitConstants::FIT_TYPE_PROPERTY_NAME().c_str(), mitk::StringProperty::New(mitk::ModelFitConstants::FIT_TYPE_VALUE_PIXELBASED().c_str())); + paramImage2->SetProperty(mitk::ModelFitConstants::FIT_INPUT_IMAGEUID_PROPERTY_NAME().c_str(), mitk::StringProperty::New(inputUID.c_str())); - node2->SetStringProperty(mitk::ModelFitConstants::MODEL_TYPE_PROPERTY_NAME().c_str(),"TestModels"); - node2->SetStringProperty(mitk::ModelFitConstants::MODEL_NAME_PROPERTY_NAME().c_str(),"TestModel_1"); - node2->SetStringProperty(mitk::ModelFitConstants::MODEL_FUNCTION_PROPERTY_NAME().c_str(),""); - node2->SetStringProperty(mitk::ModelFitConstants::MODEL_FUNCTION_CLASS_PROPERTY_NAME().c_str(),"ModelClass"); - node2->SetStringProperty(mitk::ModelFitConstants::MODEL_X_PROPERTY_NAME().c_str(),"myX"); + paramImage2->SetProperty(mitk::ModelFitConstants::MODEL_TYPE_PROPERTY_NAME().c_str(), mitk::StringProperty::New("TestModels")); + paramImage2->SetProperty(mitk::ModelFitConstants::MODEL_NAME_PROPERTY_NAME().c_str(), mitk::StringProperty::New("TestModel_1")); + paramImage2->SetProperty(mitk::ModelFitConstants::MODEL_FUNCTION_PROPERTY_NAME().c_str(), mitk::StringProperty::New("")); + paramImage2->SetProperty(mitk::ModelFitConstants::MODEL_FUNCTION_CLASS_PROPERTY_NAME().c_str(), mitk::StringProperty::New("ModelClass")); + paramImage2->SetProperty(mitk::ModelFitConstants::MODEL_X_PROPERTY_NAME().c_str(), mitk::StringProperty::New("myX")); - node2->SetStringProperty(mitk::ModelFitConstants::XAXIS_NAME_PROPERTY_NAME().c_str(),mitk::ModelFitConstants::XAXIS_NAME_VALUE_DEFAULT().c_str()); - node2->SetStringProperty(mitk::ModelFitConstants::XAXIS_UNIT_PROPERTY_NAME().c_str(),"h"); - node2->SetStringProperty(mitk::ModelFitConstants::YAXIS_NAME_PROPERTY_NAME().c_str(),mitk::ModelFitConstants::YAXIS_NAME_VALUE_DEFAULT().c_str()); - node2->SetStringProperty(mitk::ModelFitConstants::YAXIS_UNIT_PROPERTY_NAME().c_str(),"kg"); + paramImage2->SetProperty(mitk::ModelFitConstants::XAXIS_NAME_PROPERTY_NAME().c_str(), mitk::StringProperty::New(mitk::ModelFitConstants::XAXIS_NAME_VALUE_DEFAULT().c_str())); + paramImage2->SetProperty(mitk::ModelFitConstants::XAXIS_UNIT_PROPERTY_NAME().c_str(), mitk::StringProperty::New("h")); + paramImage2->SetProperty(mitk::ModelFitConstants::YAXIS_NAME_PROPERTY_NAME().c_str(), mitk::StringProperty::New(mitk::ModelFitConstants::YAXIS_NAME_VALUE_DEFAULT().c_str())); + paramImage2->SetProperty(mitk::ModelFitConstants::YAXIS_UNIT_PROPERTY_NAME().c_str(), mitk::StringProperty::New("kg")); - node2->SetStringProperty(mitk::ModelFitConstants::PARAMETER_NAME_PROPERTY_NAME().c_str(),"Param2"); - node2->SetStringProperty(mitk::ModelFitConstants::PARAMETER_UNIT_PROPERTY_NAME().c_str(),"a"); - node2->SetStringProperty(mitk::ModelFitConstants::PARAMETER_TYPE_PROPERTY_NAME().c_str(),mitk::ModelFitConstants::PARAMETER_TYPE_VALUE_DERIVED_PARAMETER().c_str()); + paramImage2->SetProperty(mitk::ModelFitConstants::PARAMETER_NAME_PROPERTY_NAME().c_str(), mitk::StringProperty::New("Param2")); + paramImage2->SetProperty(mitk::ModelFitConstants::PARAMETER_UNIT_PROPERTY_NAME().c_str(), mitk::StringProperty::New("a")); + paramImage2->SetProperty(mitk::ModelFitConstants::PARAMETER_TYPE_PROPERTY_NAME().c_str(), mitk::StringProperty::New(mitk::ModelFitConstants::PARAMETER_TYPE_VALUE_DERIVED_PARAMETER().c_str())); storage->Add(node2, parents); //create result for Fit 2 mitk::DataNode::Pointer node3 = mitk::DataNode::New(); node3->SetName("Param_Other"); + mitk::Image::Pointer paramImage3 = mitk::Image::New(); + node3->SetData(paramImage3); mitk::EnsureModelFitUID(node3); - node3->SetStringProperty(mitk::ModelFitConstants::FIT_UID_PROPERTY_NAME().c_str(),"Fit2"); - node3->SetStringProperty(mitk::ModelFitConstants::FIT_TYPE_PROPERTY_NAME().c_str(),mitk::ModelFitConstants::FIT_TYPE_VALUE_PIXELBASED().c_str()); - node3->SetStringProperty(mitk::ModelFitConstants::FIT_INPUT_IMAGEUID_PROPERTY_NAME().c_str(),inputUID.c_str()); + paramImage3->SetProperty(mitk::ModelFitConstants::FIT_UID_PROPERTY_NAME().c_str(), mitk::StringProperty::New("Fit2")); + paramImage3->SetProperty(mitk::ModelFitConstants::FIT_TYPE_PROPERTY_NAME().c_str(), mitk::StringProperty::New(mitk::ModelFitConstants::FIT_TYPE_VALUE_PIXELBASED().c_str())); + paramImage3->SetProperty(mitk::ModelFitConstants::FIT_INPUT_IMAGEUID_PROPERTY_NAME().c_str(), mitk::StringProperty::New(inputUID.c_str())); - node3->SetStringProperty(mitk::ModelFitConstants::MODEL_TYPE_PROPERTY_NAME().c_str(),"TestModels"); - node3->SetStringProperty(mitk::ModelFitConstants::MODEL_NAME_PROPERTY_NAME().c_str(),"TestModel_2"); - node3->SetStringProperty(mitk::ModelFitConstants::MODEL_FUNCTION_PROPERTY_NAME().c_str(),""); - node3->SetStringProperty(mitk::ModelFitConstants::MODEL_FUNCTION_CLASS_PROPERTY_NAME().c_str(),"ModelClass_B"); + paramImage3->SetProperty(mitk::ModelFitConstants::MODEL_TYPE_PROPERTY_NAME().c_str(), mitk::StringProperty::New("TestModels")); + paramImage3->SetProperty(mitk::ModelFitConstants::MODEL_NAME_PROPERTY_NAME().c_str(), mitk::StringProperty::New("TestModel_2")); + paramImage3->SetProperty(mitk::ModelFitConstants::MODEL_FUNCTION_PROPERTY_NAME().c_str(), mitk::StringProperty::New("")); + paramImage3->SetProperty(mitk::ModelFitConstants::MODEL_FUNCTION_CLASS_PROPERTY_NAME().c_str(), mitk::StringProperty::New("ModelClass_B")); - node3->SetStringProperty(mitk::ModelFitConstants::PARAMETER_NAME_PROPERTY_NAME().c_str(),"Param_Other"); - node3->SetStringProperty(mitk::ModelFitConstants::PARAMETER_UNIT_PROPERTY_NAME().c_str(),"a"); + paramImage3->SetProperty(mitk::ModelFitConstants::PARAMETER_NAME_PROPERTY_NAME().c_str(), mitk::StringProperty::New("Param_Other")); + paramImage3->SetProperty(mitk::ModelFitConstants::PARAMETER_UNIT_PROPERTY_NAME().c_str(), mitk::StringProperty::New("a")); storage->Add(node3, parents); return storage; } int mitkModelFitInfoTest(int /*argc*/, char*[] /*argv[]*/) { MITK_TEST_BEGIN("mitkModelFitTest") mitk::modelFit::Parameter::Pointer p = mitk::modelFit::Parameter::New(); p->name = "p"; mitk::modelFit::ModelFitInfo::Pointer fit = mitk::modelFit::ModelFitInfo::New(); fit->AddParameter(p); MITK_TEST_CONDITION_REQUIRED(fit->GetParameters().size() == 1, "Testing if AddParameter successfully adds a parameter."); mitk::modelFit::Parameter::ConstPointer resultParam = fit->GetParameter("test", mitk::modelFit::Parameter::ParameterType); MITK_TEST_CONDITION_REQUIRED(resultParam.IsNull(), "Testing if GetParameter returns NULL for wrong parameter."); resultParam = fit->GetParameter("p", mitk::modelFit::Parameter::ParameterType); MITK_TEST_CONDITION_REQUIRED(resultParam == p, "Testing if GetParameter returns the correct parameter."); p->type = mitk::modelFit::Parameter::CriterionType; resultParam = fit->GetParameter("p", mitk::modelFit::Parameter::CriterionType); MITK_TEST_CONDITION_REQUIRED(resultParam == p, "Testing if GetParameter returns the correct parameter with a " << "non-default type."); fit->DeleteParameter("test", mitk::modelFit::Parameter::CriterionType); MITK_TEST_CONDITION_REQUIRED(fit->GetParameters().size() == 1, "Testing if DeleteParameter fails for wrong parameter."); fit->DeleteParameter("p", mitk::modelFit::Parameter::CriterionType); MITK_TEST_CONDITION_REQUIRED(fit->GetParameters().size() == 0, "Testing if DeleteParameter successfully removes a parameter."); mitk::DataNode::Pointer node = generateModelFitTestNode(); mitk::DataNode::Pointer invalideNode = mitk::DataNode::New(); MITK_TEST_FOR_EXCEPTION(mitk::modelFit::ModelFitException, mitk::modelFit::GetMandatoryProperty(node.GetPointer(), "modelfit.testInvalid")); MITK_TEST_FOR_EXCEPTION(mitk::modelFit::ModelFitException, mitk::modelFit::GetMandatoryProperty(node.GetPointer(), "modelfit.testEmpty")); MITK_TEST_CONDITION_REQUIRED(mitk::modelFit::GetMandatoryProperty(node.GetPointer(), "modelfit.testValid") == "test", "Testing if GetMandatoryProperty returns the correct value."); mitk::StandaloneDataStorage::Pointer storage = generateModelFitTestStorage(); MITK_TEST_CONDITION_REQUIRED(mitk::modelFit::CreateFitInfoFromNode("Fit1",NULL).IsNull(), "Testing if CreateFitInfoFromNode returns NULL for invalid node."); MITK_TEST_CONDITION_REQUIRED(mitk::modelFit::CreateFitInfoFromNode("invalide_UID",storage).IsNull(), "Testing if CreateFitInfoFromNode returns NULL for node with " << "missing properties."); mitk::DataNode::Pointer testNode = storage->GetNamedNode("Param1"); mitk::modelFit::ModelFitInfo::Pointer resultFit = mitk::modelFit::CreateFitInfoFromNode("Fit1", storage); MITK_TEST_CONDITION_REQUIRED(resultFit.IsNotNull(), "Testing if CreateFitInfoFromNode returns a valid model fit info."); MITK_TEST_CONDITION_REQUIRED(resultFit->fitType == mitk::ModelFitConstants::FIT_TYPE_VALUE_PIXELBASED() && resultFit->uid == "Fit1" && resultFit->modelType == "TestModels" && resultFit->modelName == "TestModel_1" && resultFit->function == ""&& resultFit->functionClassID == "ModelClass" && resultFit->x == "myX" && resultFit->xAxisName == mitk::ModelFitConstants::XAXIS_NAME_VALUE_DEFAULT() && resultFit->xAxisUnit == "h" && resultFit->yAxisName == mitk::ModelFitConstants::YAXIS_NAME_VALUE_DEFAULT() && resultFit->yAxisUnit == "kg" && resultFit->GetParameters().size() == 2, "Testing if CreateFitInfoFromNode creates a fit with correct attributes."); mitk::modelFit::Parameter::ConstPointer param = resultFit->GetParameter("Param1",mitk::modelFit::Parameter::ParameterType); MITK_TEST_CONDITION_REQUIRED(param.IsNotNull(), "Testing if param 1 exists."); MITK_TEST_CONDITION_REQUIRED(param->name == "Param1" && param->unit == "b" && param->image == testNode->GetData(), "Testing if param 1 is configured correctly."); mitk::modelFit::Parameter::ConstPointer param2 = resultFit->GetParameter("Param2",mitk::modelFit::Parameter::DerivedType); MITK_TEST_CONDITION_REQUIRED(param2.IsNotNull(), "Testing if param 2 exists."); testNode = storage->GetNamedNode("Param2"); MITK_TEST_CONDITION_REQUIRED(param2->name == "Param2" && param2->unit == "a" && param2->image == testNode->GetData(), "Testing if param 2 is configured correctly."); MITK_TEST_CONDITION_REQUIRED(mitk::modelFit::GetNodesOfFit(resultFit->uid,storage)->Size() == 2, "Testing if GetNodesOfFit works correctly for Fit1"); MITK_TEST_CONDITION_REQUIRED(mitk::modelFit::GetNodesOfFit("Fit2",storage)->Size() == 1, "Testing if GetNodesOfFit works correctly for Fit1"); MITK_TEST_CONDITION_REQUIRED(mitk::modelFit::GetNodesOfFit("unkown_fit",storage)->Size() == 0, "Testing if GetNodesOfFit works correctly for unkown fits."); MITK_TEST_CONDITION_REQUIRED(mitk::modelFit::GetNodesOfFit("unkown_fit",NULL).IsNull(), "Testing if GetNodesOfFit works correctly for illegal calls."); testNode = storage->GetNamedNode("Input"); mitk::modelFit::NodeUIDSetType uidSet = mitk::modelFit::GetFitUIDsOfNode(testNode,storage); MITK_TEST_CONDITION_REQUIRED(uidSet.size() == 2 && uidSet.find("Fit1")!=uidSet.end() && uidSet.find("Fit2")!=uidSet.end(), "Testing if GetFitUIDsOfNode works correctly."); uidSet = mitk::modelFit::GetFitUIDsOfNode(NULL,storage); MITK_TEST_CONDITION_REQUIRED(uidSet.size() == 0, "Testing if GetFitUIDsOfNode works correctly with invalid node."); uidSet = mitk::modelFit::GetFitUIDsOfNode(testNode,NULL); MITK_TEST_CONDITION_REQUIRED(uidSet.size() == 0, "Testing if GetFitUIDsOfNode works correctly with invalid storage."); MITK_TEST_END() } diff --git a/Modules/ModelFit/test/mitkModelFitUIDHelperTest.cpp b/Modules/ModelFit/test/mitkModelFitUIDHelperTest.cpp index 9e3366f9e3..8eb8e2caae 100644 --- a/Modules/ModelFit/test/mitkModelFitUIDHelperTest.cpp +++ b/Modules/ModelFit/test/mitkModelFitUIDHelperTest.cpp @@ -1,72 +1,75 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include #include "mitkTestingMacros.h" #include "mitkDataNode.h" +#include "mitkImage.h" #include "mitkStandaloneDataStorage.h" #include "mitkModelFitUIDHelper.h" int mitkModelFitUIDHelperTest(int /*argc*/, char*[] /*argv[]*/) { MITK_TEST_BEGIN("mitkModelFitUIDHelperTest") mitk::DataNode::Pointer node1 = mitk::DataNode::New(); + node1->SetData(mitk::Image::New()); mitk::DataNode::Pointer node2 = mitk::DataNode::New(); + node2->SetData(mitk::Image::New()); mitk::DataNode* nullNode = nullptr; mitk::BaseData* nullData = nullptr; MITK_TEST_FOR_EXCEPTION(mitk::Exception, mitk::EnsureModelFitUID(nullNode)); MITK_TEST_CONDITION_REQUIRED(mitk::CheckModelFitUID(nullNode,"testUID") == false, "Testing if CheckModelFitUID fails of null pointer is passed."); MITK_TEST_FOR_EXCEPTION(mitk::Exception, mitk::EnsureModelFitUID(nullData)); MITK_TEST_CONDITION_REQUIRED(mitk::CheckModelFitUID(nullData, "testUID") == false, "Testing if CheckModelFitUID fails of null pointer is passed."); mitk::NodeUIDType uid = mitk::EnsureModelFitUID(node1); MITK_TEST_CONDITION_REQUIRED(mitk::CheckModelFitUID(node1,"testUID") == false, "Testing if CheckModelFitUID fails of wrong UID is passed."); MITK_TEST_CONDITION_REQUIRED(mitk::CheckModelFitUID(node1, uid) == true, "Testing if CheckModelFitUID succeeds if correct UID is passed."); mitk::NodeUIDType uid2ndCall = mitk::EnsureModelFitUID(node1); MITK_TEST_CONDITION_REQUIRED(uid == uid2ndCall, "Testing if EnsureModelFitUID does not create new UIDs on multiple calls."); mitk::NodeUIDType uid2 = mitk::EnsureModelFitUID(node2); MITK_TEST_CONDITION_REQUIRED(uid != uid2, "Testing if EnsureModelFitUID does create different UIDs for different nodes."); mitk::StandaloneDataStorage::Pointer storage = mitk::StandaloneDataStorage::New(); storage->Add(node1); storage->Add(node2); MITK_TEST_CONDITION_REQUIRED(node1 == GetNodeByModelFitUID(storage,uid), "Testing if GetNodeByModelFitUID finds node 1."); MITK_TEST_CONDITION_REQUIRED(node2 == GetNodeByModelFitUID(storage,uid2), "Testing if GetNodeByModelFitUID finds node 2."); MITK_TEST_CONDITION_REQUIRED(GetNodeByModelFitUID(storage,"unkown_uid").IsNull(), "Testing if GetNodeByModelFitUID returns NULL for unkown UID."); MITK_TEST_END() } diff --git a/Modules/ModelFit/test/mitkSimpleBarrierConstraintCheckerTest.cpp b/Modules/ModelFit/test/mitkSimpleBarrierConstraintCheckerTest.cpp index 2268455407..74381e936e 100644 --- a/Modules/ModelFit/test/mitkSimpleBarrierConstraintCheckerTest.cpp +++ b/Modules/ModelFit/test/mitkSimpleBarrierConstraintCheckerTest.cpp @@ -1,171 +1,170 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include #include "mitkTestingMacros.h" #include "mitkSimpleBarrierConstraintChecker.h" #include "mitkModelFitConstants.h" #include "mitkModelFitException.h" mitk::SimpleBarrierConstraintChecker::ParametersType GenerateParameters(double p1, double p2, double p3) { mitk::SimpleBarrierConstraintChecker::ParametersType result(3); result[0] = p1; result[1] = p2; result[2] = p3; return result; } int mitkSimpleBarrierConstraintCheckerTest(int /*argc*/, char*[] /*argv[]*/) { MITK_TEST_BEGIN("mitkSimpleBarrierConstraintCheckerTest") mitk::SimpleBarrierConstraintChecker::Pointer checker = mitk::SimpleBarrierConstraintChecker::New(); + double defaultMaxPenalty = 1e15; + //check freshly created checker; - MITK_TEST_CONDITION_REQUIRED(checker->GetNumberOfConstraints() == 0, - "Testing GetNumberOfConstraints for new checker."); - MITK_TEST_CONDITION_REQUIRED(checker->GetFailedConstraintValue() == 1e6, - "Testing GetNumberOfConstraints for new checker."); - MITK_TEST_CONDITION_REQUIRED(checker->GetMaxConstraintPenalty() == 1e6, - "Testing GetNumberOfConstraints for new checker."); + MITK_TEST_CONDITION_REQUIRED(checker->GetNumberOfConstraints() == 0, "Testing GetNumberOfConstraints for new checker."); + MITK_TEST_CONDITION_REQUIRED(checker->GetFailedConstraintValue() == defaultMaxPenalty, "Testing GetNumberOfConstraints for new checker."); + MITK_TEST_CONDITION_REQUIRED(checker->GetMaxConstraintPenalty() == defaultMaxPenalty, "Testing GetNumberOfConstraints for new checker."); //configure checker (test setter) checker->SetLowerBarrier(0,5); checker->SetLowerBarrier(1,10,3); checker->SetUpperBarrier(1,100,10); checker->SetUpperBarrier(2,50); typedef mitk::SimpleBarrierConstraintChecker::ParametersType ParametersType; typedef mitk::SimpleBarrierConstraintChecker::PenaltyArrayType PenaltiesType; ParametersType p1 = GenerateParameters(10,30,40); ParametersType p2 = GenerateParameters(5.0001,30,40); ParametersType p3 = GenerateParameters(5,30,40); ParametersType p4 = GenerateParameters(4.5,12,40); ParametersType p5 = GenerateParameters(10,10,40); ParametersType p6 = GenerateParameters(10,91,40); ParametersType p7 = GenerateParameters(10,100,40); ParametersType p8 = GenerateParameters(1000,30,50); ParametersType p9 = GenerateParameters(10,30,49.999); PenaltiesType penalties = checker->GetPenalties(p1); MITK_TEST_CONDITION_REQUIRED(penalties[0] == 0.0, "Testing penalty 1 of test parameters p1."); MITK_TEST_CONDITION_REQUIRED(penalties[1] == 0.0, "Testing penalty 2 of test parameters p1."); MITK_TEST_CONDITION_REQUIRED(penalties[2] == 0.0, "Testing penalty 3 of test parameters p1."); MITK_TEST_CONDITION_REQUIRED(penalties[3] == 0.0, "Testing penalty 4 of test parameters p1."); MITK_TEST_CONDITION_REQUIRED(checker->GetPenaltySum(p1) == penalties[0] + penalties[1] + penalties[2] + penalties[3], "Testing penalty sum of test parameters p1."); penalties = checker->GetPenalties(p2); MITK_TEST_CONDITION_REQUIRED(penalties[0] == 0.0, "Testing penalty 1 of test parameters p2."); MITK_TEST_CONDITION_REQUIRED(penalties[1] == 0.0, "Testing penalty 2 of test parameters p2."); MITK_TEST_CONDITION_REQUIRED(penalties[2] == 0.0, "Testing penalty 3 of test parameters p2."); MITK_TEST_CONDITION_REQUIRED(penalties[3] == 0.0, "Testing penalty 4 of test parameters p2."); MITK_TEST_CONDITION_REQUIRED(checker->GetPenaltySum(p2) == penalties[0] + penalties[1] + penalties[2] + penalties[3], "Testing penalty sum of test parameters p2."); penalties = checker->GetPenalties(p3); - MITK_TEST_CONDITION_REQUIRED(penalties[0] == 1e6, "Testing penalty 1 of test parameters p3."); + MITK_TEST_CONDITION_REQUIRED(penalties[0] == defaultMaxPenalty, "Testing penalty 1 of test parameters p3."); MITK_TEST_CONDITION_REQUIRED(penalties[1] == 0.0, "Testing penalty 2 of test parameters p3."); MITK_TEST_CONDITION_REQUIRED(penalties[2] == 0.0, "Testing penalty 3 of test parameters p3."); MITK_TEST_CONDITION_REQUIRED(penalties[3] == 0.0, "Testing penalty 4 of test parameters p3."); MITK_TEST_CONDITION_REQUIRED(checker->GetPenaltySum(p3) == penalties[0] + penalties[1] + penalties[2] + penalties[3], "Testing penalty sum of test parameters p3."); penalties = checker->GetPenalties(p4); - MITK_TEST_CONDITION_REQUIRED(penalties[0] == 1e6, "Testing penalty 1 of test parameters p4."); + MITK_TEST_CONDITION_REQUIRED(penalties[0] == defaultMaxPenalty, "Testing penalty 1 of test parameters p4."); MITK_TEST_CONDITION_REQUIRED(penalties[1] == -1*log(2/3.), "Testing penalty 2 of test parameters p4."); MITK_TEST_CONDITION_REQUIRED(penalties[2] == 0.0, "Testing penalty 3 of test parameters p4."); MITK_TEST_CONDITION_REQUIRED(penalties[3] == 0.0, "Testing penalty 4 of test parameters p4."); MITK_TEST_CONDITION_REQUIRED(checker->GetPenaltySum(p4) == penalties[0] + penalties[1] + penalties[2] + penalties[3], "Testing penalty sum of test parameters p4."); penalties = checker->GetPenalties(p5); MITK_TEST_CONDITION_REQUIRED(penalties[0] == 0.0, "Testing penalty 1 of test parameters p5."); - MITK_TEST_CONDITION_REQUIRED(penalties[1] == 1e6, "Testing penalty 2 of test parameters p5."); + MITK_TEST_CONDITION_REQUIRED(penalties[1] == defaultMaxPenalty, "Testing penalty 2 of test parameters p5."); MITK_TEST_CONDITION_REQUIRED(penalties[2] == 0.0, "Testing penalty 3 of test parameters p5."); MITK_TEST_CONDITION_REQUIRED(penalties[3] == 0.0, "Testing penalty 4 of test parameters p5."); MITK_TEST_CONDITION_REQUIRED(checker->GetPenaltySum(p5) == penalties[0] + penalties[1] + penalties[2] + penalties[3], "Testing penalty sum of test parameters p5."); penalties = checker->GetPenalties(p6); MITK_TEST_CONDITION_REQUIRED(penalties[0] == 0.0, "Testing penalty 1 of test parameters p6."); MITK_TEST_CONDITION_REQUIRED(penalties[1] == 0.0, "Testing penalty 2 of test parameters p6."); MITK_TEST_CONDITION_REQUIRED(penalties[2] == -1*log(9/10.), "Testing penalty 3 of test parameters p6."); MITK_TEST_CONDITION_REQUIRED(penalties[3] == 0.0, "Testing penalty 4 of test parameters p1."); MITK_TEST_CONDITION_REQUIRED(checker->GetPenaltySum(p6) == penalties[0] + penalties[1] + penalties[2] + penalties[3], "Testing penalty sum of test parameters p6."); penalties = checker->GetPenalties(p7); MITK_TEST_CONDITION_REQUIRED(penalties[0] == 0.0, "Testing penalty 1 of test parameters p7."); MITK_TEST_CONDITION_REQUIRED(penalties[1] == 0.0, "Testing penalty 2 of test parameters p7."); - MITK_TEST_CONDITION_REQUIRED(penalties[2] == 1e6, "Testing penalty 3 of test parameters p7."); + MITK_TEST_CONDITION_REQUIRED(penalties[2] == defaultMaxPenalty, "Testing penalty 3 of test parameters p7."); MITK_TEST_CONDITION_REQUIRED(penalties[3] == 0.0, "Testing penalty 4 of test parameters p7."); MITK_TEST_CONDITION_REQUIRED(checker->GetPenaltySum(p7) == penalties[0] + penalties[1] + penalties[2] + penalties[3], "Testing penalty sum of test parameters p7."); penalties = checker->GetPenalties(p8); MITK_TEST_CONDITION_REQUIRED(penalties[0] == 0.0, "Testing penalty 1 of test parameters p8."); MITK_TEST_CONDITION_REQUIRED(penalties[1] == 0.0, "Testing penalty 2 of test parameters p8."); MITK_TEST_CONDITION_REQUIRED(penalties[2] == 0.0, "Testing penalty 3 of test parameters p8."); - MITK_TEST_CONDITION_REQUIRED(penalties[3] == 1e6, "Testing penalty 4 of test parameters p8."); + MITK_TEST_CONDITION_REQUIRED(penalties[3] == defaultMaxPenalty, "Testing penalty 4 of test parameters p8."); MITK_TEST_CONDITION_REQUIRED(checker->GetPenaltySum(p8) == penalties[0] + penalties[1] + penalties[2] + penalties[3], "Testing penalty sum of test parameters p8."); penalties = checker->GetPenalties(p9); MITK_TEST_CONDITION_REQUIRED(penalties[0] == 0.0, "Testing penalty 1 of test parameters p9."); MITK_TEST_CONDITION_REQUIRED(penalties[1] == 0.0, "Testing penalty 2 of test parameters p9."); MITK_TEST_CONDITION_REQUIRED(penalties[2] == 0.0, "Testing penalty 3 of test parameters p9."); MITK_TEST_CONDITION_REQUIRED(penalties[3] == 0.0, "Testing penalty 4 of test parameters p9."); MITK_TEST_CONDITION_REQUIRED(checker->GetPenaltySum(p9) == penalties[0] + penalties[1] + penalties[2] + penalties[3], "Testing penalty sum of test parameters p9."); checker->SetMaxConstraintPenalty(2222); penalties = checker->GetPenalties(p8); MITK_TEST_CONDITION_REQUIRED(penalties[3] == 2222, "Testing penalty 3 of test parameters p8 with changed max penalty."); mitk::SimpleBarrierConstraintChecker::ParameterIndexVectorType index; index.push_back(0); index.push_back(1); checker->SetLowerSumBarrier(index,37); index[0]=1; index[1]=2; checker->SetUpperSumBarrier(index,75); penalties = checker->GetPenalties(p1); MITK_TEST_CONDITION_REQUIRED(penalties[0] == 0.0, "Testing penalty 1 of test parameters p1."); MITK_TEST_CONDITION_REQUIRED(penalties[1] == 0.0, "Testing penalty 2 of test parameters p1."); MITK_TEST_CONDITION_REQUIRED(penalties[2] == 0.0, "Testing penalty 3 of test parameters p1."); MITK_TEST_CONDITION_REQUIRED(penalties[3] == 0.0, "Testing penalty 4 of test parameters p1."); MITK_TEST_CONDITION_REQUIRED(penalties[4] == 0.0, "Testing penalty 5 of test parameters p1."); MITK_TEST_CONDITION_REQUIRED(penalties[5] == 0.0, "Testing penalty 6 of test parameters p1."); penalties = checker->GetPenalties(p2); MITK_TEST_CONDITION_REQUIRED(penalties[0] == 0.0, "Testing penalty 1 of test parameters p2."); MITK_TEST_CONDITION_REQUIRED(penalties[1] == 0.0, "Testing penalty 2 of test parameters p2."); MITK_TEST_CONDITION_REQUIRED(penalties[2] == 0.0, "Testing penalty 3 of test parameters p2."); MITK_TEST_CONDITION_REQUIRED(penalties[3] == 0.0, "Testing penalty 4 of test parameters p2."); MITK_TEST_CONDITION_REQUIRED(penalties[4] == 2222, "Testing penalty 5 of test parameters p2."); MITK_TEST_CONDITION_REQUIRED(penalties[5] == 0.0, "Testing penalty 6 of test parameters p2."); penalties = checker->GetPenalties(p9); MITK_TEST_CONDITION_REQUIRED(penalties[0] == 0.0, "Testing penalty 1 of test parameters p9."); MITK_TEST_CONDITION_REQUIRED(penalties[1] == 0.0, "Testing penalty 2 of test parameters p9."); MITK_TEST_CONDITION_REQUIRED(penalties[2] == 0.0, "Testing penalty 3 of test parameters p9."); MITK_TEST_CONDITION_REQUIRED(penalties[3] == 0.0, "Testing penalty 4 of test parameters p9."); MITK_TEST_CONDITION_REQUIRED(penalties[4] == 0.0, "Testing penalty 5 of test parameters p9."); MITK_TEST_CONDITION_REQUIRED(penalties[5] == 2222, "Testing penalty 6 of test parameters p9."); ParametersType invalidP; MITK_TEST_FOR_EXCEPTION(mitk::Exception, checker->GetPenalties(invalidP)); MITK_TEST_END() }