Add missing files

This commit is contained in:
Maxime Gimeno 2019-01-30 10:15:31 +01:00
parent b7d4a081c7
commit 0cbb165b9f
2 changed files with 803 additions and 0 deletions

View File

@ -0,0 +1,432 @@
#include <fstream>
// CGAL headers
#define USE_CORE_EXPR_KERNEL
#ifndef USE_CORE_EXPR_KERNEL
#include <CGAL/Exact_circular_kernel_2.h>
#include <CGAL/Hyperbolic_Delaunay_triangulation_CK_traits_2.h>
#include <internal/Qt/HyperbolicPainterOstreamCK.h>
#else
#include <CGAL/Cartesian.h>
#include <CGAL/CORE_Expr.h>
#include <CGAL/Hyperbolic_Delaunay_triangulation_traits_2.h>
#include <internal/Qt/HyperbolicPainterOstream.h>
#endif
#include <CGAL/Hyperbolic_Delaunay_triangulation_2.h>
#include <CGAL/point_generators_2.h>
// Qt headers
#include <QtGui>
#include <QString>
#include <QActionGroup>
#include <QFileDialog>
#include <QInputDialog>
#include <QGraphicsEllipseItem>
// GraphicsView items and event filters (input classes)
#include <internal/Qt/TriangulationCircumcircle.h>
#include <internal/Qt/TriangulationConflictZone.h>
#include <internal/Qt/TriangulationPointInputAndConflictZone.h>
#include <internal/Qt/TriangulationGraphicsItem.h>
#include <internal/Qt/HyperbolicVoronoiGraphicsItem.h>
// for viewportsBbox
#include <CGAL/Qt/utility.h>
// the two base classes
#include <CGAL/Qt/DemosMainWindow.h>
#include "ui_HDT2.h"
#ifndef USE_CORE_EXPR_KERNEL
typedef CGAL::Hyperbolic_Delaunay_triangulation_CK_traits_2<> K;
#else
typedef CGAL::Hyperbolic_Delaunay_triangulation_traits_2<> K;
#endif
typedef K::Point_2 Point_2;
typedef K::Iso_rectangle_2 Iso_rectangle_2;
typedef CGAL::Hyperbolic_Delaunay_triangulation_2<K> Delaunay;
class MainWindow :
public CGAL::Qt::DemosMainWindow,
public Ui::Delaunay_triangulation_2
{
Q_OBJECT
private:
Delaunay dt;
QGraphicsEllipseItem* disk;
QGraphicsScene scene;
CGAL::Qt::TriangulationGraphicsItem<Delaunay> * dgi;
CGAL::Qt::VoronoiGraphicsItem<Delaunay> * vgi;
//CGAL::Qt::TriangulationMovingPoint<Delaunay> * mp;
CGAL::Qt::TriangulationConflictZone<Delaunay> * cz;
//CGAL::Qt::TriangulationRemoveVertex<Delaunay> * trv;
CGAL::Qt::TriangulationPointInputAndConflictZone<Delaunay> * pi;
CGAL::Qt::TriangulationCircumcircle<Delaunay> *tcc;
public:
MainWindow();
public slots:
void processInput(CGAL::Object o);
void on_actionShowConflictZone_toggled(bool checked);
void on_actionCircumcenter_toggled(bool checked);
void on_actionShowDelaunay_toggled(bool checked);
void on_actionShowVoronoi_toggled(bool checked);
void on_actionInsertPoint_toggled(bool checked);
void on_actionInsertRandomPoints_triggered();
void on_actionLoadPoints_triggered();
void on_actionSavePoints_triggered();
void on_actionClear_triggered();
void on_actionRecenter_triggered();
virtual void open(QString fileName);
signals:
void changed();
};
MainWindow::MainWindow()
: DemosMainWindow()
{
setupUi(this);
this->graphicsView->setAcceptDrops(false);
// Add Poincaré disk
qreal origin_x = 0, origin_y = 0, radius = 1, diameter = 2*radius;
qreal left_top_corner_x = origin_x - radius;
qreal left_top_corner_y = origin_y - radius;
qreal width = diameter, height = diameter;
disk = new QGraphicsEllipseItem(left_top_corner_x, left_top_corner_y, width, height);
QPen pen; // creates a default pen
pen.setWidthF(0.025);
pen.setBrush(Qt::black);
disk->setPen(pen);
scene.addItem(disk);
// Add a GraphicItem for the Delaunay triangulation
dgi = new CGAL::Qt::TriangulationGraphicsItem<Delaunay>(&dt);
QObject::connect(this, SIGNAL(changed()),
dgi, SLOT(modelChanged()));
QPen vpen;
vpen.setStyle(::Qt::SolidLine);
vpen.setWidth(15);
vpen.setBrush(::Qt::red);
vpen.setCapStyle(::Qt::RoundCap);
vpen.setJoinStyle(::Qt::RoundJoin);
dgi->setVerticesPen(vpen);
QPen epen;
epen.setWidthF(0.01);
epen.setBrush(::Qt::black);
dgi->setEdgesPen(epen);
scene.addItem(dgi);
// Add a GraphicItem for the Voronoi diagram
vgi = new CGAL::Qt::VoronoiGraphicsItem<Delaunay>(&dt);
QObject::connect(this, SIGNAL(changed()),
vgi, SLOT(modelChanged()));
vgi->setEdgesPen(QPen(Qt::blue, 0.01, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
scene.addItem(vgi);
vgi->hide();
// Setup input handlers. They get events before the scene gets them
// and the input they generate is passed to the triangulation with
// the signal/slot mechanism
pi = new CGAL::Qt::TriangulationPointInputAndConflictZone<Delaunay>(&scene, &dt, this);
QObject::connect(pi, SIGNAL(generate(CGAL::Object)),
this, SLOT(processInput(CGAL::Object)));
tcc = new CGAL::Qt::TriangulationCircumcircle<Delaunay>(&scene, &dt, this);
tcc->setPen(QPen(Qt::red, 0.005, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
cz = new CGAL::Qt::TriangulationConflictZone<Delaunay>(&scene, &dt, this);
//
// Manual handling of actions
//
QObject::connect(this->actionQuit, SIGNAL(triggered()),
this, SLOT(close()));
// We put mutually exclusive actions in an QActionGroup
QActionGroup* ag = new QActionGroup(this);
ag->addAction(this->actionInsertPoint);
//ag->addAction(this->actionMovingPoint);
ag->addAction(this->actionCircumcenter);
ag->addAction(this->actionShowConflictZone);
// Check two actions
this->actionInsertPoint->setChecked(true);
this->actionShowDelaunay->setChecked(true);
//
// Setup the scene and the view
//
scene.setItemIndexMethod(QGraphicsScene::NoIndex);
scene.setSceneRect(left_top_corner_x, left_top_corner_y, width, height);
this->graphicsView->setScene(&scene);
this->graphicsView->setMouseTracking(true);
// we want to adjust the coordinates of QGraphicsView to the coordinates of QGraphicsScene
// the following line must do this:
// this->graphicsView->fitInView( scene.sceneRect(), Qt::KeepAspectRatio);
// It does not do this sufficiently well.
// Current solution:
this->graphicsView->shear(230, 230);
// Turn the vertical axis upside down
this->graphicsView->matrix().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_Delaunay_triangulation_2.html");
this->addAboutCGAL();
this->addRecentFiles(this->menuFile, this->actionQuit);
connect(this, SIGNAL(openRecentFile(QString)),
this, SLOT(open(QString)));
}
void
MainWindow::processInput(CGAL::Object o)
{
Point_2 p;
if(CGAL::assign(p, o)){
QPointF qp(CGAL::to_double(p.x()), CGAL::to_double(p.y()));
// note that if the point is on the boundary then the disk contains the point
if(disk->contains(qp)){
dt.insert(p);
}
}
emit(changed());
}
/*
* 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_<action_name>_<signal_name>"
*/
void
MainWindow::on_actionInsertPoint_toggled(bool checked)
{
if(checked){
scene.installEventFilter(pi);
} else {
scene.removeEventFilter(pi);
}
}
void
MainWindow::on_actionShowConflictZone_toggled(bool checked)
{
if(checked){
scene.installEventFilter(cz);
} else {
scene.removeEventFilter(cz);
}
}
void
MainWindow::on_actionCircumcenter_toggled(bool checked)
{
if(checked){
scene.installEventFilter(tcc);
tcc->show();
} else {
scene.removeEventFilter(tcc);
tcc->hide();
}
}
void
MainWindow::on_actionShowDelaunay_toggled(bool checked)
{
dgi->setVisibleEdges(checked);
}
void
MainWindow::on_actionShowVoronoi_toggled(bool checked)
{
vgi->setVisible(checked);
}
void
MainWindow::on_actionClear_triggered()
{
dt.clear();
emit(changed());
}
void
MainWindow::on_actionInsertRandomPoints_triggered()
{
QRectF rect = CGAL::Qt::viewportsBbox(&scene);
CGAL::Qt::Converter<K> convert;
Iso_rectangle_2 isor = convert(rect);
CGAL::Random_points_in_disc_2<Point_2> pg(1);
bool ok = false;
const int number_of_points =
QInputDialog::getInt(this,
tr("Number of random points"),
tr("Enter number of random points"),
100,
0,
std::numeric_limits<int>::max(),
1,
&ok);
if(!ok) {
return;
}
// wait cursor
QApplication::setOverrideCursor(Qt::WaitCursor);
std::vector<Point_2> points;
points.reserve(number_of_points);
for(int i = 0; i < number_of_points; ++i){
points.push_back(*pg++);
}
dt.insert(points.begin(), points.end());
// default cursor
QApplication::restoreOverrideCursor();
emit(changed());
}
void
MainWindow::on_actionLoadPoints_triggered()
{
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open Points file"),
".");
if(! fileName.isEmpty()){
open(fileName);
}
}
void
MainWindow::open(QString fileName)
{
// wait cursor
QApplication::setOverrideCursor(Qt::WaitCursor);
std::ifstream ifs(qPrintable(fileName));
K::Point_2 p;
std::vector<K::Point_2> points;
while(ifs >> p) {
points.push_back(p);
}
dt.insert(points.begin(), points.end());
// default cursor
QApplication::restoreOverrideCursor();
this->addToRecentFiles(fileName);
actionRecenter->trigger();
emit(changed());
}
void
MainWindow::on_actionSavePoints_triggered()
{
QString fileName = QFileDialog::getSaveFileName(this,
tr("Save points"),
".");
if(! fileName.isEmpty()){
std::ofstream ofs(qPrintable(fileName));
for(Delaunay::All_vertices_iterator
vit = dt.all_vertices_begin(),
end = dt.all_vertices_end();
vit!= end; ++vit)
{
ofs << dt.point(vit) << std::endl;
}
}
}
void
MainWindow::on_actionRecenter_triggered()
{
this->graphicsView->setSceneRect(dgi->boundingRect());
this->graphicsView->fitInView(dgi->boundingRect(), Qt::KeepAspectRatio);
}
#include "HDT2.moc"
int main(int argc, char **argv)
{
QApplication app(argc, argv);
app.setOrganizationDomain("geometryfactory.com");
app.setOrganizationName("GeometryFactory");
app.setApplicationName("Delaunay_triangulation_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(Triangulation_2);
Q_INIT_RESOURCE(Input);
Q_INIT_RESOURCE(CGAL);
MainWindow mainWindow;
mainWindow.show();
QStringList args = app.arguments();
args.removeAt(0);
Q_FOREACH(QString filename, args) {
mainWindow.open(filename);
}
return app.exec();
}

View File

@ -0,0 +1,371 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<author>GeometryFactory</author>
<class>Delaunay_triangulation_2</class>
<widget class="QMainWindow" name="Hyperbolic_Delaunay_triangulation_2">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>CGAL Hyperbolic Delaunay Triangulation</string>
</property>
<property name="windowIcon">
<iconset resource="../../../GraphicsView/demo/resources/CGAL.qrc">
<normaloff>:/cgal/logos/cgal_icon</normaloff>:/cgal/logos/cgal_icon</iconset>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QGridLayout">
<item row="0" column="0">
<widget class="QGraphicsView" name="graphicsView">
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOn</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOn</enum>
</property>
<property name="transformationAnchor">
<enum>QGraphicsView::NoAnchor</enum>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<widget class="QToolBar" name="fileToolBar">
<property name="windowTitle">
<string>File Tools</string>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="actionClear"/>
<addaction name="actionLoadPoints"/>
<addaction name="actionSavePoints"/>
</widget>
<widget class="QToolBar" name="toolBar">
<property name="windowTitle">
<string>Visualization Tools</string>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="actionInsertPoint"/>
<addaction name="actionMovingPoint"/>
<addaction name="actionCircumcenter"/>
<addaction name="actionShowConflictZone"/>
<addaction name="separator"/>
<addaction name="actionShowDelaunay"/>
<addaction name="actionShowVoronoi"/>
<addaction name="separator"/>
<addaction name="actionRecenter"/>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>22</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
<property name="title">
<string>&amp;File</string>
</property>
<addaction name="separator"/>
<addaction name="actionClear"/>
<addaction name="actionLoadPoints"/>
<addaction name="actionSavePoints"/>
<addaction name="separator"/>
<addaction name="actionQuit"/>
</widget>
<widget class="QMenu" name="menuEdit">
<property name="title">
<string>&amp;Edit</string>
</property>
<addaction name="actionInsertRandomPoints"/>
</widget>
<widget class="QMenu" name="menuTools">
<property name="title">
<string>&amp;Tools</string>
</property>
<addaction name="actionInsertPoint"/>
<addaction name="actionG"/>
<addaction name="actionG2"/>
<addaction name="actionG4"/>
<addaction name="actionG8"/>
<addaction name="actionG16"/>
<addaction name="actionMovingPoint"/>
<addaction name="actionCircumcenter"/>
<addaction name="actionShowConflictZone"/>
<addaction name="separator"/>
<addaction name="actionShowDelaunay"/>
<addaction name="actionShowVoronoi"/>
<addaction name="separator"/>
<addaction name="actionRecenter"/>
</widget>
<addaction name="menuFile"/>
<addaction name="menuEdit"/>
<addaction name="menuTools"/>
</widget>
<action name="actionAbout">
<property name="text">
<string>&amp;About</string>
</property>
</action>
<action name="actionAboutCGAL">
<property name="text">
<string>About &amp;CGAL</string>
</property>
</action>
<action name="actionQuit">
<property name="text">
<string>&amp;Quit</string>
</property>
<property name="shortcut">
<string>Ctrl+Q</string>
</property>
</action>
<action name="actionInsertRandomPoints">
<property name="text">
<string>&amp;Insert random points</string>
</property>
<property name="shortcut">
<string>Ctrl+I</string>
</property>
</action>
<action name="actionMovingPoint">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../../../GraphicsView/demo/Triangulation_2/Delaunay_triangulation_2.qrc">
<normaloff>:/cgal/Actions/icons/moving_point.png</normaloff>:/cgal/Actions/icons/moving_point.png</iconset>
</property>
<property name="text">
<string>&amp;Simulate insertion</string>
</property>
<property name="toolTip">
<string comment="The comment">Simulate Insertion</string>
</property>
<property name="statusTip">
<string comment="and its comment">Move mouse with left button pressed to see where point would be inserted</string>
</property>
<property name="whatsThis">
<string comment="what">whats this</string>
</property>
</action>
<action name="actionInsertPoint">
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<property name="icon">
<iconset resource="../../../GraphicsView/demo/icons/Input.qrc">
<normaloff>:/cgal/Input/inputPoint.png</normaloff>:/cgal/Input/inputPoint.png</iconset>
</property>
<property name="text">
<string>&amp;Insert Point</string>
</property>
<property name="toolTip">
<string>Insert Point</string>
</property>
<property name="statusTip">
<string>Left: Insert vtx</string>
</property>
</action>
<action name="actionClear">
<property name="icon">
<iconset resource="../../../GraphicsView/demo/icons/File.qrc">
<normaloff>:/cgal/fileToolbar/fileNew.png</normaloff>:/cgal/fileToolbar/fileNew.png</iconset>
</property>
<property name="text">
<string>&amp;Clear</string>
</property>
<property name="shortcut">
<string>Ctrl+C</string>
</property>
</action>
<action name="actionShowVoronoi">
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<property name="icon">
<iconset resource="../../../GraphicsView/demo/icons/Triangulation_2.qrc">
<normaloff>:/cgal/Triangulation_2/Voronoi_diagram_2.png</normaloff>:/cgal/Triangulation_2/Voronoi_diagram_2.png</iconset>
</property>
<property name="text">
<string>Show &amp;Voronoi Diagram</string>
</property>
<property name="shortcut">
<string>Ctrl+V</string>
</property>
</action>
<action name="actionShowDelaunay">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../../../GraphicsView/demo/Triangulation_2/Delaunay_triangulation_2.qrc">
<normaloff>:/cgal/Actions/icons/triangulation.png</normaloff>:/cgal/Actions/icons/triangulation.png</iconset>
</property>
<property name="text">
<string>Show Hyperbolic &amp;Delaunay Triangulation</string>
</property>
<property name="shortcut">
<string>Ctrl+D</string>
</property>
</action>
<action name="actionLoadPoints">
<property name="icon">
<iconset resource="../../../GraphicsView/demo/icons/File.qrc">
<normaloff>:/cgal/fileToolbar/fileOpen.png</normaloff>:/cgal/fileToolbar/fileOpen.png</iconset>
</property>
<property name="text">
<string>&amp;Load Points...</string>
</property>
<property name="shortcut">
<string>Ctrl+L</string>
</property>
</action>
<action name="actionSavePoints">
<property name="icon">
<iconset resource="../../../GraphicsView/demo/icons/File.qrc">
<normaloff>:/cgal/fileToolbar/fileSave.png</normaloff>:/cgal/fileToolbar/fileSave.png</iconset>
</property>
<property name="text">
<string>&amp;Save Points...</string>
</property>
<property name="shortcut">
<string>Ctrl+S</string>
</property>
</action>
<action name="actionCircumcenter">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../../../GraphicsView/demo/Triangulation_2/Delaunay_triangulation_2.qrc">
<normaloff>:/cgal/Actions/icons/circumcenter.png</normaloff>:/cgal/Actions/icons/circumcenter.png</iconset>
</property>
<property name="text">
<string>&amp;Circumcenter</string>
</property>
<property name="toolTip">
<string>Draw circumcenter</string>
</property>
</action>
<action name="actionRecenter">
<property name="icon">
<iconset resource="../../../GraphicsView/demo/icons/Input.qrc">
<normaloff>:/cgal/Input/zoom-best-fit</normaloff>:/cgal/Input/zoom-best-fit</iconset>
</property>
<property name="text">
<string>Re&amp;center the viewport</string>
</property>
<property name="shortcut">
<string>Ctrl+R</string>
</property>
</action>
<action name="actionShowConflictZone">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../../../GraphicsView/demo/Triangulation_2/Delaunay_triangulation_2.qrc">
<normaloff>:/cgal/Actions/icons/conflict_zone.png</normaloff>:/cgal/Actions/icons/conflict_zone.png</iconset>
</property>
<property name="text">
<string>Show Conflict Zone</string>
</property>
</action>
<action name="actionG">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="Hyperbolic_translations_2.qrc">
<normaloff>:/cgal/Actions/icons/G.png</normaloff>:/cgal/Actions/icons/G.png</iconset>
</property>
<property name="text">
<string>G</string>
</property>
</action>
<action name="actionG2">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="Hyperbolic_translations_2.qrc">
<normaloff>:/cgal/Actions/icons/G2.png</normaloff>:/cgal/Actions/icons/G2.png</iconset>
</property>
<property name="text">
<string>G2</string>
</property>
</action>
<action name="actionG4">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="Hyperbolic_translations_2.qrc">
<normaloff>:/cgal/Actions/icons/G4.png</normaloff>:/cgal/Actions/icons/G4.png</iconset>
</property>
<property name="text">
<string>G4</string>
</property>
</action>
<action name="actionG8">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="Hyperbolic_translations_2.qrc">
<normaloff>:/cgal/Actions/icons/G8.png</normaloff>:/cgal/Actions/icons/G8.png</iconset>
</property>
<property name="text">
<string>G8</string>
</property>
</action>
<action name="actionG16">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="Hyperbolic_translations_2.qrc">
<normaloff>:/cgal/Actions/icons/G16.png</normaloff>:/cgal/Actions/icons/G16.png</iconset>
</property>
<property name="text">
<string>G16</string>
</property>
</action>
</widget>
<resources>
<include location="../../../GraphicsView/demo/Triangulation_2/Delaunay_triangulation_2.qrc"/>
<include location="../../../GraphicsView/demo/icons/File.qrc"/>
<include location="Hyperbolic_translations_2.qrc"/>
<include location="../../../GraphicsView/demo/resources/CGAL.qrc"/>
<include location="../../../GraphicsView/demo/icons/Triangulation_2.qrc"/>
<include location="../../../GraphicsView/demo/icons/Input.qrc"/>
</resources>
<connections/>
</ui>