• 大小: 40KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-16
  • 语言: 其他
  • 标签: delaunay  Qt  

资源简介

使用Qt实现的delaunay三角分割的可视化,直接下载解压点击.pro文件打开就可以直接运行。Qt版本:5.11.2,Qt creator版本:4.7.1

资源截图

代码片段和文件信息

#include “coordinatesystem.h“
#include 
#include 
#include 
#include 
#include 
#include 

CoordinateSystem::CoordinateSystem(QWidget *parent) : QWidget(parent)
{
    init();
}

void CoordinateSystem::init()
{
    pixmap = QPixmap(600 600);
    pixmap.fill();
    uav = 0;
    ban = 0;
    points.clear();
    get = false;
    had = 0;
    exec = false;
}

void CoordinateSystem::mouseMoveEvent(QMouseEvent *event)
{
    QPoint cur(event->pos());
    //qDebug() << “CoordinateSystem::mouseMoveEvent(QMouseEvent *): “ << cur;
    emit sendMousePoint(cur);
}

void CoordinateSystem::mousePressEvent(QMouseEvent *event)
{
    //qDebug() << 0;
    if(event->button() == Qt::LeftButton)
    {
        //qDebug() << 1;
        QPoint cur(event->pos());
        //qDebug() << “CoordinateSystem::mousePressEvent(QMouseEvent *event): “ << cur;
        if(!get || had == uav + ban)
            return;
        //qDebug() << 2;
        auto iter = find_if(points.begin() points.end() [cur](const QPoint &p){return p == cur;});
        if(iter != points.end())
            return;
        //qDebug() << 3;
        had += 1;
        points.push_back(cur);
        //update();
        //for(auto p : points)
        //qDebug() << “CoordinateSystem::mousePressEvent(QMouseEvent *event): “ << “vector “ << points.back();
        update();
    }
}

void CoordinateSystem::receiveGetFromParent(std::pair ub)
{
    init();
    uav = ub.first;
    ban = ub.second;
    get = true;
}

void CoordinateSystem::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);

    //qDebug() << 0;
    if(had == 0)
        return;
    //qDebug() << 1;
    QPainter painter;
    //画点
    if(had <= uav + ban)
    {
        //qDebug() << 2;
        QPen pen(Qt::green 12 Qt::SolidLine Qt::SquareCap Qt::BevelJoin);
        if(had > uav)
            pen.setBrush(Qt::red);
        QPoint cur = points.back();
        painter.begin(&pixmap);
        painter.setPen(pen);
        painter.drawPoint(cur);
        //painter.drawPO
        painter.end();
    }
    //三角分割
    if(exec && had == uav + ban)
    {
        std::sort(points.begin() points.end() [](const QPoint &p1 const QPoint &p2){return p1.x() < p2.x();});
        QPen pen(Qt::black 5 Qt::SolidLine Qt::SquareCap Qt::BevelJoin);
        del.setPoints(points);
        auto tris = del.run();
        painter.begin(&pixmap);
        painter.setPen(pen);
        for(auto tri : tris)
        {
            QPoint v1 = points[tri.v1] v2 = points[tri.v2] v3 = points[tri.v3];
            painter.drawLine(v1 v2);
            painter.drawLine(v2 v3);
            painter.drawLine(v3 v1);
        }
        painter.end();
    }
    painter.begin(this);
    painter.drawPixmap(0 0 600 600 pixmap 0 0 600 600);
    painter.end();
}

void CoordinateSystem::receiveExcuteFromParent()
{
    if(had < uav + ban)
        return;
    if(exec)
        return;
    exec = true;
    //qDebug() << 0;

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-12-13 22:27  triangulate\
     文件        2644  2018-12-13 14:59  triangulate\widget.cpp
     文件         634  2018-12-13 10:51  triangulate\widget.h
     文件        1604  2018-12-12 22:37  triangulate\widget.ui
     文件         536  2018-12-13 19:11  triangulate\delaunary.h
     文件       24400  2018-12-13 21:28  triangulate\triangulate.pro.user
     文件        5452  2018-12-13 19:25  triangulate\delaunary.cpp
     文件        1286  2018-12-13 15:33  triangulate\triangulate.pro
     目录           0  2018-12-13 22:32  __MACOSX\
     目录           0  2018-12-13 22:32  __MACOSX\triangulate\
     文件         176  2018-12-13 15:33  __MACOSX\triangulate\._triangulate.pro
     文件         870  2018-12-13 14:49  triangulate\coordinatesystem.h
     目录           0  2018-12-13 22:31  triangulate\.git\
     文件         316  2018-12-13 22:31  triangulate\.git\config
     目录           0  2018-12-13 22:30  triangulate\.git\objects\
     目录           0  2018-12-13 22:30  triangulate\.git\objects\4e\
     文件         330  2018-12-13 22:30  triangulate\.git\objects\4e\ba8f815ccb5ba074abc87ae5bd8518a9f59a98
     目录           0  2018-12-13 22:27  triangulate\.git\objects\pack\
     目录           0  2018-12-13 22:27  triangulate\.git\objects\74\
     文件         354  2018-12-13 22:27  triangulate\.git\objects\74\49bb3982dd1edd95a733747bc01078e5b670ac
     目录           0  2018-12-13 22:27  triangulate\.git\objects\info\
     目录           0  2018-12-13 22:27  triangulate\.git\objects\64\
     文件        1891  2018-12-13 22:27  triangulate\.git\objects\64\227dce89a701784a3512b6205dba09a0bbe2e6
     目录           0  2018-12-13 22:27  triangulate\.git\objects\90\
     文件         136  2018-12-13 22:27  triangulate\.git\objects\90\b6d53fb950c511da62d02bc34fe46d660069f5
     目录           0  2018-12-13 22:27  triangulate\.git\objects\b8\
     文件         504  2018-12-13 22:27  triangulate\.git\objects\b8\7289075a3fb94a967713001326fc28c9575ec1
     目录           0  2018-12-13 22:27  triangulate\.git\objects\d2\
     文件         949  2018-12-13 22:27  triangulate\.git\objects\d2\0ad48f42cfa236d352e09648824a03490bb5cc
     目录           0  2018-12-13 22:30  triangulate\.git\objects\ea\
     文件         144  2018-12-13 22:30  triangulate\.git\objects\ea\f88e876ebf4078318ac3bf9645d7927fcc20ad
............此处省略45个文件信息

评论

共有 条评论