From 97fc31756d5b91f84594c631e5fce075a3a48596 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Thu, 8 Oct 2009 09:08:14 +0000
Subject: [PATCH] work on buildSTLTriangulation

---
 Geo/GFace.cpp   | 37 ++++++++++++++++++++++++++++++++-----
 Geo/GFace.h     | 10 ++++++++--
 Geo/OCCFace.cpp | 10 ++++++----
 Geo/OCCFace.h   |  2 +-
 4 files changed, 47 insertions(+), 12 deletions(-)

diff --git a/Geo/GFace.cpp b/Geo/GFace.cpp
index 47770f1c32..deeb7fc2c6 100644
--- a/Geo/GFace.cpp
+++ b/Geo/GFace.cpp
@@ -867,18 +867,23 @@ struct graphics_point{
   SVector3 n;
 };
 
-bool GFace::buildSTLTriangulation()
+bool GFace::buildSTLTriangulation(bool force)
 {
   // Build a simple triangulation for surfaces which we know are not
   // trimmed
   if(geomType() != ParametricSurface && geomType() != ProjectionFace)
     return false;
 
-  const int nu = 64, nv = 64;
-  graphics_point p[nu][nv];
+  if(va_geom_triangles){
+    if(force)
+      delete va_geom_triangles;
+    else
+      return true;
+  }
 
-  if(va_geom_triangles) delete va_geom_triangles;
+  const int nu = 64, nv = 64;
   va_geom_triangles = new VertexArray(3, 2 * (nu - 1) * (nv - 1));
+  graphics_point p[nu][nv];
 
   Range<double> ubounds = parBounds(0);
   Range<double> vbounds = parBounds(1);
@@ -986,9 +991,31 @@ int GFace::genusGeom()
     if ((*it)->isSeam(this)){
       nSeams++;
       std::set<GEdge*>::iterator it2 = single_seams.find(*it);
-      if (it2 != single_seams.end())single_seams.erase(it2);
+      if (it2 != single_seams.end()) single_seams.erase(it2);
       else single_seams.insert(*it);
     }
   }
   return nSeams - single_seams.size();
 }
+
+void GFace::fillPointCloud(double maxDist, std::vector<SPoint3> *points,
+                           std::vector<SVector3> *normals)
+{
+  if(!buildSTLTriangulation()){
+    Msg::Error("No STL triangulation available to fill point cloud");
+    return;
+  }
+
+  bool computePoints = points ? true : false;
+  bool computeNormals = normals ? true : false;
+  if(!computePoints && !computeNormals) return;
+  /*
+  int N = va_geom_triangles->getNumVertices();
+  for (int i = 0; i < N; i += 3) {
+    SPoint3 p((va_geom_triangles->getVertexArray(3 * i))[0],
+              (va_geom_triangles->getVertexArray(3 * i))[1],
+              (va_geom_triangles->getVertexArray(3 * i))[2]);
+  }
+  */
+  
+}
diff --git a/Geo/GFace.h b/Geo/GFace.h
index ac78c14bdb..f6b033a93b 100644
--- a/Geo/GFace.h
+++ b/Geo/GFace.h
@@ -194,8 +194,9 @@ class GFace : public GEntity
   virtual bool buildRepresentationCross();
 
   // build a STL triangulation and fills the vertex array
-  // va_geom_triangles
-  virtual bool buildSTLTriangulation();
+  // va_geom_triangles (or do nothing if it already exists, unless
+  // force=true)
+  virtual bool buildSTLTriangulation(bool force=false);
 
   // recompute the mean plane of the surface from a list of points
   void computeMeanPlane(const std::vector<MVertex*> &points);
@@ -229,6 +230,11 @@ class GFace : public GEntity
   void setCompound(GFaceCompound *gfc) { compound = gfc; }
   GFaceCompound *getCompound() const { return compound; }
 
+  // add points (and optionalluy normals) in vectors so that two
+  // points are at most maxDist apart
+  void fillPointCloud(double maxDist, std::vector<SPoint3> *points,
+                      std::vector<SVector3> *normals);
+
   struct {
     // do we recombine the triangles of the mesh?
     int recombine;
diff --git a/Geo/OCCFace.cpp b/Geo/OCCFace.cpp
index 1e697f5160..96cd08ffd6 100644
--- a/Geo/OCCFace.cpp
+++ b/Geo/OCCFace.cpp
@@ -303,13 +303,15 @@ surface_params OCCFace::getSurfaceParams() const
   return p;
 }
 
-bool OCCFace::buildSTLTriangulation()
+bool OCCFace::buildSTLTriangulation(bool force)
 {
   if(va_geom_triangles){
-    delete va_geom_triangles;
-    va_geom_triangles = 0;
+    if(force)
+      delete va_geom_triangles;
+    else
+      return true;
   }
-  
+
   TopLoc_Location loc;
   int p1, p2, p3;
   Bnd_Box aBox;
diff --git a/Geo/OCCFace.h b/Geo/OCCFace.h
index e84bed22b3..863d184ea2 100644
--- a/Geo/OCCFace.h
+++ b/Geo/OCCFace.h
@@ -21,7 +21,7 @@ class OCCFace : public GFace {
   Handle(Geom_Surface) occface;
   double umin, umax, vmin, vmax;
   bool _periodic[2];
-  bool buildSTLTriangulation();
+  bool buildSTLTriangulation(bool force=false);
  public:
   OCCFace(GModel *m, TopoDS_Face s, int num, TopTools_IndexedMapOfShape &emap);
   virtual ~OCCFace(){}
-- 
GitLab