diff --git a/.gitattributes b/.gitattributes index adafedc646b..6035d4a12f6 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,25 +1,16 @@ * text=auto !eol -AABB_tree/demo/AABB_tree/AABB_demo.cpp -text AABB_tree/demo/AABB_tree/AABB_demo.pdf -text svneol=unset#application/pdf AABB_tree/demo/AABB_tree/AABB_demo.ppt -text svneol=unset#application/vnd.ms-powerpoint AABB_tree/demo/AABB_tree/AABB_demo.qrc -text AABB_tree/demo/AABB_tree/CMakeLists.txt -text -AABB_tree/demo/AABB_tree/MainWindow.cpp -text -AABB_tree/demo/AABB_tree/MainWindow.h -text AABB_tree/demo/AABB_tree/MainWindow.ui -text -AABB_tree/demo/AABB_tree/Scene.cpp -text -AABB_tree/demo/AABB_tree/Scene.h -text -AABB_tree/demo/AABB_tree/Viewer.cpp -text -AABB_tree/demo/AABB_tree/Viewer.h -text AABB_tree/demo/AABB_tree/cleanup.bat eol=crlf AABB_tree/demo/AABB_tree/data/hand.off -text svneol=unset#application/octet-stream AABB_tree/demo/AABB_tree/data/knot.off -text AABB_tree/demo/AABB_tree/data/part.off -text svneol=unset#application/octet-stream AABB_tree/demo/AABB_tree/data/u.off -text svneol=unset#application/octet-stream -AABB_tree/demo/AABB_tree/render_edges.h -text AABB_tree/demo/AABB_tree/resources/about.html -text AABB_tree/demo/AABB_tree/resources/cgal_logo.xpm -text -AABB_tree/demo/AABB_tree/types.h -text AABB_tree/doc_tex/AABB_tree/PkgDescription.tex -text AABB_tree/doc_tex/AABB_tree/details.tex -text AABB_tree/doc_tex/AABB_tree/examples.tex -text diff --git a/AABB_tree/demo/AABB_tree/AABB_demo.cpp b/AABB_tree/demo/AABB_tree/AABB_demo.cpp index ba837003b26..e929f15143c 100644 --- a/AABB_tree/demo/AABB_tree/AABB_demo.cpp +++ b/AABB_tree/demo/AABB_tree/AABB_demo.cpp @@ -1,66 +1,66 @@ -// Copyright (c) 2009 INRIA Sophia-Antipolis (France). -// All rights reserved. -// -// This file is part of CGAL (www.cgal.org); you may redistribute it under -// the terms of the Q Public License version 1.0. -// See the file LICENSE.QPL distributed with CGAL. -// -// Licensees holding a valid commercial license may use this file in -// accordance with the commercial license agreement provided with the software. -// -// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -// -// $URL: $ -// $Id: $ -// -// -// Author(s) : Pierre Alliez, Camille Wormser -// -//****************************************************************************** -// File Description : demo of AABB tree on polyhedral edge and facet primitives -// -//****************************************************************************** - -#include "MainWindow.h" -#include - -int main(int argc, char **argv) -{ - QApplication app(argc, argv); - app.setOrganizationDomain("inria.fr"); - app.setOrganizationName("INRIA"); - app.setApplicationName("AABB tree demo"); - - // Import resources from libCGALQt4. - // See http://doc.trolltech.com/4.4/qdir.html#Q_INIT_RESOURCE - Q_INIT_RESOURCE(File); - Q_INIT_RESOURCE(Triangulation_2); - Q_INIT_RESOURCE(Input); - Q_INIT_RESOURCE(CGAL); - - MainWindow mainWindow; - mainWindow.show(); - QStringList args = app.arguments(); - args.removeAt(0); - - if(!args.empty() && args[0] == "--use-meta") - { - mainWindow.setAddKeyFrameKeyboardModifiers(::Qt::MetaModifier); - args.removeAt(0); - } - - Q_FOREACH(QString filename, args) - mainWindow.open(filename); - - return app.exec(); -} - -# include "Scene.cpp" -# include "Scene_moc.cpp" -# include "benchmarks.cpp" -# include "Viewer.cpp" -# include "Viewer_moc.cpp" -# include "MainWindow.cpp" -# include "MainWindow_moc.cpp" - +// Copyright (c) 2009 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you may redistribute it under +// the terms of the Q Public License version 1.0. +// See the file LICENSE.QPL distributed with CGAL. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL: $ +// $Id: $ +// +// +// Author(s) : Pierre Alliez, Camille Wormser +// +//****************************************************************************** +// File Description : demo of AABB tree on polyhedral edge and facet primitives +// +//****************************************************************************** + +#include "MainWindow.h" +#include + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + app.setOrganizationDomain("inria.fr"); + app.setOrganizationName("INRIA"); + app.setApplicationName("AABB tree demo"); + + // Import resources from libCGALQt4. + // See http://doc.trolltech.com/4.4/qdir.html#Q_INIT_RESOURCE + Q_INIT_RESOURCE(File); + Q_INIT_RESOURCE(Triangulation_2); + Q_INIT_RESOURCE(Input); + Q_INIT_RESOURCE(CGAL); + + MainWindow mainWindow; + mainWindow.show(); + QStringList args = app.arguments(); + args.removeAt(0); + + if(!args.empty() && args[0] == "--use-meta") + { + mainWindow.setAddKeyFrameKeyboardModifiers(::Qt::MetaModifier); + args.removeAt(0); + } + + Q_FOREACH(QString filename, args) + mainWindow.open(filename); + + return app.exec(); +} + +# include "Scene.cpp" +# include "Scene_moc.cpp" +# include "benchmarks.cpp" +# include "Viewer.cpp" +# include "Viewer_moc.cpp" +# include "MainWindow.cpp" +# include "MainWindow_moc.cpp" + diff --git a/AABB_tree/demo/AABB_tree/MainWindow.cpp b/AABB_tree/demo/AABB_tree/MainWindow.cpp index b7f74a97163..c4ffcc8ae3f 100644 --- a/AABB_tree/demo/AABB_tree/MainWindow.cpp +++ b/AABB_tree/demo/AABB_tree/MainWindow.cpp @@ -1,423 +1,423 @@ -#include "MainWindow.h" -#include "Scene.h" -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "ui_MainWindow.h" - -MainWindow::MainWindow(QWidget* parent) -: CGAL::Qt::DemosMainWindow(parent) -{ - ui = new Ui::MainWindow; - ui->setupUi(this); - - // saves some pointers from ui, for latter use. - m_pViewer = ui->viewer; - - // does not save the state of the viewer - m_pViewer->setStateFileName(QString::null); - - // accepts drop events - setAcceptDrops(true); - - // setups scene - m_pScene = new Scene; - m_pViewer->setScene(m_pScene); - m_pViewer->setManipulatedFrame(m_pScene->manipulatedFrame()); - - // connects actionQuit (Ctrl+Q) and qApp->quit() - connect(ui->actionQuit, SIGNAL(triggered()), - this, SLOT(quit())); - - this->addRecentFiles(ui->menuFile, ui->actionQuit); - connect(this, SIGNAL(openRecentFile(QString)), - this, SLOT(open(QString))); - - readSettings(); -} - -MainWindow::~MainWindow() -{ - delete ui; -} - -void MainWindow::dragEnterEvent(QDragEnterEvent *event) -{ - if (event->mimeData()->hasFormat("text/uri-list")) - event->acceptProposedAction(); -} - -void MainWindow::dropEvent(QDropEvent *event) -{ - Q_FOREACH(QUrl url, event->mimeData()->urls()) { - QString filename = url.toLocalFile(); - if(!filename.isEmpty()) { - QTextStream(stderr) << QString("dropEvent(\"%1\")\n").arg(filename); - open(filename); - } - } - event->acceptProposedAction(); -} - -void MainWindow::updateViewerBBox() -{ - m_pScene->update_bbox(); - const Scene::Bbox bbox = m_pScene->bbox(); - const double xmin = bbox.xmin(); - const double ymin = bbox.ymin(); - const double zmin = bbox.zmin(); - const double xmax = bbox.xmax(); - const double ymax = bbox.ymax(); - const double zmax = bbox.zmax(); - qglviewer::Vec - vec_min(xmin, ymin, zmin), - vec_max(xmax, ymax, zmax); - m_pViewer->setSceneBoundingBox(vec_min,vec_max); - m_pViewer->camera()->showEntireScene(); -} - -void MainWindow::open(QString filename) -{ - QFileInfo fileinfo(filename); - if(fileinfo.isFile() && fileinfo.isReadable()) - { - int index = m_pScene->open(filename); - if(index >= 0) - { - QSettings settings; - settings.setValue("OFF open directory", - fileinfo.absoluteDir().absolutePath()); - this->addToRecentFiles(filename); - - // update bbox - updateViewerBBox(); - m_pViewer->update(); - } - } -} - -void MainWindow::readSettings() -{ - this->readState("MainWindow", Size|State); -} - -void MainWindow::writeSettings() -{ - this->writeState("MainWindow"); - std::cerr << "Write setting... done.\n"; -} - -void MainWindow::quit() -{ - writeSettings(); - close(); -} - -void MainWindow::closeEvent(QCloseEvent *event) -{ - writeSettings(); - event->accept(); -} - -void MainWindow::on_actionLoadPolyhedron_triggered() -{ - QSettings settings; - QString directory = settings.value("OFF open directory", - QDir::current().dirName()).toString(); - QStringList filenames = - QFileDialog::getOpenFileNames(this, - tr("Load polyhedron..."), - directory, - tr("OFF files (*.off)\n" - "All files (*)")); - if(!filenames.isEmpty()) { - Q_FOREACH(QString filename, filenames) { - open(filename); - } - } -} - - -void MainWindow::setAddKeyFrameKeyboardModifiers(::Qt::KeyboardModifiers m) -{ - m_pViewer->setAddKeyFrameKeyboardModifiers(m); -} - -void MainWindow::on_actionInside_points_triggered() -{ - bool ok; - const unsigned int nb_points = (unsigned) - QInputDialog::getInteger(NULL, "#Points", - "#Points:",10000,1,100000000,9,&ok); - if(!ok) - return; - - QApplication::setOverrideCursor(Qt::WaitCursor); - m_pScene->generate_inside_points(nb_points); - QApplication::restoreOverrideCursor(); - m_pViewer->update(); -} - -void MainWindow::on_actionPoints_in_interval_triggered() -{ - bool ok; - const unsigned int nb_points = (unsigned) - QInputDialog::getInteger(NULL, "#Points", - "#Points:",10000,1,100000000,9,&ok); - if(!ok) - return; - - const double min = - QInputDialog::getDouble(NULL, "min", - "Min:",-0.1,-1000.0,1000.0,9,&ok); - if(!ok) - return; - const double max = - QInputDialog::getDouble(NULL, "max", - "Max:",0.1,-1000.0,1000.0,9,&ok); - if(!ok) - return; - - QApplication::setOverrideCursor(Qt::WaitCursor); - m_pScene->generate_points_in(nb_points,min,max); - QApplication::restoreOverrideCursor(); - m_pViewer->update(); -} - -void MainWindow::on_actionBoundary_segments_triggered() -{ - bool ok; - const unsigned int nb_slices = (unsigned) - QInputDialog::getInteger(NULL, "#Slices", - "Slices:",100,1,1000000,8,&ok); - if(!ok) - return; - - QApplication::setOverrideCursor(Qt::WaitCursor); - m_pScene->generate_boundary_segments(nb_slices); - QApplication::restoreOverrideCursor(); - m_pViewer->update(); -} - -void MainWindow::on_actionBoundary_points_triggered() -{ - bool ok; - const unsigned int nb_points = (unsigned) - QInputDialog::getInteger(NULL, "#Points", - "Points:",1000,1,10000000,8,&ok); - if(!ok) - return; - - QApplication::setOverrideCursor(Qt::WaitCursor); - m_pScene->generate_boundary_points(nb_points); - QApplication::restoreOverrideCursor(); - m_pViewer->update(); -} - -void MainWindow::on_actionEdge_points_triggered() -{ - bool ok; - const unsigned int nb_points = (unsigned) - QInputDialog::getInteger(NULL, "#Points", - "Points:",1000,1,10000000,8,&ok); - if(!ok) - return; - - QApplication::setOverrideCursor(Qt::WaitCursor); - m_pScene->generate_edge_points(nb_points); - QApplication::restoreOverrideCursor(); - m_pViewer->update(); -} - -void MainWindow::on_actionBench_distances_triggered() -{ - bool ok; - const double duration = QInputDialog::getDouble(NULL, "Duration", - "Duration (s):",1.0,0.01,1000,8,&ok); - if(!ok) - return; - - QApplication::setOverrideCursor(Qt::WaitCursor); - std::cout << std::endl << "Benchmark distances" << std::endl; - m_pScene->benchmark_distances(duration); - QApplication::restoreOverrideCursor(); -} - -void MainWindow::on_actionBench_intersections_triggered() -{ - bool ok; - const double duration = QInputDialog::getDouble(NULL, "Duration", - "Duration (s):",1.0,0.01,1000.0,8,&ok); - if(!ok) - return; - - QApplication::setOverrideCursor(Qt::WaitCursor); - std::cout << std::endl << "Benchmark intersections" << std::endl; - m_pScene->benchmark_intersections(duration); - QApplication::restoreOverrideCursor(); -} - -void MainWindow::on_actionUnsigned_distance_function_to_facets_triggered() -{ - QApplication::setOverrideCursor(Qt::WaitCursor); +#include "MainWindow.h" +#include "Scene.h" +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ui_MainWindow.h" + +MainWindow::MainWindow(QWidget* parent) +: CGAL::Qt::DemosMainWindow(parent) +{ + ui = new Ui::MainWindow; + ui->setupUi(this); + + // saves some pointers from ui, for latter use. + m_pViewer = ui->viewer; + + // does not save the state of the viewer + m_pViewer->setStateFileName(QString::null); + + // accepts drop events + setAcceptDrops(true); + + // setups scene + m_pScene = new Scene; + m_pViewer->setScene(m_pScene); + m_pViewer->setManipulatedFrame(m_pScene->manipulatedFrame()); + + // connects actionQuit (Ctrl+Q) and qApp->quit() + connect(ui->actionQuit, SIGNAL(triggered()), + this, SLOT(quit())); + + this->addRecentFiles(ui->menuFile, ui->actionQuit); + connect(this, SIGNAL(openRecentFile(QString)), + this, SLOT(open(QString))); + + readSettings(); +} + +MainWindow::~MainWindow() +{ + delete ui; +} + +void MainWindow::dragEnterEvent(QDragEnterEvent *event) +{ + if (event->mimeData()->hasFormat("text/uri-list")) + event->acceptProposedAction(); +} + +void MainWindow::dropEvent(QDropEvent *event) +{ + Q_FOREACH(QUrl url, event->mimeData()->urls()) { + QString filename = url.toLocalFile(); + if(!filename.isEmpty()) { + QTextStream(stderr) << QString("dropEvent(\"%1\")\n").arg(filename); + open(filename); + } + } + event->acceptProposedAction(); +} + +void MainWindow::updateViewerBBox() +{ + m_pScene->update_bbox(); + const Scene::Bbox bbox = m_pScene->bbox(); + const double xmin = bbox.xmin(); + const double ymin = bbox.ymin(); + const double zmin = bbox.zmin(); + const double xmax = bbox.xmax(); + const double ymax = bbox.ymax(); + const double zmax = bbox.zmax(); + qglviewer::Vec + vec_min(xmin, ymin, zmin), + vec_max(xmax, ymax, zmax); + m_pViewer->setSceneBoundingBox(vec_min,vec_max); + m_pViewer->camera()->showEntireScene(); +} + +void MainWindow::open(QString filename) +{ + QFileInfo fileinfo(filename); + if(fileinfo.isFile() && fileinfo.isReadable()) + { + int index = m_pScene->open(filename); + if(index >= 0) + { + QSettings settings; + settings.setValue("OFF open directory", + fileinfo.absoluteDir().absolutePath()); + this->addToRecentFiles(filename); + + // update bbox + updateViewerBBox(); + m_pViewer->update(); + } + } +} + +void MainWindow::readSettings() +{ + this->readState("MainWindow", Size|State); +} + +void MainWindow::writeSettings() +{ + this->writeState("MainWindow"); + std::cerr << "Write setting... done.\n"; +} + +void MainWindow::quit() +{ + writeSettings(); + close(); +} + +void MainWindow::closeEvent(QCloseEvent *event) +{ + writeSettings(); + event->accept(); +} + +void MainWindow::on_actionLoadPolyhedron_triggered() +{ + QSettings settings; + QString directory = settings.value("OFF open directory", + QDir::current().dirName()).toString(); + QStringList filenames = + QFileDialog::getOpenFileNames(this, + tr("Load polyhedron..."), + directory, + tr("OFF files (*.off)\n" + "All files (*)")); + if(!filenames.isEmpty()) { + Q_FOREACH(QString filename, filenames) { + open(filename); + } + } +} + + +void MainWindow::setAddKeyFrameKeyboardModifiers(::Qt::KeyboardModifiers m) +{ + m_pViewer->setAddKeyFrameKeyboardModifiers(m); +} + +void MainWindow::on_actionInside_points_triggered() +{ + bool ok; + const unsigned int nb_points = (unsigned) + QInputDialog::getInteger(NULL, "#Points", + "#Points:",10000,1,100000000,9,&ok); + if(!ok) + return; + + QApplication::setOverrideCursor(Qt::WaitCursor); + m_pScene->generate_inside_points(nb_points); + QApplication::restoreOverrideCursor(); + m_pViewer->update(); +} + +void MainWindow::on_actionPoints_in_interval_triggered() +{ + bool ok; + const unsigned int nb_points = (unsigned) + QInputDialog::getInteger(NULL, "#Points", + "#Points:",10000,1,100000000,9,&ok); + if(!ok) + return; + + const double min = + QInputDialog::getDouble(NULL, "min", + "Min:",-0.1,-1000.0,1000.0,9,&ok); + if(!ok) + return; + const double max = + QInputDialog::getDouble(NULL, "max", + "Max:",0.1,-1000.0,1000.0,9,&ok); + if(!ok) + return; + + QApplication::setOverrideCursor(Qt::WaitCursor); + m_pScene->generate_points_in(nb_points,min,max); + QApplication::restoreOverrideCursor(); + m_pViewer->update(); +} + +void MainWindow::on_actionBoundary_segments_triggered() +{ + bool ok; + const unsigned int nb_slices = (unsigned) + QInputDialog::getInteger(NULL, "#Slices", + "Slices:",100,1,1000000,8,&ok); + if(!ok) + return; + + QApplication::setOverrideCursor(Qt::WaitCursor); + m_pScene->generate_boundary_segments(nb_slices); + QApplication::restoreOverrideCursor(); + m_pViewer->update(); +} + +void MainWindow::on_actionBoundary_points_triggered() +{ + bool ok; + const unsigned int nb_points = (unsigned) + QInputDialog::getInteger(NULL, "#Points", + "Points:",1000,1,10000000,8,&ok); + if(!ok) + return; + + QApplication::setOverrideCursor(Qt::WaitCursor); + m_pScene->generate_boundary_points(nb_points); + QApplication::restoreOverrideCursor(); + m_pViewer->update(); +} + +void MainWindow::on_actionEdge_points_triggered() +{ + bool ok; + const unsigned int nb_points = (unsigned) + QInputDialog::getInteger(NULL, "#Points", + "Points:",1000,1,10000000,8,&ok); + if(!ok) + return; + + QApplication::setOverrideCursor(Qt::WaitCursor); + m_pScene->generate_edge_points(nb_points); + QApplication::restoreOverrideCursor(); + m_pViewer->update(); +} + +void MainWindow::on_actionBench_distances_triggered() +{ + bool ok; + const double duration = QInputDialog::getDouble(NULL, "Duration", + "Duration (s):",1.0,0.01,1000,8,&ok); + if(!ok) + return; + + QApplication::setOverrideCursor(Qt::WaitCursor); + std::cout << std::endl << "Benchmark distances" << std::endl; + m_pScene->benchmark_distances(duration); + QApplication::restoreOverrideCursor(); +} + +void MainWindow::on_actionBench_intersections_triggered() +{ + bool ok; + const double duration = QInputDialog::getDouble(NULL, "Duration", + "Duration (s):",1.0,0.01,1000.0,8,&ok); + if(!ok) + return; + + QApplication::setOverrideCursor(Qt::WaitCursor); + std::cout << std::endl << "Benchmark intersections" << std::endl; + m_pScene->benchmark_intersections(duration); + QApplication::restoreOverrideCursor(); +} + +void MainWindow::on_actionUnsigned_distance_function_to_facets_triggered() +{ + QApplication::setOverrideCursor(Qt::WaitCursor); m_pScene->activate_cutting_plane(); - m_pScene->unsigned_distance_function(); - QApplication::restoreOverrideCursor(); - m_pViewer->update(); -} - -void MainWindow::on_actionUnsigned_distance_function_to_edges_triggered() -{ - QApplication::setOverrideCursor(Qt::WaitCursor); + m_pScene->unsigned_distance_function(); + QApplication::restoreOverrideCursor(); + m_pViewer->update(); +} + +void MainWindow::on_actionUnsigned_distance_function_to_edges_triggered() +{ + QApplication::setOverrideCursor(Qt::WaitCursor); m_pScene->activate_cutting_plane(); - m_pScene->unsigned_distance_function_to_edges(); - QApplication::restoreOverrideCursor(); - m_pViewer->update(); -} - -void MainWindow::on_actionSigned_distance_function_to_facets_triggered() -{ - QApplication::setOverrideCursor(Qt::WaitCursor); + m_pScene->unsigned_distance_function_to_edges(); + QApplication::restoreOverrideCursor(); + m_pViewer->update(); +} + +void MainWindow::on_actionSigned_distance_function_to_facets_triggered() +{ + QApplication::setOverrideCursor(Qt::WaitCursor); m_pScene->activate_cutting_plane(); - m_pScene->signed_distance_function(); - QApplication::restoreOverrideCursor(); - m_pViewer->update(); -} - + m_pScene->signed_distance_function(); + QApplication::restoreOverrideCursor(); + m_pViewer->update(); +} + void MainWindow::on_actionIntersection_cutting_plane_triggered() -{ - QApplication::setOverrideCursor(Qt::WaitCursor); - m_pScene->activate_cutting_plane(); +{ + QApplication::setOverrideCursor(Qt::WaitCursor); + m_pScene->activate_cutting_plane(); m_pScene->cut_segment_plane(); - QApplication::restoreOverrideCursor(); - m_pViewer->update(); -} - + QApplication::restoreOverrideCursor(); + m_pViewer->update(); +} + void MainWindow::on_actionCutting_plane_none_triggered() { m_pScene->clear_cutting_plane(); m_pViewer->update(); } -void MainWindow::on_actionView_polyhedron_triggered() -{ - m_pScene->toggle_view_poyhedron(); - m_pViewer->update(); -} - -void MainWindow::on_actionView_points_triggered() -{ - m_pScene->toggle_view_points(); - m_pViewer->update(); -} - -void MainWindow::on_actionView_segments_triggered() -{ - m_pScene->toggle_view_segments(); - m_pViewer->update(); -} - -void MainWindow::on_actionView_cutting_plane_triggered() -{ - m_pScene->toggle_view_plane(); - m_pViewer->update(); -} - -void MainWindow::on_actionClear_points_triggered() -{ - m_pScene->clear_points(); - m_pViewer->update(); -} - -void MainWindow::on_actionClear_segments_triggered() -{ - m_pScene->clear_segments(); - m_pViewer->update(); -} - -void MainWindow::on_actionClear_cutting_plane_triggered() -{ - m_pScene->clear_cutting_plane(); - m_pViewer->update(); -} - -void MainWindow::on_actionRefine_bisection_triggered() -{ - bool ok; - const double max_len = - QInputDialog::getDouble(NULL, "Max edge len", - "Max edge len:",0.1,0.001,100.0,9,&ok); - if(!ok) - return; - - QApplication::setOverrideCursor(Qt::WaitCursor); - m_pScene->refine_bisection(max_len * max_len); - QApplication::restoreOverrideCursor(); - m_pViewer->update(); -} - -void MainWindow::on_actionBench_memory_triggered() -{ - QApplication::setOverrideCursor(Qt::WaitCursor); - m_pScene->bench_memory(); - QApplication::restoreOverrideCursor(); -} - -void MainWindow::on_actionBench_construction_triggered() -{ - QApplication::setOverrideCursor(Qt::WaitCursor); - m_pScene->bench_construction(); - QApplication::restoreOverrideCursor(); -} - -void MainWindow::on_actionBench_intersections_vs_nbt_triggered() -{ - QApplication::setOverrideCursor(Qt::WaitCursor); - m_pScene->bench_intersections_vs_nbt(); - QApplication::restoreOverrideCursor(); -} - -void MainWindow::on_actionBench_distances_vs_nbt_triggered() -{ - QApplication::setOverrideCursor(Qt::WaitCursor); - m_pScene->bench_distances_vs_nbt(); - 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); - m_pViewer->saveSnapshot(QString("snapshot.png")); - QApplication::restoreOverrideCursor(); -} -void MainWindow::on_actionCopy_snapshot_triggered() -{ - // copy snapshot to clipboard - QApplication::setOverrideCursor(Qt::WaitCursor); - QClipboard *qb = QApplication::clipboard(); - m_pViewer->makeCurrent(); - m_pViewer->raise(); - QImage snapshot = m_pViewer->grabFrameBuffer(true); - qb->setImage(snapshot); - QApplication::restoreOverrideCursor(); -} - - - - +void MainWindow::on_actionView_polyhedron_triggered() +{ + m_pScene->toggle_view_poyhedron(); + m_pViewer->update(); +} + +void MainWindow::on_actionView_points_triggered() +{ + m_pScene->toggle_view_points(); + m_pViewer->update(); +} + +void MainWindow::on_actionView_segments_triggered() +{ + m_pScene->toggle_view_segments(); + m_pViewer->update(); +} + +void MainWindow::on_actionView_cutting_plane_triggered() +{ + m_pScene->toggle_view_plane(); + m_pViewer->update(); +} + +void MainWindow::on_actionClear_points_triggered() +{ + m_pScene->clear_points(); + m_pViewer->update(); +} + +void MainWindow::on_actionClear_segments_triggered() +{ + m_pScene->clear_segments(); + m_pViewer->update(); +} + +void MainWindow::on_actionClear_cutting_plane_triggered() +{ + m_pScene->clear_cutting_plane(); + m_pViewer->update(); +} + +void MainWindow::on_actionRefine_bisection_triggered() +{ + bool ok; + const double max_len = + QInputDialog::getDouble(NULL, "Max edge len", + "Max edge len:",0.1,0.001,100.0,9,&ok); + if(!ok) + return; + + QApplication::setOverrideCursor(Qt::WaitCursor); + m_pScene->refine_bisection(max_len * max_len); + QApplication::restoreOverrideCursor(); + m_pViewer->update(); +} + +void MainWindow::on_actionBench_memory_triggered() +{ + QApplication::setOverrideCursor(Qt::WaitCursor); + m_pScene->bench_memory(); + QApplication::restoreOverrideCursor(); +} + +void MainWindow::on_actionBench_construction_triggered() +{ + QApplication::setOverrideCursor(Qt::WaitCursor); + m_pScene->bench_construction(); + QApplication::restoreOverrideCursor(); +} + +void MainWindow::on_actionBench_intersections_vs_nbt_triggered() +{ + QApplication::setOverrideCursor(Qt::WaitCursor); + m_pScene->bench_intersections_vs_nbt(); + QApplication::restoreOverrideCursor(); +} + +void MainWindow::on_actionBench_distances_vs_nbt_triggered() +{ + QApplication::setOverrideCursor(Qt::WaitCursor); + m_pScene->bench_distances_vs_nbt(); + 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); + m_pViewer->saveSnapshot(QString("snapshot.png")); + QApplication::restoreOverrideCursor(); +} +void MainWindow::on_actionCopy_snapshot_triggered() +{ + // copy snapshot to clipboard + QApplication::setOverrideCursor(Qt::WaitCursor); + QClipboard *qb = QApplication::clipboard(); + 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/Scene.cpp b/AABB_tree/demo/AABB_tree/Scene.cpp index f11926dd57d..128b74b1c61 100644 --- a/AABB_tree/demo/AABB_tree/Scene.cpp +++ b/AABB_tree/demo/AABB_tree/Scene.cpp @@ -1,134 +1,134 @@ -#include "Scene.h" - -#include -#include - -#include -#include -#include -#include -#include - -#include "Refiner.h" -#include "render_edges.h" - -#include -#include -#include - +#include "Scene.h" + +#include +#include + +#include +#include +#include +#include +#include + +#include "Refiner.h" +#include "render_edges.h" + +#include +#include +#include + // constants const double slow_distance_grid_size = 100; const double fast_distance_grid_size = 20; -Scene::Scene() - : m_frame (new ManipulatedFrame()) - , m_view_plane(false) +Scene::Scene() + : m_frame (new ManipulatedFrame()) + , m_view_plane(false) , m_grid_size(slow_distance_grid_size) , m_cut_plane(NONE) -{ - m_pPolyhedron = NULL; - - // view options - m_view_points = true; - m_view_segments = true; - m_view_polyhedron = true; - - // distance function - m_red_ramp.build_red(); - m_blue_ramp.build_blue(); - m_max_distance_function = (FT)0.0; -} - -Scene::~Scene() -{ - delete m_pPolyhedron; - delete m_frame; -} - -int Scene::open(QString filename) -{ - QTextStream cerr(stderr); - cerr << QString("Opening file \"%1\"\n").arg(filename); - QApplication::setOverrideCursor(QCursor(::Qt::WaitCursor)); - - 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(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(); - - delete m_pPolyhedron; - m_pPolyhedron = NULL; - - return -1; - } - - // clear tree - clear_internal_data(); - - QApplication::restoreOverrideCursor(); - return 0; -} - -void Scene::update_bbox() -{ - std::cout << "Compute bbox..."; - m_bbox = Bbox(); - - if(m_pPolyhedron == NULL) - { - std::cout << "failed (no 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; -} - -void Scene::draw() -{ - if(m_view_plane) - ::glEnable(GL_DEPTH_TEST); - else - ::glDisable(GL_DEPTH_TEST); - - if(m_view_polyhedron) - draw_polyhedron(); - - if(m_view_points) - draw_points(); - - if(m_view_segments) - draw_segments(); - +{ + m_pPolyhedron = NULL; + + // view options + m_view_points = true; + m_view_segments = true; + m_view_polyhedron = true; + + // distance function + m_red_ramp.build_red(); + m_blue_ramp.build_blue(); + m_max_distance_function = (FT)0.0; +} + +Scene::~Scene() +{ + delete m_pPolyhedron; + delete m_frame; +} + +int Scene::open(QString filename) +{ + QTextStream cerr(stderr); + cerr << QString("Opening file \"%1\"\n").arg(filename); + QApplication::setOverrideCursor(QCursor(::Qt::WaitCursor)); + + 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(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(); + + delete m_pPolyhedron; + m_pPolyhedron = NULL; + + return -1; + } + + // clear tree + clear_internal_data(); + + QApplication::restoreOverrideCursor(); + return 0; +} + +void Scene::update_bbox() +{ + std::cout << "Compute bbox..."; + m_bbox = Bbox(); + + if(m_pPolyhedron == NULL) + { + std::cout << "failed (no 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; +} + +void Scene::draw() +{ + if(m_view_plane) + ::glEnable(GL_DEPTH_TEST); + else + ::glDisable(GL_DEPTH_TEST); + + if(m_view_polyhedron) + draw_polyhedron(); + + if(m_view_points) + draw_points(); + + if(m_view_segments) + draw_segments(); + if (m_view_plane) - { + { switch( m_cut_plane ) { case UNSIGNED_EDGES: @@ -144,75 +144,75 @@ void Scene::draw() case NONE: // do nothing break; } - } -} - -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); - } -} - -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(); - } -} - -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(); - } -} - + } +} + +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); + } +} + +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(); + } +} + +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(); + } +} + void Scene::draw_distance_function(const Color_ramp& ramp_pos, const Color_ramp& ramp_neg) const -{ - ::glDisable(GL_LIGHTING); +{ + ::glDisable(GL_LIGHTING); if ( m_fast_distance ) { ::glShadeModel(GL_FLAT); } else { ::glShadeModel(GL_SMOOTH); } - ::glBegin(GL_QUADS); - int i,j; + ::glBegin(GL_QUADS); + int i,j; const int nb_quads = m_grid_size-1; - for(i=0;i 0.0) + // assembles one quad + if(d00 > 0.0) ::glColor3ub(ramp_pos.r(i00),ramp_pos.g(i00),ramp_pos.b(i00)); - else + else ::glColor3ub(ramp_neg.r(i00),ramp_neg.g(i00),ramp_neg.b(i00)); - ::glVertex3d(p00.x(),p00.y(),p00.z()); + ::glVertex3d(p00.x(),p00.y(),p00.z()); - if(d01 > 0.0) + if(d01 > 0.0) ::glColor3ub(ramp_pos.r(i01),ramp_pos.g(i01),ramp_pos.b(i01)); - else + else ::glColor3ub(ramp_neg.r(i01),ramp_neg.g(i01),ramp_neg.b(i01)); - ::glVertex3d(p01.x(),p01.y(),p01.z()); + ::glVertex3d(p01.x(),p01.y(),p01.z()); - if(d11 > 0) + if(d11 > 0) ::glColor3ub(ramp_pos.r(i11),ramp_pos.g(i11),ramp_pos.b(i11)); - else + else ::glColor3ub(ramp_neg.r(i11),ramp_neg.g(i11),ramp_neg.b(i11)); - ::glVertex3d(p11.x(),p11.y(),p11.z()); + ::glVertex3d(p11.x(),p11.y(),p11.z()); - if(d10 > 0) + if(d10 > 0) ::glColor3ub(ramp_pos.r(i10),ramp_pos.g(i10),ramp_pos.b(i10)); - else + else ::glColor3ub(ramp_neg.r(i10),ramp_neg.g(i10),ramp_neg.b(i10)); - ::glVertex3d(p10.x(),p10.y(),p10.z()); - } - } - ::glEnd(); -} - + ::glVertex3d(p10.x(),p10.y(),p10.z()); + } + } + ::glEnd(); +} + void Scene::draw_cut_segment_plane() const -{ +{ float diag = .6f * float(bbox_diag()); - - ::glDisable(GL_LIGHTING); - ::glLineWidth(1.0f); - ::glColor3f(.6f, .6f, .6f); - - // draw grid - ::glPushMatrix(); - ::glMultMatrixd(m_frame->matrix()); - QGLViewer::drawGrid(diag); - ::glPopMatrix(); - - // draw cut segments - ::glLineWidth(2.0f); - ::glColor3f(1.f, 0.f, 0.f); - ::glBegin(GL_LINES); + + ::glDisable(GL_LIGHTING); + ::glLineWidth(1.0f); + ::glColor3f(.6f, .6f, .6f); + + // draw grid + ::glPushMatrix(); + ::glMultMatrixd(m_frame->matrix()); + QGLViewer::drawGrid(diag); + ::glPopMatrix(); + + // draw cut segments + ::glLineWidth(2.0f); + ::glColor3f(1.f, 0.f, 0.f); + ::glBegin(GL_LINES); for ( std::vector::const_iterator it = m_cut_segments.begin(), - end = m_cut_segments.end() ; it != end ; ++it ) - { - const Point& a = it->source(); - const Point& b = it->target(); - - ::glVertex3d(a.x(), a.y(), a.z()); - ::glVertex3d(b.x(), b.y(), b.z()); - } - ::glEnd(); - - // fill grid with transparent blue - ::glPushMatrix(); - ::glMultMatrixd(m_frame->matrix()); - ::glColor4f(.6f, .85f, 1.f, .65f); - - ::glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); - ::glEnable(GL_BLEND); - ::glBegin(GL_QUADS); - ::glVertex3d(-diag, -diag, 0.); - ::glVertex3d(-diag, diag, 0.); - ::glVertex3d( diag, diag, 0.); - ::glVertex3d( diag, -diag, 0.); - ::glEnd(); - ::glDisable(GL_BLEND); - - ::glPopMatrix(); -} - -FT Scene::random_in(const double a, - const double b) -{ - double r = rand() / (double)RAND_MAX; - return (FT)(a + (b - a) * r); -} - -Point Scene::random_point(const CGAL::Bbox_3& bbox) -{ - FT x = random_in(bbox.xmin(),bbox.xmax()); - FT y = random_in(bbox.ymin(),bbox.ymax()); - FT z = random_in(bbox.zmin(),bbox.zmax()); - return Point(x,y,z); -} - -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); -} - -Ray Scene::random_ray(const CGAL::Bbox_3& bbox) -{ - 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); -} - -Line Scene::random_line(const CGAL::Bbox_3& bbox) -{ - 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); -} - -Plane Scene::frame_plane() const -{ - const qglviewer::Vec& pos = m_frame->position(); - const qglviewer::Vec& n = m_frame->inverseTransformOf(qglviewer::Vec(0.f, 0.f, 1.f)); - - return Plane(n[0], n[1], n[2], - n * pos); -} - + end = m_cut_segments.end() ; it != end ; ++it ) + { + const Point& a = it->source(); + const Point& b = it->target(); + + ::glVertex3d(a.x(), a.y(), a.z()); + ::glVertex3d(b.x(), b.y(), b.z()); + } + ::glEnd(); + + // fill grid with transparent blue + ::glPushMatrix(); + ::glMultMatrixd(m_frame->matrix()); + ::glColor4f(.6f, .85f, 1.f, .65f); + + ::glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + ::glEnable(GL_BLEND); + ::glBegin(GL_QUADS); + ::glVertex3d(-diag, -diag, 0.); + ::glVertex3d(-diag, diag, 0.); + ::glVertex3d( diag, diag, 0.); + ::glVertex3d( diag, -diag, 0.); + ::glEnd(); + ::glDisable(GL_BLEND); + + ::glPopMatrix(); +} + +FT Scene::random_in(const double a, + const double b) +{ + double r = rand() / (double)RAND_MAX; + return (FT)(a + (b - a) * r); +} + +Point Scene::random_point(const CGAL::Bbox_3& bbox) +{ + FT x = random_in(bbox.xmin(),bbox.xmax()); + FT y = random_in(bbox.ymin(),bbox.ymax()); + FT z = random_in(bbox.zmin(),bbox.zmax()); + return Point(x,y,z); +} + +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); +} + +Ray Scene::random_ray(const CGAL::Bbox_3& bbox) +{ + 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); +} + +Line Scene::random_line(const CGAL::Bbox_3& bbox) +{ + 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); +} + +Plane Scene::frame_plane() const +{ + const qglviewer::Vec& pos = m_frame->position(); + const qglviewer::Vec& n = m_frame->inverseTransformOf(qglviewer::Vec(0.f, 0.f, 1.f)); + + return Plane(n[0], n[1], n[2], - n * pos); +} + Aff_transformation Scene::frame_transformation() const { const ::GLdouble* m = m_frame->matrix(); @@ -386,26 +386,26 @@ FT Scene::bbox_diag() const return FT(std::sqrt(dx*dx + dy*dy + dz*dz)); } -void Scene::build_facet_tree() -{ - if ( NULL == m_pPolyhedron ) - { - std::cerr << "Build facet tree failed: load polyhedron first." << std::endl; - return; - } +void Scene::build_facet_tree() +{ + if ( NULL == m_pPolyhedron ) + { + std::cerr << "Build facet tree failed: load polyhedron first." << std::endl; + return; + } // Don't rebuild tree if it is already built if ( !m_facet_tree.empty() ) { return; } - - // build tree - CGAL::Timer timer; - timer.start(); + + // build tree + CGAL::Timer timer; + timer.start(); std::cout << "Construct Facet AABB tree..."; - m_facet_tree.rebuild(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end()); + m_facet_tree.rebuild(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end()); m_facet_tree.accelerate_distance_queries(); - std::cout << "done (" << timer.time() << " s)" << std::endl; -} - + std::cout << "done (" << timer.time() << " s)" << std::endl; +} + void Scene::build_edge_tree() { if ( NULL == m_pPolyhedron ) @@ -426,276 +426,276 @@ void Scene::build_edge_tree() std::cout << "done (" << timer.time() << " s)" << std::endl; } -void Scene::clear_internal_data() -{ - m_facet_tree.clear(); +void Scene::clear_internal_data() +{ + m_facet_tree.clear(); m_edge_tree.clear(); - - clear_points(); - clear_segments(); - clear_cutting_plane(); -} - -void Scene::clear_cutting_plane() -{ - m_cut_segments.clear(); + + clear_points(); + clear_segments(); + clear_cutting_plane(); +} + +void Scene::clear_cutting_plane() +{ + m_cut_segments.clear(); m_cut_plane = NONE; - deactivate_cutting_plane(); -} - + deactivate_cutting_plane(); +} + void Scene::update_grid_size() { m_grid_size = m_fast_distance ? fast_distance_grid_size : slow_distance_grid_size; } -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_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; - - 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; -} - - -void Scene::generate_inside_points(const unsigned int nb_points) -{ - if(m_pPolyhedron == NULL) - { - std::cout << "Load polyhedron first." << std::endl; - return; - } - - 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; - - 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; -} - -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_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; - - 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 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; -} - -void Scene::generate_boundary_points(const unsigned int nb_points) -{ - if(m_pPolyhedron == NULL) - { - std::cout << "Load polyhedron first." << std::endl; - return; - } - - 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; - - 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()); - - 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; -} - -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_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; - - 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 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; -} - +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_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; + + 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; +} + + +void Scene::generate_inside_points(const unsigned int nb_points) +{ + if(m_pPolyhedron == NULL) + { + std::cout << "Load polyhedron first." << std::endl; + return; + } + + 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; + + 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; +} + +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_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; + + 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 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; +} + +void Scene::generate_boundary_points(const unsigned int nb_points) +{ + if(m_pPolyhedron == NULL) + { + std::cout << "Load polyhedron first." << std::endl; + return; + } + + 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; + + 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()); + + 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; +} + +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_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; + + 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 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; +} + template void Scene::compute_distance_function(const Tree& tree) -{ +{ // Get transformation Aff_transformation t = frame_transformation(); @@ -707,7 +707,7 @@ void Scene::compute_distance_function(const Tree& tree) const FT z (0); for(int i=0 ; i void Scene::sign_distance_function(const Tree& tree) { Vector random_vec = random_vector(); for(int i=0 ; i Intersections; Intersections intersections; - m_facet_tree.all_intersections(plane, std::back_inserter(intersections)); + m_facet_tree.all_intersections(plane, std::back_inserter(intersections)); - // Fill data structure - m_cut_segments.clear(); + // Fill data structure + m_cut_segments.clear(); for ( Intersections::iterator it = intersections.begin(), - end = intersections.end() ; it != end ; ++it ) - { - const Segment* inter_seg = CGAL::object_cast(&(it->first)); - - if ( NULL != inter_seg ) - { - m_cut_segments.push_back(*inter_seg); - } - } + end = intersections.end() ; it != end ; ++it ) + { + const Segment* inter_seg = CGAL::object_cast(&(it->first)); + + if ( NULL != inter_seg ) + { + m_cut_segments.push_back(*inter_seg); + } + } m_cut_plane = CUT_SEGMENTS; -} - +} + void Scene::cutting_plane() { switch( m_cut_plane ) @@ -833,64 +833,64 @@ void Scene::cutting_plane() CGAL_assertion(false); } -void Scene::toggle_view_poyhedron() -{ - m_view_polyhedron = !m_view_polyhedron; -} - -void Scene::toggle_view_segments() -{ - m_view_segments = !m_view_segments; -} - -void Scene::toggle_view_points() -{ - m_view_points = !m_view_points; -} - -void Scene::toggle_view_plane() -{ - m_view_plane = !m_view_plane; -} - -void Scene::refine_bisection(const FT max_sqlen) -{ - if(m_pPolyhedron == NULL) - { - std::cout << "Load polyhedron first." << std::endl; - return; - } - 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; - - clear_internal_data(); -} - -void Scene::refine_loop() -{ - if(m_pPolyhedron == NULL) - { - std::cout << "Load polyhedron first." << std::endl; - return; - } - std::cout << "Loop subdivision..."; - CGAL::Subdivision_method_3::Loop_subdivision(*m_pPolyhedron, 1); - std::cout << "done (" << m_pPolyhedron->size_of_facets() << " facets)" << std::endl; - - clear_internal_data(); -} - - -void Scene::activate_cutting_plane() -{ - connect(m_frame, SIGNAL(modified()), this, SLOT(cutting_plane())); - m_view_plane = true; -} - -void Scene::deactivate_cutting_plane() -{ - disconnect(m_frame, SIGNAL(modified()), this, SLOT(cutting_plane())); - m_view_plane = false; -} +void Scene::toggle_view_poyhedron() +{ + m_view_polyhedron = !m_view_polyhedron; +} + +void Scene::toggle_view_segments() +{ + m_view_segments = !m_view_segments; +} + +void Scene::toggle_view_points() +{ + m_view_points = !m_view_points; +} + +void Scene::toggle_view_plane() +{ + m_view_plane = !m_view_plane; +} + +void Scene::refine_bisection(const FT max_sqlen) +{ + if(m_pPolyhedron == NULL) + { + std::cout << "Load polyhedron first." << std::endl; + return; + } + 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; + + clear_internal_data(); +} + +void Scene::refine_loop() +{ + if(m_pPolyhedron == NULL) + { + std::cout << "Load polyhedron first." << std::endl; + return; + } + std::cout << "Loop subdivision..."; + CGAL::Subdivision_method_3::Loop_subdivision(*m_pPolyhedron, 1); + std::cout << "done (" << m_pPolyhedron->size_of_facets() << " facets)" << std::endl; + + clear_internal_data(); +} + + +void Scene::activate_cutting_plane() +{ + connect(m_frame, SIGNAL(modified()), this, SLOT(cutting_plane())); + m_view_plane = true; +} + +void Scene::deactivate_cutting_plane() +{ + disconnect(m_frame, SIGNAL(modified()), this, SLOT(cutting_plane())); + m_view_plane = false; +} diff --git a/AABB_tree/demo/AABB_tree/Scene.h b/AABB_tree/demo/AABB_tree/Scene.h index acc710ce56b..8bdbeb2a6b8 100644 --- a/AABB_tree/demo/AABB_tree/Scene.h +++ b/AABB_tree/demo/AABB_tree/Scene.h @@ -1,97 +1,97 @@ -#ifndef SCENE_H -#define SCENE_H - -#include -#include -#include - -#include -#include "types.h" -#include "Color_ramp.h" - -#include -#include -#include -#include - -#include -#include -#include - -class Scene : public QObject -{ - Q_OBJECT -public: - Scene(); - virtual ~Scene(); -public: - // types - typedef CGAL::Bbox_3 Bbox; +#ifndef SCENE_H +#define SCENE_H + +#include +#include +#include + +#include +#include "types.h" +#include "Color_ramp.h" + +#include +#include +#include +#include + +#include +#include +#include + +class Scene : public QObject +{ + Q_OBJECT +public: + Scene(); + virtual ~Scene(); +public: + // types + typedef CGAL::Bbox_3 Bbox; private: typedef CGAL::AABB_polyhedron_triangle_primitive Facet_Primitive; typedef CGAL::AABB_traits Facet_Traits; typedef CGAL::AABB_tree Facet_tree; - + typedef CGAL::AABB_polyhedron_segment_primitive Edge_Primitive; typedef CGAL::AABB_traits Edge_Traits; typedef CGAL::AABB_tree Edge_tree; - typedef qglviewer::ManipulatedFrame ManipulatedFrame; + typedef qglviewer::ManipulatedFrame ManipulatedFrame; enum Cut_planes_types { NONE, UNSIGNED_FACETS, SIGNED_FACETS, UNSIGNED_EDGES, CUT_SEGMENTS }; - -public: - void draw(); - void update_bbox(); - Bbox bbox() { return m_bbox; } - ManipulatedFrame* manipulatedFrame() const { return m_frame; } - -private: - // member data - Bbox m_bbox; - Polyhedron *m_pPolyhedron; - std::list m_points; - std::list m_segments; - std::vector m_cut_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; - typedef std::pair Point_distance; - Point_distance m_distance_function[100][100]; - - // frame - ManipulatedFrame* m_frame; - bool m_view_plane; + +public: + void draw(); + void update_bbox(); + Bbox bbox() { return m_bbox; } + ManipulatedFrame* manipulatedFrame() const { return m_frame; } + +private: + // member data + Bbox m_bbox; + Polyhedron *m_pPolyhedron; + std::list m_points; + std::list m_segments; + std::vector m_cut_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; + typedef std::pair Point_distance; + Point_distance m_distance_function[100][100]; + + // frame + ManipulatedFrame* m_frame; + bool m_view_plane; int m_grid_size; bool m_fast_distance; - + // An aabb_tree indexing polyhedron facets/segments - Facet_tree m_facet_tree; + Facet_tree m_facet_tree; Edge_tree m_edge_tree; Cut_planes_types m_cut_plane; - -private: - // 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); - Plane frame_plane() const; + +private: + // 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); + Plane frame_plane() const; Aff_transformation frame_transformation() const; FT bbox_diag() const; - void build_facet_tree(); + void build_facet_tree(); void build_edge_tree(); - void clear_internal_data(); + void clear_internal_data(); void update_grid_size(); template @@ -99,96 +99,96 @@ private: template void sign_distance_function(const Tree& tree); - -public: - // file menu - int open(QString filename); - - // edit menu - void clear_points() { m_points.clear(); } - void clear_segments() { m_segments.clear(); } - void clear_cutting_plane(); + +public: + // file menu + int open(QString filename); + + // edit menu + void clear_points() { m_points.clear(); } + void clear_segments() { m_segments.clear(); } + void clear_cutting_plane(); // fast distance setter void set_fast_distance(bool b) { m_fast_distance = b; update_grid_size(); } - - // 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); - - // algorithms/refine - void refine_loop(); - void refine_bisection(const FT max_sqlen); - - // distance functions - void signed_distance_function(); - void unsigned_distance_function(); - void unsigned_distance_function_to_edges(); + + // 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); + + // algorithms/refine + void refine_loop(); + void refine_bisection(const FT max_sqlen); + + // distance functions + void signed_distance_function(); + void unsigned_distance_function(); + void unsigned_distance_function_to_edges(); void cut_segment_plane(); - - // toggle view options - void toggle_view_points(); - void toggle_view_segments(); - void toggle_view_poyhedron(); - void toggle_view_plane(); - - // view options - bool m_view_points; - bool m_view_segments; - bool m_view_polyhedron; - - // 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); - - template - void bench_intersection(Facet_tree& tree,const int function,const double duration, - const char *query_name, const std::vector& queries, const int nb_queries); - void bench_intersections(Facet_tree& tree, const double duration, const int function, - const char *function_name, const std::vector& rays, - const std::vector& lines, const std::vector& planes, - const std::vector& segments, const int nb_queries); - - // 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(); + + // toggle view options + void toggle_view_points(); + void toggle_view_segments(); + void toggle_view_poyhedron(); + void toggle_view_plane(); + + // view options + bool m_view_points; + bool m_view_segments; + bool m_view_polyhedron; + + // 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); + + template + void bench_intersection(Facet_tree& tree,const int function,const double duration, + const char *query_name, const std::vector& queries, const int nb_queries); + void bench_intersections(Facet_tree& tree, const double duration, const int function, + const char *function_name, const std::vector& rays, + const std::vector& lines, const std::vector& planes, + const std::vector& segments, const int nb_queries); + + // 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_distance_function(const Color_ramp& ramp_pos, const Color_ramp& ramp_neg) const; void draw_cut_segment_plane() const; - - // cutting plane activation/deactivation - void activate_cutting_plane(); - void deactivate_cutting_plane(); - -public slots: - // cutting plane - void cutting_plane(); - -}; // end class Scene - -#endif // SCENE_H + + // cutting plane activation/deactivation + void activate_cutting_plane(); + void deactivate_cutting_plane(); + +public slots: + // cutting plane + void cutting_plane(); + +}; // end class Scene + +#endif // SCENE_H diff --git a/AABB_tree/demo/AABB_tree/types.h b/AABB_tree/demo/AABB_tree/types.h index 36ec222775f..8604472e202 100644 --- a/AABB_tree/demo/AABB_tree/types.h +++ b/AABB_tree/demo/AABB_tree/types.h @@ -1,21 +1,21 @@ -#ifndef AABB_DEMO_TYPES_H -#define AABB_DEMO_TYPES_H - -#include - -typedef CGAL::Simple_cartesian Kernel; // fastest in experiments - -typedef Kernel::FT FT; -typedef Kernel::Ray_3 Ray; -typedef Kernel::Line_3 Line; -typedef Kernel::Point_3 Point; -typedef Kernel::Plane_3 Plane; -typedef Kernel::Vector_3 Vector; -typedef Kernel::Segment_3 Segment; -typedef Kernel::Triangle_3 Triangle; -typedef Kernel::Aff_transformation_3 Aff_transformation; - -#include -typedef CGAL::Polyhedron_3 Polyhedron; - -#endif // AABB_DEMO_TYPES_H +#ifndef AABB_DEMO_TYPES_H +#define AABB_DEMO_TYPES_H + +#include + +typedef CGAL::Simple_cartesian Kernel; // fastest in experiments + +typedef Kernel::FT FT; +typedef Kernel::Ray_3 Ray; +typedef Kernel::Line_3 Line; +typedef Kernel::Point_3 Point; +typedef Kernel::Plane_3 Plane; +typedef Kernel::Vector_3 Vector; +typedef Kernel::Segment_3 Segment; +typedef Kernel::Triangle_3 Triangle; +typedef Kernel::Aff_transformation_3 Aff_transformation; + +#include +typedef CGAL::Polyhedron_3 Polyhedron; + +#endif // AABB_DEMO_TYPES_H