From cd80e3098c7e03286674b62507d4f9ea13e9a8b6 Mon Sep 17 00:00:00 2001
From: Emilie Marchandise <emilie.marchandise@uclouvain.be>
Date: Mon, 13 Sep 2010 09:28:58 +0000
Subject: [PATCH] Corrected bug for reading stl with nb vertices < 10

---
 Geo/GModel.cpp        | 11 ++++++-----
 Geo/GModelIO_Mesh.cpp |  5 +++--
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/Geo/GModel.cpp b/Geo/GModel.cpp
index 2988a38526..2eee730c2d 100644
--- a/Geo/GModel.cpp
+++ b/Geo/GModel.cpp
@@ -1004,7 +1004,7 @@ void GModel::checkMeshCoherence(double tolerance)
     for(unsigned int i = 0; i < entities.size(); i++)
       vertices.insert(vertices.end(), entities[i]->mesh_vertices.begin(), 
                       entities[i]->mesh_vertices.end());
-    MVertexPositionSet pos(vertices);
+    MVertexPositionSet pos(vertices, std::min((int)vertices.size(), 10));
     for(unsigned int i = 0; i < vertices.size(); i++)
       pos.find(vertices[i]->x(), vertices[i]->y(), vertices[i]->z(), eps);
     int num = 0;
@@ -1026,7 +1026,7 @@ void GModel::checkMeshCoherence(double tolerance)
         SPoint3 p = entities[i]->getMeshElement(j)->barycenter();
         vertices.push_back(new MVertex(p.x(), p.y(), p.z()));
       }
-    MVertexPositionSet pos(vertices);
+    MVertexPositionSet pos(vertices, std::min((int)vertices.size(), 10));
     for(unsigned int i = 0; i < vertices.size(); i++)
       pos.find(vertices[i]->x(), vertices[i]->y(), vertices[i]->z(), eps);
     int num = 0;
@@ -1061,7 +1061,7 @@ int GModel::removeDuplicateMeshVertices(double tolerance)
       MVertex *v = entities[i]->mesh_vertices[j];
       vertices.push_back(new MVertex(v->x(), v->y(), v->z()));
     }
-  MVertexPositionSet pos(vertices);
+  MVertexPositionSet pos(vertices, std::min((int)vertices.size(), 10));
   for(unsigned int i = 0; i < vertices.size(); i++)
     pos.find(vertices[i]->x(), vertices[i]->y(), vertices[i]->z(), eps);
   int num = 0;
@@ -1124,11 +1124,12 @@ int GModel::removeDuplicateMeshVertices(double tolerance)
 
 void GModel::createTopologyFromMesh()
 {
-  removeDuplicateMeshVertices(CTX::instance()->geom.tolerance);
-
+  
   Msg::StatusBar(2, true, "Creating topology from mesh...");
   double t1 = Cpu();
 
+  removeDuplicateMeshVertices(CTX::instance()->geom.tolerance);
+
   // for each discreteRegion, create topology
   std::vector<discreteRegion*> discRegions;
   for(riter it = firstRegion(); it != lastRegion(); it++)
diff --git a/Geo/GModelIO_Mesh.cpp b/Geo/GModelIO_Mesh.cpp
index a46ac32040..0ae1de21ba 100644
--- a/Geo/GModelIO_Mesh.cpp
+++ b/Geo/GModelIO_Mesh.cpp
@@ -970,7 +970,7 @@ int GModel::readSTL(const std::string &name, double tolerance)
       // "endfacet"
       if(!fgets(buffer, sizeof(buffer), fp)) break;
     }
-  }
+   }
 
   // check if we could parse something
   bool empty = true;
@@ -981,6 +981,7 @@ int GModel::readSTL(const std::string &name, double tolerance)
     }
   }
   if(empty) points.clear();
+ 
 
   // binary STL (we also try to read in binary mode if the header told
   // us the format was ASCII but we could not read any vertices)
@@ -1044,7 +1045,7 @@ int GModel::readSTL(const std::string &name, double tolerance)
     for(unsigned int j = 0; j < points[i].size(); j++)
       vertices.push_back(new MVertex(points[i][j].x(), points[i][j].y(),
                                      points[i][j].z()));
-  MVertexPositionSet pos(vertices);
+  MVertexPositionSet pos(vertices, std::min((int)vertices.size(),10));
   
   for(unsigned int i = 0; i < points.size(); i ++){
     for(unsigned int j = 0; j < points[i].size(); j += 3){
-- 
GitLab