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 itkDefaultVectorPixelAccessorFunctor_h 19 #define itkDefaultVectorPixelAccessorFunctor_h 20 21 #include "itkMacro.h" 22 23 namespace itk 24 { 25 /** \class DefaultVectorPixelAccessorFunctor 26 * \brief This class provides a common API for pixel accessors for Image and 27 * VectorImage. (between the DefaultVectorPixelAccessor and DefaultPixelAccessor). 28 * 29 * The pixel accessor is set with the SetPixelAccessor method. This accessor is 30 * meant to be used only for VectorImage and not for Image. Prior to use, the 31 * start of the VectorImage buffer must also be set with the SetBegin method. 32 * 33 * \sa DefaultVectorPixelAccessor 34 * \sa DefaultPixelAccessor 35 * \sa DefaultPixelAccessorFunctor 36 * 37 * \note 38 * This work is part of the National Alliance for Medical Image Computing 39 * (NAMIC), funded by the National Institutes of Health through the NIH Roadmap 40 * for Medical Research, Grant U54 EB005149. 41 * 42 * \ingroup ImageAdaptors 43 * \ingroup ITKCommon 44 */ 45 template< typename TImageType > 46 class DefaultVectorPixelAccessorFunctor 47 { 48 public: 49 50 using ImageType = TImageType; 51 using InternalPixelType = typename ImageType::InternalPixelType; 52 using ExternalPixelType = typename ImageType::PixelType; 53 using PixelAccessorType = typename ImageType::AccessorType; 54 using VectorLengthType = unsigned int; 55 56 57 /** 58 * example usage: 59 * todo 60 * 61 */ 62 template <typename UImageType> 63 struct Rebind 64 { 65 using Type = DefaultVectorPixelAccessorFunctor<UImageType>; 66 }; 67 68 SetVectorLength(ImageType * image,VectorLengthType length)69 static void SetVectorLength(ImageType *image, VectorLengthType length) 70 { 71 image->SetVectorLength(length); 72 } 73 GetVectorLength(const ImageType * image)74 static VectorLengthType GetVectorLength(const ImageType *image) 75 { 76 return image->GetVectorLength(); 77 } 78 79 80 DefaultVectorPixelAccessorFunctor() = default; 81 82 /** Set the PixelAccessor. This is set at construction time by the image iterators. 83 * The type PixelAccessorType is obtained from the ImageType over which the iterators 84 * are templated. 85 * */ SetPixelAccessor(const PixelAccessorType & accessor)86 inline void SetPixelAccessor(const PixelAccessorType & accessor) 87 { 88 m_PixelAccessor = accessor; 89 } 90 91 /** Set the pointer index to the start of the buffer. */ SetBegin(const InternalPixelType * begin)92 inline void SetBegin(const InternalPixelType *begin) 93 { this->m_Begin = const_cast< InternalPixelType * >( begin ); } 94 95 /** Set output using the value in input */ Set(InternalPixelType & output,const ExternalPixelType & input)96 inline void Set(InternalPixelType & output, const ExternalPixelType & input) const 97 { 98 m_PixelAccessor.Set(output, input, ( &output ) - m_Begin); 99 } 100 101 /** Get the value from input */ Get(const InternalPixelType & input)102 inline ExternalPixelType Get(const InternalPixelType & input) const 103 { 104 return m_PixelAccessor.Get(input, &input - m_Begin); 105 } 106 107 private: 108 PixelAccessorType m_PixelAccessor; // The pixel accessor 109 InternalPixelType *m_Begin{nullptr}; // Begin of the buffer 110 }; 111 } 112 113 #endif 114