ITK  4.2.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 
94 protected:
97 
98  virtual void ThreadedProcessLabelObject( LabelObjectType * labelObject );
99 
100  template< class TAttributeAccessor >
101  void TemplatedThreadedProcessLabelObject( const TAttributeAccessor & accessor, bool physical, LabelObjectType * labelObject )
102  {
103  typedef typename TAttributeAccessor::AttributeValueType AttributeValueType;
104  AttributeValueType position = accessor( labelObject );
105  // change it to an index position if it is physical
106  IndexType idx;
107  if( physical )
108  {
109  typedef double CoordinateType;
111  // copy the position to a point, required by TransformPhysicalPointToIndex
112  for( int i=0; i<ImageDimension; i++ )
113  {
114  // FIXME: This is a bug. The cast should be as in the following line
115  // where CoordinateType is used as the type to cast to. We are temporarily
116  // keeping this original line here to avoid confusing the patch for 64 bits.
117  point[i] = static_cast<OffsetValueType>( position[i] ); // FIXME: use next line instead.
118  // point[i] = static_cast<CoordinateType>( position[i] );
119  }
120  this->GetOutput()->TransformPhysicalPointToIndex( point, idx );
121  }
122  else
123  {
124  // copy the position to the index, to avoid warnings
125  for( int i=0; i<ImageDimension; i++ )
126  {
127  idx[i] = static_cast<IndexValueType>( position[i] );
128  }
129  }
130  // clear the label object
131  labelObject->Clear();
132  // and mark only the pixel we are interested in
133  labelObject->AddIndex( idx );
134  }
135 
136  void PrintSelf(std::ostream& os, Indent indent) const;
137 
139 
140 private:
141  ShapePositionLabelMapFilter(const Self&); //purposely not implemented
142  void operator=(const Self&); //purposely not implemented
143 
144 }; // end of class
145 
146 } // end namespace itk
147 
148 #ifndef ITK_MANUAL_INSTANTIATION
149 #include "itkShapePositionLabelMapFilter.hxx"
150 #endif
151 
152 #endif
153