mirror of https://github.com/CGAL/cgal
PCA demo: skeleton in place.
This commit is contained in:
parent
c68470ad34
commit
349d976629
|
|
@ -2976,6 +2976,9 @@ Polytope_distance_d/test/Polytope_distance_d/test_PD_data/two_numbers.data -text
|
|||
Polytope_distance_d/test/Polytope_distance_d/test_PD_data/two_squares.data -text
|
||||
Polytope_distance_d/test/Polytope_distance_d/wilms_bug.cpp -text
|
||||
Polytope_distance_d/test/Polytope_distance_d/zwick_bug.cpp -text
|
||||
Principal_component_analysis/demo/Principal_component_analysis/MainWindow.ui -text
|
||||
Principal_component_analysis/demo/Principal_component_analysis/PCA_demo.qrc -text
|
||||
Principal_component_analysis/demo/Principal_component_analysis/cleanup.bat eol=crlf
|
||||
Principal_component_analysis/demo/Principal_component_analysis/data/cylinder_iso1_locally_refined.off -text
|
||||
Principal_component_analysis/demo/Principal_component_analysis/data/cylinder_iso2.off -text
|
||||
Principal_component_analysis/demo/Principal_component_analysis/data/ellipsoid.off -text
|
||||
|
|
@ -2983,6 +2986,7 @@ Principal_component_analysis/demo/Principal_component_analysis/data/mushroom-19v
|
|||
Principal_component_analysis/demo/Principal_component_analysis/data/mushroom-651v.off -text
|
||||
Principal_component_analysis/demo/Principal_component_analysis/data/mushroom-81v.off -text
|
||||
Principal_component_analysis/demo/Principal_component_analysis/data/mushroom.off -text
|
||||
Principal_component_analysis/demo/Principal_component_analysis/resources/about.html svneol=native#text/html
|
||||
Principal_component_analysis/doc_tex/Principal_component_analysis/examples.tex -text
|
||||
Principal_component_analysis/doc_tex/Principal_component_analysis/fit.eps -text svneol=unset#application/postscript
|
||||
Principal_component_analysis/doc_tex/Principal_component_analysis/fit.jpg -text
|
||||
|
|
|
|||
|
|
@ -0,0 +1,95 @@
|
|||
# This is the CMake script for compiling the PCA demo.
|
||||
|
||||
project( PCA_demo )
|
||||
|
||||
cmake_minimum_required(VERSION 2.4.5)
|
||||
|
||||
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
|
||||
|
||||
if(COMMAND cmake_policy)
|
||||
cmake_policy(SET CMP0003 NEW)
|
||||
endif(COMMAND cmake_policy)
|
||||
|
||||
foreach(INCDIR ../../include ../../../STL_Extension/include ../../../GraphicsView/include ../../../filtered_kernel/include )
|
||||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${INCDIR}")
|
||||
include_directories (BEFORE "${CMAKE_CURRENT_SOURCE_DIR}/${INCDIR}")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
include_directories( ./ )
|
||||
|
||||
# Find CGAL and CGAL Qt4
|
||||
find_package(CGAL COMPONENTS Qt4)
|
||||
include( ${CGAL_USE_FILE} )
|
||||
|
||||
# Find Qt4 itself
|
||||
set( QT_USE_QTXML TRUE )
|
||||
set( QT_USE_QTMAIN TRUE )
|
||||
set( QT_USE_QTSCRIPT TRUE )
|
||||
set( QT_USE_QTOPENGL TRUE )
|
||||
find_package(Qt4)
|
||||
|
||||
# Find OpenGL
|
||||
find_package(OpenGL)
|
||||
|
||||
# Find QGLViewer
|
||||
if(QT4_FOUND)
|
||||
include(${QT_USE_FILE})
|
||||
find_package(QGLViewer )
|
||||
endif(QT4_FOUND)
|
||||
|
||||
if(CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND)
|
||||
|
||||
include_directories ( ${QGLVIEWER_INCLUDE_DIR} )
|
||||
|
||||
qt4_wrap_ui( UI_FILES MainWindow.ui )
|
||||
|
||||
include(AddFileDependencies)
|
||||
|
||||
qt4_generate_moc( "${CMAKE_CURRENT_SOURCE_DIR}/MainWindow.h" MainWindow_moc.cpp )
|
||||
add_file_dependencies( MainWindow_moc.cpp "${CMAKE_CURRENT_SOURCE_DIR}/MainWindow.h" )
|
||||
|
||||
qt4_generate_moc( "${CMAKE_CURRENT_SOURCE_DIR}/Viewer.h" Viewer_moc.cpp )
|
||||
add_file_dependencies( Viewer_moc.cpp "${CMAKE_CURRENT_SOURCE_DIR}/Viewer.h" )
|
||||
|
||||
qt4_add_resources ( RESOURCE_FILES PCA_demo.qrc )
|
||||
|
||||
add_file_dependencies( PCA_demo.cpp "${CMAKE_CURRENT_BINARY_DIR}/MainWindow_moc.cpp"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/Viewer_moc.cpp" )
|
||||
add_executable ( PCA_demo PCA_demo.cpp ${UI_FILES} ${RESOURCE_FILES} )
|
||||
|
||||
# Link with Qt libraries
|
||||
target_link_libraries( PCA_demo ${QT_LIBRARIES} )
|
||||
|
||||
# Link with CGAL
|
||||
target_link_libraries( PCA_demo ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES} )
|
||||
|
||||
# Link with libQGLViewer, OpenGL
|
||||
target_link_libraries( PCA_demo ${QGLVIEWER_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} )
|
||||
|
||||
add_to_cached_list( CGAL_EXECUTABLE_TARGETS PCA_demo )
|
||||
|
||||
|
||||
else (CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND)
|
||||
|
||||
set(PCA_MISSING_DEPS "")
|
||||
|
||||
if(NOT CGAL_Qt4_FOUND)
|
||||
set(PCA_MISSING_DEPS "the CGAL Qt4 library, ${PCA_MISSING_DEPS}")
|
||||
endif()
|
||||
|
||||
if(NOT QT4_FOUND)
|
||||
set(PCA_MISSING_DEPS "Qt4, ${PCA_MISSING_DEPS}")
|
||||
endif()
|
||||
|
||||
if(NOT OPENGL_FOUND)
|
||||
set(PCA_MISSING_DEPS "OpenGL, ${PCA_MISSING_DEPS}")
|
||||
endif()
|
||||
|
||||
if(NOT QGLVIEWER_FOUND)
|
||||
set(PCA_MISSING_DEPS "QGLViewer, ${PCA_MISSING_DEPS}")
|
||||
endif()
|
||||
|
||||
message(STATUS "NOTICE: This demo requires ${PCA_MISSING_DEPS} and will not be compiled.")
|
||||
|
||||
endif (CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND)
|
||||
|
|
@ -0,0 +1,184 @@
|
|||
#include "MainWindow.h"
|
||||
#include "Scene.h"
|
||||
#include <CGAL/Qt/debug.h>
|
||||
|
||||
#include <QDragEnterEvent>
|
||||
#include <QDropEvent>
|
||||
#include <QTextStream>
|
||||
#include <QUrl>
|
||||
#include <QFileDialog>
|
||||
#include <QSettings>
|
||||
#include <QHeaderView>
|
||||
#include <QClipboard>
|
||||
|
||||
#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);
|
||||
|
||||
// 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::on_actionView_polyhedron_triggered()
|
||||
{
|
||||
m_pScene->toggle_view_poyhedron();
|
||||
m_pViewer->update();
|
||||
}
|
||||
|
||||
void MainWindow::on_actionRefine_loop_triggered()
|
||||
{
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
m_pScene->refine_loop();
|
||||
QApplication::restoreOverrideCursor();
|
||||
m_pViewer->update();
|
||||
}
|
||||
|
||||
|
||||
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_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();
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QtOpenGL/qgl.h>
|
||||
#include <CGAL/Qt/DemosMainWindow.h>
|
||||
|
||||
class QDragEnterEvent;
|
||||
class QDropEvent;
|
||||
class Scene;
|
||||
class Viewer;
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
}
|
||||
|
||||
|
||||
class MainWindow :
|
||||
public CGAL::Qt::DemosMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MainWindow(QWidget* parent = 0);
|
||||
~MainWindow();
|
||||
|
||||
public slots:
|
||||
void updateViewerBBox();
|
||||
void open(QString filename);
|
||||
void setAddKeyFrameKeyboardModifiers(Qt::KeyboardModifiers);
|
||||
|
||||
protected slots:
|
||||
|
||||
// settings
|
||||
void quit();
|
||||
void readSettings();
|
||||
void writeSettings();
|
||||
|
||||
// drag & drop
|
||||
void dropEvent(QDropEvent *event);
|
||||
void closeEvent(QCloseEvent *event);
|
||||
void dragEnterEvent(QDragEnterEvent *event);
|
||||
|
||||
// file menu
|
||||
void on_actionLoadPolyhedron_triggered();
|
||||
|
||||
// edit menu
|
||||
void on_actionSave_snapshot_triggered();
|
||||
void on_actionCopy_snapshot_triggered();
|
||||
|
||||
// algorithm menu
|
||||
void on_actionRefine_loop_triggered();
|
||||
|
||||
|
||||
// view menu
|
||||
void on_actionView_polyhedron_triggered();
|
||||
|
||||
private:
|
||||
Scene* m_pScene;
|
||||
Viewer* m_pViewer;
|
||||
Ui::MainWindow* ui;
|
||||
};
|
||||
|
||||
#endif // ifndef MAINWINDOW_H
|
||||
|
|
@ -0,0 +1,240 @@
|
|||
<ui version="4.0" >
|
||||
<class>MainWindow</class>
|
||||
<widget class="QMainWindow" name="MainWindow" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>638</width>
|
||||
<height>495</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle" >
|
||||
<string>CGAL - PCA tree demo</string>
|
||||
</property>
|
||||
<property name="windowIcon" >
|
||||
<iconset resource="PCA_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" >
|
||||
<widget class="Viewer" native="1" name="viewer" >
|
||||
<property name="locale" >
|
||||
<locale country="UnitedStates" language="English" />
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menubar" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>638</width>
|
||||
<height>24</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuFile" >
|
||||
<property name="title" >
|
||||
<string>&File</string>
|
||||
</property>
|
||||
<addaction name="actionLoadPolyhedron" />
|
||||
<addaction name="separator" />
|
||||
<addaction name="actionQuit" />
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuView" >
|
||||
<property name="title" >
|
||||
<string>&View</string>
|
||||
</property>
|
||||
<addaction name="actionView_polyhedron" />
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuAlgorithms" >
|
||||
<property name="title" >
|
||||
<string>Algorithms</string>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuRefine" >
|
||||
<property name="title" >
|
||||
<string>Refine</string>
|
||||
</property>
|
||||
<addaction name="actionRefine_bisection" />
|
||||
<addaction name="actionRefine_loop" />
|
||||
</widget>
|
||||
<addaction name="menuRefine" />
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuEdit" >
|
||||
<property name="title" >
|
||||
<string>Edit</string>
|
||||
</property>
|
||||
<addaction name="actionCopy_snapshot" />
|
||||
<addaction name="actionSave_snapshot" />
|
||||
</widget>
|
||||
<addaction name="menuFile" />
|
||||
<addaction name="menuEdit" />
|
||||
<addaction name="menuAlgorithms" />
|
||||
<addaction name="menuBenchmarks" />
|
||||
<addaction name="menuView" />
|
||||
</widget>
|
||||
<action name="actionQuit" >
|
||||
<property name="text" >
|
||||
<string>&Quit</string>
|
||||
</property>
|
||||
<property name="shortcut" >
|
||||
<string>Ctrl+Q</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionLoadPolyhedron" >
|
||||
<property name="text" >
|
||||
<string>Load polyhedron...</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionInside_points" >
|
||||
<property name="text" >
|
||||
<string>Inside points...</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionBench_distances" >
|
||||
<property name="text" >
|
||||
<string>Distances</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionUnsigned_distance_function_to_facets" >
|
||||
<property name="text" >
|
||||
<string>Unsigned distance function to facets</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionUnsigned_distance_function_to_edges" >
|
||||
<property name="text" >
|
||||
<string>Unsigned distance function to edges</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionSigned_distance_function_to_facets" >
|
||||
<property name="text" >
|
||||
<string>Signed distance function to facets</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionView_polyhedron" >
|
||||
<property name="text" >
|
||||
<string>Polyhedron</string>
|
||||
</property>
|
||||
<property name="shortcut" >
|
||||
<string>P</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionView_points" >
|
||||
<property name="text" >
|
||||
<string>Points</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionClear_points" >
|
||||
<property name="text" >
|
||||
<string>Clear points</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionBoundary_segments" >
|
||||
<property name="text" >
|
||||
<string>Boundary segments...</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionBoundary_points" >
|
||||
<property name="text" >
|
||||
<string>Boundary points...</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionClear_segments" >
|
||||
<property name="text" >
|
||||
<string>Clear segments</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionView_segments" >
|
||||
<property name="text" >
|
||||
<string>Segments</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionEdge_points" >
|
||||
<property name="text" >
|
||||
<string>Edge points...</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionBench_intersections" >
|
||||
<property name="text" >
|
||||
<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>
|
||||
<action name="actionRefine_bisection" >
|
||||
<property name="text" >
|
||||
<string>Longest edge bisection</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionLoop_subdivision" >
|
||||
<property name="text" >
|
||||
<string>Loop subdivision</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionBench_memory" >
|
||||
<property name="text" >
|
||||
<string>Memory</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionBench_construction" >
|
||||
<property name="text" >
|
||||
<string>Construction</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionBench_intersections_vs_nbt" >
|
||||
<property name="text" >
|
||||
<string>Intersections</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionBench_distances_vs_nbt" >
|
||||
<property name="text" >
|
||||
<string>Distances</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionPoints_in_interval" >
|
||||
<property name="text" >
|
||||
<string>Points in interval...</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionSave_snapshot" >
|
||||
<property name="text" >
|
||||
<string>Save snapshot</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionCopy_snapshot" >
|
||||
<property name="text" >
|
||||
<string>Copy snapshot</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionRefine_loop" >
|
||||
<property name="text" >
|
||||
<string>Loop subdivision</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>Viewer</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>Viewer.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="PCA_demo.qrc" />
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
// 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
|
||||
//
|
||||
//******************************************************************************
|
||||
// File Description : demo of PCA component on polyhedron surface primitives
|
||||
//
|
||||
//******************************************************************************
|
||||
|
||||
#include "MainWindow.h"
|
||||
#include <QApplication>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
app.setOrganizationDomain("inria.fr");
|
||||
app.setOrganizationName("INRIA");
|
||||
app.setApplicationName("PCA 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 "Viewer.cpp"
|
||||
# include "Viewer_moc.cpp"
|
||||
# include "MainWindow.cpp"
|
||||
# include "MainWindow_moc.cpp"
|
||||
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<RCC>
|
||||
<qresource prefix="/cgal/icons" >
|
||||
<file>resources/cgal_logo.xpm</file>
|
||||
</qresource>
|
||||
<qresource prefix="/cgal/PCA_demo" >
|
||||
<file alias="about.html" >resources/about.html</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
@ -0,0 +1,126 @@
|
|||
#include "Scene.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include <QString>
|
||||
#include <QTextStream>
|
||||
#include <QFileInfo>
|
||||
#include <QInputDialog>
|
||||
|
||||
#include <CGAL/Timer.h>
|
||||
#include <CGAL/IO/Polyhedron_iostream.h>
|
||||
#include <CGAL/Subdivision_method_3.h>
|
||||
|
||||
#include "render_edges.h"
|
||||
|
||||
Scene::Scene()
|
||||
{
|
||||
m_pPolyhedron = NULL;
|
||||
|
||||
// view options
|
||||
m_view_polyhedron = true;
|
||||
}
|
||||
|
||||
Scene::~Scene()
|
||||
{
|
||||
delete m_pPolyhedron;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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_polyhedron)
|
||||
draw_polyhedron();
|
||||
}
|
||||
|
||||
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::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;
|
||||
}
|
||||
|
||||
void Scene::toggle_view_poyhedron()
|
||||
{
|
||||
m_view_polyhedron = !m_view_polyhedron;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
#ifndef SCENE_H
|
||||
#define SCENE_H
|
||||
|
||||
#include <QtOpenGL/qgl.h>
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
|
||||
#include "types.h"
|
||||
|
||||
|
||||
class Scene
|
||||
{
|
||||
public:
|
||||
Scene();
|
||||
~Scene();
|
||||
public:
|
||||
// types
|
||||
typedef CGAL::Bbox_3 Bbox;
|
||||
|
||||
public:
|
||||
void draw();
|
||||
void update_bbox();
|
||||
Bbox bbox() { return m_bbox; }
|
||||
|
||||
private:
|
||||
// member data
|
||||
Bbox m_bbox;
|
||||
Polyhedron *m_pPolyhedron;
|
||||
|
||||
private:
|
||||
|
||||
public:
|
||||
// file menu
|
||||
int open(QString filename);
|
||||
|
||||
// toggle view options
|
||||
void toggle_view_poyhedron();
|
||||
|
||||
// view options
|
||||
bool m_view_polyhedron;
|
||||
|
||||
// refinement
|
||||
void refine_loop();
|
||||
|
||||
// drawing
|
||||
void draw_polyhedron();
|
||||
}; // end class Scene
|
||||
|
||||
|
||||
#endif // SCENE_H
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
#include "Viewer.h"
|
||||
#include "Scene.h"
|
||||
|
||||
Viewer::Viewer(QWidget* parent)
|
||||
: QGLViewer(parent),
|
||||
m_pScene(NULL)
|
||||
{
|
||||
setBackgroundColor(::Qt::white);
|
||||
}
|
||||
|
||||
void Viewer::setScene(Scene* pScene)
|
||||
{
|
||||
this->m_pScene = pScene;
|
||||
}
|
||||
|
||||
void Viewer::draw()
|
||||
{
|
||||
QGLViewer::draw();
|
||||
if(m_pScene != NULL)
|
||||
{
|
||||
::glClearColor(1.0f,1.0f,1.0f,0.0f);
|
||||
m_pScene->draw();
|
||||
}
|
||||
}
|
||||
|
||||
void Viewer::initializeGL()
|
||||
{
|
||||
QGLViewer::initializeGL();
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
#ifndef VIEWER_H
|
||||
#define VIEWER_H
|
||||
|
||||
#include <QGLViewer/qglviewer.h>
|
||||
|
||||
// forward declarations
|
||||
class QWidget;
|
||||
class Scene;
|
||||
|
||||
class Viewer : public QGLViewer {
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Viewer(QWidget * parent);
|
||||
|
||||
// overload several QGLViewer virtual functions
|
||||
void draw();
|
||||
void initializeGL();
|
||||
void setScene(Scene* pScene);
|
||||
|
||||
private:
|
||||
Scene* m_pScene;
|
||||
}; // end class Viewer
|
||||
|
||||
#endif // VIEWER_H
|
||||
|
|
@ -0,0 +1 @@
|
|||
del *.vcproj* *.user *.cmake ZERO* *.ncb *.sln AABB_demo.suo CMakeCache.txt *_moc.* qrc* ui_*.h /Q
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
#ifndef _GL_RENDER_EDGES_
|
||||
#define _GL_RENDER_EDGES_
|
||||
|
||||
#include <CGAL/gl.h>
|
||||
|
||||
template <class Polyhedron>
|
||||
void gl_render_edges(Polyhedron& polyhedron)
|
||||
{
|
||||
typedef typename Polyhedron::Traits Kernel;
|
||||
typedef typename Kernel::Point_3 Point;
|
||||
|
||||
::glBegin(GL_LINES);
|
||||
typename Polyhedron::Edge_iterator he;
|
||||
for(he = polyhedron.edges_begin();
|
||||
he != polyhedron.edges_end();
|
||||
he++)
|
||||
{
|
||||
const Point& a = he->vertex()->point();
|
||||
const Point& b = he->opposite()->vertex()->point();
|
||||
::glVertex3d(a.x(),a.y(),a.z());
|
||||
::glVertex3d(b.x(),b.y(),b.z());
|
||||
}
|
||||
::glEnd();
|
||||
}
|
||||
|
||||
#endif // _GL_RENDER_EDGES_
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<html>
|
||||
<body>
|
||||
<h2>AABB Tree Demo</h2>
|
||||
<p>Copyright ©2009
|
||||
<a href="http://www-sop.inria.fr/">INRIA Sophia Antipolis - Mediterranee<a/></p>
|
||||
<p>This application illustrates the AABB tree component
|
||||
of <a href="http://www.cgal.org/">CGAL</a>, applied to polyhedron
|
||||
facets and edges.</p>
|
||||
<p>See also the following chapters of the manual:
|
||||
<ul>
|
||||
<li><a href="http://www.cgal.org/Pkg/Polyhedron">
|
||||
3D Polyhedral Surface</a>,
|
||||
</li>
|
||||
</ul>
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
/* XPM */
|
||||
const char * demoicon_xpm[] = {
|
||||
/* columns rows colors chars-per-pixel */
|
||||
"16 16 3 1",
|
||||
" c None",
|
||||
". c #FFFF00",
|
||||
"+ c #000000",
|
||||
/* pixels */
|
||||
"................",
|
||||
"...++++...++++..",
|
||||
"..+....+.+....+.",
|
||||
"..+......+......",
|
||||
"..+......+..+++.",
|
||||
"..+......+....+.",
|
||||
"..+....+.+....+.",
|
||||
"...++++...++++..",
|
||||
"................",
|
||||
"...++++...+.....",
|
||||
"..+....+..+.....",
|
||||
"..+....+..+.....",
|
||||
"..++++++..+.....",
|
||||
"..+....+..+.....",
|
||||
"..+....+..+++++.",
|
||||
"................"};
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
#ifndef PCA_DEMO_TYPES_H
|
||||
#define PCA_DEMO_TYPES_H
|
||||
|
||||
#include <CGAL/Simple_cartesian.h>
|
||||
|
||||
typedef CGAL::Simple_cartesian<double> 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;
|
||||
|
||||
#include <CGAL/Polyhedron_3.h>
|
||||
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
|
||||
|
||||
#endif // PCA_DEMO_TYPES_H
|
||||
Loading…
Reference in New Issue