18 #ifndef itkShapeUniqueLabelMapFilter_h
19 #define itkShapeUniqueLabelMapFilter_h
43 template <
typename TImage>
62 using LineType =
typename LabelObjectType::LineType;
67 static constexpr
unsigned int ImageDimension = TImage::ImageDimension;
75 #ifdef ITK_USE_CONCEPT_CHECKING
91 itkGetConstMacro(ReverseOrdering,
bool);
92 itkSetMacro(ReverseOrdering,
bool);
93 itkBooleanMacro(ReverseOrdering);
105 this->SetAttribute(LabelObjectType::GetAttributeFromName(s));
114 GenerateData()
override;
116 template <
typename TAttributeAccessor>
121 this->AllocateOutputs();
124 using PriorityQueueType =
126 PriorityQueueType priorityQueue;
131 for (
typename ImageType::Iterator it(this->GetLabelMap()); !it.IsAtEnd(); ++it)
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])
182 assert(newMainLine || (idx[0] >= prevIdx[0]));
194 if (prevIdx[0] + prevLength > idx[0])
203 const typename TAttributeAccessor::AttributeValueType prevAttr = accessor(prev.
labelObject);
204 const typename TAttributeAccessor::AttributeValueType attr = accessor(l.
labelObject);
211 keepCurrent = !m_ReverseOrdering;
215 keepCurrent = m_ReverseOrdering;
222 keepCurrent = !m_ReverseOrdering;
226 keepCurrent = m_ReverseOrdering;
237 if (prevIdx[0] + prevLength > idx[0] + length)
243 newIdx[0] = idx[0] + length;
248 prevLength = idx[0] - prevIdx[0];
251 assert(prevIdx[0] <= idx[0]);
252 lines.back().line.SetLength(idx[0] - prevIdx[0]);
267 if (prevIdx[0] + prevLength >= idx[0] + length)
274 newIdx[0] = prevIdx[0] + prevLength;
278 l.
line.SetIndex(newIdx);
279 l.
line.SetLength(newLength);
282 priorityQueue.push(l);
296 prevIdx = prev.
line.GetIndex();
300 for (
size_t i = 0; i < lines.size(); ++i)
307 typename ImageType::Iterator it(this->GetLabelMap());
308 while (!it.IsAtEnd())
310 const typename LabelObjectType::LabelType label = it.GetLabel();
313 if (labelObject->Empty())
318 this->GetLabelMap()->RemoveLabel(label);
328 PrintSelf(std::ostream & os,
Indent indent)
const override;
333 bool m_ReverseOrdering{};
336 using LineType =
typename LabelObjectType::LineType;
340 this->labelObject = _lo;
353 for (
int i = ImageDimension - 1; i >= 0; i--)
355 if (lla.
line.GetIndex()[i] > llb.
line.GetIndex()[i])
359 else if (lla.
line.GetIndex()[i] < llb.
line.GetIndex()[i])
370 #ifndef ITK_MANUAL_INSTANTIATION
371 # include "itkShapeUniqueLabelMapFilter.hxx"