From 3c7ee0dd9fe5e1fa785f47de16691880dfc80b87 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Thu, 23 Aug 2001 17:19:55 +0000
Subject: [PATCH] *** empty log message ***

---
 Common/DefaultOptions.h              |  2 +
 Common/Options.cpp                   | 15 ++++++-
 Common/Options.h                     |  1 +
 Common/Views.cpp                     | 60 ++++++++++++----------------
 Common/Views.h                       |  1 +
 Graphics/IsoSimplex.cpp              |  6 +--
 Graphics/PostSimplex.cpp             |  8 ++--
 benchmarks/extrude/stator-newxtr.geo |  2 +-
 8 files changed, 52 insertions(+), 43 deletions(-)

diff --git a/Common/DefaultOptions.h b/Common/DefaultOptions.h
index bb45d4bf5a..fe76e48eee 100644
--- a/Common/DefaultOptions.h
+++ b/Common/DefaultOptions.h
@@ -457,6 +457,8 @@ StringXNumber ViewOptions_Number[] = {
     "Draw the N-b dimensional boundary of the simplex (N=dimension, b=option value)" },
   { F|O, "Light" , opt_view_light , 0. ,
     "Enable light sources?" },
+  { F|O, "AngleSmoothNormals" , opt_view_angle_smooth_normals , 15. ,
+    "Treshold angle below which we do not smooth the normals" },
   { F|O, "SmoothNormals" , opt_view_smooth_normals , 0. ,
     "Smooth the normals?" },
   { F|O, "ShowElement" , opt_view_show_element , 0. ,
diff --git a/Common/Options.cpp b/Common/Options.cpp
index 7e45391b98..c932621976 100644
--- a/Common/Options.cpp
+++ b/Common/Options.cpp
@@ -1,4 +1,4 @@
-// $Id: Options.cpp,v 1.40 2001-08-20 07:38:29 geuzaine Exp $
+// $Id: Options.cpp,v 1.41 2001-08-23 17:19:02 geuzaine Exp $
 
 #include "Gmsh.h"
 #include "GmshUI.h"
@@ -1816,6 +1816,19 @@ double opt_view_smooth_normals(OPT_ARGS_NUM){
 #endif
   return v->SmoothNormals;
 }
+
+double opt_view_angle_smooth_normals(OPT_ARGS_NUM){
+  GET_VIEW(0.) ;
+  if(action & GMSH_SET){
+    v->angle_smooth_normals = val;
+    v->Changed = 1;
+  }
+//  #ifdef _FLTK
+//    if(WID && (action & GMSH_GUI) && (num == WID->view_number))
+//      WID->view_butt[27]->value(v->SmoothNormals);
+//  #endif
+  return v->angle_smooth_normals;
+}
 double opt_view_show_element(OPT_ARGS_NUM){
   GET_VIEW(0.) ;
   if(action & GMSH_SET){
diff --git a/Common/Options.h b/Common/Options.h
index 30ed840b5b..9b6eee7a18 100644
--- a/Common/Options.h
+++ b/Common/Options.h
@@ -211,6 +211,7 @@ double opt_view_nb_iso(OPT_ARGS_NUM);
 double opt_view_boundary(OPT_ARGS_NUM);
 double opt_view_light(OPT_ARGS_NUM);
 double opt_view_smooth_normals(OPT_ARGS_NUM);
+double opt_view_angle_smooth_normals(OPT_ARGS_NUM);
 double opt_view_show_element(OPT_ARGS_NUM);
 double opt_view_show_time(OPT_ARGS_NUM);
 double opt_view_show_scale(OPT_ARGS_NUM);
diff --git a/Common/Views.cpp b/Common/Views.cpp
index a4885d6a1e..7d8c7c1f5b 100644
--- a/Common/Views.cpp
+++ b/Common/Views.cpp
@@ -1,4 +1,4 @@
-// $Id: Views.cpp,v 1.51 2001-08-15 06:56:22 geuzaine Exp $
+// $Id: Views.cpp,v 1.52 2001-08-23 17:19:03 geuzaine Exp $
 
 #include <set>
 #include "Gmsh.h"
@@ -403,6 +403,7 @@ void CopyViewOptions(Post_View *src, Post_View *dest){
   dest->NbIso = src->NbIso;
   dest->Light = src->Light ;
   dest->SmoothNormals = src->SmoothNormals ;
+  dest->angle_smooth_normals = src->angle_smooth_normals ;
   dest->ShowElement = src->ShowElement;
   dest->ShowTime = src->ShowTime;
   dest->ShowScale = src->ShowScale;
@@ -731,7 +732,7 @@ void xyzv::update (int n, double *v){
 // (eps2) de p2.val, et qui renvoie le xyzv qui a le xyz dans eps ET
 // val eps2... Sinon, pour un smoothing de normales, les "coins"
 // deviennent de la bouillie.
-
+/*
 struct lessthanxyzv{
   bool operator () (const xyzv & p2, const xyzv &p1) const{
     if( p1.x - p2.x > xyzv::eps)return true;
@@ -742,9 +743,10 @@ struct lessthanxyzv{
     return false;  
   }
 };
-/*
-double angle (double * aa, double * bb){
-  double angplan, cosc, sinc, a[3],b[3],c[3];
+*/
+
+double angle_normals (double * aa, double * bb){ 
+ double angplan, cosc, sinc, a[3],b[3],c[3];
   if(!aa || !bb) return 0.;
   a[0] = aa[0];
   a[1] = aa[1];
@@ -760,6 +762,7 @@ double angle (double * aa, double * bb){
   angplan = myatan2 (sinc, cosc);
   return angplan*180./Pi;
 }
+
 struct lessthanxyzv{
   bool operator () (const xyzv & p2, const xyzv &p1) const{
     if( p1.x - p2.x > xyzv::eps)return true;
@@ -768,12 +771,9 @@ struct lessthanxyzv{
     if( p1.y - p2.y <-xyzv::eps)return false;
     if( p1.z - p2.z > xyzv::eps)return true;
     if( p1.z - p2.z <-xyzv::eps)return false;
-    double a = angle(p1.vals,p2.vals);
-    if( a < 30 ) return true;
     return false;
   }
 };
-*/
 
 typedef set<xyzv,lessthanxyzv> mycont;
 typedef mycont::const_iterator iter;
@@ -868,9 +868,12 @@ void Post_View :: reset_normals(){
 void Post_View :: add_normal(double x, double y, double z, 
 			     double nx, double ny, double nz){
   if(!normals) normals = new smooth_container;
-  xyzv xyz(x,y,z);
+
   double n[3] = {nx,ny,nz};
+  xyzv xyz(x,y,z);
+
   iter it = normals->c.find(xyz);
+
   if(it == normals->c.end()){
     xyz.update(3,n);
     normals->c.insert(xyz);
@@ -880,39 +883,28 @@ void Post_View :: add_normal(double x, double y, double z,
     xx->update(3,n);
   }
 }
-/*
-void Post_View :: add_normal(double x, double y, double z, 
-			     double nx, double ny, double nz){
-  if(!normals) normals = new smooth_container;
-  double *n = new double[3];
-  n[0] = nx;
-  n[1] = ny;
-  n[2] = nz;
-  xyzv xyz(x,y,z,n);
-  iter it = normals->c.find(xyz);
 
-  xyzv xyz2(x,y,z);
-  double n2[3]={nx,ny,nz};
 
-  if(it == normals->c.end()){
-    xyz2.update(3,n2);
-    normals->c.insert(xyz2);
-  }
-  else{
-    xyzv *xx = (xyzv*) &(*it); 
-    xx->update(3,n);
-  }
-}
-*/
 bool Post_View :: get_normal(double x, double y, double z, 
 			     double &nx, double &ny, double &nz){
   if(!normals) return false;
+
+  double n[3] = {nx,ny,nz};
   xyzv xyz(x,y,z);
+
   iter it = normals->c.find(xyz);
+
   if(it == normals->c.end()) return false;
-  nx = (*it).vals[0];
-  ny = (*it).vals[1];
-  nz = (*it).vals[2];
+
+  double angle = angle_normals ((*it).vals, n);
+
+  if(fabs(angle) < angle_smooth_normals)
+    {
+      nx = (*it).vals[0];
+      ny = (*it).vals[1];
+      nz = (*it).vals[2];
+    }
+
   return true;
 }
 
diff --git a/Common/Views.h b/Common/Views.h
index 9c0ffa5383..e83a426404 100644
--- a/Common/Views.h
+++ b/Common/Views.h
@@ -30,6 +30,7 @@ class Post_View{
   double CustomMin, CustomMax;
   double Offset[3], Raise[3], ArrowScale, Explode;
   int Visible, IntervalsType, NbIso, Light, SmoothNormals ;
+  double angle_smooth_normals;
   int SaturateValues;
   int ShowElement, ShowTime, ShowScale;
   int TransparentScale, ScaleType, RangeType;
diff --git a/Graphics/IsoSimplex.cpp b/Graphics/IsoSimplex.cpp
index e2fdfa36e7..ecaa568547 100644
--- a/Graphics/IsoSimplex.cpp
+++ b/Graphics/IsoSimplex.cpp
@@ -96,11 +96,11 @@ void EnhanceSimplexPolygon (Post_View *View,
     }
     else{
       for(i=0;i<nb;i++){
+	norms[3*i] = n[0];
+	norms[3*i+1] = n[1];
+	norms[3*i+2] = n[2];
 	if(!View->get_normal(Xp[i],Yp[i],Zp[i],norms[3*i],norms[3*i+1],norms[3*i+2])){
 	  //Msg(WARNING, "Oups, did not find smoothed normal");
-	  norms[3*i] = n[0];
-	  norms[3*i+1] = n[1];
-	  norms[3*i+2] = n[2];
 	}	      
       }	  
     }
diff --git a/Graphics/PostSimplex.cpp b/Graphics/PostSimplex.cpp
index ebdefcf01f..3c85a266a6 100644
--- a/Graphics/PostSimplex.cpp
+++ b/Graphics/PostSimplex.cpp
@@ -1,4 +1,4 @@
-// $Id: PostSimplex.cpp,v 1.29 2001-08-11 23:28:32 geuzaine Exp $
+// $Id: PostSimplex.cpp,v 1.30 2001-08-23 17:19:06 geuzaine Exp $
 
 #include "Gmsh.h"
 #include "GmshUI.h"
@@ -252,12 +252,12 @@ void Draw_ScalarTriangle(Post_View *View, int preproNormals,
       }
       else{
 	for(i=0;i<3;i++){
+	  norms[3*i] = nn[0];
+	  norms[3*i+1] = nn[1];
+	  norms[3*i+2] = nn[2];
 	  if(!View->get_normal(X[i]+Raise[0][i],Y[i]+Raise[1][i],Z[i]+Raise[2][i],
 			       norms[3*i],norms[3*i+1],norms[3*i+2])){
 	    Msg(WARNING, "Oups, did not find smoothed normal");
-	    norms[3*i] = nn[0];
-	    norms[3*i+1] = nn[1];
-	    norms[3*i+2] = nn[2];
 	  }
 	}
       }
diff --git a/benchmarks/extrude/stator-newxtr.geo b/benchmarks/extrude/stator-newxtr.geo
index fd7f5c85e6..2a61217ec0 100644
--- a/benchmarks/extrude/stator-newxtr.geo
+++ b/benchmarks/extrude/stator-newxtr.geo
@@ -118,7 +118,7 @@ Extrude Surface {235, {0,0,1}, {0,0,0}, Pi/180}{
 // 2nd pizeo
 
 Extrude Surface {257, {0,0,1}, {0,0,0}, Pi/2-Pi/180}{
- Layers { {1,1,1,nArc,1,1,1}, {9001,9001,9001,9001,9001,9001,9001,9001}, {0.02, 0.05, 0.09, 0.91, 0.95, 0.98, 1} } ;
+ Layers { {1,1,1,nArc,1,1,1}, {9001,9001,9001,9001,9001,9001,9001}, {0.02, 0.05, 0.09, 0.91, 0.95, 0.98, 1} } ;
 };
 Extrude Surface {279, {0,0,1}, {0,0,0}, Pi/2-Pi/180}{
  Layers { {1,1,1,nArc,1,1,1}, {9005, 9005,9005,9005, 9005,9005,9005}, {0.02, 0.05, 0.09, 0.91, 0.95, 0.98, 1} } ;
-- 
GitLab