1 | /*
|
---|
2 | * NonConvexEnvelopeAction.cpp
|
---|
3 | *
|
---|
4 | * Created on: May 10, 2010
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "Helpers/MemDebug.hpp"
|
---|
9 |
|
---|
10 | #include "Actions/TesselationAction/NonConvexEnvelopeAction.hpp"
|
---|
11 | #include "Actions/ActionRegistry.hpp"
|
---|
12 | #include "boundary.hpp"
|
---|
13 | #include "linkedcell.hpp"
|
---|
14 | #include "Helpers/Log.hpp"
|
---|
15 | #include "molecule.hpp"
|
---|
16 | #include "tesselation.hpp"
|
---|
17 | #include "Helpers/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 "Actions/ValueStorage.hpp"
|
---|
28 |
|
---|
29 | /****** TesselationNonConvexEnvelopeAction *****/
|
---|
30 |
|
---|
31 | // memento to remember the state when undoing
|
---|
32 |
|
---|
33 | //class TesselationNonConvexEnvelopeState : public ActionState {
|
---|
34 | //public:
|
---|
35 | // TesselationNonConvexEnvelopeState(molecule* _mol,std::string _lastName) :
|
---|
36 | // mol(_mol),
|
---|
37 | // lastName(_lastName)
|
---|
38 | // {}
|
---|
39 | // molecule* mol;
|
---|
40 | // std::string lastName;
|
---|
41 | //};
|
---|
42 |
|
---|
43 | const char TesselationNonConvexEnvelopeAction::NAME[] = "nonconvex-envelope";
|
---|
44 |
|
---|
45 | TesselationNonConvexEnvelopeAction::TesselationNonConvexEnvelopeAction() :
|
---|
46 | Action(NAME)
|
---|
47 | {}
|
---|
48 |
|
---|
49 | TesselationNonConvexEnvelopeAction::~TesselationNonConvexEnvelopeAction()
|
---|
50 | {}
|
---|
51 |
|
---|
52 | void TesselationNonConvexEnvelope(double radius, std::string &filename) {
|
---|
53 | ValueStorage::getInstance().setCurrentValue(TesselationNonConvexEnvelopeAction::NAME, radius);
|
---|
54 | ValueStorage::getInstance().setCurrentValue("nonconvex-file", filename);
|
---|
55 | ActionRegistry::getInstance().getActionByName(TesselationNonConvexEnvelopeAction::NAME)->call(Action::NonInteractive);
|
---|
56 | };
|
---|
57 |
|
---|
58 | Dialog* TesselationNonConvexEnvelopeAction::fillDialog(Dialog *dialog) {
|
---|
59 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
60 |
|
---|
61 | dialog->queryDouble(NAME, MapOfActions::getInstance().getDescription(NAME));
|
---|
62 | dialog->queryString("nonconvex-file", MapOfActions::getInstance().getDescription("nonconvex-file"));
|
---|
63 |
|
---|
64 | return dialog;
|
---|
65 | }
|
---|
66 |
|
---|
67 | Action::state_ptr TesselationNonConvexEnvelopeAction::performCall() {
|
---|
68 | string filename;
|
---|
69 | molecule * Boundary = NULL;
|
---|
70 | double SphereRadius = 0;
|
---|
71 | bool Success = false;
|
---|
72 | clock_t start,end;
|
---|
73 |
|
---|
74 | ValueStorage::getInstance().queryCurrentValue(NAME, SphereRadius);
|
---|
75 | ValueStorage::getInstance().queryCurrentValue("nonconvex-file", filename);
|
---|
76 |
|
---|
77 | for (World::MoleculeSelectionIterator iter = World::getInstance().beginMoleculeSelection(); iter != World::getInstance().endMoleculeSelection(); ++iter) {
|
---|
78 | Boundary = iter->second;
|
---|
79 | class Tesselation *T = NULL;
|
---|
80 | const LinkedCell *LCList = NULL;
|
---|
81 | DoLog(0) && (Log() << Verbose(0) << "Evaluating non-convex envelope of molecule." << Boundary->getId() << endl);
|
---|
82 | DoLog(1) && (Log() << Verbose(1) << "Using rolling ball of radius " << SphereRadius << " and storing tecplot data in " << filename << "." << endl);
|
---|
83 | DoLog(1) && (Log() << Verbose(1) << "Specified molecule has " << Boundary->getAtomCount() << " atoms." << endl);
|
---|
84 | start = clock();
|
---|
85 | LCList = new LinkedCell(Boundary, SphereRadius*2.);
|
---|
86 | Success = FindNonConvexBorder(Boundary, T, LCList, SphereRadius, filename.c_str());
|
---|
87 | //FindDistributionOfEllipsoids(T, &LCList, N, number, filename.c_str());
|
---|
88 | end = clock();
|
---|
89 | DoLog(0) && (Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl);
|
---|
90 | delete(LCList);
|
---|
91 | delete(T);
|
---|
92 | }
|
---|
93 | if (Success)
|
---|
94 | return Action::success;
|
---|
95 | else
|
---|
96 | return Action::failure;
|
---|
97 | }
|
---|
98 |
|
---|
99 | Action::state_ptr TesselationNonConvexEnvelopeAction::performUndo(Action::state_ptr _state) {
|
---|
100 | // TesselationNonConvexEnvelopeState *state = assert_cast<TesselationNonConvexEnvelopeState*>(_state.get());
|
---|
101 |
|
---|
102 | // string newName = state->mol->getName();
|
---|
103 | // state->mol->setName(state->lastName);
|
---|
104 |
|
---|
105 | return Action::failure;
|
---|
106 | }
|
---|
107 |
|
---|
108 | Action::state_ptr TesselationNonConvexEnvelopeAction::performRedo(Action::state_ptr _state){
|
---|
109 | // Undo and redo have to do the same for this action
|
---|
110 | return performUndo(_state);
|
---|
111 | }
|
---|
112 |
|
---|
113 | bool TesselationNonConvexEnvelopeAction::canUndo() {
|
---|
114 | return false;
|
---|
115 | }
|
---|
116 |
|
---|
117 | bool TesselationNonConvexEnvelopeAction::shouldUndo() {
|
---|
118 | return false;
|
---|
119 | }
|
---|
120 |
|
---|
121 | const string TesselationNonConvexEnvelopeAction::getName() {
|
---|
122 | return NAME;
|
---|
123 | }
|
---|