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 itkNeighborhoodAccessorFunctor_h
19 #define itkNeighborhoodAccessorFunctor_h
20 
21 #include "itkImageBoundaryCondition.h"
22 #include "itkImageBase.h"
23 
24 namespace itk
25 {
26 /** \class NeighborhoodAccessorFunctor
27  * \brief Provides accessor interfaces to Get pixels and is meant to be
28  * used on pointers contained within Neighborhoods. A typical user should
29  * not need to use this class directly. This class is used by the
30  * neighborhood iterators to get pixels from pixel pointers or assign
31  * a pixel to an address.
32  *
33  *
34  * \note
35  * This work is part of the National Alliance for Medical Image Computing
36  * (NAMIC), funded by the National Institutes of Health through the NIH Roadmap
37  * for Medical Research, Grant U54 EB005149.
38   * \ingroup ITKCommon
39  */
40 template< typename TImage >
41 class ITK_TEMPLATE_EXPORT NeighborhoodAccessorFunctor final
42 {
43 public:
44   using Self = NeighborhoodAccessorFunctor;
45   using ImageType = TImage;
46   using PixelType = typename ImageType::PixelType;
47   using InternalPixelType = typename ImageType::InternalPixelType;
48   using VectorLengthType = unsigned int;
49   using OffsetType = typename ImageType::OffsetType;
50 
51   static constexpr unsigned int ImageDimension = TImage::ImageDimension;
52   using NeighborhoodType = Neighborhood< InternalPixelType *, Self::ImageDimension >;
53 
54   template<typename TOutput=ImageType>
55   using ImageBoundaryConditionType = ImageBoundaryCondition<ImageType, TOutput>;
56 
57   /** Set the pointer index to the start of the buffer. */
SetBegin(const InternalPixelType *)58   inline void SetBegin(const InternalPixelType *) {}
59 
60   /** Method to dereference a pixel pointer. This is used from the
61    * ConstNeighborhoodIterator as the equivalent operation to (*it).
62    * This method should be preferred over the former (*it) notation.
63    * The reason is that dereferencing a pointer to a location of
64    * VectorImage pixel involves a different operation that simply
65    * dereferencing the pointer.  */
Get(const InternalPixelType * pixelPointer)66   inline PixelType Get(const InternalPixelType *pixelPointer) const
67   {
68     return ( *pixelPointer );
69   }
70 
71   /** Method to set the pixel value at a certain pixel pointer */
Set(InternalPixelType * const pixelPointer,const PixelType & p)72   inline void Set(InternalPixelType * const pixelPointer, const PixelType & p) const
73   {
74     *pixelPointer = p;
75   }
76 
77   template <typename TOutput>
78   inline typename ImageBoundaryConditionType<TOutput>::OutputPixelType
BoundaryCondition(const OffsetType & point_index,const OffsetType & boundary_offset,const NeighborhoodType * data,const ImageBoundaryConditionType<TOutput> * boundaryCondition)79     BoundaryCondition(
80       const OffsetType & point_index,
81       const OffsetType & boundary_offset,
82       const NeighborhoodType *data,
83       const ImageBoundaryConditionType<TOutput> *boundaryCondition) const
84   {
85     return boundaryCondition->operator()(point_index, boundary_offset, data);
86   }
87 
SetVectorLength(VectorLengthType)88   void SetVectorLength(VectorLengthType) {}
SetVectorLength()89   VectorLengthType SetVectorLength() { return 0; }
90 };
91 } // end namespace itk
92 
93 //template< typename TImage > const unsigned int
94 // itk::NeighborhoodAccessorFunctor<TImage>::ImageDimension;
95 
96 #endif
97