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