18 #ifndef __itkShapeUniqueLabelMapFilter_h
19 #define __itkShapeUniqueLabelMapFilter_h
41 template<
class TImage >
59 typedef typename LabelObjectType::LineType
LineType;
64 itkStaticConstMacro(ImageDimension,
unsigned int,
65 TImage::ImageDimension);
74 #ifdef ITK_USE_CONCEPT_CHECKING
92 itkGetConstMacro(ReverseOrdering,
bool);
93 itkSetMacro(ReverseOrdering,
bool);
94 itkBooleanMacro(ReverseOrdering);
103 void SetAttribute(
const std::string & s)
105 this->SetAttribute( LabelObjectType::GetAttributeFromName(s) );
115 template<
class TAttributeAccessor >
116 void TemplatedGenerateData(
const TAttributeAccessor & accessor)
119 this->AllocateOutputs();
122 typedef typename std::priority_queue< LineOfLabelObject, std::vector< LineOfLabelObject >,
124 PriorityQueueType pq;
129 for (
typename ImageType::Iterator it2( this->GetLabelMap() );
138 typename LabelObjectType::ConstLineIterator lit( lo );
139 while( ! lit.IsAtEnd() )
158 typedef typename std::deque< LineOfLabelObject > LinesType;
161 lines.push_back( pq.top() );
166 while ( !pq.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);
205 if ( attr == prevAttr )
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 (
unsigned int 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;
325 void operator=(
const Self &);
329 typedef typename LabelObjectType::LineType
LineType;
333 this->labelObject = _lo;
345 for (
int i = ImageDimension - 1; i >= 0; i-- )
347 if ( lla.
line.GetIndex()[i] > llb.
line.GetIndex()[i] )
351 else if ( lla.
line.GetIndex()[i] < llb.
line.GetIndex()[i] )
362 #ifndef ITK_MANUAL_INSTANTIATION
363 #include "itkShapeUniqueLabelMapFilter.hxx"