Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: Load factories in Python at runtime
Load IO and FFT factories at runtime based on the itk-module.cmake FACTORY_NAMES metadata, as is done with C++ static binary initialization. This enables run-time discovery of all Python IO or FFT implementations. Some may be added with remote module Python packages. This also addresses Slicer's use case where Slice is performing initialization of IO factories with static initialization. Only one static binary initialization is intended to be supported per application. Do not perform static binary initialization in the Python modules. FFTImageFilter consolidation was finalized, and the required corresponding VnlFFTImageFilterFactory and FFTWFFTImageFilterFactory classes created and wrapped. Add the missing required TransformIO wrapping.
- Loading branch information
Showing
26 changed files
with
341 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
Modules/Filtering/FFT/include/itkFFTWFFTImageFilterFactory.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/*========================================================================= | ||
* | ||
* 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 itkFFTWFFTImageFilterFactory_h | ||
#define itkFFTWFFTImageFilterFactory_h | ||
#include "ITKFFTExport.h" | ||
|
||
#include "itkObjectFactoryBase.h" | ||
|
||
namespace itk | ||
{ | ||
/** | ||
*\class FFTWFFTImageFilterFactory | ||
* \brief Create instances of FFTW FFT ImageFilter objects using an object factory. | ||
* \ingroup ITKFFT | ||
*/ | ||
class ITKFFT_EXPORT FFTWFFTImageFilterFactory : public ObjectFactoryBase | ||
{ | ||
public: | ||
ITK_DISALLOW_COPY_AND_MOVE(FFTWFFTImageFilterFactory); | ||
|
||
/** Standard class type aliases. */ | ||
using Self = FFTWFFTImageFilterFactory; | ||
using Superclass = ObjectFactoryBase; | ||
using Pointer = SmartPointer<Self>; | ||
using ConstPointer = SmartPointer<const Self>; | ||
|
||
/** Class methods used to interface with the registered factories. */ | ||
const char * | ||
GetITKSourceVersion() const override; | ||
|
||
const char * | ||
GetDescription() const override; | ||
|
||
/** Method for class instantiation. */ | ||
itkFactorylessNewMacro(Self); | ||
|
||
/** Run-time type information (and related methods). */ | ||
itkTypeMacro(FFTWFFTImageFilterFactory, ObjectFactoryBase); | ||
|
||
/** Register one factory of this type */ | ||
static void | ||
RegisterOneFactory() | ||
{ | ||
auto factory = FFTWFFTImageFilterFactory::New(); | ||
|
||
ObjectFactoryBase::RegisterFactoryInternal(factory); | ||
} | ||
|
||
protected: | ||
FFTWFFTImageFilterFactory(); | ||
~FFTWFFTImageFilterFactory() override; | ||
}; | ||
} // end namespace itk | ||
|
||
#endif |
70 changes: 70 additions & 0 deletions
70
Modules/Filtering/FFT/include/itkVnlFFTImageFilterFactory.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/*========================================================================= | ||
* | ||
* 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 itkVnlFFTImageFilterFactory_h | ||
#define itkVnlFFTImageFilterFactory_h | ||
#include "ITKFFTExport.h" | ||
|
||
#include "itkObjectFactoryBase.h" | ||
|
||
namespace itk | ||
{ | ||
/** | ||
*\class VnlFFTImageFilterFactory | ||
* \brief Create instances of Vnl FFT ImageFilter objects using an object factory. | ||
* \ingroup ITKFFT | ||
*/ | ||
class ITKFFT_EXPORT VnlFFTImageFilterFactory : public ObjectFactoryBase | ||
{ | ||
public: | ||
ITK_DISALLOW_COPY_AND_MOVE(VnlFFTImageFilterFactory); | ||
|
||
/** Standard class type aliases. */ | ||
using Self = VnlFFTImageFilterFactory; | ||
using Superclass = ObjectFactoryBase; | ||
using Pointer = SmartPointer<Self>; | ||
using ConstPointer = SmartPointer<const Self>; | ||
|
||
/** Class methods used to interface with the registered factories. */ | ||
const char * | ||
GetITKSourceVersion() const override; | ||
|
||
const char * | ||
GetDescription() const override; | ||
|
||
/** Method for class instantiation. */ | ||
itkFactorylessNewMacro(Self); | ||
|
||
/** Run-time type information (and related methods). */ | ||
itkTypeMacro(VnlFFTImageFilterFactory, ObjectFactoryBase); | ||
|
||
/** Register one factory of this type */ | ||
static void | ||
RegisterOneFactory() | ||
{ | ||
auto factory = VnlFFTImageFilterFactory::New(); | ||
|
||
ObjectFactoryBase::RegisterFactoryInternal(factory); | ||
} | ||
|
||
protected: | ||
VnlFFTImageFilterFactory(); | ||
~VnlFFTImageFilterFactory() override; | ||
}; | ||
} // end namespace itk | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
Modules/Filtering/FFT/wrapping/itkFFTWFFTImageFilterFactory.wrap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
if(ITK_USE_FFTWF OR ITK_USE_FFTWD) | ||
itk_wrap_simple_class("itk::FFTWFFTImageFilterFactory" POINTER) | ||
endif() |
1 change: 1 addition & 0 deletions
1
Modules/Filtering/FFT/wrapping/itkVnlFFTImageFilterFactory.wrap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
itk_wrap_simple_class("itk::VnlFFTImageFilterFactory" POINTER) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
itk_wrap_module(ITKIOTransformHDF5) | ||
itk_auto_load_submodules() | ||
itk_end_wrap_module() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
UNIQUE(types "D;${WRAP_ITK_REAL}") | ||
|
||
set(WRAPPER_AUTO_INCLUDE_HEADERS OFF) | ||
itk_wrap_include("itkHDF5TransformIO.h") | ||
itk_wrap_class("itk::HDF5TransformIOTemplate" POINTER) | ||
foreach(t ${types}) | ||
itk_wrap_template("${ITKM_${t}}" "${ITKT_${t}}") | ||
endforeach() | ||
itk_end_wrap_class() | ||
set(WRAPPER_AUTO_INCLUDE_HEADERS ON) | ||
|
||
itk_wrap_simple_class("itk::HDF5TransformIOFactory" POINTER) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
itk_wrap_module(ITKIOTransformInsightLegacy) | ||
itk_auto_load_submodules() | ||
itk_end_wrap_module() |
12 changes: 12 additions & 0 deletions
12
Modules/IO/TransformInsightLegacy/wrapping/itkTxtTransformIO.wrap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
UNIQUE(types "D;${WRAP_ITK_REAL}") | ||
|
||
set(WRAPPER_AUTO_INCLUDE_HEADERS OFF) | ||
itk_wrap_include("itkTxtTransformIO.h") | ||
itk_wrap_class("itk::TxtTransformIOTemplate" POINTER) | ||
foreach(t ${types}) | ||
itk_wrap_template("${ITKM_${t}}" "${ITKT_${t}}") | ||
endforeach() | ||
itk_end_wrap_class() | ||
set(WRAPPER_AUTO_INCLUDE_HEADERS ON) | ||
|
||
itk_wrap_simple_class("itk::TxtTransformIOFactory" POINTER) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
itk_wrap_module(ITKIOTransformMINC) | ||
itk_auto_load_submodules() | ||
itk_end_wrap_module() |
Oops, something went wrong.