diff --git a/AABB_tree/demo/AABB_tree/AABB_demo.pdf b/AABB_tree/demo/AABB_tree/AABB_demo.pdf index 1c85d073f7d..4336f97f0cb 100644 Binary files a/AABB_tree/demo/AABB_tree/AABB_demo.pdf and b/AABB_tree/demo/AABB_tree/AABB_demo.pdf differ diff --git a/AABB_tree/demo/AABB_tree/AABB_demo.ppt b/AABB_tree/demo/AABB_tree/AABB_demo.ppt index 69dbf0656a8..88cd9410403 100644 Binary files a/AABB_tree/demo/AABB_tree/AABB_demo.ppt and b/AABB_tree/demo/AABB_tree/AABB_demo.ppt differ diff --git a/AABB_tree/demo/AABB_tree/MainWindow.cpp b/AABB_tree/demo/AABB_tree/MainWindow.cpp index 028ad3a403c..4b80e3bee41 100644 --- a/AABB_tree/demo/AABB_tree/MainWindow.cpp +++ b/AABB_tree/demo/AABB_tree/MainWindow.cpp @@ -373,6 +373,14 @@ void MainWindow::on_actionBench_distances_vs_nbt_triggered() QApplication::restoreOverrideCursor(); } +void MainWindow::on_actionRefine_loop_triggered() +{ + QApplication::setOverrideCursor(Qt::WaitCursor); + m_pScene->refine_loop(); + QApplication::restoreOverrideCursor(); + m_pViewer->update(); +} + void MainWindow::on_actionSave_snapshot_triggered() { QApplication::setOverrideCursor(Qt::WaitCursor); @@ -384,8 +392,8 @@ void MainWindow::on_actionCopy_snapshot_triggered() // copy snapshot to clipboard QApplication::setOverrideCursor(Qt::WaitCursor); QClipboard *qb = QApplication::clipboard(); - m_pViewer->makeCurrent(); - m_pViewer->raise(); + m_pViewer->makeCurrent(); + m_pViewer->raise(); QImage snapshot = m_pViewer->grabFrameBuffer(true); qb->setImage(snapshot); QApplication::restoreOverrideCursor(); diff --git a/AABB_tree/demo/AABB_tree/MainWindow.h b/AABB_tree/demo/AABB_tree/MainWindow.h index 81289578ea3..5b262fc1a70 100644 --- a/AABB_tree/demo/AABB_tree/MainWindow.h +++ b/AABB_tree/demo/AABB_tree/MainWindow.h @@ -49,6 +49,7 @@ public: void on_actionClear_distance_function_triggered(); // algorithm menu + void on_actionRefine_loop_triggered(); void on_actionEdge_points_triggered(); void on_actionInside_points_triggered(); void on_actionBoundary_points_triggered(); diff --git a/AABB_tree/demo/AABB_tree/MainWindow.ui b/AABB_tree/demo/AABB_tree/MainWindow.ui index 24dd97313ff..834bb49b7ce 100644 --- a/AABB_tree/demo/AABB_tree/MainWindow.ui +++ b/AABB_tree/demo/AABB_tree/MainWindow.ui @@ -65,6 +65,7 @@ Refine + @@ -253,6 +254,11 @@ Copy snapshot + + + Loop subdivision + + diff --git a/AABB_tree/demo/AABB_tree/Scene.cpp b/AABB_tree/demo/AABB_tree/Scene.cpp index aebb4aa70c8..a0ca77535be 100644 --- a/AABB_tree/demo/AABB_tree/Scene.cpp +++ b/AABB_tree/demo/AABB_tree/Scene.cpp @@ -10,264 +10,270 @@ #include "Refiner.h" #include "render_edges.h" -#include + #include +#include +#include Scene::Scene() { - m_pPolyhedron = NULL; + m_pPolyhedron = NULL; - // view options - m_view_points = true; - m_view_segments = true; - m_view_polyhedron = true; - m_view_distance_function = true; + // view options + m_view_points = true; + m_view_segments = true; + m_view_polyhedron = true; + m_view_distance_function = true; - // distance function - m_red_ramp.build_red(); - m_blue_ramp.build_blue(); - m_max_distance_function = (FT)0.0; - m_signed_distance_function = false; + // distance function + m_red_ramp.build_red(); + m_blue_ramp.build_blue(); + m_max_distance_function = (FT)0.0; + m_signed_distance_function = false; } Scene::~Scene() { - delete m_pPolyhedron; + delete m_pPolyhedron; } int Scene::open(QString filename) { - QTextStream cerr(stderr); - cerr << QString("Opening file \"%1\"\n").arg(filename); - QApplication::setOverrideCursor(QCursor(::Qt::WaitCursor)); + QTextStream cerr(stderr); + cerr << QString("Opening file \"%1\"\n").arg(filename); + QApplication::setOverrideCursor(QCursor(::Qt::WaitCursor)); - QFileInfo fileinfo(filename); - std::ifstream in(filename.toUtf8()); + QFileInfo fileinfo(filename); + std::ifstream in(filename.toUtf8()); - if(!in || !fileinfo.isFile() || ! fileinfo.isReadable()) - { - std::cerr << "unable to open file" << std::endl; - QApplication::restoreOverrideCursor(); - return -1; - } + if(!in || !fileinfo.isFile() || ! fileinfo.isReadable()) + { + std::cerr << "unable to open file" << std::endl; + QApplication::restoreOverrideCursor(); + return -1; + } - if(m_pPolyhedron != NULL) - delete m_pPolyhedron; + if(m_pPolyhedron != NULL) + delete m_pPolyhedron; - // allocate new polyhedron - m_pPolyhedron = new Polyhedron; - in >> *m_pPolyhedron; - if(!in) - { - std::cerr << "invalid OFF file" << std::endl; - QApplication::restoreOverrideCursor(); + // allocate new polyhedron + m_pPolyhedron = new Polyhedron; + in >> *m_pPolyhedron; + if(!in) + { + std::cerr << "invalid OFF file" << std::endl; + QApplication::restoreOverrideCursor(); - delete m_pPolyhedron; - m_pPolyhedron = NULL; + delete m_pPolyhedron; + m_pPolyhedron = NULL; - return -1; - } + return -1; + } - QApplication::restoreOverrideCursor(); - return 0; + QApplication::restoreOverrideCursor(); + return 0; } void Scene::update_bbox() { - std::cout << "Compute bbox..."; - m_bbox = Bbox(); + std::cout << "Compute bbox..."; + m_bbox = Bbox(); - if(m_pPolyhedron == NULL) - { - std::cout << "failed (no polyhedron)." << std::endl; - return; - } + if(m_pPolyhedron == NULL) + { + std::cout << "failed (no polyhedron)." << std::endl; + return; + } - if(m_pPolyhedron->empty()) - { - std::cout << "failed (empty polyhedron)." << std::endl; - return; - } + if(m_pPolyhedron->empty()) + { + std::cout << "failed (empty polyhedron)." << std::endl; + return; + } - Polyhedron::Point_iterator it = m_pPolyhedron->points_begin(); - m_bbox = (*it).bbox(); - for(; it != m_pPolyhedron->points_end();it++) - m_bbox = m_bbox + (*it).bbox(); - std::cout << "done (" << m_pPolyhedron->size_of_facets() - << " facets)" << std::endl; + Polyhedron::Point_iterator it = m_pPolyhedron->points_begin(); + m_bbox = (*it).bbox(); + for(; it != m_pPolyhedron->points_end();it++) + m_bbox = m_bbox + (*it).bbox(); + std::cout << "done (" << m_pPolyhedron->size_of_facets() + << " facets)" << std::endl; } void Scene::draw() { - if(m_view_polyhedron) - draw_polyhedron(); + if(m_view_polyhedron) + draw_polyhedron(); - if(m_view_points) - draw_points(); + if(m_view_points) + draw_points(); - if(m_view_segments) - draw_segments(); + if(m_view_segments) + draw_segments(); - if(m_view_distance_function) - { - if(m_signed_distance_function) - draw_signed_distance_function(); - else - draw_unsigned_distance_function(); - } + if(m_view_distance_function) + { + if(m_signed_distance_function) + draw_signed_distance_function(); + else + draw_unsigned_distance_function(); + } } void Scene::draw_polyhedron() { - // draw black edges - if(m_pPolyhedron != NULL) - { - ::glDisable(GL_LIGHTING); - ::glColor3ub(0,0,0); - ::glLineWidth(1.0f); - gl_render_edges(*m_pPolyhedron); - } + // draw black edges + if(m_pPolyhedron != NULL) + { + ::glDisable(GL_LIGHTING); + ::glColor3ub(0,0,0); + ::glLineWidth(1.0f); + gl_render_edges(*m_pPolyhedron); + } } void Scene::draw_segments() { - if(m_segments.size() != 0) - { - ::glDisable(GL_LIGHTING); - ::glColor3ub(0,100,0); - ::glLineWidth(2.0f); - ::glBegin(GL_LINES); - std::list::iterator it; - for(it = m_segments.begin(); it != m_segments.end(); it++) - { - const Segment& s = *it; - const Point& p = s.source(); - const Point& q = s.target(); - ::glVertex3d(p.x(),p.y(),p.z()); - ::glVertex3d(q.x(),q.y(),q.z()); - } - ::glEnd(); - } + if(m_segments.size() != 0) + { + ::glDisable(GL_LIGHTING); + ::glColor3ub(0,100,0); + ::glLineWidth(2.0f); + ::glBegin(GL_LINES); + std::list::iterator it; + for(it = m_segments.begin(); it != m_segments.end(); it++) + { + const Segment& s = *it; + const Point& p = s.source(); + const Point& q = s.target(); + ::glVertex3d(p.x(),p.y(),p.z()); + ::glVertex3d(q.x(),q.y(),q.z()); + } + ::glEnd(); + } } void Scene::draw_points() { - // draw red points - if(m_points.size() != 0) - { - ::glDisable(GL_LIGHTING); - ::glColor3ub(180,0,0); - ::glPointSize(2.0f); - ::glBegin(GL_POINTS); - std::list::iterator it; - for(it = m_points.begin(); it != m_points.end(); it++) - { - const Point& p = *it; - ::glVertex3d(p.x(),p.y(),p.z()); - } - ::glEnd(); - } + // draw red points + if(m_points.size() != 0) + { + ::glDisable(GL_LIGHTING); + ::glColor3ub(180,0,0); + ::glPointSize(2.0f); + ::glBegin(GL_POINTS); + std::list::iterator it; + for(it = m_points.begin(); it != m_points.end(); it++) + { + const Point& p = *it; + ::glVertex3d(p.x(),p.y(),p.z()); + } + ::glEnd(); + } } void Scene::draw_unsigned_distance_function() { - if(m_max_distance_function == (FT)0.0) - return; + if(m_max_distance_function == (FT)0.0) + return; - ::glDisable(GL_LIGHTING); - ::glShadeModel(GL_SMOOTH); - ::glBegin(GL_QUADS); - int i,j; - const int nb_quads = 99; - for(i=0;i 0.0) - ::glColor3ub(m_red_ramp.r(i00),m_red_ramp.g(i00),m_red_ramp.b(i00)); - else - ::glColor3ub(m_blue_ramp.r(i00),m_blue_ramp.g(i00),m_blue_ramp.b(i00)); - ::glVertex3d(p00.x(),p00.y(),p00.z()); + // assembles one quad + if(d00 > 0.0) + ::glColor3ub(m_red_ramp.r(i00),m_red_ramp.g(i00),m_red_ramp.b(i00)); + else + ::glColor3ub(m_blue_ramp.r(i00),m_blue_ramp.g(i00),m_blue_ramp.b(i00)); + ::glVertex3d(p00.x(),p00.y(),p00.z()); - if(d01 > 0.0) - ::glColor3ub(m_red_ramp.r(i01),m_red_ramp.g(i01),m_red_ramp.b(i01)); - else - ::glColor3ub(m_blue_ramp.r(i01),m_blue_ramp.g(i01),m_blue_ramp.b(i01)); - ::glVertex3d(p01.x(),p01.y(),p01.z()); + if(d01 > 0.0) + ::glColor3ub(m_red_ramp.r(i01),m_red_ramp.g(i01),m_red_ramp.b(i01)); + else + ::glColor3ub(m_blue_ramp.r(i01),m_blue_ramp.g(i01),m_blue_ramp.b(i01)); + ::glVertex3d(p01.x(),p01.y(),p01.z()); - if(d11 > 0) - ::glColor3ub(m_red_ramp.r(i11),m_red_ramp.g(i11),m_red_ramp.b(i11)); - else - ::glColor3ub(m_blue_ramp.r(i11),m_blue_ramp.g(i11),m_blue_ramp.b(i11)); - ::glVertex3d(p11.x(),p11.y(),p11.z()); + if(d11 > 0) + ::glColor3ub(m_red_ramp.r(i11),m_red_ramp.g(i11),m_red_ramp.b(i11)); + else + ::glColor3ub(m_blue_ramp.r(i11),m_blue_ramp.g(i11),m_blue_ramp.b(i11)); + ::glVertex3d(p11.x(),p11.y(),p11.z()); - if(d10 > 0) - ::glColor3ub(m_red_ramp.r(i10),m_red_ramp.g(i10),m_red_ramp.b(i10)); - else - ::glColor3ub(m_blue_ramp.r(i10),m_blue_ramp.g(i10),m_blue_ramp.b(i10)); - ::glVertex3d(p10.x(),p10.y(),p10.z()); - } - ::glEnd(); + if(d10 > 0) + ::glColor3ub(m_red_ramp.r(i10),m_red_ramp.g(i10),m_red_ramp.b(i10)); + else + ::glColor3ub(m_blue_ramp.r(i10),m_blue_ramp.g(i10),m_blue_ramp.b(i10)); + ::glVertex3d(p10.x(),p10.y(),p10.z()); + } + } + ::glEnd(); } FT Scene::random_in(const double a, @@ -287,382 +293,389 @@ Point Scene::random_point(const CGAL::Bbox_3& bbox) Vector Scene::random_vector() { - FT x = random_in(0.0,1.0); - FT y = random_in(0.0,1.0); - FT z = random_in(0.0,1.0); - return Vector(x,y,z); + FT x = random_in(0.0,1.0); + FT y = random_in(0.0,1.0); + FT z = random_in(0.0,1.0); + return Vector(x,y,z); } Ray Scene::random_ray(const CGAL::Bbox_3& bbox) { - Point p = random_point(bbox); - Point q = random_point(bbox); - return Ray(p,q); + Point p = random_point(bbox); + Point q = random_point(bbox); + return Ray(p,q); } Segment Scene::random_segment(const CGAL::Bbox_3& bbox) { - Point p = random_point(bbox); - Point q = random_point(bbox); - return Segment(p,q); + Point p = random_point(bbox); + Point q = random_point(bbox); + return Segment(p,q); } Line Scene::random_line(const CGAL::Bbox_3& bbox) { - Point p = random_point(bbox); - Point q = random_point(bbox); - return Line(p,q); + Point p = random_point(bbox); + Point q = random_point(bbox); + return Line(p,q); } Plane Scene::random_plane(const CGAL::Bbox_3& bbox) { - Point p = random_point(bbox); - Vector vec = random_vector(); - return Plane(p,vec); + Point p = random_point(bbox); + Vector vec = random_vector(); + return Plane(p,vec); } void Scene::generate_points_in(const unsigned int nb_points, const double min, const double max) { - typedef CGAL::AABB_polyhedron_triangle_primitive Primitive; - typedef CGAL::AABB_traits Traits; - typedef CGAL::AABB_tree Tree; + typedef CGAL::AABB_polyhedron_triangle_primitive Primitive; + typedef CGAL::AABB_traits Traits; + typedef CGAL::AABB_tree Tree; - std::cout << "Construct AABB tree..."; - Tree tree(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end()); - std::cout << "done." << std::endl; + std::cout << "Construct AABB tree..."; + Tree tree(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end()); + std::cout << "done." << std::endl; - CGAL::Timer timer; - timer.start(); - std::cout << "Generate " << nb_points << " points in interval [" - << min << ";" << max << "]"; + 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()); + 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 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; + // 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; + 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; } void Scene::generate_inside_points(const unsigned int nb_points) { - typedef CGAL::AABB_polyhedron_triangle_primitive Primitive; - typedef CGAL::AABB_traits Traits; - typedef CGAL::AABB_tree Tree; + typedef CGAL::AABB_polyhedron_triangle_primitive Primitive; + typedef CGAL::AABB_traits Traits; + typedef CGAL::AABB_tree Tree; - std::cout << "Construct AABB tree..."; - Tree tree(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end()); - std::cout << "done." << std::endl; + std::cout << "Construct AABB tree..."; + Tree tree(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end()); + std::cout << "done." << std::endl; - CGAL::Timer timer; - timer.start(); - std::cout << "Generate " << nb_points << " inside points"; + CGAL::Timer timer; + timer.start(); + std::cout << "Generate " << nb_points << " inside points"; - unsigned int nb_trials = 0; - Vector vec = random_vector(); - while(m_points.size() < nb_points) - { - Point p = random_point(tree.bbox()); - Ray ray(p,vec); - int nb_intersections = (int)tree.number_of_intersected_primitives(ray); - if(nb_intersections % 2 != 0) - { - 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; + unsigned int nb_trials = 0; + Vector vec = random_vector(); + while(m_points.size() < nb_points) + { + Point p = random_point(tree.bbox()); + Ray ray(p,vec); + int nb_intersections = (int)tree.number_of_intersected_primitives(ray); + if(nb_intersections % 2 != 0) + { + 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; } void Scene::generate_boundary_segments(const unsigned int nb_slices) { - typedef CGAL::AABB_polyhedron_triangle_primitive Primitive; - typedef CGAL::AABB_traits Traits; - typedef CGAL::AABB_tree Tree; - typedef Tree::Object_and_primitive_id Object_and_primitive_id; + typedef CGAL::AABB_polyhedron_triangle_primitive Primitive; + typedef CGAL::AABB_traits Traits; + typedef CGAL::AABB_tree Tree; + typedef Tree::Object_and_primitive_id Object_and_primitive_id; - std::cout << "Construct AABB tree..."; - Tree tree(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end()); - std::cout << "done." << std::endl; + std::cout << "Construct AABB tree..."; + Tree tree(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end()); + std::cout << "done." << std::endl; - CGAL::Timer timer; - timer.start(); - std::cout << "Generate boundary segments from " << nb_slices << " slices: "; + 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; + 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 intersections; - tree.all_intersections(plane,std::back_inserter(intersections)); + std::list intersections; + tree.all_intersections(plane,std::back_inserter(intersections)); - std::list::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; + std::list::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; } void Scene::generate_boundary_points(const unsigned int nb_points) { - typedef CGAL::AABB_polyhedron_triangle_primitive Primitive; - typedef CGAL::AABB_traits Traits; - typedef CGAL::AABB_tree Tree; - typedef Tree::Object_and_primitive_id Object_and_primitive_id; + typedef CGAL::AABB_polyhedron_triangle_primitive Primitive; + typedef CGAL::AABB_traits Traits; + typedef CGAL::AABB_tree Tree; + typedef Tree::Object_and_primitive_id Object_and_primitive_id; - std::cout << "Construct AABB tree..."; - Tree tree(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end()); - std::cout << "done." << std::endl; + std::cout << "Construct AABB tree..."; + Tree tree(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end()); + std::cout << "done." << std::endl; - CGAL::Timer timer; - timer.start(); - std::cout << "Generate boundary points: "; + CGAL::Timer timer; + timer.start(); + std::cout << "Generate boundary points: "; - unsigned int nb = 0; - unsigned int nb_lines = 0; - while(nb < nb_points) - { - Line line = random_line(tree.bbox()); + unsigned int nb = 0; + unsigned int nb_lines = 0; + while(nb < nb_points) + { + Line line = random_line(tree.bbox()); - std::list intersections; - tree.all_intersections(line,std::back_inserter(intersections)); - nb_lines++; + std::list intersections; + tree.all_intersections(line,std::back_inserter(intersections)); + nb_lines++; - std::list::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_lines << " line queries, " << timer.time() << " s." << std::endl; + std::list::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_lines << " line queries, " << timer.time() << " s." << std::endl; } void Scene::generate_edge_points(const unsigned int nb_points) { - typedef CGAL::AABB_polyhedron_segment_primitive Primitive; - typedef CGAL::AABB_traits Traits; - typedef CGAL::AABB_tree Tree; - typedef Tree::Object_and_primitive_id Object_and_primitive_id; + typedef CGAL::AABB_polyhedron_segment_primitive Primitive; + typedef CGAL::AABB_traits Traits; + typedef CGAL::AABB_tree Tree; + typedef Tree::Object_and_primitive_id Object_and_primitive_id; - std::cout << "Construct AABB tree..."; - Tree tree(m_pPolyhedron->edges_begin(),m_pPolyhedron->edges_end()); - std::cout << "done." << std::endl; + std::cout << "Construct AABB tree..."; + Tree tree(m_pPolyhedron->edges_begin(),m_pPolyhedron->edges_end()); + std::cout << "done." << std::endl; - CGAL::Timer timer; - timer.start(); - std::cout << "Generate edge points: "; + 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()); + unsigned int nb = 0; + unsigned int nb_planes = 0; + while(nb < nb_points) + { + Plane plane = random_plane(tree.bbox()); - std::list intersections; - tree.all_intersections(plane,std::back_inserter(intersections)); - nb_planes++; + std::list intersections; + tree.all_intersections(plane,std::back_inserter(intersections)); + nb_planes++; - std::list::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; + std::list::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; } void Scene::unsigned_distance_function() { - CGAL::Timer timer; - timer.start(); - std::cout << "Construct AABB tree..."; - Facet_tree tree(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end()); - tree.accelerate_distance_queries(); - std::cout << "done (" << timer.time() << " s)" << std::endl; + CGAL::Timer timer; + timer.start(); + std::cout << "Construct AABB tree..."; + Facet_tree tree(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end()); + tree.accelerate_distance_queries(); + std::cout << "done (" << timer.time() << " s)" << std::endl; - m_max_distance_function = (FT)0.0; - int i,j; - const double dx = m_bbox.xmax() - m_bbox.xmin(); - const double dy = m_bbox.ymax() - m_bbox.ymin(); - const double z = 0.5 * (m_bbox.zmax() + m_bbox.zmin()); - for(i=0;i<100;i++) - { - FT x = m_bbox.xmin() + (FT)((double)i/100.0 * dx); - for(j=0;j<100;j++) - { - FT y = m_bbox.ymin() + (FT)((double)j/100.0 * dy); - Point query(x,y,z); - FT sq_distance = tree.squared_distance(query); - FT distance = std::sqrt(sq_distance); - m_distance_function[i][j] = Point_distance(query,distance); - m_max_distance_function = distance > m_max_distance_function ? - distance : m_max_distance_function; - } - } - m_signed_distance_function = false; + m_max_distance_function = (FT)0.0; + int i,j; + const double dx = m_bbox.xmax() - m_bbox.xmin(); + const double dy = m_bbox.ymax() - m_bbox.ymin(); + const double z = 0.5 * (m_bbox.zmax() + m_bbox.zmin()); + for(i=0;i<100;i++) + { + FT x = m_bbox.xmin() + (FT)((double)i/100.0 * dx); + for(j=0;j<100;j++) + { + FT y = m_bbox.ymin() + (FT)((double)j/100.0 * dy); + Point query(x,y,z); + FT sq_distance = tree.squared_distance(query); + FT distance = std::sqrt(sq_distance); + m_distance_function[i][j] = Point_distance(query,distance); + m_max_distance_function = distance > m_max_distance_function ? +distance : m_max_distance_function; + } + } + m_signed_distance_function = false; } void Scene::unsigned_distance_function_to_edges() { - typedef CGAL::AABB_polyhedron_segment_primitive Primitive; - typedef CGAL::AABB_traits Traits; - typedef CGAL::AABB_tree Edge_tree; + typedef CGAL::AABB_polyhedron_segment_primitive Primitive; + typedef CGAL::AABB_traits Traits; + typedef CGAL::AABB_tree Edge_tree; - CGAL::Timer timer; - timer.start(); - std::cout << "Construct AABB tree from edges..."; - Edge_tree tree(m_pPolyhedron->edges_begin(),m_pPolyhedron->edges_end()); - tree.accelerate_distance_queries(); - std::cout << "done (" << timer.time() << " s)" << std::endl; + CGAL::Timer timer; + timer.start(); + std::cout << "Construct AABB tree from edges..."; + Edge_tree tree(m_pPolyhedron->edges_begin(),m_pPolyhedron->edges_end()); + tree.accelerate_distance_queries(); + std::cout << "done (" << timer.time() << " s)" << std::endl; - m_max_distance_function = (FT)0.0; - const double dx = m_bbox.xmax() - m_bbox.xmin(); - const double dy = m_bbox.ymax() - m_bbox.ymin(); - const double z = 0.5 * (m_bbox.zmax() + m_bbox.zmin()); - int i,j; - for(i=0;i<100;i++) - { - FT x = m_bbox.xmin() + (FT)((double)i/100.0 * dx); - for(j=0;j<100;j++) - { - FT y = m_bbox.ymin() + (FT)((double)j/100.0 * dy); - Point query(x,y,z); - FT sq_distance = tree.squared_distance(query); - FT distance = std::sqrt(sq_distance); - m_distance_function[i][j] = Point_distance(query,distance); - m_max_distance_function = distance > m_max_distance_function ? + m_max_distance_function = (FT)0.0; + const double dx = m_bbox.xmax() - m_bbox.xmin(); + const double dy = m_bbox.ymax() - m_bbox.ymin(); + const double z = 0.5 * (m_bbox.zmax() + m_bbox.zmin()); + int i,j; + for(i=0;i<100;i++) + { + FT x = m_bbox.xmin() + (FT)((double)i/100.0 * dx); + for(j=0;j<100;j++) + { + FT y = m_bbox.ymin() + (FT)((double)j/100.0 * dy); + Point query(x,y,z); + FT sq_distance = tree.squared_distance(query); + FT distance = std::sqrt(sq_distance); + m_distance_function[i][j] = Point_distance(query,distance); + m_max_distance_function = distance > m_max_distance_function ? distance : m_max_distance_function; - } - } - m_signed_distance_function = false; + } + } + m_signed_distance_function = false; } void Scene::signed_distance_function() { - CGAL::Timer timer; - timer.start(); - std::cout << "Construct AABB tree..."; - Facet_tree tree(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end()); - tree.accelerate_distance_queries(); - std::cout << "done (" << timer.time() << " s)" << std::endl; + CGAL::Timer timer; + timer.start(); + std::cout << "Construct AABB tree..."; + Facet_tree tree(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end()); + tree.accelerate_distance_queries(); + std::cout << "done (" << timer.time() << " s)" << std::endl; - m_max_distance_function = (FT)0.0; - Vector vec = random_vector(); + m_max_distance_function = (FT)0.0; + Vector vec = random_vector(); - const double dx = m_bbox.xmax() - m_bbox.xmin(); - const double dy = m_bbox.ymax() - m_bbox.ymin(); - const double z = 0.5 * (m_bbox.zmax() + m_bbox.zmin()); - int i,j; - for(i=0;i<100;i++) - { - FT x = m_bbox.xmin() + (FT)((double)i/100.0 * dx); - for(j=0;j<100;j++) - { - FT y = m_bbox.ymin() + (FT)((double)j/100.0 * dy); - Point query(x,y,z); - FT sq_distance = tree.squared_distance(query); - FT unsigned_distance = std::sqrt(sq_distance); + const double dx = m_bbox.xmax() - m_bbox.xmin(); + const double dy = m_bbox.ymax() - m_bbox.ymin(); + const double z = 0.5 * (m_bbox.zmax() + m_bbox.zmin()); + int i,j; + for(i=0;i<100;i++) + { + FT x = m_bbox.xmin() + (FT)((double)i/100.0 * dx); + for(j=0;j<100;j++) + { + FT y = m_bbox.ymin() + (FT)((double)j/100.0 * dy); + Point query(x,y,z); + FT sq_distance = tree.squared_distance(query); + FT unsigned_distance = std::sqrt(sq_distance); - // get sign through ray casting (random vector) - Ray ray(query,vec); - unsigned int nbi = tree.number_of_intersected_primitives(ray); - FT sign = nbi%2 == 0 ? (FT)1.0 : (FT)-1.0; - FT signed_distance = sign * unsigned_distance; + // get sign through ray casting (random vector) + Ray ray(query,vec); + unsigned int nbi = tree.number_of_intersected_primitives(ray); + FT sign = nbi%2 == 0 ? (FT)1.0 : (FT)-1.0; + FT signed_distance = sign * unsigned_distance; - m_distance_function[i][j] = Point_distance(query,signed_distance); - m_max_distance_function = unsigned_distance > m_max_distance_function ? + m_distance_function[i][j] = Point_distance(query,signed_distance); + m_max_distance_function = unsigned_distance > m_max_distance_function ? unsigned_distance : m_max_distance_function; - } - } - m_signed_distance_function = true; + } + } + m_signed_distance_function = true; } void Scene::toggle_view_poyhedron() { - m_view_polyhedron = !m_view_polyhedron; + m_view_polyhedron = !m_view_polyhedron; } void Scene::toggle_view_segments() { - m_view_segments = !m_view_segments; + m_view_segments = !m_view_segments; } void Scene::toggle_view_points() { - m_view_points = !m_view_points; + m_view_points = !m_view_points; } void Scene::toggle_view_distance_function() { - m_view_distance_function = !m_view_distance_function; + m_view_distance_function = !m_view_distance_function; } void Scene::refine_bisection(const FT max_sqlen) { - std::cout << "Refine through recursive longest edge bisection..."; - Refiner refiner(m_pPolyhedron); - refiner(max_sqlen); - std::cout << "done (" << m_pPolyhedron->size_of_facets() << " facets)" << std::endl; + std::cout << "Refine through recursive longest edge bisection..."; + Refiner refiner(m_pPolyhedron); + refiner(max_sqlen); + std::cout << "done (" << m_pPolyhedron->size_of_facets() << " facets)" << std::endl; +} + +void Scene::refine_loop() +{ + std::cout << "Loop subdivision..."; + CGAL::Subdivision_method_3::Loop_subdivision(*m_pPolyhedron, 1); + std::cout << "done (" << m_pPolyhedron->size_of_facets() << " facets)" << std::endl; } diff --git a/AABB_tree/demo/AABB_tree/Scene.h b/AABB_tree/demo/AABB_tree/Scene.h index 6d5c6ca8abf..02270e5e0de 100644 --- a/AABB_tree/demo/AABB_tree/Scene.h +++ b/AABB_tree/demo/AABB_tree/Scene.h @@ -17,121 +17,124 @@ class Scene { public: - Scene(); - ~Scene(); + Scene(); + ~Scene(); public: - // types - typedef CGAL::Bbox_3 Bbox; - typedef CGAL::AABB_polyhedron_triangle_primitive Primitive; - typedef CGAL::AABB_traits Traits; - typedef CGAL::AABB_tree Facet_tree; - typedef Facet_tree::Object_and_primitive_id Object_and_primitive_id; - typedef Facet_tree::Primitive_id Primitive_id; + // types + typedef CGAL::Bbox_3 Bbox; + typedef CGAL::AABB_polyhedron_triangle_primitive Primitive; + typedef CGAL::AABB_traits Traits; + typedef CGAL::AABB_tree Facet_tree; + typedef Facet_tree::Object_and_primitive_id Object_and_primitive_id; + typedef Facet_tree::Primitive_id Primitive_id; public: - void draw(); - void update_bbox(); - Bbox bbox() { return m_bbox; } + void draw(); + void update_bbox(); + Bbox bbox() { return m_bbox; } private: - // member data - Bbox m_bbox; - Polyhedron *m_pPolyhedron; - std::list m_points; - std::list m_segments; + // member data + Bbox m_bbox; + Polyhedron *m_pPolyhedron; + std::list m_points; + std::list m_segments; - // distance functions (simple 2D arrays) - Color_ramp m_red_ramp; - Color_ramp m_blue_ramp; - Color_ramp m_thermal_ramp; - FT m_max_distance_function; - bool m_view_distance_function; - bool m_signed_distance_function; - typedef std::pair Point_distance; - Point_distance m_distance_function[100][100]; + // distance functions (simple 2D arrays) + Color_ramp m_red_ramp; + Color_ramp m_blue_ramp; + Color_ramp m_thermal_ramp; + FT m_max_distance_function; + bool m_view_distance_function; + bool m_signed_distance_function; + typedef std::pair Point_distance; + Point_distance m_distance_function[100][100]; private: - // utility functions - Vector random_vector(); - Ray random_ray(const Bbox& bbox); - FT random_in(const double a,const double b); - Line random_line(const Bbox& bbox); - Point random_point(const Bbox& bbox); - Plane random_plane(const Bbox& bbox); - Segment random_segment(const Bbox& bbox); + // utility functions + Vector random_vector(); + Ray random_ray(const Bbox& bbox); + Line random_line(const Bbox& bbox); + Point random_point(const Bbox& bbox); + Plane random_plane(const Bbox& bbox); + Segment random_segment(const Bbox& bbox); + FT random_in(const double a,const double b); public: - // file menu - int open(QString filename); + // file menu + int open(QString filename); - // edit menu - void clear_points() { m_points.clear(); } - void clear_segments() { m_segments.clear(); } - void clear_distance_function() { m_max_distance_function = 0.0; } + // edit menu + void clear_points() { m_points.clear(); } + void clear_segments() { m_segments.clear(); } + void clear_distance_function() { m_max_distance_function = 0.0; } - // algorithms - void refine_bisection(const FT max_sqlen); - void generate_edge_points(const unsigned int nb_points); - void generate_inside_points(const unsigned int nb_points); - void generate_boundary_points(const unsigned int nb_points); - void generate_boundary_segments(const unsigned int nb_slices); - void generate_points_in(const unsigned int nb_points, - const double min, const double max); + // algorithms + void generate_edge_points(const unsigned int nb_points); + void generate_inside_points(const unsigned int nb_points); + void generate_boundary_points(const unsigned int nb_points); + void generate_boundary_segments(const unsigned int nb_slices); + void generate_points_in(const unsigned int nb_points, + const double min, const double max); - // distance functions - void signed_distance_function(); - void unsigned_distance_function(); - void unsigned_distance_function_to_edges(); + // algorithms/refine + void refine_loop(); + void refine_bisection(const FT max_sqlen); - // toggle view options - void toggle_view_points(); - void toggle_view_segments(); - void toggle_view_poyhedron(); - void toggle_view_distance_function(); + // distance functions + void signed_distance_function(); + void unsigned_distance_function(); + void unsigned_distance_function_to_edges(); - // view options - bool m_view_points; - bool m_view_segments; - bool m_view_polyhedron; + // toggle view options + void toggle_view_points(); + void toggle_view_segments(); + void toggle_view_poyhedron(); + void toggle_view_distance_function(); - // benchmarks - enum {DO_INTERSECT, - ANY_INTERSECTION, - NB_INTERSECTIONS, - ALL_INTERSECTIONS, - ANY_INTERSECTED_PRIMITIVE, - ALL_INTERSECTED_PRIMITIVES}; - void bench_memory(); - void bench_construction(); - void bench_distances_vs_nbt(); - void bench_intersections_vs_nbt(); - void benchmark_intersections(const double duration); - unsigned int nb_digits(const unsigned int value); + // view options + bool m_view_points; + bool m_view_segments; + bool m_view_polyhedron; - template - void bench_intersection(Facet_tree& tree,const int function,const double duration, - char *query_name, const std::vector& queries, const int nb_queries); - void bench_intersections(Facet_tree& tree, const double duration, const int function, - char *function_name, const std::vector& rays, - const std::vector& lines, const std::vector& planes, - const std::vector& segments, const int nb_queries); + // benchmarks + enum {DO_INTERSECT, + ANY_INTERSECTION, + NB_INTERSECTIONS, + ALL_INTERSECTIONS, + ANY_INTERSECTED_PRIMITIVE, + ALL_INTERSECTED_PRIMITIVES}; + void bench_memory(); + void bench_construction(); + void bench_distances_vs_nbt(); + void bench_intersections_vs_nbt(); + void benchmark_intersections(const double duration); + unsigned int nb_digits(const unsigned int value); - // distance benchmarks - enum {SQ_DISTANCE, - CLOSEST_POINT, - CLOSEST_POINT_AND_PRIMITIVE_ID}; - void benchmark_distances(const double duration); - void bench_closest_point(Facet_tree& tree,const double duration); - void bench_squared_distance(Facet_tree& tree,const double duration); - void bench_closest_point_and_primitive(Facet_tree& tree,const double duration); - void bench_distance(Facet_tree& tree,const int function,const double duration); + template + void bench_intersection(Facet_tree& tree,const int function,const double duration, + char *query_name, const std::vector& queries, const int nb_queries); + void bench_intersections(Facet_tree& tree, const double duration, const int function, + char *function_name, const std::vector& rays, + const std::vector& lines, const std::vector& planes, + const std::vector& segments, const int nb_queries); - // drawing - void draw_points(); - void draw_segments(); - void draw_polyhedron(); - void draw_signed_distance_function(); - void draw_unsigned_distance_function(); + // distance benchmarks + enum {SQ_DISTANCE, + CLOSEST_POINT, + CLOSEST_POINT_AND_PRIMITIVE_ID}; + void benchmark_distances(const double duration); + void bench_closest_point(Facet_tree& tree,const double duration); + void bench_squared_distance(Facet_tree& tree,const double duration); + void bench_closest_point_and_primitive(Facet_tree& tree,const double duration); + void bench_distance(Facet_tree& tree,const int function,const double duration); + + // drawing + void draw_points(); + void draw_segments(); + void draw_polyhedron(); + void draw_signed_distance_function(); + void draw_unsigned_distance_function(); }; // end class Scene diff --git a/AABB_tree/doc_tex/AABB_tree/performances.tex b/AABB_tree/doc_tex/AABB_tree/performances.tex index a20515dffb3..e614129e549 100644 --- a/AABB_tree/doc_tex/AABB_tree/performances.tex +++ b/AABB_tree/doc_tex/AABB_tree/performances.tex @@ -1,11 +1,11 @@ \section{Performances} \label{AABB_tree_section_performances} -We provide some performance numbers for the case where the AABB tree contains a set of polyhedron triangle facets. We measure the tree construction time, the memory occupancy, and the number of queries per second for a variety of intersection and distance queries. The machine used is a PC running Windows XP64 with an Intel CPU Core2 Extreme clocked at 3.06 GHz with 4GB of RAM. By default the kernel used is \ccc{Simple_cartesian} (the fastest in our experiments). The program has been compiled with Visual C++ 2005 compiler with the O2 option (maximize speed). +We provide some performance numbers for the case where the AABB tree contains a set of polyhedron triangle facets. We measure the tree construction time, the memory occupancy and the number of queries per second for a variety of intersection and distance queries. The machine used is a PC running Windows XP64 with an Intel CPU Core2 Extreme clocked at 3.06 GHz with 4GB of RAM. By default the kernel used is \ccc{Simple_cartesian} (the fastest in our experiments). The program has been compiled with Visual C++ 2005 compiler with the O2 option which maximizes speed. \subsection{Construction} -The surface triangle mesh chosen for benchmarking the tree construction is the knot model (14,400 triangles) available in the demo data folder. We measure the tree construction time (both AABB tree alone and AABB tree with internal KD-tree) for this model as well as for three denser versions subdivided through the Loop subdivision scheme which increases the number of triangles by a factor of four. +The surface triangle mesh chosen for benchmarking the tree construction is the knot model (14,400 triangles) depicted by Figure \ref{fig:AABB-tree-bench}. We measure the tree construction time (both AABB tree alone and AABB tree with internal KD-tree) for this model as well as for three denser versions subdivided through the Loop subdivision scheme which multiplies the number of triangles by four. \begin{tabular}{|l|c|c|} \hline @@ -111,7 +111,7 @@ The surface triangle mesh chosen for benchmarking distances is again the knot mo \subsection{Summary} -The experiments described above are neither exhaustive nor conclusive as we have chosen one specific case where the input primitives are the facets of a triangle surface polyhedron. Nevertheless we provide the reader with some general observations and advices about how to put the AABB tree to use with satisfactory performances. While the tree construction times and memory occupancy do not fluctuate much in our experiments depending on the input surface triangle mesh, the performance expressed in number of queries varies greatly depending on a complex combination of criteria: type of kernel, number of input primitives, distribution of primitives in space, type of function queried, type of query, and location of query in space. +The experiments described above are neither exhaustive nor conclusive as we have chosen one specific case where the input primitives are the facets of a triangle surface polyhedron. Nevertheless we now provide some general observations and advices about how to put the AABB tree to use with satisfactory performances. While the tree construction times and memory occupancy do not fluctuate much in our experiments depending on the input surface triangle mesh, the performance expressed in number of queries varies greatly depending on a complex combination of criteria: type of kernel, number of input primitives, distribution of primitives in space, type of function queried, type of query and location of query in space. \begin{itemize}