Orfeo Toolbox  3.16
itkCurvatureFlowFunction.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkCurvatureFlowFunction.txx,v $
5  Language: C++
6  Date: $Date: 2009-07-30 11:57:13 $
7  Version: $Revision: 1.20 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 #ifndef __itkCurvatureFlowFunction_txx
18 #define __itkCurvatureFlowFunction_txx
20 
21 #include "vnl/vnl_math.h"
22 
23 namespace itk {
24 
28 template<class TImage>
31 {
32 
33  RadiusType r;
34  unsigned int j;
35  for( j = 0; j < ImageDimension; j++ )
36  {
37  r[j] = 1;
38  }
39 
40  this->SetRadius(r);
41 
42  m_TimeStep = 0.05f;
43 
44 }
45 
46 
50 template<class TImage>
53 ::ComputeGlobalTimeStep( void *itkNotUsed(gd) ) const
54 {
55 
56  return this->GetTimeStep();
57 
58 
59  // \todo compute timestep based on CFL condition
60 #if 0
61  GlobalDataStruct *globalData = (GlobalDataStruct *)gd;
62  TimeStepType dt;
63 
64  if ( globalData->m_MaxChange > 0.0 )
65  {
66  dt = 1.0 / globalData->m_MaxChange;
67  }
68  else
69  {
70  dt = 0.0;
71  }
72 
73  return dt;
74 #endif
75 }
76 
77 
81 template<class TImage>
84 ::ComputeUpdate(const NeighborhoodType &it, void * itkNotUsed(gd),
85  const FloatOffsetType& itkNotUsed(offset))
86 {
87  PixelRealType firstderiv[ImageDimension];
88  PixelRealType secderiv[ImageDimension];
89  PixelRealType crossderiv[ImageDimension][ImageDimension];
90  unsigned long center;
91  unsigned long stride[ImageDimension];
92  unsigned int i,j;
93 
94  const NeighborhoodScalesType neighborhoodScales = this->ComputeNeighborhoodScales();
95 
96  // get the center pixel position
97  center = it.Size() / 2;
98 
99  // cache the stride for each dimension
100  for( i = 0; i < ImageDimension; i++ )
101  {
102  stride[i] = it.GetStride( (unsigned long) i );
103  }
104 
105  PixelRealType magnitudeSqr = 0.0;
106  for( i = 0; i < ImageDimension; i++ )
107  {
108 
109  // compute first order derivatives
110  firstderiv[i] = 0.5 * ( it.GetPixel(center + stride[i]) -
111  it.GetPixel(center - stride[i]) ) * neighborhoodScales[i];
112 
113  // compute second order derivatives
114  secderiv[i] = ( it.GetPixel(center + stride[i]) -
115  2 * it.GetPixel(center) + it.GetPixel( center - stride[i] ) ) * vnl_math_sqr( neighborhoodScales[i] );
116 
117  // compute cross derivatives
118  for( j = i + 1; j < ImageDimension; j++ )
119  {
120  crossderiv[i][j] = 0.25 * (
121  it.GetPixel( center - stride[i] - stride[j] )
122  - it.GetPixel( center - stride[i] + stride[j] )
123  - it.GetPixel( center + stride[i] - stride[j] )
124  + it.GetPixel( center + stride[i] + stride[j] ) )
125  * neighborhoodScales[i] * neighborhoodScales[j];
126  }
127 
128  // accumlate the gradient magnitude squared
129  magnitudeSqr += vnl_math_sqr( (double)firstderiv[i] );
130 
131  }
132 
133  if ( magnitudeSqr < 1e-9 )
134  {
136  }
137 
138  // compute the update value = mean curvature * magnitude
139  PixelRealType update = 0.0;
140  PixelRealType temp;
141 
142  // accumulate dx^2 * (dyy + dzz) terms
143  for( i = 0; i < ImageDimension; i++ )
144  {
145  temp = 0.0;
146  for( j = 0; j < ImageDimension; j++ )
147  {
148  if( j == i ) continue;
149  temp += secderiv[j];
150  }
151 
152  update += temp * vnl_math_sqr( (double)firstderiv[i] );
153  }
154 
155  // accumlate -2 * dx * dy * dxy terms
156  for( i = 0; i < ImageDimension; i++ )
157  {
158  for( j = i + 1; j < ImageDimension; j++ )
159  {
160  update -= 2 * firstderiv[i] * firstderiv[j] *
161  crossderiv[i][j];
162  }
163  }
164 
165  update /= magnitudeSqr;
166 
167  // \todo compute timestep based on CFL condition
168 #if 0
169  GlobalDataStruct *globalData = (GlobalDataStruct *)gd;
170  globalData->m_MaxChange =
171  vnl_math_max( globalData->m_MaxChange, vnl_math_abs(update) );
172 #endif
173  return static_cast<PixelType>(update);
174 
175 }
176 
177 } // end namespace itk
178 
179 #endif

Generated at Sat May 18 2013 23:35:23 for Orfeo Toolbox with doxygen 1.8.3.1