18 #ifndef __itkShapeUniqueLabelMapFilter_h
19 #define __itkShapeUniqueLabelMapFilter_h
40 template<
class TImage >
58 typedef typename LabelObjectType::LineType
LineType;
63 itkStaticConstMacro(ImageDimension,
unsigned int,
64 TImage::ImageDimension);
73 #ifdef ITK_USE_CONCEPT_CHECKING
91 itkGetConstMacro(ReverseOrdering,
bool);
92 itkSetMacro(ReverseOrdering,
bool);
93 itkBooleanMacro(ReverseOrdering);
102 void SetAttribute(
const std::string & s)
104 this->SetAttribute( LabelObjectType::GetAttributeFromName(s) );
114 template<
class TAttributeAccessor >
115 void TemplatedGenerateData(
const TAttributeAccessor & accessor)
118 this->AllocateOutputs();
121 typedef typename std::priority_queue< LineOfLabelObject, std::vector< LineOfLabelObject >,
123 PriorityQueueType pq;
128 for (
typename ImageType::Iterator it2( this->GetLabelMap() );
137 typename LabelObjectType::ConstLineIterator lit( lo );
138 while( ! lit.IsAtEnd() )
157 typedef typename std::deque< LineOfLabelObject > LinesType;
160 lines.push_back( pq.top() );
165 while ( !pq.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);
204 if ( attr == prevAttr )
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 (
unsigned int 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 void PrintSelf(std::ostream & os,
Indent indent)
const;
323 void operator=(
const Self &);
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"