Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_CONTAINERS_MESH_POLYMESH_UTIL_POLYMESH_IS_CONVEX_H
00002 #define OPENTISSUE_CORE_CONTAINERS_MESH_POLYMESH_UTIL_POLYMESH_IS_CONVEX_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/containers/mesh/polymesh/polymesh.h>
00013 #include <OpenTissue/core/containers/mesh/polymesh/util/polymesh_dihedral_angle.h>
00014 #include <OpenTissue/core/containers/mesh/common/util/mesh_compute_face_center.h>
00015 #include <OpenTissue/core/containers/mesh/common/util/mesh_compute_face_plane.h>
00016 #include <OpenTissue/core/containers/mesh/polymesh/util/polymesh_valency.h>
00017 #include <OpenTissue/core/geometry/geometry_plane.h>
00018
00019 #include <functional>
00020
00021 namespace OpenTissue
00022 {
00023 namespace polymesh
00024 {
00025
00026 template<typename mesh_type,typename real_type>
00027 bool is_convex(PolyMeshHalfEdge<mesh_type> const & e,real_type const & tolerance)
00028 {
00029 real_type radian;
00030 compute_dihedral_angle(e,radian);
00031 if( radian <= -tolerance )
00032 return false;
00033 return true;
00034 }
00035
00036 template<typename mesh_type>
00037 bool is_convex(PolyMeshHalfEdge<mesh_type> const & e)
00038 {
00039 typedef typename mesh_type::math_types::value_traits value_traits;
00040 return is_convex(e,value_traits::zero());
00041 }
00042
00043 template<typename mesh_type,typename real_type>
00044 bool is_convex(PolyMeshFace<mesh_type> const & face, real_type const & tolerance)
00045 {
00046 typedef typename mesh_type::face_face_circulator face_face_circulator;
00047
00048 typedef typename mesh_type::math_types math_types;
00049 typedef typename math_types::vector3_type vector3_type;
00050 typedef geometry::Plane<math_types> plane_type;
00051
00052 if(valency(face)==0)
00053 {
00054 std::cout << "is_convex(face): No border!" << std::endl;
00055 return false;
00056 }
00057 plane_type plane;
00058 vector3_type center;
00059
00060 compute_face_center(face,center);
00061
00062 face_face_circulator twin(face),end;
00063 for(;twin!=end;++twin)
00064 {
00065 compute_face_plane( *twin, plane );
00066 if(plane.signed_distance(center) > tolerance)
00067 return false;
00068 }
00069 return true;
00070 }
00071
00072 template<typename mesh_type>
00073 bool is_convex(PolyMeshFace<mesh_type> const & face)
00074 {
00075 typedef typename mesh_type::math_types::value_traits value_traits;
00076
00077 return is_convex(face,value_traits::zero());
00078 }
00079
00080 template<typename mesh_type,typename real_type>
00081 bool is_convex(PolyMeshVertex<mesh_type> const & v,real_type const & tolerance)
00082 {
00083 typedef typename mesh_type::vertex_halfedge_circulator vertex_halfedge_circulator;
00084
00085 if(valency(v)==0)
00086 return false;
00087
00088 vertex_halfedge_circulator h(v), end;
00089 for(;h!=end;++h)
00090 {
00091 if( ! is_convex(*h,tolerance) )
00092 return false;
00093 }
00094 return true;
00095 }
00096
00097 template<typename mesh_type>
00098 bool is_convex(PolyMeshVertex<mesh_type> const & v)
00099 {
00100 typedef typename mesh_type::math_types::value_traits value_traits;
00101 return is_convex(v, value_traits::zero());
00102 }
00103
00104 template< typename mesh_type, typename real_type>
00105 bool is_convex( mesh_type const & mesh, real_type const & tolerance)
00106 {
00107 typename mesh_type::const_face_iterator end = mesh.face_end();
00108 typename mesh_type::const_face_iterator f = mesh.face_begin();
00109 for(;f!=end;++f)
00110 {
00111 if(! is_convex( *f, tolerance ) )
00112 return false;
00113 }
00114 return true;
00115 }
00116
00117 template< typename mesh_type >
00118 bool is_convex( mesh_type const & mesh)
00119 {
00120 typedef typename mesh_type::math_types::value_traits value_traits;
00121 return is_convex(mesh, value_traits::zero());
00122 }
00123
00124 }
00125
00126 }
00127
00128
00129 #endif