Go to the documentation of this file.00001 #ifndef OPENTISSUE_COLLISION_SDF_SDF_INIT_GEOMETRY_H
00002 #define OPENTISSUE_COLLISION_SDF_SDF_INIT_GEOMETRY_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/collision/sdf/sdf_compute_point_sampling.h>
00013 #include <OpenTissue/collision/sdf/sdf_top_down_policy.h>
00014
00015 namespace OpenTissue
00016 {
00017
00018 namespace sdf
00019 {
00020
00021
00041 template<typename mesh_type,typename grid_type,typename sdf_geometry_type>
00042 void init_geometry(
00043 mesh_type & mesh
00044 , grid_type & phi
00045 , double edge_resolution
00046 , bool face_sampling
00047 , sdf_geometry_type & geometry
00048 )
00049 {
00050 typedef typename sdf_geometry_type::bvh_type bvh_type;
00051 typedef typename sdf_geometry_type::vector3_type vector3_type;
00052 typedef typename vector3_type::value_type real_type;
00053 typedef TopDownPolicy<bvh_type> top_down_policy;
00054 typedef bvh::TopDownConstructor<bvh_type, top_down_policy > constructor_type;
00055
00056 geometry.m_mesh = mesh;
00057 geometry.m_phi = phi;
00058
00059 geometry.m_sampling.clear();
00060 compute_point_sampling(mesh,phi, edge_resolution, face_sampling, geometry.m_sampling);
00061
00062 geometry.m_min_coord(0) = math::detail::highest<real_type>();
00063 geometry.m_min_coord(1) = math::detail::highest<real_type>();
00064 geometry.m_min_coord(2) = math::detail::highest<real_type>();
00065 geometry.m_max_coord(0) = math::detail::lowest<real_type>();
00066 geometry.m_max_coord(1) = math::detail::lowest<real_type>();
00067 geometry.m_max_coord(2) = math::detail::lowest<real_type>();
00068 geometry.m_max_radius = 0;
00069 for(typename sdf_geometry_type::point_iterator p = geometry.m_sampling.begin();p!=geometry.m_sampling.end();++p)
00070 {
00071 geometry.m_min_coord = min ( geometry.m_min_coord, (*p) );
00072 geometry.m_max_coord = max ( geometry.m_max_coord, (*p) );
00073 real_type distance = std::sqrt( (*p)*(*p) );
00074 if(distance>geometry.m_max_radius)
00075 geometry.m_max_radius = distance;
00076 }
00077
00078 geometry.m_bvh.clear();
00079 constructor_type constructor;
00080 constructor.run(geometry.m_sampling.begin(),geometry.m_sampling.end(),geometry.m_bvh);
00081
00082 std::cout << "init_geometry(): Sample points = " << geometry.m_sampling.size() << std::endl;
00083 std::cout << "init_geometry(): BVH nodes = " << geometry.m_bvh.size() << std::endl;
00084 }
00085
00086 }
00087
00088 }
00089
00090
00091 #endif