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])
192 if (prevIdx[0] + prevLength >= idx[0])
201 typename TAttributeAccessor::AttributeValueType prevAttr = accessor(prev.
labelObject);
202 typename TAttributeAccessor::AttributeValueType attr = accessor(l.
labelObject);
209 keepCurrent = !m_ReverseOrdering;
213 keepCurrent = m_ReverseOrdering;
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];
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 (
size_t 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);
320 PrintSelf(std::ostream & os,
Indent indent)
const override;
328 using LineType =
typename LabelObjectType::LineType;
332 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"