00001 #ifndef OPENTISSUE_CORE_CONTAINERS_MESH_POLYMESH_UTIL_POLYMESH_COMPUTE_FACE_AREA_H 00002 #define OPENTISSUE_CORE_CONTAINERS_MESH_POLYMESH_UTIL_POLYMESH_COMPUTE_FACE_AREA_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/util/polymesh_valency.h> 00013 #include <OpenTissue/core/containers/mesh/polymesh/polymesh_face.h> 00014 00015 #include <cmath> 00016 00017 namespace OpenTissue 00018 { 00019 namespace polymesh 00020 { 00021 00029 template<typename mesh_type> 00030 typename mesh_type::math_types::real_type 00031 compute_face_area(PolyMeshFace<mesh_type> const & f) 00032 { 00033 using std::sqrt; 00034 00035 typedef typename mesh_type::face_vertex_circulator face_vertex_circulator; 00036 typedef typename mesh_type::vertex_type vertex_type; 00037 00038 typedef typename mesh_type::math_types math_types; 00039 typedef typename math_types::vector3_type vector3_type; 00040 typedef typename math_types::real_type real_type; 00041 00042 00043 real_type area = real_type(); // by standard defualt consructed integral types are zero 00044 00045 if(valency(f)<=2) 00046 { 00047 std::cout << "compute_face_area(): Face has less than three vertices!" << std::endl; 00048 return real_type(); 00049 } 00050 00051 face_vertex_circulator v(f),end; 00052 face_vertex_circulator vi(f);++vi; 00053 face_vertex_circulator vj(f);++vj;++vj; 00054 00055 vector3_type A; 00056 A.clear(); // By OT convention, sets elements to zero! 00057 00058 for(;vj!=end;++vi,++vj) 00059 { 00060 vector3_type ui = vi->m_coord - v->m_coord; 00061 vector3_type uj = vj->m_coord - v->m_coord; 00062 A += (ui % uj); 00063 } 00064 area = sqrt(A*A)*0.5; 00065 return area; 00066 } 00067 00068 } // namespace polymesh 00069 } // namespace OpenTissue 00070 00071 //OPENTISSUE_CORE_CONTAINERS_MESH_POLYMESH_UTIL_POLYMESH_COMPUTE_FACE_AREA_H 00072 #endif