Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_CONTAINERS_MESH_COMMON_UTIL_MAKE_SPHERE_H
00002 #define OPENTISSUE_CORE_CONTAINERS_MESH_COMMON_UTIL_MAKE_SPHERE_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/containers/mesh/common/util/mesh_profile_sweep.h>
00013
00014 namespace OpenTissue
00015 {
00016 namespace mesh
00017 {
00018
00019
00030 template<typename mesh_type, typename real_type>
00031 bool make_sphere(
00032 real_type const & radius
00033 , unsigned int slices
00034 , unsigned int segments
00035 , mesh_type & mesh
00036 )
00037 {
00038 using std::cos;
00039 using std::sin;
00040
00041 typedef typename mesh_type::math_types math_types;
00042 typedef typename math_types::value_traits value_traits;
00043 typedef typename math_types::vector3_type vector3_type;
00044
00045
00046 if(slices<3)
00047 throw std::invalid_argument("mesh::make_sphere(): slices was less than 3");
00048 if(segments<2)
00049 throw std::invalid_argument("mesh::make_sphere(): segments was less than 2");
00050
00051 mesh.clear();
00052
00053
00054 std::vector< vector3_type > profile(segments+1);
00055
00056 real_type delta_angle = boost::numeric_cast<real_type>( value_traits::pi()/segments);
00057 real_type angle = delta_angle;
00058
00059 profile[0] = vector3_type(value_traits::zero(),value_traits::zero(),-radius);
00060
00061 for(unsigned int s=1;s<segments;++s)
00062 {
00063 real_type cosinus = boost::numeric_cast<real_type>( cos(angle) );
00064 real_type sinus = boost::numeric_cast<real_type>( sin(angle) );
00065
00066 profile[s](0) = - sinus*radius;
00067 profile[s](1) = value_traits::zero();
00068 profile[s](2) = - cosinus * radius;
00069 angle += delta_angle;
00070 }
00071
00072 profile[segments] = vector3_type(value_traits::zero(),value_traits::zero(),radius);
00073
00074 return profile_sweep(profile.begin(),profile.end(),value_traits::two()*value_traits::pi(),slices,mesh);
00075 }
00076
00077 }
00078 }
00079
00080
00081 #endif