SuPReMo  0.1.1
Loading...
Searching...
No Matches
Transformation.h
1// ====================================================================================================
2//
3// SuPReMo: Surrogate Parameterised Respiratory Motion Model
4// An implementation of the generalised motion modelling and image registration framework
5//
6// Copyright (c) University College London (UCL). All rights reserved.
7//
8// This software is distributed WITHOUT ANY WARRANTY; without even
9// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10// PURPOSE.
11//
12// See LICENSE.txt in the top level directory for details.
13//
14// ====================================================================================================
15
16
17
18
19#pragma once
20
21
22#include "nifti1_io.h"
23#include <memory>
24#include <vector>
25
26
27template <class PrecisionType>
28void interpolantCubicSpline( PrecisionType ratio, PrecisionType *basis )
29{
30 if (ratio < 0.0) ratio = 0.0; //reg_rounding error
31 PrecisionType FF = ratio * ratio;
32 basis[0] = (PrecisionType)((ratio * ((2.0 - ratio)*ratio - 1.0)) / 2.0);
33 basis[1] = (PrecisionType)((FF * (3.0*ratio - 5.0) + 2.0) / 2.0);
34 basis[2] = (PrecisionType)((ratio * ((4.0 - 3.0*ratio)*ratio + 1.0)) / 2.0);
35 basis[3] = (PrecisionType)((ratio - 1.0) * FF / 2.0);
36}
37
38template <class PrecisionType>
39void interpolantCubicSpline( PrecisionType ratio, PrecisionType *basis, PrecisionType *derivative )
40{
41 interpolantCubicSpline<PrecisionType>( ratio, basis );
42 if (ratio < 0.0) ratio = 0.0; //reg_rounding error
43 PrecisionType FF = ratio * ratio;
44 derivative[0] = (PrecisionType)((4.0*ratio - 3.0*FF - 1.0) / 2.0);
45 derivative[1] = (PrecisionType)((9.0*ratio - 10.0) * ratio / 2.0);
46 derivative[2] = (PrecisionType)((8.0*ratio - 9.0*FF + 1) / 2.0);
47 derivative[3] = (PrecisionType)((3.0*ratio - 2.0) * ratio / 2.0);
48}
49
50
55{
56public:
57 typedef float PrecisionType;
58
59 virtual ~Transformation(){};
60
64 virtual void InitialiseLevel(unsigned int level) = 0;
65
69
72 virtual unsigned int GetNumberOfParameters() { return this->numberOfParameters; };
73
76 virtual void SetParameters( PrecisionType* paramsIn, bool parametersAreDisplacements ) = 0;
77
84 virtual nifti_image* GetDeformationVectorField( nifti_image* targetImageIn ) = 0;
85
93 virtual PrecisionType* GetDVFGradientWRTTransformationParameters( nifti_image* denseDVFIn ) = 0;
94
99
102 virtual double GetConstraintValue() = 0;
103
109 void TransformImage( nifti_image* sourceImage, nifti_image* warpedImage );
110
123 void TransformImageAdjoint( nifti_image* sourceImage, nifti_image* sourceWeightsImage,
124 nifti_image* warpedImage, nifti_image* warpedWeightsImage );
125
128 virtual std::shared_ptr<Transformation> DeepCopy() = 0;
129
133
137
145 virtual void GetImageGradientWRTDVF(nifti_image* sourceImage, nifti_image* outWarpedGradientImage);
146
152 void ReorientateVectorImage(nifti_image* vectorFieldToReorientate, mat44 reorientationMatrix);
153
154
161
162
166 virtual std::vector<nifti_image*> GetTransformationAsImage() = 0;
167
168
172
173protected:
174
178 bool CheckDVFImageUpdateRequired( nifti_image* targetImageIn );
179
180
187 bool CheckImageGeometryEquality( nifti_image* img1, nifti_image* img2 );
188
189
193
194 // Functions brought forward from reg-resp
195 void CubicSplineTransformImage3D(nifti_image* sourceImage, nifti_image* warpedImage);
196 void CubicSplineTransformImage2D( nifti_image* sourceImage, nifti_image* warpedImage );
197 void NearestNeighbourTransformImage3D( nifti_image* sourceImage, nifti_image* warpedImage );
198 void NearestNeighbourTransformImage2D( nifti_image* sourceImage, nifti_image* warpedImage );
199 void TrilinearTransformImage( nifti_image* sourceImage, nifti_image* warpedImage );
200 void BilinearTransformImage( nifti_image* sourceImage, nifti_image* warpedImage );
201
202 void CubicSplineTransformImageAdjoint3D( nifti_image * sourceImage, nifti_image * sourceWeightsImage, nifti_image * warpedImage, nifti_image * warpedWeightsImage );
203 void CubicSplineTransformImageAdjoint2D( nifti_image * sourceImage, nifti_image * sourceWeightsImage, nifti_image * warpedImage, nifti_image * warpedWeightsImage );
204 void NearestNeighbourTransformImageAdjoint3D( nifti_image * sourceImage, nifti_image * sourceWeightsImage, nifti_image * warpedImage, nifti_image * warpedWeightsImage );
205 void NearestNeighbourTransformImageAdjoint2D( nifti_image * sourceImage, nifti_image * sourceWeightsImage, nifti_image * warpedImage, nifti_image * warpedWeightsImage );
206 void TrilinearTransformImageAdjoint( nifti_image * sourceImage, nifti_image * sourceWeightsImage, nifti_image * warpedImage, nifti_image * warpedWeightsImage );
207 void BilinearTransformImageAdjoint( nifti_image * sourceImage, nifti_image * sourceWeightsImage, nifti_image * warpedImage, nifti_image * warpedWeightsImage );
208
209 void TrilinearImageGradient( nifti_image* sourceImage, nifti_image* resultGradientImage );
210 void BilinearImageGradient( nifti_image* sourceImage, nifti_image* resultGradientImage );
211 void CubicSplineImageGradient3D( nifti_image* sourceImage, nifti_image* resultGradientImage );
212 void CubicSplineImageGradient2D( nifti_image* sourceImage, nifti_image* resultGradientImage );
213
215 unsigned int numberOfParameters;
219};
Definition: Transformation.h:55
bool dvfImageUpdateRequired
Indicates if the DVF requires re-calculation when it is required.
Definition: Transformation.h:214
float PrecisionType
Definition: Transformation.h:57
virtual double GetConstraintValue()=0
int interpolation
Type of interpolation used.
Definition: Transformation.h:216
virtual PrecisionType GetSumOfPenaltyWeights()=0
void BilinearTransformImage(nifti_image *sourceImage, nifti_image *warpedImage)
Definition: Transformation.cpp:1450
void CubicSplineTransformImage3D(nifti_image *sourceImage, nifti_image *warpedImage)
Definition: Transformation.cpp:919
virtual ~Transformation()
Definition: Transformation.h:59
virtual nifti_image * GetDeformationVectorField(nifti_image *targetImageIn)=0
void CubicSplineImageGradient2D(nifti_image *sourceImage, nifti_image *resultGradientImage)
Definition: Transformation.cpp:698
void TransformImageAdjoint(nifti_image *sourceImage, nifti_image *sourceWeightsImage, nifti_image *warpedImage, nifti_image *warpedWeightsImage)
Definition: Transformation.cpp:108
void NearestNeighbourTransformImage3D(nifti_image *sourceImage, nifti_image *warpedImage)
Definition: Transformation.cpp:1150
PrecisionType GetPaddingValue()
Definition: Transformation.h:171
void NearestNeighbourTransformImageAdjoint3D(nifti_image *sourceImage, nifti_image *sourceWeightsImage, nifti_image *warpedImage, nifti_image *warpedWeightsImage)
Definition: Transformation.cpp:1823
virtual void ClearDeformationVectorFieldImage()
Definition: Transformation.cpp:904
virtual unsigned int GetNumberOfParameters()
Definition: Transformation.h:72
virtual PrecisionType * GetCopyOfParameters()=0
void BilinearImageGradient(nifti_image *sourceImage, nifti_image *resultGradientImage)
Definition: Transformation.cpp:419
bool CheckImageGeometryEquality(nifti_image *img1, nifti_image *img2)
Definition: Transformation.cpp:847
virtual void SetParameters(PrecisionType *paramsIn, bool parametersAreDisplacements)=0
void CubicSplineTransformImageAdjoint2D(nifti_image *sourceImage, nifti_image *sourceWeightsImage, nifti_image *warpedImage, nifti_image *warpedWeightsImage)
Definition: Transformation.cpp:1702
void CubicSplineImageGradient3D(nifti_image *sourceImage, nifti_image *resultGradientImage)
Definition: Transformation.cpp:543
void CubicSplineTransformImageAdjoint3D(nifti_image *sourceImage, nifti_image *sourceWeightsImage, nifti_image *warpedImage, nifti_image *warpedWeightsImage)
Definition: Transformation.cpp:1559
nifti_image * deformationVectorFieldImage
The deformation vector field image.
Definition: Transformation.h:218
PrecisionType warpedPaddingValue
Padding value for the warped image.
Definition: Transformation.h:217
virtual void DisplayTransformationParameters()=0
virtual PrecisionType * GetDVFGradientWRTTransformationParameters(nifti_image *denseDVFIn)=0
virtual std::vector< nifti_image * > GetTransformationAsImage()=0
void TrilinearTransformImage(nifti_image *sourceImage, nifti_image *warpedImage)
Definition: Transformation.cpp:1292
void NearestNeighbourTransformImage2D(nifti_image *sourceImage, nifti_image *warpedImage)
Definition: Transformation.cpp:1223
virtual PrecisionType * GetConstraintGradientWRTTransformationParameters()=0
void TrilinearImageGradient(nifti_image *sourceImage, nifti_image *resultGradientImage)
Definition: Transformation.cpp:224
virtual void GetImageGradientWRTDVF(nifti_image *sourceImage, nifti_image *outWarpedGradientImage)
Definition: Transformation.cpp:166
bool CheckDVFImageUpdateRequired(nifti_image *targetImageIn)
Definition: Transformation.cpp:815
virtual std::shared_ptr< Transformation > DeepCopy()=0
void CubicSplineTransformImage2D(nifti_image *sourceImage, nifti_image *warpedImage)
Definition: Transformation.cpp:1038
void TransformImage(nifti_image *sourceImage, nifti_image *warpedImage)
Definition: Transformation.cpp:35
void TrilinearTransformImageAdjoint(nifti_image *sourceImage, nifti_image *sourceWeightsImage, nifti_image *warpedImage, nifti_image *warpedWeightsImage)
Definition: Transformation.cpp:1969
void ReorientateVectorImage(nifti_image *vectorFieldToReorientate, mat44 reorientationMatrix)
Definition: Transformation.cpp:2218
void BilinearTransformImageAdjoint(nifti_image *sourceImage, nifti_image *sourceWeightsImage, nifti_image *warpedImage, nifti_image *warpedWeightsImage)
Definition: Transformation.cpp:2104
unsigned int numberOfParameters
The total number of parameters needed to describe the transformation.
Definition: Transformation.h:215
virtual void InitialiseLevel(unsigned int level)=0
virtual PrecisionType GetMaxTransformationParameterLength(PrecisionType *parametersIn)=0
void NearestNeighbourTransformImageAdjoint2D(nifti_image *sourceImage, nifti_image *sourceWeightsImage, nifti_image *warpedImage, nifti_image *warpedWeightsImage)
Definition: Transformation.cpp:1896