Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
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
00066
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
00082 kk[0] += CubicSpline::DerivInterpSpline( k, f[0] ) * (*coeff_kk);
00083
00084 const Types::Coordinate tmp = CubicSpline::InterpSpline( k, f[0] ) * (*coeff_kk);
00085 kk[1] += tmp;
00086
00087 kk[2] += tmp;
00088 }
00089
00090
00091 const Types::Coordinate tmp = CubicSpline::InterpSpline( l, f[1] );
00092 ll[0] += tmp * kk[0];
00093
00094 ll[1] += CubicSpline::DerivInterpSpline( l, f[1] ) * kk[1];
00095
00096 ll[2] += tmp * kk[2];
00097 }
00098
00099
00100 const Types::Coordinate tmp = CubicSpline::InterpSpline( m, f[2] );
00101 J[dim][0] += tmp * ll[0];
00102
00103 J[dim][1] += tmp * ll[1];
00104
00105 J[dim][2] += CubicSpline::DerivInterpSpline( m, f[2] ) * ll[2];
00106 }
00107 }
00108 }
00109
00110 }