diff --git a/.gitignore b/.gitignore index 4befed30a1c63e1cd7071109bbaae5f687c583f4..0e6f6bcc574f16ceb9a964ebc4b591e1af987127 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .DS_Store .idea +.kdev4 \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 80eb02fe4056453cbf255c088725c411ff96fd89..41a0ed33869e7e0a8db3864fbc36d2a879f738c3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,23 +12,25 @@ compiler: - gcc before_install: - - pwd - - date -u - - uname -a + - if [ "${TRAVIS_OS_NAME}" == "linux" ]; then sudo add-apt-repository ppa:george-edison55/cmake-3.x -y; fi + - if [ "${TRAVIS_OS_NAME}" == "osx" ]; then brew update; fi - # Out-of-source build - - cd .. - - mkdir SuperElastix-build - - cd SuperElastix-build +install: + - if [ "${TRAVIS_OS_NAME}" == "linux" ]; then sudo apt-get upgrade; fi + - if [ "${TRAVIS_OS_NAME}" == "osx" ]; then brew upgrade cmake; fi before_script: - export OMP_NUM_THREADS=2 - echo $OMP_NUM_THREADS + # Out-of-source build + - cd .. + - mkdir SuperElastix-build + - cd SuperElastix-build script: - cmake ../SuperElastix/SuperBuild - - make --jobs=2 | grep -v '^--' | grep -v '^Installing' | grep -v '^common' + - make | grep -v '^-- Installing' after_success: - - cd Elastix-build + - cd SuperElastix-build - ctest diff --git a/CMake/elxWinConfig.cmake b/CMake/elxWinConfig.cmake deleted file mode 100644 index e0b1b38c129f9632c7c919475551c72a54c8bdf7..0000000000000000000000000000000000000000 --- a/CMake/elxWinConfig.cmake +++ /dev/null @@ -1,18 +0,0 @@ -# Visual Studio complains if paths are too long -string( LENGTH "${CMAKE_CURRENT_SOURCE_DIR}" n ) -if( n GREATER 50 ) -message( - FATAL_ERROR - "Source code directory path length is too long for MSVC (${n} > 50)." - "Please move the source code directory to a directory with a shorter path." - ) -endif() - -string( LENGTH "${CMAKE_CURRENT_BINARY_DIR}" n ) -if( n GREATER 50 ) -message( - FATAL_ERROR - "Build directory path length is too long for MSVC (${n} > 50)." - "Please move the build directory to a directory with a shorter path." - ) -endif() \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index b47c76b0c30535473657c353ba6b5968ff7ae99a..eca368899867c67de24406d4b4c3aa4586ffa326 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,11 @@ -cmake_minimum_required( VERSION 2.8 ) +cmake_minimum_required( VERSION 3.0.2 ) # Explicitly add INCREMENTAL linking option to command lines. # http://www.cmake.org/pipermail/cmake/2010-February/035174.html #set( MSVC_INCREMENTAL_DEFAULT ON ) # --------------------------------------------------------------------- -project( Elastix ) +project( SuperElastix ) enable_language(C) enable_language(CXX) @@ -19,9 +19,36 @@ set( CMAKE_RUNTIME_OUTPUT_DIRECTORY # Include SuperElastix CMake scripts list( APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake" ) +# ----------------------------------------------------------------- +# Compiler-dependent settings +# GCC +if( ${CMAKE_CXX_COMPILER_ID} STREQUAL GNU ) + add_definitions( + -DVCL_CAN_STATIC_CONST_INIT_FLOAT=0 + -DVCL_CAN_STATIC_CONST_INIT_INT=0 + ) +endif() + +# MSVC if( ${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC ) - include( elxWinConfig ) + string( LENGTH "${CMAKE_CURRENT_SOURCE_DIR}" n ) + if( n GREATER 50 ) + message( + FATAL_ERROR + "Source code directory path length is too long for MSVC (${n} > 50)." + "Please move the source code directory to a directory with a shorter path." + ) + endif() + + string( LENGTH "${CMAKE_CURRENT_BINARY_DIR}" n ) + if( n GREATER 50 ) + message( + FATAL_ERROR + "Build directory path length is too long for MSVC (${n} > 50)." + "Please move the build directory to a directory with a shorter path." + ) + endif() endif() # --------------------------------------------------------------------- @@ -36,6 +63,16 @@ include("${CMAKE_CURRENT_SOURCE_DIR}/CMake/elxRequiredITKModules.cmake") find_package( Boost REQUIRED ) include_directories( ${Boost_INCLUDE_DIRS} ) +# --------------------------------------------------------------------- +# OpenMP Library +# Required for ElastixComponent +# gcc needs the appropriate flags to support OpenMP +find_package(OpenMP) +if (OPENMP_FOUND) + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") +endif() + # --------------------------------------------------------------------- # Build SuperElastix diff --git a/Modules/Components/Elastix/ModuleElastix.cmake b/Modules/Components/Elastix/ModuleElastix.cmake index 3cb0e879b634ca731621186036039ef38a297a47..4d54550cce7922242e43706778cd745a47d29829 100644 --- a/Modules/Components/Elastix/ModuleElastix.cmake +++ b/Modules/Components/Elastix/ModuleElastix.cmake @@ -8,6 +8,14 @@ endif() include( ${ELASTIX_USE_FILE} ) +# If OpenMP is supported by this machine, elastix will be compiled with +# OpenMP flags, and we need to add them here as well +find_package( OpenMP ) +if (OPENMP_FOUND) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}" ) + set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}" ) +endif() + # Export include files set( ${MODULE}_INCLUDE_DIRS ${${MODULE}_SOURCE_DIR}/include diff --git a/Modules/Core/ComponentInterface/include/ComponentBase.h b/Modules/Core/ComponentInterface/include/ComponentBase.h index a84aef60d94f19902f13f0becf0ea9757c9bfac6..cfbbcec875f7b720331a10c8ddbc662a23dbcf8f 100644 --- a/Modules/Core/ComponentInterface/include/ComponentBase.h +++ b/Modules/Core/ComponentInterface/include/ComponentBase.h @@ -1,18 +1,50 @@ #ifndef ComponentBase_h #define ComponentBase_h +#include "itkLightObject.h" + +#include "itkObjectFactory.h" +//#include "itkComponentBase.h" +#include <list> #include <iostream> +#include <fstream> +#include <string> #include <cstring> -namespace elx +#include <map> + +namespace selx { - enum interfaceStatus { success, noaccepter, noprovider }; - class ComponentBase { + class ComponentBase : public itk::LightObject + { public: + /** Standard class typedefs */ + typedef ComponentBase Self; + typedef itk::LightObject Superclass; + typedef itk::SmartPointer< Self > Pointer; + + /** 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; + + enum interfaceStatus { success, noaccepter, noprovider }; + virtual interfaceStatus ConnectFrom(const char *, ComponentBase*) = 0; virtual int ConnectFrom(ComponentBase*) = 0; - //protected: + bool MeetsCriteria(const CriteriaType &criteria); + + virtual bool MeetsCriterium(const CriteriumType &criterium) = 0; + protected: + virtual bool HasAcceptingInterface(const char *) = 0; + virtual bool HasProvidingInterface(const char *) = 0; + ComponentBase() {}; virtual ~ComponentBase() {}; + }; -} // end namespace elx -#endif // #define ComponentBase_h \ No newline at end of file + +} // end namespace selx + + +#endif // ComponentBase_h diff --git a/Modules/Core/ComponentInterface/include/ComponentFactory.h b/Modules/Core/ComponentInterface/include/ComponentFactory.h new file mode 100644 index 0000000000000000000000000000000000000000..170b73cb86dfcece155c05a60386c645faa8644e --- /dev/null +++ b/Modules/Core/ComponentInterface/include/ComponentFactory.h @@ -0,0 +1,73 @@ +/*========================================================================= + * + * Copyright Insight Software Consortium + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0.txt + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *=========================================================================*/ +#ifndef ComponentFactory_h +#define ComponentFactory_h + +#include "ComponentSelector.h" +#include "ComponentBase.h" + +namespace selx +{ +/** \class MetricComponent1Factory + * \brief Create instances of MetaImageIO objects using an object factory. + * \ingroup ITKIOMeta + */ + template <class ComponentT> + class ComponentFactory : public itk::ObjectFactoryBase +{ +public: + /** Standard class typedefs. */ + typedef ComponentFactory Self; + typedef itk::ObjectFactoryBase Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + /** Class methods used to interface with the registered factories. */ + virtual const char * GetITKSourceVersion() const ITK_OVERRIDE; + + virtual const char * GetDescription() const ITK_OVERRIDE; + + /** Method for class instantiation. */ + itkFactorylessNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(ComponentFactory, ObjectFactoryBase); + + /** Register one factory of this type */ + static void RegisterOneFactory() + { + Pointer thisFactory = Self::New(); + + ObjectFactoryBase::RegisterFactory(thisFactory); + } + +protected: + ComponentFactory(); + ~ComponentFactory() {}; + +private: + ComponentFactory(const Self &); //purposely not implemented + void operator=(const Self &); //purposely not implemented +}; +} // end namespace selx + + +#ifndef ITK_MANUAL_INSTANTIATION +#include "ComponentFactory.hxx" +#endif +#endif diff --git a/Modules/Core/ComponentInterface/include/ComponentFactory.hxx b/Modules/Core/ComponentInterface/include/ComponentFactory.hxx new file mode 100644 index 0000000000000000000000000000000000000000..f152a290dbec5ff13b7c2ade5ac495fe16828050 --- /dev/null +++ b/Modules/Core/ComponentInterface/include/ComponentFactory.hxx @@ -0,0 +1,61 @@ +/*========================================================================= + * + * Copyright Insight Software Consortium + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0.txt + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *=========================================================================*/ +#include "ComponentFactory.h" +//#include "itkMetricComponent1.h" +#include "itkVersion.h" +//#include "ComponentTraits.h" +#include <typeinfo> +namespace selx +{ + +template<class ComponentT> +ComponentFactory<ComponentT>::ComponentFactory() +{ + this->RegisterOverride( "ComponentBase", + typeid(ComponentT).name(), //(&ComponentT)->GetNameOfClass(), // + ComponentT::GetDescription(), + 1, + itk::CreateObjectFunction< ComponentT >::New()); +} +template<class ComponentT> +const char * ComponentFactory<ComponentT>::GetITKSourceVersion() const +{ + return ITK_SOURCE_VERSION; +} + +template<class ComponentT> +const char * ComponentFactory<ComponentT>::GetDescription() const +{ + return ComponentT::GetDescription(); //TODO should this be the description of the factory instead of the component? +} + +// Undocumented API used to register during static initialization. +// DO NOT CALL DIRECTLY. +/* +static bool MetricComponent1FactoryHasBeenRegistered; + +void MetricComponent1FactoryRegister__Private(void) +{ + if( ! MetricComponent1FactoryHasBeenRegistered ) + { + MetricComponent1FactoryHasBeenRegistered = true; + MetricComponent1Factory::RegisterOneFactory(); + } +} +*/ +} // end namespace selx diff --git a/Modules/Core/Install/include/itkComponentFactory.h b/Modules/Core/ComponentInterface/include/ComponentSelector.h similarity index 78% rename from Modules/Core/Install/include/itkComponentFactory.h rename to Modules/Core/ComponentInterface/include/ComponentSelector.h index b1bbaa58b6ae6f483dd76aacbe31d4962e52b4d4..f4cae7d060d452fdde24bd154640631bf6f0eeae 100644 --- a/Modules/Core/Install/include/itkComponentFactory.h +++ b/Modules/Core/ComponentInterface/include/ComponentSelector.h @@ -15,33 +15,33 @@ * limitations under the License. * *=========================================================================*/ -#ifndef itkComponentFactory_h -#define itkComponentFactory_h +#ifndef itkComponentSelector_h +#define itkComponentSelector_h #include "itkObjectFactory.h" -#include "itkComponentBase.h" +#include "ComponentBase.h" -namespace itk +namespace selx { /** \class ComponentFactor * \brief Create instances of MetaImageIO objects using an object factory. * \ingroup ITKIOMeta */ -class ComponentFactory:public Object +class ComponentSelector:public itk::Object { public: /** Standard class typedefs. */ - typedef ComponentFactory Self; + typedef ComponentSelector Self; typedef Object Superclass; - typedef SmartPointer< Self > Pointer; - typedef SmartPointer< const Self > ConstPointer; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; /** Class methods used to interface with the registered factories. */ //virtual const char * GetITKSourceVersion() const { return ITK_SOURCE_VERSION; } /** Run-time type information (and related methods). */ - itkTypeMacro(ComponentFactory, Object); + itkTypeMacro(ComponentSelector, Object); /** New macro for creation of through the object factory. */ itkNewMacro(Self); @@ -60,26 +60,23 @@ public: void UpdatePossibleComponents(void); - /** Create the appropriate ComponentIO depending on - * the particulars of the file. - */ ComponentBasePointer GetComponent(void); protected: mutable CriteriaType m_Criteria; mutable ComponentListType m_PossibleComponents; - ComponentFactory(); - ~ComponentFactory(); + ComponentSelector(); + ~ComponentSelector(); private: - ComponentFactory(const Self &); //purposely not implemented + ComponentSelector(const Self &); //purposely not implemented void operator=(const Self &); //purposely not implemented }; -} // end namespace itk +} // end namespace selx #ifndef ITK_MANUAL_INSTANTIATION -#include "itkComponentFactory.hxx" +#include "ComponentSelector.hxx" #endif #endif diff --git a/Modules/Core/Install/include/itkComponentFactory.hxx b/Modules/Core/ComponentInterface/include/ComponentSelector.hxx similarity index 71% rename from Modules/Core/Install/include/itkComponentFactory.hxx rename to Modules/Core/ComponentInterface/include/ComponentSelector.hxx index 4f4021f6598c8c4c5dc6c778c0c76bb7145d7a66..252a6fcaa4d962fa4426df29930f8bb39b0f01fd 100644 --- a/Modules/Core/Install/include/itkComponentFactory.hxx +++ b/Modules/Core/ComponentInterface/include/ComponentSelector.hxx @@ -15,28 +15,28 @@ * limitations under the License. * *=========================================================================*/ -#ifndef itkComponentFactory_hxx -#define itkComponentFactory_hxx +#ifndef itkComponentSelector_hxx +#define itkComponentSelector_hxx -#include "itkComponentFactory.h" +#include "ComponentSelector.h" -namespace itk +namespace selx { -ComponentFactory::ComponentFactory() +ComponentSelector::ComponentSelector() { this->m_PossibleComponents.clear(); } -ComponentFactory::~ComponentFactory() +ComponentSelector::~ComponentSelector() { } -void ComponentFactory::Initialize() +void ComponentSelector::Initialize() { - std::list< LightObject::Pointer > allobjects = - ObjectFactoryBase::CreateAllInstance("itkComponentBase"); + std::list< itk::LightObject::Pointer > allobjects = + itk::ObjectFactoryBase::CreateAllInstance("ComponentBase"); - for (std::list< LightObject::Pointer >::iterator i = allobjects.begin(); + for (std::list< itk::LightObject::Pointer >::iterator i = allobjects.begin(); i != allobjects.end(); ++i) { ComponentBase *io = @@ -47,7 +47,7 @@ void ComponentFactory::Initialize() } } } -void ComponentFactory::SetCriteria(const CriteriaType &criteria) +void ComponentSelector::SetCriteria(const CriteriaType &criteria) { this->Initialize(); this->m_Criteria = criteria; @@ -55,7 +55,7 @@ void ComponentFactory::SetCriteria(const CriteriaType &criteria) } -void ComponentFactory::AddCriteria(const CriteriaType &criteria) +void ComponentSelector::AddCriteria(const CriteriaType &criteria) { this->m_Criteria.insert(criteria.begin(), criteria.end()); this->Modified(); @@ -66,13 +66,13 @@ void ComponentFactory::AddCriteria(const CriteriaType &criteria) // bool operator() (const ComponentBasePointer& component) { return !component->MeetsCriteria(this->m_Criteria) } //}; -void ComponentFactory::UpdatePossibleComponents() +void 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); }); } -ComponentFactory::ComponentBasePointer ComponentFactory::GetComponent() +ComponentSelector::ComponentBasePointer ComponentSelector::GetComponent() { //TODO check if Modified this->UpdatePossibleComponents(); @@ -86,6 +86,6 @@ ComponentFactory::ComponentBasePointer ComponentFactory::GetComponent() return ITK_NULLPTR; } } -} // end namespace itk +} // end namespace selx #endif diff --git a/Modules/Core/ComponentInterface/include/ComponentTraits.h b/Modules/Core/ComponentInterface/include/ComponentTraits.h new file mode 100644 index 0000000000000000000000000000000000000000..6f4235ec2857a83d36fb2517372b41e11201fcc9 --- /dev/null +++ b/Modules/Core/ComponentInterface/include/ComponentTraits.h @@ -0,0 +1,46 @@ +#ifndef ComponentTraits_h +#define ComponentTraits_h + +#include "GDOptimizer3rdPartyComponent.h" + +namespace selx +{ +// Traits to get printable interface name +// default implementation +template <typename T> +struct ComponentTraits +{ + //static_assert(false, "Please implement a template specialization for the appropriate Component"); + + // I would like to be it a real Trait but this is not allowed: + //static const char* Name = "ERROR: Please implement Name"; + //a static data member with an in - class initializer must have non - volatile const integral type + static const char* GetDescription() + { + return "ERROR: Please implement Description"; + } + static const char* GetName() + { + return "ERROR: Please implement Name"; + } + +}; + +// a specialization for each type of those you want to support +// and don't like the string returned by typeid +template <> +struct InterfaceName < GDOptimizer3rdPartyComponent > +{ + static const char* GetDescription() + { + return "GD Optimizer 3rdParty Component"; + } + static const char* GetName() + { + return "GDOptimizer3rdPartyComponent"; + } +}; +} // end namespace selx + + +#endif // #define ComponentTraits_h \ No newline at end of file diff --git a/Modules/Core/ComponentInterface/include/GDOptimizer3rdPartyComponent.h b/Modules/Core/ComponentInterface/include/GDOptimizer3rdPartyComponent.h deleted file mode 100644 index 1d281e9b9fa7541e14721693433c8f307937578a..0000000000000000000000000000000000000000 --- a/Modules/Core/ComponentInterface/include/GDOptimizer3rdPartyComponent.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef GDOptimizer3rdPartyComponent_h -#define GDOptimizer3rdPartyComponent_h - -#include "ComponentBase.h" -#include "Interfaces.hxx" -#include "Example3rdPartyCode.h" -#include "Metric3rdPartyWrapper.h" -#include <string.h> - -namespace elx -{ - - class GDOptimizer3rdPartyComponent : - public Implements< - Accepting< MetricValueInterface, MetricDerivativeInterface >, - Providing< OptimizerUpdateInterface> - > - { - public: - GDOptimizer3rdPartyComponent(); - virtual ~GDOptimizer3rdPartyComponent(); - Example3rdParty::GDOptimizer3rdParty* theImplementation; - Metric3rdPartyWrapper* MetricObject; - //virtual int ConnectFrom(const char *, ComponentBase*); - int Set(MetricValueInterface*); - int Set(MetricDerivativeInterface*); - int Update(); - }; -} //end namespace elx -#endif // #define GDOptimizer3rdPartyComponent_h \ No newline at end of file diff --git a/Modules/Core/ComponentInterface/include/GDOptimizer4thPartyComponent.h b/Modules/Core/ComponentInterface/include/GDOptimizer4thPartyComponent.h deleted file mode 100644 index eff1bb78cd856c4f9b6ae6088c2b5d555fb05077..0000000000000000000000000000000000000000 --- a/Modules/Core/ComponentInterface/include/GDOptimizer4thPartyComponent.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef GDOptimizer4thPartyComponent_h -#define GDOptimizer4thPartyComponent_h - -#include "ComponentBase.h" -#include "Interfaces.hxx" -#include "Example4thPartyCode.h" -#include "Metric4thPartyWrapper.h" - -namespace elx -{ - // wrapping into components: - class GDOptimizer4thPartyComponent : - public Implements < - Accepting< MetricValueInterface >, - Providing < OptimizerUpdateInterface > - > - - { - public: - GDOptimizer4thPartyComponent(); - virtual ~GDOptimizer4thPartyComponent(); - Example4thParty::GDOptimizer4thParty* theImplementation; - Metric4thPartyWrapper* MetricObject; - //virtual int ConnectFrom(const char *, ComponentBase*); - int Set(MetricValueInterface*); - int Update(); - }; - -} //end namespace elx -#endif // #define GDOptimizer4thPartyComponent_h \ No newline at end of file diff --git a/Modules/Core/ComponentInterface/include/InterfaceTraits.h b/Modules/Core/ComponentInterface/include/InterfaceTraits.h index 5dd03ec37bccab68b6be2b1450cb6d588532d0e5..0333755f4d8014c918bbeb1a92be225af4dd732e 100644 --- a/Modules/Core/ComponentInterface/include/InterfaceTraits.h +++ b/Modules/Core/ComponentInterface/include/InterfaceTraits.h @@ -3,7 +3,7 @@ #include "Interfaces.h" -namespace elx +namespace selx { // Traits to get printable interface name // default implementation @@ -12,6 +12,7 @@ struct InterfaceName { static const char* Get() { + //static_assert(false, "Please implement a template specialization for the appropriate InterfaceName"); return typeid(T).name(); } }; @@ -43,6 +44,25 @@ struct InterfaceName < OptimizerUpdateInterface > } }; +template <> +struct InterfaceName < ConflictinUpdateInterface > +{ + static const char* Get() + { + return "ConflictinUpdateInterface"; + } +}; + +template <> +struct InterfaceName < TransformedImageInterface > +{ + static const char* Get() + { + return "TransformedImageInterface"; + } +}; + + // partial specialization of InterfaceName template<template<typename> class TT, typename T1> @@ -63,7 +83,7 @@ struct AcceptorInterfaceName } }; -} // end namespace elx +} // end namespace selx #endif // #define InterfaceTraits_h \ No newline at end of file diff --git a/Modules/Core/ComponentInterface/include/Interfaces.h b/Modules/Core/ComponentInterface/include/Interfaces.h index 281d763d3ebbaf8608afb70fd02bdf98b0b9ce57..47938c2f66316599935a654af60cb596985c9a9f 100644 --- a/Modules/Core/ComponentInterface/include/Interfaces.h +++ b/Modules/Core/ComponentInterface/include/Interfaces.h @@ -2,74 +2,118 @@ #define Interfaces_h #include "ComponentBase.h" -#include "InterfaceTraits.h" #include <typeinfo> +#include <string> -namespace elx +namespace selx { -// Define the providing interfaces abstractly -class MetricDerivativeInterface { + // Define the providing interfaces abstractly + class MetricDerivativeInterface { public: virtual int GetDerivative() = 0; -}; + }; -class MetricValueInterface { + class MetricValueInterface { public: virtual int GetValue() = 0; -}; + }; -class OptimizerUpdateInterface { -public: - virtual int Update() = 0; -}; + class OptimizerUpdateInterface { + public: + virtual int Update() = 0; + }; -// Define the accepting interfaces as templated by the providing interface + class TransformedImageInterface { + public: + virtual int GetTransformedImage() = 0; + }; -template<class InterfaceT> -class InterfaceAcceptor { -public: + class ConflictinUpdateInterface { + public: + // "error" : member function templates cannot be virtual + // template <class ConflictinUpdateInterface> virtual int Update() = 0; + //TODO http://en.cppreference.com/w/cpp/language/member_template - // Set() is called by a succesfull Connect() - // The implementation of Set() must be provided by component developers. - virtual int Set(InterfaceT*) = 0; + //TODO solution: http://stackoverflow.com/questions/2004820/inherit-interfaces-which-share-a-method-name + //TODO better?: http://stackoverflow.com/questions/18398409/c-inherit-from-multiple-base-classes-with-the-same-virtual-function-name + virtual int Update(ConflictinUpdateInterface*) = 0; + }; - // Connect tries to connect this accepting interface with all interfaces of the provider component. - int Connect(ComponentBase*); -private: - bool isSet; -}; + + // Define the accepting interfaces as templated by the providing interface + + template<class InterfaceT> + class InterfaceAcceptor { + public: + + // Set() is called by a succesfull Connect() + // The implementation of Set() must be provided by component developers. + virtual int Set(InterfaceT*) = 0; + + // Connect tries to connect this accepting interface with all interfaces of the provider component. + int Connect(ComponentBase*); + + private: + bool isSet; + }; template<typename ... RestInterfaces> class Accepting { public: - interfaceStatus ConnectFromImpl(const char *, ComponentBase*) { return interfaceStatus::noaccepter; }; //no interface called interfacename ; + ComponentBase::interfaceStatus ConnectFromImpl(const char *, ComponentBase*) { return ComponentBase::interfaceStatus::noaccepter; }; //no interface called interfacename ; int ConnectFromImpl(ComponentBase*) { return 0; }; //Empty RestInterfaces does 0 successful connects ; +protected: + bool HasInterface(const char *) { return false; }; }; template<typename FirstInterface, typename ... RestInterfaces> class Accepting<FirstInterface, RestInterfaces... > : public InterfaceAcceptor<FirstInterface>, public Accepting< RestInterfaces ... > { public: - interfaceStatus ConnectFromImpl(const char *, ComponentBase*); + ComponentBase::interfaceStatus ConnectFromImpl(const char *, ComponentBase*); int ConnectFromImpl(ComponentBase*); +protected: + bool HasInterface(const char *); + }; -template<typename... Interfaces> -class Providing : public Interfaces... +template<typename ... RestInterfaces> +class Providing { +protected: + bool HasInterface(const char *) { return false; }; }; +template<typename FirstInterface, typename ... RestInterfaces> +class Providing<FirstInterface, RestInterfaces... > : public FirstInterface, public Providing < RestInterfaces ... > +{ +protected: + bool HasInterface(const char *); + +}; + +//template<typename... Interfaces> +//class Providing : public Interfaces... +//{ +//}; + template<typename AcceptingInterfaces, typename ProvidingInterfaces> class Implements : public AcceptingInterfaces, public ProvidingInterfaces, public ComponentBase { public: virtual interfaceStatus ConnectFrom(const char *, ComponentBase*); virtual int ConnectFrom(ComponentBase*); +protected: + virtual bool HasAcceptingInterface(const char *); + virtual bool HasProvidingInterface(const char *); }; -} // end namespace elx + + + +} // end namespace selx #ifndef ITK_MANUAL_INSTANTIATION #include "Interfaces.hxx" diff --git a/Modules/Core/ComponentInterface/include/Interfaces.hxx b/Modules/Core/ComponentInterface/include/Interfaces.hxx index cade1ce157abcb8b48165d0993ff80785a50d2dd..e54719b8b7cc5c8215b5de3c74967f888993454a 100644 --- a/Modules/Core/ComponentInterface/include/Interfaces.hxx +++ b/Modules/Core/ComponentInterface/include/Interfaces.hxx @@ -2,7 +2,7 @@ #define Interfaces_hxx #include "InterfaceTraits.h" -namespace elx +namespace selx { template<class InterfaceT> int InterfaceAcceptor<InterfaceT>::Connect(ComponentBase* providerComponent){ @@ -10,16 +10,17 @@ int InterfaceAcceptor<InterfaceT>::Connect(ComponentBase* providerComponent){ InterfaceT* providerInterface = dynamic_cast<InterfaceT*> (providerComponent); if (!providerInterface) { - std::cout << "providerComponent does not have required " << InterfaceName < InterfaceT >::Get() << std::endl; + //TODO log message? + //std::cout << "providerComponent does not have required " << InterfaceName < InterfaceT >::Get() << std::endl; return 0; } // connect value interfaces this->Set(providerInterface); // due to the input argument being uniquely defined in the multiple inheritance tree, all versions of Set() are accessible at component level return 1; } - +////////////////////////////////////////////////////////////////////////// template<typename AcceptingInterfaces, typename ProvidingInterfaces> -interfaceStatus Implements<AcceptingInterfaces, ProvidingInterfaces>::ConnectFrom(const char * interfacename, ComponentBase* other) +ComponentBase::interfaceStatus Implements<AcceptingInterfaces, ProvidingInterfaces>::ConnectFrom(const char * interfacename, ComponentBase* other) { return AcceptingInterfaces::ConnectFromImpl(interfacename, other); } @@ -30,25 +31,38 @@ int Implements<AcceptingInterfaces, ProvidingInterfaces>::ConnectFrom(ComponentB return AcceptingInterfaces::ConnectFromImpl(other); } +template<typename AcceptingInterfaces, typename ProvidingInterfaces> +bool Implements<AcceptingInterfaces, ProvidingInterfaces>::HasAcceptingInterface(const char * interfacename) +{ + return AcceptingInterfaces::HasInterface(interfacename); +} + +template<typename AcceptingInterfaces, typename ProvidingInterfaces> +bool Implements<AcceptingInterfaces, ProvidingInterfaces>::HasProvidingInterface(const char * interfacename) +{ + return ProvidingInterfaces::HasInterface(interfacename); +} + +////////////////////////////////////////////////////////////////////////// template<typename FirstInterface, typename ... RestInterfaces> -interfaceStatus Accepting<FirstInterface, RestInterfaces... >::ConnectFromImpl(const char * interfacename, ComponentBase* other) +ComponentBase::interfaceStatus Accepting<FirstInterface, RestInterfaces... >::ConnectFromImpl(const char * interfacename, ComponentBase* other) { // does our component have an accepting interface called interfacename? - if (0 ==std::strcmp(InterfaceName<InterfaceAcceptor<FirstInterface>>::Get(), interfacename)) + if (0 ==strcmp(InterfaceName<InterfaceAcceptor<FirstInterface>>::Get(), interfacename)) { - // static_cast always succeeds since we know via the template arguments of the component which InterfaceAcceptors its base classes are. - InterfaceAcceptor<FirstInterface>* acceptIF = static_cast<InterfaceAcceptor<FirstInterface>*> (this); + // cast always succeeds since we know via the template arguments of the component which InterfaceAcceptors its base classes are. + InterfaceAcceptor<FirstInterface>* acceptIF = this; // See if the other component has the right interface and try to connect them if (1 == acceptIF->Connect(other)) { //success. By terminating this function, we assume only one interface listens to interfacename and that one connection with the other component can be made by this name - return interfaceStatus::success; + return ComponentBase::interfaceStatus::success; } else { // interfacename was found, but other component doesn't match - return interfaceStatus::noprovider; + return ComponentBase::interfaceStatus::noprovider; } } return Accepting< RestInterfaces ... >::ConnectFromImpl(interfacename, other); @@ -57,15 +71,35 @@ interfaceStatus Accepting<FirstInterface, RestInterfaces... >::ConnectFromImpl(c template<typename FirstInterface, typename ... RestInterfaces> int Accepting<FirstInterface, RestInterfaces... >::ConnectFromImpl(ComponentBase* other) { - // static_cast always succeeds since we know via the template arguments of the component which InterfaceAcceptors its base classes are. - InterfaceAcceptor<FirstInterface>* acceptIF = static_cast<InterfaceAcceptor<FirstInterface>*> (this); + // cast always succeeds since we know via the template arguments of the component which InterfaceAcceptors its base classes are. + InterfaceAcceptor<FirstInterface>* acceptIF = (this); // See if the other component has the right interface and try to connect them // count the number of successes return acceptIF->Connect(other) + Accepting< RestInterfaces ... >::ConnectFromImpl(other); } -} // end namespace elx +template<typename FirstInterface, typename ... RestInterfaces> +bool Accepting<FirstInterface, RestInterfaces... >::HasInterface(const char* interfacename) +{ + if (0 == strcmp(InterfaceName<InterfaceAcceptor<FirstInterface>>::Get(), interfacename)) + { + return true; + } + return Accepting< RestInterfaces ... >::HasInterface(interfacename); +} + +template<typename FirstInterface, typename ... RestInterfaces> +bool Providing<FirstInterface, RestInterfaces... >::HasInterface(const char* interfacename) +{ + if (0 == strcmp(InterfaceName<FirstInterface>::Get(), interfacename)) + { + return true; + } + return Providing< RestInterfaces ... >::HasInterface(interfacename); +} + +} // end namespace selx #endif // #define Interfaces_hxx \ No newline at end of file diff --git a/Modules/Core/ComponentInterface/include/SSDMetric3rdPartyComponent.h b/Modules/Core/ComponentInterface/include/SSDMetric3rdPartyComponent.h deleted file mode 100644 index 860398a559b4862de5c5a9bc923e669b652b8f04..0000000000000000000000000000000000000000 --- a/Modules/Core/ComponentInterface/include/SSDMetric3rdPartyComponent.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef SSDMetric3rdPartyComponent_h -#define SSDMetric3rdPartyComponent_h - -#include "ComponentBase.h" -#include "Interfaces.hxx" -#include "Example3rdPartyCode.h" - -namespace elx -{ - // SSDMetric3rdPartyComponent provides a value and a derivative - class SSDMetric3rdPartyComponent : - public Implements< - Accepting<>, - Providing< MetricDerivativeInterface, MetricValueInterface> - > - { - public: - SSDMetric3rdPartyComponent(); - virtual ~SSDMetric3rdPartyComponent(); - Example3rdParty::SSDMetric3rdParty* theImplementation; - int GetValue(); - int GetDerivative(); - }; -} //end namespace elx -#endif // #define SSDMetric3rdPartyComponent_h \ No newline at end of file diff --git a/Modules/Core/ComponentInterface/include/SSDMetric4thPartyComponent.h b/Modules/Core/ComponentInterface/include/SSDMetric4thPartyComponent.h deleted file mode 100644 index c07ff0abce595d7f55e6dda9c8aaaed38d19237c..0000000000000000000000000000000000000000 --- a/Modules/Core/ComponentInterface/include/SSDMetric4thPartyComponent.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef SSDMetric4thPartyComponent_h -#define SSDMetric4thPartyComponent_h - -#include "ComponentBase.h" -#include "Interfaces.hxx" -#include "Example4thPartyCode.h" - -namespace elx -{ - // SSDMetric4thPartyComponent provides only a value and not a derivative - class SSDMetric4thPartyComponent : - public Implements< - Accepting<>, - Providing< MetricValueInterface> - > - { - public: - SSDMetric4thPartyComponent(); - virtual ~SSDMetric4thPartyComponent(); - Example4thParty::SSDMetric4thParty* theImplementation; - int GetValue(); - }; -} //end namespace elx -#endif // #define SSDMetric4thPartyComponent_h \ No newline at end of file diff --git a/Modules/Core/ComponentInterface/src/ComponentBase.cxx b/Modules/Core/ComponentInterface/src/ComponentBase.cxx new file mode 100644 index 0000000000000000000000000000000000000000..f6fffb18eabd2c2f2fc33b13dae520de9f75fb24 --- /dev/null +++ b/Modules/Core/ComponentInterface/src/ComponentBase.cxx @@ -0,0 +1,54 @@ +#include "ComponentBase.h" + +namespace selx +{ + + + bool ComponentBase::MeetsCriteria(const CriteriaType &criteria) + { + bool hasUndefinedCriteria(false); + bool meetsCriteria(true); + for (CriteriaType::const_iterator it = criteria.begin(); it != criteria.end(); ++it) + { + if (strcmp(it->first.c_str(), "NameOfClass") == 0) + { + if (strcmp(it->second.c_str(), this->GetNameOfClass()) != 0) + { + meetsCriteria = false; + break; + } + } + else if (strcmp(it->first.c_str(), "HasAcceptingInterface") == 0) + { + if (this->HasAcceptingInterface(it->second.c_str()) != true) + { + meetsCriteria = false; + break; + } + } + else if (strcmp(it->first.c_str(), "HasProvidingInterface") == 0) + { + if (this->HasProvidingInterface(it->second.c_str()) != true) + { + meetsCriteria = false; + break; + } + } + else if (this->MeetsCriterium(CriteriumType(it->first, it->second)) == true) + { + meetsCriteria = true; + + } + else + { + meetsCriteria = false; + hasUndefinedCriteria = true; + break; + } + + } + return meetsCriteria; + } + +} // end namespace selx + diff --git a/Modules/Core/ComponentInterface/src/SSDMetric4thPartyComponent.cxx b/Modules/Core/ComponentInterface/src/SSDMetric4thPartyComponent.cxx deleted file mode 100644 index de00af4de98fdc8b30c74a72d30ee324b90de619..0000000000000000000000000000000000000000 --- a/Modules/Core/ComponentInterface/src/SSDMetric4thPartyComponent.cxx +++ /dev/null @@ -1,18 +0,0 @@ -#include "SSDMetric4thPartyComponent.h" -namespace elx -{ - -SSDMetric4thPartyComponent::SSDMetric4thPartyComponent() -{ - this->theImplementation = new Example4thParty::SSDMetric4thParty(); -} -SSDMetric4thPartyComponent::~SSDMetric4thPartyComponent() -{ - delete this->theImplementation; -} - -int SSDMetric4thPartyComponent::GetValue() -{ - return this->theImplementation->GetCost(); // translate method name -}; -} //end namespace elx \ No newline at end of file diff --git a/Modules/Core/ComponentInterface/src/componenthandshake.cxx b/Modules/Core/ComponentInterface/src/componenthandshake.cxx deleted file mode 100644 index 87492b3421751b307d47297914f09912b6027097..0000000000000000000000000000000000000000 --- a/Modules/Core/ComponentInterface/src/componenthandshake.cxx +++ /dev/null @@ -1,147 +0,0 @@ -#include <iostream> - -// test case: Assume there are two (slightly) incompatible codebases (i.e. 3rd party and 4th! party), each with an optimizer object and a metric object. The example classes of 3rd and 4th party code bases cannot be changed, but the wrapping is in our control. -// goal: make elastix components of all objects and define a handshake that checks if connections can be made. - -#include "SSDMetric3rdPartyComponent.h" -#include "GDOptimizer3rdPartyComponent.h" -#include "SSDMetric4thPartyComponent.h" -#include "GDOptimizer4thPartyComponent.h" - - - -using namespace elx; - int main() { - { - std::cout << InterfaceName<MetricValueInterface>::Get() << std::endl; - - std::cout << AcceptorInterfaceName<InterfaceAcceptor<MetricValueInterface> >::Get() << std::endl; - - std::cout << InterfaceName<InterfaceAcceptor<MetricValueInterface> >::Get() << std::endl; - std::cout << InterfaceName<InterfaceProvider<MetricValueInterface> >::Get() << std::endl; - - - } - { - /************ testing interface casts *********** - * expected: ok - */ - SSDMetric3rdPartyComponent* tempmetric3p = new SSDMetric3rdPartyComponent(); - ComponentBase* metric3p = tempmetric3p; - - MetricValueInterface* valIF = dynamic_cast<MetricValueInterface*> (metric3p); - std::cout << valIF->GetValue() << std::endl; - - MetricDerivativeInterface* derIF = dynamic_cast<MetricDerivativeInterface*> (metric3p); - std::cout << derIF->GetDerivative() << std::endl; - } - /************ Connect metric4p to optimizer4p *********** - * expected: ok - */ - { - SSDMetric4thPartyComponent* tempmetric4p = new SSDMetric4thPartyComponent(); - ComponentBase* metric4p = tempmetric4p; // type returned by our component factory - - GDOptimizer4thPartyComponent* tempOptimizer4p = new GDOptimizer4thPartyComponent(); - ComponentBase* optimizer4p = tempOptimizer4p; // type returned by our component factory - - interfaceStatus IFstatus = optimizer4p->ConnectFrom("MetricValueInterface", metric4p); - - InterfaceAcceptor<MetricValueInterface>* opValIF = dynamic_cast<InterfaceAcceptor<MetricValueInterface>*> (optimizer4p); - if (!opValIF) - { - std::cout << "optimizer4p has no OptimizerValueInterface" << std::endl; - } - - // connect value interfaces - opValIF->Connect(metric4p); - - OptimizerUpdateInterface* opUpdIF = dynamic_cast<OptimizerUpdateInterface*> (optimizer4p); - if (!opValIF) - { - std::cout << "optimizer4p has no OptimizerUpdateInterface" << std::endl; - } - - // Update the optimizer component - opUpdIF->Update(); - } - /************ Connect metric3p to optimizer4p *********** - * expected: ok - * optimizer4p will only use/have access to the GetValue interface of metric3p - */ - { - SSDMetric3rdPartyComponent* tempmetric3p = new SSDMetric3rdPartyComponent(); - ComponentBase* metric3p = tempmetric3p; // type returned by our component factory - - GDOptimizer4thPartyComponent* tempOptimizer4p = new GDOptimizer4thPartyComponent(); - ComponentBase* optimizer4p = tempOptimizer4p; // type returned by our component factory - - InterfaceAcceptor<MetricValueInterface>* opValIF = dynamic_cast<InterfaceAcceptor<MetricValueInterface>*> (optimizer4p); - if (!opValIF) - { - std::cout << "optimizer4p has no OptimizerValueInterface" << std::endl; - } - - // connect value interfaces - if (!opValIF->Connect(metric3p)) - { - std::cout << "metric3p cannot connect to optimizer4p by ValueInterface" << std::endl; - } - - OptimizerUpdateInterface* opUpdIF = dynamic_cast<OptimizerUpdateInterface*> (optimizer4p); - if (!opValIF) - { - std::cout << "optimizer4p has no OptimizerUpdateInterface" << std::endl; - } - - // Update the optimizer component - opUpdIF->Update(); - } - /************ Connect metric4p to optimizer3p *********** - * expected: fail - * optimizer3p needs a metric with GetDerivative which metric4p doesn't have - */ - { - SSDMetric4thPartyComponent* tempmetric4p = new SSDMetric4thPartyComponent(); - ComponentBase* metric4p = tempmetric4p; // type returned by our component factory - - GDOptimizer3rdPartyComponent* tempOptimizer3p = new GDOptimizer3rdPartyComponent(); - ComponentBase* optimizer3p = tempOptimizer3p; // type returned by our component factory - - InterfaceAcceptor<MetricValueInterface>* opValIF = dynamic_cast<InterfaceAcceptor<MetricValueInterface>*> (optimizer3p); - if (!opValIF) - { - std::cout << "optimizer3p has no OptimizerValueInterface" << std::endl; - } - - // connect value interfaces - if (!opValIF->Connect(metric4p)) - { - std::cout << "metric4p cannot connect to optimizer3p by ValueInterface" << std::endl; - } - - //opValIF->Set(tempmetric4p); - - InterfaceAcceptor<MetricDerivativeInterface>* opDerivIF = dynamic_cast<InterfaceAcceptor<MetricDerivativeInterface>*> (optimizer3p); - if (!opDerivIF) - { - std::cout << "optimizer3p has no OptimizerDerivativeInterface" << std::endl; - } - // connect derivative interfaces - if (!opDerivIF->Connect(metric4p)) - { - std::cout << "metric4p cannot connect to optimizer3p by DerivativeInterface" << std::endl; - } - - - OptimizerUpdateInterface* opUpdIF = dynamic_cast<OptimizerUpdateInterface*> (optimizer3p); - if (!opValIF) - { - std::cout << "optimizer3p has no OptimizerUpdateInterface" << std::endl; - } - - // Update the optimizer component - // opUpdIF->Update(); // will fail since the metric does'nt have GetDerivative() - } - return 0; - } diff --git a/Modules/Core/ComponentInterface/include/Example3rdPartyCode.h b/Modules/Core/ExampleComponents/include/Example3rdPartyCode.h similarity index 100% rename from Modules/Core/ComponentInterface/include/Example3rdPartyCode.h rename to Modules/Core/ExampleComponents/include/Example3rdPartyCode.h diff --git a/Modules/Core/ComponentInterface/include/Example4thPartyCode.h b/Modules/Core/ExampleComponents/include/Example4thPartyCode.h similarity index 100% rename from Modules/Core/ComponentInterface/include/Example4thPartyCode.h rename to Modules/Core/ExampleComponents/include/Example4thPartyCode.h diff --git a/Modules/Core/ExampleComponents/include/GDOptimizer3rdPartyComponent.h b/Modules/Core/ExampleComponents/include/GDOptimizer3rdPartyComponent.h new file mode 100644 index 0000000000000000000000000000000000000000..1ac5f923c8e9446fe6878c2ee26c173cc98c3051 --- /dev/null +++ b/Modules/Core/ExampleComponents/include/GDOptimizer3rdPartyComponent.h @@ -0,0 +1,48 @@ +#ifndef GDOptimizer3rdPartyComponent_h +#define GDOptimizer3rdPartyComponent_h + +#include "ComponentBase.h" +#include "Interfaces.h" +#include "Example3rdPartyCode.h" +#include "Metric3rdPartyWrapper.h" +#include <string.h> + +namespace selx +{ + + class GDOptimizer3rdPartyComponent : + public Implements< + Accepting< MetricValueInterface, MetricDerivativeInterface >, + Providing< OptimizerUpdateInterface> + > + { + public: + /** Standard class typedefs. */ + typedef GDOptimizer3rdPartyComponent Self; + typedef ComponentBase Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + /** New macro for creation of through the object factory. */ + itkNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(GDOptimizer3rdPartyComponent, Superclass); + + + GDOptimizer3rdPartyComponent(); + virtual ~GDOptimizer3rdPartyComponent(); + Example3rdParty::GDOptimizer3rdParty* theImplementation; + Metric3rdPartyWrapper* MetricObject; + //virtual int ConnectFrom(const char *, ComponentBase*); + int Set(MetricValueInterface*); + int Set(MetricDerivativeInterface*); + int Update(); + //virtual bool MeetsCriteria(const CriteriaType &criteria); + virtual bool MeetsCriterium(const CriteriumType &criterium); + + //static const char * GetName() { return "GDOptimizer3rdPartyComponent"; } ; + static const char * GetDescription() { return "GD Optimizer 3rd Party Component"; }; + }; +} //end namespace selx +#endif // #define GDOptimizer3rdPartyComponent_h \ No newline at end of file diff --git a/Modules/Core/ExampleComponents/include/GDOptimizer4thPartyComponent.h b/Modules/Core/ExampleComponents/include/GDOptimizer4thPartyComponent.h new file mode 100644 index 0000000000000000000000000000000000000000..8b108d70a8647ce82821baee80b7ddb992c0334f --- /dev/null +++ b/Modules/Core/ExampleComponents/include/GDOptimizer4thPartyComponent.h @@ -0,0 +1,50 @@ +#ifndef GDOptimizer4thPartyComponent_h +#define GDOptimizer4thPartyComponent_h + +#include "ComponentBase.h" +#include "Interfaces.hxx" +#include "Example4thPartyCode.h" +#include "Metric4thPartyWrapper.h" + +namespace selx +{ + // wrapping into components: + class GDOptimizer4thPartyComponent : + public Implements < + Accepting< MetricValueInterface >, + Providing < OptimizerUpdateInterface, ConflictinUpdateInterface > + > + + { + public: + /** Standard class typedefs. */ + typedef GDOptimizer4thPartyComponent Self; + typedef ComponentBase Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + /** New macro for creation of through the object factory. */ + itkNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(GDOptimizer4thPartyComponent, Superclass); + + GDOptimizer4thPartyComponent(); + virtual ~GDOptimizer4thPartyComponent(); + Example4thParty::GDOptimizer4thParty* theImplementation; + Metric4thPartyWrapper* MetricObject; + //virtual int ConnectFrom(const char *, ComponentBase*); + int Set(MetricValueInterface*); + int Update(); + + //template <class ConflictinUpdateInterface> virtual int Update() { return 5; }; + // "error" : member function templates cannot be virtual + int Update(ConflictinUpdateInterface*) { return 5; }; + //virtual bool MeetsCriteria(const CriteriaType &criteria); + virtual bool MeetsCriterium(const CriteriumType &criterium); + //static const char * GetName(){ return "GDOptimizer4thPartyComponent"; }; + static const char * GetDescription(){ return "GD Optimizer 4th Party Component"; }; + }; + +} //end namespace selx +#endif // #define GDOptimizer4thPartyComponent_h \ No newline at end of file diff --git a/Modules/Core/ComponentInterface/include/Metric3rdPartyWrapper.h b/Modules/Core/ExampleComponents/include/Metric3rdPartyWrapper.h similarity index 94% rename from Modules/Core/ComponentInterface/include/Metric3rdPartyWrapper.h rename to Modules/Core/ExampleComponents/include/Metric3rdPartyWrapper.h index 6612b04e15862cf04e0e2e1fbd8ec8dbc5f2c44f..4fbd3d972bbaa1497d1a143ec9b4b727f99b4eea 100644 --- a/Modules/Core/ComponentInterface/include/Metric3rdPartyWrapper.h +++ b/Modules/Core/ExampleComponents/include/Metric3rdPartyWrapper.h @@ -3,7 +3,7 @@ #include "Example3rdPartyCode.h" #include "Interfaces.hxx" -namespace elx +namespace selx { // An Optimizer3rdParty expects that Metric3rdParty will be set as input. All accepted interfaces by the Optimizer3rdPartyCompoment will be delegated to the Metric3rdPartyWrapper object. class Metric3rdPartyWrapper : public Example3rdParty::Metric3rdPartyBase { @@ -16,5 +16,5 @@ private: MetricValueInterface* metricval; MetricDerivativeInterface* metricderiv; }; -} // end namespace elx +} // end namespace selx #endif // #define Metric3rdPartyWrapper_h \ No newline at end of file diff --git a/Modules/Core/ComponentInterface/include/Metric4thPartyWrapper.h b/Modules/Core/ExampleComponents/include/Metric4thPartyWrapper.h similarity index 93% rename from Modules/Core/ComponentInterface/include/Metric4thPartyWrapper.h rename to Modules/Core/ExampleComponents/include/Metric4thPartyWrapper.h index 1a481281dec62a18df619ec497bb76c3fb406c0d..90036a21098486a34726b9646adf5d86c003a071 100644 --- a/Modules/Core/ComponentInterface/include/Metric4thPartyWrapper.h +++ b/Modules/Core/ExampleComponents/include/Metric4thPartyWrapper.h @@ -3,7 +3,7 @@ #include "Example4thPartyCode.h" #include "Interfaces.hxx" -namespace elx +namespace selx { // An Optimizer4thParty expects that Metric4thParty will be set as input. All accepted interfaces by the Optimizer4thPartyCompoment will be delegated to the Metric4thPartyWrapper object. class Metric4thPartyWrapper : public Example4thParty::Metric4thPartyBase { @@ -13,5 +13,5 @@ public: private: MetricValueInterface* metricval; }; -} // end namespace elx +} // end namespace selx #endif // #define Metric3rdPartyWrapper_h \ No newline at end of file diff --git a/Modules/Core/ExampleComponents/include/MetricComponent1.h b/Modules/Core/ExampleComponents/include/MetricComponent1.h new file mode 100644 index 0000000000000000000000000000000000000000..344421c5235e5c722c3b82bceac0f7ddb11ee27a --- /dev/null +++ b/Modules/Core/ExampleComponents/include/MetricComponent1.h @@ -0,0 +1,58 @@ +#ifndef itkMetricComponent1_h +#define itkMetricComponent1_h + +#include "ComponentBase.h" +#include "Interfaces.h" + +namespace selx +{ +class MetricComponent1 : + public Implements < + Accepting< TransformedImageInterface>, + Providing < MetricValueInterface > + > +{ +public: + /** Standard class typedefs. */ + typedef MetricComponent1 Self; + typedef ComponentBase Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + /** New macro for creation of through the object factory. */ + itkNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(MetricComponent1, ComponentBase); + + typedef Superclass::CriteriaType CriteriaType; + typedef Superclass::CriteriumType CriteriumType; + + virtual int Set(TransformedImageInterface *); + virtual int GetValue(){ return 0; } + + //std::string GetComponentTypeAsString() const; + //static const char * GetName(){ return "MetricComponent1"; }; + static const char * GetDescription(){ return "Example Metric Component 1"; }; +protected: + + MetricComponent1(); + virtual ~MetricComponent1() + { + } + +private: + MetricComponent1(const Self &); // purposely not implemented + void operator=(const Self &); // purposely not implemented + + virtual bool MeetsCriterium(const CriteriumType &criterium); + //virtual bool MeetsCriteria(const CriteriaType&); + +}; +} // end namespace selx + +//#ifndef ITK_MANUAL_INSTANTIATION +//#include "itkMetricComponent1.hxx" +//#endif + +#endif diff --git a/Modules/Core/Install/include/itkMetricComponent1Factory.h b/Modules/Core/ExampleComponents/include/MetricComponent1Factory.h similarity index 86% rename from Modules/Core/Install/include/itkMetricComponent1Factory.h rename to Modules/Core/ExampleComponents/include/MetricComponent1Factory.h index 16e5f11302dcbc4bea2ccdcbc755dc65611f2ddb..acbbf6a34db7580b6edec6b9f074a8724a036c72 100644 --- a/Modules/Core/Install/include/itkMetricComponent1Factory.h +++ b/Modules/Core/ExampleComponents/include/MetricComponent1Factory.h @@ -18,23 +18,23 @@ #ifndef itkMetricComponent1Factory_h #define itkMetricComponent1Factory_h -#include "itkComponentFactory.h" -#include "itkComponentBase.h" +#include "ComponentSelector.h" +#include "ComponentBase.h" -namespace itk +namespace selx { /** \class MetricComponent1Factory * \brief Create instances of MetaImageIO objects using an object factory. * \ingroup ITKIOMeta */ - class MetricComponent1Factory :public ObjectFactoryBase + class MetricComponent1Factory :public itk::ObjectFactoryBase { public: /** Standard class typedefs. */ typedef MetricComponent1Factory Self; - typedef ObjectFactoryBase Superclass; - typedef SmartPointer< Self > Pointer; - typedef SmartPointer< const Self > ConstPointer; + typedef itk::ObjectFactoryBase Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; /** Class methods used to interface with the registered factories. */ virtual const char * GetITKSourceVersion() const ITK_OVERRIDE; @@ -63,7 +63,7 @@ private: MetricComponent1Factory(const Self &); //purposely not implemented void operator=(const Self &); //purposely not implemented }; -} // end namespace itk +} // end namespace selx #ifndef ITK_MANUAL_INSTANTIATION diff --git a/Modules/Core/Install/include/itkMetricComponent1Factory.hxx b/Modules/Core/ExampleComponents/include/MetricComponent1Factory.hxx similarity index 90% rename from Modules/Core/Install/include/itkMetricComponent1Factory.hxx rename to Modules/Core/ExampleComponents/include/MetricComponent1Factory.hxx index de2c9abdb0efcab0b9349d4c9176854eba640404..8687dc6713e961dfd99a02fd36b37a48bdd01b29 100644 --- a/Modules/Core/Install/include/itkMetricComponent1Factory.hxx +++ b/Modules/Core/ExampleComponents/include/MetricComponent1Factory.hxx @@ -19,16 +19,16 @@ #include "itkMetricComponent1.h" #include "itkVersion.h" -namespace itk +namespace selx { MetricComponent1Factory::MetricComponent1Factory() { - this->RegisterOverride( "itkComponentBase", + this->RegisterOverride( "ComponentBase", "itkMetricComponent1", "Metric Component 1", 1, - CreateObjectFunction< MetricComponent1 >::New() ); //float + itk::CreateObjectFunction< MetricComponent1 >::New()); //float } const char * @@ -57,4 +57,4 @@ void MetricComponent1FactoryRegister__Private(void) } } */ -} // end namespace itk +} // end namespace selx diff --git a/Modules/Core/ExampleComponents/include/SSDMetric3rdPartyComponent.h b/Modules/Core/ExampleComponents/include/SSDMetric3rdPartyComponent.h new file mode 100644 index 0000000000000000000000000000000000000000..92c0f1fae87d542dcbf0facbbb2999ecdbe20508 --- /dev/null +++ b/Modules/Core/ExampleComponents/include/SSDMetric3rdPartyComponent.h @@ -0,0 +1,41 @@ +#ifndef SSDMetric3rdPartyComponent_h +#define SSDMetric3rdPartyComponent_h + +#include "ComponentBase.h" +#include "Interfaces.hxx" +#include "Example3rdPartyCode.h" + +namespace selx +{ + // SSDMetric3rdPartyComponent provides a value and a derivative + class SSDMetric3rdPartyComponent : + public Implements< + Accepting<>, + Providing< MetricDerivativeInterface, MetricValueInterface> + > + { + public: + /** Standard class typedefs. */ + typedef SSDMetric3rdPartyComponent Self; + typedef ComponentBase Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + /** New macro for creation of through the object factory. */ + itkNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(SSDMetric3rdPartyComponent, Superclass); + + SSDMetric3rdPartyComponent(); + virtual ~SSDMetric3rdPartyComponent(); + Example3rdParty::SSDMetric3rdParty* theImplementation; + int GetValue(); + int GetDerivative(); + //virtual bool MeetsCriteria(const CriteriaType &criteria); + virtual bool MeetsCriterium(const CriteriumType &criterium); + static const char * GetName(){ return "SSDMetric3rdPartyComponent"; } + static const char * GetDescription(){ return "SSD Metric 3rd Party Component"; }; + }; +} //end namespace selx +#endif // #define SSDMetric3rdPartyComponent_h \ No newline at end of file diff --git a/Modules/Core/ExampleComponents/include/SSDMetric4thPartyComponent.h b/Modules/Core/ExampleComponents/include/SSDMetric4thPartyComponent.h new file mode 100644 index 0000000000000000000000000000000000000000..353615947aa21055d84a0fa1b66c42a6c13d9b9d --- /dev/null +++ b/Modules/Core/ExampleComponents/include/SSDMetric4thPartyComponent.h @@ -0,0 +1,41 @@ +#ifndef SSDMetric4thPartyComponent_h +#define SSDMetric4thPartyComponent_h + +#include "ComponentBase.h" +#include "Interfaces.hxx" +#include "Example4thPartyCode.h" + +namespace selx +{ + // SSDMetric4thPartyComponent provides only a value and not a derivative + class SSDMetric4thPartyComponent : + public Implements< + Accepting<>, + Providing< MetricValueInterface> + > + { + public: + /** Standard class typedefs. */ + typedef SSDMetric4thPartyComponent Self; + typedef ComponentBase Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + /** New macro for creation of through the object factory. */ + itkNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(SSDMetric4thPartyComponent, Superclass); + + SSDMetric4thPartyComponent(); + virtual ~SSDMetric4thPartyComponent(); + Example4thParty::SSDMetric4thParty* theImplementation; + int GetValue(); + virtual bool MeetsCriterium(const CriteriumType &criterium); + //virtual bool MeetsCriteria(const CriteriaType &criteria); + //static const char * GetName(){ return "SSDMetric4thPartyComponent"; }; + static const char * GetDescription(){ return "SSD Metric 4th Party Component"; }; + + }; +} //end namespace selx +#endif // #define SSDMetric4thPartyComponent_h \ No newline at end of file diff --git a/Modules/Core/ExampleComponents/include/TransformComponent1.h b/Modules/Core/ExampleComponents/include/TransformComponent1.h new file mode 100644 index 0000000000000000000000000000000000000000..4236031ec4cfebdce3fedb34bacc04dda0f1a35e --- /dev/null +++ b/Modules/Core/ExampleComponents/include/TransformComponent1.h @@ -0,0 +1,53 @@ +#ifndef itkTransformComponent1_h +#define itkTransformComponent1_h + +#include "Interfaces.h" +#include "ComponentBase.h" + +namespace selx +{ +class TransformComponent1 : + public Implements < + Accepting< >, + Providing < TransformedImageInterface > + > +{ +public: + /** Standard class typedefs. */ + typedef TransformComponent1 Self; + typedef ComponentBase Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + /** New macro for creation of through the object factory. */ + itkNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(TransformComponent1, ComponentBase); + + typedef Superclass::CriteriaType CriteriaType; + typedef Superclass::CriteriumType CriteriumType; + + int GetTransformedImage(){ return 0; }; + static const char * GetDescription(){ return "Example Transform Component 1"; }; + virtual bool MeetsCriterium(const CriteriumType &criterium); +protected: + TransformComponent1(); + virtual ~TransformComponent1() + { + } + +private: + TransformComponent1(const Self &); // purposely not implemented + void operator=(const Self &); // purposely not implemented + + //virtual bool MeetsCriteria(const CriteriaType&); + +}; +} // end namespace selx + +//#ifndef ITK_MANUAL_INSTANTIATION +//#include "itkTransformComponent1.hxx" +//#endif + +#endif diff --git a/Modules/Core/Install/include/itkTransformComponent1Factory.h b/Modules/Core/ExampleComponents/include/TransformComponent1Factory.h similarity index 86% rename from Modules/Core/Install/include/itkTransformComponent1Factory.h rename to Modules/Core/ExampleComponents/include/TransformComponent1Factory.h index fbea1a99b2925f6c3c2d3bbe4d549ea9b4ff625b..72b8c16458a4f38899df8ae75733338f76108fdf 100644 --- a/Modules/Core/Install/include/itkTransformComponent1Factory.h +++ b/Modules/Core/ExampleComponents/include/TransformComponent1Factory.h @@ -18,23 +18,23 @@ #ifndef itkTransformComponent1Factory_h #define itkTransformComponent1Factory_h -#include "itkComponentFactory.h" -#include "itkComponentBase.h" +#include "ComponentSelector.h" +#include "ComponentBase.h" -namespace itk +namespace selx { /** \class TransformComponent1Factory * \brief Create instances of MetaImageIO objects using an object factory. * \ingroup ITKIOMeta */ - class TransformComponent1Factory :public ObjectFactoryBase + class TransformComponent1Factory :public itk::ObjectFactoryBase { public: /** Standard class typedefs. */ typedef TransformComponent1Factory Self; - typedef ObjectFactoryBase Superclass; - typedef SmartPointer< Self > Pointer; - typedef SmartPointer< const Self > ConstPointer; + typedef itk::ObjectFactoryBase Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; /** Class methods used to interface with the registered factories. */ virtual const char * GetITKSourceVersion() const ITK_OVERRIDE; @@ -63,7 +63,7 @@ private: TransformComponent1Factory(const Self &); //purposely not implemented void operator=(const Self &); //purposely not implemented }; -} // end namespace itk +} // end namespace selx #ifndef ITK_MANUAL_INSTANTIATION #include "itkTransformComponent1Factory.hxx" diff --git a/Modules/Core/Install/include/itkTransformComponent1Factory.hxx b/Modules/Core/ExampleComponents/include/TransformComponent1Factory.hxx similarity index 90% rename from Modules/Core/Install/include/itkTransformComponent1Factory.hxx rename to Modules/Core/ExampleComponents/include/TransformComponent1Factory.hxx index 2a3a8c50b90fa15da1817dde4c2c34d1cd111622..5e08c827cdd1f7e90f9675d1440716c8d30477f4 100644 --- a/Modules/Core/Install/include/itkTransformComponent1Factory.hxx +++ b/Modules/Core/ExampleComponents/include/TransformComponent1Factory.hxx @@ -19,16 +19,16 @@ #include "itkTransformComponent1.h" #include "itkVersion.h" -namespace itk +namespace selx { TransformComponent1Factory::TransformComponent1Factory() { - this->RegisterOverride( "itkComponentBase", + this->RegisterOverride( "ComponentBase", "itkTransformComponent1", "Transform Component 1", 1, - CreateObjectFunction< TransformComponent1 >::New() ); //float + itk::CreateObjectFunction< TransformComponent1 >::New()); //float } @@ -58,4 +58,4 @@ void TransformComponent1FactoryRegister__Private(void) } } */ -} // end namespace itk +} // end namespace selx diff --git a/Modules/Core/ComponentInterface/src/Example3rdPartyCode.cxx b/Modules/Core/ExampleComponents/src/Example3rdPartyCode.cxx similarity index 100% rename from Modules/Core/ComponentInterface/src/Example3rdPartyCode.cxx rename to Modules/Core/ExampleComponents/src/Example3rdPartyCode.cxx diff --git a/Modules/Core/ComponentInterface/src/Example4thPartyCode.cxx b/Modules/Core/ExampleComponents/src/Example4thPartyCode.cxx similarity index 100% rename from Modules/Core/ComponentInterface/src/Example4thPartyCode.cxx rename to Modules/Core/ExampleComponents/src/Example4thPartyCode.cxx diff --git a/Modules/Core/ComponentInterface/src/GDOptimizer3rdPartyComponent.cxx b/Modules/Core/ExampleComponents/src/GDOptimizer3rdPartyComponent.cxx similarity index 65% rename from Modules/Core/ComponentInterface/src/GDOptimizer3rdPartyComponent.cxx rename to Modules/Core/ExampleComponents/src/GDOptimizer3rdPartyComponent.cxx index 3f0e0db01c83d6a4f24d67490df5a12f0a9a1555..c2d7e20f1e66ef54e7c59201161cb13b388a5c69 100644 --- a/Modules/Core/ComponentInterface/src/GDOptimizer3rdPartyComponent.cxx +++ b/Modules/Core/ExampleComponents/src/GDOptimizer3rdPartyComponent.cxx @@ -1,6 +1,6 @@ #include "GDOptimizer3rdPartyComponent.h" -namespace elx +namespace selx { GDOptimizer3rdPartyComponent::GDOptimizer3rdPartyComponent() { @@ -29,4 +29,21 @@ int GDOptimizer3rdPartyComponent::Update() this->theImplementation->SetMetric(this->MetricObject); return this->theImplementation->Optimize(); // 3rd party specific call } -} //end namespace elx \ No newline at end of file + +bool +GDOptimizer3rdPartyComponent +::MeetsCriterium(const CriteriumType &criterium) +{ + bool hasUndefinedCriteria(false); + bool meetsCriteria(false); + if (strcmp(criterium.first.c_str(), "ComponentProperty") == 0) + { + if (strcmp(criterium.second.c_str(), "SomeProperty") == 0) // e.g. "GradientDescent", "SupportsSparseSamples + { + meetsCriteria = true; + } + } + return meetsCriteria; +} + +} //end namespace selx \ No newline at end of file diff --git a/Modules/Core/ComponentInterface/src/GDOptimizer4thPartyComponent.cxx b/Modules/Core/ExampleComponents/src/GDOptimizer4thPartyComponent.cxx similarity index 61% rename from Modules/Core/ComponentInterface/src/GDOptimizer4thPartyComponent.cxx rename to Modules/Core/ExampleComponents/src/GDOptimizer4thPartyComponent.cxx index cd797a94d9c1bb8855885e94c823528639cfacf8..81c87c6de38e9714c6d8b28fa99591d2824193e6 100644 --- a/Modules/Core/ComponentInterface/src/GDOptimizer4thPartyComponent.cxx +++ b/Modules/Core/ExampleComponents/src/GDOptimizer4thPartyComponent.cxx @@ -1,6 +1,6 @@ #include "GDOptimizer4thPartyComponent.h" -namespace elx +namespace selx { GDOptimizer4thPartyComponent::GDOptimizer4thPartyComponent() @@ -26,4 +26,21 @@ int GDOptimizer4thPartyComponent::Update() this->theImplementation->SetMetric(this->MetricObject); return this->theImplementation->DoOptimization(); // 4th party specific call } -} //end namespace elx \ No newline at end of file + +bool +GDOptimizer4thPartyComponent +::MeetsCriterium(const CriteriumType &criterium) +{ + bool hasUndefinedCriteria(false); + bool meetsCriteria(false); + if (strcmp(criterium.first.c_str(), "ComponentProperty") == 0) + { + if (strcmp(criterium.second.c_str(), "SomeProperty") == 0) // e.g. "GradientDescent", "SupportsSparseSamples + { + meetsCriteria = true; + } + } + return meetsCriteria; +} + +} //end namespace selx \ No newline at end of file diff --git a/Modules/Core/ComponentInterface/src/Metric3rdPartyWrapper.cxx b/Modules/Core/ExampleComponents/src/Metric3rdPartyWrapper.cxx similarity index 93% rename from Modules/Core/ComponentInterface/src/Metric3rdPartyWrapper.cxx rename to Modules/Core/ExampleComponents/src/Metric3rdPartyWrapper.cxx index 18feaa555add72667d1d1a8256156ed77ef46e96..931041a012f4b57bff80f1335502360458f91a10 100644 --- a/Modules/Core/ComponentInterface/src/Metric3rdPartyWrapper.cxx +++ b/Modules/Core/ExampleComponents/src/Metric3rdPartyWrapper.cxx @@ -1,6 +1,6 @@ #include "Metric3rdPartyWrapper.h" -namespace elx +namespace selx { void Metric3rdPartyWrapper::SetMetricValueComponent(MetricValueInterface* metricValueComponent) { @@ -21,4 +21,4 @@ int Metric3rdPartyWrapper::GetDerivative() { return this->metricderiv->GetDerivative(); } -} // end namespace elx \ No newline at end of file +} // end namespace selx \ No newline at end of file diff --git a/Modules/Core/ComponentInterface/src/Metric4thPartyWrapper.cxx b/Modules/Core/ExampleComponents/src/Metric4thPartyWrapper.cxx similarity index 87% rename from Modules/Core/ComponentInterface/src/Metric4thPartyWrapper.cxx rename to Modules/Core/ExampleComponents/src/Metric4thPartyWrapper.cxx index 0bda72bbbad99aa4d6ae5ba3685f317d695dd414..6592e1eac595705b7fedf390cc01d58004e5a950 100644 --- a/Modules/Core/ComponentInterface/src/Metric4thPartyWrapper.cxx +++ b/Modules/Core/ExampleComponents/src/Metric4thPartyWrapper.cxx @@ -1,6 +1,6 @@ #include "Metric4thPartyWrapper.h" -namespace elx +namespace selx { void Metric4thPartyWrapper::SetMetricValueComponent(MetricValueInterface* metricValueComponent) { @@ -12,4 +12,4 @@ int Metric4thPartyWrapper::GetCost() return this->metricval->GetValue(); } -} // end namespace elx \ No newline at end of file +} // end namespace selx \ No newline at end of file diff --git a/Modules/Core/ExampleComponents/src/MetricComponent1.cxx b/Modules/Core/ExampleComponents/src/MetricComponent1.cxx new file mode 100644 index 0000000000000000000000000000000000000000..08b35ef3b310c327ea2b62af38490e110c168afd --- /dev/null +++ b/Modules/Core/ExampleComponents/src/MetricComponent1.cxx @@ -0,0 +1,58 @@ +/*========================================================================= + * + * Copyright Insight Software Consortium + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0.txt + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *=========================================================================*/ +#ifndef MetricComponent1_hxx +#define MetricComponent1_hxx + +#include "MetricComponent1.h" + +namespace selx +{ +MetricComponent1::MetricComponent1() +{ +} +int MetricComponent1::Set(TransformedImageInterface* providingInterface) +{ + return 0; +} + + bool + MetricComponent1 + ::MeetsCriterium(const CriteriumType &criterium) + { + bool hasUndefinedCriteria(false); + bool meetsCriteria(false); + if (strcmp(criterium.first.c_str(), "ComponentProperty") == 0) + { + if (strcmp(criterium.second.c_str(), "SomeProperty") == 0) // e.g. "GradientDescent", "SupportsSparseSamples + { + meetsCriteria = true; + } + } + else if (strcmp(criterium.first.c_str(), "ComponentInput") == 0) + { + if (strcmp(criterium.second.c_str(), "Transform") == 0) // e.g. "GradientDescent", "SupportsSparseSamples + { + meetsCriteria = true; + } + } + return meetsCriteria; + } + +} // end namespace selx + +#endif diff --git a/Modules/Core/ComponentInterface/src/SSDMetric3rdPartyComponent.cxx b/Modules/Core/ExampleComponents/src/SSDMetric3rdPartyComponent.cxx similarity index 51% rename from Modules/Core/ComponentInterface/src/SSDMetric3rdPartyComponent.cxx rename to Modules/Core/ExampleComponents/src/SSDMetric3rdPartyComponent.cxx index c4bc8260ebdd4aa0dba97b14859dfcfb837d0019..af0239f75ef55a2081782ce224324fbfc7499e2f 100644 --- a/Modules/Core/ComponentInterface/src/SSDMetric3rdPartyComponent.cxx +++ b/Modules/Core/ExampleComponents/src/SSDMetric3rdPartyComponent.cxx @@ -1,5 +1,5 @@ #include "SSDMetric3rdPartyComponent.h" -namespace elx +namespace selx { SSDMetric3rdPartyComponent::SSDMetric3rdPartyComponent() { @@ -19,4 +19,21 @@ int SSDMetric3rdPartyComponent::GetValue() { return this->theImplementation->GetValue(); }; -} //end namespace elx \ No newline at end of file + +bool +SSDMetric3rdPartyComponent +::MeetsCriterium(const CriteriumType &criterium) +{ + bool hasUndefinedCriteria(false); + bool meetsCriteria(false); + if (strcmp(criterium.first.c_str(), "ComponentProperty") == 0) + { + if (strcmp(criterium.second.c_str(), "SomeProperty") == 0) // e.g. "GradientDescent", "SupportsSparseSamples + { + meetsCriteria = true; + } + } + return meetsCriteria; +} + +} //end namespace selx \ No newline at end of file diff --git a/Modules/Core/ExampleComponents/src/SSDMetric4thPartyComponent.cxx b/Modules/Core/ExampleComponents/src/SSDMetric4thPartyComponent.cxx new file mode 100644 index 0000000000000000000000000000000000000000..6364ef9342ccecb1b799d0ca355a9e46cf8a4899 --- /dev/null +++ b/Modules/Core/ExampleComponents/src/SSDMetric4thPartyComponent.cxx @@ -0,0 +1,34 @@ +#include "SSDMetric4thPartyComponent.h" +namespace selx +{ + +SSDMetric4thPartyComponent::SSDMetric4thPartyComponent() +{ + this->theImplementation = new Example4thParty::SSDMetric4thParty(); +} +SSDMetric4thPartyComponent::~SSDMetric4thPartyComponent() +{ + delete this->theImplementation; +} + +int SSDMetric4thPartyComponent::GetValue() +{ + return this->theImplementation->GetCost(); // translate method name +}; + +bool +SSDMetric4thPartyComponent +::MeetsCriterium(const CriteriumType &criterium) +{ + bool hasUndefinedCriteria(false); + bool meetsCriteria(false); + if (strcmp(criterium.first.c_str(), "ComponentProperty") == 0) + { + if (strcmp(criterium.second.c_str(), "SomeProperty") == 0) // e.g. "GradientDescent", "SupportsSparseSamples + { + meetsCriteria = true; + } + } + return meetsCriteria; +} +} //end namespace selx \ No newline at end of file diff --git a/Modules/Core/ExampleComponents/src/TransformComponent1.cxx b/Modules/Core/ExampleComponents/src/TransformComponent1.cxx new file mode 100644 index 0000000000000000000000000000000000000000..9f26d649326bdc4c05defea57b0ab98c51d3a351 --- /dev/null +++ b/Modules/Core/ExampleComponents/src/TransformComponent1.cxx @@ -0,0 +1,61 @@ +/*========================================================================= + * + * Copyright Insight Software Consortium + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0.txt + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *=========================================================================*/ +#ifndef TransformComponent1_hxx +#define TransformComponent1_hxx + +#include "TransformComponent1.h" + +namespace selx +{ + TransformComponent1::TransformComponent1() + { + } + + bool + TransformComponent1::MeetsCriterium(const CriteriumType &criterium) + { + bool hasUndefinedCriteria(false); + bool meetsCriteria(false); + if (strcmp(criterium.first.c_str(), "ComponentProperty") == 0) + { + if (strcmp(criterium.second.c_str(), "SomeProperty") == 0) // e.g. "GradientDescent", "SupportsSparseSamples + { + meetsCriteria = true; + } + } + else if (strcmp(criterium.first.c_str(), "ComponentOutput") == 0) + { + if (strcmp(criterium.second.c_str(), "Transform") == 0) + { + meetsCriteria = true; + } + } + else if (strcmp(criterium.first.c_str(), "ComponentInput") == 0) + { + if (strcmp(criterium.second.c_str(), "Sampler") == 0) + { + meetsCriteria = true; + } + } + return meetsCriteria; + } + + +} // end namespace selx + +#endif diff --git a/Modules/Core/Install/CmakeLists.txt b/Modules/Core/Install/CmakeLists.txt deleted file mode 100644 index 3c538aace947b741a8414682ae69e71af66b4000..0000000000000000000000000000000000000000 --- a/Modules/Core/Install/CmakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -PROJECT(itkfactory) -cmake_minimum_required(VERSION 2.6) -cmake_policy(VERSION 2.6) - -FIND_PACKAGE(ITK) -IF(ITK_FOUND) - INCLUDE(${ITK_USE_FILE}) -ELSE(ITK_FOUND) - MESSAGE(FATAL_ERROR "ITK not found. Please set ITK_DIR.") -ENDIF(ITK_FOUND) - -include_directories( ${itkfactory_SOURCE_DIR}/include ) -ADD_EXECUTABLE(itkfactory src/itkfactory.cxx - include/itkTransformComponent1.h include/itkTransformComponent1.h include/itkTransformComponent1Factory.h include/itkMetricComponent1.h include/itkMetricComponent1Factory.h include/itkComponentBase.h include/itkComponentFactory.h include/itkTransformComponent1.hxx include/itkTransformComponent1Factory.hxx include/itkMetricComponent1.hxx include/itkMetricComponent1Factory.hxx include/itkComponentFactory.hxx) -TARGET_LINK_LIBRARIES(itkfactory ${ITK_LIBRARIES} ITKCommon ) diff --git a/Modules/Core/Install/include/itkComponentBase.h b/Modules/Core/Install/include/itkComponentBase.h deleted file mode 100644 index 6dafa7c244f5e202011c01afa27af53ba8668e8a..0000000000000000000000000000000000000000 --- a/Modules/Core/Install/include/itkComponentBase.h +++ /dev/null @@ -1,97 +0,0 @@ -/*========================================================================= - * - * Copyright Insight Software Consortium - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0.txt - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - *=========================================================================*/ -#ifndef itkComponentBase_h -#define itkComponentBase_h - -#include "itkLightProcessObject.h" -//#include "itkComponentBase.h" -#include <list> -#include <iostream> -#include <fstream> -#include <string> -#include <map> - -namespace itk -{ - -/** \class ComponentBaseTemplate - * - * \brief Abstract superclass defining the Component IO interface. - * - * ComponentBaseTemplate is a pure virtual base class for derived classes that - * read/write Component data considering the type of input Component. - * First, ComponentBase is derived from this class for legacy read/write Component. - * This class also is used by the ComponentFileReader and ComponentFileWriter - * classes. End users don't directly manipulate classes derived from ComponentBaseTemplate; - * the ComponentFactory is used by the Reader/Writer to pick a concrete derived class to do - * the actual reading/writing of Components. - * - * \ingroup ITKIOComponentBase - */ -class ComponentBase:public LightProcessObject -{ -public: - /** Standard class typedefs */ - typedef ComponentBase Self; - typedef LightProcessObject Superclass; - typedef SmartPointer< Self > Pointer; - - /** Run-time type information (and related methods). */ - itkTypeMacro(ComponentBase, Superclass); - - /** Component types */ - //typedef TScalar ScalarType; - //typedef ComponentBaseTemplate<ScalarType> ComponentType; - /** For writing, a const Component list gets passed in, for - * reading, a non-const Component list is created from the file. - */ - //typedef typename ComponentType::Pointer ComponentPointer; - //typedef std::list< ComponentPointer > ComponentListType; - //typedef typename ComponentType::ConstPointer ConstComponentPointer; - //typedef std::list< ConstComponentPointer > ConstComponentListType; - - typedef std::map<std::string, std::string> CriteriaType; - typedef std::pair<std::string, std::string> CriteriumType; - - /** Set/Get the name of the file to be read. */ - itkSetStringMacro(FileName); - itkGetStringMacro(FileName); - - /** Reads the data from disk into the memory buffer provided. */ - virtual void Read() = 0; - - /** Writes the Component list to disk. */ - virtual void Write() = 0; - - /** Determine the file type. Returns true if this Component can read the - * file specified. */ - virtual bool MeetsCriteria(const CriteriaType &criteria) = 0; - -protected: - ComponentBase() {}; - virtual ~ComponentBase() {}; - //virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE; - - std::string m_FileName; - -}; - -} // end namespace itk - - -#endif // itkComponentBase_h diff --git a/Modules/Core/Install/include/itkMetricComponent1.h b/Modules/Core/Install/include/itkMetricComponent1.h deleted file mode 100644 index a931e5396152cac0c8d9fdd496f43ca17224c6fc..0000000000000000000000000000000000000000 --- a/Modules/Core/Install/include/itkMetricComponent1.h +++ /dev/null @@ -1,74 +0,0 @@ -#ifndef itkMetricComponent1_h -#define itkMetricComponent1_h - -#include "itkComponentBase.h" - -namespace itk -{ -class MetricComponent1 : public ComponentBase -{ -public: - /** Standard class typedefs. */ - typedef MetricComponent1 Self; - typedef ComponentBase Superclass; - typedef SmartPointer< Self > Pointer; - typedef SmartPointer< const Self > ConstPointer; - - /** New macro for creation of through the object factory. */ - itkNewMacro(Self); - - /** Run-time type information (and related methods). */ - itkTypeMacro(MetricComponent1, ComponentBase); - - /** define the Clone method */ - // itkCloneMacro(Self); - - /** Type of the scalar representing coordinate and vector elements. */ - //typedef TScalar ScalarType; - - typedef Superclass::CriteriaType CriteriaType; - typedef Superclass::CriteriumType CriteriumType; - - std::string GetComponentTypeAsString() const; -protected: - /** - * Clone the current Metric. - * This does a complete copy of the Metric - * state to the new Metric - */ - virtual LightObject::Pointer InternalClone() const ITK_OVERRIDE; - - MetricComponent1(); - virtual ~MetricComponent1() - { - } - -private: - MetricComponent1(const Self &); // purposely not implemented - void operator=(const Self &); // purposely not implemented - - - std::string GetComponentTypeAsString(float *) const - { - std::string rval("float"); - - return rval; - } - - std::string GetComponentTypeAsString(double *) const - { - std::string rval("double"); - - return rval; - } - virtual void Read(); - virtual void Write(); - virtual bool MeetsCriteria(const CriteriaType&); -}; -} // end namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -#include "itkMetricComponent1.hxx" -#endif - -#endif diff --git a/Modules/Core/Install/include/itkMetricComponent1.hxx b/Modules/Core/Install/include/itkMetricComponent1.hxx deleted file mode 100644 index 6b15943708e2b026110e910d21f68f7f65bc822c..0000000000000000000000000000000000000000 --- a/Modules/Core/Install/include/itkMetricComponent1.hxx +++ /dev/null @@ -1,120 +0,0 @@ -/*========================================================================= - * - * Copyright Insight Software Consortium - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0.txt - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - *=========================================================================*/ -#ifndef itkMetricComponent1_hxx -#define itkMetricComponent1_hxx - -#include "itkMetricComponent1.h" - -namespace itk -{ - MetricComponent1::MetricComponent1() -{ -} - -std::string MetricComponent1::GetComponentTypeAsString() const -{ - std::ostringstream n; - - n << GetNameOfClass(); - n << "_"; - n << this->GetComponentTypeAsString(static_cast<float *>(ITK_NULLPTR)); - //n << "_" << this->GetInputSpaceDimension() << "_" << this->GetOutputSpaceDimension(); - return n.str(); -} - -LightObject::Pointer -MetricComponent1::InternalClone() const -{ - // Default implementation just copies the parameters from - // this to new Metric. - LightObject::Pointer loPtr = Superclass::InternalClone(); - - Self::Pointer rval = - dynamic_cast<Self *>(loPtr.GetPointer()); - if(rval.IsNull()) - { - itkExceptionMacro(<< "downcast to type " - << this->GetNameOfClass() - << " failed."); - } - //rval->SetFixedParameters(this->GetFixedParameters()); - //rval->SetParameters(this->GetParameters()); - return loPtr; -} - - - void - MetricComponent1 - ::Read() -{ - return; -} - - - void - MetricComponent1 - ::Write() -{ - return; -} - - bool - MetricComponent1 - ::MeetsCriteria(const CriteriaType& criteria) -{ - bool hasUndefinedCriteria(false); - bool meetsCriteria(true); - - for (CriteriaType::const_iterator it = criteria.begin(); it != criteria.end(); ++it) - { - if (strcmp(it->first.c_str(), "Name") == 0) - { - if (strcmp(it->second.c_str(), typeid(Self).name()) != 0) - { - meetsCriteria = false; - return false; - } - } - else if (strcmp(it->first.c_str(), "ComponentOutput") == 0) - { - if (strcmp(it->second.c_str(), "Metric") != 0) - { - meetsCriteria = false; - return false; - } - } - else if (strcmp(it->first.c_str(), "ComponentInput") == 0) - { - if (strcmp(it->second.c_str(), "Transform") != 0) - { - meetsCriteria = false; - return false; - } - } - else - { - hasUndefinedCriteria = true; - } - - } - return meetsCriteria; -} - -} // end namespace itk - -#endif diff --git a/Modules/Core/Install/include/itkTransformComponent1.h b/Modules/Core/Install/include/itkTransformComponent1.h deleted file mode 100644 index d7763d9797ddde09ded6c2e8842ee108483cb543..0000000000000000000000000000000000000000 --- a/Modules/Core/Install/include/itkTransformComponent1.h +++ /dev/null @@ -1,74 +0,0 @@ -#ifndef itkTransformComponent1_h -#define itkTransformComponent1_h - -#include "itkComponentBase.h" - -namespace itk -{ -class TransformComponent1 : public ComponentBase -{ -public: - /** Standard class typedefs. */ - typedef TransformComponent1 Self; - typedef ComponentBase Superclass; - typedef SmartPointer< Self > Pointer; - typedef SmartPointer< const Self > ConstPointer; - - /** New macro for creation of through the object factory. */ - itkNewMacro(Self); - - /** Run-time type information (and related methods). */ - itkTypeMacro(TransformComponent1, ComponentBase); - - /** define the Clone method */ - // itkCloneMacro(Self); - - /** Type of the scalar representing coordinate and vector elements. */ - //typedef TScalar ScalarType; - - typedef Superclass::CriteriaType CriteriaType; - typedef Superclass::CriteriumType CriteriumType; - - std::string GetComponentTypeAsString() const; -protected: - /** - * Clone the current Transform. - * This does a complete copy of the Transform - * state to the new Transform - */ - virtual LightObject::Pointer InternalClone() const ITK_OVERRIDE; - - TransformComponent1(); - virtual ~TransformComponent1() - { - } - -private: - TransformComponent1(const Self &); // purposely not implemented - void operator=(const Self &); // purposely not implemented - - - std::string GetComponentTypeAsString(float *) const - { - std::string rval("float"); - - return rval; - } - - std::string GetComponentTypeAsString(double *) const - { - std::string rval("double"); - - return rval; - } - virtual void Read(); - virtual void Write(); - virtual bool MeetsCriteria(const CriteriaType&); -}; -} // end namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -#include "itkTransformComponent1.hxx" -#endif - -#endif diff --git a/Modules/Core/Install/include/itkTransformComponent1.hxx b/Modules/Core/Install/include/itkTransformComponent1.hxx deleted file mode 100644 index 1add28fc16647d53c74206664a2db23d408e0fb4..0000000000000000000000000000000000000000 --- a/Modules/Core/Install/include/itkTransformComponent1.hxx +++ /dev/null @@ -1,120 +0,0 @@ -/*========================================================================= - * - * Copyright Insight Software Consortium - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0.txt - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - *=========================================================================*/ -#ifndef itkTransformComponent1_hxx -#define itkTransformComponent1_hxx - -#include "itkTransformComponent1.h" - -namespace itk -{ - TransformComponent1::TransformComponent1() - { - } - -std::string TransformComponent1::GetComponentTypeAsString() const -{ - std::ostringstream n; - - n << GetNameOfClass(); - n << "_"; - n << this->GetComponentTypeAsString(static_cast<float *>(ITK_NULLPTR)); - //n << "_" << this->GetInputSpaceDimension() << "_" << this->GetOutputSpaceDimension(); - return n.str(); -} - -LightObject::Pointer -TransformComponent1::InternalClone() const -{ - // Default implementation just copies the parameters from - // this to new Transform. - LightObject::Pointer loPtr = Superclass::InternalClone(); - - Self::Pointer rval = - dynamic_cast<Self *>(loPtr.GetPointer()); - if(rval.IsNull()) - { - itkExceptionMacro(<< "downcast to type " - << this->GetNameOfClass() - << " failed."); - } - //rval->SetFixedParameters(this->GetFixedParameters()); - //rval->SetParameters(this->GetParameters()); - return loPtr; -} - - - void - TransformComponent1 - ::Read() -{ - return; -} - - - void - TransformComponent1 - ::Write() -{ - return; -} - - bool - TransformComponent1 - ::MeetsCriteria(const CriteriaType &criteria) - { - bool hasUndefinedCriteria(false); - bool meetsCriteria(true); - - for (CriteriaType::const_iterator it = criteria.begin(); it != criteria.end(); ++it) - { - if (strcmp(it->first.c_str(), "Name") == 0) - { - if (strcmp(it->second.c_str(), typeid(Self).name()) != 0) - { - meetsCriteria = false; - return false; - } - } - else if (strcmp(it->first.c_str(), "ComponentOutput") == 0) - { - if (strcmp(it->second.c_str(), "Transform") != 0) - { - meetsCriteria = false; - return false; - } - } - else if (strcmp(it->first.c_str(), "ComponentInput") == 0) - { - if (strcmp(it->second.c_str(), "Sampler") != 0) - { - meetsCriteria = false; - return false; - } - } - else - { - hasUndefinedCriteria = true; - } - - } - return meetsCriteria; -} - -} // end namespace itk - -#endif diff --git a/Modules/Core/ModuleCore.cmake b/Modules/Core/ModuleCore.cmake index 69e0465f7c860d7c4062c4a596f46a9b9920f311..50b396b3a8ae300e02bc247f350fc9981df59d58 100644 --- a/Modules/Core/ModuleCore.cmake +++ b/Modules/Core/ModuleCore.cmake @@ -1,19 +1,20 @@ set( MODULE ModuleCore ) -# Module source files -set( ${MODULE}_SOURCE_FILES - ${${MODULE}_SOURCE_DIR}/Blueprints/src/elxBlueprint.cxx -) - # Export include files set( ${MODULE}_INCLUDE_DIRS ${${MODULE}_SOURCE_DIR}/Common/include ${${MODULE}_SOURCE_DIR}/Blueprints/include ${${MODULE}_SOURCE_DIR}/ParameterObject/include - ${${MODULE}_SOURCE_DIR}/Install/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... +#I read: CMake will figure out that they're headers; it won't try to build them. http://stackoverflow.com/questions/8316104/specify-how-cmake-creates-visual-studio-project + + + # Export libraries set( ${MODULE}_LIBRARIES ${MODULE} @@ -22,16 +23,21 @@ set( ${MODULE}_LIBRARIES # Module source files set( ${MODULE}_SOURCE_FILES ${${MODULE}_SOURCE_DIR}/Blueprints/src/elxBlueprint.cxx - ${${MODULE}_SOURCE_DIR}/ComponentInterface/src/Example3rdPartyCode.cxx - ${${MODULE}_SOURCE_DIR}/ComponentInterface/src/Example4thPartyCode.cxx - ${${MODULE}_SOURCE_DIR}/ComponentInterface/src/GDOptimizer3rdPartyComponent.cxx - ${${MODULE}_SOURCE_DIR}/ComponentInterface/src/GDOptimizer4thPartyComponent.cxx - ${${MODULE}_SOURCE_DIR}/ComponentInterface/src/Metric3rdPartyWrapper.cxx - ${${MODULE}_SOURCE_DIR}/ComponentInterface/src/Metric4thPartyWrapper.cxx - ${${MODULE}_SOURCE_DIR}/ComponentInterface/src/SSDMetric3rdPartyComponent.cxx - ${${MODULE}_SOURCE_DIR}/ComponentInterface/src/SSDMetric4thPartyComponent.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 ) # Compile library -add_library( ${MODULE} STATIC "${${MODULE}_SOURCE_FILES}" ) + +add_library( ${MODULE} STATIC "${${MODULE}_SOURCE_FILES}" ${${MODULE}_HEADER_FILES}) + target_link_libraries( ${MODULE} ${ELASTIX_LIBRARIES} ) diff --git a/SuperBuild/CMakeLists.txt b/SuperBuild/CMakeLists.txt index 71e20206c73b9afbe1c4bb9377892e705cdc0cda..097964a8c4670be97270b4a53c00ffb1ed30f7b9 100644 --- a/SuperBuild/CMakeLists.txt +++ b/SuperBuild/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required( VERSION 2.8 ) +cmake_minimum_required( VERSION 3.0.2 ) # --------------------------------------------------------------------- project( SuperElastixSuperBuild ) diff --git a/Testing/Unit/elxBluePrintTest.cxx b/Testing/Unit/elxBlueprintTest.cxx similarity index 100% rename from Testing/Unit/elxBluePrintTest.cxx rename to Testing/Unit/elxBlueprintTest.cxx diff --git a/Testing/Unit/elxComponentFactoryTest.cxx b/Testing/Unit/elxComponentFactoryTest.cxx index 222006b1cbcd661ac2243fdc4faad3309b93a65a..b18550ad31c5bffbd55aedb808ecbc5c21650827 100644 --- a/Testing/Unit/elxComponentFactoryTest.cxx +++ b/Testing/Unit/elxComponentFactoryTest.cxx @@ -1,22 +1,27 @@ #include "gtest/gtest.h" -#include "itkTransformComponent1.h" -#include "itkTransformComponent1Factory.h" +#include "TransformComponent1.h" +//#include "itkTransformComponent1Factory.h" -#include "itkMetricComponent1.h" -#include "itkMetricComponent1Factory.h" +#include "MetricComponent1.h" +//#include "itkMetricComponent1Factory.h" +#include "ComponentFactory.h" +#include "GDOptimizer3rdPartyComponent.h" +#include "GDOptimizer4thPartyComponent.h" +#include "SSDMetric3rdPartyComponent.h" +#include "SSDMetric4thPartyComponent.h" -namespace { +namespace selx{ class ComponentFactoryTest : public ::testing::Test { public: typedef std::list< itk::LightObject::Pointer > RegisteredObjectsContainerType; - typedef itk::ComponentBase ComponentType; + typedef ComponentBase ComponentType; typedef std::map<std::string, std::string> CriteriaType; typedef std::pair<std::string, std::string> CriteriumType; - typedef itk::ComponentFactory::Pointer NodePointer; + typedef ComponentSelector::Pointer NodePointer; virtual void SetUp() { @@ -36,7 +41,7 @@ TEST_F(ComponentFactoryTest, EmptyObjectFactoryBase) RegisteredObjectsContainerType registeredComponents; // "When CMake is not used to register the Component classes, there are" - EXPECT_NO_THROW(registeredComponents = itk::ObjectFactoryBase::CreateAllInstance("itkComponentBase")); + EXPECT_NO_THROW(registeredComponents = itk::ObjectFactoryBase::CreateAllInstance("ComponentBase")); // " 0 Component objects available to the Overlord." EXPECT_EQ(registeredComponents.size(), 0); @@ -47,21 +52,25 @@ TEST_F(ComponentFactoryTest, FilledObjectFactoryBase) // In this test we manually register 2 dummy modules: itkTransformComponent1 and itkMetricComponent1. RegisteredObjectsContainerType registeredComponents; - EXPECT_NO_THROW(itk::TransformComponent1Factory::RegisterOneFactory()); - EXPECT_NO_THROW(itk::MetricComponent1Factory::RegisterOneFactory()); + EXPECT_NO_THROW(ComponentFactory<TransformComponent1>::RegisterOneFactory()); + //EXPECT_NO_THROW(TransformComponent1Factory::RegisterOneFactory()); + EXPECT_NO_THROW(ComponentFactory<MetricComponent1>::RegisterOneFactory()); + //EXPECT_NO_THROW(MetricComponent1Factory::RegisterOneFactory()); // After registering the TransformComponent1 and MetricComponent1object, there are - EXPECT_NO_THROW(registeredComponents = itk::ObjectFactoryBase::CreateAllInstance("itkComponentBase")); + EXPECT_NO_THROW(registeredComponents = itk::ObjectFactoryBase::CreateAllInstance("ComponentBase")); // " 2 Component objects available to the Overlord." EXPECT_EQ(registeredComponents.size(), 2); } TEST_F(ComponentFactoryTest, SetEmptyCriteria) { + EXPECT_NO_THROW(ComponentFactory<TransformComponent1>::RegisterOneFactory()); + EXPECT_NO_THROW(ComponentFactory<MetricComponent1>::RegisterOneFactory()); CriteriaType emptyCriteria; - ASSERT_NO_THROW(Node1 = itk::ComponentFactory::New()); + ASSERT_NO_THROW(Node1 = ComponentSelector::New()); EXPECT_NO_THROW(Node1->SetCriteria(emptyCriteria)); ComponentType::Pointer Node1Component; @@ -73,11 +82,13 @@ TEST_F(ComponentFactoryTest, SetEmptyCriteria) TEST_F(ComponentFactoryTest, SetSufficientCriteria) { + EXPECT_NO_THROW(ComponentFactory<TransformComponent1>::RegisterOneFactory()); + EXPECT_NO_THROW(ComponentFactory<MetricComponent1>::RegisterOneFactory()); CriteriaType criteria2; criteria2["ComponentInput"] = "Transform"; //criteria1.insert(CriteriumType("ComponentInput", "Metric")); - ASSERT_NO_THROW(Node2 = itk::ComponentFactory::New()); + ASSERT_NO_THROW(Node2 = ComponentSelector::New()); Node2->SetCriteria(criteria2); ComponentType::Pointer Node2Component; @@ -91,12 +102,15 @@ TEST_F(ComponentFactoryTest, SetSufficientCriteria) } TEST_F(ComponentFactoryTest, AddCriteria) { + EXPECT_NO_THROW(ComponentFactory<TransformComponent1>::RegisterOneFactory()); + EXPECT_NO_THROW(ComponentFactory<MetricComponent1>::RegisterOneFactory()); + CriteriaType emptyCriteria; CriteriaType criteria1; //criteria1.insert(CriteriumType("ComponentOutput","Metric")); criteria1["ComponentOutput"] = "Transform"; //criteria1.insert(CriteriumType("ComponentInput", "Metric")); - Node1 = itk::ComponentFactory::New(); + Node1 = ComponentSelector::New(); Node1->SetCriteria(emptyCriteria); EXPECT_NO_THROW(Node1->AddCriteria(criteria1)); @@ -109,4 +123,65 @@ TEST_F(ComponentFactoryTest, AddCriteria) EXPECT_STREQ(Node1Component->GetNameOfClass(), "TransformComponent1"); } +TEST_F(ComponentFactoryTest, InterfacedObjects) +{ + RegisteredObjectsContainerType registeredComponents; + EXPECT_NO_THROW(ComponentFactory<TransformComponent1>::RegisterOneFactory()); + EXPECT_NO_THROW(ComponentFactory<MetricComponent1>::RegisterOneFactory()); + EXPECT_NO_THROW(ComponentFactory<GDOptimizer3rdPartyComponent>::RegisterOneFactory()); + EXPECT_NO_THROW(ComponentFactory<GDOptimizer4thPartyComponent>::RegisterOneFactory()); + EXPECT_NO_THROW(ComponentFactory<SSDMetric3rdPartyComponent>::RegisterOneFactory()); + EXPECT_NO_THROW(ComponentFactory<SSDMetric4thPartyComponent>::RegisterOneFactory()); + + EXPECT_NO_THROW(registeredComponents = itk::ObjectFactoryBase::CreateAllInstance("ComponentBase")); + // " 6 Component objects available to the Overlord." + EXPECT_EQ(registeredComponents.size(), 6); + + CriteriaType criteria3; + // Criteria could be name or other properties + //criteria3["NameOfClass"] = "GDOptimizer3rdPartyComponent"; + criteria3["HasAcceptingInterface"] = "MetricDerivativeInterface"; + NodePointer Node3 = ComponentSelector::New(); + Node3->SetCriteria(criteria3); + ComponentType::Pointer Node3Component; + EXPECT_NO_THROW(Node3Component = Node3->GetComponent()); + EXPECT_STREQ(Node3Component->GetNameOfClass(), "GDOptimizer3rdPartyComponent"); + + CriteriaType criteria4; + // Criteria could be name or other properties + criteria4["NameOfClass"] = "GDOptimizer4thPartyComponent"; + //criteria3["HasDerivative"] = "True"; + + NodePointer Node4 = ComponentSelector::New(); + Node4->SetCriteria(criteria4); + ComponentType::Pointer Node4Component; + EXPECT_NO_THROW(Node4Component = Node4->GetComponent()); + EXPECT_STREQ(Node4Component->GetNameOfClass(), "GDOptimizer4thPartyComponent"); + + CriteriaType criteria5; + // Criteria could be name or other properties + //criteria5["NameOfClass"] = "SSDMetric3rdPartyComponent"; + criteria5["HasProvidingInterface"] = "MetricDerivativeInterface"; + //criteria3["HasDerivative"] = "True"; + NodePointer Node5 = ComponentSelector::New(); + Node5->SetCriteria(criteria5); + ComponentType::Pointer Node5Component; + EXPECT_NO_THROW(Node5Component = Node5->GetComponent()); + EXPECT_STREQ(Node5Component->GetNameOfClass(), "SSDMetric3rdPartyComponent"); + + CriteriaType criteria6; + // Criteria could be name or other properties + criteria6["NameOfClass"] = "SSDMetric4thPartyComponent"; + //criteria3["HasDerivative"] = "True"; + NodePointer Node6 = ComponentSelector::New(); + Node6->SetCriteria(criteria6); + ComponentType::Pointer Node6Component; + EXPECT_NO_THROW(Node6Component = Node6->GetComponent()); + EXPECT_STREQ(Node6Component->GetNameOfClass(), "SSDMetric4thPartyComponent"); + +} + + + + } // namespace elx diff --git a/Testing/Unit/elxComponentInterfaceTest.cxx b/Testing/Unit/elxComponentInterfaceTest.cxx index 43e2b6ee798b8a496fd9fc5bbcee4674d18bd692..5847148694bbc910cdb35ae8e8fd138b49a9805f 100644 --- a/Testing/Unit/elxComponentInterfaceTest.cxx +++ b/Testing/Unit/elxComponentInterfaceTest.cxx @@ -5,7 +5,7 @@ #include "gtest/gtest.h" -namespace elx { +namespace selx { class InterfaceTest : public ::testing::Test { public: @@ -19,10 +19,10 @@ public: } virtual void TearDown() { - delete metric3p; - delete optimizer3p; - delete metric4p; - delete optimizer4p; + //delete metric3p; + //delete optimizer3p; + //delete metric4p; + //delete optimizer4p; } // types as if returned by our component factory ComponentBase* metric3p; @@ -68,49 +68,72 @@ TEST_F( InterfaceTest, DynamicCast ) TEST_F( InterfaceTest, ConnectByName ) { - interfaceStatus IFstatus; + ComponentBase::interfaceStatus IFstatus; EXPECT_NO_THROW(IFstatus = optimizer3p->ConnectFrom("MetricValueInterface", metric3p)); - EXPECT_EQ(IFstatus, interfaceStatus::success); + EXPECT_EQ(IFstatus, ComponentBase::interfaceStatus::success); EXPECT_NO_THROW(IFstatus = optimizer3p->ConnectFrom("MetricValueInterface", metric4p)); - EXPECT_EQ(IFstatus, interfaceStatus::success); + EXPECT_EQ(IFstatus, ComponentBase::interfaceStatus::success); EXPECT_NO_THROW(IFstatus = optimizer4p->ConnectFrom("MetricValueInterface", metric3p)); - EXPECT_EQ(IFstatus, interfaceStatus::success); + EXPECT_EQ(IFstatus, ComponentBase::interfaceStatus::success); EXPECT_NO_THROW(IFstatus = optimizer4p->ConnectFrom("MetricValueInterface", metric4p)); - EXPECT_EQ(IFstatus, interfaceStatus::success); + EXPECT_EQ(IFstatus, ComponentBase::interfaceStatus::success); EXPECT_NO_THROW(IFstatus = optimizer3p->ConnectFrom("MetricDerivativeInterface", metric3p)); - EXPECT_EQ(IFstatus, interfaceStatus::success); + EXPECT_EQ(IFstatus, ComponentBase::interfaceStatus::success); EXPECT_NO_THROW(IFstatus = optimizer3p->ConnectFrom("MetricDerivativeInterface", metric4p)); - EXPECT_EQ(IFstatus, interfaceStatus::noprovider); - + EXPECT_EQ(IFstatus, ComponentBase::interfaceStatus::noprovider); + EXPECT_NO_THROW(IFstatus = optimizer4p->ConnectFrom("MetricDerivativeInterface", metric3p)); - EXPECT_EQ(IFstatus, interfaceStatus::noaccepter); + EXPECT_EQ(IFstatus, ComponentBase::interfaceStatus::noaccepter); } TEST_F(InterfaceTest, ConnectAll) { int connectionCount = 0; + int returnval; + OptimizerUpdateInterface* updateIF; EXPECT_NO_THROW(connectionCount = optimizer3p->ConnectFrom(metric3p)); EXPECT_EQ(connectionCount, 2); // both MetricValueInterface and MetricDerivativeInterface are connected + //optimizer3p should have a OptimizerUpdateInterface + updateIF = dynamic_cast<OptimizerUpdateInterface*> (optimizer3p); + ASSERT_NE(updateIF, nullptr); + EXPECT_NO_THROW(returnval = updateIF->Update()); // Update can only be called if metric and optimizer are connected + EXPECT_NO_THROW(connectionCount = optimizer3p->ConnectFrom(metric4p)); EXPECT_EQ(connectionCount, 1); // only MetricValueInterface is connected + + //metric4p does not have MetricDerivativeInterface, so optimizer3p cannot run + EXPECT_NO_THROW(connectionCount = optimizer4p->ConnectFrom(metric3p)); EXPECT_EQ(connectionCount, 1); // only MetricValueInterface is connected + updateIF = dynamic_cast<OptimizerUpdateInterface*> (optimizer4p); + ASSERT_NE(updateIF, nullptr); + EXPECT_NO_THROW(returnval = updateIF->Update()); + EXPECT_NO_THROW(connectionCount = optimizer4p->ConnectFrom(metric4p)); EXPECT_EQ(connectionCount, 1); // only MetricValueInterface is connected + updateIF = dynamic_cast<OptimizerUpdateInterface*> (optimizer4p); + ASSERT_NE(updateIF, nullptr); + EXPECT_NO_THROW(returnval = updateIF->Update()); EXPECT_NO_THROW(connectionCount = metric4p->ConnectFrom(optimizer4p)); EXPECT_EQ(connectionCount, 0); // cannot connect in this direction + + ConflictinUpdateInterface* update2IF = dynamic_cast<ConflictinUpdateInterface*> (optimizer4p); + ASSERT_NE(update2IF, nullptr); + EXPECT_NO_THROW(returnval = update2IF->Update(update2IF)); + + } } // namespace elx