From 0fac90ff3161242e236e2b643c06ee288cc65d98 Mon Sep 17 00:00:00 2001
From: Emilie Marchandise <emilie.marchandise@uclouvain.be>
Date: Sat, 14 Jan 2012 12:13:08 +0000
Subject: [PATCH] Improved centerlinefield + removed smoothMetric 1D which
 makes Blasius benchmark fail ...

---
 Geo/GModel.cpp           |  2 +-
 Mesh/CenterlineField.cpp | 23 +++++++++++++++++------
 Mesh/CenterlineField.h   |  4 ++--
 Mesh/meshGEdge.cpp       |  2 +-
 Mesh/meshMetric.cpp      |  3 +--
 5 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/Geo/GModel.cpp b/Geo/GModel.cpp
index 2653288b72..c43f9b6735 100644
--- a/Geo/GModel.cpp
+++ b/Geo/GModel.cpp
@@ -559,7 +559,7 @@ int GModel::adaptMesh(int technique, simpleFunction<double> *f,
       writeMSH(name);
             
       if (ITER++ >= niter)  break;
-      if (ITER > 5 && fabs((double)(nbElems - nbElemsOld)) < 0.0 * nbElemsOld) break;
+      if (ITER > 3 && fabs((double)(nbElems - nbElemsOld)) < 0.01 * nbElemsOld) break;
 	   
       nbElemsOld = nbElems;  
     }
diff --git a/Mesh/CenterlineField.cpp b/Mesh/CenterlineField.cpp
index 88b7791880..c81328fbb6 100644
--- a/Mesh/CenterlineField.cpp
+++ b/Mesh/CenterlineField.cpp
@@ -12,12 +12,17 @@
 #include <vector>
 #include <map>
 #include <string>
+#include <fstream>
+#include <sstream>
 #include "GModel.h"
 #include "MElement.h"
 #include "MVertex.h"
 #include "MLine.h"
 #include "GEntity.h"
 #include "Field.h"
+#include "Os.h"
+
+
 
 #if defined(HAVE_ANN)
 #include <ANN/ANN.h>
@@ -37,14 +42,9 @@ Centerline::Centerline(): kdtree(0), nodes(0){
 
   index = new ANNidx[1];
   dist = new ANNdist[1];
-  update_needed = false;
 
-  options["FileName"] = new FieldOptionString (fileName, "File Name for the centerlines");
+  options["FileName"] = new FieldOptionString (fileName, "File name for the centerlines",  &update_needed);
   fileName = "centerlines.vtk";//default
-  //TODO get fileName from file 
-
-  importFile(fileName);
-  buildKdTree();
 
 }
 
@@ -131,6 +131,17 @@ void Centerline::buildKdTree(){
 
 double Centerline::operator() (double x, double y, double z, GEntity *ge){
 
+  if (update_needed){
+    std::ifstream input;
+    input.open(fileName.c_str());
+  
+    if(StatFile(fileName)) Msg::Fatal("Centerline file '%s' does not exist", fileName.c_str());
+   
+    importFile(fileName);
+    buildKdTree();
+    update_needed = false;
+  }
+
   double xyz[3] = {x,y,z };
   int num_neighbours = 1;
   kdtree->annkSearch(xyz, num_neighbours, index, dist);
diff --git a/Mesh/CenterlineField.h b/Mesh/CenterlineField.h
index b8c8ba4089..ceb2c4ddfd 100644
--- a/Mesh/CenterlineField.h
+++ b/Mesh/CenterlineField.h
@@ -46,8 +46,8 @@ class Centerline : public Field{
   virtual std::string getDescription()
   {
     return "The value of this field is the distance to the centerline.\n\n"
-" You should specify a fileName that contains the centerline.\n"
-" The centerline of a surface can be obtained using the open source software vmtk\n\n"
+" You should specify a fileName that contains the centerline."
+" The centerline of a surface can be obtained with the open source software vmtk (http://www.vmtk.org/)"
 " using the following script:\n\n"
 "vmtk vmtkcenterlines -seedselector openprofiles -ifile mysurface.stl -ofile centerlines.vtp --pipe vmtksurfacewriter -ifile centerlines.vtp -ofile centerlines.vtk\n";
   }
diff --git a/Mesh/meshGEdge.cpp b/Mesh/meshGEdge.cpp
index 8a5ba76b00..c491c5d6f3 100644
--- a/Mesh/meshGEdge.cpp
+++ b/Mesh/meshGEdge.cpp
@@ -396,7 +396,7 @@ void meshGEdge::operator() (GEdge *ge)
     
     // FIXME JF : MAYBE WE SHOULD NOT ALWAYS SMOOTH THE 1D MESH SIZE FIELD ??
     //printFandPrimitive(ge->tag(), Points);
-    a =  smoothPrimitive (ge,CTX::instance()->mesh.smoothRatio*CTX::instance()->mesh.smoothRatio,Points);
+    // a =  smoothPrimitive (ge,CTX::instance()->mesh.smoothRatio*CTX::instance()->mesh.smoothRatio,Points);
     //printFandPrimitive(ge->tag()+10000, Points);
     
     N = std::max(ge->minimumMeshSegments() + 1, (int)(a + 1.));
diff --git a/Mesh/meshMetric.cpp b/Mesh/meshMetric.cpp
index 79c0e52a47..eb690c3f92 100644
--- a/Mesh/meshMetric.cpp
+++ b/Mesh/meshMetric.cpp
@@ -80,7 +80,7 @@ meshMetric::meshMetric(GModel *gm, int technique, simpleFunction<double> *fct, s
  
   computeMetric();
 
-  //printMetric("toto.pos");
+  printMetric("toto.pos");
   //exit(1);
 
 }
@@ -332,7 +332,6 @@ void meshMetric::computeMetric(){
   //smoothMetric (sol);
   //curvatureContributionToMetric();
 
- 
 }
 
 double meshMetric::operator() (double x, double y, double z, GEntity *ge) {
-- 
GitLab