ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-3.0/src/primitives/StuntDouble.hpp
Revision: 1883
Committed: Mon Dec 13 22:30:27 2004 UTC (19 years, 7 months ago) by tim
File size: 29930 byte(s)
Log Message:
MPI version is built

File Contents

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

Properties

Name Value
svn:executable *