Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_GEOMETRY_GEOMETRY_ELLIPSOID_GROWTH_H
00002 #define OPENTISSUE_CORE_GEOMETRY_GEOMETRY_ELLIPSOID_GROWTH_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/math/math_constants.h>
00013
00014 #include <OpenTissue/core/geometry/geometry_quadric.h>
00015 #include <cmath>
00016
00017 namespace OpenTissue
00018 {
00019 namespace geometry
00020 {
00021
00039 template<typename real_type, typename vector3_type, typename vector3_iterator>
00040 Quadric<real_type> ellipsoid_growth(
00041 real_type const & radius
00042 , vector3_type const & center
00043 , vector3_type const & p
00044 , vector3_type const & q
00045 , vector3_iterator begin
00046 , vector3_iterator end
00047 , real_type & alpha
00048 , vector3_type & r
00049 )
00050 {
00051 using std::fabs;
00052
00053 typedef Quadric<real_type> quadric_type;
00054
00055 assert(p!=q || !"ellipsoid_growth(): p and q are the same");
00056 assert(radius>0 || "ellipsoid_growth(): Non-positive radius");
00057
00058 vector3_type np = normalize(p - center);
00059 vector3_type nq = normalize(q - center);
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125 quadric_type Q1 = make_sphere_quadric(radius,center);
00126 quadric_type Q2 = make_plane_product_quadric(p, np, q, nq);
00127
00128 alpha = math::detail::highest<real_type>();
00129 for(vector3_iterator x = begin;x!=end;++x)
00130 {
00131 vector3_type dxp = (*x) - p;
00132 vector3_type dxq = (*x) - q;
00133 if( (dxp*np<0) && (dxq*nq<0) )
00134 {
00135 real_type q2 = Q2( (*x) );
00136 real_type q1 = Q1( (*x) );
00137 q1 = q1<0?0:q1;
00138 real_type tst = - q1 / q2;
00139 assert(q2 < 0 || !"ellipsoid_growth(): argh something was wrong");
00140 assert(q1 >= 0 || !"ellipsoid_growth(): argh something was wrong");
00141 assert(tst >= 0 || !"ellipsoid_growth(): argh something was wrong");
00142 if(0<=tst && tst < alpha )
00143 {
00144 alpha = tst;
00145 r = *x;
00146 }
00147 }
00148 }
00149
00150 if( alpha == math::detail::highest<real_type>() )
00151 alpha=0;
00152
00153 return (Q1 + (Q2*alpha));
00154 }
00155
00156 }
00157 }
00158
00159
00160 #endif