cmtkImagePairAffineRegistrationFunctionalDevice.cxx

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: 2567 $
00026 //
00027 //  $LastChangedDate: 2010-11-29 14:45:58 -0800 (Mon, 29 Nov 2010) $
00028 //
00029 //  $LastChangedBy: torstenrohlfing $
00030 //
00031 */
00032 
00033 #include "cmtkImagePairAffineRegistrationFunctionalDevice.h"
00034 
00035 #include <GPU/cmtkImagePairAffineRegistrationFunctionalDevice_kernels.h>
00036 
00037 namespace
00038 cmtk
00039 {
00040 
00043 
00044 ImagePairAffineRegistrationFunctionalDevice::ImagePairAffineRegistrationFunctionalDevice
00045 ( UniformVolume::SmartConstPtr& fixedVolume, UniformVolume::SmartConstPtr& movingVolume ) 
00046   : ImagePairRegistrationFunctional( fixedVolume, movingVolume ),
00047     m_FixedVolumeOnDevice( DeviceUniformVolumeArray::Create( *(fixedVolume) ) ),
00048     m_MovingVolumeOnDevice( DeviceUniformVolumeArray::Create( *(movingVolume) ) )
00049 {
00050 }
00051 
00052 ImagePairAffineRegistrationFunctionalDevice::ReturnType
00053 ImagePairAffineRegistrationFunctionalDevice::Evaluate()
00054 {
00055   const AffineXform::MatrixType xformMatrix;
00056 
00057   float matrix[4][4];
00058   for ( size_t j = 0; j < 4; ++j )
00059     {
00060     for ( size_t i = 0; i < 4; ++i )
00061       {
00062       matrix[j][i] = static_cast<float>( xformMatrix[j][i] );
00063       }
00064     }
00065 
00066   FixedVector<3,float> deltas = this->m_ReferenceGrid->Deltas();
00067 
00068   // multiply deltas for index-to-image space conversion
00069   for ( size_t j = 0; j < 3; ++j )
00070     {
00071     for ( size_t i = 0; i < 3; ++i )
00072       {
00073       matrix[j][i] *= deltas[j];
00074       }
00075     }
00076 
00077   // divide by size to get to normalized image coordinates after mirror
00078   for ( size_t j = 0; j < 4; ++j ) // here, need to run up to 3 because translation is also in output space
00079     {
00080     for ( size_t i = 0; i < 3; ++i )
00081       {
00082       matrix[j][i] /= this->m_FloatingGrid->Size[i];
00083       }
00084     }
00085   
00086   return -ImagePairAffineRegistrationFunctionalDeviceEvaluateMSD( this->m_ReferenceGrid->m_Dims.begin(), this->m_FixedVolumeOnDevice->GetDeviceArrayPtr()->GetArrayOnDevice(), 
00087                                                                   this->m_FloatingGrid->m_Dims.begin(), this->m_MovingVolumeOnDevice->GetDeviceArrayPtr()->GetArrayOnDevice(), matrix );
00088 }
00089 
00090 } // namespace cmtk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines