• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

/home/hauberg/Dokumenter/Capture/humim-tracker-0.1/src/OpenTissue/OpenTissue/core/containers/mesh/polymesh/util/polymesh_compute_face_normal.h

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 // 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 #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       // From Mantyla 88:
00027       //
00028       //HalfEdge        *he;
00029       //double          a, b, c, norm;
00030       //double          xi, yi, zi, xj, yj, zj, xc, yc, zc;
00031       //int             length;
00032       //
00033       //a = b = c = xc = yc = zc = 0.0;
00034       //length = 0;
00035       //he = l->ledg;
00036       //do
00037       //{
00038       //        xi = he->vtx->vcoord[0];
00039       //        yi = he->vtx->vcoord[1];
00040       //        zi = he->vtx->vcoord[2];
00041       //        xj = he->nxt->vtx->vcoord[0];
00042       //        yj = he->nxt->vtx->vcoord[1];
00043       //        zj = he->nxt->vtx->vcoord[2];
00044       //        a += (yi - yj) * (zi + zj);
00045       //        b += (zi - zj) * (xi + xj);
00046       //        c += (xi - xj) * (yi + yj);
00047       //        xc += xi;
00048       //        yc += yi;
00049       //        zc += zi;
00050       //        length++;
00051       //}
00052       //while((he = he->nxt) != l->ledg);
00053       //
00054       //if((norm = sqrt(a*a + b*b + c*c)) != 0.0)
00055       //{
00056       //        eq[0] = a / norm;
00057       //        eq[1] = b / norm;
00058       //        eq[2] = c / norm;
00059       //        eq[3] = (eq[0]*xc + eq[1]*yc + eq[2]*zc) / (-length);
00060       //return(SUCCESS);
00061       //}
00062       //else
00063       //{
00064       //        printf("faceeq: null face %d\n", l->lface->faceno);
00065       //        return(ERROR);
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   } // namespace polymesh
00100 } // namespace OpenTissue
00101 
00102 //OPENTISSUE_CORE_CONTAINERS_MESH_POLYMESH_UTIL_POLYMESH_COMPUTE_FACE_NORMAL_H
00103 #endif

Generated on Thu Dec 1 2011 12:51:18 for HUMIM Tracker by  doxygen 1.7.1