00001 #ifndef OPENTISSUE_CORE_CONTAINERS_MESH_POLYMESH_UTIL_POLYMESH_IS_CONVEX_BOUNDARY_H 00002 #define OPENTISSUE_CORE_CONTAINERS_MESH_POLYMESH_UTIL_POLYMESH_IS_CONVEX_BOUNDARY_H 00003 // 00004 // OpenTissue Template Library 00005 // - A generic toolbox for physics-based modeling and simulation. 00006 // Copyright (C) 2008 Department of Computer Science, University of Copenhagen. 00007 // 00008 // OTTL is licensed under zlib: http://opensource.org/licenses/zlib-license.php 00009 // 00010 #include <OpenTissue/configuration.h> 00011 00012 #include <OpenTissue/core/containers/mesh/polymesh/polymesh_face.h> 00013 #include <OpenTissue/core/containers/mesh/polymesh/util/polymesh_valency.h> 00014 #include <OpenTissue/core/containers/mesh/polymesh/util/polymesh_compute_face_normal.h> 00015 00016 00017 namespace OpenTissue 00018 { 00019 namespace polymesh 00020 { 00021 00022 template<typename mesh_type> 00023 bool is_convex_boundary(PolyMeshFace<mesh_type> const & f) 00024 { 00025 typedef typename mesh_type::face_halfedge_circulator face_halfedge_circulator; 00026 typedef typename mesh_type::math_types math_types; 00027 typedef typename math_types::vector3_type vector3_type; 00028 00029 if(valency(f)==0) 00030 { 00031 std::cout << "is_convex_boundary(face): No border!" << std::endl; 00032 return false; 00033 } 00034 00035 vector3_type n; 00036 compute_face_normal(f, n); 00037 00038 face_halfedge_circulator cur(f),end; 00039 face_halfedge_circulator next(f); ++next; 00040 00041 vector3_type u1 = cur->get_destination_iterator()->m_coord - cur->get_origin_iterator()->m_coord; 00042 00043 for(;cur!=end;++cur,++next) 00044 { 00045 vector3_type u2 = next->get_destination_iterator()->m_coord - next->get_origin_iterator()->m_coord; 00046 if( (n*cross(u1 , u2)) <0) 00047 return false; 00048 u1 = u2; 00049 } 00050 return true; 00051 } 00052 00053 } // namespace polymesh 00054 } // namespace OpenTissue 00055 00056 //OPENTISSUE_CORE_CONTAINERS_MESH_POLYMESH_UTIL_POLYMESH_IS_CONVEX_BOUNDARY_H 00057 #endif