From fb56354496fc03ebb269472b3391e1a56bba3fa8 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Mon, 16 Mar 2009 07:23:49 +0000
Subject: [PATCH] better code for consistent tri orientation

---
 Mesh/meshGFaceDelaunayInsertion.cpp |  9 ++++----
 Mesh/meshGFaceOptimize.cpp          | 34 ++++++++++++++---------------
 Mesh/meshGFaceOptimize.h            |  3 ++-
 doc/VERSIONS.txt                    |  5 +++--
 4 files changed, 26 insertions(+), 25 deletions(-)

diff --git a/Mesh/meshGFaceDelaunayInsertion.cpp b/Mesh/meshGFaceDelaunayInsertion.cpp
index 2a4298869d..102b11fe5d 100644
--- a/Mesh/meshGFaceDelaunayInsertion.cpp
+++ b/Mesh/meshGFaceDelaunayInsertion.cpp
@@ -646,7 +646,8 @@ void gmshBowyerWatson(GFace *gf)
                        Vs[base->getVertex(2)->getNum()]) / 3.};
       buildMetric(gf, pa, metric);
       circumCenterMetric(worst->tri(), metric, Us, Vs, center, r2);       
-      insertAPoint(gf,AllTris.begin(),center,metric,Us,Vs,vSizes,vSizesBGM,AllTris);
+      insertAPoint(gf, AllTris.begin(), center, metric, Us, Vs, vSizes, vSizesBGM, 
+                   AllTris);
     }
     //     if(ITER % 10== 0){
     //       char name[245];
@@ -654,7 +655,7 @@ void gmshBowyerWatson(GFace *gf)
     //       _printTris (name, AllTris, Us,Vs,false);
     //     }
   }    
-  transferDataStructure(gf, AllTris); 
+  transferDataStructure(gf, AllTris, Us, Vs); 
 }
 
 /*
@@ -791,6 +792,6 @@ void gmshBowyerWatsonFrontal(GFace *gf)
 
   // char name[245];
   // sprintf(name,"frontal%d.pos", gf->tag());
-  // _printTris (name, AllTris, Us,Vs);
-  transferDataStructure(gf, AllTris); 
+  // _printTris (name, AllTris, Us, Vs);
+  transferDataStructure(gf, AllTris, Us, Vs); 
 } 
diff --git a/Mesh/meshGFaceOptimize.cpp b/Mesh/meshGFaceOptimize.cpp
index 9317b2dac3..7bd6005778 100644
--- a/Mesh/meshGFaceOptimize.cpp
+++ b/Mesh/meshGFaceOptimize.cpp
@@ -93,10 +93,11 @@ void buildMeshGenerationDataStructures(GFace *gf,
   connectTriangles(AllTris);
 }
 
-void transferDataStructure(GFace *gf, std::set<MTri3*, compareTri3Ptr> &AllTris)
+void transferDataStructure(GFace *gf, std::set<MTri3*, compareTri3Ptr> &AllTris,
+                           std::vector<double> &Us, std::vector<double> &Vs)
 {
   while (1) {
-    if (AllTris.begin() == AllTris.end() ) break;
+    if (AllTris.begin() == AllTris.end()) break;
     MTri3 *worst = *AllTris.begin();
     if (worst->isDeleted())
       delete worst->tri();
@@ -106,26 +107,23 @@ void transferDataStructure(GFace *gf, std::set<MTri3*, compareTri3Ptr> &AllTris)
     AllTris.erase(AllTris.begin());      
   }
 
-  // make sure all the triangles are oriented in the same way (in
-  // parameter space). FIXME: this is really ugly and slow. JF: we
-  // need to change the actual algorithm to ensure that we create
-  // correctly oriented triangles in the first place
+  // make sure all the triangles are oriented in the same way in
+  // parameter space (it would be nicer to change the actual algorithm
+  // to ensure that we create correctly-oriented triangles in the
+  // first place)
   if(gf->triangles.size() > 1){
-    double u[3], v[3], n1[3], n2[3];
+    double n1[3], n2[3];
     MTriangle *t = gf->triangles[0];
-    SPoint2 uv[3];
-    for(int i = 0; i < 3; i++)
-      reparamMeshVertexOnFace(t->getVertex(i), gf, uv[i]);
-    normal3points(uv[0].x(), uv[0].y(), 0., 
-                  uv[1].x(), uv[1].y(), 0., 
-                  uv[2].x(), uv[2].y(), 0., n1);
+    MVertex *v0 = t->getVertex(0), *v1 = t->getVertex(1), *v2 = t->getVertex(2);
+    normal3points(Us[v0->getNum()], Vs[v0->getNum()], 0.,
+                  Us[v1->getNum()], Vs[v1->getNum()], 0.,
+                  Us[v2->getNum()], Vs[v2->getNum()], 0., n1);
     for(unsigned int j = 1; j < gf->triangles.size(); j++){
       t = gf->triangles[j];
-      for(int i = 0; i < 3; i++)
-        reparamMeshVertexOnFace(t->getVertex(i), gf, uv[i]);
-      normal3points(uv[0].x(), uv[0].y(), 0., 
-                    uv[1].x(), uv[1].y(), 0., 
-                    uv[2].x(), uv[2].y(), 0., n2);
+      v0 = t->getVertex(0); v1 = t->getVertex(1); v2 = t->getVertex(2);
+      normal3points(Us[v0->getNum()], Vs[v0->getNum()], 0.,
+                    Us[v1->getNum()], Vs[v1->getNum()], 0.,
+                    Us[v2->getNum()], Vs[v2->getNum()], 0., n2);
       double pp; prosca(n1, n2, &pp);
       if(pp < 0) t->revert();
     }
diff --git a/Mesh/meshGFaceOptimize.h b/Mesh/meshGFaceOptimize.h
index fb96c8ea83..729740391d 100644
--- a/Mesh/meshGFaceOptimize.h
+++ b/Mesh/meshGFaceOptimize.h
@@ -52,7 +52,8 @@ void buildMeshGenerationDataStructures(GFace *gf,
                                        std::vector<double> &vSizesBGM,
                                        std::vector<double> &Us,
                                        std::vector<double> &Vs);
-void transferDataStructure (GFace *gf, std::set<MTri3*, compareTri3Ptr> &AllTris);
+void transferDataStructure(GFace *gf, std::set<MTri3*, compareTri3Ptr> &AllTris,
+                           std::vector<double> &Us, std::vector<double> &Vs);
 void gmshRecombineIntoQuads(GFace *gf);
 
 struct swapquad{
diff --git a/doc/VERSIONS.txt b/doc/VERSIONS.txt
index 79b58b29ad..ea83933b27 100644
--- a/doc/VERSIONS.txt
+++ b/doc/VERSIONS.txt
@@ -1,9 +1,10 @@
-$Id: VERSIONS.txt,v 1.39 2009-03-15 10:36:40 geuzaine Exp $
+$Id: VERSIONS.txt,v 1.40 2009-03-16 07:23:48 geuzaine Exp $
 
 (?): removed GSL dependency (Gmsh now simply requires Blas and
 Lapack); new per-window visibility; added support for composite window
 printing and background images; fixes for string options in parser;
-fixed surface mesh orientation for Open Cascade models.
+fixed surface mesh orientation for Open Cascade models; fixed triangle
+orientations in Delaunay and Frontal algorithms.
 
 2.3.0 (Jan 23, 2009): major graphics and GUI code refactoring; new
 full-quad/hexa subdivision algorithm (removed Mesh.RecombineAlgo);
-- 
GitLab