00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <sofa/core/objectmodel/Context.h>
00028
00029
00030
00031 namespace sofa
00032 {
00033
00034 namespace core
00035 {
00036
00037 namespace objectmodel
00038 {
00039
00040 Context::Context()
00041 : is_activated(initData(&is_activated, true, "activated", "To Activate a node"))
00042 , worldGravity_(initData(&worldGravity_, Vec3(0,0,0),"gravity","Gravity in the world coordinate system"))
00043 , dt_(initData(&dt_,0.01,"dt","Time step"))
00044 , time_(initData(&time_,0.,"time","Current time"))
00045 , animate_(initData(&animate_,false,"animate","Animate the Simulation(applied at initialization only)"))
00046 , showVisualModels_ (initData(&showVisualModels_, -1, "showVisualModels","display Visual Models"))
00047 , showBehaviorModels_ (initData(&showBehaviorModels_, -1,"showBehaviorModels","display Behavior Models"))
00048 , showCollisionModels_ (initData(&showCollisionModels_, -1,"showCollisionModels","display Collision Models"))
00049 , showBoundingCollisionModels_(initData(&showBoundingCollisionModels_,-1,"showBoundingCollisionModels","display Bounding Collision Models"))
00050 , showMappings_ (initData(&showMappings_, -1,"showMappings","display Mappings"))
00051 , showMechanicalMappings_ (initData(&showMechanicalMappings_, -1,"showMechanicalMappings","display Mechanical Mappings"))
00052 , showForceFields_ (initData(&showForceFields_, -1,"showForceFields","display Force Fields"))
00053 , showInteractionForceFields_ (initData(&showInteractionForceFields_, -1,"showInteractionForceFields","display Interaction Force Fields"))
00054 , showWireFrame_ (initData(&showWireFrame_, -1,"showWireFrame","display in WireFrame"))
00055 , showNormals_ (initData(&showNormals_, -1,"showNormals","display Normals"))
00056 , multiThreadSimulation_(initData(&multiThreadSimulation_,false,"multiThreadSimulation","Apply multithreaded simulation"))
00057 , currentLevel_(initData(¤tLevel_,0,"currentLevel","Current level of details"))
00058 , coarsestLevel_(initData(&coarsestLevel_,3,"coarsestLevel","Coarsest level of details"))
00059 , finestLevel_(initData(&finestLevel_,0,"finestLevel","Finest level of details"))
00060 {
00061 setPositionInWorld(objectmodel::BaseContext::getPositionInWorld());
00062 setGravityInWorld(objectmodel::BaseContext::getLocalGravity());
00063 setVelocityInWorld(objectmodel::BaseContext::getVelocityInWorld());
00064 setVelocityBasedLinearAccelerationInWorld(objectmodel::BaseContext::getVelocityBasedLinearAccelerationInWorld());
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 }
00080
00082 bool Context::isActive() const {return is_activated.getValue();}
00083
00085 void Context::setActive(bool val){ is_activated.setValue(val);}
00086
00088 const Context::Frame& Context::getPositionInWorld() const
00089 {
00090 return localFrame_;
00091 }
00093 void Context::setPositionInWorld(const Frame& f)
00094 {
00095 localFrame_ = f;
00096 }
00097
00099 const Context::SpatialVector& Context::getVelocityInWorld() const
00100 {
00101 return spatialVelocityInWorld_;
00102 }
00104 void Context::setVelocityInWorld(const SpatialVector& v)
00105 {
00106 spatialVelocityInWorld_ = v;
00107 }
00108
00110 const Context::Vec3& Context::getVelocityBasedLinearAccelerationInWorld() const
00111 {
00112 return velocityBasedLinearAccelerationInWorld_;
00113 }
00115 void Context::setVelocityBasedLinearAccelerationInWorld(const Vec3& a )
00116 {
00117 velocityBasedLinearAccelerationInWorld_ = a;
00118 }
00119
00120
00121
00123 double Context::getDt() const
00124 {
00125 return dt_.getValue();
00126 }
00127
00129 double Context::getTime() const
00130 {
00131 return time_.getValue();
00132 }
00133
00135
00136
00137
00138
00139
00141 Context::Vec3 Context::getLocalGravity() const
00142 {
00143 return getPositionInWorld().backProjectVector(worldGravity_.getValue());
00144 }
00145
00147 const Context::Vec3& Context::getGravityInWorld() const
00148 {
00149 return worldGravity_.getValue();
00150 }
00151
00152
00153
00155 bool Context::getAnimate() const
00156 {
00157 return animate_.getValue();
00158 }
00159
00161 bool Context::getMultiThreadSimulation() const
00162 {
00163 return multiThreadSimulation_.getValue();
00164 }
00165
00167 bool Context::getShowCollisionModels() const
00168 {
00169 if (showCollisionModels_.getValue() < 0) return false;
00170 else return showCollisionModels_.getValue() != 0;
00171 }
00172
00174 bool Context::getShowBoundingCollisionModels() const
00175 {
00176 if (showBoundingCollisionModels_.getValue() < 0) return false;
00177 else return showBoundingCollisionModels_.getValue()!= 0;
00178 }
00179
00181 bool Context::getShowBehaviorModels() const
00182 {
00183 if (showBehaviorModels_.getValue() < 0) return false;
00184 else return showBehaviorModels_.getValue()!= 0;
00185 }
00186
00188 bool Context::getShowVisualModels() const
00189 {
00190 if (showVisualModels_.getValue() < 0) return true;
00191 else return showVisualModels_.getValue()!= 0;
00192 }
00193
00195 bool Context::getShowMappings() const
00196 {
00197 if (showMappings_.getValue() < 0) return false;
00198 else return showMappings_.getValue()!= 0;
00199 }
00200
00202 bool Context::getShowMechanicalMappings() const
00203 {
00204 if (showMechanicalMappings_.getValue() < 0) return false;
00205 else return showMechanicalMappings_.getValue()!= 0;
00206 }
00207
00209 bool Context::getShowForceFields() const
00210 {
00211 if (showForceFields_.getValue() < 0) return false;
00212 else return showForceFields_.getValue()!= 0;
00213 }
00214
00216 bool Context::getShowInteractionForceFields() const
00217 {
00218 if (showInteractionForceFields_.getValue() < 0) return false;
00219 else return showInteractionForceFields_.getValue()!= 0;
00220 }
00221
00223 bool Context::getShowWireFrame() const
00224 {
00225 if (showWireFrame_.getValue() < 0) return false;
00226 else return showWireFrame_.getValue()!= 0;
00227 }
00228
00230 bool Context::getShowNormals() const
00231 {
00232 if (showNormals_.getValue() < 0) return false;
00233 else return showNormals_.getValue()!= 0;
00234 }
00235
00236
00237
00238
00239 int Context::getCurrentLevel() const
00240 {
00241 return currentLevel_.getValue();
00242 }
00243 int Context::getCoarsestLevel() const
00244 {
00245 return coarsestLevel_.getValue();
00246 }
00247 int Context::getFinestLevel() const
00248 {
00249 return finestLevel_.getValue();
00250 }
00251
00252
00253
00254
00256 void Context::setDt(double val)
00257 {
00258 dt_.setValue(val);
00259 }
00260
00262 void Context::setTime(double val)
00263 {
00264 time_.setValue(val);
00265 }
00266
00268
00269
00270
00271
00272
00274 void Context::setGravityInWorld(const Vec3& g)
00275 {
00276 worldGravity_ .setValue(g);
00277 }
00278
00280 void Context::setAnimate(bool val)
00281 {
00282 animate_.setValue(val);
00283 }
00284
00286 void Context::setMultiThreadSimulation(bool val)
00287 {
00288 multiThreadSimulation_.setValue(val);
00289 }
00290
00292 void Context::setShowCollisionModels(bool val)
00293 {
00294 showCollisionModels_.setValue(val);
00295 }
00296
00298 void Context::setShowBoundingCollisionModels(bool val)
00299 {
00300 showBoundingCollisionModels_.setValue(val);
00301 }
00302
00304 void Context::setShowBehaviorModels(bool val)
00305 {
00306 showBehaviorModels_.setValue(val);
00307 }
00308
00310 void Context::setShowVisualModels(bool val)
00311 {
00312 showVisualModels_.setValue(val);
00313 }
00314
00316 void Context::setShowMappings(bool val)
00317 {
00318 showMappings_.setValue(val);
00319 }
00320
00322 void Context::setShowMechanicalMappings(bool val)
00323 {
00324 showMechanicalMappings_.setValue(val);
00325 }
00326
00328 void Context::setShowForceFields(bool val)
00329 {
00330 showForceFields_.setValue(val);
00331 }
00332
00334 void Context::setShowInteractionForceFields(bool val)
00335 {
00336 showInteractionForceFields_.setValue(val);
00337 }
00338
00340 void Context::setShowWireFrame(bool val)
00341 {
00342 showWireFrame_.setValue(val);
00343 }
00344
00346 void Context::setShowNormals(bool val)
00347 {
00348 showNormals_.setValue(val);
00349 }
00350
00351
00352
00353
00354 bool Context::setCurrentLevel(int l)
00355 {
00356 if( l > coarsestLevel_.getValue() )
00357 {
00358 currentLevel_.setValue(coarsestLevel_.getValue());
00359 return false;
00360 }
00361 else if( l < 0 )
00362 {
00363
00364 currentLevel_.setValue( 0 );
00365 return false;
00366 }
00367 currentLevel_.setValue(l);
00368 if( l == coarsestLevel_.getValue() ) return false;
00369 return true;
00370 }
00371 void Context::setCoarsestLevel(int l)
00372 {
00373 coarsestLevel_.setValue( l );
00374 }
00375 void Context::setFinestLevel(int l)
00376 {
00377 finestLevel_.setValue( l );
00378 }
00379
00380
00381
00382
00383 void Context::copyContext(const Context& c)
00384 {
00385
00386
00387
00388 copySimulationContext(c);
00389 copyVisualContext(c);
00390 }
00391
00392
00393 void Context::copySimulationContext(const Context& c)
00394 {
00395 worldGravity_.setValue(c.worldGravity_.getValue());
00396 dt_.setValue(c.dt_.getValue());
00397 time_.setValue(c.time_.getValue());
00398 animate_.setValue(c.animate_.getValue());
00399 multiThreadSimulation_.setValue(c.multiThreadSimulation_.getValue());
00400
00401 localFrame_ = c.localFrame_;
00402 spatialVelocityInWorld_ = c.spatialVelocityInWorld_;
00403 velocityBasedLinearAccelerationInWorld_ = c.velocityBasedLinearAccelerationInWorld_;
00404
00405
00406
00407
00408
00409
00410 }
00411
00412 void Context::copyVisualContext(const Context& c)
00413 {
00414 showCollisionModels_.setValue(c.showCollisionModels_.getValue());
00415 showBoundingCollisionModels_.setValue(c.showBoundingCollisionModels_.getValue());
00416 showBehaviorModels_.setValue(c.showBehaviorModels_.getValue());
00417 showVisualModels_.setValue(c.showVisualModels_.getValue());
00418 showMappings_.setValue(c.showMappings_.getValue());
00419 showMechanicalMappings_.setValue(c.showMechanicalMappings_.getValue());
00420 showForceFields_.setValue(c.showForceFields_.getValue());
00421 showInteractionForceFields_.setValue(c.showInteractionForceFields_.getValue());
00422 showWireFrame_.setValue(c.showWireFrame_.getValue());
00423 showNormals_.setValue(c.showNormals_.getValue());
00424 }
00425
00426 std::ostream& operator << (std::ostream& out, const Context& c )
00427 {
00428 out<<std::endl<<"local gravity = "<<c.getLocalGravity();
00429 out<<std::endl<<"transform from local to world = "<<c.getPositionInWorld();
00430
00431 out<<std::endl<<"spatial velocity = "<<c.getVelocityInWorld();
00432 out<<std::endl<<"acceleration of the origin = "<<c.getVelocityBasedLinearAccelerationInWorld();
00433 return out;
00434 }
00435
00436
00437
00438
00439
00440 }
00441
00442 }
00443
00444 }
00445