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