cmtkImageOperationReplace.h

Go to the documentation of this file.
00001 /*
00002 //
00003 //  Copyright 2010 Torsten Rohlfing
00004 //
00005 //  Copyright 2011 SRI International
00006 //
00007 //  This file is part of the Computational Morphometry Toolkit.
00008 //
00009 //  http://www.nitrc.org/projects/cmtk/
00010 //
00011 //  The Computational Morphometry Toolkit is free software: you can
00012 //  redistribute it and/or modify it under the terms of the GNU General Public
00013 //  License as published by the Free Software Foundation, either version 3 of
00014 //  the License, or (at your option) any later version.
00015 //
00016 //  The Computational Morphometry Toolkit is distributed in the hope that it
00017 //  will be useful, but WITHOUT ANY WARRANTY; without even the implied
00018 //  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 //  GNU General Public License for more details.
00020 //
00021 //  You should have received a copy of the GNU General Public License along
00022 //  with the Computational Morphometry Toolkit.  If not, see
00023 //  <http://www.gnu.org/licenses/>.
00024 //
00025 //  $Revision: 2755 $
00026 //
00027 //  $LastChangedDate: 2011-01-18 11:42:28 -0800 (Tue, 18 Jan 2011) $
00028 //
00029 //  $LastChangedBy: torstenrohlfing $
00030 //
00031 */
00032 
00033 #ifndef __cmtkImageOperationReplace_h_included_
00034 #define __cmtkImageOperationReplace_h_included_
00035 
00036 #include <cmtkconfig.h>
00037 
00038 #include <Base/cmtkImageOperation.h>
00039 
00040 namespace
00041 cmtk
00042 {
00043 
00045 class ImageOperationReplace
00047   : public ImageOperation
00048 {
00049 public:
00051   typedef ImageOperationReplace Self;
00052 
00054   typedef ImageOperation Superclass;
00055 
00057   typedef enum
00058   {
00060     REPLACE_PADDING,
00062     REPLACE_INF_NAN
00063   } Mode;
00064 
00066   ImageOperationReplace( const Self::Mode mode , const Types::DataItem value  )
00067     : m_Mode( mode ),
00068       m_ReplacementValue( value )
00069   {}
00070 
00072   virtual cmtk::UniformVolume::SmartPtr  Apply( cmtk::UniformVolume::SmartPtr& volume )
00073   {
00074     TypedArray& volumeData = *(volume->GetData());
00075     switch ( this->m_Mode ) 
00076       {
00077       case Self::REPLACE_PADDING:
00078         volumeData.ReplacePaddingData( this->m_ReplacementValue );
00079         break;
00080       case Self::REPLACE_INF_NAN:
00081 #pragma omp parallel for
00082         for ( size_t i = 0; i < volumeData.GetDataSize(); ++i )
00083           {
00084           cmtk::Types::DataItem value = 0;
00085           if ( volumeData.Get( value, i ) )
00086             {
00087             if ( !finite( value ) )
00088               {
00089               volumeData.Set( this->m_ReplacementValue, i );
00090               }
00091             }
00092           }
00093         break;
00094       }
00095     return volume;
00096   }
00097   
00099   static void NewReplacePadding( const double value  )
00100   {
00101     ImageOperation::m_ImageOperationList.push_back( SmartPtr( new Self( Self::REPLACE_PADDING, value ) ) );
00102   }
00103 
00105   static void NewReplaceInfNaN( const double value  )
00106   {
00107     ImageOperation::m_ImageOperationList.push_back( SmartPtr( new Self( Self::REPLACE_INF_NAN, value ) ) );
00108   }
00109   
00110 private:
00112   Self::Mode m_Mode;
00113 
00115   Types::DataItem m_ReplacementValue;
00116 };
00117 
00118 } // namespace cmtk
00119 
00120 #endif // #ifndef __cmtkImageOperationReplace_h_included_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines