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 itkNeighborhoodAlgorithm_h
19 #define itkNeighborhoodAlgorithm_h
20 
21 #include <list>
22 #include "itkImage.h"
23 #include "itkNeighborhoodOperator.h"
24 #include "itkNeighborhoodIterator.h"
25 
26 namespace itk
27 {
28 namespace NeighborhoodAlgorithm
29 {
30 /** \class ImageBoundaryFacesCalculator
31 *   \brief Splits an image into a main region and several "face" regions
32 *          which are used to handle computations on the boundary of an image.
33 *
34 * Splitting the image into the necessary regions is an easy task when you use
35 * the ImageBoundaryFacesCalculator.  The face
36 * calculator is so named because it returns a list of the "faces" of the ND
37 * dataset.  Faces are those regions whose pixels all lie within a distance \f$d\f$
38 * from the boundary, where \f$d\f$ is the radius of the neighborhood stencil used
39 * for the numerical calculations. In other words, faces are those regions
40 * where a neighborhood iterator of radius \f$d\f$ will always overlap the boundary
41 * of the image. The face calculator also returns the single \em inner
42 * region, in which out-of-bounds values are never required and bounds checking
43 * is not necessary.
44 *
45 * \image html FaceBoundaryCalculator.png "Example regions produced by the calculator."
46 *
47 * First we find center (non-boundary) region 0.
48 * then find the face on the lower side of the 0th dimension (Region 1).
49 * Next we find the face opposite to that face (Region 2).
50 * Then we find the face between region 1 and region 2 on
51 * the lower side of the 1th dimension.(region 3).
52 * Finally we find the face opposite to face 3 (region 4).
53 *
54 * \note The first region contained in faceList should be the
55 * non-boundary region, if there is one. The existence of a
56 * non-boundary region depends on the relative location of
57 * regionToProcess and bufferedRegion. The non-boundary regions (if
58 * any) are the remaining faces in faceList.
59 *
60 * \ingroup ITKCommon
61 */
62 template< typename TImage >
63 struct ImageBoundaryFacesCalculator {
64   using RadiusType = typename NeighborhoodIterator< TImage >::RadiusType;
65   using RegionType = typename TImage::RegionType;
66   using IndexType = typename TImage::IndexType;
67   using SizeType = typename TImage::SizeType;
68   using FaceListType = std::list< RegionType >;
69   static constexpr unsigned int ImageDimension = TImage::ImageDimension;
70 
71   FaceListType operator()(const TImage *, RegionType, RadiusType);
72 };
73 
74 /** \class CalculateOutputWrapOffsetModifiers
75  *  \brief Sets up itkNeighborhoodIterator output buffers.
76  *
77  * Helper class for setting up itkNeighborhoodIterator output
78  * buffers. Calculates the necessary modifiers to synchronize input and output
79  * iteration between images with equal RequestedRegion sizes but unequal
80  * BufferedRegion sizes.
81  * \ingroup ITKCommon
82  */
83 template< typename TImage >
84 struct CalculateOutputWrapOffsetModifiers {
85   using OffsetType = Offset< TImage::ImageDimension >;
86   OffsetType operator()(TImage *, TImage *) const;
87 };
88 } // end namespace NeighborhoodAlgorithm
89 } // end namespace itk
90 
91 #ifndef ITK_MANUAL_INSTANTIATION
92 #include "itkNeighborhoodAlgorithm.hxx"
93 #endif
94 
95 #endif
96