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 itkFloodFilledSpatialFunctionConditionalConstIterator_h
19 #define itkFloodFilledSpatialFunctionConditionalConstIterator_h
20 
21 #include "itkFloodFilledFunctionConditionalConstIterator.h"
22 
23 namespace itk
24 {
25 /**
26  * \class FloodFilledSpatialFunctionConditionalConstIterator
27  * \brief Iterates over a flood-filled spatial function with read-only access
28  *        to pixels.
29  *
30  * \ingroup ImageIterators
31  *
32  * \ingroup ITKCommon
33  */
34 template< typename TImage, typename TFunction >
35 class ITK_TEMPLATE_EXPORT FloodFilledSpatialFunctionConditionalConstIterator:public FloodFilledFunctionConditionalConstIterator<
36     TImage, TFunction >
37 {
38 public:
39   /** Standard class type aliases. */
40   using Self = FloodFilledSpatialFunctionConditionalConstIterator;
41   using Superclass = FloodFilledFunctionConditionalConstIterator< 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" */
73   FloodFilledSpatialFunctionConditionalConstIterator(const ImageType *imagePtr,
74                                                      FunctionType *fnPtr,
75                                                      IndexType 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. */
80   FloodFilledSpatialFunctionConditionalConstIterator(const ImageType *imagePtr,
81                                                      FunctionType *fnPtr);
82   /** Default Destructor. */
83   ~FloodFilledSpatialFunctionConditionalConstIterator() override = default;
84 
85   /** Compute whether the index of interest should be included in the flood */
86   bool IsPixelIncluded(const IndexType & index) const override;
87 
88   /** Set the inclusion strategy to origin */
SetOriginInclusionStrategy()89   void SetOriginInclusionStrategy() { m_InclusionStrategy = 0; }
90 
91   /** Set the inclusion strategy to center */
SetCenterInclusionStrategy()92   void SetCenterInclusionStrategy() { m_InclusionStrategy = 1; }
93 
94   /** Set the inclusion strategy to complete */
SetCompleteInclusionStrategy()95   void SetCompleteInclusionStrategy() { m_InclusionStrategy = 2; }
96 
97   /** Set the inclusion strategy to intersect */
SetIntersectInclusionStrategy()98   void SetIntersectInclusionStrategy() { m_InclusionStrategy = 3; }
99 
100 protected: //made protected so other iterators can access
101 
102   /** How the pixel (index) is examined in order to decide whether or not
103  * it's included. The strategies are:
104  * 0) Origin: if the origin of the pixel in physical space is inside the function,
105  * then the pixel is inside the function
106  * 1) Center: if the center of a pixel, in physical space, is inside the function,
107  * then the pixel is inside the function
108  * 2) Complete: if all of the corners of the pixel in physical space are inside the function,
109  * then the pixel is inside the function
110  * 3) Intersect: if any of the corners of the pixel in physical space are inside the function,
111  * then the pixel is inside the function */
112 
113   unsigned char m_InclusionStrategy;
114 };
115 } // end namespace itk
116 
117 #ifndef ITK_MANUAL_INSTANTIATION
118 #include "itkFloodFilledSpatialFunctionConditionalConstIterator.hxx"
119 #endif
120 
121 #endif
122