17 #ifndef __itkShapeUniqueLabelMapFilter_h
18 #define __itkShapeUniqueLabelMapFilter_h
36 template<
class TImage>
54 typedef typename LabelObjectType::LineType
LineType;
59 itkStaticConstMacro(ImageDimension,
unsigned int,
60 TImage::ImageDimension);
69 #ifdef ITK_USE_CONCEPT_CHECKING
86 itkGetConstMacro( ReverseOrdering,
bool );
87 itkSetMacro( ReverseOrdering,
bool );
88 itkBooleanMacro( ReverseOrdering );
96 void SetAttribute(
const std::string & s )
98 this->SetAttribute( LabelObjectType::GetAttributeFromName( s ) );
108 template <
class TAttributeAccessor>
109 void TemplatedGenerateData(
const TAttributeAccessor & accessor )
112 this->AllocateOutputs();
115 typedef typename std::priority_queue< LineOfLabelObject, std::vector<LineOfLabelObject>,
LineOfLabelObjectComparator > PriorityQueueType;
116 PriorityQueueType pq;
121 typedef typename ImageType::LabelObjectContainerType LabelObjectsType;
123 const LabelObjectsType & labelObjects = this->GetLabelMap()->GetLabelObjectContainer();
124 for(
typename LabelObjectsType::const_iterator it2 = labelObjects.begin();
125 it2 != labelObjects.end();
133 typename LabelObjectType::LineContainerType::const_iterator lit;
134 typename LabelObjectType::LineContainerType & lineContainer = lo->GetLineContainer();
136 for( lit = lineContainer.begin(); lit != lineContainer.end(); lit++ )
142 lineContainer.clear();
154 typedef typename std::deque<LineOfLabelObject> LinesType;
157 lines.push_back( pq.top() );
168 bool newMainLine =
false;
170 for(
int i=1; i<ImageDimension; i++ )
172 if( idx[i] != prevIdx[i] )
181 lines.push_back( l );
185 unsigned long prevLength = prev.
line.GetLength();
186 unsigned long length = l.
line.GetLength();
188 if( prevIdx[0] + (
long)prevLength >= idx[0] )
195 typename TAttributeAccessor::AttributeValueType prevAttr = accessor( prev.
labelObject );
196 typename TAttributeAccessor::AttributeValueType attr = accessor( l.
labelObject );
198 if( attr == prevAttr )
202 keepCurrent = !m_ReverseOrdering;
206 keepCurrent = m_ReverseOrdering;
211 if( attr > prevAttr )
213 keepCurrent = !m_ReverseOrdering;
217 keepCurrent = m_ReverseOrdering;
226 if( prevIdx[0] + prevLength > idx[0] + length )
231 newIdx[0] = idx[0] + length;
232 unsigned long newLength = prevIdx[0] + prevLength - newIdx[0];
236 prevLength = idx[0] - prevIdx[0];
237 if( prevLength != 0 )
239 lines.back().line.SetLength( idx[0] - prevIdx[0] );
247 lines.push_back( l );
253 if( prevIdx[0] + prevLength > idx[0] + length )
260 newIdx[0] = prevIdx[0] + prevLength;
261 unsigned long newLength = idx[0] + length - newIdx[0];
262 l.
line.SetIndex( newIdx );
263 l.
line.SetLength( newLength );
264 lines.push_back( l );
272 lines.push_back( l );
278 prevIdx = prev.
line.GetIndex();
282 for(
unsigned int i=0; i<lines.size(); i++ )
289 typename LabelObjectsType::const_iterator it = labelObjects.begin();
290 while( it != labelObjects.end() )
292 typename LabelObjectType::LabelType label = it->first;
295 if( labelObject->Empty() )
299 this->GetLabelMap()->RemoveLabel( label );
309 void PrintSelf(std::ostream& os,
Indent indent)
const;
315 void operator=(
const Self&);
320 typedef typename LabelObjectType::LineType
LineType;
324 this->labelObject = _lo;
335 for(
int i=ImageDimension-1; i>=0; i-- )
337 if( lla.
line.GetIndex()[i] > llb.
line.GetIndex()[i] )
341 else if( lla.
line.GetIndex()[i] < llb.
line.GetIndex()[i] )
354 #ifndef ITK_MANUAL_INSTANTIATION