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 {
48 template <typename TImage>
49 class ITK_TEMPLATE_EXPORT ShapeOpeningLabelMapFilter : public InPlaceLabelMapFilter<TImage>
50 {
51 public:
52  ITK_DISALLOW_COPY_AND_MOVE(ShapeOpeningLabelMapFilter);
53 
59 
61  using ImageType = TImage;
62  using ImagePointer = typename ImageType::Pointer;
63  using ImageConstPointer = typename ImageType::ConstPointer;
64  using PixelType = typename ImageType::PixelType;
65  using IndexType = typename ImageType::IndexType;
66  using LabelObjectType = typename ImageType::LabelObjectType;
67 
68  using AttributeType = typename LabelObjectType::AttributeType;
69 
71  static constexpr unsigned int ImageDimension = TImage::ImageDimension;
72 
74  itkNewMacro(Self);
75 
78 
79 #ifdef ITK_USE_CONCEPT_CHECKING
80  // Begin concept checking
81 /* itkConceptMacro(InputEqualityComparableCheck,
82  (Concept::EqualityComparable<InputImagePixelType>));
83  itkConceptMacro(IntConvertibleToInputCheck,
84  (Concept::Convertible<int, InputImagePixelType>));
85  itkConceptMacro(InputOStreamWritableCheck,
86  (Concept::OStreamWritable<InputImagePixelType>));*/
87 // End concept checking
88 #endif
89 
93  itkGetConstMacro(Lambda, double);
94  itkSetMacro(Lambda, double);
96 
103  itkGetConstMacro(ReverseOrdering, bool);
104  itkSetMacro(ReverseOrdering, bool);
105  itkBooleanMacro(ReverseOrdering);
107 
112  itkGetConstMacro(Attribute, AttributeType);
113  itkSetMacro(Attribute, AttributeType);
114  void
115  SetAttribute(const std::string & s)
116  {
117  this->SetAttribute(LabelObjectType::GetAttributeFromName(s));
118  }
120 
121 protected:
123  ~ShapeOpeningLabelMapFilter() override = default;
124 
125  void
126  GenerateData() override;
127 
128  template <typename TAttributeAccessor>
129  void
130  TemplatedGenerateData(const TAttributeAccessor & accessor)
131  {
132  // Allocate the output
133  this->AllocateOutputs();
134 
135  ImageType * output = this->GetOutput();
136  ImageType * output2 = this->GetOutput(1);
137  itkAssertInDebugAndIgnoreInReleaseMacro(this->GetNumberOfIndexedOutputs() == 2);
138  itkAssertInDebugAndIgnoreInReleaseMacro(output2 != nullptr);
139 
140  // set the background value for the second output - this is not done in the
141  // superclasses
142  output2->SetBackgroundValue(output->GetBackgroundValue());
143 
144  ProgressReporter progress(this, 0, output->GetNumberOfLabelObjects());
145 
146  typename ImageType::Iterator it(output);
147  while (!it.IsAtEnd())
148  {
149  typename LabelObjectType::LabelType label = it.GetLabel();
150  LabelObjectType * labelObject = it.GetLabelObject();
151 
152  if ((!m_ReverseOrdering && accessor(labelObject) < m_Lambda) ||
153  (m_ReverseOrdering && accessor(labelObject) > m_Lambda))
154  {
155  // must increment the iterator before removing the object to avoid
156  // invalidating the iterator
157  ++it;
158  output2->AddLabelObject(labelObject);
159  output->RemoveLabel(label);
160  }
161  else
162  {
163  ++it;
164  }
165 
166  progress.CompletedPixel();
167  }
168  }
169 
170  void
171  PrintSelf(std::ostream & os, Indent indent) const override;
172 
173  double m_Lambda;
174 
176 
178 }; // end of class
179 } // end namespace itk
180 
181 #ifndef ITK_MANUAL_INSTANTIATION
182 # include "itkShapeOpeningLabelMapFilter.hxx"
183 #endif
184 
185 #endif
itk::ShapeOpeningLabelMapFilter::ImagePointer
typename ImageType::Pointer ImagePointer
Definition: itkShapeOpeningLabelMapFilter.h:62
itk::ShapeOpeningLabelMapFilter::SetAttribute
void SetAttribute(const std::string &s)
Definition: itkShapeOpeningLabelMapFilter.h:115
itk::ShapeOpeningLabelMapFilter::ImageType
TImage ImageType
Definition: itkShapeOpeningLabelMapFilter.h:61
itk::ShapeOpeningLabelMapFilter::TemplatedGenerateData
void TemplatedGenerateData(const TAttributeAccessor &accessor)
Definition: itkShapeOpeningLabelMapFilter.h:130
itk::InPlaceLabelMapFilter
Base class for filters that takes an image as input and overwrites that image as the output.
Definition: itkInPlaceLabelMapFilter.h:83
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:177
itk::ShapeOpeningLabelMapFilter::PixelType
typename ImageType::PixelType PixelType
Definition: itkShapeOpeningLabelMapFilter.h:64
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:63
itkInPlaceLabelMapFilter.h
itk::ShapeOpeningLabelMapFilter::LabelObjectType
typename ImageType::LabelObjectType LabelObjectType
Definition: itkShapeOpeningLabelMapFilter.h:66
itk::ShapeOpeningLabelMapFilter
Remove objects according to the value of their shape attribute.
Definition: itkShapeOpeningLabelMapFilter.h:49
itk::ShapeOpeningLabelMapFilter::IndexType
typename ImageType::IndexType IndexType
Definition: itkShapeOpeningLabelMapFilter.h:65
itk::ShapeOpeningLabelMapFilter::m_Lambda
double m_Lambda
Definition: itkShapeOpeningLabelMapFilter.h:173
itk::ShapeOpeningLabelMapFilter::AttributeType
typename LabelObjectType::AttributeType AttributeType
Definition: itkShapeOpeningLabelMapFilter.h:68
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:175
itk::ProgressReporter
Implements progress tracking for a filter.
Definition: itkProgressReporter.h:60