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"
|
---|
11 | #include "Actions/ActionRegistry.hpp"
|
---|
12 | #include "analysis_correlation.hpp"
|
---|
13 | #include "boundary.hpp"
|
---|
14 | #include "linkedcell.hpp"
|
---|
15 | #include "Helpers/Verbose.hpp"
|
---|
16 | #include "Helpers/Log.hpp"
|
---|
17 | #include "element.hpp"
|
---|
18 | #include "molecule.hpp"
|
---|
19 | #include "periodentafel.hpp"
|
---|
20 | #include "tesselation.hpp"
|
---|
21 | #include "LinearAlgebra/Vector.hpp"
|
---|
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"
|
---|
31 | #include "Actions/ValueStorage.hpp"
|
---|
32 |
|
---|
33 | const char AnalysisSurfaceCorrelationAction::NAME[] = "surface-correlation";
|
---|
34 |
|
---|
35 | AnalysisSurfaceCorrelationAction::AnalysisSurfaceCorrelationAction() :
|
---|
36 | Action(NAME)
|
---|
37 | {}
|
---|
38 |
|
---|
39 | AnalysisSurfaceCorrelationAction::~AnalysisSurfaceCorrelationAction()
|
---|
40 | {}
|
---|
41 |
|
---|
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 |
|
---|
55 | Dialog* AnalysisSurfaceCorrelationAction::fillDialog(Dialog *dialog) {
|
---|
56 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
57 |
|
---|
58 | dialog->queryMolecule("molecule-by-id", ValueStorage::getInstance().getDescription("molecule-by-id"));
|
---|
59 | dialog->queryElements("elements", ValueStorage::getInstance().getDescription("elements"));
|
---|
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"));
|
---|
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;
|
---|
81 | std::vector<const element *> elements;
|
---|
82 | string type;
|
---|
83 | Vector Point;
|
---|
84 | BinPairMap *binmap = NULL;
|
---|
85 |
|
---|
86 | // obtain information
|
---|
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);
|
---|
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
|
---|
113 | std::vector<molecule*> molecules = World::getInstance().getSelectedMolecules();
|
---|
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 | }
|
---|