18#ifndef itkShapeUniqueLabelMapFilter_h
19#define itkShapeUniqueLabelMapFilter_h
43template <
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));
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 typename TAttributeAccessor::AttributeValueType prevAttr = accessor(prev.
labelObject);
204 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 typename LabelObjectType::LabelType label = it.GetLabel();
313 if (labelObject->Empty())
318 this->GetLabelMap()->RemoveLabel(label);
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"
Base class for filters that takes an image as input and overwrites that image as the output.
Control indentation during Print() invocation.
Light weight base class for most itk classes.
Implements progress tracking for a filter.
bool operator()(const LineOfLabelObject &lla, const LineOfLabelObject &llb)
Remove some pixels in the label object according to the value of their shape attribute to ensure that...
ShapeUniqueLabelMapFilter()
typename ImageType::IndexType IndexType
typename ImageType::PixelType PixelType
void GenerateData() override
void TemplatedGenerateData(const TAttributeAccessor &accessor)
void PrintSelf(std::ostream &os, Indent indent) const override
typename LabelObjectType::AttributeType AttributeType
typename ImageType::Pointer ImagePointer
void SetAttribute(const std::string &s)
typename ImageType::ConstPointer ImageConstPointer
typename LabelObjectType::LineType LineType
typename ImageType::LabelObjectType LabelObjectType
~ShapeUniqueLabelMapFilter() override=default
SmartPointer< const Self > ConstPointer
SmartPointer< Self > Pointer
ImageBaseType::IndexType IndexType
bool ExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Return the result of an exact comparison between two scalar values of potentially different types.
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
LineOfLabelObject(const LineType _line, LabelObjectType *_lo)
typename LabelObjectType::LineType LineType
LabelObjectType * labelObject