ITK  5.2.0
Insight Toolkit
itkShapeOpeningLabelMapFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkShapeOpeningLabelMapFilter_h
19 #define itkShapeOpeningLabelMapFilter_h
20 
23 #include "itkProgressReporter.h"
24 
25 namespace itk
26 {
49 template <typename TImage>
50 class ITK_TEMPLATE_EXPORT ShapeOpeningLabelMapFilter : public InPlaceLabelMapFilter<TImage>
51 {
52 public:
53  ITK_DISALLOW_COPY_AND_ASSIGN(ShapeOpeningLabelMapFilter);
54 
60 
62  using ImageType = TImage;
63  using ImagePointer = typename ImageType::Pointer;
64  using ImageConstPointer = typename ImageType::ConstPointer;
65  using PixelType = typename ImageType::PixelType;
66  using IndexType = typename ImageType::IndexType;
67  using LabelObjectType = typename ImageType::LabelObjectType;
68 
69  using AttributeType = typename LabelObjectType::AttributeType;
70 
72  static constexpr unsigned int ImageDimension = TImage::ImageDimension;
73 
75  itkNewMacro(Self);
76 
79 
80 #ifdef ITK_USE_CONCEPT_CHECKING
81  // Begin concept checking
82 /* itkConceptMacro(InputEqualityComparableCheck,
83  (Concept::EqualityComparable<InputImagePixelType>));
84  itkConceptMacro(IntConvertibleToInputCheck,
85  (Concept::Convertible<int, InputImagePixelType>));
86  itkConceptMacro(InputOStreamWritableCheck,
87  (Concept::OStreamWritable<InputImagePixelType>));*/
88 // End concept checking
89 #endif
90 
94  itkGetConstMacro(Lambda, double);
95  itkSetMacro(Lambda, double);
97 
104  itkGetConstMacro(ReverseOrdering, bool);
105  itkSetMacro(ReverseOrdering, bool);
106  itkBooleanMacro(ReverseOrdering);
108 
113  itkGetConstMacro(Attribute, AttributeType);
114  itkSetMacro(Attribute, AttributeType);
115  void
116  SetAttribute(const std::string & s)
117  {
118  this->SetAttribute(LabelObjectType::GetAttributeFromName(s));
119  }
121 
122 protected:
124  ~ShapeOpeningLabelMapFilter() override = default;
125 
126  void
127  GenerateData() override;
128 
129  template <typename TAttributeAccessor>
130  void
131  TemplatedGenerateData(const TAttributeAccessor & accessor)
132  {
133  // Allocate the output
134  this->AllocateOutputs();
135 
136  ImageType * output = this->GetOutput();
137  ImageType * output2 = this->GetOutput(1);
138  itkAssertInDebugAndIgnoreInReleaseMacro(this->GetNumberOfIndexedOutputs() == 2);
139  itkAssertInDebugAndIgnoreInReleaseMacro(output2 != nullptr);
140 
141  // set the background value for the second output - this is not done in the
142  // superclasses
143  output2->SetBackgroundValue(output->GetBackgroundValue());
144 
145  ProgressReporter progress(this, 0, output->GetNumberOfLabelObjects());
146 
147  typename ImageType::Iterator it(output);
148  while (!it.IsAtEnd())
149  {
150  typename LabelObjectType::LabelType label = it.GetLabel();
151  LabelObjectType * labelObject = it.GetLabelObject();
152 
153  if ((!m_ReverseOrdering && accessor(labelObject) < m_Lambda) ||
154  (m_ReverseOrdering && accessor(labelObject) > m_Lambda))
155  {
156  // must increment the iterator before removing the object to avoid
157  // invalidating the iterator
158  ++it;
159  output2->AddLabelObject(labelObject);
160  output->RemoveLabel(label);
161  }
162  else
163  {
164  ++it;
165  }
166 
167  progress.CompletedPixel();
168  }
169  }
170 
171  void
172  PrintSelf(std::ostream & os, Indent indent) const override;
173 
174  double m_Lambda;
175 
177 
179 }; // end of class
180 } // end namespace itk
181 
182 #ifndef ITK_MANUAL_INSTANTIATION
183 # include "itkShapeOpeningLabelMapFilter.hxx"
184 #endif
185 
186 #endif
itk::ShapeOpeningLabelMapFilter::ImagePointer
typename ImageType::Pointer ImagePointer
Definition: itkShapeOpeningLabelMapFilter.h:63
itk::ShapeOpeningLabelMapFilter::SetAttribute
void SetAttribute(const std::string &s)
Definition: itkShapeOpeningLabelMapFilter.h:116
itk::ShapeOpeningLabelMapFilter::ImageType
TImage ImageType
Definition: itkShapeOpeningLabelMapFilter.h:62
itk::ShapeOpeningLabelMapFilter::TemplatedGenerateData
void TemplatedGenerateData(const TAttributeAccessor &accessor)
Definition: itkShapeOpeningLabelMapFilter.h:131
itk::InPlaceLabelMapFilter
Base class for filters that takes an image as input and overwrites that image as the output.
Definition: itkInPlaceLabelMapFilter.h:84
itkProgressReporter.h
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itkShapeLabelObjectAccessors.h
itk::ShapeOpeningLabelMapFilter::m_Attribute
AttributeType m_Attribute
Definition: itkShapeOpeningLabelMapFilter.h:178
itk::ShapeOpeningLabelMapFilter::PixelType
typename ImageType::PixelType PixelType
Definition: itkShapeOpeningLabelMapFilter.h:65
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::ShapeOpeningLabelMapFilter::ImageConstPointer
typename ImageType::ConstPointer ImageConstPointer
Definition: itkShapeOpeningLabelMapFilter.h:64
itkInPlaceLabelMapFilter.h
itk::ShapeOpeningLabelMapFilter::LabelObjectType
typename ImageType::LabelObjectType LabelObjectType
Definition: itkShapeOpeningLabelMapFilter.h:67
itk::ShapeOpeningLabelMapFilter
Remove objects according to the value of their shape attribute.
Definition: itkShapeOpeningLabelMapFilter.h:50
itk::ShapeOpeningLabelMapFilter::IndexType
typename ImageType::IndexType IndexType
Definition: itkShapeOpeningLabelMapFilter.h:66
itk::ShapeOpeningLabelMapFilter::m_Lambda
double m_Lambda
Definition: itkShapeOpeningLabelMapFilter.h:174
itk::ShapeOpeningLabelMapFilter::AttributeType
typename LabelObjectType::AttributeType AttributeType
Definition: itkShapeOpeningLabelMapFilter.h:69
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::ShapeOpeningLabelMapFilter::m_ReverseOrdering
bool m_ReverseOrdering
Definition: itkShapeOpeningLabelMapFilter.h:176
itk::ProgressReporter
Implements progress tracking for a filter.
Definition: itkProgressReporter.h:60