cmtkReformatVolumeReformat.txx

Go to the documentation of this file.
00001 /*
00002 //
00003 //  Copyright 1997-2009 Torsten Rohlfing
00004 //
00005 //  Copyright 2004-2010 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: 2278 $
00026 //
00027 //  $LastChangedDate: 2010-08-23 12:57:38 -0700 (Mon, 23 Aug 2010) $
00028 //
00029 //  $LastChangedBy: torstenrohlfing $
00030 //
00031 */
00032 
00033 namespace
00034 cmtk
00035 {
00036 
00039 
00040 template<class TInterpolator, class Fct> 
00041 TypedArray::SmartPtr
00042 ReformatVolume::ReformatMasked
00043 ( const UniformVolume* target, const cmtk::XformList& targetToRef, const cmtk::XformList& refToFloat, Fct& fct, const UniformVolume* floating, TInterpolator& interpolator )
00044 {
00045   const DataGrid::IndexType& dims = target->GetDims();
00046 
00047   TypedArray::SmartPtr result = TypedArray::Create( fct.GetDataType( *floating ), target->GetNumberOfPixels() );
00048   if ( fct.UsePaddingValue )
00049     result->SetPaddingValue( fct.PaddingValue );
00050   const TypedArray* targetData = target->GetData();
00051   
00052   Progress::Begin( 0, dims[2], 1, "Volume reformatting" );
00053   
00054 #pragma omp parallel for
00055   for ( int z = 0; z < dims[2]; z++ ) 
00056     {
00057     Vector3D vRef;
00058     Types::DataItem value, targetValue;
00059     size_t offset = z * dims[0] * dims[1];
00060 
00061 #ifdef _OPENMP
00062     if ( ! omp_get_thread_num() )
00063 #endif
00064       Progress::SetProgress( z );
00065     
00066     for ( int y = 0; y < dims[1]; y++ ) 
00067       {
00068       for ( int x = 0; x < dims[0]; x++, offset++ ) 
00069         {
00070         if ( !targetData || (targetData->Get( targetValue, offset ) && (targetValue != 0))) 
00071           {
00072           vRef = target->GetGridLocation( x, y, z );
00073           if ( targetToRef.ApplyInPlace( vRef ) && fct( value, vRef, refToFloat, interpolator ) ) 
00074             {
00075             result->Set( value, offset );
00076             } 
00077           else
00078             {
00079             result->SetPaddingAt( offset );
00080             }
00081           } 
00082         else
00083           {
00084           result->SetPaddingAt( offset );
00085           }
00086         }
00087       }
00088     }
00089   
00090   Progress::Done();
00091   return result;
00092 }
00093 
00094 template<class TInterpolator, class Fct> 
00095 TypedArray::SmartPtr
00096 ReformatVolume::ReformatUnmasked
00097 ( const UniformVolume* target, const cmtk::XformList& targetToRef, const cmtk::XformList& refToFloat, Fct& fct, const UniformVolume* floating, TInterpolator& interpolator )
00098 {
00099   const DataGrid::IndexType& dims = target->GetDims();
00100 
00101   TypedArray::SmartPtr result = TypedArray::Create( fct.GetDataType( *floating ), target->GetNumberOfPixels() );
00102   if ( fct.UsePaddingValue )
00103     result->SetPaddingValue( fct.PaddingValue );
00104 
00105   Progress::Begin( 0, dims[2], 1, "Volume reformatting" );
00106   
00107 #pragma omp parallel for
00108   for ( int z = 0; z < dims[2]; z++ ) 
00109     {
00110     Vector3D vRef;
00111     Types::DataItem value;
00112     size_t offset = z * dims[0] * dims[1];
00113 
00114 #ifdef _OPENMP
00115     if ( ! omp_get_thread_num() )
00116 #endif
00117       Progress::SetProgress( z );
00118     
00119     for ( int y = 0; y < dims[1]; y++ ) 
00120       {
00121       for ( int x = 0; x < dims[0]; x++, offset++ ) 
00122         {
00123         vRef = target->GetGridLocation( x, y, z );
00124         if ( targetToRef.ApplyInPlace( vRef ) && fct( value, vRef, refToFloat, interpolator ) ) 
00125           {
00126           result->Set( value, offset );
00127           } 
00128         else
00129           {
00130           result->SetPaddingAt( offset );
00131           }
00132         } 
00133       }
00134     }
00135   
00136   Progress::Done();
00137   return result;
00138 }
00139 
00140 } // namespace cmtk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines