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