0
# Core Data Structures
1
2
ITK's core data structures provide the foundation for all medical image analysis operations. These classes handle n-dimensional images, geometric primitives, and region specifications with full template-based type safety.
3
4
## Image Classes
5
6
### Image
7
8
The primary data structure for storing n-dimensional pixel data.
9
10
```cpp { .api }
11
template<typename TPixel, unsigned int VDimension>
12
class Image : public ImageBase<VDimension>
13
{
14
public:
15
typedef Image Self;
16
typedef ImageBase<VDimension> Superclass;
17
typedef SmartPointer<Self> Pointer;
18
typedef SmartPointer<const Self> ConstPointer;
19
20
// Creation
21
static Pointer New();
22
23
// Pixel access
24
const TPixel & GetPixel(const IndexType & index) const;
25
void SetPixel(const IndexType & index, const TPixel & value);
26
TPixel & GetPixel(const IndexType & index);
27
28
// Memory management
29
void Allocate();
30
void FillBuffer(const TPixel & value);
31
32
// Container access
33
TPixel * GetBufferPointer();
34
const TPixel * GetBufferPointer() const;
35
36
// Region management
37
void SetRegions(const SizeType & size);
38
void SetRegions(const RegionType & region);
39
const RegionType & GetRequestedRegion() const;
40
const RegionType & GetLargestPossibleRegion() const;
41
};
42
```
43
44
### ImageBase
45
46
Abstract base class providing geometric information for images.
47
48
```cpp { .api }
49
template<unsigned int VDimension>
50
class ImageBase : public DataObject
51
{
52
public:
53
typedef ImageBase Self;
54
typedef DataObject Superclass;
55
typedef SmartPointer<Self> Pointer;
56
typedef SmartPointer<const Self> ConstPointer;
57
58
// Geometric properties
59
virtual void SetOrigin(const PointType & origin);
60
virtual const PointType & GetOrigin() const;
61
62
virtual void SetSpacing(const SpacingType & spacing);
63
virtual const SpacingType & GetSpacing() const;
64
65
virtual void SetDirection(const DirectionType & direction);
66
virtual const DirectionType & GetDirection() const;
67
68
// Coordinate transformations
69
template<typename TCoordinate>
70
void TransformPhysicalPointToIndex(const Point<TCoordinate, VDimension> & point,
71
IndexType & index) const;
72
73
template<typename TCoordinate>
74
void TransformIndexToPhysicalPoint(const IndexType & index,
75
Point<TCoordinate, VDimension> & point) const;
76
77
// Region management
78
virtual void SetRegions(const RegionType & region);
79
virtual const RegionType & GetLargestPossibleRegion() const;
80
};
81
```
82
83
### VectorImage
84
85
Image class for variable-length pixel vectors.
86
87
```cpp { .api }
88
template<typename TPixel, unsigned int VDimension>
89
class VectorImage : public ImageBase<VDimension>
90
{
91
public:
92
typedef VectorImage Self;
93
typedef ImageBase<VDimension> Superclass;
94
typedef SmartPointer<Self> Pointer;
95
typedef SmartPointer<const Self> ConstPointer;
96
97
// Vector-specific methods
98
void SetNumberOfComponentsPerPixel(unsigned int n);
99
unsigned int GetNumberOfComponentsPerPixel() const;
100
101
// Pixel access
102
const PixelType & GetPixel(const IndexType & index) const;
103
void SetPixel(const IndexType & index, const PixelType & value);
104
105
// Component access
106
const InternalPixelType & GetPixelComponent(const IndexType & index,
107
unsigned int component) const;
108
void SetPixelComponent(const IndexType & index, unsigned int component,
109
const InternalPixelType & value);
110
};
111
```
112
113
## Geometric Primitives
114
115
### Point
116
117
N-dimensional point representation.
118
119
```cpp { .api }
120
template<typename T, unsigned int VDimension>
121
class Point : public FixedArray<T, VDimension>
122
{
123
public:
124
typedef Point Self;
125
typedef FixedArray<T, VDimension> Superclass;
126
127
// Constructors
128
Point();
129
Point(const ValueType & value);
130
Point(const ValueType values[VDimension]);
131
132
// Arithmetic operations
133
VectorType operator-(const Self & point) const;
134
Self operator+(const VectorType & vector) const;
135
Self operator-(const VectorType & vector) const;
136
137
// Distance calculations
138
RealType EuclideanDistanceTo(const Self & point) const;
139
RealType SquaredEuclideanDistanceTo(const Self & point) const;
140
141
// Array access
142
ValueType & operator[](unsigned int index);
143
const ValueType & operator[](unsigned int index) const;
144
};
145
```
146
147
### Vector
148
149
N-dimensional vector representation.
150
151
```cpp { .api }
152
template<typename T, unsigned int VDimension>
153
class Vector : public FixedArray<T, VDimension>
154
{
155
public:
156
typedef Vector Self;
157
typedef FixedArray<T, VDimension> Superclass;
158
159
// Constructors
160
Vector();
161
Vector(const ValueType & value);
162
Vector(const ValueType values[VDimension]);
163
164
// Vector operations
165
Self operator+(const Self & vector) const;
166
Self operator-(const Self & vector) const;
167
Self operator*(const ValueType & scalar) const;
168
Self operator/(const ValueType & scalar) const;
169
170
// Geometric operations
171
RealType GetNorm() const;
172
RealType GetSquaredNorm() const;
173
RealType Normalize();
174
175
// Dot product
176
ValueType operator*(const Self & vector) const;
177
};
178
```
179
180
### CovariantVector
181
182
Vector that transforms covariantly under coordinate transformations.
183
184
```cpp { .api }
185
template<typename T, unsigned int VDimension>
186
class CovariantVector : public FixedArray<T, VDimension>
187
{
188
public:
189
typedef CovariantVector Self;
190
typedef FixedArray<T, VDimension> Superclass;
191
192
// Vector operations
193
Self operator+(const Self & vector) const;
194
Self operator-(const Self & vector) const;
195
Self operator*(const ValueType & scalar) const;
196
197
// Geometric operations
198
RealType GetNorm() const;
199
RealType Normalize();
200
201
// Dot products with regular vectors
202
ValueType operator*(const Vector<T, VDimension> & vector) const;
203
};
204
```
205
206
## Index and Size Types
207
208
### Index
209
210
N-dimensional index for discrete grid positions.
211
212
```cpp { .api }
213
template<unsigned int VDimension>
214
class Index : public FixedArray<IndexValueType, VDimension>
215
{
216
public:
217
typedef Index Self;
218
typedef FixedArray<IndexValueType, VDimension> Superclass;
219
220
// Constructors
221
Index();
222
Index(const IndexValueType value[VDimension]);
223
Index(const IndexValueType & value);
224
225
// Arithmetic operations
226
const Self operator+(const OffsetType & offset) const;
227
const Self operator-(const OffsetType & offset) const;
228
const OffsetType operator-(const Self & index) const;
229
230
// Element access
231
IndexValueType & operator[](unsigned int index);
232
const IndexValueType & operator[](unsigned int index) const;
233
234
// Utilities
235
void Fill(IndexValueType value);
236
static unsigned int GetIndexDimension();
237
};
238
```
239
240
### Size
241
242
N-dimensional size specification.
243
244
```cpp { .api }
245
template<unsigned int VDimension>
246
struct Size : public FixedArray<SizeValueType, VDimension>
247
{
248
public:
249
typedef Size Self;
250
typedef FixedArray<SizeValueType, VDimension> Superclass;
251
252
// Constructors
253
Size();
254
Size(const SizeValueType value[VDimension]);
255
Size(const SizeValueType & value);
256
257
// Element access
258
SizeValueType & operator[](unsigned int index);
259
const SizeValueType & operator[](unsigned int index) const;
260
261
// Utilities
262
void Fill(SizeValueType value);
263
static unsigned int GetSizeDimension();
264
};
265
```
266
267
### Offset
268
269
N-dimensional offset for relative positioning.
270
271
```cpp { .api }
272
template<unsigned int VDimension>
273
class Offset : public FixedArray<OffsetValueType, VDimension>
274
{
275
public:
276
typedef Offset Self;
277
typedef FixedArray<OffsetValueType, VDimension> Superclass;
278
279
// Arithmetic operations
280
const Self operator+(const Self & offset) const;
281
const Self operator-(const Self & offset) const;
282
Self & operator+=(const Self & offset);
283
Self & operator-=(const Self & offset);
284
285
// Element access
286
OffsetValueType & operator[](unsigned int index);
287
const OffsetValueType & operator[](unsigned int index) const;
288
};
289
```
290
291
## Region Specification
292
293
### ImageRegion
294
295
Defines a rectangular region within an image.
296
297
```cpp { .api }
298
template<unsigned int VDimension>
299
class ImageRegion
300
{
301
public:
302
typedef ImageRegion Self;
303
typedef IndexType IndexType;
304
typedef SizeType SizeType;
305
306
// Constructors
307
ImageRegion();
308
ImageRegion(const IndexType & index, const SizeType & size);
309
ImageRegion(const SizeType & size);
310
311
// Region properties
312
void SetIndex(const IndexType & index);
313
const IndexType & GetIndex() const;
314
IndexType & GetModifiableIndex();
315
316
void SetSize(const SizeType & size);
317
const SizeType & GetSize() const;
318
SizeType & GetModifiableSize();
319
320
// Computed properties
321
IndexType GetUpperIndex() const;
322
SizeValueType GetNumberOfPixels() const;
323
324
// Region operations
325
void Crop(const Self & region);
326
bool IsInside(const IndexType & index) const;
327
bool IsInside(const Self & region) const;
328
329
// Comparison
330
bool operator==(const Self & region) const;
331
bool operator!=(const Self & region) const;
332
};
333
```
334
335
## Pixel Types
336
337
### RGBPixel
338
339
RGB color pixel representation.
340
341
```cpp { .api }
342
template<typename TComponent>
343
class RGBPixel : public FixedArray<TComponent, 3>
344
{
345
public:
346
typedef RGBPixel Self;
347
typedef FixedArray<TComponent, 3> Superclass;
348
349
// Color component access
350
void SetRed(ComponentType red);
351
ComponentType GetRed() const;
352
353
void SetGreen(ComponentType green);
354
ComponentType GetGreen() const;
355
356
void SetBlue(ComponentType blue);
357
ComponentType GetBlue() const;
358
359
// Luminance calculation
360
ComponentType GetLuminance() const;
361
};
362
```
363
364
### RGBAPixel
365
366
RGBA color pixel with alpha channel.
367
368
```cpp { .api }
369
template<typename TComponent>
370
class RGBAPixel : public FixedArray<TComponent, 4>
371
{
372
public:
373
typedef RGBAPixel Self;
374
typedef FixedArray<TComponent, 4> Superclass;
375
376
// Color component access
377
void SetRed(ComponentType red);
378
ComponentType GetRed() const;
379
380
void SetGreen(ComponentType green);
381
ComponentType GetGreen() const;
382
383
void SetBlue(ComponentType blue);
384
ComponentType GetBlue() const;
385
386
void SetAlpha(ComponentType alpha);
387
ComponentType GetAlpha() const;
388
};
389
```
390
391
## Type Definitions
392
393
```cpp { .api }
394
// Standard typedefs
395
typedef long IndexValueType;
396
typedef unsigned long SizeValueType;
397
typedef signed long OffsetValueType;
398
typedef double SpacePrecisionType;
399
typedef float FloatOffsetPrecisionType;
400
401
// Common instantiations
402
typedef Image<unsigned char, 2> UCharImage2D;
403
typedef Image<unsigned char, 3> UCharImage3D;
404
typedef Image<short, 2> ShortImage2D;
405
typedef Image<short, 3> ShortImage3D;
406
typedef Image<float, 2> FloatImage2D;
407
typedef Image<float, 3> FloatImage3D;
408
typedef Image<double, 2> DoubleImage2D;
409
typedef Image<double, 3> DoubleImage3D;
410
411
// Point and vector types
412
typedef Point<double, 2> Point2D;
413
typedef Point<double, 3> Point3D;
414
typedef Vector<double, 2> Vector2D;
415
typedef Vector<double, 3> Vector3D;
416
417
// Index and size types
418
typedef Index<2> Index2D;
419
typedef Index<3> Index3D;
420
typedef Size<2> Size2D;
421
typedef Size<3> Size3D;
422
typedef ImageRegion<2> Region2D;
423
typedef ImageRegion<3> Region3D;
424
```
425
426
These core data structures form the foundation of all ITK operations, providing type-safe, efficient representations for medical image data and associated geometric information.