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