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 itkImageRegionExclusionIteratorWithIndex_h
19 #define itkImageRegionExclusionIteratorWithIndex_h
20 
21 #include "itkImageRegionExclusionConstIteratorWithIndex.h"
22 #include "itkImageIteratorWithIndex.h"
23 
24 namespace itk
25 {
26 /** \class ImageRegionExclusionIteratorWithIndex
27  *  \brief A multi-dimensional image iterator that walks an image region,
28  *         excluding a second region contained within the first, with write
29  *         access to pixels.
30  *
31  * Most of the functionality of this iterator is inherited from the
32  * ImageRegionExclusionConstIteratorWithIndex, which should be consulted for
33  * details.  This class only adds write access to the iterator.
34  *
35  * \par MORE INFORMATION
36  * For a complete description of the ITK Image Iterators and their API, please
37  * see the Iterators chapter in the ITK Software Guide.  The ITK Software Guide
38  * is available in print and as a free .pdf download from https://www.itk.org.
39  *
40  * \ingroup ImageIterators
41  *
42  * \sa ImageConstIterator \sa ConditionalConstIterator
43  * \sa ConstNeighborhoodIterator \sa ConstShapedNeighborhoodIterator
44  * \sa ConstSliceIterator  \sa CorrespondenceDataStructureIterator
45  * \sa FloodFilledFunctionConditionalConstIterator
46  * \sa FloodFilledImageFunctionConditionalConstIterator
47  * \sa FloodFilledImageFunctionConditionalIterator
48  * \sa FloodFilledSpatialFunctionConditionalConstIterator
49  * \sa FloodFilledSpatialFunctionConditionalIterator
50  * \sa ImageConstIterator \sa ImageConstIteratorWithIndex
51  * \sa ImageIterator \sa ImageIteratorWithIndex
52  * \sa ImageLinearConstIteratorWithIndex  \sa ImageLinearIteratorWithIndex
53  * \sa ImageRandomConstIteratorWithIndex  \sa ImageRandomIteratorWithIndex
54  * \sa ImageRegionConstIterator \sa ImageRegionConstIteratorWithIndex
55  * \sa ImageRegionExclusionConstIteratorWithIndex
56  * \sa ImageRegionExclusionIteratorWithIndex
57  * \sa ImageRegionIterator  \sa ImageRegionIteratorWithIndex
58  * \sa ImageRegionReverseConstIterator  \sa ImageRegionReverseIterator
59  * \sa ImageReverseConstIterator  \sa ImageReverseIterator
60  * \sa ImageSliceConstIteratorWithIndex  \sa ImageSliceIteratorWithIndex
61  * \sa NeighborhoodIterator \sa PathConstIterator  \sa PathIterator
62  * \sa ShapedNeighborhoodIterator  \sa SliceIterator
63  * \sa ImageConstIteratorWithIndex
64  * \ingroup ITKCommon
65  */
66 template< typename TImage >
67 class ITK_TEMPLATE_EXPORT ImageRegionExclusionIteratorWithIndex:public ImageRegionExclusionConstIteratorWithIndex< TImage >
68 {
69 public:
70   /** Standard class type aliases. */
71   using Self = ImageRegionExclusionIteratorWithIndex;
72   using Superclass = ImageRegionExclusionConstIteratorWithIndex< TImage >;
73 
74   /** Types inherited from the Superclass */
75   using IndexType = typename Superclass::IndexType;
76   using SizeType = typename Superclass::SizeType;
77   using OffsetType = typename Superclass::OffsetType;
78   using RegionType = typename Superclass::RegionType;
79   using ImageType = typename Superclass::ImageType;
80   using PixelContainer = typename Superclass::PixelContainer;
81   using PixelContainerPointer = typename Superclass::PixelContainerPointer;
82   using InternalPixelType = typename Superclass::InternalPixelType;
83   using PixelType = typename Superclass::PixelType;
84   using AccessorType = typename Superclass::AccessorType;
85 
86   /** Default constructor. Needed since we provide a cast constructor. */
87   ImageRegionExclusionIteratorWithIndex() = default;
88 
89   /** Constructor establishes an iterator to walk a particular image and a
90    * particular region of that image. */
91   ImageRegionExclusionIteratorWithIndex(ImageType *ptr, const RegionType & region);
92 
93   /** Constructor that can be used to cast from an ImageIterator to an
94    * ImageRegionExclusionIteratorWithIndex. Many routines return an ImageIterator, but for a
95    * particular task, you may want an ImageRegionExclusionIteratorWithIndex.  Rather than
96    * provide overloaded APIs that return different types of Iterators, itk
97    * returns ImageIterators and uses constructors to cast from an
98    * ImageIterator to a ImageRegionExclusionIteratorWithIndex. */
99   ImageRegionExclusionIteratorWithIndex(const ImageIteratorWithIndex< TImage > & it);
100 
101   /** Set the pixel value */
Set(const PixelType & value)102   void Set(const PixelType & value) const
103   { this->m_PixelAccessorFunctor.Set(*( const_cast< InternalPixelType * >( this->m_Position ) ), value); }
104 
105   /** Return a reference to the pixel.
106    * This method will provide the fastest access to pixel
107    * data, but it will NOT support ImageAdaptors. */
Value()108   PixelType & Value()
109   { return *( const_cast< InternalPixelType * >( this->m_Position ) ); }
110 
111 protected:
112   /** The construction from a const iterator is declared protected
113       in order to enforce const correctness. */
114   ImageRegionExclusionIteratorWithIndex(const ImageRegionExclusionConstIteratorWithIndex< TImage > & it);
115   Self & operator=(const ImageRegionExclusionConstIteratorWithIndex< TImage > & it);
116 };
117 } // end namespace itk
118 
119 #ifndef ITK_MANUAL_INSTANTIATION
120 #include "itkImageRegionExclusionIteratorWithIndex.hxx"
121 #endif
122 
123 #endif
124