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);
163 for (
typename LineMapType::iterator LineIt = MapBegin; LineIt != MapEnd; ++LineIt)
165 for (
auto cIt = LineIt->begin(); cIt != LineIt->end(); ++cIt)
188 const std::lock_guard<std::mutex> lockGuard(
m_Mutex);
213 for (
size_t i = 1; i < N; ++i)
215 const auto label =
static_cast<size_t>(
m_UnionFind[i]);
218 if (consecutiveLabel == backgroundValue)
248 return (diffSum <= 1);
266 bool sameLine = sameLineOffset;
287 auto mIt = Neighbour.begin();
289 for (
auto cIt = current.begin(); cIt != current.end(); ++cIt)
298 mIt = Neighbour.begin();
301 for (
auto nIt = mIt; nIt != Neighbour.end(); ++nIt)
303 if (!labelCompare || cIt->label != nIt->label)
331 if ((ss1 >= cStart) && (ee2 <= cLast))
338 else if ((ss1 <= cStart) && (ee2 >= cLast))
345 else if ((ss1 <= cLast) && (ee2 >= cLast))
352 else if ((ss1 <= cStart) && (ee2 >= cStart))
362 callback(cIt, nIt, oStart, oLast);
363 if (sameLineOffset && oStart == cStart && oLast == cLast)
370 if (!sameLineOffset && ee1 >= cLast)
403 PretendSizeType PretendSize;
405 for (
SizeValueType i = 0; i < PretendSize.GetSizeDimension(); ++i)
407 PretendSize[i] = OutSize[i + 1];
410 LineRegion.
SetSize(PretendSize);
411 fakeImage->SetRegions(LineRegion);
412 auto kernelRadius = PretendSizeType::Filled(1);
413 LineNeighborhoodType lnit(kernelRadius, fakeImage, LineRegion);
415 if (wholeNeighborhood)
424 typename LineNeighborhoodType::IndexListType ActiveIndexes = lnit.GetActiveIndexList();
426 const PretendIndexType idx = LineRegion.GetIndex();
429 for (
auto LI = ActiveIndexes.begin(); LI != ActiveIndexes.end(); ++LI)
431 m_LineOffsets.push_back(fakeImage->ComputeOffset(idx + lnit.GetOffset(*LI)) - offset);
434 if (wholeNeighborhood)
451 const SizeValueType xsizeForThread = outputRegionForThread.GetSize()[0];
452 const SizeValueType numberOfLines = outputRegionForThread.GetNumberOfPixels() / xsizeForThread;
455 const SizeValueType lastLine = firstLine + numberOfLines - 1;
471 itkAssertInDebugAndIgnoreInReleaseMacro(lastLine >= wud.
lastLine);
482 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])