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 itkImageSliceIteratorWithIndex_h 19 #define itkImageSliceIteratorWithIndex_h 20 21 #include "itkImageSliceConstIteratorWithIndex.h" 22 #include "itkImageIteratorWithIndex.h" 23 24 namespace itk 25 { 26 /** \class ImageSliceIteratorWithIndex 27 * \brief A multi-dimensional image iterator that extends the 28 * ImageLinearIteratorWithIndex from iteration along lines in an image to 29 * iteration along both lines and planes (slices) within an image. 30 * 31 * A slice is defined as a 2D plane spanned by two vectors pointing along 32 * orthogonal coordinate axes. Most of the functionality is inherited from 33 * the ImageSliceConstIteratorWithIndex. The current class only adds 34 * write access to image pixels. See ImageSliceConstIteratorWithIndex 35 * for details. 36 * 37 * \par MORE INFORMATION 38 * For a complete description of the ITK Image Iterators and their API, please 39 * see the Iterators chapter in the ITK Software Guide. The ITK Software Guide 40 * is available in print and as a free .pdf download from https://www.itk.org. 41 * 42 * \ingroup ImageIterators 43 * 44 * \sa ImageConstIterator \sa ConditionalConstIterator 45 * \sa ConstNeighborhoodIterator \sa ConstShapedNeighborhoodIterator 46 * \sa ConstSliceIterator \sa CorrespondenceDataStructureIterator 47 * \sa FloodFilledFunctionConditionalConstIterator 48 * \sa FloodFilledImageFunctionConditionalConstIterator 49 * \sa FloodFilledImageFunctionConditionalIterator 50 * \sa FloodFilledSpatialFunctionConditionalConstIterator 51 * \sa FloodFilledSpatialFunctionConditionalIterator 52 * \sa ImageConstIterator \sa ImageConstIteratorWithIndex 53 * \sa ImageIterator \sa ImageIteratorWithIndex 54 * \sa ImageLinearConstIteratorWithIndex \sa ImageLinearIteratorWithIndex 55 * \sa ImageRandomConstIteratorWithIndex \sa ImageRandomIteratorWithIndex 56 * \sa ImageRegionConstIterator \sa ImageRegionConstIteratorWithIndex 57 * \sa ImageRegionExclusionConstIteratorWithIndex 58 * \sa ImageRegionExclusionIteratorWithIndex 59 * \sa ImageRegionIterator \sa ImageRegionIteratorWithIndex 60 * \sa ImageRegionReverseConstIterator \sa ImageRegionReverseIterator 61 * \sa ImageReverseConstIterator \sa ImageReverseIterator 62 * \sa ImageSliceConstIteratorWithIndex \sa ImageSliceIteratorWithIndex 63 * \sa NeighborhoodIterator \sa PathConstIterator \sa PathIterator 64 * \sa ShapedNeighborhoodIterator \sa SliceIterator 65 * \sa ImageConstIteratorWithIndex 66 * \ingroup ITKCommon 67 */ 68 template< typename TImage > 69 class ITK_TEMPLATE_EXPORT ImageSliceIteratorWithIndex:public ImageSliceConstIteratorWithIndex< TImage > 70 { 71 public: 72 /** Standard class type aliases. */ 73 using Self = ImageSliceIteratorWithIndex; 74 using Superclass = ImageSliceConstIteratorWithIndex< TImage >; 75 76 /** Types inherited from the Superclass */ 77 using IndexType = typename Superclass::IndexType; 78 using SizeType = typename Superclass::SizeType; 79 using OffsetType = typename Superclass::OffsetType; 80 using RegionType = typename Superclass::RegionType; 81 using ImageType = typename Superclass::ImageType; 82 using PixelContainer = typename Superclass::PixelContainer; 83 using PixelContainerPointer = typename Superclass::PixelContainerPointer; 84 using InternalPixelType = typename Superclass::InternalPixelType; 85 using PixelType = typename Superclass::PixelType; 86 using AccessorType = typename Superclass::AccessorType; 87 88 /** Default constructor. Needed since we provide a cast constructor. */ 89 ImageSliceIteratorWithIndex() = default; 90 91 /** Constructor establishes an iterator to walk a particular image and a 92 * particular region of that image. */ 93 ImageSliceIteratorWithIndex(ImageType *ptr, const RegionType & region); 94 95 /** Constructor that can be used to cast from an ImageIterator to an 96 * ImageSliceIteratorWithIndex. Many routines return an ImageIterator, but for a 97 * particular task, you may want an ImageSliceIteratorWithIndex. Rather than 98 * provide overloaded APIs that return different types of Iterators, itk 99 * returns ImageIterators and uses constructors to cast from an 100 * ImageIterator to a ImageSliceIteratorWithIndex. */ 101 ImageSliceIteratorWithIndex(const ImageIteratorWithIndex< TImage > & it); 102 103 /** Set the pixel value */ Set(const PixelType & value)104 void Set(const PixelType & value) const 105 { this->m_PixelAccessorFunctor.Set(*( const_cast< InternalPixelType * >( this->m_Position ) ), value); } 106 107 /** Return a reference to the pixel. 108 * This method will provide the fastest access to pixel 109 * data, but it will NOT support ImageAdaptors. */ Value()110 PixelType & Value() 111 { return *( const_cast< InternalPixelType * >( this->m_Position ) ); } 112 113 protected: 114 /** The construction from a const iterator is declared protected 115 in order to enforce const correctness. */ 116 ImageSliceIteratorWithIndex(const ImageSliceConstIteratorWithIndex< TImage > & it); 117 Self & operator=(const ImageSliceConstIteratorWithIndex< TImage > & it); 118 }; 119 } // end namespace itk 120 121 #ifndef ITK_MANUAL_INSTANTIATION 122 #include "itkImageSliceIteratorWithIndex.hxx" 123 #endif 124 125 #endif 126