Skip to content

Commit

Permalink
ENH: Use itkBooleanMacro for ImageSpacing, `InterpolateSurfaceLoc…
Browse files Browse the repository at this point in the history
…ation`

Use `itkBooleanMacro` to set `ImageSpacing` and
`InterpolateSurfaceLocation` boolean member variable values to On/Off:
- Deprecate `Set*(On/Off)` signatures.
- Test the methods.
  • Loading branch information
jhlegarreta authored and dzenanz committed Feb 24, 2021
1 parent 4334133 commit 80cd0ce
Show file tree
Hide file tree
Showing 23 changed files with 177 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ namespace itk
* itk::Image<TRealType, N>.
*
* \par Filter Parameters
* The method SetUseImageSpacingOn will cause derivatives in the image to be
* The method UseImageSpacingOn will cause derivatives in the image to be
* scaled (inversely) with the pixel size of the input image, effectively
* taking derivatives in world coordinates (versus isotropic image
* space). SetUseImageSpacingOff turns this functionality off. Default is
* space). UseImageSpacingOff turns this functionality off. Default is
* UseImageSpacingOn. The parameter UseImageSpacing can
* be set directly with the method SetUseImageSpacing(bool).
*
Expand Down Expand Up @@ -170,10 +170,23 @@ class ITK_TEMPLATE_EXPORT DisplacementFieldJacobianDeterminantFilter
void
GenerateInputRequestedRegion() override;

/** Set/Get whether or not the filter will use the spacing of the input
* image (1/spacing) in the calculation of the Jacobian determinant. Use On
* to compute the Jacobian determinant in the space in which the data was
* acquired; use Off to reset the derivative weights, ignore the image
* spacing, and to compute the Jacobian determinant in the image space.
* Default is On. */
void
SetUseImageSpacing(bool);
itkGetConstMacro(UseImageSpacing, bool);
itkBooleanMacro(UseImageSpacing);

#if !defined(ITK_FUTURE_LEGACY_REMOVE)
/** Set the derivative weights according to the spacing of the input image
(1/spacing). Use this option if you want to calculate the Jacobian
determinant in the space in which the data was acquired. Default
is ImageSpacingOn. */
is ImageSpacingOn.
\deprecated Use DisplacementFieldJacobianDeterminantFilter::UseImageSpacingOn instead. */
void
SetUseImageSpacingOn()
{
Expand All @@ -182,19 +195,14 @@ class ITK_TEMPLATE_EXPORT DisplacementFieldJacobianDeterminantFilter

/** Reset the derivative weights to ignore image spacing. Use this option if
you want to calculate the Jacobian determinant in the image space.
Default is ImageSpacingOn. */
Default is ImageSpacingOn.
\deprecated Use DisplacementFieldJacobianDeterminantFilter::UseImageSpacingOff instead. */
void
SetUseImageSpacingOff()
{
this->SetUseImageSpacing(false);
}

/** Set/Get whether or not the filter will use the spacing of the input
image in its calculations */
void
SetUseImageSpacing(bool);

itkGetConstMacro(UseImageSpacing, bool);
#endif

using WeightsType = FixedArray<TRealType, ImageDimension>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "itkDisplacementFieldJacobianDeterminantFilter.h"
#include "itkNullImageToImageFilterDriver.hxx"
#include "itkStdStreamStateSave.h"
#include "itkTestingMacros.h"


static bool
TestDisplacementJacobianDeterminantValue()
Expand Down Expand Up @@ -76,6 +78,20 @@ TestDisplacementJacobianDeterminantValue()
itk::DisplacementFieldJacobianDeterminantFilter<VectorImageType, float>::Pointer filter =
itk::DisplacementFieldJacobianDeterminantFilter<VectorImageType, float>::New();


bool useImageSpacing = true;
#if !defined(ITK_FUTURE_LEGACY_REMOVE)
if (useImageSpacing)
{
filter->SetUseImageSpacingOn();
}
else
{
filter->SetUseImageSpacingOff();
}
#endif
ITK_TEST_SET_GET_BOOLEAN(filter, UseImageSpacing, useImageSpacing);

filter->SetInput(dispacementfield);
filter->Update();
itk::Image<float, 2>::Pointer output = filter->GetOutput();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,10 @@ class ITK_TEMPLATE_EXPORT ContourDirectedMeanDistanceImageFilter : public ImageT
/** Return the computed directed Mean distance. */
itkGetConstMacro(ContourDirectedMeanDistance, RealType);

/** Set if image spacing should be used in computing distances. */
/** Set/Get if image spacing should be used in computing distances. */
itkSetMacro(UseImageSpacing, bool);
itkGetConstMacro(UseImageSpacing, bool);
itkBooleanMacro(UseImageSpacing);

#ifdef ITK_USE_CONCEPT_CHECKING
// Begin concept checking
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,10 @@ class ITK_TEMPLATE_EXPORT DirectedHausdorffDistanceImageFilter : public ImageToI
const InputImage2Type *
GetInput2();

/** Set if image spacing should be used in computing distances. */
/** Set/Get if image spacing should be used in computing distances. */
itkSetMacro(UseImageSpacing, bool);
itkGetConstMacro(UseImageSpacing, bool);
itkBooleanMacro(UseImageSpacing);

/** Return the computed directed Hausdorff distance. */
itkGetConstMacro(DirectedHausdorffDistance, RealType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "itkContourDirectedMeanDistanceImageFilter.h"
#include "itkSimpleFilterWatcher.h"
#include "itkTestingMacros.h"

int
itkContourDirectedMeanDistanceImageFilterTest(int, char *[])
Expand Down Expand Up @@ -78,13 +79,17 @@ itkContourDirectedMeanDistanceImageFilterTest(int, char *[])
++it2;
}

auto useImageSpacing = true;

// compute the directed Mean distance h(image1,image2)
{
using FilterType = itk::ContourDirectedMeanDistanceImageFilter<Image1Type, Image2Type>;
FilterType::Pointer filter = FilterType::New();
itk::SimpleFilterWatcher watcher(filter, "filter");


ITK_TEST_SET_GET_BOOLEAN(filter, UseImageSpacing, useImageSpacing);

filter->SetInput1(image1);
filter->SetInput2(image2);
filter->Update();
Expand All @@ -111,6 +116,9 @@ itkContourDirectedMeanDistanceImageFilterTest(int, char *[])
using FilterType = itk::ContourDirectedMeanDistanceImageFilter<Image2Type, Image1Type>;
FilterType::Pointer filter = FilterType::New();


ITK_TEST_SET_GET_BOOLEAN(filter, UseImageSpacing, useImageSpacing);

filter->SetInput1(image2);
filter->SetInput2(image1);
filter->Update();
Expand Down
15 changes: 10 additions & 5 deletions Modules/Filtering/ImageFeature/include/itkDerivativeImageFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ class ITK_TEMPLATE_EXPORT DerivativeImageFilter : public ImageToImageFilter<TInp
itkSetMacro(Direction, unsigned int);
itkGetConstMacro(Direction, unsigned int);

/** Set/Get whether or not the filter will use the spacing of the input
* image in its calculations. Use On to compute the derivatives in physical
* space; use Off to ignore the image spacing and to compute the derivatives
* in isotropic voxel space. Default is On. */
itkSetMacro(UseImageSpacing, bool);
itkGetConstMacro(UseImageSpacing, bool);
itkBooleanMacro(UseImageSpacing);

#if !defined(ITK_FUTURE_LEGACY_REMOVE)
/** Use the image spacing information in calculations. Use this option if you
* want derivatives in physical space. Default is UseImageSpacingOn. */
void
Expand All @@ -107,11 +116,7 @@ class ITK_TEMPLATE_EXPORT DerivativeImageFilter : public ImageToImageFilter<TInp
{
this->SetUseImageSpacing(false);
}

/** Set/Get whether or not the filter will use the spacing of the input
image in its calculations */
itkSetMacro(UseImageSpacing, bool);
itkGetConstMacro(UseImageSpacing, bool);
#endif

/** DerivativeImageFilter needs a larger input requested region than
* the output requested region (larger in the direction of the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ itkDerivativeImageFilterTest(int argc, char * argv[])
filter->SetOrder(std::stoi(argv[3]));
filter->SetDirection(std::stoi(argv[4]));

auto useImageSpacing = true;
#if !defined(ITK_FUTURE_LEGACY_REMOVE)
if (useImageSpacing)
{
filter->SetUseImageSpacingOn();
}
else
{
filter->SetUseImageSpacingOff();
}
#endif
ITK_TEST_SET_GET_BOOLEAN(filter, UseImageSpacing, useImageSpacing);


itk::SimpleFilterWatcher watcher(filter, "Derivative");

// wire the pipeline
Expand Down
22 changes: 15 additions & 7 deletions Modules/Filtering/ImageGradient/include/itkGradientImageFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,27 +107,35 @@ class ITK_TEMPLATE_EXPORT GradientImageFilter : public ImageToImageFilter<TInput
void
GenerateInputRequestedRegion() override;

/** Set/Get whether or not the filter will use the spacing of the input
* image in its calculations. Use On to take the image spacing information
* into account and to compute the derivatives in physical space; use Off to
* ignore the image spacing and to compute the derivatives in isotropic
* voxel space. Default is On. */
itkSetMacro(UseImageSpacing, bool);
itkGetConstMacro(UseImageSpacing, bool);
itkBooleanMacro(UseImageSpacing);

#if !defined(ITK_FUTURE_LEGACY_REMOVE)
/** Use the image spacing information in calculations. Use this option if you
* want derivatives in physical space. Default is UseImageSpacingOn. */
want derivatives in physical space. Default is UseImageSpacingOn.
\deprecated Use GradientImageFilter::UseImageSpacingOn instead. */
void
SetUseImageSpacingOn()
{
this->SetUseImageSpacing(true);
}

/** Ignore the image spacing. Use this option if you want derivatives in
isotropic pixel space. Default is UseImageSpacingOn. */
isotropic pixel space. Default is UseImageSpacingOn.
\deprecated Use GradientImageFilter::UseImageSpacingOff instead. */
void
SetUseImageSpacingOff()
{
this->SetUseImageSpacing(false);
}
#endif

/** Set/Get whether or not the filter will use the spacing of the input
image in its calculations */
itkSetMacro(UseImageSpacing, bool);
itkGetConstMacro(UseImageSpacing, bool);
itkBooleanMacro(UseImageSpacing);
/** Allows to change the default boundary condition */
void
OverrideBoundaryCondition(ImageBoundaryCondition<TInputImage> * boundaryCondition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,26 +86,33 @@ class ITK_TEMPLATE_EXPORT GradientMagnitudeImageFilter : public ImageToImageFilt
void
GenerateInputRequestedRegion() override;

/** Set/Get whether or not the filter will use the spacing of the input
* image in the computation of the derivatives. Use On to compute the
* gradient in physical space; use Off to ignore image spacing and to
* compute the gradient in isotropic voxel space. Default is On. */
itkSetMacro(UseImageSpacing, bool);
itkGetConstMacro(UseImageSpacing, bool);
itkBooleanMacro(UseImageSpacing);

#if !defined(ITK_FUTURE_LEGACY_REMOVE)
/** Use the image spacing information in calculations. Use this option if you
* want derivatives in physical space. Default is UseImageSpacingOn. */
* want derivatives in physical space. Default is UseImageSpacingOn.
\deprecated Use GradientMagnitudeImageFilter::UseImageSpacingOn instead. */
void
SetUseImageSpacingOn()
{
this->SetUseImageSpacing(true);
}

/** Ignore the image spacing. Use this option if you want derivatives in
isotropic pixel space. Default is UseImageSpacingOn. */
isotropic pixel space. Default is UseImageSpacingOn.
\deprecated Use GradientMagnitudeImageFilter::UseImageSpacingOff instead. */
void
SetUseImageSpacingOff()
{
this->SetUseImageSpacing(false);
}

/** Set/Get whether or not the filter will use the spacing of the input
image in its calculations */
itkSetMacro(UseImageSpacing, bool);
itkGetConstMacro(UseImageSpacing, bool);
#endif

#ifdef ITK_USE_CONCEPT_CHECKING
// Begin concept checking
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ namespace itk
* SetUsePrincipleComponentsOn/Off determine controls the calculation mode that
* is used.
*
* The method SetUseImageSpacingOn will cause derivatives in the image to be
* The method UseImageSpacingOn will cause derivatives in the image to be
* scaled (inversely) with the pixel size of the input image, effectively
* taking derivatives in world coordinates (versus isotropic image
* space). SetUseImageSpacingOff turns this functionality off. Default is
* space). UseImageSpacingOff turns this functionality off. Default is
* UseImageSpacingOn. The parameter UseImageSpacing can be set
* directly with the method SetUseImageSpacing(bool).
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ itkGradientImageFilterTest(int argc, char * argv[])


auto useImageSpacing = static_cast<bool>(std::stoi(argv[1]));
#if !defined(ITK_FUTURE_LEGACY_REMOVE)
if (useImageSpacing)
{
filter1->SetUseImageSpacingOn();
}
else
{
filter1->SetUseImageSpacingOff();
}
#endif
ITK_TEST_SET_GET_BOOLEAN(filter1, UseImageSpacing, useImageSpacing);

auto useImageDirection = static_cast<bool>(std::stoi(argv[2]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <iostream>
#include "itkGradientMagnitudeImageFilter.h"
#include "itkNullImageToImageFilterDriver.hxx"
#include "itkTestingMacros.h"


inline std::ostream &
operator<<(std::ostream & o, const itk::Vector<float, 3> & v)
Expand All @@ -38,6 +40,19 @@ itkGradientMagnitudeImageFilterTest(int, char *[])
itk::GradientMagnitudeImageFilter<ImageType, ImageType>::Pointer filter =
itk::GradientMagnitudeImageFilter<ImageType, ImageType>::New();

bool useImageSpacing = true;
#if !defined(ITK_FUTURE_LEGACY_REMOVE)
if (useImageSpacing)
{
filter->SetUseImageSpacingOn();
}
else
{
filter->SetUseImageSpacingOff();
}
#endif
ITK_TEST_SET_GET_BOOLEAN(filter, UseImageSpacing, useImageSpacing);

// Run Test
itk::Size<2> sz;
sz[0] = 100;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ itkVectorGradientMagnitudeImageFilterTest1(int argc, char * argv[])
filter->SetInput(adaptor);

auto useImageSpacing = static_cast<bool>(std::stoi(argv[3]));
#if !defined(ITK_FUTURE_LEGACY_REMOVE)
if (useImageSpacing)
{
filter->SetUseImageSpacingOn();
}
else
{
filter->SetUseImageSpacingOff();
}
#endif
ITK_TEST_SET_GET_BOOLEAN(filter, UseImageSpacing, useImageSpacing);

auto derivativeWeightsValue = static_cast<FilterType::DerivativeWeightsType::ValueType>(std::stod(argv[4]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ itkOrthogonalSwath2DPathFilterTest(int, char *[])
// kernel, and so setting the maximum error to 1.0 (no limit) will make it
// stop growing the kernel at the desired 3x3 size.
double maxError = 0.9;
smoothFilter->SetUseImageSpacingOff();
smoothFilter->UseImageSpacingOff();
smoothFilter->SetVariance(gaussianVariance);
smoothFilter->SetMaximumError(maxError);

Expand Down
Loading

0 comments on commit 80cd0ce

Please sign in to comment.