-
Notifications
You must be signed in to change notification settings - Fork 6
/
pctZengBackProjectionImageFilter.txx
112 lines (100 loc) · 3.55 KB
/
pctZengBackProjectionImageFilter.txx
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
#ifndef __pctZengBackProjectionImageFilter_txx
#define __pctZengBackProjectionImageFilter_txx
#include <itkImageRegionConstIteratorWithIndex.h>
#include <itkMacro.h>
#include <itkImageRegionIteratorWithIndex.h>
namespace pct
{
template <class TInputImage, class TOutputImage>
ZengBackProjectionImageFilter<TInputImage, TOutputImage>
::ZengBackProjectionImageFilter()
{
this->SetNumberOfRequiredOutputs(2);
this->SetNthOutput( 0, this->MakeOutput(0) );
this->SetNthOutput( 1, this->MakeOutput(1) );
}
template <class TInputImage, class TOutputImage>
void
ZengBackProjectionImageFilter<TInputImage, TOutputImage>
::GenerateOutputInformation()
{
typename OutputImageType::RegionType region;
typename OutputImageType::PointType origin;
typename OutputImageType::SpacingType spacing;
for(unsigned int i=0; i<TOutputImage::ImageDimension; i++)
{
region.SetIndex(i, this->GetInput()->GetLargestPossibleRegion().GetIndex(i));
region.SetSize(i, this->GetInput()->GetLargestPossibleRegion().GetSize(i));
spacing[i] = this->GetInput()->GetSpacing()[i];
origin[i] = this->GetInput()->GetOrigin()[i];
}
for(unsigned int i=0; i<this->GetNumberOfRequiredOutputs(); i++)
{
this->GetOutput(i)->SetSpacing(spacing);
this->GetOutput(i)->SetOrigin(origin);
this->GetOutput(i)->SetRegions(region);
}
}
template <class TInputImage, class TOutputImage>
void
ZengBackProjectionImageFilter<TInputImage, TOutputImage>
::DynamicThreadedGenerateData(const OutputImageRegionType& outputRegionForThread)
{
typename TInputImage::IndexType idxIn;
for(unsigned int i=0; i<TOutputImage::ImageDimension; i++)
idxIn[i] = outputRegionForThread.GetIndex(i);
idxIn[TOutputImage::ImageDimension] = 0;
const typename TInputImage::PixelType *pIn = this->GetInput()->GetBufferPointer() + this->GetInput()->ComputeOffset(idxIn);
typename OutputImageRegionType::SizeValueType npix = this->GetOutput()->GetLargestPossibleRegion().GetNumberOfPixels();
// Input / ouput iterators
itk::ImageRegionIterator<OutputImageType> itOutC(this->GetOutput(0), outputRegionForThread);
itk::ImageRegionIterator<OutputImageType> itOutS(this->GetOutput(1), outputRegionForThread);
double angspac = itk::Math::pi / this->GetInput()->GetLargestPossibleRegion().GetSize(TInputImage::ImageDimension-1);
const double phi = 0.;
while(!itOutC.IsAtEnd())
{
double ang = angspac * 0.5 + itk::Math::pi_over_2;
double vs = 0.;
double vc = 0.;
const typename TInputImage::PixelType *pInCurr = pIn;
for(unsigned int i=0; i<this->GetInput()->GetLargestPossibleRegion().GetSize(TInputImage::ImageDimension-1); i++)
{
while(ang>itk::Math::pi) ang -= itk::Math::pi;
double sign = 1.;
if(sin(ang-phi)<0.)
sign = -1.;
vs += sin(ang) * (*pInCurr) * sign;
vc += cos(ang) * (*pInCurr) * sign;
ang += angspac;
pInCurr += npix;
}
itOutC.Set(vc * angspac);
itOutS.Set(-1. * vs * angspac);
++itOutC;
++itOutS;
++pIn;
}
}
template <class TInputImage, class TOutputImage>
itk::DataObject::Pointer
ZengBackProjectionImageFilter<TInputImage, TOutputImage>
::MakeOutput(itk::ProcessObject::DataObjectPointerArraySizeType idx)
{
itk::DataObject::Pointer output;
switch ( idx )
{
case 0:
output = ( TOutputImage::New() ).GetPointer();
break;
case 1:
output = ( TOutputImage::New() ).GetPointer();
break;
default:
std::cerr << "No output " << idx << std::endl;
output = NULL;
break;
}
return output.GetPointer();
}
} // end namespace pct
#endif