Move Qt4 based demo in the right package

This commit is contained in:
Andreas Fabri 2010-04-08 16:01:34 +00:00
parent 082667ba2c
commit 675691a4f8
10 changed files with 0 additions and 614 deletions

1
.gitattributes vendored
View File

@ -1312,7 +1312,6 @@ Geomview/doc_tex/Geomview/geomview.gif -text
GraphicsView/GraphicsView.odp -text
GraphicsView/TODO -text
GraphicsView/demo/Alpha_shapes_3/Alpha_shape_3.qrc -text
GraphicsView/demo/Alpha_shapes_3/MainWindow.ui -text
GraphicsView/demo/Circular_kernel_2/Circular_kernel_2.qrc -text
GraphicsView/demo/Circular_kernel_2/Circular_kernel_2.ui -text
GraphicsView/demo/Circular_kernel_2/arcs.arc -text

View File

@ -1,26 +0,0 @@
#include "MainWindow.h"
#include "typedefs.h"
#include <QApplication>
int main(int argc, char** argv)
{
QApplication application(argc,argv);
application.setOrganizationDomain("geometryfactory.com");
application.setOrganizationName("GeometryFactory");
application.setApplicationName("Alpha Shape Reconstruction");
// Import resources from libCGALQt4.
// See http://doc.trolltech.com/4.4/qdir.html#Q_INIT_RESOURCE
Q_INIT_RESOURCE(File);
Q_INIT_RESOURCE(Alpha_shape_3);
Q_INIT_RESOURCE(CGAL);
MainWindow mw;
mw.show();
return application.exec();
}

View File

@ -1,53 +0,0 @@
# Created by the script cgal_create_cmake_script
# This is the CMake script for compiling a CGAL application.
project (Alpha_shape_3)
cmake_minimum_required(VERSION 2.4.5)
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
if ( COMMAND cmake_policy )
cmake_policy( SET CMP0003 NEW )
endif()
find_package(CGAL COMPONENTS Qt4)
include(${CGAL_USE_FILE})
set( QT_USE_QTXML TRUE )
set( QT_USE_QTMAIN TRUE )
set( QT_USE_QTSCRIPT TRUE )
set( QT_USE_QTOPENGL TRUE )
find_package(Qt4)
find_package(OpenGL)
find_package(QGLViewer)
if ( CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND )
include(${QT_USE_FILE})
include_directories (${QGLVIEWER_INCLUDE_DIR})
include_directories (BEFORE ../../include ./ )
# ui file, created wih Qt Designer
qt4_wrap_ui( uis MainWindow.ui )
# qrc files (resources files, that contain icons, at least)
qt4_add_resources ( RESOURCE_FILES ./Alpha_shape_3.qrc )
qt4_automoc( MainWindow.cpp Viewer.cpp)
add_executable ( Alpha_shape_3 Alpha_shape_3.cpp MainWindow.cpp Viewer.cpp ${uis} ${RESOURCE_FILES} )
add_to_cached_list( CGAL_EXECUTABLE_TARGETS Alpha_shape_3 )
target_link_libraries( Alpha_shape_3 ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES})
target_link_libraries( Alpha_shape_3 ${QT_LIBRARIES} ${QGLVIEWER_LIBRARIES} )
target_link_libraries( Alpha_shape_3 ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} )
else()
message(STATUS "NOTICE: This demo requires CGAL, the QGLViewer, OpenGL and Qt4, and will not be compiled.")
endif()

View File

@ -1,111 +0,0 @@
#include "MainWindow.h"
MainWindow::MainWindow(QWidget* parent): CGAL::Qt::DemosMainWindow(parent)
{
setupUi(this);
this->viewer->setScene(&scene);
connectActions();
this->addAboutDemo(":/cgal/help/about_Alpha_shapes_3.html");
this->addAboutCGAL();
this->addRecentFiles(this->menuFile, this->actionQuit);
connect(this, SIGNAL(openRecentFile(QString)),
this, SLOT(open(QString)));
}
void
MainWindow::connectActions()
{
QObject::connect(this->actionLoad_New_File, SIGNAL(triggered()),
this, SLOT(open_file()));
QObject::connect(this->alphaSlider, SIGNAL(valueChanged(int)),
this, SLOT(alphaChanged(int)));
QObject::connect(this->alphaBox, SIGNAL(valueChanged(int)),
this, SLOT(alphaChanged(int)));
QObject::connect(this->alphaSlider, SIGNAL(valueChanged(int)),
this->alphaBox, SLOT(setValue(int)));
QObject::connect(this->alphaBox, SIGNAL(valueChanged(int)),
this->alphaSlider, SLOT(setValue(int)));
QObject::connect(this, SIGNAL(sceneChanged()),
this->viewer, SLOT(sceneChanged()));
QObject::connect(this, SIGNAL(alphaChanged()),
this->viewer, SLOT(update()));
QObject::connect(this->actionQuit, SIGNAL(triggered()),
qApp, SLOT(quit()));
}
void
MainWindow::open_file()
{
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open Points File"),
"./data",
tr("pts files (*.pts)"));
if(! fileName.isEmpty()){
open(fileName);
}
}
void
MainWindow::alphaChanged(int i)
{
if (scene.alpha_shape.number_of_alphas() > 0){
if(i < 100){
int n = (i * scene.alpha_shape.number_of_alphas())/ 100;
if(n == 0) n++;
scene.alpha_shape.set_alpha(scene.alpha_shape.get_nth_alpha(n));
} else {
Alpha_iterator alpha_end_it = scene.alpha_shape.alpha_end();
scene.alpha_shape.set_alpha((*(--alpha_end_it))+1);
}
} else {
scene.alpha_shape.set_alpha(0);
}
emit (alphaChanged());
}
void
MainWindow::open(const QString& fileName)
{
QApplication::setOverrideCursor(Qt::WaitCursor);
scene.alpha_shape.clear();
scene.points.clear();
std::ifstream ifs(qPrintable(fileName));
int n;
ifs >> n;
Point_3 p;
for(int i=0; i<n; i++){
ifs >> p;
scene.points.push_back(p);
}
timer.reset();
timer.start();
scene.alpha_shape.make_alpha_shape(scene.points.begin(), scene.points.end());
scene.alpha_shape.set_alpha(16);
timer.stop();
alphaSlider->setRange(0,100);
alphaSlider->setSliderPosition(50);
this->addToRecentFiles(fileName);
QApplication::restoreOverrideCursor();
emit (sceneChanged());
}
#include "MainWindow.moc"

View File

@ -1,40 +0,0 @@
#ifndef MAIN_WINDOW_H
#define MAIN_WINDOW_H
#include "typedefs.h"
#include "ui_MainWindow.h"
#include <CGAL/Qt/DemosMainWindow.h>
#include <QSlider>
#include <QFileDialog>
class QWidget;
class MainWindow : public CGAL::Qt::DemosMainWindow, private Ui::MainWindow
{
Q_OBJECT
public:
MainWindow(QWidget* parent = 0);
void connectActions();
Scene scene;
Timer timer;
public slots:
void open(const QString& fileName);
void open_file();
void alphaChanged(int i);
signals:
void sceneChanged();
void alphaChanged();
};
#endif

View File

@ -1,123 +0,0 @@
<ui version="4.0" >
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>635</width>
<height>504</height>
</rect>
</property>
<property name="windowTitle" >
<string>CGAL 3D Alpha Shape</string>
</property>
<property name="windowIcon" >
<iconset resource="../resources/CGAL.qrc" >
<normaloff>:/cgal/logos/cgal_icon</normaloff>:/cgal/logos/cgal_icon</iconset>
</property>
<widget class="QWidget" name="centralwidget" >
<layout class="QVBoxLayout" >
<item>
<layout class="QHBoxLayout" >
<item>
<widget class="QLabel" name="alphaLabel" >
<property name="font" >
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text" >
<string>&amp;alpha:</string>
</property>
<property name="buddy" >
<cstring>alphaBox</cstring>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="alphaBox" >
<property name="suffix" >
<string>%</string>
</property>
<property name="maximum" >
<number>100</number>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="alphaSlider" >
<property name="maximum" >
<number>100</number>
</property>
<property name="singleStep" >
<number>1</number>
</property>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Viewer" native="1" name="viewer" />
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>635</width>
<height>19</height>
</rect>
</property>
<widget class="QMenu" name="menuFile" >
<property name="title" >
<string>File</string>
</property>
<addaction name="actionLoad_New_File" />
<addaction name="actionLoad_Additional_File" />
<addaction name="separator" />
<addaction name="actionQuit" />
</widget>
<addaction name="menuFile" />
</widget>
<widget class="QStatusBar" name="statusbar" />
<action name="actionLoad_New_File" >
<property name="text" >
<string>Load New File</string>
</property>
</action>
<action name="actionLoad_Additional_File" >
<property name="text" >
<string>Load Additional File</string>
</property>
</action>
<action name="actionLoad_Points" >
<property name="text" >
<string>Load Points</string>
</property>
</action>
<action name="actionQuit" >
<property name="text" >
<string>Quit</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
<class>Viewer</class>
<extends>QWidget</extends>
<header>Viewer.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="../resources/CGAL.qrc" />
<include location="Alpha_shape_3.qrc" />
</resources>
<connections/>
</ui>

View File

@ -1,138 +0,0 @@
#include "Viewer.h"
#include <vector>
#include <CGAL/bounding_box.h>
#include <QGLViewer/vec.h>
void
Viewer::sceneChanged()
{
Iso_cuboid_3 bb = CGAL::bounding_box(scene->points.begin(), scene->points.end());
this->camera()->setSceneBoundingBox(qglviewer::Vec(bb.xmin(), bb.ymin(), bb.zmin()),
qglviewer::Vec(bb.xmax(),
bb.ymax(),
bb.zmax()));
this->showEntireScene();
}
void
Viewer::draw()
{
// define material
float ambient[] = { 0.25f,
0.20725f,
0.20725f,
0.922f };
float diffuse[] = { 1.0f,
0.829f,
0.829f,
0.922f };
float specular[] = { 0.296648f,
0.296648f,
0.296648f,
0.522f };
float emission[] = { 0.3f,
0.3f,
0.3f,
1.0f };
float shininess[] = { 11.264f };
// apply material
::glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT, ambient);
::glMaterialfv( GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse);
::glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, specular);
::glMaterialfv( GL_FRONT_AND_BACK, GL_SHININESS, shininess);
::glMaterialfv( GL_FRONT_AND_BACK, GL_EMISSION, emission);
// anti-aliasing (if the OpenGL driver permits that)
::glEnable(GL_LINE_SMOOTH);
::glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
// draw surface mesh
bool m_view_surface = true;
bool draw_triangles_edges = true;
if(m_view_surface)
{
::glEnable(GL_LIGHTING);
::glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
::glColor3f(0.2f, 0.2f, 1.f);
::glEnable(GL_POLYGON_OFFSET_FILL);
::glPolygonOffset(3.0f,-3.0f);
gl_draw_surface();
if(draw_triangles_edges)
{
::glDisable(GL_LIGHTING);
::glLineWidth(1.);
::glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
::glColor3ub(0,0,0);
::glDisable(GL_POLYGON_OFFSET_FILL);
gl_draw_surface();
}
}
}
void
Viewer::gl_draw_surface()
{
::glColor3f(1.0f, 0.0f, 0.0f);
::glDisable(GL_LIGHTING);
::glEnable(GL_POINT_SMOOTH);
::glPointSize(5);
::glBegin(GL_POINTS);
for(std::list<Point_3>::iterator it = scene->points.begin();
it != scene->points.end();
++it){
::glVertex3d(it->x(), it->y(), it->z());
}
::glEnd();
::glDisable(GL_POINT_SMOOTH);
::glEnable(GL_LIGHTING);
::glBegin(GL_TRIANGLES);
::glColor3f(0.2f, 1.0f, 0.2f);
std::list<Facet> facets;
scene->alpha_shape.get_alpha_shape_facets(std::back_inserter(facets), Alpha_shape_3::REGULAR);
for(std::list<Facet>::iterator fit = facets.begin();
fit != facets.end();
++fit) {
const Cell_handle& ch = fit->first;
const int index = fit->second;
//const Vector_3& n = ch->normal(index); // must be unit vector
const Point_3& a = ch->vertex((index+1)&3)->point();
const Point_3& b = ch->vertex((index+2)&3)->point();
const Point_3& c = ch->vertex((index+3)&3)->point();
Vector_3 v = CGAL::unit_normal(a,b,c);
::glNormal3d(v.x(),v.y(),v.z());
::glVertex3d(a.x(),a.y(),a.z());
::glVertex3d(b.x(),b.y(),b.z());
::glVertex3d(c.x(),c.y(),c.z());
}
::glEnd();
}
#include "Viewer.moc"

View File

@ -1,39 +0,0 @@
#ifndef VIEWER_H
#define VIEWER_H
#include "typedefs.h"
#include <QGLViewer/qglviewer.h>
class Viewer : public QGLViewer {
Q_OBJECT
CGAL::Timer timer;
Scene* scene;
int nr_of_facets;
public:
Viewer(QWidget* parent)
: QGLViewer(parent)
{}
void setScene(Scene* scene_)
{
scene = scene_;
}
void clear();
public:
void draw();
void
gl_draw_surface();
public slots :
void sceneChanged();
};
#endif

View File

@ -1,10 +0,0 @@
<html>
<body>
<h2>3D Alpha Shapes</h2>
<p>Copyright &copy; 2008 GeometryFactory</p>
<p>This application illustrates the 3D Alpha shapes
of <a href="http://www.cgal.org/">CGAL</a>.</p>
<p>See also <a href="http://www.cgal.org/Pkg/AlphaShapes3">the online
manual</a>.</p>
</body>
</html>

View File

@ -1,73 +0,0 @@
#ifndef TYPEDEFS_H
#define TYPEDEFS_H
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Alpha_shape_vertex_base_3.h>
#include <CGAL/Alpha_shape_cell_base_3.h>
#include <CGAL/Triangulation_data_structure_3.h>
#include <CGAL/Delaunay_triangulation_3.h>
#include <CGAL/Alpha_shape_3.h>
#include <CGAL/Timer.h>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <fstream>
#include <vector>
#include <list>
typedef double coord_type;
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef K::Point_3 Point_3;
typedef K::Vector_3 Vector_3;
typedef K::Segment_3 Segment_3;
typedef K::Ray_3 Ray_3;
typedef K::Line_3 Line;
typedef K::Triangle_3 Triangle_3;
typedef K::Iso_cuboid_3 Iso_cuboid_3;
typedef CGAL::Alpha_shape_vertex_base_3<K> Vb;
typedef CGAL::Alpha_shape_cell_base_3<K> Fb;
typedef CGAL::Triangulation_data_structure_3<Vb,Fb> Tds;
typedef CGAL::Delaunay_triangulation_3<K,Tds> Triangulation_3;
typedef CGAL::Alpha_shape_3<Triangulation_3> Alpha_shape_3;
typedef Alpha_shape_3::Cell Cell;
typedef Alpha_shape_3::Vertex Vertex;
typedef Alpha_shape_3::Edge Edge;
typedef Alpha_shape_3::Facet Facet;
typedef Alpha_shape_3::Cell_handle Cell_handle;
typedef Alpha_shape_3::Vertex_handle Vertex_handle;
typedef Alpha_shape_3::Cell_circulator Cell_circulator;
typedef Alpha_shape_3::Locate_type Locate_type;
typedef Alpha_shape_3::Cell_iterator Cell_iterator;
typedef Alpha_shape_3::Vertex_iterator Vertex_iterator;
typedef Alpha_shape_3::Edge_iterator Edge_iterator;
typedef Alpha_shape_3::Coord_type Coord_type;
typedef Alpha_shape_3::Alpha_iterator Alpha_iterator;
typedef CGAL::Timer Timer;
struct Scene {
Alpha_shape_3 alpha_shape;
std::list<Point_3> points;
};
#endif