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

/home/hauberg/Dokumenter/Capture/humim-tracker-0.1/src/OpenTissue/OpenTissue/dynamics/edm/models/edm_generic_bezier_patch.h

Go to the documentation of this file.
00001 #ifndef OPENTISSUE_DYNAMICS_EDM_MODELS_EDM_GENERIC_BEZIER_PATCH_H
00002 #define OPENTISSUE_DYNAMICS_EDM_MODELS_EDM_GENERIC_BEZIER_PATCH_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/dynamics/edm/edm_surface.h>
00013 #include <OpenTissue/core/math/math_functions.h>
00014 
00015 #include <vector>
00016 #include <cmath>
00017 
00018 
00019 namespace OpenTissue
00020 {
00021 
00022   namespace edm
00023   {
00024 
00025     template<typename edm_types>
00026     class GenericBezierPatch
00027       : public Surface<edm_types>
00028     {
00029     public:
00030 
00031       typedef          Surface<edm_types>       base_type;
00032       typedef typename edm_types::value_traits  value_traits;
00033       typedef typename edm_types::real_type     real_type;
00034       typedef typename edm_types::vector3_type  vector3_type;
00035 
00036     public:
00037       GenericBezierPatch() 
00038         : base_type()
00039         , m_n(0)
00040       {}
00041 
00042       virtual ~GenericBezierPatch() {}
00043       
00044       void set(size_t order)
00045       {
00046         using std::pow;
00047         base_type::set(static_cast<size_t>(pow(static_cast<real_type>(order)+value_traits::one(),2)));
00048         m_n = order;
00049       }
00050 
00051     private:
00052 
00053       vector3_type position(vector3_type const * a, real_type const & u, real_type const & v) const
00054       {
00055         std::vector<real_type> U(m_n+1), V(m_n+1);
00056         for (size_t i = 0; i <= m_n; ++i)
00057         {
00058           U[i] = B(i,u);
00059           V[i] = B(i,v);
00060         }
00061         vector3_type Q;
00062         for (size_t i = 0; i <= m_n; ++i)
00063           for (size_t j = 0; j <= m_n; ++j)
00064             Q += a[i*(m_n+1)+j]*V[i]*U[j];
00065         return vector3_type(Q);
00066       }
00067 
00068       vector3_type normal(size_t m, size_t n) const
00069       {
00070         // 2009-11-03 kenny: Why do r only accept longs?
00071         long lm = m;
00072         long ln = n;
00073                 
00074         vector3_type const v = this->r(lm+1,ln) - this->r(lm-1,ln);
00075         vector3_type const w = this->r(lm,ln+1) - this->r(lm,ln-1);
00076         return vector3_type(unit( cross(v,w) ));
00077       }
00078 
00079     private:
00080 
00081       real_type B(size_t i, real_type const & t) const
00082       {
00083         using std::pow;
00084         return real_type(pow(t,static_cast<int>(i))*pow(value_traits::one()-t,static_cast<int>(m_n-i))*math::fac<real_type>(m_n)/math::fac<real_type>(i)/math::fac<real_type>(m_n-i));
00085       }
00086 
00087     private:
00088 
00089       size_t m_n;
00090 
00091     };
00092 
00093   }  // namespace edm
00094 
00095 }  // namespace OpenTissue
00096 
00097 // OPENTISSUE_DYNAMICS_EDM_MODELS_EDM_GENERIC_BEZIER_PATCH_H
00098 #endif

Generated on Thu Dec 1 2011 12:52:15 for HUMIM Tracker by  doxygen 1.7.1