ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkShapeOpeningLabelMapFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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:
50  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 SetAttribute(const std::string & s)
116  {
117  this->SetAttribute( LabelObjectType::GetAttributeFromName(s) );
118  }
120 
121 protected:
123  ~ShapeOpeningLabelMapFilter() override = default;
124 
125  void GenerateData() override;
126 
127  template< typename TAttributeAccessor >
128  void TemplatedGenerateData(const TAttributeAccessor & accessor)
129  {
130  // Allocate the output
131  this->AllocateOutputs();
132 
133  ImageType *output = this->GetOutput();
134  ImageType *output2 = this->GetOutput(1);
135  itkAssertInDebugAndIgnoreInReleaseMacro(this->GetNumberOfIndexedOutputs() == 2);
136  itkAssertInDebugAndIgnoreInReleaseMacro(output2 != nullptr);
137 
138  // set the background value for the second output - this is not done in the
139  // superclasses
140  output2->SetBackgroundValue( output->GetBackgroundValue() );
141 
142  ProgressReporter progress( this, 0, output->GetNumberOfLabelObjects() );
143 
144  typename ImageType::Iterator it( output );
145  while ( ! it.IsAtEnd() )
146  {
147  typename LabelObjectType::LabelType label = it.GetLabel();
148  LabelObjectType *labelObject = it.GetLabelObject();
149 
150  if ( ( !m_ReverseOrdering && accessor(labelObject) < m_Lambda )
151  || ( m_ReverseOrdering && accessor(labelObject) > m_Lambda ) )
152  {
153  // must increment the iterator before removing the object to avoid
154  // invalidating the iterator
155  ++it;
156  output2->AddLabelObject(labelObject);
157  output->RemoveLabel(label);
158  }
159  else
160  {
161  ++it;
162  }
163 
164  progress.CompletedPixel();
165  }
166  }
167 
168  void PrintSelf(std::ostream & os, Indent indent) const override;
169 
170  double m_Lambda;
171 
173 
175 }; // end of class
176 } // end namespace itk
177 
178 #ifndef ITK_MANUAL_INSTANTIATION
179 #include "itkShapeOpeningLabelMapFilter.hxx"
180 #endif
181 
182 #endif
typename LabelObjectType::AttributeType AttributeType
Light weight base class for most itk classes.
typename ImageType::LabelObjectType LabelObjectType
typename ImageType::ConstPointer ImageConstPointer
Remove objects according to the value of their shape attribute.
Base class for filters that takes an image as input and overwrites that image as the output...
typename ImageType::IndexType IndexType
Implements progress tracking for a filter.
void TemplatedGenerateData(const TAttributeAccessor &accessor)
Control indentation during Print() invocation.
Definition: itkIndent.h:49
typename ImageType::PixelType PixelType