Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_CONTAINERS_MESH_POLYMESH_UTIL_POLYMESH_COMPUTE_FACE_NORMAL_H
00002 #define OPENTISSUE_CORE_CONTAINERS_MESH_POLYMESH_UTIL_POLYMESH_COMPUTE_FACE_NORMAL_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011 #include <OpenTissue/core/containers/mesh/polymesh/polymesh_face.h>
00012 #include <stdexcept>
00013
00014 namespace OpenTissue
00015 {
00016 namespace polymesh
00017 {
00018
00019 template<typename mesh_type,typename vector3_type>
00020 void compute_face_normal(PolyMeshFace<mesh_type> const & f, vector3_type & normal)
00021 {
00022 typedef typename mesh_type::face_vertex_circulator face_vertex_circulator;
00023 typedef typename vector3_type::value_type real_type;
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 normal.clear();
00072
00073 if(valency(f)<=2)
00074 {
00075 throw std::invalid_argument( "compute_face_plane(): Face has less than three vertices!" );
00076 return;
00077 }
00078
00079 face_vertex_circulator cur(f),end;
00080 face_vertex_circulator prev(f);--prev;
00081 face_vertex_circulator next(f);++next;
00082
00083 real_type max_area = static_cast<real_type>(0.0);
00084
00085 for(;cur!=end; ++cur,++next,++prev)
00086 {
00087 vector3_type u1 = cur->m_coord - prev->m_coord;
00088 vector3_type u2 = next->m_coord - cur->m_coord;
00089 vector3_type u1xu2 = u1 % u2;
00090 real_type area_sqr = u1xu2*u1xu2;
00091 if(area_sqr > max_area)
00092 {
00093 max_area = area_sqr;
00094 normal = normalize(u1xu2);
00095 }
00096 }
00097 }
00098
00099 }
00100 }
00101
00102
00103 #endif