Skip to content

Commit

Permalink
WIP: Try adding factory classes in fft class files
Browse files Browse the repository at this point in the history
  • Loading branch information
tbirdso committed Oct 25, 2021
1 parent 12a4dbb commit b6b9c08
Show file tree
Hide file tree
Showing 6 changed files with 222 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,32 +44,6 @@ ComplexToComplex1DFFTImageFilter<TInputImage, TOutputImage>::New()
smartPtr->UnRegister();
}

#ifdef ITK_USE_FFTWD
if (smartPtr.IsNull())
{
if (typeid(typename TInputImage::PixelType::value_type) == typeid(double))
{
smartPtr =
dynamic_cast<Self *>(FFTWComplexToComplex1DFFTImageFilter<TInputImage, TOutputImage>::New().GetPointer());
}
}
#endif
#ifdef ITK_USE_FFTWF
if (smartPtr.IsNull())
{
if (typeid(typename TInputImage::PixelType::value_type) == typeid(float))
{
smartPtr =
dynamic_cast<Self *>(FFTWComplexToComplex1DFFTImageFilter<TInputImage, TOutputImage>::New().GetPointer());
}
}
#endif

if (smartPtr.IsNull())
{
smartPtr = VnlComplexToComplex1DFFTImageFilter<TInputImage, TOutputImage>::New().GetPointer();
}

return smartPtr;
}

Expand Down
77 changes: 76 additions & 1 deletion Modules/Filtering/FFT/include/itkFFTWForward1DFFTImageFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ namespace itk
/** \class FFTWForward1DFFTImageFilter
* \brief only do FFT along one dimension using FFTW as a backend.
*
* \ingroup Ultrasound
* \ingroup FourierTransform
* \ingroup ITKFFT
*/
template <typename TInputImage,
typename TOutputImage = Image<std::complex<typename TInputImage::PixelType>, TInputImage::ImageDimension>>
Expand Down Expand Up @@ -97,6 +98,80 @@ class ITK_TEMPLATE_EXPORT FFTWForward1DFFTImageFilter : public Forward1DFFTImage
PlanBufferPointerType m_OutputBufferArray;
};


/** \class FFTWForward1DFFTImageFilterFactory
*
* \brief Object Factory implementation for FFTWForward1DFFTImageFilter
*
* \ingroup FourierTransform
* \ingroup ITKFFT
*/
class FFTWForward1DFFTImageFilterFactory : public itk::ObjectFactoryBase
{
public:
ITK_DISALLOW_COPY_AND_MOVE(FFTWForward1DFFTImageFilterFactory);

using Self = FFTWForward1DFFTImageFilterFactory;
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
{
return ITK_SOURCE_VERSION;
}
const char *
GetDescription() const override
{
return "A Factory for FFTWForward1DFFTImageFilterFactory";
}

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

/** Run-time type information (and related methods). */
itkTypeMacro(FFTWForward1DFFTImageFilterFactory, itk::ObjectFactoryBase);

/** Register one factory of this type */
static void
RegisterOneFactory()
{
FFTWForward1DFFTImageFilterFactory::Pointer factory = FFTWForward1DFFTImageFilterFactory::New();

ObjectFactoryBase::RegisterFactory(factory);
}

private:
#define OverrideFFTWForward1DFFTImageFilterTypeMacro(ipt, opt, dm) \
{ \
using InputImageType = Image<ipt, dm>; \
using OutputImageType = Image<std::complex<opt>, dm>; \
this->RegisterOverride(typeid(Forward1DFFTImageFilter<InputImageType, OutputImageType>).name(), \
typeid(FFTWForward1DFFTImageFilter<InputImageType, OutputImageType>).name(), \
"FFTW Forward 1D FFT Image Filter Override", \
true, \
CreateObjectFunction<FFTWForward1DFFTImageFilter<InputImageType, OutputImageType>>::New()); \
} \
ITK_MACROEND_NOOP_STATEMENT

FFTWForward1DFFTImageFilterFactory()
{
#ifdef ITK_USE_FFTWF
OverrideFFTWForward1DFFTImageFilterTypeMacro(float, float, 1);
OverrideFFTWForward1DFFTImageFilterTypeMacro(float, float, 2);
OverrideFFTWForward1DFFTImageFilterTypeMacro(float, float, 3);
#endif // ITK_USE_FFTWF

#ifdef ITK_USE_FFTWD
OverrideFFTWForward1DFFTImageFilterTypeMacro(double, double, 1);
OverrideFFTWForward1DFFTImageFilterTypeMacro(double, double, 2);
OverrideFFTWForward1DFFTImageFilterTypeMacro(double, double, 3);
#endif // ITK_USE_FFTWD
}
};

} // namespace itk

#ifndef ITK_MANUAL_INSTANTIATION
Expand Down
48 changes: 0 additions & 48 deletions Modules/Filtering/FFT/include/itkForward1DFFTImageFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -33,59 +33,11 @@ namespace itk
template <typename TInputImage, typename TOutputImage>
class VnlForward1DFFTImageFilter;

template <typename TSelfPointer, typename TInputImage, typename TOutputImage, typename TPixel>
struct Dispatch_1DRealToComplexConjugate_New
{
static TSelfPointer
Apply()
{
return VnlForward1DFFTImageFilter<TInputImage, TOutputImage>::New().GetPointer();
}
};

#ifdef ITK_USE_FFTWD
template <typename TSelfPointer, typename TInputImage, typename TOutputImage>
struct Dispatch_1DRealToComplexConjugate_New<TSelfPointer, TInputImage, TOutputImage, double>
{
static TSelfPointer
Apply()
{
return FFTWForward1DFFTImageFilter<TInputImage, TOutputImage>::New().GetPointer();
}
};
#endif // ITK_USE_FFTWD

#ifdef ITK_USE_FFTWF
template <typename TSelfPointer, typename TInputImage, typename TOutputImage>
struct Dispatch_1DRealToComplexConjugate_New<TSelfPointer, TInputImage, TOutputImage, float>
{
static TSelfPointer
Apply()
{
return FFTWForward1DFFTImageFilter<TInputImage, TOutputImage>::New().GetPointer();
}
};
#endif // ITK_USE_FFTWF

template <typename TInputImage, typename TOutputImage>
typename Forward1DFFTImageFilter<TInputImage, TOutputImage>::Pointer
Forward1DFFTImageFilter<TInputImage, TOutputImage>::New()
{
Pointer smartPtr = ObjectFactory<Self>::Create();

if (smartPtr.IsNull())
{
smartPtr = Dispatch_1DRealToComplexConjugate_New<
Pointer,
TInputImage,
TOutputImage,
typename NumericTraits<typename TOutputImage::PixelType>::ValueType>::Apply();
}
else
{
smartPtr->UnRegister();
}

return smartPtr;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#include "itkComplexToComplex1DFFTImageFilter.h"
#include <complex>
#include "itkVersion.h"
#include "itkObjectFactoryBase.h"

namespace itk
{
Expand Down Expand Up @@ -64,6 +66,77 @@ class ITK_TEMPLATE_EXPORT VnlComplexToComplex1DFFTImageFilter
GenerateData() override;
};


/** \class VnlComplexToComplex1DFFTImageFilterFactory
*
* \brief Object Factory implementation for VnlComplexToComplex1DFFTImageFilterFactory
*
* \ingroup FourierTransform
* \ingroup ITKFFT
*/
class VnlComplexToComplex1DFFTImageFilterFactory : public itk::ObjectFactoryBase
{
public:
ITK_DISALLOW_COPY_AND_MOVE(VnlComplexToComplex1DFFTImageFilterFactory);

using Self = VnlComplexToComplex1DFFTImageFilterFactory;
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
{
return ITK_SOURCE_VERSION;
}
const char *
GetDescription() const override
{
return "A Factory for VnlComplexToComplex1DFFTImageFilterFactory";
}

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

/** Run-time type information (and related methods). */
itkTypeMacro(VnlComplexToComplex1DFFTImageFilterFactory, itk::ObjectFactoryBase);

/** Register one factory of this type */
static void
RegisterOneFactory()
{
VnlComplexToComplex1DFFTImageFilterFactory::Pointer factory = VnlComplexToComplex1DFFTImageFilterFactory::New();

ObjectFactoryBase::RegisterFactory(factory);
}

private:
#define OverrideVnlComplexToComplex1DFFTImageFilterTypeMacro(ipt, opt, dm) \
{ \
using InputImageType = Image<ipt, dm>; \
using OutputImageType = Image<std::complex<opt>, dm>; \
this->RegisterOverride( \
typeid(ComplexToComplex1DFFTImageFilter<InputImageType, OutputImageType>).name(), \
typeid(VnlComplexToComplex1DFFTImageFilter<InputImageType, OutputImageType>).name(), \
"Vnl Forward 1D FFT Image Filter Override", \
true, \
CreateObjectFunction<VnlComplexToComplex1DFFTImageFilter<InputImageType, OutputImageType>>::New()); \
} \
ITK_MACROEND_NOOP_STATEMENT

VnlComplexToComplex1DFFTImageFilterFactory()
{
OverrideVnlComplexToComplex1DFFTImageFilterTypeMacro(float, float, 1);
OverrideVnlComplexToComplex1DFFTImageFilterTypeMacro(float, float, 2);
OverrideVnlComplexToComplex1DFFTImageFilterTypeMacro(float, float, 3);

OverrideVnlComplexToComplex1DFFTImageFilterTypeMacro(double, double, 1);
OverrideVnlComplexToComplex1DFFTImageFilterTypeMacro(double, double, 2);
OverrideVnlComplexToComplex1DFFTImageFilterTypeMacro(double, double, 3);
}
};

} // end namespace itk

#ifndef ITK_MANUAL_INSTANTIATION
Expand Down
71 changes: 71 additions & 0 deletions Modules/Filtering/FFT/include/itkVnlForward1DFFTImageFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "itkForward1DFFTImageFilter.h"
#include <complex>
#include "itkVersion.h"

namespace itk
{
Expand Down Expand Up @@ -64,6 +65,76 @@ class ITK_TEMPLATE_EXPORT VnlForward1DFFTImageFilter : public Forward1DFFTImageF
private:
};


/** \class VnlForward1DFFTImageFilterFactory
*
* \brief Object Factory implementation for VnlForward1DFFTImageFilter
*
* \ingroup FourierTransform
* \ingroup ITKFFT
*/
class VnlForward1DFFTImageFilterFactory : public itk::ObjectFactoryBase
{
public:
ITK_DISALLOW_COPY_AND_MOVE(VnlForward1DFFTImageFilterFactory);

using Self = VnlForward1DFFTImageFilterFactory;
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
{
return ITK_SOURCE_VERSION;
}
const char *
GetDescription() const override
{
return "A Factory for VnlForward1DFFTImageFilterFactory";
}

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

/** Run-time type information (and related methods). */
itkTypeMacro(VnlForward1DFFTImageFilterFactory, itk::ObjectFactoryBase);

/** Register one factory of this type */
static void
RegisterOneFactory()
{
VnlForward1DFFTImageFilterFactory::Pointer factory = VnlForward1DFFTImageFilterFactory::New();

ObjectFactoryBase::RegisterFactory(factory);
}

private:
#define OverrideVnlForward1DFFTImageFilterTypeMacro(ipt, opt, dm) \
{ \
using InputImageType = Image<ipt, dm>; \
using OutputImageType = Image<std::complex<opt>, dm>; \
this->RegisterOverride(typeid(Forward1DFFTImageFilter<InputImageType, OutputImageType>).name(), \
typeid(VnlForward1DFFTImageFilter<InputImageType, OutputImageType>).name(), \
"Vnl Forward 1D FFT Image Filter Override", \
true, \
CreateObjectFunction<VnlForward1DFFTImageFilter<InputImageType, OutputImageType>>::New()); \
} \
ITK_MACROEND_NOOP_STATEMENT

VnlForward1DFFTImageFilterFactory()
{
OverrideVnlForward1DFFTImageFilterTypeMacro(float, float, 1);
OverrideVnlForward1DFFTImageFilterTypeMacro(float, float, 2);
OverrideVnlForward1DFFTImageFilterTypeMacro(float, float, 3);

OverrideVnlForward1DFFTImageFilterTypeMacro(double, double, 1);
OverrideVnlForward1DFFTImageFilterTypeMacro(double, double, 2);
OverrideVnlForward1DFFTImageFilterTypeMacro(double, double, 3);
}
};

} // end namespace itk

#ifndef ITK_MANUAL_INSTANTIATION
Expand Down
3 changes: 2 additions & 1 deletion Modules/Filtering/FFT/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
set(ITKFFT_SRCS itkComplexToComplexFFTImageFilter.cxx)
set(ITKFFT_SRCS
itkComplexToComplexFFTImageFilter.cxx)

if( ITK_USE_FFTWF OR ITK_USE_FFTWD AND NOT ITK_USE_CUFFTW)
list(APPEND ITKFFT_SRCS itkFFTWGlobalConfiguration.cxx )
Expand Down

0 comments on commit b6b9c08

Please sign in to comment.