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