18 #ifndef itkShapeKeepNObjectsLabelMapFilter_h
19 #define itkShapeKeepNObjectsLabelMapFilter_h
43 template<
typename TImage >
65 itkStaticConstMacro(ImageDimension,
unsigned int, TImage::ImageDimension);
73 #ifdef ITK_USE_CONCEPT_CHECKING
89 itkSetMacro(ReverseOrdering,
bool);
90 itkGetConstReferenceMacro(ReverseOrdering,
bool);
91 itkBooleanMacro(ReverseOrdering);
111 this->SetAttribute( LabelObjectType::GetAttributeFromName(s) );
118 void GenerateData() ITK_OVERRIDE;
120 template< typename TAttributeAccessor >
121 void TemplatedGenerateData(const TAttributeAccessor &)
124 this->AllocateOutputs();
131 output2->SetBackgroundValue( output->GetBackgroundValue() );
133 typedef typename LabelObjectType::Pointer LabelObjectPointer;
134 typedef std::vector< LabelObjectPointer >
VectorType;
136 ProgressReporter progress(
this, 0, 2 * output->GetNumberOfLabelObjects() );
139 VectorType labelObjects;
140 labelObjects.reserve( output->GetNumberOfLabelObjects() );
141 typename ImageType::Iterator it( output );
142 while ( ! it.IsAtEnd() )
144 labelObjects.push_back( it.GetLabelObject() );
145 progress.CompletedPixel();
150 if ( m_NumberOfObjects < output->GetNumberOfLabelObjects() )
152 typename VectorType::iterator end = labelObjects.begin() + m_NumberOfObjects;
153 if ( m_ReverseOrdering )
156 std::nth_element(labelObjects.begin(), end, labelObjects.end(), comparator);
161 std::nth_element(labelObjects.begin(), end, labelObjects.end(), comparator);
163 progress.CompletedPixel();
166 for (
typename VectorType::const_iterator it2 = end;
167 it2 != labelObjects.end();
170 output2->AddLabelObject(*it2);
171 output->RemoveLabelObject(*it2);
172 progress.CompletedPixel();
177 void PrintSelf(std::ostream & os,
Indent indent)
const ITK_OVERRIDE;
189 #ifndef ITK_MANUAL_INSTANTIATION
190 #include "itkShapeKeepNObjectsLabelMapFilter.hxx"
ImageType::ConstPointer ImageConstPointer
Light weight base class for most itk classes.
InPlaceLabelMapFilter< TImage > Superclass
SizeValueType m_NumberOfObjects
unsigned long SizeValueType
ImageBaseType::SpacingType VectorType
Base class for filters that takes an image as input and overwrites that image as the output...
ImageType::Pointer ImagePointer
Implements progress tracking for a filter.
Keep N objects according to their shape attributes.
LabelObjectType::AttributeType AttributeType
AttributeType m_Attribute
SmartPointer< Self > Pointer
void SetAttribute(const std::string &s)
ImageType::IndexType IndexType
SmartPointer< const Self > ConstPointer
Control indentation during Print() invocation.
ImageType::LabelObjectType LabelObjectType
~ShapeKeepNObjectsLabelMapFilter() override
ShapeKeepNObjectsLabelMapFilter Self
ImageType::PixelType PixelType
ImageBaseType::IndexType IndexType