ITK  4.2.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< class TImage >
49 class ITK_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 
80 /* itkConceptMacro(InputEqualityComparableCheck,
81  (Concept::EqualityComparable<InputImagePixelType>));
82  itkConceptMacro(IntConvertibleToInputCheck,
83  (Concept::Convertible<int, InputImagePixelType>));
84  itkConceptMacro(InputOStreamWritableCheck,
85  (Concept::OStreamWritable<InputImagePixelType>));*/
86 
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 SetAttribute(const std::string & s)
115  {
116  this->SetAttribute( LabelObjectType::GetAttributeFromName(s) );
117  }
119 
120 protected:
123 
124  void GenerateData();
125 
126  template< class TAttributeAccessor >
127  void TemplatedGenerateData(const TAttributeAccessor & accessor)
128  {
129  // Allocate the output
130  this->AllocateOutputs();
131 
132  ImageType *output = this->GetOutput();
133  ImageType *output2 = this->GetOutput(1);
134  itkAssertInDebugAndIgnoreInReleaseMacro(this->GetNumberOfIndexedOutputs() == 2);
135  itkAssertInDebugAndIgnoreInReleaseMacro(output2 != NULL);
136 
137  // set the background value for the second output - this is not done in the
138  // superclasses
139  output2->SetBackgroundValue( output->GetBackgroundValue() );
140 
141  ProgressReporter progress( this, 0, output->GetNumberOfLabelObjects() );
142 
143  typename ImageType::Iterator it( output );
144  while ( ! it.IsAtEnd() )
145  {
146  typename LabelObjectType::LabelType label = it.GetLabel();
147  LabelObjectType *labelObject = it.GetLabelObject();
148 
149  if ( ( !m_ReverseOrdering && accessor(labelObject) < m_Lambda )
150  || ( m_ReverseOrdering && accessor(labelObject) > m_Lambda ) )
151  {
152  // must increment the iterator before removing the object to avoid
153  // invalidating the iterator
154  ++it;
155  output2->AddLabelObject(labelObject);
156  output->RemoveLabel(label);
157  }
158  else
159  {
160  ++it;
161  }
162 
163  progress.CompletedPixel();
164  }
165  }
166 
167  void PrintSelf(std::ostream & os, Indent indent) const;
168 
169  double m_Lambda;
170 
172 
174 private:
175  ShapeOpeningLabelMapFilter(const Self &); //purposely not implemented
176  void operator=(const Self &); //purposely not implemented
177 }; // end of class
178 } // end namespace itk
179 
180 #ifndef ITK_MANUAL_INSTANTIATION
181 #include "itkShapeOpeningLabelMapFilter.hxx"
182 #endif
183 
184 #endif
185