From f5c843efed468036a1da9cee7854f384148e988e Mon Sep 17 00:00:00 2001
From: Tristan Carrier Baudouin <tristan.carrier@uclouvain.be>
Date: Mon, 6 Jun 2011 15:57:57 +0000
Subject: [PATCH] lpcvt

---
 Mesh/BackgroundMesh.cpp |  4 ++++
 Mesh/BackgroundMesh.h   |  1 +
 Mesh/meshGFaceLloyd.cpp | 12 ++++--------
 Mesh/meshGFaceLloyd.h   |  2 +-
 4 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/Mesh/BackgroundMesh.cpp b/Mesh/BackgroundMesh.cpp
index 165c55a73e..369d107f27 100644
--- a/Mesh/BackgroundMesh.cpp
+++ b/Mesh/BackgroundMesh.cpp
@@ -791,4 +791,8 @@ void backgroundMesh::print(const std::string &filename, GFace *gf,
   fclose(f);
 }
 
+MElementOctree* backgroundMesh::get_octree(){
+  return _octree;
+}
+
 backgroundMesh* backgroundMesh::_current = 0;
diff --git a/Mesh/BackgroundMesh.h b/Mesh/BackgroundMesh.h
index f98db7599d..393b1eb349 100644
--- a/Mesh/BackgroundMesh.h
+++ b/Mesh/BackgroundMesh.h
@@ -62,6 +62,7 @@ class backgroundMesh : public simpleFunction<double>
     default : print(filename,gf,_angles); return;
     }
   }
+  MElementOctree* get_octree();
 };
 
 double BGM_MeshSize(GEntity *ge, double U, double V, double X, double Y, double Z);
diff --git a/Mesh/meshGFaceLloyd.cpp b/Mesh/meshGFaceLloyd.cpp
index ff9f9a9f00..8712e771ae 100644
--- a/Mesh/meshGFaceLloyd.cpp
+++ b/Mesh/meshGFaceLloyd.cpp
@@ -68,7 +68,7 @@ void callback(const alglib::real_1d_array& x,double& func,alglib::real_1d_array&
 	if(obj.interior(*pointer,gf,i)){
 	  u = x[index];
 	  v = x[index + dimension/2];
-	  inside = domain_search(octree,gf,u,v);
+	  inside = domain_search(octree,u,v);
 	  if(!inside) error1 = 1;
 	  pointer->points[i].where.h = u;
 	  pointer->points[i].where.v = v;
@@ -136,12 +136,10 @@ void callback(const alglib::real_1d_array& x,double& func,alglib::real_1d_array&
   }	
 }
 
-bool domain_search(MElementOctree* octree,GFace* gf,double x,double y){
-  GPoint gp;
+bool domain_search(MElementOctree* octree,double x,double y){
   MElement* element;
 	
-  gp = gf->point(x,y);
-  element = (MElement*)octree->find(gp.x(),gp.y(),gp.z(),2,true);
+  element = (MElement*)octree->find(x,y,0.0,2,true);
   if(element!=NULL) return 1;
   else return 0;
 }
@@ -317,7 +315,7 @@ void smoothing::optimize_face(GFace* gf){
 	
   x.setcontent(2*num_interior,initial_conditions);
 
-  octree = new MElementOctree(gf->model());	
+  octree = backgroundMesh::current()->get_octree();	
 	
   w.set_p(exponent);
   w.set_dimension(2*num_interior);
@@ -331,8 +329,6 @@ void smoothing::optimize_face(GFace* gf){
   minlbfgsoptimize(state,callback,NULL,&w);
   minlbfgsresults(state,x,rep);
 
-  delete octree;	
-	
   /*lpcvt obj2;
   SPoint2 val = obj2.seed(triangulator,gf);
   triangulator.concave(val.x(),val.y(),gf);
diff --git a/Mesh/meshGFaceLloyd.h b/Mesh/meshGFaceLloyd.h
index 5487c9287a..58942d703c 100644
--- a/Mesh/meshGFaceLloyd.h
+++ b/Mesh/meshGFaceLloyd.h
@@ -24,7 +24,7 @@ class segment_list;
 class metric;
 
 void callback(const alglib::real_1d_array&,double&,alglib::real_1d_array&,void*);
-bool domain_search(MElementOctree*,GFace*,double,double);
+bool domain_search(MElementOctree*,double,double);
 
 class smoothing{
   int ITER_MAX;
-- 
GitLab