1 |
tim |
1232 |
#ifndef _CONSTRAINTELEMENT_H_ |
2 |
|
|
#define _CONSTRAINTELEMENT_H_ |
3 |
|
|
|
4 |
|
|
#include "RigidBody.hpp" |
5 |
|
|
#include "Atom.hpp" |
6 |
tim |
1452 |
#include "Vector3d.hpp" |
7 |
tim |
1232 |
|
8 |
|
|
|
9 |
tim |
1452 |
class Vector3dData : public GenericData{ |
10 |
|
|
public: |
11 |
|
|
Vector3d getData() {return vec;} |
12 |
|
|
void setData(const Vector3d& rhs) { vec = rhs;} |
13 |
|
|
private: |
14 |
|
|
Vector3d vec; |
15 |
|
|
|
16 |
|
|
}; |
17 |
|
|
|
18 |
tim |
1232 |
//class ConstraintElement is designed to not only provide the interface of StuntDouble, but also |
19 |
|
|
//neccessary functionality to retrieve old position, old velocity and etc. |
20 |
|
|
//First of all, those old data should be stored inside StuntDouble. We decide to store it on StuntDouble's |
21 |
|
|
//generic property. |
22 |
|
|
//////////////////////////////////////////////////////////////////////////////// |
23 |
|
|
//Declaration of ConstraintElement |
24 |
|
|
//////////////////////////////////////////////////////////////////////////////// |
25 |
|
|
class ConstraintElement{ |
26 |
|
|
public: |
27 |
|
|
|
28 |
|
|
virtual ~ConstraintElement() {} |
29 |
|
|
|
30 |
|
|
//Interface of stunt double |
31 |
|
|
bool isAtom() {return refSd->isAtom();} |
32 |
|
|
bool isDirectionalAtom() {return refSd->isDirectional();} |
33 |
|
|
bool isRigidBody() {return refSd->isRigidBody();} |
34 |
|
|
|
35 |
|
|
double getMass(void) {return refSd->getMass();} |
36 |
|
|
|
37 |
|
|
void getPos(double pos[3]) {refSd->getPos(pos);} |
38 |
|
|
void setPos(double pos[3]) {refSd->setPos(pos);} |
39 |
|
|
|
40 |
|
|
void getVel(double vel[3]) {refSd->getVel(vel);} |
41 |
|
|
void setVel(double vel[3]) {refSd->setVel(vel);} |
42 |
|
|
|
43 |
|
|
void getFrc(double frc[3]) {refSd->getFrc(frc);} |
44 |
|
|
void addFrc(double frc[3]) {refSd->addFrc(frc);} |
45 |
|
|
|
46 |
|
|
void getA(double A[3][3]) {refSd->getA(A);} |
47 |
|
|
void setA(double A[3][3]) {refSd->setA(A);} |
48 |
|
|
|
49 |
|
|
void getJ(double j[3]) {refSd->getJ(j);} |
50 |
|
|
void setJ(double j[3]) {refSd->setJ(j);} |
51 |
|
|
|
52 |
|
|
void getQ( double q[4] ) {refSd->getQ(q);} |
53 |
|
|
void setQ( double q[4] ) {refSd->setQ(q);} |
54 |
|
|
|
55 |
|
|
void setType(char* type){refSd->setType(type);} |
56 |
|
|
char* getType() {return refSd->getType();} |
57 |
|
|
|
58 |
|
|
void getTrq(double trq[3]) {refSd->getTrq(trq);} |
59 |
|
|
void addTrq(double trq[3]) {refSd->addTrq(trq);} |
60 |
|
|
|
61 |
|
|
void getI(double I[3][3]) {refSd->getI(I);} |
62 |
|
|
void lab2Body(double vec[3]) {refSd->lab2Body(vec);} |
63 |
|
|
|
64 |
|
|
void getGrad(double grad[6]) {refSd->getGrad(grad);} |
65 |
|
|
void setEuler(double phi, double theta, double psi) {refSd->setEuler(phi, theta, psi);} |
66 |
|
|
void getEulerAngles(double eulers[3]) {refSd->getEulerAngles(eulers);} |
67 |
|
|
|
68 |
|
|
bool isLinear() {return refSd->isLinear();} |
69 |
|
|
int linearAxis() {return refSd->linearAxis();} |
70 |
|
|
|
71 |
|
|
double getZangle() {return refSd->getZangle();} |
72 |
|
|
void setZangle(double zAngle) {refSd->setZangle(zAngle);} |
73 |
|
|
void addZangle(double zAngle) {refSd->addZangle(zAngle);} |
74 |
|
|
|
75 |
tim |
1254 |
StuntDouble* getStuntDouble() {return refSd;} |
76 |
tim |
1232 |
|
77 |
|
|
virtual void getOldPos(double pos[3])=0; |
78 |
|
|
virtual void getOldVel(double vel[3])=0; |
79 |
|
|
virtual void getOldJ(double j[3])=0; |
80 |
|
|
virtual void getOldA(double a[3][3])=0; |
81 |
|
|
virtual void getOldQ(double q[4])=0; |
82 |
|
|
|
83 |
|
|
bool getMoved() {return movedData->getData();} |
84 |
|
|
void setMoved(bool status) {movedData->setData(status);} |
85 |
|
|
|
86 |
|
|
bool getMoving() {return movingData->getData();} |
87 |
|
|
void setMoving(bool status) {movingData->setData(status);} |
88 |
|
|
|
89 |
tim |
1452 |
//constraint force |
90 |
|
|
void addConsForce(const Vector3d& frc){ |
91 |
|
|
Vector3d tempFrc; |
92 |
|
|
tempFrc = consForceData->getData(); |
93 |
|
|
tempFrc += frc; |
94 |
|
|
consForceData->setData(tempFrc); |
95 |
|
|
} |
96 |
|
|
Vector3d getConsForce() { return consForceData->getData();} |
97 |
|
|
void setConsTorque(const Vector3d& frc) {consForceData->setData(frc);} |
98 |
|
|
|
99 |
|
|
|
100 |
|
|
//constraint torque |
101 |
|
|
void addConsTorque(const Vector3d& trq){ |
102 |
|
|
Vector3d tempTrq; |
103 |
|
|
tempTrq = consTorqueData->getData(); |
104 |
|
|
tempTrq += trq; |
105 |
|
|
consTorqueData->setData(tempTrq); |
106 |
|
|
} |
107 |
|
|
Vector3d getConsTorque() { return consTorqueData->getData();} |
108 |
|
|
void setConsForce(const Vector3d& trq) {consTorqueData->setData(trq);} |
109 |
|
|
|
110 |
|
|
|
111 |
tim |
1232 |
virtual void saveOldState() = 0; |
112 |
|
|
|
113 |
|
|
protected: |
114 |
|
|
ConstraintElement(StuntDouble* rhs); |
115 |
|
|
|
116 |
|
|
StuntDouble* refSd; |
117 |
|
|
|
118 |
|
|
private: |
119 |
|
|
BoolData* movedData; |
120 |
|
|
BoolData* movingData; |
121 |
tim |
1452 |
Vector3dData* consForceData; |
122 |
|
|
Vector3dData* consTorqueData; |
123 |
tim |
1232 |
}; |
124 |
|
|
|
125 |
|
|
|
126 |
|
|
//////////////////////////////////////////////////////////////////////////////// |
127 |
|
|
//Declaration of ConsAtomData |
128 |
|
|
//////////////////////////////////////////////////////////////////////////////// |
129 |
|
|
struct ConsAtomInfo{ |
130 |
|
|
double pos[3]; |
131 |
|
|
double vel[3]; |
132 |
|
|
double a[3][3]; |
133 |
|
|
double j[3]; |
134 |
|
|
double q[4]; |
135 |
tim |
1452 |
double frc[3]; |
136 |
|
|
double trq[3]; |
137 |
tim |
1232 |
}; |
138 |
|
|
|
139 |
|
|
class ConsAtomData : public GenericData{ |
140 |
|
|
public: |
141 |
|
|
ConsAtomData() : data(NULL){} |
142 |
|
|
~ConsAtomData(){ |
143 |
|
|
if(data != NULL) |
144 |
|
|
delete data; |
145 |
|
|
} |
146 |
|
|
|
147 |
|
|
ConsAtomInfo* getData() {return data;} |
148 |
|
|
void setData(ConsAtomInfo* info) { |
149 |
|
|
if (data != NULL) |
150 |
|
|
delete data; |
151 |
|
|
|
152 |
|
|
data = info; |
153 |
|
|
} |
154 |
|
|
|
155 |
|
|
private: |
156 |
|
|
ConsAtomInfo* data; |
157 |
|
|
}; |
158 |
|
|
//////////////////////////////////////////////////////////////////////////////// |
159 |
|
|
//Declaration of ConstraintElement |
160 |
|
|
//////////////////////////////////////////////////////////////////////////////// |
161 |
|
|
class ConstraintAtom : public ConstraintElement{ |
162 |
|
|
public: |
163 |
|
|
ConstraintAtom(Atom* rhs); |
164 |
|
|
|
165 |
|
|
void getOldPos(double pos[3]); |
166 |
|
|
void getOldVel(double vel[3]); |
167 |
|
|
void getOldJ(double j[3]); |
168 |
|
|
void getOldA(double a[3][3]); |
169 |
|
|
void getOldQ(double q[4]); |
170 |
|
|
|
171 |
|
|
Atom* getAtom() {return dynamic_cast<Atom*>(refSd);} |
172 |
|
|
|
173 |
|
|
virtual void saveOldState(); |
174 |
|
|
|
175 |
|
|
protected: |
176 |
|
|
ConsAtomInfo* oldConsAtomInfo; |
177 |
|
|
|
178 |
|
|
}; |
179 |
|
|
|
180 |
|
|
|
181 |
|
|
|
182 |
|
|
//////////////////////////////////////////////////////////////////////////////// |
183 |
|
|
//Declaration of ConsRbData |
184 |
|
|
//////////////////////////////////////////////////////////////////////////////// |
185 |
|
|
class ConsRbData : public GenericData{ |
186 |
|
|
public: |
187 |
|
|
ConsRbData() : rb(NULL){} |
188 |
|
|
~ConsRbData(){ |
189 |
|
|
if (rb != NULL) |
190 |
|
|
delete rb; |
191 |
|
|
} |
192 |
|
|
|
193 |
|
|
RigidBody* getData() {return rb;} |
194 |
|
|
void setData(RigidBody* rhs) { |
195 |
|
|
if (rb != NULL) |
196 |
|
|
delete rb; |
197 |
|
|
rb = rhs; |
198 |
|
|
} |
199 |
|
|
|
200 |
|
|
private: |
201 |
|
|
RigidBody* rb; |
202 |
|
|
}; |
203 |
|
|
|
204 |
|
|
//////////////////////////////////////////////////////////////////////////////// |
205 |
|
|
//Declaration of ConstraintElement |
206 |
|
|
//////////////////////////////////////////////////////////////////////////////// |
207 |
|
|
class ConstraintRigidBody : public ConstraintElement{ |
208 |
|
|
public: |
209 |
|
|
ConstraintRigidBody(RigidBody*rhs, int index); |
210 |
|
|
|
211 |
|
|
void getOldPos(double pos[3]) {oldRb->getPos(pos);} |
212 |
|
|
void getOldVel(double vel[3]) {oldRb->getVel(vel);} |
213 |
|
|
void getOldJ(double j[3]) {oldRb->getJ(j);} |
214 |
|
|
void getOldA(double a[3][3]) {oldRb->getA(a);} |
215 |
|
|
void getOldQ(double q[4]) {oldRb->getQ(q);} |
216 |
|
|
|
217 |
|
|
void getOldAtomPos(double pos[3]) {oldRb->getAtomPos(pos, consAtomIndex);} |
218 |
|
|
void getCurAtomPos(double pos[3]) {((RigidBody*)refSd)->getAtomPos(pos, consAtomIndex);} |
219 |
tim |
1254 |
|
220 |
tim |
1284 |
void getOldAtomVel(double vel[3]) {oldRb->getAtomVel(vel, consAtomIndex);}; |
221 |
|
|
void getCurAtomVel(double vel[3]) {((RigidBody*)refSd)->getAtomVel(vel, consAtomIndex);}; |
222 |
|
|
|
223 |
tim |
1254 |
void getRefCoor(double pos[3]) {return ((RigidBody*)refSd)->getAtomRefCoor(pos, consAtomIndex);} |
224 |
tim |
1232 |
RigidBody* getRigidBody() { return dynamic_cast<RigidBody*>(refSd);} |
225 |
|
|
|
226 |
|
|
virtual void saveOldState(); |
227 |
tim |
1452 |
|
228 |
|
|
void restoreUnconsStatus(); |
229 |
|
|
|
230 |
tim |
1232 |
|
231 |
|
|
private: |
232 |
|
|
int consAtomIndex; |
233 |
|
|
RigidBody* oldRb; |
234 |
tim |
1452 |
|
235 |
tim |
1232 |
}; |
236 |
|
|
#endif // endif _CONSTRAINTELEMENT_H_ |