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])
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);
325 bool m_ReverseOrdering{};
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"
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