[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"
|
---|
[88b400] | 17 | #include "tesselation.hpp"
|
---|
[952f38] | 18 | #include "Helpers/Verbose.hpp"
|
---|
[628b52] | 19 | #include "World.hpp"
|
---|
[97ebf8] | 20 |
|
---|
| 21 | #include <iostream>
|
---|
| 22 | #include <string>
|
---|
| 23 |
|
---|
| 24 | using namespace std;
|
---|
| 25 |
|
---|
| 26 | #include "UIElements/UIFactory.hpp"
|
---|
| 27 | #include "UIElements/Dialog.hpp"
|
---|
[861874] | 28 | #include "Actions/ValueStorage.hpp"
|
---|
[97ebf8] | 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 |
|
---|
[628b52] | 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 |
|
---|
[047878] | 59 | Dialog* TesselationConvexEnvelopeAction::fillDialog(Dialog *dialog) {
|
---|
| 60 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
[8ae5d5] | 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 |
|
---|
[97ebf8] | 69 | Action::state_ptr TesselationConvexEnvelopeAction::performCall() {
|
---|
| 70 | string filenameConvex;
|
---|
| 71 | string filenameNonConvex;
|
---|
| 72 | molecule * mol = NULL;
|
---|
[8ae5d5] | 73 | bool Success = true;
|
---|
[f6bd32] | 74 | config *configuration = World::getInstance().getConfig();
|
---|
[97ebf8] | 75 |
|
---|
[8ae5d5] | 76 | ValueStorage::getInstance().queryCurrentValue("convex-file", filenameConvex);
|
---|
| 77 | ValueStorage::getInstance().queryCurrentValue("nonconvex-file", filenameNonConvex);
|
---|
[97ebf8] | 78 |
|
---|
[8ae5d5] | 79 | for (World::MoleculeSelectionIterator iter = World::getInstance().beginMoleculeSelection(); iter != World::getInstance().endMoleculeSelection(); ++iter) {
|
---|
| 80 | mol = iter->second;
|
---|
[97ebf8] | 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.);
|
---|
[25b9d2] | 87 | //Boundaries *BoundaryPoints = NULL;
|
---|
[bdc91e] | 88 | //FindConvexBorder(mol, BoundaryPoints, TesselStruct, LCList, argv[argptr]);
|
---|
[97ebf8] | 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]);
|
---|
[f6bd32] | 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);
|
---|
[97ebf8] | 96 | delete(TesselStruct);
|
---|
| 97 | delete(LCList);
|
---|
| 98 | }
|
---|
[8ae5d5] | 99 | if (Success)
|
---|
| 100 | return Action::success;
|
---|
| 101 | else
|
---|
| 102 | return Action::failure;
|
---|
[97ebf8] | 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 | }
|
---|