ITK  4.13.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:
47 
49  typedef TImage ImageType;
50  typedef typename ImageType::Pointer ImagePointer;
51  typedef typename ImageType::ConstPointer ImageConstPointer;
52  typedef typename ImageType::PixelType PixelType;
53  typedef typename ImageType::IndexType IndexType;
54  typedef typename ImageType::LabelObjectType LabelObjectType;
55 
56  typedef typename LabelObjectType::AttributeType AttributeType;
57 
59  itkStaticConstMacro(ImageDimension, unsigned int,
60  TImage::ImageDimension);
61 
63  itkNewMacro(Self);
64 
66  itkTypeMacro(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 SetAttribute( const std::string & s )
87  {
88  this->SetAttribute( LabelObjectType::GetAttributeFromName( s ) );
89  }
91 
92 protected:
94  ~ShapePositionLabelMapFilter() ITK_OVERRIDE {};
95 
96  virtual void ThreadedProcessLabelObject( LabelObjectType * labelObject ) ITK_OVERRIDE;
97 
98  template< typename TAttributeAccessor >
99  void TemplatedThreadedProcessLabelObject( const TAttributeAccessor & accessor, bool physical, LabelObjectType * labelObject )
100  {
101  typedef typename TAttributeAccessor::AttributeValueType AttributeValueType;
102  AttributeValueType position = accessor( labelObject );
103  // change it to an index position if it is physical
104  IndexType idx;
105  if( physical )
106  {
107  typedef double CoordinateType;
109  // copy the position to a point, required by TransformPhysicalPointToIndex
110  for(unsigned int i=0; i<ImageDimension; i++ )
111  {
112  // FIXME: This is a bug. The cast should be as in the following line
113  // where CoordinateType is used as the type to cast to. We are temporarily
114  // keeping this original line here to avoid confusing the patch for 64 bits.
115  point[i] = static_cast<OffsetValueType>( position[i] ); // FIXME: use next line instead.
116  // point[i] = static_cast<CoordinateType>( position[i] );
117  }
118  this->GetOutput()->TransformPhysicalPointToIndex( point, idx );
119  }
120  else
121  {
122  // copy the position to the index, to avoid warnings
123  for(unsigned int i=0; i<ImageDimension; i++ )
124  {
125  idx[i] = static_cast<IndexValueType>( position[i] );
126  }
127  }
128  // clear the label object
129  labelObject->Clear();
130  // and mark only the pixel we are interested in
131  labelObject->AddIndex( idx );
132  }
133 
134  void PrintSelf(std::ostream& os, Indent indent) const ITK_OVERRIDE;
135 
137 
138 private:
139  ITK_DISALLOW_COPY_AND_ASSIGN(ShapePositionLabelMapFilter);
140 
141 }; // end of class
142 
143 } // end namespace itk
144 
145 #ifndef ITK_MANUAL_INSTANTIATION
146 #include "itkShapePositionLabelMapFilter.hxx"
147 #endif
148 
149 #endif
Light weight base class for most itk classes.
void TemplatedThreadedProcessLabelObject(const TAttributeAccessor &accessor, bool physical, LabelObjectType *labelObject)
signed long OffsetValueType
Definition: itkIntTypes.h:154
signed long IndexValueType
Definition: itkIntTypes.h:150
InPlaceLabelMapFilter< TImage > Superclass
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...
LabelObjectType::AttributeType AttributeType
Control indentation during Print() invocation.
Definition: itkIndent.h:49
A templated class holding a geometric point in n-Dimensional space.
Definition: itkPoint.h:52