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 __itkBinaryProjectionImageFilter_h 00019 #define __itkBinaryProjectionImageFilter_h 00020 00021 #include "itkProjectionImageFilter.h" 00022 #include "itkConceptChecking.h" 00023 00024 namespace itk 00025 { 00049 namespace Functor 00050 { 00051 template< class TInputPixel, class TOutputPixel > 00052 class BinaryAccumulator 00053 { 00054 public: 00055 BinaryAccumulator( SizeValueType ) {} 00056 ~BinaryAccumulator(){} 00057 00058 inline void Initialize() 00059 { 00060 m_IsForeground = false; 00061 } 00062 00063 inline void operator()(const TInputPixel & input) 00064 { 00065 if ( input == m_ForegroundValue ) 00066 { 00067 m_IsForeground = true; 00068 } 00069 } 00070 00071 inline TOutputPixel GetValue() 00072 { 00073 if ( m_IsForeground ) 00074 { 00075 return (TOutputPixel)m_ForegroundValue; 00076 } 00077 else 00078 { 00079 return m_BackgroundValue; 00080 } 00081 } 00082 00083 bool m_IsForeground; 00084 00085 TInputPixel m_ForegroundValue; 00086 00087 TOutputPixel m_BackgroundValue; 00088 }; 00089 } // end namespace Function 00090 00091 template< class TInputImage, class TOutputImage > 00092 class ITK_EXPORT BinaryProjectionImageFilter: 00093 public ProjectionImageFilter< TInputImage, TOutputImage, 00094 Functor::BinaryAccumulator< 00095 typename TInputImage::PixelType, 00096 typename TOutputImage::PixelType > > 00097 { 00098 public: 00099 typedef BinaryProjectionImageFilter Self; 00100 typedef ProjectionImageFilter< TInputImage, TOutputImage, 00101 Functor::BinaryAccumulator< 00102 typename TInputImage::PixelType, 00103 typename TOutputImage::PixelType > > Superclass; 00104 00105 typedef SmartPointer< Self > Pointer; 00106 typedef SmartPointer< const Self > ConstPointer; 00107 00109 itkTypeMacro(BinaryProjectionImageFilter, ProjectionImageFilter); 00110 00112 itkNewMacro(Self); 00113 00115 typedef TInputImage InputImageType; 00116 typedef TOutputImage OutputImageType; 00117 00119 typedef typename InputImageType::PixelType InputPixelType; 00120 typedef typename OutputImageType::PixelType OutputPixelType; 00121 00122 typedef typename Superclass::AccumulatorType AccumulatorType; 00123 00127 itkSetMacro(ForegroundValue, InputPixelType); 00128 00131 itkGetConstMacro(ForegroundValue, InputPixelType); 00132 00137 itkSetMacro(BackgroundValue, OutputPixelType); 00138 00143 itkGetConstMacro(BackgroundValue, OutputPixelType); 00144 00145 #ifdef ITK_USE_CONCEPT_CHECKING 00146 00147 itkConceptMacro( InputPixelTypeGreaterThanComparable, 00148 ( Concept::EqualityComparable< InputPixelType > ) ); 00149 itkConceptMacro( InputHasNumericTraitsCheck, 00150 ( Concept::HasNumericTraits< InputPixelType > ) ); 00151 00153 #endif 00154 protected: 00155 BinaryProjectionImageFilter() 00156 { 00157 m_ForegroundValue = NumericTraits< InputPixelType >::max(); 00158 m_BackgroundValue = NumericTraits< OutputPixelType >::NonpositiveMin(); 00159 } 00161 00162 virtual ~BinaryProjectionImageFilter() {} 00163 00164 void PrintSelf(std::ostream & os, Indent indent) const 00165 { 00166 Superclass::PrintSelf(os, indent); 00167 00168 typedef typename NumericTraits< InputPixelType >::PrintType 00169 InputPixelPrintType; 00170 00171 os << indent << "ForegroundValue: " 00172 << static_cast< InputPixelPrintType >( m_ForegroundValue ) 00173 << std::endl; 00174 00175 typedef typename NumericTraits< OutputPixelType >::PrintType 00176 OutputPixelPrintType; 00177 00178 os << indent << "BackgroundValue: " 00179 << static_cast< OutputPixelPrintType >( m_BackgroundValue ) 00180 << std::endl; 00181 } 00182 00183 virtual AccumulatorType NewAccumulator( SizeValueType size ) const 00184 { 00185 AccumulatorType accumulator(size); 00186 00187 accumulator.m_ForegroundValue = m_ForegroundValue; 00188 accumulator.m_BackgroundValue = m_BackgroundValue; 00189 return accumulator; 00190 } 00191 00193 InputPixelType m_ForegroundValue; 00194 00196 OutputPixelType m_BackgroundValue; 00197 private: 00198 BinaryProjectionImageFilter(const Self &); //purposely not implemented 00199 void operator=(const Self &); //purposely not implemented 00200 }; // end BinaryProjectionImageFilter 00201 } //end namespace itk 00203 00204 #endif 00205