-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathitkTransformDeformationFieldFilter.hxx
145 lines (130 loc) · 4.27 KB
/
itkTransformDeformationFieldFilter.hxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#ifndef __TransformDeformationFieldFilter_hxx
#define __TransformDeformationFieldFilter_hxx
#include "itkTransformDeformationFieldFilter.h"
namespace itk
{
template <class TInput, class TOutput, int NDimensions>
TransformDeformationFieldFilter<TInput, TOutput, NDimensions>
::TransformDeformationFieldFilter()
{
this->SetNumberOfRequiredInputs( 1 );
}
template <class TInput, class TOutput, int NDimensions>
unsigned long
TransformDeformationFieldFilter<TInput, TOutput, NDimensions>
::GetMTime() const
{
unsigned long latestTime = Object::GetMTime();
if( m_Transform.IsNotNull() )
{
if( latestTime < m_Transform->GetMTime() )
{
latestTime = m_Transform->GetMTime();
}
}
return latestTime;
}
template <class TInput, class TOutput, int NDimensions>
void
TransformDeformationFieldFilter<TInput, TOutput, NDimensions>
::BeforeThreadedGenerateData()
{
if( m_Transform.IsNull() )
{
itkExceptionMacro( << "Transform not set" );
}
if( !this->GetInput( 0 ) )
{
itkExceptionMacro( << "Input deformation field not set" );
}
}
template <class TInput, class TOutput, int NDimensions>
void
TransformDeformationFieldFilter<TInput, TOutput, NDimensions>
::SetInput( InputDeformationFieldPointerType inputImage )
{
this->Superclass::SetInput( 0, inputImage );
}
template <class TInput, class TOutput, int NDimensions>
void
TransformDeformationFieldFilter<TInput, TOutput, NDimensions>
::ThreadedGenerateData( const OutputImageRegionType & outputRegionForThread,
ThreadIdType threadId )
{
OutputDeformationFieldPointerType outputImagePtr = this->GetOutput( 0 );
InputIteratorType it( this->GetInput( 0 ), outputRegionForThread );
OutputIteratorType out( outputImagePtr, outputRegionForThread );
itk::Index<NDimensions> index;
itk::Point<double, NDimensions> point;
itk::Point<double, NDimensions> tempPoint;
itk::Point<double, NDimensions> outputPoint;
for( it.GoToBegin(), out.GoToBegin(); !it.IsAtEnd(); ++it, ++out )
{
index = it.GetIndex();
InputDeformationPixelType vector = it.Get();
this->GetInput( 0 )->TransformIndexToPhysicalPoint( index, point );
for( int i = 0; i < NDimensions; i++ )
{
tempPoint[i] = point[i] + static_cast<double>( vector[i] );
}
outputPoint = m_Transform->TransformPoint( tempPoint );
OutputDeformationPixelType outputVector;
for( int i = 0; i < NDimensions; i++ )
{
outputVector[i] = static_cast<OutputDataType>( outputPoint[i] - point[i] );
}
out.Set( outputVector );
}
}
/**
* Inform pipeline of required output region
*/
template <class TInput, class TOutput, int NDimensions>
void
TransformDeformationFieldFilter<TInput, TOutput, NDimensions>
::GenerateOutputInformation()
{
// call the superclass' implementation of this method
Superclass::GenerateOutputInformation();
// get pointers to the input and output
OutputDeformationFieldPointerType outputPtr = this->GetOutput( 0 );
if( !outputPtr )
{
return;
}
outputPtr->SetSpacing( this->GetInput( 0 )->GetSpacing() );
outputPtr->SetOrigin( this->GetInput( 0 )->GetOrigin() );
outputPtr->SetDirection( this->GetInput( 0 )->GetDirection() );
// Set the size of the output region
outputPtr->SetRegions( this->GetInput( 0 )->GetLargestPossibleRegion() );
return;
}
/**
* Inform pipeline of necessary input image region
*
* Determining the actual input region is non-trivial, especially
* when we cannot assume anything about the transform being used.
* So we do the easy thing and request the entire input image.
*/
template <class TInput, class TOutput, int NDimensions>
void
TransformDeformationFieldFilter<TInput, TOutput, NDimensions>
::GenerateInputRequestedRegion()
{
// call the superclass's implementation of this method
Superclass::GenerateInputRequestedRegion();
if( !this->GetInput() )
{
return;
}
// get pointers to the input and output
InputDeformationFieldPointerType inputPtr =
const_cast<InputDeformationFieldType *>( this->GetInput() );
// Request the entire input image
typename InputDeformationFieldType::RegionType inputRegion;
inputRegion = inputPtr->GetLargestPossibleRegion();
inputPtr->SetRequestedRegion( inputRegion );
return;
}
} // end namespace itk
#endif