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