From 1362e005ab21dbdf072e44d44edaaf97db11bf72 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Tue, 5 Feb 2008 15:59:35 +0000
Subject: [PATCH] - fixed embedded version - removed OCC STL meshgen for now
 (OCC/triangle clashes with our own version of triangle)

---
 Geo/GFace.cpp             |   9 +--
 Geo/GFace.h               |   7 +-
 Geo/OCCFace.cpp           | 138 ++++++++++++++++++--------------------
 Graphics/Geom.cpp         |   6 +-
 Graphics/Mesh.cpp         |   4 +-
 demos/sphere-discrete.geo |   2 +-
 6 files changed, 82 insertions(+), 84 deletions(-)

diff --git a/Geo/GFace.cpp b/Geo/GFace.cpp
index 4782cf9f19..1eb708fba2 100644
--- a/Geo/GFace.cpp
+++ b/Geo/GFace.cpp
@@ -1,4 +1,4 @@
-// $Id: GFace.cpp,v 1.43 2008-02-05 14:40:29 remacle Exp $
+// $Id: GFace.cpp,v 1.44 2008-02-05 15:59:34 geuzaine Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
@@ -23,13 +23,13 @@
 #include "GFace.h"
 #include "GEdge.h"
 #include "MElement.h"
-#include "VertexArray.h"
 
 #if defined(HAVE_GMSH_EMBEDDED)
 #  include "GmshEmbedded.h"
 #else
 #  include "Message.h"
 #  include "Numeric.h"
+#  include "VertexArray.h"
 #  include "Context.h"
 #  if defined(HAVE_GSL)
 #    include <gsl/gsl_vector.h>
@@ -43,7 +43,8 @@ void dsvdcmp(double **a, int m, int n, double w[], double **v);
 
 extern Context_T CTX;
 
-GFace::GFace(GModel *model, int tag) : GEntity(model, tag), r1(0), r2(0), va_geom_triangles(0)
+GFace::GFace(GModel *model, int tag) 
+  : GEntity(model, tag), r1(0), r2(0), va_geom_triangles(0)
 {
   meshStatistics.status = GFace::PENDING;
   resetMeshAttributes();
@@ -67,7 +68,7 @@ GFace::~GFace()
   for(unsigned int i = 0; i < quadrangles.size(); i++) 
     delete quadrangles[i];
 
-  if (va_geom_triangles)
+  if(va_geom_triangles)
     delete va_geom_triangles;
 }
 
diff --git a/Geo/GFace.h b/Geo/GFace.h
index 34399563e0..b985de3e0c 100644
--- a/Geo/GFace.h
+++ b/Geo/GFace.h
@@ -73,9 +73,9 @@ class GFace : public GEntity
   // i.e. closed edge loops.  the first wire is the one that is the
   // outer contour of the face.
   void resolveWires();
-  // builds a STL triangulation and fill the vertex array va_geom_triangles
-  // by default, do nothing
-  virtual bool buildSTLTriangulation () {return false;}
+  // builds a STL triangulation and fill the vertex array
+  // va_geom_triangles (by default, do nothing)
+  virtual bool buildSTLTriangulation () { return false; }
  public:
   GFace(GModel *model, int tag);
   virtual ~GFace();
@@ -210,7 +210,6 @@ class GFace : public GEntity
 
   // Vertex array to draw the geometry efficiently
   VertexArray *va_geom_triangles;
-
 };
 
 #endif
diff --git a/Geo/OCCFace.cpp b/Geo/OCCFace.cpp
index 9903385554..677278353c 100644
--- a/Geo/OCCFace.cpp
+++ b/Geo/OCCFace.cpp
@@ -1,4 +1,4 @@
-// $Id: OCCFace.cpp,v 1.29 2008-02-05 14:40:29 remacle Exp $
+// $Id: OCCFace.cpp,v 1.30 2008-02-05 15:59:34 geuzaine Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
@@ -38,7 +38,8 @@
 #include "Geom_BezierSurface.hxx"
 #include "Geom_Plane.hxx"
 #include "gp_Pln.hxx"
-#include "BRepMesh_FastDiscret.hxx"
+// FIX THIS WHEN TRIANGLE IS GONE
+//#include "BRepMesh_FastDiscret.hxx"
 
 OCCFace::OCCFace(GModel *m, TopoDS_Face _s, int num, TopTools_IndexedMapOfShape &emap)
   : GFace(m, num), s(_s)
@@ -274,80 +275,75 @@ surface_params OCCFace::getSurfaceParams() const
   return p;
 }
 
-
-bool OCCFace::buildSTLTriangulation ()
+bool OCCFace::buildSTLTriangulation()
 {
-
-  if (va_geom_triangles){
+  // FIX THIS WHEN TRIANGLE IS GONE
+  return false;
+  /*
+  if(va_geom_triangles){
     delete va_geom_triangles;
     va_geom_triangles = 0;
   }
-
-   TopLoc_Location loc;
-   int p1,p2,p3;
-   Bnd_Box aBox;
-   Standard_Boolean bWithShare;
-   Standard_Real aDiscret, aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
-   Standard_Real dX, dY, dZ, dMax, aCoeff, aAngle;     
-   BRepBndLib::Add(s, aBox);
-   aBox.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
+  
+  TopLoc_Location loc;
+  int p1, p2, p3;
+  Bnd_Box aBox;
+  Standard_Boolean bWithShare;
+  Standard_Real aDiscret, aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
+  Standard_Real dX, dY, dZ, dMax, aCoeff, aAngle;     
+  BRepBndLib::Add(s, aBox);
+  aBox.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
    
-   //   if (tag() > 100)return;
-   dX=aXmax-aXmin;
-   dY=aYmax-aYmin;
-   dZ=aZmax-aZmin;
-   dMax=dX;
-   if (dY>dMax) {
-     dMax=dY;
-   }
-   if (dZ>dMax) {
-     dMax=dZ;
-   }
-   //
-   aCoeff=0.01;
-   aDiscret=aCoeff*dMax;     
-   BRepMesh_FastDiscret aMesher(aDiscret,
-				0.5,
-				aBox,
-				bWithShare,
-				Standard_True,
-				Standard_False,
-				Standard_True);
-   aMesher.Add(s);
-   Handle(Poly_Triangulation) triangulation = BRep_Tool::Triangulation (s, loc);
-   if (triangulation.IsNull()){
-     Msg(WARNING,"OCC STL triangulation failed!\n");    //     return;
-     return false;
-   }
-
-   int ntriangles = triangulation -> NbTriangles();
-   if (!triangulation->HasUVNodes())
-     return false;
-   va_geom_triangles  = new VertexArray(3,ntriangles);
-
-
-   unsigned int c = CTX.color.geom.surface;
-   unsigned int col[4] = {c, c, c, c};
-   for (int j = 1; j <= ntriangles; j++){
-     Poly_Triangle triangle = (triangulation -> Triangles())(j);
-     triangle.Get (p1,p2,p3);
-     gp_Pnt2d x1 = (triangulation->UVNodes())(p1);
-     gp_Pnt2d x2 = (triangulation->UVNodes())(p2);
-     gp_Pnt2d x3 = (triangulation->UVNodes())(p3);
-     GPoint gp1 = point (x1.X(),x1.Y());
-     GPoint gp2 = point (x2.X(),x2.Y());
-     GPoint gp3 = point (x3.X(),x3.Y());
-     SVector3 n[3];
-     n[0] = normal (SPoint2(x1.X(),x1.Y()));
-     n[1] = normal (SPoint2(x2.X(),x2.Y()));
-     n[2] = normal (SPoint2(x3.X(),x3.Y()));
-     double x[3] = {gp1.x(),gp2.x(),gp3.x()};
-     double y[3] = {gp1.y(),gp2.y(),gp3.y()};
-     double z[3] = {gp1.z(),gp2.z(),gp3.z()};
-     va_geom_triangles->add (x,y,z,n,col);
-   }  
-   va_geom_triangles->finalize();
-   return true;
+  dX = aXmax-aXmin;
+  dY = aYmax-aYmin;
+  dZ = aZmax-aZmin;
+  dMax = dX;
+  if(dY > dMax) {
+    dMax = dY;
+  }
+  if(dZ > dMax) {
+    dMax = dZ;
+  }
+  //
+  aCoeff = 0.01;
+  aDiscret = aCoeff * dMax;
+  BRepMesh_FastDiscret aMesher(aDiscret, 0.5, aBox, bWithShare, Standard_True,
+			       Standard_False, Standard_True);
+  aMesher.Add(s);
+  Handle(Poly_Triangulation) triangulation = BRep_Tool::Triangulation(s, loc);
+  if (triangulation.IsNull()){
+    Msg(WARNING,"OCC STL triangulation failed");
+    return false;
+  }
+  
+  int ntriangles = triangulation->NbTriangles();
+  if(!triangulation->HasUVNodes()) return false;
+
+  va_geom_triangles = new VertexArray(3, ntriangles);
+  
+  unsigned int c = CTX.color.geom.surface;
+  unsigned int col[4] = {c, c, c, c};
+  for (int j = 1; j <= ntriangles; j++){
+    Poly_Triangle triangle = (triangulation->Triangles())(j);
+    triangle.Get(p1,p2,p3);
+    gp_Pnt2d x1 = (triangulation->UVNodes())(p1);
+    gp_Pnt2d x2 = (triangulation->UVNodes())(p2);
+    gp_Pnt2d x3 = (triangulation->UVNodes())(p3);
+    GPoint gp1 = point(x1.X(), x1.Y());
+    GPoint gp2 = point(x2.X(), x2.Y());
+    GPoint gp3 = point(x3.X(), x3.Y());
+    SVector3 n[3];
+    n[0] = normal(SPoint2(x1.X(), x1.Y()));
+    n[1] = normal(SPoint2(x2.X(), x2.Y()));
+    n[2] = normal(SPoint2(x3.X(), x3.Y()));
+    double x[3] = {gp1.x(), gp2.x(), gp3.x()};
+    double y[3] = {gp1.y(), gp2.y(), gp3.y()};
+    double z[3] = {gp1.z(), gp2.z(), gp3.z()};
+    va_geom_triangles->add(x, y, z, n, col);
+  }  
+  va_geom_triangles->finalize();
+  return true;
+  */
 }
 
 #endif
diff --git a/Graphics/Geom.cpp b/Graphics/Geom.cpp
index 4be7623dfa..251096419f 100644
--- a/Graphics/Geom.cpp
+++ b/Graphics/Geom.cpp
@@ -1,4 +1,4 @@
-// $Id: Geom.cpp,v 1.146 2008-02-05 14:40:30 remacle Exp $
+// $Id: Geom.cpp,v 1.147 2008-02-05 15:59:34 geuzaine Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
@@ -202,6 +202,7 @@ class drawGEdge {
 
 void drawArrays(GEntity *e, VertexArray *va, GLint type, bool useNormalArray, 
 		int forceColor=0, unsigned int color=0);
+
 class drawGFace {
  private:
   void _drawNonPlaneGFace(GFace *f)
@@ -447,7 +448,8 @@ public :
     }
 
     if(f->va_geom_triangles)
-      drawArrays(f, f->va_geom_triangles, GL_TRIANGLES, CTX.geom.light, CTX.geom.surfaces,CTX.color.geom.surface);
+      drawArrays(f, f->va_geom_triangles, GL_TRIANGLES, CTX.geom.light, 
+		 CTX.geom.surfaces, CTX.color.geom.surface);
     else if(f->geomType() == GEntity::Plane)
       _drawPlaneGFace(f);
     else if(f->geomType() == GEntity::ProjectionFace ||
diff --git a/Graphics/Mesh.cpp b/Graphics/Mesh.cpp
index 80ff495a6a..3c8b9306e4 100644
--- a/Graphics/Mesh.cpp
+++ b/Graphics/Mesh.cpp
@@ -1,4 +1,4 @@
-// $Id: Mesh.cpp,v 1.212 2008-02-05 14:40:30 remacle Exp $
+// $Id: Mesh.cpp,v 1.213 2008-02-05 15:59:34 geuzaine Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
@@ -441,7 +441,7 @@ static void addElementsInArrays(GEntity *e, std::vector<T*> &elements,
 }
 
 void drawArrays(GEntity *e, VertexArray *va, GLint type, bool useNormalArray, 
-		       int forceColor=0, unsigned int color=0)
+		int forceColor=0, unsigned int color=0)
 {
   if(!va) return;
 
diff --git a/demos/sphere-discrete.geo b/demos/sphere-discrete.geo
index a6f8a929e9..6f9a16757a 100644
--- a/demos/sphere-discrete.geo
+++ b/demos/sphere-discrete.geo
@@ -1,4 +1,4 @@
-// merge a surface mesh
+// merge a surface mesh (any format will work: .msh, .unv, etc.)
 
 Merge "sphere-surf.stl";
 
-- 
GitLab