18 #ifndef itkShapeUniqueLabelMapFilter_h
19 #define itkShapeUniqueLabelMapFilter_h
42 template<
typename TImage >
62 using LineType =
typename LabelObjectType::LineType;
67 static constexpr
unsigned int ImageDimension = TImage::ImageDimension;
76 #ifdef ITK_USE_CONCEPT_CHECKING
92 itkGetConstMacro(ReverseOrdering,
bool);
93 itkSetMacro(ReverseOrdering,
bool);
94 itkBooleanMacro(ReverseOrdering);
105 this->SetAttribute( LabelObjectType::GetAttributeFromName(s) );
113 void GenerateData()
override;
115 template<
typename TAttributeAccessor >
119 this->AllocateOutputs();
122 using PriorityQueueType =
typename std::priority_queue< LineOfLabelObject, std::vector< LineOfLabelObject >,
124 PriorityQueueType priorityQueue;
129 for (
typename ImageType::Iterator it( this->GetLabelMap() );
136 labelObject->Optimize();
138 typename LabelObjectType::ConstLineIterator lit( labelObject );
139 while( ! lit.IsAtEnd() )
146 labelObject->Clear();
152 if ( priorityQueue.empty() )
158 using LinesType =
typename std::deque< LineOfLabelObject >;
161 lines.push_back( priorityQueue.top() );
166 while ( !priorityQueue.empty() )
172 bool newMainLine =
false;
174 for (
unsigned int i = 1; i < ImageDimension; i++ )
176 if ( idx[i] != prevIdx[i] )
192 if ( prevIdx[0] + prevLength >= idx[0] )
201 typename TAttributeAccessor::AttributeValueType prevAttr = accessor(prev.
labelObject);
202 typename TAttributeAccessor::AttributeValueType attr = accessor(l.
labelObject);
209 keepCurrent = !m_ReverseOrdering;
213 keepCurrent = m_ReverseOrdering;
218 if ( attr > prevAttr )
220 keepCurrent = !m_ReverseOrdering;
224 keepCurrent = m_ReverseOrdering;
235 if ( prevIdx[0] + prevLength > idx[0] + length )
241 newIdx[0] = idx[0] + length;
246 prevLength = idx[0] - prevIdx[0];
247 if ( prevLength != 0 )
249 lines.back(). line.SetLength(idx[0] - prevIdx[0]);
264 if ( prevIdx[0] + prevLength > idx[0] + length )
271 newIdx[0] = prevIdx[0] + prevLength;
273 l.
line.SetIndex(newIdx);
274 l.
line.SetLength(newLength);
288 prevIdx = prev.
line.GetIndex();
292 for (
size_t i = 0; i < lines.size(); ++i )
299 typename ImageType::Iterator it( this->GetLabelMap() );
300 while ( ! it.IsAtEnd() )
302 typename LabelObjectType::LabelType label = it.GetLabel();
305 if ( labelObject->Empty() )
310 this->GetLabelMap()->RemoveLabel(label);
319 void PrintSelf(std::ostream & os,
Indent indent)
const override;
326 using LineType =
typename LabelObjectType::LineType;
330 this->labelObject = _lo;
342 for (
int i = ImageDimension - 1; i >= 0; i-- )
344 if ( lla.
line.GetIndex()[i] > llb.
line.GetIndex()[i] )
348 else if ( lla.
line.GetIndex()[i] < llb.
line.GetIndex()[i] )
359 #ifndef ITK_MANUAL_INSTANTIATION
360 #include "itkShapeUniqueLabelMapFilter.hxx"
bool operator()(const LineOfLabelObject &lla, const LineOfLabelObject &llb)
Light weight base class for most itk classes.
typename ImageType::PixelType PixelType
bool ExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Return the result of an exact comparison between two scalar values of potetially different types...
typename LabelObjectType::LineType LineType
typename ImageType::LabelObjectType LabelObjectType
ImageBaseType::IndexType IndexType
Base class for filters that takes an image as input and overwrites that image as the output...
typename ImageType::IndexType IndexType
Remove some pixels in the label object according to the value of their shape attribute to ensure that...
typename LabelObjectType::AttributeType AttributeType
typename LabelObjectType::LineType LineType
Implements progress tracking for a filter.
LabelObjectType * labelObject
typename ImageType::ConstPointer ImageConstPointer
void TemplatedGenerateData(const TAttributeAccessor &accessor)
void SetAttribute(const std::string &s)
LineOfLabelObject(const LineType _line, LabelObjectType *_lo)
Control indentation during Print() invocation.
typename ImageType::Pointer ImagePointer
signed long OffsetValueType
AttributeType m_Attribute