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

ADD: Component database with 2 modules. Module creation based on criteria

check
parent fa65c221
No related branches found
No related tags found
No related merge requests found
Showing
with 688 additions and 198 deletions
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 )
#ifndef itkMetricModule1_h #ifndef itkMetricModule1_h
#define itkMetricModule1_h #define itkMetricModule1_h
#include "itkModuleBase.h" #include "itkModuleIOBase.h"
namespace itk namespace itk
{ {
template <typename TScalar, class MetricModule1 : public ModuleIOBase
unsigned int NInputDimensions = 3,
unsigned int NOutputDimensions = 3>
class MetricModule1 : public ModuleBaseTemplate< TScalar >
{ {
public: public:
/** Standard class typedefs. */ /** Standard class typedefs. */
typedef MetricModule1 Self; typedef MetricModule1 Self;
typedef ModuleBaseTemplate< TScalar > Superclass; typedef ModuleIOBase Superclass;
typedef SmartPointer< Self > Pointer; typedef SmartPointer< Self > Pointer;
typedef SmartPointer< const Self > ConstPointer; typedef SmartPointer< const Self > ConstPointer;
...@@ -21,13 +18,17 @@ public: ...@@ -21,13 +18,17 @@ public:
itkNewMacro(Self); itkNewMacro(Self);
/** Run-time type information (and related methods). */ /** Run-time type information (and related methods). */
itkTypeMacro(MetricModule1, ModuleBaseTemplate); itkTypeMacro(MetricModule1, ModuleIOBase);
/** define the Clone method */ /** define the Clone method */
// itkCloneMacro(Self); // itkCloneMacro(Self);
/** Type of the scalar representing coordinate and vector elements. */ /** 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; std::string GetModuleTypeAsString() const;
protected: protected:
/** /**
...@@ -35,7 +36,7 @@ protected: ...@@ -35,7 +36,7 @@ protected:
* This does a complete copy of the Metric * This does a complete copy of the Metric
* state to the new Metric * state to the new Metric
*/ */
virtual typename LightObject::Pointer InternalClone() const ITK_OVERRIDE; virtual LightObject::Pointer InternalClone() const ITK_OVERRIDE;
MetricModule1(); MetricModule1();
virtual ~MetricModule1() virtual ~MetricModule1()
...@@ -46,13 +47,6 @@ private: ...@@ -46,13 +47,6 @@ private:
MetricModule1(const Self &); // purposely not implemented MetricModule1(const Self &); // purposely not implemented
void operator=(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 std::string GetModuleTypeAsString(float *) const
{ {
...@@ -67,7 +61,9 @@ private: ...@@ -67,7 +61,9 @@ private:
return rval; return rval;
} }
virtual void Read();
virtual void Write();
virtual bool MeetsCriteria(const CriteriaType&);
}; };
} // end namespace itk } // end namespace itk
......
...@@ -22,44 +22,29 @@ ...@@ -22,44 +22,29 @@
namespace itk namespace itk
{ {
MetricModule1::MetricModule1()
template <typename TScalar,
unsigned int NInputDimensions,
unsigned int NOutputDimensions>
MetricModule1<TScalar, NInputDimensions, NOutputDimensions>
::MetricModule1()
{ {
} }
std::string MetricModule1::GetModuleTypeAsString() const
template <typename TScalar,
unsigned int NInputDimensions,
unsigned int NOutputDimensions>
std::string MetricModule1<TScalar, NInputDimensions, NOutputDimensions>
::GetModuleTypeAsString() const
{ {
std::ostringstream n; std::ostringstream n;
n << GetNameOfClass(); n << GetNameOfClass();
n << "_"; n << "_";
n << this->GetModuleTypeAsString(static_cast<TScalar *>(ITK_NULLPTR)); n << this->GetModuleTypeAsString(static_cast<float *>(ITK_NULLPTR));
//n << "_" << this->GetInputSpaceDimension() << "_" << this->GetOutputSpaceDimension(); //n << "_" << this->GetInputSpaceDimension() << "_" << this->GetOutputSpaceDimension();
return n.str(); return n.str();
} }
LightObject::Pointer
template <typename TScalar, MetricModule1::InternalClone() const
unsigned int NInputDimensions,
unsigned int NOutputDimensions>
typename LightObject::Pointer
MetricModule1<TScalar, NInputDimensions, NOutputDimensions>
::InternalClone() const
{ {
// Default implementation just copies the parameters from // Default implementation just copies the parameters from
// this to new Metric. // 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()); dynamic_cast<Self *>(loPtr.GetPointer());
if(rval.IsNull()) if(rval.IsNull())
{ {
...@@ -73,6 +58,62 @@ MetricModule1<TScalar, NInputDimensions, NOutputDimensions> ...@@ -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 } // end namespace itk
......
...@@ -15,65 +15,58 @@ ...@@ -15,65 +15,58 @@
* limitations under the License. * limitations under the License.
* *
*=========================================================================*/ *=========================================================================*/
#ifndef itkModuleBase_h #ifndef itkMetricModule1Factory_h
#define itkModuleBase_h #define itkMetricModule1Factory_h
#include "itkObject.h" #include "itkModuleFactoryBase.h"
#include "itkObjectFactory.h" #include "itkModuleIOBase.h"
#include "itkIntTypes.h"
namespace itk namespace itk
{ {
/** \class itkModuleBaseTemplate /** \class MetricModule1Factory
* * \brief Create instances of MetaImageIO objects using an object factory.
* This class is an abstract class to represent a spatial Module. * \ingroup ITKIOMeta
* */
* This class is templated over the scalar type used to store the Module's class MetricModule1Factory:public ModuleFactoryBase
* parameters. {
* public:
* \ingroup ITKModule /** Standard class typedefs. */
*/ typedef MetricModule1Factory Self;
template< typename TScalar > typedef ModuleFactoryBase Superclass;
class ModuleBaseTemplate :public Object typedef SmartPointer< Self > Pointer;
{ typedef SmartPointer< const Self > ConstPointer;
public:
/** Standard class typedefs. */
typedef ModuleBaseTemplate Self;
typedef Object Superclass;
typedef SmartPointer< Self > Pointer;
typedef SmartPointer< const Self > ConstPointer;
/** Type of the input parameters. */ /** Class methods used to interface with the registered factories. */
typedef TScalar ParametersValueType; virtual const char * GetITKSourceVersion() const ITK_OVERRIDE;
//typedef OptimizerParameters< ParametersValueType > ParametersType;
/** Run-time type information (and related methods). */ virtual const char * GetDescription() const ITK_OVERRIDE;
itkTypeMacro(ModuleBaseTemplate, Object);
/** Generate a platform independent name */ /** Method for class instantiation. */
virtual std::string GetModuleTypeAsString() const = 0; itkFactorylessNewMacro(Self);
/*
typedef enum {
UnknownModuleCategory=0,
Linear=1,
BSpline=2,
Spline=3,
DisplacementField=4,
VelocityField=5
} ModuleCategoryType;
*/
/** Get Module category */
//virtual ModuleCategoryType GetModuleCategory() const = 0;
protected: /** Run-time type information (and related methods). */
ModuleBaseTemplate(){} itkTypeMacro(MetricModule1Factory, ModuleFactoryBase);
virtual ~ModuleBaseTemplate() {}
/** Register one factory of this type */
static void RegisterOneFactory()
{
MetricModule1Factory::Pointer MetricModule1Factory = MetricModule1Factory::New();
private: ModuleFactoryBase::RegisterFactory(MetricModule1Factory);
ModuleBaseTemplate(const Self &); //purposely not implemented }
void operator=(const Self &); //purposely not implemented
};
protected:
MetricModule1Factory();
~MetricModule1Factory() {};
private:
MetricModule1Factory(const Self &); //purposely not implemented
void operator=(const Self &); //purposely not implemented
};
} // end namespace itk } // end namespace itk
#ifndef ITK_MANUAL_INSTANTIATION
#include "itkMetricModule1Factory.hxx"
#endif
#endif #endif
/*=========================================================================
*
* 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
...@@ -15,84 +15,57 @@ ...@@ -15,84 +15,57 @@
* limitations under the License. * 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 #ifndef itkModuleFactoryBase_h
#define itkModuleFactoryBase_h #define itkModuleFactoryBase_h
#include "itkObjectFactoryBase.h" #include "itkObjectFactoryBase.h"
#include "itkModuleIOBase.h"
namespace itk namespace itk
{ {
/** \class ModuleFactoryBase /** \class ModuleFactoryBase
* \brief Create instances of Modules * \brief Create instances of MetaImageIO objects using an object factory.
* \ingroup ITKIOModuleBase * \ingroup ITKIOMeta
*/ */
class ModuleFactoryBase:public ObjectFactoryBase
class ModuleFactoryBase :public ObjectFactoryBase {
{ public:
public: /** Standard class typedefs. */
/** Standard class typedefs. */ typedef ModuleFactoryBase Self;
typedef ModuleFactoryBase Self; typedef ObjectFactoryBase Superclass;
typedef ObjectFactoryBase 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. */
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);
/** Method for class instantiation. */
itkFactorylessNewMacro(Self);
/** Register all builtin Modules */
static void RegisterDefaultModules();
/** Register this Module */ /** Class methods used to interface with the registered factories. */
static ModuleFactoryBase * GetFactory() //virtual const char * GetITKSourceVersion() const { return ITK_SOURCE_VERSION; }
{
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;
}
void RegisterModule(const char *classOverride, /** Run-time type information (and related methods). */
const char *overrideClassName, itkTypeMacro(ModuleFactoryBase, ObjectFactoryBase);
const char *description,
bool enableFlag, /** Convenient typedefs. */
CreateObjectFunctionBase *createFunction) typedef ModuleIOBase::Pointer ModuleIOBasePointer;
{ typedef ModuleIOBase::CriteriaType CriteriaType;
this->RegisterOverride(classOverride, overrideClassName, description, enableFlag, createFunction);
}
protected: /** Create the appropriate ModuleIO depending on
ModuleFactoryBase(); * the particulars of the file.
virtual ~ModuleFactoryBase(); */
static ModuleIOBasePointer
CreateModuleIO(const CriteriaType &criteria);
private: protected:
ModuleFactoryBase(const Self &); //purposely not implemented ModuleFactoryBase() {};
void operator=(const Self &); //purposely not implemented ~ModuleFactoryBase() {};
static ModuleFactoryBase *m_Factory; private:
}; ModuleFactoryBase(const Self &); //purposely not implemented
void operator=(const Self &); //purposely not implemented
};
} // end namespace itk } // end namespace itk
#ifndef ITK_MANUAL_INSTANTIATION
#include "itkModuleFactoryBase.hxx"
#endif
#endif #endif
...@@ -15,45 +15,42 @@ ...@@ -15,45 +15,42 @@
* limitations under the License. * limitations under the License.
* *
*=========================================================================*/ *=========================================================================*/
/*========================================================================= #ifndef itkModuleFactoryBase_hxx
* #define itkModuleFactoryBase_hxx
* 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" #include "itkModuleFactoryBase.h"
namespace itk namespace itk
{ {
/** \class ModuleFactory
* \brief Create instances of Transforms
* \ingroup ITKIOTransformBase
*/
template< typename T > ModuleIOBase::Pointer ModuleFactoryBase::CreateModuleIO(const CriteriaType &criteria)
class ModuleFactory:public ModuleFactoryBase
{ {
public: std::list< typename ModuleIOBase::Pointer > possibleModuleIO;
static void RegisterModule() // std::list< LightObject::Pointer > allobjects =
{ // ObjectFactoryBase::CreateAllInstance("itkModuleIOBaseTemplate");
typename T::Pointer t = T::New(); std::list< LightObject::Pointer > allobjects =
ObjectFactoryBase::CreateAllInstance("itkModuleIOBase");
ModuleFactoryBase::Pointer f = ModuleFactoryBase::GetFactory();
f->RegisterModule ( t->GetModuleTypeAsString().c_str(), for ( std::list< LightObject::Pointer >::iterator i = allobjects.begin();
t->GetModuleTypeAsString().c_str(), i != allobjects.end(); ++i )
t->GetModuleTypeAsString().c_str(), {
1, ModuleIOBase *io =
CreateObjectFunction< T >::New() ); 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 } // end namespace itk
#endif #endif
/*=========================================================================
*
* 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
#ifndef itkTransformModule1_h #ifndef itkTransformModule1_h
#define itkTransformModule1_h #define itkTransformModule1_h
#include "itkModuleBase.h" #include "itkModuleIOBase.h"
namespace itk namespace itk
{ {
template <typename TScalar, class TransformModule1 : public ModuleIOBase
unsigned int NInputDimensions = 3,
unsigned int NOutputDimensions = 3>
class TransformModule1 : public ModuleBaseTemplate< TScalar >
{ {
public: public:
/** Standard class typedefs. */ /** Standard class typedefs. */
typedef TransformModule1 Self; typedef TransformModule1 Self;
typedef ModuleBaseTemplate< TScalar > Superclass; typedef ModuleIOBase Superclass;
typedef SmartPointer< Self > Pointer; typedef SmartPointer< Self > Pointer;
typedef SmartPointer< const Self > ConstPointer; typedef SmartPointer< const Self > ConstPointer;
...@@ -21,43 +18,25 @@ public: ...@@ -21,43 +18,25 @@ public:
itkNewMacro(Self); itkNewMacro(Self);
/** Run-time type information (and related methods). */ /** Run-time type information (and related methods). */
itkTypeMacro(TransformModule1, ModuleBaseTemplate); itkTypeMacro(TransformModule1, ModuleIOBase);
/** define the Clone method */ /** define the Clone method */
//itkCloneMacro(Self); // itkCloneMacro(Self);
/** Type of the scalar representing coordinate and vector elements. */ /** Type of the scalar representing coordinate and vector elements. */
typedef TScalar ScalarType; //typedef TScalar ScalarType;
/** Dimension of the domain space. */ typedef Superclass::CriteriaType CriteriaType;
itkStaticConstMacro(InputSpaceDimension, unsigned int, NInputDimensions); typedef Superclass::CriteriumType CriteriumType;
itkStaticConstMacro(OutputSpaceDimension, unsigned int, NOutputDimensions);
/** Get the size of the input space */ std::string GetModuleTypeAsString() const;
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;
protected: protected:
/** /**
* Clone the current transform. * Clone the current Transform.
* This does a complete copy of the transform * This does a complete copy of the Transform
* state to the new transform * state to the new Transform
*/ */
virtual typename LightObject::Pointer InternalClone() const ITK_OVERRIDE; virtual LightObject::Pointer InternalClone() const ITK_OVERRIDE;
TransformModule1(); TransformModule1();
virtual ~TransformModule1() virtual ~TransformModule1()
...@@ -68,13 +47,6 @@ private: ...@@ -68,13 +47,6 @@ private:
TransformModule1(const Self &); // purposely not implemented TransformModule1(const Self &); // purposely not implemented
void operator=(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 std::string GetModuleTypeAsString(float *) const
{ {
...@@ -89,7 +61,9 @@ private: ...@@ -89,7 +61,9 @@ private:
return rval; return rval;
} }
virtual void Read();
virtual void Write();
virtual bool MeetsCriteria(const CriteriaType&);
}; };
} // end namespace itk } // end namespace itk
......
...@@ -22,45 +22,29 @@ ...@@ -22,45 +22,29 @@
namespace itk namespace itk
{ {
TransformModule1::TransformModule1()
{
}
template <typename TScalar, std::string TransformModule1::GetModuleTypeAsString() const
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::ostringstream n; std::ostringstream n;
n << GetNameOfClass(); n << GetNameOfClass();
n << "_"; n << "_";
n << this->GetModuleTypeAsString(static_cast<TScalar *>(ITK_NULLPTR) ); n << this->GetModuleTypeAsString(static_cast<float *>(ITK_NULLPTR));
n << "_" << this->GetInputSpaceDimension() << "_" << this->GetOutputSpaceDimension(); //n << "_" << this->GetInputSpaceDimension() << "_" << this->GetOutputSpaceDimension();
return n.str(); return n.str();
} }
LightObject::Pointer
template <typename TScalar, TransformModule1::InternalClone() const
unsigned int NInputDimensions,
unsigned int NOutputDimensions>
typename LightObject::Pointer
TransformModule1<TScalar, NInputDimensions, NOutputDimensions>
::InternalClone() const
{ {
// Default implementation just copies the parameters from // Default implementation just copies the parameters from
// this to new transform. // this to new Transform.
typename LightObject::Pointer loPtr = Superclass::InternalClone(); LightObject::Pointer loPtr = Superclass::InternalClone();
typename Self::Pointer rval = Self::Pointer rval =
dynamic_cast<Self *>(loPtr.GetPointer()); dynamic_cast<Self *>(loPtr.GetPointer());
if(rval.IsNull()) if(rval.IsNull())
{ {
...@@ -74,6 +58,62 @@ TransformModule1<TScalar, NInputDimensions, NOutputDimensions> ...@@ -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 } // end namespace itk
......
/*=========================================================================
*
* 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
...@@ -15,56 +15,47 @@ ...@@ -15,56 +15,47 @@
* limitations under the License. * limitations under the License.
* *
*=========================================================================*/ *=========================================================================*/
#include "itkModuleFactory.h" #include "itkTransformModule1Factory.h"
#include "itkVersion.h"
#include "itkTransformModule1.h" #include "itkTransformModule1.h"
#include "itkMetricModule1.h" #include "itkVersion.h"
namespace itk namespace itk
{ {
ModuleFactoryBase *ModuleFactoryBase:: m_Factory = ITK_NULLPTR;
namespace ModuleFactoryBasePrivate TransformModule1Factory::TransformModule1Factory()
{ {
bool DefaultModulesRegistered = false; this->RegisterOverride( "itkModuleIOBase",
"itkTransformModule1",
"Transform Module 1",
1,
CreateObjectFunction< TransformModule1 >::New() ); //float
} }
ModuleFactoryBase::ModuleFactoryBase()
{}
ModuleFactoryBase::~ModuleFactoryBase()
{}
void ModuleFactoryBase::RegisterDefaultModules() const char *
TransformModule1Factory::GetITKSourceVersion() const
{ {
// return ITK_SOURCE_VERSION;
// 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 * const char *
ModuleFactoryBase::GetITKSourceVersion(void) const TransformModule1Factory::GetDescription() const
{ {
return ITK_SOURCE_VERSION; return "Test module 1 for transforms";
} }
const char * // Undocumented API used to register during static initialization.
ModuleFactoryBase::GetDescription() const // DO NOT CALL DIRECTLY.
/*static bool TransformModule1FactoryHasBeenRegistered;
void TransformModule1FactoryRegister__Private(void)
{ {
return "Module FactoryBase"; if( ! TransformModule1FactoryHasBeenRegistered )
{
TransformModule1FactoryHasBeenRegistered = true;
TransformModule1Factory::RegisterOneFactory();
}
} }
*/
} // end namespace itk } // end namespace itk
...@@ -15,10 +15,10 @@ ...@@ -15,10 +15,10 @@
* limitations under the License. * limitations under the License.
* *
*=========================================================================*/ *=========================================================================*/
//#include "itkModuleIOFactoryRegisterManager.h"
#include "itkImageFileReader.h" #include "itkImageFileReader.h"
#include "itkImageFileWriter.h" #include "itkImageFileWriter.h"
#include "itkDisplacementFieldTransform.h" #include "itkDisplacementFieldTransform.h"
#include "itkComposeDisplacementFieldsImageFilter.h" #include "itkComposeDisplacementFieldsImageFilter.h"
#include "itkCompositeTransform.h" #include "itkCompositeTransform.h"
...@@ -32,35 +32,70 @@ ...@@ -32,35 +32,70 @@
//Floris: The module factory is based on the transformIO factory. //Floris: The module factory is based on the transformIO factory.
// By default it creates 2 dummy modules: itkTransformModule1 and itkMetricModule1 // By default it creates 2 dummy modules: itkTransformModule1 and itkMetricModule1
#include "itkModuleFactoryBase.h" //CMake\UseITK.cmake sets up the IOFactory_Register_Manager for transforms and images
#include "itkModuleFactory.h" //#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[]) int main(int argc, char *argv[])
{ {
std::string fileName; typedef float ScalarType;
if (argc == 1) // No arguments were provided
{ typedef std::list< itk::LightObject::Pointer > RegisteredObjectsContainerType;
fileName = "test.tfm"; RegisteredObjectsContainerType registeredIOs =
} itk::ObjectFactoryBase::CreateAllInstance("itkModuleIOBase");
else std::cout << "When CMake is not used to register the IO classes, there are\n"
{ << registeredIOs.size()
fileName = argv[1]; << " IO objects available to the Overlord.\n" << std::endl;
}
std::cout << "After registering the TransformModule1 object, ";
typedef itk::MatrixOffsetTransformBase< double, 3, 3 > MatrixOffsetTransformType; itk::TransformModule1Factory::RegisterOneFactory();
itk::TransformFactory<MatrixOffsetTransformType>::RegisterTransform(); itk::MetricModule1Factory::RegisterOneFactory();
std::cout << "there are\n";
#if (ITK_VERSION_MAJOR == 4 && ITK_VERSION_MINOR >= 5) || ITK_VERSION_MAJOR > 4 registeredIOs = itk::ObjectFactoryBase::CreateAllInstance("itkModuleIOBase");
itk::TransformFileReaderTemplate<float>::Pointer reader = std::cout << registeredIOs.size()
itk::TransformFileReaderTemplate<float>::New(); << " IO objects available to the Overlord.\n" << std::endl;
#else
itk::TransformFileReader::Pointer reader = itk::TransformFileReader::New(); std::cout << "Now, when we try to read a MetaImage, we will ";
#endif //typedef itk::ModuleBaseTemplate< ScalarType > ModuleType;
reader->SetFileName(fileName); //typedef itk::ModuleFactoryBase ModuleFactoryType;
reader->Update();
typedef itk::ModuleIOBase ModuleIOType;
std::cout << *(reader->GetTransformList()->begin()) << std::endl; //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; return EXIT_SUCCESS;
} }
\ No newline at end of file
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