18#ifndef itkRLEImageConstIterator_h
19#define itkRLEImageConstIterator_h
30class MultiLabelMeshPipeline;
41template <
typename TPixel,
unsigned int VImageDimension,
typename CounterType>
44 friend class ::MultiLabelMeshPipeline;
60 using ImageType = RLEImage<TPixel, VImageDimension, CounterType>;
63 using RLLine =
typename ImageType::RLLine;
66 using BufferType =
typename ImageType::BufferType;
69 using BufferIterator = ImageRegionIterator<BufferType>;
72 using IndexType =
typename ImageType::IndexType;
78 using SizeType =
typename ImageType::SizeType;
81 using OffsetType =
typename ImageType::OffsetType;
84 using RegionType =
typename ImageType::RegionType;
90 using PixelType =
typename ImageType::PixelType;
95 : m_RunLengthLine(nullptr)
103 m_SegmentRemainder = 0;
113 m_RunLengthLine = it.m_RunLengthLine;
115 m_Index0 = it.m_Index0;
116 this->m_BI = it.m_BI;
118 m_RealIndex = it.m_RealIndex;
119 m_SegmentRemainder = it.m_SegmentRemainder;
120 m_BeginIndex0 = it.m_BeginIndex0;
121 m_EndIndex0 = it.m_EndIndex0;
141 m_RunLengthLine = it.m_RunLengthLine;
143 m_Index0 = it.m_Index0;
146 m_RealIndex = it.m_RealIndex;
147 m_SegmentRemainder = it.m_SegmentRemainder;
148 m_BeginIndex0 = it.m_BeginIndex0;
149 m_EndIndex0 = it.m_EndIndex0;
160 if (region.GetNumberOfPixels() > 0)
163 itkAssertOrThrowMacro((bufferedRegion.IsInside(region)),
164 "Region " << region <<
" is outside of buffered region " << bufferedRegion);
167 m_BI = BufferIterator(
m_Buffer, region.Slice(0));
168 m_Index0 = region.GetIndex(0);
169 m_BeginIndex0 = m_Index0 -
m_Image->GetBufferedRegion().GetIndex(0);
170 m_EndIndex0 = m_BeginIndex0 + region.GetSize(0);
171 SetIndexInternal(m_BeginIndex0);
178 return VImageDimension;
186 return m_BI != it.m_BI || m_Index0 + m_BeginIndex0 != it.m_Index0 + it.m_BeginIndex0;
194 return m_BI == it.m_BI && m_Index0 + m_BeginIndex0 == it.m_Index0 + it.m_BeginIndex0;
206 else if (m_BI > it.m_BI)
210 return m_Index0 + m_BeginIndex0 <= it.m_Index0 + it.m_BeginIndex0;
222 else if (m_BI > it.m_BI)
226 return m_Index0 + m_BeginIndex0 < it.m_Index0 + it.m_BeginIndex0;
238 else if (m_BI < it.m_BI)
242 return m_Index0 + m_BeginIndex0 >= it.m_Index0 + it.m_BeginIndex0;
254 else if (m_BI < it.m_BI)
258 return m_Index0 + m_BeginIndex0 > it.m_Index0 + it.m_BeginIndex0;
268 typename BufferType::IndexType bufInd = m_BI.ComputeIndex();
271 indR[i] = bufInd[i - 1];
280 typename BufferType::IndexType bufInd;
283 bufInd[i - 1] = ind[i];
285 m_BI.SetIndex(bufInd);
286 SetIndexInternal(ind[0] -
m_Image->GetBufferedRegion().GetIndex(0));
296 r.SetIndex(0, m_BeginIndex0 +
m_Image->GetBufferedRegion().GetIndex(0));
297 r.SetSize(0, m_EndIndex0 - m_BeginIndex0);
298 typename BufferType::RegionType ir = m_BI.GetRegion();
301 r.SetIndex(i, ir.GetIndex(i - 1));
302 r.SetSize(i, ir.GetSize(i - 1));
327 RLLine & line =
const_cast<Self *
>(
this)->m_BI.Value();
329 return line[m_RealIndex].second;
338 SetIndexInternal(m_BeginIndex0);
347 m_Index0 = m_BeginIndex0;
355 return m_Index0 == m_BeginIndex0 && m_BI.IsAtBegin();
363 return m_Index0 == m_BeginIndex0 && m_BI.IsAtEnd();
372 m_RunLengthLine = &m_BI.Value();
376 for (; x < (*m_RunLengthLine).size(); x++)
378 t += (*m_RunLengthLine)[x].first;
385 m_SegmentRemainder = t - m_Index0;
388 typename ImageType::ConstWeakPointer
m_Image;
392 const RLLine * m_RunLengthLine;
401 typename BufferType::Pointer
m_Buffer;
404template <
typename TPixel,
unsigned int VImageDimension,
typename CounterType>
419 this->m_BI.GoToReverseBegin();
420 this->m_Index0 = this->m_EndIndex0 - 1;
421 SetIndexInternal(this->m_Index0);
427 return this->m_BI.IsAtReverseEnd();
447template <
typename TPixel,
unsigned int VImageDimension,
typename CounterType>
ImageConstIteratorWithIndex(const ImageConstIteratorWithIndex &it)
typename itk::ImageConstIterator< RLEImage< TPixel, VImageDimension, CounterType > >::RegionType RegionType
ImageConstIteratorWithIndex()
ImageConstIteratorWithIndex(const ImageType *ptr, const RegionType ®ion)
RLEImage< TPixel, VImageDimension, CounterType > ImageType
ImageConstIteratorWithOnlyIndex(const ImageConstIteratorWithOnlyIndex &it)
ImageConstIteratorWithOnlyIndex()
typename itk::ImageConstIterator< RLEImage< TPixel, VImageDimension, CounterType > >::RegionType RegionType
RLEImage< TPixel, VImageDimension, CounterType > ImageType
ImageConstIteratorWithOnlyIndex(const ImageType *ptr, const RegionType ®ion)
Read-only ImageIterator: ImageConstIterator<TImage> behaves as ImageIterator<const TImage>.
ImageConstIterator()=default
Self & operator=(const Self &)=default
virtual void SetIndex(const IndexType &ind)
std::conditional_t< std::is_const_v< TImage >, const InternalPixelType, InternalPixelType > * m_Buffer
detail::IteratorImageType_t< TImage > ImageType
static unsigned int GetImageIteratorDimension()
static constexpr unsigned int ImageIteratorDimension
bool operator>=(const ImageIterator< TOtherImage > &it) const
virtual void SetRegion(const RegionType ®ion)
typename TImage::OffsetType OffsetType
typename TImage::InternalPixelType InternalPixelType
bool operator>(const ImageIterator< TOtherImage > &it) const
bool operator==(const ImageIterator< TOtherImage > &it) const
typename TImage::IndexType IndexType
const PixelType & Value() const
WeakPointer< TImage > m_Image
bool operator!=(const ImageIterator< TOtherImage > &it) const
bool operator<=(const ImageIterator< TOtherImage > &it) const
typename TImage::SizeType SizeType
typename TImage::RegionType RegionType
TImage * GetImage() const
typename TImage::PixelType PixelType
const RegionType & GetRegion() const
bool operator<(const ImageIterator< TOtherImage > &it) const
Run-Length Encoded image. It saves memory for label images at the expense of processing times....
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
unsigned long SizeValueType