Skip to content

Commit

Permalink
ENH: Refactor TransformGeometryImageFilter pipeline i/o
Browse files Browse the repository at this point in the history
Add named pipeline inputs of InputImage and RigidTransform and use
macro to provide standard class methods from named inputs.

Removed unneeded m_OutputImage member variable.
  • Loading branch information
blowekamp authored and hjmjohnson committed Sep 10, 2021
1 parent 3b1c297 commit 2de73ab
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 37 deletions.
19 changes: 5 additions & 14 deletions Modules/Core/Transform/include/itkTransformGeometryImageFilter.h
Expand Up @@ -21,6 +21,7 @@

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

namespace itk
{
Expand Down Expand Up @@ -142,29 +143,19 @@ class ITK_TEMPLATE_EXPORT TransformGeometryImageFilter : public ImageToImageFilt
using RigidTransformConstPointer = typename RigidTransformType::ConstPointer;

/** Set/Get rigid transform. The default is an identity transform */
itkSetConstObjectMacro(RigidTransform, RigidTransformType);
itkGetConstObjectMacro(RigidTransform, RigidTransformType);
itkSetGetDecoratedObjectInputMacro(RigidTransform, RigidTransformType);

/** Set/Get required input image. (A wrapper to this->Set/GetInput()) */
void
SetInputImage(const InputImageType * image);
itkSetInputMacro(InputImage, InputImageType);

const InputImageType *
GetInputImage() const;
itkGetInputMacro(InputImage, InputImageType);

protected:
TransformGeometryImageFilter() = default;
TransformGeometryImageFilter();
~TransformGeometryImageFilter() override = default;

void
GenerateData() override;

void
PrintSelf(std::ostream & os, Indent indent) const override;

private:
OutputImagePointer m_OutputImage;
RigidTransformConstPointer m_RigidTransform;
};
} // end namespace itk

Expand Down
38 changes: 15 additions & 23 deletions Modules/Core/Transform/include/itkTransformGeometryImageFilter.hxx
Expand Up @@ -24,18 +24,17 @@

namespace itk
{
template <typename TInputImage, typename TOutputImage>
void
TransformGeometryImageFilter<TInputImage, TOutputImage>::SetInputImage(const InputImageType * image)
{
this->SetInput(0, image);
}


template <typename TInputImage, typename TOutputImage>
const typename TransformGeometryImageFilter<TInputImage, TOutputImage>::InputImageType *
TransformGeometryImageFilter<TInputImage, TOutputImage>::GetInputImage() const
TransformGeometryImageFilter<TInputImage, TOutputImage>::TransformGeometryImageFilter()
{
return this->GetInput(0);
Self::SetPrimaryInputName("InputImage");

// "RigidTransform" required ( not numbered )
Self::AddRequiredInputName("RigidTransform");

// initialize transform
}


Expand All @@ -49,6 +48,8 @@ TransformGeometryImageFilter<TInputImage, TOutputImage>::GenerateData()
return;
}

typename OutputImageType::Pointer outputPtr;

// SEE HEADER FILE FOR MATH DESCRIPTION

{
Expand All @@ -57,10 +58,10 @@ TransformGeometryImageFilter<TInputImage, TOutputImage>::GenerateData()
typename DuplicatorType::Pointer CastFilter = DuplicatorType::New();
CastFilter->SetInput(this->GetInput());
CastFilter->Update();
m_OutputImage = CastFilter->GetOutput();
outputPtr = CastFilter->GetOutput();
}

RigidTransformConstPointer FMTxfm = this->m_RigidTransform.GetPointer();
RigidTransformConstPointer FMTxfm = this->GetRigidTransform();
const typename RigidTransformType::MatrixType inverseRotation(FMTxfm->GetMatrix().GetInverse());

// Modify the origin and direction info of the image to reflect the transform.
Expand All @@ -73,21 +74,12 @@ TransformGeometryImageFilter<TInputImage, TOutputImage>::GenerateData()
{
newOriginPoint[i] = newOriginVector[i];
}
m_OutputImage->SetOrigin(newOriginPoint);
m_OutputImage->SetDirection(inverseRotation * this->GetInput()->GetDirection()); // NewDC = [R^-1][DC]
outputPtr->SetOrigin(newOriginPoint);
outputPtr->SetDirection(inverseRotation * this->GetInput()->GetDirection()); // NewDC = [R^-1][DC]

this->GraftOutput(m_OutputImage);
this->GraftOutput(outputPtr);
}

template <typename TInputImage, typename TOutputImage>
void
TransformGeometryImageFilter<TInputImage, TOutputImage>::PrintSelf(std::ostream & os, Indent indent) const
{
Superclass::PrintSelf(os, indent);

os << indent << "Input transform: " << m_RigidTransform << std::endl;
os << indent << "Output image: " << m_OutputImage << std::endl;
}
} // end namespace itk

#endif

0 comments on commit 2de73ab

Please sign in to comment.