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