ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 #ifndef __itkShapePositionLabelMapFilter_h 00019 #define __itkShapePositionLabelMapFilter_h 00020 00021 #include "itkInPlaceLabelMapFilter.h" 00022 00023 namespace itk { 00037 template<class TImage> 00038 class ITK_EXPORT ShapePositionLabelMapFilter : 00039 public InPlaceLabelMapFilter<TImage> 00040 { 00041 public: 00043 typedef ShapePositionLabelMapFilter Self; 00044 typedef InPlaceLabelMapFilter<TImage> Superclass; 00045 typedef SmartPointer<Self> Pointer; 00046 typedef SmartPointer<const Self> ConstPointer; 00047 00049 typedef TImage ImageType; 00050 typedef typename ImageType::Pointer ImagePointer; 00051 typedef typename ImageType::ConstPointer ImageConstPointer; 00052 typedef typename ImageType::PixelType PixelType; 00053 typedef typename ImageType::IndexType IndexType; 00054 typedef typename ImageType::LabelObjectType LabelObjectType; 00055 00056 typedef typename LabelObjectType::AttributeType AttributeType; 00057 00059 itkStaticConstMacro(ImageDimension, unsigned int, 00060 TImage::ImageDimension); 00061 00063 itkNewMacro(Self); 00064 00066 itkTypeMacro(ShapePositionLabelMapFilter, 00067 InPlaceLabelMapFilter); 00068 00069 #ifdef ITK_USE_CONCEPT_CHECKING 00070 00071 /* itkConceptMacro(InputEqualityComparableCheck, 00072 (Concept::EqualityComparable<InputImagePixelType>)); 00073 itkConceptMacro(IntConvertibleToInputCheck, 00074 (Concept::Convertible<int, InputImagePixelType>)); 00075 itkConceptMacro(InputOStreamWritableCheck, 00076 (Concept::OStreamWritable<InputImagePixelType>));*/ 00077 00079 #endif 00080 00085 itkGetConstMacro( Attribute, AttributeType ); 00086 itkSetMacro( Attribute, AttributeType ); 00087 void SetAttribute( const std::string & s ) 00088 { 00089 this->SetAttribute( LabelObjectType::GetAttributeFromName( s ) ); 00090 } 00092 00093 00094 protected: 00095 ShapePositionLabelMapFilter(); 00096 ~ShapePositionLabelMapFilter() {}; 00097 00098 virtual void ThreadedProcessLabelObject( LabelObjectType * labelObject ); 00099 00100 template< class TAttributeAccessor > 00101 void TemplatedThreadedProcessLabelObject( const TAttributeAccessor & accessor, bool physical, LabelObjectType * labelObject ) 00102 { 00103 typedef typename TAttributeAccessor::AttributeValueType AttributeValueType; 00104 AttributeValueType position = accessor( labelObject ); 00105 // change it to an index position if it is physical 00106 IndexType idx; 00107 if( physical ) 00108 { 00109 typedef double CoordinateType; 00110 Point< CoordinateType, ImageDimension > point; 00111 // copy the position to a point, required by TransformPhysicalPointToIndex 00112 for( int i=0; i<ImageDimension; i++ ) 00113 { 00114 // FIXME: This is a bug. The cast should be as in the following line 00115 // where CoordinateType is used as the type to cast to. We are temporarily 00116 // keeping this original line here to avoid confusing the patch for 64 bits. 00117 point[i] = static_cast<OffsetValueType>( position[i] ); // FIXME: use next line instead. 00118 // point[i] = static_cast<CoordinateType>( position[i] ); 00119 } 00120 this->GetOutput()->TransformPhysicalPointToIndex( point, idx ); 00121 } 00122 else 00123 { 00124 // copy the position to the index, to avoid warnings 00125 for( int i=0; i<ImageDimension; i++ ) 00126 { 00127 idx[i] = static_cast<IndexValueType>( position[i] ); 00128 } 00129 } 00130 // clear the label object 00131 labelObject->Clear(); 00132 // and mark only the pixel we are interested in 00133 labelObject->AddIndex( idx ); 00134 } 00135 00136 void PrintSelf(std::ostream& os, Indent indent) const; 00137 00138 AttributeType m_Attribute; 00139 00140 private: 00141 ShapePositionLabelMapFilter(const Self&); //purposely not implemented 00142 void operator=(const Self&); //purposely not implemented 00143 00144 }; // end of class 00145 00146 } // end namespace itk 00147 00148 #ifndef ITK_MANUAL_INSTANTIATION 00149 #include "itkShapePositionLabelMapFilter.hxx" 00150 #endif 00151 00152 #endif 00153