| [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"
 | 
|---|
 | 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"
 | 
|---|
| [9d33ba] | 30 | #include "UIElements/ValueStorage.hpp"
 | 
|---|
| [d02e07] | 31 | 
 | 
|---|
 | 32 | const char AnalysisSurfaceCorrelationAction::NAME[] = "surface-correlation";
 | 
|---|
 | 33 | 
 | 
|---|
 | 34 | AnalysisSurfaceCorrelationAction::AnalysisSurfaceCorrelationAction() :
 | 
|---|
 | 35 |   Action(NAME)
 | 
|---|
 | 36 | {}
 | 
|---|
 | 37 | 
 | 
|---|
 | 38 | AnalysisSurfaceCorrelationAction::~AnalysisSurfaceCorrelationAction()
 | 
|---|
 | 39 | {}
 | 
|---|
 | 40 | 
 | 
|---|
| [b31cfa] | 41 | void AnalysisSurfaceCorrelation(std::vector< element *> &elements, molecule *mol, double BinStart, double BinWidth, double BinEnd, std::string &outputname, std::string &binoutputname, bool periodic) {
 | 
|---|
 | 42 |   ValueStorage::getInstance().setCurrentValue("elements", elements);
 | 
|---|
 | 43 |   ValueStorage::getInstance().setCurrentValue("molecule-by-id", mol);
 | 
|---|
 | 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(AnalysisSurfaceCorrelationAction::NAME)->call(Action::NonInteractive);
 | 
|---|
 | 51 | };
 | 
|---|
 | 52 | 
 | 
|---|
 | 53 | 
 | 
|---|
| [047878] | 54 | Dialog* AnalysisSurfaceCorrelationAction::fillDialog(Dialog *dialog) {
 | 
|---|
 | 55 |   ASSERT(dialog,"No Dialog given when filling action dialog");
 | 
|---|
| [d02e07] | 56 | 
 | 
|---|
| [9d33ba] | 57 |   dialog->queryMolecule("molecule-by-id", ValueStorage::getInstance().getDescription("molecule-by-id"));
 | 
|---|
| [e65de8] | 58 |   dialog->queryElements("elements", ValueStorage::getInstance().getDescription("elements"));
 | 
|---|
| [9d33ba] | 59 |   dialog->queryDouble("bin-start", ValueStorage::getInstance().getDescription("bin-start"));
 | 
|---|
 | 60 |   dialog->queryDouble("bin-width", ValueStorage::getInstance().getDescription("bin-width"));
 | 
|---|
 | 61 |   dialog->queryDouble("bin-end", ValueStorage::getInstance().getDescription("bin-end"));
 | 
|---|
 | 62 |   dialog->queryString("output-file", ValueStorage::getInstance().getDescription("output-file"));
 | 
|---|
 | 63 |   dialog->queryString("bin-output-file", ValueStorage::getInstance().getDescription("bin-output-file"));
 | 
|---|
 | 64 |   dialog->queryBoolean("periodic", ValueStorage::getInstance().getDescription("periodic"));
 | 
|---|
| [d02e07] | 65 | 
 | 
|---|
 | 66 |   return dialog;
 | 
|---|
 | 67 | }
 | 
|---|
 | 68 | 
 | 
|---|
 | 69 | Action::state_ptr AnalysisSurfaceCorrelationAction::performCall() {
 | 
|---|
 | 70 |   int ranges[3] = {1, 1, 1};
 | 
|---|
 | 71 |   double BinEnd = 0.;
 | 
|---|
 | 72 |   double BinStart = 0.;
 | 
|---|
 | 73 |   double BinWidth = 0.;
 | 
|---|
 | 74 |   molecule *Boundary = NULL;
 | 
|---|
 | 75 |   string outputname;
 | 
|---|
 | 76 |   string binoutputname;
 | 
|---|
 | 77 |   bool periodic;
 | 
|---|
 | 78 |   ofstream output;
 | 
|---|
 | 79 |   ofstream binoutput;
 | 
|---|
 | 80 |   std::vector< element *> elements;
 | 
|---|
 | 81 |   string type;
 | 
|---|
 | 82 |   Vector Point;
 | 
|---|
 | 83 |   BinPairMap *binmap = NULL;
 | 
|---|
 | 84 | 
 | 
|---|
 | 85 |   // obtain information
 | 
|---|
| [9d33ba] | 86 |   ValueStorage::getInstance().queryCurrentValue("molecule-by-id", Boundary);
 | 
|---|
 | 87 |   ValueStorage::getInstance().queryCurrentValue("elements", elements);
 | 
|---|
 | 88 |   ValueStorage::getInstance().queryCurrentValue("bin-start", BinStart);
 | 
|---|
 | 89 |   ValueStorage::getInstance().queryCurrentValue("bin-width", BinWidth);
 | 
|---|
 | 90 |   ValueStorage::getInstance().queryCurrentValue("bin-end", BinEnd);
 | 
|---|
 | 91 |   ValueStorage::getInstance().queryCurrentValue("output-file", outputname);
 | 
|---|
 | 92 |   ValueStorage::getInstance().queryCurrentValue("bin-output-file", binoutputname);
 | 
|---|
 | 93 |   ValueStorage::getInstance().queryCurrentValue("periodic", periodic);
 | 
|---|
| [d02e07] | 94 | 
 | 
|---|
 | 95 |   // execute action
 | 
|---|
 | 96 |   output.open(outputname.c_str());
 | 
|---|
 | 97 |   binoutput.open(binoutputname.c_str());
 | 
|---|
 | 98 |   ASSERT(Boundary != NULL, "No molecule specified for SurfaceCorrelation.");
 | 
|---|
 | 99 |   const double radius = 4.;
 | 
|---|
 | 100 |   double LCWidth = 20.;
 | 
|---|
 | 101 |   if (BinEnd > 0) {
 | 
|---|
 | 102 |     if (BinEnd > 2.*radius)
 | 
|---|
 | 103 |       LCWidth = BinEnd;
 | 
|---|
 | 104 |     else
 | 
|---|
 | 105 |       LCWidth = 2.*radius;
 | 
|---|
 | 106 |   }
 | 
|---|
 | 107 | 
 | 
|---|
 | 108 |   // get the boundary
 | 
|---|
 | 109 |   class Tesselation *TesselStruct = NULL;
 | 
|---|
 | 110 |   const LinkedCell *LCList = NULL;
 | 
|---|
 | 111 |   // find biggest molecule
 | 
|---|
| [e65de8] | 112 |   std::vector<molecule*> molecules = World::getInstance().getSelectedMolecules();
 | 
|---|
 | 113 |   int counter  = molecules.size();
 | 
|---|
| [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 | }
 | 
|---|