13 #include <itkInterpolateImageFunction.h> 14 #include <itkNearestNeighborInterpolateImageFunction.h> 15 #include <itkLinearInterpolateImageFunction.h> 16 #include <itkBSplineInterpolateImageFunction.h> 17 #include <itkWindowedSincInterpolateImageFunction.h> 25 #include "mapRegistration.h" 30 template <
typename TImage >
33 typedef ::itk::InterpolateImageFunction< TImage > BaseInterpolatorType;
34 typename BaseInterpolatorType::Pointer result;
36 switch (interpolatorType)
40 result = ::itk::NearestNeighborInterpolateImageFunction<TImage>::New();
45 typename ::itk::BSplineInterpolateImageFunction<TImage>::Pointer spInterpolator = ::itk::BSplineInterpolateImageFunction<TImage>::New();
46 spInterpolator->SetSplineOrder(3);
47 result = spInterpolator;
52 result = ::itk::WindowedSincInterpolateImageFunction<TImage,4>::New();
57 result = ::itk::WindowedSincInterpolateImageFunction<TImage,4,::itk::Function::WelchWindowFunction<4> >::New();
62 result = ::itk::LinearInterpolateImageFunction<TImage>::New();
71 template <
typename TPixelType,
unsigned int VImageDimension >
76 typedef ::map::core::Registration<VImageDimension,VImageDimension> ConcreteRegistrationType;
77 typedef ::map::core::ImageMappingTask<ConcreteRegistrationType, ::itk::Image<TPixelType,VImageDimension>, ::itk::Image<TPixelType,VImageDimension> > MappingTaskType;
78 typename MappingTaskType::Pointer spTask = MappingTaskType::New();
80 typedef typename MappingTaskType::ResultImageDescriptorType ResultImageDescriptorType;
81 typename ResultImageDescriptorType::Pointer resultDescriptor;
85 if (registration->getMovingDimensions()!=VImageDimension)
87 map::core::OStringStream str;
88 str <<
"Dimension of MITK image ("<<VImageDimension<<
") does not equal the moving dimension of the registration object ("<<registration->getMovingDimensions()<<
").";
92 if (registration->getTargetDimensions()!=VImageDimension)
94 map::core::OStringStream str;
95 str <<
"Dimension of MITK image ("<<VImageDimension<<
") does not equal the target dimension of the registration object ("<<registration->getTargetDimensions()<<
").";
99 const ConcreteRegistrationType* castedReg =
dynamic_cast<const ConcreteRegistrationType*
>(registration);
101 if (registration->getTargetDimensions()==2 && resultGeometry)
105 if (bounds[4]!=0 || bounds[5]!=0)
110 map::core::OStringStream str;
111 str <<
"Dimension of defined result geometry does not equal the target dimension of the registration object ("<<registration->getTargetDimensions()<<
").";
120 resultDescriptor = ResultImageDescriptorType::New();
122 typename ResultImageDescriptorType::PointType origin;
123 typename ResultImageDescriptorType::SizeType size;
124 typename ResultImageDescriptorType::SpacingType fieldSpacing;
125 typename ResultImageDescriptorType::DirectionType matrix;
132 for (
unsigned int i = 0; i<VImageDimension; ++i)
136 size[i] =
static_cast<typename ResultImageDescriptorType::SizeType::SizeValueType
>(geoBounds[(2*i)+1]-geoBounds[2*i])*fieldSpacing[i];
140 matrix.SetIdentity();
154 if ( VImageDimension == 2)
156 if ( ( geoMatrix[0][2] != 0) ||
157 ( geoMatrix[1][2] != 0) ||
158 ( geoMatrix[2][0] != 0) ||
159 ( geoMatrix[2][1] != 0) ||
160 (( geoMatrix[2][2] != 1) && ( geoMatrix[2][2] != -1) ))
168 for ( i=0; i < 2; ++i)
170 for( j=0; j < 2; ++j )
172 matrix[i][j] = geoMatrix[i][j]/fieldSpacing[j];
177 else if (VImageDimension == 3)
180 for ( i=0; i < 3; ++i)
182 for( j=0; j < 3; ++j )
184 matrix[i][j] = geoMatrix[i][j]/fieldSpacing[j];
197 resultDescriptor->setOrigin(origin);
198 resultDescriptor->setSize(size);
199 resultDescriptor->setSpacing(fieldSpacing);
200 resultDescriptor->setDirection(matrix);
205 typedef ::itk::InterpolateImageFunction< ::itk::Image<TPixelType,VImageDimension> > BaseInterpolatorType;
206 typename BaseInterpolatorType::Pointer interpolator = generateInterpolator< ::itk::Image<TPixelType,VImageDimension> >(interpolatorType);
207 assert(interpolator.IsNotNull());
208 spTask->setImageInterpolator(interpolator);
209 spTask->setInputImage(input);
210 spTask->setRegistration(castedReg);
211 spTask->setResultImageDescriptor(resultDescriptor);
212 spTask->setThrowOnMappingError(throwOnMappingError);
213 spTask->setErrorValue(errorValue);
214 spTask->setThrowOnPaddingError(throwOnOutOfInputAreaError);
215 spTask->setPaddingValue(paddingValue);
218 mitk::CastToMitkImage<>(spTask->getResultImage(),result);
228 mitkThrow() <<
"Cannot map image. Passed registration wrapper pointer is nullptr.";
232 mitkThrow() <<
"Cannot map image. Passed image pointer is nullptr.";
239 AccessByItk_n(input,
doMITKMap, (result, registration, throwOnOutOfInputAreaError, paddingValue, resultGeometry, throwOnMappingError, errorValue, interpolatorType));
250 mappedTimeGeometry->SetTimeStepGeometry(mappedGeometry,i);
259 imageTimeSelector->SetInput(input);
260 imageTimeSelector->SetTimeNr(i);
261 imageTimeSelector->UpdateLargestPossibleRegion();
265 AccessByItk_n(timeStepInput,
doMITKMap, (timeStepResult, registration, throwOnOutOfInputAreaError, paddingValue, resultGeometry, throwOnMappingError, errorValue, interpolatorType));
267 result->SetVolume(readAccess.
GetData(),i);
281 mitkThrow() <<
"Cannot map image. Passed registration wrapper pointer is nullptr.";
285 mitkThrow() <<
"Cannot map image. Passed registration wrapper containes no registration.";
289 mitkThrow() <<
"Cannot map image. Passed image pointer is nullptr.";
306 mitkThrow() <<
"Cannot refine image geometry. Passed registration pointer is nullptr.";
310 mitkThrow() <<
"Cannot refine image geometry. Passed image pointer is nullptr.";
314 if(spTransform.IsNull() && throwOnError)
316 mitkThrow() <<
"Cannot refine image geometry. Registration does not contain a suitable direct mapping kernel (3D affine transformation or compatible required).";
319 if(spTransform.IsNotNull())
322 result = input->
Clone();
325 for(
unsigned int i = 0; i < result->GetTimeSteps(); ++i)
327 result->GetGeometry(i)->Compose(spTransform);
329 result->GetTimeGeometry()->Update();
342 mitkThrow() <<
"Cannot refine image geometry. Passed registration wrapper pointer is nullptr.";
346 mitkThrow() <<
"Cannot refine image geometry. Passed registration wrapper containes no registration.";
350 mitkThrow() <<
"Cannot refine image geometry. Passed image pointer is nullptr.";
365 mitkThrow() <<
"Cannot check refine capability of registration. Passed registration pointer is nullptr.";
380 mitkThrow() <<
"Cannot check refine capability of registration. Passed registration wrapper pointer is nullptr.";
384 mitkThrow() <<
"Cannot check refine capability of registration. Passed registration wrapper containes no registration.";
static Affine3DTransformType::Pointer getAffineMatrix(const mitk::MAPRegistrationWrapper *wrapper, bool inverseKernel)
BoundingBoxType::BoundsArrayType BoundsArrayType
const mitk::PixelType GetPixelType(int n=0) const
Returns the PixelType of channel n.
MAPRegistrationWrapper Wrapper class to allow the handling of MatchPoint registration objects as mitk...
#define AccessByItk_n(mitkImage, itkImageTypeFunction, va_tuple)
Access a MITK image by an ITK image with one or more parameters.
const mitk::TimeGeometry * GetTimeGeometry() const
Return the TimeGeometry of the data as const pointer.
::map::core::RegistrationBase * GetRegistration()
MITKMATCHPOINTREGISTRATION_EXPORT bool canRefineGeometry(const RegistrationType *registration)
ValueType
Type of the value held by a Value object.
Image class for storing images.
MITKMATCHPOINTREGISTRATION_EXPORT ResultImageType::Pointer refineGeometry(const InputImageType *input, const RegistrationType *registration, bool throwOnError=true)
void doMITKMap(const ::itk::Image< TPixelType, VImageDimension > *input, mitk::ImageMappingHelper::ResultImageType::Pointer &result, const mitk::ImageMappingHelper::RegistrationType *®istration, bool throwOnOutOfInputAreaError, const double &paddingValue, const mitk::ImageMappingHelper::ResultImageGeometryType *&resultGeometry, bool throwOnMappingError, const double &errorValue, mitk::ImageMappingInterpolator::Type interpolatorType)
const Point3D GetOrigin() const
Get the origin, e.g. the upper-left corner of the plane.
MITKMATCHPOINTREGISTRATION_EXPORT ResultImageType::Pointer map(const InputImageType *input, const RegistrationType *registration, bool throwOnOutOfInputAreaError=false, const double &paddingValue=0, const ResultImageGeometryType *resultGeometry=nullptr, bool throwOnMappingError=true, const double &errorValue=0, mitk::ImageMappingInterpolator::Type interpolatorType=mitk::ImageMappingInterpolator::Linear)
Exception class thrown in AccessByItk macros.
const mitk::Vector3D GetSpacing() const
Get the spacing (size of a pixel).
unsigned int GetTimeSteps() const
Get the number of time steps from the TimeGeometry As the base data has not a data vector given by it...
ImageReadAccessor class to get locked read access for a particular image part.
typename ::itk::InterpolateImageFunction< TImage >::Pointer generateInterpolator(mitk::ImageMappingInterpolator::Type interpolatorType)
::map::core::RegistrationBase RegistrationType
const BoundsArrayType GetBounds() const
BaseGeometry Describes the geometry of a data object.
const void * GetData() const
Gives const access to the data.
mitk::AffineTransform3D * GetIndexToWorldTransform()
Get the transformation used to convert from index to world coordinates.