Go to the documentation of this file.00001 #ifndef OPENTISSUE_DYNAMICS_EDM_EDM_SYSTEM_H
00002 #define OPENTISSUE_DYNAMICS_EDM_EDM_SYSTEM_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <map>
00013 #include <cassert>
00014
00015 namespace OpenTissue
00016 {
00017
00018 namespace edm
00019 {
00020
00021 template<typename edm_types_>
00022 class System
00023 {
00024 public:
00025 typedef edm_types_ edm_types;
00026 typedef typename edm_types::value_traits value_traits;
00027 typedef typename edm_types::model_type model_type;
00028 typedef typename edm_types::force_type force_type;
00029 typedef typename edm_types::object_type object_type;
00030
00031 typedef std::map<std::string, force_type *> EDMIOForces;
00032 typedef std::map<std::string, object_type *> EDMIOObjects;
00033 typedef std::map<std::string, model_type *> EDMIOModels;
00034
00035 public:
00036
00037 System()
00038 {}
00039
00040 virtual ~System()
00041 {
00042 reset();
00043 }
00044
00045 public:
00046
00047 void run(bool compute_elasticity = false)
00048 {
00049 typename EDMIOModels::iterator model, end = m_models.end();
00050 for (model = m_models.begin(); model != end; ++model)
00051 model->second->run(compute_elasticity);
00052 }
00053
00054 public:
00055
00056 void reset()
00057 {
00058
00059
00060
00061 for (typename EDMIOModels::iterator iob = m_models.begin(); iob != m_models.end(); ++iob)
00062 delete iob->second;
00063
00064 m_models.clear();
00065
00066
00067 for (typename EDMIOObjects::iterator ioo = m_objects.begin(); ioo != m_objects.end(); ++ioo)
00068 delete ioo->second;
00069
00070 m_objects.clear();
00071
00072
00073 for (typename EDMIOForces::iterator iof = m_forces.begin(); iof != m_forces.end(); ++iof)
00074 delete iof->second;
00075
00076 m_forces.clear();
00077 }
00078
00079 template<typename edm_force>
00080 edm_force * create_force(std::string const & id)
00081 {
00082 if (m_forces.end() != m_forces.find(id))
00083 return 0;
00084 edm_force* f = new edm_force;
00085 m_forces[id] = f;
00086 return f;
00087 }
00088
00089 void delete_force(std::string const & id)
00090 {
00091 typename EDMIOForces::iterator f = m_forces.find(id);
00092 if (m_forces.end() == f)
00093 return 0;
00094 delete f->second;
00095 m_forces.erase(f);
00096 }
00097
00098 force_type const * get_force(std::string const & id) const
00099 {
00100 typename EDMIOForces::const_iterator f = m_forces.find(id);
00101 if (m_forces.end() == f)
00102 return 0;
00103 return f->second;
00104 }
00105
00106 template<typename shape_type>
00107 shape_type * create_object(std::string const & id)
00108 {
00109 if (m_objects.end() != m_objects.find(id))
00110 return 0;
00111 object_type * o = new object_type;
00112 m_objects[id] = o;
00113 return &o->template create_shape<shape_type>();
00114 }
00115
00116 void delete_object(std::string const & id)
00117 {
00118 typename EDMIOObjects::iterator o = m_objects.find(id);
00119 if (m_objects.end() == o)
00120 return 0;
00121 delete o->second;
00122 m_objects.erase(o);
00123 }
00124
00125 object_type const * get_object(std::string const & id) const
00126 {
00127 typename EDMIOObjects::const_iterator o = m_objects.find(id);
00128 if (m_objects.end() == o)
00129 return 0;
00130 return o->second;
00131 }
00132
00133 object_type * get_object(std::string const & id)
00134 {
00135 typename EDMIOObjects::const_iterator o = m_objects.find(id);
00136 if (m_objects.end() == o)
00137 return 0;
00138 return o->second;
00139 }
00140
00141 template<typename edm_model>
00142 edm_model * create_model(std::string const & id)
00143 {
00144 if (m_models.end() != m_models.find(id))
00145 return 0;
00146 edm_model* m = new edm_model;
00147 m_models[id] = m;
00148 return m;
00149 }
00150
00151 void delete_model(std::string const & id)
00152 {
00153 typename EDMIOModels::iterator b = m_models.find(id);
00154 if (m_models.end() == b)
00155 return 0;
00156 delete b->second;
00157 m_models.erase(b);
00158 }
00159
00160 model_type const * get_model(std::string const & id) const
00161 {
00162 typename EDMIOModels::const_iterator b = m_models.find(id);
00163 if (m_models.end() == b)
00164 return 0;
00165 return b->second;
00166 }
00167
00168 model_type & get_model(size_t idx)
00169 {
00170 typename EDMIOModels::iterator tmp = m_models.begin();
00171 while (idx--) ++tmp;
00172 assert(m_models.end() != tmp);
00173 return *tmp->second;
00174 }
00175
00176 size_t model_count() const
00177 {
00178 return size_t(static_cast<size_t>(m_models.size()));
00179 }
00180
00181 EDMIOForces const & forces() const
00182 {
00183 return m_forces;
00184 }
00185
00186 EDMIOObjects const & objects() const
00187 {
00188 return m_objects;
00189 }
00190
00191 EDMIOModels const & models() const
00192 {
00193 return m_models;
00194 }
00195
00196 private:
00197
00198 EDMIOForces m_forces;
00199 EDMIOObjects m_objects;
00200 EDMIOModels m_models;
00201
00202 };
00203
00204 }
00205
00206 }
00207
00208
00209 #endif