00001 #ifndef OPENTISSUE_CORE_CONTAINERS_MESH_POLYMESH_UTIL_POLYMESH_IS_COLLINEAR_H 00002 #define OPENTISSUE_CORE_CONTAINERS_MESH_POLYMESH_UTIL_POLYMESH_IS_COLLINEAR_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 00015 namespace OpenTissue 00016 { 00017 namespace polymesh 00018 { 00019 00020 template<typename mesh_type,typename real_type> 00021 bool is_collinear(PolyMeshFace<mesh_type> const & f, real_type const & tolerance) 00022 { 00023 typedef typename mesh_type::face_halfedge_circulator face_halfedge_circulator; 00024 typedef typename mesh_type::math_types math_types; 00025 typedef typename math_types::vector3_type vector3_type; 00026 00027 if(valency(f)==0) 00028 { 00029 std::cout << "is_collinear(face): No border!" << std::endl; 00030 return false; 00031 } 00032 real_type tol2 = tolerance*tolerance; 00033 face_halfedge_circulator cur(f),end; 00034 face_halfedge_circulator next(f); ++next; 00035 vector3_type u1 = cur->get_destination_iterator()->m_coord - cur->get_origin_iterator()->m_coord; 00036 for(;cur!=end;++cur,++next) 00037 { 00038 vector3_type u2 = next->get_destination_iterator()->m_coord - next->get_origin_iterator()->m_coord; 00039 vector3_type u1xu2 = u1 % u2; 00040 bool collinear = (u1xu2*u1xu2 < tol2); 00041 if(!collinear) 00042 return false; 00043 u1 = u2; 00044 } 00045 return true; 00046 } 00047 00048 template<typename mesh_type> 00049 bool is_collinear(PolyMeshFace<mesh_type> const & f) 00050 { 00051 typedef typename mesh_type::math_types::value_traits value_traits; 00052 00053 return is_collinear(f,value_traits::zero()); 00054 } 00055 00056 } // namespace polymesh 00057 } // namespace OpenTissue 00058 00059 //OPENTISSUE_CORE_CONTAINERS_MESH_POLYMESH_UTIL_POLYMESH_IS_COLLINEAR_H 00060 #endif