KWStyle - itkImageRegionExclusionConstIteratorWithIndex.txx
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkImageRegionExclusionConstIteratorWithIndex.txx.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:39 $
7   Version:   $Revision: 1.4 $
8
9   Copyright (c) Insight Software Consortium. All rights reserved.
10   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11
12      This software is distributed WITHOUT ANY WARRANTY; without even 
13      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14      PURPOSE.  See the above copyright notices for more information.
15
16 =========================================================================*/
17 DEF #ifndef _itkImageRegionExclusionConstIteratorWithIndex_txx
18 DEF #define _itkImageRegionExclusionConstIteratorWithIndex_txx
19
20 #include "itkImageRegionExclusionConstIteratorWithIndex.h"
21
22 namespace itk
23 {
24   
25
26    
27 //----------------------------------------------------------------------
28 //  Set the region to exclude from the walk
29 //----------------------------------------------------------------------
30 template<class TImage>
31 void
32 ImageRegionExclusionConstIteratorWithIndex<TImage>
33 ::SetExclusionRegion( const RegionType & region )
34 {
35   
36   if( !this->m_Region.IsInside( region ) )
37     {
38 LEN     itkGenericExceptionMacro(<< "Attempt to set a exclusion region that is NOT contained inside the iterator region");
39     }
40   m_ExclusionRegion      = region;
41   m_ExclusionBegin       = m_ExclusionRegion.GetIndex();
42   SizeType exclusionSize = m_ExclusionRegion.GetSize();
43   
44   for(unsigned int i=0; i<TImage::ImageDimension; ++i)
45     {
46     m_ExclusionEnd[i] = m_ExclusionBegin[i] + exclusionSize[i];
47     }
48
49 }
50
51  
52 //----------------------------------------------------------------------
53 //  Set the region to exclude from the walk to a region that is inset
54 //  one pixel from the boundary of the region
55 //----------------------------------------------------------------------
56 template<class TImage>
57 void
58 ImageRegionExclusionConstIteratorWithIndex<TImage>
59 ::SetExclusionRegionToInsetRegion()
60 {
61   RegionType excludeRegion;
62   excludeRegion = this->m_Region;
63   for (unsigned int i=0; i < TImage::ImageDimension; ++i)
64     {
65     if ( excludeRegion.GetSize()[i] >= 2 )
66       {
67       // region is large enough to inset, adjust size and index
68       excludeRegion.SetSize( i, excludeRegion.GetSize()[i] - 2);
69       excludeRegion.SetIndex( i, excludeRegion.GetIndex()[i] + 1);
70       }
71     else
72       {
73       // region is not large enough to inset, set exclusion size to
74       // zero and keep the index the same.
75       excludeRegion.SetSize( i, 0 );
76       }
77     }
78   this->SetExclusionRegion( excludeRegion );
79 }
80
81 //----------------------------------------------------------------------
82 //  Advance along the line
83 //----------------------------------------------------------------------
84 template<class TImage>
85 ImageRegionExclusionConstIteratorWithIndex<TImage> &
86 ImageRegionExclusionConstIteratorWithIndex<TImage>
87 ::operator++()
88 {
89   
90   this->m_Remaining = false;
91   for( unsigned int in=0; in<TImage::ImageDimension; in++ )
92     {
93     this->m_PositionIndex[ in  ]++;
94     
95     // if entering the exclusion region... jump over it
96     if( m_ExclusionRegion.IsInside( this->m_PositionIndex ) )
97       {
98       this->m_PositionIndex[ in ]  = m_ExclusionEnd[ in ];
99       this->m_Position      += this->m_OffsetTable[in] * 
100 IND ********m_ExclusionRegion.GetSize()[ in ];
101       }
102
103     if( this->m_PositionIndex[ in ] < this->m_EndIndex[ in ] )
104       {
105       this->m_Position += this->m_OffsetTable[in];
106       this->m_Remaining = true;
107       break;
108       }
109     else 
110       {
111 LEN       this->m_Position -= this->m_OffsetTable[ in ] * ( static_cast<long>(this->m_Region.GetSize()[in])-1 );
112       this->m_PositionIndex[ in ] = this->m_BeginIndex[ in ]; 
113       }
114     }
115
116   if( !this->m_Remaining ) // It will not advance here otherwise
117     {
118     this->m_Position = this->m_End;
119     }
120
121   return *this;
122 }
123
124
125 //----------------------------------------------------------------------
126 //  Advance along the line in reverse direction
127 //----------------------------------------------------------------------
128 template<class TImage>
129 ImageRegionExclusionConstIteratorWithIndex<TImage> &
130 ImageRegionExclusionConstIteratorWithIndex<TImage>
131 ::operator--()
132 {
133   
134   this->m_Remaining = false;
135   for( unsigned int in=0; in<TImage::ImageDimension; in++ )
136     {
137       
138     if( this->m_PositionIndex[ in ] > this->m_BeginIndex[ in ] )
139       {
140
141       this->m_PositionIndex[ in  ]--;
142       this->m_Position -= this->m_OffsetTable[in];
143
144       // if entering the exclusion region... jump over it
145       if( m_ExclusionRegion.IsInside( this->m_PositionIndex ) )
146         {
147         this->m_PositionIndex[ in ]  = m_ExclusionBegin[ in ]-1;
148 LEN         this->m_Position      -= this->m_OffsetTable[in] * m_ExclusionRegion.GetSize()[ in ];
149         }
150
151       this->m_Remaining = true;
152       break;
153       }
154     else 
155       {
156       this->m_PositionIndex[ in  ]--;
157 LEN       this->m_Position += this->m_OffsetTable[ in ] * ( static_cast<long>(this->m_Region.GetSize()[in])-1 );
158       this->m_PositionIndex[ in ] = this->m_EndIndex[ in ] - 1; 
159       }
160
161     }
162
163   if( !this->m_Remaining ) // It will not advance here otherwise
164     {
165     this->m_Position = this->m_End;
166     }
167
168   return *this;
169 }
170
171 // end namespace itk
172
173 #endif
174

Generated by KWStyle 1.0b on Tuesday January,17 at 02:14:14PM
© Kitware Inc.