Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_GEOMETRY_GEOMETRY_HYBRID_FIT_H
00002 #define OPENTISSUE_CORE_GEOMETRY_GEOMETRY_HYBRID_FIT_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/geometry/geometry_hybrid.h>
00013 #include <OpenTissue/core/geometry/geometry_aabb_fit.h>
00014 #include <OpenTissue/core/geometry/geometry_obb_fit.h>
00015 #include <OpenTissue/core/geometry/geometry_compute_smallest_sphere.h>
00016 #include <OpenTissue/core/geometry/geometry_cylinder_fit.h>
00017 #include <OpenTissue/core/geometry/geometry_prism_fit.h>
00018
00019 #include <boost/bind.hpp>
00020
00021 #include <algorithm>
00022 #include <vector>
00023 #include <cmath>
00024 #include <iostream>
00025
00026 namespace OpenTissue
00027 {
00028 namespace geometry
00029 {
00030
00060 template <typename vector3_iterator,typename hybrid_type>
00061 void hybrid_fit(
00062 vector3_iterator begin
00063 , vector3_iterator end
00064 , hybrid_type & hybrid
00065 , bool const & use_convex_surface = true
00066 )
00067 {
00068 typedef typename hybrid_type::real_type real_type;
00069 typedef typename hybrid_type::matrix3x3_type matrix3x3_type;
00070 typedef typename hybrid_type::vector3_type vector3_type;
00071
00072
00073 if(begin==end)
00074 return;
00075
00076 aabb_fit( begin, end, hybrid.m_aabb );
00077 obb_fit( begin, end ,hybrid.m_obb, use_convex_surface );
00078 compute_smallest_sphere( begin, end, hybrid.m_sphere );
00079 cylinder_fit( begin, end, hybrid.m_cylinder, use_convex_surface );
00080 prism_fit( begin, end, hybrid.m_prism, use_convex_surface);
00081
00082 real_type V = hybrid.m_aabb.volume();
00083 hybrid.m_picked = hybrid_type::selection_aabb;
00084
00085 real_type obbV = hybrid.m_obb.volume();
00086 if(obbV<V)
00087 {
00088 V = obbV;
00089 hybrid.m_picked = hybrid_type::selection_obb;
00090 }
00091 real_type cylV = hybrid.m_cylinder.volume();
00092 if(cylV<V)
00093 {
00094 V = cylV;
00095 hybrid.m_picked = hybrid_type::selection_cylinder;
00096 }
00097 real_type sphV = hybrid.m_sphere.volume();
00098 if(sphV<V)
00099 {
00100 V = sphV;
00101 hybrid.m_picked = hybrid_type::selection_sphere;
00102 }
00103 real_type prmV = hybrid.m_prism.volume();
00104 if(prmV<V)
00105 {
00106 V = prmV;
00107 hybrid.m_picked = hybrid_type::selection_prism;
00108 }
00109 }
00110
00121 template <typename hybrid_volume_iterator,typename hybrid_type>
00122 void hybrid_volume_fit(
00123 hybrid_volume_iterator begin
00124 , hybrid_volume_iterator end
00125 , hybrid_type & hybrid
00126 )
00127 {
00128 typedef typename hybrid_type::volume_type volume_type;
00129 typedef typename hybrid_type::vector3_type vector3_type;
00130
00131
00132 if(begin==end)
00133 return;
00134
00135 std::vector<vector3_type> points;
00136
00137 std::for_each(
00138 begin
00139 , end
00140 , boost::bind(
00141 &volume_type::compute_surface_points
00142 , _1
00143 , boost::ref( points )
00144 )
00145 );
00146
00147
00148
00149
00150
00151
00152
00153
00154 hybrid_fit(points.begin(),points.end(),hybrid,true);
00155 }
00156
00157 }
00158 }
00159
00160
00161 #endif