18 #ifndef itkShapeKeepNObjectsLabelMapFilter_h
19 #define itkShapeKeepNObjectsLabelMapFilter_h
43 template<
typename TImage >
67 static constexpr
unsigned int ImageDimension = TImage::ImageDimension;
75 #ifdef ITK_USE_CONCEPT_CHECKING
91 itkSetMacro(ReverseOrdering,
bool);
92 itkGetConstReferenceMacro(ReverseOrdering,
bool);
93 itkBooleanMacro(ReverseOrdering);
113 this->SetAttribute( LabelObjectType::GetAttributeFromName(s) );
120 void GenerateData()
override;
122 template<
typename TAttributeAccessor >
126 this->AllocateOutputs();
133 output2->SetBackgroundValue( output->GetBackgroundValue() );
135 using LabelObjectPointer =
typename LabelObjectType::Pointer;
136 using VectorType = std::vector< LabelObjectPointer >;
138 ProgressReporter progress(
this, 0, 2 * output->GetNumberOfLabelObjects() );
142 labelObjects.reserve( output->GetNumberOfLabelObjects() );
143 typename ImageType::Iterator it( output );
144 while ( ! it.IsAtEnd() )
146 labelObjects.push_back( it.GetLabelObject() );
147 progress.CompletedPixel();
152 if ( m_NumberOfObjects < output->GetNumberOfLabelObjects() )
154 auto end = labelObjects.begin() + m_NumberOfObjects;
155 if ( m_ReverseOrdering )
158 std::nth_element(labelObjects.begin(), end, labelObjects.end(), comparator);
163 std::nth_element(labelObjects.begin(), end, labelObjects.end(), comparator);
165 progress.CompletedPixel();
168 for (
typename VectorType::const_iterator it2 = end;
169 it2 != labelObjects.end();
172 output2->AddLabelObject(*it2);
173 output->RemoveLabelObject(*it2);
174 progress.CompletedPixel();
179 void PrintSelf(std::ostream & os,
Indent indent)
const override;
188 #ifndef ITK_MANUAL_INSTANTIATION
189 #include "itkShapeKeepNObjectsLabelMapFilter.hxx"
Light weight base class for most itk classes.
unsigned long SizeValueType
SizeValueType m_NumberOfObjects
void TemplatedGenerateData(const TAttributeAccessor &)
typename ImageType::PixelType PixelType
ImageBaseType::IndexType IndexType
Base class for filters that takes an image as input and overwrites that image as the output...
typename ImageType::LabelObjectType LabelObjectType
Implements progress tracking for a filter.
Keep N objects according to their shape attributes.
typename LabelObjectType::AttributeType AttributeType
typename ImageType::IndexType IndexType
AttributeType m_Attribute
void SetAttribute(const std::string &s)
Control indentation during Print() invocation.
typename ImageType::ConstPointer ImageConstPointer
ImageBaseType::SpacingType VectorType
typename ImageType::Pointer ImagePointer