Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_SPLINE_SPLINE_SOLVE_TRIDIAGONAL_H
00002 #define OPENTISSUE_CORE_SPLINE_SPLINE_SOLVE_TRIDIAGONAL_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012
00013 #include <OpenTissue/core/math/math_is_number.h>
00014
00015 #include <cassert>
00016
00017 namespace OpenTissue
00018 {
00019 namespace spline
00020 {
00021 namespace detail
00022 {
00041 template<typename vector_type, typename point_container>
00042 inline void solve_tridiagonal(
00043 vector_type const & a
00044 , vector_type const & b
00045 , vector_type const & c
00046 , point_container & P
00047 , point_container const & X
00048 , int const n
00049 )
00050 {
00051 typedef typename vector_type::value_type T;
00052 typedef point_container matrix_type;
00053
00054 int i,j;
00055 int const dim = X[0].size();
00056
00057 vector_type g(n);
00058
00059
00060 matrix_type d;
00061 d.resize(n);
00062 for(i=0;i<n;++i)
00063 {
00064 d[i].resize(dim);
00065 }
00066
00067
00068 g(0) = c[0]/b[0];
00069 assert( is_number( g(0) ) || !"solve_tridiagonal(): NaN encountered");
00070
00071 for(j=0; j<dim; ++j)
00072 {
00073 d[0](j) = X[0](j)/b[0];
00074 assert( is_number( d[0](j) ) || !"solve_tridiagonal(): NaN encountered");
00075 }
00076
00077 for(i=1; i<n; ++i)
00078 {
00079 T tmp = b[i] - a[i]*g(i-1);
00080 g(i) = c[i]/tmp;
00081 assert( is_number( g(i) ) || !"solve_tridiagonal(): NaN encountered");
00082
00083 for(j=0; j<dim; ++j)
00084 {
00085 d[i](j) = (X[i](j) - a[i]*d[i-1](j)) /tmp;
00086 assert( is_number( d[i](j) ) || !"solve_tridiagonal(): NaN encountered");
00087 }
00088 }
00089
00090
00091 for(j=0; j<dim; ++j)
00092 {
00093 P[n-1](j) = d[n-1](j);
00094 assert( is_number( P[n-1](j) ) || !"solve_tridiagonal(): NaN encountered");
00095 }
00096
00097 for(i=n-2; i>=0; --i)
00098 {
00099 for(j=0; j<dim; ++j)
00100 {
00101 P[i](j) = d[i](j) - g(i) * P[i+1](j);
00102 assert( is_number( P[i](j) ) || !"solve_tridiagonal(): NaN encountered");
00103 }
00104 }
00105 }
00106
00107 }
00108 }
00109 }
00110
00111
00112 #endif