ITK  4.3.0
Insight Segmentation and Registration Toolkit
itkConstNeighborhoodIteratorWithOnlyIndex.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkConstNeighborhoodIteratorWithOnlyIndex_h
19 #define __itkConstNeighborhoodIteratorWithOnlyIndex_h
20 
21 #include <vector>
22 #include <cstring>
23 #include <iostream>
24 #include "itkImage.h"
25 #include "itkNeighborhood.h"
26 #include "itkMacro.h"
27 
28 namespace itk
29 {
59 template< class TImage >
61  public Neighborhood< char, TImage::ImageDimension >
62 {
63 public:
64 
66  typedef unsigned int DimensionValueType;
67 
69  itkStaticConstMacro(Dimension, DimensionValueType, TImage::ImageDimension);
70 
72 
76 
79  typedef typename Superclass::RadiusType RadiusType;
80  typedef typename Superclass::SizeType SizeType;
81  typedef typename Superclass::Iterator Iterator;
83 
85  typedef TImage ImageType;
86  typedef typename TImage::RegionType RegionType;
90 
93 
96 
99 
102 
105  ConstNeighborhoodIteratorWithOnlyIndex(const SizeType & radius, const ImageType *ptr, const RegionType & region);
106 
108  Self & operator=(const Self & orig);
109 
111  virtual void PrintSelf(std::ostream &, Indent) const;
112 
115  OffsetType ComputeInternalIndex(NeighborIndexType n) const;
116 
118  IndexType GetBound() const
119  {
120  return m_Bound;
121  }
122 
126  {
127  return m_Bound[n];
128  }
129 
131  const ImageType * GetImagePointer(void) const
132  {
133  return m_ConstImage;
134  }
135 
138  virtual IndexType GetIndex(void) const
139  {
140  return m_Loop;
141  }
142 
145  virtual IndexType GetIndex(const OffsetType & o) const
146  {
147  return ( this->GetIndex() + o );
148  }
149 
152  virtual IndexType GetIndex(NeighborIndexType i) const
153  {
154  return ( this->GetIndex() + this->GetOffset(i) );
155  }
156 
158  RegionType GetRegion() const
159  {
160  return m_Region;
161  }
162 
165  IndexType GetBeginIndex() const
166  {
167  return m_BeginIndex;
168  }
169 
172  RegionType GetBoundingBoxAsImageRegion() const;
173 
177  virtual void GoToBegin();
178 
181  virtual void GoToEnd();
182 
185  virtual void Initialize(const SizeType & radius, const ImageType *ptr, const RegionType & region);
186 
189  virtual bool IsAtBegin() const
190  {
191  return ( this->GetIndex() == m_BeginIndex );
192  }
193 
196  virtual bool IsAtEnd() const;
197 
202  Self & operator++();
203 
208  Self & operator--();
209 
213  bool operator==(const Self & it) const
214  {
215  return it.GetIndex() == this->GetIndex();
216  }
217 
221  bool operator!=(const Self & it) const
222  {
223  return it.GetIndex() != this->GetIndex();
224  }
225 
231  bool operator<(const Self & it) const;
232 
238  bool operator<=(const Self & it) const;
239 
245  bool operator>(const Self & it) const;
246 
252  bool operator>=(const Self & it) const;
253 
258  void SetLocation(const IndexType & position)
259  {
260  this->SetLoop(position);
261  }
262 
266  Self & operator+=(const OffsetType &);
267 
271  Self & operator-=(const OffsetType &);
272 
275  {
276  return m_Loop - b.m_Loop;
277  }
278 
282  bool InBounds() const;
283 
295  bool IndexInBounds(NeighborIndexType n, OffsetType & internalIndex, OffsetType & offset ) const;
296 
298  void NeedToUseBoundaryConditionOn()
299  {
300  this->SetNeedToUseBoundaryCondition(true);
301  }
302 
303  void NeedToUseBoundaryConditionOff()
304  {
305  this->SetNeedToUseBoundaryCondition(false);
306  }
307 
308  void SetNeedToUseBoundaryCondition(bool b)
309  {
310  m_NeedToUseBoundaryCondition = b;
311  }
312 
313  bool GetNeedToUseBoundaryCondition() const
314  {
315  return m_NeedToUseBoundaryCondition;
316  }
317 
318 protected:
319 
322  virtual void SetLoop(const IndexType & p)
323  {
324  m_Loop = p; m_IsInBoundsValid = false;
325  }
326 
330  virtual void SetBound(const SizeType &);
331 
334  virtual void SetBeginIndex(const IndexType & start)
335  {
336  m_BeginIndex = start;
337  }
338 
341  virtual void SetEndIndex();
342 
346 
349 
351  typename ImageType::ConstPointer m_ConstImage;
352 
356 
359 
362 
365  mutable bool m_InBounds[Dimension];
366 
368  mutable bool m_IsInBounds;
369 
373  mutable bool m_IsInBoundsValid;
374 
377 
380 
383 };
384 
385 template< class TImage >
389  ::OffsetType & ind)
390 {
392  ret = it;
393  ret += ind;
394  return ret;
395 }
396 
397 template< class TImage >
398 inline ConstNeighborhoodIteratorWithOnlyIndex< TImage >
400  ::OffsetType & ind,
402 { return ( it + ind ); }
403 
404 template< class TImage >
405 inline ConstNeighborhoodIteratorWithOnlyIndex< TImage >
408  ::OffsetType & ind)
409 {
411  ret = it;
412  ret -= ind;
413  return ret;
414 }
415 } // namespace itk
416 
417 #ifndef ITK_MANUAL_INSTANTIATION
418 #include "itkConstNeighborhoodIteratorWithOnlyIndex.hxx"
419 #endif
420 
421 #endif
422