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