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