Skip to content

Commit

Permalink
Merge pull request #3156 from thewtex/io-factory-registration-python
Browse files Browse the repository at this point in the history
io factory registration python
  • Loading branch information
tbirdso committed Mar 7, 2022
2 parents b836eb1 + 67dbfc1 commit c266651
Show file tree
Hide file tree
Showing 36 changed files with 445 additions and 182 deletions.
24 changes: 10 additions & 14 deletions CMake/ITKFactoryRegistration.cmake
Expand Up @@ -14,7 +14,7 @@
# Overview: Static registration of ITK factories
# ----------------------------------------------
#
# For each factory type (Image, Transform, Mesh, FFT, ...), a
# For each factory type (Image, Transform, Mesh, FFTImageFilterInit, ...), a
# registration manager header named
# `itk<factory_type>FactoryRegisterManager.h` is configured.
#
Expand All @@ -32,8 +32,14 @@
# a list in a CMake variable named after `LIST_OF_<factory_type>IO_FORMATS`
# generated by this file.
#
# For the FFT factories, each FFT filter which has a factory needs to
# be included.
# "Init factories" (such as "VnlFFTImageFilterInitFactory") are intended to reduce
# overhead. They have the sole purpose of registering multiple factories with the
# object factory singleton at once. Init factories do not inherit from
# ObjectFactoryBase, cannot define initialization overrides, and will never be
# added to the global singleton list of object factories.
#
# For the FFTImageFilterInitFactory classes, each FFT filter which has a factory needs to
# be included in its initialization list.
#
#
#
Expand All @@ -52,7 +58,7 @@
# Setting variable `ITK_NO_<factory_name_uc>_FACTORY_REGISTER_MANAGER` to `ON` prior calling
# `include(${ITK_USE_FILE})` disables the static registration.
# Here <factory_name_uc> is the upper case name of the factory. For example,
# `IMAGEIO`, `MESHIO`, `TRANSFORMIO`, or `FFT`.
# `IMAGEIO`, `MESHIO`, `TRANSFORMIO`, or `FFTIMAGEFILTERINIT`.
#
# All factories can be disabled with the following CMake code:
# foreach(_factory_name ${ITK_FACTORY_LIST})
Expand Down Expand Up @@ -156,11 +162,6 @@ function(_itk_configure_FactoryRegisterManager factory_type formats)
${_module_name} ${_factory_name})
endforeach()

# Special case: FFT::<format> inputs are for "<format>FFTImageFilter" classes
if(factory_type STREQUAL "FFT")
set(factory_type "FFTImageFilter")
endif()

configure_file(${ITK_CMAKE_DIR}/itk${factory_type}FactoryRegisterManager.h.in
"${CMAKE_CURRENT_BINARY_DIR}/ITKFactoryRegistration/itk${factory_type}FactoryRegisterManager.h" @ONLY)

Expand All @@ -178,11 +179,6 @@ macro(_itk_ADD_FACTORY_REGISTRATION _registration_list_var _names_list_var _modu
set(_abi "ITK_ABI_IMPORT")
endif()

# Special case: FFT::<format> inputs are for "<format>FFTImageFilter" classes
if(_factory_name STREQUAL "FFT")
set(_factory_name "FFTImageFilter")
endif()

set(${_registration_list_var}
"${${_registration_list_var}}void ${_abi} ${_factory_name}FactoryRegister__Private();")
set(${_names_list_var} "${${_names_list_var}}${_factory_name}FactoryRegister__Private,")
Expand Down
Expand Up @@ -16,8 +16,8 @@
*
*=========================================================================*/

#ifndef itkFFTImageFilterFactoryRegisterManager_h
#define itkFFTImageFilterFactoryRegisterManager_h
#ifndef itkFFTImageFilterInitFactoryRegisterManager_h
#define itkFFTImageFilterInitFactoryRegisterManager_h

namespace itk {

Expand All @@ -27,16 +27,11 @@ namespace itk {
//
@LIST_OF_FACTORIES_REGISTRATION@

class FFTImageFilterFactoryRegisterManager
class FFTImageFilterInitFactoryRegisterManager
{
public:
explicit FFTImageFilterFactoryRegisterManager()
explicit FFTImageFilterInitFactoryRegisterManager(void (* const list[])(void))
{
void (* const FFTImageFilterFactoryRegisterRegisterList[])(void) = {
@LIST_OF_FACTORY_NAMES@
nullptr};

auto list = FFTImageFilterFactoryRegisterRegisterList;
for(;*list != nullptr; ++list)
{
(*list)();
Expand All @@ -49,7 +44,10 @@ class FFTImageFilterFactoryRegisterManager
// application translation units. Note that this code will be expanded in the
// ITK-based applications and not in ITK itself.
//
const FFTImageFilterFactoryRegisterManager FFTImageFilterFactoryRegisterManagerInstance;
void (* const FFTImageFilterInitFactoryRegisterList[])(void) = {
@LIST_OF_FACTORY_NAMES@
nullptr};
const FFTImageFilterInitFactoryRegisterManager FFTImageFilterInitFactoryRegisterManagerInstance(FFTImageFilterInitFactoryRegisterList);

}

Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Expand Up @@ -582,7 +582,7 @@ install(FILES ${ITK_BINARY_DIR}/CMakeFiles/ITKConfig.cmake
CMake/ITKModuleAPI.cmake
CMake/UseITK.cmake
CMake/ITKFactoryRegistration.cmake
CMake/itkFFTImageFilterFactoryRegisterManager.h.in
CMake/itkFFTImageFilterInitFactoryRegisterManager.h.in
CMake/itkImageIOFactoryRegisterManager.h.in
CMake/itkTransformIOFactoryRegisterManager.h.in
CMake/itkMeshIOFactoryRegisterManager.h.in
Expand Down
Expand Up @@ -119,8 +119,8 @@ class ITK_TEMPLATE_EXPORT ComplexToComplex1DFFTImageFilter : public ImageToImage
# include "itkComplexToComplex1DFFTImageFilter.hxx"
#endif

#ifdef ITK_FFT_FACTORY_REGISTER_MANAGER
# include "itkFFTImageFilterFactoryRegisterManager.h"
#ifdef ITK_FFTIMAGEFILTERINIT_FACTORY_REGISTER_MANAGER
# include "itkFFTImageFilterInitFactoryRegisterManager.h"
#endif

#endif // itkComplexToComplex1DFFTImageFilter_h
Expand Up @@ -134,8 +134,8 @@ class ITK_TEMPLATE_EXPORT ComplexToComplexFFTImageFilter : public ImageToImageFi
# include "itkComplexToComplexFFTImageFilter.hxx"
#endif

#ifdef ITK_FFT_FACTORY_REGISTER_MANAGER
# include "itkFFTImageFilterFactoryRegisterManager.h"
#ifdef ITK_FFTIMAGEFILTERINIT_FACTORY_REGISTER_MANAGER
# include "itkFFTImageFilterInitFactoryRegisterManager.h"
#endif

#endif
73 changes: 73 additions & 0 deletions Modules/Filtering/FFT/include/itkFFTWFFTImageFilterInitFactory.h
@@ -0,0 +1,73 @@
/*=========================================================================
*
* Copyright NumFOCUS
*
* 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 itkFFTWFFTImageFilterInitFactory_h
#define itkFFTWFFTImageFilterInitFactory_h
#include "ITKFFTExport.h"

#include "itkLightObject.h"

namespace itk
{
/**
*\class FFTWFFTImageFilterInitFactory
* \brief Initialize FFTW FFT image filter factory backends.
*
* The purpose of FFTWFFTImageFilterInitFactory is to perform
* one-time registration of factory objects that handle
* creation of FFTW-backend FFT image filter classes
* through the ITK object factory singleton mechanism.
*
* \ingroup ITKFFT
*/
class ITKFFT_EXPORT FFTWFFTImageFilterInitFactory : public LightObject
{
public:
ITK_DISALLOW_COPY_AND_MOVE(FFTWFFTImageFilterInitFactory);

/** Standard class type aliases. */
using Self = FFTWFFTImageFilterInitFactory;
using Superclass = LightObject;
using Pointer = SmartPointer<Self>;
using ConstPointer = SmartPointer<const Self>;

/** Method for class instantiation. */
itkFactorylessNewMacro(Self);

/** Run-time type information (and related methods). */
itkTypeMacro(FFTWFFTImageFilterInitFactory, LightObject);

/** Register one factory of this type.
* The purpose of an InitFactory is to simply load other factories
* in its constructor, so nothing is returned here.
* Method is required for factory to load correct in Python. */
static void
RegisterOneFactory()
{
RegisterFactories();
}

static void
RegisterFactories();

protected:
FFTWFFTImageFilterInitFactory();
~FFTWFFTImageFilterInitFactory() override;
};
} // end namespace itk

#endif
4 changes: 2 additions & 2 deletions Modules/Filtering/FFT/include/itkForward1DFFTImageFilter.h
Expand Up @@ -104,8 +104,8 @@ class ITK_TEMPLATE_EXPORT Forward1DFFTImageFilter : public ImageToImageFilter<TI
# include "itkForward1DFFTImageFilter.hxx"
#endif

#ifdef ITK_FFT_FACTORY_REGISTER_MANAGER
# include "itkFFTImageFilterFactoryRegisterManager.h"
#ifdef ITK_FFTIMAGEFILTERINIT_FACTORY_REGISTER_MANAGER
# include "itkFFTImageFilterInitFactoryRegisterManager.h"
#endif

#endif // itkForward1DFFTImageFilter_h
4 changes: 2 additions & 2 deletions Modules/Filtering/FFT/include/itkForwardFFTImageFilter.h
Expand Up @@ -116,8 +116,8 @@ class ITK_TEMPLATE_EXPORT ForwardFFTImageFilter : public ImageToImageFilter<TInp
# include "itkForwardFFTImageFilter.hxx"
#endif

#ifdef ITK_FFT_FACTORY_REGISTER_MANAGER
# include "itkFFTImageFilterFactoryRegisterManager.h"
#ifdef ITK_FFTIMAGEFILTERINIT_FACTORY_REGISTER_MANAGER
# include "itkFFTImageFilterInitFactoryRegisterManager.h"
#endif

#endif
Expand Up @@ -118,8 +118,8 @@ class ITK_TEMPLATE_EXPORT HalfHermitianToRealInverseFFTImageFilter
# include "itkHalfHermitianToRealInverseFFTImageFilter.hxx"
#endif

#ifdef ITK_FFT_FACTORY_REGISTER_MANAGER
# include "itkFFTImageFilterFactoryRegisterManager.h"
#ifdef ITK_FFTIMAGEFILTERINIT_FACTORY_REGISTER_MANAGER
# include "itkFFTImageFilterInitFactoryRegisterManager.h"
#endif

#endif
4 changes: 2 additions & 2 deletions Modules/Filtering/FFT/include/itkInverse1DFFTImageFilter.h
Expand Up @@ -99,8 +99,8 @@ class ITK_TEMPLATE_EXPORT Inverse1DFFTImageFilter : public ImageToImageFilter<TI
# include "itkInverse1DFFTImageFilter.hxx"
#endif

#ifdef ITK_FFT_FACTORY_REGISTER_MANAGER
# include "itkFFTImageFilterFactoryRegisterManager.h"
#ifdef ITK_FFTIMAGEFILTERINIT_FACTORY_REGISTER_MANAGER
# include "itkFFTImageFilterInitFactoryRegisterManager.h"
#endif

#endif // itkInverse1DFFTImageFilter_h
4 changes: 2 additions & 2 deletions Modules/Filtering/FFT/include/itkInverseFFTImageFilter.h
Expand Up @@ -102,8 +102,8 @@ class ITK_TEMPLATE_EXPORT InverseFFTImageFilter : public ImageToImageFilter<TInp
# include "itkInverseFFTImageFilter.hxx"
#endif

#ifdef ITK_FFT_FACTORY_REGISTER_MANAGER
# include "itkFFTImageFilterFactoryRegisterManager.h"
#ifdef ITK_FFTIMAGEFILTERINIT_FACTORY_REGISTER_MANAGER
# include "itkFFTImageFilterInitFactoryRegisterManager.h"
#endif

#endif
Expand Up @@ -120,8 +120,8 @@ class ITK_TEMPLATE_EXPORT RealToHalfHermitianForwardFFTImageFilter
# include "itkRealToHalfHermitianForwardFFTImageFilter.hxx"
#endif

#ifdef ITK_FFT_FACTORY_REGISTER_MANAGER
# include "itkFFTImageFilterFactoryRegisterManager.h"
#ifdef ITK_FFTIMAGEFILTERINIT_FACTORY_REGISTER_MANAGER
# include "itkFFTImageFilterInitFactoryRegisterManager.h"
#endif

#endif
71 changes: 71 additions & 0 deletions Modules/Filtering/FFT/include/itkVnlFFTImageFilterInitFactory.h
@@ -0,0 +1,71 @@
/*=========================================================================
*
* Copyright NumFOCUS
*
* 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 itkVnlFFTImageFilterInitFactory_h
#define itkVnlFFTImageFilterInitFactory_h
#include "ITKFFTExport.h"

#include "itkLightObject.h"

namespace itk
{
/**
*\class VnlFFTImageFilterInitFactory
* \brief Initialize Vnl FFT image filter factory backends.
*
* The purpose of VnlFFTImageFilterInitFactory is to perform
* one-time registration of factory objects that handle
* creation of Vnl-backend FFT image filter classes
* through the ITK object factory singleton mechanism.
*
* \ingroup ITKFFT
*/
class ITKFFT_EXPORT VnlFFTImageFilterInitFactory : public LightObject
{
public:
ITK_DISALLOW_COPY_AND_MOVE(VnlFFTImageFilterInitFactory);

/** Standard class type aliases. */
using Self = VnlFFTImageFilterInitFactory;
using Superclass = LightObject;
using Pointer = SmartPointer<Self>;
using ConstPointer = SmartPointer<const Self>;

/** Method for class instantiation. */
itkFactorylessNewMacro(Self);

/** Run-time type information (and related methods). */
itkTypeMacro(VnlFFTImageFilterInitFactory, LightObject);

/** Mimic factory interface for Python initialization */
static void
RegisterOneFactory()
{
RegisterFactories();
}

/** Register all Vnl FFT factories */
static void
RegisterFactories();

protected:
VnlFFTImageFilterInitFactory();
~VnlFFTImageFilterInitFactory() override;
};
} // end namespace itk

#endif
4 changes: 2 additions & 2 deletions Modules/Filtering/FFT/itk-module.cmake
Expand Up @@ -5,10 +5,10 @@ computations of Fast Fourier Transforms based on
<a href=\"http://www.fftw.org\">FFTW</a>. Note that when using the FFTW
implementation you must comply with the GPL license.")

set(_fft_backends "FFT::VnlComplexToComplex1D;FFT::VnlComplexToComplex;FFT::VnlForward1D;FFT::VnlForward;FFT::VnlHalfHermitianToRealInverse;FFT::VnlInverse1D;FFT::VnlInverse;FFT::VnlRealToHalfHermitianForward")
set(_fft_backends "FFTImageFilterInit::Vnl")
if(ITK_USE_FFTWF OR ITK_USE_FFTWD)
# Prepend so that FFTW constructor is preferred
list(PREPEND _fft_backends "FFT::FFTWComplexToComplex1D;FFT::FFTWComplexToComplex;FFT::FFTWForward1D;FFT::FFTWForward;FFT::FFTWHalfHermitianToRealInverse;FFT::FFTWInverse1D;FFT::FFTWInverse;FFT::FFTWRealToHalfHermitianForward")
list(PREPEND _fft_backends "FFTImageFilterInit::FFTW")
endif()

itk_module(ITKFFT
Expand Down
4 changes: 2 additions & 2 deletions Modules/Filtering/FFT/src/CMakeLists.txt
@@ -1,10 +1,10 @@
set(ITKFFT_SRCS
itkComplexToComplexFFTImageFilter.cxx
itkVnlFFTImageFilterFactories.cxx)
itkVnlFFTImageFilterInitFactory.cxx)

if( ITK_USE_FFTWF OR ITK_USE_FFTWD AND NOT ITK_USE_CUFFTW)
list(APPEND ITKFFT_SRCS itkFFTWGlobalConfiguration.cxx )
list(APPEND ITKFFT_SRCS itkFFTWFFTImageFilterFactories.cxx )
list(APPEND ITKFFT_SRCS itkFFTWFFTImageFilterInitFactory.cxx )
endif()

itk_module_add_library(ITKFFT ${ITKFFT_SRCS})
Expand Down

0 comments on commit c266651

Please sign in to comment.