[97ebf8] | 1 | /*
|
---|
| 2 | * NonConvexEnvelopeAction.cpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: May 10, 2010
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
[112b09] | 8 | #include "Helpers/MemDebug.hpp"
|
---|
| 9 |
|
---|
[97ebf8] | 10 | #include "Actions/TesselationAction/NonConvexEnvelopeAction.hpp"
|
---|
[0430e3] | 11 | #include "Actions/ActionRegistry.hpp"
|
---|
[628b52] | 12 | #include "boundary.hpp"
|
---|
| 13 | #include "linkedcell.hpp"
|
---|
[952f38] | 14 | #include "Helpers/Log.hpp"
|
---|
[628b52] | 15 | #include "molecule.hpp"
|
---|
[88b400] | 16 | #include "tesselation.hpp"
|
---|
[952f38] | 17 | #include "Helpers/Verbose.hpp"
|
---|
[628b52] | 18 | #include "World.hpp"
|
---|
[97ebf8] | 19 |
|
---|
| 20 | #include <iostream>
|
---|
| 21 | #include <string>
|
---|
| 22 |
|
---|
| 23 | using namespace std;
|
---|
| 24 |
|
---|
| 25 | #include "UIElements/UIFactory.hpp"
|
---|
| 26 | #include "UIElements/Dialog.hpp"
|
---|
[861874] | 27 | #include "Actions/ValueStorage.hpp"
|
---|
[97ebf8] | 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 |
|
---|
[628b52] | 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 |
|
---|
[047878] | 58 | Dialog* TesselationNonConvexEnvelopeAction::fillDialog(Dialog *dialog) {
|
---|
| 59 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
[ff4fd2a] | 60 |
|
---|
[c89fb4] | 61 | dialog->queryDouble(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
| 62 | dialog->queryString("nonconvex-file", ValueStorage::getInstance().getDescription("nonconvex-file"));
|
---|
[ff4fd2a] | 63 |
|
---|
| 64 | return dialog;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
[97ebf8] | 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 |
|
---|
[1d9b7d2] | 74 | ValueStorage::getInstance().queryCurrentValue(NAME, SphereRadius);
|
---|
[ff4fd2a] | 75 | ValueStorage::getInstance().queryCurrentValue("nonconvex-file", filename);
|
---|
[97ebf8] | 76 |
|
---|
[ff4fd2a] | 77 | for (World::MoleculeSelectionIterator iter = World::getInstance().beginMoleculeSelection(); iter != World::getInstance().endMoleculeSelection(); ++iter) {
|
---|
| 78 | Boundary = iter->second;
|
---|
[97ebf8] | 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);
|
---|
[1024cb] | 83 | DoLog(1) && (Log() << Verbose(1) << "Specified molecule has " << Boundary->getAtomCount() << " atoms." << endl);
|
---|
[97ebf8] | 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 | }
|
---|
[ff4fd2a] | 93 | if (Success)
|
---|
| 94 | return Action::success;
|
---|
| 95 | else
|
---|
| 96 | return Action::failure;
|
---|
[97ebf8] | 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 | }
|
---|