C++ 如何称之为CGAL';QT接口功能是否正确?
我的环境是Ubuntu 14.04上的CGAL 4.5和QT5 我正在学习如何使用CGAL渲染几何对象,如点、线、线段。在网上似乎没有使用这个框架的例子,所以我现在很挣扎 我似乎无法让我的测试代码正常工作。它编译但抛出seg错误 这是我的代码,来自通过QtCreator创建的我的QTwidgets应用程序中的我的C++ 如何称之为CGAL';QT接口功能是否正确?,c++,qt,cgal,C++,Qt,Cgal,我的环境是Ubuntu 14.04上的CGAL 4.5和QT5 我正在学习如何使用CGAL渲染几何对象,如点、线、线段。在网上似乎没有使用这个框架的例子,所以我现在很挣扎 我似乎无法让我的测试代码正常工作。它编译但抛出seg错误 这是我的代码,来自通过QtCreator创建的我的QTwidgets应用程序中的我的MainWindow.cpp文件 #include <iostream> #include <CGAL/Simple_cartesian.h> #include
MainWindow.cpp
文件
#include <iostream>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Qt/PointsGraphicsItem.h>
#include <CGAL/Qt/SegmentsGraphicsItem.h>
#include <vector>
typedef CGAL::Simple_cartesian<double> Kernel;
typedef Kernel::Point_2 Point_2;
typedef Kernel::Segment_2 Segment_2;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
scene = new QGraphicsScene(this);
ui->graphicsView->setScene(scene);
std::vector<Point_2> pts;
pts.push_back(Point_2(1,1));
pts.push_back(Point_2(10,10));
CGAL::Qt::PointsGraphicsItem< std::vector<Point_2> > graphical_points(&pts);
}
我在这个函数调用中做错了什么?我知道我必须将点添加到图形场景中,但目前这并不重要
理想情况下,当代码运行时,在我将这些点添加到场景中后,它应该显示两个点,一个在(1,1),另一个在(10,10)
是指向Pastebin上完整
PointsGraphicsSitem.h
文件的链接 您应该使用点的新矢量和空矢量创建图形项,并调用scene.addItem(..)
。用点填充向量时,在将其连接到点GraphicsSitem::modelChanged()后发出信号
如果我是你,我会采取现有的演示,如多边形2演示
一点一点地修改它
请注意,演示并不是我们的重点,因为CGAL主要是关于几何数据结构和算法的 好吧,现在我知道你的代码的问题在哪里了。向量pts
的生命周期就是构造函数MainWindow::MainWindow(..)
。
当点graphicsitem
的绘制方法尝试绘制这些点时,它们不再存在
CGAL::Qt::PointsGraphicsItem< std::vector<Point_2> > graphical_points(&pts);
CGAL::Qt::PointsGraphicsItem< std::vector<Point_2> > graphical_points(&pts);
LIBS += -lCGAL -lgmp
QMAKE_CXXFLAGS += -frounding-math