diff --git a/Modules/Core/Install/CmakeLists.txt b/Modules/Core/Install/CmakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..73a1feefe530a9ddbf0216c35074149a59aba9ea --- /dev/null +++ b/Modules/Core/Install/CmakeLists.txt @@ -0,0 +1,13 @@ +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) + +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) +TARGET_LINK_LIBRARIES(itkfactory ${ITK_LIBRARIES} ITKCommon ) diff --git a/Modules/Core/Install/itkMetricModule1.h b/Modules/Core/Install/itkMetricModule1.h index 9df36b313e9259dc0fb95d1c501f27499579b926..ec3637371178e305be2417d023da4cf6081d47a0 100644 --- a/Modules/Core/Install/itkMetricModule1.h +++ b/Modules/Core/Install/itkMetricModule1.h @@ -1,19 +1,16 @@ #ifndef itkMetricModule1_h #define itkMetricModule1_h -#include "itkModuleBase.h" +#include "itkModuleIOBase.h" namespace itk { -template <typename TScalar, - unsigned int NInputDimensions = 3, - unsigned int NOutputDimensions = 3> -class MetricModule1 : public ModuleBaseTemplate< TScalar > +class MetricModule1 : public ModuleIOBase { public: /** Standard class typedefs. */ typedef MetricModule1 Self; - typedef ModuleBaseTemplate< TScalar > Superclass; + typedef ModuleIOBase Superclass; typedef SmartPointer< Self > Pointer; typedef SmartPointer< const Self > ConstPointer; @@ -21,13 +18,17 @@ public: itkNewMacro(Self); /** Run-time type information (and related methods). */ - itkTypeMacro(MetricModule1, ModuleBaseTemplate); + itkTypeMacro(MetricModule1, ModuleIOBase); /** define the Clone method */ // itkCloneMacro(Self); /** Type of the scalar representing coordinate and vector elements. */ - typedef TScalar ScalarType; + //typedef TScalar ScalarType; + + typedef Superclass::CriteriaType CriteriaType; + typedef Superclass::CriteriumType CriteriumType; + std::string GetModuleTypeAsString() const; protected: /** @@ -35,7 +36,7 @@ protected: * This does a complete copy of the Metric * state to the new Metric */ - virtual typename LightObject::Pointer InternalClone() const ITK_OVERRIDE; + virtual LightObject::Pointer InternalClone() const ITK_OVERRIDE; MetricModule1(); virtual ~MetricModule1() @@ -46,13 +47,6 @@ private: MetricModule1(const Self &); // purposely not implemented void operator=(const Self &); // purposely not implemented - template <typename TType> - std::string GetModuleTypeAsString(TType *) const - { - std::string rval("other"); - - return rval; - } std::string GetModuleTypeAsString(float *) const { @@ -67,7 +61,9 @@ private: return rval; } - + virtual void Read(); + virtual void Write(); + virtual bool MeetsCriteria(const CriteriaType&); }; } // end namespace itk diff --git a/Modules/Core/Install/itkMetricModule1.hxx b/Modules/Core/Install/itkMetricModule1.hxx index 749e23eb09efd1c4b51799459f1c6290b78499f5..670ee08551094212d105cfe1fa99b57281dd4bf7 100644 --- a/Modules/Core/Install/itkMetricModule1.hxx +++ b/Modules/Core/Install/itkMetricModule1.hxx @@ -22,44 +22,29 @@ namespace itk { - -template <typename TScalar, - unsigned int NInputDimensions, - unsigned int NOutputDimensions> -MetricModule1<TScalar, NInputDimensions, NOutputDimensions> -::MetricModule1() + MetricModule1::MetricModule1() { } - -template <typename TScalar, - unsigned int NInputDimensions, - unsigned int NOutputDimensions> -std::string MetricModule1<TScalar, NInputDimensions, NOutputDimensions> -::GetModuleTypeAsString() const +std::string MetricModule1::GetModuleTypeAsString() const { std::ostringstream n; n << GetNameOfClass(); n << "_"; - n << this->GetModuleTypeAsString(static_cast<TScalar *>(ITK_NULLPTR)); + n << this->GetModuleTypeAsString(static_cast<float *>(ITK_NULLPTR)); //n << "_" << this->GetInputSpaceDimension() << "_" << this->GetOutputSpaceDimension(); return n.str(); } - -template <typename TScalar, - unsigned int NInputDimensions, - unsigned int NOutputDimensions> -typename LightObject::Pointer -MetricModule1<TScalar, NInputDimensions, NOutputDimensions> -::InternalClone() const +LightObject::Pointer +MetricModule1::InternalClone() const { // Default implementation just copies the parameters from // this to new Metric. - typename LightObject::Pointer loPtr = Superclass::InternalClone(); + LightObject::Pointer loPtr = Superclass::InternalClone(); - typename Self::Pointer rval = + Self::Pointer rval = dynamic_cast<Self *>(loPtr.GetPointer()); if(rval.IsNull()) { @@ -73,6 +58,62 @@ MetricModule1<TScalar, NInputDimensions, NOutputDimensions> } + void + MetricModule1 + ::Read() +{ + return; +} + + + void + MetricModule1 + ::Write() +{ + return; +} + + bool + MetricModule1 + ::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(), "ModuleOutput") == 0) + { + if (strcmp(it->second.c_str(), "Metric") != 0) + { + meetsCriteria = false; + return false; + } + } + else if (strcmp(it->first.c_str(), "ModuleInput") == 0) + { + if (strcmp(it->second.c_str(), "Transform") != 0) + { + meetsCriteria = false; + return false; + } + } + else + { + hasUndefinedCriteria = true; + } + + } + return meetsCriteria; +} } // end namespace itk diff --git a/Modules/Core/Install/itkMetricModule1Factory.h b/Modules/Core/Install/itkMetricModule1Factory.h new file mode 100644 index 0000000000000000000000000000000000000000..909a373cdb673a2a965709ac1e5d39cdda15f031 --- /dev/null +++ b/Modules/Core/Install/itkMetricModule1Factory.h @@ -0,0 +1,72 @@ +/*========================================================================= + * + * 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 itkMetricModule1Factory_h +#define itkMetricModule1Factory_h + +#include "itkModuleFactoryBase.h" +#include "itkModuleIOBase.h" + +namespace itk +{ +/** \class MetricModule1Factory + * \brief Create instances of MetaImageIO objects using an object factory. + * \ingroup ITKIOMeta + */ +class MetricModule1Factory:public ModuleFactoryBase +{ +public: + /** Standard class typedefs. */ + typedef MetricModule1Factory Self; + typedef ModuleFactoryBase Superclass; + typedef SmartPointer< Self > Pointer; + typedef 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(MetricModule1Factory, ModuleFactoryBase); + + /** Register one factory of this type */ + static void RegisterOneFactory() + { + MetricModule1Factory::Pointer MetricModule1Factory = MetricModule1Factory::New(); + + ModuleFactoryBase::RegisterFactory(MetricModule1Factory); + } + +protected: + MetricModule1Factory(); + ~MetricModule1Factory() {}; + +private: + MetricModule1Factory(const Self &); //purposely not implemented + void operator=(const Self &); //purposely not implemented +}; +} // end namespace itk + + +#ifndef ITK_MANUAL_INSTANTIATION +#include "itkMetricModule1Factory.hxx" +#endif +#endif diff --git a/Modules/Core/Install/itkMetricModule1Factory.hxx b/Modules/Core/Install/itkMetricModule1Factory.hxx new file mode 100644 index 0000000000000000000000000000000000000000..6c869e7f9ee11c160e357de1dc8626806a825442 --- /dev/null +++ b/Modules/Core/Install/itkMetricModule1Factory.hxx @@ -0,0 +1,60 @@ +/*========================================================================= + * + * 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 "itkMetricModule1Factory.h" +#include "itkMetricModule1.h" +#include "itkVersion.h" + +namespace itk +{ + +MetricModule1Factory::MetricModule1Factory() +{ + this->RegisterOverride( "itkModuleIOBase", + "itkMetricModule1", + "Metric Module 1", + 1, + CreateObjectFunction< MetricModule1 >::New() ); //float +} + +const char * +MetricModule1Factory::GetITKSourceVersion() const +{ + return ITK_SOURCE_VERSION; +} + +const char * +MetricModule1Factory::GetDescription() const +{ + return "Test module 1 for Metrics"; +} + +// Undocumented API used to register during static initialization. +// DO NOT CALL DIRECTLY. +/* +static bool MetricModule1FactoryHasBeenRegistered; + +void MetricModule1FactoryRegister__Private(void) +{ + if( ! MetricModule1FactoryHasBeenRegistered ) + { + MetricModule1FactoryHasBeenRegistered = true; + MetricModule1Factory::RegisterOneFactory(); + } +} +*/ +} // end namespace itk diff --git a/Modules/Core/Install/itkModuleBase.h b/Modules/Core/Install/itkModuleBase.h deleted file mode 100644 index 51adc2cfc7c1c8b285ae90ecb05b6b5aa9bba974..0000000000000000000000000000000000000000 --- a/Modules/Core/Install/itkModuleBase.h +++ /dev/null @@ -1,79 +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 itkModuleBase_h -#define itkModuleBase_h - -#include "itkObject.h" -#include "itkObjectFactory.h" -#include "itkIntTypes.h" - -namespace itk -{ - /** \class itkModuleBaseTemplate - * - * This class is an abstract class to represent a spatial Module. - * - * This class is templated over the scalar type used to store the Module's - * parameters. - * - * \ingroup ITKModule - */ - template< typename TScalar > - class ModuleBaseTemplate :public Object - { - public: - /** Standard class typedefs. */ - typedef ModuleBaseTemplate Self; - typedef Object Superclass; - typedef SmartPointer< Self > Pointer; - typedef SmartPointer< const Self > ConstPointer; - - /** Type of the input parameters. */ - typedef TScalar ParametersValueType; - //typedef OptimizerParameters< ParametersValueType > ParametersType; - - /** Run-time type information (and related methods). */ - itkTypeMacro(ModuleBaseTemplate, Object); - - /** Generate a platform independent name */ - virtual std::string GetModuleTypeAsString() const = 0; - /* - typedef enum { - UnknownModuleCategory=0, - Linear=1, - BSpline=2, - Spline=3, - DisplacementField=4, - VelocityField=5 - } ModuleCategoryType; - */ - /** Get Module category */ - //virtual ModuleCategoryType GetModuleCategory() const = 0; - - protected: - ModuleBaseTemplate(){} - virtual ~ModuleBaseTemplate() {} - - private: - ModuleBaseTemplate(const Self &); //purposely not implemented - void operator=(const Self &); //purposely not implemented - }; - -} // end namespace itk - -#endif diff --git a/Modules/Core/Install/itkModuleFactory.h b/Modules/Core/Install/itkModuleFactory.h deleted file mode 100644 index 50fa98b8c913b75720235f68ce61aefd8100979a..0000000000000000000000000000000000000000 --- a/Modules/Core/Install/itkModuleFactory.h +++ /dev/null @@ -1,59 +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. - * - *=========================================================================*/ -/*========================================================================= - * - * Portions of this file are subject to the VTK Toolkit Version 3 copyright. - * - * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen - * - * For complete copyright, license and disclaimer of warranty information - * please refer to the NOTICE file at the top of the ITK source tree. - * - *=========================================================================*/ -#ifndef itkModuleFactory_h -#define itkModuleFactory_h - -#include "itkModuleFactoryBase.h" - -namespace itk -{ -/** \class ModuleFactory - * \brief Create instances of Transforms - * \ingroup ITKIOTransformBase - */ - -template< typename T > -class ModuleFactory:public ModuleFactoryBase -{ -public: - static void RegisterModule() - { - typename T::Pointer t = T::New(); - - ModuleFactoryBase::Pointer f = ModuleFactoryBase::GetFactory(); - - f->RegisterModule ( t->GetModuleTypeAsString().c_str(), - t->GetModuleTypeAsString().c_str(), - t->GetModuleTypeAsString().c_str(), - 1, - CreateObjectFunction< T >::New() ); - } -}; -} // end namespace itk - -#endif diff --git a/Modules/Core/Install/itkModuleFactoryBase.cxx b/Modules/Core/Install/itkModuleFactoryBase.cxx deleted file mode 100644 index 69df185a5599fbc0f9b52feef1e4885a6588e952..0000000000000000000000000000000000000000 --- a/Modules/Core/Install/itkModuleFactoryBase.cxx +++ /dev/null @@ -1,70 +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. - * - *=========================================================================*/ -#include "itkModuleFactory.h" -#include "itkVersion.h" - -#include "itkTransformModule1.h" -#include "itkMetricModule1.h" - -namespace itk -{ -ModuleFactoryBase *ModuleFactoryBase:: m_Factory = ITK_NULLPTR; - -namespace ModuleFactoryBasePrivate -{ -bool DefaultModulesRegistered = false; -} - -ModuleFactoryBase::ModuleFactoryBase() -{} - -ModuleFactoryBase::~ModuleFactoryBase() -{} - -void ModuleFactoryBase::RegisterDefaultModules() -{ - // - // make sure that the the factory instance has - // been created. All normal paths to this method - // already do this but this makes certain sure it's done - (void)ModuleFactoryBase::GetFactory(); - - if ( !ModuleFactoryBasePrivate::DefaultModulesRegistered ) - { - // - // double instances (in alphabetical order) - // - ModuleFactory< TransformModule1< double, 2 > >::RegisterModule (); - ModuleFactory< MetricModule1< double, 2 > >::RegisterModule (); - - } - ModuleFactoryBasePrivate::DefaultModulesRegistered = true; -} - -const char * -ModuleFactoryBase::GetITKSourceVersion(void) const -{ - return ITK_SOURCE_VERSION; -} - -const char * -ModuleFactoryBase::GetDescription() const -{ - return "Module FactoryBase"; -} -} // end namespace itk diff --git a/Modules/Core/Install/itkModuleFactoryBase.h b/Modules/Core/Install/itkModuleFactoryBase.h index 749008422332d3ef3a4c48af28e2cdf006509f95..ffde5992b435067323c81d6197e6af74d82834bf 100644 --- a/Modules/Core/Install/itkModuleFactoryBase.h +++ b/Modules/Core/Install/itkModuleFactoryBase.h @@ -15,84 +15,57 @@ * limitations under the License. * *=========================================================================*/ -/*========================================================================= - * - * Portions of this file are subject to the VTK Toolkit Version 3 copyright. - * - * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen - * - * For complete copyright, license and disclaimer of warranty information - * please refer to the NOTICE file at the top of the ITK source tree. - * - *=========================================================================*/ #ifndef itkModuleFactoryBase_h #define itkModuleFactoryBase_h #include "itkObjectFactoryBase.h" +#include "itkModuleIOBase.h" namespace itk { - /** \class ModuleFactoryBase - * \brief Create instances of Modules - * \ingroup ITKIOModuleBase - */ - - class ModuleFactoryBase :public ObjectFactoryBase - { - public: - /** Standard class typedefs. */ - typedef ModuleFactoryBase Self; - typedef ObjectFactoryBase Superclass; - typedef SmartPointer< Self > Pointer; - typedef SmartPointer< const Self > ConstPointer; - - /** Class methods used to interface with the registered factories. */ - virtual const char * GetITKSourceVersion(void) const ITK_OVERRIDE; - - virtual const char * GetDescription(void) const ITK_OVERRIDE; - - /** Run-time type information (and related methods). */ - itkTypeMacro(ModuleFactoryBase, ObjectFactoryBase); +/** \class ModuleFactoryBase + * \brief Create instances of MetaImageIO objects using an object factory. + * \ingroup ITKIOMeta + */ +class ModuleFactoryBase:public ObjectFactoryBase +{ +public: + /** Standard class typedefs. */ + typedef ModuleFactoryBase Self; + typedef ObjectFactoryBase Superclass; + typedef SmartPointer< Self > Pointer; + typedef SmartPointer< const Self > ConstPointer; - /** Method for class instantiation. */ - itkFactorylessNewMacro(Self); - /** Register all builtin Modules */ - static void RegisterDefaultModules(); - /** Register this Module */ - static ModuleFactoryBase * GetFactory() - { - if (m_Factory == ITK_NULLPTR) - { - // Make and register the factory - Pointer p = New(); - m_Factory = p.GetPointer(); - ObjectFactoryBase::RegisterFactory(p); - p->RegisterDefaultModules(); - } - return m_Factory; - } + /** Class methods used to interface with the registered factories. */ + //virtual const char * GetITKSourceVersion() const { return ITK_SOURCE_VERSION; } - void RegisterModule(const char *classOverride, - const char *overrideClassName, - const char *description, - bool enableFlag, - CreateObjectFunctionBase *createFunction) - { - this->RegisterOverride(classOverride, overrideClassName, description, enableFlag, createFunction); - } + /** Run-time type information (and related methods). */ + itkTypeMacro(ModuleFactoryBase, ObjectFactoryBase); + + /** Convenient typedefs. */ + typedef ModuleIOBase::Pointer ModuleIOBasePointer; + typedef ModuleIOBase::CriteriaType CriteriaType; - protected: - ModuleFactoryBase(); - virtual ~ModuleFactoryBase(); + /** Create the appropriate ModuleIO depending on + * the particulars of the file. + */ + static ModuleIOBasePointer + CreateModuleIO(const CriteriaType &criteria); - private: - ModuleFactoryBase(const Self &); //purposely not implemented - void operator=(const Self &); //purposely not implemented +protected: + ModuleFactoryBase() {}; + ~ModuleFactoryBase() {}; - static ModuleFactoryBase *m_Factory; - }; +private: + ModuleFactoryBase(const Self &); //purposely not implemented + void operator=(const Self &); //purposely not implemented +}; } // end namespace itk +#ifndef ITK_MANUAL_INSTANTIATION +#include "itkModuleFactoryBase.hxx" +#endif + #endif diff --git a/Modules/Core/Install/itkModuleFactoryBase.hxx b/Modules/Core/Install/itkModuleFactoryBase.hxx new file mode 100644 index 0000000000000000000000000000000000000000..6cfb301db780cb50660a79b2e5c89a75c99a750b --- /dev/null +++ b/Modules/Core/Install/itkModuleFactoryBase.hxx @@ -0,0 +1,56 @@ +/*========================================================================= + * + * 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 itkModuleFactoryBase_hxx +#define itkModuleFactoryBase_hxx + +#include "itkModuleFactoryBase.h" + +namespace itk +{ + +ModuleIOBase::Pointer ModuleFactoryBase::CreateModuleIO(const CriteriaType &criteria) +{ + std::list< typename ModuleIOBase::Pointer > possibleModuleIO; +// std::list< LightObject::Pointer > allobjects = +// ObjectFactoryBase::CreateAllInstance("itkModuleIOBaseTemplate"); + std::list< LightObject::Pointer > allobjects = + ObjectFactoryBase::CreateAllInstance("itkModuleIOBase"); + + for ( std::list< LightObject::Pointer >::iterator i = allobjects.begin(); + i != allobjects.end(); ++i ) + { + ModuleIOBase *io = + dynamic_cast< ModuleIOBase * >( i->GetPointer() ); + if ( io ) + { + possibleModuleIO.push_back(io); + } + } + for ( std::list< typename ModuleIOBase::Pointer >::iterator k = possibleModuleIO.begin(); + k != possibleModuleIO.end(); ++k ) + { + if ( ( *k )->MeetsCriteria(criteria) ) + { + return *k; + } + } + return ITK_NULLPTR; +} +} // end namespace itk + +#endif diff --git a/Modules/Core/Install/itkModuleIOBase.h b/Modules/Core/Install/itkModuleIOBase.h new file mode 100644 index 0000000000000000000000000000000000000000..b21b49f86eec439b2e504c96b42e4294c37b4869 --- /dev/null +++ b/Modules/Core/Install/itkModuleIOBase.h @@ -0,0 +1,97 @@ +/*========================================================================= + * + * 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 itkModuleIOBase_h +#define itkModuleIOBase_h + +#include "itkLightProcessObject.h" +//#include "itkModuleBase.h" +#include <list> +#include <iostream> +#include <fstream> +#include <string> +#include <map> + +namespace itk +{ + +/** \class ModuleIOBaseTemplate + * + * \brief Abstract superclass defining the Module IO interface. + * + * ModuleIOBaseTemplate 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. + * 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 + * the actual reading/writing of Modules. + * + * \ingroup ITKIOModuleBase + */ +class ModuleIOBase:public LightProcessObject +{ +public: + /** Standard class typedefs */ + typedef ModuleIOBase Self; + typedef LightProcessObject Superclass; + typedef SmartPointer< Self > Pointer; + + /** Run-time type information (and related methods). */ + itkTypeMacro(ModuleIOBase, Superclass); + + /** Module types */ + //typedef TScalar ScalarType; + //typedef ModuleBaseTemplate<ScalarType> ModuleType; + /** For writing, a const Module list gets passed in, for + * reading, a non-const Module list is created from the file. + */ + //typedef typename ModuleType::Pointer ModulePointer; + //typedef std::list< ModulePointer > ModuleListType; + //typedef typename ModuleType::ConstPointer ConstModulePointer; + //typedef std::list< ConstModulePointer > ConstModuleListType; + + 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 Module list to disk. */ + virtual void Write() = 0; + + /** Determine the file type. Returns true if this ModuleIO can read the + * file specified. */ + virtual bool MeetsCriteria(const CriteriaType &criteria) = 0; + +protected: + ModuleIOBase() {}; + virtual ~ModuleIOBase() {}; + //virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE; + + std::string m_FileName; + +}; + +} // end namespace itk + + +#endif // itkModuleIOBase_h diff --git a/Modules/Core/Install/itkTransformModule1.h b/Modules/Core/Install/itkTransformModule1.h index 69e772e4a40ad08c03148127dd5e7d32ffd2a1ab..959ab694216da02694b15d143d0bc1e2edb5fa01 100644 --- a/Modules/Core/Install/itkTransformModule1.h +++ b/Modules/Core/Install/itkTransformModule1.h @@ -1,19 +1,16 @@ #ifndef itkTransformModule1_h #define itkTransformModule1_h -#include "itkModuleBase.h" +#include "itkModuleIOBase.h" namespace itk { -template <typename TScalar, - unsigned int NInputDimensions = 3, - unsigned int NOutputDimensions = 3> -class TransformModule1 : public ModuleBaseTemplate< TScalar > +class TransformModule1 : public ModuleIOBase { public: /** Standard class typedefs. */ typedef TransformModule1 Self; - typedef ModuleBaseTemplate< TScalar > Superclass; + typedef ModuleIOBase Superclass; typedef SmartPointer< Self > Pointer; typedef SmartPointer< const Self > ConstPointer; @@ -21,43 +18,25 @@ public: itkNewMacro(Self); /** Run-time type information (and related methods). */ - itkTypeMacro(TransformModule1, ModuleBaseTemplate); + itkTypeMacro(TransformModule1, ModuleIOBase); /** define the Clone method */ - //itkCloneMacro(Self); + // itkCloneMacro(Self); /** Type of the scalar representing coordinate and vector elements. */ - typedef TScalar ScalarType; + //typedef TScalar ScalarType; - /** Dimension of the domain space. */ - itkStaticConstMacro(InputSpaceDimension, unsigned int, NInputDimensions); - itkStaticConstMacro(OutputSpaceDimension, unsigned int, NOutputDimensions); + typedef Superclass::CriteriaType CriteriaType; + typedef Superclass::CriteriumType CriteriumType; - /** Get the size of the input space */ - unsigned int GetInputSpaceDimension(void) const ITK_OVERRIDE - { - return NInputDimensions; - } - - /** Get the size of the output space */ - unsigned int GetOutputSpaceDimension(void) const ITK_OVERRIDE - { - return NOutputDimensions; - } - - /** Standard coordinate point type for this class */ - //typedef Point<TScalar, NInputDimensions> InputPointType; - //typedef Point<TScalar, NOutputDimensions> OutputPointType; - - //virtual OutputPointType TransformPoint(const InputPointType &) const = 0; - virtual std::string GetModuleTypeAsString() const; + std::string GetModuleTypeAsString() const; protected: /** - * Clone the current transform. - * This does a complete copy of the transform - * state to the new transform + * Clone the current Transform. + * This does a complete copy of the Transform + * state to the new Transform */ - virtual typename LightObject::Pointer InternalClone() const ITK_OVERRIDE; + virtual LightObject::Pointer InternalClone() const ITK_OVERRIDE; TransformModule1(); virtual ~TransformModule1() @@ -68,13 +47,6 @@ private: TransformModule1(const Self &); // purposely not implemented void operator=(const Self &); // purposely not implemented - template <typename TType> - std::string GetModuleTypeAsString(TType *) const - { - std::string rval("other"); - - return rval; - } std::string GetModuleTypeAsString(float *) const { @@ -89,7 +61,9 @@ private: return rval; } - + virtual void Read(); + virtual void Write(); + virtual bool MeetsCriteria(const CriteriaType&); }; } // end namespace itk diff --git a/Modules/Core/Install/itkTransformModule1.hxx b/Modules/Core/Install/itkTransformModule1.hxx index a976d67fc63997b54e5cef5a37ab2d9650f6a45e..4ca520a8882046f747ac58bc90a9cddd37254fb1 100644 --- a/Modules/Core/Install/itkTransformModule1.hxx +++ b/Modules/Core/Install/itkTransformModule1.hxx @@ -22,45 +22,29 @@ namespace itk { + TransformModule1::TransformModule1() + { + } -template <typename TScalar, - unsigned int NInputDimensions, - unsigned int NOutputDimensions> -TransformModule1<TScalar, NInputDimensions, NOutputDimensions> -::TransformModule1() -{ -} - - - -template <typename TScalar, - unsigned int NInputDimensions, - unsigned int NOutputDimensions> - std::string TransformModule1<TScalar, NInputDimensions, NOutputDimensions> -::GetModuleTypeAsString() const +std::string TransformModule1::GetModuleTypeAsString() const { std::ostringstream n; n << GetNameOfClass(); n << "_"; - n << this->GetModuleTypeAsString(static_cast<TScalar *>(ITK_NULLPTR) ); - n << "_" << this->GetInputSpaceDimension() << "_" << this->GetOutputSpaceDimension(); + n << this->GetModuleTypeAsString(static_cast<float *>(ITK_NULLPTR)); + //n << "_" << this->GetInputSpaceDimension() << "_" << this->GetOutputSpaceDimension(); return n.str(); } - -template <typename TScalar, - unsigned int NInputDimensions, - unsigned int NOutputDimensions> -typename LightObject::Pointer -TransformModule1<TScalar, NInputDimensions, NOutputDimensions> -::InternalClone() const +LightObject::Pointer +TransformModule1::InternalClone() const { // Default implementation just copies the parameters from - // this to new transform. - typename LightObject::Pointer loPtr = Superclass::InternalClone(); + // this to new Transform. + LightObject::Pointer loPtr = Superclass::InternalClone(); - typename Self::Pointer rval = + Self::Pointer rval = dynamic_cast<Self *>(loPtr.GetPointer()); if(rval.IsNull()) { @@ -74,6 +58,62 @@ TransformModule1<TScalar, NInputDimensions, NOutputDimensions> } + void + TransformModule1 + ::Read() +{ + return; +} + + + void + TransformModule1 + ::Write() +{ + return; +} + + bool + TransformModule1 + ::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(), "ModuleOutput") == 0) + { + if (strcmp(it->second.c_str(), "Transform") != 0) + { + meetsCriteria = false; + return false; + } + } + else if (strcmp(it->first.c_str(), "ModuleInput") == 0) + { + if (strcmp(it->second.c_str(), "Sampler") != 0) + { + meetsCriteria = false; + return false; + } + } + else + { + hasUndefinedCriteria = true; + } + + } + return meetsCriteria; +} } // end namespace itk diff --git a/Modules/Core/Install/itkTransformModule1Factory.h b/Modules/Core/Install/itkTransformModule1Factory.h new file mode 100644 index 0000000000000000000000000000000000000000..c8bcdd49d632edc8106e9185c5d5e2d71906514e --- /dev/null +++ b/Modules/Core/Install/itkTransformModule1Factory.h @@ -0,0 +1,72 @@ +/*========================================================================= + * + * 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 itkTransformModule1Factory_h +#define itkTransformModule1Factory_h + +#include "itkModuleFactoryBase.h" +#include "itkModuleIOBase.h" + +namespace itk +{ +/** \class TransformModule1Factory + * \brief Create instances of MetaImageIO objects using an object factory. + * \ingroup ITKIOMeta + */ +class TransformModule1Factory:public ModuleFactoryBase +{ +public: + /** Standard class typedefs. */ + typedef TransformModule1Factory Self; + typedef ModuleFactoryBase Superclass; + typedef SmartPointer< Self > Pointer; + typedef 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(TransformModule1Factory, ModuleFactoryBase); + + /** Register one factory of this type */ + static void RegisterOneFactory() + { + TransformModule1Factory::Pointer transformModule1Factory = TransformModule1Factory::New(); + + ModuleFactoryBase::RegisterFactory(transformModule1Factory); + } + +protected: + TransformModule1Factory(); + ~TransformModule1Factory(){}; + +private: + TransformModule1Factory(const Self &); //purposely not implemented + void operator=(const Self &); //purposely not implemented +}; +} // end namespace itk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "itkTransformModule1Factory.hxx" +#endif + +#endif diff --git a/Modules/Core/Install/itkTransformModule1Factory.hxx b/Modules/Core/Install/itkTransformModule1Factory.hxx new file mode 100644 index 0000000000000000000000000000000000000000..bd87dadea9437f1e519b06e2384387b69d4dfe4e --- /dev/null +++ b/Modules/Core/Install/itkTransformModule1Factory.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 "itkTransformModule1Factory.h" +#include "itkTransformModule1.h" +#include "itkVersion.h" + +namespace itk +{ + +TransformModule1Factory::TransformModule1Factory() +{ + this->RegisterOverride( "itkModuleIOBase", + "itkTransformModule1", + "Transform Module 1", + 1, + CreateObjectFunction< TransformModule1 >::New() ); //float +} + + +const char * +TransformModule1Factory::GetITKSourceVersion() const +{ + return ITK_SOURCE_VERSION; +} + +const char * +TransformModule1Factory::GetDescription() const +{ + return "Test module 1 for transforms"; +} + +// Undocumented API used to register during static initialization. +// DO NOT CALL DIRECTLY. + +/*static bool TransformModule1FactoryHasBeenRegistered; + +void TransformModule1FactoryRegister__Private(void) +{ + if( ! TransformModule1FactoryHasBeenRegistered ) + { + TransformModule1FactoryHasBeenRegistered = true; + TransformModule1Factory::RegisterOneFactory(); + } +} +*/ +} // end namespace itk diff --git a/Modules/Core/Install/itkfactory.cxx b/Modules/Core/Install/itkfactory.cxx index faea2e2e0bfd83d257f52d3a222b00c78b6e74ba..0e91a0269e2f1f65b921f01cb2b6ac5ddf24a764 100644 --- a/Modules/Core/Install/itkfactory.cxx +++ b/Modules/Core/Install/itkfactory.cxx @@ -15,10 +15,10 @@ * limitations under the License. * *=========================================================================*/ +//#include "itkModuleIOFactoryRegisterManager.h" #include "itkImageFileReader.h" #include "itkImageFileWriter.h" - #include "itkDisplacementFieldTransform.h" #include "itkComposeDisplacementFieldsImageFilter.h" #include "itkCompositeTransform.h" @@ -32,35 +32,70 @@ //Floris: The module factory is based on the transformIO factory. // By default it creates 2 dummy modules: itkTransformModule1 and itkMetricModule1 -#include "itkModuleFactoryBase.h" -#include "itkModuleFactory.h" +//CMake\UseITK.cmake sets up the IOFactory_Register_Manager for transforms and images +//#include "itkModuleFactoryBase.h" +//#include "itkModuleFactory.h" + +#include "itkModuleIOBase.h" +//#include "itkModuleIOFactory.h" + +#include <map> +#include <string> + +#include "itkTransformModule1.h" +#include "itkTransformModule1Factory.h" +#include "itkMetricModule1.h" +#include "itkMetricModule1Factory.h" int main(int argc, char *argv[]) { - std::string fileName; - if (argc == 1) // No arguments were provided - { - fileName = "test.tfm"; - } - else - { - fileName = argv[1]; - } - - typedef itk::MatrixOffsetTransformBase< double, 3, 3 > MatrixOffsetTransformType; - itk::TransformFactory<MatrixOffsetTransformType>::RegisterTransform(); - -#if (ITK_VERSION_MAJOR == 4 && ITK_VERSION_MINOR >= 5) || ITK_VERSION_MAJOR > 4 - itk::TransformFileReaderTemplate<float>::Pointer reader = - itk::TransformFileReaderTemplate<float>::New(); -#else - itk::TransformFileReader::Pointer reader = itk::TransformFileReader::New(); -#endif - reader->SetFileName(fileName); - reader->Update(); - - std::cout << *(reader->GetTransformList()->begin()) << std::endl; + typedef float ScalarType; + + typedef std::list< itk::LightObject::Pointer > RegisteredObjectsContainerType; + RegisteredObjectsContainerType registeredIOs = + itk::ObjectFactoryBase::CreateAllInstance("itkModuleIOBase"); + 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; + + std::cout << "After registering the TransformModule1 object, "; + itk::TransformModule1Factory::RegisterOneFactory(); + itk::MetricModule1Factory::RegisterOneFactory(); + std::cout << "there are\n"; + registeredIOs = itk::ObjectFactoryBase::CreateAllInstance("itkModuleIOBase"); + 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 std::map<std::string, std::string> CriteriaType; + typedef std::pair<std::string, std::string> CriteriumType; + + CriteriaType criteria1; + //criteria1.insert(CriteriumType("ModuleOutput","Metric")); + criteria1["ModuleOutput"] = "Transform"; + CriteriaType criteria2; + criteria2["ModuleInput"] = "Transform"; + //criteria1.insert(CriteriumType("ModuleInput", "Metric")); + + + ModuleIOType::Pointer Node1 = itk::ModuleFactoryBase::CreateModuleIO(criteria1); + + ModuleIOType::Pointer Node2 = itk::ModuleFactoryBase::CreateModuleIO(criteria2); + + + return EXIT_SUCCESS; } \ No newline at end of file