From 72dfacdc77986d41564b2fa7bb2a9e7bbb79efa4 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Fri, 3 Apr 2015 12:58:44 +0000
Subject: [PATCH] new 'visible' option for MinMax

---
 Plugin/Integrate.cpp |  6 +++---
 Plugin/MinMax.cpp    | 17 +++++++++++------
 2 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/Plugin/Integrate.cpp b/Plugin/Integrate.cpp
index 91b8862ac7..a183777199 100644
--- a/Plugin/Integrate.cpp
+++ b/Plugin/Integrate.cpp
@@ -52,7 +52,7 @@ PView *GMSH_IntegratePlugin::execute(PView * v)
   int iView = (int)IntegrateOptions_Number[0].def;
   int overTime = (int)IntegrateOptions_Number[1].def;
   int dimension = (int)IntegrateOptions_Number[2].def;
-  bool checkVisible = (bool)IntegrateOptions_Number[3].def;
+  bool visible = (bool)IntegrateOptions_Number[3].def;
 
   PView *v1 = getView(iView, v);
   if(!v1) return v;
@@ -72,9 +72,9 @@ PView *GMSH_IntegratePlugin::execute(PView * v)
       double res = 0, resv[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
       bool simpleSum = false;
       for(int ent = 0; ent < data1->getNumEntities(step); ent++){
-        if(checkVisible && data1->skipEntity(step, ent)) continue;
+        if(visible && data1->skipEntity(step, ent)) continue;
 	for(int ele = 0; ele < data1->getNumElements(step, ent); ele++){
-	  if(data1->skipElement(step, ent, ele, checkVisible)) continue;
+	  if(data1->skipElement(step, ent, ele, visible)) continue;
 	  int numComp = data1->getNumComponents(step, ent, ele);
 	  int numEdges = data1->getNumEdges(step, ent, ele);
 	  bool scalar = (numComp == 1);
diff --git a/Plugin/MinMax.cpp b/Plugin/MinMax.cpp
index 2ab645f4b0..451798968d 100644
--- a/Plugin/MinMax.cpp
+++ b/Plugin/MinMax.cpp
@@ -9,7 +9,8 @@
 StringXNumber MinMaxOptions_Number[] = {
   {GMSH_FULLRC, "View", NULL, -1.},
   {GMSH_FULLRC, "OverTime", NULL, 0},
-  {GMSH_FULLRC, "Argument", NULL, 0}
+  {GMSH_FULLRC, "Argument", NULL, 0},
+  {GMSH_FULLRC, "Visible", NULL, 1}
 };
 
 extern "C"
@@ -23,9 +24,11 @@ extern "C"
 std::string GMSH_MinMaxPlugin::getHelp() const
 {
   return "Plugin(MinMax) computes the min/max of a view.\n\n"
-    "If `View' < 0, the plugin is run on the current view.\n\n"
-    "If `OverTime' = 1, calculates the min/max over space AND time\n\n"
-    "If `Argument' = 1, calculates the min/max AND the argmin/argmax\n\n"
+    "If `View' < 0, the plugin is run on the current view. "
+    "If `OverTime' = 1, the plugin calculates the min/max over "
+    "space and time. If `Argument' = 1, the plugin calculates the "
+    "min/max and the argmin/argmax. If `Visible' = 1, the plugin "
+    "is only applied to visible entities.\n\n"
     "Plugin(MinMax) creates two new views.";
 }
 
@@ -44,6 +47,7 @@ PView *GMSH_MinMaxPlugin::execute(PView * v)
   int iView = (int)MinMaxOptions_Number[0].def;
   int overTime = (int)MinMaxOptions_Number[1].def;
   int argument = (int)MinMaxOptions_Number[2].def;
+  bool visible = (bool)MinMaxOptions_Number[3].def;
 
   PView *v1 = getView(iView, v);
   if(!v1) return v;
@@ -64,15 +68,16 @@ PView *GMSH_MinMaxPlugin::execute(PView * v)
     dataMax->NbSP = 1;
   }
 
-  double min=VAL_INF, max=-VAL_INF, timeMin=0, timeMax=0;
+  double min = VAL_INF, max = -VAL_INF, timeMin = 0, timeMax = 0;
 
   for(int step = 0; step < data1->getNumTimeSteps(); step++){
     if(data1->hasTimeStep(step)){
-
       double minView = VAL_INF, maxView = -VAL_INF;
       double xmin = 0., ymin = 0., zmin = 0., xmax = 0., ymax = 0., zmax = 0.;
       for(int ent = 0; ent < data1->getNumEntities(step); ent++){
+        if(visible && data1->skipEntity(step, ent)) continue;
 	for(int ele = 0; ele < data1->getNumElements(step, ent); ele++){
+	  if(data1->skipElement(step, ent, ele, visible)) continue;
 	  for(int nod = 0; nod < data1->getNumNodes(step, ent, ele); nod++){
 	    double val;
 	    data1->getScalarValue(step, ent, ele, nod, val);
-- 
GitLab