Пример #1
0
Dt *construct3DDelaunayTriangulation(){
	int i;

	Dt *dt = new Dt();

	for (i = 0; i < vertexCount; i++){
		Point point = Point(v[i].vec[0], v[i].vec[1], v[i].vec[2]);
		DVertex vh = dt->insert(point); //hier absturz
		vh->info().setIndex(i);
	}

	//	cout << "DT3: finite: vertices=" << dt->number_of_vertices() << ", edges=" << dt->number_of_finite_edges() << ", faces=" << dt->number_of_finite_facets() << ", cells=" << dt->number_of_finite_cells() << endl;
	cout << "DT3: all: vertices=" << (dt->number_of_vertices() + 1) << ", edges=" << dt->number_of_edges() << ", faces=" << dt->number_of_facets() << ", cells=" << dt->number_of_cells() << endl;

	if ((int)dt->number_of_vertices() != vertexCount){
		cout << "Warning: point set contains identical points: will fail later because of indices larger than that count!" << endl;

		// adjust indices to account for removed duplicate points (required for consistency, and no indices >= vertexcount!)
		map<int, int> vertexMap;
		i = 0;

		for (Dt::Vertex_iterator vhIter = dt->vertices_begin(); vhIter != dt->vertices_end(); vhIter++){
			DVertex vh = vhIter;

			if (vh->info().index() != -1)
			{
				vertexMap[i] = vh->info().index();
				vh->info().setIndex(i);
				i++;
			}
		}

		cout << "vertices reduced from " << vertexCount << " to " << (int)dt->number_of_vertices() << endl;

		vertexCount = (int)dt->number_of_vertices();
		_Vertex *newV = new _Vertex[vertexCount];

		for (i = 0; i < vertexCount; i++){
			//			cout << i << ": " << vertexMap[i] << endl;
			newV[i].vec = v[vertexMap[i]].vec;
		}

		//		delete v;	// TODO: dirty
		v = newV;
	}
	return dt;
}
Пример #2
0
void  fct(int ii, int jj)
{
  typedef std::map<Vertex_handle,Point_2> SM;
  typedef std::unordered_map<Vertex_handle,Point_2> SUM;
  typedef boost::unordered_map<Vertex_handle,Point_2> BUM;
  
  Dt dt;
  Vector_2 v(0,0);
  Random_points rp( 250);
  std::vector<Point_2> points;
  for(int i =0; i < ii; i++){
    Point_2 p = *rp++;
    points.push_back(p); 
  }

  dt.insert(points.begin(), points.end());

  std::vector<Vertex_handle> vertices;
  Finite_vertices_iterator b = dt.finite_vertices_begin(), e = dt.finite_vertices_end();
  for(; b!=e; ++b){
    vertices.push_back(b);
  }
  random_shuffle(vertices.begin(), vertices.end());

  Timer tsmc, tsumc, tbumc;
  Timer tsmq, tsumq, tbumq;
  for(int j=0; j <jj; j++){
    
    {
      tsmc.start();
      SM sm;
      for(Vertex_handle vh : vertices){
        sm[vh] = vh->point();
      }
      tsmc.stop();
      
      
      tsmq.start();
      for(Vertex_handle vh : vertices){
        v = v + (sm[vh] - CGAL::ORIGIN);
      }
      tsmq.stop();
    }
    {
      tsumc.start();
      SUM sm;
      for(Vertex_handle vh : vertices){
        sm[vh] = vh->point();
      }
      tsumc.stop();
      
      
      tsumq.start();
      for(Vertex_handle vh : vertices){
        v = v + (sm[vh] - CGAL::ORIGIN);
      }
      tsumq.stop();
    }
    {
      tbumc.start();
      BUM sm;
      for(Vertex_handle vh : vertices){
        sm[vh] = vh->point();
      }
      tbumc.stop();
      
      
      tbumq.start();
      for(Vertex_handle vh : vertices){
        v = v + (sm[vh] - CGAL::ORIGIN);
      }
      tbumq.stop();
    }
  }
  std::cerr << ii << " items and queries (repeated " << jj << " times)" << std::endl;
  std::cerr << "std::map             construction : "<< tsmc.time() << " sec." << std::endl;
  std::cerr << "std::map             queries      : "<< tsmq.time() << " sec." << std::endl;
  
  std::cerr << "std::unordered_map   construction : "<< tsumc.time() << " sec." << std::endl;
  std::cerr << "std::unordered_map   queries      : "<< tsumq.time() << " sec." << std::endl;
  
  std::cerr << "boost::unordered_map construction : "<< tbumc.time() << " sec." << std::endl;
  std::cerr << "boost::unordered_map queries      : "<< tbumq.time() << " sec.\n" << std::endl;
}