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 
23 namespace itk
24 {
38 template <typename TImage>
39 class ITK_TEMPLATE_EXPORT ShapePositionLabelMapFilter : public InPlaceLabelMapFilter<TImage>
40 {
41 public:
42  ITK_DISALLOW_COPY_AND_MOVE(ShapePositionLabelMapFilter);
43 
49 
51  using ImageType = TImage;
52  using ImagePointer = typename ImageType::Pointer;
54  using PixelType = typename ImageType::PixelType;
55  using IndexType = typename ImageType::IndexType;
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  }
93 protected:
95  ~ShapePositionLabelMapFilter() override = default;
96 
97  void
98  ThreadedProcessLabelObject(LabelObjectType * labelObject) override;
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
itk::ShapePositionLabelMapFilter::TemplatedThreadedProcessLabelObject
void TemplatedThreadedProcessLabelObject(const TAttributeAccessor &accessor, bool physical, LabelObjectType *labelObject)
Definition: itkShapePositionLabelMapFilter.h:102
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
ConstPointer
SmartPointer< const Self > ConstPointer
Definition: itkAddImageFilter.h:94
itk::InPlaceLabelMapFilter
Base class for filters that takes an image as input and overwrites that image as the output.
Definition: itkInPlaceLabelMapFilter.h:83
itk::ShapePositionLabelMapFilter
Mark a single pixel in the label object which correspond to a position given by an attribute.
Definition: itkShapePositionLabelMapFilter.h:39
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::ShapePositionLabelMapFilter::ImageConstPointer
typename ImageType::ConstPointer ImageConstPointer
Definition: itkShapePositionLabelMapFilter.h:53
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itk::ShapePositionLabelMapFilter::ImagePointer
typename ImageType::Pointer ImagePointer
Definition: itkShapePositionLabelMapFilter.h:52
itk::point
*par Constraints *The filter requires an 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
itk::ShapePositionLabelMapFilter::PixelType
typename ImageType::PixelType PixelType
Definition: itkShapePositionLabelMapFilter.h:54
itkInPlaceLabelMapFilter.h
itk::ShapePositionLabelMapFilter::IndexType
typename ImageType::IndexType IndexType
Definition: itkShapePositionLabelMapFilter.h:55
itk::ShapePositionLabelMapFilter::LabelObjectType
typename ImageType::LabelObjectType LabelObjectType
Definition: itkShapePositionLabelMapFilter.h:56
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::ShapePositionLabelMapFilter::ImageType
TImage ImageType
Definition: itkShapePositionLabelMapFilter.h:51
itk::ShapePositionLabelMapFilter::AttributeType
typename LabelObjectType::AttributeType AttributeType
Definition: itkShapePositionLabelMapFilter.h:58
itk::Point
A templated class holding a geometric point in n-Dimensional space.
Definition: itkPoint.h:53
itk::ShapePositionLabelMapFilter::SetAttribute
void SetAttribute(const std::string &s)
Definition: itkShapePositionLabelMapFilter.h:87