diff --git a/CMake/itkFFTImageFilterFactoryRegisterManager.h.in b/CMake/itkFFTImageFilterInitFactoryRegisterManager.h.in similarity index 73% rename from CMake/itkFFTImageFilterFactoryRegisterManager.h.in rename to CMake/itkFFTImageFilterInitFactoryRegisterManager.h.in index 97fbfce3e3f..7868831eb43 100644 --- a/CMake/itkFFTImageFilterFactoryRegisterManager.h.in +++ b/CMake/itkFFTImageFilterInitFactoryRegisterManager.h.in @@ -16,8 +16,8 @@ * *=========================================================================*/ -#ifndef itkFFTImageFilterFactoryRegisterManager_h -#define itkFFTImageFilterFactoryRegisterManager_h +#ifndef itkFFTImageFilterInitFactoryRegisterManager_h +#define itkFFTImageFilterInitFactoryRegisterManager_h namespace itk { @@ -27,10 +27,10 @@ namespace itk { // @LIST_OF_FACTORIES_REGISTRATION@ -class FFTImageFilterFactoryRegisterManager +class FFTImageFilterInitFactoryRegisterManager { public: - explicit FFTImageFilterFactoryRegisterManager(void (* const list[])(void)) + explicit FFTImageFilterInitFactoryRegisterManager(void (* const list[])(void)) { for(;*list != nullptr; ++list) { @@ -44,10 +44,10 @@ class FFTImageFilterFactoryRegisterManager // application translation units. Note that this code will be expanded in the // ITK-based applications and not in ITK itself. // -void (* const FFTImageFilterFactoryRegisterRegisterList[])(void) = { +void (* const FFTImageFilterInitFactoryRegisterRegisterList[])(void) = { @LIST_OF_FACTORY_NAMES@ nullptr}; -const FFTImageFilterFactoryRegisterManager FFTImageFilterFactoryRegisterManagerInstance(FFTImageFilterFactoryRegisterRegisterList); +const FFTImageFilterInitFactoryRegisterManager FFTImageFilterInitFactoryRegisterManagerInstance(FFTImageFilterInitFactoryRegisterRegisterList); } diff --git a/Modules/Filtering/FFT/itk-module.cmake b/Modules/Filtering/FFT/itk-module.cmake index 1fb5965cff4..8eccc19a2ba 100644 --- a/Modules/Filtering/FFT/itk-module.cmake +++ b/Modules/Filtering/FFT/itk-module.cmake @@ -5,10 +5,10 @@ computations of Fast Fourier Transforms based on FFTW. Note that when using the FFTW implementation you must comply with the GPL license.") -set(_fft_backends "FFTImageFilter::Vnl") +set(_fft_backends "FFTImageFilterInit::Vnl") if(ITK_USE_FFTWF OR ITK_USE_FFTWD) # Prepend so that FFTW constructor is preferred - list(PREPEND _fft_backends "FFTImageFilter::FFTW") + list(PREPEND _fft_backends "FFTImageFilterInit::FFTW") endif() itk_module(ITKFFT diff --git a/Wrapping/Generators/Python/itk/support/base.py b/Wrapping/Generators/Python/itk/support/base.py index f75cf61f5de..2e3b11d9d3a 100644 --- a/Wrapping/Generators/Python/itk/support/base.py +++ b/Wrapping/Generators/Python/itk/support/base.py @@ -80,11 +80,6 @@ def itk_load_swig_module(name: str, namespace=None): namespace[k] = v return - # We're definitely going to load the templates. We set templates_loaded - # here instead of at the end of the file to protect against cyclical - # dependencies that could kill the recursive lookup below. - this_module.__templates_loaded = True - # Now, we definitely need to load the template_feature instantiations from the # named module, and possibly also load the underlying SWIG module. Before # we can load the template_feature instantiations of this module, we need to load @@ -101,6 +96,11 @@ def itk_load_swig_module(name: str, namespace=None): for dep in deps: itk_load_swig_module(dep, namespace) + # TODO check if module was loaded as part of underlying + # dependency load, such as the case where this module + # defined a factory overload for a dependency module + # and was manually loaded early. + if itkConfig.ImportCallback: itkConfig.ImportCallback(name, 0) @@ -206,6 +206,11 @@ def itk_load_swig_module(name: str, namespace=None): f"exception:\n {e}" ) + # Indicate that templates have been fully loaded from the module. + # Any subsequent attempts to load the module will bail out early + # if this flag is set. + this_module.__templates_loaded = True + for snakeCaseFunction in l_data.get_snake_case_functions(): namespace[snakeCaseFunction] = getattr(l_module, snakeCaseFunction) init_name = snakeCaseFunction + "_init_docstring" @@ -321,12 +326,14 @@ def load_factories(factory_name: str) -> None: # Only load factories once if factory_name in _factories_loaded: return - import importlib + import itk for module_name, data in itk_base_global_module_data.items(): for name, factory_class_prefix in data.get_module_factories()[:2]: if name == factory_name: + # Get the factory, loading new modules with itk_load_swig_module as necessary factory = getattr(itk, f"{factory_class_prefix}{name}Factory") + # Static method initializes factory overrides without adding to auto_pipeline factory.RegisterOneFactory() _factories_loaded.append(factory_name) diff --git a/Wrapping/Generators/Python/itk/support/extras.py b/Wrapping/Generators/Python/itk/support/extras.py index faab7f1f17d..3a60915c9ed 100644 --- a/Wrapping/Generators/Python/itk/support/extras.py +++ b/Wrapping/Generators/Python/itk/support/extras.py @@ -1040,8 +1040,6 @@ def meshwrite( The writer is instantiated according to the type of the input mesh. """ import itk - from itk.support.base import load_factories - load_factories('MeshIO') mesh.UpdateOutputInformation() # don't put that writer in the automatic pipeline @@ -1072,8 +1070,6 @@ def meshread( wrapped). """ import itk - from itk.support.base import load_factories - load_factories('MeshIO') if fallback_only: if pixel_type is None: @@ -1123,8 +1119,6 @@ def transformread(filename: fileiotype) -> List["itkt.TransformBase"]: A Python list containing the transforms in the file. """ import itk - from itk.support.base import load_factories - load_factories('TransformIO') reader = itk.TransformFileReaderTemplate[itk.D].New() reader.SetFileName(f"{filename}") @@ -1160,8 +1154,6 @@ def transformwrite( Use compression, if the file format supports it. """ import itk - from itk.support.base import load_factories - load_factories('TransformIO') writer = itk.TransformFileWriterTemplate[itk.D].New() writer.SetFileName(f"{filename}")