1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkImageIterator.txx
5 
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10      This software is distributed WITHOUT ANY WARRANTY; without even
11      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12      PURPOSE.  See the above copyright notice for more information.
13 
14 =========================================================================*/
15 // Include blockers needed since vtkImageIterator.h includes this file
16 // when VTK_NO_EXPLICIT_TEMPLATE_INSTANTIATION is defined.
17 
18 #ifndef vtkImageIterator_txx
19 #define vtkImageIterator_txx
20 
21 #include "vtkImageIterator.h"
22 #include "vtkImageData.h"
23 
24 //----------------------------------------------------------------------------
25 template <class DType>
vtkImageIterator()26 vtkImageIterator<DType>::vtkImageIterator()
27 {
28   this->Pointer = 0;
29   this->EndPointer = 0;
30   this->SpanEndPointer = 0;
31   this->SliceEndPointer = 0;
32 }
33 
34 //----------------------------------------------------------------------------
35 template <class DType>
Initialize(vtkImageData * id,int * ext)36 void vtkImageIterator<DType>::Initialize(vtkImageData *id, int *ext)
37 {
38   this->Pointer = static_cast<DType *>(id->GetScalarPointerForExtent(ext));
39   id->GetIncrements(this->Increments[0], this->Increments[1],
40                     this->Increments[2]);
41   id->GetContinuousIncrements(ext,this->ContinuousIncrements[0],
42                               this->ContinuousIncrements[1],
43                               this->ContinuousIncrements[2]);
44   this->EndPointer =
45     static_cast<DType *>(id->GetScalarPointer(ext[1],ext[3],ext[5]))
46     +this->Increments[0];
47 
48   // if the extent is empty then the end pointer should equal the beg pointer
49   if (ext[1] < ext[0] || ext[3] < ext[2] || ext[5] < ext[4])
50     {
51     this->EndPointer = this->Pointer;
52     }
53 
54   this->SpanEndPointer =
55     this->Pointer + this->Increments[0]*(ext[1] - ext[0] + 1);
56   this->SliceEndPointer =
57     this->Pointer + this->Increments[1]*(ext[3] - ext[2] + 1);
58 }
59 
60 //----------------------------------------------------------------------------
61 template <class DType>
vtkImageIterator(vtkImageData * id,int * ext)62 vtkImageIterator<DType>::vtkImageIterator(vtkImageData *id, int *ext)
63 {
64   this->Initialize(id, ext);
65 }
66 
67 
68 //----------------------------------------------------------------------------
69 template <class DType>
NextSpan()70 void vtkImageIterator<DType>::NextSpan()
71 {
72   this->Pointer += this->Increments[1];
73   this->SpanEndPointer += this->Increments[1];
74   if (this->Pointer >= this->SliceEndPointer)
75     {
76     this->Pointer += this->ContinuousIncrements[2];
77     this->SpanEndPointer += this->ContinuousIncrements[2];
78     this->SliceEndPointer += this->Increments[2];
79     }
80 }
81 
82 #endif
83