17 #include <itkInterpolateImageFunction.h>
18 #include <itkNearestNeighborInterpolateImageFunction.h>
19 #include <itkLinearInterpolateImageFunction.h>
20 #include <itkBSplineInterpolateImageFunction.h>
21 #include <itkWindowedSincInterpolateImageFunction.h>
29 #include "mapRegistration.h"
34 template <
typename TImage >
37 typedef ::itk::InterpolateImageFunction< TImage > BaseInterpolatorType;
40 switch (interpolatorType)
50 spInterpolator->SetSplineOrder(3);
51 result = spInterpolator;
61 result = ::itk::WindowedSincInterpolateImageFunction<TImage,4,::itk::Function::WelchWindowFunction<4> >
::New();
75 template <
typename TPixelType,
unsigned int VImageDimension >
80 typedef ::map::core::Registration<VImageDimension,VImageDimension> ConcreteRegistrationType;
81 typedef ::map::core::ImageMappingTask<ConcreteRegistrationType, ::itk::Image<TPixelType,VImageDimension>, ::itk::Image<TPixelType,VImageDimension> > MappingTaskType;
84 typedef typename MappingTaskType::ResultImageDescriptorType ResultImageDescriptorType;
89 if (registration->getMovingDimensions()!=VImageDimension)
91 map::core::OStringStream str;
92 str <<
"Dimension of MITK image ("<<VImageDimension<<
") does not equal the moving dimension of the registration object ("<<registration->getMovingDimensions()<<
").";
96 if (registration->getTargetDimensions()!=VImageDimension)
98 map::core::OStringStream str;
99 str <<
"Dimension of MITK image ("<<VImageDimension<<
") does not equal the target dimension of the registration object ("<<registration->getTargetDimensions()<<
").";
103 const ConcreteRegistrationType* castedReg =
dynamic_cast<const ConcreteRegistrationType*
>(registration);
105 if (registration->getTargetDimensions()==2 && resultGeometry)
109 if (bounds[4]!=0 || bounds[5]!=0)
114 map::core::OStringStream str;
115 str <<
"Dimension of defined result geometry does not equal the target dimension of the registration object ("<<registration->getTargetDimensions()<<
").";
127 typename ResultImageDescriptorType::SizeType size;
128 typename ResultImageDescriptorType::SpacingType fieldSpacing;
129 typename ResultImageDescriptorType::DirectionType matrix;
136 for (
unsigned int i = 0; i<VImageDimension; ++i)
140 size[i] =
static_cast<typename ResultImageDescriptorType::SizeType::SizeValueType
>(geoBounds[(2*i)+1]-geoBounds[2*i])*fieldSpacing[i];
144 matrix.SetIdentity();
158 if ( VImageDimension == 2)
160 if ( ( geoMatrix[0][2] != 0) ||
161 ( geoMatrix[1][2] != 0) ||
162 ( geoMatrix[2][0] != 0) ||
163 ( geoMatrix[2][1] != 0) ||
164 (( geoMatrix[2][2] != 1) && ( geoMatrix[2][2] != -1) ))
172 for ( i=0; i < 2; ++i)
174 for( j=0; j < 2; ++j )
176 matrix[i][j] = geoMatrix[i][j]/fieldSpacing[j];
181 else if (VImageDimension == 3)
184 for ( i=0; i < 3; ++i)
186 for( j=0; j < 3; ++j )
188 matrix[i][j] = geoMatrix[i][j]/fieldSpacing[j];
201 resultDescriptor->setOrigin(origin);
202 resultDescriptor->setSize(size);
203 resultDescriptor->setSpacing(fieldSpacing);
204 resultDescriptor->setDirection(matrix);
209 typedef ::itk::InterpolateImageFunction< ::itk::Image<TPixelType,VImageDimension> > BaseInterpolatorType;
211 assert(interpolator.IsNotNull());
212 spTask->setImageInterpolator(interpolator);
213 spTask->setInputImage(input);
214 spTask->setRegistration(castedReg);
215 spTask->setResultImageDescriptor(resultDescriptor);
216 spTask->setThrowOnMappingError(throwOnMappingError);
217 spTask->setErrorValue(errorValue);
218 spTask->setThrowOnPaddingError(throwOnOutOfInputAreaError);
219 spTask->setPaddingValue(paddingValue);
222 mitk::CastToMitkImage<>(spTask->getResultImage(),result);
232 mitkThrow() <<
"Cannot map image. Passed registration wrapper pointer is NULL.";
236 mitkThrow() <<
"Cannot map image. Passed image pointer is NULL.";
243 AccessByItk_n(input,
doMITKMap, (result, registration, throwOnOutOfInputAreaError, paddingValue, resultGeometry, throwOnMappingError, errorValue, interpolatorType));
254 mappedTimeGeometry->SetTimeStepGeometry(mappedGeometry,i);
263 imageTimeSelector->SetInput(input);
264 imageTimeSelector->SetTimeNr(i);
265 imageTimeSelector->UpdateLargestPossibleRegion();
269 AccessByItk_n(timeStepInput,
doMITKMap, (timeStepResult, registration, throwOnOutOfInputAreaError, paddingValue, resultGeometry, throwOnMappingError, errorValue, interpolatorType));
270 result->SetVolume(timeStepResult->GetVolumeData()->GetData(),i);
284 mitkThrow() <<
"Cannot map image. Passed registration wrapper pointer is NULL.";
288 mitkThrow() <<
"Cannot map image. Passed registration wrapper containes no registration.";
292 mitkThrow() <<
"Cannot map image. Passed image pointer is NULL.";
309 mitkThrow() <<
"Cannot refine image geometry. Passed registration pointer is NULL.";
313 mitkThrow() <<
"Cannot refine image geometry. Passed image pointer is NULL.";
317 if(spTransform.IsNull() && throwOnError)
319 mitkThrow() <<
"Cannot refine image geometry. Registration does not contain a suitable direct mapping kernel (3D affine transformation or compatible required).";
322 if(spTransform.IsNotNull())
325 result = input->
Clone();
328 for(
unsigned int i = 0; i < result->GetTimeSteps(); ++i)
330 result->GetGeometry(i)->Compose(spTransform);
332 result->GetTimeGeometry()->Update();
345 mitkThrow() <<
"Cannot refine image geometry. Passed registration wrapper pointer is NULL.";
349 mitkThrow() <<
"Cannot refine image geometry. Passed registration wrapper containes no registration.";
353 mitkThrow() <<
"Cannot refine image geometry. Passed image pointer is NULL.";
368 mitkThrow() <<
"Cannot check refine capability of registration. Passed registration pointer is NULL.";
383 mitkThrow() <<
"Cannot check refine capability of registration. Passed registration wrapper pointer is NULL.";
387 mitkThrow() <<
"Cannot check refine capability of registration. Passed registration wrapper containes no registration.";
const Point3D GetOrigin() const
Get the origin, e.g. the upper-left corner of the plane.
static Affine3DTransformType::Pointer getAffineMatrix(const mitk::MAPRegistrationWrapper *wrapper, bool inverseKernel)
itk::SmartPointer< Self > Pointer
BoundingBoxType::BoundsArrayType BoundsArrayType
const mitk::Vector3D GetSpacing() const
Get the spacing (size of a pixel).
const mitk::TimeGeometry * GetTimeGeometry() const
Return the TimeGeometry of the data as const pointer.
MAPRegistrationWrapper Wrapper class to allow the handling of MatchPoint registration objects as mitk...
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...
#define AccessByItk_n(mitkImage, itkImageTypeFunction, va_tuple)
Access a MITK image by an ITK image with one or more parameters.
const BoundsArrayType GetBounds() const
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)
const mitk::PixelType GetPixelType(int n=0) const
Returns the PixelType of channel n.
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)
Exception class thrown in AccessByItk macros.
MITKMATCHPOINTREGISTRATION_EXPORT ResultImageType::Pointer map(const InputImageType *input, const RegistrationType *registration, bool throwOnOutOfInputAreaError=false, const double &paddingValue=0, const ResultImageGeometryType *resultGeometry=NULL, bool throwOnMappingError=true, const double &errorValue=0, mitk::ImageMappingInterpolator::Type interpolatorType=mitk::ImageMappingInterpolator::Linear)
typename::itk::InterpolateImageFunction< TImage >::Pointer generateInterpolator(mitk::ImageMappingInterpolator::Type interpolatorType)
::map::core::RegistrationBase RegistrationType
BaseGeometry Describes the geometry of a data object.
mitk::AffineTransform3D * GetIndexToWorldTransform()
Get the transformation used to convert from index to world coordinates.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.