Пример #1
0
int main(int argc, char* argv[])
{
  CGAL::Timer timer;
  // first param is dimension
  // second param is number of points
  int dimension = 4;
  int n = 100;
  int m = 100;

  if (argc > 1 && std::string(argv[1])== std::string("-h")) {
    std::cout<<"usage: "<<argv[0]<<" [dim] [#points] [max coords]\n";
    return 1;
  }
  if (argc > 1)  dimension = atoi(argv[1]);
  if (argc > 2)  n = atoi(argv[2]);
  if (argc > 3)  m = atoi(argv[2]);

  Delaunay_d T(dimension);
  std::list<Point_d> L;

  random_points_in_range(n,dimension,-m,m,L);

  timer.start();
  int i=0;
  std::list<Point_d>::iterator it;
  for(it = L.begin(); it!=L.end(); ++it) {
    T.insert(*it); i++;
    if (i%10==0)
      std::cout << i << " points inserted" << std::endl;
  }
  timer.stop();
  std::cout << "used time for inserts  " << timer.time() << std::endl;

  std::cout << "entering check" << std::endl;

  timer.reset();
  timer.start();
  T.is_valid();
  timer.stop();
  std::cout << "used time for sanity check  " << timer.time() << std::endl;
  

  std::cout << "entering nearest neighbor location" << std::endl;
  L.clear();
  random_points_in_range(n/10,dimension,-m,m,L);

  timer.reset();
  timer.start();
  i = 0;
  for(it = L.begin(); it!=L.end(); ++it) {
    T.nearest_neighbor(*it); i++;
    if (i%10==0) std::cout << i << " points located" << std::endl;
  }
  timer.stop();
  std::cout << "used time for location  " << timer.time() << std::endl;

  T.print_statistics();
  std::cout << "done" << std::endl;
  return 0;
}
int main() {
  const unsigned int N = 50;
  CGAL::Timer timer;
  timer.start();

  std::vector<Point_3> points, queries;
  Point_3 p;

  std::ifstream point_stream("points.xyz");
  while(point_stream >> p){
    points.push_back(p);

  }

  My_point_property_map ppmap(points);
  Distance tr_dist(ppmap);

  std::ifstream query_stream("queries.xyz");
  while(query_stream >> p ){
    queries.push_back(p);

  }
  timer.stop();
  std::cerr << "reading points took " << timer.time() << " sec." << std::endl;


  timer.reset();
  timer.start();
  Tree tree( boost::counting_iterator<std::size_t>(0),
             boost::counting_iterator<std::size_t>(points.size()),
             Splitter(),
             Traits(ppmap));
  tree.build();
  timer.stop();
  std::cerr << "tree construction took " << timer.time() << " sec." << std::endl;


  // Initialize the search structure, and search all N points
  
  double d = 0;
  timer.reset();
  timer.start();
  for(int i = 0; i < queries.size(); i++){
    K_neighbor_search search(tree, queries[i], 50, 0, true, tr_dist);

    // report the N nearest neighbors and their distance
    // This should sort all N points by increasing distance from origin
    for(K_neighbor_search::iterator it = search.begin(); it != search.end(); ++it){
      //std::cout << it->first << std::endl;
      d += get(ppmap,it->first).x();
    }
  }
  timer.stop();
  std::cerr << d << std::endl;
  std::cerr << queries.size() << " queries in " << timer.time() << " sec." << std::endl;

  return 0;
}
Пример #3
0
void time_insertion_and_check(pp_int V, int n, int d,
  CGAL::Convex_hull_d<R>& C, std::string s, bool check=true)
{
  typedef typename CGAL::Convex_hull_d<R>::chull_has_local_non_convexity
    chull_has_local_non_convexity;
  typedef typename CGAL::Convex_hull_d<R>::chull_has_double_coverage
    chull_has_double_coverage;
  typedef typename CGAL::Convex_hull_d<R>::
    chull_has_center_on_wrong_side_of_hull_facet
    chull_has_center_on_wrong_side_of_hull_facet;

  std::cout << " timing of " << s << std::endl;
  std::vector< CGAL::Point_d<R> > P(n); int i;
  for(i=0; i<n; ++i)
    P[i] = CGAL::Point_d<R>(d,V[i],V[i]+d,1);

  timer.reset(); timer.start(); // float ti = used_time();
  for(i=0; i<n; ++i) {
    C.insert(P[i]);
    if (i%10==0) std::cout << i << " points inserted" << std::endl;
  }
  timer.stop();
  double t = timer.time(); timer.reset(); // float t = used_time(ti);
  (*p_table_file) << s << "\t" << d << " " << n << " "
                  << C.number_of_vertices() << " " << C.number_of_facets()
                  << "\t" << t;
  C.print_statistics();
  std::cout << "used time for inserts  " << t << std::endl;

  C.clear(d);
  timer.start(); // ti = used_time();
  C.initialize(P.begin(),P.end());
  timer.stop(); t = timer.time(); timer.reset();
  // t = used_time(ti);
  C.print_statistics();
  std::cout << "used time for inserts  " << t << std::endl;

  if (check) {
    timer.start();
    std::cout << "entering check" << std::endl;
    try { C.is_valid(true); }
    catch ( chull_has_local_non_convexity )
    { std::cerr << "local non-convexity determined\n"; }
    catch ( chull_has_double_coverage )
    { std::cerr << "double coverage determined\n"; }
    catch ( chull_has_center_on_wrong_side_of_hull_facet )
    { std::cerr << "facet center problem determined\n"; }

    // t = used_time(ti);
    timer.stop(); t = timer.time();
    (*p_table_file) << "\t" << t <<std::endl;
    std::cout<<"used time for sanity check  "<< t <<std::endl<<std::endl;
  } else {
    (*p_table_file) << "\t" << "no"<<std::endl;
    std::cout<<"no check"<<std::endl;
  }
  p_table_file->flush();
}
Пример #4
0
int main(int argc, char **argv)
{
  int N = 100; if( argc > 2 )N = atoi(argv[1]); // number of points
  CGAL::Timer cost;  // timer

  // Instanciate a random point generator
  CGAL::Random rng(0);
  typedef CGAL::Random_points_in_cube_d<T::Point> Random_points_iterator;
  Random_points_iterator rand_it(D, 1.0, rng);
  // Generate N random points
  std::vector<T::Point> points;
  CGAL::cpp11::copy_n(rand_it, N, std::back_inserter(points));
  
  T t(D);
  CGAL_assertion(t.empty());
  
  // insert the points in the triangulation
  cost.reset();cost.start();
  std::cout << "  Delaunay triangulation of "<<N<<" points in dim "<<D<< std::flush;
  t.insert(points.begin(), points.end());
  std::cout << " done in "<<cost.time()<<" seconds." << std::endl;
  CGAL_assertion( t.is_valid() );

  // insert with special operations in conflict zone and new created cells
  cost.reset();
  std::cout << "  adding "<<N<<" other points "<< std::endl;
  for(int i=0; i<N; ++i)
  {
    T::Vertex_handle v;
    T::Face f(t.current_dimension()); 
    T::Facet ft; 
    T::Full_cell_handle c; 
    T::Locate_type lt;
    typedef std::vector<T::Full_cell_handle> Full_cells; 
    Full_cells zone, new_full_cells; 
    std::back_insert_iterator<Full_cells> out(zone); 
    c = t.locate(*++rand_it, lt, f, ft, v);
    // previously inserted vertex v is used as hint for point location (if defined)
    T::Facet ftc = t.compute_conflict_zone(*rand_it, c, out); 
    std::cout<<i<<"     conflict zone of size "<<zone.size()<<" -> "<<std::flush;
    out = std::back_inserter(new_full_cells);
    CGAL_assertion( t.is_valid() );
    v = t.insert_in_hole(*rand_it, zone.begin(), zone.end(), ftc, out);
    std::cout<<new_full_cells.size()<<" new cells"<<std::endl;
  }

  std::cout << " done in "<<cost.time()<<" seconds." << std::endl;
  return 0;
}
Пример #5
0
/**
 * Note that it always return EXIT_SUCCESS if .off file is read successfully.
 */
int main(void)
{	
    Polyhedron mesh;
    if( !read_to_polyhedron("./data/cactus.off", mesh) ) { return 1; }
  
    typedef std::map<Polyhedron::Facet_const_handle, double> Facet_double_map;
    Facet_double_map internal_map;
    
    CGAL::Timer timer; timer.start();
    std::pair<double, double> min_max_sdf = CGAL::sdf_values(mesh, 
      boost::associative_property_map<Facet_double_map>(internal_map) );
    std::cout << "minimum sdf: " << min_max_sdf.first << " maximum sdf: " << min_max_sdf.second << std::endl;
    std::cout << "Calculation time (fast traversal on): *** " << timer.time() << std::endl;

    timer.reset();
    Facet_double_map internal_map_2;
    min_max_sdf = CGAL::sdf_values<false>(mesh, 
      boost::associative_property_map<Facet_double_map>(internal_map_2) );
    std::cout << "minimum sdf: " << min_max_sdf.first << " maximum sdf: " << min_max_sdf.second << std::endl;
    std::cout << "Calculation time (fast traversal off): *** " << timer.time() << std::endl;

    timer.reset();
    typedef std::map<Polyhedron::Facet_const_handle, std::size_t> Facet_int_map;
    Facet_int_map internal_segment_map;
    // calculate SDF values and segment the mesh using default parameters.
    std::size_t number_of_segments = CGAL::segmentation_via_sdf_values(mesh, 
      boost::associative_property_map<Facet_int_map>(internal_segment_map));
    std::cout << "Number of segments: " << number_of_segments << std::endl;
    std::cout << "Calculation time (fast traversal on): *** " << timer.time() << std::endl;

    timer.reset();
    Facet_int_map internal_segment_map_2;
    // calculate SDF values and segment the mesh using default parameters.
    number_of_segments = CGAL::segmentation_via_sdf_values<false>(mesh, 
      boost::associative_property_map<Facet_int_map>(internal_segment_map_2));
    std::cout << "Number of segments: " << number_of_segments << std::endl;
    std::cout << "Calculation time (fast traversal off): *** " << timer.time() << std::endl;

}
Пример #6
0
void
insert_constraints_using_spatial_sort(SDG& sdg)
{
  typedef typename Points_container::const_iterator Points_iterator;
  typedef std::vector<Points_iterator> Indices;
  typedef std::vector<typename SDG::Vertex_handle> Vertices;

  Sort_traits_2<K, Points_iterator> sort_traits;

  Indices indices;
  indices.reserve(points.size());
  for(Points_iterator it = points.begin(); it != points.end(); ++it) {
    indices.push_back(it);
  }
  std::random_shuffle(indices.begin(), indices.end());
  CGAL::spatial_sort(indices.begin(), indices.end(),
                     sort_traits);

  std::cerr << "Inserting " << points.size() << " points...";
  CGAL::Timer timer;
  timer.start();
  Vertices vertices;
  vertices.resize(points.size());
  typename SDG::Vertex_handle hint;
  for(typename Indices::const_iterator
        pt_it_it = indices.begin(), end = indices.end();
      pt_it_it != end; ++pt_it_it) {
    typename SDG::Vertex_handle vh = sdg.insert(**pt_it_it, hint);
    hint = vh;
    vertices[*pt_it_it - points.begin()] = vh;
  }
  timer.stop();
  std::cerr << " done (" << timer.time() << "s)\n";

  std::cerr << "Inserting " << constraints.size() << " constraints...";

  timer.reset();
  timer.start();
  for(typename Constraints_container::const_iterator
        cit = constraints.begin(), end = constraints.end();
      cit != end; ++cit) {
    const typename SDG::Vertex_handle& v1 = vertices[cit->first];
    const typename SDG::Vertex_handle& v2 = vertices[cit->second];
    if(v1 != v2)
      sdg.insert(v1, v2);
  }

  timer.stop();
  std::cerr << " done (" << timer.time() << "s)\n";
}
Пример #7
0
int main(){
    int N = 3;
    CGAL::Timer cost;
    std::vector<Point_d> points;
   

   Point_d point1(1,3,5);
   Point_d point2(4,8,10);
   Point_d point3(2,7,9);

    Point_d point(1,2,3);


    points.push_back(point1);
    points.push_back(point2);
    points.push_back(point3);
   
    K Kernel 
    D Dt(d,Kernel,Kernel);
  //  CGAL_assertion(Dt.empty());
   
    // insert the points in the triangulation
    cost.reset();cost.start();
    std::cout << "  Delaunay triangulation of "<<N<<" points in dim "<<d<< std::flush;
    std::vector<Point_d>::iterator it;
    for(it = points.begin(); it!= points.end(); ++it){
	Dt.insert(*it); 
    }
    std::list<Simplex_handle> NL = Dt.all_simplices(D::NEAREST);
    std::cout << " done in "<<cost.time()<<" seconds." << std::endl;
    CGAL_assertion(Dt.is_valid() );
    CGAL_assertion(!Dt.empty());
 
   
    Vertex_handle v = Dt.nearest_neighbor(point);
    Simplex_handle s = Dt.simplex(v);    
     
    std::vector<Point_d> Simplex_vertices;
    for(int j=0; j<=d; ++j){
 	  Vertex_handle vertex = Dt.vertex_of_simplex(s,j);
       	  Simplex_vertices.push_back(Dt.associated_point(vertex));
     }
    
    std::vector<K::FT> coords;
    K::Barycentric_coordinates_d BaryCoords;
    BaryCoords(Simplex_vertices.begin(), Simplex_vertices.end(),point,std::inserter(coords, coords.begin()));
    std::cout << coords[0] << std::endl; 
   return 0;
}
int main()
{
  const int d = 10;       // change this in order to experiment
  const int n = 100000;   // change this in order to experiment

  // generate n random d-dimensional points in [0,1]^d
  CGAL::Random rd;
  std::vector<Point_d> points;
  for (int j =0; j<n; ++j) {
    std::vector<double> coords;
    for (int i=0; i<d; ++i) 
      coords.push_back(rd.get_double());
    points.push_back (Point_d (d, coords.begin(), coords.end()));
  }
  
  // benchmark all pricing strategies in turn
  CGAL::Quadratic_program_pricing_strategy strategy[] = {
    CGAL::QP_CHOOSE_DEFAULT,              // QP_PARTIAL_FILTERED_DANTZIG
    CGAL::QP_DANTZIG,                     // Dantzig's pivot rule...
    CGAL::QP_PARTIAL_DANTZIG,             // ... with partial pricing
    CGAL::QP_BLAND,                       // Bland's pivot rule
    CGAL::QP_FILTERED_DANTZIG,            // Dantzig's filtered pivot rule...
    CGAL::QP_PARTIAL_FILTERED_DANTZIG     // ... with partial pricing
  };
  
  CGAL::Timer t;
  for (int i=0; i<6; ++i) {
    // test strategy i
    CGAL::Quadratic_program_options options;
    options.set_pricing_strategy (strategy[i]);
    t.reset(); t.start();
    // is origin in convex hull of the points? (most likely, not)
    solve_convex_hull_containment_lp 
      (Point_d (d, CGAL::ORIGIN), points.begin(), points.end(), 
       ET(0), options);
    t.stop();
    std::cout << "Time (s) = " << t.time() << std::endl;
  }

  return 0;
}
int main()
{
	CGAL::Timer t;
	t.start();
	Tr tr;            // 3D-Delaunay triangulation
	C2t3 c2t3 (tr);   // 2D-complex in 3D-Delaunay triangulation

	// defining the surface
	Surface_3 surface(klein_function,             // pointer to function
	      	    Sphere_3(CGAL::ORIGIN, 2.)); // bounding sphere
	// Note that "2." above is the *squared* radius of the bounding sphere!

	// defining meshing criteria
	CGAL::Surface_mesh_default_criteria_3<Tr> criteria(30.,  // angular bound
	      					     0.1,  // radius bound
	      					     0.1); // distance bound
	// meshing surface
	CGAL::make_surface_mesh(c2t3, surface, criteria, CGAL::Non_manifold_tag());

	CGAL::Random rand;
	
	t.stop();
	std::cout << "Time elapsed for building the mesh: " << t.time() << std::endl;
	t.reset();

	t.start();
	int nr = 1000;
	std::vector<Point_3> points;
	points.reserve(nr);
	CGAL::Random_points_on_surface_mesh_3<Point_3, C2t3> g(c2t3);
	t.stop();
	std::cout << "Time elapsed for init Random_points_in_surface_mesh_3: " <<
		t.time() << std::endl;
	t.reset();

	t.start();
	CGAL::cpp11::copy_n( g, nr, std::back_inserter(points));
	t.stop();
	std::cout << "Time elapsed for generating the points: " << t.time() << std::endl;
	t.reset();

	std::cout << "Actual number of facet: " <<c2t3.number_of_facets() << "\n";
	int cont = 0;
	C2t3::Facet_iterator it = c2t3.facets_begin();
	for (; it != c2t3.facets_end(); ++it) {
		Vertex v[4];
		int k = 0;
		for(int j = 0; j < 4; j++)
		{
			if(j == it->second) continue;
			v[k] = it->first->vertex(j);
			k++;
		}
		Triangle_3 aux(v[0]->point(), v[1]->point(),
				v[2]->point());
		std::cout << aux.vertex(0).x() << " "<< aux.vertex(0).y() << " "<<
			aux.vertex(0).z() << "\n";
		std::cout << aux.vertex(1).x() << " "<< aux.vertex(1).y() << " "<<
			aux.vertex(1).z() << "\n";
		std::cout << aux.vertex(2).x() << " "<< aux.vertex(2).y() << " "<<
			aux.vertex(2).z() << "\n";
		cont++;
	}
	std::cout << "Number of facets counted by me " << cont << '\n';

	std::cout << "The generated points are: " << std::endl;
	for (int i = 0; i < nr; i++) {
		std::cout << points[i].x() << " " << points[i].y() << " " <<
			points[i].z() << std::endl;
	}
	points.clear();
	return 0;
}
  void operator()() const
  {
    //-------------------------------------------------------
    // Data generation : get 4 nearly coplanar points
    //-------------------------------------------------------
    Point_creator creator;
    FT little(1e-10);
    FT tiny(1e-25);
    
    Point p1 = creator(little,1,tiny);
    Point p2 = creator(1,little,0);
    Point p3 = creator(-1*little,1,0);
    Point p4 = creator(1,-1*little,0);
    Point p5 = creator(0,0,1);
    Point p6 = creator(0,1,0);

    std::cerr << "Using points: p1[" << p1 << "]\tp2[" << p2
              << "]\tp3[" << p3 << "]\tp4[" << p4 << "]\tp5[" << p5
              << "]\tp6[" << p6 << "]\n";

    //-------------------------------------------------------
    // Test correctness
    //-------------------------------------------------------
    typename Gt::Construct_weighted_circumcenter_3 circumcenter =
        Gt().construct_weighted_circumcenter_3_object();

    Point center = circumcenter(p1,p2);
    std::cerr << "\tcircumcenter(p1,p2)=[" << center << "]\n";

    center = circumcenter(p1,p3,p6);
    std::cerr << "\tcircumcenter(p1,p3,p6)=[" << center << "]\n";

    center = circumcenter(p1,p2,p5);
    std::cerr << "\tcircumcenter(p1,p3,p5)=[" << center << "]\n";

    // Use positive orientation
    center = circumcenter(p2,p3,p4,p1);
    std::cerr << "\tcircumcenter(p2,p3,p4,p1)=[" << center << "]\n";

    center = circumcenter(p1,p3,p2,p5);
    std::cerr << "\tcircumcenter(p1,p3,p2,p5)=[" << center << "]\n";


    //-------------------------------------------------------
    // Test speed
    //-------------------------------------------------------
    std::cerr << "Test speed: compute loops of: 999*c(p1,p3,p2,p5) "
              << "and 1*c(p2,p3,p4,p1)\n";

    CGAL::Timer timer;
    timer.start();
    int nb_loop = 0;
    while ( timer.time() < 0.5 )
    {
      // Compute 1000 fast queries
      for ( int i = 0 ; i < 999 ; ++i)
        circumcenter(p1,p3,p2,p5);

      // Compute 1 exact query
      circumcenter(p2,p3,p4,p1);
      ++nb_loop;
    }
    timer.stop();
    std::cerr << "\t" << nb_loop*1000/timer.time()
              << " circumcenter computation / second\n";

    
    std::cerr << "Test speed: compute loops of: 999*c(p2,p3,p4,p1) "
              << "and 1*c(p1,p3,p2,p5)\n";
    
    timer.reset();
    timer.start();
    nb_loop = 0;
    while ( timer.time() < 0.5 )
    {
      // Compute 1 exact queries
      for ( int i = 0 ; i < 999 ; ++i)
        circumcenter(p2,p3,p4,p1);
      
      // Compute 1 fast query
      circumcenter(p1,p3,p2,p5);
      ++nb_loop;
    }
    timer.stop();
    std::cerr << "\t" << nb_loop*1000/timer.time()
              << " circumcenter computation / second\n";
    
  }
int main(int argc, char* argv[])
{
  std::cerr.precision(17);

  std::ifstream points_file(argv[2]);

  std::vector<Point> points;
  std::copy(std::istream_iterator<Point>(points_file),
            std::istream_iterator<Point>(),
            std::back_inserter(points));


  int gridsize = 10;
  if(argc>3){
    gridsize = boost::lexical_cast<int>(argv[3]);
  }
  std::cerr << "gridsize = " << gridsize << std::endl;
  
  int nb_points=points.size();
  
  std::vector<bool> ray_res(nb_points);
  std::vector<bool> grid_res(nb_points);
  
  //using ray
  {
    Polyhedron polyhedron;
    std::ifstream polyhedron_file(argv[1]);
    polyhedron_file >> polyhedron;
    std::cerr << "|V| = " << polyhedron.size_of_vertices() << std::endl;
    
    CGAL::Timer timer;
    timer.start();
    CGAL::Point_inside_polyhedron_3<Polyhedron,K> inside_with_ray(polyhedron,0);
    timer.stop();
    std::cerr <<"Using ray"<< std::endl;
    std::cerr << "  Preprocessing took " << timer.time() << " sec." << std::endl;
    timer.reset();  
    int n_inside = 0;
    
    timer.start();
    for(int k=0;k<nb_points;++k){
      ray_res[k]=inside_with_ray(points[k]);
      if(ray_res[k]){
        ++n_inside;
      }
    }
    timer.stop();
    std::cerr << "  " << n_inside << " points inside " << std::endl;
    std::cerr << "  " << points.size() - n_inside << " points outside "  << std::endl;
    std::cerr << " Queries took " << timer.time() << " sec." << std::endl; 

  }
  
  //using grid
  {
    Polyhedron polyhedron;
    std::ifstream polyhedron_file(argv[1]);
    polyhedron_file >> polyhedron;
    std::cerr << "|V| = " << polyhedron.size_of_vertices() << std::endl;
    
    CGAL::Timer timer;
    timer.start();
    CGAL::Point_inside_polyhedron_3<Polyhedron,K> inside_with_grid(polyhedron, gridsize);
    timer.stop();
    std::cerr <<"Using grid"<< std::endl;
    std::cerr << "  Preprocessing took " << timer.time() << " sec." << std::endl;
    timer.reset();

    if(argc>5){
      random_points(argv[4],inside_with_grid.bbox() ,boost::lexical_cast<int>(argv[5]) );
    }
    
    int n_inside = 0;
    timer.start();
    for(int k=0;k<nb_points;++k){
      grid_res[k]=inside_with_grid(points[k]);
      if(grid_res[k]){
        ++n_inside;
      }
    }
    timer.stop();
    std::cerr << "  " << n_inside << " points inside " << std::endl;
    std::cerr << "  " << points.size() - n_inside << " points outside "  << std::endl;
    std::cerr << "  Queries took " << timer.time() << " sec." << std::endl; 
  }

  for(int k=0;k<nb_points;++k){
    if(ray_res[k]!=grid_res[k]){
      std::cerr << "WARNING: Result is different for point " << k << std::endl;
    }
  }
  
  //using original code
  {
    Polyhedron polyhedron;
    std::ifstream polyhedron_file(argv[1]);
    polyhedron_file >> polyhedron;
    std::cerr << "|V| = " << polyhedron.size_of_vertices() << std::endl;

    
    std::cerr <<"Using ray (original code)"<< std::endl;
    CGAL::Point_inside_polyhedron_3<Polyhedron,K> inside_with_ray(polyhedron,0);
    
    CGAL::Timer timer;  
    int n_inside = 0;
    timer.start();
    for(int k=0;k<nb_points;++k)
      if(inside_with_ray(points[k],true)) ++n_inside;
    timer.stop();
    std::cerr << "  " << n_inside << " points inside " << std::endl;
    std::cerr << "  " << points.size() - n_inside << " points outside "  << std::endl;
    std::cerr << "  Queries took " << timer.time() << " sec." << std::endl; 
  }
  
  return 0;
}
/**
 * Executes one custom timestep
 * @param averageEdgeLength The function to compute the average edge length for a given vertex
 * @param getOffsetPoint Computes the new location of the given point
 * @return The results of running the timestep
 */
stepResults StoneWeatherer::doOneCustomStep( double ( *averageEdgeLength )( const Vertex_handle & v ), Point( *getOffsetPoint )( const Point & p, const VertexData & d, const StoneWeatherer * caller ) ) {

	CGAL::Timer timestamp;
	stepResults result;
	result.secondsTotal = 0.0;
	timestamp.start();
	timestamp.reset();
	
	/**
	 * Maps circumcenters to where they really came from
	 */
	 map<Point,Point> pointMap;

	// Generate the correct-resolution offset points
	vector<Point> newPoints;
	int n;
	int i;
	int j;
	Vertex_handle vhi;
	Vertex_handle vhj;
	double dist2;
	Point a;
	Point b;
	Point c;
	VertexData d;

	// Put in midPoints of edges as needed, and flag redundant vertices
	for ( Cell_iterator it = newDT->finite_cells_begin(); it != newDT->finite_cells_end(); ++it ) {

		if ( it->info() != AIR ) {
			
			for ( n = 0; n < 4; ++n ) {

				if ( it->neighbor( n )->info() != it->info() || newDT->is_infinite( it->neighbor( n ) ) ) {

					for ( i = 1; i < 4; ++i ) {

						Vertex_handle vhi = it->vertex( n ^ i );

						for ( j = i + 1; j < 4; ++j ) {

							Vertex_handle vhj = it->vertex( n ^ j );

							// Only check each edge once...
							if ( vhi < vhj ) {

								dist2 = ( vhi->point() - vhj->point() ).squared_length();

								if ( dist2 > maxSquareDistance( averageEdgeLength, vhi, vhj ) ) {

									// Don't split non-live edges
									a = vhi->point();
									b = vhj->point();

									if ( !live( a.x(), a.y(), a.z() ) && !live( b.x(), b.y(), b.z() ) ) {

										continue;
									}

									// Split edge
									a = CGAL::ORIGIN + ( ( a - CGAL::ORIGIN ) + ( b - CGAL::ORIGIN ) ) * 0.5;
									d = VertexData::midPoint( vhi->info(), vhj->info() );
									
									//// If the vertex is shared by both objects, split it
									//if ( ( d.flag & ROCK ) && ( d.flag & MORE_ROCK ) ) {

									//	VertexData d1;
									//	VertexData d2;
									//	splitVertexData( d, d1, d2 );
									//	
									//	Point a1 = jitterPoint( a );
									//	Point a2 = jitterPoint( a );
									//	
									//	c = getOffsetPoint( a1, d1, this );
									//	newPoints.push_back( c );
									//	pointMap.insert( pair<Point,Point>( c, a1 ) );

									//	c = getOffsetPoint( a2, d2, this );
									//	newPoints.push_back( c );
									//	pointMap.insert( pair<Point,Point>( c, a2 ) );
									//}
									//else {

										c = getOffsetPoint( a, d, this );
										newPoints.push_back( c );
										pointMap.insert( pair<Point,Point>( c, a ) );
									//}
								}
								else if ( vhi->info().kill != TOO_CLOSE && dist2 < minSquareDistance( averageEdgeLength, vhi, vhj ) ) {

									// The higher-address endpoint
									vhj->info().kill = TOO_CLOSE;
								}
							}
						}
					}
				}
			}
		}
	}

	double bound[ 3 ][ 2 ] = {
		{ 1.0e30, -1.0e30 },
		{ 1.0e30, -1.0e30 },
		{ 1.0e30, -1.0e30 }
	};

	// Put in all the border vertices
	for ( Vertex_iterator it = newDT->finite_vertices_begin(); it != newDT->finite_vertices_end(); ++it ) {

		if ( it->point().x() < bound[ 0 ][ 0 ] ) {

			bound[ 0 ][ 0 ] = it->point().x();
		}
		else if ( it->point().x() > bound[ 0 ][ 1 ] ) {

			bound[ 0 ][ 1 ] = it->point().x();
		}

		if ( it->point().y() < bound[ 1 ][ 0 ] ) {

			bound[ 1 ][ 0 ] = it->point().y();
		}
		else if ( it->point().y() > bound[ 1 ][ 1 ] ) {

			bound[ 1 ][ 1 ] = it->point().y();
		}

		if ( it->point().z() < bound[ 2 ][ 0 ] ) {

			bound[ 2 ][ 0 ] = it->point().z();
		}
		else if ( it->point().z() > bound[ 2 ][ 1 ] ) {

			bound[ 2 ][ 1 ] = it->point().z();
		}

		if ( !live( it->point().x(), it->point().y(), it->point().z() ) ) {

			newPoints.push_back( it->point() );
			pointMap.insert( pair<Point,Point>( it->point(), it->point() ) );
		}
		else if ( it->info().kill == BORDER ) {

			VertexData d = it->info();
			Point a = it->point();
			Point c;

			//// If the vertex is shared by both objects, split it
			//if ( ( d.flag & ROCK ) && ( d.flag & MORE_ROCK ) ) {

			//	VertexData d1;
			//	VertexData d2;
			//	splitVertexData( d, d1, d2 );
			//	
			//	Point a1 = jitterPoint( a );
			//	Point a2 = jitterPoint( a );
			//	
			//	c = getOffsetPoint( a1, d1, this );
			//	newPoints.push_back( c );
			//	pointMap.insert( pair<Point,Point>( c, a1 ) );

			//	c = getOffsetPoint( a2, d2, this );
			//	newPoints.push_back( c );
			//	pointMap.insert( pair<Point,Point>( c, a2 ) );
			//}
			//else {

				c = getOffsetPoint( a, d, this );
				newPoints.push_back( c );
				pointMap.insert( pair<Point,Point>( c, a ) );
			//}
		}
	}

	result.secondsTotal += ( result.secondsMotion = timestamp.time() );
	timestamp.reset();

	// Create the new mesh
	swapDT();
	newDT->clear();
	newDT->insert( newPoints.begin(), newPoints.end() );

	result.secondsTotal += ( result.secondsCGAL = timestamp.time() );
	//secondsTotal += result.secondsCGAL;
	//secondsCGAL += result.secondsCGAL;
	timestamp.reset();

	// Update the inside-outside flags of new tetrahedrons
	setContentFlags( result.midPoint, pointMap );
	result.midPoint[ 0 ] = ( bound[ 0 ][ 0 ] + bound[ 0 ][ 1 ] ) * 0.5;
	result.midPoint[ 1 ] = ( bound[ 1 ][ 0 ] + bound[ 1 ][ 1 ] ) * 0.5;
	result.midPoint[ 2 ] = ( bound[ 2 ][ 0 ] + bound[ 2 ][ 1 ] ) * 0.5;

	result.secondsTotal += ( result.secondsLabeling = timestamp.time() );
	//secondsTotal += result.secondsLabeling;
	//secondsLabeling += result.secondsLabeling;
	timestamp.reset();

	// Update vertex information
	setVertexInfo();

	result.secondsTotal += ( result.secondsAnalysis = timestamp.time() );
	timestamp.reset();
	timestamp.stop();

	result.numVertices = newDT->number_of_vertices();
	result.numTetrahedrons = newDT->number_of_cells();

	cumulativeResults.secondsTotal += result.secondsTotal;
	cumulativeResults.secondsMotion += result.secondsMotion;
	cumulativeResults.secondsCGAL += result.secondsCGAL;
	cumulativeResults.secondsLabeling += result.secondsLabeling;
	cumulativeResults.secondsAnalysis += result.secondsAnalysis;

	return result;
}
Пример #13
0
int main(int argc, char* argv[]) {
    // We've put the typedefs here as VC7 gives us an ICE if they are global typedefs
    typedef Nef_polyhedron::SNC_structure SNC_structure;
    typedef CGAL::visual_hull_creator<SNC_structure> VHC;

    if(argc!=2) {
        std::cerr << "Usage: visual_hull file" << std::endl;
        std::cerr << "For more information read the README file" << std::endl;
        return 1;
    }

    std::ifstream in(argv[1]);

    NaryInt ni;

    CGAL::Timer t;

    Point_3 room_min = read_point(in);
    Point_3 room_max = read_point(in);

    int ncameras;
    in >> ncameras;
    for(int cam=0; cam<ncameras; ++cam) {

        Point_3 camera(read_point(in));

        int npolygons;
        in >> npolygons;

        std::list<std::list<Point_3> > polygon_list;
        for(int poly=0; poly<npolygons; ++poly) {

            int npoints;
            in >> npoints;

            std::list<Point_3> input_points;
            for(int pnt=0; pnt<npoints; ++pnt)
                input_points.push_back(read_point(in));
            polygon_list.push_back(input_points);
        }

        std::list<std::list<Point_3> >::iterator li;
        for(li=polygon_list.begin(); li!=polygon_list.end(); ++li) {
            std::list<Point_3>::iterator pi(li->begin()), pimin(pi), pi_next,pi_prev;
            for(; pi!=li->end(); ++pi) {
                if(CGAL::lexicographically_xyz_smaller(*pi,*pimin))
                    pimin=pi;
            }
            pi_next=pi_prev=pimin;
            ++pi_next;
            if(pi_next==li->end()) pi_next=li->begin();
            if(pi_prev==li->begin()) pi_prev=li->end();
            --pi_prev;
            if(CGAL::orientation(*pi_prev,*pimin,*pi_next,camera)
                    == CGAL::POSITIVE)
                li->reverse();
        }

        t.start();
        Nef_polyhedron N;
        VHC vhc(room_min, room_max, camera, polygon_list);
        N.delegate(vhc,true);
        CGAL_assertion(N.is_valid());
        t.stop();
        std::cerr << "create view " << t.time() << std::endl;
        t.reset();
        ni.add_polyhedron(N);
    }

    Nef_polyhedron result = ni.get_intersection();

    QApplication a(argc,argv);
    CGAL::Qt_widget_Nef_3<Nef_polyhedron>* w =
        new CGAL::Qt_widget_Nef_3<Nef_polyhedron>(result);
    a.setMainWidget(w);
    w->show();
    a.exec();
}
Пример #14
0
int main ()
{
  int nb_points_2 = 5000, nb_points_3 = 5000, 
    nb_points_d=10000, small_nb_points_d=3;
  CGAL::Random random (42);
  CGAL::Timer cost;

    std::cout << "Testing Hilbert sort." << std::endl;

    {
      std::cout << "Testing 2D: Generating "<<nb_points_2<<" random points... " << std::flush;

        std::vector<Point_2> v;
        v.reserve (nb_points_2);

        CGAL::Random_points_in_square_2<Point_2> gen (1.0, random);

        for (int i = 0; i < nb_points_2; ++i)
            v.push_back (*gen++);

        std::cout << "done." << std::endl;

        std::vector<Point_2> v2 (v);

        std::cout << "            Sorting points...    " << std::flush;

	cost.reset();cost.start();
        CGAL::hilbert_sort (v.begin(), v.end());
	cost.stop();

        std::cout << "done in "<<cost.time()<<"seconds." << std::endl;

        std::cout << "            Checking...          " << std::flush;

        std::sort (v.begin(),  v.end(),  K().less_xy_2_object());
        std::sort (v2.begin(), v2.end(), K().less_xy_2_object());
        assert(v == v2);

        std::cout << "no points lost." << std::endl;
    }
    {
	int size=256;               // 2^(xd)   with x=4 d=2
	double box_size = 15.0;     // 2^x -1
	std::cout << "Testing 2D: Generating "<<size<<" grid points... " << std::flush;
        std::vector<Point_2> v; 
	v.reserve(size);

        CGAL::points_on_square_grid_2 (box_size, (std::size_t)size, 
				     std::back_inserter(v), Creator_2() );

        std::cout << "done." << std::endl;

        std::cout << "            Sorting points...    " << std::flush;

	cost.reset();cost.start();
        CGAL::hilbert_sort (v.begin(), v.end());
	cost.stop();

        std::cout << "done in "<<cost.time()<<"seconds." << std::endl;

        std::cout << "            Checking...          " << std::flush;

        for (int i = 0; i < size-1; ++i) 
	  assert(CGAL::squared_distance( v[i], v[i+1]) - 4.0 < 0.1 );

        std::cout << "OK." << std::endl;
    }
    {
      std::cout << "Testing 2D (middle policy): Generating "
		<<nb_points_2<<" random points... " << std::flush;

        std::vector<Point_2> v;
        v.reserve (nb_points_2);

        CGAL::Random_points_in_square_2<Point_2> gen (1.0, random);

        for (int i = 0; i < nb_points_2; ++i)
            v.push_back (*gen++);

        std::cout << "done." << std::endl;

        std::vector<Point_2> v2 (v);

        std::cout << "            Sorting points...    " << std::flush;

	cost.reset();cost.start();
        CGAL::hilbert_sort(v.begin(),v.end(), CGAL::Hilbert_sort_middle_policy());
	cost.stop();

        std::cout << "done in "<<cost.time()<<"seconds." << std::endl;

        std::cout << "            Checking...          " << std::flush;

        std::sort (v.begin(),  v.end(),  K().less_xy_2_object());
        std::sort (v2.begin(), v2.end(), K().less_xy_2_object());
        assert(v == v2);

        std::cout << "no points lost." << std::endl;
    }
    {
	int size=256;               // 2^(xd)
	double box_size = 15.0;     // 2^x -1                with x=4 d=2
	std::cout << "Testing 2D (middle policy): Generating "
		  <<size<<" grid points... " << std::flush;
        std::vector<Point_2> v; 
	v.reserve(size);

        CGAL::points_on_square_grid_2 (box_size, (std::size_t)size, 
				     std::back_inserter(v), Creator_2() );

        std::cout << "done." << std::endl;

        std::cout << "            Sorting points...    " << std::flush;

	cost.reset();cost.start();
        CGAL::hilbert_sort(v.begin(),v.end(), CGAL::Hilbert_sort_middle_policy());
	cost.stop();

        std::cout << "done in "<<cost.time()<<"seconds." << std::endl;

        std::cout << "            Checking...          " << std::flush;

        for (int i = 0; i < size-1; ++i) {
	  assert(CGAL::squared_distance( v[i], v[i+1]) - 4.0 < 0.1 );
	}
        std::cout << "OK." << std::endl;
    }

    {
      std::cout << "Testing 3D: Generating "<<nb_points_3<<" random points... " << std::flush;

        std::vector<Point_3> v;
        v.reserve (nb_points_3);

        CGAL::Random_points_in_cube_3<Point_3> gen (1.0, random);

        for (int i = 0; i < nb_points_3; ++i)
            v.push_back (*gen++);

        std::cout << "done." << std::endl;

        std::vector<Point_3> v2 (v);

        std::cout << "            Sorting points...    " << std::flush;

	cost.reset();cost.start();
        CGAL::hilbert_sort (v.begin(), v.end());
	cost.stop();

        std::cout << "done in "<<cost.time()<<"seconds." << std::endl;

        std::cout << "            Checking...          " << std::flush;

        std::sort (v.begin(),  v.end(),  K().less_xyz_3_object());
        std::sort (v2.begin(), v2.end(), K().less_xyz_3_object());
        assert(v == v2);

        std::cout << "no points lost." << std::endl;
    }
    {
	int size=512;              // 2^(xd)   with x=3 d=3
	double box_size = 7.0;     // 2^x -1

	std::cout << "Testing 3D: Generating "<<size<<" grid points... " << std::flush;

        std::vector<Point_3> v;
	v.reserve(size);

        CGAL::points_on_cube_grid_3 (box_size, (std::size_t)size, 
				     std::back_inserter(v), Creator_3() );

        std::cout << "done." << std::endl;

        std::cout << "            Sorting points...    " << std::flush;

	cost.reset();cost.start();
        CGAL::hilbert_sort (v.begin(), v.end());
	cost.stop();

        std::cout << "done in "<<cost.time()<<"seconds." << std::endl;

        std::cout << "            Checking...          " << std::flush;

        for (int i = 0; i < size-1; ++i)
	  assert(CGAL::squared_distance( v[i], v[i+1]) - 4.0 < 0.1 );

        std::cout << "OK." << std::endl;
    }

    {
      std::cout << "Testing 3D (middle policy): Generating "<<nb_points_3<<" random points... " << std::flush;

        std::vector<Point_3> v;
        v.reserve (nb_points_3);

        CGAL::Random_points_in_cube_3<Point_3> gen (1.0, random);

        for (int i = 0; i < nb_points_3; ++i)
            v.push_back (*gen++);

        std::cout << "done." << std::endl;

        std::vector<Point_3> v2 (v);

        std::cout << "            Sorting points...    " << std::flush;

	cost.reset();cost.start();
        CGAL::hilbert_sort(v.begin(),v.end(),CGAL::Hilbert_sort_middle_policy());
	cost.stop();

        std::cout << "done in "<<cost.time()<<"seconds." << std::endl;

        std::cout << "            Checking...          " << std::flush;

        std::sort (v.begin(),  v.end(),  K().less_xyz_3_object());
        std::sort (v2.begin(), v2.end(), K().less_xyz_3_object());
        assert(v == v2);

        std::cout << "no points lost." << std::endl;
    }
    {
      int size=4096;              // 2^(xd)   with x=4 d=3
      double box_size = 15.0;     // 2^x -1

	std::cout << "Testing 3D (middle policy): Generating "<<size<<" grid points... " << std::flush;

        std::vector<Point_3> v;
	v.reserve(size);

        CGAL::points_on_cube_grid_3 (box_size, (std::size_t)size, 
				     std::back_inserter(v), Creator_3() );

        std::cout << "done." << std::endl;

        std::cout << "            Sorting points...    " << std::flush;

	cost.reset();cost.start();
        CGAL::hilbert_sort(v.begin(),v.end(),CGAL::Hilbert_sort_middle_policy());
	cost.stop();

        std::cout << "done in "<<cost.time()<<"seconds." << std::endl;

        std::cout << "            Checking...          " << std::flush;

        for (int i = 0; i < size-1; ++i) {
	  assert(CGAL::squared_distance( v[i], v[i+1]) - 4.0 < 0.1 );
	}
        std::cout << "OK." << std::endl;
    }
	{
      std::cout << "Testing Spherical (median policy): Generating "<<nb_points_3<<" random points... " << std::flush;

        std::vector<Point_3> v;
        v.reserve (nb_points_3);

        CGAL::Random_points_on_sphere_3<Point_3> gen (1.0, random);

        for (int i = 0; i < nb_points_3; ++i)
            v.push_back (*gen++);

        std::cout << "done." << std::endl;

        std::vector<Point_3> v2 (v);

        std::cout << "            Sorting points...    " << std::flush;

	cost.reset();cost.start();
        CGAL::hilbert_sort(v.begin(),v.end());
	cost.stop();

        std::cout << "done in "<<cost.time()<<"seconds." << std::endl;

        std::cout << "            Checking...          " << std::flush;

        std::sort (v.begin(),  v.end(),  K().less_xyz_3_object());
        std::sort (v2.begin(), v2.end(), K().less_xyz_3_object());
        assert(v == v2);

        std::cout << "no points lost." << std::endl;
    }
    {
      std::cout << "Testing Spherical (median policy) + given sphere: Generating "<<nb_points_3<<" random points... " << std::flush;

        std::vector<Point_3> v;
        v.reserve (nb_points_3);

        CGAL::Random_points_on_sphere_3<Point_3> gen (2.0, random);

        for (int i = 0; i < nb_points_3; ++i)
            v.push_back (*gen++ + Vector_3(3,5,5));

        std::cout << "done." << std::endl;

        std::vector<Point_3> v2 (v);

        std::cout << "            Sorting points...    " << std::flush;

	cost.reset();cost.start();
        CGAL::hilbert_sort_on_sphere(v.begin(),v.end(), 4, CGAL::ORIGIN + Vector_3(3,5,5));
	cost.stop();

        std::cout << "done in "<<cost.time()<<"seconds." << std::endl;

        std::cout << "            Checking...          " << std::flush;

        std::sort (v.begin(),  v.end(),  K().less_xyz_3_object());
        std::sort (v2.begin(), v2.end(), K().less_xyz_3_object());
        assert(v == v2);

        std::cout << "no points lost." << std::endl;
    }
	{
      std::cout << "Testing Spherical (middle policy): Generating "<<nb_points_3<<" random points... " << std::flush;

        std::vector<Point_3> v;
        v.reserve (nb_points_3);

        CGAL::Random_points_on_sphere_3<Point_3> gen (1.0, random);

        for (int i = 0; i < nb_points_3; ++i)
            v.push_back (*gen++);

        std::cout << "done." << std::endl;

        std::vector<Point_3> v2 (v);

        std::cout << "            Sorting points...    " << std::flush;

	cost.reset();cost.start();
        CGAL::hilbert_sort_on_sphere(v.begin(),v.end(),CGAL::Hilbert_sort_middle_policy());
	cost.stop();

        std::cout << "done in "<<cost.time()<<"seconds." << std::endl;

        std::cout << "            Checking...          " << std::flush;

        std::sort (v.begin(),  v.end(),  K().less_xyz_3_object());
        std::sort (v2.begin(), v2.end(), K().less_xyz_3_object());
        assert(v == v2);

        std::cout << "no points lost." << std::endl;
    }
    {
      std::cout << "Testing Spherical (middle policy) + given sphere: Generating "<<nb_points_3<<" random points... " << std::flush;

        std::vector<Point_3> v;
        v.reserve (nb_points_3);

        CGAL::Random_points_on_sphere_3<Point_3> gen (2.0, random);

        for (int i = 0; i < nb_points_3; ++i)
            v.push_back (*gen++ + Vector_3(3,5,5));

        std::cout << "done." << std::endl;

        std::vector<Point_3> v2 (v);

        std::cout << "            Sorting points...    " << std::flush;

	cost.reset();cost.start();
        CGAL::hilbert_sort_on_sphere(v.begin(),v.end(),CGAL::Hilbert_sort_middle_policy(), 4, CGAL::ORIGIN + Vector_3(3,5,5));
	cost.stop();

        std::cout << "done in "<<cost.time()<<"seconds." << std::endl;

        std::cout << "            Checking...          " << std::flush;

        std::sort (v.begin(),  v.end(),  K().less_xyz_3_object());
        std::sort (v2.begin(), v2.end(), K().less_xyz_3_object());
        assert(v == v2);

        std::cout << "no points lost." << std::endl;
    }
    {
      int dim =5;
      std::cout << "Testing "<<dim<<"D: Generating "<<nb_points_d<<" random points... " << std::flush;

        std::vector<Point> v;
        v.reserve (nb_points_d);

        CGAL::Random_points_in_cube_d<Point> gen (dim, 1.0, random);

        for (int i = 0; i < nb_points_d; ++i)
            v.push_back (*gen++);

        std::cout << "done." << std::endl;

        std::vector<Point> v2 (v);

        std::cout << "            Sorting points...    " << std::flush;

	cost.reset();cost.start();
        CGAL::hilbert_sort (v.begin(), v.end(),CGAL::Hilbert_sort_median_policy());
	cost.stop();

        std::cout << "done in "<<cost.time()<<"seconds." << std::endl;

        std::cout << "            Checking...          " << std::flush;

        std::sort (v.begin(),  v.end(), Kd().less_lexicographically_d_object());
        std::sort (v2.begin(), v2.end(),Kd().less_lexicographically_d_object());
        assert(v == v2);

        std::cout << "no points lost." << std::endl;
    }
    {
      int dim = 1000;
      std::cout << "Testing "<<dim<<"D: Generating "<<nb_points_d<<" random points... " << std::flush;

        std::vector<Point> v;
        v.reserve (nb_points_d);

        CGAL::Random_points_in_cube_d<Point> gen (dim, 1.0, random);

        for (int i = 0; i < nb_points_d; ++i)
            v.push_back (*gen++);

        std::cout << "done." << std::endl;

        std::vector<Point> v2 (v);

        std::cout << "            Sorting points...    " << std::flush;

	cost.reset();cost.start();
        CGAL::hilbert_sort (v.begin(), v.end());
	cost.stop();

        std::cout << "done in "<<cost.time()<<"seconds." << std::endl;

        std::cout << "            Checking...          " << std::flush;

        std::sort (v.begin(),  v.end(), Kd().less_lexicographically_d_object());
        std::sort (v2.begin(), v2.end(),Kd().less_lexicographically_d_object());
        assert(v == v2);

        std::cout << "no points lost." << std::endl;
    }
    {
      int dim = 10;
      std::cout << "Testing "<<dim<<"D (middle policy): Generating "<<nb_points_d<<" random points... " << std::flush;

        std::vector<Point> v;
        v.reserve (nb_points_d);

        CGAL::Random_points_in_cube_d<Point> gen (dim, 1.0, random);

        for (int i = 0; i < nb_points_d; ++i)
            v.push_back (*gen++);

        std::cout << "done." << std::endl;

        std::vector<Point> v2 (v);

        std::cout << "            Sorting points ...    " << std::flush;

	cost.reset();cost.start();
        CGAL::hilbert_sort (v.begin(), v.end(),
			    CGAL::Hilbert_sort_middle_policy());
	cost.stop();

        std::cout << "done in "<<cost.time()<<"seconds." << std::endl;

        std::cout << "            Checking...          " << std::flush;

        std::sort (v.begin(),  v.end(), Kd().less_lexicographically_d_object());
        std::sort (v2.begin(), v2.end(),Kd().less_lexicographically_d_object());
        assert(v == v2);

        std::cout << "no points lost." << std::endl;
    }
    {
      int dim=5;
      std::cout << "Testing "<<dim<<"D: Generating "<<small_nb_points_d<<" random points... " << std::flush;

        std::vector<Point> v;
        v.reserve (nb_points_d);

        CGAL::Random_points_in_cube_d<Point> gen (dim, 1.0, random);

        for (int i = 0; i < nb_points_d; ++i)
            v.push_back (*gen++);

        std::cout << "done." << std::endl;

        std::vector<Point> v2 (v);

        std::cout << "            Sorting points...    " << std::flush;

	cost.reset();cost.start();
        CGAL::hilbert_sort (v.begin(), v.end());
	cost.stop();

        std::cout << "done in "<<cost.time()<<"seconds." << std::endl;

        std::cout << "            Checking...          " << std::flush;

        std::sort (v.begin(),  v.end(), Kd().less_lexicographically_d_object());
        std::sort (v2.begin(), v2.end(),Kd().less_lexicographically_d_object());
        assert(v == v2);

        std::cout << "no points lost." << std::endl;
    }
    {
	int dim=5;
	int size=32768;            // 2^(x.dim)   with x=3  
	double box_size = 7.0;     // 2^x -1

	std::cout << "Testing "<<dim<<"D: Generating "<<size<<" grid points... " << std::flush;

        std::vector<Point> v(size);

        CGAL::points_on_cube_grid_d (dim, box_size, (std::size_t)size, 
					  v.begin(), Creator_d(dim) );

        std::cout << "done." << std::endl;

        std::cout << "            Sorting points...    " << std::flush;

	cost.reset();cost.start();
        CGAL::hilbert_sort (v.begin(), v.begin()+size);
	cost.stop();

        std::cout << "done in "<<cost.time()<<"seconds." << std::endl;

        std::cout << "            Checking...          " << std::flush;

        for (int i = 0; i < size-1; ++i) 
	  assert(CGAL::squared_distance( v[i], v[i+1]) - 4.0 < 0.1 );

        std::cout << "OK." << std::endl;
    }
    {
	int dim=3;
	int size=32768;            // 2^(x.dim)   with x=5
	double box_size = 31.0;     // 2^x -1

	std::cout << "Testing "<<dim<<"D (middle policy): Generating "<<size<<" grid points... " << std::flush;

        std::vector<Point> v(size);

        CGAL::points_on_cube_grid_d (dim, box_size, (std::size_t)size, 
					  v.begin(), Creator_d(dim) );

        std::cout << "done." << std::endl;

        std::cout << "            Sorting points...    " << std::flush;

	cost.reset();cost.start();
        CGAL::hilbert_sort (v.begin(), v.begin()+size,
			    CGAL::Hilbert_sort_middle_policy());
	cost.stop();

        std::cout << "done in "<<cost.time()<<"seconds." << std::endl;

        std::cout << "            Checking...          " << std::flush;

        for (int i = 0; i < size-1; ++i) 
	  assert(CGAL::squared_distance( v[i], v[i+1]) - 4.0 < 0.1 );

        std::cout << "OK." << std::endl;
    }

    {
	int dim=5;
	int size=32768;            // 2^(x.dim)   with x=3  
	double box_size = 7.0;     // 2^x -1

	std::cout << "Testing "<<dim<<"D (middle policy): Generating "<<size<<" grid points... " << std::flush;

        std::vector<Point> v(size);

        CGAL::points_on_cube_grid_d (dim, box_size, (std::size_t)size, 
					  v.begin(), Creator_d(dim) );

        std::cout << "done." << std::endl;

        std::cout << "            Sorting points...    " << std::flush;

	cost.reset();cost.start();
        CGAL::hilbert_sort (v.begin(), v.begin()+size,
			    CGAL::Hilbert_sort_middle_policy());
	cost.stop();

        std::cout << "done in "<<cost.time()<<"seconds." << std::endl;

        std::cout << "            Checking...          " << std::flush;

        for (int i = 0; i < size-1; ++i) 
	  assert(CGAL::squared_distance( v[i], v[i+1]) - 4.0 < 0.1 );

        std::cout << "OK." << std::endl;
    }

    {
      int dim = 50;
      std::cout << "Testing "<<dim<<"D (median policy): Generating "<<nb_points_d<<" random points... " << std::flush;

        std::vector<Point> v;
        v.reserve (nb_points_d);

        CGAL::Random_points_in_cube_d<Point> gen (dim, 1.0, random);

        for (int i = 0; i < nb_points_d; ++i)
            v.push_back (*gen++);

        std::cout << "done." << std::endl;

        std::vector<Point> v2 (v);

        std::cout << "            Sorting points...    " << std::flush;

	cost.reset();cost.start();
        CGAL::hilbert_sort (v.begin(), v.end());
	cost.stop();

        std::cout << "done in "<<cost.time()<<"seconds." << std::endl;

        std::cout << "            Checking...          " << std::flush;

        std::sort (v.begin(),  v.end(), Kd().less_lexicographically_d_object());
        std::sort (v2.begin(), v2.end(),Kd().less_lexicographically_d_object());
        assert(v == v2);

        std::cout << "no points lost." << std::endl;
    }

    return 0;
}
int main()
{
	CGAL::Timer t;
	t.start();
	// Define functions
	Function f1(&torus_function);
	Function f2(&sphere_function<5>);
	Function f3(&tanglecube_function);
	Function f4(&heart_function);
	Function f5(&klein_function);
	Function f6(&false_knot_function);
	Function f7(&knot1_function);
	Function f8(&octic_function);

	Function_vector v;
	v.push_back(&f1);
	//v.push_back(&f2);
	//v.push_back(&f3);
	//v.push_back(&f4);
	//v.push_back(&f5);
	//v.push_back(&f6);
	//v.push_back(&f7);
	//v.push_back(&f8);

	// Domain (Warning: Sphere_3 constructor uses square radius !)
	Mesh_domain domain(v, K::Sphere_3(CGAL::ORIGIN, 5.*5.), 1e-6);

	// Set mesh criteria
	Facet_criteria facet_criteria(30, 0.2, 0.02); // angle, size, approximation
	Cell_criteria cell_criteria(2., 0.4); // radius-edge ratio, size
	Mesh_criteria criteria(facet_criteria, cell_criteria);

	// Mesh generation
	C3t3 c3t3 = CGAL::make_mesh_3<C3t3>(domain, criteria, no_exude(), no_perturb());

	// Perturbation (maximum cpu time: 10s, targeted dihedral angle: default)
	CGAL::perturb_mesh_3(c3t3, domain, time_limit = 10);
	
	// Exudation
	CGAL::exude_mesh_3(c3t3,12);

	CGAL::Random rand;

	t.stop();
	std::cout << "Time elapsed for building the mesh: " << t.time() << std::endl;
	t.reset();
	
	t.start();
	int nr = 1500;
	std::vector<Point> points;
	points.reserve(nr);
	CGAL::Random_points_in_mesh_3<Point, C3t3, FastPolicy> g(c3t3);
	t.stop();
	std::cout << "Time elapsed for init Random_points_in_mesh_3: " <<
		t.time() << std::endl;
	t.reset();

	t.start();
	CGAL::cpp11::copy_n( g, nr, std::back_inserter(points));
	t.stop();
	std::cout << "Time elapsed for generating the points: " << t.time() << std::endl;
	t.reset();

	Tr tr = c3t3.triangulation();
	Tetrahedron3 tet;
	Tr::Finite_cells_iterator it = tr.finite_cells_begin();
	for (; it != tr.finite_cells_end(); it++) {
		if (c3t3.is_in_complex(it)) {
			tet = tr.tetrahedron(it);
			break;
		}
	}

	t.start();
	std::vector<Point> points_tet;
	points_tet.reserve(nr);
	CGAL::Random_points_in_tetrahedron_3<Point> g1(tet);
	CGAL::cpp11::copy_n(g1, nr, std::back_inserter(points_tet));
	t.stop();
	std::cout << "Time elapsed for " << nr << " points in one tetrahedron: " <<
		t.time() << std::endl;
	t.reset();

	std::cout << "The generated points are: " << std::endl;
	for (int i = 0; i < nr; i++) {
		std::cout << points[i].x() << " " << points[i].y() << " " <<
			points[i].z() << std::endl;
	}

	points_tet.clear();
	points.clear();
	v.clear();
	return 0;
}