ITK  5.1.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  * 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 itkShapePositionLabelMapFilter_h
19 #define itkShapePositionLabelMapFilter_h
20 
22 
23 namespace itk
24 {
39 template <typename TImage>
40 class ITK_TEMPLATE_EXPORT ShapePositionLabelMapFilter : public InPlaceLabelMapFilter<TImage>
41 {
42 public:
43  ITK_DISALLOW_COPY_AND_ASSIGN(ShapePositionLabelMapFilter);
44 
50 
52  using ImageType = TImage;
53  using ImagePointer = typename ImageType::Pointer;
54  using ImageConstPointer = typename ImageType::ConstPointer;
55  using PixelType = typename ImageType::PixelType;
56  using IndexType = typename ImageType::IndexType;
57  using LabelObjectType = typename ImageType::LabelObjectType;
58 
59  using AttributeType = typename LabelObjectType::AttributeType;
60 
62  static constexpr unsigned int ImageDimension = TImage::ImageDimension;
63 
65  itkNewMacro(Self);
66 
69 
70 #ifdef ITK_USE_CONCEPT_CHECKING
71  // Begin concept checking
72  /* itkConceptMacro(InputEqualityComparableCheck,
73  (Concept::EqualityComparable<InputImagePixelType>));
74  itkConceptMacro(IntConvertibleToInputCheck,
75  (Concept::Convertible<int, InputImagePixelType>));
76  itkConceptMacro(InputOStreamWritableCheck,
77  (Concept::OStreamWritable<InputImagePixelType>));*/
78  // End concept checking
79 #endif
80 
85  itkGetConstMacro(Attribute, AttributeType);
86  itkSetMacro(Attribute, AttributeType);
87  void
88  SetAttribute(const std::string & s)
89  {
90  this->SetAttribute(LabelObjectType::GetAttributeFromName(s));
91  }
93 
94 protected:
96  ~ShapePositionLabelMapFilter() override = default;
97 
98  void
99  ThreadedProcessLabelObject(LabelObjectType * labelObject) override;
100 
101  template <typename TAttributeAccessor>
102  void
103  TemplatedThreadedProcessLabelObject(const TAttributeAccessor & accessor, bool physical, LabelObjectType * labelObject)
104  {
105  using AttributeValueType = typename TAttributeAccessor::AttributeValueType;
106  AttributeValueType position = accessor(labelObject);
107  // change it to an index position if it is physical
108  IndexType idx;
109  if (physical)
110  {
111  using CoordinateType = double;
113  // copy the position to a point, required by TransformPhysicalPointToIndex
114  for (unsigned int i = 0; i < ImageDimension; i++)
115  {
116  // FIXME: This is a bug. The cast should be as in the following line
117  // where CoordinateType is used as the type to cast to. We are temporarily
118  // keeping this original line here to avoid confusing the patch for 64 bits.
119  point[i] = static_cast<OffsetValueType>(position[i]); // FIXME: use next line instead.
120  // point[i] = static_cast<CoordinateType>( position[i] );
121  }
122  this->GetOutput()->TransformPhysicalPointToIndex(point, idx);
123  }
124  else
125  {
126  // copy the position to the index, to avoid warnings
127  for (unsigned int i = 0; i < ImageDimension; i++)
128  {
129  idx[i] = static_cast<IndexValueType>(position[i]);
130  }
131  }
132  // clear the label object
133  labelObject->Clear();
134  // and mark only the pixel we are interested in
135  labelObject->AddIndex(idx);
136  }
137 
138  void
139  PrintSelf(std::ostream & os, Indent indent) const override;
140 
142 }; // end of class
143 
144 } // end namespace itk
145 
146 #ifndef ITK_MANUAL_INSTANTIATION
147 # include "itkShapePositionLabelMapFilter.hxx"
148 #endif
149 
150 #endif
itk::ShapePositionLabelMapFilter::TemplatedThreadedProcessLabelObject
void TemplatedThreadedProcessLabelObject(const TAttributeAccessor &accessor, bool physical, LabelObjectType *labelObject)
Definition: itkShapePositionLabelMapFilter.h:103
itk::ShapePositionLabelMapFilter::m_Attribute
AttributeType m_Attribute
Definition: itkShapePositionLabelMapFilter.h:141
itk::InPlaceLabelMapFilter
Base class for filters that takes an image as input and overwrites that image as the output.
Definition: itkInPlaceLabelMapFilter.h:84
itk::ShapePositionLabelMapFilter
Mark a single pixel in the label object which correspond to a position given by an attribute.
Definition: itkShapePositionLabelMapFilter.h:40
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::ShapePositionLabelMapFilter::ImageConstPointer
typename ImageType::ConstPointer ImageConstPointer
Definition: itkShapePositionLabelMapFilter.h:54
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:59
itk::ShapePositionLabelMapFilter::ImagePointer
typename ImageType::Pointer ImagePointer
Definition: itkShapePositionLabelMapFilter.h:53
itk::ShapePositionLabelMapFilter::PixelType
typename ImageType::PixelType PixelType
Definition: itkShapePositionLabelMapFilter.h:55
itkInPlaceLabelMapFilter.h
itk::ShapePositionLabelMapFilter::IndexType
typename ImageType::IndexType IndexType
Definition: itkShapePositionLabelMapFilter.h:56
itk::ShapePositionLabelMapFilter::LabelObjectType
typename ImageType::LabelObjectType LabelObjectType
Definition: itkShapePositionLabelMapFilter.h:57
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkArray.h:26
itk::ShapePositionLabelMapFilter::ImageType
TImage ImageType
Definition: itkShapePositionLabelMapFilter.h:52
itk::ShapePositionLabelMapFilter::AttributeType
typename LabelObjectType::AttributeType AttributeType
Definition: itkShapePositionLabelMapFilter.h:59
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:88