Go to the documentation of this file.00001 #ifndef OPENTISSUE_DYNAMICS_PSYS_PSYS_PARTICLE_H
00002 #define OPENTISSUE_DYNAMICS_PSYS_PSYS_PARTICLE_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/dynamics/psys/psys_connector_facade.h>
00013
00014 namespace OpenTissue
00015 {
00016
00017 namespace psys
00018 {
00019
00020
00021 template<typename types>
00022 class Particle
00023 : public ConnectorFacade< types >
00024 {
00025 public:
00026
00027 typedef typename types::math_types math_types;
00028 typedef typename math_types::real_type real_type;
00029 typedef typename math_types::vector3_type vector3_type;
00030 typedef typename types::system_type system_type;
00031
00032 protected:
00033
00034 bool m_coupled;
00035
00036 vector3_type * m_ptr_r;
00037
00038 vector3_type m_r;
00039 vector3_type m_old_r;
00040 vector3_type m_v;
00041 vector3_type m_f;
00042 vector3_type m_a;
00043 real_type m_inv_mass;
00044 real_type m_mass;
00045
00046
00047 public:
00048
00049 Particle()
00050 : m_coupled (false)
00051 , m_ptr_r(0)
00052 , m_r(0,0,0)
00053 , m_old_r(0,0,0)
00054 , m_v(0,0,0)
00055 , m_f(0,0,0)
00056 , m_a(0,0,0)
00057 , m_inv_mass(1.0)
00058 , m_mass(1.0)
00059
00060 {
00061 }
00062
00063 void bind(vector3_type const & r)
00064 {
00065 m_ptr_r = const_cast<vector3_type*>(&r);
00066 m_old_r = r;
00067 m_coupled = true;
00068 }
00069
00070 void release()
00071 {
00072 if(m_coupled)
00073 {
00074 m_r = *m_ptr_r;
00075 }
00076 m_coupled = false;
00077 }
00078
00079 public:
00080
00081 vector3_type & position() { return m_coupled?*m_ptr_r:m_r; }
00082 vector3_type const & position() const { return m_coupled?*m_ptr_r:m_r; }
00083 vector3_type & old_position() { return m_old_r; }
00084 vector3_type const & old_position() const { return m_old_r; }
00085 vector3_type & velocity() { return m_v; }
00086 vector3_type const & velocity() const { return m_v; }
00087 vector3_type & force() { return m_f; }
00088 vector3_type const & force() const { return m_f; }
00089 vector3_type & acceleration() { return m_a; }
00090 vector3_type const & acceleration() const { return m_a; }
00091 real_type & inv_mass() { return m_inv_mass; }
00092 real_type const & inv_mass() const { return m_inv_mass; }
00093 real_type & mass() { return m_mass; }
00094 real_type const & mass() const { return m_mass; }
00095
00096 };
00097
00098 }
00099
00100 }
00101
00102
00103 #endif