--- trunk/OOPSE-2.0/src/primitives/StuntDouble.hpp 2004/11/04 16:22:03 1709 +++ trunk/OOPSE-2.0/src/primitives/StuntDouble.hpp 2005/01/12 22:41:40 1930 @@ -1,97 +1,904 @@ -#ifndef __STUNTDOUBLE_HPP__ -#define __STUNTDOUBLE_HPP__ + /* + * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. + * + * The University of Notre Dame grants you ("Licensee") a + * non-exclusive, royalty free, license to use, modify and + * redistribute this software in source and binary code form, provided + * that the following conditions are met: + * + * 1. Acknowledgement of the program authors must be made in any + * publication of scientific results based in part on use of the + * program. An acceptable form of acknowledgement is citation of + * the article in which the program was described (Matthew + * A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher + * J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented + * Parallel Simulation Engine for Molecular Dynamics," + * J. Comput. Chem. 26, pp. 252-271 (2005)) + * + * 2. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 3. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * This software is provided "AS IS," without a warranty of any + * kind. All express or implied conditions, representations and + * warranties, including any implied warranty of merchantability, + * fitness for a particular purpose or non-infringement, are hereby + * excluded. The University of Notre Dame and its licensors shall not + * be liable for any damages suffered by licensee as a result of + * using, modifying or distributing the software or its + * derivatives. In no event will the University of Notre Dame or its + * licensors be liable for any lost revenue, profit or data, or for + * direct, indirect, special, consequential, incidental or punitive + * damages, however caused and regardless of the theory of liability, + * arising out of the use of or inability to use software, even if the + * University of Notre Dame has been advised of the possibility of + * such damages. + */ + +/** + * @file StuntDouble.hpp + * @author tlin + * @date 10/22/2004 + * @version 1.0 + */ + + #ifndef PRIMITIVES_STUNTDOUBLE_HPP + #define PRIMITIVES_STUNTDOUBLE_HPP -#include -#include "utils/GenericData.hpp" +#include -#define OT_ATOM 0 -#define OT_DATOM 1 -#define OT_RIGIDBODY 2 +#include "visitors/BaseVisitor.hpp" +#include "math/Quaternion.hpp" +#include "math/SquareMatrix3.hpp" +#include "math/Vector3.hpp" +#include "utils/PropertyMap.hpp" +#include "brains/Snapshot.hpp" +#include "brains/SnapshotManager.hpp" +namespace oopse{ -using namespace std; -using namespace oopse; -class BaseVisitor; + + /** + * @class StuntDouble StuntDouble.hpp "Primitives/StuntDouble.hpp" + * @brief + * StuntDouble is a very strange idea. A StuntDouble stands in for + * some object that can be manipulated by the Integrators or + * Minimizers. Some of the manipulable objects are Atoms, some are + * DirectionalAtoms, and some are RigidBodies. StuntDouble + * provides an interface for the Integrators and Minimizers to use, + * and does some preliminary sanity checking so that the program + * doesn't try to do something stupid like torque an Atom + * @note the dynamic data of stuntdouble will be stored outside of the class + */ + class StuntDouble{ + public: -class StuntDouble { - public: - virtual ~StuntDouble(); - - int getObjType(); - - bool isAtom(){ - return objType == OT_ATOM || objType == OT_DATOM; - } + enum ObjectType{ + otAtom, + otDAtom, + otRigidBody + }; - bool isDirectionalAtom(){ - return objType == OT_DATOM; - } + virtual ~StuntDouble(); + + /** + * Returns the global index of this stuntdouble. + * @return the global index of this stuntdouble + */ + int getGlobalIndex() { + return globalIndex_; + } - bool isRigidBody(){ - return objType == OT_RIGIDBODY; - } + /** + * Sets the global index of this stuntdouble. + * @param new global index to be set + */ + void setGlobalIndex(int index) { + globalIndex_ = index; + } + + /** + * Returns the local index of this stuntdouble + * @return the local index of this stuntdouble + */ + int getLocalIndex() { + return localIndex_; + } - bool isDirectional(){ - return isDirectionalAtom() || isRigidBody(); - } + /** + * Sets the local index of this stuntdouble + * @param index new index to be set + */ + void setLocalIndex(int index) { + localIndex_ = index; + } - virtual double getMass(void); - - virtual void getPos(double pos[3]); - virtual void setPos(double pos[3]); - - virtual void getVel(double vel[3]); - virtual void setVel(double vel[3]); - - virtual void getFrc(double frc[3]); - virtual void addFrc(double frc[3]); + /** + * Sets the Snapshot Manager of this stuntdouble + */ + void setSnapshotManager(SnapshotManager* sman) { + snapshotMan_ = sman; + } - virtual void getA(double A[3][3]); - virtual void setA(double A[3][3]); + /** + * Tests if this stuntdouble is an atom + * @return true is this stuntdouble is an atom(or a directional atom), return false otherwise + */ + bool isAtom(){ + return objType_ == otAtom || objType_ == otDAtom; + } - virtual void getJ(double j[3]); - virtual void setJ(double j[3]); + /** + * Tests if this stuntdouble is an directional atom + * @return true if this stuntdouble is an directional atom, return false otherwise + */ + bool isDirectionalAtom(){ + return objType_ == otDAtom; + } - virtual void getQ( double q[4] ); // get the quanternions - virtual void setQ( double q[4] ); + /** + * Tests if this stuntdouble is a rigid body. + * @return true if this stuntdouble is a rigid body, otherwise return false + */ + bool isRigidBody(){ + return objType_ == otRigidBody; + } - virtual void setType(char* type) = 0; - virtual char* getType() = 0; - - virtual void getTrq(double trq[3]); - virtual void addTrq(double trq[3]); + /** + * Tests if this stuntdouble is a directional one. + * @return true is this stuntdouble is a directional atom or a rigid body, return false otherwise + */ + bool isDirectional(){ + return isDirectionalAtom() || isRigidBody(); + } - virtual void getI(double I[3][3]); - virtual void lab2Body(double vec[3]); + /** + * Returns the previous position of this stuntdouble + * @return the position of this stuntdouble + */ + Vector3d getPrevPos() { + return ((snapshotMan_->getPrevSnapshot())->*storage_).position[localIndex_]; + } + + /** + * Returns the current position of this stuntdouble + * @return the position of this stuntdouble + */ + Vector3d getPos() { + return ((snapshotMan_->getCurrentSnapshot())->*storage_).position[localIndex_]; + } - virtual void getGrad(double grad[6]); - virtual void setEuler(double phi, double theta, double psi); - virtual void getEulerAngles(double eulers[3]); + /** + * Returns the position of this stuntdouble in specified snapshot + * @return the position of this stuntdouble + * @param snapshotNo + */ + Vector3d getPos(int snapshotNo) { + return ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).position[localIndex_]; + } - virtual bool isLinear() { return false;} - virtual int linearAxis() { return -1; } - - virtual double getZangle(); - virtual void setZangle(double zAngle); - virtual void addZangle(double zAngle); - - virtual void accept(BaseVisitor* v) = 0; - - void addProperty(GenericData* data); - void removeProperty(const string& propName); - GenericData* getProperty(const string& propName); - - protected: - StuntDouble(){} + /** + * Sets the previous position of this stuntdouble + * @param pos new position + * @see #getPos + */ + void setPrevPos(const Vector3d& pos) { + ((snapshotMan_->getPrevSnapshot())->*storage_).position[localIndex_] = pos; + } + + /** + * Sets the current position of this stuntdouble + * @param pos new position + */ + void setPos(const Vector3d& pos) { + DataStorage& data = snapshotMan_->getCurrentSnapshot()->*storage_; + data.position[localIndex_] = pos; + //((snapshotMan_->getCurrentSnapshot())->*storage_).position[localIndex_] = pos; + } - //prevent default copy constructor copy information from properties which will cause problem - StuntDouble(const StuntDouble& sd){ - objType = sd.objType; - } - - int objType; + /** + * Sets the position of this stuntdouble in specified snapshot + * @param pos position to be set + * @param snapshotNo + * @see #getPos + */ + void setPos(const Vector3d& pos, int snapshotNo) { - map properties; + ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).position[localIndex_] = pos; + + } + + /** + * Returns the previous velocity of this stuntdouble + * @return the velocity of this stuntdouble + */ + Vector3d getPrevVel() { + return ((snapshotMan_->getPrevSnapshot())->*storage_).velocity[localIndex_]; + } + + /** + * Returns the current velocity of this stuntdouble + * @return the velocity of this stuntdouble + */ + Vector3d getVel() { + return ((snapshotMan_->getCurrentSnapshot())->*storage_).velocity[localIndex_]; + } + + /** + * Returns the velocity of this stuntdouble in specified snapshot + * @return the velocity of this stuntdouble + * @param snapshotNo + */ + Vector3d getVel(int snapshotNo) { + return ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).velocity[localIndex_]; + } + + /** + * Sets the previous velocity of this stuntdouble + * @param vel new velocity + * @see #getVel + */ + void setPrevVel(const Vector3d& vel) { + ((snapshotMan_->getPrevSnapshot())->*storage_).velocity[localIndex_] = vel; + } + + /** + * Sets the current velocity of this stuntdouble + * @param vel new velocity + */ + void setVel(const Vector3d& vel) { + ((snapshotMan_->getCurrentSnapshot())->*storage_).velocity[localIndex_] = vel; + } + + /** + * Sets the velocity of this stuntdouble in specified snapshot + * @param vel velocity to be set + * @param snapshotNo + * @see #getVel + */ + void setVel(const Vector3d& vel, int snapshotNo) { + ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).velocity[localIndex_] = vel; + } + + /** + * Returns the previous rotation matrix of this stuntdouble + * @return the rotation matrix of this stuntdouble + */ + RotMat3x3d getPrevA() { + return ((snapshotMan_->getPrevSnapshot())->*storage_).aMat[localIndex_]; + } + + /** + * Returns the current rotation matrix of this stuntdouble + * @return the rotation matrix of this stuntdouble + */ + RotMat3x3d getA() { + return ((snapshotMan_->getCurrentSnapshot())->*storage_).aMat[localIndex_]; + } + + /** + * Returns the rotation matrix of this stuntdouble in specified snapshot + * + * @return the rotation matrix of this stuntdouble + * @param snapshotNo + */ + RotMat3x3d getA(int snapshotNo) { + return ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).aMat[localIndex_]; + } + + /** + * Sets the previous rotation matrix of this stuntdouble + * @param a new rotation matrix + * @see #getA + */ + virtual void setPrevA(const RotMat3x3d& a) { + ((snapshotMan_->getPrevSnapshot())->*storage_).aMat[localIndex_] = a; + } + + /** + * Sets the current rotation matrix of this stuntdouble + * @param a new rotation matrix + */ + virtual void setA(const RotMat3x3d& a) { + ((snapshotMan_->getCurrentSnapshot())->*storage_).aMat[localIndex_] = a; + } + + /** + * Sets the rotation matrix of this stuntdouble in specified snapshot + * @param a rotation matrix to be set + * @param snapshotNo + * @see #getA + */ + virtual void setA(const RotMat3x3d& a, int snapshotNo) { + ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).aMat[localIndex_] = a; + } + + /** + * Returns the previous angular momentum of this stuntdouble (body-fixed). + * @return the angular momentum of this stuntdouble + */ + Vector3d getPrevJ() { + return ((snapshotMan_->getPrevSnapshot())->*storage_).angularMomentum[localIndex_]; + } + + /** + * Returns the current angular momentum of this stuntdouble (body -fixed). + * @return the angular momentum of this stuntdouble + */ + Vector3d getJ() { + return ((snapshotMan_->getCurrentSnapshot())->*storage_).angularMomentum[localIndex_]; + } + + /** + * Returns the angular momentum of this stuntdouble in specified snapshot (body-fixed). + * @return the angular momentum of this stuntdouble + * @param snapshotNo + */ + Vector3d getJ(int snapshotNo) { + return ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).angularMomentum[localIndex_]; + } + + /** + * Sets the previous angular momentum of this stuntdouble (body-fixed). + * @param angMom new angular momentum + * @see #getJ + */ + void setPrevJ(const Vector3d& angMom) { + ((snapshotMan_->getPrevSnapshot())->*storage_).angularMomentum[localIndex_] = angMom; + } + + /** + * Sets the current angular momentum of this stuntdouble (body-fixed). + * @param angMom new angular momentum + */ + void setJ(const Vector3d& angMom) { + ((snapshotMan_->getCurrentSnapshot())->*storage_).angularMomentum[localIndex_] = angMom; + } + + /** + * Sets the angular momentum of this stuntdouble in specified snapshot(body-fixed). + * @param angMom angular momentum to be set + * @param snapshotNo + * @see #getJ + */ + void setJ(const Vector3d& angMom, int snapshotNo) { + ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).angularMomentum[localIndex_] = angMom; + } + + /** + * Returns the previous quaternion of this stuntdouble + * @return the quaternion of this stuntdouble + */ + Quat4d getPrevQ() { + return ((snapshotMan_->getPrevSnapshot())->*storage_).aMat[localIndex_].toQuaternion(); + } + + /** + * Returns the current quaternion of this stuntdouble + * @return the quaternion of this stuntdouble + */ + Quat4d getQ() { + return ((snapshotMan_->getCurrentSnapshot())->*storage_).aMat[localIndex_].toQuaternion(); + } + + /** + * Returns the quaternion of this stuntdouble in specified snapshot + * @return the quaternion of this stuntdouble + * @param snapshotNo + */ + Quat4d getQ(int snapshotNo) { + return ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).aMat[localIndex_].toQuaternion(); + } + + /** + * Sets the previous quaternion of this stuntdouble + * @param q new quaternion + * @note actual storage data is rotation matrix + */ + void setPrevQ(const Quat4d& q) { + setPrevA(q); + } + + /** + * Sets the current quaternion of this stuntdouble + * @param q new quaternion + * @note actual storage data is rotation matrix + */ + void setQ(const Quat4d& q) { + setA(q); + } + + /** + * Sets the quaternion of this stuntdouble in specified snapshot + * + * @param q quaternion to be set + * @param snapshotNo + * @note actual storage data is rotation matrix + */ + void setQ(const Quat4d& q, int snapshotNo) { + setA(q, snapshotNo); + } + + /** + * Returns the previous euler angles of this stuntdouble + * @return the euler angles of this stuntdouble + */ + Vector3d getPrevEuler() { + return ((snapshotMan_->getPrevSnapshot())->*storage_).aMat[localIndex_].toEulerAngles(); + } + + /** + * Returns the current euler angles of this stuntdouble + * @return the euler angles of this stuntdouble + */ + Vector3d getEuler() { + return ((snapshotMan_->getCurrentSnapshot())->*storage_).aMat[localIndex_].toEulerAngles(); + } + + /** + * Returns the euler angles of this stuntdouble in specified snapshot. + * @return the euler angles of this stuntdouble + * @param snapshotNo + */ + Vector3d getEuler(int snapshotNo) { + return ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).aMat[localIndex_].toEulerAngles(); + } + + /** + * Sets the previous euler angles of this stuntdouble. + * @param euler new euler angles + * @see #getEuler + * @note actual storage data is rotation matrix + */ + void setPrevEuler(const Vector3d& euler) { + ((snapshotMan_->getPrevSnapshot())->*storage_).aMat[localIndex_] = euler; + } + + /** + * Sets the current euler angles of this stuntdouble + * @param euler new euler angles + */ + void setEuler(const Vector3d& euler) { + ((snapshotMan_->getCurrentSnapshot())->*storage_).aMat[localIndex_] = euler; + } + + /** + * Sets the euler angles of this stuntdouble in specified snapshot + * + * @param euler euler angles to be set + * @param snapshotNo + * @note actual storage data is rotation matrix + */ + void setEuler(const Vector3d& euler, int snapshotNo) { + ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).aMat[localIndex_] = euler; + } + + /** + * Returns the previous unit vectors of this stuntdouble + * @return the unit vectors of this stuntdouble + */ + RotMat3x3d getPrevElectroFrame() { + return ((snapshotMan_->getPrevSnapshot())->*storage_).electroFrame[localIndex_]; + } + + /** + * Returns the current unit vectors of this stuntdouble + * @return the unit vectors of this stuntdouble + */ + RotMat3x3d getElectroFrame() { + return ((snapshotMan_->getCurrentSnapshot())->*storage_).electroFrame[localIndex_]; + } + + /** + * Returns the unit vectors of this stuntdouble in specified snapshot + * + * @return the unit vectors of this stuntdouble + * @param snapshotNo + */ + RotMat3x3d getElectroFrame(int snapshotNo) { + return ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).electroFrame[localIndex_]; + } + + /** + * Returns the previous force of this stuntdouble + * @return the force of this stuntdouble + */ + Vector3d getPrevFrc() { + return ((snapshotMan_->getPrevSnapshot())->*storage_).force[localIndex_]; + } + + /** + * Returns the current force of this stuntdouble + * @return the force of this stuntdouble + */ + Vector3d getFrc() { + return ((snapshotMan_->getCurrentSnapshot())->*storage_).force[localIndex_]; + } + + /** + * Returns the force of this stuntdouble in specified snapshot + * + * @return the force of this stuntdouble + * @param snapshotNo + */ + Vector3d getFrc(int snapshotNo) { + return ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).force[localIndex_]; + } + + /** + * Sets the previous force of this stuntdouble + * + * @param frc new force + * @see #getFrc + */ + void setPrevFrc(const Vector3d& frc) { + ((snapshotMan_->getPrevSnapshot())->*storage_).force[localIndex_] = frc; + } + + /** + * Sets the current force of this stuntdouble + * @param frc new force + */ + void setFrc(const Vector3d& frc) { + ((snapshotMan_->getCurrentSnapshot())->*storage_).force[localIndex_] = frc; + } + + /** + * Sets the force of this stuntdouble in specified snapshot + * + * @param frc force to be set + * @param snapshotNo + * @see #getFrc + */ + void setFrc(const Vector3d& frc, int snapshotNo) { + ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).force[localIndex_] = frc; + } + + /** + * Adds force into the previous force of this stuntdouble + * + * @param frc new force + * @see #getFrc + */ + void addPrevFrc(const Vector3d& frc) { + ((snapshotMan_->getPrevSnapshot())->*storage_).force[localIndex_] += frc; + } + + /** + * Adds force into the current force of this stuntdouble + * @param frc new force + */ + void addFrc(const Vector3d& frc) { + ((snapshotMan_->getCurrentSnapshot())->*storage_).force[localIndex_] += frc; + } + + /** + * Adds force into the force of this stuntdouble in specified snapshot + * + * @param frc force to be set + * @param snapshotNo + * @see #getFrc + */ + void addFrc(const Vector3d& frc, int snapshotNo) { + ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).force[localIndex_] += frc; + } + + /** + * Returns the previous torque of this stuntdouble + * @return the torque of this stuntdouble + */ + Vector3d getPrevTrq() { + return ((snapshotMan_->getPrevSnapshot())->*storage_).torque[localIndex_]; + } + + /** + * Returns the current torque of this stuntdouble + * @return the torque of this stuntdouble + */ + Vector3d getTrq() { + return ((snapshotMan_->getCurrentSnapshot())->*storage_).torque[localIndex_]; + } + + /** + * Returns the torque of this stuntdouble in specified snapshot + * + * @return the torque of this stuntdouble + * @param snapshotNo + */ + Vector3d getTrq(int snapshotNo) { + return ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).torque[localIndex_]; + } + + /** + * Sets the previous torque of this stuntdouble + * + * @param trq new torque + * @see #getTrq + */ + void setPrevTrq(const Vector3d& trq) { + ((snapshotMan_->getPrevSnapshot())->*storage_).torque[localIndex_] = trq; + } + + /** + * Sets the current torque of this stuntdouble + * @param trq new torque + */ + void setTrq(const Vector3d& trq) { + ((snapshotMan_->getCurrentSnapshot())->*storage_).torque[localIndex_] = trq; + } + + /** + * Sets the torque of this stuntdouble in specified snapshot + * + * @param trq torque to be set + * @param snapshotNo + * @see #getTrq + */ + void setTrq(const Vector3d& trq, int snapshotNo) { + ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).torque[localIndex_] = trq; + } + + /** + * Adds torque into the previous torque of this stuntdouble + * + * @param trq new torque + * @see #getTrq + */ + void addPrevTrq(const Vector3d& trq) { + ((snapshotMan_->getPrevSnapshot())->*storage_).torque[localIndex_] += trq; + } + + /** + * Adds torque into the current torque of this stuntdouble + * @param trq new torque + */ + void addTrq(const Vector3d& trq) { + ((snapshotMan_->getCurrentSnapshot())->*storage_).torque[localIndex_] += trq; + } + + /** + * Adds torque into the torque of this stuntdouble in specified snapshot + * + * @param trq torque to be add + * @param snapshotNo + * @see #getTrq + */ + void addTrq(const Vector3d& trq, int snapshotNo) { + ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).torque[localIndex_] += trq; + } + + + /** + * Returns the previous z-angle of this stuntdouble + * @return the z-angle of this stuntdouble + */ + double getPrevZangle() { + return ((snapshotMan_->getPrevSnapshot())->*storage_).zAngle[localIndex_]; + } + + /** + * Returns the current z-angle of this stuntdouble + * @return the z-angle of this stuntdouble + */ + double getZangle() { + return ((snapshotMan_->getCurrentSnapshot())->*storage_).zAngle[localIndex_]; + } + + /** + * Returns the z-angle of this stuntdouble in specified snapshot + * @return the z-angle of this stuntdouble + * @param snapshotNo + */ + double getZangle(int snapshotNo) { + return ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).zAngle[localIndex_]; + } + + /** + * Sets the previous z-angle of this stuntdouble + * @param angle new z-angle + * @see #getZangle + */ + void setPrevZangle(double angle) { + ((snapshotMan_->getPrevSnapshot())->*storage_).zAngle[localIndex_] = angle; + } + + /** + * Sets the current z-angle of this stuntdouble + * @param angle new z-angle + */ + void setZangle(double angle) { + ((snapshotMan_->getCurrentSnapshot())->*storage_).zAngle[localIndex_] = angle; + } + + /** + * Sets the z-angle of this stuntdouble in specified snapshot + * @param angle z-angle to be set + * @param snapshotNo + * @see #getZangle + */ + void setZangle(double angle, int snapshotNo) { + ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).zAngle[localIndex_] = angle; + } + + /** + * Adds z-angle into the previous z-angle of this stuntdouble + * @param angle new z-angle + * @see #getZangle + */ + void addPrevZangle(double angle) { + ((snapshotMan_->getPrevSnapshot())->*storage_).zAngle[localIndex_] += angle; + } + + /** + * Adds z-angle into the current z-angle of this stuntdouble + * @param angle new z-angle + */ + void addZangle(double angle) { + ((snapshotMan_->getCurrentSnapshot())->*storage_).zAngle[localIndex_] += angle; + } + + /** + * Adds z-angle into the z-angle of this stuntdouble in specified snapshot + * @param angle z-angle to be add + * @param snapshotNo + * @see #getZangle + */ + void addZangle(double angle, int snapshotNo) { + ((snapshotMan_->getSnapshot(snapshotNo))->*storage_).zAngle[localIndex_] += angle; + } + + /** Set the force of this stuntdouble to zero */ + void zeroForcesAndTorques(); + /** + * Returns the inertia tensor of this stuntdouble + * @return the inertia tensor of this stuntdouble + */ + virtual Mat3x3d getI() = 0; + + /** + * Returns the gradient of this stuntdouble + * @return the gradient of this stuntdouble + */ + virtual std::vector getGrad() = 0; + + /** + * Tests the if this stuntdouble is a linear rigidbody + * + * @return true if this stuntdouble is a linear rigidbody, otherwise return false + * @note atom and directional atom will always return false + * + * @see #linearAxis + */ + bool isLinear() { + return linear_; + } + + /** + * Returns the linear axis of the rigidbody, atom and directional atom will always return -1 + * + * @return the linear axis of the rigidbody + * + * @see #isLinear + */ + int linearAxis() { + return linearAxis_; + } + + /** Returns the mass of this stuntdouble */ + double getMass() { + return mass_; + } + + /** + * Sets the mass of this stuntdoulbe + * @param mass the mass to be set + */ + void setMass(double mass) { + mass_ = mass; + } + + /** Returns the name of this stuntdouble */ + virtual std::string getType() = 0; + + /** Sets the name of this stuntdouble*/ + virtual void setType(const std::string& name) {} + + /** + * Converts a lab fixed vector to a body fixed vector. + * @return body fixed vector + * @param v lab fixed vector + */ + Vector3d lab2Body(const Vector3d& v) { + return getA() * v; + } + + /** + * Converts a body fixed vector to a lab fixed vector. + * @return corresponding lab fixed vector + * @param v body fixed vector + */ + Vector3d body2Lab(const Vector3d& v){ + return getA().transpose() * v; + } + /** + *

+ * The purpose of the Visitor Pattern is to encapsulate an operation that you want to perform on + * the elements of a data structure. In this way, you can change the operation being performed + * on a structure without the need of changing the classes of the elements that you are operating + * on. Using a Visitor pattern allows you to decouple the classes for the data structure and the + * algorithms used upon them + *

+ * @param v visitor + */ + virtual void accept(BaseVisitor* v) = 0; + + //below functions are just forward functions + /** + * Adds property into property map + * @param genData GenericData to be added into PropertyMap + */ + void addProperty(GenericData* genData); + + /** + * Removes property from PropertyMap by name + * @param propName the name of property to be removed + */ + void removeProperty(const std::string& propName); + + /** + * clear all of the properties + */ + void clearProperties(); + + /** + * Returns all names of properties + * @return all names of properties + */ + std::vector getPropertyNames(); + + /** + * Returns all of the properties in PropertyMap + * @return all of the properties in PropertyMap + */ + std::vector getProperties(); + + /** + * Returns property + * @param propName name of property + * @return a pointer point to property with propName. If no property named propName + * exists, return NULL + */ + GenericData* getPropertyByName(const std::string& propName); + + protected: + + StuntDouble(ObjectType objType, DataStoragePointer storage); + + StuntDouble(const StuntDouble& sd); + StuntDouble& operator=(const StuntDouble& sd); + + ObjectType objType_; + DataStoragePointer storage_; + SnapshotManager* snapshotMan_; + + bool linear_; + int linearAxis_; + + + int globalIndex_; + int localIndex_; + + + double mass_; + + private: + + PropertyMap properties_; }; -#endif +}//end namespace oopse +#endif //PRIMITIVES_STUNTDOUBLE_HPP