| 1 | /* | 
| 2 | * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. | 
| 3 | * | 
| 4 | * The University of Notre Dame grants you ("Licensee") a | 
| 5 | * non-exclusive, royalty free, license to use, modify and | 
| 6 | * redistribute this software in source and binary code form, provided | 
| 7 | * that the following conditions are met: | 
| 8 | * | 
| 9 | * 1. Acknowledgement of the program authors must be made in any | 
| 10 | *    publication of scientific results based in part on use of the | 
| 11 | *    program.  An acceptable form of acknowledgement is citation of | 
| 12 | *    the article in which the program was described (Matthew | 
| 13 | *    A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher | 
| 14 | *    J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented | 
| 15 | *    Parallel Simulation Engine for Molecular Dynamics," | 
| 16 | *    J. Comput. Chem. 26, pp. 252-271 (2005)) | 
| 17 | * | 
| 18 | * 2. Redistributions of source code must retain the above copyright | 
| 19 | *    notice, this list of conditions and the following disclaimer. | 
| 20 | * | 
| 21 | * 3. Redistributions in binary form must reproduce the above copyright | 
| 22 | *    notice, this list of conditions and the following disclaimer in the | 
| 23 | *    documentation and/or other materials provided with the | 
| 24 | *    distribution. | 
| 25 | * | 
| 26 | * This software is provided "AS IS," without a warranty of any | 
| 27 | * kind. All express or implied conditions, representations and | 
| 28 | * warranties, including any implied warranty of merchantability, | 
| 29 | * fitness for a particular purpose or non-infringement, are hereby | 
| 30 | * excluded.  The University of Notre Dame and its licensors shall not | 
| 31 | * be liable for any damages suffered by licensee as a result of | 
| 32 | * using, modifying or distributing the software or its | 
| 33 | * derivatives. In no event will the University of Notre Dame or its | 
| 34 | * licensors be liable for any lost revenue, profit or data, or for | 
| 35 | * direct, indirect, special, consequential, incidental or punitive | 
| 36 | * damages, however caused and regardless of the theory of liability, | 
| 37 | * arising out of the use of or inability to use software, even if the | 
| 38 | * University of Notre Dame has been advised of the possibility of | 
| 39 | * such damages. | 
| 40 | */ | 
| 41 |  | 
| 42 | /** | 
| 43 | * @file StuntDouble.hpp | 
| 44 | * @author    tlin | 
| 45 | * @date  10/22/2004 | 
| 46 | * @version 1.0 | 
| 47 | */ | 
| 48 |  | 
| 49 | #ifndef PRIMITIVES_STUNTDOUBLE_HPP | 
| 50 | #define PRIMITIVES_STUNTDOUBLE_HPP | 
| 51 |  | 
| 52 | #include <vector> | 
| 53 |  | 
| 54 | #include "visitors/BaseVisitor.hpp" | 
| 55 | #include "math/Quaternion.hpp" | 
| 56 | #include "math/SquareMatrix3.hpp" | 
| 57 | #include "math/Vector3.hpp" | 
| 58 | #include "utils/PropertyMap.hpp" | 
| 59 | #include "brains/Snapshot.hpp" | 
| 60 | #include "brains/SnapshotManager.hpp" | 
| 61 | namespace oopse{ | 
| 62 |  | 
| 63 |  | 
| 64 |  | 
| 65 | /** | 
| 66 | * @class StuntDouble StuntDouble.hpp "Primitives/StuntDouble.hpp" | 
| 67 | * @brief | 
| 68 | *     "Don't move, or you're dead! Stand up! Captain, we've got them!" | 
| 69 | * | 
| 70 | *     "Spectacular stunt, my friends, but all for naught. Turn around | 
| 71 | *      please. Ha. What a pity. What a pity. So, Princess, you thought | 
| 72 | *      you could outwit the imperious forces of...." | 
| 73 | * | 
| 74 | *     "You idiots! These are not them. You've captured their stunt | 
| 75 | *      doubles! Search the area. Find them! Find them!" | 
| 76 | * | 
| 77 | * StuntDouble is a very strange idea.  A StuntDouble stands in for | 
| 78 | * some object that can be manipulated by the Integrators or | 
| 79 | * Minimizers.  Some of the manipulable objects are Atoms, some are | 
| 80 | * DirectionalAtoms, and some are RigidBodies.  StuntDouble | 
| 81 | * provides an interface for the Integrators and Minimizers to use, | 
| 82 | * and does some preliminary sanity checking so that the program | 
| 83 | * doesn't try to do something stupid like torque an Atom (The | 
| 84 | * quotes above are from Spaceballs...) | 
| 85 | * | 
| 86 | * @note the dynamic data of stuntdouble will be stored outside of the class | 
| 87 | */ | 
| 88 | class StuntDouble{ | 
| 89 | public: | 
| 90 |  | 
| 91 | enum ObjectType{ | 
| 92 | otAtom, | 
| 93 | otDAtom, | 
| 94 | otRigidBody | 
| 95 | }; | 
| 96 |  | 
| 97 | virtual ~StuntDouble(); | 
| 98 |  | 
| 99 | /** | 
| 100 | * Returns the global index of this stuntdouble. | 
| 101 | * @return  the global index of this stuntdouble | 
| 102 | */ | 
| 103 | int getGlobalIndex() { | 
| 104 | return globalIndex_; | 
| 105 | } | 
| 106 |  | 
| 107 | /** | 
| 108 | * Sets the global index of this stuntdouble. | 
| 109 | * @param new global index to be set | 
| 110 | */ | 
| 111 | void setGlobalIndex(int index) { | 
| 112 | globalIndex_ = index; | 
| 113 | } | 
| 114 |  | 
| 115 | /** | 
| 116 | * Returns the local index of this stuntdouble | 
| 117 | * @return the local index of this stuntdouble | 
| 118 | */ | 
| 119 | int getLocalIndex() { | 
| 120 | return localIndex_; | 
| 121 | } | 
| 122 |  | 
| 123 | /** | 
| 124 | * Sets the local index of this stuntdouble | 
| 125 | * @param index new index to be set | 
| 126 | */ | 
| 127 | void setLocalIndex(int index) { | 
| 128 | localIndex_ = index; | 
| 129 | } | 
| 130 |  | 
| 131 | /** | 
| 132 | * Sets the Snapshot Manager of this stuntdouble | 
| 133 | */ | 
| 134 | void setSnapshotManager(SnapshotManager* sman) { | 
| 135 | snapshotMan_ = sman; | 
| 136 | } | 
| 137 |  | 
| 138 | /** | 
| 139 | * Tests if this stuntdouble is an atom | 
| 140 | * @return true is this stuntdouble is an atom(or a directional atom), return false otherwise | 
| 141 | */ | 
| 142 | bool isAtom(){ | 
| 143 | return objType_ == otAtom || objType_ == otDAtom; | 
| 144 | } | 
| 145 |  | 
| 146 | /** | 
| 147 | * Tests if this stuntdouble is an directional atom | 
| 148 | * @return true if this stuntdouble is an directional atom, return false otherwise | 
| 149 | */ | 
| 150 | bool isDirectionalAtom(){ | 
| 151 | return objType_ == otDAtom; | 
| 152 | } | 
| 153 |  | 
| 154 | /** | 
| 155 | * Tests if this stuntdouble is a rigid body. | 
| 156 | * @return true if this stuntdouble is a rigid body, otherwise return false | 
| 157 | */ | 
| 158 | bool isRigidBody(){ | 
| 159 | return objType_ == otRigidBody; | 
| 160 | } | 
| 161 |  | 
| 162 | /** | 
| 163 | * Tests if this stuntdouble is a directional one. | 
| 164 | * @return true is this stuntdouble is a directional atom or a rigid body, return false otherwise | 
| 165 | */ | 
| 166 | bool isDirectional(){ | 
| 167 | return isDirectionalAtom() || isRigidBody(); | 
| 168 | } | 
| 169 |  | 
| 170 | /** | 
| 171 | * Returns the previous position of this stuntdouble | 
| 172 | * @return the position of this stuntdouble | 
| 173 | */ | 
| 174 | Vector3d getPrevPos() { | 
| 175 | return ((snapshotMan_->getPrevSnapshot())->*storage_).position[localIndex_]; | 
| 176 | } | 
| 177 |  | 
| 178 | /** | 
| 179 | * Returns the current position of this stuntdouble | 
| 180 | * @return the position of this stuntdouble | 
| 181 | */ | 
| 182 | Vector3d getPos() { | 
| 183 | return ((snapshotMan_->getCurrentSnapshot())->*storage_).position[localIndex_]; | 
| 184 | } | 
| 185 |  | 
| 186 | /** | 
| 187 | * Returns the position of this stuntdouble in specified snapshot | 
| 188 | * @return the position of this stuntdouble | 
| 189 | * @param snapshotNo | 
| 190 | */ | 
| 191 | Vector3d getPos(int snapshotNo) { | 
| 192 | return ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).position[localIndex_]; | 
| 193 | } | 
| 194 |  | 
| 195 | /** | 
| 196 | * Sets  the previous position of this stuntdouble | 
| 197 | * @param pos  new position | 
| 198 | * @see #getPos | 
| 199 | */ | 
| 200 | void setPrevPos(const Vector3d& pos) { | 
| 201 | ((snapshotMan_->getPrevSnapshot())->*storage_).position[localIndex_] = pos; | 
| 202 | } | 
| 203 |  | 
| 204 | /** | 
| 205 | * Sets  the current position of this stuntdouble | 
| 206 | * @param pos  new position | 
| 207 | */ | 
| 208 | void setPos(const Vector3d& pos) { | 
| 209 | DataStorage&  data = snapshotMan_->getCurrentSnapshot()->*storage_; | 
| 210 | data.position[localIndex_] = pos; | 
| 211 | //((snapshotMan_->getCurrentSnapshot())->*storage_).position[localIndex_] = pos; | 
| 212 | } | 
| 213 |  | 
| 214 | /** | 
| 215 | * Sets  the position of this stuntdouble in specified snapshot | 
| 216 | * @param pos position to be set | 
| 217 | * @param snapshotNo | 
| 218 | * @see #getPos | 
| 219 | */ | 
| 220 | void setPos(const Vector3d& pos, int snapshotNo) { | 
| 221 |  | 
| 222 | ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).position[localIndex_] = pos; | 
| 223 |  | 
| 224 | } | 
| 225 |  | 
| 226 | /** | 
| 227 | * Returns the previous velocity of this stuntdouble | 
| 228 | * @return the velocity of this stuntdouble | 
| 229 | */ | 
| 230 | Vector3d getPrevVel() { | 
| 231 | return ((snapshotMan_->getPrevSnapshot())->*storage_).velocity[localIndex_]; | 
| 232 | } | 
| 233 |  | 
| 234 | /** | 
| 235 | * Returns the current velocity of this stuntdouble | 
| 236 | * @return the velocity of this stuntdouble | 
| 237 | */ | 
| 238 | Vector3d getVel() { | 
| 239 | return ((snapshotMan_->getCurrentSnapshot())->*storage_).velocity[localIndex_]; | 
| 240 | } | 
| 241 |  | 
| 242 | /** | 
| 243 | * Returns the velocity of this stuntdouble in specified snapshot | 
| 244 | * @return the velocity of this stuntdouble | 
| 245 | * @param snapshotNo | 
| 246 | */ | 
| 247 | Vector3d getVel(int snapshotNo) { | 
| 248 | return ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).velocity[localIndex_]; | 
| 249 | } | 
| 250 |  | 
| 251 | /** | 
| 252 | * Sets  the previous velocity of this stuntdouble | 
| 253 | * @param vel  new velocity | 
| 254 | * @see #getVel | 
| 255 | */ | 
| 256 | void setPrevVel(const Vector3d& vel) { | 
| 257 | ((snapshotMan_->getPrevSnapshot())->*storage_).velocity[localIndex_] = vel; | 
| 258 | } | 
| 259 |  | 
| 260 | /** | 
| 261 | * Sets  the current velocity of this stuntdouble | 
| 262 | * @param vel  new velocity | 
| 263 | */ | 
| 264 | void setVel(const Vector3d& vel) { | 
| 265 | ((snapshotMan_->getCurrentSnapshot())->*storage_).velocity[localIndex_] = vel; | 
| 266 | } | 
| 267 |  | 
| 268 | /** | 
| 269 | * Sets  the velocity of this stuntdouble in specified snapshot | 
| 270 | * @param vel velocity to be set | 
| 271 | * @param snapshotNo | 
| 272 | * @see #getVel | 
| 273 | */ | 
| 274 | void setVel(const Vector3d& vel, int snapshotNo) { | 
| 275 | ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).velocity[localIndex_] = vel; | 
| 276 | } | 
| 277 |  | 
| 278 | /** | 
| 279 | * Returns the previous rotation matrix of this stuntdouble | 
| 280 | * @return the rotation matrix of this stuntdouble | 
| 281 | */ | 
| 282 | RotMat3x3d getPrevA() { | 
| 283 | return ((snapshotMan_->getPrevSnapshot())->*storage_).aMat[localIndex_]; | 
| 284 | } | 
| 285 |  | 
| 286 | /** | 
| 287 | * Returns the current rotation matrix of this stuntdouble | 
| 288 | * @return the rotation matrix of this stuntdouble | 
| 289 | */ | 
| 290 | RotMat3x3d getA() { | 
| 291 | return ((snapshotMan_->getCurrentSnapshot())->*storage_).aMat[localIndex_]; | 
| 292 | } | 
| 293 |  | 
| 294 | /** | 
| 295 | * Returns the rotation matrix of this stuntdouble in specified snapshot | 
| 296 | * | 
| 297 | * @return the rotation matrix of this stuntdouble | 
| 298 | * @param snapshotNo | 
| 299 | */ | 
| 300 | RotMat3x3d getA(int snapshotNo) { | 
| 301 | return ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).aMat[localIndex_]; | 
| 302 | } | 
| 303 |  | 
| 304 | /** | 
| 305 | * Sets  the previous rotation matrix of this stuntdouble | 
| 306 | * @param a  new rotation matrix | 
| 307 | * @see #getA | 
| 308 | */ | 
| 309 | virtual void setPrevA(const RotMat3x3d& a) { | 
| 310 | ((snapshotMan_->getPrevSnapshot())->*storage_).aMat[localIndex_] = a; | 
| 311 | } | 
| 312 |  | 
| 313 | /** | 
| 314 | * Sets  the current rotation matrix of this stuntdouble | 
| 315 | * @param a  new rotation matrix | 
| 316 | */ | 
| 317 | virtual void setA(const RotMat3x3d& a) { | 
| 318 | ((snapshotMan_->getCurrentSnapshot())->*storage_).aMat[localIndex_] = a; | 
| 319 | } | 
| 320 |  | 
| 321 | /** | 
| 322 | * Sets  the rotation matrix of this stuntdouble in specified snapshot | 
| 323 | * @param a rotation matrix to be set | 
| 324 | * @param snapshotNo | 
| 325 | * @see #getA | 
| 326 | */ | 
| 327 | virtual void setA(const RotMat3x3d& a, int snapshotNo) { | 
| 328 | ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).aMat[localIndex_] = a; | 
| 329 | } | 
| 330 |  | 
| 331 | /** | 
| 332 | * Returns the previous angular momentum of this stuntdouble (body-fixed). | 
| 333 | * @return the angular momentum of this stuntdouble | 
| 334 | */ | 
| 335 | Vector3d getPrevJ() { | 
| 336 | return ((snapshotMan_->getPrevSnapshot())->*storage_).angularMomentum[localIndex_]; | 
| 337 | } | 
| 338 |  | 
| 339 | /** | 
| 340 | * Returns the current angular momentum of this stuntdouble (body -fixed). | 
| 341 | * @return the angular momentum of this stuntdouble | 
| 342 | */ | 
| 343 | Vector3d getJ() { | 
| 344 | return ((snapshotMan_->getCurrentSnapshot())->*storage_).angularMomentum[localIndex_]; | 
| 345 | } | 
| 346 |  | 
| 347 | /** | 
| 348 | * Returns the angular momentum of this stuntdouble in specified snapshot (body-fixed). | 
| 349 | * @return the angular momentum of this stuntdouble | 
| 350 | * @param snapshotNo | 
| 351 | */ | 
| 352 | Vector3d getJ(int snapshotNo) { | 
| 353 | return ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).angularMomentum[localIndex_]; | 
| 354 | } | 
| 355 |  | 
| 356 | /** | 
| 357 | * Sets  the previous angular momentum of this stuntdouble (body-fixed). | 
| 358 | * @param angMom  new angular momentum | 
| 359 | * @see #getJ | 
| 360 | */ | 
| 361 | void setPrevJ(const Vector3d& angMom) { | 
| 362 | ((snapshotMan_->getPrevSnapshot())->*storage_).angularMomentum[localIndex_] = angMom; | 
| 363 | } | 
| 364 |  | 
| 365 | /** | 
| 366 | * Sets  the current angular momentum of this stuntdouble (body-fixed). | 
| 367 | * @param angMom  new angular momentum | 
| 368 | */ | 
| 369 | void setJ(const Vector3d& angMom) { | 
| 370 | ((snapshotMan_->getCurrentSnapshot())->*storage_).angularMomentum[localIndex_] = angMom; | 
| 371 | } | 
| 372 |  | 
| 373 | /** | 
| 374 | * Sets the angular momentum of this stuntdouble in specified snapshot(body-fixed). | 
| 375 | * @param angMom angular momentum to be set | 
| 376 | * @param snapshotNo | 
| 377 | * @see #getJ | 
| 378 | */ | 
| 379 | void setJ(const Vector3d& angMom, int snapshotNo) { | 
| 380 | ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).angularMomentum[localIndex_] = angMom; | 
| 381 | } | 
| 382 |  | 
| 383 | /** | 
| 384 | * Returns the previous quaternion of this stuntdouble | 
| 385 | * @return the quaternion of this stuntdouble | 
| 386 | */ | 
| 387 | Quat4d getPrevQ() { | 
| 388 | return ((snapshotMan_->getPrevSnapshot())->*storage_).aMat[localIndex_].toQuaternion(); | 
| 389 | } | 
| 390 |  | 
| 391 | /** | 
| 392 | * Returns the current quaternion of this stuntdouble | 
| 393 | * @return the quaternion of this stuntdouble | 
| 394 | */ | 
| 395 | Quat4d getQ() { | 
| 396 | return ((snapshotMan_->getCurrentSnapshot())->*storage_).aMat[localIndex_].toQuaternion(); | 
| 397 | } | 
| 398 |  | 
| 399 | /** | 
| 400 | * Returns the quaternion of this stuntdouble in specified snapshot | 
| 401 | * @return the quaternion of this stuntdouble | 
| 402 | * @param snapshotNo | 
| 403 | */ | 
| 404 | Quat4d getQ(int snapshotNo) { | 
| 405 | return ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).aMat[localIndex_].toQuaternion(); | 
| 406 | } | 
| 407 |  | 
| 408 | /** | 
| 409 | * Sets  the previous quaternion of this stuntdouble | 
| 410 | * @param q  new quaternion | 
| 411 | * @note actual storage data is rotation matrix | 
| 412 | */ | 
| 413 | void setPrevQ(const Quat4d& q) { | 
| 414 | setPrevA(q); | 
| 415 | } | 
| 416 |  | 
| 417 | /** | 
| 418 | * Sets  the current quaternion of this stuntdouble | 
| 419 | * @param q  new quaternion | 
| 420 | * @note actual storage data is rotation matrix | 
| 421 | */ | 
| 422 | void setQ(const Quat4d& q) { | 
| 423 | setA(q); | 
| 424 | } | 
| 425 |  | 
| 426 | /** | 
| 427 | * Sets  the quaternion of this stuntdouble in specified snapshot | 
| 428 | * | 
| 429 | * @param q quaternion to be set | 
| 430 | * @param snapshotNo | 
| 431 | * @note actual storage data is rotation matrix | 
| 432 | */ | 
| 433 | void setQ(const Quat4d& q, int snapshotNo) { | 
| 434 | setA(q, snapshotNo); | 
| 435 | } | 
| 436 |  | 
| 437 | /** | 
| 438 | * Returns the previous euler angles of this stuntdouble | 
| 439 | * @return the euler angles of this stuntdouble | 
| 440 | */ | 
| 441 | Vector3d getPrevEuler() { | 
| 442 | return ((snapshotMan_->getPrevSnapshot())->*storage_).aMat[localIndex_].toEulerAngles(); | 
| 443 | } | 
| 444 |  | 
| 445 | /** | 
| 446 | * Returns the current euler angles of this stuntdouble | 
| 447 | * @return the euler angles of this stuntdouble | 
| 448 | */ | 
| 449 | Vector3d getEuler() { | 
| 450 | return ((snapshotMan_->getCurrentSnapshot())->*storage_).aMat[localIndex_].toEulerAngles(); | 
| 451 | } | 
| 452 |  | 
| 453 | /** | 
| 454 | * Returns the euler angles of this stuntdouble in specified snapshot. | 
| 455 | * @return the euler angles of this stuntdouble | 
| 456 | * @param snapshotNo | 
| 457 | */ | 
| 458 | Vector3d getEuler(int snapshotNo) { | 
| 459 | return ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).aMat[localIndex_].toEulerAngles(); | 
| 460 | } | 
| 461 |  | 
| 462 | /** | 
| 463 | * Sets  the previous euler angles of this stuntdouble. | 
| 464 | * @param euler  new euler angles | 
| 465 | * @see #getEuler | 
| 466 | * @note actual storage data is rotation matrix | 
| 467 | */ | 
| 468 | void setPrevEuler(const Vector3d& euler) { | 
| 469 | ((snapshotMan_->getPrevSnapshot())->*storage_).aMat[localIndex_] = euler; | 
| 470 | } | 
| 471 |  | 
| 472 | /** | 
| 473 | * Sets  the current euler angles of this stuntdouble | 
| 474 | * @param euler  new euler angles | 
| 475 | */ | 
| 476 | void setEuler(const Vector3d& euler) { | 
| 477 | ((snapshotMan_->getCurrentSnapshot())->*storage_).aMat[localIndex_] = euler; | 
| 478 | } | 
| 479 |  | 
| 480 | /** | 
| 481 | * Sets  the euler angles  of this stuntdouble in specified snapshot | 
| 482 | * | 
| 483 | * @param euler euler angles to be set | 
| 484 | * @param snapshotNo | 
| 485 | * @note actual storage data is rotation matrix | 
| 486 | */ | 
| 487 | void setEuler(const Vector3d& euler, int snapshotNo) { | 
| 488 | ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).aMat[localIndex_] = euler; | 
| 489 | } | 
| 490 |  | 
| 491 | /** | 
| 492 | * Returns the previous unit vectors of this stuntdouble | 
| 493 | * @return the unit vectors of this stuntdouble | 
| 494 | */ | 
| 495 | RotMat3x3d getPrevElectroFrame() { | 
| 496 | return ((snapshotMan_->getPrevSnapshot())->*storage_).electroFrame[localIndex_]; | 
| 497 | } | 
| 498 |  | 
| 499 | /** | 
| 500 | * Returns the current unit vectors of this stuntdouble | 
| 501 | * @return the unit vectors of this stuntdouble | 
| 502 | */ | 
| 503 | RotMat3x3d getElectroFrame() { | 
| 504 | return ((snapshotMan_->getCurrentSnapshot())->*storage_).electroFrame[localIndex_]; | 
| 505 | } | 
| 506 |  | 
| 507 | /** | 
| 508 | * Returns the unit vectors of this stuntdouble in specified snapshot | 
| 509 | * | 
| 510 | * @return the unit vectors of this stuntdouble | 
| 511 | * @param snapshotNo | 
| 512 | */ | 
| 513 | RotMat3x3d getElectroFrame(int snapshotNo) { | 
| 514 | return ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).electroFrame[localIndex_]; | 
| 515 | } | 
| 516 |  | 
| 517 | /** | 
| 518 | * Returns the previous force of this stuntdouble | 
| 519 | * @return the force of this stuntdouble | 
| 520 | */ | 
| 521 | Vector3d getPrevFrc() { | 
| 522 | return ((snapshotMan_->getPrevSnapshot())->*storage_).force[localIndex_]; | 
| 523 | } | 
| 524 |  | 
| 525 | /** | 
| 526 | * Returns the current force of this stuntdouble | 
| 527 | * @return the force of this stuntdouble | 
| 528 | */ | 
| 529 | Vector3d getFrc() { | 
| 530 | return ((snapshotMan_->getCurrentSnapshot())->*storage_).force[localIndex_]; | 
| 531 | } | 
| 532 |  | 
| 533 | /** | 
| 534 | * Returns the force of this stuntdouble in specified snapshot | 
| 535 | * | 
| 536 | * @return the force of this stuntdouble | 
| 537 | * @param snapshotNo | 
| 538 | */ | 
| 539 | Vector3d getFrc(int snapshotNo) { | 
| 540 | return ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).force[localIndex_]; | 
| 541 | } | 
| 542 |  | 
| 543 | /** | 
| 544 | * Sets  the previous force of this stuntdouble | 
| 545 | * | 
| 546 | * @param frc  new force | 
| 547 | * @see #getFrc | 
| 548 | */ | 
| 549 | void setPrevFrc(const Vector3d& frc) { | 
| 550 | ((snapshotMan_->getPrevSnapshot())->*storage_).force[localIndex_] = frc; | 
| 551 | } | 
| 552 |  | 
| 553 | /** | 
| 554 | * Sets  the current force of this stuntdouble | 
| 555 | * @param frc  new force | 
| 556 | */ | 
| 557 | void setFrc(const Vector3d& frc) { | 
| 558 | ((snapshotMan_->getCurrentSnapshot())->*storage_).force[localIndex_] = frc; | 
| 559 | } | 
| 560 |  | 
| 561 | /** | 
| 562 | * Sets  the force of this stuntdouble in specified snapshot | 
| 563 | * | 
| 564 | * @param frc force to be set | 
| 565 | * @param snapshotNo | 
| 566 | * @see #getFrc | 
| 567 | */ | 
| 568 | void setFrc(const Vector3d& frc, int snapshotNo) { | 
| 569 | ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).force[localIndex_] = frc; | 
| 570 | } | 
| 571 |  | 
| 572 | /** | 
| 573 | * Adds force into the previous force of this stuntdouble | 
| 574 | * | 
| 575 | * @param frc  new force | 
| 576 | * @see #getFrc | 
| 577 | */ | 
| 578 | void addPrevFrc(const Vector3d& frc) { | 
| 579 | ((snapshotMan_->getPrevSnapshot())->*storage_).force[localIndex_] += frc; | 
| 580 | } | 
| 581 |  | 
| 582 | /** | 
| 583 | * Adds force into the current force of this stuntdouble | 
| 584 | * @param frc  new force | 
| 585 | */ | 
| 586 | void addFrc(const Vector3d& frc) { | 
| 587 | ((snapshotMan_->getCurrentSnapshot())->*storage_).force[localIndex_] += frc; | 
| 588 | } | 
| 589 |  | 
| 590 | /** | 
| 591 | * Adds force into the force of this stuntdouble in specified snapshot | 
| 592 | * | 
| 593 | * @param frc force to be set | 
| 594 | * @param snapshotNo | 
| 595 | * @see #getFrc | 
| 596 | */ | 
| 597 | void addFrc(const Vector3d& frc, int snapshotNo) { | 
| 598 | ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).force[localIndex_] += frc; | 
| 599 | } | 
| 600 |  | 
| 601 | /** | 
| 602 | * Returns the previous torque of this stuntdouble | 
| 603 | * @return the torque of this stuntdouble | 
| 604 | */ | 
| 605 | Vector3d getPrevTrq() { | 
| 606 | return ((snapshotMan_->getPrevSnapshot())->*storage_).torque[localIndex_]; | 
| 607 | } | 
| 608 |  | 
| 609 | /** | 
| 610 | * Returns the current torque of this stuntdouble | 
| 611 | * @return the torque of this stuntdouble | 
| 612 | */ | 
| 613 | Vector3d getTrq() { | 
| 614 | return ((snapshotMan_->getCurrentSnapshot())->*storage_).torque[localIndex_]; | 
| 615 | } | 
| 616 |  | 
| 617 | /** | 
| 618 | * Returns the torque of this stuntdouble in specified snapshot | 
| 619 | * | 
| 620 | * @return the torque of this stuntdouble | 
| 621 | * @param snapshotNo | 
| 622 | */ | 
| 623 | Vector3d getTrq(int snapshotNo) { | 
| 624 | return ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).torque[localIndex_]; | 
| 625 | } | 
| 626 |  | 
| 627 | /** | 
| 628 | * Sets  the previous torque of this stuntdouble | 
| 629 | * | 
| 630 | * @param trq  new torque | 
| 631 | * @see #getTrq | 
| 632 | */ | 
| 633 | void setPrevTrq(const Vector3d& trq) { | 
| 634 | ((snapshotMan_->getPrevSnapshot())->*storage_).torque[localIndex_] = trq; | 
| 635 | } | 
| 636 |  | 
| 637 | /** | 
| 638 | * Sets  the current torque of this stuntdouble | 
| 639 | * @param trq  new torque | 
| 640 | */ | 
| 641 | void setTrq(const Vector3d& trq) { | 
| 642 | ((snapshotMan_->getCurrentSnapshot())->*storage_).torque[localIndex_] = trq; | 
| 643 | } | 
| 644 |  | 
| 645 | /** | 
| 646 | * Sets  the torque of this stuntdouble in specified snapshot | 
| 647 | * | 
| 648 | * @param trq torque to be set | 
| 649 | * @param snapshotNo | 
| 650 | * @see #getTrq | 
| 651 | */ | 
| 652 | void setTrq(const Vector3d& trq, int snapshotNo) { | 
| 653 | ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).torque[localIndex_] = trq; | 
| 654 | } | 
| 655 |  | 
| 656 | /** | 
| 657 | * Adds torque into the previous torque of this stuntdouble | 
| 658 | * | 
| 659 | * @param trq  new torque | 
| 660 | * @see #getTrq | 
| 661 | */ | 
| 662 | void addPrevTrq(const Vector3d& trq) { | 
| 663 | ((snapshotMan_->getPrevSnapshot())->*storage_).torque[localIndex_] += trq; | 
| 664 | } | 
| 665 |  | 
| 666 | /** | 
| 667 | * Adds torque into the current torque of this stuntdouble | 
| 668 | * @param trq  new torque | 
| 669 | */ | 
| 670 | void addTrq(const Vector3d& trq) { | 
| 671 | ((snapshotMan_->getCurrentSnapshot())->*storage_).torque[localIndex_] += trq; | 
| 672 | } | 
| 673 |  | 
| 674 | /** | 
| 675 | * Adds torque into the torque of this stuntdouble in specified snapshot | 
| 676 | * | 
| 677 | * @param trq torque to be add | 
| 678 | * @param snapshotNo | 
| 679 | * @see #getTrq | 
| 680 | */ | 
| 681 | void addTrq(const Vector3d& trq, int snapshotNo) { | 
| 682 | ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).torque[localIndex_] += trq; | 
| 683 | } | 
| 684 |  | 
| 685 |  | 
| 686 | /** | 
| 687 | * Returns the previous z-angle of this stuntdouble | 
| 688 | * @return the z-angle of this stuntdouble | 
| 689 | */ | 
| 690 | double getPrevZangle() { | 
| 691 | return ((snapshotMan_->getPrevSnapshot())->*storage_).zAngle[localIndex_]; | 
| 692 | } | 
| 693 |  | 
| 694 | /** | 
| 695 | * Returns the current z-angle of this stuntdouble | 
| 696 | * @return the z-angle of this stuntdouble | 
| 697 | */ | 
| 698 | double getZangle() { | 
| 699 | return ((snapshotMan_->getCurrentSnapshot())->*storage_).zAngle[localIndex_]; | 
| 700 | } | 
| 701 |  | 
| 702 | /** | 
| 703 | * Returns the z-angle of this stuntdouble in specified snapshot | 
| 704 | * @return the z-angle of this stuntdouble | 
| 705 | * @param snapshotNo | 
| 706 | */ | 
| 707 | double getZangle(int snapshotNo) { | 
| 708 | return ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).zAngle[localIndex_]; | 
| 709 | } | 
| 710 |  | 
| 711 | /** | 
| 712 | * Sets  the previous z-angle of this stuntdouble | 
| 713 | * @param angle  new z-angle | 
| 714 | * @see #getZangle | 
| 715 | */ | 
| 716 | void setPrevZangle(double angle) { | 
| 717 | ((snapshotMan_->getPrevSnapshot())->*storage_).zAngle[localIndex_] = angle; | 
| 718 | } | 
| 719 |  | 
| 720 | /** | 
| 721 | * Sets  the current z-angle of this stuntdouble | 
| 722 | * @param angle  new z-angle | 
| 723 | */ | 
| 724 | void setZangle(double angle) { | 
| 725 | ((snapshotMan_->getCurrentSnapshot())->*storage_).zAngle[localIndex_] = angle; | 
| 726 | } | 
| 727 |  | 
| 728 | /** | 
| 729 | * Sets  the z-angle of this stuntdouble in specified snapshot | 
| 730 | * @param angle z-angle to be set | 
| 731 | * @param snapshotNo | 
| 732 | * @see #getZangle | 
| 733 | */ | 
| 734 | void setZangle(double angle, int snapshotNo) { | 
| 735 | ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).zAngle[localIndex_] = angle; | 
| 736 | } | 
| 737 |  | 
| 738 | /** | 
| 739 | * Adds z-angle into the previous z-angle of this stuntdouble | 
| 740 | * @param angle  new z-angle | 
| 741 | * @see #getZangle | 
| 742 | */ | 
| 743 | void addPrevZangle(double angle) { | 
| 744 | ((snapshotMan_->getPrevSnapshot())->*storage_).zAngle[localIndex_] += angle; | 
| 745 | } | 
| 746 |  | 
| 747 | /** | 
| 748 | * Adds z-angle into the current z-angle of this stuntdouble | 
| 749 | * @param angle  new z-angle | 
| 750 | */ | 
| 751 | void addZangle(double angle) { | 
| 752 | ((snapshotMan_->getCurrentSnapshot())->*storage_).zAngle[localIndex_] += angle; | 
| 753 | } | 
| 754 |  | 
| 755 | /** | 
| 756 | * Adds z-angle into the z-angle of this stuntdouble in specified snapshot | 
| 757 | * @param angle z-angle to be add | 
| 758 | * @param snapshotNo | 
| 759 | * @see #getZangle | 
| 760 | */ | 
| 761 | void addZangle(double angle, int snapshotNo) { | 
| 762 | ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).zAngle[localIndex_] += angle; | 
| 763 | } | 
| 764 |  | 
| 765 | /** Set the force of this stuntdouble to zero */ | 
| 766 | void zeroForcesAndTorques(); | 
| 767 | /** | 
| 768 | * Returns the inertia tensor of this stuntdouble | 
| 769 | * @return the inertia tensor of this stuntdouble | 
| 770 | */ | 
| 771 | virtual Mat3x3d getI() = 0; | 
| 772 |  | 
| 773 | /** | 
| 774 | * Returns the gradient of this stuntdouble | 
| 775 | * @return the gradient of this stuntdouble | 
| 776 | */ | 
| 777 | virtual std::vector<double> getGrad() = 0; | 
| 778 |  | 
| 779 | /** | 
| 780 | * Tests the  if this stuntdouble is a  linear rigidbody | 
| 781 | * | 
| 782 | * @return true if this stuntdouble is a  linear rigidbody, otherwise return false | 
| 783 | * @note atom and directional atom will always return false | 
| 784 | * | 
| 785 | * @see #linearAxis | 
| 786 | */ | 
| 787 | bool isLinear() { | 
| 788 | return linear_; | 
| 789 | } | 
| 790 |  | 
| 791 | /** | 
| 792 | * Returns the linear axis of the rigidbody, atom and directional atom will always return -1 | 
| 793 | * | 
| 794 | * @return the linear axis of the rigidbody | 
| 795 | * | 
| 796 | * @see #isLinear | 
| 797 | */ | 
| 798 | int linearAxis() { | 
| 799 | return linearAxis_; | 
| 800 | } | 
| 801 |  | 
| 802 | /** Returns the mass of this stuntdouble */ | 
| 803 | double getMass() { | 
| 804 | return mass_; | 
| 805 | } | 
| 806 |  | 
| 807 | /** | 
| 808 | * Sets the mass of this stuntdoulbe | 
| 809 | * @param mass the mass to be set | 
| 810 | */ | 
| 811 | void setMass(double mass) { | 
| 812 | mass_ = mass; | 
| 813 | } | 
| 814 |  | 
| 815 | /** Returns the name of this stuntdouble */ | 
| 816 | virtual std::string getType() = 0; | 
| 817 |  | 
| 818 | /** Sets the name of this stuntdouble*/ | 
| 819 | virtual void setType(const std::string& name) {} | 
| 820 |  | 
| 821 | /** | 
| 822 | * Converts a lab fixed vector to a body fixed vector. | 
| 823 | * @return body fixed vector | 
| 824 | * @param v lab fixed vector | 
| 825 | */ | 
| 826 | Vector3d lab2Body(const Vector3d& v) { | 
| 827 | return getA() * v; | 
| 828 | } | 
| 829 |  | 
| 830 | Vector3d lab2Body(const Vector3d& v, int frame) { | 
| 831 | return getA(frame) * v; | 
| 832 | } | 
| 833 |  | 
| 834 | /** | 
| 835 | * Converts a body fixed vector to a lab fixed vector. | 
| 836 | * @return corresponding lab fixed vector | 
| 837 | * @param v body fixed vector | 
| 838 | */ | 
| 839 | Vector3d body2Lab(const Vector3d& v){ | 
| 840 | return getA().transpose() * v; | 
| 841 | } | 
| 842 |  | 
| 843 | Vector3d body2Lab(const Vector3d& v, int frame){ | 
| 844 | return getA(frame).transpose() * v; | 
| 845 | } | 
| 846 | /** | 
| 847 | * <p> | 
| 848 | * The purpose of the Visitor Pattern is to encapsulate an operation that you want to perform on | 
| 849 | * the elements of a data structure. In this way, you can change the operation being performed | 
| 850 | * on a structure without the need of changing the classes of the elements that you are operating | 
| 851 | * on. Using a Visitor pattern allows you to decouple the classes for the data structure and the | 
| 852 | * algorithms used upon them | 
| 853 | * </p> | 
| 854 | * @param v visitor | 
| 855 | */ | 
| 856 | virtual void accept(BaseVisitor* v) = 0; | 
| 857 |  | 
| 858 | //below functions are just forward functions | 
| 859 | /** | 
| 860 | * Adds property into property map | 
| 861 | * @param genData GenericData to be added into PropertyMap | 
| 862 | */ | 
| 863 | void addProperty(GenericData* genData); | 
| 864 |  | 
| 865 | /** | 
| 866 | * Removes property from PropertyMap by name | 
| 867 | * @param propName the name of property to be removed | 
| 868 | */ | 
| 869 | void removeProperty(const std::string& propName); | 
| 870 |  | 
| 871 | /** | 
| 872 | * clear all of the properties | 
| 873 | */ | 
| 874 | void clearProperties(); | 
| 875 |  | 
| 876 | /** | 
| 877 | * Returns all names of properties | 
| 878 | * @return all names of properties | 
| 879 | */ | 
| 880 | std::vector<std::string> getPropertyNames(); | 
| 881 |  | 
| 882 | /** | 
| 883 | * Returns all of the properties in PropertyMap | 
| 884 | * @return all of the properties in PropertyMap | 
| 885 | */ | 
| 886 | std::vector<GenericData*> getProperties(); | 
| 887 |  | 
| 888 | /** | 
| 889 | * Returns property | 
| 890 | * @param propName name of property | 
| 891 | * @return a pointer point to property with propName. If no property named propName | 
| 892 | * exists, return NULL | 
| 893 | */ | 
| 894 | GenericData* getPropertyByName(const std::string& propName); | 
| 895 |  | 
| 896 | protected: | 
| 897 |  | 
| 898 | StuntDouble(ObjectType objType, DataStoragePointer storage); | 
| 899 |  | 
| 900 | StuntDouble(const StuntDouble& sd); | 
| 901 | StuntDouble& operator=(const StuntDouble& sd); | 
| 902 |  | 
| 903 | ObjectType objType_; | 
| 904 | DataStoragePointer storage_; | 
| 905 | SnapshotManager* snapshotMan_; | 
| 906 |  | 
| 907 | bool linear_; | 
| 908 | int linearAxis_; | 
| 909 |  | 
| 910 |  | 
| 911 | int globalIndex_; | 
| 912 | int localIndex_; | 
| 913 |  | 
| 914 |  | 
| 915 | double mass_; | 
| 916 |  | 
| 917 | private: | 
| 918 |  | 
| 919 | PropertyMap properties_; | 
| 920 | }; | 
| 921 |  | 
| 922 | }//end namespace oopse | 
| 923 | #endif //PRIMITIVES_STUNTDOUBLE_HPP |