diff --git a/.gitattributes b/.gitattributes index 159c2ac90fa..e26119e092b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1297,6 +1297,9 @@ GraphicsView/TODO -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 +GraphicsView/demo/Generator/Generator_2.qrc -text +GraphicsView/demo/Generator/Generator_2.ui -text +GraphicsView/demo/Generator/about_Generator_2.html svneol=native#text/html GraphicsView/demo/Polygon/Polygon_2.qrc -text GraphicsView/demo/Polygon/Polygon_2.ui -text GraphicsView/demo/Segment_Delaunay_graph_2/Segment_voronoi_2.qrc -text diff --git a/GraphicsView/demo/Generator/CMakeLists.txt b/GraphicsView/demo/Generator/CMakeLists.txt new file mode 100644 index 00000000000..6a886b01ab2 --- /dev/null +++ b/GraphicsView/demo/Generator/CMakeLists.txt @@ -0,0 +1,56 @@ +# Created by the script cgal_create_cmake_script +# This is the CMake script for compiling a CGAL application. + +project (GeneratorDemo) + +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) + +include_directories (BEFORE ../../include) + +if ( CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND ) + + include(${QT_USE_FILE}) + #-------------------------------- + # Demo: Generator_2 + #-------------------------------- + # UI files (Qt Designer files) + qt4_wrap_ui( DT_UI_FILES Generator_2.ui ) + + # qrc files (resources files, that contain icons, at least) + qt4_add_resources ( DT_RESOURCE_FILES ./Generator_2.qrc ) + + # use the Qt MOC preprocessor on classes that derives from QObject + qt4_generate_moc( Generator_2.cpp Generator_2.moc ) + + # The executable itself. + add_executable ( Generator_2 Generator_2.cpp Generator_2.moc ${DT_UI_FILES} ${DT_RESOURCE_FILES} ) + + add_to_cached_list( CGAL_EXECUTABLE_TARGETS Generator_2 ) + + # Link with Qt libraries + target_link_libraries( Generator_2 ${QT_LIBRARIES} ) + # And with CGAL libraries + target_link_libraries( Generator_2 ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES} ) + +else() + + message(STATUS "NOTICE: This demo requires CGAL, and Qt4, and will not be compiled.") + +endif() diff --git a/GraphicsView/demo/Generator/Generator_2.cpp b/GraphicsView/demo/Generator/Generator_2.cpp new file mode 100644 index 00000000000..d0588069380 --- /dev/null +++ b/GraphicsView/demo/Generator/Generator_2.cpp @@ -0,0 +1,293 @@ +#include +// CGAL headers +#include +#include +#include +#include +#include + +// Qt headers +#include +#include +#include +#include + +// GraphicsView items and event filters (input classes) +#include +#include +#include + +// the two base classes +#include "ui_Generator_2.h" +#include + +typedef CGAL::Exact_predicates_inexact_constructions_kernel K; +typedef K::Point_2 Point_2; +typedef K::Vector_2 Vector_2; +typedef K::Segment_2 Segment_2; +typedef K::Iso_rectangle_2 Iso_rectangle_2; + +class MainWindow : + public CGAL::Qt::DemosMainWindow, + public Ui::Generator_2 +{ + Q_OBJECT + +private: + + + + CGAL::Qt::Converter convert; + std::vector points; + std::vector segments; + QGraphicsScene scene; + + CGAL::Qt::PointsGraphicsItem > * pgi; + CGAL::Qt::SegmentsGraphicsItem > * sgi; + + + template + void + on_actionGenerate_triggered() + { + QRectF rect = CGAL::Qt::viewportsBbox(&scene); + CGAL::Qt::Converter convert; + Iso_rectangle_2 isor = convert(rect); + Point_2 center = CGAL::midpoint(isor[0], isor[2]); + Vector_2 offset = center - CGAL::ORIGIN; + double w = isor.xmax() - isor.xmin(); + double h = isor.ymax() - isor.ymin(); + double radius = (w::max(), + 1, + &ok); + + if(!ok) { + return; + } + + // wait cursor + QApplication::setOverrideCursor(Qt::WaitCursor); + + points.reserve(points.size() + number_of_points); + for(int i = 0; i < number_of_points; ++i){ + points.push_back(*pg + offset); + ++pg; + } + // default cursor + QApplication::restoreOverrideCursor(); + emit(changed()); + } + +public: + MainWindow(); + +public slots: + + void on_actionClear_triggered(); + + + void on_actionRecenter_triggered(); + void on_actionGeneratePointsOnCircle_triggered(); + void on_actionGeneratePointsInSquare_triggered(); + void on_actionGeneratePointsInDisc_triggered(); + void on_actionGenerateSegments_triggered(); + void on_actionGenerateSegmentFans_triggered(); + void clear(); + +signals: + void changed(); +}; + + +MainWindow::MainWindow() + : DemosMainWindow() +{ + setupUi(this); + + // Add a GraphicItem for the point set + pgi = new CGAL::Qt::PointsGraphicsItem >(&points); + sgi = new CGAL::Qt::SegmentsGraphicsItem >(&segments); + + QObject::connect(this, SIGNAL(changed()), + pgi, SLOT(modelChanged())); + + + QObject::connect(this, SIGNAL(changed()), + sgi, SLOT(modelChanged())); + + pgi->setVerticesPen(QPen(Qt::red, 3, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); + sgi->setVerticesPen(QPen(Qt::red, 3, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); + scene.addItem(pgi); + scene.addItem(sgi); + + + // + // Manual handling of actions + // + QObject::connect(this->actionQuit, SIGNAL(triggered()), + this, SLOT(close())); + + + // + // Setup the scene and the view + // + scene.setItemIndexMethod(QGraphicsScene::NoIndex); + scene.setSceneRect(-100, -100, 100, 100); + this->graphicsView->setScene(&scene); + + // Uncomment the following line to get antialiasing by default. +// actionUse_Antialiasing->setChecked(true); + + // Turn the vertical axis upside down + this->graphicsView->scale(1, -1); + + // The navigation adds zooming and translation functionality to the + // QGraphicsView + this->addNavigation(this->graphicsView); + + this->setupStatusBar(); + this->setupOptionsMenu(); + this->addAboutDemo(":/cgal/help/about_Generator_2.html"); + this->addAboutCGAL(); + +} + + +/* + * Qt Automatic Connections + * http://doc.trolltech.com/4.4/designer-using-a-component.html#automatic-connections + * + * setupUi(this) generates connections to the slots named + * "on__" + */ + +void +MainWindow::on_actionClear_triggered() +{ + clear(); + emit(changed()); +} + +void +MainWindow::on_actionRecenter_triggered() +{ + this->graphicsView->setSceneRect(pgi->boundingRect()); + this->graphicsView->fitInView(pgi->boundingRect(), Qt::KeepAspectRatio); +} + +void +MainWindow::on_actionGeneratePointsOnCircle_triggered() +{ + typedef CGAL::Random_points_on_circle_2 Generator; + on_actionGenerate_triggered(); +} + + +void +MainWindow::on_actionGeneratePointsInSquare_triggered() +{ + typedef CGAL::Random_points_in_square_2 Generator; + on_actionGenerate_triggered(); +} + + +void +MainWindow::on_actionGeneratePointsInDisc_triggered() +{ + typedef CGAL::Random_points_in_disc_2 Generator; + on_actionGenerate_triggered(); +} + + +void +MainWindow::on_actionGenerateSegments_triggered() +{ + segments.reserve(segments.size() + 200); + + // Prepare point generator for the horizontal segment, length 200. + typedef CGAL::Random_points_on_segment_2 Rpos_generator; + Rpos_generator rpos( Point_2(-100,0), Point_2(100,0)); + + // Prepare point generator for random points on circle, radius 250. + typedef CGAL::Random_points_on_circle_2 Rpoc_generator; + Rpoc_generator rpoc( 250); + + // Create 200 segments. + typedef CGAL::Creator_uniform_2< Point_2, Segment_2> Seg_creator; + typedef CGAL::Join_input_iterator_2< Rpos_generator, Rpoc_generator, Seg_creator> Seg_iterator; + Seg_iterator g( rpos, rpoc); + CGAL::copy_n( g, 200, std::back_inserter(segments)); + + emit(changed()); +} + + +void +MainWindow::on_actionGenerateSegmentFans_triggered() +{ + typedef CGAL::Points_on_segment_2 PG; + typedef CGAL::Creator_uniform_2< Point_2, Segment_2> Creator; + typedef CGAL::Join_input_iterator_2< PG, PG, Creator> Segm_iterator; + typedef CGAL::Counting_iterator Count_iterator; + + segments.reserve(segments.size() + 100); + + // A horizontal like fan. + PG p1( Point_2(-250, -50), Point_2(-250, 50),50); // Point generator. + PG p2( Point_2( 250,-250), Point_2( 250,250),50); + Segm_iterator t1( p1, p2); // Segment generator. + Count_iterator t1_begin( t1); // Finite range. + Count_iterator t1_end( 50); + std::copy( t1_begin, t1_end, std::back_inserter(segments)); + + // A vertical like fan. + PG p3( Point_2( -50,-250), Point_2( 50,-250),50); + PG p4( Point_2(-250, 250), Point_2( 250, 250),50); + Segm_iterator t2( p3, p4); + Count_iterator t2_begin( t2); + Count_iterator t2_end( 50); + std::copy( t2_begin, t2_end, std::back_inserter(segments)); + + emit(changed()); +} + + +void +MainWindow::clear() +{ + points.clear(); + segments.clear(); +} + + +#include "Generator_2.moc" + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + app.setOrganizationDomain("geometryfactory.com"); + app.setOrganizationName("GeometryFactory"); + app.setApplicationName("Generator_2 demo"); + + // Import resources from libCGALQt4. + // See http://doc.trolltech.com/4.4/qdir.html#Q_INIT_RESOURCE + Q_INIT_RESOURCE(File); + Q_INIT_RESOURCE(Generator_2); + Q_INIT_RESOURCE(Input); + Q_INIT_RESOURCE(CGAL); + + MainWindow mainWindow; + mainWindow.show(); + return app.exec(); +} diff --git a/GraphicsView/demo/Generator/Generator_2.qrc b/GraphicsView/demo/Generator/Generator_2.qrc new file mode 100644 index 00000000000..80f34477ca7 --- /dev/null +++ b/GraphicsView/demo/Generator/Generator_2.qrc @@ -0,0 +1,6 @@ + + + ../resources/about_CGAL.html + about_Generator_2.html + + diff --git a/GraphicsView/demo/Generator/Generator_2.ui b/GraphicsView/demo/Generator/Generator_2.ui new file mode 100644 index 00000000000..2206a6ef322 --- /dev/null +++ b/GraphicsView/demo/Generator/Generator_2.ui @@ -0,0 +1,252 @@ + + + GeometryFactory + Generator_2 + + + + 0 + 0 + 568 + 325 + + + + CGAL 2D Generator + + + + :/cgal/logos/cgal_icon:/cgal/logos/cgal_icon + + + + + + + Qt::Horizontal + + + + + 2 + 0 + + + + Qt::StrongFocus + + + Qt::ScrollBarAlwaysOn + + + Qt::ScrollBarAlwaysOn + + + QGraphicsView::NoAnchor + + + + + + + + + + File Tools + + + TopToolBarArea + + + false + + + + + + Visualization Tools + + + TopToolBarArea + + + false + + + + + + + 0 + 0 + 568 + 26 + + + + + &File + + + + + + + + + &Algorithms + + + + + + + + + + + + + + + &About + + + + + About &CGAL + + + + + &Quit + + + Ctrl+Q + + + + + + :/cgal/fileToolbar/fileNew.png:/cgal/fileToolbar/fileNew.png + + + &Clear + + + Ctrl+C + + + + + + :/cgal/fileToolbar/fileOpen.png:/cgal/fileToolbar/fileOpen.png + + + &Load Generator + + + Ctrl+L + + + + + + :/cgal/fileToolbar/fileSave.png:/cgal/fileToolbar/fileSave.png + + + &Save Generator + + + Ctrl+S + + + + + + :/cgal/Input/zoom-best-fit:/cgal/Input/zoom-best-fit + + + Re&center the viewport + + + Ctrl+R + + + + + Y-monotone Partition + + + + + true + + + Create Input Generator + + + + + Inner Skeleton + + + + + Outer Offset + + + + + Optimal Convex Partition + + + + + Approximate Convex Partition + + + + + Linear Least Squares Fitting of Points + + + + + Linear Least Squares Fitting of Segments + + + + + Generate Points on Circle + + + + + Generate Points in Square + + + + + Generate Segments + + + + + Generate Points in Disc + + + + + Generate Segment Fans + + + + + + + + + + + diff --git a/GraphicsView/demo/Generator/about_Generator_2.html b/GraphicsView/demo/Generator/about_Generator_2.html new file mode 100644 index 00000000000..a3a807a4bf3 --- /dev/null +++ b/GraphicsView/demo/Generator/about_Generator_2.html @@ -0,0 +1,10 @@ + + +

2D Object Generators

+

Copyright © 2010 GeometryFactory

+

This application illustrates the 2D object generators + of CGAL

+

See also the online + manual.

+ +