本文整理汇总了C++中cgal::Timer类的典型用法代码示例。如果您正苦于以下问题:C++ Timer类的具体用法?C++ Timer怎么用?C++ Timer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Timer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
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: bench_distance
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: createPlane
//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 ¢er, 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: tr
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: main
// 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: main
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: main
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: main
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: generate_points_in
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: generate_edge_points
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: test_speed_for_query
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: build_skeleton
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: generate_boundary_segments
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: main
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: while
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;
}