diff --git a/Modules/Core/Install/itkMetricModule1.h b/Modules/Core/Install/itkMetricModule1.h new file mode 100644 index 0000000000000000000000000000000000000000..9df36b313e9259dc0fb95d1c501f27499579b926 --- /dev/null +++ b/Modules/Core/Install/itkMetricModule1.h @@ -0,0 +1,78 @@ +#ifndef itkMetricModule1_h +#define itkMetricModule1_h + +#include "itkModuleBase.h" + +namespace itk +{ +template <typename TScalar, + unsigned int NInputDimensions = 3, + unsigned int NOutputDimensions = 3> +class MetricModule1 : public ModuleBaseTemplate< TScalar > +{ +public: + /** Standard class typedefs. */ + typedef MetricModule1 Self; + typedef ModuleBaseTemplate< TScalar > Superclass; + typedef SmartPointer< Self > Pointer; + typedef SmartPointer< const Self > ConstPointer; + + /** New macro for creation of through the object factory. */ + itkNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(MetricModule1, ModuleBaseTemplate); + + /** define the Clone method */ + // itkCloneMacro(Self); + + /** Type of the scalar representing coordinate and vector elements. */ + typedef TScalar ScalarType; + std::string GetModuleTypeAsString() const; +protected: + /** + * Clone the current Metric. + * This does a complete copy of the Metric + * state to the new Metric + */ + virtual typename LightObject::Pointer InternalClone() const ITK_OVERRIDE; + + MetricModule1(); + virtual ~MetricModule1() + { + } + +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 + { + std::string rval("float"); + + return rval; + } + + std::string GetModuleTypeAsString(double *) const + { + std::string rval("double"); + + return rval; + } + +}; +} // end namespace itk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "itkMetricModule1.hxx" +#endif + +#endif diff --git a/Modules/Core/Install/itkMetricModule1.hxx b/Modules/Core/Install/itkMetricModule1.hxx new file mode 100644 index 0000000000000000000000000000000000000000..749e23eb09efd1c4b51799459f1c6290b78499f5 --- /dev/null +++ b/Modules/Core/Install/itkMetricModule1.hxx @@ -0,0 +1,79 @@ +/*========================================================================= + * + * 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 itkMetricModule1_hxx +#define itkMetricModule1_hxx + +#include "itkMetricModule1.h" + +namespace itk +{ + +template <typename TScalar, + unsigned int NInputDimensions, + unsigned int NOutputDimensions> +MetricModule1<TScalar, NInputDimensions, NOutputDimensions> +::MetricModule1() +{ +} + + +template <typename TScalar, + unsigned int NInputDimensions, + unsigned int NOutputDimensions> +std::string MetricModule1<TScalar, NInputDimensions, NOutputDimensions> +::GetModuleTypeAsString() const +{ + std::ostringstream n; + + n << GetNameOfClass(); + n << "_"; + n << this->GetModuleTypeAsString(static_cast<TScalar *>(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 +{ + // Default implementation just copies the parameters from + // this to new Metric. + typename LightObject::Pointer loPtr = Superclass::InternalClone(); + + typename Self::Pointer rval = + dynamic_cast<Self *>(loPtr.GetPointer()); + if(rval.IsNull()) + { + itkExceptionMacro(<< "downcast to type " + << this->GetNameOfClass() + << " failed."); + } + //rval->SetFixedParameters(this->GetFixedParameters()); + //rval->SetParameters(this->GetParameters()); + return loPtr; +} + + + +} // end namespace itk + +#endif diff --git a/Modules/Core/Install/itkModuleBase.h b/Modules/Core/Install/itkModuleBase.h new file mode 100644 index 0000000000000000000000000000000000000000..51adc2cfc7c1c8b285ae90ecb05b6b5aa9bba974 --- /dev/null +++ b/Modules/Core/Install/itkModuleBase.h @@ -0,0 +1,79 @@ +/*========================================================================= + * + * 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 new file mode 100644 index 0000000000000000000000000000000000000000..50fa98b8c913b75720235f68ce61aefd8100979a --- /dev/null +++ b/Modules/Core/Install/itkModuleFactory.h @@ -0,0 +1,59 @@ +/*========================================================================= + * + * 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 new file mode 100644 index 0000000000000000000000000000000000000000..69df185a5599fbc0f9b52feef1e4885a6588e952 --- /dev/null +++ b/Modules/Core/Install/itkModuleFactoryBase.cxx @@ -0,0 +1,70 @@ +/*========================================================================= + * + * 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 new file mode 100644 index 0000000000000000000000000000000000000000..749008422332d3ef3a4c48af28e2cdf006509f95 --- /dev/null +++ b/Modules/Core/Install/itkModuleFactoryBase.h @@ -0,0 +1,98 @@ +/*========================================================================= + * + * 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 itkModuleFactoryBase_h +#define itkModuleFactoryBase_h + +#include "itkObjectFactoryBase.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); + + /** 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; + } + + void RegisterModule(const char *classOverride, + const char *overrideClassName, + const char *description, + bool enableFlag, + CreateObjectFunctionBase *createFunction) + { + this->RegisterOverride(classOverride, overrideClassName, description, enableFlag, createFunction); + } + + protected: + ModuleFactoryBase(); + virtual ~ModuleFactoryBase(); + + private: + ModuleFactoryBase(const Self &); //purposely not implemented + void operator=(const Self &); //purposely not implemented + + static ModuleFactoryBase *m_Factory; + }; +} // end namespace itk + +#endif diff --git a/Modules/Core/Install/itkTransformModule1.h b/Modules/Core/Install/itkTransformModule1.h new file mode 100644 index 0000000000000000000000000000000000000000..69e772e4a40ad08c03148127dd5e7d32ffd2a1ab --- /dev/null +++ b/Modules/Core/Install/itkTransformModule1.h @@ -0,0 +1,100 @@ +#ifndef itkTransformModule1_h +#define itkTransformModule1_h + +#include "itkModuleBase.h" + +namespace itk +{ +template <typename TScalar, + unsigned int NInputDimensions = 3, + unsigned int NOutputDimensions = 3> +class TransformModule1 : public ModuleBaseTemplate< TScalar > +{ +public: + /** Standard class typedefs. */ + typedef TransformModule1 Self; + typedef ModuleBaseTemplate< TScalar > Superclass; + typedef SmartPointer< Self > Pointer; + typedef SmartPointer< const Self > ConstPointer; + + /** New macro for creation of through the object factory. */ + itkNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(TransformModule1, ModuleBaseTemplate); + + /** define the Clone method */ + //itkCloneMacro(Self); + + /** Type of the scalar representing coordinate and vector elements. */ + typedef TScalar ScalarType; + + /** Dimension of the domain space. */ + itkStaticConstMacro(InputSpaceDimension, unsigned int, NInputDimensions); + itkStaticConstMacro(OutputSpaceDimension, unsigned int, NOutputDimensions); + + /** 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; +protected: + /** + * 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; + + TransformModule1(); + virtual ~TransformModule1() + { + } + +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 + { + std::string rval("float"); + + return rval; + } + + std::string GetModuleTypeAsString(double *) const + { + std::string rval("double"); + + return rval; + } + +}; +} // end namespace itk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "itkTransformModule1.hxx" +#endif + +#endif diff --git a/Modules/Core/Install/itkTransformModule1.hxx b/Modules/Core/Install/itkTransformModule1.hxx new file mode 100644 index 0000000000000000000000000000000000000000..a976d67fc63997b54e5cef5a37ab2d9650f6a45e --- /dev/null +++ b/Modules/Core/Install/itkTransformModule1.hxx @@ -0,0 +1,80 @@ +/*========================================================================= + * + * 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 itkTransformModule1_hxx +#define itkTransformModule1_hxx + +#include "itkTransformModule1.h" + +namespace itk +{ + +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::ostringstream n; + + n << GetNameOfClass(); + n << "_"; + n << this->GetModuleTypeAsString(static_cast<TScalar *>(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 +{ + // Default implementation just copies the parameters from + // this to new transform. + typename LightObject::Pointer loPtr = Superclass::InternalClone(); + + typename Self::Pointer rval = + dynamic_cast<Self *>(loPtr.GetPointer()); + if(rval.IsNull()) + { + itkExceptionMacro(<< "downcast to type " + << this->GetNameOfClass() + << " failed."); + } + //rval->SetFixedParameters(this->GetFixedParameters()); + //rval->SetParameters(this->GetParameters()); + return loPtr; +} + + + +} // end namespace itk + +#endif diff --git a/Modules/Core/Install/itkfactory.cxx b/Modules/Core/Install/itkfactory.cxx new file mode 100644 index 0000000000000000000000000000000000000000..faea2e2e0bfd83d257f52d3a222b00c78b6e74ba --- /dev/null +++ b/Modules/Core/Install/itkfactory.cxx @@ -0,0 +1,66 @@ +/*========================================================================= +* +* 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 "itkImageFileReader.h" +#include "itkImageFileWriter.h" + +#include "itkDisplacementFieldTransform.h" +#include "itkComposeDisplacementFieldsImageFilter.h" +#include "itkCompositeTransform.h" +#include "itkVector.h" +#include "itkPoint.h" + +#include "itkTransformFileReader.h" +#include "itkTransformFactoryBase.h" +#include "itkTransformFactory.h" +#include "itkMatrixOffsetTransformBase.h" + +//Floris: The module factory is based on the transformIO factory. +// By default it creates 2 dummy modules: itkTransformModule1 and itkMetricModule1 +#include "itkModuleFactoryBase.h" +#include "itkModuleFactory.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; + + return EXIT_SUCCESS; +} \ No newline at end of file