ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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 * https://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
25namespace itk
26{
48template <typename TImage>
49class ITK_TEMPLATE_EXPORT ShapeOpeningLabelMapFilter : public InPlaceLabelMapFilter<TImage>
50{
51public:
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
77 itkOverrideGetNameOfClassMacro(ShapeOpeningLabelMapFilter);
78
79 /*itkConceptMacro(InputEqualityComparableCheck,
80 (Concept::EqualityComparable<InputImagePixelType>));
81 itkConceptMacro(IntConvertibleToInputCheck,
82 (Concept::Convertible<int, InputImagePixelType>));
83 itkConceptMacro(InputOStreamWritableCheck,
84 (Concept::OStreamWritable<InputImagePixelType>));*/
85
89 itkGetConstMacro(Lambda, double);
90 itkSetMacro(Lambda, double);
92
99 itkGetConstMacro(ReverseOrdering, bool);
100 itkSetMacro(ReverseOrdering, bool);
101 itkBooleanMacro(ReverseOrdering);
103
108 itkGetConstMacro(Attribute, AttributeType);
109 itkSetMacro(Attribute, AttributeType);
110 void
111 SetAttribute(const std::string & s)
112 {
113 this->SetAttribute(LabelObjectType::GetAttributeFromName(s));
114 }
115
116
117protected:
119 ~ShapeOpeningLabelMapFilter() override = default;
120
121 void
122 GenerateData() override;
123
124 template <typename TAttributeAccessor>
125 void
126 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 != 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 const 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
167 PrintSelf(std::ostream & os, Indent indent) const override;
168
169 double m_Lambda{};
170
172
174}; // end of class
175} // end namespace itk
176
177#ifndef ITK_MANUAL_INSTANTIATION
178# include "itkShapeOpeningLabelMapFilter.hxx"
179#endif
180
181#endif
OutputImageType * GetOutput()
void AllocateOutputs() override
Control indentation during Print() invocation.
Definition itkIndent.h:50
DataObjectPointerArraySizeType GetNumberOfIndexedOutputs() const
The number of defined Indexed outputs.
Implements progress tracking for a filter.
void TemplatedGenerateData(const TAttributeAccessor &accessor)
virtual void SetAttribute(AttributeType _arg)
void PrintSelf(std::ostream &os, Indent indent) const override
~ShapeOpeningLabelMapFilter() override=default
typename LabelObjectType::AttributeType AttributeType
Implements transparent reference counting.
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....