Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_GEOMETRY_GEOMETRY_GROWING_ELLIPSOID_FIT_H
00002 #define OPENTISSUE_CORE_GEOMETRY_GEOMETRY_GROWING_ELLIPSOID_FIT_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/geometry/geometry_ellipsoid.h>
00013 #include <OpenTissue/core/geometry/geometry_quadric.h>
00014 #include <OpenTissue/core/geometry/geometry_spherical_growth.h>
00015 #include <OpenTissue/core/geometry/geometry_cylinder_growth.h>
00016 #include <OpenTissue/core/geometry/geometry_ellipsoid_growth.h>
00017 #include <cmath>
00018
00019 namespace OpenTissue
00020 {
00021 namespace geometry
00022 {
00023
00036 template<typename vector3_type, typename vector3_iterator, typename ellipsoid_type>
00037 void ellipsoid_growth_fit(
00038 vector3_type const & p
00039 , vector3_type const & n
00040 , vector3_iterator begin
00041 , vector3_iterator end
00042 , ellipsoid_type & E
00043 )
00044 {
00045
00046 using std::fabs;
00047
00048 typedef typename vector3_type::value_type real_type;
00049 typedef Quadric<typename vector3_type::value_type> quadric_type;
00050
00051 vector3_type q,r,s;
00052 real_type radius,alpha,beta;
00053
00054 quadric_type Q1 = spherical_growth(p,n,begin,end,radius,q);
00055 vector3_type center = p - n*radius;
00056 quadric_type Q = ellipsoid_growth(radius,center,p,q,begin,end,alpha,r);
00057 if(!(fabs(alpha)>0))
00058 {
00059 std::cout << "alpha == 0" << std::endl;
00060 E.set_equation(Q1.m_A, Q1.m_B, Q1.m_C);
00061 return;
00062 }
00063 if(!is_valid_ellipsoid(Q))
00064 {
00065 E.set_equation(Q1.m_A, Q1.m_B, Q1.m_C);
00066 return;
00067 }
00068 quadric_type Q4 = cylindrical_growth(center,radius,p,q,r,alpha,begin,end,beta,s);
00069 if(!(fabs(beta)>0))
00070 {
00071 std::cout << "beta == 0" << std::endl;
00072 E.set_equation(Q.m_A, Q.m_B, Q.m_C);
00073 return;
00074 }
00075
00076
00077
00078
00079
00080
00081 E.set_equation(Q4.m_A, Q4.m_B, Q4.m_C);
00082 return;
00083 }
00084
00085 }
00086 }
00087
00088
00089 #endif