ITK  6.0.0
Insight Toolkit
itkShapePositionLabelMapFilter.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 itkShapePositionLabelMapFilter_h
19#define itkShapePositionLabelMapFilter_h
20
22
23namespace itk
24{
38template <typename TImage>
39class ITK_TEMPLATE_EXPORT ShapePositionLabelMapFilter : public InPlaceLabelMapFilter<TImage>
40{
41public:
42 ITK_DISALLOW_COPY_AND_MOVE(ShapePositionLabelMapFilter);
43
49
51 using ImageType = TImage;
54 using PixelType = typename ImageType::PixelType;
56 using LabelObjectType = typename ImageType::LabelObjectType;
57
58 using AttributeType = typename LabelObjectType::AttributeType;
59
61 static constexpr unsigned int ImageDimension = TImage::ImageDimension;
62
64 itkNewMacro(Self);
65
67 itkOverrideGetNameOfClassMacro(ShapePositionLabelMapFilter);
68
69#ifdef ITK_USE_CONCEPT_CHECKING
70 // Begin concept checking
71 /* itkConceptMacro(InputEqualityComparableCheck,
72 (Concept::EqualityComparable<InputImagePixelType>));
73 itkConceptMacro(IntConvertibleToInputCheck,
74 (Concept::Convertible<int, InputImagePixelType>));
75 itkConceptMacro(InputOStreamWritableCheck,
76 (Concept::OStreamWritable<InputImagePixelType>));*/
77 // End concept checking
78#endif
79
84 itkGetConstMacro(Attribute, AttributeType);
85 itkSetMacro(Attribute, AttributeType);
86 void
87 SetAttribute(const std::string & s)
88 {
89 this->SetAttribute(LabelObjectType::GetAttributeFromName(s));
90 }
93protected:
95 ~ShapePositionLabelMapFilter() override = default;
96
97 void
99
100 template <typename TAttributeAccessor>
101 void
102 TemplatedThreadedProcessLabelObject(const TAttributeAccessor & accessor, bool physical, LabelObjectType * labelObject)
103 {
104 using AttributeValueType = typename TAttributeAccessor::AttributeValueType;
105 AttributeValueType position = accessor(labelObject);
106 // change it to an index position if it is physical
107 IndexType idx;
108 if (physical)
109 {
110 using CoordinateType = double;
112 // copy the position to a point, required by TransformPhysicalPointToIndex
113 for (unsigned int i = 0; i < ImageDimension; ++i)
114 {
115 // FIXME: This is a bug. The cast should be as in the following line
116 // where CoordinateType is used as the type to cast to. We are temporarily
117 // keeping this original line here to avoid confusing the patch for 64 bits.
118 point[i] = static_cast<OffsetValueType>(position[i]); // FIXME: use next line instead.
119 // point[i] = static_cast<CoordinateType>( position[i] );
120 }
121 idx = this->GetOutput()->TransformPhysicalPointToIndex(point);
122 }
123 else
124 {
125 // copy the position to the index, to avoid warnings
126 for (unsigned int i = 0; i < ImageDimension; ++i)
127 {
128 idx[i] = static_cast<IndexValueType>(position[i]);
129 }
130 }
131 // clear the label object
132 labelObject->Clear();
133 // and mark only the pixel we are interested in
134 labelObject->AddIndex(idx);
135 }
136
137 void
138 PrintSelf(std::ostream & os, Indent indent) const override;
139
140 AttributeType m_Attribute{};
141}; // end of class
142
143} // end namespace itk
144
145#ifndef ITK_MANUAL_INSTANTIATION
146# include "itkShapePositionLabelMapFilter.hxx"
147#endif
148
149#endif
Base class for filters that takes an image as input and overwrites that image as the output.
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Light weight base class for most itk classes.
A templated class holding a geometric point in n-Dimensional space.
Definition: itkPoint.h:54
Mark a single pixel in the label object which correspond to a position given by an attribute.
typename ImageType::LabelObjectType LabelObjectType
typename ImageType::ConstPointer ImageConstPointer
void TemplatedThreadedProcessLabelObject(const TAttributeAccessor &accessor, bool physical, LabelObjectType *labelObject)
~ShapePositionLabelMapFilter() override=default
typename LabelObjectType::AttributeType AttributeType
void PrintSelf(std::ostream &os, Indent indent) const override
void ThreadedProcessLabelObject(LabelObjectType *labelObject) override
SmartPointer< const Self > ConstPointer
SmartPointer< Self > Pointer
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
*par Constraints *The filter image with at least two dimensions and a vector *length of at least The theory supports extension to scalar but *the implementation of the itk vector classes do not **The template parameter TRealType must be floating point(float or double) or *a user-defined "real" numerical type with arithmetic operations defined *sufficient to compute derivatives. **\par Performance *This filter will automatically multithread if run with *SetUsePrincipleComponents
long IndexValueType
Definition: itkIntTypes.h:93
long OffsetValueType
Definition: itkIntTypes.h:97