ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkShapePositionLabelMapFilter.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 itkShapePositionLabelMapFilter_h
19 #define itkShapePositionLabelMapFilter_h
20 
22 
23 namespace itk {
37 template<typename TImage>
38 class ITK_TEMPLATE_EXPORT ShapePositionLabelMapFilter :
39  public InPlaceLabelMapFilter<TImage>
40 {
41 public:
42  ITK_DISALLOW_COPY_AND_ASSIGN(ShapePositionLabelMapFilter);
43 
49 
51  using ImageType = TImage;
52  using ImagePointer = typename ImageType::Pointer;
53  using ImageConstPointer = typename ImageType::ConstPointer;
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  itkTypeMacro(ShapePositionLabelMapFilter,
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 SetAttribute( const std::string & s )
88  {
89  this->SetAttribute( LabelObjectType::GetAttributeFromName( s ) );
90  }
92 
93 protected:
95  ~ShapePositionLabelMapFilter() override = default;
96 
97  void ThreadedProcessLabelObject( LabelObjectType * labelObject ) override;
98 
99  template< typename TAttributeAccessor >
100  void TemplatedThreadedProcessLabelObject( const TAttributeAccessor & accessor, bool physical, LabelObjectType * labelObject )
101  {
102  using AttributeValueType = typename TAttributeAccessor::AttributeValueType;
103  AttributeValueType position = accessor( labelObject );
104  // change it to an index position if it is physical
105  IndexType idx;
106  if( physical )
107  {
108  using CoordinateType = double;
110  // copy the position to a point, required by TransformPhysicalPointToIndex
111  for(unsigned int i=0; i<ImageDimension; i++ )
112  {
113  // FIXME: This is a bug. The cast should be as in the following line
114  // where CoordinateType is used as the type to cast to. We are temporarily
115  // keeping this original line here to avoid confusing the patch for 64 bits.
116  point[i] = static_cast<OffsetValueType>( position[i] ); // FIXME: use next line instead.
117  // point[i] = static_cast<CoordinateType>( position[i] );
118  }
119  this->GetOutput()->TransformPhysicalPointToIndex( point, idx );
120  }
121  else
122  {
123  // copy the position to the index, to avoid warnings
124  for(unsigned int i=0; i<ImageDimension; i++ )
125  {
126  idx[i] = static_cast<IndexValueType>( position[i] );
127  }
128  }
129  // clear the label object
130  labelObject->Clear();
131  // and mark only the pixel we are interested in
132  labelObject->AddIndex( idx );
133  }
134 
135  void PrintSelf(std::ostream& os, Indent indent) const override;
136 
138 }; // end of class
139 
140 } // end namespace itk
141 
142 #ifndef ITK_MANUAL_INSTANTIATION
143 #include "itkShapePositionLabelMapFilter.hxx"
144 #endif
145 
146 #endif
typename LabelObjectType::AttributeType AttributeType
Light weight base class for most itk classes.
void TemplatedThreadedProcessLabelObject(const TAttributeAccessor &accessor, bool physical, LabelObjectType *labelObject)
typename ImageType::ConstPointer ImageConstPointer
typename ImageType::LabelObjectType LabelObjectType
Mark a single pixel in the label object which correspond to a position given by an attribute...
Base class for filters that takes an image as input and overwrites that image as the output...
signed long IndexValueType
Definition: itkIntTypes.h:90
Control indentation during Print() invocation.
Definition: itkIndent.h:49
A templated class holding a geometric point in n-Dimensional space.
Definition: itkPoint.h:52
signed long OffsetValueType
Definition: itkIntTypes.h:94