コード例 #1
0
ファイル: main.cpp プロジェクト: binqi0830/HilbertRTree
void search_ND(int items){
	std::vector< Rect<size> > rectangles;
	unsigned int edge_size = (unsigned int)ceil(pow((double)items, 1.0 / (double)size));
	int no_iterations = std::max(max_elements / items, 10);
	generateRectangles(items, edge_size, rectangles);

	RTree<int, unsigned int, size, float> tree;

	for (size_t i = 0; i < rectangles.size(); ++i){
		tree.Insert(rectangles[i].min, rectangles[i].max, i);
	}

	auto begin = std::chrono::high_resolution_clock::now();

	for (int i = 0; i < no_iterations; i++){
		std::vector<unsigned int> min(size, 0);

		for (unsigned int j = 0; j < edge_size; ++j){
			std::vector<unsigned int> max(size, (j + 1)*tile_size);

			Rect<size> search_rect(min, max);
			int nhits = tree.Search(search_rect.min, search_rect.max, MySearchCallback, NULL);
		}

	}

	auto end = std::chrono::high_resolution_clock::now();

	of << "Running " << edge_size << "queries on " << size << "D items:" << (double)std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count() / (double)no_iterations << "ns" << std::endl;
}
コード例 #2
0
ファイル: main.cpp プロジェクト: binqi0830/HilbertRTree
void pointQueries_ND(int items){
	std::vector< Rect<size> > rectangles;
	std::vector< Rect<size> > queries;
	unsigned int edge_size = (unsigned int)ceil(pow((double)items, 1.0 / (double)size));
	int no_iterations = std::max(max_elements / items, 10);
	generateRectangles(items, edge_size, rectangles);

	RTree<int, unsigned int, size, float> tree;

	for (size_t i = 0; i < rectangles.size(); ++i){
		tree.Insert(rectangles[i].min, rectangles[i].max, i);
		std::vector<unsigned int> min(size, i*tile_size+1);
		std::vector<unsigned int> max(size, i*tile_size+1);
		Rect<size> pointQuery(min, max);
		queries.push_back(pointQuery);
	}

	auto begin = std::chrono::high_resolution_clock::now();

	for (int i = 0; i < no_iterations; i++){
		for (size_t j = 0; j < queries.size(); j++){
			tree.Search(queries[j].min, queries[j].max, MySearchCallback, NULL);
		}
	}

	auto end = std::chrono::high_resolution_clock::now();

	of << "Running " << queries.size() << " point queries " << size << "D items:" << (double)std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count() / (double)no_iterations << "ns" << std::endl;
}
コード例 #3
0
ファイル: Test.cpp プロジェクト: larcohex/random
void main()
{
    RTree<int, int, 2, float> tree;

    int i, nhits;
    printf("nrects = %d\n", nrects);

    for(i=0; i<nrects; i++)
    {
        tree.Insert(rects[i].min, rects[i].max, i); // Note, all values including zero are fine in this version
    }

    nhits = tree.Search(search_rect.min, search_rect.max, MySearchCallback, NULL);

    printf("Search resulted in %d hits\n", nhits);

    // Iterator test
    int itIndex = 0;
    RTree<int, int, 2, float>::Iterator it;
    for( tree.GetFirst(it);
            !tree.IsNull(it);
            tree.GetNext(it) )
    {
        int value = tree.GetAt(it);

        int boundsMin[2] = {0,0};
        int boundsMax[2] = {0,0};
        it.GetBounds(boundsMin, boundsMax);
        printf("it[%d] %d = (%d,%d,%d,%d)\n", itIndex++, value, boundsMin[0], boundsMin[1], boundsMax[0], boundsMax[1]);
    }

    // Iterator test, alternate syntax
    itIndex = 0;
    tree.GetFirst(it);
    while( !it.IsNull() )
    {
        int value = *it;
        ++it;
        printf("it[%d] %d\n", itIndex++, value);
    }

    getchar(); // Wait for keypress on exit so we can read console output

    // Output:
    //
    // nrects = 4
    // Hit data rect 1
    // Hit data rect 2
    // Search resulted in 2 hits
    // it[0] 0 = (0,0,2,2)
    // it[1] 1 = (5,5,7,7)
    // it[2] 2 = (8,5,9,6)
    // it[3] 3 = (7,1,9,2)
    // it[0] 0
    // it[1] 1
    // it[2] 2
    // it[3] 3
}
コード例 #4
0
int main()
{
	RTree tree;
	
	for(int i = 0;i < DATA_NUMBER; ++i)
	{
		double min[2],max[2];
		min[0] = rand() % MAP_SIZE;
		max[0] = min[0];
		min[1] = rand() % MAP_SIZE;
		max[1] = min[1];
		tree.Insert(min, max, i);  //Insert (x,y,id)
	}
	outFileData(&tree);
	//tree.fileInsert("data.txt");
	//tree.printRec(tree.getMBR(tree.getRoot()));

	RTree::Iterator it;
	for( tree.GetFirst(it); 
       !tree.IsNull(it);
       tree.GetNext(it) )
	{
		int value = tree.GetAt(it);
    
		double x,y;
		it.GetCard(&x,&y);
		cout << "ID " << value << " : " << "(" << x << "," << y << ")" << endl;
	}

	Table1 table1;
	Table2 table2;
	Table3 table3;
	generateTable(&tree,&table1,&table2,&table3);
	printTable(&table1,&table2,&table3);
	outFileTable(&table1,&table2,&table3);

	TimeCounter tc;
	double CreateTime = 0.0;
	tc.StartTime();
	cout << QueryPlan(&tree,K_NEAREST) << endl;
	CreateTime = tc.EndTime();
	cout << "QueryPlan Time: " << CreateTime << " ms" << endl;

//	outFileRect(&tree);

	system("pause");
	return 0;
}
コード例 #5
0
ファイル: main.cpp プロジェクト: binqi0830/HilbertRTree
void insert_ND(int items){
	std::vector< Rect<size> > rectangles;
	int no_iterations = std::max(max_elements / items, 10);
	unsigned int edge_size = (unsigned int)ceil(pow((double)items, 1.0 / (double)size));
	generateRectangles(items, edge_size, rectangles);

	auto begin = std::chrono::high_resolution_clock::now();

	for (int i = 0; i < no_iterations; i++){
		RTree<unsigned int, unsigned int, size, float> tree;

		for (size_t j = 0; j < rectangles.size(); ++j){
			tree.Insert(rectangles[j].min, rectangles[j].max, j);
		}
	}

	auto end = std::chrono::high_resolution_clock::now();

	of << "Inserting " << rectangles.size() << " " << size << "D items:" << (double)std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count() / (double)no_iterations << "ns" << std::endl;
}
コード例 #6
0
ファイル: main.cpp プロジェクト: binqi0830/HilbertRTree
void search_ND_All(int items){
	std::vector< Rect<size> > rectangles;
	unsigned int edge_size = (unsigned int)ceil(pow((double)items, 1.0 / (double)size));
	int no_iterations = std::max(max_elements / items, 10);
	generateRectangles(items, edge_size, rectangles);

	RTree<int, unsigned int, size, float> tree;

	for (size_t i = 0; i < rectangles.size(); ++i){
		tree.Insert(rectangles[i].min, rectangles[i].max, i);
	}

	auto begin = std::chrono::high_resolution_clock::now();

	for (int i = 0; i < no_iterations; i++){
		for (size_t j = 0; j < rectangles.size(); j++){
			tree.Search(rectangles[j].min, rectangles[j].max, MySearchCallback, NULL);
		}
	}

	auto end = std::chrono::high_resolution_clock::now();

	of << "Querying tree with " << rectangles.size() << " tiles using " << items << " queries over " << size << "D items:" << (double)std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count() / (double)no_iterations << "ns" << std::endl;
}
コード例 #7
0
ファイル: simple3D.cpp プロジェクト: feelpp/debian-gmsh
void Filler::treat_region(GRegion* gr){

  int NumSmooth = CTX::instance()->mesh.smoothCrossField;
  std::cout << "NumSmooth = " << NumSmooth << std::endl ;
  if(NumSmooth && (gr->dim() == 3)){
    double scale = gr->bounds().diag()*1e-2;
    Frame_field::initRegion(gr,NumSmooth);
    Frame_field::saveCrossField("cross0.pos",scale);

    Frame_field::smoothRegion(gr,NumSmooth);
    Frame_field::saveCrossField("cross1.pos",scale);
  }

#if defined(HAVE_RTREE)
  unsigned int i;
  int j;
  int count;
  int limit;
  bool ok2;
  double x,y,z;
  SPoint3 point;
  Node *node,*individual,*parent;
  MVertex* vertex;
  MElement* element;
  MElementOctree* octree;
  deMeshGRegion deleter;
  Wrapper wrapper;
  GFace* gf;
  std::queue<Node*> fifo;
  std::vector<Node*> spawns;
  std::vector<Node*> garbage;
  std::vector<MVertex*> boundary_vertices;
  std::set<MVertex*> temp;
  std::list<GFace*> faces;
  std::map<MVertex*,int> limits;
  std::set<MVertex*>::iterator it;
  std::list<GFace*>::iterator it2;
  std::map<MVertex*,int>::iterator it3;
  RTree<Node*,double,3,double> rtree;
  
  Frame_field::init_region(gr);
  Size_field::init_region(gr);
  Size_field::solve(gr);
  octree = new MElementOctree(gr->model());
  garbage.clear();
  boundary_vertices.clear();
  temp.clear();
  new_vertices.clear();
  faces.clear();
  limits.clear();

  faces = gr->faces();	
  for(it2=faces.begin();it2!=faces.end();it2++){
    gf = *it2;
	limit = code(gf->tag());
	for(i=0;i<gf->getNumMeshElements();i++){
	  element = gf->getMeshElement(i);
      for(j=0;j<element->getNumVertices();j++){
	    vertex = element->getVertex(j);
		temp.insert(vertex);
		limits.insert(std::pair<MVertex*,int>(vertex,limit));
	  }
	}
  }
		
  /*for(i=0;i<gr->getNumMeshElements();i++){
    element = gr->getMeshElement(i);
    for(j=0;j<element->getNumVertices();j++){
      vertex = element->getVertex(j);
      temp.insert(vertex);
    }
  }*/

  for(it=temp.begin();it!=temp.end();it++){
    if((*it)->onWhat()->dim()==0){
	  boundary_vertices.push_back(*it);
	}
  }
	
  for(it=temp.begin();it!=temp.end();it++){
    if((*it)->onWhat()->dim()==1){
	  boundary_vertices.push_back(*it);
	}
  }
	
  for(it=temp.begin();it!=temp.end();it++){
    if((*it)->onWhat()->dim()==2){
	  boundary_vertices.push_back(*it);
	}
  }
	
  /*for(it=temp.begin();it!=temp.end();it++){
    if((*it)->onWhat()->dim()<3){
      boundary_vertices.push_back(*it);
    }
  }*/
  //std::ofstream file("nodes.pos");
  //file << "View \"test\" {\n";	

  for(i=0;i<boundary_vertices.size();i++){
    x = boundary_vertices[i]->x();
    y = boundary_vertices[i]->y();
    z = boundary_vertices[i]->z();
    
    node = new Node(SPoint3(x,y,z));
    compute_parameters(node,gr);
	node->set_layer(0);
	
	it3 = limits.find(boundary_vertices[i]);
	node->set_limit(it3->second);
	
	rtree.Insert(node->min,node->max,node);
	fifo.push(node);
    //print_node(node,file);
  }
  
  count = 1;
  while(!fifo.empty()){
    parent = fifo.front();
	fifo.pop();
	garbage.push_back(parent);
	  
	if(parent->get_limit()!=-1 && parent->get_layer()>=parent->get_limit()){
	  continue;
	}
	  
	spawns.clear();
	spawns.resize(6);
	  
	for(i=0;i<6;i++){
	  spawns[i] = new Node();
	}
	
	create_spawns(gr,octree,parent,spawns);
	
	for(i=0;i<6;i++){
	  ok2 = 0;
	  individual = spawns[i];
	  point = individual->get_point();
	  x = point.x();
	  y = point.y();
	  z = point.z();
	  
	  if(inside_domain(octree,x,y,z)){
		compute_parameters(individual,gr);
		individual->set_layer(parent->get_layer()+1);
		individual->set_limit(parent->get_limit());
		
		if(far_from_boundary(octree,individual)){
		  wrapper.set_ok(1);
		  wrapper.set_individual(individual);
		  wrapper.set_parent(parent);
		  rtree.Search(individual->min,individual->max,rtree_callback,&wrapper);
			
		  if(wrapper.get_ok()){
		    fifo.push(individual);
		    rtree.Insert(individual->min,individual->max,individual);
			vertex = new MVertex(x,y,z,gr,0);
			new_vertices.push_back(vertex);
			ok2 = 1;
			//print_segment(individual->get_point(),parent->get_point(),file);
		  }
	    }
	  }
		
	  if(!ok2) delete individual;
	}
	
	if(count%100==0){
	  printf("%d\n",count);
	}
	count++;
  }
  
  //file << "};\n";

  int option = CTX::instance()->mesh.algo3d;
  CTX::instance()->mesh.algo3d = ALGO_3D_DELAUNAY;

  deleter(gr);
  std::vector<GRegion*> regions;
  regions.push_back(gr);
  meshGRegion mesher(regions); //?
  mesher(gr); //?
  MeshDelaunayVolume(regions);

  CTX::instance()->mesh.algo3d = option;
	
  for(i=0;i<garbage.size();i++) delete garbage[i];
  for(i=0;i<new_vertices.size();i++) delete new_vertices[i];
  new_vertices.clear();
  delete octree;
  rtree.RemoveAll();
  Size_field::clear();
  Frame_field::clear();
#endif
}
コード例 #8
0
ファイル: pointInsertion.cpp プロジェクト: iyer-arvind/gmsh
bool Filler3D::treat_region(GRegion *gr)
{
  BGMManager::set_use_cross_field(true);

  bool use_vectorial_smoothness;
  bool use_fifo;
  string algo;

  // readValue("param.dat","SMOOTHNESSALGO",algo);
  algo.assign("SCALAR");

  if (!algo.compare("SCALAR")){
    use_vectorial_smoothness = false;
    use_fifo = false;
  }
  else if (!algo.compare("FIFO")){
    use_vectorial_smoothness = false;
    use_fifo = true;
  }
  else{
    cout << "unknown SMOOTHNESSALGO !" << endl;
    throw;
  }

  const bool debug=false;
  const bool export_stuff=true;
  double a;

  cout << "ENTERING POINTINSERTION3D" << endl;

  // acquire background mesh
  cout << "pointInsertion3D: recover BGM" << endl;
  a = Cpu();
  frameFieldBackgroundMesh3D *bgm =
    dynamic_cast<frameFieldBackgroundMesh3D*>(BGMManager::get(gr));
  time_smoothing += (Cpu() - a);

  if (!bgm){
    cout << "pointInsertion3D:: BGM dynamic cast failed ! " << endl;
    throw;
  }

  // export BGM fields
  if(export_stuff){
    cout << "pointInsertion3D: export size field " << endl;
    stringstream ss;
    ss << "bg3D_sizefield_" << gr->tag() << ".pos";
    bgm->exportSizeField(ss.str());

    cout << "pointInsertion3D : export crossfield " << endl;
    stringstream sscf;
    sscf << "bg3D_crossfield_" << gr->tag() << ".pos";
    bgm->exportCrossField(sscf.str());

    cout << "pointInsertion3D : export smoothness " << endl;
    stringstream sss;
    sss << "bg3D_smoothness_" << gr->tag() << ".pos";
    bgm->exportSmoothness(sss.str());

    if (use_vectorial_smoothness){
      cout << "pointInsertion3D : export vectorial smoothness " << endl;
      stringstream ssvs;
      ssvs << "bg3D_vectorial_smoothness_" << gr->tag() << ".pos";
      bgm->exportVectorialSmoothness(ssvs.str());
    }
  }

  // ---------------- START FILLING NEW POINTS ----------------
  cout << "pointInsertion3D : inserting points in region " << gr->tag()  << endl;

  //ProfilerStart("/home/bernard/profile");
  a = Cpu();

  // ----- initialize fifo list -----

  RTree<MVertex*,double,3,double> rtree;
  listOfPoints *fifo;
  if (use_fifo)
    fifo = new listOfPointsFifo();
  else if (use_vectorial_smoothness)
    fifo = new listOfPointsVectorialSmoothness();
  else
    fifo = new listOfPointsScalarSmoothness();

  set<MVertex*> temp;
  vector<MVertex*> boundary_vertices;
  map<MVertex*,int> vert_priority;
  map<MVertex*,double> smoothness_forplot;
  MElement *element;
  MVertex *vertex;
  list<GFace*> faces = gr->faces();
  for(list<GFace*>::iterator it=faces.begin();it!=faces.end();it++){// for all faces
    GFace *gf = *it;
    // int limit = code_kesskessai(gf->tag());
    for(unsigned int i=0;i<gf->getNumMeshElements();i++){
      element = gf->getMeshElement(i);
      for(int j=0;j<element->getNumVertices();j++){// for all vertices
        vertex = element->getVertex(j);
        temp.insert(vertex);
        // limits.insert(make_pair(vertex,limit));
      }
    }
  }

  int geodim;
  for(set<MVertex*>::iterator it=temp.begin();it!=temp.end();it++){
    geodim = (*it)->onWhat()->dim();
    if ((geodim==0) || (geodim==1) || (geodim==2)) boundary_vertices.push_back(*it);
  }

  double min[3],max[3],x,y,z,h;
  for(unsigned int i=0;i<boundary_vertices.size();i++){

    x = boundary_vertices[i]->x();
    y = boundary_vertices[i]->y();
    z = boundary_vertices[i]->z();

    // "on boundary since working on boundary_vertices ...
    MVertex *closest = bgm->get_nearest_neighbor_on_boundary(boundary_vertices[i]);
    h = bgm->size(closest);// get approximate size, closest vertex, faster ?!

    fill_min_max(x,y,z,h,min,max);

    rtree.Insert(min,max,boundary_vertices[i]);

    if (!use_vectorial_smoothness){
      smoothness_vertex_pair *svp = new smoothness_vertex_pair();
      svp->v = boundary_vertices[i];
      svp->rank = bgm->get_smoothness(x,y,z);
      svp->dir = 0;
      svp->layer = 0;
      svp->size = h;
      bgm->eval_approximate_crossfield(closest, svp->cf);

      fifo->insert(svp);
      if (debug){
        smoothness_forplot[svp->v] = svp->rank;
      }
    }
    else{
      STensor3 temp;
      bgm->eval_approximate_crossfield(closest, temp);
      for (int idir=0;idir<3;idir++){
        smoothness_vertex_pair *svp = new smoothness_vertex_pair();
        svp->v = boundary_vertices[i];
        svp->rank = bgm->get_vectorial_smoothness(idir,x,y,z);
        svp->dir = idir;
        svp->layer = 0;
        svp->size = h;
        svp->cf = temp;
        for (int k=0;k<3;k++) svp->direction(k) = temp(k,idir);

        // cout << "fifo size=" << fifo->size() << " inserting   "  ;
        fifo->insert(svp);
        // cout << " ->  fifo size=" << fifo->size() << endl;
      }
    }
  }

  // TODO: si fifo était list of *PTR -> pas de copies, gain temps ?
  Wrapper3D wrapper;
  wrapper.set_bgm(bgm);
  MVertex *parent,*individual;
  new_vertices.clear();
  bool spawn_created;
  int priority_counter=0;
  STensor3 crossfield;
  int parent_layer;

  while(!fifo->empty()){

    parent =  fifo->get_first_vertex();
    //    parent_limit = fifo->get_first_limit();
    parent_layer = fifo->get_first_layer();

    //    if(parent_limit!=-1 && parent_layer>=parent_limit()){
    //      continue;
    //    }

    vector<MVertex*> spawns;
    if (!use_vectorial_smoothness){
      spawns.resize(6);
      computeSixNeighbors(bgm,parent,spawns,fifo->get_first_crossfield(),
                          fifo->get_first_size());
    }
    else{
      spawns.resize(2);
      computeTwoNeighbors(bgm,parent,spawns,fifo->get_first_direction(),
                          fifo->get_first_size());
    }
    fifo->erase_first();

    //    cout << "while, fifo->size()=" << fifo->size() << " parent=(" <<
    //    parent->x() << "," << parent->y() << "," << parent->z() << ")" <<
    //    endl;

    for(unsigned int i=0;i<spawns.size();i++){
      spawn_created = false;
      individual = spawns[i];
      x = individual->x();
      y = individual->y();
      z = individual->z();
      //      cout << " working on candidate " << "(" << individual->x() << ","
      //      << individual->y() << "," << individual->z() << ")" << endl;

      if(bgm->inDomain(x,y,z)){
        //        cout << "   spawn " << i << " in domain" << endl;

        MVertex *closest = bgm->get_nearest_neighbor(individual);
        h = bgm->size(closest);// get approximate size, closest vertex, faster ?!

        if(far_from_boundary_3D(bgm,individual,h)){
          //        cout << "   spawn " << i << " far from bnd" << endl;
          bgm->eval_approximate_crossfield(closest, crossfield);
          wrapper.set_ok(true);
          wrapper.set_individual(individual);
          wrapper.set_parent(parent);
          wrapper.set_size(&h);
          wrapper.set_crossfield(&crossfield);

          fill_min_max(x,y,z,h,min,max);

          rtree.Search(min,max,rtree_callback_3D,&wrapper);

          if(wrapper.get_ok()){
            //        cout << "   spawn " << i << " wrapper OK" << endl;

            if (!use_vectorial_smoothness){
              smoothness_vertex_pair *svp = new smoothness_vertex_pair();
              svp->v = individual;
              svp->rank=bgm->get_smoothness(individual->x(),individual->y(),individual->z());
              svp->dir = 0;
              svp->layer = parent_layer+1;
              svp->size = h;
              svp->cf = crossfield;
              fifo->insert(svp);
              if (debug){
                smoothness_forplot[svp->v] = svp->rank;
                vert_priority[individual] = priority_counter++;
              }

            }
            else{
              if (debug) vert_priority[individual] = priority_counter++;
              for (int idir=0;idir<3;idir++){
                smoothness_vertex_pair *svp = new smoothness_vertex_pair();
                svp->v = individual;
                svp->rank = bgm->get_vectorial_smoothness(idir,x,y,z);
                svp->dir = idir;
                svp->layer = parent_layer+1;
                svp->size = h;
                for (int k=0;k<3;k++) svp->direction(k) = crossfield(k,idir);
                svp->cf = crossfield;
                fifo->insert(svp);
              }
            }

            rtree.Insert(min,max,individual);
            new_vertices.push_back(individual);
            spawn_created = true;

          }
        }
      }
      if(!spawn_created){
        delete individual;
      }
    }// end loop on spawns
  }

  //ProfilerStop();

  time_insert_points += (Cpu() - a);

  // --- output ---
  if (debug){
    stringstream ss;
    ss << "priority_3D_" << gr->tag() << ".pos";
    print_nodal_info(ss.str().c_str(),vert_priority);
    ss.clear();

    stringstream sss;
    sss << "smoothness_3D_" << gr->tag() << ".pos";
    print_nodal_info(sss.str().c_str(),smoothness_forplot);
    sss.clear();
  }

  // ------- meshing using new points
  cout << "tets in gr before= " << gr->tetrahedra.size() << endl;
  cout << "nb new vertices= " << new_vertices.size() << endl;
  a=Cpu();

  int option = CTX::instance()->mesh.algo3d;
  CTX::instance()->mesh.algo3d = ALGO_3D_DELAUNAY;

  deMeshGRegion deleter;
  deleter(gr);
  std::vector<GRegion*> regions;
  regions.push_back(gr);
  meshGRegion mesher(regions); //?
  mesher(gr); //?
  MeshDelaunayVolume(regions);
  time_meshing += (Cpu() - a);

  cout << "tets in gr after= " << gr->tetrahedra.size() << endl;
  cout << "gr tag=" << gr->tag() << endl;

  CTX::instance()->mesh.algo3d = option;

  delete fifo;
  for(unsigned int i=0;i<new_vertices.size();i++) delete new_vertices[i];
  new_vertices.clear();
  rtree.RemoveAll();

  return true;
}
コード例 #9
0
ファイル: pointInsertion.cpp プロジェクト: iyer-arvind/gmsh
void Filler2D::pointInsertion2D(GFace* gf,  vector<MVertex*> &packed,
                                vector<SMetric3> &metrics)
{
  // NB/ do not use the mesh in GFace, use the one in backgroundMesh2D!

  //  if(debug) cout << " ------------------   OLD -------------------" << endl;
  //  stringstream ssa;
  ////  ssa << "oldbgm_angles_" << gf->tag() << ".pos";
  ////  backgroundMesh::current()->print(ssa.str(),gf,1);
  //  ssa << "oldbgm_sizes_" << gf->tag() << ".pos";
  //  backgroundMesh::current()->print(ssa.str(),gf,0);
  //
  //
  //
  //
  //  if(debug) cout << " ------------------   NEW -------------------" << endl;
  //  backgroundMesh2D *bgm2 = dynamic_cast<backgroundMesh2D*>(BGMManager::get(gf));
  //  stringstream ss2;
  //  ss2 << "basebg_sizefield_" << gf->tag() << ".pos";
  //  bgm2->exportSizeField(ss2.str());
  //
  //
  //
  //  return;
  //

  BGMManager::set_use_cross_field(true);

  const bool goNonLinear = true;
  const bool debug=false;
  const bool export_stuff=true;

  if (debug) cout << "ENTERING POINTINSERTION2D" << endl;

  double a;

  // acquire background mesh
  if(debug) cout << "pointInsertion2D: recover BGM" << endl;
  a=Cpu();
  frameFieldBackgroundMesh2D *bgm =
    dynamic_cast<frameFieldBackgroundMesh2D*>(BGMManager::get(gf));
  time_bgm_and_smoothing += (Cpu() - a);

  if (!bgm){
    Msg::Error("BGM dynamic cast failed in filler2D::pointInsertion2D");
    return;
  }

  // export BGM size field
  if(export_stuff){
    cout << "pointInsertion2D: export size field " << endl;
    stringstream ss;
    ss << "bg2D_sizefield_" << gf->tag() << ".pos";
    bgm->exportSizeField(ss.str());

    cout << "pointInsertion2D : export crossfield " << endl;
    stringstream sscf;
    sscf << "bg2D_crossfield_" << gf->tag() << ".pos";
    bgm->exportCrossField(sscf.str());

    cout << "pointInsertion2D : export smoothness " << endl;
    stringstream sss;
    sss << "bg2D_smoothness_" << gf->tag() << ".pos";
    bgm->exportSmoothness(sss.str());
  }



  // point insertion algorithm:
  a=Cpu();

  // for debug check...
  int priority_counter=0;
  map<MVertex*,int> vert_priority;

  // get all the boundary vertices
  if(debug) cout << "pointInsertion2D : get bnd vertices " << endl;
  set<MVertex*> bnd_vertices = bgm->get_vertices_of_maximum_dim(1);

  // put boundary vertices in a fifo queue
  set<smoothness_point_pair, compareSurfacePointWithExclusionRegionPtr_Smoothness> fifo;
  vector<surfacePointWithExclusionRegion*> vertices;

  // initiate the rtree
  if(debug) cout << "pointInsertion2D : initiate RTree " << endl;
  RTree<surfacePointWithExclusionRegion*,double,2,double> rtree;
  SMetric3 metricField(1.0);
  SPoint2 newp[4][NUMDIR];
  set<MVertex*>::iterator it = bnd_vertices.begin() ;

  for (; it !=  bnd_vertices.end() ; ++it){
    SPoint2 midpoint;
    computeFourNeighbors(bgm,*it, midpoint, goNonLinear, newp, metricField);
    surfacePointWithExclusionRegion *sp = new surfacePointWithExclusionRegion
      (*it, newp, midpoint,metricField);

    smoothness_point_pair mp;
    mp.ptr = sp;
    mp.rank=(1.-bgm->get_smoothness(midpoint[0],midpoint[1]));
    fifo.insert(mp);

    vertices.push_back(sp);
    double _min[2],_max[2];
    sp->minmax(_min,_max);
    rtree.Insert(_min,_max,sp);
  }

  // ---------- main loop -----------------
  while(!fifo.empty()){
    if(debug) cout << " -------- fifo.size() = " << fifo.size() << endl;
    int count_nbaddedpt = 0;

    surfacePointWithExclusionRegion * parent = (*fifo.begin()).ptr;
    fifo.erase(fifo.begin());

    for (int dir=0;dir<NUMDIR;dir++){
      for (int i=0;i<4;i++){
        if (!inExclusionZone (parent->_p[i][dir], rtree, vertices) ){

          GPoint gp = gf->point(parent->_p[i][dir]);
          MFaceVertex *v = new MFaceVertex(gp.x(),gp.y(),gp.z(),gf,gp.u(),gp.v());
          SPoint2 midpoint;
          computeFourNeighbors(bgm,v, midpoint, goNonLinear, newp, metricField);
          surfacePointWithExclusionRegion *sp = new surfacePointWithExclusionRegion
            (v, newp, midpoint, metricField, parent);
          smoothness_point_pair mp;mp.ptr = sp;mp.rank=(1.-bgm->get_smoothness(gp.u(),gp.v()));

          if (debug) vert_priority[v] = priority_counter++;

          fifo.insert(mp);
          vertices.push_back(sp);
          double _min[2],_max[2];
          sp->minmax(_min,_max);
          rtree.Insert(_min,_max,sp);

          if (debug){
            cout << "  adding node (" << sp->_v->x() << "," << sp->_v->y()
                 << "," << sp->_v->z() << ")" << endl;
            cout << "    ----------------------------- sub --- fifo.size() = "
                 << fifo.size() << endl;
          }
          count_nbaddedpt++;
        }
      }
    }
    if(debug) cout << "////////// nbre of added point: " << count_nbaddedpt << endl;
  }
  time_insertion += (Cpu() - a);

  if (debug){
    stringstream ss;
    ss << "priority_" << gf->tag() << ".pos";
    print_nodal_info(ss.str().c_str(),vert_priority);
    ss.clear();
  }

  // add the vertices as additional vertices in the
  // surface mesh
  char ccc[256]; sprintf(ccc,"points%d.pos",gf->tag());
  FILE *f = Fopen(ccc,"w");
  if(f){
    fprintf(f,"View \"\"{\n");
    for (unsigned int i=0;i<vertices.size();i++){
      vertices[i]->print(f,i);
      if(vertices[i]->_v->onWhat() == gf) {
        packed.push_back(vertices[i]->_v);
        metrics.push_back(vertices[i]->_meshMetric);
        SPoint2 midpoint;
        reparamMeshVertexOnFace(vertices[i]->_v, gf, midpoint);
      }
      delete  vertices[i];
    }
    fprintf(f,"};");
    fclose(f);
  }
}