diff --git a/CMakeLists.txt b/CMakeLists.txt index eca368899867c67de24406d4b4c3aa4586ffa326..a693c37aa4078132e587ec120a3e5434a233f5d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,6 +80,7 @@ endif() include( elxModules ) elxmodule_enable( ModuleCore ) elxmodule_enable( ModuleElastix ) +elxmodule_enable( ModuleExamples ) # TODO: Build tests depending on enabled modules diff --git a/Modules/Components/Examples/ModuleExamples.cmake b/Modules/Components/Examples/ModuleExamples.cmake new file mode 100644 index 0000000000000000000000000000000000000000..30a9571909cd08b944a34fc681674c93df8c7af2 --- /dev/null +++ b/Modules/Components/Examples/ModuleExamples.cmake @@ -0,0 +1,34 @@ +set( MODULE ModuleExamples ) + +# Export include files +set( ${MODULE}_INCLUDE_DIRS + ${${MODULE}_SOURCE_DIR}/include +) + +# Collect header files for Visual Studio Project +file(GLOB ${MODULE}_HEADER_FILES "${${MODULE}_SOURCE_DIR}/include/*.*") + +# Export libraries +set( ${MODULE}_LIBRARIES + ${MODULE} +) + +# Module source files +set( ${MODULE}_SOURCE_FILES + ${${MODULE}_SOURCE_DIR}/src/Example3rdPartyCode.cxx + ${${MODULE}_SOURCE_DIR}/src/Example4thPartyCode.cxx + ${${MODULE}_SOURCE_DIR}/src/GDOptimizer3rdPartyComponent.cxx + ${${MODULE}_SOURCE_DIR}/src/GDOptimizer4thPartyComponent.cxx + ${${MODULE}_SOURCE_DIR}/src/Metric3rdPartyWrapper.cxx + ${${MODULE}_SOURCE_DIR}/src/Metric4thPartyWrapper.cxx + ${${MODULE}_SOURCE_DIR}/src/SSDMetric3rdPartyComponent.cxx + ${${MODULE}_SOURCE_DIR}/src/SSDMetric4thPartyComponent.cxx + ${${MODULE}_SOURCE_DIR}/src/TransformComponent1.cxx + ${${MODULE}_SOURCE_DIR}/src/MetricComponent1.cxx +) + +# Compile library + +add_library( ${MODULE} STATIC "${${MODULE}_SOURCE_FILES}" ${${MODULE}_HEADER_FILES}) + +target_link_libraries( ${MODULE} ${ELASTIX_LIBRARIES} ) diff --git a/Modules/Core/ExampleComponents/include/Example3rdPartyCode.h b/Modules/Components/Examples/include/Example3rdPartyCode.h similarity index 100% rename from Modules/Core/ExampleComponents/include/Example3rdPartyCode.h rename to Modules/Components/Examples/include/Example3rdPartyCode.h diff --git a/Modules/Core/ExampleComponents/include/Example4thPartyCode.h b/Modules/Components/Examples/include/Example4thPartyCode.h similarity index 100% rename from Modules/Core/ExampleComponents/include/Example4thPartyCode.h rename to Modules/Components/Examples/include/Example4thPartyCode.h diff --git a/Modules/Core/ExampleComponents/include/GDOptimizer3rdPartyComponent.h b/Modules/Components/Examples/include/GDOptimizer3rdPartyComponent.h similarity index 96% rename from Modules/Core/ExampleComponents/include/GDOptimizer3rdPartyComponent.h rename to Modules/Components/Examples/include/GDOptimizer3rdPartyComponent.h index 1ac5f923c8e9446fe6878c2ee26c173cc98c3051..4293168d2dc47c03376ea17924feba391ad51ed3 100644 --- a/Modules/Core/ExampleComponents/include/GDOptimizer3rdPartyComponent.h +++ b/Modules/Components/Examples/include/GDOptimizer3rdPartyComponent.h @@ -39,7 +39,7 @@ namespace selx int Set(MetricDerivativeInterface*); int Update(); //virtual bool MeetsCriteria(const CriteriaType &criteria); - virtual bool MeetsCriterium(const CriteriumType &criterium); + virtual bool MeetsCriterion(const CriterionType &criterion); //static const char * GetName() { return "GDOptimizer3rdPartyComponent"; } ; static const char * GetDescription() { return "GD Optimizer 3rd Party Component"; }; diff --git a/Modules/Core/ExampleComponents/include/GDOptimizer4thPartyComponent.h b/Modules/Components/Examples/include/GDOptimizer4thPartyComponent.h similarity index 96% rename from Modules/Core/ExampleComponents/include/GDOptimizer4thPartyComponent.h rename to Modules/Components/Examples/include/GDOptimizer4thPartyComponent.h index 8b108d70a8647ce82821baee80b7ddb992c0334f..881d0b9ed143f0d4172ce8e8e31093ac2876fd6b 100644 --- a/Modules/Core/ExampleComponents/include/GDOptimizer4thPartyComponent.h +++ b/Modules/Components/Examples/include/GDOptimizer4thPartyComponent.h @@ -41,7 +41,7 @@ namespace selx // "error" : member function templates cannot be virtual int Update(ConflictinUpdateInterface*) { return 5; }; //virtual bool MeetsCriteria(const CriteriaType &criteria); - virtual bool MeetsCriterium(const CriteriumType &criterium); + virtual bool MeetsCriterion(const CriterionType &criterion); //static const char * GetName(){ return "GDOptimizer4thPartyComponent"; }; static const char * GetDescription(){ return "GD Optimizer 4th Party Component"; }; }; diff --git a/Modules/Core/ExampleComponents/include/Metric3rdPartyWrapper.h b/Modules/Components/Examples/include/Metric3rdPartyWrapper.h similarity index 100% rename from Modules/Core/ExampleComponents/include/Metric3rdPartyWrapper.h rename to Modules/Components/Examples/include/Metric3rdPartyWrapper.h diff --git a/Modules/Core/ExampleComponents/include/Metric4thPartyWrapper.h b/Modules/Components/Examples/include/Metric4thPartyWrapper.h similarity index 100% rename from Modules/Core/ExampleComponents/include/Metric4thPartyWrapper.h rename to Modules/Components/Examples/include/Metric4thPartyWrapper.h diff --git a/Modules/Core/ExampleComponents/include/MetricComponent1.h b/Modules/Components/Examples/include/MetricComponent1.h similarity index 92% rename from Modules/Core/ExampleComponents/include/MetricComponent1.h rename to Modules/Components/Examples/include/MetricComponent1.h index 344421c5235e5c722c3b82bceac0f7ddb11ee27a..c6a6cf6632988c641e367eed4b5f7378998ec617 100644 --- a/Modules/Core/ExampleComponents/include/MetricComponent1.h +++ b/Modules/Components/Examples/include/MetricComponent1.h @@ -26,7 +26,7 @@ public: itkTypeMacro(MetricComponent1, ComponentBase); typedef Superclass::CriteriaType CriteriaType; - typedef Superclass::CriteriumType CriteriumType; + typedef Superclass::CriterionType CriterionType; virtual int Set(TransformedImageInterface *); virtual int GetValue(){ return 0; } @@ -45,7 +45,7 @@ private: MetricComponent1(const Self &); // purposely not implemented void operator=(const Self &); // purposely not implemented - virtual bool MeetsCriterium(const CriteriumType &criterium); + virtual bool MeetsCriterion(const CriterionType &criterion); //virtual bool MeetsCriteria(const CriteriaType&); }; diff --git a/Modules/Core/ExampleComponents/include/MetricComponent1Factory.h b/Modules/Components/Examples/include/MetricComponent1Factory.h similarity index 100% rename from Modules/Core/ExampleComponents/include/MetricComponent1Factory.h rename to Modules/Components/Examples/include/MetricComponent1Factory.h diff --git a/Modules/Core/ExampleComponents/include/MetricComponent1Factory.hxx b/Modules/Components/Examples/include/MetricComponent1Factory.hxx similarity index 100% rename from Modules/Core/ExampleComponents/include/MetricComponent1Factory.hxx rename to Modules/Components/Examples/include/MetricComponent1Factory.hxx diff --git a/Modules/Core/ExampleComponents/include/SSDMetric3rdPartyComponent.h b/Modules/Components/Examples/include/SSDMetric3rdPartyComponent.h similarity index 95% rename from Modules/Core/ExampleComponents/include/SSDMetric3rdPartyComponent.h rename to Modules/Components/Examples/include/SSDMetric3rdPartyComponent.h index 92c0f1fae87d542dcbf0facbbb2999ecdbe20508..8d8a7e5f88d39702648e19bbebca0ff111a5d678 100644 --- a/Modules/Core/ExampleComponents/include/SSDMetric3rdPartyComponent.h +++ b/Modules/Components/Examples/include/SSDMetric3rdPartyComponent.h @@ -33,7 +33,7 @@ namespace selx int GetValue(); int GetDerivative(); //virtual bool MeetsCriteria(const CriteriaType &criteria); - virtual bool MeetsCriterium(const CriteriumType &criterium); + virtual bool MeetsCriterion(const CriterionType &criterion); static const char * GetName(){ return "SSDMetric3rdPartyComponent"; } static const char * GetDescription(){ return "SSD Metric 3rd Party Component"; }; }; diff --git a/Modules/Core/ExampleComponents/include/SSDMetric4thPartyComponent.h b/Modules/Components/Examples/include/SSDMetric4thPartyComponent.h similarity index 95% rename from Modules/Core/ExampleComponents/include/SSDMetric4thPartyComponent.h rename to Modules/Components/Examples/include/SSDMetric4thPartyComponent.h index 353615947aa21055d84a0fa1b66c42a6c13d9b9d..b5bfa9d56c289239d9afed47ce19fab7bdc4ba12 100644 --- a/Modules/Core/ExampleComponents/include/SSDMetric4thPartyComponent.h +++ b/Modules/Components/Examples/include/SSDMetric4thPartyComponent.h @@ -31,7 +31,7 @@ namespace selx virtual ~SSDMetric4thPartyComponent(); Example4thParty::SSDMetric4thParty* theImplementation; int GetValue(); - virtual bool MeetsCriterium(const CriteriumType &criterium); + virtual bool MeetsCriterion(const CriterionType &criterion); //virtual bool MeetsCriteria(const CriteriaType &criteria); //static const char * GetName(){ return "SSDMetric4thPartyComponent"; }; static const char * GetDescription(){ return "SSD Metric 4th Party Component"; }; diff --git a/Modules/Core/ExampleComponents/include/TransformComponent1.h b/Modules/Components/Examples/include/TransformComponent1.h similarity index 91% rename from Modules/Core/ExampleComponents/include/TransformComponent1.h rename to Modules/Components/Examples/include/TransformComponent1.h index 4236031ec4cfebdce3fedb34bacc04dda0f1a35e..19aa1a56182da8b0de148c43c5fc08af15afddf7 100644 --- a/Modules/Core/ExampleComponents/include/TransformComponent1.h +++ b/Modules/Components/Examples/include/TransformComponent1.h @@ -26,11 +26,11 @@ public: itkTypeMacro(TransformComponent1, ComponentBase); typedef Superclass::CriteriaType CriteriaType; - typedef Superclass::CriteriumType CriteriumType; + typedef Superclass::CriterionType CriterionType; int GetTransformedImage(){ return 0; }; static const char * GetDescription(){ return "Example Transform Component 1"; }; - virtual bool MeetsCriterium(const CriteriumType &criterium); + virtual bool MeetsCriterion(const CriterionType &criterion); protected: TransformComponent1(); virtual ~TransformComponent1() diff --git a/Modules/Core/ExampleComponents/include/TransformComponent1Factory.h b/Modules/Components/Examples/include/TransformComponent1Factory.h similarity index 100% rename from Modules/Core/ExampleComponents/include/TransformComponent1Factory.h rename to Modules/Components/Examples/include/TransformComponent1Factory.h diff --git a/Modules/Core/ExampleComponents/include/TransformComponent1Factory.hxx b/Modules/Components/Examples/include/TransformComponent1Factory.hxx similarity index 100% rename from Modules/Core/ExampleComponents/include/TransformComponent1Factory.hxx rename to Modules/Components/Examples/include/TransformComponent1Factory.hxx diff --git a/Modules/Core/ExampleComponents/src/Example3rdPartyCode.cxx b/Modules/Components/Examples/src/Example3rdPartyCode.cxx similarity index 100% rename from Modules/Core/ExampleComponents/src/Example3rdPartyCode.cxx rename to Modules/Components/Examples/src/Example3rdPartyCode.cxx diff --git a/Modules/Core/ExampleComponents/src/Example4thPartyCode.cxx b/Modules/Components/Examples/src/Example4thPartyCode.cxx similarity index 100% rename from Modules/Core/ExampleComponents/src/Example4thPartyCode.cxx rename to Modules/Components/Examples/src/Example4thPartyCode.cxx diff --git a/Modules/Core/ExampleComponents/src/GDOptimizer3rdPartyComponent.cxx b/Modules/Components/Examples/src/GDOptimizer3rdPartyComponent.cxx similarity index 75% rename from Modules/Core/ExampleComponents/src/GDOptimizer3rdPartyComponent.cxx rename to Modules/Components/Examples/src/GDOptimizer3rdPartyComponent.cxx index c2d7e20f1e66ef54e7c59201161cb13b388a5c69..ed5fd6d3f5aea31d44a1d049d48e1663405f2c11 100644 --- a/Modules/Core/ExampleComponents/src/GDOptimizer3rdPartyComponent.cxx +++ b/Modules/Components/Examples/src/GDOptimizer3rdPartyComponent.cxx @@ -32,15 +32,19 @@ int GDOptimizer3rdPartyComponent::Update() bool GDOptimizer3rdPartyComponent -::MeetsCriterium(const CriteriumType &criterium) +::MeetsCriterion(const CriterionType &criterion) { bool hasUndefinedCriteria(false); bool meetsCriteria(false); - if (strcmp(criterium.first.c_str(), "ComponentProperty") == 0) + if (criterion.first == "ComponentProperty") { - if (strcmp(criterium.second.c_str(), "SomeProperty") == 0) // e.g. "GradientDescent", "SupportsSparseSamples + meetsCriteria = true; + for (auto const & criterionValue : criterion.second) // auto&& preferred? { - meetsCriteria = true; + if (criterionValue != "SomeProperty") // e.g. "GradientDescent", "SupportsSparseSamples + { + meetsCriteria = false; + } } } return meetsCriteria; diff --git a/Modules/Core/ExampleComponents/src/GDOptimizer4thPartyComponent.cxx b/Modules/Components/Examples/src/GDOptimizer4thPartyComponent.cxx similarity index 72% rename from Modules/Core/ExampleComponents/src/GDOptimizer4thPartyComponent.cxx rename to Modules/Components/Examples/src/GDOptimizer4thPartyComponent.cxx index 81c87c6de38e9714c6d8b28fa99591d2824193e6..c90fe03cc01046286c1805a188d4a7c9b0e8621b 100644 --- a/Modules/Core/ExampleComponents/src/GDOptimizer4thPartyComponent.cxx +++ b/Modules/Components/Examples/src/GDOptimizer4thPartyComponent.cxx @@ -29,15 +29,19 @@ int GDOptimizer4thPartyComponent::Update() bool GDOptimizer4thPartyComponent -::MeetsCriterium(const CriteriumType &criterium) +::MeetsCriterion(const CriterionType &criterion) { bool hasUndefinedCriteria(false); bool meetsCriteria(false); - if (strcmp(criterium.first.c_str(), "ComponentProperty") == 0) + if (criterion.first == "ComponentProperty") { - if (strcmp(criterium.second.c_str(), "SomeProperty") == 0) // e.g. "GradientDescent", "SupportsSparseSamples + meetsCriteria = true; + for (auto const & criterionValue : criterion.second) // auto&& preferred? { - meetsCriteria = true; + if (criterionValue != "SomeProperty") // e.g. "GradientDescent", "SupportsSparseSamples + { + meetsCriteria = false; + } } } return meetsCriteria; diff --git a/Modules/Core/ExampleComponents/src/Metric3rdPartyWrapper.cxx b/Modules/Components/Examples/src/Metric3rdPartyWrapper.cxx similarity index 100% rename from Modules/Core/ExampleComponents/src/Metric3rdPartyWrapper.cxx rename to Modules/Components/Examples/src/Metric3rdPartyWrapper.cxx diff --git a/Modules/Core/ExampleComponents/src/Metric4thPartyWrapper.cxx b/Modules/Components/Examples/src/Metric4thPartyWrapper.cxx similarity index 100% rename from Modules/Core/ExampleComponents/src/Metric4thPartyWrapper.cxx rename to Modules/Components/Examples/src/Metric4thPartyWrapper.cxx diff --git a/Modules/Core/ExampleComponents/src/MetricComponent1.cxx b/Modules/Components/Examples/src/MetricComponent1.cxx similarity index 63% rename from Modules/Core/ExampleComponents/src/MetricComponent1.cxx rename to Modules/Components/Examples/src/MetricComponent1.cxx index 08b35ef3b310c327ea2b62af38490e110c168afd..81b9ce71d451ed3b345d2d7b90ba09bbce807a52 100644 --- a/Modules/Core/ExampleComponents/src/MetricComponent1.cxx +++ b/Modules/Components/Examples/src/MetricComponent1.cxx @@ -32,22 +32,32 @@ int MetricComponent1::Set(TransformedImageInterface* providingInterface) bool MetricComponent1 - ::MeetsCriterium(const CriteriumType &criterium) + ::MeetsCriterion(const CriterionType &criterion) { bool hasUndefinedCriteria(false); bool meetsCriteria(false); - if (strcmp(criterium.first.c_str(), "ComponentProperty") == 0) + if (criterion.first == "ComponentProperty") { - if (strcmp(criterium.second.c_str(), "SomeProperty") == 0) // e.g. "GradientDescent", "SupportsSparseSamples + meetsCriteria = true; + for (auto const & criterionValue : criterion.second) // auto&& preferred? { - meetsCriteria = true; + if (criterionValue != "SomeProperty") // e.g. "GradientDescent", "SupportsSparseSamples + { + meetsCriteria = false; + return false; + } } } - else if (strcmp(criterium.first.c_str(), "ComponentInput") == 0) + if (criterion.first == "ComponentInput") { - if (strcmp(criterium.second.c_str(), "Transform") == 0) // e.g. "GradientDescent", "SupportsSparseSamples + meetsCriteria = true; + for (auto const & criterionValue : criterion.second) // auto&& preferred? { - meetsCriteria = true; + if (criterionValue != "Transform") // e.g. "GradientDescent", "SupportsSparseSamples + { + meetsCriteria = false; + return false; + } } } return meetsCriteria; diff --git a/Modules/Core/ExampleComponents/src/SSDMetric3rdPartyComponent.cxx b/Modules/Components/Examples/src/SSDMetric3rdPartyComponent.cxx similarity index 65% rename from Modules/Core/ExampleComponents/src/SSDMetric3rdPartyComponent.cxx rename to Modules/Components/Examples/src/SSDMetric3rdPartyComponent.cxx index af0239f75ef55a2081782ce224324fbfc7499e2f..00af77bc1c2c24d708b48313a7dd9ba88c9e7ffe 100644 --- a/Modules/Core/ExampleComponents/src/SSDMetric3rdPartyComponent.cxx +++ b/Modules/Components/Examples/src/SSDMetric3rdPartyComponent.cxx @@ -22,15 +22,19 @@ int SSDMetric3rdPartyComponent::GetValue() bool SSDMetric3rdPartyComponent -::MeetsCriterium(const CriteriumType &criterium) +::MeetsCriterion(const CriterionType &criterion) { bool hasUndefinedCriteria(false); bool meetsCriteria(false); - if (strcmp(criterium.first.c_str(), "ComponentProperty") == 0) + if (criterion.first == "ComponentProperty") { - if (strcmp(criterium.second.c_str(), "SomeProperty") == 0) // e.g. "GradientDescent", "SupportsSparseSamples + meetsCriteria = true; + for (auto const & criterionValue : criterion.second) // auto&& preferred? { - meetsCriteria = true; + if (criterionValue != "SomeProperty") // e.g. "GradientDescent", "SupportsSparseSamples + { + meetsCriteria = false; + } } } return meetsCriteria; diff --git a/Modules/Core/ExampleComponents/src/SSDMetric4thPartyComponent.cxx b/Modules/Components/Examples/src/SSDMetric4thPartyComponent.cxx similarity index 62% rename from Modules/Core/ExampleComponents/src/SSDMetric4thPartyComponent.cxx rename to Modules/Components/Examples/src/SSDMetric4thPartyComponent.cxx index 6364ef9342ccecb1b799d0ca355a9e46cf8a4899..eb9b98398c8594cac9e581a57448b9a385f21a2f 100644 --- a/Modules/Core/ExampleComponents/src/SSDMetric4thPartyComponent.cxx +++ b/Modules/Components/Examples/src/SSDMetric4thPartyComponent.cxx @@ -18,15 +18,19 @@ int SSDMetric4thPartyComponent::GetValue() bool SSDMetric4thPartyComponent -::MeetsCriterium(const CriteriumType &criterium) +::MeetsCriterion(const CriterionType &criterion) { bool hasUndefinedCriteria(false); bool meetsCriteria(false); - if (strcmp(criterium.first.c_str(), "ComponentProperty") == 0) + if (criterion.first == "ComponentProperty") { - if (strcmp(criterium.second.c_str(), "SomeProperty") == 0) // e.g. "GradientDescent", "SupportsSparseSamples + meetsCriteria = true; + for (auto const & criterionValue : criterion.second) // auto&& preferred? { - meetsCriteria = true; + if (criterionValue != "SomeProperty") // e.g. "GradientDescent", "SupportsSparseSamples + { + meetsCriteria = false; + } } } return meetsCriteria; diff --git a/Modules/Core/ExampleComponents/src/TransformComponent1.cxx b/Modules/Components/Examples/src/TransformComponent1.cxx similarity index 53% rename from Modules/Core/ExampleComponents/src/TransformComponent1.cxx rename to Modules/Components/Examples/src/TransformComponent1.cxx index 9f26d649326bdc4c05defea57b0ab98c51d3a351..0f4ffac3fe412bfe3a7cae5c356a803eec204590 100644 --- a/Modules/Core/ExampleComponents/src/TransformComponent1.cxx +++ b/Modules/Components/Examples/src/TransformComponent1.cxx @@ -27,31 +27,46 @@ namespace selx } bool - TransformComponent1::MeetsCriterium(const CriteriumType &criterium) + TransformComponent1::MeetsCriterion(const CriterionType &criterion) { bool hasUndefinedCriteria(false); bool meetsCriteria(false); - if (strcmp(criterium.first.c_str(), "ComponentProperty") == 0) + if (criterion.first == "ComponentProperty") { - if (strcmp(criterium.second.c_str(), "SomeProperty") == 0) // e.g. "GradientDescent", "SupportsSparseSamples + meetsCriteria = true; + for (auto const & criterionValue : criterion.second) // auto&& preferred? { - meetsCriteria = true; + if (criterionValue != "SomeProperty") // e.g. "GradientDescent", "SupportsSparseSamples + { + meetsCriteria = false; + return false; + } } } - else if (strcmp(criterium.first.c_str(), "ComponentOutput") == 0) + if (criterion.first == "ComponentOutput") + { + meetsCriteria = true; + for (auto const & criterionValue : criterion.second) // auto&& preferred? { - if (strcmp(criterium.second.c_str(), "Transform") == 0) + if (criterionValue != "Transform") // e.g. "GradientDescent", "SupportsSparseSamples { - meetsCriteria = true; + meetsCriteria = false; + return false; } } - else if (strcmp(criterium.first.c_str(), "ComponentInput") == 0) + } + if (criterion.first == "ComponentInput") + { + meetsCriteria = true; + for (auto const & criterionValue : criterion.second) // auto&& preferred? { - if (strcmp(criterium.second.c_str(), "Sampler") == 0) + if (criterionValue != "Sampler") // e.g. "GradientDescent", "SupportsSparseSamples { - meetsCriteria = true; + meetsCriteria = false; + return false; } } + } return meetsCriteria; } diff --git a/Modules/Core/ComponentInterface/include/ComponentBase.h b/Modules/Core/ComponentInterface/include/ComponentBase.h index cfbbcec875f7b720331a10c8ddbc662a23dbcf8f..9406918930d8d6b11c055109f6dd587a34deb023 100644 --- a/Modules/Core/ComponentInterface/include/ComponentBase.h +++ b/Modules/Core/ComponentInterface/include/ComponentBase.h @@ -2,8 +2,9 @@ #define ComponentBase_h #include "itkLightObject.h" - #include "itkObjectFactory.h" +#include "itkMacro.h" + //#include "itkComponentBase.h" #include <list> #include <iostream> @@ -26,16 +27,22 @@ namespace selx /** Run-time type information (and related methods). */ itkTypeMacro(ComponentBase, Superclass); - typedef std::map<std::string, std::string> CriteriaType; - typedef std::pair<std::string, std::string> CriteriumType; + typedef std::string ParameterKeyType; + typedef std::vector< std::string > ParameterValueType; + //typedef std::map< ParameterKeyType, ParameterValueType > ParameterMapType; + //TODO choose uniform naming for Typedefs + typedef std::map<ParameterKeyType, ParameterValueType> CriteriaType; + typedef std::pair<ParameterKeyType, ParameterValueType> CriterionType; enum interfaceStatus { success, noaccepter, noprovider }; virtual interfaceStatus ConnectFrom(const char *, ComponentBase*) = 0; virtual int ConnectFrom(ComponentBase*) = 0; + + /** if there is any failed criterion, return false (like a short - circuit AND) */ bool MeetsCriteria(const CriteriaType &criteria); - virtual bool MeetsCriterium(const CriteriumType &criterium) = 0; + virtual bool MeetsCriterion(const CriterionType &criterion) = 0; protected: virtual bool HasAcceptingInterface(const char *) = 0; virtual bool HasProvidingInterface(const char *) = 0; diff --git a/Modules/Core/ComponentInterface/include/ComponentSelector.h b/Modules/Core/ComponentInterface/include/ComponentSelector.h index f4cae7d060d452fdde24bd154640631bf6f0eeae..6f19d30ce02c6d1b18a9171c2a3d5e6ffaf5f5cc 100644 --- a/Modules/Core/ComponentInterface/include/ComponentSelector.h +++ b/Modules/Core/ComponentInterface/include/ComponentSelector.h @@ -15,12 +15,14 @@ * limitations under the License. * *=========================================================================*/ -#ifndef itkComponentSelector_h -#define itkComponentSelector_h +#ifndef ComponentSelector_h +#define ComponentSelector_h #include "itkObjectFactory.h" #include "ComponentBase.h" +//#pragma once + namespace selx { /** \class ComponentFactor @@ -51,6 +53,7 @@ public: typedef ComponentBase::CriteriaType CriteriaType; typedef std::list< ComponentBasePointer > ComponentListType; + typedef ComponentListType::size_type NumberOfComponentsType; /** set selection criteria for possibleComponents*/ void Initialize(); void SetCriteria(const CriteriaType &criteria); @@ -58,7 +61,7 @@ public: /** Narrow selection criteria*/ void AddCriteria(const CriteriaType &criteria); - void UpdatePossibleComponents(void); + NumberOfComponentsType UpdatePossibleComponents(void); ComponentBasePointer GetComponent(void); @@ -75,8 +78,8 @@ private: }; } // end namespace selx -#ifndef ITK_MANUAL_INSTANTIATION -#include "ComponentSelector.hxx" -#endif +//#ifndef ITK_MANUAL_INSTANTIATION +//#include "ComponentSelector.hxx" +//#endif #endif diff --git a/Modules/Core/ComponentInterface/include/Overlord.h b/Modules/Core/ComponentInterface/include/Overlord.h new file mode 100644 index 0000000000000000000000000000000000000000..5ca7a0c542e2c5d8cb960bbe42df51c01665a373 --- /dev/null +++ b/Modules/Core/ComponentInterface/include/Overlord.h @@ -0,0 +1,56 @@ +#ifndef Overlord_h +#define Overlord_h + +#include "itkLightProcessObject.h" + +#include "itkObjectFactory.h" +//#include "itkComponentBase.h" +#include <list> +#include <vector> +#include <iostream> +#include <fstream> +#include <string> +#include <cstring> +#include <map> + +#include "elxMacro.h" +#include "elxBlueprint.h" +//#include "ComponentBase.h" +#include "ComponentFactory.h" + +namespace selx +{ + + class Overlord : public itk::LightProcessObject + { + public: + + elxNewMacro(Overlord, itk::LightProcessObject); + + typedef std::map<std::string, std::string> CriteriaType; + typedef std::pair<std::string, std::string> CriterionType; + + typedef ComponentBase ComponentType; + typedef ComponentSelector::Pointer ComponentSelectorPointer; + typedef std::vector<ComponentSelectorPointer> ComponentSelectorContainerType; + typedef ComponentSelectorContainerType::iterator ComponentSelectorIteratorType; + + void SetBlueprint(const Blueprint::Pointer); + bool Configure(); + protected: + + Overlord() {}; + virtual ~Overlord() {}; + private: + void ApplyNodeConfiguration(); + void ApplyConnectionConfiguration(); + bool UpdateSelectors(); + bool ConnectComponents(); + Blueprint::Pointer m_Blueprint; + ComponentSelectorContainerType m_ComponentSelectorContainer; + }; + +} // end namespace selx + + +#endif // Overlord_h diff --git a/Modules/Core/ComponentInterface/src/ComponentBase.cxx b/Modules/Core/ComponentInterface/src/ComponentBase.cxx index f6fffb18eabd2c2f2fc33b13dae520de9f75fb24..836bc0b7a6a6d6dcfd7d1074f088f4d8e02b6b88 100644 --- a/Modules/Core/ComponentInterface/src/ComponentBase.cxx +++ b/Modules/Core/ComponentInterface/src/ComponentBase.cxx @@ -8,41 +8,65 @@ namespace selx { bool hasUndefinedCriteria(false); bool meetsCriteria(true); - for (CriteriaType::const_iterator it = criteria.begin(); it != criteria.end(); ++it) + for (CriteriaType::const_iterator it = criteria.begin(); it != criteria.cend(); ++it) { - if (strcmp(it->first.c_str(), "NameOfClass") == 0) + if (it->first == "NameOfClass") + //if (strcmp(it->first.c_str(), "NameOfClass") == 0) { - if (strcmp(it->second.c_str(), this->GetNameOfClass()) != 0) + if (it->second.size() != 1) + { + itkExceptionMacro("The criterion NameOfClass may have only 1 value"); + } + + //if (strcmp(it->second->c_str(), this->GetNameOfClass()) != 0) + if (it->second[0] != this->GetNameOfClass()) + //if (strcmp((it->second.cbegin)->c_str(), this->GetNameOfClass()) != 0 ) { meetsCriteria = false; - break; + //break; + return false; //if there is any failed criterion, return false (like a short-circuit AND) } + } - else if (strcmp(it->first.c_str(), "HasAcceptingInterface") == 0) + + else if (it->first == "HasAcceptingInterface") { - if (this->HasAcceptingInterface(it->second.c_str()) != true) + ParameterValueType::const_iterator valueIt; + const ParameterValueType::const_iterator valueItEnd = it->second.cend(); + + for (valueIt = it->second.cbegin(); valueIt != valueItEnd; ++valueIt) { - meetsCriteria = false; - break; + if (this->HasAcceptingInterface(valueIt->c_str()) == false) + { + meetsCriteria = false; + //break; + return false; //if there is any failed criterion, return false (like a short-circuit AND) + } } + } - else if (strcmp(it->first.c_str(), "HasProvidingInterface") == 0) + else if (it->first =="HasProvidingInterface") { - if (this->HasProvidingInterface(it->second.c_str()) != true) - { - meetsCriteria = false; - break; + ParameterValueType::const_iterator valueIt; + const ParameterValueType::const_iterator valueItEnd = it->second.cend(); + + for (valueIt = it->second.cbegin(); valueIt != valueItEnd; ++valueIt){ + if (this->HasProvidingInterface(valueIt->c_str()) == false) + { + meetsCriteria = false; + //break; + return false; //if there is any failed criterion, return false (like a short-circuit AND) + } } } - else if (this->MeetsCriterium(CriteriumType(it->first, it->second)) == true) + else if (this->MeetsCriterion(CriterionType(it->first, it->second)) == false) { - meetsCriteria = true; - + meetsCriteria = false; + return false; //if there is any failed criterion, return false (like a short-circuit AND) } else { - meetsCriteria = false; - hasUndefinedCriteria = true; + hasUndefinedCriteria = true; //TODO break; } diff --git a/Modules/Core/ComponentInterface/include/ComponentSelector.hxx b/Modules/Core/ComponentInterface/src/ComponentSelector.cxx similarity index 92% rename from Modules/Core/ComponentInterface/include/ComponentSelector.hxx rename to Modules/Core/ComponentInterface/src/ComponentSelector.cxx index 252a6fcaa4d962fa4426df29930f8bb39b0f01fd..1d82c84e1c9d66ec5d90f0f6d80bfdb3f6d3549f 100644 --- a/Modules/Core/ComponentInterface/include/ComponentSelector.hxx +++ b/Modules/Core/ComponentInterface/src/ComponentSelector.cxx @@ -15,8 +15,8 @@ * limitations under the License. * *=========================================================================*/ -#ifndef itkComponentSelector_hxx -#define itkComponentSelector_hxx +//#ifndef ComponentSelector_hxx +//#define ComponentSelector_hxx #include "ComponentSelector.h" @@ -66,11 +66,12 @@ void ComponentSelector::AddCriteria(const CriteriaType &criteria) // bool operator() (const ComponentBasePointer& component) { return !component->MeetsCriteria(this->m_Criteria) } //}; -void ComponentSelector::UpdatePossibleComponents() +ComponentSelector::NumberOfComponentsType ComponentSelector::UpdatePossibleComponents() { // Check each possible component if it meets the criteria // Using a Lambda function. this->m_PossibleComponents.remove_if([&](ComponentBasePointer component){ return !component->MeetsCriteria(this->m_Criteria); }); + return this->m_PossibleComponents.size(); } ComponentSelector::ComponentBasePointer ComponentSelector::GetComponent() { @@ -88,4 +89,4 @@ ComponentSelector::ComponentBasePointer ComponentSelector::GetComponent() } } // end namespace selx -#endif +//#endif diff --git a/Modules/Core/ComponentInterface/src/Overlord.cxx b/Modules/Core/ComponentInterface/src/Overlord.cxx new file mode 100644 index 0000000000000000000000000000000000000000..6d0ae07aacf9cb4eb0fc4d63a6573464dd00059b --- /dev/null +++ b/Modules/Core/ComponentInterface/src/Overlord.cxx @@ -0,0 +1,147 @@ +#include "Overlord.h" + +namespace selx +{ + void Overlord::SetBlueprint(const Blueprint::Pointer blueprint) + { + m_Blueprint = blueprint; + return; + + } + bool Overlord::UpdateSelectors() + { + bool allUniqueComponents = true; + Blueprint::ComponentIteratorPairType componentItPair = this->m_Blueprint->GetComponentIterator(); + Blueprint::ComponentIteratorPairType::first_type componentIt; + Blueprint::ComponentIteratorPairType::second_type componentItEnd = componentItPair.second; + for (componentIt = componentItPair.first; componentIt != componentItEnd; ++componentIt) + { + ComponentSelector::NumberOfComponentsType numberOfComponents = this->m_ComponentSelectorContainer[*componentIt]->UpdatePossibleComponents(); + + // The current idea of the configuration setup is that the number of + // possible components at a node can only be reduced by adding criteria. + // If a node has 0 possible components, the configuration is aborted (with an exception) + // If all nodes have exactly 1 possible component, no more criteria are needed. + if (numberOfComponents == 0) + { + itkExceptionMacro("Too many criteria for component"); + } + else if (numberOfComponents > 1) + { + allUniqueComponents = false; + } + std::cout << "blueprint node " << *componentIt << " has " << numberOfComponents << " components" << std::endl; + + } + return allUniqueComponents; + } + + bool Overlord::Configure() + { + bool isSuccess(false); + bool allUniqueComponents; + this->ApplyNodeConfiguration(); + allUniqueComponents = this->UpdateSelectors(); + std::cout << "Based on Component Criteria unique components could " << (allUniqueComponents ? "":"not ") << "be selected" << std::endl; + + this->ApplyConnectionConfiguration(); + allUniqueComponents = this->UpdateSelectors(); + std::cout << "By adding Connection Criteria unique components could " << (allUniqueComponents ? "" : "not ") << "be selected" << std::endl; + + if (allUniqueComponents) + { + isSuccess = this->ConnectComponents(); + } + + return isSuccess; + } + void Overlord::ApplyNodeConfiguration() + { + Blueprint::ComponentIteratorPairType componentItPair = this->m_Blueprint->GetComponentIterator(); + Blueprint::ComponentIteratorPairType::first_type componentIt; + Blueprint::ComponentIteratorPairType::second_type componentItEnd = componentItPair.second; + for (componentIt = componentItPair.first; componentIt != componentItEnd; ++componentIt) + { + ComponentSelectorPointer currentComponentSelector = ComponentSelector::New(); + Blueprint::ParameterMapType currentProperty = this->m_Blueprint->GetComponent(*componentIt); + currentComponentSelector->SetCriteria(currentProperty); + this->m_ComponentSelectorContainer.push_back(currentComponentSelector); + } + return; + } + void Overlord::ApplyConnectionConfiguration() + { + //typedef Blueprint::OutputIteratorType OutputIteratorType; + //typedef Blueprint::OutputIteratorPairType OutputIteratorPairType; + + //TODO: these loops have to be redesigned for a number of reasons: + // - They rely on the assumption that the index of the vector equals the componentIndex in blueprint + // - Tedious, integer indexing. + // + // We might consider copying the blueprint graph to a component selector + // graph, such that all graph operations correspond + + // Or loop over connections: + //Blueprint::ConnectionIteratorPairType connectionItPair = this->m_Blueprint->GetConnectionIterator(); + //Blueprint::ConnectionIteratorPairType::first_type connectionIt; + //Blueprint::ConnectionIteratorPairType::second_type connectionItEnd = connectionItPair.second; + //int count = 0; + //for (connectionIt = connectionItPair.first; connectionIt != connectionItEnd; ++connectionIt) + //{ + //} + + + Blueprint::ComponentIndexType index; + for (index = 0; index < this->m_ComponentSelectorContainer.size(); ++index) + { + Blueprint::OutputIteratorPairType ouputItPair = this->m_Blueprint->GetOutputIterator(index); + Blueprint::OutputIteratorPairType::first_type ouputIt; + Blueprint::OutputIteratorPairType::second_type ouputItEnd = ouputItPair.second; + for (ouputIt = ouputItPair.first; ouputIt != ouputItEnd; ++ouputIt) + { + //TODO check direction upstream/downstream input/output source/target + Blueprint::ParameterMapType currentProperty = this->m_Blueprint->GetConnection(ouputIt->m_source, ouputIt->m_target); + for (Blueprint::ParameterMapType::const_iterator it = currentProperty.begin(); it != currentProperty.cend(); ++it) + { + if (it->first == "NameOfInterface") + { + ComponentBase::CriteriaType additionalSourceCriteria; + additionalSourceCriteria.insert(ComponentBase::CriterionType("HasProvidingInterface", it->second)); + + ComponentBase::CriteriaType additionalTargetCriteria; + additionalTargetCriteria.insert(ComponentBase::CriterionType("HasAcceptingInterface", it->second)); + + this->m_ComponentSelectorContainer[ouputIt->m_source]->AddCriteria(additionalSourceCriteria); + this->m_ComponentSelectorContainer[ouputIt->m_target]->AddCriteria(additionalTargetCriteria); + } + } + } + } + + return; + } + bool Overlord::ConnectComponents() + { + + //TODO: redesign loops, see ApplyConnectionConfiguration() + Blueprint::ComponentIndexType index; + for (index = 0; index < this->m_ComponentSelectorContainer.size(); ++index) + { + Blueprint::OutputIteratorPairType ouputItPair = this->m_Blueprint->GetOutputIterator(index); + Blueprint::OutputIteratorPairType::first_type ouputIt; + Blueprint::OutputIteratorPairType::second_type ouputItEnd = ouputItPair.second; + for (ouputIt = ouputItPair.first; ouputIt != ouputItEnd; ++ouputIt) + { + //TODO check direction upstream/downstream input/output source/target + //TODO GetComponent returns NULL if possible components !=1 we can check for that, but Overlord::UpdateSelectors() does something similar. + ComponentBase::Pointer sourceComponent = this->m_ComponentSelectorContainer[ouputIt->m_source]->GetComponent(); + ComponentBase::Pointer targetComponent = this->m_ComponentSelectorContainer[ouputIt->m_target]->GetComponent(); + targetComponent->ConnectFrom(sourceComponent); + } + } + //TODO should we communicate by exceptions instead of returning booleans? + return true; + } + +} // end namespace selx + diff --git a/Modules/Core/ModuleCore.cmake b/Modules/Core/ModuleCore.cmake index 50b396b3a8ae300e02bc247f350fc9981df59d58..e2d6c9d582c0696e561d67440480705e20e673f9 100644 --- a/Modules/Core/ModuleCore.cmake +++ b/Modules/Core/ModuleCore.cmake @@ -6,8 +6,7 @@ set( ${MODULE}_INCLUDE_DIRS ${${MODULE}_SOURCE_DIR}/Blueprints/include ${${MODULE}_SOURCE_DIR}/ParameterObject/include ${${MODULE}_SOURCE_DIR}/ComponentInterface/include - ${${MODULE}_SOURCE_DIR}/ExampleComponents/include -) + ) file(GLOB ${MODULE}_HEADER_FILES "${${MODULE}_SOURCE_DIR}/*/include/*.*") #@Kasper: file GLOB is generally disencouraged for source files (missing files are not detected and CMake doesn't know if the project has to be updated when due to a checkout extra source files are in the tree), but since this I think is not really an issue for header files... @@ -24,20 +23,12 @@ set( ${MODULE}_LIBRARIES set( ${MODULE}_SOURCE_FILES ${${MODULE}_SOURCE_DIR}/Blueprints/src/elxBlueprint.cxx ${${MODULE}_SOURCE_DIR}/ComponentInterface/src/ComponentBase.cxx - ${${MODULE}_SOURCE_DIR}/ExampleComponents/src/Example3rdPartyCode.cxx - ${${MODULE}_SOURCE_DIR}/ExampleComponents/src/Example4thPartyCode.cxx - ${${MODULE}_SOURCE_DIR}/ExampleComponents/src/GDOptimizer3rdPartyComponent.cxx - ${${MODULE}_SOURCE_DIR}/ExampleComponents/src/GDOptimizer4thPartyComponent.cxx - ${${MODULE}_SOURCE_DIR}/ExampleComponents/src/Metric3rdPartyWrapper.cxx - ${${MODULE}_SOURCE_DIR}/ExampleComponents/src/Metric4thPartyWrapper.cxx - ${${MODULE}_SOURCE_DIR}/ExampleComponents/src/SSDMetric3rdPartyComponent.cxx - ${${MODULE}_SOURCE_DIR}/ExampleComponents/src/SSDMetric4thPartyComponent.cxx - ${${MODULE}_SOURCE_DIR}/ExampleComponents/src/TransformComponent1.cxx - ${${MODULE}_SOURCE_DIR}/ExampleComponents/src/MetricComponent1.cxx + ${${MODULE}_SOURCE_DIR}/ComponentInterface/src/Overlord.cxx + ${${MODULE}_SOURCE_DIR}/ComponentInterface/src/ComponentSelector.cxx ) # Compile library -add_library( ${MODULE} STATIC "${${MODULE}_SOURCE_FILES}" ${${MODULE}_HEADER_FILES}) +add_library( ${MODULE} STATIC "${${MODULE}_SOURCE_FILES}" ${${MODULE}_HEADER_FILES} ) target_link_libraries( ${MODULE} ${ELASTIX_LIBRARIES} ) diff --git a/Testing/Unit/CMakeLists.txt b/Testing/Unit/CMakeLists.txt index a0bccf19094d1d7380d10af761857a9cabd2fe99..732932e4bd6d8b0085e3a92ae7cdcb47730df89e 100644 --- a/Testing/Unit/CMakeLists.txt +++ b/Testing/Unit/CMakeLists.txt @@ -9,6 +9,7 @@ set( ElastixUnitTestFilenames elxTransformixFilterTest.cxx elxComponentFactoryTest.cxx elxComponentInterfaceTest.cxx + elxOverlordTest.cxx ) # --------------------------------------------------------------------- diff --git a/Testing/Unit/elxComponentFactoryTest.cxx b/Testing/Unit/elxComponentFactoryTest.cxx index b18550ad31c5bffbd55aedb808ecbc5c21650827..c52206456a880310f2d1adc257b664c14aee1f3c 100644 --- a/Testing/Unit/elxComponentFactoryTest.cxx +++ b/Testing/Unit/elxComponentFactoryTest.cxx @@ -18,14 +18,22 @@ class ComponentFactoryTest : public ::testing::Test { public: typedef std::list< itk::LightObject::Pointer > RegisteredObjectsContainerType; typedef ComponentBase ComponentType; - typedef std::map<std::string, std::string> CriteriaType; - typedef std::pair<std::string, std::string> CriteriumType; + + typedef ComponentBase::CriteriaType CriteriaType; + typedef ComponentBase::CriterionType CriterionType; + typedef ComponentBase::ParameterValueType ParameterValueType; + //typedef std::map<std::string, std::string> CriteriaType; + //typedef std::pair<std::string, std::string> CriterionType; typedef ComponentSelector::Pointer NodePointer; virtual void SetUp() { } + virtual void TearDown() + { + itk::ObjectFactoryBase::UnRegisterAllFactories(); + } // each node can hold multiple components (or none). Its the overlord's task to make it one per node. NodePointer Node1; NodePointer Node2; @@ -68,7 +76,7 @@ TEST_F(ComponentFactoryTest, SetEmptyCriteria) EXPECT_NO_THROW(ComponentFactory<TransformComponent1>::RegisterOneFactory()); EXPECT_NO_THROW(ComponentFactory<MetricComponent1>::RegisterOneFactory()); - CriteriaType emptyCriteria; + CriteriaType emptyCriteria; // = CriteriaType(); ASSERT_NO_THROW(Node1 = ComponentSelector::New()); @@ -86,8 +94,8 @@ TEST_F(ComponentFactoryTest, SetSufficientCriteria) EXPECT_NO_THROW(ComponentFactory<MetricComponent1>::RegisterOneFactory()); CriteriaType criteria2; - criteria2["ComponentInput"] = "Transform"; - //criteria1.insert(CriteriumType("ComponentInput", "Metric")); + //criteria2["ComponentInput"] = "Transform"; + criteria2.insert(CriterionType("ComponentInput", ParameterValueType(1,"Transform"))); ASSERT_NO_THROW(Node2 = ComponentSelector::New()); Node2->SetCriteria(criteria2); @@ -107,9 +115,10 @@ TEST_F(ComponentFactoryTest, AddCriteria) CriteriaType emptyCriteria; CriteriaType criteria1; - //criteria1.insert(CriteriumType("ComponentOutput","Metric")); - criteria1["ComponentOutput"] = "Transform"; - //criteria1.insert(CriteriumType("ComponentInput", "Metric")); + //criteria1.insert(CriterionType("ComponentOutput","Metric")); + //criteria1["ComponentOutput"] = "Transform"; + criteria1.insert(CriterionType("ComponentOutput", ParameterValueType(1, "Transform"))); + //criteria1.insert(CriterionType("ComponentInput", "Metric")); Node1 = ComponentSelector::New(); Node1->SetCriteria(emptyCriteria); @@ -140,7 +149,8 @@ TEST_F(ComponentFactoryTest, InterfacedObjects) CriteriaType criteria3; // Criteria could be name or other properties //criteria3["NameOfClass"] = "GDOptimizer3rdPartyComponent"; - criteria3["HasAcceptingInterface"] = "MetricDerivativeInterface"; + //criteria3["HasAcceptingInterface"] = "MetricDerivativeInterface"; + criteria3.insert(CriterionType("HasAcceptingInterface", ParameterValueType(1, "MetricDerivativeInterface"))); NodePointer Node3 = ComponentSelector::New(); Node3->SetCriteria(criteria3); ComponentType::Pointer Node3Component; @@ -149,7 +159,8 @@ TEST_F(ComponentFactoryTest, InterfacedObjects) CriteriaType criteria4; // Criteria could be name or other properties - criteria4["NameOfClass"] = "GDOptimizer4thPartyComponent"; + //criteria4["NameOfClass"] = "GDOptimizer4thPartyComponent"; + criteria4.insert(CriterionType("NameOfClass", ParameterValueType(1, "GDOptimizer4thPartyComponent"))); //criteria3["HasDerivative"] = "True"; NodePointer Node4 = ComponentSelector::New(); @@ -161,7 +172,9 @@ TEST_F(ComponentFactoryTest, InterfacedObjects) CriteriaType criteria5; // Criteria could be name or other properties //criteria5["NameOfClass"] = "SSDMetric3rdPartyComponent"; - criteria5["HasProvidingInterface"] = "MetricDerivativeInterface"; + + //criteria5["HasProvidingInterface"] = "MetricDerivativeInterface"; + criteria5.insert(CriterionType("HasProvidingInterface", ParameterValueType(1, "MetricDerivativeInterface"))); //criteria3["HasDerivative"] = "True"; NodePointer Node5 = ComponentSelector::New(); Node5->SetCriteria(criteria5); @@ -171,7 +184,8 @@ TEST_F(ComponentFactoryTest, InterfacedObjects) CriteriaType criteria6; // Criteria could be name or other properties - criteria6["NameOfClass"] = "SSDMetric4thPartyComponent"; + //criteria6["NameOfClass"] = "SSDMetric4thPartyComponent"; + criteria6.insert(CriterionType("NameOfClass", ParameterValueType(1, "SSDMetric4thPartyComponent"))); //criteria3["HasDerivative"] = "True"; NodePointer Node6 = ComponentSelector::New(); Node6->SetCriteria(criteria6); diff --git a/Testing/Unit/elxOverlordTest.cxx b/Testing/Unit/elxOverlordTest.cxx new file mode 100644 index 0000000000000000000000000000000000000000..e18ba0d6d76fb8460c2758d32092a62a4fb3630a --- /dev/null +++ b/Testing/Unit/elxOverlordTest.cxx @@ -0,0 +1,76 @@ +#include "Overlord.h" + +//#include "ComponentFactory.h" +#include "TransformComponent1.h" +#include "MetricComponent1.h" +#include "GDOptimizer3rdPartyComponent.h" +#include "GDOptimizer4thPartyComponent.h" +#include "SSDMetric3rdPartyComponent.h" +#include "SSDMetric4thPartyComponent.h" + + +#include "gtest/gtest.h" + +namespace selx { + +class OverlordTest : public ::testing::Test { +public: + typedef Overlord::Pointer OverlordPointerType; + typedef Blueprint::Pointer BlueprintPointerType; + typedef Blueprint::ConstPointer BlueprintConstPointerType; + typedef Blueprint::ComponentIndexType ComponentIndexType; + typedef Blueprint::ParameterMapType ParameterMapType; + typedef Blueprint::ParameterValueType ParameterValueType; + + virtual void SetUp() { + /** register all example components */ + ComponentFactory<TransformComponent1>::RegisterOneFactory(); + ComponentFactory<MetricComponent1>::RegisterOneFactory(); + ComponentFactory<GDOptimizer3rdPartyComponent>::RegisterOneFactory(); + ComponentFactory<GDOptimizer4thPartyComponent>::RegisterOneFactory(); + ComponentFactory<SSDMetric3rdPartyComponent>::RegisterOneFactory(); + ComponentFactory<SSDMetric4thPartyComponent>::RegisterOneFactory(); + + /** make example blueprint configuration */ + blueprint = Blueprint::New(); + ParameterMapType metricComponentParameters; + metricComponentParameters["NameOfClass"] = ParameterValueType(1, "MetricComponent1"); + + ParameterMapType transformComponentParameters; + transformComponentParameters["NameOfClass"] = ParameterValueType(1, "TransformComponent1"); + + ComponentIndexType index0 = blueprint->AddComponent(metricComponentParameters); + ComponentIndexType index1 = blueprint->AddComponent(transformComponentParameters); + + ParameterMapType metric2TransformConnectionParameters; + metric2TransformConnectionParameters["NameOfInterface"] = ParameterValueType(1, "TransformedImageInterface"); + + //TODO: check direction + blueprint->AddConnection(index1, index0, metric2TransformConnectionParameters); + + } + + virtual void TearDown() { + itk::ObjectFactoryBase::UnRegisterAllFactories(); + } + + BlueprintPointerType blueprint; + Overlord::Pointer overlord; +}; + +TEST_F( OverlordTest, Create ) +{ + EXPECT_NO_THROW( overlord = Overlord::New() ); + EXPECT_NO_THROW( overlord->SetBlueprint(blueprint) ); +} + +TEST_F(OverlordTest, Configure) +{ + overlord = Overlord::New(); + overlord->SetBlueprint(blueprint); + bool allUniqueComponents; + EXPECT_NO_THROW(allUniqueComponents = overlord->Configure()); + EXPECT_TRUE(allUniqueComponents); +} + +} // namespace elx