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