diff --git a/.gitattributes b/.gitattributes index b373f49574c..5cfca6a561e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1432,6 +1432,9 @@ 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/Largest_empty_rect_2/Largest_empty_rectangle_2.qrc -text +GraphicsView/demo/Largest_empty_rect_2/Largest_empty_rectangle_2.ui -text +GraphicsView/demo/Largest_empty_rect_2/about_Largest_empty_rectangle_2.html svneol=native#text/html GraphicsView/demo/Polygon/Polygon_2.qrc -text GraphicsView/demo/Polygon/Polygon_2.ui -text GraphicsView/demo/Polygon/unweighted_polygon.poly -text diff --git a/GraphicsView/demo/Largest_empty_rect_2/CMakeLists.txt b/GraphicsView/demo/Largest_empty_rect_2/CMakeLists.txt new file mode 100644 index 00000000000..23ff0246ba8 --- /dev/null +++ b/GraphicsView/demo/Largest_empty_rect_2/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 (Largest_empty_rectangleDemo) + +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: Largest_empty_rectangle_2 + #-------------------------------- + # UI files (Qt Designer files) + qt4_wrap_ui( DT_UI_FILES Largest_empty_rectangle_2.ui ) + + # qrc files (resources files, that contain icons, at least) + qt4_add_resources ( DT_RESOURCE_FILES ./Largest_empty_rectangle_2.qrc ) + + # use the Qt MOC preprocessor on classes that derives from QObject + qt4_generate_moc( Largest_empty_rectangle_2.cpp Largest_empty_rectangle_2.moc ) + + # The executable itself. + add_executable ( Largest_empty_rectangle_2 Largest_empty_rectangle_2.cpp Largest_empty_rectangle_2.moc ${DT_UI_FILES} ${DT_RESOURCE_FILES} ) + + add_to_cached_list( CGAL_EXECUTABLE_TARGETS Largest_empty_rectangle_2 ) + + # Link with Qt libraries + target_link_libraries( Largest_empty_rectangle_2 ${QT_LIBRARIES} ) + # And with CGAL libraries + target_link_libraries( Largest_empty_rectangle_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/Largest_empty_rect_2/Largest_empty_rectangle_2.cpp b/GraphicsView/demo/Largest_empty_rect_2/Largest_empty_rectangle_2.cpp new file mode 100644 index 00000000000..c0a28dd1dab --- /dev/null +++ b/GraphicsView/demo/Largest_empty_rect_2/Largest_empty_rectangle_2.cpp @@ -0,0 +1,288 @@ +#include +// CGAL headers +#include +#include +#include + +// Qt headers +#include +#include +#include +#include +#include + +// GraphicsView items and event filters (input classes) +#include +#include +#include + +// the two base classes +#include "ui_Largest_empty_rectangle_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; +typedef CGAL::Largest_empty_iso_rectangle_2 Largest_empty_iso_rectangle_2; + + +class MainWindow : + public CGAL::Qt::DemosMainWindow, + public Ui::Largest_empty_rectangle_2 +{ + Q_OBJECT + +private: + + Iso_rectangle_2 square; + Largest_empty_iso_rectangle_2 ler; + CGAL::Qt::Converter convert; + std::vector points; + QGraphicsScene scene; + + CGAL::Qt::PointsGraphicsItem > * pgi; + QGraphicsRectItem * rgi; + QGraphicsLineItem* frame[4]; + CGAL::Qt::GraphicsViewPolylineInput * pi; + + template + void + on_actionGenerate_triggered() + { + Iso_rectangle_2 isor = square; + 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); + ler.insert(points.back()); + ++pg; + } + + // default cursor + QApplication::restoreOverrideCursor(); + emit(changed()); + } + +public: + MainWindow(); + +public slots: + + void on_actionClear_triggered(); + + void processInput(CGAL::Object); + + void on_actionRecenter_triggered(); + void on_actionGeneratePointsOnCircle_triggered(); + void on_actionGeneratePointsInSquare_triggered(); + void on_actionGeneratePointsInDisc_triggered(); + void clear(); + + void update_largest_empty_rectangle(); + +signals: + void changed(); +}; + + +MainWindow::MainWindow() + : DemosMainWindow(), square(Point_2(-1, -1), Point_2(1,1)), ler(square) +{ + setupUi(this); + + // Add a GraphicItem for the point set + pgi = new CGAL::Qt::PointsGraphicsItem >(&points); + + rgi = new QGraphicsRectItem(convert(square)); + + Point_2 bl(-1,-1), br(1,-1), tl(-1,1), tr(1,1); + + frame[0] = new QGraphicsLineItem(convert(Segment_2(bl, br))); + frame[1] = new QGraphicsLineItem(convert(Segment_2(br, tr))); + frame[2] = new QGraphicsLineItem(convert(Segment_2(tr, tl))); + frame[3] = new QGraphicsLineItem(convert(Segment_2(tl, bl))); + + QObject::connect(this, SIGNAL(changed()), + pgi, SLOT(modelChanged())); + + QObject::connect(this, SIGNAL(changed()), + this, SLOT(update_largest_empty_rectangle())); + + pgi->setVerticesPen(QPen(Qt::red, 3, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); + rgi->setBrush(QBrush(Qt::cyan)); + scene.addItem(pgi); + scene.addItem(rgi); + scene.addItem(frame[0]); + scene.addItem(frame[1]); + scene.addItem(frame[2]); + scene.addItem(frame[3]); + + // + // Manual handling of actions + // + QObject::connect(this->actionQuit, SIGNAL(triggered()), + this, SLOT(close())); + + + pi = new CGAL::Qt::GraphicsViewPolylineInput(this, &scene, 1, false); // inputs a list with one point + QObject::connect(pi, SIGNAL(generate(CGAL::Object)), + this, SLOT(processInput(CGAL::Object))); + + scene.installEventFilter(pi); + // + // Setup the scene and the view + // + scene.setItemIndexMethod(QGraphicsScene::NoIndex); + scene.setSceneRect(-1, -1, 1, 1); + 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_Largest_empty_rectangle_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::processInput(CGAL::Object o) +{ + std::list input; + if(CGAL::assign(input, o)){ + if(input.size() == 1) { + Point_2 p = input.front(); + if(! square.has_on_unbounded_side(p)){ + points.push_back(p); + ler.insert(p); + } + } + emit(changed()); + } + +} + + +void +MainWindow::update_largest_empty_rectangle() +{ + rgi->setRect(convert(ler.get_largest_empty_iso_rectangle())); +} + + +void +MainWindow::on_actionClear_triggered() +{ + clear(); + emit(changed()); +} + +void +MainWindow::on_actionRecenter_triggered() +{ + this->graphicsView->setSceneRect(convert(square)); + this->graphicsView->fitInView(convert(square), 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::clear() +{ + points.clear(); + ler.clear(); + rgi->setRect(convert(square)); +} + + +#include "Largest_empty_rectangle_2.moc" + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + app.setOrganizationDomain("geometryfactory.com"); + app.setOrganizationName("GeometryFactory"); + app.setApplicationName("Largest_empty_rectangle_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(Largest_empty_rectangle_2); + Q_INIT_RESOURCE(Input); + Q_INIT_RESOURCE(CGAL); + + MainWindow mainWindow; + mainWindow.show(); + mainWindow.on_actionRecenter_triggered(); + return app.exec(); +} diff --git a/GraphicsView/demo/Largest_empty_rect_2/Largest_empty_rectangle_2.qrc b/GraphicsView/demo/Largest_empty_rect_2/Largest_empty_rectangle_2.qrc new file mode 100644 index 00000000000..4de66265cbc --- /dev/null +++ b/GraphicsView/demo/Largest_empty_rect_2/Largest_empty_rectangle_2.qrc @@ -0,0 +1,6 @@ + + + ../resources/about_CGAL.html + about_Largest_empty_rectangle_2.html + + diff --git a/GraphicsView/demo/Largest_empty_rect_2/Largest_empty_rectangle_2.ui b/GraphicsView/demo/Largest_empty_rect_2/Largest_empty_rectangle_2.ui new file mode 100644 index 00000000000..19c46f07374 --- /dev/null +++ b/GraphicsView/demo/Largest_empty_rect_2/Largest_empty_rectangle_2.ui @@ -0,0 +1,210 @@ + + + GeometryFactory + Largest_empty_rectangle_2 + + + + 0 + 0 + 500 + 500 + + + + CGAL 2D Largest Empty Iso Rectangle + + + + :/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 + 500 + 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 + + + + + true + + + Create Input Generator + + + + + Generate Points on Circle + + + + + Generate Points in Square + + + + + Generate Points in Disc + + + + + Generate Segment Fans + + + + + + + + + + + diff --git a/GraphicsView/demo/Largest_empty_rect_2/about_Largest_empty_rectangle_2.html b/GraphicsView/demo/Largest_empty_rect_2/about_Largest_empty_rectangle_2.html new file mode 100644 index 00000000000..9de593cb8b2 --- /dev/null +++ b/GraphicsView/demo/Largest_empty_rect_2/about_Largest_empty_rectangle_2.html @@ -0,0 +1,10 @@ + + +

2D Largest Empty Iso Rectangle

+

Copyright © 2010 GeometryFactory

+

This application illustrates the 2D largest empty iso rectangle + of CGAL

+

See also the online + manual.

+ +