cmtkDeformationField_Jacobian.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: 2425 $
00026 //
00027 //  $LastChangedDate: 2010-10-07 16:14:23 -0700 (Thu, 07 Oct 2010) $
00028 //
00029 //  $LastChangedBy: torstenrohlfing $
00030 //
00031 */
00032 
00033 #include "cmtkDeformationField.h"
00034 
00035 #include <Base/cmtkCubicSpline.h>
00036 
00037 namespace
00038 cmtk
00039 {
00040 
00043 
00044 void
00045 DeformationField::GetJacobian
00046 ( const Self::SpaceVectorType& v, CoordinateMatrix3x3& J ) const
00047 {
00048   Types::Coordinate r[3], f[3];
00049   int grid[3];
00050   
00051   for ( int dim = 0; dim<3; ++dim ) 
00052     {
00053     r[dim] = this->InverseSpacing[dim] * (v[dim] - this->m_Offset[dim]);
00054     grid[dim] = static_cast<int>( r[dim]-1 );
00055     if ( (grid[dim] < 0) || (grid[dim] >= this->m_Dims[dim]-3) )
00056       {
00057       J.Fill( 0.0 );
00058       return;
00059       }
00060     f[dim] = r[dim] - grid[dim] - 1;
00061     }
00062 
00063   const Types::Coordinate* coeff = this->m_Parameters + 3 * ( grid[0] + this->m_Dims[0] * (grid[1] + this->m_Dims[1] * grid[2]) );
00064   
00065   // loop over the three components of the coordinate transformation function,
00066   // x, y, z.
00067   for ( int dim = 0; dim<3; ++dim, ++coeff ) 
00068     {
00069     const Types::Coordinate *coeff_mm = coeff;
00070     for ( int m = 0; m < 4; ++m, coeff_mm += nextK ) 
00071       {
00072       Types::Coordinate ll[3] = { 0, 0, 0 };
00073       const Types::Coordinate *coeff_ll = coeff_mm;
00074       for ( int l = 0; l < 4; ++l, coeff_ll += nextJ ) 
00075         {
00076         Types::Coordinate kk[3] = { 0, 0, 0 };
00077         const Types::Coordinate *coeff_kk = coeff_ll;
00078         
00079         for ( int k = 0; k < 4; ++k, coeff_kk+=3 ) 
00080           {
00081           // dT / dx
00082           kk[0] += CubicSpline::DerivInterpSpline( k, f[0] ) * (*coeff_kk);
00083           // dT / dy
00084           const Types::Coordinate tmp = CubicSpline::InterpSpline( k, f[0] ) * (*coeff_kk);
00085           kk[1] += tmp;
00086           // dT / dz
00087           kk[2] += tmp;
00088           }
00089         
00090         // dT / dx
00091         const Types::Coordinate tmp = CubicSpline::InterpSpline( l, f[1] );
00092         ll[0] += tmp * kk[0];
00093         // dT / dy
00094         ll[1] += CubicSpline::DerivInterpSpline( l, f[1] ) * kk[1];
00095         // dT / dz
00096         ll[2] += tmp * kk[2];
00097         }
00098 
00099       // dT / dx
00100       const Types::Coordinate tmp = CubicSpline::InterpSpline( m, f[2] );
00101       J[dim][0] += tmp * ll[0];
00102       // dT / dy
00103       J[dim][1] += tmp * ll[1];
00104       // dT / dz
00105       J[dim][2] += CubicSpline::DerivInterpSpline( m, f[2] ) * ll[2];
00106       }
00107     }
00108 }
00109 
00110 } // namespace cmtk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines