ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-2.0/src/constraints/ConstraintElem.hpp
Revision: 1911
Committed: Mon Jan 10 18:05:45 2005 UTC (19 years, 5 months ago) by tim
File size: 25834 byte(s)
Log Message:
more work in zconstraint

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

Properties

Name Value
svn:executable *