From 6c8f2feee0328d12ac753a77ef1329170e398a80 Mon Sep 17 00:00:00 2001 From: Floris Berendsen <floris.berendsen@gmail.com> Date: Thu, 1 Oct 2015 17:47:50 +0200 Subject: [PATCH] WIP: removed IO from names. ModuleFactory not derived from ObjectFactoryBase anymore --- Modules/Core/Install/CmakeLists.txt | 2 +- Modules/Core/Install/itkMetricModule1.h | 8 ++-- .../Core/Install/itkMetricModule1Factory.h | 12 ++--- .../Core/Install/itkMetricModule1Factory.hxx | 2 +- .../{itkModuleIOBase.h => itkModuleBase.h} | 28 +++++------ ...ModuleFactoryBase.h => itkModuleFactory.h} | 46 +++++++++++-------- ...leFactoryBase.hxx => itkModuleFactory.hxx} | 32 ++++++++----- Modules/Core/Install/itkTransformModule1.h | 8 ++-- .../Core/Install/itkTransformModule1Factory.h | 12 ++--- .../Install/itkTransformModule1Factory.hxx | 2 +- Modules/Core/Install/itkfactory.cxx | 37 ++++++--------- Testing/Unit/CMakeLists.txt | 1 + 12 files changed, 101 insertions(+), 89 deletions(-) rename Modules/Core/Install/{itkModuleIOBase.h => itkModuleBase.h} (80%) rename Modules/Core/Install/{itkModuleFactoryBase.h => itkModuleFactory.h} (62%) rename Modules/Core/Install/{itkModuleFactoryBase.hxx => itkModuleFactory.hxx} (65%) diff --git a/Modules/Core/Install/CmakeLists.txt b/Modules/Core/Install/CmakeLists.txt index 73a1feef..26107cb5 100644 --- a/Modules/Core/Install/CmakeLists.txt +++ b/Modules/Core/Install/CmakeLists.txt @@ -9,5 +9,5 @@ ELSE(ITK_FOUND) MESSAGE(FATAL_ERROR "ITK not found. Please set ITK_DIR.") ENDIF(ITK_FOUND) -ADD_EXECUTABLE(itkfactory itkfactory.cxx itkTransformModule1.h itkTransformModule1Factory.h itkTransformModule1.hxx itkTransformModule1Factory.hxx itkMetricModule1.h itkMetricModule1.hxx itkMetricModule1Factory.h itkMetricModule1Factory.hxx itkModuleIOBase.h itkModuleIOFactoryRegisterManager.h) +ADD_EXECUTABLE(itkfactory itkfactory.cxx itkTransformModule1.h itkTransformModule1Factory.h itkTransformModule1.hxx itkTransformModule1Factory.hxx itkMetricModule1.h itkMetricModule1.hxx itkMetricModule1Factory.h itkMetricModule1Factory.hxx itkModuleBase.h itkModuleFactory.h itkModuleFactory.hxx) TARGET_LINK_LIBRARIES(itkfactory ${ITK_LIBRARIES} ITKCommon ) diff --git a/Modules/Core/Install/itkMetricModule1.h b/Modules/Core/Install/itkMetricModule1.h index ec363737..e846de4f 100644 --- a/Modules/Core/Install/itkMetricModule1.h +++ b/Modules/Core/Install/itkMetricModule1.h @@ -1,16 +1,16 @@ #ifndef itkMetricModule1_h #define itkMetricModule1_h -#include "itkModuleIOBase.h" +#include "itkModuleBase.h" namespace itk { -class MetricModule1 : public ModuleIOBase +class MetricModule1 : public ModuleBase { public: /** Standard class typedefs. */ typedef MetricModule1 Self; - typedef ModuleIOBase Superclass; + typedef ModuleBase Superclass; typedef SmartPointer< Self > Pointer; typedef SmartPointer< const Self > ConstPointer; @@ -18,7 +18,7 @@ public: itkNewMacro(Self); /** Run-time type information (and related methods). */ - itkTypeMacro(MetricModule1, ModuleIOBase); + itkTypeMacro(MetricModule1, ModuleBase); /** define the Clone method */ // itkCloneMacro(Self); diff --git a/Modules/Core/Install/itkMetricModule1Factory.h b/Modules/Core/Install/itkMetricModule1Factory.h index 909a373c..daf9a90f 100644 --- a/Modules/Core/Install/itkMetricModule1Factory.h +++ b/Modules/Core/Install/itkMetricModule1Factory.h @@ -18,8 +18,8 @@ #ifndef itkMetricModule1Factory_h #define itkMetricModule1Factory_h -#include "itkModuleFactoryBase.h" -#include "itkModuleIOBase.h" +#include "itkModuleFactory.h" +#include "itkModuleBase.h" namespace itk { @@ -27,12 +27,12 @@ namespace itk * \brief Create instances of MetaImageIO objects using an object factory. * \ingroup ITKIOMeta */ -class MetricModule1Factory:public ModuleFactoryBase + class MetricModule1Factory :public ObjectFactoryBase { public: /** Standard class typedefs. */ typedef MetricModule1Factory Self; - typedef ModuleFactoryBase Superclass; + typedef ObjectFactoryBase Superclass; typedef SmartPointer< Self > Pointer; typedef SmartPointer< const Self > ConstPointer; @@ -45,14 +45,14 @@ public: itkFactorylessNewMacro(Self); /** Run-time type information (and related methods). */ - itkTypeMacro(MetricModule1Factory, ModuleFactoryBase); + itkTypeMacro(MetricModule1Factory, ObjectFactoryBase); /** Register one factory of this type */ static void RegisterOneFactory() { MetricModule1Factory::Pointer MetricModule1Factory = MetricModule1Factory::New(); - ModuleFactoryBase::RegisterFactory(MetricModule1Factory); + ObjectFactoryBase::RegisterFactory(MetricModule1Factory); } protected: diff --git a/Modules/Core/Install/itkMetricModule1Factory.hxx b/Modules/Core/Install/itkMetricModule1Factory.hxx index 6c869e7f..a55c3e11 100644 --- a/Modules/Core/Install/itkMetricModule1Factory.hxx +++ b/Modules/Core/Install/itkMetricModule1Factory.hxx @@ -24,7 +24,7 @@ namespace itk MetricModule1Factory::MetricModule1Factory() { - this->RegisterOverride( "itkModuleIOBase", + this->RegisterOverride( "itkModuleBase", "itkMetricModule1", "Metric Module 1", 1, diff --git a/Modules/Core/Install/itkModuleIOBase.h b/Modules/Core/Install/itkModuleBase.h similarity index 80% rename from Modules/Core/Install/itkModuleIOBase.h rename to Modules/Core/Install/itkModuleBase.h index b21b49f8..b4125786 100644 --- a/Modules/Core/Install/itkModuleIOBase.h +++ b/Modules/Core/Install/itkModuleBase.h @@ -15,8 +15,8 @@ * limitations under the License. * *=========================================================================*/ -#ifndef itkModuleIOBase_h -#define itkModuleIOBase_h +#ifndef itkModuleBase_h +#define itkModuleBase_h #include "itkLightProcessObject.h" //#include "itkModuleBase.h" @@ -29,30 +29,30 @@ namespace itk { -/** \class ModuleIOBaseTemplate +/** \class ModuleBaseTemplate * * \brief Abstract superclass defining the Module IO interface. * - * ModuleIOBaseTemplate is a pure virtual base class for derived classes that + * ModuleBaseTemplate is a pure virtual base class for derived classes that * read/write Module data considering the type of input Module. - * First, ModuleIOBase is derived from this class for legacy read/write Module. + * First, ModuleBase is derived from this class for legacy read/write Module. * This class also is used by the ModuleFileReader and ModuleFileWriter - * classes. End users don't directly manipulate classes derived from ModuleIOBaseTemplate; - * the ModuleIOFactory is used by the Reader/Writer to pick a concrete derived class to do + * classes. End users don't directly manipulate classes derived from ModuleBaseTemplate; + * the ModuleFactory is used by the Reader/Writer to pick a concrete derived class to do * the actual reading/writing of Modules. * * \ingroup ITKIOModuleBase */ -class ModuleIOBase:public LightProcessObject +class ModuleBase:public LightProcessObject { public: /** Standard class typedefs */ - typedef ModuleIOBase Self; + typedef ModuleBase Self; typedef LightProcessObject Superclass; typedef SmartPointer< Self > Pointer; /** Run-time type information (and related methods). */ - itkTypeMacro(ModuleIOBase, Superclass); + itkTypeMacro(ModuleBase, Superclass); /** Module types */ //typedef TScalar ScalarType; @@ -78,13 +78,13 @@ public: /** Writes the Module list to disk. */ virtual void Write() = 0; - /** Determine the file type. Returns true if this ModuleIO can read the + /** Determine the file type. Returns true if this Module can read the * file specified. */ virtual bool MeetsCriteria(const CriteriaType &criteria) = 0; protected: - ModuleIOBase() {}; - virtual ~ModuleIOBase() {}; + ModuleBase() {}; + virtual ~ModuleBase() {}; //virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE; std::string m_FileName; @@ -94,4 +94,4 @@ protected: } // end namespace itk -#endif // itkModuleIOBase_h +#endif // itkModuleBase_h diff --git a/Modules/Core/Install/itkModuleFactoryBase.h b/Modules/Core/Install/itkModuleFactory.h similarity index 62% rename from Modules/Core/Install/itkModuleFactoryBase.h rename to Modules/Core/Install/itkModuleFactory.h index ffde5992..c0a3f1b5 100644 --- a/Modules/Core/Install/itkModuleFactoryBase.h +++ b/Modules/Core/Install/itkModuleFactory.h @@ -15,57 +15,67 @@ * limitations under the License. * *=========================================================================*/ -#ifndef itkModuleFactoryBase_h -#define itkModuleFactoryBase_h +#ifndef itkModuleFactory_h +#define itkModuleFactory_h -#include "itkObjectFactoryBase.h" -#include "itkModuleIOBase.h" +#include "itkObjectFactory.h" +#include "itkModuleBase.h" namespace itk { -/** \class ModuleFactoryBase +/** \class ModuleFactor * \brief Create instances of MetaImageIO objects using an object factory. * \ingroup ITKIOMeta */ -class ModuleFactoryBase:public ObjectFactoryBase +class ModuleFactory:public Object { public: /** Standard class typedefs. */ - typedef ModuleFactoryBase Self; - typedef ObjectFactoryBase Superclass; + typedef ModuleFactory Self; + typedef Object Superclass; typedef SmartPointer< Self > Pointer; typedef 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(ModuleFactoryBase, ObjectFactoryBase); + itkTypeMacro(ModuleFactory, Object); /** Convenient typedefs. */ - typedef ModuleIOBase::Pointer ModuleIOBasePointer; - typedef ModuleIOBase::CriteriaType CriteriaType; + typedef ModuleBase::Pointer ModuleBasePointer; + typedef ModuleBase::CriteriaType CriteriaType; + + typedef std::list< typename ModuleBasePointer > ModuleListType; + /** set selection criteria for possibleModules*/ + void SetCriteria(const CriteriaType &criteria); + + /** Narrow selection criteria*/ + void AddCriteria(const CriteriaType &criteria); + /** Create the appropriate ModuleIO depending on * the particulars of the file. */ - static ModuleIOBasePointer - CreateModuleIO(const CriteriaType &criteria); + static ModuleBasePointer + CreateModule(const CriteriaType &criteria); + protected: - ModuleFactoryBase() {}; - ~ModuleFactoryBase() {}; + CriteriaType m_Criteria; + mutable ModuleListType m_PossibleModules; + ModuleFactory(); + ~ModuleFactory(); private: - ModuleFactoryBase(const Self &); //purposely not implemented + ModuleFactory(const Self &); //purposely not implemented void operator=(const Self &); //purposely not implemented }; } // end namespace itk #ifndef ITK_MANUAL_INSTANTIATION -#include "itkModuleFactoryBase.hxx" +#include "itkModuleFactory.hxx" #endif #endif diff --git a/Modules/Core/Install/itkModuleFactoryBase.hxx b/Modules/Core/Install/itkModuleFactory.hxx similarity index 65% rename from Modules/Core/Install/itkModuleFactoryBase.hxx rename to Modules/Core/Install/itkModuleFactory.hxx index 6cfb301d..44405689 100644 --- a/Modules/Core/Install/itkModuleFactoryBase.hxx +++ b/Modules/Core/Install/itkModuleFactory.hxx @@ -15,34 +15,44 @@ * limitations under the License. * *=========================================================================*/ -#ifndef itkModuleFactoryBase_hxx -#define itkModuleFactoryBase_hxx +#ifndef itkModuleFactory_hxx +#define itkModuleFactory_hxx -#include "itkModuleFactoryBase.h" +#include "itkModuleFactory.h" namespace itk { -ModuleIOBase::Pointer ModuleFactoryBase::CreateModuleIO(const CriteriaType &criteria) +ModuleFactory::ModuleFactory() + { + this->m_PossibleModules.clear(); + } +ModuleFactory::~ModuleFactory() + { + } + + + +ModuleBase::Pointer ModuleFactory::CreateModule(const CriteriaType &criteria) { - std::list< typename ModuleIOBase::Pointer > possibleModuleIO; + std::list< typename ModuleBase::Pointer > possibleModules; // std::list< LightObject::Pointer > allobjects = // ObjectFactoryBase::CreateAllInstance("itkModuleIOBaseTemplate"); std::list< LightObject::Pointer > allobjects = - ObjectFactoryBase::CreateAllInstance("itkModuleIOBase"); + ObjectFactoryBase::CreateAllInstance("itkModuleBase"); for ( std::list< LightObject::Pointer >::iterator i = allobjects.begin(); i != allobjects.end(); ++i ) { - ModuleIOBase *io = - dynamic_cast< ModuleIOBase * >( i->GetPointer() ); + ModuleBase *io = + dynamic_cast< ModuleBase * >( i->GetPointer() ); if ( io ) { - possibleModuleIO.push_back(io); + possibleModules.push_back(io); } } - for ( std::list< typename ModuleIOBase::Pointer >::iterator k = possibleModuleIO.begin(); - k != possibleModuleIO.end(); ++k ) + for (std::list< typename ModuleBase::Pointer >::iterator k = possibleModules.begin(); + k != possibleModules.end(); ++k) { if ( ( *k )->MeetsCriteria(criteria) ) { diff --git a/Modules/Core/Install/itkTransformModule1.h b/Modules/Core/Install/itkTransformModule1.h index 959ab694..f9b87e45 100644 --- a/Modules/Core/Install/itkTransformModule1.h +++ b/Modules/Core/Install/itkTransformModule1.h @@ -1,16 +1,16 @@ #ifndef itkTransformModule1_h #define itkTransformModule1_h -#include "itkModuleIOBase.h" +#include "itkModuleBase.h" namespace itk { -class TransformModule1 : public ModuleIOBase +class TransformModule1 : public ModuleBase { public: /** Standard class typedefs. */ typedef TransformModule1 Self; - typedef ModuleIOBase Superclass; + typedef ModuleBase Superclass; typedef SmartPointer< Self > Pointer; typedef SmartPointer< const Self > ConstPointer; @@ -18,7 +18,7 @@ public: itkNewMacro(Self); /** Run-time type information (and related methods). */ - itkTypeMacro(TransformModule1, ModuleIOBase); + itkTypeMacro(TransformModule1, ModuleBase); /** define the Clone method */ // itkCloneMacro(Self); diff --git a/Modules/Core/Install/itkTransformModule1Factory.h b/Modules/Core/Install/itkTransformModule1Factory.h index c8bcdd49..050552d2 100644 --- a/Modules/Core/Install/itkTransformModule1Factory.h +++ b/Modules/Core/Install/itkTransformModule1Factory.h @@ -18,8 +18,8 @@ #ifndef itkTransformModule1Factory_h #define itkTransformModule1Factory_h -#include "itkModuleFactoryBase.h" -#include "itkModuleIOBase.h" +#include "itkModuleFactory.h" +#include "itkModuleBase.h" namespace itk { @@ -27,12 +27,12 @@ namespace itk * \brief Create instances of MetaImageIO objects using an object factory. * \ingroup ITKIOMeta */ -class TransformModule1Factory:public ModuleFactoryBase + class TransformModule1Factory :public ObjectFactoryBase { public: /** Standard class typedefs. */ typedef TransformModule1Factory Self; - typedef ModuleFactoryBase Superclass; + typedef ObjectFactoryBase Superclass; typedef SmartPointer< Self > Pointer; typedef SmartPointer< const Self > ConstPointer; @@ -45,14 +45,14 @@ public: itkFactorylessNewMacro(Self); /** Run-time type information (and related methods). */ - itkTypeMacro(TransformModule1Factory, ModuleFactoryBase); + itkTypeMacro(TransformModule1Factory, ObjectFactoryBase); /** Register one factory of this type */ static void RegisterOneFactory() { TransformModule1Factory::Pointer transformModule1Factory = TransformModule1Factory::New(); - ModuleFactoryBase::RegisterFactory(transformModule1Factory); + ObjectFactoryBase::RegisterFactory(transformModule1Factory); } protected: diff --git a/Modules/Core/Install/itkTransformModule1Factory.hxx b/Modules/Core/Install/itkTransformModule1Factory.hxx index bd87dade..97712f6c 100644 --- a/Modules/Core/Install/itkTransformModule1Factory.hxx +++ b/Modules/Core/Install/itkTransformModule1Factory.hxx @@ -24,7 +24,7 @@ namespace itk TransformModule1Factory::TransformModule1Factory() { - this->RegisterOverride( "itkModuleIOBase", + this->RegisterOverride( "itkModuleBase", "itkTransformModule1", "Transform Module 1", 1, diff --git a/Modules/Core/Install/itkfactory.cxx b/Modules/Core/Install/itkfactory.cxx index 0e91a026..f3fea881 100644 --- a/Modules/Core/Install/itkfactory.cxx +++ b/Modules/Core/Install/itkfactory.cxx @@ -15,7 +15,7 @@ * limitations under the License. * *=========================================================================*/ -//#include "itkModuleIOFactoryRegisterManager.h" +//#include "itkModuleFactoryRegisterManager.h" #include "itkImageFileReader.h" #include "itkImageFileWriter.h" @@ -30,14 +30,15 @@ #include "itkTransformFactory.h" #include "itkMatrixOffsetTransformBase.h" -//Floris: The module factory is based on the transformIO factory. -// By default it creates 2 dummy modules: itkTransformModule1 and itkMetricModule1 -//CMake\UseITK.cmake sets up the IOFactory_Register_Manager for transforms and images +//Floris: The module factory is based on the ImageIO factory. +// We manually register 2 dummy modules: itkTransformModule1 and itkMetricModule1. +// in ITK CMake\UseITK.cmake sets up the IOFactory_Register_Manager for transforms and images +// Elastix (by Denis) uses (simpleITK's) Typelists to register all GPU filters //#include "itkModuleFactoryBase.h" //#include "itkModuleFactory.h" -#include "itkModuleIOBase.h" -//#include "itkModuleIOFactory.h" +#include "itkModuleBase.h" +//#include "itkModuleFactory.h" #include <map> #include <string> @@ -54,7 +55,7 @@ int main(int argc, char *argv[]) typedef std::list< itk::LightObject::Pointer > RegisteredObjectsContainerType; RegisteredObjectsContainerType registeredIOs = - itk::ObjectFactoryBase::CreateAllInstance("itkModuleIOBase"); + itk::ObjectFactoryBase::CreateAllInstance("itkModuleBase"); std::cout << "When CMake is not used to register the IO classes, there are\n" << registeredIOs.size() << " IO objects available to the Overlord.\n" << std::endl; @@ -63,21 +64,11 @@ int main(int argc, char *argv[]) itk::TransformModule1Factory::RegisterOneFactory(); itk::MetricModule1Factory::RegisterOneFactory(); std::cout << "there are\n"; - registeredIOs = itk::ObjectFactoryBase::CreateAllInstance("itkModuleIOBase"); + registeredIOs = itk::ObjectFactoryBase::CreateAllInstance("itkModuleBase"); std::cout << registeredIOs.size() << " IO objects available to the Overlord.\n" << std::endl; - std::cout << "Now, when we try to read a MetaImage, we will "; - //typedef itk::ModuleBaseTemplate< ScalarType > ModuleType; - //typedef itk::ModuleFactoryBase ModuleFactoryType; - - typedef itk::ModuleIOBase ModuleIOType; - //typedef itk::ModuleIOFactoryTemplate< ScalarType > ModuleFactoryIOType; - std::string moduleName("Metric"); - - //register a 3rd module - //typedef itk::TransformModule1< double, 3, 3 > TransformModule1Type; - //itk::ModuleFactory<TransformModule1Type>::RegisterModule(); + typedef itk::ModuleBase ModuleType; typedef std::map<std::string, std::string> CriteriaType; typedef std::pair<std::string, std::string> CriteriumType; @@ -90,12 +81,12 @@ int main(int argc, char *argv[]) //criteria1.insert(CriteriumType("ModuleInput", "Metric")); - ModuleIOType::Pointer Node1 = itk::ModuleFactoryBase::CreateModuleIO(criteria1); - - ModuleIOType::Pointer Node2 = itk::ModuleFactoryBase::CreateModuleIO(criteria2); - + ModuleType::Pointer Node1 = itk::ModuleFactory::CreateModule(criteria1); + ModuleType::Pointer Node2 = itk::ModuleFactory::CreateModule(criteria2); + + return EXIT_SUCCESS; } \ No newline at end of file diff --git a/Testing/Unit/CMakeLists.txt b/Testing/Unit/CMakeLists.txt index 15246366..404c59a4 100644 --- a/Testing/Unit/CMakeLists.txt +++ b/Testing/Unit/CMakeLists.txt @@ -6,6 +6,7 @@ set( ElastixUnitTestFilenames elxExampleUnitTest.cxx itkRegistration.cxx + itkFactory.cxx ) # --------------------------------------------------------------------- -- GitLab