1 // Gmsh - Copyright (C) 1997-2021 C. Geuzaine, J.-F. Remacle
2 //
3 // See the LICENSE.txt file in the Gmsh root directory for license information.
4 // Please report all issues on https://gitlab.onelab.info/gmsh/gmsh/issues.
5
6 #include "Isosurface.h"
7 #include "Context.h"
8
9 StringXNumber IsosurfaceOptions_Number[] = {
10 {GMSH_FULLRC, "Value", GMSH_IsosurfacePlugin::callbackValue, 0.},
11 {GMSH_FULLRC, "ExtractVolume", GMSH_IsosurfacePlugin::callbackVol, 0.},
12 {GMSH_FULLRC, "RecurLevel", GMSH_IsosurfacePlugin::callbackRecur, 3},
13 {GMSH_FULLRC, "TargetError", GMSH_IsosurfacePlugin::callbackTarget, 1e-4},
14 {GMSH_FULLRC, "View", nullptr, -1.},
15 {GMSH_FULLRC, "OtherTimeStep", nullptr, -1.},
16 {GMSH_FULLRC, "OtherView", nullptr, -1.}};
17
18 extern "C" {
GMSH_RegisterIsosurfacePlugin()19 GMSH_Plugin *GMSH_RegisterIsosurfacePlugin()
20 {
21 return new GMSH_IsosurfacePlugin();
22 }
23 }
24
callbackValue(int num,int action,double value)25 double GMSH_IsosurfacePlugin::callbackValue(int num, int action, double value)
26 {
27 double min = 0., max = 1.;
28 if(action > 0) {
29 int iview = (int)IsosurfaceOptions_Number[4].def;
30 if(iview < 0) iview = num;
31 if(iview >= 0 && iview < (int)PView::list.size()) {
32 min = PView::list[iview]->getData()->getMin();
33 max = PView::list[iview]->getData()->getMax();
34 }
35 }
36 switch(action) { // configure the input field
37 case 1: return (min - max) / 200.;
38 case 2: return min;
39 case 3: return max;
40 default: break;
41 }
42 return 0.;
43 }
44
callbackVol(int num,int action,double value)45 double GMSH_IsosurfacePlugin::callbackVol(int num, int action, double value)
46 {
47 switch(action) { // configure the input field
48 case 1: return 1.;
49 case 2: return -1.;
50 case 3: return 1.;
51 default: break;
52 }
53 return 0.;
54 }
55
callbackRecur(int num,int action,double value)56 double GMSH_IsosurfacePlugin::callbackRecur(int num, int action, double value)
57 {
58 switch(action) { // configure the input field
59 case 1: return 1.;
60 case 2: return 0.;
61 case 3: return 10.;
62 default: break;
63 }
64 return 0.;
65 }
66
callbackTarget(int num,int action,double value)67 double GMSH_IsosurfacePlugin::callbackTarget(int num, int action, double value)
68 {
69 switch(action) { // configure the input field
70 case 1: return 0.01;
71 case 2: return 0.;
72 case 3: return 1.;
73 default: break;
74 }
75 return 0.;
76 }
77
getHelp() const78 std::string GMSH_IsosurfacePlugin::getHelp() const
79 {
80 return "Plugin(Isosurface) extracts the isosurface of value "
81 "`Value' from the view `View', and draws the "
82 "`OtherTimeStep'-th step of the view `OtherView' on "
83 "this isosurface.\n\n"
84 "If `ExtractVolume' is nonzero, the plugin extracts the "
85 "isovolume with values greater (if `ExtractVolume' > 0) "
86 "or smaller (if `ExtractVolume' < 0) than the isosurface "
87 "`Value'.\n\n"
88 "If `OtherTimeStep' < 0, the plugin uses, for each time "
89 "step in `View', the corresponding time step in `OtherView'. "
90 "If `OtherView' < 0, the plugin uses `View' as the value "
91 "source.\n\n"
92 "If `View' < 0, the plugin is run on the current view.\n\n"
93 "Plugin(Isosurface) creates as many list-based views as there "
94 "are time steps in `View'.";
95 }
96
getNbOptions() const97 int GMSH_IsosurfacePlugin::getNbOptions() const
98 {
99 return sizeof(IsosurfaceOptions_Number) / sizeof(StringXNumber);
100 }
101
getOption(int iopt)102 StringXNumber *GMSH_IsosurfacePlugin::getOption(int iopt)
103 {
104 return &IsosurfaceOptions_Number[iopt];
105 }
106
levelset(double x,double y,double z,double val) const107 double GMSH_IsosurfacePlugin::levelset(double x, double y, double z,
108 double val) const
109 {
110 // we must look into the map for Map(x,y,z) - Value
111 // this is the case when the map is the same as the view,
112 // the result is the extraction of isovalue Value
113 return val - IsosurfaceOptions_Number[0].def;
114 }
115
execute(PView * v)116 PView *GMSH_IsosurfacePlugin::execute(PView *v)
117 {
118 int iView = (int)IsosurfaceOptions_Number[4].def;
119 _valueIndependent = 0;
120 _extractVolume = (int)IsosurfaceOptions_Number[1].def;
121 _recurLevel = (int)IsosurfaceOptions_Number[2].def;
122 _targetError = IsosurfaceOptions_Number[3].def;
123 _valueTimeStep = (int)IsosurfaceOptions_Number[5].def;
124 _valueView = (int)IsosurfaceOptions_Number[6].def;
125 _orientation = GMSH_LevelsetPlugin::MAP;
126
127 PView *v1 = getView(iView, v);
128 if(!v1) return v;
129
130 return GMSH_LevelsetPlugin::execute(v1);
131 }
132