[d02e07] | 1 | /*
|
---|
| 2 | * PointCorrelationAction.cpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: May 9, 2010
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #include "Helpers/MemDebug.hpp"
|
---|
| 9 |
|
---|
| 10 | #include "Actions/AnalysisAction/PointCorrelationAction.hpp"
|
---|
[0430e3] | 11 | #include "Actions/ActionRegistry.hpp"
|
---|
[d02e07] | 12 | #include "analysis_correlation.hpp"
|
---|
| 13 | #include "boundary.hpp"
|
---|
| 14 | #include "linkedcell.hpp"
|
---|
[952f38] | 15 | #include "Helpers/Verbose.hpp"
|
---|
| 16 | #include "Helpers/Log.hpp"
|
---|
[d02e07] | 17 | #include "element.hpp"
|
---|
| 18 | #include "molecule.hpp"
|
---|
| 19 | #include "periodentafel.hpp"
|
---|
[57f243] | 20 | #include "LinearAlgebra/Vector.hpp"
|
---|
[d02e07] | 21 | #include "World.hpp"
|
---|
| 22 |
|
---|
| 23 | #include <iostream>
|
---|
| 24 | #include <string>
|
---|
| 25 |
|
---|
| 26 | using namespace std;
|
---|
| 27 |
|
---|
| 28 | #include "UIElements/UIFactory.hpp"
|
---|
| 29 | #include "UIElements/Dialog.hpp"
|
---|
[861874] | 30 | #include "Actions/ValueStorage.hpp"
|
---|
[d02e07] | 31 |
|
---|
| 32 | const char AnalysisPointCorrelationAction::NAME[] = "point-correlation";
|
---|
| 33 |
|
---|
| 34 | AnalysisPointCorrelationAction::AnalysisPointCorrelationAction() :
|
---|
| 35 | Action(NAME)
|
---|
| 36 | {}
|
---|
| 37 |
|
---|
| 38 | AnalysisPointCorrelationAction::~AnalysisPointCorrelationAction()
|
---|
| 39 | {}
|
---|
| 40 |
|
---|
[b31cfa] | 41 | void AnalysisPointCorrelation(std::vector< element *> &elements, Vector &position, double BinStart, double BinWidth, double BinEnd, string &outputname, string &binoutputname, bool periodic) {
|
---|
| 42 | ValueStorage::getInstance().setCurrentValue("elements", elements);
|
---|
| 43 | ValueStorage::getInstance().setCurrentValue("position", position);
|
---|
| 44 | ValueStorage::getInstance().setCurrentValue("bin-start", BinStart);
|
---|
| 45 | ValueStorage::getInstance().setCurrentValue("bin-width", BinWidth);
|
---|
| 46 | ValueStorage::getInstance().setCurrentValue("bin-end", BinEnd);
|
---|
| 47 | ValueStorage::getInstance().setCurrentValue("output-file", outputname);
|
---|
| 48 | ValueStorage::getInstance().setCurrentValue("bin-output-file", binoutputname);
|
---|
| 49 | ValueStorage::getInstance().setCurrentValue("periodic", periodic);
|
---|
| 50 | ActionRegistry::getInstance().getActionByName(AnalysisPointCorrelationAction::NAME)->call(Action::NonInteractive);
|
---|
| 51 | };
|
---|
| 52 |
|
---|
[047878] | 53 | Dialog* AnalysisPointCorrelationAction::fillDialog(Dialog *dialog) {
|
---|
| 54 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
[d02e07] | 55 |
|
---|
[9d33ba] | 56 | dialog->queryVector("position", false, ValueStorage::getInstance().getDescription("position"));
|
---|
[e65de8] | 57 | dialog->queryElements("elements", ValueStorage::getInstance().getDescription("elements"));
|
---|
[9d33ba] | 58 | dialog->queryDouble("bin-start", ValueStorage::getInstance().getDescription("bin-start"));
|
---|
| 59 | dialog->queryDouble("bin-width", ValueStorage::getInstance().getDescription("bin-width"));
|
---|
| 60 | dialog->queryDouble("bin-end", ValueStorage::getInstance().getDescription("bin-end"));
|
---|
| 61 | dialog->queryString("output-file", ValueStorage::getInstance().getDescription("output-file"));
|
---|
| 62 | dialog->queryString("bin-output-file", ValueStorage::getInstance().getDescription("bin-output-file"));
|
---|
| 63 | dialog->queryBoolean("periodic", ValueStorage::getInstance().getDescription("periodic"));
|
---|
[d02e07] | 64 |
|
---|
| 65 | return dialog;
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | Action::state_ptr AnalysisPointCorrelationAction::performCall() {
|
---|
| 69 | int ranges[3] = {1, 1, 1};
|
---|
| 70 | double BinEnd = 0.;
|
---|
| 71 | double BinStart = 0.;
|
---|
| 72 | double BinWidth = 0.;
|
---|
| 73 | string outputname;
|
---|
| 74 | string binoutputname;
|
---|
| 75 | bool periodic;
|
---|
| 76 | ofstream output;
|
---|
| 77 | ofstream binoutput;
|
---|
| 78 | std::vector< element *> elements;
|
---|
| 79 | string type;
|
---|
| 80 | Vector Point;
|
---|
| 81 | BinPairMap *binmap = NULL;
|
---|
| 82 |
|
---|
| 83 | // obtain information
|
---|
[9d33ba] | 84 | ValueStorage::getInstance().queryCurrentValue("position", Point);
|
---|
| 85 | ValueStorage::getInstance().queryCurrentValue("elements", elements);
|
---|
| 86 | ValueStorage::getInstance().queryCurrentValue("bin-start", BinStart);
|
---|
| 87 | ValueStorage::getInstance().queryCurrentValue("bin-width", BinWidth);
|
---|
| 88 | ValueStorage::getInstance().queryCurrentValue("bin-end", BinEnd);
|
---|
| 89 | ValueStorage::getInstance().queryCurrentValue("output-file", outputname);
|
---|
| 90 | ValueStorage::getInstance().queryCurrentValue("bin-output-file", binoutputname);
|
---|
| 91 | ValueStorage::getInstance().queryCurrentValue("periodic", periodic);
|
---|
[d02e07] | 92 |
|
---|
| 93 | // execute action
|
---|
| 94 | output.open(outputname.c_str());
|
---|
| 95 | binoutput.open(binoutputname.c_str());
|
---|
| 96 | cout << "Point to correlate to is " << Point << endl;
|
---|
| 97 | CorrelationToPointMap *correlationmap = NULL;
|
---|
[e65de8] | 98 | for(std::vector< element *>::iterator iter = elements.begin(); iter != elements.end(); ++iter)
|
---|
| 99 | cout << "element is " << (*iter)->symbol << endl;
|
---|
| 100 | std::vector<molecule*> molecules = World::getInstance().getSelectedMolecules();
|
---|
[d02e07] | 101 | if (periodic)
|
---|
| 102 | correlationmap = PeriodicCorrelationToPoint(molecules, elements, &Point, ranges);
|
---|
| 103 | else
|
---|
| 104 | correlationmap = CorrelationToPoint(molecules, elements, &Point);
|
---|
| 105 | OutputCorrelationToPoint(&output, correlationmap);
|
---|
| 106 | binmap = BinData( correlationmap, BinWidth, BinStart, BinEnd );
|
---|
| 107 | OutputCorrelation ( &binoutput, binmap );
|
---|
| 108 | delete(binmap);
|
---|
| 109 | delete(correlationmap);
|
---|
| 110 | output.close();
|
---|
| 111 | binoutput.close();
|
---|
| 112 | return Action::success;
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | Action::state_ptr AnalysisPointCorrelationAction::performUndo(Action::state_ptr _state) {
|
---|
| 116 | return Action::success;
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | Action::state_ptr AnalysisPointCorrelationAction::performRedo(Action::state_ptr _state){
|
---|
| 120 | return Action::success;
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | bool AnalysisPointCorrelationAction::canUndo() {
|
---|
| 124 | return true;
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | bool AnalysisPointCorrelationAction::shouldUndo() {
|
---|
| 128 | return true;
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | const string AnalysisPointCorrelationAction::getName() {
|
---|
| 132 | return NAME;
|
---|
| 133 | }
|
---|