18#ifndef itkScanlineFilterCommon_h
19#define itkScanlineFilterCommon_h
40template <
typename TInputImage,
typename TOutputImage>
65 if (smartPtr ==
nullptr)
67 smartPtr =
new Self(
nullptr);
69 smartPtr->UnRegister();
97#ifdef ITK_USE_CONCEPT_CHECKING
148 itkAssertOrThrowMacro(requestedRegion.GetIndex(dim) <= index[dim],
"Index must be within the requested region!");
149 linearIndex += (index[dim] - requestedRegion.GetIndex(dim)) * stride;
150 stride *= requestedRegion.GetSize(dim);
160 typename LineMapType::iterator MapBegin, MapEnd, LineIt;
165 for (LineIt = MapBegin; LineIt != MapEnd; ++LineIt)
168 for (cIt = LineIt->begin(); cIt != LineIt->end(); ++cIt)
191 const std::lock_guard<std::mutex> lockGuard(
m_Mutex);
216 for (
size_t i = 1; i < N; ++i)
218 const auto label =
static_cast<size_t>(
m_UnionFind[i]);
221 if (consecutiveLabel == backgroundValue)
251 return (diffSum <= 1);
269 bool sameLine = sameLineOffset;
292 mIt = Neighbour.begin();
294 for (cIt = current.begin(); cIt != current.end(); ++cIt)
303 mIt = Neighbour.begin();
306 for (nIt = mIt; nIt != Neighbour.end(); ++nIt)
308 if (!labelCompare || cIt->label != nIt->label)
336 if ((ss1 >= cStart) && (ee2 <= cLast))
343 else if ((ss1 <= cStart) && (ee2 >= cLast))
350 else if ((ss1 <= cLast) && (ee2 >= cLast))
357 else if ((ss1 <= cStart) && (ee2 >= cStart))
367 callback(cIt, nIt, oStart, oLast);
368 if (sameLineOffset && oStart == cStart && oLast == cLast)
375 if (!sameLineOffset && ee1 >= cLast)
409 PretendSizeType PretendSize;
411 for (
SizeValueType i = 0; i < PretendSize.GetSizeDimension(); ++i)
413 PretendSize[i] = OutSize[i + 1];
416 LineRegion.
SetSize(PretendSize);
417 fakeImage->SetRegions(LineRegion);
418 auto kernelRadius = PretendSizeType::Filled(1);
419 LineNeighborhoodType lnit(kernelRadius, fakeImage, LineRegion);
421 if (wholeNeighborhood)
430 typename LineNeighborhoodType::IndexListType ActiveIndexes;
431 ActiveIndexes = lnit.GetActiveIndexList();
433 typename LineNeighborhoodType::IndexListType::const_iterator LI;
435 PretendIndexType idx = LineRegion.GetIndex();
438 for (LI = ActiveIndexes.begin(); LI != ActiveIndexes.end(); ++LI)
440 m_LineOffsets.push_back(fakeImage->ComputeOffset(idx + lnit.GetOffset(*LI)) - offset);
443 if (wholeNeighborhood)
460 const SizeValueType xsizeForThread = outputRegionForThread.GetSize()[0];
461 const SizeValueType numberOfLines = outputRegionForThread.GetNumberOfPixels() / xsizeForThread;
464 const SizeValueType lastLine = firstLine + numberOfLines - 1;
480 itkAssertInDebugAndIgnoreInReleaseMacro(lastLine >= wud.
lastLine);
491 if (neighIdx >= 0 && neighIdx < linecount && !
m_LineMap[neighIdx].empty())
Const version of ShapedNeighborhoodIterator, defining iteration of a local N-dimensional neighborhood...
const SizeType & GetSize() const
Base class for filters that take an image as input and produce an image as output.
Templated n-dimensional image class.
static T::Pointer Create()
Base class for most ITK classes.
void UnRegister() const noexcept override
void Register() const override
Helper class for a group of filters which operate on scan-lines.
typename TInputImage::IndexType IndexType
OffsetVectorType m_LineOffsets
typename OffsetVectorType::const_iterator OffsetVectorConstIterator
typename TOutputImage::SizeType OutputSizeType
typename TOutputImage::RegionType::SizeType OutSizeType
typename LineEncodingType::const_iterator LineEncodingConstIterator
InternalLabelType LookupSet(const InternalLabelType label)
SizeValueType InternalLabelType
void InitUnion(InternalLabelType numberOfLabels)
ConsecutiveVectorType m_Consecutive
std::deque< WorkUnitData > m_WorkUnitResults
typename InputImageType::Pointer InputImagePointer
SizeValueType IndexToLinearIndex(const IndexType &index) const
typename TInputImage::OffsetType OffsetType
void ComputeEquivalence(const SizeValueType workUnitResultsIndex, bool strictlyLess)
void SetupLineOffsets(bool wholeNeighborhood)
bool CheckNeighbors(const OutputIndexType &A, const OutputIndexType &B) const
static constexpr unsigned int InputImageDimension
typename TOutputImage::PixelType OutputImagePixelType
typename LineEncodingType::iterator LineEncodingIterator
WorkUnitData CreateWorkUnitData(const RegionType &outputRegionForThread)
TInputImage InputImageType
static constexpr unsigned int ImageDimension
void LinkLabels(const InternalLabelType label1, const InternalLabelType label2)
std::vector< LineEncodingType > LineMapType
SizeValueType CreateConsecutive(OutputPixelType backgroundValue)
typename TOutputImage::OffsetType OutputOffsetType
typename InputImageType::ConstPointer InputImageConstPointer
std::vector< RunLength > LineEncodingType
typename TInputImage::SizeType SizeType
std::vector< OffsetValueType > OffsetVectorType
std::vector< InternalLabelType > UnionFindType
~ScanlineFilterCommon()=default
std::vector< OutputPixelType > ConsecutiveVectorType
UnionFindType m_UnionFind
typename TOutputImage::RegionType OutputRegionType
void UnRegister() const noexcept
std::function< void(const LineEncodingConstIterator ¤tRun, const LineEncodingConstIterator &neighborRun, OffsetValueType oStart, OffsetValueType oLast)> CompareLinesCallback
typename TOutputImage::IndexType OutputIndexType
OutputRegionType RegionType
std::atomic< SizeValueType > m_NumberOfLabels
typename TInputImage::PixelType InputPixelType
ScanlineFilterCommon Self
void CompareLines(const LineEncodingType ¤t, const LineEncodingType &Neighbour, bool sameLineOffset, bool labelCompare, OutputPixelType background, CompareLinesCallback callback)
WeakPointer< EnclosingFilter > m_EnclosingFilter
TOutputImage OutputImageType
static constexpr unsigned int OutputImageDimension
typename OutputImageType::Pointer OutputImagePointer
ScanlineFilterCommon(EnclosingFilter *enclosingFilter)
typename TOutputImage::PixelType OutputPixelType
Implements a weak reference to an object.
SmartPointer< const Self > ConstPointer
SmartPointer< Self > Pointer
#define itkConceptMacro(name, concept)
ImageBaseType::RegionType RegionType
ImageBaseType::IndexType IndexType
ImageBaseType::SizeType SizeType
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
TIterator * setConnectivity(TIterator *it, bool fullyConnected=false)
unsigned long SizeValueType
TIterator * setConnectivityPrevious(TIterator *it, bool fullyConnected=false)
InputImageType::IndexType where
RunLength(SizeValueType iLength, const IndexType &iWhere, InternalLabelType iLabel=0)
void SetSize(const SizeValueType val[VDimension])