ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-2.0/src/visitors/OtherVisitor.cpp
(Generate patch)

Comparing trunk/OOPSE-2.0/src/visitors/OtherVisitor.cpp (file contents):
Revision 1977 by tim, Fri Feb 4 22:45:48 2005 UTC vs.
Revision 2204 by gezelter, Fri Apr 15 22:04:00 2005 UTC

# Line 1 | Line 1
1 < /*
1 > /*
2   * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3   *
4   * The University of Notre Dame grants you ("Licensee") a
# Line 38 | Line 38
38   * University of Notre Dame has been advised of the possibility of
39   * such damages.
40   */
41 <
41 > #include "selection/SelectionManager.hpp"
42   #include "visitors/OtherVisitor.hpp"
43   #include "primitives/DirectionalAtom.hpp"
44   #include "primitives/RigidBody.hpp"
# Line 46 | Line 46 | namespace oopse {
46   #include "brains/SimInfo.hpp"
47   namespace oopse {
48  
49 < //----------------------------------------------------------------------------//
50 < void IgnoreVisitor::visit(Atom *atom) {
51 <    if (isIgnoreType(atom->getType()))
52 <        internalVisit(atom);
53 < }
49 >  void WrappingVisitor::visit(Atom *atom) {
50 >    internalVisit(atom);
51 >  }
52  
53 < void IgnoreVisitor::visit(DirectionalAtom *datom) {
54 <    if (isIgnoreType(datom->getType()))
55 <        internalVisit(datom);
58 < }
53 >  void WrappingVisitor::visit(DirectionalAtom *datom) {
54 >    internalVisit(datom);
55 >  }
56  
57 < void IgnoreVisitor::visit(RigidBody *rb) {
58 <    std::vector<Atom *>           myAtoms;
59 <    std::vector<Atom *>::iterator atomIter;
63 <    AtomInfo *                    atomInfo;
57 >  void WrappingVisitor::visit(RigidBody *rb) {
58 >    internalVisit(rb);
59 >  }
60  
61 <    if (isIgnoreType(rb->getType())) {
66 <        internalVisit(rb);
67 <
68 <        myAtoms = rb->getAtoms();
69 <
70 <        for( atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter )
71 <            internalVisit(*atomIter);
72 <    }
73 < }
74 <
75 < bool IgnoreVisitor::isIgnoreType(const std::string&name) {
76 < return itList.find(name) != itList.end() ? true : false;
77 < }
78 <
79 < void IgnoreVisitor::internalVisit(StuntDouble *sd) {
80 <    info->getSelectionManager()->clearSelection(sd);
81 <    //GenericData *data;
82 <    //data = sd->getPropertyByName("IGNORE");
83 <    //
84 <    ////if this stuntdoulbe is already marked as ignore just skip it
85 <    //if (data == NULL) {
86 <    //    data = new GenericData;
87 <    //    data->setID("IGNORE");
88 <    //    sd->addProperty(data);
89 <    //}
90 < }
91 <
92 < const std::string IgnoreVisitor::toString() {
93 <    char                            buffer[65535];
94 <    std::string                     result;
95 <    std::set<std::string>::iterator i;
96 <
97 <    sprintf(buffer,
98 <            "------------------------------------------------------------------\n");
99 <    result += buffer;
100 <
101 <    sprintf(buffer, "Visitor name: %s\n", visitorName.c_str());
102 <    result += buffer;
103 <
104 <    sprintf(buffer, "Visitor Description: ignore  stuntdoubles\n");
105 <    result += buffer;
106 <
107 <    //print the ignore type list
108 <    sprintf(buffer, "Ignore type list contains below types:\n");
109 <    result += buffer;
110 <
111 <    for( i = itList.begin(); i != itList.end(); ++i ) {
112 <        sprintf(buffer, "%s\t", i->c_str());
113 <        result += buffer;
114 <    }
115 <
116 <    sprintf(buffer, "\n");
117 <    result += buffer;
118 <
119 <    sprintf(buffer,
120 <            "------------------------------------------------------------------\n");
121 <    result += buffer;
122 <
123 <    return result;
124 < }
125 <
126 < //----------------------------------------------------------------------------//
127 <
128 < void WrappingVisitor::visit(Atom *atom) {
129 < internalVisit(atom);
130 < }
131 <
132 < void WrappingVisitor::visit(DirectionalAtom *datom) {
133 < internalVisit(datom);
134 < }
135 <
136 < void WrappingVisitor::visit(RigidBody *rb) {
137 < internalVisit(rb);
138 < }
139 <
140 < void WrappingVisitor::internalVisit(StuntDouble *sd) {
61 >  void WrappingVisitor::internalVisit(StuntDouble *sd) {
62      GenericData *                     data;
63      AtomData *                        atomData;
64      AtomInfo *                        atomInfo;
# Line 146 | Line 67 | void WrappingVisitor::internalVisit(StuntDouble *sd) {
67      data = sd->getPropertyByName("ATOMDATA");
68  
69      if (data != NULL) {
70 <        atomData = dynamic_cast<AtomData *>(data);
70 >      atomData = dynamic_cast<AtomData *>(data);
71  
72 <        if (atomData == NULL)
73 <            return;
72 >      if (atomData == NULL)
73 >        return;
74      } else
75 <        return;
75 >      return;
76  
77      Snapshot* currSnapshot = info->getSnapshotManager()->getCurrentSnapshot();
78      
79      for( atomInfo = atomData->beginAtomInfo(i); atomInfo; atomInfo = atomData->nextAtomInfo(i) ) {
80 <        currSnapshot->wrapVector(atomInfo->pos);
80 >      currSnapshot->wrapVector(atomInfo->pos);
81      }
82 < }
82 >  }
83  
84 < const std::string WrappingVisitor::toString() {
84 >  const std::string WrappingVisitor::toString() {
85      char        buffer[65535];
86      std::string result;
87  
# Line 180 | Line 101 | const std::string WrappingVisitor::toString() {
101      result += buffer;
102  
103      return result;
104 < }
104 >  }
105  
106 < //----------------------------------------------------------------------------//
106 >  //----------------------------------------------------------------------------//
107  
108 < ReplicateVisitor::ReplicateVisitor(SimInfo *info, Vector3i opt) :
108 >  ReplicateVisitor::ReplicateVisitor(SimInfo *info, Vector3i opt) :
109      BaseVisitor() {
110 <    this->info = info;
111 <    visitorName = "ReplicateVisitor";
112 <    this->replicateOpt = opt;
110 >      this->info = info;
111 >      visitorName = "ReplicateVisitor";
112 >      this->replicateOpt = opt;
113  
114 <    //generate the replicate directions
115 <    for( int i = 0; i <= replicateOpt[0]; i++ ) {
114 >      //generate the replicate directions
115 >      for( int i = 0; i <= replicateOpt[0]; i++ ) {
116          for( int j = 0; j <= replicateOpt[1]; j++ ) {
117 <            for( int k = 0; k <= replicateOpt[2]; k++ ) {
118 <                //skip original frame
119 <                if (i == 0 && j == 0 && k == 0) {
120 <                    continue;
121 <                } else {
122 <                    dir.push_back(Vector3i(i, j, k));
123 <                }
124 <            }
117 >          for( int k = 0; k <= replicateOpt[2]; k++ ) {
118 >            //skip original frame
119 >            if (i == 0 && j == 0 && k == 0) {
120 >              continue;
121 >            } else {
122 >              dir.push_back(Vector3i(i, j, k));
123 >            }
124 >          }
125          }
126 <    }
126 >      }
127      
128 < }
128 >    }
129  
130 < void ReplicateVisitor::visit(Atom *atom) {
131 < internalVisit(atom);
132 < }
130 >  void ReplicateVisitor::visit(Atom *atom) {
131 >    internalVisit(atom);
132 >  }
133  
134 < void ReplicateVisitor::visit(DirectionalAtom *datom) {
135 < internalVisit(datom);
136 < }
134 >  void ReplicateVisitor::visit(DirectionalAtom *datom) {
135 >    internalVisit(datom);
136 >  }
137  
138 < void ReplicateVisitor::visit(RigidBody *rb) {
139 < internalVisit(rb);
140 < }
138 >  void ReplicateVisitor::visit(RigidBody *rb) {
139 >    internalVisit(rb);
140 >  }
141  
142 < void ReplicateVisitor::internalVisit(StuntDouble *sd) {
142 >  void ReplicateVisitor::internalVisit(StuntDouble *sd) {
143      GenericData *          data;
144      AtomData *             atomData;
145  
# Line 226 | Line 147 | void ReplicateVisitor::internalVisit(StuntDouble *sd)
147      data = sd->getPropertyByName("ATOMDATA");
148  
149      if (data != NULL) {
150 <        atomData = dynamic_cast<AtomData *>(data);
150 >      atomData = dynamic_cast<AtomData *>(data);
151  
152 <        if (atomData == NULL) {
153 <            return;
154 <        }
152 >      if (atomData == NULL) {
153 >        return;
154 >      }
155      } else {
156 <        return;
156 >      return;
157      }
158  
159      Snapshot* currSnapshot = info->getSnapshotManager()->getCurrentSnapshot();
# Line 241 | Line 162 | void ReplicateVisitor::internalVisit(StuntDouble *sd)
162      std::vector<AtomInfo *> atomInfoList = atomData->getData();
163  
164      replicate(atomInfoList, atomData, box);
165 < }
165 >  }
166  
167 < void ReplicateVisitor::replicate(std::vector<AtomInfo *>&infoList, AtomData *data, const Mat3x3d& box) {
167 >  void ReplicateVisitor::replicate(std::vector<AtomInfo *>&infoList, AtomData *data, const Mat3x3d& box) {
168      AtomInfo* newAtomInfo;
169      std::vector<Vector3i>::iterator dirIter;
170      std::vector<AtomInfo *>::iterator i;
171  
172      for( dirIter = dir.begin(); dirIter != dir.end(); ++dirIter ) {
173 <        for( i = infoList.begin(); i != infoList.end(); i++ ) {
174 <            newAtomInfo = new AtomInfo();
175 <            *newAtomInfo = *(*i);
173 >      for( i = infoList.begin(); i != infoList.end(); i++ ) {
174 >        newAtomInfo = new AtomInfo();
175 >        *newAtomInfo = *(*i);
176  
177 <            for( int j = 0; j < 3; j++ )
178 <                newAtomInfo->pos[j] += (*dirIter)[0]*box(j, 0) + (*dirIter)[1]*box(j, 1) + (*dirIter)[2]*box(j, 2);
177 >        for( int j = 0; j < 3; j++ )
178 >          newAtomInfo->pos[j] += (*dirIter)[0]*box(j, 0) + (*dirIter)[1]*box(j, 1) + (*dirIter)[2]*box(j, 2);
179  
180 <            data->addAtomInfo(newAtomInfo);
181 <        }
180 >        data->addAtomInfo(newAtomInfo);
181 >      }
182      } // end for(dirIter)  
183 < }
183 >  }
184  
185 < const std::string ReplicateVisitor::toString() {
185 >  const std::string ReplicateVisitor::toString() {
186      char                            buffer[65535];
187      std::string                     result;
188      std::set<std::string>::iterator i;
# Line 292 | Line 213 | const std::string ReplicateVisitor::toString() {
213      result += buffer;
214  
215      return result;
216 < }
216 >  }
217  
218 < //----------------------------------------------------------------------------//
218 >  //----------------------------------------------------------------------------//
219  
220 < XYZVisitor::XYZVisitor(SimInfo *info, bool printDipole) :
221 <    BaseVisitor() {
222 <    this->info = info;
223 <    visitorName = "XYZVisitor";
303 <    this->printDipole = printDipole;
304 < }
220 >  XYZVisitor::XYZVisitor(SimInfo *info) :
221 >    BaseVisitor(), seleMan(info), evaluator(info){
222 >      this->info = info;
223 >      visitorName = "XYZVisitor";
224  
225 < void XYZVisitor::visit(Atom *atom) {
307 <    if (isSelected(atom))
308 <        internalVisit(atom);
309 < }
225 >      evaluator.loadScriptString("select all");
226  
227 < void XYZVisitor::visit(DirectionalAtom *datom) {
228 <    if (isSelected(datom))
229 <        internalVisit(datom);
314 < }
227 >      if (!evaluator.isDynamic()) {
228 >        seleMan.setSelectionSet(evaluator.evaluate());
229 >      }
230  
231 < void XYZVisitor::visit(RigidBody *rb) {
317 <    if (isSelected(rb))
318 <        internalVisit(rb);
319 < }
231 >    }
232  
233 < void XYZVisitor::internalVisit(StuntDouble *sd) {
233 >  XYZVisitor::XYZVisitor(SimInfo *info, const std::string& script) :
234 >    BaseVisitor(), seleMan(info), evaluator(info) {
235 >      this->info = info;
236 >      visitorName = "XYZVisitor";
237 >
238 >      evaluator.loadScriptString(script);
239 >
240 >      if (!evaluator.isDynamic()) {
241 >        seleMan.setSelectionSet(evaluator.evaluate());
242 >      }
243 >          
244 >    }
245 >    
246 >  void XYZVisitor::visit(Atom *atom) {
247 >    if (isSelected(atom))
248 >      internalVisit(atom);
249 >  }
250 >
251 >  void XYZVisitor::visit(DirectionalAtom *datom) {
252 >    if (isSelected(datom))
253 >      internalVisit(datom);
254 >  }
255 >
256 >  void XYZVisitor::visit(RigidBody *rb) {
257 >    if (isSelected(rb))
258 >      internalVisit(rb);
259 >  }
260 >
261 >  void XYZVisitor::update() {
262 >    //if dynamic, we need to re-evaluate the selection
263 >    if (evaluator.isDynamic()) {
264 >      seleMan.setSelectionSet(evaluator.evaluate());
265 >    }
266 >  }
267 >
268 >  void XYZVisitor::internalVisit(StuntDouble *sd) {
269      GenericData *                     data;
270      AtomData *                        atomData;
271      AtomInfo *                        atomInfo;
# Line 329 | Line 276 | void XYZVisitor::internalVisit(StuntDouble *sd) {
276      data = sd->getPropertyByName("ATOMDATA");
277  
278      if (data != NULL) {
279 <        atomData = dynamic_cast<AtomData *>(data);
279 >      atomData = dynamic_cast<AtomData *>(data);
280  
281 <        if (atomData == NULL)
282 <            return;
281 >      if (atomData == NULL)
282 >        return;
283      } else
284 <        return;
284 >      return;
285  
286      for( atomInfo = atomData->beginAtomInfo(i); atomInfo;
287 <        atomInfo = atomData->nextAtomInfo(i) ) {
288 <        if (printDipole)
289 <            sprintf(buffer,
290 <                    "%s%15.8f%15.8f%15.8f%15.8f%15.8f%15.8f",
291 <                    atomInfo->AtomType.c_str(),
292 <                    atomInfo->pos[0],
293 <                    atomInfo->pos[1],
294 <                    atomInfo->pos[2],
295 <                    atomInfo->dipole[0],
296 <                    atomInfo->dipole[1],
297 <                    atomInfo->dipole[2]); else
351 <            sprintf(buffer,                     "%s%15.8f%15.8f%15.8f",
352 <                    atomInfo->AtomType.c_str(), atomInfo->pos[0],
353 <                    atomInfo->pos[1],           atomInfo->pos[2]);
354 <
355 <        frame.push_back(buffer);
287 >         atomInfo = atomData->nextAtomInfo(i) ) {
288 >      sprintf(buffer,
289 >              "%s%15.8f%15.8f%15.8f%15.8f%15.8f%15.8f",
290 >              atomInfo->atomTypeName.c_str(),
291 >              atomInfo->pos[0],
292 >              atomInfo->pos[1],
293 >              atomInfo->pos[2],
294 >              atomInfo->dipole[0],
295 >              atomInfo->dipole[1],
296 >              atomInfo->dipole[2]);
297 >      frame.push_back(buffer);
298      }
299 < }
299 >  }
300  
301 < bool XYZVisitor::isSelected(StuntDouble *sd) {
302 <    return info->getSelectionManager()->isSelected(sd);
303 < }
301 >  bool XYZVisitor::isSelected(StuntDouble *sd) {
302 >    return seleMan.isSelected(sd);
303 >  }
304  
305 < void XYZVisitor::writeFrame(std::ostream &outStream) {
305 >  void XYZVisitor::writeFrame(std::ostream &outStream) {
306      std::vector<std::string>::iterator i;
307      char buffer[1024];
308  
309      if (frame.size() == 0)
310 <        std::cerr << "Current Frame does not contain any atoms" << std::endl;
310 >      std::cerr << "Current Frame does not contain any atoms" << std::endl;
311  
312      //total number of atoms  
313      outStream << frame.size() << std::endl;
# Line 384 | Line 326 | void XYZVisitor::writeFrame(std::ostream &outStream) {
326      outStream << buffer << std::endl;
327  
328      for( i = frame.begin(); i != frame.end(); ++i )
329 <        outStream << *i << std::endl;
330 < }
329 >      outStream << *i << std::endl;
330 >  }
331  
332 < const std::string XYZVisitor::toString() {
332 >  const std::string XYZVisitor::toString() {
333      char        buffer[65535];
334      std::string result;
335  
# Line 407 | Line 349 | const std::string XYZVisitor::toString() {
349      result += buffer;
350  
351      return result;
352 < }
352 >  }
353  
354 < //----------------------------------------------------------------------------//
354 >  //----------------------------------------------------------------------------//
355  
356 < void PrepareVisitor::internalVisit(Atom *atom) {
356 >  void PrepareVisitor::internalVisit(Atom *atom) {
357      GenericData *data;
358      AtomData *   atomData;
359  
# Line 419 | Line 361 | void PrepareVisitor::internalVisit(Atom *atom) {
361      data = atom->getPropertyByName("VISITED");
362  
363      if (data != NULL) {
364 <    atom->removeProperty("VISITED");
364 >      atom->removeProperty("VISITED");
365      }
366  
367      //remove atomdata
368      data = atom->getPropertyByName("ATOMDATA");
369  
370      if (data != NULL) {
371 <        atomData = dynamic_cast<AtomData *>(data);
371 >      atomData = dynamic_cast<AtomData *>(data);
372  
373 <        if (atomData != NULL)
374 <            atom->removeProperty("ATOMDATA");
373 >      if (atomData != NULL)
374 >        atom->removeProperty("ATOMDATA");
375      }
376 < }
376 >  }
377  
378 < void PrepareVisitor::internalVisit(RigidBody *rb) {
378 >  void PrepareVisitor::internalVisit(RigidBody *rb) {
379      GenericData* data;
380      AtomData* atomData;
381      std::vector<Atom *> myAtoms;
# Line 443 | Line 385 | void PrepareVisitor::internalVisit(RigidBody *rb) {
385      data = rb->getPropertyByName("VISITED");
386  
387      if (data != NULL) {
388 <    rb->removeProperty("VISITED");
388 >      rb->removeProperty("VISITED");
389      }
390  
391      //remove atomdata
392      data = rb->getPropertyByName("ATOMDATA");
393  
394      if (data != NULL) {
395 <        atomData = dynamic_cast<AtomData *>(data);
395 >      atomData = dynamic_cast<AtomData *>(data);
396  
397 <        if (atomData != NULL)
398 <            rb->removeProperty("ATOMDATA");
397 >      if (atomData != NULL)
398 >        rb->removeProperty("ATOMDATA");
399      }
400  
401      myAtoms = rb->getAtoms();
402  
403      for( atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter )
404 <        internalVisit(*atomIter);
405 < }
404 >      internalVisit(*atomIter);
405 >  }
406  
407 < const std::string PrepareVisitor::toString() {
408 <     char buffer[65535];
409 <     std::string result;
407 >  const std::string PrepareVisitor::toString() {
408 >    char buffer[65535];
409 >    std::string result;
410  
411 <     sprintf(buffer,
412 <             "------------------------------------------------------------------\n");
413 <     result += buffer;
411 >    sprintf(buffer,
412 >            "------------------------------------------------------------------\n");
413 >    result += buffer;
414  
415 <     sprintf(buffer, "Visitor name: %s", visitorName.c_str());
416 <     result += buffer;
415 >    sprintf(buffer, "Visitor name: %s", visitorName.c_str());
416 >    result += buffer;
417  
418 <     sprintf(buffer,
419 <             "Visitor Description: prepare for operation of other vistors\n");
420 <     result += buffer;
418 >    sprintf(buffer,
419 >            "Visitor Description: prepare for operation of other vistors\n");
420 >    result += buffer;
421  
422 <     sprintf(buffer,
423 <             "------------------------------------------------------------------\n");
424 <     result += buffer;
422 >    sprintf(buffer,
423 >            "------------------------------------------------------------------\n");
424 >    result += buffer;
425  
426 <     return result;
427 < }
426 >    return result;
427 >  }
428  
429 < //----------------------------------------------------------------------------//
429 >  //----------------------------------------------------------------------------//
430  
431 < WaterTypeVisitor::WaterTypeVisitor() {
431 >  WaterTypeVisitor::WaterTypeVisitor() {
432      visitorName = "WaterTypeVisitor";
433      waterTypeList.insert("TIP3P_RB_0");
434      waterTypeList.insert("TIP4P_RB_0");
435      waterTypeList.insert("TIP5P_RB_0");
436      waterTypeList.insert("SPCE_RB_0");
437 < }
437 >  }
438  
439 < void WaterTypeVisitor::visit(RigidBody *rb) {
439 >  void WaterTypeVisitor::visit(RigidBody *rb) {
440      std::string rbName;
441      std::vector<Atom *> myAtoms;
442      std::vector<Atom *>::iterator atomIter;
# Line 506 | Line 448 | void WaterTypeVisitor::visit(RigidBody *rb) {
448      rbName = rb->getType();
449  
450      if (waterTypeList.find(rbName) != waterTypeList.end()) {
451 <        myAtoms = rb->getAtoms();
451 >      myAtoms = rb->getAtoms();
452  
453 <        for( atomIter = myAtoms.begin(); atomIter != myAtoms.end();
454 <            ++atomIter ) {
455 <            data = (*atomIter)->getPropertyByName("ATOMDATA");
453 >      for( atomIter = myAtoms.begin(); atomIter != myAtoms.end();
454 >           ++atomIter ) {
455 >        data = (*atomIter)->getPropertyByName("ATOMDATA");
456  
457 <            if (data != NULL) {
458 <                atomData = dynamic_cast<AtomData *>(data);
457 >        if (data != NULL) {
458 >          atomData = dynamic_cast<AtomData *>(data);
459  
460 <                if (atomData == NULL)
461 <                    continue;
462 <            } else
463 <                continue;
460 >          if (atomData == NULL)
461 >            continue;
462 >        } else
463 >          continue;
464  
465 <            for( atomInfo = atomData->beginAtomInfo(i); atomInfo;
466 <                atomInfo = atomData->nextAtomInfo(i) ) {
467 <            replaceType(atomInfo->AtomType);
468 <            } //end for(atomInfo)
469 <        }     //end for(atomIter)
465 >        for( atomInfo = atomData->beginAtomInfo(i); atomInfo;
466 >             atomInfo = atomData->nextAtomInfo(i) ) {
467 >          atomInfo->atomTypeName = trimmedName(atomInfo->atomTypeName);
468 >        } //end for(atomInfo)
469 >      }     //end for(atomIter)
470      }         //end if (waterTypeList.find(rbName) != waterTypeList.end())
471 < }
471 >  }
472  
473 < void WaterTypeVisitor::replaceType(std::string&atomType) {
474 < atomType = atomType.substr(0, atomType.find('_'));
475 < }
473 >  std::string WaterTypeVisitor::trimmedName(const std::string&atomTypeName) {
474 >    return atomTypeName.substr(0, atomTypeName.find('_'));
475 >  }
476  
477 < const std::string WaterTypeVisitor::toString() {
477 >  const std::string WaterTypeVisitor::toString() {
478      char buffer[65535];
479      std::string result;
480  
# Line 552 | Line 494 | const std::string WaterTypeVisitor::toString() {
494      result += buffer;
495  
496      return result;
497 < }
497 >  }
498  
499   } //namespace oopse

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines