| 1 | /*
 | 
|---|
| 2 |  * ConvexEnvelopeAction.cpp
 | 
|---|
| 3 |  *
 | 
|---|
| 4 |  *  Created on: May 12, 2010
 | 
|---|
| 5 |  *      Author: heber
 | 
|---|
| 6 |  */
 | 
|---|
| 7 | 
 | 
|---|
| 8 | #include "Helpers/MemDebug.hpp"
 | 
|---|
| 9 | 
 | 
|---|
| 10 | #include "Actions/TesselationAction/ConvexEnvelopeAction.hpp"
 | 
|---|
| 11 | #include "Actions/ActionRegistry.hpp"
 | 
|---|
| 12 | #include "boundary.hpp"
 | 
|---|
| 13 | #include "config.hpp"
 | 
|---|
| 14 | #include "linkedcell.hpp"
 | 
|---|
| 15 | #include "Helpers/Log.hpp"
 | 
|---|
| 16 | #include "molecule.hpp"
 | 
|---|
| 17 | #include "tesselation.hpp"
 | 
|---|
| 18 | #include "Helpers/Verbose.hpp"
 | 
|---|
| 19 | #include "World.hpp"
 | 
|---|
| 20 | 
 | 
|---|
| 21 | #include <iostream>
 | 
|---|
| 22 | #include <string>
 | 
|---|
| 23 | 
 | 
|---|
| 24 | using namespace std;
 | 
|---|
| 25 | 
 | 
|---|
| 26 | #include "UIElements/UIFactory.hpp"
 | 
|---|
| 27 | #include "UIElements/Dialog.hpp"
 | 
|---|
| 28 | #include "Actions/ValueStorage.hpp"
 | 
|---|
| 29 | 
 | 
|---|
| 30 | /****** TesselationConvexEnvelopeAction *****/
 | 
|---|
| 31 | 
 | 
|---|
| 32 | // memento to remember the state when undoing
 | 
|---|
| 33 | 
 | 
|---|
| 34 | //class TesselationConvexEnvelopeState : public ActionState {
 | 
|---|
| 35 | //public:
 | 
|---|
| 36 | //  TesselationConvexEnvelopeState(molecule* _mol,std::string _lastName) :
 | 
|---|
| 37 | //    mol(_mol),
 | 
|---|
| 38 | //    lastName(_lastName)
 | 
|---|
| 39 | //  {}
 | 
|---|
| 40 | //  molecule* mol;
 | 
|---|
| 41 | //  std::string lastName;
 | 
|---|
| 42 | //};
 | 
|---|
| 43 | 
 | 
|---|
| 44 | const char TesselationConvexEnvelopeAction::NAME[] = "convex-envelope";
 | 
|---|
| 45 | 
 | 
|---|
| 46 | TesselationConvexEnvelopeAction::TesselationConvexEnvelopeAction() :
 | 
|---|
| 47 |   Action(NAME)
 | 
|---|
| 48 | {}
 | 
|---|
| 49 | 
 | 
|---|
| 50 | TesselationConvexEnvelopeAction::~TesselationConvexEnvelopeAction()
 | 
|---|
| 51 | {}
 | 
|---|
| 52 | 
 | 
|---|
| 53 | void TesselationConvexEnvelope(std::string &filenameConvex, std::string &filenameNonConvex) {
 | 
|---|
| 54 |   ValueStorage::getInstance().setCurrentValue("convex-file", filenameConvex);
 | 
|---|
| 55 |   ValueStorage::getInstance().setCurrentValue("nonconvex-file", filenameConvex);
 | 
|---|
| 56 |   ActionRegistry::getInstance().getActionByName(TesselationConvexEnvelopeAction::NAME)->call(Action::NonInteractive);
 | 
|---|
| 57 | };
 | 
|---|
| 58 | 
 | 
|---|
| 59 | Dialog* TesselationConvexEnvelopeAction::fillDialog(Dialog *dialog) {
 | 
|---|
| 60 |   ASSERT(dialog,"No Dialog given when filling action dialog");
 | 
|---|
| 61 | 
 | 
|---|
| 62 |   dialog->queryEmpty(NAME, ValueStorage::getInstance().getDescription(NAME));
 | 
|---|
| 63 |   dialog->queryString("convex-file", ValueStorage::getInstance().getDescription("convex-file"));
 | 
|---|
| 64 |   dialog->queryString("nonconvex-file", ValueStorage::getInstance().getDescription("nonconvex-file"));
 | 
|---|
| 65 | 
 | 
|---|
| 66 |   return dialog;
 | 
|---|
| 67 | }
 | 
|---|
| 68 | 
 | 
|---|
| 69 | Action::state_ptr TesselationConvexEnvelopeAction::performCall() {
 | 
|---|
| 70 |   string filenameConvex;
 | 
|---|
| 71 |   string filenameNonConvex;
 | 
|---|
| 72 |   molecule * mol = NULL;
 | 
|---|
| 73 |   bool Success = true;
 | 
|---|
| 74 |   config *configuration = World::getInstance().getConfig();
 | 
|---|
| 75 | 
 | 
|---|
| 76 |   ValueStorage::getInstance().queryCurrentValue("convex-file", filenameConvex);
 | 
|---|
| 77 |   ValueStorage::getInstance().queryCurrentValue("nonconvex-file", filenameNonConvex);
 | 
|---|
| 78 | 
 | 
|---|
| 79 |   for (World::MoleculeSelectionIterator iter = World::getInstance().beginMoleculeSelection(); iter != World::getInstance().endMoleculeSelection(); ++iter) {
 | 
|---|
| 80 |     mol = iter->second;
 | 
|---|
| 81 |     class Tesselation *TesselStruct = NULL;
 | 
|---|
| 82 |     const LinkedCell *LCList = NULL;
 | 
|---|
| 83 |     DoLog(0) && (Log() << Verbose(0) << "Evaluating volume of the convex envelope.");
 | 
|---|
| 84 |     DoLog(1) && (Log() << Verbose(1) << "Storing tecplot convex data in " << filenameConvex << "." << endl);
 | 
|---|
| 85 |     DoLog(1) && (Log() << Verbose(1) << "Storing tecplot non-convex data in " << filenameNonConvex << "." << endl);
 | 
|---|
| 86 |     LCList = new LinkedCell(mol, 100.);
 | 
|---|
| 87 |     //Boundaries *BoundaryPoints = NULL;
 | 
|---|
| 88 |     //FindConvexBorder(mol, BoundaryPoints, TesselStruct, LCList, argv[argptr]);
 | 
|---|
| 89 |     // TODO: Beide Funktionen sollten streams anstelle des Filenamen benutzen, besser fuer unit tests
 | 
|---|
| 90 |     FindNonConvexBorder(mol, TesselStruct, LCList, 50., filenameNonConvex.c_str());
 | 
|---|
| 91 |     //RemoveAllBoundaryPoints(TesselStruct, mol, argv[argptr]);
 | 
|---|
| 92 |     const double volumedifference = ConvexizeNonconvexEnvelope(TesselStruct, mol, filenameConvex.c_str());
 | 
|---|
| 93 |     const double clustervolume = VolumeOfConvexEnvelope(TesselStruct, configuration);
 | 
|---|
| 94 |     DoLog(0) && (Log() << Verbose(0) << "The tesselated volume area is " << clustervolume << " " << (configuration->GetIsAngstroem() ? "angstrom" : "atomiclength") << "^3." << endl);
 | 
|---|
| 95 |     DoLog(0) && (Log() << Verbose(0) << "The non-convex tesselated volume area is " << clustervolume-volumedifference << " " << (configuration->GetIsAngstroem() ? "angstrom" : "atomiclength") << "^3." << endl);
 | 
|---|
| 96 |     delete(TesselStruct);
 | 
|---|
| 97 |     delete(LCList);
 | 
|---|
| 98 |   }
 | 
|---|
| 99 |   if (Success)
 | 
|---|
| 100 |     return Action::success;
 | 
|---|
| 101 |   else
 | 
|---|
| 102 |     return Action::failure;
 | 
|---|
| 103 | }
 | 
|---|
| 104 | 
 | 
|---|
| 105 | Action::state_ptr TesselationConvexEnvelopeAction::performUndo(Action::state_ptr _state) {
 | 
|---|
| 106 | //  TesselationConvexEnvelopeState *state = assert_cast<TesselationConvexEnvelopeState*>(_state.get());
 | 
|---|
| 107 | 
 | 
|---|
| 108 | //  string newName = state->mol->getName();
 | 
|---|
| 109 | //  state->mol->setName(state->lastName);
 | 
|---|
| 110 | 
 | 
|---|
| 111 |   return Action::failure;
 | 
|---|
| 112 | }
 | 
|---|
| 113 | 
 | 
|---|
| 114 | Action::state_ptr TesselationConvexEnvelopeAction::performRedo(Action::state_ptr _state){
 | 
|---|
| 115 |   // Undo and redo have to do the same for this action
 | 
|---|
| 116 |   return performUndo(_state);
 | 
|---|
| 117 | }
 | 
|---|
| 118 | 
 | 
|---|
| 119 | bool TesselationConvexEnvelopeAction::canUndo() {
 | 
|---|
| 120 |   return false;
 | 
|---|
| 121 | }
 | 
|---|
| 122 | 
 | 
|---|
| 123 | bool TesselationConvexEnvelopeAction::shouldUndo() {
 | 
|---|
| 124 |   return false;
 | 
|---|
| 125 | }
 | 
|---|
| 126 | 
 | 
|---|
| 127 | const string TesselationConvexEnvelopeAction::getName() {
 | 
|---|
| 128 |   return NAME;
 | 
|---|
| 129 | }
 | 
|---|