Skip to content
Snippets Groups Projects
Commit 6c8f2fee authored by Floris Berendsen's avatar Floris Berendsen
Browse files

WIP: removed IO from names. ModuleFactory not derived from

ObjectFactoryBase anymore
parent d1860bb9
No related branches found
No related tags found
No related merge requests found
...@@ -9,5 +9,5 @@ ELSE(ITK_FOUND) ...@@ -9,5 +9,5 @@ ELSE(ITK_FOUND)
MESSAGE(FATAL_ERROR "ITK not found. Please set ITK_DIR.") MESSAGE(FATAL_ERROR "ITK not found. Please set ITK_DIR.")
ENDIF(ITK_FOUND) 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 ) TARGET_LINK_LIBRARIES(itkfactory ${ITK_LIBRARIES} ITKCommon )
#ifndef itkMetricModule1_h #ifndef itkMetricModule1_h
#define itkMetricModule1_h #define itkMetricModule1_h
#include "itkModuleIOBase.h" #include "itkModuleBase.h"
namespace itk namespace itk
{ {
class MetricModule1 : public ModuleIOBase class MetricModule1 : public ModuleBase
{ {
public: public:
/** Standard class typedefs. */ /** Standard class typedefs. */
typedef MetricModule1 Self; typedef MetricModule1 Self;
typedef ModuleIOBase Superclass; typedef ModuleBase Superclass;
typedef SmartPointer< Self > Pointer; typedef SmartPointer< Self > Pointer;
typedef SmartPointer< const Self > ConstPointer; typedef SmartPointer< const Self > ConstPointer;
...@@ -18,7 +18,7 @@ public: ...@@ -18,7 +18,7 @@ public:
itkNewMacro(Self); itkNewMacro(Self);
/** Run-time type information (and related methods). */ /** Run-time type information (and related methods). */
itkTypeMacro(MetricModule1, ModuleIOBase); itkTypeMacro(MetricModule1, ModuleBase);
/** define the Clone method */ /** define the Clone method */
// itkCloneMacro(Self); // itkCloneMacro(Self);
......
...@@ -18,8 +18,8 @@ ...@@ -18,8 +18,8 @@
#ifndef itkMetricModule1Factory_h #ifndef itkMetricModule1Factory_h
#define itkMetricModule1Factory_h #define itkMetricModule1Factory_h
#include "itkModuleFactoryBase.h" #include "itkModuleFactory.h"
#include "itkModuleIOBase.h" #include "itkModuleBase.h"
namespace itk namespace itk
{ {
...@@ -27,12 +27,12 @@ namespace itk ...@@ -27,12 +27,12 @@ namespace itk
* \brief Create instances of MetaImageIO objects using an object factory. * \brief Create instances of MetaImageIO objects using an object factory.
* \ingroup ITKIOMeta * \ingroup ITKIOMeta
*/ */
class MetricModule1Factory:public ModuleFactoryBase class MetricModule1Factory :public ObjectFactoryBase
{ {
public: public:
/** Standard class typedefs. */ /** Standard class typedefs. */
typedef MetricModule1Factory Self; typedef MetricModule1Factory Self;
typedef ModuleFactoryBase Superclass; typedef ObjectFactoryBase Superclass;
typedef SmartPointer< Self > Pointer; typedef SmartPointer< Self > Pointer;
typedef SmartPointer< const Self > ConstPointer; typedef SmartPointer< const Self > ConstPointer;
...@@ -45,14 +45,14 @@ public: ...@@ -45,14 +45,14 @@ public:
itkFactorylessNewMacro(Self); itkFactorylessNewMacro(Self);
/** Run-time type information (and related methods). */ /** Run-time type information (and related methods). */
itkTypeMacro(MetricModule1Factory, ModuleFactoryBase); itkTypeMacro(MetricModule1Factory, ObjectFactoryBase);
/** Register one factory of this type */ /** Register one factory of this type */
static void RegisterOneFactory() static void RegisterOneFactory()
{ {
MetricModule1Factory::Pointer MetricModule1Factory = MetricModule1Factory::New(); MetricModule1Factory::Pointer MetricModule1Factory = MetricModule1Factory::New();
ModuleFactoryBase::RegisterFactory(MetricModule1Factory); ObjectFactoryBase::RegisterFactory(MetricModule1Factory);
} }
protected: protected:
......
...@@ -24,7 +24,7 @@ namespace itk ...@@ -24,7 +24,7 @@ namespace itk
MetricModule1Factory::MetricModule1Factory() MetricModule1Factory::MetricModule1Factory()
{ {
this->RegisterOverride( "itkModuleIOBase", this->RegisterOverride( "itkModuleBase",
"itkMetricModule1", "itkMetricModule1",
"Metric Module 1", "Metric Module 1",
1, 1,
......
...@@ -15,8 +15,8 @@ ...@@ -15,8 +15,8 @@
* limitations under the License. * limitations under the License.
* *
*=========================================================================*/ *=========================================================================*/
#ifndef itkModuleIOBase_h #ifndef itkModuleBase_h
#define itkModuleIOBase_h #define itkModuleBase_h
#include "itkLightProcessObject.h" #include "itkLightProcessObject.h"
//#include "itkModuleBase.h" //#include "itkModuleBase.h"
...@@ -29,30 +29,30 @@ ...@@ -29,30 +29,30 @@
namespace itk namespace itk
{ {
/** \class ModuleIOBaseTemplate /** \class ModuleBaseTemplate
* *
* \brief Abstract superclass defining the Module IO interface. * \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. * 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 * This class also is used by the ModuleFileReader and ModuleFileWriter
* classes. End users don't directly manipulate classes derived from ModuleIOBaseTemplate; * classes. End users don't directly manipulate classes derived from ModuleBaseTemplate;
* the ModuleIOFactory is used by the Reader/Writer to pick a concrete derived class to do * the ModuleFactory is used by the Reader/Writer to pick a concrete derived class to do
* the actual reading/writing of Modules. * the actual reading/writing of Modules.
* *
* \ingroup ITKIOModuleBase * \ingroup ITKIOModuleBase
*/ */
class ModuleIOBase:public LightProcessObject class ModuleBase:public LightProcessObject
{ {
public: public:
/** Standard class typedefs */ /** Standard class typedefs */
typedef ModuleIOBase Self; typedef ModuleBase Self;
typedef LightProcessObject Superclass; typedef LightProcessObject Superclass;
typedef SmartPointer< Self > Pointer; typedef SmartPointer< Self > Pointer;
/** Run-time type information (and related methods). */ /** Run-time type information (and related methods). */
itkTypeMacro(ModuleIOBase, Superclass); itkTypeMacro(ModuleBase, Superclass);
/** Module types */ /** Module types */
//typedef TScalar ScalarType; //typedef TScalar ScalarType;
...@@ -78,13 +78,13 @@ public: ...@@ -78,13 +78,13 @@ public:
/** Writes the Module list to disk. */ /** Writes the Module list to disk. */
virtual void Write() = 0; 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. */ * file specified. */
virtual bool MeetsCriteria(const CriteriaType &criteria) = 0; virtual bool MeetsCriteria(const CriteriaType &criteria) = 0;
protected: protected:
ModuleIOBase() {}; ModuleBase() {};
virtual ~ModuleIOBase() {}; virtual ~ModuleBase() {};
//virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE; //virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
std::string m_FileName; std::string m_FileName;
...@@ -94,4 +94,4 @@ protected: ...@@ -94,4 +94,4 @@ protected:
} // end namespace itk } // end namespace itk
#endif // itkModuleIOBase_h #endif // itkModuleBase_h
...@@ -15,57 +15,67 @@ ...@@ -15,57 +15,67 @@
* limitations under the License. * limitations under the License.
* *
*=========================================================================*/ *=========================================================================*/
#ifndef itkModuleFactoryBase_h #ifndef itkModuleFactory_h
#define itkModuleFactoryBase_h #define itkModuleFactory_h
#include "itkObjectFactoryBase.h" #include "itkObjectFactory.h"
#include "itkModuleIOBase.h" #include "itkModuleBase.h"
namespace itk namespace itk
{ {
/** \class ModuleFactoryBase /** \class ModuleFactor
* \brief Create instances of MetaImageIO objects using an object factory. * \brief Create instances of MetaImageIO objects using an object factory.
* \ingroup ITKIOMeta * \ingroup ITKIOMeta
*/ */
class ModuleFactoryBase:public ObjectFactoryBase class ModuleFactory:public Object
{ {
public: public:
/** Standard class typedefs. */ /** Standard class typedefs. */
typedef ModuleFactoryBase Self; typedef ModuleFactory Self;
typedef ObjectFactoryBase Superclass; typedef Object Superclass;
typedef SmartPointer< Self > Pointer; typedef SmartPointer< Self > Pointer;
typedef SmartPointer< const Self > ConstPointer; typedef SmartPointer< const Self > ConstPointer;
/** Class methods used to interface with the registered factories. */ /** Class methods used to interface with the registered factories. */
//virtual const char * GetITKSourceVersion() const { return ITK_SOURCE_VERSION; } //virtual const char * GetITKSourceVersion() const { return ITK_SOURCE_VERSION; }
/** Run-time type information (and related methods). */ /** Run-time type information (and related methods). */
itkTypeMacro(ModuleFactoryBase, ObjectFactoryBase); itkTypeMacro(ModuleFactory, Object);
/** Convenient typedefs. */ /** Convenient typedefs. */
typedef ModuleIOBase::Pointer ModuleIOBasePointer; typedef ModuleBase::Pointer ModuleBasePointer;
typedef ModuleIOBase::CriteriaType CriteriaType; 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 /** Create the appropriate ModuleIO depending on
* the particulars of the file. * the particulars of the file.
*/ */
static ModuleIOBasePointer static ModuleBasePointer
CreateModuleIO(const CriteriaType &criteria); CreateModule(const CriteriaType &criteria);
protected: protected:
ModuleFactoryBase() {}; CriteriaType m_Criteria;
~ModuleFactoryBase() {}; mutable ModuleListType m_PossibleModules;
ModuleFactory();
~ModuleFactory();
private: private:
ModuleFactoryBase(const Self &); //purposely not implemented ModuleFactory(const Self &); //purposely not implemented
void operator=(const Self &); //purposely not implemented void operator=(const Self &); //purposely not implemented
}; };
} // end namespace itk } // end namespace itk
#ifndef ITK_MANUAL_INSTANTIATION #ifndef ITK_MANUAL_INSTANTIATION
#include "itkModuleFactoryBase.hxx" #include "itkModuleFactory.hxx"
#endif #endif
#endif #endif
...@@ -15,34 +15,44 @@ ...@@ -15,34 +15,44 @@
* limitations under the License. * limitations under the License.
* *
*=========================================================================*/ *=========================================================================*/
#ifndef itkModuleFactoryBase_hxx #ifndef itkModuleFactory_hxx
#define itkModuleFactoryBase_hxx #define itkModuleFactory_hxx
#include "itkModuleFactoryBase.h" #include "itkModuleFactory.h"
namespace itk 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 = // std::list< LightObject::Pointer > allobjects =
// ObjectFactoryBase::CreateAllInstance("itkModuleIOBaseTemplate"); // ObjectFactoryBase::CreateAllInstance("itkModuleIOBaseTemplate");
std::list< LightObject::Pointer > allobjects = std::list< LightObject::Pointer > allobjects =
ObjectFactoryBase::CreateAllInstance("itkModuleIOBase"); ObjectFactoryBase::CreateAllInstance("itkModuleBase");
for ( std::list< LightObject::Pointer >::iterator i = allobjects.begin(); for ( std::list< LightObject::Pointer >::iterator i = allobjects.begin();
i != allobjects.end(); ++i ) i != allobjects.end(); ++i )
{ {
ModuleIOBase *io = ModuleBase *io =
dynamic_cast< ModuleIOBase * >( i->GetPointer() ); dynamic_cast< ModuleBase * >( i->GetPointer() );
if ( io ) if ( io )
{ {
possibleModuleIO.push_back(io); possibleModules.push_back(io);
} }
} }
for ( std::list< typename ModuleIOBase::Pointer >::iterator k = possibleModuleIO.begin(); for (std::list< typename ModuleBase::Pointer >::iterator k = possibleModules.begin();
k != possibleModuleIO.end(); ++k ) k != possibleModules.end(); ++k)
{ {
if ( ( *k )->MeetsCriteria(criteria) ) if ( ( *k )->MeetsCriteria(criteria) )
{ {
......
#ifndef itkTransformModule1_h #ifndef itkTransformModule1_h
#define itkTransformModule1_h #define itkTransformModule1_h
#include "itkModuleIOBase.h" #include "itkModuleBase.h"
namespace itk namespace itk
{ {
class TransformModule1 : public ModuleIOBase class TransformModule1 : public ModuleBase
{ {
public: public:
/** Standard class typedefs. */ /** Standard class typedefs. */
typedef TransformModule1 Self; typedef TransformModule1 Self;
typedef ModuleIOBase Superclass; typedef ModuleBase Superclass;
typedef SmartPointer< Self > Pointer; typedef SmartPointer< Self > Pointer;
typedef SmartPointer< const Self > ConstPointer; typedef SmartPointer< const Self > ConstPointer;
...@@ -18,7 +18,7 @@ public: ...@@ -18,7 +18,7 @@ public:
itkNewMacro(Self); itkNewMacro(Self);
/** Run-time type information (and related methods). */ /** Run-time type information (and related methods). */
itkTypeMacro(TransformModule1, ModuleIOBase); itkTypeMacro(TransformModule1, ModuleBase);
/** define the Clone method */ /** define the Clone method */
// itkCloneMacro(Self); // itkCloneMacro(Self);
......
...@@ -18,8 +18,8 @@ ...@@ -18,8 +18,8 @@
#ifndef itkTransformModule1Factory_h #ifndef itkTransformModule1Factory_h
#define itkTransformModule1Factory_h #define itkTransformModule1Factory_h
#include "itkModuleFactoryBase.h" #include "itkModuleFactory.h"
#include "itkModuleIOBase.h" #include "itkModuleBase.h"
namespace itk namespace itk
{ {
...@@ -27,12 +27,12 @@ namespace itk ...@@ -27,12 +27,12 @@ namespace itk
* \brief Create instances of MetaImageIO objects using an object factory. * \brief Create instances of MetaImageIO objects using an object factory.
* \ingroup ITKIOMeta * \ingroup ITKIOMeta
*/ */
class TransformModule1Factory:public ModuleFactoryBase class TransformModule1Factory :public ObjectFactoryBase
{ {
public: public:
/** Standard class typedefs. */ /** Standard class typedefs. */
typedef TransformModule1Factory Self; typedef TransformModule1Factory Self;
typedef ModuleFactoryBase Superclass; typedef ObjectFactoryBase Superclass;
typedef SmartPointer< Self > Pointer; typedef SmartPointer< Self > Pointer;
typedef SmartPointer< const Self > ConstPointer; typedef SmartPointer< const Self > ConstPointer;
...@@ -45,14 +45,14 @@ public: ...@@ -45,14 +45,14 @@ public:
itkFactorylessNewMacro(Self); itkFactorylessNewMacro(Self);
/** Run-time type information (and related methods). */ /** Run-time type information (and related methods). */
itkTypeMacro(TransformModule1Factory, ModuleFactoryBase); itkTypeMacro(TransformModule1Factory, ObjectFactoryBase);
/** Register one factory of this type */ /** Register one factory of this type */
static void RegisterOneFactory() static void RegisterOneFactory()
{ {
TransformModule1Factory::Pointer transformModule1Factory = TransformModule1Factory::New(); TransformModule1Factory::Pointer transformModule1Factory = TransformModule1Factory::New();
ModuleFactoryBase::RegisterFactory(transformModule1Factory); ObjectFactoryBase::RegisterFactory(transformModule1Factory);
} }
protected: protected:
......
...@@ -24,7 +24,7 @@ namespace itk ...@@ -24,7 +24,7 @@ namespace itk
TransformModule1Factory::TransformModule1Factory() TransformModule1Factory::TransformModule1Factory()
{ {
this->RegisterOverride( "itkModuleIOBase", this->RegisterOverride( "itkModuleBase",
"itkTransformModule1", "itkTransformModule1",
"Transform Module 1", "Transform Module 1",
1, 1,
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
* *
*=========================================================================*/ *=========================================================================*/
//#include "itkModuleIOFactoryRegisterManager.h" //#include "itkModuleFactoryRegisterManager.h"
#include "itkImageFileReader.h" #include "itkImageFileReader.h"
#include "itkImageFileWriter.h" #include "itkImageFileWriter.h"
...@@ -30,14 +30,15 @@ ...@@ -30,14 +30,15 @@
#include "itkTransformFactory.h" #include "itkTransformFactory.h"
#include "itkMatrixOffsetTransformBase.h" #include "itkMatrixOffsetTransformBase.h"
//Floris: The module factory is based on the transformIO factory. //Floris: The module factory is based on the ImageIO factory.
// By default it creates 2 dummy modules: itkTransformModule1 and itkMetricModule1 // We manually register 2 dummy modules: itkTransformModule1 and itkMetricModule1.
//CMake\UseITK.cmake sets up the IOFactory_Register_Manager for transforms and images // 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 "itkModuleFactoryBase.h"
//#include "itkModuleFactory.h" //#include "itkModuleFactory.h"
#include "itkModuleIOBase.h" #include "itkModuleBase.h"
//#include "itkModuleIOFactory.h" //#include "itkModuleFactory.h"
#include <map> #include <map>
#include <string> #include <string>
...@@ -54,7 +55,7 @@ int main(int argc, char *argv[]) ...@@ -54,7 +55,7 @@ int main(int argc, char *argv[])
typedef std::list< itk::LightObject::Pointer > RegisteredObjectsContainerType; typedef std::list< itk::LightObject::Pointer > RegisteredObjectsContainerType;
RegisteredObjectsContainerType registeredIOs = 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" std::cout << "When CMake is not used to register the IO classes, there are\n"
<< registeredIOs.size() << registeredIOs.size()
<< " IO objects available to the Overlord.\n" << std::endl; << " IO objects available to the Overlord.\n" << std::endl;
...@@ -63,21 +64,11 @@ int main(int argc, char *argv[]) ...@@ -63,21 +64,11 @@ int main(int argc, char *argv[])
itk::TransformModule1Factory::RegisterOneFactory(); itk::TransformModule1Factory::RegisterOneFactory();
itk::MetricModule1Factory::RegisterOneFactory(); itk::MetricModule1Factory::RegisterOneFactory();
std::cout << "there are\n"; std::cout << "there are\n";
registeredIOs = itk::ObjectFactoryBase::CreateAllInstance("itkModuleIOBase"); registeredIOs = itk::ObjectFactoryBase::CreateAllInstance("itkModuleBase");
std::cout << registeredIOs.size() std::cout << registeredIOs.size()
<< " IO objects available to the Overlord.\n" << std::endl; << " IO objects available to the Overlord.\n" << std::endl;
std::cout << "Now, when we try to read a MetaImage, we will "; typedef itk::ModuleBase ModuleType;
//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 std::map<std::string, std::string> CriteriaType; typedef std::map<std::string, std::string> CriteriaType;
typedef std::pair<std::string, std::string> CriteriumType; typedef std::pair<std::string, std::string> CriteriumType;
...@@ -90,12 +81,12 @@ int main(int argc, char *argv[]) ...@@ -90,12 +81,12 @@ int main(int argc, char *argv[])
//criteria1.insert(CriteriumType("ModuleInput", "Metric")); //criteria1.insert(CriteriumType("ModuleInput", "Metric"));
ModuleIOType::Pointer Node1 = itk::ModuleFactoryBase::CreateModuleIO(criteria1); ModuleType::Pointer Node1 = itk::ModuleFactory::CreateModule(criteria1);
ModuleIOType::Pointer Node2 = itk::ModuleFactoryBase::CreateModuleIO(criteria2);
ModuleType::Pointer Node2 = itk::ModuleFactory::CreateModule(criteria2);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
\ No newline at end of file
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
set( ElastixUnitTestFilenames set( ElastixUnitTestFilenames
elxExampleUnitTest.cxx elxExampleUnitTest.cxx
itkRegistration.cxx itkRegistration.cxx
itkFactory.cxx
) )
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment