| [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"
 | 
|---|
 | 15 | #include "verbose.hpp"
 | 
|---|
 | 16 | #include "log.hpp"
 | 
|---|
 | 17 | #include "element.hpp"
 | 
|---|
 | 18 | #include "molecule.hpp"
 | 
|---|
 | 19 | #include "periodentafel.hpp"
 | 
|---|
 | 20 | #include "vector.hpp"
 | 
|---|
 | 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 |   molecule *Boundary = NULL;
 | 
|---|
 | 74 |   string outputname;
 | 
|---|
 | 75 |   string binoutputname;
 | 
|---|
 | 76 |   bool periodic;
 | 
|---|
 | 77 |   ofstream output;
 | 
|---|
 | 78 |   ofstream binoutput;
 | 
|---|
 | 79 |   std::vector< element *> elements;
 | 
|---|
 | 80 |   string type;
 | 
|---|
 | 81 |   Vector Point;
 | 
|---|
 | 82 |   BinPairMap *binmap = NULL;
 | 
|---|
 | 83 | 
 | 
|---|
 | 84 |   // obtain information
 | 
|---|
| [9d33ba] | 85 |   ValueStorage::getInstance().queryCurrentValue("position", Point);
 | 
|---|
 | 86 |   ValueStorage::getInstance().queryCurrentValue("elements", elements);
 | 
|---|
 | 87 |   ValueStorage::getInstance().queryCurrentValue("bin-start", BinStart);
 | 
|---|
 | 88 |   ValueStorage::getInstance().queryCurrentValue("bin-width", BinWidth);
 | 
|---|
 | 89 |   ValueStorage::getInstance().queryCurrentValue("bin-end", BinEnd);
 | 
|---|
 | 90 |   ValueStorage::getInstance().queryCurrentValue("output-file", outputname);
 | 
|---|
 | 91 |   ValueStorage::getInstance().queryCurrentValue("bin-output-file", binoutputname);
 | 
|---|
 | 92 |   ValueStorage::getInstance().queryCurrentValue("periodic", periodic);
 | 
|---|
| [d02e07] | 93 | 
 | 
|---|
 | 94 |   // execute action
 | 
|---|
 | 95 |   output.open(outputname.c_str());
 | 
|---|
 | 96 |   binoutput.open(binoutputname.c_str());
 | 
|---|
 | 97 |   cout << "Point to correlate to is  " << Point << endl;
 | 
|---|
 | 98 |   CorrelationToPointMap *correlationmap = NULL;
 | 
|---|
| [e65de8] | 99 |   for(std::vector< element *>::iterator iter = elements.begin(); iter != elements.end(); ++iter)
 | 
|---|
 | 100 |     cout << "element is " << (*iter)->symbol << endl;
 | 
|---|
 | 101 |   std::vector<molecule*> molecules = World::getInstance().getSelectedMolecules();
 | 
|---|
| [d02e07] | 102 |   if (periodic)
 | 
|---|
 | 103 |     correlationmap  = PeriodicCorrelationToPoint(molecules, elements, &Point, ranges);
 | 
|---|
 | 104 |   else
 | 
|---|
 | 105 |     correlationmap = CorrelationToPoint(molecules, elements, &Point);
 | 
|---|
 | 106 |   OutputCorrelationToPoint(&output, correlationmap);
 | 
|---|
 | 107 |   binmap = BinData( correlationmap, BinWidth, BinStart, BinEnd );
 | 
|---|
 | 108 |   OutputCorrelation ( &binoutput, binmap );
 | 
|---|
 | 109 |   delete(binmap);
 | 
|---|
 | 110 |   delete(correlationmap);
 | 
|---|
 | 111 |   output.close();
 | 
|---|
 | 112 |   binoutput.close();
 | 
|---|
 | 113 |   return Action::success;
 | 
|---|
 | 114 | }
 | 
|---|
 | 115 | 
 | 
|---|
 | 116 | Action::state_ptr AnalysisPointCorrelationAction::performUndo(Action::state_ptr _state) {
 | 
|---|
 | 117 |   return Action::success;
 | 
|---|
 | 118 | }
 | 
|---|
 | 119 | 
 | 
|---|
 | 120 | Action::state_ptr AnalysisPointCorrelationAction::performRedo(Action::state_ptr _state){
 | 
|---|
 | 121 |   return Action::success;
 | 
|---|
 | 122 | }
 | 
|---|
 | 123 | 
 | 
|---|
 | 124 | bool AnalysisPointCorrelationAction::canUndo() {
 | 
|---|
 | 125 |   return true;
 | 
|---|
 | 126 | }
 | 
|---|
 | 127 | 
 | 
|---|
 | 128 | bool AnalysisPointCorrelationAction::shouldUndo() {
 | 
|---|
 | 129 |   return true;
 | 
|---|
 | 130 | }
 | 
|---|
 | 131 | 
 | 
|---|
 | 132 | const string AnalysisPointCorrelationAction::getName() {
 | 
|---|
 | 133 |   return NAME;
 | 
|---|
 | 134 | }
 | 
|---|