[d02e07] | 1 | /*
|
---|
| 2 | * SurfaceCorrelationAction.cpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: May 9, 2010
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #include "Helpers/MemDebug.hpp"
|
---|
| 9 |
|
---|
| 10 | #include "Actions/AnalysisAction/SurfaceCorrelationAction.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"
|
---|
[88b400] | 20 | #include "tesselation.hpp"
|
---|
[57f243] | 21 | #include "LinearAlgebra/Vector.hpp"
|
---|
[d02e07] | 22 | #include "World.hpp"
|
---|
| 23 |
|
---|
| 24 | #include <iostream>
|
---|
| 25 | #include <string>
|
---|
| 26 |
|
---|
| 27 | using namespace std;
|
---|
| 28 |
|
---|
| 29 | #include "UIElements/UIFactory.hpp"
|
---|
| 30 | #include "UIElements/Dialog.hpp"
|
---|
[861874] | 31 | #include "Actions/ValueStorage.hpp"
|
---|
[d02e07] | 32 |
|
---|
| 33 | const char AnalysisSurfaceCorrelationAction::NAME[] = "surface-correlation";
|
---|
| 34 |
|
---|
| 35 | AnalysisSurfaceCorrelationAction::AnalysisSurfaceCorrelationAction() :
|
---|
| 36 | Action(NAME)
|
---|
| 37 | {}
|
---|
| 38 |
|
---|
| 39 | AnalysisSurfaceCorrelationAction::~AnalysisSurfaceCorrelationAction()
|
---|
| 40 | {}
|
---|
| 41 |
|
---|
[b31cfa] | 42 | void AnalysisSurfaceCorrelation(std::vector< element *> &elements, molecule *mol, double BinStart, double BinWidth, double BinEnd, std::string &outputname, std::string &binoutputname, bool periodic) {
|
---|
| 43 | ValueStorage::getInstance().setCurrentValue("elements", elements);
|
---|
| 44 | ValueStorage::getInstance().setCurrentValue("molecule-by-id", mol);
|
---|
| 45 | ValueStorage::getInstance().setCurrentValue("bin-start", BinStart);
|
---|
| 46 | ValueStorage::getInstance().setCurrentValue("bin-width", BinWidth);
|
---|
| 47 | ValueStorage::getInstance().setCurrentValue("bin-end", BinEnd);
|
---|
| 48 | ValueStorage::getInstance().setCurrentValue("output-file", outputname);
|
---|
| 49 | ValueStorage::getInstance().setCurrentValue("bin-output-file", binoutputname);
|
---|
| 50 | ValueStorage::getInstance().setCurrentValue("periodic", periodic);
|
---|
| 51 | ActionRegistry::getInstance().getActionByName(AnalysisSurfaceCorrelationAction::NAME)->call(Action::NonInteractive);
|
---|
| 52 | };
|
---|
| 53 |
|
---|
| 54 |
|
---|
[047878] | 55 | Dialog* AnalysisSurfaceCorrelationAction::fillDialog(Dialog *dialog) {
|
---|
| 56 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
[d02e07] | 57 |
|
---|
[9d33ba] | 58 | dialog->queryMolecule("molecule-by-id", ValueStorage::getInstance().getDescription("molecule-by-id"));
|
---|
[e65de8] | 59 | dialog->queryElements("elements", ValueStorage::getInstance().getDescription("elements"));
|
---|
[9d33ba] | 60 | dialog->queryDouble("bin-start", ValueStorage::getInstance().getDescription("bin-start"));
|
---|
| 61 | dialog->queryDouble("bin-width", ValueStorage::getInstance().getDescription("bin-width"));
|
---|
| 62 | dialog->queryDouble("bin-end", ValueStorage::getInstance().getDescription("bin-end"));
|
---|
| 63 | dialog->queryString("output-file", ValueStorage::getInstance().getDescription("output-file"));
|
---|
| 64 | dialog->queryString("bin-output-file", ValueStorage::getInstance().getDescription("bin-output-file"));
|
---|
| 65 | dialog->queryBoolean("periodic", ValueStorage::getInstance().getDescription("periodic"));
|
---|
[d02e07] | 66 |
|
---|
| 67 | return dialog;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | Action::state_ptr AnalysisSurfaceCorrelationAction::performCall() {
|
---|
| 71 | int ranges[3] = {1, 1, 1};
|
---|
| 72 | double BinEnd = 0.;
|
---|
| 73 | double BinStart = 0.;
|
---|
| 74 | double BinWidth = 0.;
|
---|
| 75 | molecule *Boundary = NULL;
|
---|
| 76 | string outputname;
|
---|
| 77 | string binoutputname;
|
---|
| 78 | bool periodic;
|
---|
| 79 | ofstream output;
|
---|
| 80 | ofstream binoutput;
|
---|
[e5c0a1] | 81 | std::vector<const element *> elements;
|
---|
[d02e07] | 82 | string type;
|
---|
| 83 | Vector Point;
|
---|
| 84 | BinPairMap *binmap = NULL;
|
---|
| 85 |
|
---|
| 86 | // obtain information
|
---|
[9d33ba] | 87 | ValueStorage::getInstance().queryCurrentValue("molecule-by-id", Boundary);
|
---|
| 88 | ValueStorage::getInstance().queryCurrentValue("elements", elements);
|
---|
| 89 | ValueStorage::getInstance().queryCurrentValue("bin-start", BinStart);
|
---|
| 90 | ValueStorage::getInstance().queryCurrentValue("bin-width", BinWidth);
|
---|
| 91 | ValueStorage::getInstance().queryCurrentValue("bin-end", BinEnd);
|
---|
| 92 | ValueStorage::getInstance().queryCurrentValue("output-file", outputname);
|
---|
| 93 | ValueStorage::getInstance().queryCurrentValue("bin-output-file", binoutputname);
|
---|
| 94 | ValueStorage::getInstance().queryCurrentValue("periodic", periodic);
|
---|
[d02e07] | 95 |
|
---|
| 96 | // execute action
|
---|
| 97 | output.open(outputname.c_str());
|
---|
| 98 | binoutput.open(binoutputname.c_str());
|
---|
| 99 | ASSERT(Boundary != NULL, "No molecule specified for SurfaceCorrelation.");
|
---|
| 100 | const double radius = 4.;
|
---|
| 101 | double LCWidth = 20.;
|
---|
| 102 | if (BinEnd > 0) {
|
---|
| 103 | if (BinEnd > 2.*radius)
|
---|
| 104 | LCWidth = BinEnd;
|
---|
| 105 | else
|
---|
| 106 | LCWidth = 2.*radius;
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | // get the boundary
|
---|
| 110 | class Tesselation *TesselStruct = NULL;
|
---|
| 111 | const LinkedCell *LCList = NULL;
|
---|
| 112 | // find biggest molecule
|
---|
[e65de8] | 113 | std::vector<molecule*> molecules = World::getInstance().getSelectedMolecules();
|
---|
[d02e07] | 114 | LCList = new LinkedCell(Boundary, LCWidth);
|
---|
| 115 | FindNonConvexBorder(Boundary, TesselStruct, LCList, radius, NULL);
|
---|
| 116 | CorrelationToSurfaceMap *surfacemap = NULL;
|
---|
| 117 | if (periodic)
|
---|
| 118 | surfacemap = PeriodicCorrelationToSurface( molecules, elements, TesselStruct, LCList, ranges);
|
---|
| 119 | else
|
---|
| 120 | surfacemap = CorrelationToSurface( molecules, elements, TesselStruct, LCList);
|
---|
| 121 | delete LCList;
|
---|
| 122 | OutputCorrelationToSurface(&output, surfacemap);
|
---|
| 123 | // check whether radius was appropriate
|
---|
| 124 | {
|
---|
| 125 | double start; double end;
|
---|
| 126 | GetMinMax( surfacemap, start, end);
|
---|
| 127 | if (LCWidth < end)
|
---|
| 128 | DoeLog(1) && (eLog()<< Verbose(1) << "Linked Cell width is smaller than the found range of values! Bins can only be correct up to: " << radius << "." << endl);
|
---|
| 129 | }
|
---|
| 130 | binmap = BinData( surfacemap, BinWidth, BinStart, BinEnd );
|
---|
| 131 | OutputCorrelation ( &binoutput, binmap );
|
---|
| 132 | delete TesselStruct; // surfacemap contains refs to triangles! delete here, not earlier!
|
---|
| 133 | delete(binmap);
|
---|
| 134 | delete(surfacemap);
|
---|
| 135 | output.close();
|
---|
| 136 | binoutput.close();
|
---|
| 137 | return Action::success;
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | Action::state_ptr AnalysisSurfaceCorrelationAction::performUndo(Action::state_ptr _state) {
|
---|
| 141 | return Action::success;
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | Action::state_ptr AnalysisSurfaceCorrelationAction::performRedo(Action::state_ptr _state){
|
---|
| 145 | return Action::success;
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 | bool AnalysisSurfaceCorrelationAction::canUndo() {
|
---|
| 149 | return true;
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | bool AnalysisSurfaceCorrelationAction::shouldUndo() {
|
---|
| 153 | return true;
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | const string AnalysisSurfaceCorrelationAction::getName() {
|
---|
| 157 | return NAME;
|
---|
| 158 | }
|
---|