00001 #ifndef OPENTISSUE_DYNAMICS_PSYS_PSYS_SYSTEM_H 00002 #define OPENTISSUE_DYNAMICS_PSYS_PSYS_SYSTEM_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 <vector> 00013 00014 namespace OpenTissue 00015 { 00016 namespace psys 00017 { 00018 00019 00028 template<typename types > 00029 class System 00030 { 00031 public: 00032 00033 typedef typename types::math_types math_types; 00034 typedef typename math_types::real_type real_type; 00035 typedef typename math_types::vector3_type vector3_type; 00036 typedef typename types::particle_type particle_type; 00037 00038 typedef std::vector<particle_type> particle_container; 00039 typedef typename particle_container::iterator particle_iterator; 00040 typedef typename particle_container::const_iterator const_particle_iterator; 00041 00042 protected: 00043 00044 real_type m_time; 00045 particle_container m_particles; 00046 00047 public: 00048 00049 real_type & time() { return m_time; } 00050 real_type const & time() const { return m_time; } 00051 00052 public: 00053 00054 System() 00055 : m_time(0.0) 00056 {} 00057 00058 ~System(){ clear(); }; 00059 00060 public: 00061 00062 vector3_type min_coord() 00063 { 00064 using std::min; 00065 00066 // TODO: Is it possible to add some lazy evalutation to this? Caching 00067 // previous computed value and only re-compute it if particles have 00068 // changed? 00069 vector3_type min_coord = vector3_type( math::detail::highest<real_type>(),math::detail::highest<real_type>(),math::detail::highest<real_type>() ); 00070 particle_iterator p = particle_begin(); 00071 particle_iterator end = particle_end(); 00072 for(;p!=end;++p) 00073 min_coord = min( min_coord, p->position() ); 00074 } 00075 00076 vector3_type max_coord() 00077 { 00078 using std::max; 00079 00080 // TODO: Is it possible to add some lazy evalutation to this? Caching 00081 // previous computed value and only re-compute it if particles have 00082 // changed? 00083 vector3_type max_coord = vector3_type( math::detail::lowest<real_type>(),math::detail::lowest<real_type>(),math::detail::lowest<real_type>() ); 00084 particle_iterator p = particle_begin(); 00085 particle_iterator end = particle_end(); 00086 for(;p!=end;++p) 00087 max_coord = max( max_coord, p->position() ); 00088 } 00089 00090 public: 00091 00092 void clear() 00093 { 00094 m_particles.clear(); 00095 } 00096 00097 particle_iterator create_particle(particle_type const & p) 00098 { 00099 m_particles.push_back(p); 00100 particle_iterator particle = m_particles.end()-1; 00101 particle->connect ( *this ); 00102 return particle; 00103 } 00104 00105 void erase(particle_iterator p) 00106 { 00107 p->disconnect(); 00108 m_particles.erase(p); 00109 } 00110 00111 particle_iterator & operator()(unsigned int idx) { return m_particles.begin() + idx; } 00112 const_particle_iterator & operator()(unsigned int idx) const { return m_particles.begin() + idx; } 00113 00114 particle_iterator particle_begin() { return m_particles.begin(); } 00115 particle_iterator particle_end() { return m_particles.end(); } 00116 const_particle_iterator particle_begin() const { return m_particles.begin(); } 00117 const_particle_iterator particle_end() const { return m_particles.end(); } 00118 00119 std::size_t particles_size() const { return m_particles.size(); } 00120 00121 }; 00122 00123 } // namespace psys 00124 } // namespace OpenTissue 00125 00126 // OPENTISSUE_DYNAMICS_PSYS_PSYS_SYSTEM_H 00127 #endif