--- trunk/OOPSE-4/src/visitors/OtherVisitor.cpp 2005/02/04 22:45:48 1977 +++ trunk/OOPSE-4/src/visitors/OtherVisitor.cpp 2007/01/16 22:18:04 3116 @@ -1,4 +1,4 @@ - /* +/* * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. * * The University of Notre Dame grants you ("Licensee") a @@ -38,7 +38,7 @@ * University of Notre Dame has been advised of the possibility of * such damages. */ - +#include "selection/SelectionManager.hpp" #include "visitors/OtherVisitor.hpp" #include "primitives/DirectionalAtom.hpp" #include "primitives/RigidBody.hpp" @@ -46,98 +46,19 @@ namespace oopse { #include "brains/SimInfo.hpp" namespace oopse { -//----------------------------------------------------------------------------// -void IgnoreVisitor::visit(Atom *atom) { - if (isIgnoreType(atom->getType())) - internalVisit(atom); -} + void WrappingVisitor::visit(Atom *atom) { + internalVisit(atom); + } -void IgnoreVisitor::visit(DirectionalAtom *datom) { - if (isIgnoreType(datom->getType())) - internalVisit(datom); -} + void WrappingVisitor::visit(DirectionalAtom *datom) { + internalVisit(datom); + } -void IgnoreVisitor::visit(RigidBody *rb) { - std::vector myAtoms; - std::vector::iterator atomIter; - AtomInfo * atomInfo; + void WrappingVisitor::visit(RigidBody *rb) { + internalVisit(rb); + } - if (isIgnoreType(rb->getType())) { - internalVisit(rb); - - myAtoms = rb->getAtoms(); - - for( atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter ) - internalVisit(*atomIter); - } -} - -bool IgnoreVisitor::isIgnoreType(const std::string&name) { -return itList.find(name) != itList.end() ? true : false; -} - -void IgnoreVisitor::internalVisit(StuntDouble *sd) { - info->getSelectionManager()->clearSelection(sd); - //GenericData *data; - //data = sd->getPropertyByName("IGNORE"); - // - ////if this stuntdoulbe is already marked as ignore just skip it - //if (data == NULL) { - // data = new GenericData; - // data->setID("IGNORE"); - // sd->addProperty(data); - //} -} - -const std::string IgnoreVisitor::toString() { - char buffer[65535]; - std::string result; - std::set::iterator i; - - sprintf(buffer, - "------------------------------------------------------------------\n"); - result += buffer; - - sprintf(buffer, "Visitor name: %s\n", visitorName.c_str()); - result += buffer; - - sprintf(buffer, "Visitor Description: ignore stuntdoubles\n"); - result += buffer; - - //print the ignore type list - sprintf(buffer, "Ignore type list contains below types:\n"); - result += buffer; - - for( i = itList.begin(); i != itList.end(); ++i ) { - sprintf(buffer, "%s\t", i->c_str()); - result += buffer; - } - - sprintf(buffer, "\n"); - result += buffer; - - sprintf(buffer, - "------------------------------------------------------------------\n"); - result += buffer; - - return result; -} - -//----------------------------------------------------------------------------// - -void WrappingVisitor::visit(Atom *atom) { -internalVisit(atom); -} - -void WrappingVisitor::visit(DirectionalAtom *datom) { -internalVisit(datom); -} - -void WrappingVisitor::visit(RigidBody *rb) { -internalVisit(rb); -} - -void WrappingVisitor::internalVisit(StuntDouble *sd) { + void WrappingVisitor::internalVisit(StuntDouble *sd) { GenericData * data; AtomData * atomData; AtomInfo * atomInfo; @@ -146,21 +67,29 @@ void WrappingVisitor::internalVisit(StuntDouble *sd) { data = sd->getPropertyByName("ATOMDATA"); if (data != NULL) { - atomData = dynamic_cast(data); + atomData = dynamic_cast(data); - if (atomData == NULL) - return; + if (atomData == NULL) + return; } else - return; + return; Snapshot* currSnapshot = info->getSnapshotManager()->getCurrentSnapshot(); for( atomInfo = atomData->beginAtomInfo(i); atomInfo; atomInfo = atomData->nextAtomInfo(i) ) { - currSnapshot->wrapVector(atomInfo->pos); + Vector3d newPos = atomInfo->pos - origin_; + currSnapshot->wrapVector(newPos); + atomInfo->pos = newPos; } -} + } -const std::string WrappingVisitor::toString() { + void WrappingVisitor::update() { + if (useCom_){ + origin_ = info->getCom(); + } + } + + const std::string WrappingVisitor::toString() { char buffer[65535]; std::string result; @@ -180,45 +109,45 @@ const std::string WrappingVisitor::toString() { result += buffer; return result; -} + } -//----------------------------------------------------------------------------// + //----------------------------------------------------------------------------// -ReplicateVisitor::ReplicateVisitor(SimInfo *info, Vector3i opt) : + ReplicateVisitor::ReplicateVisitor(SimInfo *info, Vector3i opt) : BaseVisitor() { - this->info = info; - visitorName = "ReplicateVisitor"; - this->replicateOpt = opt; + this->info = info; + visitorName = "ReplicateVisitor"; + this->replicateOpt = opt; - //generate the replicate directions - for( int i = 0; i <= replicateOpt[0]; i++ ) { + //generate the replicate directions + for( int i = 0; i <= replicateOpt[0]; i++ ) { for( int j = 0; j <= replicateOpt[1]; j++ ) { - for( int k = 0; k <= replicateOpt[2]; k++ ) { - //skip original frame - if (i == 0 && j == 0 && k == 0) { - continue; - } else { - dir.push_back(Vector3i(i, j, k)); - } - } + for( int k = 0; k <= replicateOpt[2]; k++ ) { + //skip original frame + if (i == 0 && j == 0 && k == 0) { + continue; + } else { + dir.push_back(Vector3i(i, j, k)); + } + } } - } + } -} + } -void ReplicateVisitor::visit(Atom *atom) { -internalVisit(atom); -} + void ReplicateVisitor::visit(Atom *atom) { + internalVisit(atom); + } -void ReplicateVisitor::visit(DirectionalAtom *datom) { -internalVisit(datom); -} + void ReplicateVisitor::visit(DirectionalAtom *datom) { + internalVisit(datom); + } -void ReplicateVisitor::visit(RigidBody *rb) { -internalVisit(rb); -} + void ReplicateVisitor::visit(RigidBody *rb) { + internalVisit(rb); + } -void ReplicateVisitor::internalVisit(StuntDouble *sd) { + void ReplicateVisitor::internalVisit(StuntDouble *sd) { GenericData * data; AtomData * atomData; @@ -226,13 +155,13 @@ void ReplicateVisitor::internalVisit(StuntDouble *sd) data = sd->getPropertyByName("ATOMDATA"); if (data != NULL) { - atomData = dynamic_cast(data); + atomData = dynamic_cast(data); - if (atomData == NULL) { - return; - } + if (atomData == NULL) { + return; + } } else { - return; + return; } Snapshot* currSnapshot = info->getSnapshotManager()->getCurrentSnapshot(); @@ -241,27 +170,27 @@ void ReplicateVisitor::internalVisit(StuntDouble *sd) std::vector atomInfoList = atomData->getData(); replicate(atomInfoList, atomData, box); -} + } -void ReplicateVisitor::replicate(std::vector&infoList, AtomData *data, const Mat3x3d& box) { + void ReplicateVisitor::replicate(std::vector&infoList, AtomData *data, const Mat3x3d& box) { AtomInfo* newAtomInfo; std::vector::iterator dirIter; std::vector::iterator i; for( dirIter = dir.begin(); dirIter != dir.end(); ++dirIter ) { - for( i = infoList.begin(); i != infoList.end(); i++ ) { - newAtomInfo = new AtomInfo(); - *newAtomInfo = *(*i); + for( i = infoList.begin(); i != infoList.end(); i++ ) { + newAtomInfo = new AtomInfo(); + *newAtomInfo = *(*i); - for( int j = 0; j < 3; j++ ) - newAtomInfo->pos[j] += (*dirIter)[0]*box(j, 0) + (*dirIter)[1]*box(j, 1) + (*dirIter)[2]*box(j, 2); + for( int j = 0; j < 3; j++ ) + newAtomInfo->pos[j] += (*dirIter)[0]*box(j, 0) + (*dirIter)[1]*box(j, 1) + (*dirIter)[2]*box(j, 2); - data->addAtomInfo(newAtomInfo); - } + data->addAtomInfo(newAtomInfo); + } } // end for(dirIter) -} + } -const std::string ReplicateVisitor::toString() { + const std::string ReplicateVisitor::toString() { char buffer[65535]; std::string result; std::set::iterator i; @@ -292,33 +221,59 @@ const std::string ReplicateVisitor::toString() { result += buffer; return result; -} + } -//----------------------------------------------------------------------------// + //----------------------------------------------------------------------------// -XYZVisitor::XYZVisitor(SimInfo *info, bool printDipole) : - BaseVisitor() { - this->info = info; - visitorName = "XYZVisitor"; - this->printDipole = printDipole; -} + XYZVisitor::XYZVisitor(SimInfo *info) : + BaseVisitor(), seleMan(info), evaluator(info){ + this->info = info; + visitorName = "XYZVisitor"; -void XYZVisitor::visit(Atom *atom) { + evaluator.loadScriptString("select all"); + + if (!evaluator.isDynamic()) { + seleMan.setSelectionSet(evaluator.evaluate()); + } + posOnly_ = false; + } + + XYZVisitor::XYZVisitor(SimInfo *info, const std::string& script) : + BaseVisitor(), seleMan(info), evaluator(info) { + this->info = info; + visitorName = "XYZVisitor"; + + evaluator.loadScriptString(script); + + if (!evaluator.isDynamic()) { + seleMan.setSelectionSet(evaluator.evaluate()); + } + posOnly_ = false; + } + + void XYZVisitor::visit(Atom *atom) { if (isSelected(atom)) - internalVisit(atom); -} + internalVisit(atom); + } -void XYZVisitor::visit(DirectionalAtom *datom) { + void XYZVisitor::visit(DirectionalAtom *datom) { if (isSelected(datom)) - internalVisit(datom); -} + internalVisit(datom); + } -void XYZVisitor::visit(RigidBody *rb) { + void XYZVisitor::visit(RigidBody *rb) { if (isSelected(rb)) - internalVisit(rb); -} + internalVisit(rb); + } -void XYZVisitor::internalVisit(StuntDouble *sd) { + void XYZVisitor::update() { + //if dynamic, we need to re-evaluate the selection + if (evaluator.isDynamic()) { + seleMan.setSelectionSet(evaluator.evaluate()); + } + } + + void XYZVisitor::internalVisit(StuntDouble *sd) { GenericData * data; AtomData * atomData; AtomInfo * atomInfo; @@ -329,43 +284,51 @@ void XYZVisitor::internalVisit(StuntDouble *sd) { data = sd->getPropertyByName("ATOMDATA"); if (data != NULL) { - atomData = dynamic_cast(data); + atomData = dynamic_cast(data); - if (atomData == NULL) - return; + if (atomData == NULL) + return; } else - return; + return; - for( atomInfo = atomData->beginAtomInfo(i); atomInfo; - atomInfo = atomData->nextAtomInfo(i) ) { - if (printDipole) - sprintf(buffer, - "%s%15.8f%15.8f%15.8f%15.8f%15.8f%15.8f", - atomInfo->AtomType.c_str(), - atomInfo->pos[0], - atomInfo->pos[1], - atomInfo->pos[2], - atomInfo->dipole[0], - atomInfo->dipole[1], - atomInfo->dipole[2]); else - sprintf(buffer, "%s%15.8f%15.8f%15.8f", - atomInfo->AtomType.c_str(), atomInfo->pos[0], - atomInfo->pos[1], atomInfo->pos[2]); - - frame.push_back(buffer); + if (posOnly_){ + for( atomInfo = atomData->beginAtomInfo(i); atomInfo; + atomInfo = atomData->nextAtomInfo(i) ) { + sprintf(buffer, + "%s%15.8f%15.8f%15.8f", + atomInfo->atomTypeName.c_str(), + atomInfo->pos[0], + atomInfo->pos[1], + atomInfo->pos[2]); + frame.push_back(buffer); + } + }else{ + for( atomInfo = atomData->beginAtomInfo(i); atomInfo; + atomInfo = atomData->nextAtomInfo(i) ) { + sprintf(buffer, + "%s%15.8f%15.8f%15.8f%15.8f%15.8f%15.8f", + atomInfo->atomTypeName.c_str(), + atomInfo->pos[0], + atomInfo->pos[1], + atomInfo->pos[2], + atomInfo->dipole[0], + atomInfo->dipole[1], + atomInfo->dipole[2]); + frame.push_back(buffer); + } } -} + } -bool XYZVisitor::isSelected(StuntDouble *sd) { - return info->getSelectionManager()->isSelected(sd); -} + bool XYZVisitor::isSelected(StuntDouble *sd) { + return seleMan.isSelected(sd); + } -void XYZVisitor::writeFrame(std::ostream &outStream) { + void XYZVisitor::writeFrame(std::ostream &outStream) { std::vector::iterator i; char buffer[1024]; if (frame.size() == 0) - std::cerr << "Current Frame does not contain any atoms" << std::endl; + std::cerr << "Current Frame does not contain any atoms" << std::endl; //total number of atoms outStream << frame.size() << std::endl; @@ -384,10 +347,10 @@ void XYZVisitor::writeFrame(std::ostream &outStream) { outStream << buffer << std::endl; for( i = frame.begin(); i != frame.end(); ++i ) - outStream << *i << std::endl; -} + outStream << *i << std::endl; + } -const std::string XYZVisitor::toString() { + const std::string XYZVisitor::toString() { char buffer[65535]; std::string result; @@ -407,11 +370,11 @@ const std::string XYZVisitor::toString() { result += buffer; return result; -} + } -//----------------------------------------------------------------------------// + //----------------------------------------------------------------------------// -void PrepareVisitor::internalVisit(Atom *atom) { + void PrepareVisitor::internalVisit(Atom *atom) { GenericData *data; AtomData * atomData; @@ -419,21 +382,21 @@ void PrepareVisitor::internalVisit(Atom *atom) { data = atom->getPropertyByName("VISITED"); if (data != NULL) { - atom->removeProperty("VISITED"); + atom->removeProperty("VISITED"); } //remove atomdata data = atom->getPropertyByName("ATOMDATA"); if (data != NULL) { - atomData = dynamic_cast(data); + atomData = dynamic_cast(data); - if (atomData != NULL) - atom->removeProperty("ATOMDATA"); + if (atomData != NULL) + atom->removeProperty("ATOMDATA"); } -} + } -void PrepareVisitor::internalVisit(RigidBody *rb) { + void PrepareVisitor::internalVisit(RigidBody *rb) { GenericData* data; AtomData* atomData; std::vector myAtoms; @@ -443,58 +406,58 @@ void PrepareVisitor::internalVisit(RigidBody *rb) { data = rb->getPropertyByName("VISITED"); if (data != NULL) { - rb->removeProperty("VISITED"); + rb->removeProperty("VISITED"); } //remove atomdata data = rb->getPropertyByName("ATOMDATA"); if (data != NULL) { - atomData = dynamic_cast(data); + atomData = dynamic_cast(data); - if (atomData != NULL) - rb->removeProperty("ATOMDATA"); + if (atomData != NULL) + rb->removeProperty("ATOMDATA"); } myAtoms = rb->getAtoms(); for( atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter ) - internalVisit(*atomIter); -} + internalVisit(*atomIter); + } -const std::string PrepareVisitor::toString() { - char buffer[65535]; - std::string result; + const std::string PrepareVisitor::toString() { + char buffer[65535]; + std::string result; - sprintf(buffer, - "------------------------------------------------------------------\n"); - result += buffer; + sprintf(buffer, + "------------------------------------------------------------------\n"); + result += buffer; - sprintf(buffer, "Visitor name: %s", visitorName.c_str()); - result += buffer; + sprintf(buffer, "Visitor name: %s", visitorName.c_str()); + result += buffer; - sprintf(buffer, - "Visitor Description: prepare for operation of other vistors\n"); - result += buffer; + sprintf(buffer, + "Visitor Description: prepare for operation of other vistors\n"); + result += buffer; - sprintf(buffer, - "------------------------------------------------------------------\n"); - result += buffer; + sprintf(buffer, + "------------------------------------------------------------------\n"); + result += buffer; - return result; -} + return result; + } -//----------------------------------------------------------------------------// + //----------------------------------------------------------------------------// -WaterTypeVisitor::WaterTypeVisitor() { + WaterTypeVisitor::WaterTypeVisitor() { visitorName = "WaterTypeVisitor"; waterTypeList.insert("TIP3P_RB_0"); waterTypeList.insert("TIP4P_RB_0"); waterTypeList.insert("TIP5P_RB_0"); waterTypeList.insert("SPCE_RB_0"); -} + } -void WaterTypeVisitor::visit(RigidBody *rb) { + void WaterTypeVisitor::visit(RigidBody *rb) { std::string rbName; std::vector myAtoms; std::vector::iterator atomIter; @@ -506,33 +469,33 @@ void WaterTypeVisitor::visit(RigidBody *rb) { rbName = rb->getType(); if (waterTypeList.find(rbName) != waterTypeList.end()) { - myAtoms = rb->getAtoms(); + myAtoms = rb->getAtoms(); - for( atomIter = myAtoms.begin(); atomIter != myAtoms.end(); - ++atomIter ) { - data = (*atomIter)->getPropertyByName("ATOMDATA"); + for( atomIter = myAtoms.begin(); atomIter != myAtoms.end(); + ++atomIter ) { + data = (*atomIter)->getPropertyByName("ATOMDATA"); - if (data != NULL) { - atomData = dynamic_cast(data); + if (data != NULL) { + atomData = dynamic_cast(data); - if (atomData == NULL) - continue; - } else - continue; + if (atomData == NULL) + continue; + } else + continue; - for( atomInfo = atomData->beginAtomInfo(i); atomInfo; - atomInfo = atomData->nextAtomInfo(i) ) { - replaceType(atomInfo->AtomType); - } //end for(atomInfo) - } //end for(atomIter) + for( atomInfo = atomData->beginAtomInfo(i); atomInfo; + atomInfo = atomData->nextAtomInfo(i) ) { + atomInfo->atomTypeName = trimmedName(atomInfo->atomTypeName); + } //end for(atomInfo) + } //end for(atomIter) } //end if (waterTypeList.find(rbName) != waterTypeList.end()) -} + } -void WaterTypeVisitor::replaceType(std::string&atomType) { -atomType = atomType.substr(0, atomType.find('_')); -} + std::string WaterTypeVisitor::trimmedName(const std::string&atomTypeName) { + return atomTypeName.substr(0, atomTypeName.find('_')); + } -const std::string WaterTypeVisitor::toString() { + const std::string WaterTypeVisitor::toString() { char buffer[65535]; std::string result; @@ -552,6 +515,6 @@ const std::string WaterTypeVisitor::toString() { result += buffer; return result; -} + } } //namespace oopse