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();
86 using SizeType =
typename TInputImage::SizeType;
114 typename InputImageType::IndexType
where;
145 itkAssertOrThrowMacro(requestedRegion.GetIndex(dim) <= index[dim],
"Index must be within the requested region!");
146 linearIndex += (index[dim] - requestedRegion.GetIndex(dim)) * stride;
147 stride *= requestedRegion.GetSize(dim);
160 for (
typename LineMapType::iterator LineIt = MapBegin; LineIt != MapEnd; ++LineIt)
162 for (
auto cIt = LineIt->begin(); cIt != LineIt->end(); ++cIt)
185 const std::lock_guard<std::mutex> lockGuard(
m_Mutex);
210 for (
size_t i = 1; i < N; ++i)
212 const auto label =
static_cast<size_t>(
m_UnionFind[i]);
215 if (consecutiveLabel == backgroundValue)
245 return (diffSum <= 1);
263 bool sameLine = sameLineOffset;
284 auto mIt = Neighbour.begin();
286 for (
auto cIt = current.begin(); cIt != current.end(); ++cIt)
295 mIt = Neighbour.begin();
298 for (
auto nIt = mIt; nIt != Neighbour.end(); ++nIt)
300 if (!labelCompare || cIt->label != nIt->label)
328 if ((ss1 >= cStart) && (ee2 <= cLast))
335 else if ((ss1 <= cStart) && (ee2 >= cLast))
342 else if ((ss1 <= cLast) && (ee2 >= cLast))
349 else if ((ss1 <= cStart) && (ee2 >= cStart))
359 callback(cIt, nIt, oStart, oLast);
360 if (sameLineOffset && oStart == cStart && oLast == cLast)
367 if (!sameLineOffset && ee1 >= cLast)
390 using PretendSizeType =
typename PretendImageType::RegionType::SizeType;
391 using PretendIndexType =
typename PretendImageType::RegionType::IndexType;
394 auto fakeImage = PretendImageType::New();
396 typename PretendImageType::RegionType LineRegion;
398 OutSizeType OutSize = output->GetRequestedRegion().GetSize();
400 PretendSizeType PretendSize;
402 for (
SizeValueType i = 0; i < PretendSize.GetSizeDimension(); ++i)
404 PretendSize[i] = OutSize[i + 1];
407 LineRegion.SetSize(PretendSize);
408 fakeImage->SetRegions(LineRegion);
409 auto kernelRadius = PretendSizeType::Filled(1);
410 LineNeighborhoodType lnit(kernelRadius, fakeImage, LineRegion);
412 if (wholeNeighborhood)
421 typename LineNeighborhoodType::IndexListType ActiveIndexes = lnit.GetActiveIndexList();
423 const PretendIndexType idx = LineRegion.GetIndex();
426 for (
auto LI = ActiveIndexes.begin(); LI != ActiveIndexes.end(); ++LI)
428 m_LineOffsets.push_back(fakeImage->ComputeOffset(idx + lnit.GetOffset(*LI)) - offset);
431 if (wholeNeighborhood)
448 const SizeValueType xsizeForThread = outputRegionForThread.GetSize()[0];
449 const SizeValueType numberOfLines = outputRegionForThread.GetNumberOfPixels() / xsizeForThread;
452 const SizeValueType lastLine = firstLine + numberOfLines - 1;
468 itkAssertInDebugAndIgnoreInReleaseMacro(lastLine >= wud.
lastLine);
479 if (neighIdx >= 0 && neighIdx < linecount && !
m_LineMap[neighIdx].empty())
Const version of ShapedNeighborhoodIterator, defining iteration of a local N-dimensional neighborhood...
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
typename TInputImage::IndexType IndexType
OffsetVectorType m_LineOffsets
typename OffsetVectorType::const_iterator OffsetVectorConstIterator
typename TOutputImage::SizeType OutputSizeType
typename TOutputImage::RegionType::SizeType OutSizeType
ImageToImageFilter< TInputImage, TOutputImage > EnclosingFilter
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
SmartPointer< Self > Pointer
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)
std::function< void(const LineEncodingConstIterator ¤tRun, const LineEncodingConstIterator &neighborRun, OffsetValueType oStart, OffsetValueType oLast)> CompareLinesCallback
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
typename TOutputImage::IndexType OutputIndexType
OutputRegionType RegionType
std::atomic< SizeValueType > m_NumberOfLabels
typename TInputImage::PixelType InputPixelType
SmartPointer< const Self > ConstPointer
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 transparent reference counting.
Implements a weak reference to an object.
SmartPointer< Self > Pointer
#define itkConceptMacro(name, concept)
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)