| 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 | * Freezes out all velocity, angular velocity, forces and torques | 
| 172 | * on this StuntDouble.  Also computes the number of frozen degrees | 
| 173 | * of freedom. | 
| 174 | * @return the total number of frozen degrees of freedom | 
| 175 | */ | 
| 176 | int freeze() { | 
| 177 |  | 
| 178 | int fdf = 3; | 
| 179 |  | 
| 180 | setVel(V3Zero); | 
| 181 | setFrc(V3Zero); | 
| 182 | if (isDirectional()){ | 
| 183 | setJ(V3Zero); | 
| 184 | setTrq(V3Zero); | 
| 185 | if (isLinear()) | 
| 186 | fdf +=2; | 
| 187 | else | 
| 188 | fdf +=3; | 
| 189 | } | 
| 190 | return fdf; | 
| 191 | } | 
| 192 |  | 
| 193 | /** | 
| 194 | * Returns the previous position of this stuntdouble | 
| 195 | * @return the position of this stuntdouble | 
| 196 | */ | 
| 197 | Vector3d getPrevPos() { | 
| 198 | return ((snapshotMan_->getPrevSnapshot())->*storage_).position[localIndex_]; | 
| 199 | } | 
| 200 |  | 
| 201 | /** | 
| 202 | * Returns the current position of this stuntdouble | 
| 203 | * @return the position of this stuntdouble | 
| 204 | */ | 
| 205 | Vector3d getPos() { | 
| 206 | return ((snapshotMan_->getCurrentSnapshot())->*storage_).position[localIndex_]; | 
| 207 | } | 
| 208 |  | 
| 209 | /** | 
| 210 | * Returns the position of this stuntdouble in specified snapshot | 
| 211 | * @return the position of this stuntdouble | 
| 212 | * @param snapshotNo | 
| 213 | */ | 
| 214 | Vector3d getPos(int snapshotNo) { | 
| 215 | return ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).position[localIndex_]; | 
| 216 | } | 
| 217 |  | 
| 218 | /** | 
| 219 | * Sets  the previous position of this stuntdouble | 
| 220 | * @param pos  new position | 
| 221 | * @see #getPos | 
| 222 | */ | 
| 223 | void setPrevPos(const Vector3d& pos) { | 
| 224 | ((snapshotMan_->getPrevSnapshot())->*storage_).position[localIndex_] = pos; | 
| 225 | } | 
| 226 |  | 
| 227 | /** | 
| 228 | * Sets  the current position of this stuntdouble | 
| 229 | * @param pos  new position | 
| 230 | */ | 
| 231 | void setPos(const Vector3d& pos) { | 
| 232 | DataStorage&  data = snapshotMan_->getCurrentSnapshot()->*storage_; | 
| 233 | data.position[localIndex_] = pos; | 
| 234 | //((snapshotMan_->getCurrentSnapshot())->*storage_).position[localIndex_] = pos; | 
| 235 | } | 
| 236 |  | 
| 237 | /** | 
| 238 | * Sets  the position of this stuntdouble in specified snapshot | 
| 239 | * @param pos position to be set | 
| 240 | * @param snapshotNo | 
| 241 | * @see #getPos | 
| 242 | */ | 
| 243 | void setPos(const Vector3d& pos, int snapshotNo) { | 
| 244 |  | 
| 245 | ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).position[localIndex_] = pos; | 
| 246 |  | 
| 247 | } | 
| 248 |  | 
| 249 | /** | 
| 250 | * Returns the previous velocity of this stuntdouble | 
| 251 | * @return the velocity of this stuntdouble | 
| 252 | */ | 
| 253 | Vector3d getPrevVel() { | 
| 254 | return ((snapshotMan_->getPrevSnapshot())->*storage_).velocity[localIndex_]; | 
| 255 | } | 
| 256 |  | 
| 257 | /** | 
| 258 | * Returns the current velocity of this stuntdouble | 
| 259 | * @return the velocity of this stuntdouble | 
| 260 | */ | 
| 261 | Vector3d getVel() { | 
| 262 | return ((snapshotMan_->getCurrentSnapshot())->*storage_).velocity[localIndex_]; | 
| 263 | } | 
| 264 |  | 
| 265 | /** | 
| 266 | * Returns the velocity of this stuntdouble in specified snapshot | 
| 267 | * @return the velocity of this stuntdouble | 
| 268 | * @param snapshotNo | 
| 269 | */ | 
| 270 | Vector3d getVel(int snapshotNo) { | 
| 271 | return ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).velocity[localIndex_]; | 
| 272 | } | 
| 273 |  | 
| 274 | /** | 
| 275 | * Sets  the previous velocity of this stuntdouble | 
| 276 | * @param vel  new velocity | 
| 277 | * @see #getVel | 
| 278 | */ | 
| 279 | void setPrevVel(const Vector3d& vel) { | 
| 280 | ((snapshotMan_->getPrevSnapshot())->*storage_).velocity[localIndex_] = vel; | 
| 281 | } | 
| 282 |  | 
| 283 | /** | 
| 284 | * Sets  the current velocity of this stuntdouble | 
| 285 | * @param vel  new velocity | 
| 286 | */ | 
| 287 | void setVel(const Vector3d& vel) { | 
| 288 | ((snapshotMan_->getCurrentSnapshot())->*storage_).velocity[localIndex_] = vel; | 
| 289 | } | 
| 290 |  | 
| 291 | /** | 
| 292 | * Sets  the velocity of this stuntdouble in specified snapshot | 
| 293 | * @param vel velocity to be set | 
| 294 | * @param snapshotNo | 
| 295 | * @see #getVel | 
| 296 | */ | 
| 297 | void setVel(const Vector3d& vel, int snapshotNo) { | 
| 298 | ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).velocity[localIndex_] = vel; | 
| 299 | } | 
| 300 |  | 
| 301 | /** | 
| 302 | * Returns the previous rotation matrix of this stuntdouble | 
| 303 | * @return the rotation matrix of this stuntdouble | 
| 304 | */ | 
| 305 | RotMat3x3d getPrevA() { | 
| 306 | return ((snapshotMan_->getPrevSnapshot())->*storage_).aMat[localIndex_]; | 
| 307 | } | 
| 308 |  | 
| 309 | /** | 
| 310 | * Returns the current rotation matrix of this stuntdouble | 
| 311 | * @return the rotation matrix of this stuntdouble | 
| 312 | */ | 
| 313 | RotMat3x3d getA() { | 
| 314 | return ((snapshotMan_->getCurrentSnapshot())->*storage_).aMat[localIndex_]; | 
| 315 | } | 
| 316 |  | 
| 317 | /** | 
| 318 | * Returns the rotation matrix of this stuntdouble in specified snapshot | 
| 319 | * | 
| 320 | * @return the rotation matrix of this stuntdouble | 
| 321 | * @param snapshotNo | 
| 322 | */ | 
| 323 | RotMat3x3d getA(int snapshotNo) { | 
| 324 | return ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).aMat[localIndex_]; | 
| 325 | } | 
| 326 |  | 
| 327 | /** | 
| 328 | * Sets  the previous rotation matrix of this stuntdouble | 
| 329 | * @param a  new rotation matrix | 
| 330 | * @see #getA | 
| 331 | */ | 
| 332 | virtual void setPrevA(const RotMat3x3d& a) { | 
| 333 | ((snapshotMan_->getPrevSnapshot())->*storage_).aMat[localIndex_] = a; | 
| 334 | } | 
| 335 |  | 
| 336 | /** | 
| 337 | * Sets  the current rotation matrix of this stuntdouble | 
| 338 | * @param a  new rotation matrix | 
| 339 | */ | 
| 340 | virtual void setA(const RotMat3x3d& a) { | 
| 341 | ((snapshotMan_->getCurrentSnapshot())->*storage_).aMat[localIndex_] = a; | 
| 342 | } | 
| 343 |  | 
| 344 | /** | 
| 345 | * Sets  the rotation matrix of this stuntdouble in specified snapshot | 
| 346 | * @param a rotation matrix to be set | 
| 347 | * @param snapshotNo | 
| 348 | * @see #getA | 
| 349 | */ | 
| 350 | virtual void setA(const RotMat3x3d& a, int snapshotNo) { | 
| 351 | ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).aMat[localIndex_] = a; | 
| 352 | } | 
| 353 |  | 
| 354 | /** | 
| 355 | * Returns the previous angular momentum of this stuntdouble (body-fixed). | 
| 356 | * @return the angular momentum of this stuntdouble | 
| 357 | */ | 
| 358 | Vector3d getPrevJ() { | 
| 359 | return ((snapshotMan_->getPrevSnapshot())->*storage_).angularMomentum[localIndex_]; | 
| 360 | } | 
| 361 |  | 
| 362 | /** | 
| 363 | * Returns the current angular momentum of this stuntdouble (body -fixed). | 
| 364 | * @return the angular momentum of this stuntdouble | 
| 365 | */ | 
| 366 | Vector3d getJ() { | 
| 367 | return ((snapshotMan_->getCurrentSnapshot())->*storage_).angularMomentum[localIndex_]; | 
| 368 | } | 
| 369 |  | 
| 370 | /** | 
| 371 | * Returns the angular momentum of this stuntdouble in specified snapshot (body-fixed). | 
| 372 | * @return the angular momentum of this stuntdouble | 
| 373 | * @param snapshotNo | 
| 374 | */ | 
| 375 | Vector3d getJ(int snapshotNo) { | 
| 376 | return ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).angularMomentum[localIndex_]; | 
| 377 | } | 
| 378 |  | 
| 379 | /** | 
| 380 | * Sets  the previous angular momentum of this stuntdouble (body-fixed). | 
| 381 | * @param angMom  new angular momentum | 
| 382 | * @see #getJ | 
| 383 | */ | 
| 384 | void setPrevJ(const Vector3d& angMom) { | 
| 385 | ((snapshotMan_->getPrevSnapshot())->*storage_).angularMomentum[localIndex_] = angMom; | 
| 386 | } | 
| 387 |  | 
| 388 | /** | 
| 389 | * Sets  the current angular momentum of this stuntdouble (body-fixed). | 
| 390 | * @param angMom  new angular momentum | 
| 391 | */ | 
| 392 | void setJ(const Vector3d& angMom) { | 
| 393 | ((snapshotMan_->getCurrentSnapshot())->*storage_).angularMomentum[localIndex_] = angMom; | 
| 394 | } | 
| 395 |  | 
| 396 | /** | 
| 397 | * Sets the angular momentum of this stuntdouble in specified snapshot(body-fixed). | 
| 398 | * @param angMom angular momentum to be set | 
| 399 | * @param snapshotNo | 
| 400 | * @see #getJ | 
| 401 | */ | 
| 402 | void setJ(const Vector3d& angMom, int snapshotNo) { | 
| 403 | ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).angularMomentum[localIndex_] = angMom; | 
| 404 | } | 
| 405 |  | 
| 406 | /** | 
| 407 | * Returns the previous quaternion of this stuntdouble | 
| 408 | * @return the quaternion of this stuntdouble | 
| 409 | */ | 
| 410 | Quat4d getPrevQ() { | 
| 411 | return ((snapshotMan_->getPrevSnapshot())->*storage_).aMat[localIndex_].toQuaternion(); | 
| 412 | } | 
| 413 |  | 
| 414 | /** | 
| 415 | * Returns the current quaternion of this stuntdouble | 
| 416 | * @return the quaternion of this stuntdouble | 
| 417 | */ | 
| 418 | Quat4d getQ() { | 
| 419 | return ((snapshotMan_->getCurrentSnapshot())->*storage_).aMat[localIndex_].toQuaternion(); | 
| 420 | } | 
| 421 |  | 
| 422 | /** | 
| 423 | * Returns the quaternion of this stuntdouble in specified snapshot | 
| 424 | * @return the quaternion of this stuntdouble | 
| 425 | * @param snapshotNo | 
| 426 | */ | 
| 427 | Quat4d getQ(int snapshotNo) { | 
| 428 | return ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).aMat[localIndex_].toQuaternion(); | 
| 429 | } | 
| 430 |  | 
| 431 | /** | 
| 432 | * Sets  the previous quaternion of this stuntdouble | 
| 433 | * @param q  new quaternion | 
| 434 | * @note actual storage data is rotation matrix | 
| 435 | */ | 
| 436 | void setPrevQ(const Quat4d& q) { | 
| 437 | setPrevA(q); | 
| 438 | } | 
| 439 |  | 
| 440 | /** | 
| 441 | * Sets  the current quaternion of this stuntdouble | 
| 442 | * @param q  new quaternion | 
| 443 | * @note actual storage data is rotation matrix | 
| 444 | */ | 
| 445 | void setQ(const Quat4d& q) { | 
| 446 | setA(q); | 
| 447 | } | 
| 448 |  | 
| 449 | /** | 
| 450 | * Sets  the quaternion of this stuntdouble in specified snapshot | 
| 451 | * | 
| 452 | * @param q quaternion to be set | 
| 453 | * @param snapshotNo | 
| 454 | * @note actual storage data is rotation matrix | 
| 455 | */ | 
| 456 | void setQ(const Quat4d& q, int snapshotNo) { | 
| 457 | setA(q, snapshotNo); | 
| 458 | } | 
| 459 |  | 
| 460 | /** | 
| 461 | * Returns the previous euler angles of this stuntdouble | 
| 462 | * @return the euler angles of this stuntdouble | 
| 463 | */ | 
| 464 | Vector3d getPrevEuler() { | 
| 465 | return ((snapshotMan_->getPrevSnapshot())->*storage_).aMat[localIndex_].toEulerAngles(); | 
| 466 | } | 
| 467 |  | 
| 468 | /** | 
| 469 | * Returns the current euler angles of this stuntdouble | 
| 470 | * @return the euler angles of this stuntdouble | 
| 471 | */ | 
| 472 | Vector3d getEuler() { | 
| 473 | return ((snapshotMan_->getCurrentSnapshot())->*storage_).aMat[localIndex_].toEulerAngles(); | 
| 474 | } | 
| 475 |  | 
| 476 | /** | 
| 477 | * Returns the euler angles of this stuntdouble in specified snapshot. | 
| 478 | * @return the euler angles of this stuntdouble | 
| 479 | * @param snapshotNo | 
| 480 | */ | 
| 481 | Vector3d getEuler(int snapshotNo) { | 
| 482 | return ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).aMat[localIndex_].toEulerAngles(); | 
| 483 | } | 
| 484 |  | 
| 485 | /** | 
| 486 | * Sets  the previous euler angles of this stuntdouble. | 
| 487 | * @param euler  new euler angles | 
| 488 | * @see #getEuler | 
| 489 | * @note actual storage data is rotation matrix | 
| 490 | */ | 
| 491 | void setPrevEuler(const Vector3d& euler) { | 
| 492 | ((snapshotMan_->getPrevSnapshot())->*storage_).aMat[localIndex_] = euler; | 
| 493 | } | 
| 494 |  | 
| 495 | /** | 
| 496 | * Sets  the current euler angles of this stuntdouble | 
| 497 | * @param euler  new euler angles | 
| 498 | */ | 
| 499 | void setEuler(const Vector3d& euler) { | 
| 500 | ((snapshotMan_->getCurrentSnapshot())->*storage_).aMat[localIndex_] = euler; | 
| 501 | } | 
| 502 |  | 
| 503 | /** | 
| 504 | * Sets  the euler angles  of this stuntdouble in specified snapshot | 
| 505 | * | 
| 506 | * @param euler euler angles to be set | 
| 507 | * @param snapshotNo | 
| 508 | * @note actual storage data is rotation matrix | 
| 509 | */ | 
| 510 | void setEuler(const Vector3d& euler, int snapshotNo) { | 
| 511 | ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).aMat[localIndex_] = euler; | 
| 512 | } | 
| 513 |  | 
| 514 | /** | 
| 515 | * Returns the previous unit vectors of this stuntdouble | 
| 516 | * @return the unit vectors of this stuntdouble | 
| 517 | */ | 
| 518 | RotMat3x3d getPrevElectroFrame() { | 
| 519 | return ((snapshotMan_->getPrevSnapshot())->*storage_).electroFrame[localIndex_]; | 
| 520 | } | 
| 521 |  | 
| 522 | /** | 
| 523 | * Returns the current unit vectors of this stuntdouble | 
| 524 | * @return the unit vectors of this stuntdouble | 
| 525 | */ | 
| 526 | RotMat3x3d getElectroFrame() { | 
| 527 | return ((snapshotMan_->getCurrentSnapshot())->*storage_).electroFrame[localIndex_]; | 
| 528 | } | 
| 529 |  | 
| 530 | /** | 
| 531 | * Returns the unit vectors of this stuntdouble in specified snapshot | 
| 532 | * | 
| 533 | * @return the unit vectors of this stuntdouble | 
| 534 | * @param snapshotNo | 
| 535 | */ | 
| 536 | RotMat3x3d getElectroFrame(int snapshotNo) { | 
| 537 | return ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).electroFrame[localIndex_]; | 
| 538 | } | 
| 539 |  | 
| 540 | /** | 
| 541 | * Returns the previous force of this stuntdouble | 
| 542 | * @return the force of this stuntdouble | 
| 543 | */ | 
| 544 | Vector3d getPrevFrc() { | 
| 545 | return ((snapshotMan_->getPrevSnapshot())->*storage_).force[localIndex_]; | 
| 546 | } | 
| 547 |  | 
| 548 | /** | 
| 549 | * Returns the current force of this stuntdouble | 
| 550 | * @return the force of this stuntdouble | 
| 551 | */ | 
| 552 | Vector3d getFrc() { | 
| 553 | return ((snapshotMan_->getCurrentSnapshot())->*storage_).force[localIndex_]; | 
| 554 | } | 
| 555 |  | 
| 556 | /** | 
| 557 | * Returns the force of this stuntdouble in specified snapshot | 
| 558 | * | 
| 559 | * @return the force of this stuntdouble | 
| 560 | * @param snapshotNo | 
| 561 | */ | 
| 562 | Vector3d getFrc(int snapshotNo) { | 
| 563 | return ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).force[localIndex_]; | 
| 564 | } | 
| 565 |  | 
| 566 | /** | 
| 567 | * Sets  the previous force of this stuntdouble | 
| 568 | * | 
| 569 | * @param frc  new force | 
| 570 | * @see #getFrc | 
| 571 | */ | 
| 572 | void setPrevFrc(const Vector3d& frc) { | 
| 573 | ((snapshotMan_->getPrevSnapshot())->*storage_).force[localIndex_] = frc; | 
| 574 | } | 
| 575 |  | 
| 576 | /** | 
| 577 | * Sets  the current force of this stuntdouble | 
| 578 | * @param frc  new force | 
| 579 | */ | 
| 580 | void setFrc(const Vector3d& frc) { | 
| 581 | ((snapshotMan_->getCurrentSnapshot())->*storage_).force[localIndex_] = frc; | 
| 582 | } | 
| 583 |  | 
| 584 | /** | 
| 585 | * Sets  the force of this stuntdouble in specified snapshot | 
| 586 | * | 
| 587 | * @param frc force to be set | 
| 588 | * @param snapshotNo | 
| 589 | * @see #getFrc | 
| 590 | */ | 
| 591 | void setFrc(const Vector3d& frc, int snapshotNo) { | 
| 592 | ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).force[localIndex_] = frc; | 
| 593 | } | 
| 594 |  | 
| 595 | /** | 
| 596 | * Adds force into the previous force of this stuntdouble | 
| 597 | * | 
| 598 | * @param frc  new force | 
| 599 | * @see #getFrc | 
| 600 | */ | 
| 601 | void addPrevFrc(const Vector3d& frc) { | 
| 602 | ((snapshotMan_->getPrevSnapshot())->*storage_).force[localIndex_] += frc; | 
| 603 | } | 
| 604 |  | 
| 605 | /** | 
| 606 | * Adds force into the current force of this stuntdouble | 
| 607 | * @param frc  new force | 
| 608 | */ | 
| 609 | void addFrc(const Vector3d& frc) { | 
| 610 | ((snapshotMan_->getCurrentSnapshot())->*storage_).force[localIndex_] += frc; | 
| 611 | } | 
| 612 |  | 
| 613 | /** | 
| 614 | * Adds force into the force of this stuntdouble in specified snapshot | 
| 615 | * | 
| 616 | * @param frc force to be set | 
| 617 | * @param snapshotNo | 
| 618 | * @see #getFrc | 
| 619 | */ | 
| 620 | void addFrc(const Vector3d& frc, int snapshotNo) { | 
| 621 | ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).force[localIndex_] += frc; | 
| 622 | } | 
| 623 |  | 
| 624 | /** | 
| 625 | * Returns the previous torque of this stuntdouble | 
| 626 | * @return the torque of this stuntdouble | 
| 627 | */ | 
| 628 | Vector3d getPrevTrq() { | 
| 629 | return ((snapshotMan_->getPrevSnapshot())->*storage_).torque[localIndex_]; | 
| 630 | } | 
| 631 |  | 
| 632 | /** | 
| 633 | * Returns the current torque of this stuntdouble | 
| 634 | * @return the torque of this stuntdouble | 
| 635 | */ | 
| 636 | Vector3d getTrq() { | 
| 637 | return ((snapshotMan_->getCurrentSnapshot())->*storage_).torque[localIndex_]; | 
| 638 | } | 
| 639 |  | 
| 640 | /** | 
| 641 | * Returns the torque of this stuntdouble in specified snapshot | 
| 642 | * | 
| 643 | * @return the torque of this stuntdouble | 
| 644 | * @param snapshotNo | 
| 645 | */ | 
| 646 | Vector3d getTrq(int snapshotNo) { | 
| 647 | return ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).torque[localIndex_]; | 
| 648 | } | 
| 649 |  | 
| 650 | /** | 
| 651 | * Sets  the previous torque of this stuntdouble | 
| 652 | * | 
| 653 | * @param trq  new torque | 
| 654 | * @see #getTrq | 
| 655 | */ | 
| 656 | void setPrevTrq(const Vector3d& trq) { | 
| 657 | ((snapshotMan_->getPrevSnapshot())->*storage_).torque[localIndex_] = trq; | 
| 658 | } | 
| 659 |  | 
| 660 | /** | 
| 661 | * Sets  the current torque of this stuntdouble | 
| 662 | * @param trq  new torque | 
| 663 | */ | 
| 664 | void setTrq(const Vector3d& trq) { | 
| 665 | ((snapshotMan_->getCurrentSnapshot())->*storage_).torque[localIndex_] = trq; | 
| 666 | } | 
| 667 |  | 
| 668 | /** | 
| 669 | * Sets  the torque of this stuntdouble in specified snapshot | 
| 670 | * | 
| 671 | * @param trq torque to be set | 
| 672 | * @param snapshotNo | 
| 673 | * @see #getTrq | 
| 674 | */ | 
| 675 | void setTrq(const Vector3d& trq, int snapshotNo) { | 
| 676 | ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).torque[localIndex_] = trq; | 
| 677 | } | 
| 678 |  | 
| 679 | /** | 
| 680 | * Adds torque into the previous torque of this stuntdouble | 
| 681 | * | 
| 682 | * @param trq  new torque | 
| 683 | * @see #getTrq | 
| 684 | */ | 
| 685 | void addPrevTrq(const Vector3d& trq) { | 
| 686 | ((snapshotMan_->getPrevSnapshot())->*storage_).torque[localIndex_] += trq; | 
| 687 | } | 
| 688 |  | 
| 689 | /** | 
| 690 | * Adds torque into the current torque of this stuntdouble | 
| 691 | * @param trq  new torque | 
| 692 | */ | 
| 693 | void addTrq(const Vector3d& trq) { | 
| 694 | ((snapshotMan_->getCurrentSnapshot())->*storage_).torque[localIndex_] += trq; | 
| 695 | } | 
| 696 |  | 
| 697 | /** | 
| 698 | * Adds torque into the torque of this stuntdouble in specified snapshot | 
| 699 | * | 
| 700 | * @param trq torque to be add | 
| 701 | * @param snapshotNo | 
| 702 | * @see #getTrq | 
| 703 | */ | 
| 704 | void addTrq(const Vector3d& trq, int snapshotNo) { | 
| 705 | ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).torque[localIndex_] += trq; | 
| 706 | } | 
| 707 |  | 
| 708 |  | 
| 709 | /** | 
| 710 | * Returns the previous z-angle of this stuntdouble | 
| 711 | * @return the z-angle of this stuntdouble | 
| 712 | */ | 
| 713 | double getPrevZangle() { | 
| 714 | return ((snapshotMan_->getPrevSnapshot())->*storage_).zAngle[localIndex_]; | 
| 715 | } | 
| 716 |  | 
| 717 | /** | 
| 718 | * Returns the current z-angle of this stuntdouble | 
| 719 | * @return the z-angle of this stuntdouble | 
| 720 | */ | 
| 721 | double getZangle() { | 
| 722 | return ((snapshotMan_->getCurrentSnapshot())->*storage_).zAngle[localIndex_]; | 
| 723 | } | 
| 724 |  | 
| 725 | /** | 
| 726 | * Returns the z-angle of this stuntdouble in specified snapshot | 
| 727 | * @return the z-angle of this stuntdouble | 
| 728 | * @param snapshotNo | 
| 729 | */ | 
| 730 | double getZangle(int snapshotNo) { | 
| 731 | return ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).zAngle[localIndex_]; | 
| 732 | } | 
| 733 |  | 
| 734 | /** | 
| 735 | * Sets  the previous z-angle of this stuntdouble | 
| 736 | * @param angle  new z-angle | 
| 737 | * @see #getZangle | 
| 738 | */ | 
| 739 | void setPrevZangle(double angle) { | 
| 740 | ((snapshotMan_->getPrevSnapshot())->*storage_).zAngle[localIndex_] = angle; | 
| 741 | } | 
| 742 |  | 
| 743 | /** | 
| 744 | * Sets  the current z-angle of this stuntdouble | 
| 745 | * @param angle  new z-angle | 
| 746 | */ | 
| 747 | void setZangle(double angle) { | 
| 748 | ((snapshotMan_->getCurrentSnapshot())->*storage_).zAngle[localIndex_] = angle; | 
| 749 | } | 
| 750 |  | 
| 751 | /** | 
| 752 | * Sets  the z-angle of this stuntdouble in specified snapshot | 
| 753 | * @param angle z-angle to be set | 
| 754 | * @param snapshotNo | 
| 755 | * @see #getZangle | 
| 756 | */ | 
| 757 | void setZangle(double angle, int snapshotNo) { | 
| 758 | ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).zAngle[localIndex_] = angle; | 
| 759 | } | 
| 760 |  | 
| 761 | /** | 
| 762 | * Adds z-angle into the previous z-angle of this stuntdouble | 
| 763 | * @param angle  new z-angle | 
| 764 | * @see #getZangle | 
| 765 | */ | 
| 766 | void addPrevZangle(double angle) { | 
| 767 | ((snapshotMan_->getPrevSnapshot())->*storage_).zAngle[localIndex_] += angle; | 
| 768 | } | 
| 769 |  | 
| 770 | /** | 
| 771 | * Adds z-angle into the current z-angle of this stuntdouble | 
| 772 | * @param angle  new z-angle | 
| 773 | */ | 
| 774 | void addZangle(double angle) { | 
| 775 | ((snapshotMan_->getCurrentSnapshot())->*storage_).zAngle[localIndex_] += angle; | 
| 776 | } | 
| 777 |  | 
| 778 | /** | 
| 779 | * Adds z-angle into the z-angle of this stuntdouble in specified snapshot | 
| 780 | * @param angle z-angle to be add | 
| 781 | * @param snapshotNo | 
| 782 | * @see #getZangle | 
| 783 | */ | 
| 784 | void addZangle(double angle, int snapshotNo) { | 
| 785 | ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).zAngle[localIndex_] += angle; | 
| 786 | } | 
| 787 |  | 
| 788 | /** Set the force of this stuntdouble to zero */ | 
| 789 | void zeroForcesAndTorques(); | 
| 790 | /** | 
| 791 | * Returns the inertia tensor of this stuntdouble | 
| 792 | * @return the inertia tensor of this stuntdouble | 
| 793 | */ | 
| 794 | virtual Mat3x3d getI() = 0; | 
| 795 |  | 
| 796 | /** | 
| 797 | * Returns the gradient of this stuntdouble | 
| 798 | * @return the gradient of this stuntdouble | 
| 799 | */ | 
| 800 | virtual std::vector<double> getGrad() = 0; | 
| 801 |  | 
| 802 | /** | 
| 803 | * Tests the  if this stuntdouble is a  linear rigidbody | 
| 804 | * | 
| 805 | * @return true if this stuntdouble is a  linear rigidbody, otherwise return false | 
| 806 | * @note atom and directional atom will always return false | 
| 807 | * | 
| 808 | * @see #linearAxis | 
| 809 | */ | 
| 810 | bool isLinear() { | 
| 811 | return linear_; | 
| 812 | } | 
| 813 |  | 
| 814 | /** | 
| 815 | * Returns the linear axis of the rigidbody, atom and directional atom will always return -1 | 
| 816 | * | 
| 817 | * @return the linear axis of the rigidbody | 
| 818 | * | 
| 819 | * @see #isLinear | 
| 820 | */ | 
| 821 | int linearAxis() { | 
| 822 | return linearAxis_; | 
| 823 | } | 
| 824 |  | 
| 825 | /** Returns the mass of this stuntdouble */ | 
| 826 | double getMass() { | 
| 827 | return mass_; | 
| 828 | } | 
| 829 |  | 
| 830 | /** | 
| 831 | * Sets the mass of this stuntdoulbe | 
| 832 | * @param mass the mass to be set | 
| 833 | */ | 
| 834 | void setMass(double mass) { | 
| 835 | mass_ = mass; | 
| 836 | } | 
| 837 |  | 
| 838 | /** Returns the name of this stuntdouble */ | 
| 839 | virtual std::string getType() = 0; | 
| 840 |  | 
| 841 | /** Sets the name of this stuntdouble*/ | 
| 842 | virtual void setType(const std::string& name) {} | 
| 843 |  | 
| 844 | /** | 
| 845 | * Converts a lab fixed vector to a body fixed vector. | 
| 846 | * @return body fixed vector | 
| 847 | * @param v lab fixed vector | 
| 848 | */ | 
| 849 | Vector3d lab2Body(const Vector3d& v) { | 
| 850 | return getA() * v; | 
| 851 | } | 
| 852 |  | 
| 853 | Vector3d lab2Body(const Vector3d& v, int frame) { | 
| 854 | return getA(frame) * v; | 
| 855 | } | 
| 856 |  | 
| 857 | /** | 
| 858 | * Converts a body fixed vector to a lab fixed vector. | 
| 859 | * @return corresponding lab fixed vector | 
| 860 | * @param v body fixed vector | 
| 861 | */ | 
| 862 | Vector3d body2Lab(const Vector3d& v){ | 
| 863 | return getA().transpose() * v; | 
| 864 | } | 
| 865 |  | 
| 866 | Vector3d body2Lab(const Vector3d& v, int frame){ | 
| 867 | return getA(frame).transpose() * v; | 
| 868 | } | 
| 869 | /** | 
| 870 | * <p> | 
| 871 | * The purpose of the Visitor Pattern is to encapsulate an operation that you want to perform on | 
| 872 | * the elements of a data structure. In this way, you can change the operation being performed | 
| 873 | * on a structure without the need of changing the classes of the elements that you are operating | 
| 874 | * on. Using a Visitor pattern allows you to decouple the classes for the data structure and the | 
| 875 | * algorithms used upon them | 
| 876 | * </p> | 
| 877 | * @param v visitor | 
| 878 | */ | 
| 879 | virtual void accept(BaseVisitor* v) = 0; | 
| 880 |  | 
| 881 | //below functions are just forward functions | 
| 882 | /** | 
| 883 | * Adds property into property map | 
| 884 | * @param genData GenericData to be added into PropertyMap | 
| 885 | */ | 
| 886 | void addProperty(GenericData* genData); | 
| 887 |  | 
| 888 | /** | 
| 889 | * Removes property from PropertyMap by name | 
| 890 | * @param propName the name of property to be removed | 
| 891 | */ | 
| 892 | void removeProperty(const std::string& propName); | 
| 893 |  | 
| 894 | /** | 
| 895 | * clear all of the properties | 
| 896 | */ | 
| 897 | void clearProperties(); | 
| 898 |  | 
| 899 | /** | 
| 900 | * Returns all names of properties | 
| 901 | * @return all names of properties | 
| 902 | */ | 
| 903 | std::vector<std::string> getPropertyNames(); | 
| 904 |  | 
| 905 | /** | 
| 906 | * Returns all of the properties in PropertyMap | 
| 907 | * @return all of the properties in PropertyMap | 
| 908 | */ | 
| 909 | std::vector<GenericData*> getProperties(); | 
| 910 |  | 
| 911 | /** | 
| 912 | * Returns property | 
| 913 | * @param propName name of property | 
| 914 | * @return a pointer point to property with propName. If no property named propName | 
| 915 | * exists, return NULL | 
| 916 | */ | 
| 917 | GenericData* getPropertyByName(const std::string& propName); | 
| 918 |  | 
| 919 | protected: | 
| 920 |  | 
| 921 | StuntDouble(ObjectType objType, DataStoragePointer storage); | 
| 922 |  | 
| 923 | StuntDouble(const StuntDouble& sd); | 
| 924 | StuntDouble& operator=(const StuntDouble& sd); | 
| 925 |  | 
| 926 | ObjectType objType_; | 
| 927 | DataStoragePointer storage_; | 
| 928 | SnapshotManager* snapshotMan_; | 
| 929 |  | 
| 930 | bool linear_; | 
| 931 | int linearAxis_; | 
| 932 |  | 
| 933 |  | 
| 934 | int globalIndex_; | 
| 935 | int localIndex_; | 
| 936 |  | 
| 937 |  | 
| 938 | double mass_; | 
| 939 |  | 
| 940 | private: | 
| 941 |  | 
| 942 | PropertyMap properties_; | 
| 943 | }; | 
| 944 |  | 
| 945 | }//end namespace oopse | 
| 946 | #endif //PRIMITIVES_STUNTDOUBLE_HPP |