diff --git a/.gitattributes b/.gitattributes index a3268688d46..dbd37abeefd 100644 --- a/.gitattributes +++ b/.gitattributes @@ -168,6 +168,7 @@ Alpha_shapes_2/demo/Alpha_shapes_2/help/index.html svneol=native#text/html Alpha_shapes_2/doc_tex/Alpha_shapes_2/alpha-detail.png -text Alpha_shapes_2/doc_tex/Alpha_shapes_2/alphashape.pdf -text svneol=unset#application/pdf Alpha_shapes_2/doc_tex/Alpha_shapes_2/alphashape.png -text +Alpha_shapes_3/demo/MainWindow.ui -text Alpha_shapes_3/doc_tex/Alpha_shapes_3/alpha_shapes_3_large.png -text Alpha_shapes_3/doc_tex/Alpha_shapes_3/alpha_shapes_3_small.png -text Alpha_shapes_3/doc_tex/Alpha_shapes_3/alphashape.gif -text svneol=unset#image/gif diff --git a/Alpha_shapes_3/demo/Alpha_shape_3.cpp b/Alpha_shapes_3/demo/Alpha_shape_3.cpp new file mode 100644 index 00000000000..b0c30008d8e --- /dev/null +++ b/Alpha_shapes_3/demo/Alpha_shape_3.cpp @@ -0,0 +1,26 @@ + +#include "MainWindow.h" +#include "typedefs.h" +#include + + + + +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(); +} diff --git a/Alpha_shapes_3/demo/CMakeLists.txt b/Alpha_shapes_3/demo/CMakeLists.txt new file mode 100644 index 00000000000..4c2f5942ce6 --- /dev/null +++ b/Alpha_shapes_3/demo/CMakeLists.txt @@ -0,0 +1,53 @@ +# 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() diff --git a/Alpha_shapes_3/demo/MainWindow.cpp b/Alpha_shapes_3/demo/MainWindow.cpp new file mode 100644 index 00000000000..717cff353e5 --- /dev/null +++ b/Alpha_shapes_3/demo/MainWindow.cpp @@ -0,0 +1,111 @@ + +#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> 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" + diff --git a/Alpha_shapes_3/demo/MainWindow.h b/Alpha_shapes_3/demo/MainWindow.h new file mode 100644 index 00000000000..aa722a91458 --- /dev/null +++ b/Alpha_shapes_3/demo/MainWindow.h @@ -0,0 +1,40 @@ +#ifndef MAIN_WINDOW_H +#define MAIN_WINDOW_H + +#include "typedefs.h" +#include "ui_MainWindow.h" +#include +#include +#include +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 diff --git a/Alpha_shapes_3/demo/MainWindow.ui b/Alpha_shapes_3/demo/MainWindow.ui new file mode 100644 index 00000000000..89880aea5b7 --- /dev/null +++ b/Alpha_shapes_3/demo/MainWindow.ui @@ -0,0 +1,123 @@ + + MainWindow + + + + 0 + 0 + 635 + 504 + + + + CGAL 3D Alpha Shape + + + + :/cgal/logos/cgal_icon:/cgal/logos/cgal_icon + + + + + + + + + + 75 + true + + + + &alpha: + + + alphaBox + + + + + + + % + + + 100 + + + + + + + 100 + + + 1 + + + Qt::Horizontal + + + + + + + + + + + + + + 0 + 0 + 635 + 19 + + + + + File + + + + + + + + + + + + Load New File + + + + + Load Additional File + + + + + Load Points + + + + + Quit + + + + + + Viewer + QWidget +
Viewer.h
+
+
+ + + + + +
diff --git a/Alpha_shapes_3/demo/Viewer.cpp b/Alpha_shapes_3/demo/Viewer.cpp new file mode 100644 index 00000000000..38427769a6d --- /dev/null +++ b/Alpha_shapes_3/demo/Viewer.cpp @@ -0,0 +1,138 @@ +#include "Viewer.h" +#include +#include +#include + + + + +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::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 facets; + scene->alpha_shape.get_alpha_shape_facets(std::back_inserter(facets), Alpha_shape_3::REGULAR); + + for(std::list::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" diff --git a/Alpha_shapes_3/demo/Viewer.h b/Alpha_shapes_3/demo/Viewer.h new file mode 100644 index 00000000000..65b42adf368 --- /dev/null +++ b/Alpha_shapes_3/demo/Viewer.h @@ -0,0 +1,39 @@ +#ifndef VIEWER_H +#define VIEWER_H + +#include "typedefs.h" +#include + + +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 diff --git a/Alpha_shapes_3/demo/about_Alpha_shapes_3.html b/Alpha_shapes_3/demo/about_Alpha_shapes_3.html new file mode 100644 index 00000000000..9bb2ab7827b --- /dev/null +++ b/Alpha_shapes_3/demo/about_Alpha_shapes_3.html @@ -0,0 +1,10 @@ + + +

3D Alpha Shapes

+

Copyright © 2008 GeometryFactory

+

This application illustrates the 3D Alpha shapes + of CGAL.

+

See also the online + manual.

+ + diff --git a/Alpha_shapes_3/demo/typedefs.h b/Alpha_shapes_3/demo/typedefs.h new file mode 100644 index 00000000000..f130972c491 --- /dev/null +++ b/Alpha_shapes_3/demo/typedefs.h @@ -0,0 +1,73 @@ +#ifndef TYPEDEFS_H +#define TYPEDEFS_H + + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + + + +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 Vb; +typedef CGAL::Alpha_shape_cell_base_3 Fb; + +typedef CGAL::Triangulation_data_structure_3 Tds; +typedef CGAL::Delaunay_triangulation_3 Triangulation_3; + +typedef CGAL::Alpha_shape_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 points; +}; + + + +#endif