[97ebf8] | 1 | /*
|
---|
| 2 | * ConvexEnvelopeAction.cpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: May 12, 2010
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
[112b09] | 8 | #include "Helpers/MemDebug.hpp"
|
---|
| 9 |
|
---|
[97ebf8] | 10 | #include "Actions/TesselationAction/ConvexEnvelopeAction.hpp"
|
---|
[0430e3] | 11 | #include "Actions/ActionRegistry.hpp"
|
---|
[628b52] | 12 | #include "boundary.hpp"
|
---|
| 13 | #include "config.hpp"
|
---|
| 14 | #include "linkedcell.hpp"
|
---|
[952f38] | 15 | #include "Helpers/Log.hpp"
|
---|
[628b52] | 16 | #include "molecule.hpp"
|
---|
[952f38] | 17 | #include "Helpers/Verbose.hpp"
|
---|
[628b52] | 18 | #include "World.hpp"
|
---|
[97ebf8] | 19 |
|
---|
| 20 | #include <iostream>
|
---|
| 21 | #include <string>
|
---|
| 22 |
|
---|
| 23 | using namespace std;
|
---|
| 24 |
|
---|
| 25 | #include "UIElements/UIFactory.hpp"
|
---|
| 26 | #include "UIElements/Dialog.hpp"
|
---|
[861874] | 27 | #include "Actions/ValueStorage.hpp"
|
---|
[97ebf8] | 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 |
|
---|
[628b52] | 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 |
|
---|
[047878] | 58 | Dialog* TesselationConvexEnvelopeAction::fillDialog(Dialog *dialog) {
|
---|
| 59 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
[8ae5d5] | 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 |
|
---|
[97ebf8] | 68 | Action::state_ptr TesselationConvexEnvelopeAction::performCall() {
|
---|
| 69 | string filenameConvex;
|
---|
| 70 | string filenameNonConvex;
|
---|
| 71 | molecule * mol = NULL;
|
---|
[8ae5d5] | 72 | bool Success = true;
|
---|
[f6bd32] | 73 | config *configuration = World::getInstance().getConfig();
|
---|
[97ebf8] | 74 |
|
---|
[8ae5d5] | 75 | ValueStorage::getInstance().queryCurrentValue("convex-file", filenameConvex);
|
---|
| 76 | ValueStorage::getInstance().queryCurrentValue("nonconvex-file", filenameNonConvex);
|
---|
[97ebf8] | 77 |
|
---|
[8ae5d5] | 78 | for (World::MoleculeSelectionIterator iter = World::getInstance().beginMoleculeSelection(); iter != World::getInstance().endMoleculeSelection(); ++iter) {
|
---|
| 79 | mol = iter->second;
|
---|
[97ebf8] | 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.);
|
---|
[bdc91e] | 86 | //FindConvexBorder(mol, BoundaryPoints, TesselStruct, LCList, argv[argptr]);
|
---|
[97ebf8] | 87 | // TODO: Beide Funktionen sollten streams anstelle des Filenamen benutzen, besser fuer unit tests
|
---|
| 88 | FindNonConvexBorder(mol, TesselStruct, LCList, 50., filenameNonConvex.c_str());
|
---|
| 89 | //RemoveAllBoundaryPoints(TesselStruct, mol, argv[argptr]);
|
---|
[f6bd32] | 90 | const double volumedifference = ConvexizeNonconvexEnvelope(TesselStruct, mol, filenameConvex.c_str());
|
---|
| 91 | const double clustervolume = VolumeOfConvexEnvelope(TesselStruct, configuration);
|
---|
| 92 | DoLog(0) && (Log() << Verbose(0) << "The tesselated volume area is " << clustervolume << " " << (configuration->GetIsAngstroem() ? "angstrom" : "atomiclength") << "^3." << endl);
|
---|
| 93 | DoLog(0) && (Log() << Verbose(0) << "The non-convex tesselated volume area is " << clustervolume-volumedifference << " " << (configuration->GetIsAngstroem() ? "angstrom" : "atomiclength") << "^3." << endl);
|
---|
[97ebf8] | 94 | delete(TesselStruct);
|
---|
| 95 | delete(LCList);
|
---|
| 96 | }
|
---|
[8ae5d5] | 97 | if (Success)
|
---|
| 98 | return Action::success;
|
---|
| 99 | else
|
---|
| 100 | return Action::failure;
|
---|
[97ebf8] | 101 | }
|
---|
| 102 |
|
---|
| 103 | Action::state_ptr TesselationConvexEnvelopeAction::performUndo(Action::state_ptr _state) {
|
---|
| 104 | // TesselationConvexEnvelopeState *state = assert_cast<TesselationConvexEnvelopeState*>(_state.get());
|
---|
| 105 |
|
---|
| 106 | // string newName = state->mol->getName();
|
---|
| 107 | // state->mol->setName(state->lastName);
|
---|
| 108 |
|
---|
| 109 | return Action::failure;
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | Action::state_ptr TesselationConvexEnvelopeAction::performRedo(Action::state_ptr _state){
|
---|
| 113 | // Undo and redo have to do the same for this action
|
---|
| 114 | return performUndo(_state);
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | bool TesselationConvexEnvelopeAction::canUndo() {
|
---|
| 118 | return false;
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | bool TesselationConvexEnvelopeAction::shouldUndo() {
|
---|
| 122 | return false;
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | const string TesselationConvexEnvelopeAction::getName() {
|
---|
| 126 | return NAME;
|
---|
| 127 | }
|
---|