00001 #ifndef OPENTISSUE_DYNAMICS_MESHLESS_DEFORMATION_MESHLESS_DEFORMATION_SHAPE_MATCHING_SIMULATOR_H 00002 #define OPENTISSUE_DYNAMICS_MESHLESS_DEFORMATION_MESHLESS_DEFORMATION_SHAPE_MATCHING_SIMULATOR_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/meshless_deformation/meshless_deformation_particle.h> 00013 #include <OpenTissue/dynamics/meshless_deformation/meshless_deformation_cluster.h> 00014 00015 #include <list> 00016 00017 namespace OpenTissue 00018 { 00019 namespace meshless_deformation 00020 { 00048 template<typename math_types> 00049 class ShapeMatchingSimulator 00050 { 00051 public: 00052 00053 typedef typename math_types::real_type real_type; 00054 typedef typename math_types::vector3_type vector3_type; 00055 typedef detail::Particle<math_types> particle_type; 00056 typedef typename std::list<particle_type> particle_container; 00057 typedef typename particle_container::iterator particle_iterator; 00058 typedef detail::Cluster<math_types> cluster_type; 00059 typedef typename std::list<cluster_type> cluster_container; 00060 typedef typename cluster_container::iterator cluster_iterator; 00061 00062 protected: 00063 00064 cluster_container m_clusters; 00065 particle_container m_particles; 00066 00067 public: 00068 00069 particle_type * create_particle() 00070 { 00071 m_particles.push_back(particle_type()); 00072 return &(m_particles.back()); 00073 } 00074 00075 cluster_type * create_cluster() 00076 { 00077 m_clusters.push_back(cluster_type()); 00078 return &(m_clusters.back()); 00079 } 00080 00081 size_t size_particles() const { return m_particles.size(); } 00082 size_t size_clusters() const { return m_clusters.size(); } 00083 00084 particle_iterator particle_begin(){ return m_particles.begin(); } 00085 particle_iterator particle_end(){ return m_particles.end(); } 00086 00087 public: 00088 00089 void clear() 00090 { 00091 m_particles.clear(); 00092 m_clusters.clear(); 00093 } 00094 00095 void init() 00096 { 00097 cluster_iterator begin = m_clusters.begin(); 00098 cluster_iterator end = m_clusters.end(); 00099 cluster_iterator cluster; 00100 for(cluster=begin;cluster!=end;++cluster) 00101 cluster->init(); 00102 } 00103 00110 void run(real_type const & dt) 00111 { 00112 particle_iterator pbegin = m_particles.begin(); 00113 particle_iterator pend = m_particles.end(); 00114 cluster_iterator cbegin = m_clusters.begin(); 00115 cluster_iterator cend = m_clusters.end(); 00116 particle_iterator particle; 00117 cluster_iterator cluster; 00118 00119 for(particle=pbegin;particle!=pend;++particle) 00120 particle->m_f_goal.clear(); 00121 00122 for(cluster=cbegin;cluster!=cend;++cluster) 00123 cluster->run(dt); 00124 00125 for(particle=pbegin;particle!=pend;++particle) 00126 { 00127 if(particle->m_fixed) 00128 continue; 00129 00130 particle->m_v += particle->m_f_goal + (dt/particle->m_mass)*particle->m_f_ext; 00131 particle->x() += dt * particle->m_v; 00132 } 00133 } 00134 00135 }; 00136 00137 } // namespace meshless_deformation 00138 } // namespace OpenTissue 00139 00140 //OPENTISSUE_DYNAMICS_MESHLESS_DEFORMATION_MESHLESS_DEFORMATION_SHAPE_MATCHING_SIMULATOR_H 00141 #endif