コード例 #1
0
ファイル: convex.cpp プロジェクト: ArcEarth/cgal
int main( int argc, char **argv) {
    if ( argc != 3) {
        cerr << "Usage: " << argv[0] << " <infile1> <infile2>" << endl;
        cerr << "       Minkowsky sum of two 3d polyhedra in OFF format." 
             << endl;
        cerr << "       Output in OFF to stdout." << endl;
        exit(1);
    }
    Polyhedron P1;
    Polyhedron P2;
    read( argv[1], P1);
    read( argv[2], P2);

    CGAL::Timer t;
    t.start();

    vector<Point> points;
    Add_points add;
    fold( P1.vertices_begin(), P1.vertices_end(),
          P2.vertices_begin(), P2.vertices_end(),
          back_inserter( points),
          add);
    Polyhedron P3;
    convex_hull_3( points.begin(), points.end(), P3);

    t.stop();
    std::cout << "Runtime Minkowski Sum: " << t.time() << std::endl;

    //    cout << P3;
    return 0;
}
コード例 #2
0
ファイル: benchmarks.cpp プロジェクト: FMX/CGAL
void Scene::bench_distance(Facet_tree& tree,
                           const int function,
                           const double duration)
{

    // generates 100K random point queries
    srand(0);
    unsigned int nb_queries = 100000;
    std::vector<Point> queries;
    for(unsigned int i=0;i<nb_queries;i++)
        queries.push_back(random_point(tree.bbox()));

    CGAL::Timer timer;
    timer.start();
    unsigned int nb = 0;
    while(timer.time() < duration)
    {
        const Point& query = queries[nb%nb_queries];
        switch(function)
        {
        case SQ_DISTANCE:
            tree.squared_distance(query);
            break;
        case CLOSEST_POINT:
            tree.closest_point(query);
            break;
        case CLOSEST_POINT_AND_PRIMITIVE_ID:
            tree.closest_point_and_primitive(query);
        }
        nb++;
    }

    double speed = (double)nb / (double)timer.time();
    std::cout << speed << " queries/s" << std::endl;
}
コード例 #3
0
ファイル: SgpProp.cpp プロジェクト: aldongqing/jjcao_code
//create a plane passing the center, with the average of some normals as normal
//the plane created is stored in m_basePlane
//用:CGAL::Plane_3<Kernel>我们这里默认了所得到的边界点是有顺序的!!!
void SgpProp::createPlane(Vertex_handle &center, Polyhedron* mesh)
{
	std::cout << "  SgpProp::createPlane() begin!" <<std::endl;
	CGAL::Timer timer;
	timer.start();	

	std::list<Vertex_handle>& main_border = mesh->main_border();
	if (main_border.empty())
	{
		main_border = mesh->extract_longest_border();
	}

	std::list<Vector_3 > spokes;//a circular linked list
	for (std::list<Vertex_handle>::iterator it=main_border.begin(); it!=main_border.end(); ++it)
	{
		Vertex_handle vh = *it;
		spokes.push_back(vh->point() - center->point());
	}
	spokes.push_back(*(spokes.begin()) );

	std::list<Vector_3 >::iterator bVector = spokes.begin();
	std::list<Vector_3 >::iterator nVector = bVector;
	Vector_3 sum_norm(0,0,0);
	for(++nVector; nVector != spokes.end(); ++nVector,++bVector)
	{
		sum_norm = sum_norm + CGAL::cross_product(*bVector,*nVector);
	} 

	m_basePlaneNormal = sum_norm/(spokes.size()+1);
	
	std::cout << "....Time: " << timer.time() << " seconds." << std::endl<<std::endl;
}
コード例 #4
0
ファイル: timings.cpp プロジェクト: Fox-Heracles/cgal
template < class Traits > double test_sort(unsigned int degree, unsigned int n)
{
    typedef CGAL::Kinetic::Sort < Traits > Sort;
    Traits tr(0, 10000);
    Sort sort(tr);
    CGAL::Random r;
    for (unsigned int i = 0; i < n; ++i) {
        std::vector < double >cf;
        for (unsigned int j = 0; j < degree + 1; ++j) {
            cf.push_back(r.get_double());
        }
        typename Traits::Kinetic_kernel::Motion_function fn(cf.begin(),
            cf.end());
        typename Traits::Kinetic_kernel::Point_1 pt(fn);
        tr.active_points_1_table_handle()->insert(pt);
    }
    CGAL::Timer timer;
    timer.start();
    int ne = 0;
    while (tr.simulator_handle()->next_event_time() !=
    tr.simulator_handle()->end_time()) {
        tr.simulator_handle()->set_current_event_number(tr.
            simulator_handle()->
            current_event_number()
            + 1);
        ++ne;
        if (ne == 1000)
            break;
    }
    timer.stop();
    return timer.time() / static_cast < double >(ne);
}
コード例 #5
0
// just reusing the tests from the T3 package to check whether the
// periodic vertices and cells fulfill the requirements.
int main(int, char**)
{
  CGAL::Timer timer;
  timer.start();
  _test_cls_periodic_3_tds_3(Tds());
  std::cerr << timer.time() << " sec." << std::endl;
  return 0;
}
コード例 #6
0
ファイル: lloyd_algorithm.cpp プロジェクト: freehawkzk/cgal
int main (int argc, char *argv[]) {
    // Cube
    std::list<Plane> planes;
    planes.push_back(Plane(1, 0, 0, -1));
    planes.push_back(Plane(-1, 0, 0, -1));
    planes.push_back(Plane(0, 1, 0, -1));
    planes.push_back(Plane(0, -1, 0, -1));
    planes.push_back(Plane(0, 0, 1, -1));
    planes.push_back(Plane(0, 0, -1, -1));

    std::vector<Point> points;
    int N, steps;
    // Number of points
    if (argc > 1) {
        N = atoi(argv[1]);
    } else {
        N = 50;
    }

    // Number of steps
    if (argc > 2) {
        steps = atoi(argv[2]);
    } else {
        steps = 10;
    }

    CGAL::Random_points_in_sphere_3<Point> g;
    for (int i = 0; i < N; i++) {
        Point p = *g++;
        points.push_back(p);
    }

    std::ofstream bos("before_lloyd.xyz");
    std::copy(points.begin(), points.end(),
              std::ostream_iterator<Point>(bos, "\n"));

    // Apply Lloyd algorithm: will generate points
    // uniformly sampled inside a cube.
    for (int i = 0; i < steps; i++) {
        std::cout << "iteration " << i + 1 << std::endl;

        CGAL::Timer timer;
        timer.start();
        lloyd_algorithm(planes.begin(),
                        planes.end(),
                        points);
        timer.stop();

        std::cout << "Execution time : " << timer.time() << "s\n";
    }

    std::ofstream aos("after_lloyd.xyz");
    std::copy(points.begin(), points.end(),
              std::ostream_iterator<Point>(aos, "\n"));

    return 0;
}
コード例 #7
0
ファイル: predefined_kernel.cpp プロジェクト: 2php/cgal
int main (int argc, char *argv[])
{
  // Get the name of the input file from the command line, or use the default
  // fan_grids.dat file if no command-line parameters are given.
  const char * filename = (argc > 1) ? argv[1] : "fan_grids.dat";

  // Open the input file.
  std::ifstream     in_file (filename);

  if (! in_file.is_open()) {
    std::cerr << "Failed to open " << filename << " ..." << std::endl;
    return (1);
  }

  // Read the segments from the file.
  // The input file format should be (all coordinate values are integers):
  // <n>                                 // number of segments.
  // <sx_1> <sy_1>  <tx_1> <ty_1>        // source and target of segment #1.
  // <sx_2> <sy_2>  <tx_2> <ty_2>        // source and target of segment #2.
  //   :      :       :      :
  // <sx_n> <sy_n>  <tx_n> <ty_n>        // source and target of segment #n.
  
  std::list<Segment_2>  segments;

  unsigned int n;
  in_file >> n;
  unsigned int i;
  for (i = 0; i < n; ++i) {
    int sx, sy, tx, ty;
    in_file >> sx >> sy >> tx >> ty;
    segments.push_back (Segment_2 (Point_2 (Number_type(sx), Number_type(sy)),
                                   Point_2 (Number_type(tx), Number_type(ty))));
  }
  in_file.close();

  // Construct the arrangement by aggregately inserting all segments.
  Arrangement_2                  arr;
  CGAL::Timer                    timer;

  std::cout << "Performing aggregated insertion of " 
            << n << " segments." << std::endl;

  timer.start();
  insert (arr, segments.begin(), segments.end());
  timer.stop();

  // Print the arrangement dimensions.
  std::cout << "V = " << arr.number_of_vertices()
	    << ",  E = " << arr.number_of_edges() 
	    << ",  F = " << arr.number_of_faces() << std::endl;

  std::cout << "Construction took " << timer.time() 
	    << " seconds." << std::endl;
  
  return 0;
}
コード例 #8
0
int main()
{
  CGAL::Timer timer;
  timer.start();
  _test_cls_alpha_shape_3<Alpha_shape_3>();
  _test_cls_alpha_shape_3_exact<EAlpha_shape_3>();

  std::cerr << timer.time() << " sec." << std::endl;
  return 0;
}
コード例 #9
0
ファイル: Scene.cpp プロジェクト: weaselp/cgal
void Scene::generate_points_in(const unsigned int nb_points,
                               const double min,
                               const double max)
{
    if(m_pPolyhedron == NULL)
    {
        std::cout << "Load polyhedron first." << std::endl;
        return;
    }

    typedef CGAL::AABB_face_graph_triangle_primitive<Polyhedron> Primitive;
    typedef CGAL::AABB_traits<Kernel, Primitive> Traits;
    typedef CGAL::AABB_tree<Traits> Tree;

    std::cout << "Construct AABB tree...";
    Tree tree(faces(*m_pPolyhedron).first, faces(*m_pPolyhedron).second, *m_pPolyhedron);
    std::cout << "done." << std::endl;

    CGAL::Timer timer;
    timer.start();
    std::cout << "Generate " << nb_points << " points in interval ["
              << min << ";" << max << "]";

    unsigned int nb_trials = 0;
    Vector vec = random_vector();
    while(m_points.size() < nb_points)
    {
        Point p = random_point(tree.bbox());

        // measure distance
        FT signed_distance = std::sqrt(tree.squared_distance(p));

        // measure sign
        Ray ray(p,vec);
        int nb_intersections = (int)tree.number_of_intersected_primitives(ray);
        if(nb_intersections % 2 != 0)
            signed_distance *= -1.0;

        if(signed_distance >= min &&
                signed_distance <= max)
        {
            m_points.push_back(p);
            if(m_points.size()%(nb_points/10) == 0)
                std::cout << "."; // ASCII progress bar
        }
        nb_trials++;
    }
    double speed = (double)nb_trials / timer.time();
    std::cout << "done (" << nb_trials << " trials, "
              << timer.time() << " s, "
              << speed << " queries/s)" << std::endl;
    changed();
}
コード例 #10
0
ファイル: Scene.cpp プロジェクト: weaselp/cgal
void Scene::generate_edge_points(const unsigned int nb_points)
{
    if(m_pPolyhedron == NULL)
    {
        std::cout << "Load polyhedron first." << std::endl;
        return;
    }

    typedef CGAL::AABB_halfedge_graph_segment_primitive<Polyhedron> Primitive;
    typedef CGAL::AABB_traits<Kernel, Primitive> Traits;
    typedef CGAL::AABB_tree<Traits> Tree;
    typedef Tree::Object_and_primitive_id Object_and_primitive_id;

    std::cout << "Construct AABB tree...";
    Tree tree( CGAL::edges(*m_pPolyhedron).first,
               CGAL::edges(*m_pPolyhedron).second,
               *m_pPolyhedron);
    std::cout << "done." << std::endl;

    CGAL::Timer timer;
    timer.start();
    std::cout << "Generate edge points: ";

    unsigned int nb = 0;
    unsigned int nb_planes = 0;
    while(nb < nb_points)
    {
        Plane plane = random_plane(tree.bbox());

        std::list<Object_and_primitive_id> intersections;
        tree.all_intersections(plane,std::back_inserter(intersections));
        nb_planes++;

        std::list<Object_and_primitive_id>::iterator it;
        for(it = intersections.begin();
            it != intersections.end();
            it++)
        {
            Object_and_primitive_id op = *it;
            CGAL::Object object = op.first;
            Point point;
            if(CGAL::assign(point,object))
            {
                m_points.push_back(point);
                nb++;
            }
        }
    }
    std::cout << nb_planes << " plane queries, " << timer.time() << " s." << std::endl;
    changed();
}
コード例 #11
0
void test_speed_for_query(const Tree& tree,
                          const Query_type query_type,
                          const char *query_name,
                          const double duration)
{
    typedef typename K::Ray_3 Ray;
    typedef typename K::Line_3 Line;
    typedef typename K::Point_3 Point;
    typedef typename K::Vector_3 Vector;
    typedef typename K::Segment_3 Segment;

    CGAL::Timer timer;
    unsigned int nb = 0;
    timer.start();
    while(timer.time() < duration)
    {
        switch(query_type)
        {
            case RAY_QUERY:
                {
                    Point source = random_point_in<K>(tree.bbox());
                    Vector vec = random_vector<K>();
                    Ray ray(source, vec);
                    tree.do_intersect(ray);
                    break;
                }
            case SEGMENT_QUERY:
                {
                    Point a = random_point_in<K>(tree.bbox());
                    Point b = random_point_in<K>(tree.bbox());
                    tree.do_intersect(Segment(a,b));
                    break;
                }
                break;
            case LINE_QUERY:
                {
                    Point a = random_point_in<K>(tree.bbox());
                    Point b = random_point_in<K>(tree.bbox());
                    tree.do_intersect(Line(a,b));
                    break;
                }
        }
        nb++;
    }
    unsigned int speed = (unsigned int)(nb / timer.time());
    std::cout.precision(10);
    std::cout.width(15);
    std::cout << speed << " intersections/s with " << query_name << std::endl;
    timer.stop();
}
コード例 #12
0
void build_skeleton(const char* fname)
{
  typedef typename Kernel::Point_2                                         Point_2;
  typedef CGAL::Polygon_2<Kernel>                                 Polygon_2;
  typedef CGAL::Straight_skeleton_builder_traits_2<Kernel>        SsBuilderTraits;
  typedef CGAL::Straight_skeleton_2<Kernel>                       Ss;
  typedef CGAL::Straight_skeleton_builder_2<SsBuilderTraits,Ss>   SsBuilder;
  
  Polygon_2 pgn;
  
  std::ifstream input(fname);
  
  FT x,y;
  while(input)
  {
    input >> x;
    if (!input) break;
    input >> y;
    if (!input) break;
    pgn.push_back( Point_2( typename Kernel::FT(x), typename Kernel::FT(y) ) );
  }
  input.close();
  
  std::cout << "Polygon has " << pgn.size() <<  " points\n";
  
  if(!pgn.is_counterclockwise_oriented()) {
      std::cerr << "Polygon is not CCW Oriented" << std::endl;
  }
  if(!pgn.is_simple()) {
      std::cerr << "Polygon is not simple" << std::endl;
  }  

  CGAL::Timer time;
  time.start();
  SsBuilder ssb;
  ssb.enter_contour(pgn.vertices_begin(), pgn.vertices_end());
  boost::shared_ptr<Ss> straight_ske = ssb.construct_skeleton();
  time.stop();
  
  std::cout << "Time spent to build skeleton " << time.time() << "\n";
  
  if(!straight_ske->is_valid()) {
      std::cerr << "Straight skeleton is not valid" << std::endl;
  }

  std::cerr.precision(60);
  print_straight_skeleton(*straight_ske);
  
}
コード例 #13
0
ファイル: Scene.cpp プロジェクト: weaselp/cgal
void Scene::generate_boundary_segments(const unsigned int nb_slices)
{
    if(m_pPolyhedron == NULL)
    {
        std::cout << "Load polyhedron first." << std::endl;
        return;
    }

    typedef CGAL::AABB_face_graph_triangle_primitive<Polyhedron> Primitive;
    typedef CGAL::AABB_traits<Kernel, Primitive> Traits;
    typedef CGAL::AABB_tree<Traits> Tree;
    typedef Tree::Object_and_primitive_id Object_and_primitive_id;

    std::cout << "Construct AABB tree...";
    Tree tree(faces(*m_pPolyhedron).first,faces(*m_pPolyhedron).second,*m_pPolyhedron);
    std::cout << "done." << std::endl;

    CGAL::Timer timer;
    timer.start();
    std::cout << "Generate boundary segments from " << nb_slices << " slices: ";

    Vector normal((FT)0.0,(FT)0.0,(FT)1.0);
    unsigned int i;

    const double dz = m_bbox.zmax() - m_bbox.zmin();
    for(i=0;i<nb_slices;i++)
    {
        FT z = m_bbox.zmin() + (FT)i / (FT)nb_slices * dz;
        Point p((FT)0.0, (FT)0.0, z);
        Plane plane(p,normal);

        std::list<Object_and_primitive_id> intersections;
        tree.all_intersections(plane,std::back_inserter(intersections));

        std::list<Object_and_primitive_id>::iterator it;
        for(it = intersections.begin();
            it != intersections.end();
            it++)
        {
            Object_and_primitive_id op = *it;
            CGAL::Object object = op.first;
            Segment segment;
            if(CGAL::assign(segment,object))
                m_segments.push_back(segment);
        }
    }
    std::cout << m_segments.size() << " segments, " << timer.time() << " s." << std::endl;
    changed();
}
コード例 #14
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;
}
コード例 #15
0
ファイル: benchmark-gen.cpp プロジェクト: Asuzer/cgal
bool
load_cin_file(std::istream& ifs, SDG& sdg) {
  std::cerr << "Loading file... ";
  CGAL::Timer timer;
  timer.start();
  bool not_first = false;
  if(!ifs.good())
    return false;
  Point_2 p, q, qold;
  int point_counter = 0;
  SDGLinf::Site_2 site;
  while (ifs >> site) {
    //std::cout << site << std::endl;
    if (site.is_point()) {
      //std::cout << "site is point" << std::endl;
      q = site.point();
      points.push_back(q);
      ++point_counter;
    } else if (site.is_segment()) {
      //std::cout << "site is seg" << std::endl;
      p = site.source();
      q = site.target();
      if(not_first and (p == qold)) {
        points.push_back(q);
        //std::cout << "push pq old" << std::endl;
        constraints.push_back(std::make_pair(point_counter-1, point_counter));
        ++point_counter;
      }
      else {
        points.push_back(p);
        points.push_back(q);
        //std::cout << "push pq new" << std::endl;
        constraints.push_back(std::make_pair(point_counter, point_counter+1));
        point_counter += 2;
      }
    } else {
      if (not_first) {
        return false;
      } else {
        continue;
      }
    }
    qold = q;
    not_first = true;
  }
  std::cerr << "done (" << timer.time() << "s)" << std::endl;
  insert_constraints_using_spatial_sort(sdg);
  return true;
}
コード例 #16
0
Meshing_thread* cgal_code_mesh_3(const Polyhedron* pMesh,
                                 const Polylines_container& polylines,
                                 QString filename,
                                 const double facet_angle,
                                 const double facet_sizing,
                                 const double facet_approx,
                                 const double tet_sizing,
                                 const double tet_shape,
                                 bool protect_features,
                                 CGAL::Three::Scene_interface* scene)
{
  if(!pMesh) return 0;

  std::cerr << "Meshing file \"" << qPrintable(filename) << "\"\n";
  std::cerr << "  angle: " << facet_angle << std::endl
            << "  facets size bound: " << facet_sizing << std::endl
            << "  approximation bound: " << facet_approx << std::endl
            << "  tetrahedra size bound: " << tet_sizing << std::endl;
  std::cerr << "Build AABB tree...";
  CGAL::Timer timer;
  timer.start();
  // Create domain
  Polyhedral_mesh_domain* p_domain = new Polyhedral_mesh_domain(*pMesh);
  if(polylines.empty() && protect_features) {
      p_domain->detect_features();
  }
  if(! polylines.empty()){
    p_domain->add_features(polylines.begin(), polylines.end());
    protect_features = true; // so that it will be passed in make_mesh_3
  }

  std::cerr << "done (" << timer.time() << " ms)" << std::endl;

  Scene_c3t3_item* p_new_item = new Scene_c3t3_item;
  p_new_item->set_scene(scene);

  Mesh_parameters param;
  param.facet_angle = facet_angle;
  param.facet_sizing = facet_sizing;
  param.facet_approx = facet_approx;
  param.tet_sizing = tet_sizing;
  param.tet_shape = tet_shape;
  param.protect_features = protect_features;

  typedef ::Mesh_function<Polyhedral_mesh_domain> Mesh_function;
  Mesh_function* p_mesh_function = new Mesh_function(p_new_item->c3t3(),
                                                     p_domain, param);
  return new Meshing_thread(p_mesh_function, p_new_item);
}
コード例 #17
0
ファイル: benchmark-gen.cpp プロジェクト: Asuzer/cgal
void
run_benchmark(SDG& sdg)
{  
  load_cin_file(std::cin, sdg);

  CGAL::Timer timer;
  timer.start();
  if(! sdg.is_valid(true, 1) ){
    std::cerr << "invalid data structure" << std::endl;
  } else {
    std::cerr << "valid data structure" << std::endl;
  }
  timer.stop();
  std::cerr << "Data structure checking time = " << timer.time() << "s\n";
}
コード例 #18
0
ファイル: MeshCheck.cpp プロジェクト: Sunwinds/larmor-physx
TrianglesList meshRemoveIntersectedTriangles(TrianglesList &triangles)
{
	CGAL::Timer timer;
	timer.start();

	TrianglesList result;

	//Collision boxes
	std::vector<BoxInt> boxes;

	std::list<Triangle>::iterator triangleIter;
	for(triangleIter = triangles.begin(); triangleIter != triangles.end(); ++triangleIter)
	{
		//Triangle t = *triangleIter;

		TriangleVisitedInfoMC *tvi = new TriangleVisitedInfoMC;
		tvi->triangle = &(*triangleIter); //Use the pointer, it should not change into the container, since there aren't new added elements
		tvi->intersected = false;

		boxes.push_back( BoxInt( (*triangleIter).bbox(), tvi ));
	}


	//Do intersection
	CGAL::box_self_intersection_d( boxes.begin(), boxes.end(), reportSelfIntersectionCallback);


	//cycle on boxes and build result and delete tvi
	std::vector<BoxInt>::iterator vectorBoxesIter;
	for(vectorBoxesIter = boxes.begin(); vectorBoxesIter != boxes.end(); ++vectorBoxesIter)
	{
		BoxInt boxInt = *vectorBoxesIter;
		TriangleVisitedInfoMC *tviHandled = boxInt.handle();
		if ((!(tviHandled->intersected)) && (!(tviHandled->triangle->is_degenerate())))
		{
			Triangle t = *(tviHandled->triangle);
			result.push_back(t);
		}

		delete tviHandled;
	}


	timer.stop();
	std::cout << "Total meshRemoveIntersectedTriangles time: " << timer.time() << std::endl;

	return result;
}
コード例 #19
0
int main(int argc, const char *argv[])
{
    CavConfig cfg;
    const char *run_control_file = "cavity_volumes_fin.inp";

    if (argc > 1)
        run_control_file = argv[1];

    if (!cfg.init(run_control_file)) {
        std::cerr << "Error while initializing from run control file : " << run_control_file << std::endl;
        return 2;
    }

    cfg.out_inf << "Run control file : " << run_control_file << std::endl;

    CGAL::Timer t;
    int processed_cnt = 0;

    cfg.out_inf << std::endl;
    t.start();
    while (cfg.next_timestep()) {
        const Array_double_3 &a = cfg.atoms.back();
        cfg.out_inf << "Number of input atoms : " << cfg.atoms.size() << std::endl;
        cfg.out_inf << "MD info : " << cfg.ts_info << std::endl;
        cfg.out_inf << "Box : [ " << cfg.box[0] << ", " << cfg.box[1] << ", " << cfg.box[2] << " ]" << std::endl;
        cfg.out_inf << "Last atom : " << a[0] << " " << a[1] << " " << a[2] << std::endl;
        if (!process_conf(cfg)) {
            cfg.out_inf << "process_conf() error. Exiting..." << std::endl;
            return 1;
        }
        processed_cnt++;
    }
    t.stop();

    // save accumulated per-atom surfaces
    if (cfg.out_asf.is_open()) {
        long double total_surf = std::accumulate(cfg.atom_confs_surf.begin(), cfg.atom_confs_surf.end(), 0.0L);
        cfg.out_asf << total_surf << std::endl;  // first line is total exposed surface of all atoms in all confs
        cfg.out_asf << cfg.atom_confs_surf.size() << std::endl;  // second line is the number of atoms
        for (size_t i = 0; i < cfg.atom_confs_surf.size(); i++)
            cfg.out_asf << cfg.atom_confs_surf[i] << std::endl;
    }

    cfg.out_inf << "Processed " << processed_cnt << " (of " << cfg.traj_ts_cnt() << ") configurations." << std::endl;
    cfg.out_inf << "Time: " << t.time() << " sec." << std::endl;

    return 0;
}
コード例 #20
0
int main()
{
  CGAL::Timer timer;
  timer.start();
  typedef CGAL::Periodic_3_Delaunay_triangulation_3< PTT1 > P3T3_1;
  _test_cls_periodic_3_delaunay_3( P3T3_1() );

  typedef CGAL::Periodic_3_Delaunay_triangulation_3< PTT2 > P3T3_2;
  _test_cls_periodic_3_delaunay_3( P3T3_2() );

  // typedef CGAL::Periodic_3_Delaunay_triangulation_3< PTT3 > P3T3_3;
  // this takes too much time for the test suite.
  //_test_cls_periodic_3_delaunay_3( P3T3_3(), true );

  std::cerr << timer.time() << " sec." << std::endl;
  return 0;
}
コード例 #21
0
//TODO: still sometimes is crashing: test on linux and using a different compiler or TBB libs
std::list<MeshData> voronoiShatter(MeshData &meshData, std::list<KDPoint> points, bool useDelaunay, double bCriteria, double sCriteria)
{
	CGAL::Timer timer;
	timer.start();

	std::list<MeshData> resultMeshdata;
	//tbb::concurrent_vector<MeshData> concurrentResultMeshdata;
	Delaunay T(points.begin(), points.end());
	std::cout << "T.number_of_vertices:" <<  T.number_of_vertices() << std::endl;
	std::cout << "T.number_of_edges:" <<  T.number_of_finite_edges() << std::endl;
	std::cout << "T.is_valid:" <<  T.is_valid() << std::endl;
	std::vector<DVertex_handle> vertexHandleVector;
	Delaunay::Finite_vertices_iterator vit;
	for (vit = T.finite_vertices_begin(); vit != T.finite_vertices_end(); ++vit)
	{
		DVertex_handle vh = vit;
		vertexHandleVector.push_back(vh);
	}

	//Run multiple Thread using TBB
	//TBBVoronoiCell tbbVC(meshData, T, concurrentResultMeshdata);
	TBBVoronoiCell tbbVC(meshData, T, resultMeshdata, useDelaunay, bCriteria, sCriteria);
	int numberThreads = tbb::task_scheduler_init::default_num_threads();
	std::cout << "numberThreads: " << numberThreads << std::endl;
	tbb::task_scheduler_init init(numberThreads);
	//tbb::parallel_do(T.finite_vertices_begin(), T.finite_vertices_end(), tbbVC);
	tbb::parallel_do(vertexHandleVector.begin(), vertexHandleVector.end(), tbbVC);

	/*
	//Build result
	std::cout << "Building result..." << std::endl;
	tbb::concurrent_vector<MeshData>::iterator crmi;
	for (crmi = concurrentResultMeshdata.begin(); crmi != concurrentResultMeshdata.end(); ++crmi)
	{
		//MeshData md = *crmi;
		resultMeshdata.push_back(*crmi);
	}
	*/

	timer.stop();
	std::cout << "Total tbb voronoiShatter construction took " << timer.time() << " seconds, total cells:" << resultMeshdata.size() << std::endl;

	return resultMeshdata;
}
コード例 #22
0
void read_handle_difs_and_deform(DeformMesh& deform_mesh, InputIterator begin, InputIterator end)
{
  typedef CGAL::Simple_cartesian<double>::Vector_3 Vector;

  if(!deform_mesh.preprocess()) {
    std::cerr << "Error: preprocess() failed!" << std::endl;
    assert(false);
  }

  std::ifstream dif_stream("data/cactus_handle_differences.txt");
  std::vector<Vector> dif_vector;
  double x, y, z;
  while(dif_stream >> x >> y >> z)
  { dif_vector.push_back(Vector(x, y, z)); }

  CGAL::Timer timer;

  //the original behavior of translate was to overwrite the previous
  //translation. Now that it is cumulative, we need to substract the
  //previous translation vector to mimic the overwrite
  Vector previous(0,0,0);
  for(std::size_t i = 0; i < dif_vector.size(); ++i)
  {
    timer.start();
    deform_mesh.translate(begin, end, dif_vector[i]-previous);
    deform_mesh.deform();
    timer.stop();
    previous=dif_vector[i];

    // read pre-deformed cactus
    std::stringstream predeformed_cactus_file;
    predeformed_cactus_file << "data/cactus_deformed/cactus_deformed_" << i << ".off";
    Mesh predeformed_cactus;

    OpenMesh::IO::read_mesh(predeformed_cactus, predeformed_cactus_file.str().c_str());
    compare_mesh(predeformed_cactus, deform_mesh.halfedge_graph());

    // for saving deformation
    //std::ofstream(predeformed_cactus_file) << deform_mesh.halfedge_graph();
    //std::cerr << predeformed_cactus_file << std::endl;
  }
  std::cerr << "Deformation performance (with default number_of_iteration and tolerance) " << std::endl
    << dif_vector.size() << " translation: " << timer.time() << std::endl;
}
コード例 #23
0
ファイル: benchmarks.cpp プロジェクト: FMX/CGAL
void Scene::bench_distances_vs_nbt()
{
    if(m_pPolyhedron == NULL)
    {
        std::cout << "Load polyhedron first." << std::endl;
        return;
    }

    std::cout << std::endl << "Benchmark distances against #triangles" << std::endl;
    std::cout << std::endl << "for random point queries and closest_point()" << std::endl;
    std::cout << "#Facets, #queries/s" << std::endl;

    // generates 10K random point queries
    const int nb_queries = 10000;
    std::vector<Point> queries;
    srand(0);
    for(int i=0;i<nb_queries;i++)
        queries.push_back(random_point(m_bbox));

    while(m_pPolyhedron->size_of_facets() < 1000000)
    {
        // refines mesh at increasing speed
        Refiner<Kernel,Polyhedron> refiner(m_pPolyhedron);
        std::size_t digits = nb_digits(m_pPolyhedron->size_of_facets());
        unsigned int nb_splits =
          static_cast<unsigned int>(0.2 * std::pow(10.0,(double)digits - 1.0));
        refiner.run_nb_splits(nb_splits);

        // constructs tree (out of timing)
        Facet_tree tree(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end());
        tree.accelerate_distance_queries();

        // calls queries
        CGAL::Timer timer;
        timer.start();
        for(int i=0;i<nb_queries;i++)
            tree.closest_point(queries[i]);
        double duration = timer.time();
        int speed = (int)((double)nb_queries / (double)duration);

        std::cout << m_pPolyhedron->size_of_facets() << ", " << speed << std::endl;
    }
}
コード例 #24
0
Meshing_thread* cgal_code_mesh_3(const Image* pImage,
                                 const Polylines_container& polylines,
                                 const double facet_angle,
                                 const double facet_sizing,
                                 const double facet_approx,
                                 const double tet_sizing,
                                 const double tet_shape,
                                 bool protect_features,
                                 CGAL::Three::Scene_interface* scene)
{
  if (NULL == pImage) { return NULL; }

  Image_mesh_domain* p_domain = new Image_mesh_domain(*pImage, 1e-6);


  if(protect_features && polylines.empty()){
    std::vector<std::vector<Point_3> > polylines_on_bbox;
    CGAL::polylines_to_protect<Point_3>(*pImage, polylines_on_bbox);
    p_domain->add_features(polylines_on_bbox.begin(), polylines_on_bbox.end());
  }
  if(! polylines.empty()){
    // Insert edge in domain
    p_domain->add_features(polylines.begin(), polylines.end());
    protect_features = true; // so that it will be passed in make_mesh_3
  }
  CGAL::Timer timer;
  timer.start();
  Scene_c3t3_item* p_new_item = new Scene_c3t3_item;
  p_new_item->set_scene(scene);

  Mesh_parameters param;
  param.protect_features = false;
  param.facet_angle = facet_angle;
  param.facet_sizing = facet_sizing;
  param.facet_approx = facet_approx;
  param.tet_sizing = tet_sizing;
  param.tet_shape = tet_shape;
  
  typedef ::Mesh_function<Image_mesh_domain> Mesh_function;
  Mesh_function* p_mesh_function = new Mesh_function(p_new_item->c3t3(),
                                                     p_domain, param);
  return new Meshing_thread(p_mesh_function, p_new_item);
}
コード例 #25
0
ファイル: Scene.cpp プロジェクト: weaselp/cgal
void Scene::build_edge_tree()
{
    if ( NULL == m_pPolyhedron )
    {
        std::cerr << "Build edge tree failed: load polyhedron first." << std::endl;
        return;
    }

    // Don't rebuild tree if it is already built
    if ( !m_edge_tree.empty() ) { return; }

    // build tree
    CGAL::Timer timer;
    timer.start();
    std::cout << "Construct Edge AABB tree...";
    m_edge_tree.rebuild(edges(*m_pPolyhedron).first,edges(*m_pPolyhedron).second,*m_pPolyhedron);
    m_edge_tree.accelerate_distance_queries();
    std::cout << "done (" << timer.time() << " s)" << std::endl;
}
コード例 #26
0
ファイル: approx_inset.cpp プロジェクト: BijanZarif/mshr
int main ()
{
  // Open the input file.
  std::ifstream    in_file ("tight.dat");

  if (! in_file.is_open())
  {
    std::cerr << "Failed to open the input file." << std::endl;
    return (1);
  }

  // Read the input polygon.
  Polygon_2        P;

  in_file >> P;
  in_file.close();

  std::cout << "Read an input polygon with "
            << P.size() << " vertices." << std::endl;

  // Approximate the offset polygon.
  const Number_type                      radius = 1;
  const double                           err_bound = 0.00001;
  std::list<Offset_polygon_2>            inset_polygons;
  std::list<Offset_polygon_2>::iterator  iit;
  CGAL::Timer                            timer;

  timer.start();
  approximated_inset_2 (P, radius, err_bound,
                        std::back_inserter (inset_polygons));
  timer.stop();

  std::cout << "The inset comprises " 
            << inset_polygons.size() << " polygon(s)." << std::endl;
  for (iit = inset_polygons.begin(); iit != inset_polygons.end(); ++iit)
  {
      std::cout << "    Polygon with "
                << iit->size() << " vertices." << std::endl;
  }
  std::cout << "Inset computation took "
            << timer.time() << " seconds." << std::endl;
  return (0);
}
コード例 #27
0
ファイル: benchmarks.cpp プロジェクト: FMX/CGAL
void Scene::benchmark_intersections(const double duration)
{
    if(m_pPolyhedron == NULL)
    {
        std::cout << "Load polyhedron first." << std::endl;
        return;
    }

    // constructs tree
    std::cout << "Construct AABB tree...";
    CGAL::Timer timer;
    timer.start();
    Facet_tree tree(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end());
    std::cout << "done (" << timer.time() << " s)" << std::endl;

    // generates random queries
    const int nb_queries = 1000000;
    std::cout << "Generates random queries...";
    std::vector<Ray> rays;
    std::vector<Line> lines;
    std::vector<Plane> planes;
    std::vector<Segment> segments;
    timer.start();
    srand(0);
    int i = 0;
    for(i=0; i<nb_queries; i++)
    {
        rays.push_back(random_ray(tree.bbox()));
        lines.push_back(random_line(tree.bbox()));
        planes.push_back(random_plane(tree.bbox()));
        segments.push_back(random_segment(tree.bbox()));
    }
    std::cout << "done (" << timer.time() << " s)" << std::endl;

    // bench for all functions and query types
    bench_intersections(tree,duration,DO_INTERSECT,"do_intersect()",rays,lines,planes,segments,nb_queries);
    bench_intersections(tree,duration,ANY_INTERSECTED_PRIMITIVE,"any_intersected_primitive()",rays,lines,planes,segments,nb_queries);
    bench_intersections(tree,duration,ANY_INTERSECTION,"any_intersection()",rays,lines,planes,segments,nb_queries);
    bench_intersections(tree,duration,NB_INTERSECTIONS,"number_of_intersected_primitives()",rays,lines,planes,segments,nb_queries);
    bench_intersections(tree,duration,ALL_INTERSECTED_PRIMITIVES,"all_intersected_primitives()",rays,lines,planes,segments,nb_queries);
    bench_intersections(tree,duration,ALL_INTERSECTIONS,"all_intersections()",rays,lines,planes,segments,nb_queries);
}
コード例 #28
0
ファイル: benchmarks.cpp プロジェクト: FMX/CGAL
void Scene::benchmark_distances(const double duration)
{
    if(m_pPolyhedron == NULL)
    {
        std::cout << "Load polyhedron first." << std::endl;
        return;
    }

    CGAL::Timer timer;
    timer.start();
    std::cout << "Construct AABB tree and internal KD tree...";
    Facet_tree tree(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end());
    tree.accelerate_distance_queries();
    std::cout << "done (" << timer.time() << " s)" << std::endl;

    // benchmark
    bench_closest_point(tree,duration);
    bench_squared_distance(tree,duration);
    bench_closest_point_and_primitive(tree,duration);
}
コード例 #29
0
ファイル: benchmarks.cpp プロジェクト: FMX/CGAL
void Scene::bench_intersection(Facet_tree& tree,
                               const int function,
                               const double duration,
                               const char *query_name,
                               const std::vector<Query>& queries,
                               const int nb_queries)
{
    CGAL::Timer timer;
    timer.start();
    unsigned int nb = 0;
    std::list<Facet_tree::Primitive_id> primitive_ids;
    std::list<Facet_tree::Object_and_primitive_id> intersections;
    while(timer.time() < duration)
    {
        const Query& query = queries[nb % nb_queries]; // loop over vector
        switch(function)
        {
        case DO_INTERSECT:
            tree.do_intersect(query);
            break;
        case ANY_INTERSECTION:
            tree.any_intersection(query);
            break;
        case NB_INTERSECTIONS:
            tree.number_of_intersected_primitives(query);
            break;
        case ALL_INTERSECTIONS:
            tree.all_intersections(query,std::back_inserter(intersections));
            break;
        case ANY_INTERSECTED_PRIMITIVE:
            tree.any_intersected_primitive(query);
            break;
        case ALL_INTERSECTED_PRIMITIVES:
            tree.all_intersected_primitives(query,std::back_inserter(primitive_ids));
        }
        nb++;
    }

    double speed = (double)nb / (double)timer.time();
    std::cout << speed << " queries/s with " << query_name << std::endl;
}
コード例 #30
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;
}