32 |
|
*/ |
33 |
|
|
34 |
|
#include <cassert> |
35 |
+ |
#include <set> |
36 |
|
|
37 |
|
#include "brains/MoleculeCreator.hpp" |
38 |
|
#include "primitives/GhostBend.hpp" |
156 |
|
mol->addCutoffGroup(cutoffGroup); |
157 |
|
} |
158 |
|
//create constraints |
159 |
< |
|
159 |
> |
createConstraintPair(mol); |
160 |
> |
createConstraintElem(mol); |
161 |
> |
|
162 |
|
//the construction of this molecule is finished |
163 |
|
mol->complete(); |
164 |
|
|
421 |
|
for (bond = mol->beginBond(bi); bond != NULL; bond = mol->nextBond(bi)) { |
422 |
|
|
423 |
|
BondType* bt = bond->getBondType(); |
421 |
– |
FixedBondType* fbt = dynamic_cast<FixedBondType*>(bt); |
424 |
|
|
425 |
< |
//found a constraint pair |
426 |
< |
if (fbt != NULL) { |
427 |
< |
ConstraintPair* consPair = new ConstraintPair(bond->getAtomA(), bond->getAtomB(), fbt->getEquilibriumBondLength()); |
425 |
> |
//class Parent1 {}; |
426 |
> |
//class Child1 : public Parent {}; |
427 |
> |
//class Child2 : public Parent {}; |
428 |
> |
//Child1* ch1 = new Child1(); |
429 |
> |
//Child2* ch2 = dynamic_cast<Child2*>(ch1); |
430 |
> |
//the dynamic_cast is succeed in above line. A compiler bug? |
431 |
> |
|
432 |
> |
if (typeid(FixedBondType) == typeid(*bt)) { |
433 |
> |
FixedBondType* fbt = dynamic_cast<FixedBondType*>(bt); |
434 |
> |
|
435 |
> |
ConstraintElem* consElemA = new ConstraintElem(bond->getAtomA()); |
436 |
> |
ConstraintElem* consElemB = new ConstraintElem(bond->getAtomB()); |
437 |
> |
ConstraintPair* consPair = new ConstraintPair(consElemA, consElemB, fbt->getEquilibriumBondLength()); |
438 |
|
mol->addConstraintPair(consPair); |
439 |
|
} |
428 |
– |
|
440 |
|
} |
441 |
|
|
442 |
|
//rigidbody -- rigidbody constraint is not support yet |
432 |
– |
|
443 |
|
} |
444 |
|
|
445 |
+ |
void MoleculeCreator::createConstraintElem(Molecule* mol) { |
446 |
+ |
|
447 |
+ |
ConstraintPair* consPair; |
448 |
+ |
Molecule::ConstraintPairIterator cpi; |
449 |
+ |
std::set<StuntDouble*> sdSet; |
450 |
+ |
for (consPair = mol->beginConstraintPair(cpi); consPair != NULL; consPair = mol->nextConstraintPair(cpi)) { |
451 |
+ |
|
452 |
+ |
StuntDouble* sdA = consPair->getConsElem1()->getStuntDouble(); |
453 |
+ |
if (sdSet.find(sdA) == sdSet.end()){ |
454 |
+ |
sdSet.insert(sdA); |
455 |
+ |
mol->addConstraintElem(new ConstraintElem(sdA)); |
456 |
+ |
} |
457 |
+ |
|
458 |
+ |
StuntDouble* sdB = consPair->getConsElem2()->getStuntDouble(); |
459 |
+ |
if (sdSet.find(sdB) == sdSet.end()){ |
460 |
+ |
sdSet.insert(sdB); |
461 |
+ |
mol->addConstraintElem(new ConstraintElem(sdB)); |
462 |
+ |
} |
463 |
+ |
|
464 |
+ |
} |
465 |
+ |
|
466 |
|
} |
467 |
+ |
|
468 |
+ |
} |