From f76e2f79eedf001cc5a1153e72c992acf8bdc9e6 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Fri, 20 Mar 2015 15:09:57 +0000
Subject: [PATCH] surface extrusions now handle embedded points/edges

---
 Geo/GFace.cpp                | 20 ++++++++++++++++++++
 Geo/GFace.h                  |  4 +++-
 Mesh/meshGFaceExtruded.cpp   | 16 ++++++++++++----
 Mesh/meshGRegionExtruded.cpp | 15 ++++++++++++---
 4 files changed, 47 insertions(+), 8 deletions(-)

diff --git a/Geo/GFace.cpp b/Geo/GFace.cpp
index 2363410532..dd32bae429 100644
--- a/Geo/GFace.cpp
+++ b/Geo/GFace.cpp
@@ -276,6 +276,26 @@ surface_params GFace::getSurfaceParams() const
   return p;
 }
 
+std::vector<MVertex*> GFace::getEmbeddedMeshVertices() const
+{
+  std::set<MVertex*> tmp;
+  for(std::list<GEdge *>::const_iterator it = embedded_edges.begin();
+      it != embedded_edges.end(); it++){
+    tmp.insert((*it)->mesh_vertices.begin(), (*it)->mesh_vertices.end());
+    tmp.insert((*it)->getBeginVertex()->mesh_vertices.begin(),
+               (*it)->getBeginVertex()->mesh_vertices.end());
+    tmp.insert((*it)->getEndVertex()->mesh_vertices.begin(),
+               (*it)->getEndVertex()->mesh_vertices.end());
+  }
+  for(std::list<GVertex *>::const_iterator it = embedded_vertices.begin();
+      it != embedded_vertices.end(); it++){
+    tmp.insert((*it)->mesh_vertices.begin(), (*it)->mesh_vertices.end());
+  }
+  std::vector<MVertex*> res;
+  res.insert(res.end(), tmp.begin(), tmp.end());
+  return res;
+}
+
 std::list<GVertex*> GFace::vertices() const
 {
   std::set<GVertex*> v;
diff --git a/Geo/GFace.h b/Geo/GFace.h
index ec2d27231a..a4432a81ec 100644
--- a/Geo/GFace.h
+++ b/Geo/GFace.h
@@ -67,7 +67,7 @@ class GFace : public GEntity
   // vertices are classifed on this GFace, their type is MFaceVertex.
   // After mesh generation, those are moved to the mesh_vertices array
   std::vector<MVertex*> additionalVertices;
-  
+
  public:
   GFace(GModel *model, int tag);
   virtual ~GFace();
@@ -121,6 +121,8 @@ class GFace : public GEntity
   // edges that are embedded in the face
   virtual std::list<GVertex*> embeddedVertices() const { return embedded_vertices; }
 
+  std::vector<MVertex*> getEmbeddedMeshVertices() const;
+
   // vertices that bound the face
   virtual std::list<GVertex*> vertices() const;
 
diff --git a/Mesh/meshGFaceExtruded.cpp b/Mesh/meshGFaceExtruded.cpp
index bbcc3a651d..6aea9520ed 100644
--- a/Mesh/meshGFaceExtruded.cpp
+++ b/Mesh/meshGFaceExtruded.cpp
@@ -152,9 +152,16 @@ static void copyMesh(GFace *from, GFace *to, MVertexRTree &pos)
 {
   ExtrudeParams *ep = to->meshAttributes.extrude;
 
-  // create vertices
-  for(unsigned int i = 0; i < from->mesh_vertices.size(); i++){
-    MVertex *v = from->mesh_vertices[i];
+  // interior vertices
+  std::vector<MVertex*> mesh_vertices = from->mesh_vertices;
+
+  // add all embedded vertices
+  std::vector<MVertex*> embedded = from->getEmbeddedMeshVertices();
+  mesh_vertices.insert(mesh_vertices.end(), embedded.begin(), embedded.end());
+
+  // create extruded vertices
+  for(unsigned int i = 0; i < mesh_vertices.size(); i++){
+    MVertex *v = mesh_vertices[i];
     double x = v->x(), y = v->y(), z = v->z();
     ep->Extrude(ep->mesh.NbLayer - 1, ep->mesh.NbElmLayer[ep->mesh.NbLayer - 1],
                 x, y, z);
@@ -261,8 +268,9 @@ int MeshExtrudedSurface(GFace *gf,
 
   // if the edges of the mesh are constrained, the vertices already
   // exist on the face--so we add them to the set
-  if(constrainedEdges)
+  if(constrainedEdges){
     pos.insert(gf->mesh_vertices);
+  }
 
   if(ep->geo.Mode == EXTRUDED_ENTITY) {
     // surface is extruded from a curve
diff --git a/Mesh/meshGRegionExtruded.cpp b/Mesh/meshGRegionExtruded.cpp
index 32958b7a0e..50c392dcad 100644
--- a/Mesh/meshGRegionExtruded.cpp
+++ b/Mesh/meshGRegionExtruded.cpp
@@ -136,9 +136,16 @@ static void extrudeMesh(GFace *from, GRegion *to, MVertexRTree &pos)
 {
   ExtrudeParams *ep = to->meshAttributes.extrude;
 
-  // create vertices
-  for(unsigned int i = 0; i < from->mesh_vertices.size(); i++){
-    MVertex *v = from->mesh_vertices[i];
+  // interior vertices
+  std::vector<MVertex*> mesh_vertices = from->mesh_vertices;
+
+  // add all embedded vertices
+  std::vector<MVertex*> embedded = from->getEmbeddedMeshVertices();
+  mesh_vertices.insert(mesh_vertices.end(), embedded.begin(), embedded.end());
+
+  // create extruded vertices
+  for(unsigned int i = 0; i < mesh_vertices.size(); i++){
+    MVertex *v = mesh_vertices[i];
     for(int j = 0; j < ep->mesh.NbLayer; j++) {
       for(int k = 0; k < ep->mesh.NbElmLayer[j]; k++) {
         double x = v->x(), y = v->y(), z = v->z();
@@ -194,6 +201,8 @@ static void insertAllVertices(GRegion *gr, MVertexRTree &pos)
   std::list<GFace*>::iterator itf = faces.begin();
   while(itf != faces.end()){
     pos.insert((*itf)->mesh_vertices);
+    std::vector<MVertex*> embedded = (*itf)->getEmbeddedMeshVertices();
+    pos.insert(embedded);
     std::list<GEdge*> edges = (*itf)->edges();
     std::list<GEdge*>::iterator ite = edges.begin();
     while(ite != edges.end()){
-- 
GitLab