如何设置一个简单的CGAL+Qt程序

How can I set up a simple CGAL + Qt program

本文关键字:简单 CGAL+Qt 程序 一个 何设置 设置      更新时间:2023-10-16

我想设置一个简单的CGAL+Qt程序。简而言之,我想采取以下措施:

https://github.com/CGAL/cgal/blob/master/Arrangement_on_surface_2/examples/Arrangement_on_surface_2/conics.cpp

并使用Qt打印出它的可视化。我没有问题编译以上:

cgal_create_CMakeLists -c Core
cmake -DCGAL_DIR=/usr/share/CGAL/ .
make

并且已经能够使用qmake编译各种Qt程序,但我很难在conics.cpp文件中使用Qt。

我的问题是:

  • 我需要包含哪些Qt库
  • 如何使用插入器将arr插入Qt小部件流
  • 如何使用cmake设置和运行

更新

我一直在想如何用Qt头编译一个程序。在Polygon演示之后,我添加了:

// 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而不是CCD_ 1。

CGAL中的Arrangement_2项由"顶点"、"边"answers"面"的组合表示。因此,您需要一个自定义QGraphicsItem来在Qt中的场景上显示Arrangement_2。

在CGAL Demo中,您可以在Arrangement_2GraphicsItem.h中找到一个预定义的图形项,该项可用于显示圆锥的排列。

  • 如何使用插入器将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})