ITK  4.4.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<class TImage>
38 class ITK_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 
71 /* itkConceptMacro(InputEqualityComparableCheck,
72  (Concept::EqualityComparable<InputImagePixelType>));
73  itkConceptMacro(IntConvertibleToInputCheck,
74  (Concept::Convertible<int, InputImagePixelType>));
75  itkConceptMacro(InputOStreamWritableCheck,
76  (Concept::OStreamWritable<InputImagePixelType>));*/
77 
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:
96 
97  virtual void ThreadedProcessLabelObject( LabelObjectType * labelObject );
98 
99  template< class TAttributeAccessor >
100  void TemplatedThreadedProcessLabelObject( const TAttributeAccessor & accessor, bool physical, LabelObjectType * labelObject )
101  {
102  typedef typename TAttributeAccessor::AttributeValueType 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  typedef double CoordinateType;
110  // copy the position to a point, required by TransformPhysicalPointToIndex
111  for( 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( 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;
136 
138 
139 private:
140  ShapePositionLabelMapFilter(const Self&); //purposely not implemented
141  void operator=(const Self&); //purposely not implemented
142 
143 }; // end of class
144 
145 } // end namespace itk
146 
147 #ifndef ITK_MANUAL_INSTANTIATION
148 #include "itkShapePositionLabelMapFilter.hxx"
149 #endif
150 
151 #endif
152