forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtkImagePointIterator.h
162 lines (143 loc) · 4.44 KB
/
vtkImagePointIterator.h
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*=========================================================================
Program: Visualization Toolkit
Module: vtkImagePointIterator.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/**
* @class vtkImagePointIterator
* @brief iterate over all data points in an image.
*
* This class will iterate over an image. For each position, it provides
* the (x,y,z) position, the (I,J,K) index, and the point Id. If a stencil
* is provided, then it also reports, for each point, whether the point is
* inside the stencil.
* <p>The iterator can go through the image point-by-point or span-by-span.
* The Next() method advances to the next point, while the NextSpan() method
* skips to the beginning of the next span, where a span is defined as a
* start position and point count within an image row.
* @sa
* vtkImageData vtkImageStencilData vtkImageProgressIterator
*/
#ifndef vtkImagePointIterator_h
#define vtkImagePointIterator_h
#include "vtkImagePointDataIterator.h"
class VTKIMAGINGCORE_EXPORT vtkImagePointIterator :
public vtkImagePointDataIterator
{
public:
/**
* Default constructor, its use must be followed by Initialize().
*/
vtkImagePointIterator();
/**
* Create an iterator for the given image, with several options.
* If a stencil is provided, then the iterator's IsInStencil() method
* reports whether each span is inside the stencil. If an extent is
* provided, it iterates over the extent and ignores the rest of the
* image (the provided extent must be within the image extent). If
* a pointer to the algorithm is provided, then progress events will
* provided by the algorithm if threadId is zero.
*/
vtkImagePointIterator(vtkImageData *image,
const int extent[6] = 0,
vtkImageStencilData *stencil=0,
vtkAlgorithm *algorithm=0,
int threadId=0);
/**
* Initialize an iterator. See constructor for more details.
*/
void Initialize(vtkImageData *image,
const int extent[6] = 0,
vtkImageStencilData *stencil=0,
vtkAlgorithm *algorithm=0,
int threadId=0);
//@{
/**
* Move the iterator to the beginning of the next span.
* A span is a contiguous region of the image over which nothing but
* the point Id and the X index changes.
*/
void NextSpan()
{
this->vtkImagePointDataIterator::NextSpan();
this->UpdatePosition();
}
//@}
//@{
/**
* Move to the next position (rather than directly to the next span).
* This will automatically advance to the next span if the end of the
* current span is reached.
*/
void Next()
{
if (++(this->Id) == this->SpanEnd)
{
this->NextSpan();
}
else
{
this->Index[0]++;
this->Position[0] = this->Origin[0] + this->Index[0]*this->Spacing[0];
}
}
//@}
/**
* Test if the iterator has completed iterating over the entire extent.
*/
bool IsAtEnd()
{
return this->vtkImagePointDataIterator::IsAtEnd();
}
/**
* Get the current position.
*/
double *GetPosition()
{
return this->Position;
}
//@{
/**
* Get the current position and place it in the provided array.
*/
void GetPosition(double x[3])
{
x[0] = this->Position[0];
x[1] = this->Position[1];
x[2] = this->Position[2];
}
//@}
//@{
/**
* Get the current position and place it in the provided array.
*/
void GetPosition(float x[3])
{
x[0] = this->Position[0];
x[1] = this->Position[1];
x[2] = this->Position[2];
}
//@}
protected:
//@{
/**
* Helper method to update the position coordinate from the index.
*/
void UpdatePosition()
{
this->Position[0] = this->Origin[0] + this->Index[0]*this->Spacing[0];
this->Position[1] = this->Origin[1] + this->Index[1]*this->Spacing[1];
this->Position[2] = this->Origin[2] + this->Index[2]*this->Spacing[2];
}
//@}
double Origin[3];
double Spacing[3];
double Position[3];
};
#endif
// VTK-HeaderTest-Exclude: vtkImagePointIterator.h