58 |
|
: info(si), nameFinder(info), distanceFinder(info), hullFinder(info), |
59 |
|
indexFinder(info), hasSurfaceArea_(false), |
60 |
|
isLoaded_(false){ |
61 |
< |
nStuntDouble = info->getNGlobalAtoms() + info->getNGlobalRigidBodies(); |
62 |
< |
} |
63 |
< |
|
61 |
> |
nObjects.push_back(info->getNGlobalAtoms() + info->getNGlobalRigidBodies()); |
62 |
> |
nObjects.push_back(info->getNGlobalBonds()); |
63 |
> |
nObjects.push_back(info->getNGlobalBends()); |
64 |
> |
nObjects.push_back(info->getNGlobalTorsions()); |
65 |
> |
nObjects.push_back(info->getNGlobalInversions()); |
66 |
> |
} |
67 |
> |
|
68 |
|
bool SelectionEvaluator::loadScript(const std::string& filename, |
69 |
|
const std::string& script) { |
70 |
|
clearDefinitionsAndLoadPredefined(); |
131 |
|
return loadScript(filename, script); |
132 |
|
} |
133 |
|
|
134 |
< |
void SelectionEvaluator::instructionDispatchLoop(OpenMDBitSet& bs){ |
134 |
> |
void SelectionEvaluator::instructionDispatchLoop(SelectionSet& bs){ |
135 |
|
|
136 |
|
while ( pc < aatoken.size()) { |
137 |
|
statement = aatoken[pc++]; |
152 |
|
|
153 |
|
} |
154 |
|
|
155 |
< |
void SelectionEvaluator::instructionDispatchLoop(OpenMDBitSet& bs, int frame){ |
155 |
> |
void SelectionEvaluator::instructionDispatchLoop(SelectionSet& bs, int frame){ |
156 |
|
|
157 |
|
while ( pc < aatoken.size()) { |
158 |
|
statement = aatoken[pc++]; |
173 |
|
|
174 |
|
} |
175 |
|
|
176 |
< |
OpenMDBitSet SelectionEvaluator::expression(const std::vector<Token>& code, |
176 |
> |
SelectionSet SelectionEvaluator::expression(const std::vector<Token>& code, |
177 |
|
int pcStart) { |
178 |
< |
OpenMDBitSet bs; |
179 |
< |
std::stack<OpenMDBitSet> stack; |
178 |
> |
SelectionSet bs = createSelectionSets(); |
179 |
> |
std::stack<SelectionSet> stack; |
180 |
> |
vector<int> bsSize = bs.size(); |
181 |
|
|
182 |
|
for (unsigned int pc = pcStart; pc < code.size(); ++pc) { |
183 |
|
Token instruction = code[pc]; |
189 |
|
break; |
190 |
|
case Token::all: |
191 |
|
bs = allInstruction(); |
192 |
< |
stack.push(bs); |
192 |
> |
stack.push(bs); |
193 |
|
break; |
194 |
|
case Token::none: |
195 |
< |
bs = OpenMDBitSet(nStuntDouble); |
196 |
< |
stack.push(bs); |
195 |
> |
bs = createSelectionSets(); |
196 |
> |
stack.push(bs); |
197 |
|
break; |
198 |
|
case Token::opOr: |
199 |
< |
bs = stack.top(); |
200 |
< |
stack.pop(); |
201 |
< |
stack.top() |= bs; |
199 |
> |
bs= stack.top(); |
200 |
> |
stack.pop(); |
201 |
> |
stack.top() |= bs; |
202 |
|
break; |
203 |
|
case Token::opAnd: |
204 |
< |
bs = stack.top(); |
205 |
< |
stack.pop(); |
206 |
< |
stack.top() &= bs; |
204 |
> |
bs = stack.top(); |
205 |
> |
stack.pop(); |
206 |
> |
stack.top() &= bs; |
207 |
|
break; |
208 |
|
case Token::opNot: |
209 |
< |
stack.top().flip(); |
209 |
> |
stack.top().flip(); |
210 |
|
break; |
211 |
|
case Token::within: |
212 |
|
withinInstruction(instruction, stack.top()); |
213 |
|
break; |
214 |
|
case Token::hull: |
215 |
< |
stack.push(hull()); |
215 |
> |
stack.push(hull()); |
216 |
|
break; |
217 |
|
//case Token::selected: |
218 |
|
// stack.push(getSelectionSet()); |
219 |
|
// break; |
220 |
|
case Token::name: |
221 |
< |
stack.push(nameInstruction(boost::any_cast<std::string>(instruction.value))); |
221 |
> |
stack.push(nameInstruction(boost::any_cast<std::string>(instruction.value))); |
222 |
|
break; |
223 |
|
case Token::index: |
224 |
< |
stack.push(indexInstruction(instruction.value)); |
224 |
> |
stack.push(indexInstruction(instruction.value)); |
225 |
|
break; |
226 |
|
case Token::identifier: |
227 |
< |
stack.push(lookupValue(boost::any_cast<std::string>(instruction.value))); |
227 |
> |
stack.push(lookupValue(boost::any_cast<std::string>(instruction.value))); |
228 |
|
break; |
229 |
|
case Token::opLT: |
230 |
|
case Token::opLE: |
245 |
|
} |
246 |
|
|
247 |
|
|
248 |
< |
OpenMDBitSet SelectionEvaluator::expression(const std::vector<Token>& code, |
248 |
> |
SelectionSet SelectionEvaluator::expression(const std::vector<Token>& code, |
249 |
|
int pcStart, int frame) { |
250 |
< |
OpenMDBitSet bs; |
251 |
< |
std::stack<OpenMDBitSet> stack; |
250 |
> |
SelectionSet bs = createSelectionSets(); |
251 |
> |
std::stack<SelectionSet> stack; |
252 |
|
|
253 |
|
for (unsigned int pc = pcStart; pc < code.size(); ++pc) { |
254 |
|
Token instruction = code[pc]; |
263 |
|
stack.push(bs); |
264 |
|
break; |
265 |
|
case Token::none: |
266 |
< |
bs = OpenMDBitSet(nStuntDouble); |
266 |
> |
bs = SelectionSet(nObjects); |
267 |
|
stack.push(bs); |
268 |
|
break; |
269 |
|
case Token::opOr: |
317 |
|
|
318 |
|
|
319 |
|
|
320 |
< |
OpenMDBitSet SelectionEvaluator::comparatorInstruction(const Token& instruction) { |
320 |
> |
SelectionSet SelectionEvaluator::comparatorInstruction(const Token& instruction) { |
321 |
|
int comparator = instruction.tok; |
322 |
|
int property = instruction.intValue; |
323 |
|
float comparisonValue = boost::any_cast<float>(instruction.value); |
324 |
< |
OpenMDBitSet bs(nStuntDouble); |
324 |
> |
SelectionSet bs = createSelectionSets(); |
325 |
|
bs.clearAll(); |
326 |
|
|
327 |
|
SimInfo::MoleculeIterator mi; |
347 |
|
return bs; |
348 |
|
} |
349 |
|
|
350 |
< |
OpenMDBitSet SelectionEvaluator::comparatorInstruction(const Token& instruction, int frame) { |
350 |
> |
SelectionSet SelectionEvaluator::comparatorInstruction(const Token& instruction, int frame) { |
351 |
|
int comparator = instruction.tok; |
352 |
|
int property = instruction.intValue; |
353 |
|
float comparisonValue = boost::any_cast<float>(instruction.value); |
354 |
< |
OpenMDBitSet bs(nStuntDouble); |
354 |
> |
SelectionSet bs = createSelectionSets(); |
355 |
|
bs.clearAll(); |
356 |
|
|
357 |
|
SimInfo::MoleculeIterator mi; |
377 |
|
return bs; |
378 |
|
} |
379 |
|
|
380 |
< |
void SelectionEvaluator::compareProperty(StuntDouble* sd, OpenMDBitSet& bs, |
380 |
> |
void SelectionEvaluator::compareProperty(StuntDouble* sd, SelectionSet& bs, |
381 |
|
int property, int comparator, |
382 |
|
float comparisonValue) { |
383 |
|
RealType propertyValue = 0.0; |
384 |
|
Vector3d pos; |
385 |
+ |
|
386 |
|
switch (property) { |
387 |
|
case Token::mass: |
388 |
|
propertyValue = sd->getMass(); |
452 |
|
match = propertyValue != comparisonValue; |
453 |
|
break; |
454 |
|
} |
455 |
+ |
|
456 |
|
if (match) |
457 |
< |
bs.setBitOn(sd->getGlobalIndex()); |
457 |
> |
bs.bitsets_[STUNTDOUBLE].setBitOn(sd->getGlobalIndex()); |
458 |
|
|
459 |
|
|
460 |
|
} |
461 |
|
|
462 |
< |
void SelectionEvaluator::compareProperty(StuntDouble* sd, OpenMDBitSet& bs, |
462 |
> |
void SelectionEvaluator::compareProperty(StuntDouble* sd, SelectionSet& bs, |
463 |
|
int property, int comparator, |
464 |
|
float comparisonValue, int frame) { |
465 |
|
RealType propertyValue = 0.0; |
535 |
|
break; |
536 |
|
} |
537 |
|
if (match) |
538 |
< |
bs.setBitOn(sd->getGlobalIndex()); |
538 |
> |
bs.bitsets_[STUNTDOUBLE].setBitOn(sd->getGlobalIndex()); |
539 |
|
|
540 |
|
|
541 |
|
} |
542 |
|
|
543 |
|
void SelectionEvaluator::withinInstruction(const Token& instruction, |
544 |
< |
OpenMDBitSet& bs){ |
544 |
> |
SelectionSet& bs){ |
545 |
|
|
546 |
|
boost::any withinSpec = instruction.value; |
547 |
|
float distance; |
558 |
|
} |
559 |
|
|
560 |
|
void SelectionEvaluator::withinInstruction(const Token& instruction, |
561 |
< |
OpenMDBitSet& bs, int frame){ |
561 |
> |
SelectionSet& bs, int frame){ |
562 |
|
|
563 |
|
boost::any withinSpec = instruction.value; |
564 |
|
float distance; |
615 |
|
} |
616 |
|
} |
617 |
|
|
618 |
< |
void SelectionEvaluator::select(OpenMDBitSet& bs){ |
618 |
> |
void SelectionEvaluator::select(SelectionSet& bs){ |
619 |
|
bs = expression(statement, 1); |
620 |
|
} |
621 |
|
|
622 |
< |
void SelectionEvaluator::select(OpenMDBitSet& bs, int frame){ |
622 |
> |
void SelectionEvaluator::select(SelectionSet& bs, int frame){ |
623 |
|
bs = expression(statement, 1, frame); |
624 |
|
} |
625 |
|
|
626 |
< |
OpenMDBitSet SelectionEvaluator::lookupValue(const std::string& variable){ |
626 |
> |
SelectionSet SelectionEvaluator::lookupValue(const std::string& variable){ |
627 |
|
|
628 |
< |
OpenMDBitSet bs(nStuntDouble); |
628 |
> |
SelectionSet bs = createSelectionSets(); |
629 |
|
std::map<std::string, boost::any>::iterator i = variables.find(variable); |
630 |
|
|
631 |
|
if (i != variables.end()) { |
632 |
< |
if (i->second.type() == typeid(OpenMDBitSet)) { |
633 |
< |
return boost::any_cast<OpenMDBitSet>(i->second); |
632 |
> |
if (i->second.type() == typeid(SelectionSet)) { |
633 |
> |
return boost::any_cast<SelectionSet>(i->second); |
634 |
|
} else if (i->second.type() == typeid(std::vector<Token>)){ |
635 |
|
bs = expression(boost::any_cast<std::vector<Token> >(i->second), 2); |
636 |
|
i->second = bs; /**@todo fixme */ |
643 |
|
return bs; |
644 |
|
} |
645 |
|
|
646 |
< |
OpenMDBitSet SelectionEvaluator::nameInstruction(const std::string& name){ |
646 |
> |
SelectionSet SelectionEvaluator::nameInstruction(const std::string& name){ |
647 |
|
return nameFinder.match(name); |
648 |
|
} |
649 |
|
|
664 |
|
//predefine(); |
665 |
|
} |
666 |
|
|
667 |
< |
OpenMDBitSet SelectionEvaluator::evaluate() { |
668 |
< |
OpenMDBitSet bs(nStuntDouble); |
667 |
> |
SelectionSet SelectionEvaluator::createSelectionSets() { |
668 |
> |
SelectionSet ss(nObjects); |
669 |
> |
return ss; |
670 |
> |
} |
671 |
> |
|
672 |
> |
SelectionSet SelectionEvaluator::evaluate() { |
673 |
> |
SelectionSet bs = createSelectionSets(); |
674 |
|
if (isLoaded_) { |
675 |
|
pc = 0; |
676 |
|
instructionDispatchLoop(bs); |
678 |
|
return bs; |
679 |
|
} |
680 |
|
|
681 |
< |
OpenMDBitSet SelectionEvaluator::evaluate(int frame) { |
682 |
< |
OpenMDBitSet bs(nStuntDouble); |
681 |
> |
SelectionSet SelectionEvaluator::evaluate(int frame) { |
682 |
> |
SelectionSet bs = createSelectionSets(); |
683 |
|
if (isLoaded_) { |
684 |
|
pc = 0; |
685 |
|
instructionDispatchLoop(bs, frame); |
687 |
|
return bs; |
688 |
|
} |
689 |
|
|
690 |
< |
OpenMDBitSet SelectionEvaluator::indexInstruction(const boost::any& value) { |
691 |
< |
OpenMDBitSet bs(nStuntDouble); |
690 |
> |
SelectionSet SelectionEvaluator::indexInstruction(const boost::any& value) { |
691 |
> |
SelectionSet bs = createSelectionSets(); |
692 |
|
|
693 |
|
if (value.type() == typeid(int)) { |
694 |
|
int index = boost::any_cast<int>(value); |
695 |
< |
if (index < 0 || index >= bs.size()) { |
695 |
> |
if (index < 0 || index >= bs.bitsets_[STUNTDOUBLE].size()) { |
696 |
|
invalidIndex(index); |
697 |
|
} else { |
698 |
|
bs = indexFinder.find(index); |
700 |
|
} else if (value.type() == typeid(std::pair<int, int>)) { |
701 |
|
std::pair<int, int> indexRange= boost::any_cast<std::pair<int, int> >(value); |
702 |
|
assert(indexRange.first <= indexRange.second); |
703 |
< |
if (indexRange.first < 0 || indexRange.second >= bs.size()) { |
703 |
> |
if (indexRange.first < 0 || |
704 |
> |
indexRange.second >= bs.bitsets_[STUNTDOUBLE].size()) { |
705 |
|
invalidIndexRange(indexRange); |
706 |
|
}else { |
707 |
|
bs = indexFinder.find(indexRange.first, indexRange.second); |
711 |
|
return bs; |
712 |
|
} |
713 |
|
|
714 |
< |
OpenMDBitSet SelectionEvaluator::allInstruction() { |
715 |
< |
OpenMDBitSet bs(nStuntDouble); |
714 |
> |
SelectionSet SelectionEvaluator::allInstruction() { |
715 |
> |
SelectionSet ss = createSelectionSets(); |
716 |
|
|
717 |
|
SimInfo::MoleculeIterator mi; |
705 |
– |
Molecule* mol; |
718 |
|
Molecule::AtomIterator ai; |
707 |
– |
Atom* atom; |
719 |
|
Molecule::RigidBodyIterator rbIter; |
720 |
+ |
Molecule::BondIterator bondIter; |
721 |
+ |
Molecule::BendIterator bendIter; |
722 |
+ |
Molecule::TorsionIterator torsionIter; |
723 |
+ |
Molecule::InversionIterator inversionIter; |
724 |
+ |
|
725 |
+ |
Molecule* mol; |
726 |
+ |
Atom* atom; |
727 |
|
RigidBody* rb; |
728 |
+ |
Bond* bond; |
729 |
+ |
Bend* bend; |
730 |
+ |
Torsion* torsion; |
731 |
+ |
Inversion* inversion; |
732 |
|
|
733 |
|
// Doing the loop insures that we're actually on this processor. |
734 |
|
|
735 |
|
for (mol = info->beginMolecule(mi); mol != NULL; |
736 |
|
mol = info->nextMolecule(mi)) { |
715 |
– |
|
737 |
|
for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { |
738 |
< |
bs.setBitOn(atom->getGlobalIndex()); |
739 |
< |
} |
719 |
< |
|
738 |
> |
ss.bitsets_[STUNTDOUBLE].setBitOn(atom->getGlobalIndex()); |
739 |
> |
} |
740 |
|
for (rb = mol->beginRigidBody(rbIter); rb != NULL; |
741 |
|
rb = mol->nextRigidBody(rbIter)) { |
742 |
< |
bs.setBitOn(rb->getGlobalIndex()); |
742 |
> |
ss.bitsets_[STUNTDOUBLE].setBitOn(rb->getGlobalIndex()); |
743 |
|
} |
744 |
+ |
for (bond = mol->beginBond(bondIter); bond != NULL; |
745 |
+ |
bond = mol->nextBond(bondIter)) { |
746 |
+ |
ss.bitsets_[BOND].setBitOn(bond->getGlobalIndex()); |
747 |
+ |
} |
748 |
+ |
for (bend = mol->beginBend(bendIter); bend != NULL; |
749 |
+ |
bend = mol->nextBend(bendIter)) { |
750 |
+ |
ss.bitsets_[BEND].setBitOn(bend->getGlobalIndex()); |
751 |
+ |
} |
752 |
+ |
for (torsion = mol->beginTorsion(torsionIter); torsion != NULL; |
753 |
+ |
torsion = mol->nextTorsion(torsionIter)) { |
754 |
+ |
ss.bitsets_[TORSION].setBitOn(torsion->getGlobalIndex()); |
755 |
+ |
} |
756 |
+ |
for (inversion = mol->beginInversion(inversionIter); inversion != NULL; |
757 |
+ |
inversion = mol->nextInversion(inversionIter)) { |
758 |
+ |
ss.bitsets_[INVERSION].setBitOn(inversion->getGlobalIndex()); |
759 |
+ |
} |
760 |
|
} |
761 |
|
|
762 |
< |
return bs; |
762 |
> |
return ss; |
763 |
|
} |
764 |
|
|
765 |
< |
OpenMDBitSet SelectionEvaluator::hull() { |
766 |
< |
OpenMDBitSet bs(nStuntDouble); |
765 |
> |
SelectionSet SelectionEvaluator::hull() { |
766 |
> |
SelectionSet bs = createSelectionSets(); |
767 |
|
|
768 |
|
bs = hullFinder.findHull(); |
769 |
|
surfaceArea_ = hullFinder.getSurfaceArea(); |
772 |
|
} |
773 |
|
|
774 |
|
|
775 |
< |
OpenMDBitSet SelectionEvaluator::hull(int frame) { |
776 |
< |
OpenMDBitSet bs(nStuntDouble); |
775 |
> |
SelectionSet SelectionEvaluator::hull(int frame) { |
776 |
> |
SelectionSet bs = createSelectionSets(); |
777 |
|
|
778 |
|
bs = hullFinder.findHull(frame); |
779 |
|
|