18 #ifndef itkShapeUniqueLabelMapFilter_h
19 #define itkShapeUniqueLabelMapFilter_h
42 template<
typename TImage >
60 typedef typename LabelObjectType::LineType
LineType;
65 itkStaticConstMacro(ImageDimension,
unsigned int,
66 TImage::ImageDimension);
75 #ifdef ITK_USE_CONCEPT_CHECKING
91 itkGetConstMacro(ReverseOrdering,
bool);
92 itkSetMacro(ReverseOrdering,
bool);
93 itkBooleanMacro(ReverseOrdering);
104 this->SetAttribute( LabelObjectType::GetAttributeFromName(s) );
112 virtual void GenerateData() ITK_OVERRIDE;
114 template< typename TAttributeAccessor >
115 void TemplatedGenerateData(const TAttributeAccessor & accessor)
118 this->AllocateOutputs();
121 typedef typename std::priority_queue< LineOfLabelObject, std::vector< LineOfLabelObject >,
123 PriorityQueueType priorityQueue;
128 for (
typename ImageType::Iterator it( this->GetLabelMap() );
135 labelObject->Optimize();
137 typename LabelObjectType::ConstLineIterator lit( labelObject );
138 while( ! lit.IsAtEnd() )
145 labelObject->Clear();
151 if ( priorityQueue.empty() )
157 typedef typename std::deque< LineOfLabelObject > LinesType;
160 lines.push_back( priorityQueue.top() );
165 while ( !priorityQueue.empty() )
171 bool newMainLine =
false;
173 for (
unsigned int i = 1; i < ImageDimension; i++ )
175 if ( idx[i] != prevIdx[i] )
191 if ( prevIdx[0] + prevLength >= idx[0] )
200 typename TAttributeAccessor::AttributeValueType prevAttr = accessor(prev.
labelObject);
201 typename TAttributeAccessor::AttributeValueType attr = accessor(l.
labelObject);
208 keepCurrent = !m_ReverseOrdering;
212 keepCurrent = m_ReverseOrdering;
217 if ( attr > prevAttr )
219 keepCurrent = !m_ReverseOrdering;
223 keepCurrent = m_ReverseOrdering;
234 if ( prevIdx[0] + prevLength > idx[0] + length )
240 newIdx[0] = idx[0] + length;
245 prevLength = idx[0] - prevIdx[0];
246 if ( prevLength != 0 )
248 lines.back(). line.SetLength(idx[0] - prevIdx[0]);
263 if ( prevIdx[0] + prevLength > idx[0] + length )
270 newIdx[0] = prevIdx[0] + prevLength;
272 l.
line.SetIndex(newIdx);
273 l.
line.SetLength(newLength);
287 prevIdx = prev.
line.GetIndex();
291 for (
size_t i = 0; i < lines.size(); ++i )
298 typename ImageType::Iterator it( this->GetLabelMap() );
299 while ( ! it.IsAtEnd() )
301 typename LabelObjectType::LabelType label = it.GetLabel();
304 if ( labelObject->Empty() )
309 this->GetLabelMap()->RemoveLabel(label);
318 virtual void PrintSelf(std::ostream & os,
Indent indent)
const ITK_OVERRIDE;
327 typedef typename LabelObjectType::LineType
LineType;
331 this->labelObject = _lo;
343 for (
int i = ImageDimension - 1; i >= 0; i-- )
345 if ( lla.
line.GetIndex()[i] > llb.
line.GetIndex()[i] )
349 else if ( lla.
line.GetIndex()[i] < llb.
line.GetIndex()[i] )
360 #ifndef ITK_MANUAL_INSTANTIATION
361 #include "itkShapeUniqueLabelMapFilter.hxx"
bool operator()(const LineOfLabelObject &lla, const LineOfLabelObject &llb)
Light weight base class for most itk classes.
signed long OffsetValueType
LabelObjectType::LineType LineType
SmartPointer< Self > Pointer
bool ExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Return the result of an exact comparison between two scalar values of potetially different types...
ImageType::LabelObjectType LabelObjectType
ImageType::IndexType IndexType
ImageType::ConstPointer ImageConstPointer
Base class for filters that takes an image as input and overwrites that image as the output...
ImageType::Pointer ImagePointer
Remove some pixels in the label object according to the value of their shape attribute to ensure that...
SmartPointer< const Self > ConstPointer
LabelObjectType::LineType LineType
Implements progress tracking for a filter.
LabelObjectType * labelObject
LabelObjectType::AttributeType AttributeType
ImageType::PixelType PixelType
void SetAttribute(const std::string &s)
LineOfLabelObject(const LineType _line, LabelObjectType *_lo)
Control indentation during Print() invocation.
~ShapeUniqueLabelMapFilter() override
InPlaceLabelMapFilter< TImage > Superclass
AttributeType m_Attribute
ShapeUniqueLabelMapFilter Self
ImageBaseType::IndexType IndexType