18 #ifndef itkScanlineFilterCommon_h
19 #define itkScanlineFilterCommon_h
41 template<
typename TInputImage,
typename TOutputImage >
63 if ( smartPtr ==
nullptr )
65 smartPtr =
new Self(
nullptr );
95 #ifdef ITK_USE_CONCEPT_CHECKING
147 itkAssertOrThrowMacro( requestedRegion.GetIndex( dim ) <= index[dim],
148 "Index must be within the requested region!" );
149 linearIndex += ( index[dim] - requestedRegion.GetIndex( dim ) ) * stride;
150 stride *= requestedRegion.GetSize( dim );
159 typename LineMapType::iterator MapBegin, MapEnd, LineIt;
164 for ( LineIt = MapBegin; LineIt != MapEnd; ++LineIt )
167 for ( cIt = LineIt->begin(); cIt != LineIt->end(); ++cIt )
188 std::lock_guard<std::mutex> mutexHolder(
m_Mutex);
212 for (
size_t i = 1; i < N; i++ )
214 const auto label =
static_cast< size_t >(
m_UnionFind[i] );
217 if ( consecutiveLabel == backgroundValue )
235 if ( Math::abs(A[i] - B[i]) > 1 )
254 bool sameLine = sameLineOffset;
255 if ( sameLineOffset )
277 mIt = Neighbour.begin();
279 for ( cIt = current.begin(); cIt != current.end(); ++cIt )
288 mIt = Neighbour.begin();
291 for ( nIt = mIt; nIt != Neighbour.end(); ++nIt )
293 if ( !labelCompare || cIt->label != nIt->label )
321 if ( ( ss1 >= cStart ) && ( ee2 <= cLast ) )
328 else if ( ( ss1 <= cStart ) && ( ee2 >= cLast ) )
335 else if ( ( ss1 <= cLast ) && ( ee2 >= cLast ) )
342 else if ( ( ss1 <= cStart ) && ( ee2 >= cStart ) )
352 callback(cIt, nIt, oStart, oLast);
353 if ( sameLineOffset && oStart == cStart && oLast == cLast )
360 if ( !sameLineOffset && ee1 >= cLast )
386 typename PretendImageType::Pointer fakeImage;
387 fakeImage = PretendImageType::New();
393 PretendSizeType PretendSize;
395 for (
SizeValueType i = 0; i < PretendSize.GetSizeDimension(); i++ )
397 PretendSize[i] = OutSize[i + 1];
400 LineRegion.
SetSize(PretendSize);
401 fakeImage->SetRegions(LineRegion);
402 PretendSizeType kernelRadius;
403 kernelRadius.Fill(1);
404 LineNeighborhoodType lnit(kernelRadius, fakeImage, LineRegion);
406 if (wholeNeighborhood)
415 typename LineNeighborhoodType::IndexListType ActiveIndexes;
416 ActiveIndexes = lnit.GetActiveIndexList();
418 typename LineNeighborhoodType::IndexListType::const_iterator LI;
420 PretendIndexType idx = LineRegion.GetIndex();
423 for ( LI = ActiveIndexes.begin(); LI != ActiveIndexes.end(); ++LI )
425 m_LineOffsets.push_back(fakeImage->ComputeOffset( idx + lnit.GetOffset(*LI) ) - offset);
428 if (wholeNeighborhood)
444 const SizeValueType xsizeForThread = outputRegionForThread.GetSize()[0];
445 const SizeValueType numberOfLines = outputRegionForThread.GetNumberOfPixels() / xsizeForThread;
448 const SizeValueType lastLine = firstLine + numberOfLines - 1;
463 itkAssertInDebugAndIgnoreInReleaseMacro( lastLine >= wud.
lastLine );
469 typename OffsetVectorType::const_iterator it = this->
m_LineOffsets.begin();
474 if ( neighIdx >= 0 && neighIdx < linecount && !
m_LineMap[neighIdx].empty() )
492 this->
LinkLabels(neighborRun->label, currentRun->label);
Const version of ShapedNeighborhoodIterator, defining iteration of a local N-dimensional neighborhood...
static constexpr unsigned int ImageDimension
void UnRegister() noexcept
typename TOutputImage::PixelType OutputPixelType
ScanlineFilterCommon(EnclosingFilter *enclosingFilter)
static constexpr unsigned int InputImageDimension
TIterator * setConnectivityPrevious(TIterator *it, bool fullyConnected=false)
SizeValueType IndexToLinearIndex(const IndexType &index) const
unsigned long SizeValueType
SizeValueType CreateConsecutive(OutputPixelType backgroundValue)
static constexpr unsigned int OutputImageDimension
typename TOutputImage::IndexType OutputIndexType
typename TOutputImage::RegionType OutputRegionType
typename LineEncodingType::iterator LineEncodingIterator
typename TOutputImage::PixelType OutputImagePixelType
std::vector< RunLength > LineEncodingType
std::function< void(const LineEncodingConstIterator ¤tRun, const LineEncodingConstIterator &neighborRun, OffsetValueType oStart, OffsetValueType oLast)> CompareLinesCallback
static T::Pointer Create()
void UnRegister() const noexceptoverride
TInputImage InputImageType
typename InputImageType::ConstPointer InputImageConstPointer
Implements a weak reference to an object.
RunLength(SizeValueType iLength, const IndexType &iWhere, InternalLabelType iLabel=0)
SizeValueType InternalLabelType
Helper class for a group of filters which operate on scan-lines.
typename TOutputImage::OffsetType OutputOffsetType
TIterator * setConnectivity(TIterator *it, bool fullyConnected=false)
void CompareLines(const LineEncodingType ¤t, const LineEncodingType &Neighbour, bool sameLineOffset, bool labelCompare, OutputPixelType background, CompareLinesCallback callback)
OutputRegionType RegionType
ImageBaseType::SizeType SizeType
typename OffsetVectorType::const_iterator OffsetVectorConstIterator
ImageBaseType::IndexType IndexType
void SetupLineOffsets(bool wholeNeighborhood)
WorkUnitData CreateWorkUnitData(const RegionType &outputRegionForThread)
const SizeType & GetSize() const
typename TInputImage::OffsetType OffsetType
~ScanlineFilterCommon()=default
void InitUnion(InternalLabelType numberOfLabels)
typename TOutputImage::RegionType::SizeType OutSizeType
std::vector< OutputPixelType > ConsecutiveVectorType
UnionFindType m_UnionFind
std::vector< OffsetValueType > OffsetVectorType
std::deque< WorkUnitData > m_WorkUnitResults
bool CheckNeighbors(const OutputIndexType &A, const OutputIndexType &B) const
typename TOutputImage::SizeType OutputSizeType
Base class for filters that take an image as input and produce an image as output.
void Register() const override
std::vector< LineEncodingType > LineMapType
void UnRegister() const noexcept
typename TInputImage::SizeType SizeType
void LinkLabels(const InternalLabelType label1, const InternalLabelType label2)
OffsetValueType ComputeOffset(const IndexType &ind) const
InputImageType::IndexType where
void ComputeEquivalence(const SizeValueType workUnitResultsIndex, bool strictlyLess)
typename LineEncodingType::const_iterator LineEncodingConstIterator
Base class for most ITK classes.
typename InputImageType::Pointer InputImagePointer
OffsetVectorType m_LineOffsets
ImageBaseType::RegionType RegionType
void SetSize(const SizeValueType val[VDimension])
TOutputImage OutputImageType
#define itkConceptMacro(name, concept)
typename TInputImage::PixelType InputPixelType
InternalLabelType LookupSet(const InternalLabelType label)
signed long OffsetValueType
typename TInputImage::IndexType IndexType
std::vector< InternalLabelType > UnionFindType
typename OutputImageType::Pointer OutputImagePointer
Templated n-dimensional image class.
std::atomic< SizeValueType > m_NumberOfLabels
WeakPointer< EnclosingFilter > m_EnclosingFilter
ScanlineFilterCommon Self
ConsecutiveVectorType m_Consecutive