1 | /*
|
---|
2 | * NonConvexEnvelopeAction.cpp
|
---|
3 | *
|
---|
4 | * Created on: May 10, 2010
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "Actions/TesselationAction/NonConvexEnvelopeAction.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 "linkedcell.hpp"
|
---|
22 | #include "log.hpp"
|
---|
23 | #include "molecule.hpp"
|
---|
24 | #include "verbose.hpp"
|
---|
25 | #include "World.hpp"
|
---|
26 |
|
---|
27 | /****** TesselationNonConvexEnvelopeAction *****/
|
---|
28 |
|
---|
29 | // memento to remember the state when undoing
|
---|
30 |
|
---|
31 | //class TesselationNonConvexEnvelopeState : public ActionState {
|
---|
32 | //public:
|
---|
33 | // TesselationNonConvexEnvelopeState(molecule* _mol,std::string _lastName) :
|
---|
34 | // mol(_mol),
|
---|
35 | // lastName(_lastName)
|
---|
36 | // {}
|
---|
37 | // molecule* mol;
|
---|
38 | // std::string lastName;
|
---|
39 | //};
|
---|
40 |
|
---|
41 | const char TesselationNonConvexEnvelopeAction::NAME[] = "nonconvex-envelope";
|
---|
42 |
|
---|
43 | TesselationNonConvexEnvelopeAction::TesselationNonConvexEnvelopeAction() :
|
---|
44 | Action(NAME)
|
---|
45 | {}
|
---|
46 |
|
---|
47 | TesselationNonConvexEnvelopeAction::~TesselationNonConvexEnvelopeAction()
|
---|
48 | {}
|
---|
49 |
|
---|
50 | Action::state_ptr TesselationNonConvexEnvelopeAction::performCall() {
|
---|
51 | string filename;
|
---|
52 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
53 | molecule * Boundary = NULL;
|
---|
54 | double SphereRadius = 0;
|
---|
55 | bool Success = false;
|
---|
56 | clock_t start,end;
|
---|
57 |
|
---|
58 | dialog->queryDouble(NAME, &SphereRadius, MapOfActions::getInstance().getDescription(NAME));
|
---|
59 | dialog->queryString("output", &filename, MapOfActions::getInstance().getDescription("output"));
|
---|
60 | dialog->queryMolecule("molecule-by-id", &Boundary, MapOfActions::getInstance().getDescription("molecule-by-id"));
|
---|
61 |
|
---|
62 | if(dialog->display()) {
|
---|
63 | class Tesselation *T = NULL;
|
---|
64 | const LinkedCell *LCList = NULL;
|
---|
65 | DoLog(0) && (Log() << Verbose(0) << "Evaluating non-convex envelope of molecule." << Boundary->getId() << endl);
|
---|
66 | DoLog(1) && (Log() << Verbose(1) << "Using rolling ball of radius " << SphereRadius << " and storing tecplot data in " << filename << "." << endl);
|
---|
67 | DoLog(1) && (Log() << Verbose(1) << "Specified molecule has " << Boundary->getAtomCount() << " atoms." << endl);
|
---|
68 | start = clock();
|
---|
69 | LCList = new LinkedCell(Boundary, SphereRadius*2.);
|
---|
70 | Success = FindNonConvexBorder(Boundary, T, LCList, SphereRadius, filename.c_str());
|
---|
71 | //FindDistributionOfEllipsoids(T, &LCList, N, number, filename.c_str());
|
---|
72 | end = clock();
|
---|
73 | DoLog(0) && (Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl);
|
---|
74 | delete(LCList);
|
---|
75 | delete(T);
|
---|
76 | delete dialog;
|
---|
77 | if (Success)
|
---|
78 | return Action::success;
|
---|
79 | else
|
---|
80 | return Action::failure;
|
---|
81 | }
|
---|
82 | delete dialog;
|
---|
83 | return Action::failure;
|
---|
84 | }
|
---|
85 |
|
---|
86 | Action::state_ptr TesselationNonConvexEnvelopeAction::performUndo(Action::state_ptr _state) {
|
---|
87 | // TesselationNonConvexEnvelopeState *state = assert_cast<TesselationNonConvexEnvelopeState*>(_state.get());
|
---|
88 |
|
---|
89 | // string newName = state->mol->getName();
|
---|
90 | // state->mol->setName(state->lastName);
|
---|
91 |
|
---|
92 | return Action::failure;
|
---|
93 | }
|
---|
94 |
|
---|
95 | Action::state_ptr TesselationNonConvexEnvelopeAction::performRedo(Action::state_ptr _state){
|
---|
96 | // Undo and redo have to do the same for this action
|
---|
97 | return performUndo(_state);
|
---|
98 | }
|
---|
99 |
|
---|
100 | bool TesselationNonConvexEnvelopeAction::canUndo() {
|
---|
101 | return false;
|
---|
102 | }
|
---|
103 |
|
---|
104 | bool TesselationNonConvexEnvelopeAction::shouldUndo() {
|
---|
105 | return false;
|
---|
106 | }
|
---|
107 |
|
---|
108 | const string TesselationNonConvexEnvelopeAction::getName() {
|
---|
109 | return NAME;
|
---|
110 | }
|
---|