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 itkFloodFilledSpatialFunctionConditionalIterator_h
19 #define itkFloodFilledSpatialFunctionConditionalIterator_h
20 
21 #include "itkFloodFilledSpatialFunctionConditionalConstIterator.h"
22 
23 namespace itk
24 {
25 /**
26  * \class FloodFilledSpatialFunctionConditionalIterator
27  * \brief Iterates over a flood-filled spatial function with write access
28  *        to pixels.
29  *
30  * \ingroup ImageIterators
31  *
32  * \ingroup ITKCommon
33  */
34 template< typename TImage, typename TFunction >
35 class FloodFilledSpatialFunctionConditionalIterator:public
36   FloodFilledSpatialFunctionConditionalConstIterator< TImage, TFunction >
37 {
38 public:
39   /** Standard class type aliases. */
40   using Self = FloodFilledSpatialFunctionConditionalIterator;
41   using Superclass = FloodFilledSpatialFunctionConditionalConstIterator< TImage, TFunction >;
42 
43   /** Type of function */
44   using FunctionType = typename Superclass::FunctionType;
45 
46   /** Type of vector used to store location info in the spatial function */
47   using FunctionInputType = typename Superclass::FunctionInputType;
48 
49   /** Index type alias support */
50   using IndexType = typename Superclass::IndexType;
51 
52   /** Index ContainerType. */
53   using SeedsContainerType = typename Superclass::SeedsContainerType;
54 
55   /** Size type alias support */
56   using SizeType = typename Superclass::SizeType;
57 
58   /** Region type alias support */
59   using RegionType = typename Superclass::RegionType;
60 
61   /** Image type alias support */
62   using ImageType = typename Superclass::ImageType;
63 
64   /** Internal Pixel Type */
65   using InternalPixelType = typename Superclass::InternalPixelType;
66 
67   /** External Pixel Type */
68   using PixelType = typename Superclass::PixelType;
69 
70   /** Constructor establishes an iterator to walk a particular image and a
71    * particular region of that image. This version of the constructor uses
72    * an explicit seed pixel for the flood fill, the "startIndex" */
FloodFilledSpatialFunctionConditionalIterator(ImageType * imagePtr,FunctionType * fnPtr,IndexType startIndex)73   FloodFilledSpatialFunctionConditionalIterator(ImageType *imagePtr,
74                                                 FunctionType *fnPtr,
75                                                 IndexType startIndex):Superclass(imagePtr, fnPtr, startIndex) {}
76 
77   /** Constructor establishes an iterator to walk a particular image and a
78    * particular region of that image. This version of the constructor
79    * should be used when the seed pixel is unknown. */
FloodFilledSpatialFunctionConditionalIterator(ImageType * imagePtr,FunctionType * fnPtr)80   FloodFilledSpatialFunctionConditionalIterator(ImageType *imagePtr,
81                                                 FunctionType *fnPtr):Superclass(imagePtr, fnPtr) {}
82 
83   /** Get the pixel value, const version to avoid overload warnings */
Get()84   const PixelType Get() const override
85   { return const_cast< ImageType * >( this->m_Image.GetPointer() )->GetPixel( this->m_IndexStack.front() ); }
86 
87   /** Get the pixel value, non-const version is sometimes useful. */
Get()88   PixelType Get()
89   { return const_cast< ImageType * >( this->m_Image.GetPointer() )->GetPixel( this->m_IndexStack.front() ); }
90 
91   /** Set the pixel value */
Set(const PixelType & value)92   void Set(const PixelType & value)
93   { const_cast< ImageType * >( this->m_Image.GetPointer() )->GetPixel( this->m_IndexStack.front() ) = value; }
94 
95   /** Default Destructor. */
96   ~FloodFilledSpatialFunctionConditionalIterator() override = default;
97 };
98 } // end namespace itk
99 
100 #endif
101