From c1e6d2f618e705520f5daab013ddd1c58875d4f9 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Wed, 15 Feb 2006 04:47:35 +0000
Subject: [PATCH] - recompute min/max in view after adaptation - cleanup
 superfluous resets of TimeStepMin/Max

---
 Common/AdaptiveViews.cpp | 18 +++++++++++-------
 Common/Views.cpp         | 12 +++++++++---
 Common/Views.h           | 16 ++++++++--------
 Plugin/Evaluate.cpp      | 10 +---------
 Plugin/ModulusPhase.cpp  | 10 +---------
 Plugin/Remove.cpp        |  6 +-----
 6 files changed, 31 insertions(+), 41 deletions(-)

diff --git a/Common/AdaptiveViews.cpp b/Common/AdaptiveViews.cpp
index c4378cf7c6..540f35a170 100644
--- a/Common/AdaptiveViews.cpp
+++ b/Common/AdaptiveViews.cpp
@@ -846,13 +846,12 @@ void Adaptive_Post_View::setAdaptiveResolutionLevel(Post_View * view,
     view->NbSL = 0;
     view->SL = List_Create(nbelm * 8, nbelm, sizeof(double));
   }
-  if (view->NbVT)
-    {
-      TYP  = 5;
-      List_Delete(view->VT); 
-      view->NbVT = 0;
-      view->VT =List_Create ( nbelm * 36, nbelm , sizeof(double));	
-    }
+  if (view->NbVT) {
+    TYP = 5;
+    List_Delete(view->VT); 
+    view->NbVT = 0;
+    view->VT =List_Create ( nbelm * 36, nbelm , sizeof(double));	
+  }
   if(view->NbST) {
     TYP = 1;
     List_Delete(view->ST);
@@ -917,6 +916,11 @@ void Adaptive_Post_View::setAdaptiveResolutionLevel(Post_View * view,
     if (level_act >= level) break;
     level_act ++;
   }
+
+  // recompute min/max, etc.:
+  view->Min = VAL_INF;
+  view->Max = -VAL_INF;
+  EndView(view, 0, view->FileName, view->Name);
   view->Changed = 1;
   presentZoomLevel = level;
   presentTol = tol;
diff --git a/Common/Views.cpp b/Common/Views.cpp
index af7d83605c..c47d614c54 100644
--- a/Common/Views.cpp
+++ b/Common/Views.cpp
@@ -1,4 +1,4 @@
-// $Id: Views.cpp,v 1.185 2006-02-01 02:11:02 geuzaine Exp $
+// $Id: Views.cpp,v 1.186 2006-02-15 04:47:35 geuzaine Exp $
 //
 // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle
 //
@@ -200,6 +200,8 @@ void Stat_Element(Post_View *v, int type, int nbnod, int N,
   case 0:      // scalar
     if(v->Min == VAL_INF || v->Max == -VAL_INF) {
       v->NbTimeStep = N / nbnod;
+      if(v->TimeStepMin) Free(v->TimeStepMin);
+      if(v->TimeStepMax) Free(v->TimeStepMax);
       v->TimeStepMin = (double*)Malloc(v->NbTimeStep * sizeof(double));
       v->TimeStepMax = (double*)Malloc(v->NbTimeStep * sizeof(double));
       for(i = 0; i < v->NbTimeStep; i++){
@@ -231,6 +233,8 @@ void Stat_Element(Post_View *v, int type, int nbnod, int N,
   case 1:      // vector
     if(v->Min == VAL_INF || v->Max == -VAL_INF) {
       v->NbTimeStep = N / (3 * nbnod);
+      if(v->TimeStepMin) Free(v->TimeStepMin);
+      if(v->TimeStepMax) Free(v->TimeStepMax);
       v->TimeStepMin = (double*)Malloc(v->NbTimeStep * sizeof(double));
       v->TimeStepMax = (double*)Malloc(v->NbTimeStep * sizeof(double));
       for(i = 0; i < v->NbTimeStep; i++){
@@ -262,6 +266,8 @@ void Stat_Element(Post_View *v, int type, int nbnod, int N,
   case 2:      // tensor
     if(v->Min == VAL_INF || v->Max == -VAL_INF) {
       v->NbTimeStep = N / (9 * nbnod);
+      if(v->TimeStepMin) Free(v->TimeStepMin);
+      if(v->TimeStepMax) Free(v->TimeStepMax);
       v->TimeStepMin = (double*)Malloc(v->NbTimeStep * sizeof(double));
       v->TimeStepMax = (double*)Malloc(v->NbTimeStep * sizeof(double));
       for(i = 0; i < v->NbTimeStep; i++){
@@ -356,7 +362,7 @@ void EndView(Post_View * v, int add_in_gui, char *file_name, char *name)
   // elements *AND* free all the data associated with the curved
   // elements
   v->splitCurvedElements();
-
+  
   // Points
   Stat_List(v, v->SP, 0, v->NbSP, 1);
   Stat_List(v, v->VP, 1, v->NbVP, 1);
@@ -454,7 +460,7 @@ void AliasView(int index, int withoptions)
     }
   }
 
-  // When we duplicate a view, we just point to a reference view: we
+  // When we create an alias we just point to a reference view: we
   // DON'T allocate a new data set!
   v2->Time = v1->Time;
   v2->TimeStepMin = v1->TimeStepMin;
diff --git a/Common/Views.h b/Common/Views.h
index da0c1a1dd5..762c5bfda3 100644
--- a/Common/Views.h
+++ b/Common/Views.h
@@ -115,8 +115,8 @@ class Post_View{
   } color;
 
   // dynamic
-  double (*GVFI) (double min, double max, int nb, int index);
-  int (*GIFV) (double min, double max, int nb, double value);
+  double (*GVFI)(double min, double max, int nb, int index);
+  int (*GIFV)(double min, double max, int nb, double value);
   int ExternalElementIndex;
   double ExternalMin, ExternalMax;
   double TmpBBox[6]; // dynamically computed during drawing
@@ -140,14 +140,14 @@ class Post_View{
   // minimal resolution. Then, we can interactively modify the
   // resolution.
   Adaptive_Post_View *adaptive;
-  void setGlobalResolutionLevel (int level)
+  void setGlobalResolutionLevel(int level)
   {
-    if ( adaptive )
+    if (adaptive)
       adaptive->setGlobalResolutionLevel(this, level);
   }
   void setAdaptiveResolutionLevel (int level, GMSH_Post_Plugin *plug = 0)
   {
-    if ( adaptive )
+    if (adaptive)
       adaptive->setAdaptiveResolutionLevel(this, level, plug);
   }
 
@@ -194,8 +194,8 @@ class Post_View{
 int fcmpPostViewNum(const void *v1, const void *v2);
 int fcmpPostViewAliasOf(const void *v1, const void *v2);
 
-Post_View * BeginView (int alloc);
-void EndView (Post_View *v, int AddInUI, char *FileName, char *Name);
+Post_View *BeginView(int alloc);
+void EndView(Post_View *v, int AddInUI, char *FileName, char *Name);
 void AliasView(int num, int withoptions);
 void FreeView(Post_View *v);
 bool RemoveViewByIndex(int index);
@@ -205,7 +205,7 @@ void WriteView(Post_View *v, char *filename, int format, int append);
 void CopyViewOptions(Post_View *src, Post_View *dest);
 void CombineViews(int time, int how, int remove);
 
-int BGMWithView (Post_View *ErrView);
+int BGMWithView(Post_View *ErrView);
 Post_View *Create2DGraph(char *xname, char *yname, int nbdata, double *x, double *y);
 
 GmshColorTable *Get_ColorTable(int num);
diff --git a/Plugin/Evaluate.cpp b/Plugin/Evaluate.cpp
index 5814eb9dda..452d4c7f13 100644
--- a/Plugin/Evaluate.cpp
+++ b/Plugin/Evaluate.cpp
@@ -1,4 +1,4 @@
-// $Id: Evaluate.cpp,v 1.24 2006-01-06 00:34:33 geuzaine Exp $
+// $Id: Evaluate.cpp,v 1.25 2006-02-15 04:47:35 geuzaine Exp $
 //
 // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle
 //
@@ -317,16 +317,8 @@ Post_View *GMSH_EvaluatePlugin::execute(Post_View * v)
   if(_octree) delete _octree;
 
   // recompute min/max, etc.:
-  for(int i = 0; i < v1->NbTimeStep; i++){
-    v1->TimeStepMin[i] = VAL_INF;
-    v1->TimeStepMax[i] = -VAL_INF;
-  }
   v1->Min = VAL_INF;
   v1->Max = -VAL_INF;
-  for(int i = 0; i < 3; i++) {
-    v1->BBox[2 * i] = VAL_INF;
-    v1->BBox[2 * i + 1] = -VAL_INF;
-  }
   EndView(v1, 0, v1->FileName, v1->Name);
 
   return v1;
diff --git a/Plugin/ModulusPhase.cpp b/Plugin/ModulusPhase.cpp
index d1a4f33d09..4293de5b86 100644
--- a/Plugin/ModulusPhase.cpp
+++ b/Plugin/ModulusPhase.cpp
@@ -1,4 +1,4 @@
-// $Id: ModulusPhase.cpp,v 1.2 2006-01-06 00:34:33 geuzaine Exp $
+// $Id: ModulusPhase.cpp,v 1.3 2006-02-15 04:47:35 geuzaine Exp $
 //
 // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle
 //
@@ -142,16 +142,8 @@ Post_View *GMSH_ModulusPhasePlugin::execute(Post_View * v)
   mp(v1->NbSY, v1->SY, 5, 1); mp(v1->NbVY, v1->VY, 5, 3); mp(v1->NbTY, v1->TY, 5, 9);
 
   // recompute min/max, etc.:
-  for(int i = 0; i < v1->NbTimeStep; i++){
-    v1->TimeStepMin[i] = VAL_INF;
-    v1->TimeStepMax[i] = -VAL_INF;
-  }
   v1->Min = VAL_INF;
   v1->Max = -VAL_INF;
-  for(int i = 0; i < 3; i++) {
-    v1->BBox[2 * i] = VAL_INF;
-    v1->BBox[2 * i + 1] = -VAL_INF;
-  }
   char name[1024], filename[1024];
   sprintf(name, "%s_ModulusPhase", v1->Name);
   sprintf(filename, "%s_ModulusPhase.pos", v1->Name);
diff --git a/Plugin/Remove.cpp b/Plugin/Remove.cpp
index e3675a53b6..04d248173f 100644
--- a/Plugin/Remove.cpp
+++ b/Plugin/Remove.cpp
@@ -1,4 +1,4 @@
-// $Id: Remove.cpp,v 1.6 2006-01-06 00:34:33 geuzaine Exp $
+// $Id: Remove.cpp,v 1.7 2006-02-15 04:47:35 geuzaine Exp $
 //
 // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle
 //
@@ -163,10 +163,6 @@ Post_View *GMSH_RemovePlugin::execute(Post_View * v)
   v1->Changed = 1;
 
   // recompute min/max, etc.:
-  for(int i = 0; i < v1->NbTimeStep; i++){
-    v1->TimeStepMin[i] = VAL_INF;
-    v1->TimeStepMax[i] = -VAL_INF;
-  }
   v1->Min = VAL_INF;
   v1->Max = -VAL_INF;
   for(int i = 0; i < 3; i++) {
-- 
GitLab