mirror of https://github.com/CGAL/cgal
AABB tree demo: better file structuring and cleanup.
This commit is contained in:
parent
1b51eb0384
commit
514f1e8973
|
|
@ -15,7 +15,7 @@
|
|||
// $Id: $
|
||||
//
|
||||
//
|
||||
// Author(s) : Pierre Alliez
|
||||
// Author(s) : Pierre Alliez, Camille Wormser
|
||||
//
|
||||
//******************************************************************************
|
||||
// File Description : demo of AABB tree on polyhedral edge and facet primitives
|
||||
|
|
@ -50,14 +50,14 @@ int main(int argc, char **argv)
|
|||
args.removeAt(0);
|
||||
}
|
||||
|
||||
Q_FOREACH(QString filename, args) {
|
||||
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"
|
||||
|
|
|
|||
|
|
@ -55,8 +55,7 @@ if(CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND)
|
|||
qt4_add_resources ( RESOURCE_FILES AABB_demo.qrc )
|
||||
|
||||
add_file_dependencies( AABB_demo.cpp "${CMAKE_CURRENT_BINARY_DIR}/MainWindow_moc.cpp"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/Scene_moc.cpp"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/Viewer_moc.cpp" )
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/Viewer_moc.cpp" )
|
||||
add_executable ( AABB_demo AABB_demo.cpp ${UI_FILES} ${RESOURCE_FILES} )
|
||||
|
||||
# Link with Qt libraries
|
||||
|
|
|
|||
|
|
@ -250,6 +250,11 @@ void MainWindow::on_actionView_segments_triggered()
|
|||
m_pScene->toggle_view_segments();
|
||||
}
|
||||
|
||||
void MainWindow::on_actionView_distance_function_triggered()
|
||||
{
|
||||
m_pScene->toggle_view_distance_function();
|
||||
}
|
||||
|
||||
void MainWindow::on_actionClear_points_triggered()
|
||||
{
|
||||
m_pScene->clear_points();
|
||||
|
|
@ -259,3 +264,8 @@ void MainWindow::on_actionClear_segments_triggered()
|
|||
{
|
||||
m_pScene->clear_segments();
|
||||
}
|
||||
|
||||
void MainWindow::on_actionClear_distance_function_triggered()
|
||||
{
|
||||
m_pScene->clear_distance_function();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ public:
|
|||
public slots:
|
||||
void updateViewerBBox();
|
||||
void open(QString filename);
|
||||
|
||||
void setAddKeyFrameKeyboardModifiers(Qt::KeyboardModifiers);
|
||||
|
||||
protected slots:
|
||||
|
|
@ -34,41 +33,39 @@ public:
|
|||
void readSettings();
|
||||
void writeSettings();
|
||||
|
||||
// load
|
||||
// drag & drop
|
||||
void dropEvent(QDropEvent *event);
|
||||
void closeEvent(QCloseEvent *event);
|
||||
void dragEnterEvent(QDragEnterEvent *event);
|
||||
|
||||
// file menu
|
||||
void on_actionLoadPolyhedron_triggered();
|
||||
|
||||
// view options
|
||||
void on_actionView_polyhedron_triggered();
|
||||
void on_actionView_points_triggered();
|
||||
void on_actionView_segments_triggered();
|
||||
// edit menu
|
||||
void on_actionClear_points_triggered();
|
||||
void on_actionClear_segments_triggered();
|
||||
void on_actionClear_distance_function_triggered();
|
||||
|
||||
// algorithms
|
||||
// algorithm menu
|
||||
void on_actionEdge_points_triggered();
|
||||
void on_actionInside_points_triggered();
|
||||
void on_actionBoundary_points_triggered();
|
||||
void on_actionBoundary_segments_triggered();
|
||||
void on_actionEdge_points_triggered();
|
||||
|
||||
// distance functions
|
||||
void on_actionSigned_distance_function_to_facets_triggered();
|
||||
void on_actionUnsigned_distance_function_to_edges_triggered();
|
||||
void on_actionUnsigned_distance_function_to_facets_triggered();
|
||||
|
||||
// benchmarks
|
||||
// benchmark menu
|
||||
void on_actionBench_distances_triggered();
|
||||
void on_actionBench_intersections_triggered();
|
||||
|
||||
// edit
|
||||
void on_actionClear_points_triggered();
|
||||
void on_actionClear_segments_triggered();
|
||||
|
||||
// drag & drop
|
||||
void dragEnterEvent(QDragEnterEvent *event);
|
||||
void dropEvent(QDropEvent *event);
|
||||
void closeEvent(QCloseEvent *event);
|
||||
// view menu
|
||||
void on_actionView_points_triggered();
|
||||
void on_actionView_segments_triggered();
|
||||
void on_actionView_polyhedron_triggered();
|
||||
void on_actionView_distance_function_triggered();
|
||||
|
||||
private:
|
||||
QString strippedName(const QString &fullFileName);
|
||||
|
||||
Scene* m_pScene;
|
||||
Viewer* m_pViewer;
|
||||
Ui::MainWindow* ui;
|
||||
|
|
|
|||
|
|
@ -16,6 +16,9 @@
|
|||
<iconset resource="AABB_demo.qrc" >
|
||||
<normaloff>:/cgal/icons/resources/cgal_logo.xpm</normaloff>:/cgal/icons/resources/cgal_logo.xpm</iconset>
|
||||
</property>
|
||||
<property name="locale" >
|
||||
<locale country="UnitedStates" language="English" />
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget" >
|
||||
<layout class="QGridLayout" name="gridLayout" >
|
||||
<item row="0" column="1" >
|
||||
|
|
@ -51,6 +54,7 @@
|
|||
<addaction name="actionView_points" />
|
||||
<addaction name="actionView_segments" />
|
||||
<addaction name="actionView_polyhedron" />
|
||||
<addaction name="actionView_distance_function" />
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuAlgorithms" >
|
||||
<property name="title" >
|
||||
|
|
@ -78,6 +82,7 @@
|
|||
</property>
|
||||
<addaction name="actionClear_points" />
|
||||
<addaction name="actionClear_segments" />
|
||||
<addaction name="actionClear_distance_function" />
|
||||
</widget>
|
||||
<addaction name="menuFile" />
|
||||
<addaction name="menuEdit" />
|
||||
|
|
@ -172,6 +177,16 @@
|
|||
<string>Intersections</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionView_distance_function" >
|
||||
<property name="text" >
|
||||
<string>Distance function</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionClear_distance_function" >
|
||||
<property name="text" >
|
||||
<string>Clear distance function</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
|
|
|
|||
|
|
@ -6,13 +6,7 @@
|
|||
#include <QString>
|
||||
#include <QTextStream>
|
||||
#include <QFileInfo>
|
||||
#include <QGLWidget>
|
||||
#include <QMessageBox>
|
||||
#include <QEvent>
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <QTime>
|
||||
#include <QApplication>
|
||||
#include <QInputDialog>
|
||||
|
||||
#include "render_edges.h"
|
||||
|
|
@ -26,13 +20,13 @@ Scene::Scene()
|
|||
m_view_points = true;
|
||||
m_view_segments = true;
|
||||
m_view_polyhedron = true;
|
||||
m_view_distance_function = true;
|
||||
|
||||
// distance functions
|
||||
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()
|
||||
|
|
@ -91,10 +85,13 @@ void Scene::draw()
|
|||
if(m_view_segments)
|
||||
draw_segments();
|
||||
|
||||
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()
|
||||
|
|
@ -267,6 +264,34 @@ Vector Scene::random_vector()
|
|||
return Vector(x,y,z);
|
||||
}
|
||||
|
||||
Ray Scene::random_ray()
|
||||
{
|
||||
Point p = random_point();
|
||||
Point q = random_point();
|
||||
return Ray(p,q);
|
||||
}
|
||||
|
||||
Segment Scene::random_segment()
|
||||
{
|
||||
Point p = random_point();
|
||||
Point q = random_point();
|
||||
return Segment(p,q);
|
||||
}
|
||||
|
||||
Line Scene::random_line()
|
||||
{
|
||||
Point p = random_point();
|
||||
Point q = random_point();
|
||||
return Line(p,q);
|
||||
}
|
||||
|
||||
Plane Scene::random_plane()
|
||||
{
|
||||
Point p = random_point();
|
||||
Vector vec = random_vector();
|
||||
return Plane(p,vec);
|
||||
}
|
||||
|
||||
void Scene::generate_inside_points(const unsigned int nb_trials)
|
||||
{
|
||||
typedef CGAL::AABB_polyhedron_triangle_primitive<Kernel,Polyhedron> Primitive;
|
||||
|
|
@ -425,39 +450,6 @@ void Scene::generate_edge_points(const unsigned int nb_points)
|
|||
std::cout << nb_planes << " plane queries, " << time.elapsed() << " ms." << std::endl;
|
||||
}
|
||||
|
||||
void Scene::benchmark_distances()
|
||||
{
|
||||
QTime time;
|
||||
time.start();
|
||||
std::cout << "Construct AABB tree...";
|
||||
Facet_tree tree(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end());
|
||||
tree.accelerate_distance_queries();
|
||||
std::cout << "done (" << time.elapsed() << " ms)" << std::endl;
|
||||
|
||||
// TODO: check what the KD-tree is doing in there for large models.
|
||||
std::cout << "One single call to initialize KD-tree" << std::endl;
|
||||
tree.closest_point(CGAL::ORIGIN);
|
||||
|
||||
std::cout << "------- Now, the real benchmark -------" << std::endl;
|
||||
bench_closest_point(tree);
|
||||
bench_squared_distance(tree);
|
||||
bench_closest_point_and_primitive(tree);
|
||||
}
|
||||
|
||||
void Scene::benchmark_intersections()
|
||||
{
|
||||
QTime time;
|
||||
time.start();
|
||||
std::cout << "Construct AABB tree...";
|
||||
Facet_tree tree(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end());
|
||||
std::cout << "done (" << time.elapsed() << " ms)" << std::endl;
|
||||
|
||||
bench_do_intersect(tree);
|
||||
bench_nb_intersections(tree);
|
||||
bench_any_intersection(tree);
|
||||
bench_all_intersections(tree);
|
||||
bench_all_intersected_primitives(tree);
|
||||
}
|
||||
|
||||
void Scene::unsigned_distance_function()
|
||||
{
|
||||
|
|
@ -556,376 +548,8 @@ unsigned_distance : m_max_distance_function;
|
|||
m_signed_distance_function = true;
|
||||
}
|
||||
|
||||
void Scene::bench_squared_distance(Facet_tree& tree)
|
||||
{
|
||||
QTime time;
|
||||
time.start();
|
||||
std::cout << "Benchmark squared distance" << std::endl;
|
||||
|
||||
unsigned int nb = 0;
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Point query = random_point();
|
||||
tree.squared_distance(query);
|
||||
nb++;
|
||||
}
|
||||
double speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void Scene::bench_closest_point(Facet_tree& tree)
|
||||
{
|
||||
QTime time;
|
||||
time.start();
|
||||
std::cout << "Benchmark closest point" << std::endl;
|
||||
|
||||
unsigned int nb = 0;
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Point query = random_point();
|
||||
tree.closest_point(query);
|
||||
nb++;
|
||||
}
|
||||
double speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s" << std::endl;
|
||||
}
|
||||
|
||||
void Scene::bench_closest_point_and_primitive(Facet_tree& tree)
|
||||
{
|
||||
QTime time;
|
||||
time.start();
|
||||
std::cout << "Benchmark closest point and primitive" << std::endl;
|
||||
|
||||
unsigned int nb = 0;
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Point query = random_point();
|
||||
tree.closest_point_and_primitive(query);
|
||||
nb++;
|
||||
}
|
||||
double speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void Scene::bench_all_intersected_primitives(Facet_tree& tree)
|
||||
{
|
||||
std::list<Primitive_id> primitive_ids;
|
||||
|
||||
QTime time;
|
||||
time.start();
|
||||
std::cout << "Benchmark all_intersected_primitives" << std::endl;
|
||||
|
||||
// with ray
|
||||
unsigned int nb = 0;
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Point p = random_point();
|
||||
Point q = random_point();
|
||||
Ray ray(p,q);
|
||||
tree.all_intersected_primitives(ray,std::back_inserter(primitive_ids));
|
||||
nb++;
|
||||
}
|
||||
double speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s with ray" << std::endl;
|
||||
primitive_ids.clear();
|
||||
|
||||
// with line
|
||||
nb = 0;
|
||||
time.start();
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Point p = random_point();
|
||||
Point q = random_point();
|
||||
Line line(p,q);
|
||||
tree.all_intersected_primitives(line,std::back_inserter(primitive_ids));
|
||||
nb++;
|
||||
}
|
||||
speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s with line" << std::endl;
|
||||
primitive_ids.clear();
|
||||
|
||||
// with segment
|
||||
nb = 0;
|
||||
time.start();
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Point p = random_point();
|
||||
Point q = random_point();
|
||||
Segment segment(p,q);
|
||||
tree.all_intersected_primitives(segment,std::back_inserter(primitive_ids));
|
||||
nb++;
|
||||
}
|
||||
speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s with segment" << std::endl;
|
||||
|
||||
// with segment
|
||||
nb = 0;
|
||||
time.start();
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Point p = random_point();
|
||||
Vector vec = random_vector();
|
||||
Plane plane(p,vec);
|
||||
tree.all_intersected_primitives(plane,std::back_inserter(primitive_ids));
|
||||
nb++;
|
||||
}
|
||||
speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s with plane" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void Scene::bench_do_intersect(Facet_tree& tree)
|
||||
{
|
||||
QTime time;
|
||||
time.start();
|
||||
std::cout << "Benchmark do_intersect" << std::endl;
|
||||
|
||||
// with ray
|
||||
unsigned int nb = 0;
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Point p = random_point();
|
||||
Point q = random_point();
|
||||
Ray ray(p,q);
|
||||
tree.do_intersect(ray);
|
||||
nb++;
|
||||
}
|
||||
double speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s with ray" << std::endl;
|
||||
|
||||
// with line
|
||||
nb = 0;
|
||||
time.start();
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Point p = random_point();
|
||||
Point q = random_point();
|
||||
Line line(p,q);
|
||||
tree.do_intersect(line);
|
||||
nb++;
|
||||
}
|
||||
speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s with line" << std::endl;
|
||||
|
||||
// with segment
|
||||
nb = 0;
|
||||
time.start();
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Point p = random_point();
|
||||
Point q = random_point();
|
||||
Segment segment(p,q);
|
||||
tree.do_intersect(segment);
|
||||
nb++;
|
||||
}
|
||||
speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s with segment" << std::endl;
|
||||
|
||||
// with plane
|
||||
nb = 0;
|
||||
time.start();
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Point p = random_point();
|
||||
Vector vec = random_vector();
|
||||
Plane plane(p,vec);
|
||||
tree.do_intersect(plane);
|
||||
nb++;
|
||||
}
|
||||
speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s with plane" << std::endl;
|
||||
}
|
||||
|
||||
void Scene::bench_nb_intersections(Facet_tree& tree)
|
||||
{
|
||||
QTime time;
|
||||
time.start();
|
||||
std::cout << "Benchmark number_of_intersected_primitives" << std::endl;
|
||||
|
||||
// with ray
|
||||
unsigned int nb = 0;
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Point p = random_point();
|
||||
Point q = random_point();
|
||||
Ray ray(p,q);
|
||||
tree.number_of_intersected_primitives(ray);
|
||||
nb++;
|
||||
}
|
||||
double speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s with ray" << std::endl;
|
||||
|
||||
// with line
|
||||
nb = 0;
|
||||
time.start();
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Point p = random_point();
|
||||
Point q = random_point();
|
||||
Line line(p,q);
|
||||
tree.number_of_intersected_primitives(line);
|
||||
nb++;
|
||||
}
|
||||
speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s with line" << std::endl;
|
||||
|
||||
// with segment
|
||||
nb = 0;
|
||||
time.start();
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Point p = random_point();
|
||||
Point q = random_point();
|
||||
Segment segment(p,q);
|
||||
tree.number_of_intersected_primitives(segment);
|
||||
nb++;
|
||||
}
|
||||
speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s with segment" << std::endl;
|
||||
|
||||
// with plane
|
||||
nb = 0;
|
||||
time.start();
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Point p = random_point();
|
||||
Vector vec = random_vector();
|
||||
Plane plane(p,vec);
|
||||
tree.number_of_intersected_primitives(plane);
|
||||
nb++;
|
||||
}
|
||||
speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s with plane" << std::endl;
|
||||
}
|
||||
|
||||
void Scene::bench_any_intersection(Facet_tree& tree)
|
||||
{
|
||||
QTime time;
|
||||
time.start();
|
||||
std::cout << "Benchmark any_intersection" << std::endl;
|
||||
|
||||
// with ray
|
||||
unsigned int nb = 0;
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Point p = random_point();
|
||||
Point q = random_point();
|
||||
Ray ray(p,q);
|
||||
tree.any_intersection(ray);
|
||||
nb++;
|
||||
}
|
||||
double speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s with ray" << std::endl;
|
||||
|
||||
// with line
|
||||
nb = 0;
|
||||
time.start();
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Point p = random_point();
|
||||
Point q = random_point();
|
||||
Line line(p,q);
|
||||
tree.any_intersection(line);
|
||||
nb++;
|
||||
}
|
||||
speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s with line" << std::endl;
|
||||
|
||||
// with segment
|
||||
nb = 0;
|
||||
time.start();
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Point p = random_point();
|
||||
Point q = random_point();
|
||||
Segment segment(p,q);
|
||||
tree.any_intersection(segment);
|
||||
nb++;
|
||||
}
|
||||
speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s with segment" << std::endl;
|
||||
|
||||
// with plane
|
||||
nb = 0;
|
||||
time.start();
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Point p = random_point();
|
||||
Vector vec = random_vector();
|
||||
Plane plane(p,vec);
|
||||
tree.any_intersection(plane);
|
||||
nb++;
|
||||
}
|
||||
speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s with plane" << std::endl;
|
||||
}
|
||||
|
||||
void Scene::bench_all_intersections(Facet_tree& tree)
|
||||
{
|
||||
std::list<Object_and_primitive_id> intersections;
|
||||
|
||||
QTime time;
|
||||
time.start();
|
||||
std::cout << "Benchmark all_intersections" << std::endl;
|
||||
|
||||
// with ray
|
||||
unsigned int nb = 0;
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Point p = random_point();
|
||||
Point q = random_point();
|
||||
Ray ray(p,q);
|
||||
tree.all_intersections(ray,std::back_inserter(intersections));
|
||||
nb++;
|
||||
}
|
||||
double speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s with ray" << std::endl;
|
||||
intersections.clear();
|
||||
|
||||
// with line
|
||||
nb = 0;
|
||||
time.start();
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Point p = random_point();
|
||||
Point q = random_point();
|
||||
Line line(p,q);
|
||||
tree.all_intersections(line,std::back_inserter(intersections));
|
||||
nb++;
|
||||
}
|
||||
speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s with line" << std::endl;
|
||||
|
||||
// with segment
|
||||
nb = 0;
|
||||
time.start();
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Point p = random_point();
|
||||
Point q = random_point();
|
||||
Segment segment(p,q);
|
||||
tree.all_intersections(segment,std::back_inserter(intersections));
|
||||
nb++;
|
||||
}
|
||||
speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s with segment" << std::endl;
|
||||
|
||||
// with plane
|
||||
nb = 0;
|
||||
time.start();
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Point p = random_point();
|
||||
Vector vec = random_vector();
|
||||
Plane plane(p,vec);
|
||||
tree.all_intersections(plane,std::back_inserter(intersections));
|
||||
nb++;
|
||||
}
|
||||
speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s with plane" << std::endl;
|
||||
}
|
||||
|
||||
void Scene::toggle_view_poyhedron()
|
||||
{
|
||||
|
|
@ -942,4 +566,9 @@ void Scene::toggle_view_points()
|
|||
m_view_points = !m_view_points;
|
||||
}
|
||||
|
||||
void Scene::toggle_view_distance_function()
|
||||
{
|
||||
m_view_distance_function = !m_view_distance_function;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -16,94 +16,101 @@
|
|||
|
||||
class Scene
|
||||
{
|
||||
public:
|
||||
Scene();
|
||||
~Scene();
|
||||
|
||||
Polyhedron* polyhedron() const;
|
||||
|
||||
void draw();
|
||||
|
||||
typedef CGAL::Bbox_3 Bbox;
|
||||
Bbox bbox() { return Bbox(); }
|
||||
|
||||
public:
|
||||
|
||||
// utility functions
|
||||
Point random_point();
|
||||
Vector random_vector();
|
||||
|
||||
// file menu functions
|
||||
int open(QString filename);
|
||||
|
||||
// edit menus functions
|
||||
void clear_points() { m_points.clear(); }
|
||||
void clear_segments() { m_segments.clear(); }
|
||||
|
||||
// benchmark menu functions
|
||||
void benchmark_intersections();
|
||||
void benchmark_distances();
|
||||
|
||||
// algorithms
|
||||
void generate_edge_points(const unsigned int nb_points);
|
||||
void generate_inside_points(const unsigned int nb_trials);
|
||||
void generate_boundary_points(const unsigned int nb_points);
|
||||
void generate_boundary_segments(const unsigned int nb_slices);
|
||||
|
||||
// distance functions
|
||||
void signed_distance_function();
|
||||
void unsigned_distance_function();
|
||||
void unsigned_distance_function_to_edges();
|
||||
|
||||
// toggle view options
|
||||
void toggle_view_points();
|
||||
void toggle_view_segments();
|
||||
void toggle_view_poyhedron();
|
||||
|
||||
private:
|
||||
// member data
|
||||
Polyhedron *m_pPolyhedron;
|
||||
std::list<Point> m_points;
|
||||
std::list<Segment> m_segments;
|
||||
Polyhedron *m_pPolyhedron;
|
||||
std::list<Point> m_points;
|
||||
std::list<Segment> m_segments;
|
||||
|
||||
// distance functions (simple 2D arrays)
|
||||
FT m_max_distance_function;
|
||||
bool m_signed_distance_function;
|
||||
typedef std::pair<Point,FT> Point_distance;
|
||||
Point_distance m_distance_function[100][100];
|
||||
Color_ramp m_thermal_ramp;
|
||||
Color_ramp m_red_ramp;
|
||||
Color_ramp m_blue_ramp;
|
||||
|
||||
// view options
|
||||
bool m_view_points;
|
||||
bool m_view_segments;
|
||||
bool m_view_polyhedron;
|
||||
// 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,FT> Point_distance;
|
||||
Point_distance m_distance_function[100][100];
|
||||
|
||||
// types
|
||||
typedef CGAL::AABB_polyhedron_triangle_primitive<Kernel,Polyhedron> Primitive;
|
||||
typedef CGAL::AABB_traits<Kernel, Primitive> Traits;
|
||||
typedef CGAL::AABB_tree<Traits> Facet_tree;
|
||||
typedef Facet_tree::Object_and_primitive_id Object_and_primitive_id;
|
||||
typedef Facet_tree::Primitive_id Primitive_id;
|
||||
public:
|
||||
Scene();
|
||||
~Scene();
|
||||
|
||||
// benchmarks
|
||||
void bench_do_intersect(Facet_tree& tree);
|
||||
void bench_closest_point(Facet_tree& tree);
|
||||
void bench_squared_distance(Facet_tree& tree);
|
||||
void bench_nb_intersections(Facet_tree& tree);
|
||||
void bench_any_intersection(Facet_tree& tree);
|
||||
void bench_all_intersections(Facet_tree& tree);
|
||||
void bench_closest_point_and_primitive(Facet_tree& tree);
|
||||
void bench_all_intersected_primitives(Facet_tree& tree);
|
||||
public:
|
||||
void draw();
|
||||
Polyhedron* polyhedron() const;
|
||||
|
||||
// drawing
|
||||
void draw_points();
|
||||
void draw_segments();
|
||||
void draw_polyhedron();
|
||||
void draw_signed_distance_function();
|
||||
void draw_unsigned_distance_function();
|
||||
typedef CGAL::Bbox_3 Bbox;
|
||||
Bbox bbox() { return Bbox(); }
|
||||
|
||||
public:
|
||||
|
||||
// utility functions
|
||||
Ray random_ray();
|
||||
Line random_line();
|
||||
Point random_point();
|
||||
Plane random_plane();
|
||||
Vector random_vector();
|
||||
Segment random_segment();
|
||||
|
||||
// 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; }
|
||||
|
||||
// benchmarks
|
||||
void benchmark_distances();
|
||||
void benchmark_intersections();
|
||||
|
||||
// algorithms
|
||||
void generate_edge_points(const unsigned int nb_points);
|
||||
void generate_inside_points(const unsigned int nb_trials);
|
||||
void generate_boundary_points(const unsigned int nb_points);
|
||||
void generate_boundary_segments(const unsigned int nb_slices);
|
||||
|
||||
// distance functions
|
||||
void signed_distance_function();
|
||||
void unsigned_distance_function();
|
||||
void unsigned_distance_function_to_edges();
|
||||
|
||||
// toggle view options
|
||||
void toggle_view_points();
|
||||
void toggle_view_segments();
|
||||
void toggle_view_poyhedron();
|
||||
void toggle_view_distance_function();
|
||||
|
||||
// view options
|
||||
bool m_view_points;
|
||||
bool m_view_segments;
|
||||
bool m_view_polyhedron;
|
||||
|
||||
// types
|
||||
typedef CGAL::AABB_polyhedron_triangle_primitive<Kernel,Polyhedron> Primitive;
|
||||
typedef CGAL::AABB_traits<Kernel, Primitive> Traits;
|
||||
typedef CGAL::AABB_tree<Traits> Facet_tree;
|
||||
typedef Facet_tree::Object_and_primitive_id Object_and_primitive_id;
|
||||
typedef Facet_tree::Primitive_id Primitive_id;
|
||||
|
||||
// benchmarks
|
||||
void bench_do_intersect(Facet_tree& tree);
|
||||
void bench_closest_point(Facet_tree& tree);
|
||||
void bench_squared_distance(Facet_tree& tree);
|
||||
void bench_nb_intersections(Facet_tree& tree);
|
||||
void bench_any_intersection(Facet_tree& tree);
|
||||
void bench_all_intersections(Facet_tree& tree);
|
||||
void bench_closest_point_and_primitive(Facet_tree& tree);
|
||||
void bench_all_intersected_primitives(Facet_tree& tree);
|
||||
|
||||
// drawing
|
||||
void draw_points();
|
||||
void draw_segments();
|
||||
void draw_polyhedron();
|
||||
void draw_signed_distance_function();
|
||||
void draw_unsigned_distance_function();
|
||||
}; // end class Scene
|
||||
|
||||
|
||||
#endif // SCENE_H
|
||||
#endif // SCENE_H
|
||||
|
|
@ -0,0 +1,377 @@
|
|||
#include "Scene.h"
|
||||
#include <QInputDialog>
|
||||
|
||||
void Scene::benchmark_intersections()
|
||||
{
|
||||
QTime time;
|
||||
time.start();
|
||||
std::cout << "Construct AABB tree...";
|
||||
Facet_tree tree(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end());
|
||||
std::cout << "done (" << time.elapsed() << " ms)" << std::endl;
|
||||
|
||||
bench_do_intersect(tree);
|
||||
bench_nb_intersections(tree);
|
||||
bench_any_intersection(tree);
|
||||
bench_all_intersections(tree);
|
||||
bench_all_intersected_primitives(tree);
|
||||
}
|
||||
|
||||
void Scene::benchmark_distances()
|
||||
{
|
||||
QTime time;
|
||||
time.start();
|
||||
std::cout << "Construct AABB tree...";
|
||||
Facet_tree tree(m_pPolyhedron->facets_begin(),m_pPolyhedron->facets_end());
|
||||
tree.accelerate_distance_queries();
|
||||
std::cout << "done (" << time.elapsed() << " ms)" << std::endl;
|
||||
|
||||
// TODO: check what the KD-tree is doing in there for large models.
|
||||
std::cout << "One single call to initialize KD-tree" << std::endl;
|
||||
tree.closest_point(CGAL::ORIGIN);
|
||||
|
||||
// benchmark
|
||||
bench_closest_point(tree);
|
||||
bench_squared_distance(tree);
|
||||
bench_closest_point_and_primitive(tree);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
// BENCH INTERSECTIONS
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
void Scene::bench_all_intersected_primitives(Facet_tree& tree)
|
||||
{
|
||||
std::list<Primitive_id> primitive_ids;
|
||||
|
||||
QTime time;
|
||||
time.start();
|
||||
std::cout << "Benchmark all_intersected_primitives" << std::endl;
|
||||
|
||||
// with ray
|
||||
unsigned int nb = 0;
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Ray ray = random_ray();
|
||||
tree.all_intersected_primitives(ray,std::back_inserter(primitive_ids));
|
||||
nb++;
|
||||
}
|
||||
double speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s with ray" << std::endl;
|
||||
primitive_ids.clear();
|
||||
|
||||
// with line
|
||||
nb = 0;
|
||||
time.start();
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Line line = random_line();
|
||||
tree.all_intersected_primitives(line,std::back_inserter(primitive_ids));
|
||||
nb++;
|
||||
}
|
||||
speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s with line" << std::endl;
|
||||
primitive_ids.clear();
|
||||
|
||||
// with segment
|
||||
nb = 0;
|
||||
time.start();
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Segment segment = random_segment();
|
||||
tree.all_intersected_primitives(segment,std::back_inserter(primitive_ids));
|
||||
nb++;
|
||||
}
|
||||
speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s with segment" << std::endl;
|
||||
|
||||
// with segment
|
||||
nb = 0;
|
||||
time.start();
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Plane plane = random_plane();
|
||||
tree.all_intersected_primitives(plane,std::back_inserter(primitive_ids));
|
||||
nb++;
|
||||
}
|
||||
speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s with plane" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void Scene::bench_do_intersect(Facet_tree& tree)
|
||||
{
|
||||
QTime time;
|
||||
time.start();
|
||||
std::cout << "Benchmark do_intersect" << std::endl;
|
||||
|
||||
// with ray
|
||||
unsigned int nb = 0;
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Ray ray = random_ray();
|
||||
tree.do_intersect(ray);
|
||||
nb++;
|
||||
}
|
||||
double speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s with ray" << std::endl;
|
||||
|
||||
// with line
|
||||
nb = 0;
|
||||
time.start();
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Line line = random_line();
|
||||
tree.do_intersect(line);
|
||||
nb++;
|
||||
}
|
||||
speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s with line" << std::endl;
|
||||
|
||||
// with segment
|
||||
nb = 0;
|
||||
time.start();
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Segment segment = random_segment();
|
||||
tree.do_intersect(segment);
|
||||
nb++;
|
||||
}
|
||||
speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s with segment" << std::endl;
|
||||
|
||||
// with plane
|
||||
nb = 0;
|
||||
time.start();
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Plane plane = random_plane();
|
||||
tree.do_intersect(plane);
|
||||
nb++;
|
||||
}
|
||||
speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s with plane" << std::endl;
|
||||
}
|
||||
|
||||
void Scene::bench_nb_intersections(Facet_tree& tree)
|
||||
{
|
||||
QTime time;
|
||||
time.start();
|
||||
std::cout << "Benchmark number_of_intersected_primitives" << std::endl;
|
||||
|
||||
// with ray
|
||||
unsigned int nb = 0;
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Ray ray = random_ray();
|
||||
tree.number_of_intersected_primitives(ray);
|
||||
nb++;
|
||||
}
|
||||
double speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s with ray" << std::endl;
|
||||
|
||||
// with line
|
||||
nb = 0;
|
||||
time.start();
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Line line = random_line();
|
||||
tree.number_of_intersected_primitives(line);
|
||||
nb++;
|
||||
}
|
||||
speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s with line" << std::endl;
|
||||
|
||||
// with segment
|
||||
nb = 0;
|
||||
time.start();
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Segment segment = random_segment();
|
||||
tree.number_of_intersected_primitives(segment);
|
||||
nb++;
|
||||
}
|
||||
speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s with segment" << std::endl;
|
||||
|
||||
// with plane
|
||||
nb = 0;
|
||||
time.start();
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Plane plane = random_plane();
|
||||
tree.number_of_intersected_primitives(plane);
|
||||
nb++;
|
||||
}
|
||||
speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s with plane" << std::endl;
|
||||
}
|
||||
|
||||
void Scene::bench_any_intersection(Facet_tree& tree)
|
||||
{
|
||||
QTime time;
|
||||
time.start();
|
||||
std::cout << "Benchmark any_intersection" << std::endl;
|
||||
|
||||
// with ray
|
||||
unsigned int nb = 0;
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Ray ray = random_ray();
|
||||
tree.any_intersection(ray);
|
||||
nb++;
|
||||
}
|
||||
double speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s with ray" << std::endl;
|
||||
|
||||
// with line
|
||||
nb = 0;
|
||||
time.start();
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Line line = random_line();
|
||||
tree.any_intersection(line);
|
||||
nb++;
|
||||
}
|
||||
speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s with line" << std::endl;
|
||||
|
||||
// with segment
|
||||
nb = 0;
|
||||
time.start();
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Segment segment = random_segment();
|
||||
tree.any_intersection(segment);
|
||||
nb++;
|
||||
}
|
||||
speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s with segment" << std::endl;
|
||||
|
||||
// with plane
|
||||
nb = 0;
|
||||
time.start();
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Plane plane = random_plane();
|
||||
tree.any_intersection(plane);
|
||||
nb++;
|
||||
}
|
||||
speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s with plane" << std::endl;
|
||||
}
|
||||
|
||||
void Scene::bench_all_intersections(Facet_tree& tree)
|
||||
{
|
||||
std::list<Object_and_primitive_id> intersections;
|
||||
|
||||
QTime time;
|
||||
time.start();
|
||||
std::cout << "Benchmark all_intersections" << std::endl;
|
||||
|
||||
// with ray
|
||||
unsigned int nb = 0;
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Ray ray = random_ray();
|
||||
tree.all_intersections(ray,std::back_inserter(intersections));
|
||||
nb++;
|
||||
}
|
||||
double speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s with ray" << std::endl;
|
||||
intersections.clear();
|
||||
|
||||
// with line
|
||||
nb = 0;
|
||||
time.start();
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Line line = random_line();
|
||||
tree.all_intersections(line,std::back_inserter(intersections));
|
||||
nb++;
|
||||
}
|
||||
speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s with line" << std::endl;
|
||||
intersections.clear();
|
||||
|
||||
// with segment
|
||||
nb = 0;
|
||||
time.start();
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Segment segment = random_segment();
|
||||
tree.all_intersections(segment,std::back_inserter(intersections));
|
||||
nb++;
|
||||
}
|
||||
speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s with segment" << std::endl;
|
||||
intersections.clear();
|
||||
|
||||
// with plane
|
||||
nb = 0;
|
||||
time.start();
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Plane plane = random_plane();
|
||||
tree.all_intersections(plane,std::back_inserter(intersections));
|
||||
nb++;
|
||||
}
|
||||
speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s with plane" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
// BENCH DISTANCES
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
void Scene::bench_squared_distance(Facet_tree& tree)
|
||||
{
|
||||
QTime time;
|
||||
time.start();
|
||||
std::cout << "Benchmark squared distance" << std::endl;
|
||||
|
||||
unsigned int nb = 0;
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Point query = random_point();
|
||||
tree.squared_distance(query);
|
||||
nb++;
|
||||
}
|
||||
double speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void Scene::bench_closest_point(Facet_tree& tree)
|
||||
{
|
||||
QTime time;
|
||||
time.start();
|
||||
std::cout << "Benchmark closest point" << std::endl;
|
||||
|
||||
unsigned int nb = 0;
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Point query = random_point();
|
||||
tree.closest_point(query);
|
||||
nb++;
|
||||
}
|
||||
double speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s" << std::endl;
|
||||
}
|
||||
|
||||
void Scene::bench_closest_point_and_primitive(Facet_tree& tree)
|
||||
{
|
||||
QTime time;
|
||||
time.start();
|
||||
std::cout << "Benchmark closest point and primitive" << std::endl;
|
||||
|
||||
unsigned int nb = 0;
|
||||
while(time.elapsed() < 1000)
|
||||
{
|
||||
Point query = random_point();
|
||||
tree.closest_point_and_primitive(query);
|
||||
nb++;
|
||||
}
|
||||
double speed = 1000.0 * nb / time.elapsed();
|
||||
std::cout << speed << " queries/s" << std::endl;
|
||||
}
|
||||
Loading…
Reference in New Issue