18 #ifndef __itkShapeKeepNObjectsLabelMapFilter_h
19 #define __itkShapeKeepNObjectsLabelMapFilter_h
43 template<
class TImage >
65 itkStaticConstMacro(ImageDimension,
unsigned int, TImage::ImageDimension);
73 #ifdef ITK_USE_CONCEPT_CHECKING
90 itkSetMacro(ReverseOrdering,
bool);
91 itkGetConstReferenceMacro(ReverseOrdering,
bool);
92 itkBooleanMacro(ReverseOrdering);
110 void SetAttribute(
const std::string & s)
112 this->SetAttribute( LabelObjectType::GetAttributeFromName(s) );
121 template<
class TAttributeAccessor >
122 void TemplatedGenerateData(
const TAttributeAccessor &)
125 this->AllocateOutputs();
132 output2->SetBackgroundValue( output->GetBackgroundValue() );
134 typedef typename LabelObjectType::Pointer LabelObjectPointer;
135 typedef std::vector< LabelObjectPointer > VectorType;
137 ProgressReporter progress(
this, 0, 2 * output->GetNumberOfLabelObjects() );
140 VectorType labelObjects;
141 labelObjects.reserve( output->GetNumberOfLabelObjects() );
142 typename ImageType::Iterator it( output );
143 while ( ! it.IsAtEnd() )
145 labelObjects.push_back( it.GetLabelObject() );
146 progress.CompletedPixel();
151 if ( m_NumberOfObjects < output->GetNumberOfLabelObjects() )
153 typename VectorType::iterator end = labelObjects.begin() + m_NumberOfObjects;
154 if ( m_ReverseOrdering )
157 std::nth_element(labelObjects.begin(), end, labelObjects.end(), comparator);
162 std::nth_element(labelObjects.begin(), end, labelObjects.end(), comparator);
164 progress.CompletedPixel();
167 for (
typename VectorType::const_iterator it2 = end;
168 it2 != labelObjects.end();
171 output2->AddLabelObject(*it2);
172 output->RemoveLabelObject(*it2);
173 progress.CompletedPixel();
178 void PrintSelf(std::ostream & os,
Indent indent)
const;
186 void operator=(
const Self &);
190 #ifndef ITK_MANUAL_INSTANTIATION
191 #include "itkShapeKeepNObjectsLabelMapFilter.hxx"