forked from InsightSoftwareConsortium/ITKWikiExamples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImageFilterMultipleOutputs.txx
122 lines (98 loc) · 2.58 KB
/
ImageFilterMultipleOutputs.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
113
114
115
116
117
118
119
120
121
122
#ifndef __itkImageFilterMultipleOutputs_txx
#define __itkImageFilterMultipleOutputs_txx
#include "ImageFilterMultipleOutputs.h"
#include "itkObjectFactory.h"
#include "itkImageRegionIterator.h"
#include "itkImageRegionConstIterator.h"
namespace itk
{
template< class TImage>
ImageFilterMultipleOutputs<TImage>::ImageFilterMultipleOutputs()
{
this->SetNumberOfRequiredOutputs(2);
this->SetNumberOfRequiredInputs(0);
this->SetNthOutput( 0, this->MakeOutput(0) );
this->SetNthOutput( 1, this->MakeOutput(1) );
}
template< class TImage>
void ImageFilterMultipleOutputs<TImage>::GenerateData()
{
typename TImage::IndexType start;
start[0] = 0;
start[1] = 0;
typename TImage::SizeType size;
size[0] = 20;
size[1] = 20;
typename TImage::RegionType region;
region.SetSize(size);
region.SetIndex(start);
// Setup output 1
typename TImage::Pointer output1 = this->GetOutput1();
output1->SetRegions(region);
output1->Allocate();
itk::ImageRegionIterator<TImage> outputIterator1(output1, output1->GetLargestPossibleRegion());
outputIterator1.GoToBegin();
while(!outputIterator1.IsAtEnd())
{
if(outputIterator1.GetIndex()[0] == outputIterator1.GetIndex()[1])
{
outputIterator1.Set(255);
}
else
{
outputIterator1.Set(0);
}
++outputIterator1;
}
// Setup output 2
typename TImage::Pointer output2 = this->GetOutput2();
output2->SetRegions(region);
output2->Allocate();
itk::ImageRegionIterator<TImage> outputIterator2(output2, output2->GetLargestPossibleRegion());
outputIterator2.GoToBegin();
while(!outputIterator2.IsAtEnd())
{
if(outputIterator2.GetIndex()[0] > 10)
{
outputIterator2.Set(255);
}
else
{
outputIterator2.Set(0);
}
++outputIterator2;
}
}
template< class TImage>
DataObject::Pointer ImageFilterMultipleOutputs<TImage>::MakeOutput(unsigned int idx)
{
DataObject::Pointer output;
switch ( idx )
{
case 0:
output = ( TImage::New() ).GetPointer();
break;
case 1:
output = ( TImage::New() ).GetPointer();
break;
default:
std::cerr << "No output " << idx << std::endl;
output = NULL;
break;
}
return output.GetPointer();
}
template< class TImage>
TImage* ImageFilterMultipleOutputs<TImage>::GetOutput1()
{
return dynamic_cast< TImage * >(
this->ProcessObject::GetOutput(0) );
}
template< class TImage>
TImage* ImageFilterMultipleOutputs<TImage>::GetOutput2()
{
return dynamic_cast< TImage * >(
this->ProcessObject::GetOutput(1) );
}
}// end namespace
#endif