![]() |
ITK
4.2.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 __itkGradientImageFilter_h 00019 #define __itkGradientImageFilter_h 00020 00021 #include "itkImageToImageFilter.h" 00022 #include "itkCovariantVector.h" 00023 #include "itkImageRegionIterator.h" 00024 00025 namespace itk 00026 { 00027 00028 00029 template <typename TPixelType, unsigned int VImageDimension > class VectorImage; 00030 00031 00054 template< class TInputImage, 00055 class TOperatorValueType = float, 00056 class TOutputValueType = float, 00057 class TOutputImageType = Image< CovariantVector< TOutputValueType, 00058 TInputImage::ImageDimension >, 00059 TInputImage::ImageDimension > > 00060 class ITK_EXPORT GradientImageFilter: 00061 public ImageToImageFilter< TInputImage, TOutputImageType > 00062 { 00063 public: 00065 itkStaticConstMacro(InputImageDimension, unsigned int, 00066 TInputImage::ImageDimension); 00067 itkStaticConstMacro(OutputImageDimension, unsigned int, 00068 TInputImage::ImageDimension); 00070 00072 typedef GradientImageFilter Self; 00073 00075 typedef TInputImage InputImageType; 00076 typedef typename InputImageType::Pointer InputImagePointer; 00077 typedef TOutputImageType OutputImageType; 00078 typedef typename OutputImageType::Pointer OutputImagePointer; 00079 00081 typedef ImageToImageFilter< InputImageType, OutputImageType > Superclass; 00082 typedef SmartPointer< Self > Pointer; 00083 typedef SmartPointer< const Self > ConstPointer; 00084 00086 itkNewMacro(Self); 00087 00089 itkTypeMacro(GradientImageFilter, ImageToImageFilter); 00090 00092 typedef typename InputImageType::PixelType InputPixelType; 00093 typedef TOperatorValueType OperatorValueType; 00094 typedef TOutputValueType OutputValueType; 00095 typedef typename OutputImageType::PixelType OutputPixelType; 00096 typedef CovariantVector< 00097 OutputValueType, itkGetStaticConstMacro(OutputImageDimension) > 00098 CovariantVectorType; 00099 typedef typename OutputImageType::RegionType OutputImageRegionType; 00100 00107 virtual void GenerateInputRequestedRegion() 00108 throw( InvalidRequestedRegionError ); 00109 00112 void SetUseImageSpacingOn() 00113 { this->SetUseImageSpacing(true); } 00114 00117 void SetUseImageSpacingOff() 00118 { this->SetUseImageSpacing(false); } 00119 00122 itkSetMacro(UseImageSpacing, bool); 00123 itkGetConstMacro(UseImageSpacing, bool); 00125 00126 #ifdef ITK_USE_CONCEPT_CHECKING 00127 00128 itkConceptMacro( InputConvertibleToOutputCheck, 00129 ( Concept::Convertible< InputPixelType, OutputValueType > ) ); 00130 itkConceptMacro( OutputHasNumericTraitsCheck, 00131 ( Concept::HasNumericTraits< OutputValueType > ) ); 00132 00134 #endif 00135 00146 itkSetMacro(UseImageDirection, bool); 00147 itkGetConstMacro(UseImageDirection, bool); 00148 itkBooleanMacro(UseImageDirection); 00149 protected: 00150 GradientImageFilter(); 00151 virtual ~GradientImageFilter(); 00152 void PrintSelf(std::ostream & os, Indent indent) const; 00154 00165 void ThreadedGenerateData(const OutputImageRegionType & outputRegionForThread, 00166 ThreadIdType threadId); 00167 00168 private: 00169 GradientImageFilter(const Self &); //purposely not implemented 00170 void operator=(const Self &); //purposely not implemented 00171 00172 virtual void GenerateOutputInformation(); 00173 00174 // An overloaded method which may transform the gradient to a 00175 // physical vector and converts to the correct output pixel type. 00176 template <class TValueType> 00177 void SetOutputPixel( ImageRegionIterator< VectorImage<TValueType,OutputImageDimension> > &it, CovariantVectorType &gradient ) 00178 { 00179 if ( this->m_UseImageDirection ) 00180 { 00181 CovariantVectorType physicalGradient; 00182 it.GetImage()->TransformLocalVectorToPhysicalVector( gradient, physicalGradient ); 00183 it.Set( OutputPixelType( physicalGradient.GetDataPointer(), InputImageDimension, false ) ); 00184 } 00185 else 00186 { 00187 it.Set( OutputPixelType( gradient.GetDataPointer(), InputImageDimension, false ) ); 00188 } 00189 } 00190 00191 template <class T > 00192 void SetOutputPixel( ImageRegionIterator< T > &it, CovariantVectorType &gradient ) 00193 { 00194 // This uses the more efficient set by reference method 00195 if ( this->m_UseImageDirection ) 00196 { 00197 it.GetImage()->TransformLocalVectorToPhysicalVector( gradient, it.Value() ); 00198 } 00199 else 00200 { 00201 it.Value() = gradient; 00202 } 00203 } 00204 00205 00206 bool m_UseImageSpacing; 00207 00208 // flag to take or not the image direction into account 00209 // when computing the derivatives. 00210 bool m_UseImageDirection; 00211 }; 00212 } // end namespace itk 00213 00214 #ifndef ITK_MANUAL_INSTANTIATION 00215 #include "itkGradientImageFilter.hxx" 00216 #endif 00217 00218 #endif 00219
1.7.6.1