ITK  4.13.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:
58 
60  typedef TImage ImageType;
61  typedef typename ImageType::Pointer ImagePointer;
62  typedef typename ImageType::ConstPointer ImageConstPointer;
63  typedef typename ImageType::PixelType PixelType;
64  typedef typename ImageType::IndexType IndexType;
65  typedef typename ImageType::LabelObjectType LabelObjectType;
66 
67  typedef typename LabelObjectType::AttributeType AttributeType;
68 
70  itkStaticConstMacro(ImageDimension, unsigned int, TImage::ImageDimension);
71 
73  itkNewMacro(Self);
74 
77 
78 #ifdef ITK_USE_CONCEPT_CHECKING
79  // Begin concept checking
80 /* itkConceptMacro(InputEqualityComparableCheck,
81  (Concept::EqualityComparable<InputImagePixelType>));
82  itkConceptMacro(IntConvertibleToInputCheck,
83  (Concept::Convertible<int, InputImagePixelType>));
84  itkConceptMacro(InputOStreamWritableCheck,
85  (Concept::OStreamWritable<InputImagePixelType>));*/
86 // End concept checking
87 #endif
88 
92  itkGetConstMacro(Lambda, double);
93  itkSetMacro(Lambda, double);
95 
102  itkGetConstMacro(ReverseOrdering, bool);
103  itkSetMacro(ReverseOrdering, bool);
104  itkBooleanMacro(ReverseOrdering);
106 
111  itkGetConstMacro(Attribute, AttributeType);
112  itkSetMacro(Attribute, AttributeType);
113  void SetAttribute(const std::string & s)
114  {
115  this->SetAttribute( LabelObjectType::GetAttributeFromName(s) );
116  }
118 
119 protected:
121  ~ShapeOpeningLabelMapFilter() ITK_OVERRIDE {}
122 
123  void GenerateData() ITK_OVERRIDE;
124 
125  template< typename TAttributeAccessor >
126  void TemplatedGenerateData(const TAttributeAccessor & accessor)
127  {
128  // Allocate the output
129  this->AllocateOutputs();
130 
131  ImageType *output = this->GetOutput();
132  ImageType *output2 = this->GetOutput(1);
133  itkAssertInDebugAndIgnoreInReleaseMacro(this->GetNumberOfIndexedOutputs() == 2);
134  itkAssertInDebugAndIgnoreInReleaseMacro(output2 != ITK_NULLPTR);
135 
136  // set the background value for the second output - this is not done in the
137  // superclasses
138  output2->SetBackgroundValue( output->GetBackgroundValue() );
139 
140  ProgressReporter progress( this, 0, output->GetNumberOfLabelObjects() );
141 
142  typename ImageType::Iterator it( output );
143  while ( ! it.IsAtEnd() )
144  {
145  typename LabelObjectType::LabelType label = it.GetLabel();
146  LabelObjectType *labelObject = it.GetLabelObject();
147 
148  if ( ( !m_ReverseOrdering && accessor(labelObject) < m_Lambda )
149  || ( m_ReverseOrdering && accessor(labelObject) > m_Lambda ) )
150  {
151  // must increment the iterator before removing the object to avoid
152  // invalidating the iterator
153  ++it;
154  output2->AddLabelObject(labelObject);
155  output->RemoveLabel(label);
156  }
157  else
158  {
159  ++it;
160  }
161 
162  progress.CompletedPixel();
163  }
164  }
165 
166  void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
167 
168  double m_Lambda;
169 
171 
173 
174 private:
175  ITK_DISALLOW_COPY_AND_ASSIGN(ShapeOpeningLabelMapFilter);
176 }; // end of class
177 } // end namespace itk
178 
179 #ifndef ITK_MANUAL_INSTANTIATION
180 #include "itkShapeOpeningLabelMapFilter.hxx"
181 #endif
182 
183 #endif
InPlaceLabelMapFilter< TImage > Superclass
Light weight base class for most itk classes.
LabelObjectType::AttributeType AttributeType
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...
Implements progress tracking for a filter.
Control indentation during Print() invocation.
Definition: itkIndent.h:49