我想建立一个简单的 CGAL + Qt 程序。简而言之,我想采取以下几点:
并使用 Qt 打印出它的可视化。我编译上面没有问题:
cgal_create_CMakeLists -c Core
cmake -DCGAL_DIR=/usr/share/CGAL/ .
make
并且已经能够使用 qmake 编译各种 Qt 程序,但是我很难在 conics.cpp 文件中使用 Qt。
我的问题是:
- 我需要包含哪些 Qt 库
- 如何使用插入器将 arr 插入到 Qt 小部件流中
- 如何使用 cmake 设置和运行
更新
我一直在努力弄清楚如何使用 Qt header 编译程序。在多边形演示之后,我添加了:
// Qt headers
#include <QtGui>
#include <QString>
#include <QFileDialog>
#include <QInputDialog>
#include <QGraphicsLineItem>
到 conics.cpp。我也没有运气:
cgal_create_cmake_script
或:
cgal_create_CMakeLists -c Core:Qt5
目前的工作是修改 Polygon 演示中的 CMakeLists.txt:
project (Qt_Demo)
cmake_minimum_required(VERSION 3.1)
if(NOT POLICY CMP0070 AND POLICY CMP0053)
# Only set CMP0053 to OLD with CMake<3.10, otherwise there is a warning.
cmake_policy(SET CMP0053 OLD)
endif()
find_package(CGAL COMPONENTS Qt5 Core)
include(${CGAL_USE_FILE})
find_package(Qt5 QUIET COMPONENTS Xml Script OpenGL Svg)
include_directories (BEFORE ../../include)
if ( CGAL_FOUND AND CGAL_Qt5_FOUND AND Qt5_FOUND )
add_definitions(-DQT_NO_KEYWORDS)
if( CGAL_Core_FOUND)
add_definitions(-DCGAL_USE_CORE)
endif()
#--------------------------------
# Demo: Polygon_2
#--------------------------------
# UI files (Qt Designer files)
#qt5_wrap_ui( DT_UI_FILES Polygon_2.ui )
# qrc files (resources files, that contain icons, at least)
#qt5_add_resources ( CGAL_Qt5_RESOURCE_FILES ./Polygon_2.qrc )
# use the Qt MOC preprocessor on classes that derives from QObject
qt5_generate_moc( conics.cpp "${CMAKE_CURRENT_BINARY_DIR}/conics.moc" )
# add_library( CGAL SHARED IMPORTED )
# SET_PROPERTY(TARGET CGAL PROPERTY IMPORTED_LOCATION ${CGAL_LIBRARY} )
# The executable itself.
add_executable ( conics conics.cpp conics.moc ${DT_UI_FILES} ${DT_RESOURCE_FILES} ${CGAL_Qt5_RESOURCE_FILES} ${CGAL_Qt5_MOC_FILES} )
qt5_use_modules(conics Xml Script OpenGL Svg)
add_to_cached_list( CGAL_EXECUTABLE_TARGETS conics )
# Link with Qt libraries
target_link_libraries( conics ${QT_LIBRARIES} )
# And with CGAL libraries
target_link_libraries( conics ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES} )
else()
message(STATUS "NOTICE: This demo requires CGAL, CGAL_Core, and Qt5, and will not be compiled.")
endif()
真的,应该有更简单的方法!
最佳答案
- “我需要包含哪些 Qt 库?” 您需要 Qt 中的以下库
#include <QtGui>
#include <QApplication>
#include <QGraphicsScene>
#include <QGraphicsView>
除此之外,您还需要一些 CGAL::Qt 库来支持 CGAL 数据结构
#include <CGAL/Qt/GraphicsViewNavigation.h>
您还需要一个自定义图形项来表示 Arrangement_2
而不是 QGraphicsLineItem
。
CGAL 中的 Arrangement_2 项由顶点、边和面的组合表示。因此,您需要一个自定义 QGraphicsItem 来将 Arrangement_2 显示到 Qt 中的场景中。
在CGAL Demo , 你可以在 Arrangement_2GraphicsItem.h 中找到一个预定义的图形项,它可以用来显示 arr 的二次曲线。
- 如何使用插入器将 arr 插入到 Qt 小部件流中?
一旦有了Arrangement_2GraphicsItem
,就可以将对arr的引用传递到图形项中,并将图形项添加到Qt场景中。
arr_gi = new CGAL::Qt::ArrangementGraphicsItem<Arrangement_2>(&arr);
scene.addItem(arr_gi);
- 如何使用 CMake 进行设置和运行?
您的 CMakeLists.txt 应如下所示:
cmake_minimum_required (VERSION 3.8)
project(conics)
find_package(Boost COMPONENTS thread system REQUIRED)
find_package(CGAL REQUIRED COMPONENTS Core Qt5)
find_package(Qt5 QUIET COMPONENTS Qt5 Core)
# Add source to this project's executable.
add_executable (conics
conics.cpp
ArrangementGraphicsItem.h
ArrangementPainterOstream.h #ArrangementGraphicsItem dependencies
ArrangementTypes.h
Utils.h
${CGAL_Qt5_RESOURCE_FILES} ${CGAL_Qt5_MOC_FILES})
qt5_use_modules(conics Xml Script OpenGL Svg)
include_directories(${Boost_INCLUDE_DIR})
target_link_libraries(conics CGAL::CGAL_Core CGAL::CGAL CGAL::CGAL_Qt5 ${Boost_LIBRARIES})
关于c++ - 如何设置一个简单的 CGAL + Qt 程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51354284/