mirror of https://github.com/CGAL/cgal
Added visualization of conflict zone
This commit is contained in:
parent
b6aa6d8644
commit
a54674e4e3
|
|
@ -16,6 +16,7 @@
|
||||||
// GraphicsView items and event filters (input classes)
|
// GraphicsView items and event filters (input classes)
|
||||||
#include "TriangulationCircumcircle.h"
|
#include "TriangulationCircumcircle.h"
|
||||||
#include "TriangulationMovingPoint.h"
|
#include "TriangulationMovingPoint.h"
|
||||||
|
#include "TriangulationConflictZone.h"
|
||||||
#include "TriangulationRemoveVertex.h"
|
#include "TriangulationRemoveVertex.h"
|
||||||
#include <CGAL/Qt/GraphicsViewPolylineInput.h>
|
#include <CGAL/Qt/GraphicsViewPolylineInput.h>
|
||||||
#include <CGAL/Qt/TriangulationGraphicsItem.h>
|
#include <CGAL/Qt/TriangulationGraphicsItem.h>
|
||||||
|
|
@ -45,6 +46,7 @@ private:
|
||||||
CGAL::Qt::VoronoiGraphicsItem<Delaunay> * vgi;
|
CGAL::Qt::VoronoiGraphicsItem<Delaunay> * vgi;
|
||||||
|
|
||||||
CGAL::Qt::TriangulationMovingPoint<Delaunay> * mp;
|
CGAL::Qt::TriangulationMovingPoint<Delaunay> * mp;
|
||||||
|
CGAL::Qt::TriangulationConflictZone<Delaunay> * cz;
|
||||||
CGAL::Qt::TriangulationRemoveVertex<Delaunay> * trv;
|
CGAL::Qt::TriangulationRemoveVertex<Delaunay> * trv;
|
||||||
CGAL::Qt::GraphicsViewPolylineInput<K> * pi;
|
CGAL::Qt::GraphicsViewPolylineInput<K> * pi;
|
||||||
CGAL::Qt::TriangulationCircumcircle<Delaunay> *tcc;
|
CGAL::Qt::TriangulationCircumcircle<Delaunay> *tcc;
|
||||||
|
|
@ -57,6 +59,8 @@ public slots:
|
||||||
|
|
||||||
void on_actionMovingPoint_toggled(bool checked);
|
void on_actionMovingPoint_toggled(bool checked);
|
||||||
|
|
||||||
|
void on_actionShowConflictZone_toggled(bool checked);
|
||||||
|
|
||||||
void on_actionCircumcenter_toggled(bool checked);
|
void on_actionCircumcenter_toggled(bool checked);
|
||||||
|
|
||||||
void on_actionShowDelaunay_toggled(bool checked);
|
void on_actionShowDelaunay_toggled(bool checked);
|
||||||
|
|
@ -128,6 +132,7 @@ MainWindow::MainWindow()
|
||||||
tcc = new CGAL::Qt::TriangulationCircumcircle<Delaunay>(&scene, &dt, this);
|
tcc = new CGAL::Qt::TriangulationCircumcircle<Delaunay>(&scene, &dt, this);
|
||||||
tcc->setPen(QPen(Qt::red, 0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
|
tcc->setPen(QPen(Qt::red, 0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
|
||||||
|
|
||||||
|
cz = new CGAL::Qt::TriangulationConflictZone<Delaunay>(&scene, &dt, this);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Manual handling of actions
|
// Manual handling of actions
|
||||||
|
|
@ -139,6 +144,8 @@ MainWindow::MainWindow()
|
||||||
QActionGroup* ag = new QActionGroup(this);
|
QActionGroup* ag = new QActionGroup(this);
|
||||||
ag->addAction(this->actionInsertPoint);
|
ag->addAction(this->actionInsertPoint);
|
||||||
ag->addAction(this->actionMovingPoint);
|
ag->addAction(this->actionMovingPoint);
|
||||||
|
ag->addAction(this->actionShowCircumcenter);
|
||||||
|
ag->addAction(this->actionShowConflictZone);
|
||||||
|
|
||||||
// Check two actions
|
// Check two actions
|
||||||
this->actionInsertPoint->setChecked(true);
|
this->actionInsertPoint->setChecked(true);
|
||||||
|
|
@ -211,6 +218,17 @@ MainWindow::on_actionMovingPoint_toggled(bool checked)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
MainWindow::on_actionShowConflictZone_toggled(bool checked)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(checked){
|
||||||
|
scene.installEventFilter(cz);
|
||||||
|
} else {
|
||||||
|
scene.removeEventFilter(cz);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MainWindow::on_actionCircumcenter_toggled(bool checked)
|
MainWindow::on_actionCircumcenter_toggled(bool checked)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -18,14 +18,6 @@
|
||||||
<normaloff>:/cgal/logos/cgal_icon</normaloff>:/cgal/logos/cgal_icon</iconset>
|
<normaloff>:/cgal/logos/cgal_icon</normaloff>:/cgal/logos/cgal_icon</iconset>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="centralwidget" >
|
<widget class="QWidget" name="centralwidget" >
|
||||||
<property name="geometry" >
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>66</y>
|
|
||||||
<width>400</width>
|
|
||||||
<height>209</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<layout class="QGridLayout" >
|
<layout class="QGridLayout" >
|
||||||
<item row="0" column="0" >
|
<item row="0" column="0" >
|
||||||
<widget class="QGraphicsView" name="graphicsView" >
|
<widget class="QGraphicsView" name="graphicsView" >
|
||||||
|
|
@ -45,25 +37,8 @@
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QStatusBar" name="statusbar" >
|
<widget class="QStatusBar" name="statusbar" />
|
||||||
<property name="geometry" >
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>275</y>
|
|
||||||
<width>400</width>
|
|
||||||
<height>25</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
<widget class="QToolBar" name="fileToolBar" >
|
<widget class="QToolBar" name="fileToolBar" >
|
||||||
<property name="geometry" >
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>29</y>
|
|
||||||
<width>116</width>
|
|
||||||
<height>37</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<property name="windowTitle" >
|
<property name="windowTitle" >
|
||||||
<string>File Tools</string>
|
<string>File Tools</string>
|
||||||
</property>
|
</property>
|
||||||
|
|
@ -78,14 +53,6 @@
|
||||||
<addaction name="actionSavePoints" />
|
<addaction name="actionSavePoints" />
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QToolBar" name="toolBar" >
|
<widget class="QToolBar" name="toolBar" >
|
||||||
<property name="geometry" >
|
|
||||||
<rect>
|
|
||||||
<x>116</x>
|
|
||||||
<y>29</y>
|
|
||||||
<width>284</width>
|
|
||||||
<height>37</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<property name="windowTitle" >
|
<property name="windowTitle" >
|
||||||
<string>Visualization Tools</string>
|
<string>Visualization Tools</string>
|
||||||
</property>
|
</property>
|
||||||
|
|
@ -108,7 +75,7 @@
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>400</width>
|
<width>400</width>
|
||||||
<height>29</height>
|
<height>19</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QMenu" name="menuFile" >
|
<widget class="QMenu" name="menuFile" >
|
||||||
|
|
@ -136,6 +103,7 @@
|
||||||
<addaction name="actionInsertPoint" />
|
<addaction name="actionInsertPoint" />
|
||||||
<addaction name="actionShowDelaunay" />
|
<addaction name="actionShowDelaunay" />
|
||||||
<addaction name="actionShowVoronoi" />
|
<addaction name="actionShowVoronoi" />
|
||||||
|
<addaction name="actionShowConflictZone" />
|
||||||
<addaction name="separator" />
|
<addaction name="separator" />
|
||||||
<addaction name="actionRecenter" />
|
<addaction name="actionRecenter" />
|
||||||
</widget>
|
</widget>
|
||||||
|
|
@ -307,6 +275,14 @@
|
||||||
<string>Ctrl+R</string>
|
<string>Ctrl+R</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="actionShowConflictZone" >
|
||||||
|
<property name="checkable" >
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text" >
|
||||||
|
<string>Show Conflict Zone</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="Delaunay_triangulation_2.qrc" />
|
<include location="Delaunay_triangulation_2.qrc" />
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,148 @@
|
||||||
|
|
||||||
|
#ifndef CGAL_QT_TRIANGULATION_CONFLICT_ZONE
|
||||||
|
#define CGAL_QT_TRIANGULATION_CONFLICT_ZONE
|
||||||
|
|
||||||
|
#include <CGAL/Qt/GraphicsViewInput.h>
|
||||||
|
#include <CGAL/Qt/Converter.h>
|
||||||
|
#include <QGraphicsSceneMouseEvent>
|
||||||
|
#include <QEvent>
|
||||||
|
#include <list>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace CGAL {
|
||||||
|
namespace Qt {
|
||||||
|
|
||||||
|
template <typename DT>
|
||||||
|
class TriangulationConflictZone : public GraphicsViewInput
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef typename DT::Geom_traits K;
|
||||||
|
typedef typename DT::Face_handle Face_handle;
|
||||||
|
typedef typename DT::Point Point;
|
||||||
|
|
||||||
|
TriangulationConflictZone(QGraphicsScene* s, DT * dt_, QObject* parent);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void localize_and_insert_point(QPointF qt_point);
|
||||||
|
|
||||||
|
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
bool eventFilter(QObject *obj, QEvent *event);
|
||||||
|
|
||||||
|
std::list<Face_handle> faces;
|
||||||
|
std::list<QGraphicsPolygonItem*> qfaces;
|
||||||
|
DT * dt;
|
||||||
|
Converter<K> convert;
|
||||||
|
QGraphicsScene *scene_;
|
||||||
|
bool animate;
|
||||||
|
Face_handle hint;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
TriangulationConflictZone<T>::TriangulationConflictZone(QGraphicsScene* s,
|
||||||
|
T * dt_,
|
||||||
|
QObject* parent)
|
||||||
|
: GraphicsViewInput(parent), dt(dt_), scene_(s), animate(false)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void
|
||||||
|
TriangulationConflictZone<T>::localize_and_insert_point(QPointF qt_point)
|
||||||
|
{
|
||||||
|
Point p(convert(qt_point));
|
||||||
|
|
||||||
|
faces.clear();
|
||||||
|
for(std::list<QGraphicsPolygonItem*>::iterator it = qfaces.begin();
|
||||||
|
it != qfaces.end();
|
||||||
|
++it){
|
||||||
|
delete *it;
|
||||||
|
}
|
||||||
|
qfaces.clear();
|
||||||
|
hint = dt->locate(p, hint);
|
||||||
|
dt->find_conflicts(p, faces, hint);
|
||||||
|
for(std::list<Face_handle>::iterator it = faces.begin();
|
||||||
|
it != faces.end();
|
||||||
|
++it){
|
||||||
|
if(! dt->is_infinite(*it)){
|
||||||
|
QGraphicsPolygonItem *item = new QGraphicsPolygonItem(convert(dt->triangle(*it)));
|
||||||
|
item->setBrush(::Qt::cyan);
|
||||||
|
scene_->addItem(item);
|
||||||
|
qfaces.push_back(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void
|
||||||
|
TriangulationConflictZone<T>::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||||
|
{
|
||||||
|
if(dt->number_of_vertices() == 0 ||
|
||||||
|
event->modifiers() != 0 ||
|
||||||
|
event->button() != ::Qt::LeftButton) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
hint = dt->locate(convert(event->scenePos()));
|
||||||
|
localize_and_insert_point(event->scenePos());
|
||||||
|
animate = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void
|
||||||
|
TriangulationConflictZone<T>::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||||
|
{
|
||||||
|
if(animate){
|
||||||
|
localize_and_insert_point(event->scenePos());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void
|
||||||
|
TriangulationConflictZone<T>::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||||
|
{
|
||||||
|
faces.clear();
|
||||||
|
for(std::list<QGraphicsPolygonItem*>::iterator it = qfaces.begin();
|
||||||
|
it != qfaces.end();
|
||||||
|
++it){
|
||||||
|
delete *it;
|
||||||
|
}
|
||||||
|
qfaces.clear();
|
||||||
|
animate = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
bool
|
||||||
|
TriangulationConflictZone<T>::eventFilter(QObject *obj, QEvent *event)
|
||||||
|
{
|
||||||
|
if (event->type() == QEvent::GraphicsSceneMousePress) {
|
||||||
|
QGraphicsSceneMouseEvent *mouseEvent = static_cast<QGraphicsSceneMouseEvent *>(event);
|
||||||
|
mousePressEvent(mouseEvent);
|
||||||
|
return true;
|
||||||
|
} else if (event->type() == QEvent::GraphicsSceneMouseMove) {
|
||||||
|
QGraphicsSceneMouseEvent *mouseEvent = static_cast<QGraphicsSceneMouseEvent *>(event);
|
||||||
|
mouseMoveEvent(mouseEvent);
|
||||||
|
return false; // do not eat move event!
|
||||||
|
} else if (event->type() == QEvent::GraphicsSceneMouseRelease) {
|
||||||
|
QGraphicsSceneMouseEvent *mouseEvent = static_cast<QGraphicsSceneMouseEvent *>(event);
|
||||||
|
mouseReleaseEvent(mouseEvent);
|
||||||
|
return true;
|
||||||
|
} else{
|
||||||
|
// standard event processing
|
||||||
|
return QObject::eventFilter(obj, event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Qt
|
||||||
|
} // namespace CGAL
|
||||||
|
|
||||||
|
#endif // CGAL_QT_TRIANGULATION_CONFLICT_ZONE
|
||||||
Loading…
Reference in New Issue