Skip to content

Commit

Permalink
ENH: Use InPlaceImageFilter for base class, run in-place by default
Browse files Browse the repository at this point in the history
Enable not copying the input image's bulk pixel data by default.
  • Loading branch information
blowekamp authored and hjmjohnson committed Sep 10, 2021
1 parent 374940a commit 4379b75
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#ifndef itkTransformGeometryImageFilter_h
#define itkTransformGeometryImageFilter_h

#include "itkImageToImageFilter.h"
#include "itkInPlaceImageFilter.h"
#include "itkVersorRigid3DTransform.h"
#include "itkDataObjectDecorator.h"

Expand Down Expand Up @@ -100,22 +100,22 @@ namespace itk
* \ingroup ITKTransform
*/
template <typename TInputImage, typename TOutputImage>
class ITK_TEMPLATE_EXPORT TransformGeometryImageFilter : public ImageToImageFilter<TInputImage, TOutputImage>
class ITK_TEMPLATE_EXPORT TransformGeometryImageFilter : public InPlaceImageFilter<TInputImage, TOutputImage>
{
public:
ITK_DISALLOW_COPY_AND_MOVE(TransformGeometryImageFilter);

/** Standard class type alias */
using Self = TransformGeometryImageFilter;
using Superclass = ImageToImageFilter<TInputImage, TOutputImage>;
using Superclass = InPlaceImageFilter<TInputImage, TOutputImage>;
using Pointer = SmartPointer<Self>;
using ConstPointer = SmartPointer<const Self>;

/** Method for creation through the object factory */
itkNewMacro(Self);

/** Run-time type information (and related methods) */
itkTypeMacro(TransformGeometryImageFilter, ImageToImageFilter);
itkTypeMacro(TransformGeometryImageFilter, InPlaceImageFilter);

/** input/output image type alias */
using InputImageType = TInputImage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ template <typename TInputImage, typename TOutputImage>
void
TransformGeometryImageFilter<TInputImage, TOutputImage>::GenerateData()
{
if (this->GetRunningInPlace())
{
// No need to copy the bulk data
return;
}
OutputImageType * output = this->GetOutput();

auto input = InputImageType::New();
Expand All @@ -87,6 +92,7 @@ TransformGeometryImageFilter<TInputImage, TOutputImage>::GenerateData()

// Can't use graft as it will overwrite the new meta-data
output->SetPixelContainer(castFilter->GetOutput()->GetPixelContainer());
output->SetBufferedRegion(castFilter->GetOutput()->GetBufferedRegion());
}

} // end namespace itk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ itkTransformGeometryImageFilterTest(int argc, char * argv[])

// Set up the transform filter
FilterType::Pointer filter = FilterType::New();
ITK_EXERCISE_BASIC_OBJECT_METHODS(filter, TransformGeometryImageFilter, ImageToImageFilter);
ITK_EXERCISE_BASIC_OBJECT_METHODS(filter, TransformGeometryImageFilter, InPlaceImageFilter);

// Test the exceptions
ITK_TRY_EXPECT_EXCEPTION(filter->Update());
Expand Down

0 comments on commit 4379b75

Please sign in to comment.