Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_CONTAINERS_MESH_POLYMESH_UTIL_POLYMESH_IS_PLANAR_H
00002 #define OPENTISSUE_CORE_CONTAINERS_MESH_POLYMESH_UTIL_POLYMESH_IS_PLANAR_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/containers/mesh/polymesh/polymesh_vertex.h>
00013 #include <OpenTissue/core/containers/mesh/polymesh/polymesh_halfedge.h>
00014 #include <OpenTissue/core/containers/mesh/polymesh/polymesh_face.h>
00015 #include <OpenTissue/core/containers/mesh/polymesh/util/polymesh_dihedral_angle.h>
00016 #include <OpenTissue/core/containers/mesh/polymesh/util/polymesh_compute_face_normal.h>
00017 #include <OpenTissue/core/containers/mesh/polymesh/util/polymesh_valency.h>
00018
00019 namespace OpenTissue
00020 {
00021 namespace polymesh
00022 {
00023
00024 template<typename mesh_type,typename real_type>
00025 bool is_planar(PolyMeshHalfEdge<mesh_type> const & e,real_type const & tolerance)
00026 {
00027 real_type radian;
00028 compute_dihedral_angle(e,radian);
00029 if(tolerance < radian || radian < -tolerance)
00030 return false;
00031 return true;
00032 }
00033
00034 template<typename mesh_type>
00035 bool is_planar(PolyMeshHalfEdge<mesh_type> const & e)
00036 {
00037 typedef typename mesh_type::math_types math_types;
00038 typedef typename math_types::value_traits value_traits;
00039 return is_planar(e,value_traits::zero());
00040 }
00041
00042 template<typename mesh_type,typename real_type>
00043 bool is_planar(PolyMeshFace<mesh_type> const & f, real_type const & tolerance )
00044 {
00045 typedef typename mesh_type::face_vertex_circulator face_vertex_circulator;
00046 typedef typename mesh_type::math_types math_types;
00047 typedef typename math_types::vector3_type vector3_type;
00048
00049 if(valency(f)==0)
00050 {
00051 std::cout << "is_planar(face): No border!" << std::endl;
00052 return false;
00053 }
00054 vector3_type n;
00055 compute_face_normal( f, n );
00056 face_vertex_circulator v(f),end;
00057 real_type min_proj = n*v->m_coord;
00058 real_type max_proj = min_proj;
00059 ++v;
00060 for(;v!=end;++v)
00061 {
00062 real_type proj = n*v->m_coord;
00063 min_proj = std::min(min_proj,proj);
00064 max_proj = std::max(max_proj,proj);
00065 }
00066 if( (max_proj-min_proj)>tolerance)
00067 return false;
00068 return true;
00069 }
00070
00071 template<typename mesh_type>
00072 bool is_planar(PolyMeshFace<mesh_type> const & f)
00073 {
00074 typedef typename mesh_type::math_types math_types;
00075 typedef typename math_types::value_traits value_traits;
00076 return is_planar(f, value_traits::zero() );
00077 }
00078
00079 template<typename mesh_type,typename real_type>
00080 bool is_planar(PolyMeshVertex<mesh_type> const & v,real_type const & tolerance)
00081 {
00082 typedef typename mesh_type::vertex_halfedge_circulator vertex_halfedge_circulator;
00083 if(valency(v)==0)
00084 return true;
00085 vertex_halfedge_circulator h(v), end;
00086 for(;h!=end;++h)
00087 {
00088 if(! is_planar(*h,tolerance) )
00089 return false;
00090 }
00091 return true;
00092 }
00093
00094 template<typename mesh_type>
00095 bool is_planar(PolyMeshVertex<mesh_type> const & v)
00096 {
00097 typedef typename mesh_type::math_types math_types;
00098 typedef typename math_types::value_traits value_traits;
00099
00100 return is_planar(v,value_traits::zero());
00101 }
00102
00103 }
00104 }
00105
00106
00107 #endif