diff --git a/.gitignore b/.gitignore index 0f0135b04e4..f0949b62c5c 100644 --- a/.gitignore +++ b/.gitignore @@ -189,12 +189,12 @@ GraphicsView/demo/Triangulation_2/Makefile GraphicsView/demo/Triangulation_2/Regular_triangulation_2 GraphicsView/demo/Triangulation_2/qrc_*.cxx GraphicsView/demo/Triangulation_2/ui_*.h -GraphicsView/src/CGAL_Qt4/*.dll -GraphicsView/src/CGAL_Qt4/*.lib -GraphicsView/src/CGAL_Qt4/*.so -GraphicsView/src/CGAL_Qt4/Makefile -GraphicsView/src/CGAL_Qt4/moc_*.cxx -GraphicsView/src/CGAL_Qt4/qrc_*.cxx +GraphicsView/src/CGAL_Qt5/*.dll +GraphicsView/src/CGAL_Qt5/*.lib +GraphicsView/src/CGAL_Qt5/*.so +GraphicsView/src/CGAL_Qt5/Makefile +GraphicsView/src/CGAL_Qt5/moc_*.cxx +GraphicsView/src/CGAL_Qt5/qrc_*.cxx HalfedgeDS/test/HalfedgeDS/CMakeLists.txt HalfedgeDS/test/HalfedgeDS/cgal_test_with_cmake HalfedgeDS/test/HalfedgeDS/test_hds @@ -826,7 +826,7 @@ Surface_mesher/demo/Surface_mesher/.*.deps Surface_mesher/demo/Surface_mesher/.qglviewer.xml Surface_mesher/demo/Surface_mesher/Makefile Surface_mesher/demo/Surface_mesher/Surface_mesher -Surface_mesher/demo/Surface_mesher/Surface_mesher_Qt4_Demo +Surface_mesher/demo/Surface_mesher/Surface_mesher_Qt5_Demo Surface_mesher/demo/Surface_mesher/VTK/Makefile Surface_mesher/demo/Surface_mesher/VTK/mesh_a_3D_image Surface_mesher/demo/Surface_mesher/VTK/mesh_a_VTK_3D_image @@ -841,7 +841,7 @@ Surface_mesher/demo/Surface_mesher/out*.off Surface_mesher/demo/Surface_mesher/polyhedron_remesher Surface_mesher/demo/Surface_mesher/polyhedron_remesher_with_edges Surface_mesher/demo/Surface_mesher/qrc_*.c* -Surface_mesher/demo/Surface_mesher/qt4-demo +Surface_mesher/demo/Surface_mesher/qt5-demo Surface_mesher/demo/Surface_mesher/ui_*.h Surface_mesher/doxygen Surface_mesher/examples/Surface_mesher/.*.deps @@ -1158,3 +1158,5 @@ gmon.* /Stream_support/test/Stream_support/CMakeLists.txt /Stream_support/test/Stream_support/cgal_test_with_cmake /*.html +/Snap_rounding_2/test/Snap_rounding_2/CMakeLists.txt +/Snap_rounding_2/test/Snap_rounding_2/data/out diff --git a/AABB_tree/demo/AABB_tree/AABB_demo.cpp b/AABB_tree/demo/AABB_tree/AABB_demo.cpp index ca58bb1a4b6..d481f7d5277 100644 --- a/AABB_tree/demo/AABB_tree/AABB_demo.cpp +++ b/AABB_tree/demo/AABB_tree/AABB_demo.cpp @@ -26,6 +26,8 @@ #include "MainWindow.h" #include #include +#include + int main(int argc, char **argv) { @@ -33,10 +35,11 @@ int main(int argc, char **argv) app.setOrganizationDomain("inria.fr"); app.setOrganizationName("INRIA"); app.setApplicationName("AABB tree demo"); + //for windows + app.setAttribute(Qt::AA_UseDesktopOpenGL); - // Import resources from libCGALQt4. - // See http://doc.trolltech.com/4.4/qdir.html#Q_INIT_RESOURCE - CGAL_QT4_INIT_RESOURCES; + // Import resources from libCGALQt (Qt5). + CGAL_QT_INIT_RESOURCES; MainWindow mainWindow; mainWindow.show(); diff --git a/AABB_tree/demo/AABB_tree/CMakeLists.txt b/AABB_tree/demo/AABB_tree/CMakeLists.txt index 84a11b6b2ea..0b47164a64e 100644 --- a/AABB_tree/demo/AABB_tree/CMakeLists.txt +++ b/AABB_tree/demo/AABB_tree/CMakeLists.txt @@ -2,61 +2,57 @@ project( AABB_demo ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +# Find includes in corresponding build directories +set(CMAKE_INCLUDE_CURRENT_DIR ON) +# Instruct CMake to run moc automatically when needed. +set(CMAKE_AUTOMOC ON) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() # Include this package's headers first include_directories( BEFORE ./ ./include ../../include ) - -# Find CGAL and CGAL Qt4 -find_package(CGAL COMPONENTS Qt4) +# Find CGAL and CGAL Qt5 +find_package(CGAL COMPONENTS Qt5 ) include( ${CGAL_USE_FILE} ) -# Find Qt4 itself -set( QT_USE_QTXML TRUE ) -set( QT_USE_QTMAIN TRUE ) -set( QT_USE_QTSCRIPT TRUE ) -set( QT_USE_QTOPENGL TRUE ) -find_package(Qt4) +# Find Qt5 itself +find_package(Qt5 QUIET COMPONENTS Xml Script OpenGL Gui Svg) # Find OpenGL find_package(OpenGL) # Find QGLViewer -if(QT4_FOUND) - include(${QT_USE_FILE}) +if(Qt5_FOUND) find_package(QGLViewer ) -endif(QT4_FOUND) +endif(Qt5_FOUND) -if(CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) +if(CGAL_FOUND AND CGAL_Qt5_FOUND AND Qt5_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) include_directories ( ${QGLVIEWER_INCLUDE_DIR} ) - qt4_wrap_ui( UI_FILES MainWindow.ui ) + qt5_wrap_ui( UI_FILES MainWindow.ui ) include(AddFileDependencies) - qt4_generate_moc( "MainWindow.h" "${CMAKE_CURRENT_BINARY_DIR}/MainWindow_moc.cpp" ) + qt5_generate_moc( "MainWindow.h" "${CMAKE_CURRENT_BINARY_DIR}/MainWindow_moc.cpp" ) add_file_dependencies( MainWindow_moc.cpp "${CMAKE_CURRENT_SOURCE_DIR}/MainWindow.h" ) - qt4_generate_moc( "Viewer.h" "${CMAKE_CURRENT_BINARY_DIR}/Viewer_moc.cpp" ) + qt5_generate_moc( "Viewer.h" "${CMAKE_CURRENT_BINARY_DIR}/Viewer_moc.cpp" ) add_file_dependencies( Viewer_moc.cpp "${CMAKE_CURRENT_SOURCE_DIR}/Viewer.h" ) - qt4_generate_moc( "Scene.h" "${CMAKE_CURRENT_BINARY_DIR}/Scene_moc.cpp" ) + qt5_generate_moc( "Scene.h" "${CMAKE_CURRENT_BINARY_DIR}/Scene_moc.cpp" ) add_file_dependencies( Scene_moc.cpp "${CMAKE_CURRENT_SOURCE_DIR}/Scene.h" ) - qt4_add_resources ( RESOURCE_FILES AABB_demo.qrc ) + qt5_add_resources ( RESOURCE_FILES AABB_demo.qrc ) add_file_dependencies( AABB_demo.cpp "${CMAKE_CURRENT_BINARY_DIR}/MainWindow_moc.cpp" "${CMAKE_CURRENT_BINARY_DIR}/Viewer_moc.cpp" "${CMAKE_CURRENT_BINARY_DIR}/Scene_moc.cpp" ) add_executable ( AABB_demo AABB_demo.cpp ${UI_FILES} ${RESOURCE_FILES} ) - + qt5_use_modules(AABB_demo Gui OpenGL Xml Script Svg ) # Link with Qt libraries target_link_libraries( AABB_demo ${QT_LIBRARIES} ) @@ -69,7 +65,7 @@ if(CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FO add_to_cached_list( CGAL_EXECUTABLE_TARGETS AABB_demo ) -else (CGAL_FOUND AND CGAL_CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) +else (CGAL_FOUND AND CGAL_CGAL_Qt5_FOUND AND Qt5_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) set(AABB_MISSING_DEPS "") @@ -77,12 +73,12 @@ else (CGAL_FOUND AND CGAL_CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLV set(AABB_MISSING_DEPS "the CGAL library, ${AABB_MISSING_DEPS}") endif() - if(NOT CGAL_Qt4_FOUND) - set(AABB_MISSING_DEPS "the CGAL Qt4 library, ${AABB_MISSING_DEPS}") + if(NOT CGAL_Qt5_FOUND) + set(AABB_MISSING_DEPS "the CGAL Qt5 library, ${AABB_MISSING_DEPS}") endif() - if(NOT QT4_FOUND) - set(AABB_MISSING_DEPS "Qt4, ${AABB_MISSING_DEPS}") + if(NOT Qt5_FOUND) + set(AABB_MISSING_DEPS "Qt5, ${AABB_MISSING_DEPS}") endif() if(NOT OPENGL_FOUND) @@ -95,4 +91,4 @@ else (CGAL_FOUND AND CGAL_CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLV message(STATUS "NOTICE: This demo requires ${AABB_MISSING_DEPS}and will not be compiled.") -endif (CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) +endif (CGAL_FOUND AND CGAL_Qt5_FOUND AND Qt5_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) diff --git a/AABB_tree/demo/AABB_tree/MainWindow.cpp b/AABB_tree/demo/AABB_tree/MainWindow.cpp index e3282019ab2..260cc5972bc 100644 --- a/AABB_tree/demo/AABB_tree/MainWindow.cpp +++ b/AABB_tree/demo/AABB_tree/MainWindow.cpp @@ -27,11 +27,10 @@ MainWindow::MainWindow(QWidget* parent) // accepts drop events setAcceptDrops(true); - // setups scene - m_pScene = new Scene; + m_pScene = new Scene(); m_pViewer->setScene(m_pScene); - m_pViewer->setManipulatedFrame(m_pScene->manipulatedFrame()); + m_pViewer->setManipulatedFrame(m_pScene->manipulatedFrame()); // connects actionQuit (Ctrl+Q) and qApp->quit() connect(ui->actionQuit, SIGNAL(triggered()), @@ -154,9 +153,11 @@ void MainWindow::setAddKeyFrameKeyboardModifiers(::Qt::KeyboardModifiers m) void MainWindow::on_actionInside_points_triggered() { bool ok; + const unsigned int nb_points = (unsigned) - QInputDialog::getInteger(NULL, "#Points", + QInputDialog::getInt(NULL, "#Points", "#Points:",10000,1,100000000,9,&ok); + if(!ok) return; @@ -169,9 +170,11 @@ void MainWindow::on_actionInside_points_triggered() void MainWindow::on_actionPoints_in_interval_triggered() { bool ok; + const unsigned int nb_points = (unsigned) - QInputDialog::getInteger(NULL, "#Points", + QInputDialog::getInt(NULL, "#Points", "#Points:",10000,1,100000000,9,&ok); + if(!ok) return; @@ -195,9 +198,11 @@ void MainWindow::on_actionPoints_in_interval_triggered() void MainWindow::on_actionBoundary_segments_triggered() { bool ok; + const unsigned int nb_slices = (unsigned) - QInputDialog::getInteger(NULL, "#Slices", + QInputDialog::getInt(NULL, "#Slices", "Slices:",100,1,1000000,8,&ok); + if(!ok) return; @@ -210,9 +215,11 @@ void MainWindow::on_actionBoundary_segments_triggered() void MainWindow::on_actionBoundary_points_triggered() { bool ok; + const unsigned int nb_points = (unsigned) - QInputDialog::getInteger(NULL, "#Points", + QInputDialog::getInt(NULL, "#Points", "Points:",1000,1,10000000,8,&ok); + if(!ok) return; @@ -225,9 +232,11 @@ void MainWindow::on_actionBoundary_points_triggered() void MainWindow::on_actionEdge_points_triggered() { bool ok; + const unsigned int nb_points = (unsigned) - QInputDialog::getInteger(NULL, "#Points", + QInputDialog::getInt(NULL, "#Points", "Points:",1000,1,10000000,8,&ok); + if(!ok) return; diff --git a/AABB_tree/demo/AABB_tree/Scene.cpp b/AABB_tree/demo/AABB_tree/Scene.cpp index 43a4c80db29..bb332daedb5 100644 --- a/AABB_tree/demo/AABB_tree/Scene.cpp +++ b/AABB_tree/demo/AABB_tree/Scene.cpp @@ -10,22 +10,29 @@ #include #include "Refiner.h" -#include "render_edges.h" +//#include "render_edges.h" #include #include #include +#include +#include +#include +#include "Viewer.h" + // constants const int slow_distance_grid_size = 100; const int fast_distance_grid_size = 20; +#define _SIGNED 0 +#define _UNSIGNED 1 Scene::Scene() - : m_frame (new ManipulatedFrame()) - , m_view_plane(false) - , m_grid_size(slow_distance_grid_size) - , m_cut_plane(NONE) + : m_frame (new ManipulatedFrame()) + , m_view_plane(false) + , m_grid_size(slow_distance_grid_size) + , m_cut_plane(NONE) { m_pPolyhedron = NULL; @@ -38,12 +45,481 @@ Scene::Scene() m_red_ramp.build_red(); m_blue_ramp.build_blue(); m_max_distance_function = (FT)0.0; + texture = new Texture(m_grid_size,m_grid_size); + are_buffers_initialized = false; + } Scene::~Scene() { delete m_pPolyhedron; delete m_frame; + + buffers[0].destroy(); + buffers[1].destroy(); + buffers[2].destroy(); + buffers[3].destroy(); + buffers[4].destroy(); + buffers[5].destroy(); + buffers[6].destroy(); + buffers[7].destroy(); + vao[0].destroy(); + vao[1].destroy(); + vao[2].destroy(); + vao[3].destroy(); + vao[4].destroy(); + vao[5].destroy(); + vao[6].destroy(); + + +} + +void Scene::compile_shaders() +{ + if(! buffers[0].create() || !buffers[1].create() || !buffers[2].create() || !buffers[3].create() || !buffers[4].create() || !buffers[5].create() || !buffers[6].create() || !buffers[7].create()) + { + std::cerr<<"VBO Creation FAILED"<compileSourceCode(vertex_source)) + { + std::cerr<<"Compiling vertex source FAILED"<compileSourceCode(fragment_source)) + { + std::cerr<<"Compiling fragmentsource FAILED"<compileSourceCode(tex_vertex_source)) + { + std::cerr<<"Compiling vertex source FAILED"<compileSourceCode(tex_fragment_source)) + { + std::cerr<<"Compiling fragmentsource FAILED"<(pos_points.size()*sizeof(float))); + points_vertexLocation = rendering_program.attributeLocation("vertex"); + rendering_program.bind(); + rendering_program.enableAttributeArray(points_vertexLocation); + rendering_program.setAttributeBuffer(points_vertexLocation,GL_FLOAT,0,3); + buffers[0].release(); + rendering_program.release(); + vao[0].release(); + + //Lines + vao[1].bind(); + buffers[1].bind(); + buffers[1].allocate(pos_lines.data(), + static_cast(pos_lines.size()*sizeof(float))); + lines_vertexLocation = rendering_program.attributeLocation("vertex"); + rendering_program.bind(); + rendering_program.setAttributeBuffer(lines_vertexLocation,GL_FLOAT,0,3); + buffers[1].release(); + rendering_program.enableAttributeArray(lines_vertexLocation); + rendering_program.release(); + vao[1].release(); + + //Polyhedron's edges + vao[2].bind(); + buffers[2].bind(); + buffers[2].allocate(pos_poly.data(), + static_cast(pos_poly.size()*sizeof(float))); + poly_vertexLocation = rendering_program.attributeLocation("vertex"); + rendering_program.bind(); + rendering_program.setAttributeBuffer(poly_vertexLocation,GL_FLOAT,0,3); + rendering_program.enableAttributeArray(poly_vertexLocation); + buffers[2].release(); + rendering_program.release(); + vao[2].release(); + + //cutting segments + vao[3].bind(); + buffers[3].bind(); + buffers[3].allocate(pos_cut_segments.data(), + static_cast(pos_cut_segments.size()*sizeof(float))); + poly_vertexLocation = rendering_program.attributeLocation("vertex"); + rendering_program.bind(); + rendering_program.setAttributeBuffer(poly_vertexLocation,GL_FLOAT,0,3); + rendering_program.enableAttributeArray(poly_vertexLocation); + buffers[3].release(); + rendering_program.release(); + vao[3].release(); + + //cutting plane + vao[4].bind(); + buffers[4].bind(); + buffers[4].allocate(pos_plane.data(), static_cast(pos_plane.size()*sizeof(float))); + poly_vertexLocation = rendering_program.attributeLocation("vertex"); + rendering_program.bind(); + rendering_program.setAttributeBuffer(poly_vertexLocation,GL_FLOAT,0,3); + rendering_program.enableAttributeArray(poly_vertexLocation); + buffers[4].release(); + rendering_program.release(); + + vao[4].release(); + + //grid + vao[5].bind(); + buffers[5].bind(); + buffers[5].allocate(pos_grid.data(), static_cast(pos_grid.size()*sizeof(float))); + poly_vertexLocation = rendering_program.attributeLocation("vertex"); + rendering_program.bind(); + rendering_program.setAttributeBuffer(poly_vertexLocation,GL_FLOAT,0,3); + rendering_program.enableAttributeArray(poly_vertexLocation); + buffers[5].release(); + rendering_program.release(); + vao[5].release(); + + //cutting plane + vao[6].bind(); + buffers[6].bind(); + buffers[6].allocate(pos_plane.data(), static_cast(pos_plane.size()*sizeof(float))); + poly_vertexLocation = tex_rendering_program.attributeLocation("vertex"); + tex_rendering_program.bind(); + tex_rendering_program.setAttributeBuffer(poly_vertexLocation,GL_FLOAT,0,3); + tex_rendering_program.enableAttributeArray(poly_vertexLocation); + buffers[6].release(); + tex_rendering_program.release(); + + buffers[7].bind(); + buffers[7].allocate(tex_map.data(), static_cast(tex_map.size()*sizeof(float))); + tex_Location = tex_rendering_program.attributeLocation("tex_coord"); + tex_rendering_program.bind(); + tex_rendering_program.setAttributeBuffer(tex_Location,GL_FLOAT,0,2); + tex_rendering_program.enableAttributeArray(tex_Location); + buffers[7].release(); + tex_rendering_program.release(); + + gl->glBindTexture(GL_TEXTURE_2D, textureId); + gl->glTexImage2D(GL_TEXTURE_2D, + 0, + GL_RGB, + texture->getWidth(), + texture->getHeight(), + 0, + GL_RGB, + GL_UNSIGNED_BYTE, + texture->getData()); + gl->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + gl->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + gl->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE ); + gl->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE ); + vao[6].release(); + + are_buffers_initialized = true; + + + +} + +void Scene::compute_elements(int mode) +{ + pos_points.resize(0); + pos_lines.resize(0); + pos_poly.resize(0); + pos_cut_segments.resize(0); + tex_map.resize(0); + pos_grid.resize(66); + pos_plane.resize(18); + float diag = .6f * float(bbox_diag()); + //The Points + { + std::list::iterator pit; + for(pit = m_points.begin(); pit != m_points.end(); pit++) + { + const Point& p = *pit; + pos_points.push_back(p.x()); + pos_points.push_back(p.y()); + pos_points.push_back(p.z()); + } + } + //The Segements + { + std::list::iterator sit; + for(sit = m_segments.begin(); sit != m_segments.end(); sit++) + { + const Segment& s = *sit; + const Point& p = s.source(); + const Point& q = s.target(); + + pos_lines.push_back(p.x()); + pos_lines.push_back(p.y()); + pos_lines.push_back(p.z()); + + pos_lines.push_back(q.x()); + pos_lines.push_back(q.y()); + pos_lines.push_back(q.z()); + } + } + //The Polygon's edges + { + Polyhedron::Edge_iterator he; + for(he = m_pPolyhedron->edges_begin(); + he != m_pPolyhedron->edges_end(); + he++) + { + const Point& a = he->vertex()->point(); + const Point& b = he->opposite()->vertex()->point(); + pos_poly.push_back(a.x()); + pos_poly.push_back(a.y()); + pos_poly.push_back(a.z()); + + pos_poly.push_back(b.x()); + pos_poly.push_back(b.y()); + pos_poly.push_back(b.z()); + } + } + //The cutting segments + { + for ( std::vector::const_iterator csit = m_cut_segments.begin(), + end = m_cut_segments.end() ; csit != end ; ++csit ) + { + const Point& a = csit->source(); + const Point& b = csit->target(); + + pos_cut_segments.push_back(a.x()); + pos_cut_segments.push_back(a.y()); + pos_cut_segments.push_back(a.z()); + + pos_cut_segments.push_back(b.x()); + pos_cut_segments.push_back(b.y()); + pos_cut_segments.push_back(b.z()); + } + } + //The cutting plane + { + + pos_plane[0]= -diag; pos_plane[1]=-diag; pos_plane[2]=0.0; + pos_plane[3]= -diag; pos_plane[4]= diag; pos_plane[5]=0.; + pos_plane[6]= diag; pos_plane[7]= diag; pos_plane[8]=0.; + pos_plane[9]= -diag; pos_plane[10]= -diag; pos_plane[11]=0.; + pos_plane[12]= diag; pos_plane[13]= diag; pos_plane[14]= 0.; + pos_plane[15]= diag; pos_plane[16]= -diag; pos_plane[17]= 0.; + + //UV Mapping + tex_map.push_back(-0.11f); + tex_map.push_back(-0.11f); + + tex_map.push_back(-0.11f); + tex_map.push_back(1.11f); + + tex_map.push_back(1.11f); + tex_map.push_back(1.11f); + + tex_map.push_back(-0.11f); + tex_map.push_back(-0.11f); + + tex_map.push_back(1.11f); + tex_map.push_back(1.11f); + + tex_map.push_back(1.11f); + tex_map.push_back(-0.11f); + + + + + + } + //The grid + { + float z = 0; + float x = (2 * diag)/10.0; + float y = (2 * diag)/10.0; + for(int u = 0; u < 11; u++) + { + + pos_grid.push_back(-diag + x* u); + pos_grid.push_back(-diag); + pos_grid.push_back(z); + + pos_grid.push_back(-diag + x* u); + pos_grid.push_back(diag); + pos_grid.push_back(z); + } + for(int v=0; v<11; v++) + { + + pos_grid.push_back(-diag); + pos_grid.push_back(-diag + v * y); + pos_grid.push_back(z); + + pos_grid.push_back(diag); + pos_grid.push_back(-diag + v * y); + pos_grid.push_back(z); + + } + + } + //The texture + switch(mode) + { + case _SIGNED: + for( int i=0 ; i < texture->getWidth(); i++ ) + { + for( int j=0 ; j < texture->getHeight() ; j++) + { + compute_texture(i,j,m_red_ramp,m_blue_ramp); + } + } + break; + case _UNSIGNED: + for( int i=0 ; i < texture->getWidth(); i++ ) + { + for( int j=0 ; j < texture->getHeight() ; j++) + { + compute_texture(i,j,m_thermal_ramp,m_thermal_ramp); + } + } + break;} + sampler_location = tex_rendering_program.attributeLocation("texture"); +} + +void Scene::compute_texture(int i, int j,Color_ramp pos_ramp ,Color_ramp neg_ramp) +{ + + + const FT& d00 = m_distance_function[i][j].second; + // determines grey level + unsigned int i00 = 255-(unsigned)(255.0 * (double)std::fabs(d00) / m_max_distance_function); + + if(d00 > 0.0) + texture->setData(i,j,pos_ramp.r(i00),pos_ramp.g(i00),pos_ramp.b(i00)); + else + texture->setData(i,j,neg_ramp.r(i00),neg_ramp.g(i00),neg_ramp.b(i00)); + + +} + +void Scene::attrib_buffers(QGLViewer* viewer) +{ + QMatrix4x4 mvpMatrix; + double mat[16]; + viewer->camera()->getModelViewProjectionMatrix(mat); + for(int i=0; i < 16; i++) + { + mvpMatrix.data()[i] = (float)mat[i]; + } + rendering_program.bind(); + mvpLocation = rendering_program.uniformLocation("mvp_matrix"); + fLocation = rendering_program.uniformLocation("f_matrix"); + colorLocation = rendering_program.uniformLocation("color"); + rendering_program.setUniformValue(mvpLocation, mvpMatrix); + rendering_program.release(); + + tex_rendering_program.bind(); + tex_mvpLocation = tex_rendering_program.uniformLocation("mvp_matrix"); + tex_fLocation = tex_rendering_program.uniformLocation("f_matrix"); + tex_rendering_program.setUniformValue(tex_mvpLocation, mvpMatrix); + tex_rendering_program.release(); +} + +void Scene::changed() +{ + if(m_cut_plane == UNSIGNED_FACETS || m_cut_plane == UNSIGNED_EDGES) + compute_elements(_UNSIGNED); + else + compute_elements(_SIGNED); + are_buffers_initialized = false; + } int Scene::open(QString filename) @@ -78,11 +554,12 @@ int Scene::open(QString filename) return -1; } - + // clear tree clear_internal_data(); QApplication::restoreOverrideCursor(); + changed(); return 0; } @@ -108,204 +585,128 @@ void Scene::update_bbox() for(; it != m_pPolyhedron->points_end();it++) m_bbox = m_bbox + (*it).bbox(); std::cout << "done (" << m_pPolyhedron->size_of_facets() - << " facets)" << std::endl; + << " facets)" << std::endl; } -void Scene::draw() -{ - if(m_view_plane) - ::glEnable(GL_DEPTH_TEST); - else - ::glDisable(GL_DEPTH_TEST); - - if(m_view_polyhedron) - draw_polyhedron(); +void Scene::draw(QGLViewer* viewer) +{ + if(!are_buffers_initialized) + initialize_buffers(); + QColor color; + QMatrix4x4 fMatrix; + fMatrix.setToIdentity(); + if(m_view_polyhedron && pos_poly.size()>0) + { + vao[2].bind(); + attrib_buffers(viewer); + rendering_program.bind(); + color.setRgbF(0.0,0.0,0.0); + rendering_program.setUniformValue(colorLocation, color); + rendering_program.setUniformValue(fLocation, fMatrix); + gl->glDrawArrays(GL_LINES, 0, static_cast(pos_poly.size()/3)); + rendering_program.release(); + vao[2].release(); + } + if(m_view_points && pos_points.size()>0) + { + gl->glPointSize(2.0f); + vao[0].bind(); + attrib_buffers(viewer); + rendering_program.bind(); + color.setRgbF(0.7,0.0,0.0); + rendering_program.setUniformValue(colorLocation, color); + rendering_program.setUniformValue(fLocation, fMatrix); + gl->glDrawArrays(GL_POINTS, 0, static_cast(pos_points.size()/3)); + rendering_program.release(); + vao[0].release(); + } - if(m_view_points) - draw_points(); - - if(m_view_segments) - draw_segments(); - - if (m_view_plane) + if(m_view_segments && pos_lines.size()>0) + { + vao[1].bind(); + attrib_buffers(viewer); + rendering_program.bind(); + color.setRgbF(0.0,0.7,0.0); + rendering_program.setUniformValue(colorLocation, color); + rendering_program.setUniformValue(fLocation, fMatrix); + gl->glDrawArrays(GL_LINES, 0, static_cast(pos_lines.size()/3)); + rendering_program.release(); + vao[1].release(); + } + if (m_view_plane && pos_plane.size()>0) { switch( m_cut_plane ) { - case UNSIGNED_EDGES: - case UNSIGNED_FACETS: - draw_distance_function(m_thermal_ramp, m_thermal_ramp); - break; - case SIGNED_FACETS: - draw_distance_function(m_red_ramp, m_blue_ramp); - break; - case CUT_SEGMENTS: - draw_cut_segment_plane(); - break; - case NONE: // do nothing - break; + case UNSIGNED_EDGES: + case UNSIGNED_FACETS: + case SIGNED_FACETS: + + gl->glActiveTexture(GL_TEXTURE0); + gl->glBindTexture(GL_TEXTURE_2D, textureId); + + for(int i=0; i< 16 ; i++) + fMatrix.data()[i] = m_frame->matrix()[i]; + vao[6].bind(); + attrib_buffers(viewer); + tex_rendering_program.bind(); + tex_rendering_program.setUniformValue(tex_fLocation, fMatrix); + + gl->glDrawArrays(GL_TRIANGLES, 0,static_cast(pos_plane.size()/3)); + tex_rendering_program.release(); + vao[6].release(); + break; + + case CUT_SEGMENTS: + + //cutting_segments + fMatrix.setToIdentity(); + ::glLineWidth(2.0f); + vao[3].bind(); + attrib_buffers(viewer); + rendering_program.bind(); + color.setRgbF(1.0,0.0,0.0); + rendering_program.setUniformValue(colorLocation, color); + rendering_program.setUniformValue(fLocation, fMatrix); + gl->glDrawArrays(GL_LINES, 0, static_cast(pos_cut_segments.size()/3)); + ::glLineWidth(1.0f); + rendering_program.release(); + vao[3].release(); + //grid + for(int i=0; i< 16 ; i++) + fMatrix.data()[i] = m_frame->matrix()[i]; + vao[5].bind(); + attrib_buffers(viewer); + rendering_program.bind(); + color.setRgbF(.6f, .6f, .6f); + rendering_program.setUniformValue(colorLocation, color); + rendering_program.setUniformValue(fLocation, fMatrix); + gl->glDrawArrays(GL_LINES, 0, static_cast(pos_grid.size()/3)); + rendering_program.release(); + vao[5].release(); + + //cutting_plane + // for(int i=0; i< 16 ; i++) + // fMatrix.data()[i] = m_frame->matrix()[i]; + ::glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + ::glEnable(GL_BLEND); + vao[4].bind(); + attrib_buffers(viewer); + rendering_program.bind(); + color.setRgbF(.6f, .85f, 1.f, .65f); + rendering_program.setUniformValue(colorLocation, color); + rendering_program.setUniformValue(fLocation, fMatrix); + gl->glDrawArrays(GL_TRIANGLES, 0, static_cast(pos_plane.size()/3)); + ::glDisable(GL_BLEND); + rendering_program.release(); + vao[4].release(); + + break; + case NONE: // do nothing + break; } } -} -void Scene::draw_polyhedron() -{ - // draw black edges - if(m_pPolyhedron != NULL) - { - ::glDisable(GL_LIGHTING); - ::glColor3ub(0,0,0); - ::glLineWidth(1.0f); - gl_render_edges(*m_pPolyhedron); - } -} -void Scene::draw_segments() -{ - if(m_segments.size() != 0) - { - ::glDisable(GL_LIGHTING); - ::glColor3ub(0,100,0); - ::glLineWidth(2.0f); - ::glBegin(GL_LINES); - std::list::iterator it; - for(it = m_segments.begin(); it != m_segments.end(); it++) - { - const Segment& s = *it; - const Point& p = s.source(); - const Point& q = s.target(); - ::glVertex3d(p.x(),p.y(),p.z()); - ::glVertex3d(q.x(),q.y(),q.z()); - } - ::glEnd(); - } -} - -void Scene::draw_points() -{ - // draw red points - if(m_points.size() != 0) - { - ::glDisable(GL_LIGHTING); - ::glColor3ub(180,0,0); - ::glPointSize(2.0f); - ::glBegin(GL_POINTS); - std::list::iterator it; - for(it = m_points.begin(); it != m_points.end(); it++) - { - const Point& p = *it; - ::glVertex3d(p.x(),p.y(),p.z()); - } - ::glEnd(); - } -} - -void Scene::draw_distance_function(const Color_ramp& ramp_pos, - const Color_ramp& ramp_neg) const -{ - ::glDisable(GL_LIGHTING); - if ( m_fast_distance ) { ::glShadeModel(GL_FLAT); } - else { ::glShadeModel(GL_SMOOTH); } - - ::glBegin(GL_QUADS); - int i,j; - const int nb_quads = m_grid_size-1; - for(i=0;i 0.0) - ::glColor3ub(ramp_pos.r(i00),ramp_pos.g(i00),ramp_pos.b(i00)); - else - ::glColor3ub(ramp_neg.r(i00),ramp_neg.g(i00),ramp_neg.b(i00)); - ::glVertex3d(p00.x(),p00.y(),p00.z()); - - if(d01 > 0.0) - ::glColor3ub(ramp_pos.r(i01),ramp_pos.g(i01),ramp_pos.b(i01)); - else - ::glColor3ub(ramp_neg.r(i01),ramp_neg.g(i01),ramp_neg.b(i01)); - ::glVertex3d(p01.x(),p01.y(),p01.z()); - - if(d11 > 0) - ::glColor3ub(ramp_pos.r(i11),ramp_pos.g(i11),ramp_pos.b(i11)); - else - ::glColor3ub(ramp_neg.r(i11),ramp_neg.g(i11),ramp_neg.b(i11)); - ::glVertex3d(p11.x(),p11.y(),p11.z()); - - if(d10 > 0) - ::glColor3ub(ramp_pos.r(i10),ramp_pos.g(i10),ramp_pos.b(i10)); - else - ::glColor3ub(ramp_neg.r(i10),ramp_neg.g(i10),ramp_neg.b(i10)); - ::glVertex3d(p10.x(),p10.y(),p10.z()); - } - } - ::glEnd(); -} - -void Scene::draw_cut_segment_plane() const -{ - float diag = .6f * float(bbox_diag()); - - ::glDisable(GL_LIGHTING); - ::glLineWidth(1.0f); - ::glColor3f(.6f, .6f, .6f); - - // draw grid - ::glPushMatrix(); - ::glMultMatrixd(m_frame->matrix()); - QGLViewer::drawGrid(diag); - ::glPopMatrix(); - - // draw cut segments - ::glLineWidth(2.0f); - ::glColor3f(1.f, 0.f, 0.f); - ::glBegin(GL_LINES); - for ( std::vector::const_iterator it = m_cut_segments.begin(), - end = m_cut_segments.end() ; it != end ; ++it ) - { - const Point& a = it->source(); - const Point& b = it->target(); - - ::glVertex3d(a.x(), a.y(), a.z()); - ::glVertex3d(b.x(), b.y(), b.z()); - } - ::glEnd(); - - // fill grid with transparent blue - ::glPushMatrix(); - ::glMultMatrixd(m_frame->matrix()); - ::glColor4f(.6f, .85f, 1.f, .65f); - - ::glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); - ::glEnable(GL_BLEND); - ::glBegin(GL_QUADS); - ::glVertex3d(-diag, -diag, 0.); - ::glVertex3d(-diag, diag, 0.); - ::glVertex3d( diag, diag, 0.); - ::glVertex3d( diag, -diag, 0.); - ::glEnd(); - ::glDisable(GL_BLEND); - - ::glPopMatrix(); } FT Scene::random_in(const double a, @@ -370,20 +771,20 @@ Plane Scene::frame_plane() const Aff_transformation Scene::frame_transformation() const { const ::GLdouble* m = m_frame->matrix(); - + // OpenGL matrices are row-major matrices return Aff_transformation (m[0], m[4], m[8], m[12], - m[1], m[5], m[9], m[13], - m[2], m[6], m[10], m[14]); + m[1], m[5], m[9], m[13], + m[2], m[6], m[10], m[14]); } FT Scene::bbox_diag() const { - double dx = m_bbox.xmax()-m_bbox.xmin(); - double dy = m_bbox.ymax()-m_bbox.ymin(); - double dz = m_bbox.zmax()-m_bbox.zmin(); - - return FT(std::sqrt(dx*dx + dy*dy + dz*dz)); + double dx = m_bbox.xmax()-m_bbox.xmin(); + double dy = m_bbox.ymax()-m_bbox.ymin(); + double dz = m_bbox.zmax()-m_bbox.zmin(); + + return FT(std::sqrt(dx*dx + dy*dy + dz*dz)); } void Scene::build_facet_tree() @@ -396,7 +797,7 @@ void Scene::build_facet_tree() // Don't rebuild tree if it is already built if ( !m_facet_tree.empty() ) { return; } - + // build tree CGAL::Timer timer; timer.start(); @@ -413,10 +814,10 @@ void Scene::build_edge_tree() std::cerr << "Build edge tree failed: load polyhedron first." << std::endl; return; } - + // Don't rebuild tree if it is already built if ( !m_edge_tree.empty() ) { return; } - + // build tree CGAL::Timer timer; timer.start(); @@ -440,14 +841,16 @@ void Scene::clear_cutting_plane() { m_cut_segments.clear(); m_cut_plane = NONE; - + deactivate_cutting_plane(); + changed(); } void Scene::update_grid_size() { m_grid_size = m_fast_distance ? fast_distance_grid_size : slow_distance_grid_size; + texture = new Texture(m_grid_size,m_grid_size); } void Scene::generate_points_in(const unsigned int nb_points, @@ -471,7 +874,7 @@ void Scene::generate_points_in(const unsigned int nb_points, CGAL::Timer timer; timer.start(); std::cout << "Generate " << nb_points << " points in interval [" - << min << ";" << max << "]"; + << min << ";" << max << "]"; unsigned int nb_trials = 0; Vector vec = random_vector(); @@ -489,7 +892,7 @@ void Scene::generate_points_in(const unsigned int nb_points, signed_distance *= -1.0; if(signed_distance >= min && - signed_distance <= max) + signed_distance <= max) { m_points.push_back(p); if(m_points.size()%(nb_points/10) == 0) @@ -499,8 +902,9 @@ void Scene::generate_points_in(const unsigned int nb_points, } double speed = (double)nb_trials / timer.time(); std::cout << "done (" << nb_trials << " trials, " - << timer.time() << " s, " - << speed << " queries/s)" << std::endl; + << timer.time() << " s, " + << speed << " queries/s)" << std::endl; + changed(); } @@ -541,8 +945,9 @@ void Scene::generate_inside_points(const unsigned int nb_points) } double speed = (double)nb_trials / timer.time(); std::cout << "done (" << nb_trials << " trials, " - << timer.time() << " s, " - << speed << " queries/s)" << std::endl; + << timer.time() << " s, " + << speed << " queries/s)" << std::endl; + changed(); } void Scene::generate_boundary_segments(const unsigned int nb_slices) @@ -592,6 +997,7 @@ void Scene::generate_boundary_segments(const unsigned int nb_slices) } } std::cout << m_segments.size() << " segments, " << timer.time() << " s." << std::endl; + changed(); } void Scene::generate_boundary_points(const unsigned int nb_points) @@ -641,6 +1047,7 @@ void Scene::generate_boundary_points(const unsigned int nb_points) } } std::cout << nb_lines << " line queries, " << timer.time() << " s." << std::endl; + changed(); } void Scene::generate_edge_points(const unsigned int nb_points) @@ -692,6 +1099,7 @@ void Scene::generate_edge_points(const unsigned int nb_points) } } std::cout << nb_planes << " plane queries, " << timer.time() << " s." << std::endl; + changed(); } @@ -700,25 +1108,25 @@ void Scene::compute_distance_function(const Tree& tree) { // Get transformation Aff_transformation t = frame_transformation(); - + m_max_distance_function = FT(0); FT diag = bbox_diag(); - + const FT dx = diag; const FT dy = diag; const FT z (0); - + const FT fd = FT(2); for(int i=0 ; i Intersections; Intersections intersections; m_facet_tree.all_intersections(plane, std::back_inserter(intersections)); - + // Fill data structure m_cut_segments.clear(); for ( Intersections::iterator it = intersections.begin(), - end = intersections.end() ; it != end ; ++it ) + end = intersections.end() ; it != end ; ++it ) { const Segment* inter_seg = CGAL::object_cast(&(it->first)); - + if ( NULL != inter_seg ) { m_cut_segments.push_back(*inter_seg); } } - + m_cut_plane = CUT_SEGMENTS; + changed(); } void Scene::cutting_plane() { switch( m_cut_plane ) { - case UNSIGNED_FACETS: - return unsigned_distance_function(); - case SIGNED_FACETS: - return signed_distance_function(); - case UNSIGNED_EDGES: - return unsigned_distance_function_to_edges(); - case CUT_SEGMENTS: - return cut_segment_plane(); - case NONE: // do nothing - return; + case UNSIGNED_FACETS: + return unsigned_distance_function(); + case SIGNED_FACETS: + return signed_distance_function(); + case UNSIGNED_EDGES: + return unsigned_distance_function_to_edges(); + case CUT_SEGMENTS: + return cut_segment_plane(); + case NONE: // do nothing + return; } - + // Should not be here std::cerr << "Unknown cut_plane type" << std::endl; CGAL_assertion(false); @@ -867,7 +1280,7 @@ void Scene::refine_bisection(const FT max_sqlen) Refiner refiner(m_pPolyhedron); refiner(max_sqlen); std::cout << "done (" << m_pPolyhedron->size_of_facets() << " facets)" << std::endl; - + clear_internal_data(); } @@ -881,7 +1294,7 @@ void Scene::refine_loop() std::cout << "Loop subdivision..."; CGAL::Subdivision_method_3::Loop_subdivision(*m_pPolyhedron, 1); std::cout << "done (" << m_pPolyhedron->size_of_facets() << " facets)" << std::endl; - + clear_internal_data(); } @@ -897,3 +1310,23 @@ void Scene::deactivate_cutting_plane() disconnect(m_frame, SIGNAL(modified()), this, SLOT(cutting_plane())); m_view_plane = false; } +void Scene::initGL(Viewer *viewer) +{ + //qDebug()<<"context from scene is valid :"<isValid(); + //gl = 0; + //gl = viewer->context()->versionFunctions(); + gl = new QOpenGLFunctions_3_3_Core(); + + //if (!gl) { + // qFatal("Could not obtain required OpenGL context version"); + // exit(1); + //} + if(!gl->initializeOpenGLFunctions()) + { + qFatal("ERROR : OpenGL Functions not initialized. Check your OpenGL Verison (should be >=3.3)"); + exit(1); + } + + gl->glGenTextures(1, &textureId); + compile_shaders(); +} diff --git a/AABB_tree/demo/AABB_tree/Scene.h b/AABB_tree/demo/AABB_tree/Scene.h index 648bbd81691..59eca9d3aad 100644 --- a/AABB_tree/demo/AABB_tree/Scene.h +++ b/AABB_tree/demo/AABB_tree/Scene.h @@ -18,7 +18,39 @@ #include #include #include +#include +#include +#include +#include +#include +class Texture{ +private: + int Width; + int Height; + int size; + GLubyte *data; +public: + Texture(int w, int h) + { + Width = w; + Height = h; + size = 3*Height*Width; + data = new GLubyte[Height*Width*3]; + } + int getWidth() const {return Width;} + int getHeight() const {return Height;} + int getSize() const {return size;} + void setData(int i, int j, int r, int g, int b){ + data[3*(Width*j+i) + 0] = r; + data[3*(Width*j+i) + 1] = g; + data[3*(Width*j+i) + 2] = b; + } + + GLubyte* getData(){return data; } + +}; +class Viewer; class Scene : public QObject { Q_OBJECT @@ -45,13 +77,16 @@ private: }; public: - void draw(); + QGLContext* context; + void draw(QGLViewer*); void update_bbox(); Bbox bbox() { return m_bbox; } ManipulatedFrame* manipulatedFrame() const { return m_frame; } + void initGL(Viewer *viewer); private: // member data + QOpenGLFunctions_3_3_Core *gl; Bbox m_bbox; Polyhedron *m_pPolyhedron; std::list m_points; @@ -77,6 +112,7 @@ private: Edge_tree m_edge_tree; Cut_planes_types m_cut_plane; + bool are_buffers_initialized; private: // utility functions @@ -94,20 +130,55 @@ private: void build_edge_tree(); void clear_internal_data(); void update_grid_size(); - + template void compute_distance_function(const Tree& tree); template void sign_distance_function(const Tree& tree); + //Shaders elements + + int poly_vertexLocation; + int tex_Location; + int points_vertexLocation; + int lines_vertexLocation; + int mvpLocation; + int tex_mvpLocation; + int fLocation; + int tex_fLocation; + int colorLocation; + + + + std::vector pos_points; + std::vector pos_grid; + std::vector pos_lines; + std::vector pos_poly; + std::vector pos_plane; + std::vector pos_cut_segments; + std::vector tex_map; + GLuint textureId; + + Texture *texture; + GLint sampler_location; + QOpenGLBuffer buffers[10]; + QOpenGLVertexArrayObject vao[10]; + QOpenGLShaderProgram tex_rendering_program; + QOpenGLShaderProgram rendering_program; + void initialize_buffers(); + void compute_elements(int mode); + void attrib_buffers(QGLViewer*); + void compile_shaders(); + void compute_texture(int, int, Color_ramp, Color_ramp); + public: // file menu int open(QString filename); // edit menu - void clear_points() { m_points.clear(); } - void clear_segments() { m_segments.clear(); } + void clear_points() { m_points.clear(); changed(); } + void clear_segments() { m_segments.clear(); changed(); } void clear_cutting_plane(); // fast distance setter @@ -174,14 +245,6 @@ public: void bench_closest_point_and_primitive(Facet_tree& tree,const double duration); void bench_distance(Facet_tree& tree,const int function,const double duration); - // drawing - void draw_points(); - void draw_segments(); - void draw_polyhedron(); - void draw_distance_function(const Color_ramp& ramp_pos, - const Color_ramp& ramp_neg) const; - void draw_cut_segment_plane() const; - // cutting plane activation/deactivation void activate_cutting_plane(); void deactivate_cutting_plane(); @@ -189,7 +252,7 @@ public: public slots: // cutting plane void cutting_plane(); - + void changed(); }; // end class Scene #endif // SCENE_H diff --git a/AABB_tree/demo/AABB_tree/Viewer.cpp b/AABB_tree/demo/AABB_tree/Viewer.cpp index 9fadcbb847f..d8d359c89e0 100644 --- a/AABB_tree/demo/AABB_tree/Viewer.cpp +++ b/AABB_tree/demo/AABB_tree/Viewer.cpp @@ -1,13 +1,14 @@ #include "Viewer.h" #include "Scene.h" #include +#include +#include Viewer::Viewer(QWidget* parent) - : QGLViewer(parent), + : QGLViewer(CGAL::Qt::createOpenGLContext(),parent), m_pScene(NULL), m_custom_mouse(false) { - setBackgroundColor(::Qt::white); } void Viewer::setScene(Scene* pScene) @@ -20,14 +21,16 @@ void Viewer::draw() QGLViewer::draw(); if(m_pScene != NULL) { - ::glClearColor(1.0f,1.0f,1.0f,0.0f); - m_pScene->draw(); + m_pScene->draw(this); } + } void Viewer::initializeGL() { QGLViewer::initializeGL(); + setBackgroundColor(::Qt::white); + m_pScene->initGL(this); } void Viewer::mousePressEvent(QMouseEvent* e) @@ -60,4 +63,3 @@ void Viewer::mouseReleaseEvent(QMouseEvent* e) QGLViewer::mouseReleaseEvent(e); } - diff --git a/AABB_tree/demo/AABB_tree/Viewer.h b/AABB_tree/demo/AABB_tree/Viewer.h index 7d5920fcf41..5361bc12e99 100644 --- a/AABB_tree/demo/AABB_tree/Viewer.h +++ b/AABB_tree/demo/AABB_tree/Viewer.h @@ -3,11 +3,11 @@ #include + // forward declarations class QWidget; class Scene; - -class Viewer : public QGLViewer { +class Viewer : public QGLViewer{ Q_OBJECT diff --git a/AABB_tree/demo/AABB_tree/render_edges.h b/AABB_tree/demo/AABB_tree/render_edges.h deleted file mode 100644 index 899232d79d3..00000000000 --- a/AABB_tree/demo/AABB_tree/render_edges.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef _GL_RENDER_EDGES_ -#define _GL_RENDER_EDGES_ - -#include - -template -void gl_render_edges(Polyhedron& polyhedron) -{ - typedef typename Polyhedron::Traits Kernel; - typedef typename Kernel::Point_3 Point; - - ::glBegin(GL_LINES); - typename Polyhedron::Edge_iterator he; - for(he = polyhedron.edges_begin(); - he != polyhedron.edges_end(); - he++) - { - const Point& a = he->vertex()->point(); - const Point& b = he->opposite()->vertex()->point(); - ::glVertex3d(a.x(),a.y(),a.z()); - ::glVertex3d(b.x(),b.y(),b.z()); - } - ::glEnd(); -} - -#endif // _GL_RENDER_EDGES_ - - - - diff --git a/AABB_tree/include/CGAL/internal/AABB_tree/AABB_drawing_traits.h b/AABB_tree/include/CGAL/internal/AABB_tree/AABB_drawing_traits.h index 26893bd0916..4b16e52c597 100644 --- a/AABB_tree/include/CGAL/internal/AABB_tree/AABB_drawing_traits.h +++ b/AABB_tree/include/CGAL/internal/AABB_tree/AABB_drawing_traits.h @@ -23,12 +23,15 @@ #include #include +#include namespace CGAL { template struct AABB_drawing_traits { + std::vector *v_edges; + typedef CGAL::Bbox_3 Bbox; bool go_further() { return true; } @@ -45,7 +48,7 @@ struct AABB_drawing_traits } // draw bbox - static void gl_draw(const Bbox& bb) + void gl_draw(const Bbox& bb) { ::glBegin(GL_LINES); gl_draw_edge(bb.xmin(), bb.ymin(), bb.zmin(), @@ -79,11 +82,16 @@ struct AABB_drawing_traits ::glEnd(); } - static void gl_draw_edge(double px, double py, double pz, + void gl_draw_edge(double px, double py, double pz, double qx, double qy, double qz) { - ::glVertex3d(px,py,pz); - ::glVertex3d(qx,qy,qz); + v_edges->push_back((float)px); + v_edges->push_back((float)py); + v_edges->push_back((float)pz); + + v_edges->push_back((float)qx); + v_edges->push_back((float)qy); + v_edges->push_back((float)qz); } }; // AABB_drawing_traits diff --git a/Algebraic_kernel_d/examples/Algebraic_kernel_d/CMakeLists.txt b/Algebraic_kernel_d/examples/Algebraic_kernel_d/CMakeLists.txt index 3d99075d782..9313329bca7 100644 --- a/Algebraic_kernel_d/examples/Algebraic_kernel_d/CMakeLists.txt +++ b/Algebraic_kernel_d/examples/Algebraic_kernel_d/CMakeLists.txt @@ -4,12 +4,8 @@ project( Algebraic_kernel_d_test ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) -endif() +cmake_minimum_required(VERSION 2.8.11) + find_package(CGAL QUIET COMPONENTS Core MPFI) diff --git a/Algebraic_kernel_d/test/Algebraic_kernel_d/CMakeLists.txt b/Algebraic_kernel_d/test/Algebraic_kernel_d/CMakeLists.txt index 7349cd12e46..0f04b41d484 100644 --- a/Algebraic_kernel_d/test/Algebraic_kernel_d/CMakeLists.txt +++ b/Algebraic_kernel_d/test/Algebraic_kernel_d/CMakeLists.txt @@ -3,12 +3,8 @@ project( Algebraic_kernel_d_test ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) -endif() +cmake_minimum_required(VERSION 2.8.11) + # CGAL and its components find_package( CGAL QUIET COMPONENTS Core RS3) @@ -26,7 +22,7 @@ include( ${CGAL_USE_FILE} ) include( CGAL_CreateSingleSourceCGALProgram ) # Boost and its components -find_package( Boost REQUIRED ) +find_package( Boost ) if ( NOT Boost_FOUND ) diff --git a/Alpha_shapes_2/demo/Alpha_shapes_2/qt3/CMakeLists.txt b/Alpha_shapes_2/demo/Alpha_shapes_2/qt3/CMakeLists.txt index 1d1b730f997..b750205956e 100644 --- a/Alpha_shapes_2/demo/Alpha_shapes_2/qt3/CMakeLists.txt +++ b/Alpha_shapes_2/demo/Alpha_shapes_2/qt3/CMakeLists.txt @@ -9,7 +9,7 @@ include( ${CGAL_USE_FILE} ) find_package(Qt3-patched) # FindQt3-patched.cmake is FindQt3.cmake patched by CGAL developers, so -# that it can be used together with FindQt4: all its variables are prefixed +# that it can be used together with Qt5: all its variables are prefixed # by "QT3_" instead of "QT_". if ( CGAL_FOUND AND QT3_FOUND AND CGAL_Qt3_FOUND) diff --git a/Alpha_shapes_3/demo/Alpha_shapes_3/Alpha_shape_3.cpp b/Alpha_shapes_3/demo/Alpha_shapes_3/Alpha_shape_3.cpp index 6f529d9534d..23d10e74b2b 100644 --- a/Alpha_shapes_3/demo/Alpha_shapes_3/Alpha_shape_3.cpp +++ b/Alpha_shapes_3/demo/Alpha_shapes_3/Alpha_shape_3.cpp @@ -13,10 +13,13 @@ int main(int argc, char** argv) application.setOrganizationDomain("geometryfactory.com"); application.setOrganizationName("GeometryFactory"); application.setApplicationName("Alpha Shape Reconstruction"); + //for Windows + application.setAttribute(Qt::AA_UseDesktopOpenGL); - // Import resources from libCGALQt4. - // See http://doc.trolltech.com/4.4/qdir.html#Q_INIT_RESOURCE - CGAL_QT4_INIT_RESOURCES; + // Import resources from libCGALQt (Qt5). + // See http://doc.qt.io/qt-5/qdir.html#Q_INIT_RESOURCE + + CGAL_QT_INIT_RESOURCES; Q_INIT_RESOURCE(Alpha_shape_3); MainWindow mw; diff --git a/Alpha_shapes_3/demo/Alpha_shapes_3/CMakeLists.txt b/Alpha_shapes_3/demo/Alpha_shapes_3/CMakeLists.txt index 3a8b8d9d262..6613a7714f8 100644 --- a/Alpha_shapes_3/demo/Alpha_shapes_3/CMakeLists.txt +++ b/Alpha_shapes_3/demo/Alpha_shapes_3/CMakeLists.txt @@ -2,45 +2,40 @@ # This is the CMake script for compiling a CGAL application. project (Alpha_shape_3) - -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +# Find includes in corresponding build directories +set(CMAKE_INCLUDE_CURRENT_DIR ON) +# Instruct CMake to run moc automatically when needed. +set(CMAKE_AUTOMOC ON) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() -find_package(CGAL COMPONENTS Qt4) +find_package(CGAL COMPONENTS Qt5) include(${CGAL_USE_FILE}) -set( QT_USE_QTXML TRUE ) -set( QT_USE_QTMAIN TRUE ) -set( QT_USE_QTSCRIPT TRUE ) -set( QT_USE_QTOPENGL TRUE ) -find_package(Qt4) +find_package(Qt5 QUIET COMPONENTS Xml Script OpenGL Svg) find_package(OpenGL) find_package(QGLViewer) -if ( CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND ) +if ( CGAL_FOUND AND CGAL_Qt5_FOUND AND Qt5_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND ) add_definitions(-DQT_NO_KEYWORDS) - include(${QT_USE_FILE}) + # include(${QT_USE_FILE}) include_directories (${QGLVIEWER_INCLUDE_DIR}) include_directories (BEFORE ../../include ./ ) # ui file, created wih Qt Designer - qt4_wrap_ui( uis MainWindow.ui ) + qt5_wrap_ui( uis MainWindow.ui ) # qrc files (resources files, that contain icons, at least) - qt4_add_resources ( RESOURCE_FILES ./Alpha_shape_3.qrc ) - - qt4_automoc( MainWindow.cpp Viewer.cpp) + qt5_add_resources ( RESOURCE_FILES ./Alpha_shape_3.qrc ) add_executable ( Alpha_shape_3 Alpha_shape_3.cpp MainWindow.cpp Viewer.cpp ${uis} ${RESOURCE_FILES} ) - + qt5_use_modules(Alpha_shape_3 Xml Script OpenGL Svg) add_to_cached_list( CGAL_EXECUTABLE_TARGETS Alpha_shape_3 ) target_link_libraries( Alpha_shape_3 ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES}) @@ -49,6 +44,6 @@ if ( CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_ else() - message(STATUS "NOTICE: This demo requires CGAL, the QGLViewer, OpenGL and Qt4, and will not be compiled.") + message(STATUS "NOTICE: This demo requires CGAL, the QGLViewer, OpenGL and Qt5, and will not be compiled.") endif() diff --git a/Alpha_shapes_3/demo/Alpha_shapes_3/MainWindow.cpp b/Alpha_shapes_3/demo/Alpha_shapes_3/MainWindow.cpp index 393fd5a5f19..720db51e9fc 100644 --- a/Alpha_shapes_3/demo/Alpha_shapes_3/MainWindow.cpp +++ b/Alpha_shapes_3/demo/Alpha_shapes_3/MainWindow.cpp @@ -74,6 +74,7 @@ MainWindow::alphaChanged(int i) } else { scene.alpha_shape.set_alpha(0); } + viewer->alphaChanged(); Q_EMIT(alphaChanged()); } @@ -103,6 +104,7 @@ MainWindow::open(QString fileName) this->addToRecentFiles(fileName); QApplication::restoreOverrideCursor(); + viewer->changed(); Q_EMIT(sceneChanged()); } diff --git a/Alpha_shapes_3/demo/Alpha_shapes_3/Viewer.cpp b/Alpha_shapes_3/demo/Alpha_shapes_3/Viewer.cpp index 38427769a6d..9dc670b7cf9 100644 --- a/Alpha_shapes_3/demo/Alpha_shapes_3/Viewer.cpp +++ b/Alpha_shapes_3/demo/Alpha_shapes_3/Viewer.cpp @@ -2,8 +2,268 @@ #include #include #include +#include "CGAL/Qt/CreateOpenGLContext.h" + +Viewer::Viewer(QWidget* parent) + : QGLViewer(CGAL::Qt::createOpenGLContext(),parent) +{ + are_buffers_initialized = false; +} +void Viewer::compile_shaders() +{ + initializeOpenGLFunctions(); + if(! buffers[0].create() || !buffers[1].create() || !buffers[2].create() ) + { + std::cerr<<"VBO Creation FAILED"<compileSourceCode(vertex_source)) +{ + std::cerr<<"Compiling vertex source FAILED"<compileSourceCode(fragment_source)) +{ + std::cerr<<"Compiling fragmentsource FAILED"<compileSourceCode(vertex_source_points)) +{ +std::cerr<<"Compiling vertex source FAILED"<compileSourceCode(fragment_source_points)) +{ +std::cerr<<"Compiling fragmentsource FAILED"<(pos_poly.size()*sizeof(float))); + poly_vertexLocation = rendering_program.attributeLocation("vertex"); + rendering_program.bind(); + rendering_program.enableAttributeArray(poly_vertexLocation); + rendering_program.setAttributeBuffer(poly_vertexLocation,GL_FLOAT,0,3); + buffers[0].release(); + + buffers[1].bind(); + buffers[1].allocate(normals.data(), + static_cast(normals.size()*sizeof(float))); + normalsLocation = rendering_program.attributeLocation("normal"); + rendering_program.bind(); + rendering_program.enableAttributeArray(normalsLocation); + rendering_program.setAttributeBuffer(normalsLocation,GL_FLOAT,0,3); + buffers[1].release(); + + + rendering_program.release(); + vao[0].release(); + + vao[1].bind(); + buffers[2].bind(); + buffers[2].allocate(pos_points.data(), + static_cast(pos_points.size()*sizeof(float))); + points_vertexLocation = rendering_program_points.attributeLocation("vertex"); + rendering_program_points.bind(); + rendering_program_points.enableAttributeArray(points_vertexLocation); + rendering_program_points.setAttributeBuffer(points_vertexLocation,GL_FLOAT,0,3); + buffers[2].release(); + + + rendering_program_points.release(); + vao[0].release(); + + are_buffers_initialized = true; +} + + +void Viewer::attrib_buffers(QGLViewer* viewer) +{ + QMatrix4x4 mvpMatrix; + QMatrix4x4 mvMatrix; + double mat[16]; + viewer->camera()->getModelViewProjectionMatrix(mat); + for(int i=0; i < 16; i++) + { + mvpMatrix.data()[i] = (float)mat[i]; + } + viewer->camera()->getModelViewMatrix(mat); + for(int i=0; i < 16; i++) + { + mvMatrix.data()[i] = (float)mat[i]; + } + // define material + QVector4D ambient(0.25f, 0.20725f, 0.20725f, 0.922f); + QVector4D diffuse( 1.0f, + 0.829f, + 0.829f, + 0.922f ); + + QVector4D specular( 0.6f, + 0.6f, + 0.6f, + 1.0f ); + + QVector4D position(0.0f,0.0f,1.0f,1.0f ); + GLfloat shininess = 11.264f; + + + rendering_program.bind(); + mvpLocation = rendering_program.uniformLocation("mvp_matrix"); + mvLocation = rendering_program.uniformLocation("mv_matrix"); + colorLocation = rendering_program.uniformLocation("color"); + lightLocation[0] = rendering_program.uniformLocation("light_pos"); + lightLocation[1] = rendering_program.uniformLocation("light_diff"); + lightLocation[2] = rendering_program.uniformLocation("light_spec"); + lightLocation[3] = rendering_program.uniformLocation("light_amb"); + lightLocation[4] = rendering_program.uniformLocation("spec_power"); + + rendering_program.setUniformValue(lightLocation[0], position); + rendering_program.setUniformValue(lightLocation[1], diffuse); + rendering_program.setUniformValue(lightLocation[2], specular); + rendering_program.setUniformValue(lightLocation[3], ambient); + rendering_program.setUniformValue(lightLocation[4], shininess); + rendering_program.setUniformValue(mvpLocation, mvpMatrix); + rendering_program.setUniformValue(mvLocation, mvMatrix); + + + rendering_program.release(); + + rendering_program_points.bind(); + + mvpLocation_points = rendering_program_points.uniformLocation("mvp_matrix"); + colorLocation_points = rendering_program_points.uniformLocation("color"); + rendering_program_points.setUniformValue(mvpLocation_points, mvpMatrix); + + rendering_program_points.release(); +} + +void Viewer::initializeGL() +{ + QGLViewer::initializeGL(); + compile_shaders(); +} void @@ -16,123 +276,114 @@ Viewer::sceneChanged() qglviewer::Vec(bb.xmax(), bb.ymax(), bb.zmax())); - + this->showEntireScene(); + } +void Viewer::compute_elements() +{ + + normals.resize(0); + pos_points.resize(0); + pos_poly.resize(0); + for(std::list::iterator it = scene->points.begin(); + it != scene->points.end(); + ++it){ + pos_points.push_back(it->x()); pos_points.push_back(it->y()); pos_points.push_back(it->z()); + } + + std::list facets; + scene->alpha_shape.get_alpha_shape_facets(std::back_inserter(facets), Alpha_shape_3::REGULAR); + + for(std::list::iterator fit = facets.begin(); + fit != facets.end(); + ++fit) { + const Cell_handle& ch = fit->first; + const int index = fit->second; + + //const Vector_3& n = ch->normal(index); // must be unit vector + + const Point_3& a = ch->vertex((index+1)&3)->point(); + const Point_3& b = ch->vertex((index+2)&3)->point(); + const Point_3& c = ch->vertex((index+3)&3)->point(); + + Vector_3 v = CGAL::unit_normal(a,b,c); + + normals.push_back(v.x()); normals.push_back(v.y()); normals.push_back(v.z()); + normals.push_back(v.x()); normals.push_back(v.y()); normals.push_back(v.z()); + normals.push_back(v.x()); normals.push_back(v.y()); normals.push_back(v.z()); + pos_poly.push_back(a.x()); pos_poly.push_back(a.y()); pos_poly.push_back(a.z()); + pos_poly.push_back(b.x()); pos_poly.push_back(b.y()); pos_poly.push_back(b.z()); + pos_poly.push_back(c.x()); pos_poly.push_back(c.y()); pos_poly.push_back(c.z()); + + } + + +} void Viewer::draw() { - - // define material - float ambient[] = { 0.25f, - 0.20725f, - 0.20725f, - 0.922f }; - float diffuse[] = { 1.0f, - 0.829f, - 0.829f, - 0.922f }; - - float specular[] = { 0.296648f, - 0.296648f, - 0.296648f, - 0.522f }; - - float emission[] = { 0.3f, - 0.3f, - 0.3f, - 1.0f }; - float shininess[] = { 11.264f }; - - // apply material - ::glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT, ambient); - ::glMaterialfv( GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse); - ::glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, specular); - ::glMaterialfv( GL_FRONT_AND_BACK, GL_SHININESS, shininess); - ::glMaterialfv( GL_FRONT_AND_BACK, GL_EMISSION, emission); - - // anti-aliasing (if the OpenGL driver permits that) - ::glEnable(GL_LINE_SMOOTH); - - ::glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); - // draw surface mesh - bool m_view_surface = true; - bool draw_triangles_edges = true; - - if(m_view_surface) - { - ::glEnable(GL_LIGHTING); - ::glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); - ::glColor3f(0.2f, 0.2f, 1.f); - ::glEnable(GL_POLYGON_OFFSET_FILL); - ::glPolygonOffset(3.0f,-3.0f); - gl_draw_surface(); - - if(draw_triangles_edges) - { - ::glDisable(GL_LIGHTING); - ::glLineWidth(1.); - ::glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); - ::glColor3ub(0,0,0); - ::glDisable(GL_POLYGON_OFFSET_FILL); - gl_draw_surface(); - } - } + if(!are_buffers_initialized) + initialize_buffers(); + QColor color; + //points + vao[1].bind(); + attrib_buffers(this); + rendering_program_points.bind(); + color.setRgbF(1.0f, 0.0f, 0.0f); + glPointSize(5); + ::glEnable(GL_POINT_SMOOTH); + rendering_program_points.setUniformValue(colorLocation_points, color); + glDrawArrays(GL_POINTS, 0, static_cast(pos_points.size()/3)); + rendering_program_points.release(); + vao[1].release(); + //facets + vao[0].bind(); + attrib_buffers(this); + rendering_program.bind(); + color.setRgbF(0.5f, 1.0f, 0.5f); + rendering_program.setUniformValue(colorLocation, color); + glDrawArrays(GL_TRIANGLES, 0, static_cast(pos_poly.size()/3)); + rendering_program.release(); + vao[0].release(); } - - -void -Viewer::gl_draw_surface() +void Viewer::alphaChanged() { - ::glColor3f(1.0f, 0.0f, 0.0f); - ::glDisable(GL_LIGHTING); - ::glEnable(GL_POINT_SMOOTH); - ::glPointSize(5); - ::glBegin(GL_POINTS); - for(std::list::iterator it = scene->points.begin(); - it != scene->points.end(); - ++it){ - ::glVertex3d(it->x(), it->y(), it->z()); - } - ::glEnd(); - ::glDisable(GL_POINT_SMOOTH); - ::glEnable(GL_LIGHTING); - ::glBegin(GL_TRIANGLES); + normals.resize(0); + pos_poly.resize(0); - ::glColor3f(0.2f, 1.0f, 0.2f); + std::list facets; + scene->alpha_shape.get_alpha_shape_facets(std::back_inserter(facets), Alpha_shape_3::REGULAR); - std::list facets; - scene->alpha_shape.get_alpha_shape_facets(std::back_inserter(facets), Alpha_shape_3::REGULAR); - - for(std::list::iterator fit = facets.begin(); - fit != facets.end(); - ++fit) { - const Cell_handle& ch = fit->first; - const int index = fit->second; - - //const Vector_3& n = ch->normal(index); // must be unit vector - - const Point_3& a = ch->vertex((index+1)&3)->point(); - const Point_3& b = ch->vertex((index+2)&3)->point(); - const Point_3& c = ch->vertex((index+3)&3)->point(); - - Vector_3 v = CGAL::unit_normal(a,b,c); + for(std::list::iterator fit = facets.begin(); + fit != facets.end(); + ++fit) { + const Cell_handle& ch = fit->first; + const int index = fit->second; + //const Vector_3& n = ch->normal(index); // must be unit vector - ::glNormal3d(v.x(),v.y(),v.z()); - ::glVertex3d(a.x(),a.y(),a.z()); - ::glVertex3d(b.x(),b.y(),b.z()); - ::glVertex3d(c.x(),c.y(),c.z()); - } + const Point_3& a = ch->vertex((index+1)&3)->point(); + const Point_3& b = ch->vertex((index+2)&3)->point(); + const Point_3& c = ch->vertex((index+3)&3)->point(); - - ::glEnd(); + Vector_3 v = CGAL::unit_normal(a,b,c); + + normals.push_back(v.x()); normals.push_back(v.y()); normals.push_back(v.z()); + normals.push_back(v.x()); normals.push_back(v.y()); normals.push_back(v.z()); + normals.push_back(v.x()); normals.push_back(v.y()); normals.push_back(v.z()); + pos_poly.push_back(a.x()); pos_poly.push_back(a.y()); pos_poly.push_back(a.z()); + pos_poly.push_back(b.x()); pos_poly.push_back(b.y()); pos_poly.push_back(b.z()); + pos_poly.push_back(c.x()); pos_poly.push_back(c.y()); pos_poly.push_back(c.z()); + + } + + initialize_buffers(); } - #include "Viewer.moc" diff --git a/Alpha_shapes_3/demo/Alpha_shapes_3/Viewer.h b/Alpha_shapes_3/demo/Alpha_shapes_3/Viewer.h index 9471a20ee97..a5cc54aa490 100644 --- a/Alpha_shapes_3/demo/Alpha_shapes_3/Viewer.h +++ b/Alpha_shapes_3/demo/Alpha_shapes_3/Viewer.h @@ -3,9 +3,13 @@ #include "typedefs.h" #include +#include +#include +#include +#include -class Viewer : public QGLViewer { +class Viewer : public QGLViewer, protected QOpenGLFunctions_3_3_Core{ Q_OBJECT CGAL::Timer timer; @@ -13,10 +17,15 @@ class Viewer : public QGLViewer { int nr_of_facets; public: - Viewer(QWidget* parent) - : QGLViewer(parent) - {} - + Viewer(QWidget* parent); + ~Viewer() + { + buffers[0].destroy(); + buffers[1].destroy(); + buffers[2].destroy(); + vao[0].destroy(); + vao[1].destroy(); + } void setScene(Scene* scene_) { scene = scene_; @@ -27,13 +36,41 @@ public: public: void draw(); - void - gl_draw_surface(); +private: + bool are_buffers_initialized; + //Shaders elements + int poly_vertexLocation; + int points_vertexLocation; + int normalsLocation; + int mvpLocation; + int mvpLocation_points; + int mvLocation; + int colorLocation; + int colorLocation_points; + int lightLocation[5]; + + std::vector pos_points; + std::vector pos_poly; + std::vector normals; + + QOpenGLBuffer buffers[3]; + QOpenGLVertexArrayObject vao[2]; + QOpenGLShaderProgram rendering_program; + QOpenGLShaderProgram rendering_program_points; + void initialize_buffers(); + void compute_elements(); + void attrib_buffers(QGLViewer*); + void compile_shaders(); public Q_SLOTS: + void initializeGL(); + void sceneChanged(); + void changed(){ + compute_elements(); + are_buffers_initialized = false; + } + void alphaChanged(); - void sceneChanged(); - }; #endif diff --git a/Apollonius_graph_2/demo/Apollonius_graph_2/Qt3/CMakeLists.txt b/Apollonius_graph_2/demo/Apollonius_graph_2/Qt3/CMakeLists.txt index 98ae9b2e12c..0f2e71ca21a 100644 --- a/Apollonius_graph_2/demo/Apollonius_graph_2/Qt3/CMakeLists.txt +++ b/Apollonius_graph_2/demo/Apollonius_graph_2/Qt3/CMakeLists.txt @@ -9,7 +9,7 @@ include( ${CGAL_USE_FILE} ) find_package(Qt3-patched) # FindQt3-patched.cmake is FindQt3.cmake patched by CGAL developers, so -# that it can be used together with FindQt4: all its variables are prefixed +# that it can be used together with Qt5: all its variables are prefixed # by "QT3_" instead of "QT_". if ( CGAL_FOUND AND QT3_FOUND AND CGAL_Qt3_FOUND ) diff --git a/Arithmetic_kernel/test/Arithmetic_kernel/CMakeLists.txt b/Arithmetic_kernel/test/Arithmetic_kernel/CMakeLists.txt index 49bc50f8178..610fc6f88ff 100644 --- a/Arithmetic_kernel/test/Arithmetic_kernel/CMakeLists.txt +++ b/Arithmetic_kernel/test/Arithmetic_kernel/CMakeLists.txt @@ -4,12 +4,8 @@ project( Arithmetic_kernel_test ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) -endif() +cmake_minimum_required(VERSION 2.8.11) + find_package(CGAL QUIET COMPONENTS Core GMP MPFR MPFI) diff --git a/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/ArrangementDemoPropertiesDialog.cpp b/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/ArrangementDemoPropertiesDialog.cpp index 91ff6e87397..f38de5930cc 100644 --- a/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/ArrangementDemoPropertiesDialog.cpp +++ b/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/ArrangementDemoPropertiesDialog.cpp @@ -51,6 +51,7 @@ QVariant ArrangementDemoPropertiesDialog::property( int index ) // return user data, if it is set QVariant myData = item->data( Qt::UserRole ); + /* if ( qVariantCanConvert< QColor >( myData ) || qVariantCanConvert< DeleteCurveMode >( myData ) ) { @@ -60,7 +61,17 @@ QVariant ArrangementDemoPropertiesDialog::property( int index ) { res = item->data( Qt::DisplayRole ); } + */ + if ( myData.canConvert() || + myData.canConvert()) + { + return myData; + } + else + { + res = item->data( Qt::DisplayRole ); + } return res; } diff --git a/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/ArrangementDemoWindow.cpp b/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/ArrangementDemoWindow.cpp index 513b6d6fdb5..8adfd133bb0 100644 --- a/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/ArrangementDemoWindow.cpp +++ b/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/ArrangementDemoWindow.cpp @@ -693,7 +693,7 @@ void ArrangementDemoWindow::updateConicType( QAction* newType ) curveInputCallback->setCurveType( LinearCurveInputCallback::SEGMENT ); } else if ( newType == this->ui->actionCurveRay ) - { + { curveInputCallback->setCurveType( LinearCurveInputCallback::RAY ); } else if ( newType == this->ui->actionCurveLine ) @@ -1183,38 +1183,34 @@ void ArrangementDemoWindow::on_actionPreferences_triggered( ) if ( dialog->exec( ) == QDialog::Accepted ) { typedef ArrangementDemoPropertiesDialog Dialog; - QColor edgeColor = - qVariantValue(dialog->property(Dialog::EDGE_COLOR_KEY)); - unsigned int edgeWidth = - qVariantValue(dialog->property(Dialog::EDGE_WIDTH_KEY)); - QColor vertexColor = - qVariantValue(dialog->property(Dialog::VERTEX_COLOR_KEY)); - unsigned int vertexRadius = - qVariantValue(dialog->property(Dialog::VERTEX_RADIUS_KEY)); - QColor envelopeEdgeColor = - qVariantValue(dialog->property(Dialog::ENVELOPE_EDGE_COLOR_KEY)); - unsigned int envelopeEdgeWidth = - qVariantValue(dialog->property(Dialog:: - ENVELOPE_EDGE_WIDTH_KEY)); - QColor envelopeVertexColor = - qVariantValue(dialog->property(Dialog:: - ENVELOPE_VERTEX_COLOR_KEY)); - unsigned int envelopeVertexRadius = - qVariantValue(dialog->property(Dialog:: - ENVELOPE_VERTEX_RADIUS_KEY)); - QColor verticalRayEdgeColor = - qVariantValue(dialog->property(Dialog:: - VERTICAL_RAY_EDGE_COLOR_KEY)); - unsigned int verticalRayEdgeWidth = - qVariantValue(dialog->property - (Dialog::VERTICAL_RAY_EDGE_WIDTH_KEY)); - DeleteCurveMode mode = - qVariantValue(dialog->property(Dialog:: - DELETE_CURVE_MODE_KEY)); - unsigned int gridSize = - qVariantValue(dialog->property(Dialog::GRID_SIZE_KEY)); - QColor gridColor = - qVariantValue(dialog->property(Dialog::GRID_COLOR_KEY)); + + QColor edgeColor = dialog->property(Dialog::EDGE_COLOR_KEY).value(); + + unsigned int edgeWidth = dialog->property(Dialog::EDGE_WIDTH_KEY).value(); + + QColor vertexColor = dialog->property(Dialog::VERTEX_COLOR_KEY).value(); + + unsigned int vertexRadius = dialog->property(Dialog::VERTEX_RADIUS_KEY).value(); + + QColor envelopeEdgeColor = dialog->property(Dialog::ENVELOPE_EDGE_COLOR_KEY).value(); + + unsigned int envelopeEdgeWidth = dialog->property(Dialog::ENVELOPE_EDGE_WIDTH_KEY).value(); + + QColor envelopeVertexColor = dialog->property(Dialog::ENVELOPE_VERTEX_COLOR_KEY).value(); + + unsigned int envelopeVertexRadius = dialog->property(Dialog::ENVELOPE_VERTEX_RADIUS_KEY).value(); + + QColor verticalRayEdgeColor = dialog->property(Dialog::VERTICAL_RAY_EDGE_COLOR_KEY).value(); + + unsigned int verticalRayEdgeWidth = dialog->property(Dialog::VERTICAL_RAY_EDGE_WIDTH_KEY).value(); + + DeleteCurveMode mode = dialog->property(Dialog::DELETE_CURVE_MODE_KEY).value(); + + unsigned int gridSize = dialog->property(Dialog::GRID_SIZE_KEY).value(); + + QColor gridColor = dialog->property(Dialog::GRID_COLOR_KEY).value(); + //end new for Qt5 version ! + QPen edgesPen(QBrush(edgeColor), edgeWidth); QPen verticesPen(QBrush(vertexColor), vertexRadius); diff --git a/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/CMakeLists.txt b/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/CMakeLists.txt index f192fd34a47..b6843be43ae 100644 --- a/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/CMakeLists.txt +++ b/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/CMakeLists.txt @@ -2,31 +2,28 @@ project( Arrangement_2 ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() -find_package(CGAL COMPONENTS Core Qt4 ) +find_package(CGAL COMPONENTS Core Qt5 ) include( ${CGAL_USE_FILE} ) -find_package( Qt4 ) +find_package( Qt5 QUIET COMPONENTS Script Widgets ) -if ( CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND) - include( ${QT_USE_FILE} ) +if ( CGAL_FOUND AND CGAL_Qt5_FOUND AND Qt5_FOUND) include_directories( ./ ) # Arrangement package includes include_directories( BEFORE ../../include ) - qt4_wrap_ui( arrangement_2_uis + qt5_wrap_ui( arrangement_2_uis ArrangementDemoWindow.ui NewTabDialog.ui OverlayDialog.ui ArrangementDemoPropertiesDialog.ui ) - qt4_wrap_cpp( arrangement_2_mocs + qt5_wrap_cpp( arrangement_2_mocs ArrangementDemoWindow.h ArrangementDemoTab.h Callback.h @@ -38,7 +35,7 @@ if ( CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND) PropertyValueDelegate.h #PropertyValueDelegate.cpp ) - qt4_add_resources( arrangement_2_resources + qt5_add_resources( arrangement_2_resources ArrangementDemoWindow.qrc ) add_executable( arrangement_2 @@ -68,16 +65,18 @@ if ( CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND) ${arrangement_2_uis} ${arrangement_2_resources} ) - + qt5_use_modules(arrangement_2 Widgets Script) target_link_libraries( arrangement_2 ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES} ${QT_LIBRARIES} ) + add_to_cached_list( CGAL_EXECUTABLE_TARGETS arrangement_2 ) + else() - message(STATUS "NOTICE: This demo requires CGAL and Qt4, and will not be compiled.") + message(STATUS "NOTICE: This demo requires CGAL and Qt5, and will not be compiled.") endif() diff --git a/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/ColorItemEditor.cpp b/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/ColorItemEditor.cpp index 79ab960ca78..368e44a2561 100644 --- a/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/ColorItemEditor.cpp +++ b/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/ColorItemEditor.cpp @@ -41,6 +41,8 @@ #include #include +#include + #include "ColorItemEditor.h" diff --git a/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/DeleteCurveModeItemEditor.cpp b/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/DeleteCurveModeItemEditor.cpp index 50e000f919d..4e0f8ad3129 100644 --- a/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/DeleteCurveModeItemEditor.cpp +++ b/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/DeleteCurveModeItemEditor.cpp @@ -33,8 +33,7 @@ DeleteCurveModeItemEditor::DeleteCurveModeItemEditor( QWidget* parent ) : DeleteCurveMode DeleteCurveModeItemEditor::mode( ) const { - return qVariantValue(this->itemData(this->currentIndex( ), - Qt::UserRole ) ); + return this->itemData(this->currentIndex( ), Qt::UserRole ).value< DeleteCurveMode >(); } void DeleteCurveModeItemEditor::setMode( DeleteCurveMode m ) diff --git a/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/PropertyValueDelegate.cpp b/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/PropertyValueDelegate.cpp index 71c732090f5..b8f8f325054 100644 --- a/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/PropertyValueDelegate.cpp +++ b/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/PropertyValueDelegate.cpp @@ -23,6 +23,8 @@ #include "DeleteCurveMode.h" #include +#include + PropertyValueDelegate::PropertyValueDelegate( QObject* parent ): QItemDelegate( parent ) @@ -42,6 +44,7 @@ createEditor( QWidget* parent, const QStyleOptionViewItem& option, QVariant myData = index.data( Qt::UserRole ); // check for data types we need to handle ourselves + /* if ( qVariantCanConvert< QColor >( myData ) ) { ColorItemEditor* colorEditor = new ColorItemEditor( parent ); @@ -60,6 +63,28 @@ createEditor( QWidget* parent, const QStyleOptionViewItem& option, SLOT( commit( ) ) ); } else + { // default handler + editor = QItemDelegate::createEditor( parent, option, index ); + }*/ + + if ( myData.canConvert< QColor >() ) + { + ColorItemEditor* colorEditor = new ColorItemEditor( parent ); + editor = colorEditor; + + QObject::connect( colorEditor, SIGNAL(confirmed()), this, SLOT(commit())); + } + else if ( myData.canConvert< DeleteCurveMode >() ) + { + DeleteCurveModeItemEditor* modeEditor = + new DeleteCurveModeItemEditor( parent ); + modeEditor->setMode( myData.value< DeleteCurveMode >() ); + editor = modeEditor; + + QObject::connect( modeEditor, SIGNAL( currentIndexChanged( int ) ), this, + SLOT( commit( ) ) ); + } + else { // default handler editor = QItemDelegate::createEditor( parent, option, index ); } diff --git a/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/PropertyValueDelegate.h b/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/PropertyValueDelegate.h index db8913dbe35..3f587c5e21d 100644 --- a/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/PropertyValueDelegate.h +++ b/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/PropertyValueDelegate.h @@ -21,6 +21,9 @@ #define PROPERTY_VALUE_DELEGATE_H #include +#include +#include + class PropertyValueDelegate : public QItemDelegate { diff --git a/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/old_demo/CMakeLists.txt b/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/old_demo/CMakeLists.txt index 9e2a8cbeffc..294bca8def7 100644 --- a/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/old_demo/CMakeLists.txt +++ b/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/old_demo/CMakeLists.txt @@ -2,13 +2,9 @@ project( Arrangement_2 ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 2.6) - if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) - else() - cmake_policy(VERSION 2.6) - endif() +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() find_package(CGAL COMPONENTS Core Qt3 ) @@ -17,7 +13,7 @@ include( ${CGAL_USE_FILE} ) find_package(Qt3-patched) # FindQt3-patched.cmake is FindQt3.cmake patched by CGAL developers, so -# that it can be used together with FindQt4: all its variables are prefixed +# that it can be used together with Qt5: all its variables are prefixed # by "QT3_" instead of "QT_". if ( CGAL_FOUND AND CGAL_Qt3_FOUND AND QT3_FOUND ) diff --git a/BGL/test/BGL/CMakeLists.txt b/BGL/test/BGL/CMakeLists.txt index 386735a9444..98ea1b46208 100644 --- a/BGL/test/BGL/CMakeLists.txt +++ b/BGL/test/BGL/CMakeLists.txt @@ -4,14 +4,8 @@ project( BGL ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 2.6) - if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) - else() - cmake_policy(VERSION 2.6) - endif() -endif() +cmake_minimum_required(VERSION 2.8.11) + set( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true ) @@ -36,7 +30,7 @@ include( ${CGAL_USE_FILE} ) # Boost and its components -find_package( Boost REQUIRED ) +find_package( Boost ) if ( NOT Boost_FOUND ) message(STATUS "This project requires the Boost library, and will not be compiled.") diff --git a/Boolean_set_operations_2/demo/Boolean_set_operations_2/CMakeLists.txt b/Boolean_set_operations_2/demo/Boolean_set_operations_2/CMakeLists.txt index 4af8809cee3..02f936ad331 100644 --- a/Boolean_set_operations_2/demo/Boolean_set_operations_2/CMakeLists.txt +++ b/Boolean_set_operations_2/demo/Boolean_set_operations_2/CMakeLists.txt @@ -2,11 +2,9 @@ project( Boolean_operations_2 ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() find_package(CGAL COMPONENTS Qt3 ) @@ -14,7 +12,7 @@ include( ${CGAL_USE_FILE} ) find_package(Qt3-patched) # FindQt3-patched.cmake is FindQt3.cmake patched by CGAL developers, so -# that it can be used together with FindQt4: all its variables are prefixed +# that it can be used together with Qt5: all its variables are prefixed # by "QT3_" instead of "QT_". if ( CGAL_FOUND AND CGAL_Qt3_FOUND AND QT3_FOUND ) diff --git a/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/CMakeLists.txt b/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/CMakeLists.txt index 1f3a8ae6634..0f4fff94847 100644 --- a/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/CMakeLists.txt +++ b/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/CMakeLists.txt @@ -3,41 +3,37 @@ project( Boolean_operations_2_demo ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() -find_package(CGAL COMPONENTS Qt4 Core ) +find_package(CGAL COMPONENTS Qt5 Core ) include(${CGAL_USE_FILE}) set( QT_USE_QTMAIN TRUE ) -find_package(Qt4) +find_package(Qt5 QUIET COMPONENTS Widgets Script) include_directories (BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/../../include ) include_directories (BEFORE ${CMAKE_CURRENT_BINARY_DIR}) include_directories (BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/include ) -if ( CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND AND CGAL_Core_FOUND ) - - include(${QT_USE_FILE}) +if ( CGAL_FOUND AND CGAL_Qt5_FOUND AND Qt5_FOUND AND CGAL_Core_FOUND ) # UI files (Qt Designer files) - qt4_wrap_ui( CDT_UI_FILES boolean_operations_2.ui ) + qt5_wrap_ui( CDT_UI_FILES boolean_operations_2.ui ) # qrc files (resources files, that contain icons, at least) - qt4_add_resources ( CDT_RESOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/boolean_operations_2.qrc ) + qt5_add_resources ( CDT_RESOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/boolean_operations_2.qrc ) # use the Qt MOC preprocessor on classes that derives from QObject - qt4_generate_moc( "boolean_operations_2.cpp" "${CMAKE_CURRENT_BINARY_DIR}/boolean_operations_2.moc" ) + qt5_generate_moc( "boolean_operations_2.cpp" "${CMAKE_CURRENT_BINARY_DIR}/boolean_operations_2.moc" ) # The executable itself. add_executable ( boolean_operations_2 ${CMAKE_CURRENT_SOURCE_DIR}/boolean_operations_2.cpp boolean_operations_2.moc ${CDT_UI_FILES} ${CDT_RESOURCE_FILES} ) - + qt5_use_modules(boolean_operations_2 Widgets Script) # Link with Qt libraries target_link_libraries( boolean_operations_2 ${QT_LIBRARIES} ) @@ -46,6 +42,6 @@ if ( CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND AND CGAL_Core_FOUND ) else() - message(STATUS "NOTICE: This demo requires CGAL and Qt4, and will not be compiled.") + message(STATUS "NOTICE: This demo requires CGAL and Qt5, and will not be compiled.") endif() diff --git a/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/boolean_operations_2.cpp b/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/boolean_operations_2.cpp index 70ac9d92c85..c569bc119ac 100644 --- a/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/boolean_operations_2.cpp +++ b/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/boolean_operations_2.cpp @@ -51,6 +51,7 @@ void trace( std::string s ) #include #include #include +#include #include #include @@ -81,6 +82,7 @@ void trace( std::string s ) #include #endif + #include #include #include @@ -1629,9 +1631,8 @@ int main(int argc, char **argv) app.setOrganizationName("GeometryFactory"); app.setApplicationName("Boolean_operations_2 demo"); - // Import resources from libCGALQt4. - // See http://doc.trolltech.com/4.4/qdir.html#Q_INIT_RESOURCE - CGAL_QT4_INIT_RESOURCES; + // Import resources from libCGALQt5. + CGAL_QT_INIT_RESOURCES; MainWindow mainWindow; mainWindow.show(); diff --git a/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/GraphicsViewBezierPolygonInput.h b/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/GraphicsViewBezierPolygonInput.h index a4c2897c2aa..08f6d594055 100644 --- a/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/GraphicsViewBezierPolygonInput.h +++ b/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/GraphicsViewBezierPolygonInput.h @@ -22,11 +22,13 @@ #ifndef CGAL_QT_GRAPHICS_VIEW_BEZIER_POLYGON_INPUT_H #define CGAL_QT_GRAPHICS_VIEW_BEZIER_POLYGON_INPUT_H -#include +#include #include #include #include +#include +#include #include #include @@ -132,7 +134,7 @@ namespace Qt { bool rHandled = false ; Point lP = cvt(aEvent->scenePos()); - + if ( aEvent->button() == ::Qt::LeftButton ) { switch (mState) diff --git a/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/GraphicsViewCircularPolygonInput.h b/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/GraphicsViewCircularPolygonInput.h index 46dfe4c7ece..ab86b87f36d 100644 --- a/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/GraphicsViewCircularPolygonInput.h +++ b/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/GraphicsViewCircularPolygonInput.h @@ -22,11 +22,13 @@ #ifndef CGAL_QT_GRAPHICS_VIEW_CIRCULAR_POLYGON_INPUT_H #define CGAL_QT_GRAPHICS_VIEW_CIRCULAR_POLYGON_INPUT_H -#include +#include #include #include #include +#include + #include #include diff --git a/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/PiecewiseRegionGraphicsItem.h b/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/PiecewiseRegionGraphicsItem.h index 14488fbd3f5..6a8b46029cd 100644 --- a/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/PiecewiseRegionGraphicsItem.h +++ b/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/PiecewiseRegionGraphicsItem.h @@ -80,19 +80,19 @@ protected: template void Piecewise_region_graphics_item::update_region_bbox( Piecewise_region const& aRegion, Piecewise_graphics_item_base::Bbox_builder& aBboxBuilder ) { - update_boundary_bbox( aRegion.outer_boundary(), aBboxBuilder ) ; + this->update_boundary_bbox( aRegion.outer_boundary(), aBboxBuilder ) ;//"This" added for qt5 version ! for( Hole_const_itertator hit = aRegion.holes_begin(); hit != aRegion.holes_end(); ++ hit ) - update_boundary_bbox(*hit,aBboxBuilder); + this->update_boundary_bbox(*hit,aBboxBuilder);//"This" added for qt5 version ! } template void Piecewise_region_graphics_item::draw_region( Piecewise_region const& aRegion, QPainterPath& aPath ) { - draw_boundary( aRegion.outer_boundary(), aPath ) ; + this->draw_boundary( aRegion.outer_boundary(), aPath ) ;//This added for qt5 version ! for( Hole_const_itertator hit = aRegion.holes_begin(); hit != aRegion.holes_end(); ++ hit ) - draw_boundary(*hit,aPath); + this->draw_boundary(*hit,aPath);//"This" added for qt5 version ! } diff --git a/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/PiecewiseSetGraphicsItem.h b/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/PiecewiseSetGraphicsItem.h index 3cf1f580356..445b38dbd61 100644 --- a/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/PiecewiseSetGraphicsItem.h +++ b/Boolean_set_operations_2/demo/Boolean_set_operations_2_GraphicsView/include/CGAL/Qt/PiecewiseSetGraphicsItem.h @@ -103,7 +103,7 @@ void Piecewise_set_graphics_item::update_set_bbox( Piecewise_set const& a aSet.polygons_with_holes( std::back_inserter(vec) ) ; for( Region_const_iterator rit = vec.begin(); rit != vec.end() ; ++ rit ) - update_region_bbox(*rit,aBboxBuilder); + this->update_region_bbox(*rit,aBboxBuilder);//This added for Qt5 version ! } template @@ -114,7 +114,7 @@ void Piecewise_set_graphics_item::draw_set( Piecewise_set const& aSet, QP aSet.polygons_with_holes( std::back_inserter(vec) ) ; for( Region_const_iterator rit = vec.begin(); rit != vec.end() ; ++ rit ) - draw_region(*rit,aPath); + this->draw_region(*rit,aPath);//This added for Qt5 version ! } } // namespace Qt diff --git a/Bounding_volumes/demo/Min_circle_2/CMakeLists.txt b/Bounding_volumes/demo/Min_circle_2/CMakeLists.txt index f275b9b3ec8..82e13eb325c 100644 --- a/Bounding_volumes/demo/Min_circle_2/CMakeLists.txt +++ b/Bounding_volumes/demo/Min_circle_2/CMakeLists.txt @@ -2,11 +2,9 @@ project( Min_circle_2_Demo ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() find_package(CGAL COMPONENTS Qt3 ) @@ -14,7 +12,7 @@ include( ${CGAL_USE_FILE} ) find_package(Qt3-patched) # FindQt3-patched.cmake is FindQt3.cmake patched by CGAL developers, so -# that it can be used together with FindQt4: all its variables are prefixed +# that it can be used together with Qt5: all its variables are prefixed # by "QT3_" instead of "QT_". if ( CGAL_FOUND AND CGAL_Qt3_FOUND AND QT3_FOUND ) diff --git a/Bounding_volumes/demo/Min_ellipse_2/CMakeLists.txt b/Bounding_volumes/demo/Min_ellipse_2/CMakeLists.txt index 85f3e4f7932..cb8da5cbc31 100644 --- a/Bounding_volumes/demo/Min_ellipse_2/CMakeLists.txt +++ b/Bounding_volumes/demo/Min_ellipse_2/CMakeLists.txt @@ -2,11 +2,9 @@ project( Min_ellipse_2_Demo ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() find_package(CGAL COMPONENTS Qt3 ) @@ -14,7 +12,7 @@ include( ${CGAL_USE_FILE} ) find_package(Qt3-patched) # FindQt3-patched.cmake is FindQt3.cmake patched by CGAL developers, so -# that it can be used together with FindQt4: all its variables are prefixed +# that it can be used together with Qt5: all its variables are prefixed # by "QT3_" instead of "QT_". if ( CGAL_FOUND AND CGAL_Qt3_FOUND AND QT3_FOUND ) diff --git a/Bounding_volumes/demo/Min_quadrilateral_2/Min_quadrilateral_2/CMakeLists.txt b/Bounding_volumes/demo/Min_quadrilateral_2/Min_quadrilateral_2/CMakeLists.txt index c66d1ce5cae..45345004b0a 100644 --- a/Bounding_volumes/demo/Min_quadrilateral_2/Min_quadrilateral_2/CMakeLists.txt +++ b/Bounding_volumes/demo/Min_quadrilateral_2/Min_quadrilateral_2/CMakeLists.txt @@ -2,11 +2,9 @@ project( min_quadrilateral_2 ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() find_package(CGAL COMPONENTS Qt3 ) @@ -14,7 +12,7 @@ include( ${CGAL_USE_FILE} ) find_package(Qt3-patched) # FindQt3-patched.cmake is FindQt3.cmake patched by CGAL developers, so -# that it can be used together with FindQt4: all its variables are prefixed +# that it can be used together with Qt5: all its variables are prefixed # by "QT3_" instead of "QT_". if ( CGAL_FOUND AND CGAL_Qt3_FOUND AND QT3_FOUND ) diff --git a/CGAL_Core/examples/Core/CMakeLists.txt b/CGAL_Core/examples/Core/CMakeLists.txt index e3fbde5cdfd..7d657c9eae1 100644 --- a/CGAL_Core/examples/Core/CMakeLists.txt +++ b/CGAL_Core/examples/Core/CMakeLists.txt @@ -1,14 +1,8 @@ project( Core_examples ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 2.6) - if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) - else() - cmake_policy(VERSION 2.6) - endif() -endif() +cmake_minimum_required(VERSION 2.8.11) + set( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true ) @@ -33,7 +27,7 @@ include( ${CGAL_USE_FILE} ) # Boost and its components -find_package( Boost REQUIRED ) +find_package( Boost ) if ( NOT Boost_FOUND ) diff --git a/CGAL_Core/src/CGAL_Core/CMakeLists.txt b/CGAL_Core/src/CGAL_Core/CMakeLists.txt index 02b5103db2e..08b450fb314 100644 --- a/CGAL_Core/src/CGAL_Core/CMakeLists.txt +++ b/CGAL_Core/src/CGAL_Core/CMakeLists.txt @@ -10,7 +10,9 @@ link_directories ( ${CGAL_LIBRARIES_DIR} ${CGAL_3RD_PARTY_LIBRARIES_DIRS} ) collect_cgal_library(CGAL_Core "") -target_link_libraries( CGAL_Core ${CGAL_LIBRARY} ${CGAL_3RD_PARTY_LIBRARIES} ) +# CGAL_Core does not depend on CGAL in either DEBUG or RELEASE, but we +# still link it. +target_link_libraries( CGAL_Core CGAL ${CGAL_3RD_PARTY_LIBRARIES} ) add_dependencies( CGAL_Core CGAL ) diff --git a/CGAL_ImageIO/demo/CGALimageIO/CMakeLists.txt b/CGAL_ImageIO/demo/CGALimageIO/CMakeLists.txt index e8053148c45..0c552988d8a 100644 --- a/CGAL_ImageIO/demo/CGALimageIO/CMakeLists.txt +++ b/CGAL_ImageIO/demo/CGALimageIO/CMakeLists.txt @@ -1,6 +1,27 @@ project(image_to_vtk_viewer) cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) +endif() + + +set(PACKAGE_ROOT ../..) + +# Add several CGAL packages to the include and link paths, +# if they lie in ${PACKAGE_ROOT}/. +foreach(INC_DIR ${PACKAGE_ROOT}/include + ${PACKAGE_ROOT}/../CGAL_ImageIO/include ) + if(EXISTS ${INC_DIR}) + include_directories (BEFORE ${INC_DIR}) + endif() +endforeach() +foreach(LIB_DIR ${PACKAGE_ROOT}/../CGAL_ImageIO/src/CGAL_ImageIO) + if (EXISTS ${LIB_DIR}) + link_directories (${LIB_DIR}) + endif() +endforeach() + find_package(CGAL REQUIRED ImageIO) include( ${CGAL_USE_FILE} ) diff --git a/CGAL_ImageIO/demo/CGALimageIO/image_to_vtk_viewer.cpp b/CGAL_ImageIO/demo/CGALimageIO/image_to_vtk_viewer.cpp index 47343335e13..e0102b412a8 100644 --- a/CGAL_ImageIO/demo/CGALimageIO/image_to_vtk_viewer.cpp +++ b/CGAL_ImageIO/demo/CGALimageIO/image_to_vtk_viewer.cpp @@ -52,10 +52,6 @@ int main(int argc, char** argv) QVTKWidget widget; widget.resize(256,256); -#if QT_VERSION < 0x040000 - app.setMainWidget(&widget); -#endif - CGAL::Image_3 image; if(!image.read(argv[1])) { diff --git a/CGAL_ImageIO/examples/CGALimageIO/CMakeLists.txt b/CGAL_ImageIO/examples/CGALimageIO/CMakeLists.txt index 72ddd74f69f..26e7b850fb0 100644 --- a/CGAL_ImageIO/examples/CGALimageIO/CMakeLists.txt +++ b/CGAL_ImageIO/examples/CGALimageIO/CMakeLists.txt @@ -3,12 +3,8 @@ project( CGALImageIO_example ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) -endif() +cmake_minimum_required(VERSION 2.8.11) + find_package(CGAL QUIET COMPONENTS ImageIO ) diff --git a/CGAL_ImageIO/src/CGAL_ImageIO/CMakeLists.txt b/CGAL_ImageIO/src/CGAL_ImageIO/CMakeLists.txt index b7c8c462376..ae175c265f1 100644 --- a/CGAL_ImageIO/src/CGAL_ImageIO/CMakeLists.txt +++ b/CGAL_ImageIO/src/CGAL_ImageIO/CMakeLists.txt @@ -57,7 +57,9 @@ if(OPENGL_FOUND) add_definitions( ${CGAL_3RD_PARTY_DEFINITIONS} ${CGAL_ImageIO_3RD_PARTY_DEFINITIONS} ) - target_link_libraries( CGAL_ImageIO ${CGAL_LIBRARY} ${CGAL_3RD_PARTY_LIBRARIES} ${CGAL_ImageIO_3RD_PARTY_LIBRARIES} ) + # CGAL_ImageIO only depends on CGAL in DEBUG, but we still link it + # in both build types. + target_link_libraries( CGAL_ImageIO CGAL ${CGAL_3RD_PARTY_LIBRARIES} ${CGAL_ImageIO_3RD_PARTY_LIBRARIES} ) message("libCGAL_ImageIO is configured") diff --git a/CGAL_ImageIO/test/CGAL_ImageIO/CMakeLists.txt b/CGAL_ImageIO/test/CGAL_ImageIO/CMakeLists.txt index 7508c18dbb3..efa259766ba 100644 --- a/CGAL_ImageIO/test/CGAL_ImageIO/CMakeLists.txt +++ b/CGAL_ImageIO/test/CGAL_ImageIO/CMakeLists.txt @@ -4,12 +4,8 @@ project( CGALImageIO_test ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) -endif() +cmake_minimum_required(VERSION 2.8.11) + include_directories(../../include) diff --git a/CGAL_ipelets/demo/CGAL_ipelets/CMakeLists.txt b/CGAL_ipelets/demo/CGAL_ipelets/CMakeLists.txt index f41fb59e790..8ac0e9ff203 100644 --- a/CGAL_ipelets/demo/CGAL_ipelets/CMakeLists.txt +++ b/CGAL_ipelets/demo/CGAL_ipelets/CMakeLists.txt @@ -1,8 +1,6 @@ -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() macro( remove_leading_zero var ) diff --git a/CGAL_ipelets/demo/CGAL_ipelets/cgal_test_with_cmake b/CGAL_ipelets/demo/CGAL_ipelets/cgal_test_with_cmake index e7093a67bcd..e3ea1cc9564 100755 --- a/CGAL_ipelets/demo/CGAL_ipelets/cgal_test_with_cmake +++ b/CGAL_ipelets/demo/CGAL_ipelets/cgal_test_with_cmake @@ -180,6 +180,6 @@ fi # if [ -n "${NEED_CLEAN}" ]; then if ! ( uname | grep -q "CYGWIN" ) ; then - ${MAKE_CMD} -fMakefile clean + ${MAKE_CMD} -fMakefile clean || true fi fi diff --git a/CMakeLists.txt b/CMakeLists.txt index f5ce4359bf2..22994ec982c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,11 +3,7 @@ message( "== CMake setup ==" ) project(CGAL CXX C) # Minimal version of CMake: -if(WIN32) - cmake_minimum_required(VERSION 2.8.6) -else() - cmake_minimum_required(VERSION 2.6.2) -endif() +cmake_minimum_required(VERSION 2.8.11) # option for branch build diff --git a/Circular_kernel_3/demo/Circular_kernel_3/CMakeLists.txt b/Circular_kernel_3/demo/Circular_kernel_3/CMakeLists.txt index 60bd742405f..698a7791efc 100644 --- a/Circular_kernel_3/demo/Circular_kernel_3/CMakeLists.txt +++ b/Circular_kernel_3/demo/Circular_kernel_3/CMakeLists.txt @@ -1,33 +1,28 @@ project (Circular_kernel_3) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() -find_package(CGAL COMPONENTS Qt4) +find_package(CGAL COMPONENTS Qt5) include(${CGAL_USE_FILE}) -set( QT_USE_QTXML TRUE ) -set( QT_USE_QTMAIN TRUE ) -set( QT_USE_QTSCRIPT TRUE ) -set( QT_USE_QTOPENGL TRUE ) -find_package(Qt4) +find_package(Qt5 QUIET COMPONENTS Xml Script OpenGL) find_package(OpenGL) find_package(QGLViewer) -if ( CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND ) +if ( CGAL_FOUND AND CGAL_Qt5_FOUND AND Qt5_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND ) - include(${QT_USE_FILE}) include_directories (${QGLVIEWER_INCLUDE_DIR}) include_directories (BEFORE ../../include ./ ) add_executable ( Circular_kernel_3 Circular_kernel_3.cpp Viewer.cpp ) + qt5_use_modules( Circular_kernel_3 Xml Script OpenGL) + add_to_cached_list( CGAL_EXECUTABLE_TARGETS Circular_kernel_3 ) target_link_libraries( Circular_kernel_3 ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES}) @@ -36,6 +31,6 @@ if ( CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_ else() - message(STATUS "NOTICE: This demo requires CGAL, the QGLViewer, OpenGL and Qt4, and will not be compiled.") + message(STATUS "NOTICE: This demo requires CGAL, the QGLViewer, OpenGL and Qt5, and will not be compiled.") endif() diff --git a/Circular_kernel_3/demo/Circular_kernel_3/Circular_kernel_3.cpp b/Circular_kernel_3/demo/Circular_kernel_3/Circular_kernel_3.cpp index 79d42eb9c74..07f50de2325 100644 --- a/Circular_kernel_3/demo/Circular_kernel_3/Circular_kernel_3.cpp +++ b/Circular_kernel_3/demo/Circular_kernel_3/Circular_kernel_3.cpp @@ -8,13 +8,9 @@ int main(int argc, char** argv) // Instantiate the viewer. Viewer viewer; - -#if QT_VERSION < 0x040000 - // Set the viewer as the application main widget. - application.setMainWidget(&viewer); -#else + //for Windows + application.setAttribute(Qt::AA_UseDesktopOpenGL); viewer.setWindowTitle("Intersection points of randomly generated circles."); -#endif // Make the viewer window visible on screen. viewer.show(); diff --git a/Circular_kernel_3/demo/Circular_kernel_3/Viewer.cpp b/Circular_kernel_3/demo/Circular_kernel_3/Viewer.cpp index 0bcab40685c..858aa0ab7af 100644 --- a/Circular_kernel_3/demo/Circular_kernel_3/Viewer.cpp +++ b/Circular_kernel_3/demo/Circular_kernel_3/Viewer.cpp @@ -3,153 +3,789 @@ #include #include #include +#include +Viewer::Viewer(QWidget* parent ) + : QGLViewer(CGAL::Qt::createOpenGLContext(),parent) +{ +} + +void Viewer::compile_shaders() +{ + initializeOpenGLFunctions(); + if(! buffers[0].create() || !buffers[1].create() || !buffers[2].create() || !buffers[3].create() + || !buffers[4].create() || !buffers[4].create() || !buffers[5].create() || !buffers[6].create() + || !buffers[7].create() || !buffers[8].create()) + { + std::cerr<<"VBO Creation FAILED"<compileSourceCode(vertex_source)) + { + std::cerr<<"Compiling vertex source FAILED"<compileSourceCode(fragment_source)) + { + std::cerr<<"Compiling fragmentsource FAILED"<(pos_sphere.size()*sizeof(float))); + vertexLocation[0] = rendering_program.attributeLocation("vertex"); + rendering_program.bind(); + rendering_program.enableAttributeArray(vertexLocation[0]); + rendering_program.setAttributeBuffer(vertexLocation[0],GL_FLOAT,0,3); + buffers[0].release(); + //normals of the sphere + buffers[1].bind(); + buffers[1].allocate(normals.data(), + static_cast(normals.size()*sizeof(float))); + normalsLocation[0] = rendering_program.attributeLocation("normal"); + rendering_program.bind(); + rendering_program.enableAttributeArray(normalsLocation[0]); + rendering_program.setAttributeBuffer(normalsLocation[0],GL_FLOAT,0,3); + buffers[1].release(); + //center of the sphere + buffers[2].bind(); + buffers[2].allocate(trivial_center.data(), + static_cast(trivial_center.size()*sizeof(float))); + trivialCenterLocation = rendering_program.attributeLocation("center"); + rendering_program.bind(); + rendering_program.enableAttributeArray(trivialCenterLocation); + rendering_program.setAttributeBuffer(trivialCenterLocation,GL_FLOAT,0,3); + buffers[2].release(); + glVertexAttribDivisor(trivialCenterLocation, 1); + glVertexAttribDivisor(normalsLocation[0], 0); + vao[0].release(); + + //The circles + vao[1].bind(); + buffers[3].bind(); + buffers[3].allocate(pos_lines.data(), + static_cast(pos_lines.size()*sizeof(float))); + vertexLocation[2] = rendering_program.attributeLocation("vertex"); + rendering_program.bind(); + rendering_program.enableAttributeArray(vertexLocation[2]); + rendering_program.setAttributeBuffer(vertexLocation[2],GL_FLOAT,0,3); + buffers[3].release(); + + //normals + buffers[4].bind(); + buffers[4].allocate(normals_lines.data(), + static_cast(normals_lines.size()*sizeof(float))); + normalsLocation[1] = rendering_program.attributeLocation("normal"); + rendering_program.bind(); + rendering_program.enableAttributeArray(normalsLocation[1]); + rendering_program.setAttributeBuffer(normalsLocation[1],GL_FLOAT,0,3); + buffers[4].release(); + //center + buffers[5].bind(); + buffers[5].allocate(trivial_center.data(), + static_cast(trivial_center.size()*sizeof(float))); + trivialCenterLocation = rendering_program.attributeLocation("center"); + rendering_program.bind(); + rendering_program.enableAttributeArray(trivialCenterLocation); + rendering_program.setAttributeBuffer(trivialCenterLocation,GL_FLOAT,0,3); + buffers[5].release(); + glVertexAttribDivisor(trivialCenterLocation, 1); + glVertexAttribDivisor(normalsLocation[0], 0); + rendering_program.release(); + + vao[1].release(); + + //The little green spheres + vao[2].bind(); + //points of the sphere + buffers[6].bind(); + buffers[6].allocate(pos_sphere_inter.data(), + static_cast(pos_sphere_inter.size()*sizeof(float))); + vertexLocation[2] = rendering_program.attributeLocation("vertex"); + rendering_program.bind(); + rendering_program.enableAttributeArray(vertexLocation[2]); + rendering_program.setAttributeBuffer(vertexLocation[2],GL_FLOAT,0,3); + buffers[6].release(); + //normals of the sphere + buffers[7].bind(); + buffers[7].allocate(normals_inter.data(), + static_cast(normals_inter.size()*sizeof(float))); + normalsLocation[2] = rendering_program.attributeLocation("normal"); + rendering_program.bind(); + rendering_program.enableAttributeArray(normalsLocation[2]); + rendering_program.setAttributeBuffer(normalsLocation[2],GL_FLOAT,0,3); + buffers[7].release(); + //center of the sphere + buffers[8].bind(); + buffers[8].allocate(pos_points.data(), + static_cast(pos_points.size()*sizeof(float))); + centerLocation = rendering_program.attributeLocation("center"); + rendering_program.bind(); + rendering_program.enableAttributeArray(centerLocation); + rendering_program.setAttributeBuffer(centerLocation,GL_FLOAT,0,3); + buffers[8].release(); + glVertexAttribDivisor(centerLocation, 1); + glVertexAttribDivisor(normalsLocation[1], 0); + vao[2].release(); -template -void Viewer::draw_circle_on_unit_sphere(const typename CGAL::Point_3& center) const { - const typename Kernel::Point_3 origin(0,0,0); - const typename Kernel::Plane_3 plane(center, center-origin); - typename Kernel::Vector_3 base1=plane.base1(); - typename Kernel::Vector_3 base2=plane.base2(); - base1=base1/CGAL::sqrt(base1.squared_length()); - base2=base2/CGAL::sqrt(base2.squared_length()); - const double radius=CGAL::sqrt( CGAL::to_double( 1 - CGAL::squared_distance(origin,center) ) ); - const double nb_pt_per_circle=100; - const double step=2 * CGAL_PI / nb_pt_per_circle; - ::glDisable(GL_LIGHTING); - ::glBegin(GL_LINE_LOOP); - for (double theta = 0; theta < 2 * CGAL_PI ; theta += step) { - const typename Kernel::Point_3 point=center + ( radius*cos(theta)*base1 + radius*sin(theta)*base2 ); - ::glVertex3f( point.x(),point.y(),point.z() ); - } - ::glEnd(); - ::glEnable(GL_LIGHTING); + +} + +void Viewer::compute_elements() +{ + + //The Central Sphere + { + pos_sphere.resize(0); + trivial_center.resize(0); + int rings=3,sectors=6; + float T, P, R = 0.999f; + float x[4],y[4],z[4]; + + + //Top of the sphere + for(int t=0; t<360; t+=sectors) + { + + pos_sphere.push_back(0); + pos_sphere.push_back(0); + pos_sphere.push_back(R); + + + normals.push_back(0); + normals.push_back(0); + normals.push_back(1); + + + + P = rings*M_PI/180.0; + T = t*M_PI/180.0; + x[1] = sin(P) * cos(T) ; + y[1] = sin(P) * sin(T) ; + z[1] = cos(P); + pos_sphere.push_back(R * x[1]); + pos_sphere.push_back(R * y[1]); + pos_sphere.push_back(R * z[1]); + + + normals.push_back(x[1]); + normals.push_back(y[1]); + normals.push_back(z[1]); + + // + P = rings*M_PI/180.0; + T = (t+sectors)*M_PI/180.0; + x[2] = sin(P) * cos(T) ; + y[2] = sin(P) * sin(T) ; + z[2] = cos(P); + pos_sphere.push_back(R * x[2]); + pos_sphere.push_back(R * y[2]); + pos_sphere.push_back(R * z[2]); + + normals.push_back(x[2]); + normals.push_back(y[2]); + normals.push_back(z[2]); + + } + + //Body of the sphere + for (int p=rings; p<180-rings; p+=rings) + for(int t=0; t<360; t+=sectors) + { + //A + P = p*M_PI/180.0; + T = t*M_PI/180.0; + x[0] = sin(P) * cos(T) ; + y[0] = sin(P) * sin(T) ; + z[0] = cos(P); + + pos_sphere.push_back(R * x[0]); + pos_sphere.push_back(R * y[0]); + pos_sphere.push_back(R * z[0]); + + + normals.push_back(x[0]); + normals.push_back(y[0]); + normals.push_back(z[0]); + + //B + P = (p+rings)*M_PI/180.0; + T = t*M_PI/180.0; + x[1] = sin(P) * cos(T) ; + y[1] = sin(P) * sin(T) ; + z[1] = cos(P); + pos_sphere.push_back(R * x[1]); + pos_sphere.push_back(R * y[1]); + pos_sphere.push_back(R * z[1]); + + + normals.push_back(x[1]); + normals.push_back(y[1]); + normals.push_back(z[1]); + + //C + P = p*M_PI/180.0; + T = (t+sectors)*M_PI/180.0; + x[2] = sin(P) * cos(T) ; + y[2] = sin(P) * sin(T) ; + z[2] = cos(P); + pos_sphere.push_back(R * x[2]); + pos_sphere.push_back(R * y[2]); + pos_sphere.push_back(R * z[2]); + + + normals.push_back(x[2]); + normals.push_back(y[2]); + normals.push_back(z[2]); + //D + P = (p+rings)*M_PI/180.0; + T = (t+sectors)*M_PI/180.0; + x[3] = sin(P) * cos(T) ; + y[3] = sin(P) * sin(T) ; + z[3] = cos(P); + pos_sphere.push_back(R * x[3]); + pos_sphere.push_back(R * y[3]); + pos_sphere.push_back(R * z[3]); + + + normals.push_back(x[3]); + normals.push_back(y[3]); + normals.push_back(z[3]); + + + + pos_sphere.push_back(R * x[1]); + pos_sphere.push_back(R * y[1]); + pos_sphere.push_back(R * z[1]); + + + normals.push_back(x[1]); + normals.push_back(y[1]); + normals.push_back(z[1]); + + pos_sphere.push_back(R * x[2]); + pos_sphere.push_back(R * y[2]); + pos_sphere.push_back(R * z[2]); + + + normals.push_back(x[2]); + normals.push_back(y[2]); + normals.push_back(z[2]); + + } + //Bottom of the sphere + for(int t=0; t<360; t+=sectors) + { + + + pos_sphere.push_back(0); + pos_sphere.push_back(0); + pos_sphere.push_back(-R); + + + normals.push_back(0); + normals.push_back(0); + normals.push_back(-1); + + + P = (180-rings)*M_PI/180.0; + T = t*M_PI/180.0; + x[1] = sin(P) * cos(T) ; + y[1] = sin(P) * sin(T) ; + z[1] = cos(P); + pos_sphere.push_back(R * x[1]); + pos_sphere.push_back(R * y[1]); + pos_sphere.push_back(R * z[1]); + + + normals.push_back(x[1]); + normals.push_back(y[1]); + normals.push_back(z[1]); + + + P = (180-rings)*M_PI/180.0; + T = (t+sectors)*M_PI/180.0; + x[2] = sin(P) * cos(T) ; + y[2] = sin(P) * sin(T) ; + z[2] = cos(P); + pos_sphere.push_back(R * x[2]); + pos_sphere.push_back(R * y[2]); + pos_sphere.push_back(R * z[2]); + + + normals.push_back(x[2]); + normals.push_back(y[2]); + normals.push_back(z[2]); + + } + trivial_center.push_back(0.0);trivial_center.push_back(0.0);trivial_center.push_back(0.0); + } + //The intersection spheres + { + pos_sphere_inter.resize(0); + int rings=3,sectors=3; + float T, P, R = 0.005f; + float x[4],y[4],z[4]; + + + //Top of the sphere + for(int t=0; t<360; t+=sectors) + { + + pos_sphere_inter.push_back(0); + pos_sphere_inter.push_back(0); + pos_sphere_inter.push_back(R); + + + normals_inter.push_back(0); + normals_inter.push_back(0); + normals_inter.push_back(1); + + + + P = rings*M_PI/180.0; + T = t*M_PI/180.0; + x[1] = sin(P) * cos(T) ; + y[1] = sin(P) * sin(T) ; + z[1] = cos(P); + pos_sphere_inter.push_back(R * x[1]); + pos_sphere_inter.push_back(R * y[1]); + pos_sphere_inter.push_back(R * z[1]); + + + normals_inter.push_back(x[1]); + normals_inter.push_back(y[1]); + normals_inter.push_back(z[1]); + + // + P = rings*M_PI/180.0; + T = (t+sectors)*M_PI/180.0; + x[2] = sin(P) * cos(T) ; + y[2] = sin(P) * sin(T) ; + z[2] = cos(P); + pos_sphere_inter.push_back(R * x[2]); + pos_sphere_inter.push_back(R * y[2]); + pos_sphere_inter.push_back(R * z[2]); + + normals_inter.push_back(x[2]); + normals_inter.push_back(y[2]); + normals_inter.push_back(z[2]); + + } + + //Body of the sphere + for (int p=rings; p<180-rings; p+=rings) + for(int t=0; t<360; t+=sectors) + { + //A + P = p*M_PI/180.0; + T = t*M_PI/180.0; + x[0] = sin(P) * cos(T) ; + y[0] = sin(P) * sin(T) ; + z[0] = cos(P); + + pos_sphere_inter.push_back(R * x[0]); + pos_sphere_inter.push_back(R * y[0]); + pos_sphere_inter.push_back(R * z[0]); + + + normals_inter.push_back(x[0]); + normals_inter.push_back(y[0]); + normals_inter.push_back(z[0]); + + //B + P = (p+rings)*M_PI/180.0; + T = t*M_PI/180.0; + x[1] = sin(P) * cos(T) ; + y[1] = sin(P) * sin(T) ; + z[1] = cos(P); + pos_sphere_inter.push_back(R * x[1]); + pos_sphere_inter.push_back(R * y[1]); + pos_sphere_inter.push_back(R * z[1]); + + + normals_inter.push_back(x[1]); + normals_inter.push_back(y[1]); + normals_inter.push_back(z[1]); + + //C + P = p*M_PI/180.0; + T = (t+sectors)*M_PI/180.0; + x[2] = sin(P) * cos(T) ; + y[2] = sin(P) * sin(T) ; + z[2] = cos(P); + pos_sphere_inter.push_back(R * x[2]); + pos_sphere_inter.push_back(R * y[2]); + pos_sphere_inter.push_back(R * z[2]); + + + normals_inter.push_back(x[2]); + normals_inter.push_back(y[2]); + normals_inter.push_back(z[2]); + //D + P = (p+rings)*M_PI/180.0; + T = (t+sectors)*M_PI/180.0; + x[3] = sin(P) * cos(T) ; + y[3] = sin(P) * sin(T) ; + z[3] = cos(P); + pos_sphere_inter.push_back(R * x[3]); + pos_sphere_inter.push_back(R * y[3]); + pos_sphere_inter.push_back(R * z[3]); + + + normals_inter.push_back(x[3]); + normals_inter.push_back(y[3]); + normals_inter.push_back(z[3]); + + + + pos_sphere_inter.push_back(R * x[1]); + pos_sphere_inter.push_back(R * y[1]); + pos_sphere_inter.push_back(R * z[1]); + + + normals_inter.push_back(x[1]); + normals_inter.push_back(y[1]); + normals_inter.push_back(z[1]); + + pos_sphere_inter.push_back(R * x[2]); + pos_sphere_inter.push_back(R * y[2]); + pos_sphere_inter.push_back(R * z[2]); + + + normals_inter.push_back(x[2]); + normals_inter.push_back(y[2]); + normals_inter.push_back(z[2]); + + } + //Bottom of the sphere + for(int t=0; t<360; t+=sectors) + { + + + pos_sphere_inter.push_back(0); + pos_sphere_inter.push_back(0); + pos_sphere_inter.push_back(-R); + + + normals_inter.push_back(0); + normals_inter.push_back(0); + normals_inter.push_back(-1); + + + P = (180-rings)*M_PI/180.0; + T = t*M_PI/180.0; + x[1] = sin(P) * cos(T) ; + y[1] = sin(P) * sin(T) ; + z[1] = cos(P); + pos_sphere_inter.push_back(R * x[1]); + pos_sphere_inter.push_back(R * y[1]); + pos_sphere_inter.push_back(R * z[1]); + + + normals_inter.push_back(x[1]); + normals_inter.push_back(y[1]); + normals_inter.push_back(z[1]); + + + P = (180-rings)*M_PI/180.0; + T = (t+sectors)*M_PI/180.0; + x[2] = sin(P) * cos(T) ; + y[2] = sin(P) * sin(T) ; + z[2] = cos(P); + pos_sphere_inter.push_back(R * x[2]); + pos_sphere_inter.push_back(R * y[2]); + pos_sphere_inter.push_back(R * z[2]); + + + normals_inter.push_back(x[2]); + normals_inter.push_back(y[2]); + normals_inter.push_back(z[2]); + + } + } + + + //init + { + pos_points.resize(0); + pos_lines.resize(0); + // Restore previous viewer state. + restoreStateFromFile(); + + //random generator of points within a sphere + typedef CGAL::Creator_uniform_3 Creator; + CGAL::Random_points_in_sphere_3 gen; + + const unsigned nb_circles=20; + + //vector to store input points + std::vector points; + points.reserve(nb_circles); + + + + for (unsigned i=0;i intersections; + naive_compute_intersection_points(points,std::back_inserter(intersections)); + + //draw points as small spheres + for (std::vector::const_iterator it=intersections.begin();it!=intersections.end();++it){ + pos_points.push_back(it->x()); pos_points.push_back(it->y()); pos_points.push_back(it->z()); + } + + } +} + +void Viewer::attrib_buffers(QGLViewer* viewer) +{ + QMatrix4x4 mvpMatrix; + QMatrix4x4 mvMatrix; + double mat[16]; + viewer->camera()->getModelViewProjectionMatrix(mat); + for(int i=0; i < 16; i++) + { + mvpMatrix.data()[i] = (float)mat[i]; + } + viewer->camera()->getModelViewMatrix(mat); + for(int i=0; i < 16; i++) + { + mvMatrix.data()[i] = (float)mat[i]; + } + // define material + QVector4D ambient(0.1f, 0.1f, 0.1f, 1.0f); + QVector4D diffuse( 0.9f, + 0.9f, + 0.9f, + 0.0f ); + + QVector4D specular( 0.0f, + 0.0f, + 0.0f, + 0.0f ); + + QVector4D position( -1.2f, 1.2f, .9797958971f, 1.0f ); + GLfloat shininess = 1.0f; + + + rendering_program.bind(); + mvpLocation = rendering_program.uniformLocation("mvp_matrix"); + mvLocation = rendering_program.uniformLocation("mv_matrix"); + colorLocation = rendering_program.uniformLocation("color"); + lightLocation[0] = rendering_program.uniformLocation("light_pos"); + lightLocation[1] = rendering_program.uniformLocation("light_diff"); + lightLocation[2] = rendering_program.uniformLocation("light_spec"); + lightLocation[3] = rendering_program.uniformLocation("light_amb"); + lightLocation[4] = rendering_program.uniformLocation("spec_power"); + + rendering_program.setUniformValue(lightLocation[0], position); + rendering_program.setUniformValue(lightLocation[1], diffuse); + rendering_program.setUniformValue(lightLocation[2], specular); + rendering_program.setUniformValue(lightLocation[3], ambient); + rendering_program.setUniformValue(lightLocation[4], shininess); + rendering_program.setUniformValue(mvpLocation, mvpMatrix); + rendering_program.setUniformValue(mvLocation, mvMatrix); + + + rendering_program.release(); + } void Viewer::draw() { - const int sphere_res=30; - - //draw central sphere - ::glPushMatrix(); - ::glColor3f(1,1,1); - ::gluSphere(qsphere,0.999,sphere_res,sphere_res); - ::glCallList(dl_nb); - ::glCallList(dl_nb+1); - ::glPopMatrix(); + QColor color; + + //sphere + vao[0].bind(); + attrib_buffers(this); + rendering_program.bind(); + color.setRgbF(1.0f, 1.0f, 1.0f); + rendering_program.setUniformValue(colorLocation, color); + glDrawArraysInstanced(GL_TRIANGLES, 0, static_cast(pos_sphere.size()/3), 1); + rendering_program.release(); + vao[0].release(); + + //intersection + vao[2].bind(); + attrib_buffers(this); + rendering_program.bind(); + color.setRgbF(0.0f, 1.0f, 0.0f); + rendering_program.setUniformValue(colorLocation, color); + glDrawArraysInstanced(GL_TRIANGLES, 0, static_cast(pos_sphere_inter.size()/3), static_cast(pos_points.size()/3)); + rendering_program.release(); + vao[2].release(); + + //circles + + vao[1].bind(); + attrib_buffers(this); + rendering_program.bind(); + color.setRgbF(1.0f, 0.0f, 0.0f); + rendering_program.setUniformValue(colorLocation, color); + glDrawArrays(GL_LINES, 0, static_cast(pos_lines.size()/3)); + rendering_program.release(); + vao[1].release(); + + } void Viewer::init() { - // Restore previous viewer state. - restoreStateFromFile(); - - //init quadric to store sphere. - qsphere=gluNewQuadric(); - gluQuadricOrientation(qsphere,GLU_OUTSIDE); - - //code for antialiasing - ::glEnable(GL_BLEND); - ::glEnable(GL_LINE_SMOOTH); - ::glEnable(GL_POINT_SMOOTH); - ::glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); - ::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - + compile_shaders(); + compute_elements(); + initialize_buffers(); + ::glEnable(GL_BLEND); - //set intersection point size - ::glPointSize(5); - - //random generator of points within a sphere - typedef CGAL::Creator_uniform_3 Creator; - CGAL::Random_points_in_sphere_3 gen; - - const unsigned nb_circles=20; - - //vector to store input points - std::vector points; - points.reserve(nb_circles); - - //disable lighting before drawing segments and points - ::glEnable(GL_LIGHTING); - - //init call lists - dl_nb=::glGenLists(2); - - //store circles in a display list - ::glNewList(dl_nb,GL_COMPILE); - ::glColor3f(1,0,0); - - for (unsigned i=0;i intersections; - naive_compute_intersection_points(points,std::back_inserter(intersections)); + ::glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); + ::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_POINT_SMOOTH); + glEnable(GL_LINE_SMOOTH); - ::glNewList(dl_nb+1,GL_COMPILE); - ::glColor3f(0,1,0); - //draw points as small spheres - for (std::vector::const_iterator it=intersections.begin();it!=intersections.end();++it){ - glPushMatrix(); - glTranslatef(it->x(),it->y(),it->z()); - gluSphere(qsphere,0.005,10,10); - glPopMatrix(); - } - ::glEndList(); - - //lighting - ::glEnable(GL_LIGHT0); - ::glEnable(GL_LIGHTING); - float lpos[4] = { -.2f, .2f, .9797958971f, 0.0f }; - ::glLightfv(GL_LIGHT0,GL_POSITION,lpos); - ::glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, 1.0f); - - ::glEnable(GL_NORMALIZE); - ::glShadeModel(GL_SMOOTH); } - template void Viewer::naive_compute_intersection_points(const std::vector& points,Output_iterator out) const { - typedef CGAL::Exact_spherical_kernel_3 SK; - SK::Sphere_3 sphere(SK::Point_3(0,0,0),1); - - //converter point to exact SK point type - CGAL::Cartesian_converter to_exact; - std::vector circles; - - //create circles from points: need to use a converter to change floating points coordinates into an exact NT. - for (std::vector::const_iterator it=points.begin();it!=points.end();++it){ - const SK::Point_3 center=to_exact(*it); - circles.push_back( SK::Circle_3(sphere,SK::Plane_3(center,center-CGAL::ORIGIN) ) ); - } - - - //Look for intersection points among pair of circles: use a naive and quadratic way - for (std::vector::const_iterator it_f=circles.begin();it_f!=--circles.end();++it_f){ - std::vector::const_iterator it_s=it_f; - ++it_s; - for (;it_s!=circles.end();++it_s){ - std::vector intersections; - //ensure_circles are different - CGAL_precondition(*it_s!=*it_f); - CGAL::intersection(*it_f,*it_s,std::back_inserter(intersections)); - if (!intersections.empty()){ - for (std::vector ::const_iterator it_pt=intersections.begin();it_pt!=intersections.end();++it_pt){ - const std::pair* pt= - CGAL::object_cast< std::pair > (&(*it_pt)); - assert(pt!=NULL); - *out++=EPIC::Point_3( CGAL::to_double(pt->first.x()), - CGAL::to_double(pt->first.y()), - CGAL::to_double(pt->first.z()) - ); - } - } + typedef CGAL::Exact_spherical_kernel_3 SK; + SK::Sphere_3 sphere(SK::Point_3(0,0,0),1); + + //converter point to exact SK point type + CGAL::Cartesian_converter to_exact; + std::vector circles; + + //create circles from points: need to use a converter to change floating points coordinates into an exact NT. + for (std::vector::const_iterator it=points.begin();it!=points.end();++it){ + const SK::Point_3 center=to_exact(*it); + circles.push_back( SK::Circle_3(sphere,SK::Plane_3(center,center-CGAL::ORIGIN) ) ); + } + + + //Look for intersection points among pair of circles: use a naive and quadratic way + for (std::vector::const_iterator it_f=circles.begin();it_f!=--circles.end();++it_f){ + std::vector::const_iterator it_s=it_f; + ++it_s; + for (;it_s!=circles.end();++it_s){ + std::vector intersections; + //ensure_circles are different + CGAL_precondition(*it_s!=*it_f); + CGAL::intersection(*it_f,*it_s,std::back_inserter(intersections)); + if (!intersections.empty()){ + for (std::vector ::const_iterator it_pt=intersections.begin();it_pt!=intersections.end();++it_pt){ + const std::pair* pt= + CGAL::object_cast< std::pair > (&(*it_pt)); + assert(pt!=NULL); + *out++=EPIC::Point_3( CGAL::to_double(pt->first.x()), + CGAL::to_double(pt->first.y()), + CGAL::to_double(pt->first.z()) + ); + } + } + } } - } } diff --git a/Circular_kernel_3/demo/Circular_kernel_3/Viewer.h b/Circular_kernel_3/demo/Circular_kernel_3/Viewer.h index e43abf41bd7..81b20ba1746 100644 --- a/Circular_kernel_3/demo/Circular_kernel_3/Viewer.h +++ b/Circular_kernel_3/demo/Circular_kernel_3/Viewer.h @@ -1,18 +1,52 @@ #include #include -#include + +#include +#include +#include +#include typedef CGAL::Exact_predicates_inexact_constructions_kernel EPIC; -class Viewer : public QGLViewer +class Viewer : public QGLViewer, QOpenGLFunctions_3_3_Core { - GLUquadricObj *qsphere; +public: + Viewer(QWidget* parent = 0); GLuint dl_nb; protected : virtual void draw(); virtual void init(); - template - void draw_circle_on_unit_sphere(const typename CGAL::Point_3&) const; template void naive_compute_intersection_points(const std::vector&,Output_iterator) const; +private: + //Shaders elements + + int vertexLocation[3]; + int normalsLocation[3]; + int centerLocation; + int trivialCenterLocation; + int mvpLocation; + int mvLocation; + int colorLocation; + int lightLocation[5]; + + + std::vector pos_points; + std::vector pos_lines; + std::vector pos_sphere; + std::vector pos_sphere_inter; + std::vector normals; + std::vector normals_inter; + std::vector trivial_center; + std::vector normals_lines; + + QOpenGLBuffer buffers[9]; + QOpenGLVertexArrayObject vao[3]; + QOpenGLShaderProgram rendering_program; + + void initialize_buffers(); + void compute_elements(); + void attrib_buffers(QGLViewer*); + void compile_shaders(); + }; diff --git a/Convex_decomposition_3/demo/Convex_decomposition_3/CMakeLists.txt b/Convex_decomposition_3/demo/Convex_decomposition_3/CMakeLists.txt index 72a3a04172c..d4244de750d 100644 --- a/Convex_decomposition_3/demo/Convex_decomposition_3/CMakeLists.txt +++ b/Convex_decomposition_3/demo/Convex_decomposition_3/CMakeLists.txt @@ -2,11 +2,9 @@ project( Convex_decomposition_3 ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() find_package(CGAL COMPONENTS Qt3 ) @@ -14,7 +12,7 @@ include( ${CGAL_USE_FILE} ) find_package(Qt3-patched) # FindQt3-patched.cmake is FindQt3.cmake patched by CGAL developers, so -# that it can be used together with FindQt4: all its variables are prefixed +# that it can be used together with Qt5: all its variables are prefixed # by "QT3_" instead of "QT_". if ( CGAL_FOUND AND QT3_FOUND AND CGAL_Qt3_FOUND) diff --git a/Convex_hull_2/demo/Convex_hull_2/CMakeLists.txt b/Convex_hull_2/demo/Convex_hull_2/CMakeLists.txt index a5a54803200..c69d4fa86e3 100644 --- a/Convex_hull_2/demo/Convex_hull_2/CMakeLists.txt +++ b/Convex_hull_2/demo/Convex_hull_2/CMakeLists.txt @@ -2,11 +2,9 @@ project( convex_hull_2 ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() find_package(CGAL COMPONENTS Qt3 ) @@ -14,7 +12,7 @@ include( ${CGAL_USE_FILE} ) find_package(Qt3-patched) # FindQt3-patched.cmake is FindQt3.cmake patched by CGAL developers, so -# that it can be used together with FindQt4: all its variables are prefixed +# that it can be used together with Qt5: all its variables are prefixed # by "QT3_" instead of "QT_". if ( CGAL_FOUND AND CGAL_Qt3_FOUND AND QT3_FOUND ) diff --git a/Convex_hull_3/demo/Convex_hull_3/CMakeLists.txt b/Convex_hull_3/demo/Convex_hull_3/CMakeLists.txt index 821d97f59a1..ca7554ef8ba 100644 --- a/Convex_hull_3/demo/Convex_hull_3/CMakeLists.txt +++ b/Convex_hull_3/demo/Convex_hull_3/CMakeLists.txt @@ -4,11 +4,9 @@ project( Convex_hull_3_Demo ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() find_package(CGAL QUIET COMPONENTS Core ) diff --git a/Documentation/doc/Documentation/Installation.txt b/Documentation/doc/Documentation/Installation.txt index ebe010c0a2a..34b86a241d6 100644 --- a/Documentation/doc/Documentation/Installation.txt +++ b/Documentation/doc/Documentation/Installation.txt @@ -66,10 +66,10 @@ For instance, use macports in the following way: sudo port install cgal -or if Qt4 demos are desired +or if Qt5 are desired
-sudo port install cgal +qt4 +universal +demos
+sudo port install cgal +qt5 +universal +demos
 
The setup is similar for homebrew . @@ -167,9 +167,7 @@ In order to build the \cgal libraries, you need a \cpp compiler. In order to configure, build, and install the \cgal libraries, examples and demos, you need CMake, a cross-platform "makefile generator". If CMake is not installed already you can obtain it from `http://www.cmake.org/`. -CMake version 2.6.3 or higher is required. On Windows, CMake -version 2.8.6 or higher is required, for a proper support of DLL's -generation. +CMake version 2.8.11 or higher is required. This manual explains only those features of CMake which are needed in order to build \cgal. Please refer to the CMake documentation at `http://www.cmake.org/` for further details. @@ -185,8 +183,7 @@ Visual \cpp solution and project file that you can use to build \cgal. \subsection installation_configuring_gui Configuring CGAL with the CMake GUI The simplest way to start the configuration is to run the graphical -user interface of CMake. We recommend to use `cmake-gui`. It -is available on many platforms as of CMake version 2.6. You must pass as +user interface of CMake. We recommend to use `cmake-gui`. You must pass as argument the root directory of \cgal. For example:
@@ -298,8 +295,7 @@ We next list the libraries and essential 3rd party software
 | `CGAL_Core` | `WITH_CGAL_Core`  | The CORE library for algebraic numbers.\cgalFootnote{CGAL_Core is not part of \cgal, but a custom version of the \sc{Core} library distributed by \cgal for the user convenience and it has it's own license.}  | \sc{Gmp} and \sc{Mpfr} |
 | `CGAL_ImageIO` | `WITH_CGAL_ImageIO` | Utilities to read and write image files  | \sc{OpenGL}, \sc{zlib}, \sc{Vtk}(optional) |
 | `CGAL_Qt3`  | `WITH_CGAL_Qt3` | `CGAL::Qt_widget` used by \sc{Qt}3-based demos  | \sc{Qt}3 and \sc{OpenGL}  |
-| `CGAL_Qt4`  | `WITH_CGAL_Qt4` | `QGraphicsView` support for \sc{Qt}4-based demos | \sc{Qt}4 and \sc{OpenGL} |
-
+| `CGAL_Qt5`  | `WITH_CGAL_Qt5` | `QGraphicsView` support for \sc{Qt}5-based demos | \sc{Qt}5 and \sc{OpenGL} |
 
 \subsection installation_debug Debug vs. Release
 
@@ -333,7 +329,7 @@ see \ref sec3partysoftwareconfig to specify the location of 3rd
 party software.
 
 The libraries \stl (shipped with any compiler) and \sc{Boost} are essential to all components (i.e.\ libCGAL,
-libCGAL_Core, libCGAL_ImageIO, libCGAL_Qt3 and libCGAL_Qt4).
+libCGAL_Core, libCGAL_ImageIO, libCGAL_Qt3 and libCGAL_Qt5).
 
 \subsection thirdpartystl Standard Template Library (STL) 
 
@@ -375,7 +371,7 @@ As on Windows there is no canonical directory for where to find
 
 \subsection thirdpartyMPFR GMP and MPFR
 
-The components libCGAL, libCGAL_Core, libCGAL_Qt3 and libCGAL_Qt4 require 
+The components libCGAL, libCGAL_Core, libCGAL_Qt3 and libCGAL_Qt5 require 
 \sc{Gmp} and \sc{Mpfr} which are libraries for multi precision integers and rational numbers,
 and for multi precision floating point numbers.
 
@@ -407,25 +403,25 @@ for instance, on Windows, you can download it from `http://www.opengl.org/`.
 
-\subsection thirdpartyQt Qt3 and Qt4
+\subsection thirdpartyQt Qt3 and Qt5
 
 Qt is a cross-platform application and UI framework.
 
 The component libCGAL_Qt3 requires \sc{Qt}3 installed on your system, while
-the component libCGAL_Qt4 requires \sc{Qt}4 installed on your system. 
+the component libCGAL_Qt5 requires \sc{Qt}5 installed on your system. 
 In case \sc{Qt} is not yet installed on your system, you can download 
 it from `http://qt-project.org/`.
 
 Older demos of \cgal use libCGAL_Qt3 and \sc{Qt}3, while newer and newly
-developed demos require libCGAL_Qt4 and \sc{Qt}4.
+developed demos require libCGAL_Qt5 and \sc{Qt}5.
 
-Having \sc{Qt}4 version 4.3.0 or higher is recommended.
+Having \sc{Qt}4 version 4.3.0 or higher or \sc{Qt}5 version 5.3.0 is recommended.
 
 \section installation_examples CGAL Examples and Demos
 
@@ -510,7 +506,7 @@ The \sc{Eigen} web site is `http://eigen.tu
 
 \subsection thirdpartylibQGLViewer libQGLViewer 
 
-libQGLViewer is a 3D widget based on \sc{Qt} 4's `QGLWidget`.
+libQGLViewer is a 3D widget based on \sc{Qt} 4's `QGLWidget`. In case of \sc{Qt}5 used, libQGLViewer needs to be recompiled with the proper \sc{Qt}5 version.
 
 In \cgal some 3D demos are based on libQGLViewer.
 
@@ -673,6 +669,8 @@ cmake -DWITH_examples=OFF -DWITH_demos=OFF -DCMAKE_BUILD_TYPE=Release
 /path/to/unpacked/CGAL-tarball/
 
+\todo update the output of cmake +
 -- The CXX compiler identification is GNU
 -- The C compiler identification is GNU
@@ -966,8 +964,8 @@ If the parameter is not given, the script creates one executable for each giv
 source file.
 
`-c com1:com2:...`
Lists components ("com1", "com2") of \cgal to which the executable(s) should be linked. Valid components are \cgal's -libraries (i.e.\ "Core", "ImageIO", "Qt3" and "Qt4"; note -that it only make sense to either pick "Qt3" or "Qt4") and all +libraries (i.e.\ "Core", "ImageIO", "Qt3" and "Qt5"; note +that it only make sense to either pick "Qt3" or "Qt5") and all preconfigured 3rd party software, such as "MPFI", "RS3"). An example is `-c Core:GMP:RS3:MPFI`
`-b boost1:boost2:...`
Lists components ("boost1", @@ -1001,8 +999,8 @@ this file within a CMake script sets up include paths and libraries to link with \cgal and essential third party libraries. Beyond, `find_package` can demand for `COMPONENTS` of \cgal, that is, all \cgal libraries `libCGAL_Core` (Core), -libCGAL_ImageIO (ImageIO) , libCGAL_Qt3 (Qt3) and libCGAL_Qt4 -(Qt4) or optional 3rd party software such as MPFI, RS3. +libCGAL_ImageIO (ImageIO) , libCGAL_Qt3 (Qt3) and libCGAL_Qt5 +(Qt5) or optional 3rd party software such as MPFI, RS3. A user is free to create the `CMakeLists.txt` without calling the script (manual creation). @@ -1060,7 +1058,7 @@ configure and build. Their values can be ON or OFF. | `WITH_demos` | OFF | | `WITH_CGAL_Core` | ON | | `WITH_CGAL_Qt3` | ON | -| `WITH_CGAL_Qt4` | ON | +| `WITH_CGAL_Qt5` | ON | | `WITH_CGAL_ImageIO` | ON | \subsection installation_flags Compiler and Linker Flags @@ -1213,26 +1211,11 @@ the header files and the full pathnames of the \sc{Qt}3 libraries. | `QT3_UIC_EXECUTABLE` | Full pathname to the uic executable of \sc{Qt}3 | CMake | +\subsection installation_qt5 Qt5 Library -\subsection installation_qt4 Qt4 Library - -The CMake scripts that search for \sc{Qt}4 can use the introspection feature -of the tool `qmake` included in \sc{Qt}4 distributions. If \sc{Qt}4 is not -automatically found, it is sufficient to set the `PATH` -environment variable, so that \sc{Qt}4 `qmake` tool is in the path, and -before \sc{Qt}3 `qmake` if that one exists. One can alternatively set the -CMake variable `QT_QMAKE_EXECUTABLE`. The following variables -should be then assigned automatically by CMake. - -| Variable | Description | Type | -| :- | :- | :- | -| `QT_INCLUDE_DIR` | Directory containing the `QtCore/qglobal.h` file | CMake | -|`QT_LIBRARY_DIR` | Directory containing the compiled \sc{Qt}4 libraries | CMake | -| `QT_(xyz)_LIBRARY` | Full pathname to the compiled 'xyz' \sc{Qt}4 library\cgalFootnote{If both release and debug versions are available, this variable contains a list of the following form: 'optimized;;debug;', where the 'optimized' and 'debug' tags should appear verbatim.} | CMake | -| `QT_QMAKE_EXECUTABLE` | Full pathname to the qmake executable of \sc{Qt}4 | CMake | -| `QT_MOC_EXECUTABLE` | Full pathname to the moc executable of \sc{Qt}4 | CMake | -| `QT_UIC_EXECUTABLE` | Full pathname to the uic executable of \sc{Qt}4 | CMake | - +You must set the cmake or environment variable `Qt5_DIR` to point to the path +to the directory containing the file `Qt5Config.cmake` created by your \sc{Qt}5 installation. If you are +using the open source edition it should be `/qt-everywhere-opensource-src-/qtbase/lib/cmake/Qt5`. \subsection installation_leda LEDA Library diff --git a/Envelope_3/demo/Envelope_3/CMakeLists.txt b/Envelope_3/demo/Envelope_3/CMakeLists.txt index 0ae9ff1e1dc..666f483719e 100644 --- a/Envelope_3/demo/Envelope_3/CMakeLists.txt +++ b/Envelope_3/demo/Envelope_3/CMakeLists.txt @@ -4,11 +4,9 @@ project( Envelope_3_demo ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() find_package(CGAL QUIET COMPONENTS Core Qt3 ) @@ -19,7 +17,7 @@ if ( CGAL_FOUND ) find_package(Qt3-patched QUIET ) # FindQt3-patched.cmake is FindQt3.cmake patched by CGAL developers, so - # that it can be used together with FindQt4: all its variables are prefixed + # that it can be used together with Qt5: all its variables are prefixed # by "QT3_" instead of "QT_". if(CGAL_Qt3_FOUND AND QT3_FOUND AND CGAL_Core_FOUND) diff --git a/Filtered_kernel/benchmark/Filtered_kernel/CMakeLists.txt b/Filtered_kernel/benchmark/Filtered_kernel/CMakeLists.txt index 0ea2ad48cb8..739c48d90d3 100644 --- a/Filtered_kernel/benchmark/Filtered_kernel/CMakeLists.txt +++ b/Filtered_kernel/benchmark/Filtered_kernel/CMakeLists.txt @@ -4,12 +4,8 @@ project( Filtered_kernel_test ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) -endif() +cmake_minimum_required(VERSION 2.8.11) + add_executable(bench_simple_comparisons bench_simple_comparisons.cpp) diff --git a/Generator/benchmark/Generator/CMakeLists.txt b/Generator/benchmark/Generator/CMakeLists.txt index c768dddd5a7..e382a15573b 100644 --- a/Generator/benchmark/Generator/CMakeLists.txt +++ b/Generator/benchmark/Generator/CMakeLists.txt @@ -4,12 +4,8 @@ project( Generator_example ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) -endif() +cmake_minimum_required(VERSION 2.8.11) + find_package(CGAL QUIET COMPONENTS Core ) diff --git a/Generator/demo/Generator/qt3/CMakeLists.txt b/Generator/demo/Generator/qt3/CMakeLists.txt index eb2f6f2f008..d0b0e27a65a 100644 --- a/Generator/demo/Generator/qt3/CMakeLists.txt +++ b/Generator/demo/Generator/qt3/CMakeLists.txt @@ -9,7 +9,7 @@ include( ${CGAL_USE_FILE} ) find_package(Qt3-patched) # FindQt3-patched.cmake is FindQt3.cmake patched by CGAL developers, so -# that it can be used together with FindQt4: all its variables are prefixed +# that it can be used together with Qt5: all its variables are prefixed # by "QT3_" instead of "QT_". if ( CGAL_FOUND AND CGAL_Qt3_FOUND AND QT3_FOUND ) diff --git a/Geomview/demo/Geomview/CMakeLists.txt b/Geomview/demo/Geomview/CMakeLists.txt index 7b2cd179937..6ecbf001ccc 100644 --- a/Geomview/demo/Geomview/CMakeLists.txt +++ b/Geomview/demo/Geomview/CMakeLists.txt @@ -4,11 +4,9 @@ project( Geomview_Demo ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() find_package(CGAL QUIET COMPONENTS Core ) diff --git a/GraphicsView/TODO b/GraphicsView/TODO index 4a18ce0c90c..ec7ea6d5649 100644 --- a/GraphicsView/TODO +++ b/GraphicsView/TODO @@ -8,4 +8,4 @@ Shift: pour // aux axes. Affichage du (x,y) par rapport à l'origine de l'objet en cours. -Integrer src/CGALQt4 dans le build process de CGAL, avec CMake. +Integrer src/CGALQt5 dans le build process de CGAL, avec CMake. diff --git a/GraphicsView/demo/Alpha_shapes_2/Alpha_shapes_2.cpp b/GraphicsView/demo/Alpha_shapes_2/Alpha_shapes_2.cpp index b00678d50b1..4d85393bbdc 100644 --- a/GraphicsView/demo/Alpha_shapes_2/Alpha_shapes_2.cpp +++ b/GraphicsView/demo/Alpha_shapes_2/Alpha_shapes_2.cpp @@ -186,7 +186,7 @@ void MainWindow::alphaChanged(int i) /* * Qt Automatic Connections - * http://doc.trolltech.com/4.4/designer-using-a-component.html#automatic-connections + * http://doc.qt.io/qt-5/designer-using-a-ui-file.html#automatic-connections * * setupUi(this) generates connections to the slots named * "on__" @@ -211,8 +211,9 @@ MainWindow::on_actionInsertRandomPoints_triggered() Iso_rectangle_2 isor = convert(rect); CGAL::Random_points_in_iso_rectangle_2 pg((isor.min)(), (isor.max)()); bool ok = false; + const int number_of_points = - QInputDialog::getInteger(this, + QInputDialog::getInt(this, tr("Number of random points"), tr("Enter number of random points"), 100, @@ -299,9 +300,8 @@ int main(int argc, char **argv) app.setOrganizationName("GeometryFactory"); app.setApplicationName("Alpha_shape_2 demo"); - // Import resources from libCGALQt4. - // See http://doc.trolltech.com/4.4/qdir.html#Q_INIT_RESOURCE - CGAL_QT4_INIT_RESOURCES; + // Import resources from libCGAL (Qt5). + CGAL_QT_INIT_RESOURCES; MainWindow mainWindow; mainWindow.show(); diff --git a/GraphicsView/demo/Alpha_shapes_2/CMakeLists.txt b/GraphicsView/demo/Alpha_shapes_2/CMakeLists.txt index be617caf2bd..66675dd5063 100644 --- a/GraphicsView/demo/Alpha_shapes_2/CMakeLists.txt +++ b/GraphicsView/demo/Alpha_shapes_2/CMakeLists.txt @@ -3,47 +3,39 @@ project (Alpha_shapes_2_demo) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() -find_package(CGAL COMPONENTS Qt4) +find_package(CGAL COMPONENTS Qt5) include(${CGAL_USE_FILE}) -set( QT_USE_QTXML TRUE ) -set( QT_USE_QTMAIN TRUE ) -set( QT_USE_QTSCRIPT TRUE ) -set( QT_USE_QTOPENGL TRUE ) - - -find_package(Qt4) +find_package(Qt5 QUIET COMPONENTS Xml Script OpenGL Svg) include_directories (BEFORE ../../include) include_directories (BEFORE ./include) -if ( CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND ) - +if ( CGAL_FOUND AND CGAL_Qt5_FOUND AND Qt5_FOUND ) add_definitions(-DQT_NO_KEYWORDS) -include(${QT_USE_FILE}) #-------------------------------- # The "Delaunay" demo: Alpha_shapes_2 #-------------------------------- # UI files (Qt Designer files) -qt4_wrap_ui( DT_UI_FILES Alpha_shapes_2.ui ) +qt5_wrap_ui( DT_UI_FILES Alpha_shapes_2.ui ) # qrc files (resources files, that contain icons, at least) -qt4_add_resources ( DT_RESOURCE_FILES ./Alpha_shapes_2.qrc ) +qt5_add_resources ( DT_RESOURCE_FILES ./Alpha_shapes_2.qrc ) # use the Qt MOC preprocessor on classes that derives from QObject -qt4_generate_moc( Alpha_shapes_2.cpp Alpha_shapes_2.moc ) +qt5_generate_moc( Alpha_shapes_2.cpp Alpha_shapes_2.moc ) # The executable itself. add_executable ( Alpha_shapes_2 Alpha_shapes_2.cpp Alpha_shapes_2.moc ${DT_UI_FILES} ${DT_RESOURCE_FILES} ) +qt5_use_modules(Alpha_shapes_2 Xml Script OpenGL Svg) + add_to_cached_list( CGAL_EXECUTABLE_TARGETS Alpha_shapes_2 ) # Link with Qt libraries @@ -53,6 +45,6 @@ target_link_libraries( Alpha_shapes_2 ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARI else() - message(STATUS "NOTICE: This demo requires CGAL and Qt4, and will not be compiled.") + message(STATUS "NOTICE: This demo requires CGAL and Qt5, and will not be compiled.") endif() diff --git a/GraphicsView/demo/Apollonius_graph_2/Apollonius_graph_2.cpp b/GraphicsView/demo/Apollonius_graph_2/Apollonius_graph_2.cpp index b221b8a1353..06b6664a0d2 100644 --- a/GraphicsView/demo/Apollonius_graph_2/Apollonius_graph_2.cpp +++ b/GraphicsView/demo/Apollonius_graph_2/Apollonius_graph_2.cpp @@ -151,7 +151,7 @@ MainWindow::processInput(CGAL::Object o) /* * Qt Automatic Connections - * http://doc.trolltech.com/4.4/designer-using-a-component.html#automatic-connections + * http://doc.qt.io/qt-5/designer-using-a-ui-file.html#automatic-connections * * setupUi(this) generates connections to the slots named * "on__" @@ -176,15 +176,16 @@ MainWindow::on_actionInsertRandomPoints_triggered() CGAL::Random_points_in_iso_rectangle_2 pg((isor.min)(), (isor.max)()); bool ok = false; + const int number_of_points = - QInputDialog::getInteger(this, + QInputDialog::getInt(this, tr("Number of random points"), tr("Enter number of random points"), - 100, - 0, - (std::numeric_limits::max)(), - 1, - &ok); + 100, + 0, + (std::numeric_limits::max)(), + 1, + &ok); if(!ok) { return; @@ -282,9 +283,9 @@ int main(int argc, char **argv) app.setOrganizationName("GeometryFactory"); app.setApplicationName("Apollonius_graph_2 demo"); - // Import resources from libCGALQt4. - // See http://doc.trolltech.com/4.4/qdir.html#Q_INIT_RESOURCE - CGAL_QT4_INIT_RESOURCES; + // Import resources from libCGAL (Qt5). + // See http://doc.qt.io/qt-5/qdir.html#Q_INIT_RESOURCE + CGAL_QT_INIT_RESOURCES; Q_INIT_RESOURCE(Apollonius_graph_2); MainWindow mainWindow; diff --git a/GraphicsView/demo/Apollonius_graph_2/CMakeLists.txt b/GraphicsView/demo/Apollonius_graph_2/CMakeLists.txt index 17bd71f7d57..4b6589baba5 100644 --- a/GraphicsView/demo/Apollonius_graph_2/CMakeLists.txt +++ b/GraphicsView/demo/Apollonius_graph_2/CMakeLists.txt @@ -3,45 +3,37 @@ project (Apollonius_graph_2_demo) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() -find_package(CGAL COMPONENTS Qt4) +find_package(CGAL COMPONENTS Qt5) include(${CGAL_USE_FILE}) -set( QT_USE_QTXML TRUE ) -set( QT_USE_QTMAIN TRUE ) -set( QT_USE_QTSCRIPT TRUE ) -set( QT_USE_QTOPENGL TRUE ) - - -find_package(Qt4) +find_package(Qt5 QUIET COMPONENTS Xml Script OpenGL Svg) include_directories (BEFORE ../../include) -if ( CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND ) - +if ( CGAL_FOUND AND CGAL_Qt5_FOUND AND Qt5_FOUND ) add_definitions(-DQT_NO_KEYWORDS) -include(${QT_USE_FILE}) #-------------------------------- # UI files (Qt Designer files) -qt4_wrap_ui( DT_UI_FILES Apollonius_graph_2.ui ) +qt5_wrap_ui( DT_UI_FILES Apollonius_graph_2.ui ) # qrc files (resources files, that contain icons, at least) -qt4_add_resources ( DT_RESOURCE_FILES ./Apollonius_graph_2.qrc ) +qt5_add_resources ( DT_RESOURCE_FILES ./Apollonius_graph_2.qrc ) # use the Qt MOC preprocessor on classes that derives from QObject -qt4_generate_moc( Apollonius_graph_2.cpp Apollonius_graph_2.moc ) +qt5_generate_moc( Apollonius_graph_2.cpp Apollonius_graph_2.moc ) # The executable itself. add_executable ( Apollonius_graph_2 Apollonius_graph_2.cpp Apollonius_graph_2.moc ${DT_UI_FILES} ${DT_RESOURCE_FILES} ) +qt5_use_modules(Apollonius_graph_2 Xml Script OpenGL Svg) + add_to_cached_list( CGAL_EXECUTABLE_TARGETS Apollonius_graph_2 ) # Link with Qt libraries @@ -51,6 +43,6 @@ target_link_libraries( Apollonius_graph_2 ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIB else() - message(STATUS "NOTICE: This demo requires CGAL and Qt4, and will not be compiled.") + message(STATUS "NOTICE: This demo requires CGAL and Qt5, and will not be compiled.") endif() diff --git a/GraphicsView/demo/Bounding_volumes/Bounding_volumes.cpp b/GraphicsView/demo/Bounding_volumes/Bounding_volumes.cpp index 05357565da4..884029f3b5d 100644 --- a/GraphicsView/demo/Bounding_volumes/Bounding_volumes.cpp +++ b/GraphicsView/demo/Bounding_volumes/Bounding_volumes.cpp @@ -350,7 +350,7 @@ MainWindow::processInput(CGAL::Object o) /* * Qt Automatic Connections - * http://doc.trolltech.com/4.4/designer-using-a-component.html#automatic-connections + * http://doc.qt.io/qt-5/designer-using-a-ui-file.html#automatic-connections * * setupUi(this) generates connections to the slots named * "on__" @@ -435,8 +435,9 @@ MainWindow::on_actionInsertRandomPoints_triggered() Iso_rectangle_2 isor = convert(rect); CGAL::Random_points_in_iso_rectangle_2 pg((isor.min)(), (isor.max)()); bool ok = false; + const int number_of_points = - QInputDialog::getInteger(this, + QInputDialog::getInt(this, tr("Number of random points"), tr("Enter number of random points"), 100, @@ -539,9 +540,9 @@ int main(int argc, char **argv) app.setOrganizationName("GeometryFactory"); app.setApplicationName("Bounding_volumes demo"); - // Import resources from libCGALQt4. - // See http://doc.trolltech.com/4.4/qdir.html#Q_INIT_RESOURCE - CGAL_QT4_INIT_RESOURCES; + // Import resources from libCGAL (Qt5). + // See http://doc.qt.io/qt-5/qdir.html#Q_INIT_RESOURCE + CGAL_QT_INIT_RESOURCES; MainWindow mainWindow; mainWindow.show(); diff --git a/GraphicsView/demo/Bounding_volumes/CMakeLists.txt b/GraphicsView/demo/Bounding_volumes/CMakeLists.txt index 00945777ec1..94b21534a5e 100644 --- a/GraphicsView/demo/Bounding_volumes/CMakeLists.txt +++ b/GraphicsView/demo/Bounding_volumes/CMakeLists.txt @@ -3,49 +3,42 @@ project (Bounding_volumes) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() -find_package(CGAL COMPONENTS Qt4) +find_package(CGAL COMPONENTS Qt5) include(${CGAL_USE_FILE}) -set( QT_USE_QTXML TRUE ) -set( QT_USE_QTMAIN TRUE ) -set( QT_USE_QTSCRIPT TRUE ) -set( QT_USE_QTOPENGL TRUE ) - - -find_package(Qt4) +find_package(Qt5 QUIET COMPONENTS Xml Script OpenGL Svg) include_directories (BEFORE ../../include) include_directories (BEFORE ./include) include_directories (BEFORE ../../../Matrix_search/include) -if ( CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND ) +if ( CGAL_FOUND AND CGAL_Qt5_FOUND AND Qt5_FOUND ) add_definitions(-DQT_NO_KEYWORDS) -include(${QT_USE_FILE}) #---------------------------------------------- # The "Bounding volumes" demo: Bounding_volumes #---------------------------------------------- # UI files (Qt Designer files) -qt4_wrap_ui( DT_UI_FILES Bounding_volumes.ui ) +qt5_wrap_ui( DT_UI_FILES Bounding_volumes.ui ) # qrc files (resources files, that contain icons, at least) -qt4_add_resources ( DT_RESOURCE_FILES ./Bounding_volumes.qrc ) +qt5_add_resources ( DT_RESOURCE_FILES ./Bounding_volumes.qrc ) # use the Qt MOC preprocessor on classes that derives from QObject -qt4_generate_moc( "Bounding_volumes.cpp" "${CMAKE_CURRENT_BINARY_DIR}/Bounding_volumes.moc" ) +qt5_generate_moc( "Bounding_volumes.cpp" "${CMAKE_CURRENT_BINARY_DIR}/Bounding_volumes.moc" ) # The executable itself. add_executable ( Bounding_volumes Bounding_volumes.cpp Bounding_volumes.moc ${DT_UI_FILES} ${DT_RESOURCE_FILES} ) +qt5_use_modules(Bounding_volumes Xml Script OpenGL Svg) + add_to_cached_list( CGAL_EXECUTABLE_TARGETS Bounding_volumes ) # Link with Qt libraries @@ -55,6 +48,6 @@ target_link_libraries( Bounding_volumes ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRA else() - message(STATUS "NOTICE: This demo requires CGAL and Qt4, and will not be compiled.") + message(STATUS "NOTICE: This demo requires CGAL and Qt5, and will not be compiled.") endif() diff --git a/GraphicsView/demo/Circular_kernel_2/CMakeLists.txt b/GraphicsView/demo/Circular_kernel_2/CMakeLists.txt index 977ed6477a1..14de363998b 100644 --- a/GraphicsView/demo/Circular_kernel_2/CMakeLists.txt +++ b/GraphicsView/demo/Circular_kernel_2/CMakeLists.txt @@ -3,46 +3,42 @@ project (Circular_kernel_2) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() -find_package(CGAL COMPONENTS Qt4) +find_package(CGAL COMPONENTS Qt5) include(${CGAL_USE_FILE}) -set( QT_USE_QTXML TRUE ) -set( QT_USE_QTMAIN TRUE ) -set( QT_USE_QTSCRIPT TRUE ) -set( QT_USE_QTOPENGL TRUE ) -find_package(Qt4) +find_package(Qt5 QUIET COMPONENTS Xml Script OpenGL Svg) include_directories (BEFORE ../../include) -if ( CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND ) +if ( CGAL_FOUND AND CGAL_Qt5_FOUND AND Qt5_FOUND ) add_definitions(-DQT_NO_KEYWORDS) - include(${QT_USE_FILE}) + #-------------------------------- # The demo: Circular_kernel_2 #-------------------------------- # UI files (Qt Designer files) - qt4_wrap_ui( DT_UI_FILES Circular_kernel_2.ui ) + qt5_wrap_ui( DT_UI_FILES Circular_kernel_2.ui ) # qrc files (resources files, that contain icons, at least) - qt4_add_resources ( DT_RESOURCE_FILES ./Circular_kernel_2.qrc ) + qt5_add_resources ( DT_RESOURCE_FILES ./Circular_kernel_2.qrc ) # use the Qt MOC preprocessor on classes that derives from QObject - qt4_generate_moc( "Circular_kernel_2.cpp" "${CMAKE_CURRENT_BINARY_DIR}/Circular_kernel_2.moc" ) + qt5_generate_moc( "Circular_kernel_2.cpp" "${CMAKE_CURRENT_BINARY_DIR}/Circular_kernel_2.moc" ) # The executable itself. add_executable ( Circular_kernel_2 Circular_kernel_2.cpp Circular_kernel_2.moc ${DT_UI_FILES} ${DT_RESOURCE_FILES} ) + qt5_use_modules(Circular_kernel_2 Xml Script OpenGL Svg) + add_to_cached_list( CGAL_EXECUTABLE_TARGETS Circular_kernel_2 ) # Link with Qt libraries @@ -52,6 +48,6 @@ if ( CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND ) else() - message(STATUS "NOTICE: This demo requires CGAL and Qt4, and will not be compiled.") + message(STATUS "NOTICE: This demo requires CGAL and Qt5, and will not be compiled.") endif() diff --git a/GraphicsView/demo/Circular_kernel_2/Circular_kernel_2.cpp b/GraphicsView/demo/Circular_kernel_2/Circular_kernel_2.cpp index 6573f638dcc..8ccfb5b7316 100644 --- a/GraphicsView/demo/Circular_kernel_2/Circular_kernel_2.cpp +++ b/GraphicsView/demo/Circular_kernel_2/Circular_kernel_2.cpp @@ -181,7 +181,7 @@ MainWindow::processInput(CGAL::Object o) /* * Qt Automatic Connections - * http://doc.trolltech.com/4.4/designer-using-a-component.html#automatic-connections + * http://doc.qt.io/qt-5/designer-using-a-ui-file.html#automatic-connections * * setupUi(this) generates connections to the slots named * "on__" @@ -287,9 +287,8 @@ int main(int argc, char **argv) app.setOrganizationName("GeometryFactory"); app.setApplicationName("Circular_kernel_2 demo"); - // Import resources from libCGALQt4. - // See http://doc.trolltech.com/4.4/qdir.html#Q_INIT_RESOURCE - CGAL_QT4_INIT_RESOURCES; + // Import resources from libCGAL (Qt5). + CGAL_QT_INIT_RESOURCES; MainWindow mainWindow; mainWindow.show(); diff --git a/GraphicsView/demo/Generator/CMakeLists.txt b/GraphicsView/demo/Generator/CMakeLists.txt index 6ede8178306..03ecc8f3945 100644 --- a/GraphicsView/demo/Generator/CMakeLists.txt +++ b/GraphicsView/demo/Generator/CMakeLists.txt @@ -3,44 +3,39 @@ project (GeneratorDemo) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() -find_package(CGAL COMPONENTS Qt4) +find_package(CGAL COMPONENTS Qt5) include(${CGAL_USE_FILE}) -set( QT_USE_QTXML TRUE ) -set( QT_USE_QTMAIN TRUE ) -set( QT_USE_QTSCRIPT TRUE ) -set( QT_USE_QTOPENGL TRUE ) - -find_package(Qt4) +find_package(Qt5 QUIET COMPONENTS Xml Script OpenGL Svg) include_directories (BEFORE ../../include) -if ( CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND ) +if ( CGAL_FOUND AND CGAL_Qt5_FOUND AND Qt5_FOUND ) + add_definitions(-DQT_NO_KEYWORDS) - include(${QT_USE_FILE}) #-------------------------------- # Demo: Generator_2 #-------------------------------- # UI files (Qt Designer files) - qt4_wrap_ui( DT_UI_FILES Generator_2.ui ) + qt5_wrap_ui( DT_UI_FILES Generator_2.ui ) # qrc files (resources files, that contain icons, at least) - qt4_add_resources ( DT_RESOURCE_FILES ./Generator_2.qrc ) + qt5_add_resources ( DT_RESOURCE_FILES ./Generator_2.qrc ) # use the Qt MOC preprocessor on classes that derives from QObject - qt4_generate_moc( "Generator_2.cpp" "${CMAKE_CURRENT_BINARY_DIR}/Generator_2.moc" ) + qt5_generate_moc( "Generator_2.cpp" "${CMAKE_CURRENT_BINARY_DIR}/Generator_2.moc" ) # The executable itself. add_executable ( Generator_2 Generator_2.cpp Generator_2.moc ${DT_UI_FILES} ${DT_RESOURCE_FILES} ) + qt5_use_modules(Generator_2 Xml Script OpenGL Svg) + add_to_cached_list( CGAL_EXECUTABLE_TARGETS Generator_2 ) # Link with Qt libraries @@ -50,6 +45,6 @@ if ( CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND ) else() - message(STATUS "NOTICE: This demo requires CGAL, and Qt4, and will not be compiled.") + message(STATUS "NOTICE: This demo requires CGAL, and Qt5, and will not be compiled.") endif() diff --git a/GraphicsView/demo/Generator/Generator_2.cpp b/GraphicsView/demo/Generator/Generator_2.cpp index ad98f65649f..586c9033f7a 100644 --- a/GraphicsView/demo/Generator/Generator_2.cpp +++ b/GraphicsView/demo/Generator/Generator_2.cpp @@ -13,6 +13,7 @@ // Qt headers #include #include +#include #include #include @@ -65,8 +66,9 @@ private: G pg(radius); bool ok = false; - const int number_of_points = - QInputDialog::getInteger(this, + + const int number_of_points = + QInputDialog::getInt(this, tr("Number of random points"), tr("Enter number of random points"), 100, @@ -170,7 +172,7 @@ MainWindow::MainWindow() /* * Qt Automatic Connections - * http://doc.trolltech.com/4.4/designer-using-a-component.html#automatic-connections + * http://doc.qt.io/qt-5/designer-using-a-ui-file.html#automatic-connections * * setupUi(this) generates connections to the slots named * "on__" @@ -283,7 +285,7 @@ MainWindow::on_actionGeneratePolytopeInDisc_triggered() //G pg(radius); bool ok = false; const int number_of_points = - QInputDialog::getInteger(this, + QInputDialog::getInt(this, tr("Number of random points in the disc"), tr("Enter number of random points.\nThe polytope will be the convex hull of these points."), 100, @@ -336,9 +338,9 @@ int main(int argc, char **argv) app.setOrganizationName("GeometryFactory"); app.setApplicationName("Generator_2 demo"); - // Import resources from libCGALQt4. - // See http://doc.trolltech.com/4.4/qdir.html#Q_INIT_RESOURCE - CGAL_QT4_INIT_RESOURCES; + // Import resources from libCGAL (Qt5). + // See http://doc.qt.io/qt-5/qdir.html#Q_INIT_RESOURCE + CGAL_QT_INIT_RESOURCES; Q_INIT_RESOURCE(Generator_2); MainWindow mainWindow; diff --git a/GraphicsView/demo/GraphicsView/CMakeLists.txt b/GraphicsView/demo/GraphicsView/CMakeLists.txt index 714965b9ab3..2012948280f 100644 --- a/GraphicsView/demo/GraphicsView/CMakeLists.txt +++ b/GraphicsView/demo/GraphicsView/CMakeLists.txt @@ -2,34 +2,25 @@ project (GraphicsView) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() -find_package(CGAL COMPONENTS Qt4) +find_package(CGAL COMPONENTS Qt5) include(${CGAL_USE_FILE}) +find_package(Qt5 QUIET COMPONENTS Xml Script OpenGL Svg) -set( QT_USE_QTXML TRUE ) -set( QT_USE_QTMAIN TRUE ) -set( QT_USE_QTSCRIPT TRUE ) -set( QT_USE_QTOPENGL TRUE ) - -find_package(Qt4) - -if ( CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND ) +if ( CGAL_FOUND AND CGAL_Qt5_FOUND AND Qt5_FOUND ) add_definitions(-DQT_NO_KEYWORDS) - include(${QT_USE_FILE}) - - add_executable ( min min.cpp ) + qt5_use_modules(min Xml Script OpenGL Svg) + add_to_cached_list( CGAL_EXECUTABLE_TARGETS min ) # Link with Qt libraries @@ -39,6 +30,6 @@ if ( CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND ) else() - message(STATUS "NOTICE: This demo requires CGAL and Qt4, and will not be compiled.") + message(STATUS "NOTICE: This demo requires CGAL and Qt5, and will not be compiled.") endif() diff --git a/GraphicsView/demo/GraphicsView/min.cpp b/GraphicsView/demo/GraphicsView/min.cpp index 67e8663355a..7258214a21f 100644 --- a/GraphicsView/demo/GraphicsView/min.cpp +++ b/GraphicsView/demo/GraphicsView/min.cpp @@ -4,6 +4,9 @@ #include #include #include +#include +#include +#include int main(int argc, char **argv) { diff --git a/GraphicsView/demo/L1_Voronoi_diagram_2/CMakeLists.txt b/GraphicsView/demo/L1_Voronoi_diagram_2/CMakeLists.txt index b15405f3758..1a41c660c21 100644 --- a/GraphicsView/demo/L1_Voronoi_diagram_2/CMakeLists.txt +++ b/GraphicsView/demo/L1_Voronoi_diagram_2/CMakeLists.txt @@ -3,48 +3,41 @@ project (L1_voronoi_diagram_2) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() -find_package(CGAL COMPONENTS Qt4) +find_package(CGAL COMPONENTS Qt5) include(${CGAL_USE_FILE}) -set( QT_USE_QTXML TRUE ) -set( QT_USE_QTMAIN TRUE ) -set( QT_USE_QTSCRIPT TRUE ) -set( QT_USE_QTOPENGL TRUE ) - - -find_package(Qt4) +find_package(Qt5 QUIET COMPONENTS Xml Script OpenGL Svg) include_directories (BEFORE ../../include) include_directories (BEFORE ./include) -if ( CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND ) +if ( CGAL_FOUND AND CGAL_Qt5_FOUND AND Qt5_FOUND ) add_definitions(-DQT_NO_KEYWORDS) -include(${QT_USE_FILE}) #-------------------------------- # The "L1 Voronoi diagram" demo: L1_voronoi_diagram_2 #-------------------------------- # UI files (Qt Designer files) -qt4_wrap_ui( DT_UI_FILES L1_voronoi_diagram_2.ui ) +qt5_wrap_ui( DT_UI_FILES L1_voronoi_diagram_2.ui ) # qrc files (resources files, that contain icons, at least) -qt4_add_resources ( DT_RESOURCE_FILES ./L1_voronoi_diagram_2.qrc ) +qt5_add_resources ( DT_RESOURCE_FILES ./L1_voronoi_diagram_2.qrc ) # use the Qt MOC preprocessor on classes that derives from QObject -qt4_generate_moc( L1_voronoi_diagram_2.cpp L1_voronoi_diagram_2.moc ) +qt5_generate_moc( L1_voronoi_diagram_2.cpp L1_voronoi_diagram_2.moc ) # The executable itself. add_executable ( L1_voronoi_diagram_2 L1_voronoi_diagram_2.cpp L1_voronoi_diagram_2.moc ${DT_UI_FILES} ${DT_RESOURCE_FILES} ) +qt5_use_modules(L1_voronoi_diagram_2 Xml Script OpenGL Svg) + add_to_cached_list( CGAL_EXECUTABLE_TARGETS L1_voronoi_diagram_2 ) # Link with Qt libraries @@ -54,6 +47,6 @@ target_link_libraries( L1_voronoi_diagram_2 ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_L else() - message(STATUS "NOTICE: This demo requires CGAL and Qt4, and will not be compiled.") + message(STATUS "NOTICE: This demo requires CGAL and Qt5, and will not be compiled.") endif() diff --git a/GraphicsView/demo/L1_Voronoi_diagram_2/L1_voronoi_diagram_2.cpp b/GraphicsView/demo/L1_Voronoi_diagram_2/L1_voronoi_diagram_2.cpp index a5b36f6814d..ce35c9fc222 100644 --- a/GraphicsView/demo/L1_Voronoi_diagram_2/L1_voronoi_diagram_2.cpp +++ b/GraphicsView/demo/L1_Voronoi_diagram_2/L1_voronoi_diagram_2.cpp @@ -213,7 +213,7 @@ MainWindow::processInput(CGAL::Object o) /* * Qt Automatic Connections - * http://doc.trolltech.com/4.4/designer-using-a-component.html#automatic-connections + * http://doc.qt.io/qt-5/designer-using-a-ui-file.html#automatic-connections * * setupUi(this) generates connections to the slots named * "on__" @@ -245,8 +245,9 @@ MainWindow::on_actionInsertRandomPoints_triggered() Iso_rectangle_2 isor = convert(rect); CGAL::Random_points_in_iso_rectangle_2 pg((isor.min)(), (isor.max)()); bool ok = false; + const int number_of_points = - QInputDialog::getInteger(this, + QInputDialog::getInt(this, tr("Number of random points"), tr("Enter number of random points"), 100, @@ -385,9 +386,9 @@ int main(int argc, char **argv) app.setOrganizationName("GeometryFactory"); app.setApplicationName("L1 Voronoi diagram_2 demo"); - // Import resources from libCGALQt4. - // See http://doc.trolltech.com/4.4/qdir.html#Q_INIT_RESOURCE - CGAL_QT4_INIT_RESOURCES; + // Import resources from libCGAL (Qt5). + CGAL_QT_INIT_RESOURCES; + MainWindow mainWindow; mainWindow.show(); return app.exec(); diff --git a/GraphicsView/demo/Largest_empty_rect_2/CMakeLists.txt b/GraphicsView/demo/Largest_empty_rect_2/CMakeLists.txt index 2494b44f0fb..51ee7e854de 100644 --- a/GraphicsView/demo/Largest_empty_rect_2/CMakeLists.txt +++ b/GraphicsView/demo/Largest_empty_rect_2/CMakeLists.txt @@ -3,46 +3,40 @@ project (Largest_empty_rectangleDemo) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() -find_package(CGAL COMPONENTS Qt4) +find_package(CGAL COMPONENTS Qt5) include(${CGAL_USE_FILE}) -set( QT_USE_QTXML TRUE ) -set( QT_USE_QTMAIN TRUE ) -set( QT_USE_QTSCRIPT TRUE ) -set( QT_USE_QTOPENGL TRUE ) - -find_package(Qt4) +find_package(Qt5 QUIET COMPONENTS Xml Script OpenGL Svg) include_directories (BEFORE ../../include) -if ( CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND ) +if ( CGAL_FOUND AND CGAL_Qt5_FOUND AND Qt5_FOUND ) add_definitions(-DQT_NO_KEYWORDS) - - include(${QT_USE_FILE}) + #-------------------------------- # Demo: Largest_empty_rectangle_2 #-------------------------------- # UI files (Qt Designer files) - qt4_wrap_ui( DT_UI_FILES Largest_empty_rectangle_2.ui ) + qt5_wrap_ui( DT_UI_FILES Largest_empty_rectangle_2.ui ) # qrc files (resources files, that contain icons, at least) - qt4_add_resources ( DT_RESOURCE_FILES ./Largest_empty_rectangle_2.qrc ) + qt5_add_resources ( DT_RESOURCE_FILES ./Largest_empty_rectangle_2.qrc ) # use the Qt MOC preprocessor on classes that derives from QObject - qt4_generate_moc( Largest_empty_rectangle_2.cpp Largest_empty_rectangle_2.moc ) + qt5_generate_moc( Largest_empty_rectangle_2.cpp Largest_empty_rectangle_2.moc ) # The executable itself. add_executable ( Largest_empty_rectangle_2 Largest_empty_rectangle_2.cpp Largest_empty_rectangle_2.moc ${DT_UI_FILES} ${DT_RESOURCE_FILES} ) + qt5_use_modules(Largest_empty_rectangle_2 Xml Script OpenGL Svg) + add_to_cached_list( CGAL_EXECUTABLE_TARGETS Largest_empty_rectangle_2 ) # Link with Qt libraries @@ -52,6 +46,6 @@ if ( CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND ) else() - message(STATUS "NOTICE: This demo requires CGAL, and Qt4, and will not be compiled.") + message(STATUS "NOTICE: This demo requires CGAL, and Qt5, and will not be compiled.") endif() diff --git a/GraphicsView/demo/Largest_empty_rect_2/Largest_empty_rectangle_2.cpp b/GraphicsView/demo/Largest_empty_rect_2/Largest_empty_rectangle_2.cpp index 9bddddc22dc..2657ab97707 100644 --- a/GraphicsView/demo/Largest_empty_rect_2/Largest_empty_rectangle_2.cpp +++ b/GraphicsView/demo/Largest_empty_rect_2/Largest_empty_rectangle_2.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -60,8 +61,9 @@ private: G pg(radius); bool ok = false; + const int number_of_points = - QInputDialog::getInteger(this, + QInputDialog::getInt(this, tr("Number of random points"), tr("Enter number of random points"), 100, @@ -183,7 +185,7 @@ MainWindow::MainWindow() /* * Qt Automatic Connections - * http://doc.trolltech.com/4.4/designer-using-a-component.html#automatic-connections + * http://doc.qt.io/qt-5/designer-using-a-ui-file.html#automatic-connections * * setupUi(this) generates connections to the slots named * "on__" @@ -275,9 +277,9 @@ int main(int argc, char **argv) app.setOrganizationName("GeometryFactory"); app.setApplicationName("Largest_empty_rectangle_2 demo"); - // Import resources from libCGALQt4. - // See http://doc.trolltech.com/4.4/qdir.html#Q_INIT_RESOURCE - CGAL_QT4_INIT_RESOURCES; + // Import resources from libCGAL (Qt5). + // See http://doc.qt.io/qt-5/qdir.html#Q_INIT_RESOURCE + CGAL_QT_INIT_RESOURCES; Q_INIT_RESOURCE(Largest_empty_rectangle_2); MainWindow mainWindow; diff --git a/GraphicsView/demo/Periodic_2_triangulation_2/CMakeLists.txt b/GraphicsView/demo/Periodic_2_triangulation_2/CMakeLists.txt index 99449c6186d..cb1a4a8df9c 100644 --- a/GraphicsView/demo/Periodic_2_triangulation_2/CMakeLists.txt +++ b/GraphicsView/demo/Periodic_2_triangulation_2/CMakeLists.txt @@ -1,43 +1,36 @@ -cmake_minimum_required(VERSION 2.4.5) - project (Periodic_2_Triangulation_2_demo) -set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) - -if ( COMMAND cmake_policy ) - cmake_policy( SET CMP0003 NEW ) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() -find_package(CGAL COMPONENTS Qt4 REQUIRED) +find_package(CGAL COMPONENTS Qt5) include(${CGAL_USE_FILE}) -set( QT_USE_QTXML TRUE ) -set( QT_USE_QTMAIN TRUE ) -set( QT_USE_QTSCRIPT TRUE ) -set( QT_USE_QTOPENGL TRUE ) -find_package(Qt4) +find_package(Qt5 QUIET COMPONENTS Xml Script OpenGL Svg) include_directories (BEFORE ../../../include) include_directories (BEFORE ./include) -if ( CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND ) +if ( CGAL_FOUND AND CGAL_Qt5_FOUND AND Qt5_FOUND ) add_definitions(-DQT_NO_KEYWORDS) -include(${QT_USE_FILE}) + #-------------------------------- # The "2D Periodic triangulation" demo: Periodic_2_triangulation_2 #-------------------------------- # UI files (Qt Designer files) -qt4_wrap_ui( DT_UI_FILES Periodic_2_triangulation_2.ui ) +qt5_wrap_ui( DT_UI_FILES Periodic_2_triangulation_2.ui ) # qrc files (resources files, that contain icons, at least) -qt4_add_resources ( DT_RESOURCE_FILES ./Periodic_2_triangulation_2.qrc ) +qt5_add_resources ( DT_RESOURCE_FILES ./Periodic_2_triangulation_2.qrc ) # use the Qt MOC preprocessor on classes that derives from QObject -qt4_generate_moc( Periodic_2_Delaunay_triangulation_2.cpp Periodic_2_triangulation_2.moc ) +qt5_generate_moc( Periodic_2_Delaunay_triangulation_2.cpp Periodic_2_triangulation_2.moc ) # find header files for projects that can show them file(GLOB headers "*.h") @@ -53,6 +46,8 @@ add_executable ( Periodic_2_Delaunay_triangulation_2 ${DT_UI_FILES} ${DT_RESOURCE_FILES} ${headers} ${QT_headers} ${P2T2_headers}) +qt5_use_modules( Periodic_2_Delaunay_triangulation_2 Xml Script OpenGL Svg) + add_to_cached_list( CGAL_EXECUTABLE_TARGETS Periodic_2_Delaunay_triangulation_2 ) # Link with Qt libraries @@ -61,6 +56,6 @@ target_link_libraries( Periodic_2_Delaunay_triangulation_2 ${QT_LIBRARIES} ) target_link_libraries( Periodic_2_Delaunay_triangulation_2 ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES}) else() - message(STATUS "NOTICE: This demo requires CGAL and Qt4, and will not be compiled.") + message(STATUS "NOTICE: This demo requires CGAL and Qt5, and will not be compiled.") endif() diff --git a/GraphicsView/demo/Periodic_2_triangulation_2/Periodic_2_Delaunay_triangulation_2.cpp b/GraphicsView/demo/Periodic_2_triangulation_2/Periodic_2_Delaunay_triangulation_2.cpp index e6e1aa1a1b5..191c7f20181 100644 --- a/GraphicsView/demo/Periodic_2_triangulation_2/Periodic_2_Delaunay_triangulation_2.cpp +++ b/GraphicsView/demo/Periodic_2_triangulation_2/Periodic_2_Delaunay_triangulation_2.cpp @@ -216,7 +216,7 @@ MainWindow::processInput(CGAL::Object o) /* * Qt Automatic Connections - * http://doc.trolltech.com/4.4/designer-using-a-component.html#automatic-connections + * http://doc.qt.io/qt-5/designer-using-a-ui-file.html#automatic-connections * * setupUi(this) generates connections to the slots named * "on__" @@ -294,8 +294,9 @@ MainWindow::on_actionInsertRandomPoints_triggered() CGAL::Random_points_in_iso_rectangle_2 pg((triang.domain().min)(), (triang.domain().max)()); bool ok = false; + const int number_of_points = - QInputDialog::getInteger(this, + QInputDialog::getInt(this, tr("Number of random points"), tr("Enter number of random points"), 250, @@ -442,9 +443,9 @@ int main(int argc, char **argv) app.setOrganizationName("Nico Kruithof"); app.setApplicationName("Periodic_2_Delaunay_triangulation_2 demo"); - // Import resources from libCGALQt4. - // See http://doc.trolltech.com/4.4/qdir.html#Q_INIT_RESOURCE - CGAL_QT4_INIT_RESOURCES; + // Import resources from libCGAL (Qt5). + // See http://doc.qt.io/qt-5/qdir.html#Q_INIT_RESOURCE + CGAL_QT_INIT_RESOURCES; MainWindow mainWindow; mainWindow.show(); diff --git a/GraphicsView/demo/Polygon/CMakeLists.txt b/GraphicsView/demo/Polygon/CMakeLists.txt index 19f4b4ff5f1..bfe8288eb64 100644 --- a/GraphicsView/demo/Polygon/CMakeLists.txt +++ b/GraphicsView/demo/Polygon/CMakeLists.txt @@ -3,27 +3,20 @@ project (GraphicsView) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() -find_package(CGAL COMPONENTS Qt4 Core) +find_package(CGAL COMPONENTS Qt5 Core) include(${CGAL_USE_FILE}) -set( QT_USE_QTXML TRUE ) -set( QT_USE_QTMAIN TRUE ) -set( QT_USE_QTSCRIPT TRUE ) -set( QT_USE_QTOPENGL TRUE ) - -#find_package(Qt4) +find_package(Qt5 QUIET COMPONENTS Xml Script OpenGL Svg) include_directories (BEFORE ../../include) -if ( CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND ) +if ( CGAL_FOUND AND CGAL_Qt5_FOUND AND Qt5_FOUND ) add_definitions(-DQT_NO_KEYWORDS) @@ -31,18 +24,17 @@ if ( CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND ) add_definitions(-DCGAL_USE_CORE) endif() - include(${QT_USE_FILE}) #-------------------------------- # Demo: Polygon_2 #-------------------------------- # UI files (Qt Designer files) - qt4_wrap_ui( DT_UI_FILES Polygon_2.ui ) + qt5_wrap_ui( DT_UI_FILES Polygon_2.ui ) # qrc files (resources files, that contain icons, at least) - qt4_add_resources ( DT_RESOURCE_FILES ./Polygon_2.qrc ) + qt5_add_resources ( DT_RESOURCE_FILES ./Polygon_2.qrc ) # use the Qt MOC preprocessor on classes that derives from QObject - qt4_generate_moc( Polygon_2.cpp "${CMAKE_CURRENT_BINARY_DIR}/Polygon_2.moc" ) + qt5_generate_moc( Polygon_2.cpp "${CMAKE_CURRENT_BINARY_DIR}/Polygon_2.moc" ) # add_library( CGAL SHARED IMPORTED ) # SET_PROPERTY(TARGET CGAL PROPERTY IMPORTED_LOCATION ${CGAL_LIBRARY} ) @@ -50,6 +42,8 @@ if ( CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND ) # The executable itself. add_executable ( Polygon_2 Polygon_2.cpp Polygon_2.moc ${DT_UI_FILES} ${DT_RESOURCE_FILES} ) + qt5_use_modules(Polygon_2 Xml Script OpenGL Svg) + add_to_cached_list( CGAL_EXECUTABLE_TARGETS Polygon_2 ) @@ -60,6 +54,6 @@ if ( CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND ) else() - message(STATUS "NOTICE: This demo requires CGAL, CGAL_Core, and Qt4, and will not be compiled.") + message(STATUS "NOTICE: This demo requires CGAL, CGAL_Core, and Qt5, and will not be compiled.") endif() diff --git a/GraphicsView/demo/Polygon/Polygon_2.cpp b/GraphicsView/demo/Polygon/Polygon_2.cpp index bcba0a9a4b4..5a505d8fa2b 100644 --- a/GraphicsView/demo/Polygon/Polygon_2.cpp +++ b/GraphicsView/demo/Polygon/Polygon_2.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include // GraphicsView items and event filters (input classes) @@ -205,7 +206,7 @@ MainWindow::processInput(CGAL::Object o) /* * Qt Automatic Connections - * http://doc.trolltech.com/4.4/designer-using-a-component.html#automatic-connections + * http://doc.qt.io/qt-5/designer-using-a-ui-file.html#automatic-connections * * setupUi(this) generates connections to the slots named * "on__" @@ -571,9 +572,9 @@ int main(int argc, char **argv) app.setOrganizationName("GeometryFactory"); app.setApplicationName("Polygon_2 demo"); - // Import resources from libCGALQt4. - // See http://doc.trolltech.com/4.4/qdir.html#Q_INIT_RESOURCE - CGAL_QT4_INIT_RESOURCES; + // Import resources from libCGAL (Qt5). + // See http://doc.qt.io/qt-5/qdir.html#Q_INIT_RESOURCE + CGAL_QT_INIT_RESOURCES; Q_INIT_RESOURCE(Polygon_2); MainWindow mainWindow; diff --git a/GraphicsView/demo/Segment_Delaunay_graph_2/CMakeLists.txt b/GraphicsView/demo/Segment_Delaunay_graph_2/CMakeLists.txt index 10f8f2e8d4a..0377456c903 100644 --- a/GraphicsView/demo/Segment_Delaunay_graph_2/CMakeLists.txt +++ b/GraphicsView/demo/Segment_Delaunay_graph_2/CMakeLists.txt @@ -3,14 +3,12 @@ project (Segment_voronoi_2) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() -find_package(CGAL COMPONENTS Qt4 Core) +find_package(CGAL COMPONENTS Qt5 Core) include(${CGAL_USE_FILE}) @@ -20,32 +18,32 @@ set( QT_USE_QTSCRIPT TRUE ) set( QT_USE_QTOPENGL TRUE ) -find_package(Qt4) +find_package(Qt5 QUIET COMPONENTS Xml Script OpenGL Svg) include_directories (BEFORE ../../include) include_directories (BEFORE ./include) -if ( CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND ) +if ( CGAL_FOUND AND CGAL_Qt5_FOUND AND Qt5_FOUND ) add_definitions(-DQT_NO_KEYWORDS) -include(${QT_USE_FILE}) - #-------------------------------- # The "Segment Voronoi" demo: Segment_voronoi_2 #-------------------------------- # UI files (Qt Designer files) -qt4_wrap_ui( CDT_UI_FILES Segment_voronoi_2.ui ) +qt5_wrap_ui( CDT_UI_FILES Segment_voronoi_2.ui ) # qrc files (resources files, that contain icons, at least) -qt4_add_resources ( CDT_RESOURCE_FILES ./Segment_voronoi_2.qrc ) +qt5_add_resources ( CDT_RESOURCE_FILES ./Segment_voronoi_2.qrc ) # use the Qt MOC preprocessor on classes that derives from QObject -qt4_generate_moc( "Segment_voronoi_2.cpp" "${CMAKE_CURRENT_BINARY_DIR}/Segment_voronoi_2.moc" ) +qt5_generate_moc( "Segment_voronoi_2.cpp" "${CMAKE_CURRENT_BINARY_DIR}/Segment_voronoi_2.moc" ) # The executable itself. add_executable ( Segment_voronoi_2 Segment_voronoi_2.cpp Segment_voronoi_2.moc ${CDT_UI_FILES} ${CDT_RESOURCE_FILES} ) +qt5_use_modules(Segment_voronoi_2 Xml Script OpenGL Svg) + add_to_cached_list( CGAL_EXECUTABLE_TARGETS Segment_voronoi_2 ) # Link with Qt libraries @@ -56,6 +54,6 @@ target_link_libraries( Segment_voronoi_2 ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIB else() - message(STATUS "NOTICE: This demo requires CGAL and Qt4, and will not be compiled.") + message(STATUS "NOTICE: This demo requires CGAL and Qt5, and will not be compiled.") endif() diff --git a/GraphicsView/demo/Segment_Delaunay_graph_2/Segment_voronoi_2.cpp b/GraphicsView/demo/Segment_Delaunay_graph_2/Segment_voronoi_2.cpp index bcf645c3352..e6ccd1859e8 100644 --- a/GraphicsView/demo/Segment_Delaunay_graph_2/Segment_voronoi_2.cpp +++ b/GraphicsView/demo/Segment_Delaunay_graph_2/Segment_voronoi_2.cpp @@ -17,6 +17,8 @@ #include #include #include +#include +#include // GraphicsView items and event filters (input classes) #include @@ -210,7 +212,7 @@ MainWindow::processInput(CGAL::Object o) /* * Qt Automatic Connections - * http://doc.trolltech.com/4.4/designer-using-a-component.html#automatic-connections + * http://doc.qt.io/qt-5/designer-using-a-ui-file.html#automatic-connections * * setupUi(this) generates connections to the slots named * "on__" @@ -375,9 +377,8 @@ int main(int argc, char **argv) app.setOrganizationName("GeometryFactory"); app.setApplicationName("Segment Voronoi 2 demo"); - // Import resources from libCGALQt4. - // See http://doc.trolltech.com/4.4/qdir.html#Q_INIT_RESOURCE - CGAL_QT4_INIT_RESOURCES; + // Import resources from libCGAL (Qt5). + CGAL_QT_INIT_RESOURCES; MainWindow mainWindow; mainWindow.show(); diff --git a/GraphicsView/demo/Segment_Delaunay_graph_Linf_2/CMakeLists.txt b/GraphicsView/demo/Segment_Delaunay_graph_Linf_2/CMakeLists.txt index 4c8a57d0e15..dd00fe2349a 100644 --- a/GraphicsView/demo/Segment_Delaunay_graph_Linf_2/CMakeLists.txt +++ b/GraphicsView/demo/Segment_Delaunay_graph_Linf_2/CMakeLists.txt @@ -3,14 +3,12 @@ project (Segment_voronoi_linf_2) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() -find_package(CGAL COMPONENTS Qt4 Core) +find_package(CGAL COMPONENTS Qt5 Core) include(${CGAL_USE_FILE}) @@ -20,32 +18,32 @@ set( QT_USE_QTSCRIPT TRUE ) set( QT_USE_QTOPENGL TRUE ) -find_package(Qt4) +find_package(Qt5 QUIET COMPONENTS Xml Script OpenGL Svg) include_directories (BEFORE ../../include) include_directories (BEFORE ./include) -if ( CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND ) +if ( CGAL_FOUND AND CGAL_Qt5_FOUND AND Qt5_FOUND ) add_definitions(-DQT_NO_KEYWORDS) -include(${QT_USE_FILE}) - #-------------------------------- # The "Segment Voronoi Linf" demo: Segment_voronoi_linf_2 #-------------------------------- # UI files (Qt Designer files) -qt4_wrap_ui( CDT_UI_FILES Segment_voronoi_2.ui ) +qt5_wrap_ui( CDT_UI_FILES Segment_voronoi_2.ui ) # qrc files (resources files, that contain icons, at least) -qt4_add_resources ( CDT_RESOURCE_FILES ./Segment_voronoi_2.qrc ) +qt5_add_resources ( CDT_RESOURCE_FILES ./Segment_voronoi_2.qrc ) # use the Qt MOC preprocessor on classes that derives from QObject -qt4_generate_moc( "Segment_voronoi_linf_2.cpp" "${CMAKE_CURRENT_BINARY_DIR}/Segment_voronoi_linf_2.moc" ) +qt5_generate_moc( "Segment_voronoi_linf_2.cpp" "${CMAKE_CURRENT_BINARY_DIR}/Segment_voronoi_linf_2.moc" ) # The executable itself. add_executable ( Segment_voronoi_linf_2 Segment_voronoi_linf_2.cpp Segment_voronoi_linf_2.moc ${CDT_UI_FILES} ${CDT_RESOURCE_FILES} ) +qt5_use_modules(Segment_voronoi_linf_2 Xml Script OpenGL Svg) + add_to_cached_list( CGAL_EXECUTABLE_TARGETS Segment_voronoi_linf_2 ) # Link with Qt libraries @@ -56,6 +54,6 @@ target_link_libraries( Segment_voronoi_linf_2 ${CGAL_LIBRARIES} ${CGAL_3RD_PART else() - message(STATUS "NOTICE: This demo requires CGAL and Qt4, and will not be compiled.") + message(STATUS "NOTICE: This demo requires CGAL and Qt5, and will not be compiled.") endif() diff --git a/GraphicsView/demo/Segment_Delaunay_graph_Linf_2/Segment_voronoi_2.ui b/GraphicsView/demo/Segment_Delaunay_graph_Linf_2/Segment_voronoi_2.ui index 1c459706848..f360aa5b206 100644 --- a/GraphicsView/demo/Segment_Delaunay_graph_Linf_2/Segment_voronoi_2.ui +++ b/GraphicsView/demo/Segment_Delaunay_graph_Linf_2/Segment_voronoi_2.ui @@ -1,8 +1,9 @@ - + + GeometryFactory Segment_voronoi_2 - - + + 0 0 @@ -10,240 +11,233 @@ 600 - + CGAL Segment Voronoi Diagram - - + + :/cgal/logos/cgal_icon:/cgal/logos/cgal_icon - - - - - + + + + + Qt::StrongFocus - + Qt::ScrollBarAlwaysOn - + Qt::ScrollBarAlwaysOn - + QGraphicsView::NoAnchor - - - + + + File Tools - + TopToolBarArea - + false - - - + + + - - + + Visualization Tools - + TopToolBarArea - + false - - - - - - + + + + + - - + + 0 0 800 - 19 + 26 - - + + &File - - - - - - + + + + + + - - + + &Edit - - + + &Tools - - - - - - + + + + + - - - + + + - - + + &About - - + + About &CGAL - - + + &Quit - + Ctrl+Q - - - + + true - + false - - + + :/cgal/Input/inputPolyline.png:/cgal/Input/inputPolyline.png - + &Insert Polyline - + Insert Point or Polyline - + Left: Insert vtx | Right: Final vtx | Del: Delete vtx - - - + + + :/cgal/fileToolbar/fileNew.png:/cgal/fileToolbar/fileNew.png - + &Clear - + Ctrl+C - - + + true - + false - - + + :/cgal/Triangulation_2/Voronoi_diagram_2.png:/cgal/Triangulation_2/Voronoi_diagram_2.png - + Show &Voronoi Diagram - + Ctrl+V - + false - - - - + + + :/cgal/fileToolbar/fileOpen.png:/cgal/fileToolbar/fileOpen.png - + &Load... - + Ctrl+L - - - + + + :/cgal/fileToolbar/fileSave.png:/cgal/fileToolbar/fileSave.png - + &Save... - + Ctrl+S - - - - + + + :/cgal/Input/zoom-best-fit:/cgal/Input/zoom-best-fit - + Re&center the viewport - + Ctrl+R - - - + + true - - + + :/cgal/Actions/icons/constrained_triangulation_show_constraints.png:/cgal/Actions/icons/constrained_triangulation_show_constraints.png - + Show &constraints - + Ctrl+C - - - - - - + + + + + diff --git a/GraphicsView/demo/Segment_Delaunay_graph_Linf_2/Segment_voronoi_linf_2.cpp b/GraphicsView/demo/Segment_Delaunay_graph_Linf_2/Segment_voronoi_linf_2.cpp index e0a98921267..52bc6bbf623 100644 --- a/GraphicsView/demo/Segment_Delaunay_graph_Linf_2/Segment_voronoi_linf_2.cpp +++ b/GraphicsView/demo/Segment_Delaunay_graph_Linf_2/Segment_voronoi_linf_2.cpp @@ -17,7 +17,7 @@ #include #include #include - +#include // GraphicsView items and event filters (input classes) #include #include @@ -458,9 +458,8 @@ int main(int argc, char **argv) app.setOrganizationName("GeometryFactory"); app.setApplicationName("Segment Voronoi 2 demo"); - // Import resources from libCGALQt4. - // See http://doc.trolltech.com/4.4/qdir.html#Q_INIT_RESOURCE - CGAL_QT4_INIT_RESOURCES; + // Import resources from libCGAL (Qt5) + CGAL_QT_INIT_RESOURCES; if (argc == 2) { has_file_argument = true; diff --git a/GraphicsView/demo/Segment_Delaunay_graph_Linf_2/about_Segment_voronoi_2.html b/GraphicsView/demo/Segment_Delaunay_graph_Linf_2/about_Segment_voronoi_2.html index 51dbfb1c7c7..8bffc1eed1b 100644 --- a/GraphicsView/demo/Segment_Delaunay_graph_Linf_2/about_Segment_voronoi_2.html +++ b/GraphicsView/demo/Segment_Delaunay_graph_Linf_2/about_Segment_voronoi_2.html @@ -1,10 +1,10 @@ -

Constrained Delaunay Triangulation

-

Copyright © 2008 GeometryFactory

-

This application illustrates the 2D Constrained Delaunay +

L Infinity Segment Delaunay Graphs

+

Copyright © 2015 GeometryFactory

+

This application illustrates the 2D L infinity segment Delaunay graph. of CGAL.

-

See also the online +

See also the online manual.

diff --git a/GraphicsView/demo/Snap_rounding_2/CMakeLists.txt b/GraphicsView/demo/Snap_rounding_2/CMakeLists.txt index 529a144c2a2..da969e599d7 100644 --- a/GraphicsView/demo/Snap_rounding_2/CMakeLists.txt +++ b/GraphicsView/demo/Snap_rounding_2/CMakeLists.txt @@ -3,47 +3,39 @@ project (Snap_rounding_2_demo) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() -find_package(CGAL COMPONENTS Qt4) +find_package(CGAL COMPONENTS Qt5) include(${CGAL_USE_FILE}) -set( QT_USE_QTXML TRUE ) -set( QT_USE_QTMAIN TRUE ) -set( QT_USE_QTSCRIPT TRUE ) -set( QT_USE_QTOPENGL TRUE ) - - -find_package(Qt4) +find_package(Qt5 QUIET COMPONENTS Xml Script OpenGL Svg) include_directories (BEFORE ../../include) include_directories (BEFORE ../../../Snap_rounding_2/include) -if ( CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND ) +if ( CGAL_FOUND AND CGAL_Qt5_FOUND AND Qt5_FOUND ) add_definitions(-DQT_NO_KEYWORDS) -include(${QT_USE_FILE}) - #-------------------------------- # UI files (Qt Designer files) -qt4_wrap_ui( DT_UI_FILES Snap_rounding_2.ui ) +qt5_wrap_ui( DT_UI_FILES Snap_rounding_2.ui ) # qrc files (resources files, that contain icons, at least) -qt4_add_resources ( DT_RESOURCE_FILES ./Snap_rounding_2.qrc ) +qt5_add_resources ( DT_RESOURCE_FILES ./Snap_rounding_2.qrc ) # use the Qt MOC preprocessor on classes that derives from QObject -qt4_generate_moc( Snap_rounding_2.cpp Snap_rounding_2.moc ) +qt5_generate_moc( Snap_rounding_2.cpp Snap_rounding_2.moc ) # The executable itself. add_executable ( Snap_rounding_2 Snap_rounding_2.cpp Snap_rounding_2.moc ${DT_UI_FILES} ${DT_RESOURCE_FILES} ) +qt5_use_modules(Snap_rounding_2 Xml Script OpenGL Svg) + add_to_cached_list( CGAL_EXECUTABLE_TARGETS Snap_rounding_2 ) # Link with Qt libraries @@ -53,6 +45,6 @@ target_link_libraries( Snap_rounding_2 ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRAR else() - message(STATUS "NOTICE: This demo requires CGAL and Qt4, and will not be compiled.") + message(STATUS "NOTICE: This demo requires CGAL and Qt5, and will not be compiled.") endif() diff --git a/GraphicsView/demo/Snap_rounding_2/Snap_rounding_2.cpp b/GraphicsView/demo/Snap_rounding_2/Snap_rounding_2.cpp index 3f5943dabd5..9e46f805c4a 100644 --- a/GraphicsView/demo/Snap_rounding_2/Snap_rounding_2.cpp +++ b/GraphicsView/demo/Snap_rounding_2/Snap_rounding_2.cpp @@ -198,7 +198,7 @@ MainWindow::processInput(CGAL::Object o) /* * Qt Automatic Connections - * http://doc.trolltech.com/4.4/designer-using-a-component.html#automatic-connections + * http://doc.qt.io/qt-5/designer-using-a-ui-file.html#automatic-connections * * setupUi(this) generates connections to the slots named * "on__" @@ -306,9 +306,9 @@ int main(int argc, char **argv) app.setOrganizationName("GeometryFactory"); app.setApplicationName("Snap_rounding_2 demo"); - // Import resources from libCGALQt4. - // See http://doc.trolltech.com/4.4/qdir.html#Q_INIT_RESOURCE - CGAL_QT4_INIT_RESOURCES; + // Import resources from libCGAL (Qt5). + // See http://doc.qt.io/qt-5/qdir.html#Q_INIT_RESOURCE + CGAL_QT_INIT_RESOURCES; Q_INIT_RESOURCE(Snap_rounding_2); MainWindow mainWindow; diff --git a/GraphicsView/demo/Spatial_searching_2/CMakeLists.txt b/GraphicsView/demo/Spatial_searching_2/CMakeLists.txt index 81bc8e1153e..f23272aebbd 100644 --- a/GraphicsView/demo/Spatial_searching_2/CMakeLists.txt +++ b/GraphicsView/demo/Spatial_searching_2/CMakeLists.txt @@ -3,47 +3,41 @@ project (Spatial_searchingDemo) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() -find_package(CGAL COMPONENTS Qt4) +find_package(CGAL COMPONENTS Qt5) include(${CGAL_USE_FILE}) -set( QT_USE_QTXML TRUE ) -set( QT_USE_QTMAIN TRUE ) -set( QT_USE_QTSCRIPT TRUE ) -set( QT_USE_QTOPENGL TRUE ) - -find_package(Qt4) +find_package(Qt5 QUIET COMPONENTS Xml Script OpenGL Svg) include_directories (BEFORE ../../include) include_directories (BEFORE ../../../Spatial_searching/include) -if ( CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND ) +if ( CGAL_FOUND AND CGAL_Qt5_FOUND AND Qt5_FOUND ) add_definitions(-DQT_NO_KEYWORDS) - include(${QT_USE_FILE}) #-------------------------------- # Demo: Spatial_searching_2 #-------------------------------- # UI files (Qt Designer files) - qt4_wrap_ui( DT_UI_FILES Spatial_searching_2.ui ) + qt5_wrap_ui( DT_UI_FILES Spatial_searching_2.ui ) # qrc files (resources files, that contain icons, at least) - qt4_add_resources ( DT_RESOURCE_FILES ./Spatial_searching_2.qrc ) + qt5_add_resources ( DT_RESOURCE_FILES ./Spatial_searching_2.qrc ) # use the Qt MOC preprocessor on classes that derives from QObject - qt4_generate_moc( Spatial_searching_2.cpp Spatial_searching_2.moc ) + qt5_generate_moc( Spatial_searching_2.cpp Spatial_searching_2.moc ) # The executable itself. add_executable ( Spatial_searching_2 Spatial_searching_2.cpp Spatial_searching_2.moc ${DT_UI_FILES} ${DT_RESOURCE_FILES} ) + qt5_use_modules(Spatial_searching_2 Xml Script OpenGL Svg) + add_to_cached_list( CGAL_EXECUTABLE_TARGETS Spatial_searching_2 ) # Link with Qt libraries @@ -53,6 +47,6 @@ if ( CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND ) else() - message(STATUS "NOTICE: This demo requires CGAL, and Qt4, and will not be compiled.") + message(STATUS "NOTICE: This demo requires CGAL, and Qt5, and will not be compiled.") endif() diff --git a/GraphicsView/demo/Spatial_searching_2/Spatial_searching_2.cpp b/GraphicsView/demo/Spatial_searching_2/Spatial_searching_2.cpp index 9036d2753d8..b5ed84b1500 100644 --- a/GraphicsView/demo/Spatial_searching_2/Spatial_searching_2.cpp +++ b/GraphicsView/demo/Spatial_searching_2/Spatial_searching_2.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include // GraphicsView items and event filters (input classes) @@ -66,8 +67,9 @@ public: G pg(radius); bool ok = false; + const int number_of_points = - QInputDialog::getInteger(this, + QInputDialog::getInt(this, tr("Number of random points"), tr("Enter number of random points"), 100, @@ -186,7 +188,7 @@ void MainWindow::N_changed(int i) /* * Qt Automatic Connections - * http://doc.trolltech.com/4.4/designer-using-a-component.html#automatic-connections + * http://doc.qt.io/qt-5/designer-using-a-ui-file.html#automatic-connections * * setupUi(this) generates connections to the slots named * "on__" @@ -288,9 +290,9 @@ int main(int argc, char **argv) app.setOrganizationName("GeometryFactory"); app.setApplicationName("Spatial_searching_2 demo"); - // Import resources from libCGALQt4. - // See http://doc.trolltech.com/4.4/qdir.html#Q_INIT_RESOURCE - CGAL_QT4_INIT_RESOURCES; + // Import resources from libCGAL (Qt5). + // See http://doc.qt.io/qt-5/qdir.html#Q_INIT_RESOURCE + CGAL_QT_INIT_RESOURCES; Q_INIT_RESOURCE(Spatial_searching_2); MainWindow mainWindow; diff --git a/GraphicsView/demo/Stream_lines_2/CMakeLists.txt b/GraphicsView/demo/Stream_lines_2/CMakeLists.txt index 3261850b5c2..7c3524889f6 100644 --- a/GraphicsView/demo/Stream_lines_2/CMakeLists.txt +++ b/GraphicsView/demo/Stream_lines_2/CMakeLists.txt @@ -3,46 +3,40 @@ project (Stream_lines_2_demo) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() -find_package(CGAL COMPONENTS Qt4) +find_package(CGAL COMPONENTS Qt5) include(${CGAL_USE_FILE}) -set( QT_USE_QTXML TRUE ) -set( QT_USE_QTMAIN TRUE ) -set( QT_USE_QTSCRIPT TRUE ) -set( QT_USE_QTOPENGL TRUE ) - -find_package(Qt4) +find_package(Qt5 QUIET COMPONENTS Xml Script OpenGL Svg) include_directories (BEFORE ../../include) -if ( CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND ) +if ( CGAL_FOUND AND CGAL_Qt5_FOUND AND Qt5_FOUND ) add_definitions(-DQT_NO_KEYWORDS) -include(${QT_USE_FILE}) #-------------------------------- # UI files (Qt Designer files) -qt4_wrap_ui( DT_UI_FILES Stream_lines_2.ui ) +qt5_wrap_ui( DT_UI_FILES Stream_lines_2.ui ) # qrc files (resources files, that contain icons, at least) -qt4_add_resources ( DT_RESOURCE_FILES ./Stream_lines_2.qrc ) +qt5_add_resources ( DT_RESOURCE_FILES ./Stream_lines_2.qrc ) # use the Qt MOC preprocessor on classes that derives from QObject -qt4_generate_moc( Stream_lines_2.cpp Stream_lines_2.moc ) +qt5_generate_moc( Stream_lines_2.cpp Stream_lines_2.moc ) # The executable itself. add_executable ( Stream_lines_2 Stream_lines_2.cpp Stream_lines_2.moc ${DT_UI_FILES} ${DT_RESOURCE_FILES} ) +qt5_use_modules(Stream_lines_2 Xml Script OpenGL Svg) + add_to_cached_list( CGAL_EXECUTABLE_TARGETS Stream_lines_2 ) # Link with Qt libraries @@ -52,6 +46,6 @@ target_link_libraries( Stream_lines_2 ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARI else() - message(STATUS "NOTICE: This demo requires CGAL and Qt4, and will not be compiled.") + message(STATUS "NOTICE: This demo requires CGAL and Qt5, and will not be compiled.") endif() diff --git a/GraphicsView/demo/Stream_lines_2/Stream_lines_2.cpp b/GraphicsView/demo/Stream_lines_2/Stream_lines_2.cpp index 8e748707168..b84e4f79aa4 100644 --- a/GraphicsView/demo/Stream_lines_2/Stream_lines_2.cpp +++ b/GraphicsView/demo/Stream_lines_2/Stream_lines_2.cpp @@ -122,7 +122,7 @@ MainWindow::MainWindow() /* * Qt Automatic Connections - * http://doc.trolltech.com/4.4/designer-using-a-component.html#automatic-connections + * http://doc.qt.io/qt-5/designer-using-a-ui-file.html#automatic-connections * * setupUi(this) generates connections to the slots named * "on__" @@ -239,9 +239,9 @@ int main(int argc, char **argv) app.setOrganizationName("GeometryFactory"); app.setApplicationName("Stream_lines_2 demo"); - // Import resources from libCGALQt4. - // See http://doc.trolltech.com/4.4/qdir.html#Q_INIT_RESOURCE - CGAL_QT4_INIT_RESOURCES; + // Import resources from libCGAL (Qt5). + // See http://doc.qt.io/qt-5/qdir.html#Q_INIT_RESOURCE + CGAL_QT_INIT_RESOURCES; Q_INIT_RESOURCE(Stream_lines_2); MainWindow mainWindow; diff --git a/GraphicsView/demo/Triangulation_2/CMakeLists.txt b/GraphicsView/demo/Triangulation_2/CMakeLists.txt index 9785d27fd23..ee7be01bc3b 100644 --- a/GraphicsView/demo/Triangulation_2/CMakeLists.txt +++ b/GraphicsView/demo/Triangulation_2/CMakeLists.txt @@ -3,24 +3,17 @@ project (Triangulation_2) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() -find_package(CGAL COMPONENTS Qt4) +find_package(CGAL COMPONENTS Qt5) include(${CGAL_USE_FILE}) -set( QT_USE_QTXML TRUE ) -set( QT_USE_QTMAIN TRUE ) -set( QT_USE_QTSCRIPT TRUE ) -set( QT_USE_QTOPENGL TRUE ) - -#find_package(Qt4) +find_package(Qt5 QUIET COMPONENTS Xml Script OpenGL Svg) include_directories (BEFORE ../../include) include_directories (BEFORE ./include) @@ -28,26 +21,29 @@ include_directories (BEFORE ../../../Number_types/include) include_directories (BEFORE ../../../Triangulation_2/include) -if ( CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND ) +if ( CGAL_FOUND AND CGAL_Qt5_FOUND AND Qt5_FOUND ) add_definitions(-DQT_NO_KEYWORDS) -include(${QT_USE_FILE}) + + #-------------------------------- # The "constrained Delaunay" demo: Constrained_Delaunay_triangulation_2 #-------------------------------- # UI files (Qt Designer files) -qt4_wrap_ui( CDT_UI_FILES Constrained_Delaunay_triangulation_2.ui ) +qt5_wrap_ui( CDT_UI_FILES Constrained_Delaunay_triangulation_2.ui ) # qrc files (resources files, that contain icons, at least) -qt4_add_resources ( CDT_RESOURCE_FILES ./Constrained_Delaunay_triangulation_2.qrc ) +qt5_add_resources ( CDT_RESOURCE_FILES ./Constrained_Delaunay_triangulation_2.qrc ) # use the Qt MOC preprocessor on classes that derives from QObject -qt4_generate_moc( "Constrained_Delaunay_triangulation_2.cpp" "${CMAKE_CURRENT_BINARY_DIR}/Constrained_Delaunay_triangulation_2.moc" ) +qt5_generate_moc( "Constrained_Delaunay_triangulation_2.cpp" "${CMAKE_CURRENT_BINARY_DIR}/Constrained_Delaunay_triangulation_2.moc" ) # The executable itself. add_executable ( Constrained_Delaunay_triangulation_2 Constrained_Delaunay_triangulation_2.cpp Constrained_Delaunay_triangulation_2.moc ${CDT_UI_FILES} ${CDT_RESOURCE_FILES} ) +qt5_use_modules(Constrained_Delaunay_triangulation_2 Xml Script OpenGL Svg) + add_to_cached_list( CGAL_EXECUTABLE_TARGETS Constrained_Delaunay_triangulation_2 ) # Link with Qt libraries @@ -59,17 +55,19 @@ target_link_libraries( Constrained_Delaunay_triangulation_2 ${CGAL_LIBRARIES} $ # The "Delaunay" demo: Delaunay_triangulation_2 #-------------------------------- # UI files (Qt Designer files) -qt4_wrap_ui( DT_UI_FILES Delaunay_triangulation_2.ui ) +qt5_wrap_ui( DT_UI_FILES Delaunay_triangulation_2.ui ) # qrc files (resources files, that contain icons, at least) -qt4_add_resources ( DT_RESOURCE_FILES ./Delaunay_triangulation_2.qrc ) +qt5_add_resources ( DT_RESOURCE_FILES ./Delaunay_triangulation_2.qrc ) # use the Qt MOC preprocessor on classes that derives from QObject -qt4_generate_moc( "Delaunay_triangulation_2.cpp" "${CMAKE_CURRENT_BINARY_DIR}/Delaunay_triangulation_2.moc" ) +qt5_generate_moc( "Delaunay_triangulation_2.cpp" "${CMAKE_CURRENT_BINARY_DIR}/Delaunay_triangulation_2.moc" ) # The executable itself. add_executable ( Delaunay_triangulation_2 Delaunay_triangulation_2.cpp Delaunay_triangulation_2.moc ${DT_UI_FILES} ${DT_RESOURCE_FILES} ) +qt5_use_modules(Delaunay_triangulation_2 Xml Script OpenGL Svg) + add_to_cached_list( CGAL_EXECUTABLE_TARGETS Delaunay_triangulation_2 ) # Link with Qt libraries @@ -81,17 +79,19 @@ target_link_libraries( Delaunay_triangulation_2 ${CGAL_LIBRARIES} ${CGAL_3RD_PAR # The "Regular" demo: Regular_triangulation_2 #-------------------------------- # UI files (Qt Designer files) -qt4_wrap_ui( DT_UI_FILES Regular_triangulation_2.ui ) +qt5_wrap_ui( DT_UI_FILES Regular_triangulation_2.ui ) # qrc files (resources files, that contain icons, at least) -qt4_add_resources ( DT_RESOURCE_FILES ./Regular_triangulation_2.qrc ) +qt5_add_resources ( DT_RESOURCE_FILES ./Regular_triangulation_2.qrc ) # use the Qt MOC preprocessor on classes that derives from QObject -qt4_generate_moc( "Regular_triangulation_2.cpp" "${CMAKE_CURRENT_BINARY_DIR}/Regular_triangulation_2.moc" ) +qt5_generate_moc( "Regular_triangulation_2.cpp" "${CMAKE_CURRENT_BINARY_DIR}/Regular_triangulation_2.moc" ) # The executable itself. add_executable ( Regular_triangulation_2 Regular_triangulation_2.cpp Regular_triangulation_2.moc ${DT_UI_FILES} ${DT_RESOURCE_FILES} ) +qt5_use_modules(Regular_triangulation_2 Xml Script OpenGL Svg) + add_to_cached_list( CGAL_EXECUTABLE_TARGETS Regular_triangulation_2 ) # Link with Qt libraries @@ -101,6 +101,6 @@ target_link_libraries( Regular_triangulation_2 ${CGAL_LIBRARIES} ${CGAL_3RD_PART else() - message(STATUS "NOTICE: This demo requires CGAL and Qt4, and will not be compiled.") + message(STATUS "NOTICE: This demo requires CGAL and Qt5, and will not be compiled.") endif() diff --git a/GraphicsView/demo/Triangulation_2/Constrained_Delaunay_triangulation_2.cpp b/GraphicsView/demo/Triangulation_2/Constrained_Delaunay_triangulation_2.cpp index 6c01499e504..63457b7b039 100644 --- a/GraphicsView/demo/Triangulation_2/Constrained_Delaunay_triangulation_2.cpp +++ b/GraphicsView/demo/Triangulation_2/Constrained_Delaunay_triangulation_2.cpp @@ -83,7 +83,7 @@ discoverInfiniteComponent(const CDT & ct) Face_handle fh = queue.front(); queue.pop_front(); fh->set_in_domain(false); - + for(int i = 0; i < 3; i++) { Face_handle fi = fh->neighbor(i); @@ -95,7 +95,7 @@ discoverInfiniteComponent(const CDT & ct) } template -void +void discoverComponents(const CDT & ct, const SeedList& seeds) { @@ -212,7 +212,7 @@ public Q_SLOTS: void on_actionShow_seeds_toggled(bool checked); void on_actionInsertPolyline_toggled(bool checked); - + void on_actionInsertSeeds_OnOff_toggled(bool checked); void on_actionCircumcenter_toggled(bool checked); @@ -267,7 +267,7 @@ MainWindow::MainWindow() QObject::connect(this, SIGNAL(changed()), dgi, SLOT(modelChanged())); - +qDebug()<<"setting des Pens"; dgi->setVerticesPen( QPen(Qt::red, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); dgi->setVoronoiPen( @@ -284,10 +284,10 @@ MainWindow::MainWindow() pi = new CGAL::Qt::GraphicsViewPolylineInput(this, &scene, 0, true); // inputs polylines which are not closed QObject::connect(pi, SIGNAL(generate(CGAL::Object)), this, SLOT(processInput(CGAL::Object))); - + tcc = new CGAL::Qt::TriangulationCircumcircle(&scene, &cdt, this); tcc->setPen(QPen(Qt::red, 0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); - + dms = new CGAL::Qt::DelaunayMeshInsertSeeds(&scene, &cdt, this);//input seeds QObject::connect(dms, SIGNAL(generate(CGAL::Object)), this, SLOT(processInput(CGAL::Object))); @@ -351,7 +351,7 @@ MainWindow::processInput(CGAL::Object o) cdt.insert(points.front()); else insert_polyline(points.begin(), points.end()); - } + } else { // Seed (from Shift + left clic) @@ -371,7 +371,7 @@ MainWindow::processInput(CGAL::Object o) /* * Qt Automatic Connections - * http://doc.trolltech.com/4.4/designer-using-a-component.html#automatic-connections + * http://doc.qt.io/qt-5/designer-using-a-ui-file.html#automatic-connections * * setupUi(this) generates connections to the slots named * "on__" @@ -777,8 +777,9 @@ MainWindow::on_actionInsertRandomPoints_triggered() Iso_rectangle_2 isor = convert(rect); CGAL::Random_points_in_iso_rectangle_2 pg((isor.min)(), (isor.max)()); bool ok = false; + const int number_of_points = - QInputDialog::getInteger(this, + QInputDialog::getInt(this, tr("Number of random points"), tr("Enter number of random points"), 100, @@ -855,9 +856,8 @@ int main(int argc, char **argv) app.setOrganizationName("GeometryFactory"); app.setApplicationName("Constrained_Delaunay_triangulation_2 demo"); - // Import resources from libCGALQt4. - // See http://doc.trolltech.com/4.4/qdir.html#Q_INIT_RESOURCE - CGAL_QT4_INIT_RESOURCES; + // Import resources from libCGAL (Qt5). + CGAL_QT_INIT_RESOURCES; MainWindow mainWindow; mainWindow.show(); diff --git a/GraphicsView/demo/Triangulation_2/Delaunay_triangulation_2.cpp b/GraphicsView/demo/Triangulation_2/Delaunay_triangulation_2.cpp index 12b6874999e..8f7ec1fe5ce 100644 --- a/GraphicsView/demo/Triangulation_2/Delaunay_triangulation_2.cpp +++ b/GraphicsView/demo/Triangulation_2/Delaunay_triangulation_2.cpp @@ -197,7 +197,7 @@ MainWindow::processInput(CGAL::Object o) /* * Qt Automatic Connections - * http://doc.trolltech.com/4.4/designer-using-a-component.html#automatic-connections + * http://doc.qt.io/qt-5/designer-using-a-ui-file.html#automatic-connections * * setupUi(this) generates connections to the slots named * "on__" @@ -281,8 +281,9 @@ MainWindow::on_actionInsertRandomPoints_triggered() Iso_rectangle_2 isor = convert(rect); CGAL::Random_points_in_iso_rectangle_2 pg((isor.min)(), (isor.max)()); bool ok = false; + const int number_of_points = - QInputDialog::getInteger(this, + QInputDialog::getInt(this, tr("Number of random points"), tr("Enter number of random points"), 100, @@ -383,9 +384,8 @@ int main(int argc, char **argv) app.setOrganizationName("GeometryFactory"); app.setApplicationName("Delaunay_triangulation_2 demo"); - // Import resources from libCGALQt4. - // See http://doc.trolltech.com/4.4/qdir.html#Q_INIT_RESOURCE - CGAL_QT4_INIT_RESOURCES; + // Import resources from libCGAL (QT5). + CGAL_QT_INIT_RESOURCES; MainWindow mainWindow; mainWindow.show(); diff --git a/GraphicsView/demo/Triangulation_2/Regular_triangulation_2.cpp b/GraphicsView/demo/Triangulation_2/Regular_triangulation_2.cpp index 131b5ad1d27..b67399a1649 100644 --- a/GraphicsView/demo/Triangulation_2/Regular_triangulation_2.cpp +++ b/GraphicsView/demo/Triangulation_2/Regular_triangulation_2.cpp @@ -168,7 +168,7 @@ MainWindow::processInput(CGAL::Object o) /* * Qt Automatic Connections - * http://doc.trolltech.com/4.4/designer-using-a-component.html#automatic-connections + * http://doc.qt.io/qt-5/designer-using-a-ui-file.html#automatic-connections * * setupUi(this) generates connections to the slots named * "on__" @@ -215,9 +215,10 @@ MainWindow::on_actionInsertRandomPoints_triggered() QRectF rect = CGAL::Qt::viewportsBbox(&scene); CGAL::Qt::Converter convert; Iso_rectangle_2 isor = convert(rect); - CGAL::Random_points_in_iso_rectangle_2 pg((isor.min)(), (isor.max)()); + CGAL::Random_points_in_iso_rectangle_2 pg((isor.min)(), (isor.max)()); + const int number_of_points = - QInputDialog::getInteger(this, + QInputDialog::getInt(this, tr("Number of random points"), tr("Enter number of random points"), 100, 0); @@ -295,9 +296,8 @@ int main(int argc, char **argv) app.setOrganizationName("GeometryFactory"); app.setApplicationName("Regular_triangulation_2 demo"); - // Import resources from libCGALQt4. - // See http://doc.trolltech.com/4.4/qdir.html#Q_INIT_RESOURCE - CGAL_QT4_INIT_RESOURCES; + // Import resources from libCGAL (Qt5). + CGAL_QT_INIT_RESOURCES; MainWindow mainWindow; mainWindow.show(); diff --git a/GraphicsView/doc/GraphicsView/GraphicsView.txt b/GraphicsView/doc/GraphicsView/GraphicsView.txt index d5f15a926a3..000358aea14 100644 --- a/GraphicsView/doc/GraphicsView/GraphicsView.txt +++ b/GraphicsView/doc/GraphicsView/GraphicsView.txt @@ -8,17 +8,17 @@ namespace CGAL { \cgalAutoToc \authors Andreas Fabri and Laurent Rineau -Qt is a Gui toolkit for +Qt is a Gui toolkit for cross-platform application development. \section GraphicsViewIntroduction Introduction This chapter describes classes that help to visualize two dimensional \cgal objects -with the Qt Graphics View Framework. +with the Qt Graphics View Framework. -This framework uses the model view paradigm. `QGraphicsItem`s are stored in a -`QGraphicsScene` -and are displayed in a `QGraphicsView`. The items +This framework uses the model view paradigm. `QGraphicsItem`s are stored in a +`QGraphicsScene` +and are displayed in a `QGraphicsView`. The items have a paint method which is called when an item is in the visible area of a view. The framework is also responsible for dispatching events from the view via the scene to the items. The framework is extensible in the sense @@ -50,14 +50,14 @@ classes that have to override member functions adhering to this naming scheme. \section GraphicsViewOverall Overall Design In \cgalFigureRef{graphicsviewuml} you see four classes depicted in grey, -that come from the %Qt Graphics View Framework. The `QGraphicsScene` -contains `QGraphicsItem`s, which get displayed in any number -of `QGraphicsView`s. The views are widgets, that is they take screen space +that come from the %Qt Graphics View Framework. The `QGraphicsScene` +contains `QGraphicsItem`s, which get displayed in any number +of `QGraphicsView`s. The views are widgets, that is they take screen space in an application. -The fourth class is the `QObject`. It plays an important role in %Qt for -event handling and memory management. First, it allows to add signals and -slots, and to connect them. Second, it allows to install event filters. +The fourth class is the `QObject`. It plays an important role in %Qt for +event handling and memory management. First, it allows to add signals and +slots, and to connect them. Second, it allows to install event filters. \cgalFigureBegin{graphicsviewuml,uml-design.png} UML Class Diagram with the %Qt classes (blue), \cgal classes for using the framework (yellow), \cgal data structures (red), and application classes (green). @@ -68,8 +68,8 @@ UML Class Diagram with the %Qt classes (blue), \cgal classes for using the frame In order to visualize for example a `CGAL::Delaunay_triangulation_2`, we provide the graphics item class `CGAL::Qt::TriangulationGraphicsItem`. It provides a `paint` method that draws the edges and vertices of a triangulation -using the drawing primitives of the `QPainter`. The color of vertices and edges, -can be chosen by setting a user defined `QPen`. +using the drawing primitives of the `QPainter`. The color of vertices and edges, +can be chosen by setting a user defined `QPen`. As this graphics item only stores a pointer to a triangulation, it must be notified about changes like the insertion of points coming from diff --git a/GraphicsView/doc/GraphicsView/PackageDescription.txt b/GraphicsView/doc/GraphicsView/PackageDescription.txt index 495f4b59b0d..e4c20c4278a 100644 --- a/GraphicsView/doc/GraphicsView/PackageDescription.txt +++ b/GraphicsView/doc/GraphicsView/PackageDescription.txt @@ -13,7 +13,7 @@ \cgalPkgPicture{detail.png} \cgalPkgSummaryBegin \cgalPkgAuthors{Andreas Fabri and Laurent Rineau} -\cgalPkgDesc{This package provides classes for displaying \cgal objects and data structures in the Qt 4 Graphics View Framework.} +\cgalPkgDesc{This package provides classes for displaying \cgal objects and data structures in the Qt 5 Graphics View Framework.} \cgalPkgManuals{Chapter_CGAL_and_the_Qt_Graphics_View_Framework,PkgGraphicsView} \cgalPkgSummaryEnd \cgalPkgShortInfoBegin @@ -26,7 +26,7 @@ This package provides some classes which allow to use \cgal classes in Qt applications which make use of the Qt Graphics +HREF="http://qt-project.org/doc/qt-5/graphicsview.html">Qt Graphics View Framework. \cgalClassifedRefPages diff --git a/GraphicsView/include/CGAL/Qt/CGAL_Qt4_config.h b/GraphicsView/include/CGAL/Qt/CGAL_Qt_config.h similarity index 76% rename from GraphicsView/include/CGAL/Qt/CGAL_Qt4_config.h rename to GraphicsView/include/CGAL/Qt/CGAL_Qt_config.h index 869c027d6a1..89e5b3b94c0 100644 --- a/GraphicsView/include/CGAL/Qt/CGAL_Qt4_config.h +++ b/GraphicsView/include/CGAL/Qt/CGAL_Qt_config.h @@ -17,20 +17,20 @@ // // Author(s) : Laurent Rineau -#ifndef CGAL_QT4_CONFIG_H -#define CGAL_QT4_CONFIG_H +#ifndef CGAL_QT_CONFIG_H +#define CGAL_QT_CONFIG_H #include -#ifdef CGAL_Qt4_DLL -# ifdef CGAL_Qt4_EXPORTS -# define CGAL_QT4_EXPORT Q_DECL_EXPORT +#if defined(CGAL_Qt5_DLL) +# if defined(CGAL_Qt5_EXPORTS) +# define CGAL_QT_EXPORT Q_DECL_EXPORT # else -# define CGAL_QT4_EXPORT Q_DECL_IMPORT +# define CGAL_QT_EXPORT Q_DECL_IMPORT # endif #else // empty definition -# define CGAL_QT4_EXPORT +# define CGAL_QT_EXPORT #endif -#endif // CGAL_QT4_CONFIG_H +#endif // CGAL_QT_CONFIG_H diff --git a/GraphicsView/include/CGAL/Qt/Converter.h b/GraphicsView/include/CGAL/Qt/Converter.h index e61564b73e9..87ec13c0bd9 100644 --- a/GraphicsView/include/CGAL/Qt/Converter.h +++ b/GraphicsView/include/CGAL/Qt/Converter.h @@ -28,7 +28,7 @@ #include #include -#include +#include #include @@ -182,6 +182,6 @@ public: }; -} // namesapce Qt +} // namespace Qt } // namespace CGAL #endif // CGAL_QT_CONVERTER_H diff --git a/GraphicsView/include/CGAL/Qt/CreateOpenGLContext.h b/GraphicsView/include/CGAL/Qt/CreateOpenGLContext.h new file mode 100644 index 00000000000..514b6e8007e --- /dev/null +++ b/GraphicsView/include/CGAL/Qt/CreateOpenGLContext.h @@ -0,0 +1,37 @@ +// Copyright (c) 2015 GeometryFactory SARL (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// +// +// Author(s) : Laurent Rineau and Maxime Gimeno +#ifndef CGAL_QT_CREATE_OPENGL_CONTEXT_H +#define CGAL_QT_CREATE_OPENGL_CONTEXT_H +#include +#include +namespace CGAL{ +namespace Qt{ +inline QGLContext* createOpenGLContext() +{ + QOpenGLContext *context = new QOpenGLContext(); + QSurfaceFormat format; + format.setVersion(3,3); + format.setProfile(QSurfaceFormat::CompatibilityProfile); + context->setFormat(format); + return QGLContext::fromOpenGLContext(context); +} +} // namespace Qt +} // namespace CGAL +#endif diff --git a/GraphicsView/include/CGAL/Qt/DelaunayMeshTriangulationGraphicsItem.h b/GraphicsView/include/CGAL/Qt/DelaunayMeshTriangulationGraphicsItem.h index 6afc3f47906..ad649c0b186 100644 --- a/GraphicsView/include/CGAL/Qt/DelaunayMeshTriangulationGraphicsItem.h +++ b/GraphicsView/include/CGAL/Qt/DelaunayMeshTriangulationGraphicsItem.h @@ -224,7 +224,7 @@ DelaunayMeshTriangulationGraphicsItem::drawAll(QPainter *painter) { painter->setBrush(::Qt::NoBrush); painter->setPen(::Qt::darkGreen); -// painter->setPen(this->voronoiPen()); + //painter->setPen(this->voronoiPen()); this->painterostream = PainterOstream(painter); typedef CGAL::Cvd_cell_2 Cvd_cell; diff --git a/GraphicsView/include/CGAL/Qt/DemosMainWindow.h b/GraphicsView/include/CGAL/Qt/DemosMainWindow.h index 92fbe61dd75..ef5f0e8ee10 100644 --- a/GraphicsView/include/CGAL/Qt/DemosMainWindow.h +++ b/GraphicsView/include/CGAL/Qt/DemosMainWindow.h @@ -26,8 +26,9 @@ #include #include #include -#include -#include + +#include +#include #include // forward declaration @@ -42,7 +43,7 @@ namespace Qt { // forward declaration class GraphicsViewNavigation; -class CGAL_QT4_EXPORT DemosMainWindow : public QMainWindow +class CGAL_QT_EXPORT DemosMainWindow : public QMainWindow { Q_OBJECT @@ -75,6 +76,7 @@ private: protected: DemosMainWindow (QWidget * parent = 0, ::Qt::WindowFlags flags = 0 ); + ~DemosMainWindow(); void setupStatusBar(); void addNavigation(QGraphicsView*); void setupOptionsMenu(QMenu* menu = 0); diff --git a/GraphicsView/include/CGAL/Qt/GraphicsItem.h b/GraphicsView/include/CGAL/Qt/GraphicsItem.h index b6ddbdb806c..4a3ccdf6678 100644 --- a/GraphicsView/include/CGAL/Qt/GraphicsItem.h +++ b/GraphicsView/include/CGAL/Qt/GraphicsItem.h @@ -22,8 +22,9 @@ #ifndef CGAL_QT_GRAPHICS_ITEM_H #define CGAL_QT_GRAPHICS_ITEM_H -#include -#include +#include +#include + #include #include #ifndef Q_MOC_RUN @@ -35,12 +36,10 @@ namespace CGAL { namespace Qt { -class CGAL_QT4_EXPORT GraphicsItem : public QObject, public QGraphicsItem { +class CGAL_QT_EXPORT GraphicsItem : public QObject, public QGraphicsItem { Q_OBJECT -#if QT_VERSION >= 0x040600 - Q_INTERFACES(QGraphicsItem) -#endif + public Q_SLOTS: virtual void modelChanged() = 0; diff --git a/GraphicsView/include/CGAL/Qt/GraphicsViewInput.h b/GraphicsView/include/CGAL/Qt/GraphicsViewInput.h index b489ca4509c..a814416b6d8 100644 --- a/GraphicsView/include/CGAL/Qt/GraphicsViewInput.h +++ b/GraphicsView/include/CGAL/Qt/GraphicsViewInput.h @@ -22,8 +22,10 @@ #ifndef CGAL_QT_GRAPHICS_VIEW_INPUT_H #define CGAL_QT_GRAPHICS_VIEW_INPUT_H -#include -#include + +#include +#include + #ifndef Q_MOC_RUN # include #endif @@ -31,7 +33,7 @@ namespace CGAL { namespace Qt { -class CGAL_QT4_EXPORT GraphicsViewInput : public QObject +class CGAL_QT_EXPORT GraphicsViewInput : public QObject { Q_OBJECT diff --git a/GraphicsView/include/CGAL/Qt/GraphicsViewNavigation.h b/GraphicsView/include/CGAL/Qt/GraphicsViewNavigation.h index 90f6ec5b8c3..3e212431381 100644 --- a/GraphicsView/include/CGAL/Qt/GraphicsViewNavigation.h +++ b/GraphicsView/include/CGAL/Qt/GraphicsViewNavigation.h @@ -22,8 +22,9 @@ #ifndef CGAL_QT_GRAPHICS_VIEW_NAVIGATION_H #define CGAL_QT_GRAPHICS_VIEW_NAVIGATION_H -#include -#include +#include +#include + #include #include #include @@ -39,7 +40,7 @@ class QGraphicsRectItem; namespace CGAL { namespace Qt { -class CGAL_QT4_EXPORT GraphicsViewNavigation: public QObject { +class CGAL_QT_EXPORT GraphicsViewNavigation: public QObject { Q_OBJECT diff --git a/GraphicsView/include/CGAL/Qt/GraphicsViewPolylineInput.h b/GraphicsView/include/CGAL/Qt/GraphicsViewPolylineInput.h index 730cdac1ab5..0b48d7bd5b2 100644 --- a/GraphicsView/include/CGAL/Qt/GraphicsViewPolylineInput.h +++ b/GraphicsView/include/CGAL/Qt/GraphicsViewPolylineInput.h @@ -22,13 +22,15 @@ #ifndef CGAL_QT_GRAPHICS_VIEW_POLYLINE_INPUT_H #define CGAL_QT_GRAPHICS_VIEW_POLYLINE_INPUT_H -#include -#include +#include +#include + #include #include #include #include +#include class QGraphicsScene; class QGraphicsSceneMouseEvent; @@ -41,7 +43,7 @@ class QObject; namespace CGAL { namespace Qt { -class CGAL_QT4_EXPORT GraphicsViewPolylineInput_non_templated_base : public GraphicsViewInput +class CGAL_QT_EXPORT GraphicsViewPolylineInput_non_templated_base : public GraphicsViewInput { public: void setNumberOfVertices(int n) diff --git a/GraphicsView/include/CGAL/Qt/PointsInKdTreeGraphicsItem.h b/GraphicsView/include/CGAL/Qt/PointsInKdTreeGraphicsItem.h index d8477ca52cf..5f18f723d50 100644 --- a/GraphicsView/include/CGAL/Qt/PointsInKdTreeGraphicsItem.h +++ b/GraphicsView/include/CGAL/Qt/PointsInKdTreeGraphicsItem.h @@ -130,9 +130,7 @@ PointsInKdTreeGraphicsItem::PointsInKdTreeGraphicsItem(KdTree * p_) } updateBoundingBox(); setZValue(3); -#if QT_VERSION >= 0x040600 setFlag(QGraphicsItem::ItemUsesExtendedStyleOption, true); -#endif } template diff --git a/GraphicsView/include/CGAL/Qt/debug.h b/GraphicsView/include/CGAL/Qt/debug.h index d886332b171..47b7c68329c 100644 --- a/GraphicsView/include/CGAL/Qt/debug.h +++ b/GraphicsView/include/CGAL/Qt/debug.h @@ -22,8 +22,9 @@ #ifndef CGAL_QT_DEBUG_H #define CGAL_QT_DEBUG_H -#include -#include +#include +#include + #include namespace CGAL { @@ -36,7 +37,7 @@ namespace Qt { * CGAL::Qt:traverse_resources(":"); // view all resources * and displays the resources tree on std::cerr. */ -CGAL_QT4_EXPORT void traverse_resources(const QString& name, +CGAL_QT_EXPORT void traverse_resources(const QString& name, const QString& dirname = QString(), int indent = 0); diff --git a/GraphicsView/include/CGAL/Qt/resources.h b/GraphicsView/include/CGAL/Qt/resources.h index 2e390d04bc3..f36d040681a 100644 --- a/GraphicsView/include/CGAL/Qt/resources.h +++ b/GraphicsView/include/CGAL/Qt/resources.h @@ -21,12 +21,12 @@ #ifndef CGAL_QT_RESOURCES_H #define CGAL_QT_RESOURCES_H -#include +#include // cannot use namespaces because of the Q_INIT_RESOURCE macro -CGAL_QT4_EXPORT void CGAL_Qt4_init_resources(); +CGAL_QT_EXPORT void CGAL_Qt_init_resources(); -#define CGAL_QT4_INIT_RESOURCES do { CGAL_Qt4_init_resources(); } while(0) +#define CGAL_QT_INIT_RESOURCES do { CGAL_Qt_init_resources(); } while(0) // The do{}while(0) trick is used to make that macro value a regular // statement and not a compound statement. diff --git a/GraphicsView/include/CGAL/Qt/utility.h b/GraphicsView/include/CGAL/Qt/utility.h index 5221beb0e75..f1e7fbf874d 100644 --- a/GraphicsView/include/CGAL/Qt/utility.h +++ b/GraphicsView/include/CGAL/Qt/utility.h @@ -24,8 +24,9 @@ #include #include -#include -#include + +#include +#include class QGraphicsScene; class QGraphicsView; @@ -33,8 +34,8 @@ class QGraphicsView; namespace CGAL { namespace Qt { -CGAL_QT4_EXPORT QRectF mapToScene(const QGraphicsView* v, const QRect rect); -CGAL_QT4_EXPORT QRectF viewportsBbox(const QGraphicsScene*); +CGAL_QT_EXPORT QRectF mapToScene(const QGraphicsView* v, const QRect rect); +CGAL_QT_EXPORT QRectF viewportsBbox(const QGraphicsScene*); } // namespace Qt } // namespace CGAL diff --git a/GraphicsView/include/CGAL/auto_link/Qt4.h b/GraphicsView/include/CGAL/auto_link/Qt.h similarity index 77% rename from GraphicsView/include/CGAL/auto_link/Qt4.h rename to GraphicsView/include/CGAL/auto_link/Qt.h index f21b81b7b49..19daa3cd1f3 100644 --- a/GraphicsView/include/CGAL/auto_link/Qt4.h +++ b/GraphicsView/include/CGAL/auto_link/Qt.h @@ -17,22 +17,24 @@ // // Author(s) : Laurent Rineau -#ifndef CGAL_AUTO_LINK_QT4_H -#define CGAL_AUTO_LINK_QT4_H +#ifndef CGAL_AUTO_LINK_QT_H +#define CGAL_AUTO_LINK_QT_H #include +#include -#ifndef CGAL_NO_AUTOLINK_QT4 -#if ( ! defined( CGAL_EXPORTS ) ) && (! defined ( CGAL_Qt4_EXPORTS ) ) +#if (! defined (CGAL_NO_AUTOLINK_QT)) +#if ( ! defined( CGAL_EXPORTS ) && (! defined ( CGAL_Qt5_EXPORTS ))) // If CGAL_EXPORTS is defined it means that we are building the CGAL -// library as a DLL. The CGAL.dll does not really depend on CGAL_Qt4, +// library as a DLL. The CGAL.dll does not really depend on CGAL_Qt, // whatever the header inclusion graph says. -#define CGAL_LIB_NAME CGAL_Qt4 +#define CGAL_LIB_NAME CGAL_Qt5 + #include #endif // CGAL_EXPORTS -#endif // CGAL_NO_AUTOLINK_QT4 +#endif // CGAL_NO_AUTOLINK_QT -#endif // CGAL_AUTO_LINK_QT4_H +#endif // CGAL_AUTO_LINK_QT_H diff --git a/GraphicsView/include/CGAL/export/Qt4.h b/GraphicsView/include/CGAL/export/Qt.h similarity index 67% rename from GraphicsView/include/CGAL/export/Qt4.h rename to GraphicsView/include/CGAL/export/Qt.h index d8ae4fd76fd..c8d987f157d 100644 --- a/GraphicsView/include/CGAL/export/Qt4.h +++ b/GraphicsView/include/CGAL/export/Qt.h @@ -17,33 +17,33 @@ // // Author(s) : Andreas Fabri -#ifndef CGAL_QT4_EXPORT_H -#define CGAL_QT4_EXPORT_H +#ifndef CGAL_QT_EXPORT_H +#define CGAL_QT_EXPORT_H #include #include #if defined(CGAL_BUILD_SHARED_LIBS) -# if defined(CGAL_Qt4_EXPORTS) // defined by CMake or in cpp files of the dll +# if defined(CGAL_Qt5_EXPORTS) // defined by CMake or in cpp files of the dll -# define CGAL_QT4_EXPORT CGAL_DLL_EXPORT -# define CGAL_QT4_EXPIMP_TEMPLATE +# define CGAL_QT_EXPORT CGAL_DLL_EXPORT +# define CGAL_QT_EXPIMP_TEMPLATE -# else // not CGAL_Qt4_EXPORTS +# else // not CGAL_Qt_EXPORTS -# define CGAL_QT4_EXPORT CGAL_DLL_IMPORT -# define CGAL_QT4_EXPIMP_TEMPLATE extern +# define CGAL_QT_EXPORT CGAL_DLL_IMPORT +# define CGAL_QT_EXPIMP_TEMPLATE extern -# endif // not CGAL_QT4_EXPORTS +# endif // not CGAL_QT_EXPORTS #else // not CGAL_BUILD_SHARED_LIBS -# define CGAL_QT4_EXPORT -# define CGAL_QT4_EXPIMP_TEMPLATE +# define CGAL_QT_EXPORT +# define CGAL_QT_EXPIMP_TEMPLATE #endif // not CGAL_BUILD_SHARED_LIBS -#endif // CGAL_QT4_EXPORT_H +#endif // CGAL_QT_EXPORT_H diff --git a/GraphicsView/package_info/GraphicsView/description.txt b/GraphicsView/package_info/GraphicsView/description.txt index 1c4fbfdbdf5..f68f59045fb 100644 --- a/GraphicsView/package_info/GraphicsView/description.txt +++ b/GraphicsView/package_info/GraphicsView/description.txt @@ -1,3 +1,3 @@ The future 2D graphics package using the GraphicsView framework -http://doc.trolltech.com/4.3/graphicsview.html +http://doc.qt.io/qt-5/graphicsview.html diff --git a/GraphicsView/src/CGAL_Qt4/CMakeLists.txt b/GraphicsView/src/CGAL_Qt4/CMakeLists.txt deleted file mode 100644 index c3ed5233c08..00000000000 --- a/GraphicsView/src/CGAL_Qt4/CMakeLists.txt +++ /dev/null @@ -1,87 +0,0 @@ -message("Configuring libCGAL_Qt4") - -set( QT_USE_QTMAIN TRUE ) -set( QT_USE_QTOPENGL TRUE ) -set( QT_USE_QTSVG TRUE ) -find_package(Qt4 QUIET) - -find_package(OpenGL QUIET ) - -if( QT4_FOUND ) - - if( OPENGL_FOUND ) - - include_directories (BEFORE ../../include) - - include(${QT_USE_FILE}) - - get_dependency_version(OPENGL) - - get_dependency_version(QT4 QT) - - if(COMMAND add_config_flag) - set( CGAL_HAS_QT4 TRUE ) - add_config_flag( CGAL_HAS_QT4 ) - endif() - - message( STATUS "OpenGL include: ${OPENGL_INCLUDE_DIR}" ) - message( STATUS "OpenGL libraries: ${OPENGL_LIBRARIES}" ) - message( STATUS "OpenGL definitions: ${OPENGL_DEFINITIONS}" ) - message( STATUS "Qt4 include: ${QT_INCLUDE_DIR}" ) - message( STATUS "Qt4 libraries: ${QT_LIBRARIES}" ) - message( STATUS "Qt4 definitions: ${QT_DEFINITIONS}" ) - message( STATUS "moc executable: ${QT_MOC_EXECUTABLE}" ) - message( STATUS "uic executable: ${QT_UIC_EXECUTABLE}" ) - - cache_set(CGAL_Qt4_3RD_PARTY_INCLUDE_DIRS ${QT_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR} ) - cache_set(CGAL_Qt4_3RD_PARTY_LIBRARIES ${QT_LIBRARIES} ${OPENGL_LIBRARIES} ) - cache_set(CGAL_Qt4_3RD_PARTY_DEFINITIONS ${QT_DEFINITIONS} ${OPENGL_DEFINITIONS} ) - - set(mocfiles "") - set(RESOURCE_FILES "") - - foreach (package ${CGAL_CONFIGURED_PACKAGES} ) - file(GLOB PACKAGE_QTMOC_FILES "${package}/src/CGAL_Qt4/*.qtmoc.cmake") - foreach(package_qtmoc_file ${PACKAGE_QTMOC_FILES}) - # includes 'moccing' for sources/headers in package + collects lists of moc-files for dependency (to properly build the lib) - include(${package_qtmoc_file}) -# message(STATUS QTMOC------------FILE: ${package_qtmoc_file}) - endforeach() - endforeach() - - foreach(mocfile ${mocfiles}) - list(APPEND additional_files ${mocfile}) - endforeach() - foreach(resfile ${RESOURCE_FILES}) - list(APPEND additional_files ${resfile}) - endforeach() - -# message(STATUS "Additional input files: ${additional_files}") - - use_essential_libs() - - include_directories( SYSTEM ${CGAL_3RD_PARTY_INCLUDE_DIRS} ${CGAL_Qt4_3RD_PARTY_INCLUDE_DIRS} ) - - link_directories ( ${CGAL_LIBRARIES_DIR} ${CGAL_3RD_PARTY_LIBRARIES_DIRS} ) - - collect_cgal_library( CGAL_Qt4 "${additional_files}") - - add_dependencies( CGAL_Qt4 CGAL ) - - target_link_libraries( CGAL_Qt4 ${CGAL_LIBRARY} ${CGAL_3RD_PARTY_LIBRARIES} ${CGAL_Qt4_3RD_PARTY_LIBRARIES} ) - - add_definitions ( ${CGAL_3RD_PARTY_DEFINITIONS} ${CGAL_Qt4_3RD_PARTY_DEFINITIONS} ) - - if($ENV{CGAL_FAKE_PUBLIC_RELEASE}) - add_definitions( -DCGAL_FAKE_PUBLIC_RELEASE ) - endif() - - message("libCGAL_Qt4 is configured") - - else() - message( STATUS "libCGAL_Qt4 needs OpenGL, cannot be configured.") - endif() - -else() - message( STATUS "libCGAL_Qt4 needs Qt4, cannot be configured.") -endif() diff --git a/GraphicsView/src/CGAL_Qt5/CMakeLists.txt b/GraphicsView/src/CGAL_Qt5/CMakeLists.txt new file mode 100644 index 00000000000..7e5c4db6fed --- /dev/null +++ b/GraphicsView/src/CGAL_Qt5/CMakeLists.txt @@ -0,0 +1,91 @@ +message("Configuring libCGAL_Qt5") + +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) +endif() + +find_package(Qt5 QUIET COMPONENTS OpenGL Svg QUIET) + +find_package(OpenGL QUIET ) + +if( Qt5_FOUND ) + + if( OPENGL_FOUND ) + + include_directories (BEFORE ../../include) + + get_dependency_version(OPENGL) + + get_dependency_version(QT5 QT) + + if(COMMAND add_config_flag) + set( CGAL_HAS_QT5 TRUE ) + add_config_flag( CGAL_HAS_QT5 ) + endif() + + get_property(QT_UIC_EXECUTABLE TARGET Qt5::uic PROPERTY LOCATION) + message( STATUS "OpenGL include: ${OPENGL_INCLUDE_DIR}" ) + message( STATUS "OpenGL libraries: ${OPENGL_LIBRARIES}" ) + message( STATUS "OpenGL definitions: ${OPENGL_DEFINITIONS}" ) + message( STATUS "Qt5Core include: ${Qt5Core_INCLUDE_DIRS}" ) + message( STATUS "Qt5 libraries: ${Qt5Core_LIBRARIES} ${Qt5Gui_LIBRARIES} ${Qt5Svg_LIBRARIES} ${Qt5OpenGL_LIBRARIES}" ) + message( STATUS "Qt5Core definitions: ${Qt5Core_DEFINITIONS}" ) + message( STATUS "moc executable: ${QT_MOC_EXECUTABLE}" ) + message( STATUS "uic executable: ${QT_UIC_EXECUTABLE}" ) + + cache_set(CGAL_Qt5_3RD_PARTY_INCLUDE_DIRS ${QT_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR} ) + cache_set(CGAL_Qt5_3RD_PARTY_LIBRARIES ${QT_LIBRARIES} ${OPENGL_LIBRARIES} ) + cache_set(CGAL_Qt5_3RD_PARTY_DEFINITIONS ${QT_DEFINITIONS} ${OPENGL_DEFINITIONS} ) + + set(mocfiles "") + set(RESOURCE_FILES "") + + foreach (package ${CGAL_CONFIGURED_PACKAGES} ) + file(GLOB PACKAGE_QTMOC_FILES "${package}/src/CGAL_Qt5/*.qtmoc.cmake") + foreach(package_qtmoc_file ${PACKAGE_QTMOC_FILES}) + # includes 'moccing' for sources/headers in package + collects lists of moc-files for dependency (to properly build the lib) + include(${package_qtmoc_file}) +# message(STATUS QTMOC------------FILE: ${package_qtmoc_file}) + endforeach() + endforeach() + + foreach(mocfile ${mocfiles}) + list(APPEND additional_files ${mocfile}) + endforeach() + foreach(resfile ${RESOURCE_FILES}) + list(APPEND additional_files ${resfile}) + endforeach() + +# message(STATUS "Additional input files: ${additional_files}") + + use_essential_libs() + + include_directories( SYSTEM ${CGAL_3RD_PARTY_INCLUDE_DIRS} ${CGAL_Qt5_3RD_PARTY_INCLUDE_DIRS} ) + + link_directories ( ${CGAL_LIBRARIES_DIR} ${CGAL_3RD_PARTY_LIBRARIES_DIRS} ) + + collect_cgal_library( CGAL_Qt5 "${additional_files}") + + qt5_use_modules(CGAL_Qt5 OpenGL Svg) + + add_dependencies( CGAL_Qt5 CGAL ) + + # CGAL_Qt5 only depends on CGAL in DEBUG, but we still link it in + # both build types. + target_link_libraries( CGAL_Qt5 CGAL ${CGAL_3RD_PARTY_LIBRARIES} ${CGAL_Qt5_3RD_PARTY_LIBRARIES} ) + + add_definitions ( ${CGAL_3RD_PARTY_DEFINITIONS} ${CGAL_Qt5_3RD_PARTY_DEFINITIONS} ) + + if($ENV{CGAL_FAKE_PUBLIC_RELEASE}) + add_definitions( -DCGAL_FAKE_PUBLIC_RELEASE ) + endif() + + message("libCGAL_Qt5 is configured") + + else() + message( STATUS "libCGAL_Qt5 needs OpenGL, cannot be configured.") + endif() + +else() + message( STATUS "libCGAL_Qt5 needs Qt5, cannot be configured.") +endif() diff --git a/GraphicsView/src/CGAL_Qt4/DemosMainWindow.cpp b/GraphicsView/src/CGAL_Qt5/DemosMainWindow.cpp similarity index 99% rename from GraphicsView/src/CGAL_Qt4/DemosMainWindow.cpp rename to GraphicsView/src/CGAL_Qt5/DemosMainWindow.cpp index 843bcd9769e..528f91d5a2f 100644 --- a/GraphicsView/src/CGAL_Qt4/DemosMainWindow.cpp +++ b/GraphicsView/src/CGAL_Qt5/DemosMainWindow.cpp @@ -38,6 +38,9 @@ #include #include #include +#include +#include + #include // needed to get CGAL_VERSION_STR #include @@ -82,6 +85,9 @@ DemosMainWindow::DemosMainWindow(QWidget * parent, ::Qt::WindowFlags flags) setAcceptDrops(true); } +DemosMainWindow::~DemosMainWindow() +{ +} void DemosMainWindow::dragEnterEvent(QDragEnterEvent *event) @@ -179,9 +185,8 @@ void DemosMainWindow::setUseAntialiasing(bool checked) { view->setRenderHint(QPainter::Antialiasing, checked); -#if QT_VERSION >= 0x040300 view->setRenderHint(QPainter::HighQualityAntialiasing, checked); -#endif + statusBar()->showMessage(tr("Antialiasing %1activated").arg(checked?"":"de-"), 1000); } diff --git a/GraphicsView/src/CGAL_Qt4/GraphicsView.qtmoc.cmake b/GraphicsView/src/CGAL_Qt5/GraphicsView.qtmoc.cmake similarity index 74% rename from GraphicsView/src/CGAL_Qt4/GraphicsView.qtmoc.cmake rename to GraphicsView/src/CGAL_Qt5/GraphicsView.qtmoc.cmake index 784dc09897d..86b463eb977 100644 --- a/GraphicsView/src/CGAL_Qt4/GraphicsView.qtmoc.cmake +++ b/GraphicsView/src/CGAL_Qt5/GraphicsView.qtmoc.cmake @@ -1,9 +1,9 @@ # moc files that are compiled directly as cpp files -qt4_wrap_cpp(mocfiles ../../include/CGAL/Qt/GraphicsViewNavigation.h +qt5_wrap_cpp(mocfiles ../../include/CGAL/Qt/GraphicsViewNavigation.h ../../include/CGAL/Qt/DemosMainWindow.h ../../include/CGAL/Qt/GraphicsItem.h ../../include/CGAL/Qt/GraphicsViewInput.h) # qrc files (resources files, that contain icons, at least) -qt4_add_resources ( RESOURCE_FILES ../../demo/resources/CGAL.qrc ../../demo/icons/Input.qrc ../../demo/icons/File.qrc ../../demo/icons/Triangulation_2.qrc) +qt5_add_resources ( RESOURCE_FILES ../../demo/resources/CGAL.qrc ../../demo/icons/Input.qrc ../../demo/icons/File.qrc ../../demo/icons/Triangulation_2.qrc) diff --git a/GraphicsView/src/CGAL_Qt4/GraphicsViewNavigation.cpp b/GraphicsView/src/CGAL_Qt5/GraphicsViewNavigation.cpp similarity index 100% rename from GraphicsView/src/CGAL_Qt4/GraphicsViewNavigation.cpp rename to GraphicsView/src/CGAL_Qt5/GraphicsViewNavigation.cpp diff --git a/GraphicsView/src/CGAL_Qt4/GraphicsViewPolylineInput.cpp b/GraphicsView/src/CGAL_Qt5/GraphicsViewPolylineInput.cpp similarity index 100% rename from GraphicsView/src/CGAL_Qt4/GraphicsViewPolylineInput.cpp rename to GraphicsView/src/CGAL_Qt5/GraphicsViewPolylineInput.cpp diff --git a/GraphicsView/src/CGAL_Qt4/debug.cpp b/GraphicsView/src/CGAL_Qt5/debug.cpp similarity index 100% rename from GraphicsView/src/CGAL_Qt4/debug.cpp rename to GraphicsView/src/CGAL_Qt5/debug.cpp diff --git a/GraphicsView/src/CGAL_Qt4/resources.cpp b/GraphicsView/src/CGAL_Qt5/resources.cpp similarity index 96% rename from GraphicsView/src/CGAL_Qt4/resources.cpp rename to GraphicsView/src/CGAL_Qt5/resources.cpp index e15cc66b861..99ec21e6d2b 100644 --- a/GraphicsView/src/CGAL_Qt4/resources.cpp +++ b/GraphicsView/src/CGAL_Qt5/resources.cpp @@ -22,7 +22,7 @@ #include // cannot use namespaces because of the Q_INIT_RESOURCE macro -void CGAL_Qt4_init_resources() { +void CGAL_Qt_init_resources() { Q_INIT_RESOURCE(File); Q_INIT_RESOURCE(Triangulation_2); Q_INIT_RESOURCE(Input); diff --git a/GraphicsView/src/CGAL_Qt4/utility.cpp b/GraphicsView/src/CGAL_Qt5/utility.cpp similarity index 100% rename from GraphicsView/src/CGAL_Qt4/utility.cpp rename to GraphicsView/src/CGAL_Qt5/utility.cpp diff --git a/Inscribed_areas/demo/Largest_empty_rect_2/Qt3/CMakeLists.txt b/Inscribed_areas/demo/Largest_empty_rect_2/Qt3/CMakeLists.txt index ef578436c3b..b94a666e534 100644 --- a/Inscribed_areas/demo/Largest_empty_rect_2/Qt3/CMakeLists.txt +++ b/Inscribed_areas/demo/Largest_empty_rect_2/Qt3/CMakeLists.txt @@ -10,7 +10,7 @@ include( ${CGAL_USE_FILE} ) find_package(Qt3-patched) # FindQt3-patched.cmake is FindQt3.cmake patched by CGAL developers, so -# that it can be used together with FindQt4: all its variables are prefixed +# that it can be used together with Qt5: all its variables are prefixed # by "QT3_" instead of "QT_". if ( CGAL_FOUND AND CGAL_Qt3_FOUND AND QT3_FOUND ) diff --git a/Installation/CMakeLists.txt b/Installation/CMakeLists.txt index 20a5e7ca898..814c35d9d3e 100644 --- a/Installation/CMakeLists.txt +++ b/Installation/CMakeLists.txt @@ -6,27 +6,14 @@ project(CGAL CXX C) # Minimal version of CMake: -if(WIN32) - cmake_minimum_required(VERSION 2.8.6) -else() - cmake_minimum_required(VERSION 2.6.2) -endif() +cmake_minimum_required(VERSION 2.8.11) # Tested version: -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) -endif() +cmake_policy(VERSION 2.8.11) # # Compatibility with CMake 3.0 # -if(POLICY CMP0026) - # Allow the LOCATION target property - # http://www.cmake.org/cmake/help/v3.0/policy/CMP0026.html - cmake_policy(SET CMP0026 OLD) -endif() if(POLICY CMP0042) # Do not enable the use of MACOSX_RPATH # http://www.cmake.org/cmake/help/v3.0/policy/CMP0042.html @@ -539,7 +526,7 @@ endmacro() # this is the place to tell which external libs are supporting # Remarks: -# External libs Qt3 and Qt34are configured when Qt3 or Qt4 as lib of cgal are required +# External libs Qt3 and Qt34are configured when Qt3 or Qt5 as lib of cgal are required # Coin is used in KDS, but no FindCoin or FindCOIN exists # There exists FindF2C, FindIPE, FindMKL, but they are only used to support supporting libs list (INSERT CGAL_SUPPORTING_3RD_PARTY_LIBRARIES 0 GMP MPFR ZLIB OpenGL LEDA MPFI RS RS3 OpenNL Eigen3 BLAS LAPACK QGLViewer ESBTL Coin3D NTL IPE) @@ -558,7 +545,7 @@ set(SPECIAL_PREFIXES "${SPECIAL_PREFIXES}set(CGAL_EXT_LIB_${library}_PREFIX \"${ set(CGAL_EXT_LIB_${library}_PREFIX ${prefix}) endmacro() -set_special_prefix(Qt4 QT) +set_special_prefix(Qt5 QT) set_special_prefix(Eigen3 EIGEN3) set_special_prefix(QGLViewer QGLVIEWER) set_special_prefix(Coin3D COIN3D) @@ -772,7 +759,6 @@ endforeach() include_directories (${CGAL_INCLUDE_DIRS}) -cache_get(CGAL_LIBRARY) cache_get(CGAL_3RD_PARTY_PRECONFIGURED ) cache_get(CGAL_3RD_PARTY_DEFINITIONS ) @@ -828,25 +814,6 @@ if (CGAL_BRANCH_BUILD AND CGAL_REPORT_DUPLICATE_FILES ) endif() -#-------------------------------------------------------------------------------------------------- -# -# -= USER SIDE SETTINGS =- -# -#-------------------------------------------------------------------------------------------------- - -# Set CGAL_LIBRARY_INSTALLED, CGAL_Qt3_LIBRARY_INSTALLED and so on. Those -# variables are the path to the libraries installed by the install -# target. Used in the generation of the installed CGALConfig.cmake -foreach(lib ${CGAL_CONFIGURED_LIBRARIES} CGAL) # note the added fake 'CGAL' - if(${lib}_LIBRARY) - get_filename_component(lib_name "${${lib}_LIBRARY}" NAME) - set(${lib}_LIBRARY_INSTALLED "${CMAKE_INSTALL_PREFIX}/${CGAL_INSTALL_LIB_DIR}/${lib_name}") - else() - set(${lib}_LIBRARY_INSTALLED "") - endif() - hide_variable(${lib}_LIBRARY_INSTALLED) -endforeach() - create_CGALconfig_files() #-------------------------------------------------------------------------------------------------- @@ -879,7 +846,8 @@ install(PROGRAMS ${scripts} DESTINATION ${CGAL_INSTALL_BIN_DIR}) install(DIRECTORY ${CGAL_MODULES_REL_DIR}/ DESTINATION ${CGAL_INSTALL_CMAKE_DIR} ) install(FILES ${CGAL_MODULES_REL_DIR}/UseCGAL.cmake DESTINATION ${CGAL_INSTALL_CMAKE_DIR} ) - +install(EXPORT CGALExports DESTINATION ${CGAL_INSTALL_CMAKE_DIR} + NAMESPACE CGAL:: ) if ( GMP_IN_AUXILIARY ) install(DIRECTORY auxiliary/gmp/include/ DESTINATION ${CGAL_INSTALL_INC_DIR} ) diff --git a/Installation/INSTALL.md b/Installation/INSTALL.md index e0874881b0f..cc9ae038683 100644 --- a/Installation/INSTALL.md +++ b/Installation/INSTALL.md @@ -26,9 +26,8 @@ To install CGAL, you need 'cmake' and several third-party libraries. Some are essential for entire CGAL, some are mandatory for particular CGAL packages, some are only needed for demos. - * CMake (>= 2.6.3), the build system used by CGAL + * CMake (>= 2.8.11), the build system used by CGAL Required for building CGAL - On Windows, CMake >= 2.8.6 is required. * Boost (>= 1.48) Required for building CGAL and for applications using CGAL @@ -64,8 +63,8 @@ CGAL packages, some are only needed for demos. - Qt3 (>= 3.3) ftp://ftp.qt.nokia.com/qt/source/ - - Qt4 (>= 4.3) - http://qt.nokia.com/ + - Qt5 (>= 5.3) + http://qt-project.org/ - libQGLViewer http://www.libqglviewer.com/ diff --git a/Installation/LICENSE b/Installation/LICENSE index c33b0a776e5..c13ee28b449 100644 --- a/Installation/LICENSE +++ b/Installation/LICENSE @@ -6,7 +6,7 @@ an open source license. It is also possible to obtain commercial licenses from GeometryFactory (www.geometryfactory.com) for all or parts of CGAL. The source code of the CGAL library can be found in the directories -"src/CGAL", "src/CGALQt", "src/CGALQt4" and "include/CGAL" (with the +"src/CGAL", "src/CGALQt", "src/CGALQt5" and "include/CGAL" (with the exception of "include/CGAL/CORE", "include/CGAL/OpenNL"). It is specified in each file of the CGAL library which license applies to it. This is either the GNU General Public License diff --git a/Installation/cmake/modules/2.6.2-to-2.8.1/FindQt4-Copyright.txt b/Installation/cmake/modules/2.6.2-to-2.8.1/FindQt4-Copyright.txt deleted file mode 100644 index 834c45710d7..00000000000 --- a/Installation/cmake/modules/2.6.2-to-2.8.1/FindQt4-Copyright.txt +++ /dev/null @@ -1,50 +0,0 @@ -CMake was initially developed by Kitware with the following sponsorship: - - * National Library of Medicine at the National Institutes of Health - as part of the Insight Segmentation and Registration Toolkit (ITK). - - * US National Labs (Los Alamos, Livermore, Sandia) ASC Parallel - Visualization Initiative. - - * National Alliance for Medical Image Computing (NAMIC) is funded by the - National Institutes of Health through the NIH Roadmap for Medical Research, - Grant U54 EB005149. - - * Kitware, Inc. - -The CMake copyright is as follows: - -Copyright (c) 2002 Kitware, Inc., Insight Consortium -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - * The names of Kitware, Inc., the Insight Consortium, or the names of - any consortium members, or of any contributors, may not be used to - endorse or promote products derived from this software without - specific prior written permission. - - * Modified source versions must be plainly marked as such, and must - not be misrepresented as being the original software. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS'' -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -See also the CMake web site: http://www.cmake.org for more information. diff --git a/Installation/cmake/modules/2.6.2-to-2.8.1/FindQt4.cmake b/Installation/cmake/modules/2.6.2-to-2.8.1/FindQt4.cmake deleted file mode 100644 index cc7cd63c9ec..00000000000 --- a/Installation/cmake/modules/2.6.2-to-2.8.1/FindQt4.cmake +++ /dev/null @@ -1,1188 +0,0 @@ -# This file, as well as: -# Qt4ConfigDependentSettings.cmake -# Qt4Macros.cmake -# UseQt4.cmake -# come from the distribution of CMake-2.8.1, unpatched -# See FindQt4-Copyright.txt for the license of those files. -# -- Laurent Rineau, 2010/08/02 - -# - Find QT 4 -# This module can be used to find Qt4. -# The most important issue is that the Qt4 qmake is available via the system path. -# This qmake is then used to detect basically everything else. -# This module defines a number of key variables and macros. -# The variable QT_USE_FILE is set which is the path to a CMake file that can be included -# to compile Qt 4 applications and libraries. It sets up the compilation -# environment for include directories, preprocessor defines and populates a -# QT_LIBRARIES variable. -# -# Typical usage could be something like: -# find_package(Qt4 4.4.3 COMPONENTS QtCore QtGui QtXml REQUIRED ) -# include(${QT_USE_FILE}) -# add_executable(myexe main.cpp) -# target_link_libraries(myexe ${QT_LIBRARIES}) -# -# The minimum required version can be specified using the standard find_package()-syntax -# (see example above). -# For compatibility with older versions of FindQt4.cmake it is also possible to -# set the variable QT_MIN_VERSION to the minimum required version of Qt4 before the -# find_package(Qt4) command. -# If both are used, the version used in the find_package() command overrides the -# one from QT_MIN_VERSION. -# -# When using the components argument, QT_USE_QT* variables are automatically set -# for the QT_USE_FILE to pick up. If one wishes to manually set them, the -# available ones to set include: -# QT_DONT_USE_QTCORE -# QT_DONT_USE_QTGUI -# QT_USE_QT3SUPPORT -# QT_USE_QTASSISTANT -# QT_USE_QAXCONTAINER -# QT_USE_QAXSERVER -# QT_USE_QTDESIGNER -# QT_USE_QTMOTIF -# QT_USE_QTMAIN -# QT_USE_QTMULTIMEDIA -# QT_USE_QTNETWORK -# QT_USE_QTNSPLUGIN -# QT_USE_QTOPENGL -# QT_USE_QTSQL -# QT_USE_QTXML -# QT_USE_QTSVG -# QT_USE_QTTEST -# QT_USE_QTUITOOLS -# QT_USE_QTDBUS -# QT_USE_QTSCRIPT -# QT_USE_QTASSISTANTCLIENT -# QT_USE_QTHELP -# QT_USE_QTWEBKIT -# QT_USE_QTXMLPATTERNS -# QT_USE_PHONON -# QT_USE_QTSCRIPTTOOLS -# -# QT_USE_IMPORTED_TARGETS -# If this variable is set to TRUE, FindQt4.cmake will create imported -# library targets for the various Qt libraries and set the -# library variables like QT_QTCORE_LIBRARY to point at these imported -# targets instead of the library file on disk. This provides much better -# handling of the release and debug versions of the Qt libraries and is -# also always backwards compatible, except for the case that dependencies -# of libraries are exported, these will then also list the names of the -# imported targets as dependency and not the file location on disk. This -# is much more flexible, but requires that FindQt4.cmake is executed before -# such an exported dependency file is processed. -# -# There are also some files that need processing by some Qt tools such as moc -# and uic. Listed below are macros that may be used to process those files. -# -# macro QT4_WRAP_CPP(outfiles inputfile ... OPTIONS ...) -# create moc code from a list of files containing Qt class with -# the Q_OBJECT declaration. Per-direcotry preprocessor definitions -# are also added. Options may be given to moc, such as those found -# when executing "moc -help". -# -# macro QT4_WRAP_UI(outfiles inputfile ... OPTIONS ...) -# create code from a list of Qt designer ui files. -# Options may be given to uic, such as those found -# when executing "uic -help" -# -# macro QT4_ADD_RESOURCES(outfiles inputfile ... OPTIONS ...) -# create code from a list of Qt resource files. -# Options may be given to rcc, such as those found -# when executing "rcc -help" -# -# macro QT4_GENERATE_MOC(inputfile outputfile ) -# creates a rule to run moc on infile and create outfile. -# Use this if for some reason QT4_WRAP_CPP() isn't appropriate, e.g. -# because you need a custom filename for the moc file or something similar. -# -# macro QT4_AUTOMOC(sourcefile1 sourcefile2 ... ) -# This macro is still experimental. -# It can be used to have moc automatically handled. -# So if you have the files foo.h and foo.cpp, and in foo.h a -# a class uses the Q_OBJECT macro, moc has to run on it. If you don't -# want to use QT4_WRAP_CPP() (which is reliable and mature), you can insert -# #include "foo.moc" -# in foo.cpp and then give foo.cpp as argument to QT4_AUTOMOC(). This will the -# scan all listed files at cmake-time for such included moc files and if it finds -# them cause a rule to be generated to run moc at build time on the -# accompanying header file foo.h. -# If a source file has the SKIP_AUTOMOC property set it will be ignored by this macro. -# -# macro QT4_ADD_DBUS_INTERFACE(outfiles interface basename) -# create a the interface header and implementation files with the -# given basename from the given interface xml file and add it to -# the list of sources -# -# macro QT4_ADD_DBUS_INTERFACES(outfiles inputfile ... ) -# create the interface header and implementation files -# for all listed interface xml files -# the name will be automatically determined from the name of the xml file -# -# macro QT4_ADD_DBUS_ADAPTOR(outfiles xmlfile parentheader parentclassname [basename] [classname]) -# create a dbus adaptor (header and implementation file) from the xml file -# describing the interface, and add it to the list of sources. The adaptor -# forwards the calls to a parent class, defined in parentheader and named -# parentclassname. The name of the generated files will be -# adaptor.{cpp,h} where basename defaults to the basename of the xml file. -# If is provided, then it will be used as the classname of the -# adaptor itself. -# -# macro QT4_GENERATE_DBUS_INTERFACE( header [interfacename] OPTIONS ...) -# generate the xml interface file from the given header. -# If the optional argument interfacename is omitted, the name of the -# interface file is constructed from the basename of the header with -# the suffix .xml appended. -# Options may be given to qdbuscpp2xml, such as those found when executing "qdbuscpp2xml --help" -# -# macro QT4_CREATE_TRANSLATION( qm_files directories ... sources ... -# ts_files ... OPTIONS ...) -# out: qm_files -# in: directories sources ts_files -# options: flags to pass to lupdate, such as -extensions to specify -# extensions for a directory scan. -# generates commands to create .ts (vie lupdate) and .qm -# (via lrelease) - files from directories and/or sources. The ts files are -# created and/or updated in the source tree (unless given with full paths). -# The qm files are generated in the build tree. -# Updating the translations can be done by adding the qm_files -# to the source list of your library/executable, so they are -# always updated, or by adding a custom target to control when -# they get updated/generated. -# -# macro QT4_ADD_TRANSLATION( qm_files ts_files ... ) -# out: qm_files -# in: ts_files -# generates commands to create .qm from .ts - files. The generated -# filenames can be found in qm_files. The ts_files -# must exists and are not updated in any way. -# -# -# Below is a detailed list of variables that FindQt4.cmake sets. -# QT_FOUND If false, don't try to use Qt. -# QT4_FOUND If false, don't try to use Qt 4. -# -# QT_VERSION_MAJOR The major version of Qt found. -# QT_VERSION_MINOR The minor version of Qt found. -# QT_VERSION_PATCH The patch version of Qt found. -# -# QT_EDITION Set to the edition of Qt (i.e. DesktopLight) -# QT_EDITION_DESKTOPLIGHT True if QT_EDITION == DesktopLight -# QT_QTCORE_FOUND True if QtCore was found. -# QT_QTGUI_FOUND True if QtGui was found. -# QT_QT3SUPPORT_FOUND True if Qt3Support was found. -# QT_QTASSISTANT_FOUND True if QtAssistant was found. -# QT_QTASSISTANTCLIENT_FOUND True if QtAssistantClient was found. -# QT_QAXCONTAINER_FOUND True if QAxContainer was found (Windows only). -# QT_QAXSERVER_FOUND True if QAxServer was found (Windows only). -# QT_QTDBUS_FOUND True if QtDBus was found. -# QT_QTDESIGNER_FOUND True if QtDesigner was found. -# QT_QTDESIGNERCOMPONENTS True if QtDesignerComponents was found. -# QT_QTHELP_FOUND True if QtHelp was found. -# QT_QTMOTIF_FOUND True if QtMotif was found. -# QT_QTMULTIMEDIA_FOUND True if QtMultimedia was found (since Qt 4.6.0). -# QT_QTNETWORK_FOUND True if QtNetwork was found. -# QT_QTNSPLUGIN_FOUND True if QtNsPlugin was found. -# QT_QTOPENGL_FOUND True if QtOpenGL was found. -# QT_QTSQL_FOUND True if QtSql was found. -# QT_QTSVG_FOUND True if QtSvg was found. -# QT_QTSCRIPT_FOUND True if QtScript was found. -# QT_QTSCRIPTTOOLS_FOUND True if QtScriptTools was found. -# QT_QTTEST_FOUND True if QtTest was found. -# QT_QTUITOOLS_FOUND True if QtUiTools was found. -# QT_QTWEBKIT_FOUND True if QtWebKit was found. -# QT_QTXML_FOUND True if QtXml was found. -# QT_QTXMLPATTERNS_FOUND True if QtXmlPatterns was found. -# QT_PHONON_FOUND True if phonon was found. -# -# QT_MAC_USE_COCOA For Mac OS X, its whether Cocoa or Carbon is used. -# In general, this should not be used, but its useful -# when having platform specific code. -# -# QT_DEFINITIONS Definitions to use when compiling code that uses Qt. -# You do not need to use this if you include QT_USE_FILE. -# The QT_USE_FILE will also define QT_DEBUG and QT_NO_DEBUG -# to fit your current build type. Those are not contained -# in QT_DEFINITIONS. -# -# QT_INCLUDES List of paths to all include directories of -# Qt4 QT_INCLUDE_DIR and QT_QTCORE_INCLUDE_DIR are -# always in this variable even if NOTFOUND, -# all other INCLUDE_DIRS are -# only added if they are found. -# You do not need to use this if you include QT_USE_FILE. -# -# -# Include directories for the Qt modules are listed here. -# You do not need to use these variables if you include QT_USE_FILE. -# -# QT_INCLUDE_DIR Path to "include" of Qt4 -# QT_QT3SUPPORT_INCLUDE_DIR Path to "include/Qt3Support" -# QT_QTASSISTANT_INCLUDE_DIR Path to "include/QtAssistant" -# QT_QTASSISTANTCLIENT_INCLUDE_DIR Path to "include/QtAssistant" -# QT_QAXCONTAINER_INCLUDE_DIR Path to "include/ActiveQt" (Windows only) -# QT_QAXSERVER_INCLUDE_DIR Path to "include/ActiveQt" (Windows only) -# QT_QTCORE_INCLUDE_DIR Path to "include/QtCore" -# QT_QTDBUS_INCLUDE_DIR Path to "include/QtDBus" -# QT_QTDESIGNER_INCLUDE_DIR Path to "include/QtDesigner" -# QT_QTDESIGNERCOMPONENTS_INCLUDE_DIR Path to "include/QtDesigner" -# QT_QTGUI_INCLUDE_DIR Path to "include/QtGui" -# QT_QTHELP_INCLUDE_DIR Path to "include/QtHelp" -# QT_QTMOTIF_INCLUDE_DIR Path to "include/QtMotif" -# QT_QTMULTIMEDIA_INCLUDE_DIR Path to "include/QtMultimedia" -# QT_QTNETWORK_INCLUDE_DIR Path to "include/QtNetwork" -# QT_QTNSPLUGIN_INCLUDE_DIR Path to "include/QtNsPlugin" -# QT_QTOPENGL_INCLUDE_DIR Path to "include/QtOpenGL" -# QT_QTSCRIPT_INCLUDE_DIR Path to "include/QtScript" -# QT_QTSQL_INCLUDE_DIR Path to "include/QtSql" -# QT_QTSVG_INCLUDE_DIR Path to "include/QtSvg" -# QT_QTTEST_INCLUDE_DIR Path to "include/QtTest" -# QT_QTWEBKIT_INCLUDE_DIR Path to "include/QtWebKit" -# QT_QTXML_INCLUDE_DIR Path to "include/QtXml" -# QT_QTXMLPATTERNS_INCLUDE_DIR Path to "include/QtXmlPatterns" -# QT_PHONON_INCLUDE_DIR Path to "include/phonon" -# QT_QTSCRIPTTOOLS_INCLUDE_DIR Path to "include/QtScriptTools" -# -# QT_BINARY_DIR Path to "bin" of Qt4 -# QT_LIBRARY_DIR Path to "lib" of Qt4 -# QT_PLUGINS_DIR Path to "plugins" for Qt4 -# QT_TRANSLATIONS_DIR Path to "translations" of Qt4 -# QT_DOC_DIR Path to "doc" of Qt4 -# QT_MKSPECS_DIR Path to "mkspecs" of Qt4 -# -# -# The Qt toolkit may contain both debug and release libraries. -# In that case, the following library variables will contain both. -# You do not need to use these variables if you include QT_USE_FILE, -# and use QT_LIBRARIES. -# -# QT_QT3SUPPORT_LIBRARY The Qt3Support library -# QT_QTASSISTANT_LIBRARY The QtAssistant library -# QT_QTASSISTANTCLIENT_LIBRARY The QtAssistantClient library -# QT_QAXCONTAINER_LIBRARY The QAxContainer library (Windows only) -# QT_QAXSERVER_LIBRARY The QAxServer library (Windows only) -# QT_QTCORE_LIBRARY The QtCore library -# QT_QTDBUS_LIBRARY The QtDBus library -# QT_QTDESIGNER_LIBRARY The QtDesigner library -# QT_QTDESIGNERCOMPONENTS_LIBRARY The QtDesignerComponents library -# QT_QTGUI_LIBRARY The QtGui library -# QT_QTHELP_LIBRARY The QtHelp library -# QT_QTMOTIF_LIBRARY The QtMotif library -# QT_QTMULTIMEDIA_LIBRARY The QtMultimedia library -# QT_QTNETWORK_LIBRARY The QtNetwork library -# QT_QTNSPLUGIN_LIBRARY The QtNsPLugin library -# QT_QTOPENGL_LIBRARY The QtOpenGL library -# QT_QTSCRIPT_LIBRARY The QtScript library -# QT_QTSQL_LIBRARY The QtSql library -# QT_QTSVG_LIBRARY The QtSvg library -# QT_QTTEST_LIBRARY The QtTest library -# QT_QTUITOOLS_LIBRARY The QtUiTools library -# QT_QTWEBKIT_LIBRARY The QtWebKit library -# QT_QTXML_LIBRARY The QtXml library -# QT_QTXMLPATTERNS_LIBRARY The QtXmlPatterns library -# QT_QTMAIN_LIBRARY The qtmain library for Windows -# QT_PHONON_LIBRARY The phonon library -# QT_QTSCRIPTTOOLS_LIBRARY The QtScriptTools library -# -# also defined, but NOT for general use are -# QT_MOC_EXECUTABLE Where to find the moc tool. -# QT_UIC_EXECUTABLE Where to find the uic tool. -# QT_UIC3_EXECUTABLE Where to find the uic3 tool. -# QT_RCC_EXECUTABLE Where to find the rcc tool -# QT_DBUSCPP2XML_EXECUTABLE Where to find the qdbuscpp2xml tool. -# QT_DBUSXML2CPP_EXECUTABLE Where to find the qdbusxml2cpp tool. -# QT_LUPDATE_EXECUTABLE Where to find the lupdate tool. -# QT_LRELEASE_EXECUTABLE Where to find the lrelease tool. -# QT_QCOLLECTIONGENERATOR_EXECUTABLE Where to find the qcollectiongenerator tool. -# QT_DESIGNER_EXECUTABLE Where to find the Qt designer tool. -# QT_LINGUIST_EXECUTABLE Where to find the Qt linguist tool. -# -# -# These are around for backwards compatibility -# they will be set -# QT_WRAP_CPP Set true if QT_MOC_EXECUTABLE is found -# QT_WRAP_UI Set true if QT_UIC_EXECUTABLE is found -# -# These variables do _NOT_ have any effect anymore (compared to FindQt.cmake) -# QT_MT_REQUIRED Qt4 is now always multithreaded -# -# These variables are set to "" Because Qt structure changed -# (They make no sense in Qt4) -# QT_QT_LIBRARY Qt-Library is now split - -#============================================================================= -# Copyright 2005-2009 Kitware, Inc. -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distributed this file outside of CMake, substitute the full -# License text for the above reference.) - -# Use FIND_PACKAGE( Qt4 COMPONENTS ... ) to enable modules -IF( Qt4_FIND_COMPONENTS ) - FOREACH( component ${Qt4_FIND_COMPONENTS} ) - STRING( TOUPPER ${component} _COMPONENT ) - SET( QT_USE_${_COMPONENT} 1 ) - ENDFOREACH( component ) - - # To make sure we don't use QtCore or QtGui when not in COMPONENTS - IF(NOT QT_USE_QTCORE) - SET( QT_DONT_USE_QTCORE 1 ) - ENDIF(NOT QT_USE_QTCORE) - - IF(NOT QT_USE_QTGUI) - SET( QT_DONT_USE_QTGUI 1 ) - ENDIF(NOT QT_USE_QTGUI) - -ENDIF( Qt4_FIND_COMPONENTS ) - -# If Qt3 has already been found, fail. -IF(QT_QT_LIBRARY) - IF(Qt4_FIND_REQUIRED) - MESSAGE( FATAL_ERROR "Qt3 and Qt4 cannot be used together in one project. If switching to Qt4, the CMakeCache.txt needs to be cleaned.") - ELSE(Qt4_FIND_REQUIRED) - IF(NOT Qt4_FIND_QUIETLY) - MESSAGE( STATUS "Qt3 and Qt4 cannot be used together in one project. If switching to Qt4, the CMakeCache.txt needs to be cleaned.") - ENDIF(NOT Qt4_FIND_QUIETLY) - RETURN() - ENDIF(Qt4_FIND_REQUIRED) -ENDIF(QT_QT_LIBRARY) - - -INCLUDE(CheckSymbolExists) -INCLUDE(MacroAddFileDependencies) - -SET(QT_USE_FILE ${CMAKE_ROOT}/Modules/UseQt4.cmake) - -SET( QT_DEFINITIONS "") - -SET(QT4_INSTALLED_VERSION_TOO_OLD FALSE) - -# macro for asking qmake to process pro files -MACRO(QT_QUERY_QMAKE outvar invar) - IF(QT_QMAKE_EXECUTABLE) - FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmpQmake/tmp.pro - "message(CMAKE_MESSAGE<$$${invar}>)") - - # Invoke qmake with the tmp.pro program to get the desired - # information. Use the same variable for both stdout and stderr - # to make sure we get the output on all platforms. - EXECUTE_PROCESS(COMMAND ${QT_QMAKE_EXECUTABLE} - WORKING_DIRECTORY - ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmpQmake - OUTPUT_VARIABLE _qmake_query_output - RESULT_VARIABLE _qmake_result - ERROR_VARIABLE _qmake_query_output ) - - FILE(REMOVE_RECURSE - "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmpQmake") - - IF(_qmake_result) - MESSAGE(WARNING " querying qmake for ${invar}. qmake reported:\n${_qmake_query_output}") - ELSE(_qmake_result) - STRING(REGEX REPLACE ".*CMAKE_MESSAGE<([^>]*).*" "\\1" ${outvar} "${_qmake_query_output}") - ENDIF(_qmake_result) - - ENDIF(QT_QMAKE_EXECUTABLE) -ENDMACRO(QT_QUERY_QMAKE) - -GET_FILENAME_COMPONENT(qt_install_version "[HKEY_CURRENT_USER\\Software\\trolltech\\Versions;DefaultQtVersion]" NAME) -# check for qmake -# Debian uses qmake-qt4 -# macports' Qt uses qmake-mac -FIND_PROGRAM(QT_QMAKE_EXECUTABLE NAMES qmake qmake4 qmake-qt4 qmake-mac PATHS - "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\4.0.0;InstallDir]/bin" - "[HKEY_CURRENT_USER\\Software\\Trolltech\\Versions\\4.0.0;InstallDir]/bin" - "[HKEY_CURRENT_USER\\Software\\Trolltech\\Versions\\${qt_install_version};InstallDir]/bin" - $ENV{QTDIR}/bin -) - -IF (QT_QMAKE_EXECUTABLE) - - IF(QT_QMAKE_EXECUTABLE_LAST) - STRING(COMPARE NOTEQUAL "${QT_QMAKE_EXECUTABLE_LAST}" "${QT_QMAKE_EXECUTABLE}" QT_QMAKE_CHANGED) - ENDIF(QT_QMAKE_EXECUTABLE_LAST) - - SET(QT_QMAKE_EXECUTABLE_LAST "${QT_QMAKE_EXECUTABLE}" CACHE INTERNAL "" FORCE) - - SET(QT4_QMAKE_FOUND FALSE) - - EXEC_PROGRAM(${QT_QMAKE_EXECUTABLE} ARGS "-query QT_VERSION" OUTPUT_VARIABLE QTVERSION) - - # check for qt3 qmake and then try and find qmake4 or qmake-qt4 in the path - IF("${QTVERSION}" MATCHES "Unknown") - SET(QT_QMAKE_EXECUTABLE NOTFOUND CACHE FILEPATH "" FORCE) - FIND_PROGRAM(QT_QMAKE_EXECUTABLE NAMES qmake4 qmake-qt4 PATHS - "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\4.0.0;InstallDir]/bin" - "[HKEY_CURRENT_USER\\Software\\Trolltech\\Versions\\4.0.0;InstallDir]/bin" - $ENV{QTDIR}/bin - ) - IF(QT_QMAKE_EXECUTABLE) - EXEC_PROGRAM(${QT_QMAKE_EXECUTABLE} - ARGS "-query QT_VERSION" OUTPUT_VARIABLE QTVERSION) - ENDIF(QT_QMAKE_EXECUTABLE) - ENDIF("${QTVERSION}" MATCHES "Unknown") - - # check that we found the Qt4 qmake, Qt3 qmake output won't match here - STRING(REGEX MATCH "^[0-9]+\\.[0-9]+\\.[0-9]+" qt_version_tmp "${QTVERSION}") - IF (qt_version_tmp) - - # we need at least version 4.0.0 - IF (NOT QT_MIN_VERSION) - SET(QT_MIN_VERSION "4.0.0") - ENDIF (NOT QT_MIN_VERSION) - - #now parse the parts of the user given version string into variables - STRING(REGEX MATCH "^[0-9]+\\.[0-9]+\\.[0-9]+" req_qt_major_vers "${QT_MIN_VERSION}") - IF (NOT req_qt_major_vers) - MESSAGE( FATAL_ERROR "Invalid Qt version string given: \"${QT_MIN_VERSION}\", expected e.g. \"4.0.1\"") - ENDIF (NOT req_qt_major_vers) - - # now parse the parts of the user given version string into variables - STRING(REGEX REPLACE "^([0-9]+)\\.[0-9]+\\.[0-9]+" "\\1" req_qt_major_vers "${QT_MIN_VERSION}") - STRING(REGEX REPLACE "^[0-9]+\\.([0-9])+\\.[0-9]+" "\\1" req_qt_minor_vers "${QT_MIN_VERSION}") - STRING(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" req_qt_patch_vers "${QT_MIN_VERSION}") - - # Suppport finding at least a particular version, for instance FIND_PACKAGE( Qt4 4.4.3 ) - # This implementation is a hack to avoid duplicating code and make sure we stay - # source-compatible with CMake 2.6.x - IF( Qt4_FIND_VERSION ) - SET( QT_MIN_VERSION ${Qt4_FIND_VERSION} ) - SET( req_qt_major_vers ${Qt4_FIND_VERSION_MAJOR} ) - SET( req_qt_minor_vers ${Qt4_FIND_VERSION_MINOR} ) - SET( req_qt_patch_vers ${Qt4_FIND_VERSION_PATCH} ) - ENDIF( Qt4_FIND_VERSION ) - - IF (NOT req_qt_major_vers EQUAL 4) - MESSAGE( FATAL_ERROR "Invalid Qt version string given: \"${QT_MIN_VERSION}\", major version 4 is required, e.g. \"4.0.1\"") - ENDIF (NOT req_qt_major_vers EQUAL 4) - - # and now the version string given by qmake - STRING(REGEX REPLACE "^([0-9]+)\\.[0-9]+\\.[0-9]+.*" "\\1" QT_VERSION_MAJOR "${QTVERSION}") - STRING(REGEX REPLACE "^[0-9]+\\.([0-9])+\\.[0-9]+.*" "\\1" QT_VERSION_MINOR "${QTVERSION}") - STRING(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" QT_VERSION_PATCH "${QTVERSION}") - - # compute an overall version number which can be compared at once - MATH(EXPR req_vers "${req_qt_major_vers}*10000 + ${req_qt_minor_vers}*100 + ${req_qt_patch_vers}") - MATH(EXPR found_vers "${QT_VERSION_MAJOR}*10000 + ${QT_VERSION_MINOR}*100 + ${QT_VERSION_PATCH}") - - # Support finding *exactly* a particular version, for instance FIND_PACKAGE( Qt4 4.4.3 EXACT ) - IF( Qt4_FIND_VERSION_EXACT ) - IF(found_vers EQUAL req_vers) - SET( QT4_QMAKE_FOUND TRUE ) - ELSE(found_vers EQUAL req_vers) - SET( QT4_QMAKE_FOUND FALSE ) - IF (found_vers LESS req_vers) - SET(QT4_INSTALLED_VERSION_TOO_OLD TRUE) - ELSE (found_vers LESS req_vers) - SET(QT4_INSTALLED_VERSION_TOO_NEW TRUE) - ENDIF (found_vers LESS req_vers) - ENDIF(found_vers EQUAL req_vers) - ELSE( Qt4_FIND_VERSION_EXACT ) - IF (found_vers LESS req_vers) - SET(QT4_QMAKE_FOUND FALSE) - SET(QT4_INSTALLED_VERSION_TOO_OLD TRUE) - ELSE (found_vers LESS req_vers) - SET(QT4_QMAKE_FOUND TRUE) - ENDIF (found_vers LESS req_vers) - ENDIF( Qt4_FIND_VERSION_EXACT ) - ENDIF (qt_version_tmp) - -ENDIF (QT_QMAKE_EXECUTABLE) - -IF (QT4_QMAKE_FOUND) - - # ask qmake for the library dir - # Set QT_LIBRARY_DIR - IF (NOT QT_LIBRARY_DIR OR QT_QMAKE_CHANGED) - EXEC_PROGRAM( ${QT_QMAKE_EXECUTABLE} - ARGS "-query QT_INSTALL_LIBS" - OUTPUT_VARIABLE QT_LIBRARY_DIR_TMP ) - # make sure we have / and not \ as qmake gives on windows - FILE(TO_CMAKE_PATH "${QT_LIBRARY_DIR_TMP}" QT_LIBRARY_DIR_TMP) - IF(EXISTS "${QT_LIBRARY_DIR_TMP}") - SET(QT_LIBRARY_DIR ${QT_LIBRARY_DIR_TMP} CACHE PATH "Qt library dir" FORCE) - ELSE(EXISTS "${QT_LIBRARY_DIR_TMP}") - MESSAGE("Warning: QT_QMAKE_EXECUTABLE reported QT_INSTALL_LIBS as ${QT_LIBRARY_DIR_TMP}") - MESSAGE("Warning: ${QT_LIBRARY_DIR_TMP} does NOT exist, Qt must NOT be installed correctly.") - ENDIF(EXISTS "${QT_LIBRARY_DIR_TMP}") - ENDIF(NOT QT_LIBRARY_DIR OR QT_QMAKE_CHANGED) - - IF (APPLE) - IF (EXISTS ${QT_LIBRARY_DIR}/QtCore.framework) - SET(QT_USE_FRAMEWORKS ON - CACHE BOOL "Set to ON if Qt build uses frameworks." FORCE) - ELSE (EXISTS ${QT_LIBRARY_DIR}/QtCore.framework) - SET(QT_USE_FRAMEWORKS OFF - CACHE BOOL "Set to ON if Qt build uses frameworks." FORCE) - ENDIF (EXISTS ${QT_LIBRARY_DIR}/QtCore.framework) - - MARK_AS_ADVANCED(QT_USE_FRAMEWORKS) - ENDIF (APPLE) - - # ask qmake for the binary dir - IF (QT_LIBRARY_DIR AND NOT QT_BINARY_DIR OR QT_QMAKE_CHANGED) - EXEC_PROGRAM(${QT_QMAKE_EXECUTABLE} - ARGS "-query QT_INSTALL_BINS" - OUTPUT_VARIABLE qt_bins ) - # make sure we have / and not \ as qmake gives on windows - FILE(TO_CMAKE_PATH "${qt_bins}" qt_bins) - SET(QT_BINARY_DIR ${qt_bins} CACHE INTERNAL "" FORCE) - ENDIF (QT_LIBRARY_DIR AND NOT QT_BINARY_DIR OR QT_QMAKE_CHANGED) - - # ask qmake for the include dir - IF (QT_LIBRARY_DIR AND NOT QT_HEADERS_DIR OR QT_QMAKE_CHANGED) - EXEC_PROGRAM( ${QT_QMAKE_EXECUTABLE} - ARGS "-query QT_INSTALL_HEADERS" - OUTPUT_VARIABLE qt_headers ) - # make sure we have / and not \ as qmake gives on windows - FILE(TO_CMAKE_PATH "${qt_headers}" qt_headers) - SET(QT_HEADERS_DIR ${qt_headers} CACHE INTERNAL "" FORCE) - ENDIF (QT_LIBRARY_DIR AND NOT QT_HEADERS_DIR OR QT_QMAKE_CHANGED) - - - # ask qmake for the documentation directory - IF (QT_LIBRARY_DIR AND NOT QT_DOC_DIR OR QT_QMAKE_CHANGED) - EXEC_PROGRAM( ${QT_QMAKE_EXECUTABLE} - ARGS "-query QT_INSTALL_DOCS" - OUTPUT_VARIABLE qt_doc_dir ) - # make sure we have / and not \ as qmake gives on windows - FILE(TO_CMAKE_PATH "${qt_doc_dir}" qt_doc_dir) - SET(QT_DOC_DIR ${qt_doc_dir} CACHE PATH "The location of the Qt docs" FORCE) - ENDIF (QT_LIBRARY_DIR AND NOT QT_DOC_DIR OR QT_QMAKE_CHANGED) - - # ask qmake for the mkspecs directory - IF (QT_LIBRARY_DIR AND NOT QT_MKSPECS_DIR OR QT_QMAKE_CHANGED) - EXEC_PROGRAM( ${QT_QMAKE_EXECUTABLE} - ARGS "-query QMAKE_MKSPECS" - OUTPUT_VARIABLE qt_mkspecs_dirs ) - # do not replace : on windows as it might be a drive letter - # and windows should already use ; as a separator - IF(UNIX) - STRING(REPLACE ":" ";" qt_mkspecs_dirs "${qt_mkspecs_dirs}") - ENDIF(UNIX) - SET(QT_MKSPECS_DIR NOTFOUND) - FIND_PATH(QT_MKSPECS_DIR qconfig.pri PATHS ${qt_mkspecs_dirs} - DOC "The location of the Qt mkspecs containing qconfig.pri" - NO_DEFAULT_PATH ) - ENDIF (QT_LIBRARY_DIR AND NOT QT_MKSPECS_DIR OR QT_QMAKE_CHANGED) - - # ask qmake for the plugins directory - IF (QT_LIBRARY_DIR AND NOT QT_PLUGINS_DIR OR QT_QMAKE_CHANGED) - EXEC_PROGRAM( ${QT_QMAKE_EXECUTABLE} - ARGS "-query QT_INSTALL_PLUGINS" - OUTPUT_VARIABLE qt_plugins_dir ) - # make sure we have / and not \ as qmake gives on windows - FILE(TO_CMAKE_PATH "${qt_plugins_dir}" qt_plugins_dir) - SET(QT_PLUGINS_DIR ${qt_plugins_dir} CACHE PATH "The location of the Qt plugins" FORCE) - ENDIF (QT_LIBRARY_DIR AND NOT QT_PLUGINS_DIR OR QT_QMAKE_CHANGED) - - # ask qmake for the translations directory - IF (QT_LIBRARY_DIR AND NOT QT_TRANSLATIONS_DIR OR QT_QMAKE_CHANGED) - EXEC_PROGRAM( ${QT_QMAKE_EXECUTABLE} - ARGS "-query QT_INSTALL_TRANSLATIONS" - OUTPUT_VARIABLE qt_translations_dir ) - # make sure we have / and not \ as qmake gives on windows - FILE(TO_CMAKE_PATH "${qt_translations_dir}" qt_translations_dir) - SET(QT_TRANSLATIONS_DIR ${qt_translations_dir} CACHE PATH "The location of the Qt translations" FORCE) - ENDIF (QT_LIBRARY_DIR AND NOT QT_TRANSLATIONS_DIR OR QT_QMAKE_CHANGED) - - # Make variables changeble to the advanced user - MARK_AS_ADVANCED( QT_LIBRARY_DIR QT_DOC_DIR QT_MKSPECS_DIR - QT_PLUGINS_DIR QT_TRANSLATIONS_DIR) - - - ############################################# - # - # Find out what window system we're using - # - ############################################# - # Save required variable - SET(CMAKE_REQUIRED_INCLUDES_SAVE ${CMAKE_REQUIRED_INCLUDES}) - SET(CMAKE_REQUIRED_FLAGS_SAVE ${CMAKE_REQUIRED_FLAGS}) - # Add QT_INCLUDE_DIR to CMAKE_REQUIRED_INCLUDES - SET(CMAKE_REQUIRED_INCLUDES "${CMAKE_REQUIRED_INCLUDES};${QT_HEADERS_DIR}") - # On Mac OS X when Qt has framework support, also add the framework path - IF( QT_USE_FRAMEWORKS ) - SET(CMAKE_REQUIRED_FLAGS "-F${QT_LIBRARY_DIR} ") - ENDIF( QT_USE_FRAMEWORKS ) - # Check for Window system symbols (note: only one should end up being set) - CHECK_SYMBOL_EXISTS(Q_WS_X11 "QtCore/qglobal.h" Q_WS_X11) - CHECK_SYMBOL_EXISTS(Q_WS_WIN "QtCore/qglobal.h" Q_WS_WIN) - CHECK_SYMBOL_EXISTS(Q_WS_QWS "QtCore/qglobal.h" Q_WS_QWS) - CHECK_SYMBOL_EXISTS(Q_WS_MAC "QtCore/qglobal.h" Q_WS_MAC) - IF(Q_WS_MAC) - IF(QT_QMAKE_CHANGED) - UNSET(QT_MAC_USE_COCOA CACHE) - ENDIF(QT_QMAKE_CHANGED) - CHECK_SYMBOL_EXISTS(QT_MAC_USE_COCOA "QtCore/qconfig.h" QT_MAC_USE_COCOA) - ENDIF(Q_WS_MAC) - - IF (QT_QTCOPY_REQUIRED) - CHECK_SYMBOL_EXISTS(QT_IS_QTCOPY "QtCore/qglobal.h" QT_KDE_QT_COPY) - IF (NOT QT_IS_QTCOPY) - MESSAGE(FATAL_ERROR "qt-copy is required, but hasn't been found") - ENDIF (NOT QT_IS_QTCOPY) - ENDIF (QT_QTCOPY_REQUIRED) - - # Restore CMAKE_REQUIRED_INCLUDES and CMAKE_REQUIRED_FLAGS variables - SET(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_SAVE}) - SET(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE}) - # - ############################################# - - - - ######################################## - # - # Setting the INCLUDE-Variables - # - ######################################## - - SET(QT_MODULES QtCore QtGui Qt3Support QtSvg QtScript QtTest QtUiTools - QtHelp QtWebKit QtXmlPatterns phonon QtNetwork QtMultimedia - QtNsPlugin QtOpenGL QtSql QtXml QtDesigner QtDBus QtScriptTools) - - IF(Q_WS_X11) - SET(QT_MODULES ${QT_MODULES} QtMotif) - ENDIF(Q_WS_X11) - - IF(QT_QMAKE_CHANGED) - FOREACH(QT_MODULE ${QT_MODULES}) - STRING(TOUPPER ${QT_MODULE} _upper_qt_module) - SET(QT_${_upper_qt_module}_INCLUDE_DIR NOTFOUND) - SET(QT_${_upper_qt_module}_LIBRARY_RELEASE NOTFOUND) - SET(QT_${_upper_qt_module}_LIBRARY_DEBUG NOTFOUND) - ENDFOREACH(QT_MODULE) - SET(QT_QTDESIGNERCOMPONENTS_INCLUDE_DIR NOTFOUND) - SET(QT_QTDESIGNERCOMPONENTS_LIBRARY_RELEASE NOTFOUND) - SET(QT_QTDESIGNERCOMPONENTS_LIBRARY_DEBUG NOTFOUND) - SET(QT_QTASSISTANTCLIENT_INCLUDE_DIR NOTFOUND) - SET(QT_QTASSISTANTCLIENT_LIBRARY_RELEASE NOTFOUND) - SET(QT_QTASSISTANTCLIENT_LIBRARY_DEBUG NOTFOUND) - SET(QT_QTASSISTANT_INCLUDE_DIR NOTFOUND) - SET(QT_QTASSISTANT_LIBRARY_RELEASE NOTFOUND) - SET(QT_QTASSISTANT_LIBRARY_DEBUG NOTFOUND) - SET(QT_QTCLUCENE_LIBRARY_RELEASE NOTFOUND) - SET(QT_QTCLUCENE_LIBRARY_DEBUG NOTFOUND) - SET(QT_QAXCONTAINER_INCLUDE_DIR NOTFOUND) - SET(QT_QAXCONTAINER_LIBRARY_RELEASE NOTFOUND) - SET(QT_QAXCONTAINER_LIBRARY_DEBUG NOTFOUND) - SET(QT_QAXSERVER_INCLUDE_DIR NOTFOUND) - SET(QT_QAXSERVER_LIBRARY_RELEASE NOTFOUND) - SET(QT_QAXSERVER_LIBRARY_DEBUG NOTFOUND) - IF(WIN32) - SET(QT_QTMAIN_LIBRARY_DEBUG NOTFOUND) - SET(QT_QTMAIN_LIBRARY_RELEASE NOTFOUND) - ENDIF(WIN32) - ENDIF(QT_QMAKE_CHANGED) - - FOREACH(QT_MODULE ${QT_MODULES}) - STRING(TOUPPER ${QT_MODULE} _upper_qt_module) - FIND_PATH(QT_${_upper_qt_module}_INCLUDE_DIR ${QT_MODULE} - PATHS - ${QT_HEADERS_DIR}/${QT_MODULE} - ${QT_LIBRARY_DIR}/${QT_MODULE}.framework/Headers - NO_DEFAULT_PATH - ) - # phonon doesn't seem consistent, let's try phonondefs.h for some - # installations - IF(${QT_MODULE} STREQUAL "phonon") - FIND_PATH(QT_${_upper_qt_module}_INCLUDE_DIR phonondefs.h - PATHS - ${QT_HEADERS_DIR}/${QT_MODULE} - ${QT_LIBRARY_DIR}/${QT_MODULE}.framework/Headers - NO_DEFAULT_PATH - ) - ENDIF(${QT_MODULE} STREQUAL "phonon") - ENDFOREACH(QT_MODULE) - - IF(WIN32) - SET(QT_MODULES ${QT_MODULES} QAxContainer QAxServer) - # Set QT_AXCONTAINER_INCLUDE_DIR and QT_AXSERVER_INCLUDE_DIR - FIND_PATH(QT_QAXCONTAINER_INCLUDE_DIR ActiveQt - PATHS - ${QT_HEADERS_DIR}/ActiveQt - NO_DEFAULT_PATH - ) - FIND_PATH(QT_QAXSERVER_INCLUDE_DIR ActiveQt - PATHS - ${QT_HEADERS_DIR}/ActiveQt - NO_DEFAULT_PATH - ) - ENDIF(WIN32) - - # Set QT_QTDESIGNERCOMPONENTS_INCLUDE_DIR - FIND_PATH(QT_QTDESIGNERCOMPONENTS_INCLUDE_DIR QDesignerComponents - PATHS - ${QT_HEADERS_DIR}/QtDesigner - ${QT_LIBRARY_DIR}/QtDesigner.framework/Headers - NO_DEFAULT_PATH - ) - - # Set QT_QTASSISTANT_INCLUDE_DIR - FIND_PATH(QT_QTASSISTANT_INCLUDE_DIR QtAssistant - PATHS - ${QT_HEADERS_DIR}/QtAssistant - ${QT_LIBRARY_DIR}/QtAssistant.framework/Headers - NO_DEFAULT_PATH - ) - - # Set QT_QTASSISTANTCLIENT_INCLUDE_DIR - FIND_PATH(QT_QTASSISTANTCLIENT_INCLUDE_DIR QAssistantClient - PATHS - ${QT_HEADERS_DIR}/QtAssistant - ${QT_LIBRARY_DIR}/QtAssistant.framework/Headers - NO_DEFAULT_PATH - ) - - # Set QT_INCLUDE_DIR by removine "/QtCore" in the string ${QT_QTCORE_INCLUDE_DIR} - IF( QT_QTCORE_INCLUDE_DIR ) - IF (QT_USE_FRAMEWORKS) - SET(QT_INCLUDE_DIR ${QT_HEADERS_DIR}) - ELSE (QT_USE_FRAMEWORKS) - STRING( REGEX REPLACE "/QtCore$" "" qt4_include_dir ${QT_QTCORE_INCLUDE_DIR}) - SET( QT_INCLUDE_DIR ${qt4_include_dir}) - ENDIF (QT_USE_FRAMEWORKS) - ENDIF( QT_QTCORE_INCLUDE_DIR ) - - IF( NOT QT_INCLUDE_DIR) - IF(Qt4_FIND_REQUIRED) - MESSAGE( FATAL_ERROR "Could NOT find QtCore header") - ENDIF(Qt4_FIND_REQUIRED) - ENDIF( NOT QT_INCLUDE_DIR) - - # Make variables changeble to the advanced user - MARK_AS_ADVANCED( QT_INCLUDE_DIR ) - - # Set QT_INCLUDES - SET( QT_INCLUDES ${QT_MKSPECS_DIR}/default ${QT_INCLUDE_DIR} ) - - - - - - ####################################### - # - # Qt configuration - # - ####################################### - IF(EXISTS "${QT_MKSPECS_DIR}/qconfig.pri") - FILE(READ ${QT_MKSPECS_DIR}/qconfig.pri _qconfig_FILE_contents) - STRING(REGEX MATCH "QT_CONFIG[^\n]+" QT_QCONFIG "${_qconfig_FILE_contents}") - STRING(REGEX MATCH "CONFIG[^\n]+" QT_CONFIG "${_qconfig_FILE_contents}") - STRING(REGEX MATCH "EDITION[^\n]+" QT_EDITION "${_qconfig_FILE_contents}") - STRING(REGEX MATCH "QT_LIBINFIX[^\n]+" _qconfig_qt_libinfix "${_qconfig_FILE_contents}") - STRING(REGEX REPLACE "QT_LIBINFIX *= *([^\n]*)" "\\1" QT_LIBINFIX "${_qconfig_qt_libinfix}") - ENDIF(EXISTS "${QT_MKSPECS_DIR}/qconfig.pri") - IF("${QT_EDITION}" MATCHES "DesktopLight") - SET(QT_EDITION_DESKTOPLIGHT 1) - ENDIF("${QT_EDITION}" MATCHES "DesktopLight") - - ######################################## - # - # Setting the LIBRARY-Variables - # - ######################################## - - # find the libraries - FOREACH(QT_MODULE ${QT_MODULES}) - STRING(TOUPPER ${QT_MODULE} _upper_qt_module) - FIND_LIBRARY(QT_${_upper_qt_module}_LIBRARY_RELEASE - NAMES ${QT_MODULE}${QT_LIBINFIX} ${QT_MODULE}${QT_LIBINFIX}4 - PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH - ) - FIND_LIBRARY(QT_${_upper_qt_module}_LIBRARY_DEBUG - NAMES ${QT_MODULE}${QT_LIBINFIX}_debug ${QT_MODULE}${QT_LIBINFIX}d ${QT_MODULE}${QT_LIBINFIX}d4 - PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH - ) - ENDFOREACH(QT_MODULE) - - # QtUiTools not with other frameworks with binary installation (in /usr/lib) - IF(Q_WS_MAC AND QT_QTCORE_LIBRARY_RELEASE AND NOT QT_QTUITOOLS_LIBRARY_RELEASE) - FIND_LIBRARY(QT_QTUITOOLS_LIBRARY_RELEASE NAMES QtUiTools${QT_LIBINFIX} PATHS ${QT_LIBRARY_DIR}) - ENDIF(Q_WS_MAC AND QT_QTCORE_LIBRARY_RELEASE AND NOT QT_QTUITOOLS_LIBRARY_RELEASE) - - IF( NOT QT_QTCORE_LIBRARY_DEBUG AND NOT QT_QTCORE_LIBRARY_RELEASE ) - - # try dropping a hint if trying to use Visual Studio with Qt built by mingw - IF(QT_LIBRARY_DIR AND MSVC) - IF(EXISTS ${QT_LIBRARY_DIR}/libqtmain.a) - MESSAGE( FATAL_ERROR "It appears you're trying to use Visual Studio with Qt built by mingw") - ENDIF(EXISTS ${QT_LIBRARY_DIR}/libqtmain.a) - ENDIF(QT_LIBRARY_DIR AND MSVC) - - IF(Qt4_FIND_REQUIRED) - MESSAGE( FATAL_ERROR "Could NOT find QtCore. Check ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log for more details.") - ENDIF(Qt4_FIND_REQUIRED) - ENDIF( NOT QT_QTCORE_LIBRARY_DEBUG AND NOT QT_QTCORE_LIBRARY_RELEASE ) - - # Set QT_QTDESIGNERCOMPONENTS_LIBRARY - FIND_LIBRARY(QT_QTDESIGNERCOMPONENTS_LIBRARY_RELEASE NAMES QtDesignerComponents${QT_LIBINFIX} QtDesignerComponents${QT_LIBINFIX}4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH) - FIND_LIBRARY(QT_QTDESIGNERCOMPONENTS_LIBRARY_DEBUG NAMES QtDesignerComponents${QT_LIBINFIX}_debug QtDesignerComponents${QT_LIBINFIX}d QtDesignerComponents${QT_LIBINFIX}d4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH) - - # Set QT_QTMAIN_LIBRARY - IF(WIN32) - FIND_LIBRARY(QT_QTMAIN_LIBRARY_RELEASE NAMES qtmain${QT_LIBINFIX} PATHS ${QT_LIBRARY_DIR} - NO_DEFAULT_PATH) - FIND_LIBRARY(QT_QTMAIN_LIBRARY_DEBUG NAMES qtmain${QT_LIBINFIX}d PATHS ${QT_LIBRARY_DIR} - NO_DEFAULT_PATH) - ENDIF(WIN32) - - # Set QT_QTASSISTANTCLIENT_LIBRARY - FIND_LIBRARY(QT_QTASSISTANTCLIENT_LIBRARY_RELEASE NAMES QtAssistantClient${QT_LIBINFIX} QtAssistantClient${QT_LIBINFIX}4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH) - FIND_LIBRARY(QT_QTASSISTANTCLIENT_LIBRARY_DEBUG NAMES QtAssistantClient${QT_LIBINFIX}_debug QtAssistantClient${QT_LIBINFIX}d QtAssistantClient${QT_LIBINFIX}d4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH) - - # Set QT_QTASSISTANT_LIBRARY - FIND_LIBRARY(QT_QTASSISTANT_LIBRARY_RELEASE NAMES QtAssistantClient${QT_LIBINFIX} QtAssistantClient${QT_LIBINFIX}4 QtAssistant${QT_LIBINFIX} QtAssistant${QT_LIBINFIX}4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH) - FIND_LIBRARY(QT_QTASSISTANT_LIBRARY_DEBUG NAMES QtAssistantClient${QT_LIBINFIX}_debug QtAssistantClient${QT_LIBINFIX}d QtAssistantClient${QT_LIBINFIX}d4 QtAssistant${QT_LIBINFIX}_debug QtAssistant${QT_LIBINFIX}d4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH) - - # Set QT_QTHELP_LIBRARY - FIND_LIBRARY(QT_QTCLUCENE_LIBRARY_RELEASE NAMES QtCLucene${QT_LIBINFIX} QtCLucene${QT_LIBINFIX}4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH) - FIND_LIBRARY(QT_QTCLUCENE_LIBRARY_DEBUG NAMES QtCLucene${QT_LIBINFIX}_debug QtCLucene${QT_LIBINFIX}d QtCLucene${QT_LIBINFIX}d4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH) - # QtCLucene not with other frameworks with binary installation (in /usr/lib) - IF(Q_WS_MAC AND QT_QTCORE_LIBRARY_RELEASE AND NOT QT_QTCLUCENE_LIBRARY_RELEASE) - FIND_LIBRARY(QT_QTCLUCENE_LIBRARY_RELEASE NAMES QtCLucene${QT_LIBINFIX} PATHS ${QT_LIBRARY_DIR}) - ENDIF(Q_WS_MAC AND QT_QTCORE_LIBRARY_RELEASE AND NOT QT_QTCLUCENE_LIBRARY_RELEASE) - - ############################################ - # - # Check the existence of the libraries. - # - ############################################ - - # On OSX when Qt is found as framework, never use the imported targets for now, since - # in this case the handling of the framework directory currently does not work correctly. - IF(QT_USE_FRAMEWORKS) - SET(QT_USE_IMPORTED_TARGETS FALSE) - ENDIF(QT_USE_FRAMEWORKS) - - - MACRO (_QT4_ADJUST_LIB_VARS _camelCaseBasename) - - STRING(TOUPPER "${_camelCaseBasename}" basename) - - # The name of the imported targets, i.e. the prefix "Qt4::" must not change, - # since it is stored in EXPORT-files as name of a required library. If the name would change - # here, this would lead to the imported Qt4-library targets not being resolved by cmake anymore. - IF (QT_${basename}_LIBRARY_RELEASE OR QT_${basename}_LIBRARY_DEBUG) - - IF(NOT TARGET Qt4::${_camelCaseBasename}) - ADD_LIBRARY(Qt4::${_camelCaseBasename} UNKNOWN IMPORTED ) - - IF (QT_${basename}_LIBRARY_RELEASE) - SET_PROPERTY(TARGET Qt4::${_camelCaseBasename} APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE) - SET_PROPERTY(TARGET Qt4::${_camelCaseBasename} PROPERTY IMPORTED_LOCATION_RELEASE "${QT_${basename}_LIBRARY_RELEASE}" ) - ENDIF (QT_${basename}_LIBRARY_RELEASE) - - IF (QT_${basename}_LIBRARY_DEBUG) - SET_PROPERTY(TARGET Qt4::${_camelCaseBasename} APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG) - SET_PROPERTY(TARGET Qt4::${_camelCaseBasename} PROPERTY IMPORTED_LOCATION_DEBUG "${QT_${basename}_LIBRARY_DEBUG}" ) - ENDIF (QT_${basename}_LIBRARY_DEBUG) - ENDIF(NOT TARGET Qt4::${_camelCaseBasename}) - - # If QT_USE_IMPORTED_TARGETS is enabled, the QT_QTFOO_LIBRARY variables are set to point at these - # imported targets. This works better in general, and is also in almost all cases fully - # backward compatible. The only issue is when a project A which had this enabled then exports its - # libraries via export or EXPORT_LIBRARY_DEPENDENCIES(). In this case the libraries from project - # A will depend on the imported Qt targets, and the names of these imported targets will be stored - # in the dependency files on disk. This means when a project B then uses project A, these imported - # targets must be created again, otherwise e.g. "Qt4__QtCore" will be interpreted as name of a - # library file on disk, and not as a target, and linking will fail: - IF(QT_USE_IMPORTED_TARGETS) - SET(QT_${basename}_LIBRARY Qt4::${_camelCaseBasename} ) - SET(QT_${basename}_LIBRARIES Qt4::${_camelCaseBasename} ) - ELSE(QT_USE_IMPORTED_TARGETS) - - # if the release- as well as the debug-version of the library have been found: - IF (QT_${basename}_LIBRARY_DEBUG AND QT_${basename}_LIBRARY_RELEASE) - # if the generator supports configuration types then set - # optimized and debug libraries, or if the CMAKE_BUILD_TYPE has a value - IF (CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE) - SET(QT_${basename}_LIBRARY optimized ${QT_${basename}_LIBRARY_RELEASE} debug ${QT_${basename}_LIBRARY_DEBUG}) - ELSE(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE) - # if there are no configuration types and CMAKE_BUILD_TYPE has no value - # then just use the release libraries - SET(QT_${basename}_LIBRARY ${QT_${basename}_LIBRARY_RELEASE} ) - ENDIF(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE) - SET(QT_${basename}_LIBRARIES optimized ${QT_${basename}_LIBRARY_RELEASE} debug ${QT_${basename}_LIBRARY_DEBUG}) - ENDIF (QT_${basename}_LIBRARY_DEBUG AND QT_${basename}_LIBRARY_RELEASE) - - # if only the release version was found, set the debug variable also to the release version - IF (QT_${basename}_LIBRARY_RELEASE AND NOT QT_${basename}_LIBRARY_DEBUG) - SET(QT_${basename}_LIBRARY_DEBUG ${QT_${basename}_LIBRARY_RELEASE}) - SET(QT_${basename}_LIBRARY ${QT_${basename}_LIBRARY_RELEASE}) - SET(QT_${basename}_LIBRARIES ${QT_${basename}_LIBRARY_RELEASE}) - ENDIF (QT_${basename}_LIBRARY_RELEASE AND NOT QT_${basename}_LIBRARY_DEBUG) - - # if only the debug version was found, set the release variable also to the debug version - IF (QT_${basename}_LIBRARY_DEBUG AND NOT QT_${basename}_LIBRARY_RELEASE) - SET(QT_${basename}_LIBRARY_RELEASE ${QT_${basename}_LIBRARY_DEBUG}) - SET(QT_${basename}_LIBRARY ${QT_${basename}_LIBRARY_DEBUG}) - SET(QT_${basename}_LIBRARIES ${QT_${basename}_LIBRARY_DEBUG}) - ENDIF (QT_${basename}_LIBRARY_DEBUG AND NOT QT_${basename}_LIBRARY_RELEASE) - - # put the value in the cache: - SET(QT_${basename}_LIBRARY ${QT_${basename}_LIBRARY} CACHE STRING "The Qt ${basename} library" FORCE) - - ENDIF(QT_USE_IMPORTED_TARGETS) - -# message(STATUS "QT_${basename}_LIBRARY: ${QT_${basename}_LIBRARY}") - - SET(QT_${basename}_FOUND 1) - - ENDIF (QT_${basename}_LIBRARY_RELEASE OR QT_${basename}_LIBRARY_DEBUG) - - IF (QT_${basename}_INCLUDE_DIR) - #add the include directory to QT_INCLUDES - SET(QT_INCLUDES "${QT_${basename}_INCLUDE_DIR}" ${QT_INCLUDES}) - ENDIF (QT_${basename}_INCLUDE_DIR) - - # Make variables changeble to the advanced user - MARK_AS_ADVANCED(QT_${basename}_LIBRARY QT_${basename}_LIBRARY_RELEASE QT_${basename}_LIBRARY_DEBUG QT_${basename}_INCLUDE_DIR) - ENDMACRO (_QT4_ADJUST_LIB_VARS) - - - # Set QT_xyz_LIBRARY variable and add - # library include path to QT_INCLUDES - _QT4_ADJUST_LIB_VARS(QtCore) - _QT4_ADJUST_LIB_VARS(QtGui) - _QT4_ADJUST_LIB_VARS(Qt3Support) - _QT4_ADJUST_LIB_VARS(QtAssistant) - _QT4_ADJUST_LIB_VARS(QtAssistantClient) - _QT4_ADJUST_LIB_VARS(QtCLucene) - _QT4_ADJUST_LIB_VARS(QtDBus) - _QT4_ADJUST_LIB_VARS(QtDesigner) - _QT4_ADJUST_LIB_VARS(QtDesignerComponents) - _QT4_ADJUST_LIB_VARS(QtHelp) - _QT4_ADJUST_LIB_VARS(QtMultimedia) - _QT4_ADJUST_LIB_VARS(QtNetwork) - _QT4_ADJUST_LIB_VARS(QtNsPlugin) - _QT4_ADJUST_LIB_VARS(QtOpenGL) - _QT4_ADJUST_LIB_VARS(QtScript) - _QT4_ADJUST_LIB_VARS(QtScriptTools) - _QT4_ADJUST_LIB_VARS(QtSql) - _QT4_ADJUST_LIB_VARS(QtSvg) - _QT4_ADJUST_LIB_VARS(QtTest) - _QT4_ADJUST_LIB_VARS(QtUiTools) - _QT4_ADJUST_LIB_VARS(QtWebKit) - _QT4_ADJUST_LIB_VARS(QtXml) - _QT4_ADJUST_LIB_VARS(QtXmlPatterns) - _QT4_ADJUST_LIB_VARS(phonon) - - # platform dependent libraries - IF(Q_WS_X11) - _QT4_ADJUST_LIB_VARS(QtMotif) - ENDIF(Q_WS_X11) - IF(WIN32) - _QT4_ADJUST_LIB_VARS(qtmain) - _QT4_ADJUST_LIB_VARS(QAxServer) - _QT4_ADJUST_LIB_VARS(QAxContainer) - ENDIF(WIN32) - - # If Qt is installed as a framework, we need to add QT_QTCORE_LIBRARY here (which - # is the framework directory in that case), since this will make the cmake include_directories() - # command recognize that we need the framework flag with the respective directory (-F) - IF(QT_USE_FRAMEWORKS) - SET(QT_INCLUDES ${QT_INCLUDES} ${QT_QTCORE_LIBRARY} ) - SET(QT_INCLUDE_DIR ${QT_INCLUDE_DIR} ${QT_QTCORE_LIBRARY} ) - ENDIF(QT_USE_FRAMEWORKS) - - - - ####################################### - # - # Check the executables of Qt - # ( moc, uic, rcc ) - # - ####################################### - - - IF(QT_QMAKE_CHANGED) - SET(QT_UIC_EXECUTABLE NOTFOUND) - SET(QT_MOC_EXECUTABLE NOTFOUND) - SET(QT_UIC3_EXECUTABLE NOTFOUND) - SET(QT_RCC_EXECUTABLE NOTFOUND) - SET(QT_DBUSCPP2XML_EXECUTABLE NOTFOUND) - SET(QT_DBUSXML2CPP_EXECUTABLE NOTFOUND) - SET(QT_LUPDATE_EXECUTABLE NOTFOUND) - SET(QT_LRELEASE_EXECUTABLE NOTFOUND) - SET(QT_QCOLLECTIONGENERATOR_EXECUTABLE NOTFOUND) - SET(QT_DESIGNER_EXECUTABLE NOTFOUND) - SET(QT_LINGUIST_EXECUTABLE NOTFOUND) - ENDIF(QT_QMAKE_CHANGED) - - FIND_PROGRAM(QT_MOC_EXECUTABLE - NAMES moc-qt4 moc - PATHS ${QT_BINARY_DIR} - NO_DEFAULT_PATH - ) - - FIND_PROGRAM(QT_UIC_EXECUTABLE - NAMES uic-qt4 uic - PATHS ${QT_BINARY_DIR} - NO_DEFAULT_PATH - ) - - FIND_PROGRAM(QT_UIC3_EXECUTABLE - NAMES uic3 - PATHS ${QT_BINARY_DIR} - NO_DEFAULT_PATH - ) - - FIND_PROGRAM(QT_RCC_EXECUTABLE - NAMES rcc - PATHS ${QT_BINARY_DIR} - NO_DEFAULT_PATH - ) - - FIND_PROGRAM(QT_DBUSCPP2XML_EXECUTABLE - NAMES qdbuscpp2xml - PATHS ${QT_BINARY_DIR} - NO_DEFAULT_PATH - ) - - FIND_PROGRAM(QT_DBUSXML2CPP_EXECUTABLE - NAMES qdbusxml2cpp - PATHS ${QT_BINARY_DIR} - NO_DEFAULT_PATH - ) - - FIND_PROGRAM(QT_LUPDATE_EXECUTABLE - NAMES lupdate-qt4 lupdate - PATHS ${QT_BINARY_DIR} - NO_DEFAULT_PATH - ) - - FIND_PROGRAM(QT_LRELEASE_EXECUTABLE - NAMES lrelease-qt4 lrelease - PATHS ${QT_BINARY_DIR} - NO_DEFAULT_PATH - ) - - FIND_PROGRAM(QT_QCOLLECTIONGENERATOR_EXECUTABLE - NAMES qcollectiongenerator-qt4 qcollectiongenerator - PATHS ${QT_BINARY_DIR} - NO_DEFAULT_PATH - ) - - FIND_PROGRAM(QT_DESIGNER_EXECUTABLE - NAMES designer-qt4 designer - PATHS ${QT_BINARY_DIR} - NO_DEFAULT_PATH - ) - - FIND_PROGRAM(QT_LINGUIST_EXECUTABLE - NAMES linguist-qt4 linguist - PATHS ${QT_BINARY_DIR} - NO_DEFAULT_PATH - ) - - IF (QT_MOC_EXECUTABLE) - SET(QT_WRAP_CPP "YES") - ENDIF (QT_MOC_EXECUTABLE) - - IF (QT_UIC_EXECUTABLE) - SET(QT_WRAP_UI "YES") - ENDIF (QT_UIC_EXECUTABLE) - - - - MARK_AS_ADVANCED( QT_UIC_EXECUTABLE QT_UIC3_EXECUTABLE QT_MOC_EXECUTABLE - QT_RCC_EXECUTABLE QT_DBUSXML2CPP_EXECUTABLE QT_DBUSCPP2XML_EXECUTABLE - QT_LUPDATE_EXECUTABLE QT_LRELEASE_EXECUTABLE QT_QCOLLECTIONGENERATOR_EXECUTABLE - QT_DESIGNER_EXECUTABLE QT_LINGUIST_EXECUTABLE) - - - # get the directory of the current file, used later on in the file - GET_FILENAME_COMPONENT( _qt4_current_dir "${CMAKE_CURRENT_LIST_FILE}" PATH) - - ###################################### - # - # Macros for building Qt files - # - ###################################### - - INCLUDE("${_qt4_current_dir}/Qt4Macros.cmake") - - - ###################################### - # - # decide if Qt got found - # - ###################################### - - # if the includes,libraries,moc,uic and rcc are found then we have it - IF( QT_LIBRARY_DIR AND QT_INCLUDE_DIR AND QT_MOC_EXECUTABLE AND - QT_UIC_EXECUTABLE AND QT_RCC_EXECUTABLE AND QT_QTCORE_LIBRARY) - SET( QT4_FOUND "YES" ) - INCLUDE(FindPackageMessage) - FIND_PACKAGE_MESSAGE(Qt4 "Found Qt-Version ${QTVERSION} (using ${QT_QMAKE_EXECUTABLE})" - "[${QT_LIBRARY_DIR}][${QT_INCLUDE_DIR}][${QT_MOC_EXECUTABLE}][${QT_UIC_EXECUTABLE}][${QT_RCC_EXECUTABLE}]") - ELSE( QT_LIBRARY_DIR AND QT_INCLUDE_DIR AND QT_MOC_EXECUTABLE AND - QT_UIC_EXECUTABLE AND QT_RCC_EXECUTABLE AND QT_QTCORE_LIBRARY) - SET( QT4_FOUND "NO") - SET(QT_QMAKE_EXECUTABLE "${QT_QMAKE_EXECUTABLE}-NOTFOUND" CACHE FILEPATH "Invalid qmake found" FORCE) - IF( Qt4_FIND_REQUIRED) - MESSAGE( FATAL_ERROR "Qt libraries, includes, moc, uic or/and rcc NOT found!") - ENDIF( Qt4_FIND_REQUIRED) - ENDIF( QT_LIBRARY_DIR AND QT_INCLUDE_DIR AND QT_MOC_EXECUTABLE AND - QT_UIC_EXECUTABLE AND QT_RCC_EXECUTABLE AND QT_QTCORE_LIBRARY) - - SET(QT_FOUND ${QT4_FOUND}) - - - ############################################### - # - # configuration/system dependent settings - # - ############################################### - - INCLUDE("${_qt4_current_dir}/Qt4ConfigDependentSettings.cmake") - - - ####################################### - # - # compatibility settings - # - ####################################### - # Backwards compatibility for CMake1.4 and 1.2 - SET (QT_MOC_EXE ${QT_MOC_EXECUTABLE} ) - SET (QT_UIC_EXE ${QT_UIC_EXECUTABLE} ) - - SET( QT_QT_LIBRARY "") - -ELSE(QT4_QMAKE_FOUND) - - SET(QT_QMAKE_EXECUTABLE "${QT_QMAKE_EXECUTABLE}-NOTFOUND" CACHE FILEPATH "Invalid qmake found" FORCE) - - # The code below is overly complex to make sure we do not break compatibility with CMake 2.6.x - # For CMake 2.8, it should be simplified by getting rid of QT4_INSTALLED_VERSION_TOO_OLD and - # QT4_INSTALLED_VERSION_TOO_NEW - IF(Qt4_FIND_REQUIRED) - IF(QT4_INSTALLED_VERSION_TOO_OLD) - IF( Qt4_FIND_VERSION_EXACT ) - MESSAGE(FATAL_ERROR "The installed Qt version ${QTVERSION} is too old, version ${QT_MIN_VERSION} is required") - ELSE( Qt4_FIND_VERSION_EXACT ) - MESSAGE(FATAL_ERROR "The installed Qt version ${QTVERSION} is too old, at least version ${QT_MIN_VERSION} is required") - ENDIF( Qt4_FIND_VERSION_EXACT ) - ELSE(QT4_INSTALLED_VERSION_TOO_OLD) - IF( Qt4_FIND_VERSION_EXACT AND QT4_INSTALLED_VERSION_TOO_NEW ) - MESSAGE(FATAL_ERROR "The installed Qt version ${QTVERSION} is too new, version ${QT_MIN_VERSION} is required") - ELSE( Qt4_FIND_VERSION_EXACT AND QT4_INSTALLED_VERSION_TOO_NEW ) - MESSAGE( FATAL_ERROR "Qt qmake not found!") - ENDIF( Qt4_FIND_VERSION_EXACT AND QT4_INSTALLED_VERSION_TOO_NEW ) - ENDIF(QT4_INSTALLED_VERSION_TOO_OLD) - ELSE(Qt4_FIND_REQUIRED) - IF(QT4_INSTALLED_VERSION_TOO_OLD AND NOT Qt4_FIND_QUIETLY) - MESSAGE(STATUS "The installed Qt version ${QTVERSION} is too old, at least version ${QT_MIN_VERSION} is required") - ENDIF(QT4_INSTALLED_VERSION_TOO_OLD AND NOT Qt4_FIND_QUIETLY) - ENDIF(Qt4_FIND_REQUIRED) - -ENDIF (QT4_QMAKE_FOUND) - diff --git a/Installation/cmake/modules/2.6.2-to-2.8.1/Qt4ConfigDependentSettings.cmake b/Installation/cmake/modules/2.6.2-to-2.8.1/Qt4ConfigDependentSettings.cmake deleted file mode 100644 index 1c5293d1a69..00000000000 --- a/Installation/cmake/modules/2.6.2-to-2.8.1/Qt4ConfigDependentSettings.cmake +++ /dev/null @@ -1,373 +0,0 @@ -# This file is included by FindQt4.cmake, don't include it directly. - -#============================================================================= -# Copyright 2005-2009 Kitware, Inc. -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distributed this file outside of CMake, substitute the full -# License text for the above reference.) - - -############################################### -# -# configuration/system dependent settings -# -############################################### - -# find dependencies for some Qt modules -# when doing builds against a static Qt, they are required -# when doing builds against a shared Qt, they are not required -# if a user needs the dependencies, and they couldn't be found, they can set -# the variables themselves. - -SET(QT_QTGUI_LIB_DEPENDENCIES "") -SET(QT_QTCORE_LIB_DEPENDENCIES "") -SET(QT_QTNETWORK_LIB_DEPENDENCIES "") -SET(QT_QTOPENGL_LIB_DEPENDENCIES "") -SET(QT_QTDBUS_LIB_DEPENDENCIES "") -SET(QT_QTHELP_LIB_DEPENDENCIES ${QT_QTCLUCENE_LIBRARY}) - - -IF(WIN32) - # On Windows, qconfig.pri has "static" for static library builds - IF(QT_CONFIG MATCHES "static") - SET(QT_IS_STATIC 1) - ENDIF(QT_CONFIG MATCHES "static") -ELSE(WIN32) - # On other platforms, check file extension to know if its static - IF(QT_QTCORE_LIBRARY_RELEASE) - GET_FILENAME_COMPONENT(qtcore_lib_ext "${QT_QTCORE_LIBRARY_RELEASE}" EXT) - IF("${qtcore_lib_ext}" STREQUAL "${CMAKE_STATIC_LIBRARY_SUFFIX}") - SET(QT_IS_STATIC 1) - ENDIF("${qtcore_lib_ext}" STREQUAL "${CMAKE_STATIC_LIBRARY_SUFFIX}") - ENDIF(QT_QTCORE_LIBRARY_RELEASE) - IF(QT_QTCORE_LIBRARY_DEBUG) - GET_FILENAME_COMPONENT(qtcore_lib_ext "${QT_QTCORE_LIBRARY_DEBUG}" EXT) - IF(${qtcore_lib_ext} STREQUAL ${CMAKE_STATIC_LIBRARY_SUFFIX}) - SET(QT_IS_STATIC 1) - ENDIF(${qtcore_lib_ext} STREQUAL ${CMAKE_STATIC_LIBRARY_SUFFIX}) - ENDIF(QT_QTCORE_LIBRARY_DEBUG) -ENDIF(WIN32) - -# build using shared Qt needs -DQT_DLL on Windows -IF(WIN32 AND NOT QT_IS_STATIC) - SET(QT_DEFINITIONS ${QT_DEFINITIONS} -DQT_DLL) -ENDIF(WIN32 AND NOT QT_IS_STATIC) - - -# QtOpenGL dependencies -QT_QUERY_QMAKE(QMAKE_LIBS_OPENGL "QMAKE_LIBS_OPENGL") -IF(Q_WS_MAC) -# On the Mac OpenGL is probably frameworks and QMAKE_LIBS_OPENGL can be -# e.g. "-framework OpenGL -framework AGL". The separate_arguments() call in -# the other branch makes "-framework;-OpenGL;-framework;-lAGL" appear in the -# linker command. So we need to protect the "-framework foo" as -# non-separatable strings. We do this by replacing the space after -# "-framework" with an underscore, then calling separate_arguments(), and -# then we replace the underscores again with spaces. So we get proper linker -# commands. Alex - STRING(REGEX REPLACE "-framework +" "-framework_" QMAKE_LIBS_OPENGL "${QMAKE_LIBS_OPENGL}") - SEPARATE_ARGUMENTS(QMAKE_LIBS_OPENGL) - STRING(REGEX REPLACE "-framework_" "-framework " QMAKE_LIBS_OPENGL "${QMAKE_LIBS_OPENGL}") -ELSE(Q_WS_MAC) - SEPARATE_ARGUMENTS(QMAKE_LIBS_OPENGL) -ENDIF(Q_WS_MAC) -SET (QT_QTOPENGL_LIB_DEPENDENCIES ${QT_QTOPENGL_LIB_DEPENDENCIES} ${QMAKE_LIBS_OPENGL}) - - -## system png -IF(QT_QCONFIG MATCHES "system-png") - FIND_LIBRARY(QT_PNG_LIBRARY NAMES png) - MARK_AS_ADVANCED(QT_PNG_LIBRARY) - IF(QT_PNG_LIBRARY) - SET(QT_QTGUI_LIB_DEPENDENCIES ${QT_QTGUI_LIB_DEPENDENCIES} ${QT_PNG_LIBRARY}) - ENDIF(QT_PNG_LIBRARY) -ENDIF(QT_QCONFIG MATCHES "system-png") - - -# for X11, get X11 library directory -IF(Q_WS_X11) - QT_QUERY_QMAKE(QMAKE_LIBDIR_X11 "QMAKE_LIBDIR_X11") -ENDIF(Q_WS_X11) - - -## X11 SM -IF(QT_QCONFIG MATCHES "x11sm") - # ask qmake where the x11 libs are - FIND_LIBRARY(QT_X11_SM_LIBRARY NAMES SM PATHS ${QMAKE_LIBDIR_X11}) - FIND_LIBRARY(QT_X11_ICE_LIBRARY NAMES ICE PATHS ${QMAKE_LIBDIR_X11}) - MARK_AS_ADVANCED(QT_X11_SM_LIBRARY) - MARK_AS_ADVANCED(QT_X11_ICE_LIBRARY) - IF(QT_X11_SM_LIBRARY AND QT_X11_ICE_LIBRARY) - SET(QT_QTGUI_LIB_DEPENDENCIES ${QT_QTGUI_LIB_DEPENDENCIES} ${QT_X11_SM_LIBRARY} ${QT_X11_ICE_LIBRARY}) - ENDIF(QT_X11_SM_LIBRARY AND QT_X11_ICE_LIBRARY) -ENDIF(QT_QCONFIG MATCHES "x11sm") - - -## Xi -IF(QT_QCONFIG MATCHES "tablet") - FIND_LIBRARY(QT_XI_LIBRARY NAMES Xi PATHS ${QMAKE_LIBDIR_X11}) - MARK_AS_ADVANCED(QT_XI_LIBRARY) - IF(QT_XI_LIBRARY) - SET(QT_QTGUI_LIB_DEPENDENCIES ${QT_QTGUI_LIB_DEPENDENCIES} ${QT_XI_LIBRARY}) - ENDIF(QT_XI_LIBRARY) -ENDIF(QT_QCONFIG MATCHES "tablet") - - -## Xrender -IF(QT_QCONFIG MATCHES "xrender") - FIND_LIBRARY(QT_XRENDER_LIBRARY NAMES Xrender PATHS ${QMAKE_LIBDIR_X11}) - MARK_AS_ADVANCED(QT_XRENDER_LIBRARY) - IF(QT_XRENDER_LIBRARY) - SET(QT_QTGUI_LIB_DEPENDENCIES ${QT_QTGUI_LIB_DEPENDENCIES} ${QT_XRENDER_LIBRARY}) - ENDIF(QT_XRENDER_LIBRARY) -ENDIF(QT_QCONFIG MATCHES "xrender") - - -## Xrandr -IF(QT_QCONFIG MATCHES "xrandr") - FIND_LIBRARY(QT_XRANDR_LIBRARY NAMES Xrandr PATHS ${QMAKE_LIBDIR_X11}) - MARK_AS_ADVANCED(QT_XRANDR_LIBRARY) - IF(QT_XRANDR_LIBRARY) - SET(QT_QTGUI_LIB_DEPENDENCIES ${QT_QTGUI_LIB_DEPENDENCIES} ${QT_XRANDR_LIBRARY}) - ENDIF(QT_XRANDR_LIBRARY) -ENDIF(QT_QCONFIG MATCHES "xrandr") - - -## Xcursor -IF(QT_QCONFIG MATCHES "xcursor") - FIND_LIBRARY(QT_XCURSOR_LIBRARY NAMES Xcursor PATHS ${QMAKE_LIBDIR_X11}) - MARK_AS_ADVANCED(QT_XCURSOR_LIBRARY) - IF(QT_XCURSOR_LIBRARY) - SET(QT_QTGUI_LIB_DEPENDENCIES ${QT_QTGUI_LIB_DEPENDENCIES} ${QT_XCURSOR_LIBRARY}) - ENDIF(QT_XCURSOR_LIBRARY) -ENDIF(QT_QCONFIG MATCHES "xcursor") - - -## Xinerama -IF(QT_QCONFIG MATCHES "xinerama") - FIND_LIBRARY(QT_XINERAMA_LIBRARY NAMES Xinerama PATHS ${QMAKE_LIBDIR_X11}) - MARK_AS_ADVANCED(QT_XINERAMA_LIBRARY) - IF(QT_XINERAMA_LIBRARY) - SET(QT_QTGUI_LIB_DEPENDENCIES ${QT_QTGUI_LIB_DEPENDENCIES} ${QT_XINERAMA_LIBRARY}) - ENDIF(QT_XINERAMA_LIBRARY) -ENDIF(QT_QCONFIG MATCHES "xinerama") - - -## Xfixes -IF(QT_QCONFIG MATCHES "xfixes") - FIND_LIBRARY(QT_XFIXES_LIBRARY NAMES Xfixes PATHS ${QMAKE_LIBDIR_X11}) - MARK_AS_ADVANCED(QT_XFIXES_LIBRARY) - IF(QT_XFIXES_LIBRARY) - SET(QT_QTGUI_LIB_DEPENDENCIES ${QT_QTGUI_LIB_DEPENDENCIES} ${QT_XFIXES_LIBRARY}) - ENDIF(QT_XFIXES_LIBRARY) -ENDIF(QT_QCONFIG MATCHES "xfixes") - - -## system-freetype -IF(QT_QCONFIG MATCHES "system-freetype") - FIND_LIBRARY(QT_FREETYPE_LIBRARY NAMES freetype) - MARK_AS_ADVANCED(QT_FREETYPE_LIBRARY) - IF(QT_FREETYPE_LIBRARY) - SET(QT_QTGUI_LIB_DEPENDENCIES ${QT_QTGUI_LIB_DEPENDENCIES} ${QT_FREETYPE_LIBRARY}) - ENDIF(QT_FREETYPE_LIBRARY) -ENDIF(QT_QCONFIG MATCHES "system-freetype") - - -## fontconfig -IF(QT_QCONFIG MATCHES "fontconfig") - FIND_LIBRARY(QT_FONTCONFIG_LIBRARY NAMES fontconfig) - MARK_AS_ADVANCED(QT_FONTCONFIG_LIBRARY) - IF(QT_FONTCONFIG_LIBRARY) - SET(QT_QTGUI_LIB_DEPENDENCIES ${QT_QTGUI_LIB_DEPENDENCIES} ${QT_FONTCONFIG_LIBRARY}) - ENDIF(QT_FONTCONFIG_LIBRARY) -ENDIF(QT_QCONFIG MATCHES "fontconfig") - - -## system-zlib -IF(QT_QCONFIG MATCHES "system-zlib") - FIND_LIBRARY(QT_ZLIB_LIBRARY NAMES z) - MARK_AS_ADVANCED(QT_ZLIB_LIBRARY) - IF(QT_ZLIB_LIBRARY) - SET(QT_QTCORE_LIB_DEPENDENCIES ${QT_QTCORE_LIB_DEPENDENCIES} ${QT_ZLIB_LIBRARY}) - ENDIF(QT_ZLIB_LIBRARY) -ENDIF(QT_QCONFIG MATCHES "system-zlib") - - -## openssl -IF(NOT Q_WS_WIN) - SET(_QT_NEED_OPENSSL 0) - IF(QT_VERSION_MINOR LESS 4 AND QT_QCONFIG MATCHES "openssl") - SET(_QT_NEED_OPENSSL 1) - ENDIF(QT_VERSION_MINOR LESS 4 AND QT_QCONFIG MATCHES "openssl") - IF(QT_VERSION_MINOR GREATER 3 AND QT_QCONFIG MATCHES "openssl-linked") - SET(_QT_NEED_OPENSSL 1) - ENDIF(QT_VERSION_MINOR GREATER 3 AND QT_QCONFIG MATCHES "openssl-linked") - IF(_QT_NEED_OPENSSL) - FIND_PACKAGE(OpenSSL) - IF(OPENSSL_LIBRARIES) - SET(QT_QTNETWORK_LIB_DEPENDENCIES ${QT_QTNETWORK_LIB_DEPENDENCIES} ${OPENSSL_LIBRARIES}) - ENDIF(OPENSSL_LIBRARIES) - ENDIF(_QT_NEED_OPENSSL) -ENDIF(NOT Q_WS_WIN) - - -## dbus -IF(QT_QCONFIG MATCHES "dbus") - - # if the dbus library isn't found, we'll assume its not required to build - # shared Qt on Linux doesn't require it - IF(NOT QT_DBUS_LIBRARY) - EXECUTE_PROCESS(COMMAND pkg-config --libs-only-L dbus-1 - OUTPUT_VARIABLE _dbus_query_output - RESULT_VARIABLE _dbus_result - ERROR_VARIABLE _dbus_query_output ) - - IF(_dbus_result MATCHES 0) - STRING(REPLACE "-L" "" _dbus_query_output "${_dbus_query_output}") - SEPARATE_ARGUMENTS(_dbus_query_output) - ELSE(_dbus_result MATCHES 0) - SET(_dbus_query_output) - ENDIF(_dbus_result MATCHES 0) - - FIND_LIBRARY(QT_DBUS_LIBRARY NAMES dbus-1 PATHS ${_dbus_query_output} ) - - IF(QT_DBUS_LIBRARY) - SET(QT_QTDBUS_LIB_DEPENDENCIES ${QT_QTDBUS_LIB_DEPENDENCIES} ${QT_DBUS_LIBRARY}) - ENDIF(QT_DBUS_LIBRARY) - - MARK_AS_ADVANCED(QT_DBUS_LIBRARY) - ENDIF(NOT QT_DBUS_LIBRARY) - -ENDIF(QT_QCONFIG MATCHES "dbus") - - -## glib -IF(QT_QCONFIG MATCHES "glib") - - # if the glib libraries aren't found, we'll assume its not required to build - # shared Qt on Linux doesn't require it - - # Qt 4.2.0+ uses glib-2.0 - IF(NOT QT_GLIB_LIBRARY OR NOT QT_GTHREAD_LIBRARY) - EXECUTE_PROCESS(COMMAND pkg-config --libs-only-L glib-2.0 gthread-2.0 - OUTPUT_VARIABLE _glib_query_output - RESULT_VARIABLE _glib_result - ERROR_VARIABLE _glib_query_output ) - - IF(_glib_result MATCHES 0) - STRING(REPLACE "-L" "" _glib_query_output "${_glib_query_output}") - SEPARATE_ARGUMENTS(_glib_query_output) - ELSE(_glib_result MATCHES 0) - SET(_glib_query_output) - ENDIF(_glib_result MATCHES 0) - - FIND_LIBRARY(QT_GLIB_LIBRARY NAMES glib-2.0 PATHS ${_glib_query_output} ) - FIND_LIBRARY(QT_GTHREAD_LIBRARY NAMES gthread-2.0 PATHS ${_glib_query_output} ) - - MARK_AS_ADVANCED(QT_GLIB_LIBRARY) - MARK_AS_ADVANCED(QT_GTHREAD_LIBRARY) - ENDIF(NOT QT_GLIB_LIBRARY OR NOT QT_GTHREAD_LIBRARY) - - IF(QT_GLIB_LIBRARY AND QT_GTHREAD_LIBRARY) - SET(QT_QTCORE_LIB_DEPENDENCIES ${QT_QTCORE_LIB_DEPENDENCIES} - ${QT_GTHREAD_LIBRARY} ${QT_GLIB_LIBRARY}) - ENDIF(QT_GLIB_LIBRARY AND QT_GTHREAD_LIBRARY) - - - # Qt 4.5+ also links to gobject-2.0 - IF(QT_VERSION_MINOR GREATER 4) - IF(NOT QT_GOBJECT_LIBRARY) - EXECUTE_PROCESS(COMMAND pkg-config --libs-only-L gobject-2.0 - OUTPUT_VARIABLE _glib_query_output - RESULT_VARIABLE _glib_result - ERROR_VARIABLE _glib_query_output ) - - IF(_glib_result MATCHES 0) - STRING(REPLACE "-L" "" _glib_query_output "${_glib_query_output}") - SEPARATE_ARGUMENTS(_glib_query_output) - ELSE(_glib_result MATCHES 0) - SET(_glib_query_output) - ENDIF(_glib_result MATCHES 0) - - FIND_LIBRARY(QT_GOBJECT_LIBRARY NAMES gobject-2.0 PATHS ${_glib_query_output} ) - - MARK_AS_ADVANCED(QT_GOBJECT_LIBRARY) - ENDIF(NOT QT_GOBJECT_LIBRARY) - - IF(QT_GOBJECT_LIBRARY) - SET(QT_QTCORE_LIB_DEPENDENCIES ${QT_QTCORE_LIB_DEPENDENCIES} - ${QT_GOBJECT_LIBRARY}) - ENDIF(QT_GOBJECT_LIBRARY) - ENDIF(QT_VERSION_MINOR GREATER 4) - -ENDIF(QT_QCONFIG MATCHES "glib") - - -## clock-monotonic, just see if we need to link with rt -IF(QT_QCONFIG MATCHES "clock-monotonic") - SET(CMAKE_REQUIRED_LIBRARIES_SAVE ${CMAKE_REQUIRED_LIBRARIES}) - SET(CMAKE_REQUIRED_LIBRARIES rt) - CHECK_SYMBOL_EXISTS(_POSIX_TIMERS "unistd.h;time.h" QT_POSIX_TIMERS) - SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES_SAVE}) - IF(QT_POSIX_TIMERS) - FIND_LIBRARY(QT_RT_LIBRARY NAMES rt) - MARK_AS_ADVANCED(QT_RT_LIBRARY) - IF(QT_RT_LIBRARY) - SET(QT_QTCORE_LIB_DEPENDENCIES ${QT_QTCORE_LIB_DEPENDENCIES} ${QT_RT_LIBRARY}) - ENDIF(QT_RT_LIBRARY) - ENDIF(QT_POSIX_TIMERS) -ENDIF(QT_QCONFIG MATCHES "clock-monotonic") - - -IF(Q_WS_X11) - # X11 libraries Qt absolutely depends on - QT_QUERY_QMAKE(QT_LIBS_X11 "QMAKE_LIBS_X11") - SEPARATE_ARGUMENTS(QT_LIBS_X11) - FOREACH(QT_X11_LIB ${QT_LIBS_X11}) - STRING(REGEX REPLACE "-l" "" QT_X11_LIB "${QT_X11_LIB}") - SET(QT_TMP_STR "QT_X11_${QT_X11_LIB}_LIBRARY") - FIND_LIBRARY(${QT_TMP_STR} NAMES "${QT_X11_LIB}" PATHS ${QMAKE_LIBDIR_X11}) - MARK_AS_ADVANCED(${QT_TMP_STR}) - IF(${QT_TMP_STR}) - SET(QT_QTGUI_LIB_DEPENDENCIES ${QT_QTGUI_LIB_DEPENDENCIES} ${${QT_TMP_STR}}) - ENDIF(${QT_TMP_STR}) - ENDFOREACH(QT_X11_LIB) - - QT_QUERY_QMAKE(QT_LIBS_THREAD "QMAKE_LIBS_THREAD") - SET(QT_QTCORE_LIB_DEPENDENCIES ${QT_QTCORE_LIB_DEPENDENCIES} ${QT_LIBS_THREAD}) - - QT_QUERY_QMAKE(QMAKE_LIBS_DYNLOAD "QMAKE_LIBS_DYNLOAD") - SET (QT_QTCORE_LIB_DEPENDENCIES ${QT_QTCORE_LIB_DEPENDENCIES} ${QMAKE_LIBS_DYNLOAD}) - -ENDIF(Q_WS_X11) - - -IF(Q_WS_WIN) - SET(QT_QTGUI_LIB_DEPENDENCIES ${QT_QTGUI_LIB_DEPENDENCIES} imm32 winmm) - SET(QT_QTCORE_LIB_DEPENDENCIES ${QT_QTCORE_LIB_DEPENDENCIES} ws2_32) -ENDIF(Q_WS_WIN) - - -IF(Q_WS_MAC) - SET(QT_QTGUI_LIB_DEPENDENCIES ${QT_QTGUI_LIB_DEPENDENCIES} "-framework Carbon") - - # Qt 4.0, 4.1, 4.2 use QuickTime - IF(QT_VERSION_MINOR LESS 3) - SET(QT_QTGUI_LIB_DEPENDENCIES ${QT_QTGUI_LIB_DEPENDENCIES} "-framework QuickTime") - ENDIF(QT_VERSION_MINOR LESS 3) - - # Qt 4.2+ use AppKit - IF(QT_VERSION_MINOR GREATER 1) - SET(QT_QTGUI_LIB_DEPENDENCIES ${QT_QTGUI_LIB_DEPENDENCIES} "-framework AppKit") - ENDIF(QT_VERSION_MINOR GREATER 1) - - SET(QT_QTCORE_LIB_DEPENDENCIES ${QT_QTCORE_LIB_DEPENDENCIES} "-framework ApplicationServices") -ENDIF(Q_WS_MAC) - diff --git a/Installation/cmake/modules/2.6.2-to-2.8.1/Qt4Macros.cmake b/Installation/cmake/modules/2.6.2-to-2.8.1/Qt4Macros.cmake deleted file mode 100644 index bd72c8f6453..00000000000 --- a/Installation/cmake/modules/2.6.2-to-2.8.1/Qt4Macros.cmake +++ /dev/null @@ -1,399 +0,0 @@ -# This file is included by FindQt4.cmake, don't include it directly. - -#============================================================================= -# Copyright 2005-2009 Kitware, Inc. -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distributed this file outside of CMake, substitute the full -# License text for the above reference.) - - -###################################### -# -# Macros for building Qt files -# -###################################### - - -MACRO (QT4_EXTRACT_OPTIONS _qt4_files _qt4_options) - SET(${_qt4_files}) - SET(${_qt4_options}) - SET(_QT4_DOING_OPTIONS FALSE) - FOREACH(_currentArg ${ARGN}) - IF ("${_currentArg}" STREQUAL "OPTIONS") - SET(_QT4_DOING_OPTIONS TRUE) - ELSE ("${_currentArg}" STREQUAL "OPTIONS") - IF(_QT4_DOING_OPTIONS) - LIST(APPEND ${_qt4_options} "${_currentArg}") - ELSE(_QT4_DOING_OPTIONS) - LIST(APPEND ${_qt4_files} "${_currentArg}") - ENDIF(_QT4_DOING_OPTIONS) - ENDIF ("${_currentArg}" STREQUAL "OPTIONS") - ENDFOREACH(_currentArg) -ENDMACRO (QT4_EXTRACT_OPTIONS) - - -# macro used to create the names of output files preserving relative dirs -MACRO (QT4_MAKE_OUTPUT_FILE infile prefix ext outfile ) - STRING(LENGTH ${CMAKE_CURRENT_BINARY_DIR} _binlength) - STRING(LENGTH ${infile} _infileLength) - SET(_checkinfile ${CMAKE_CURRENT_SOURCE_DIR}) - IF(_infileLength GREATER _binlength) - STRING(SUBSTRING "${infile}" 0 ${_binlength} _checkinfile) - IF(_checkinfile STREQUAL "${CMAKE_CURRENT_BINARY_DIR}") - FILE(RELATIVE_PATH rel ${CMAKE_CURRENT_BINARY_DIR} ${infile}) - ELSE(_checkinfile STREQUAL "${CMAKE_CURRENT_BINARY_DIR}") - FILE(RELATIVE_PATH rel ${CMAKE_CURRENT_SOURCE_DIR} ${infile}) - ENDIF(_checkinfile STREQUAL "${CMAKE_CURRENT_BINARY_DIR}") - ELSE(_infileLength GREATER _binlength) - FILE(RELATIVE_PATH rel ${CMAKE_CURRENT_SOURCE_DIR} ${infile}) - ENDIF(_infileLength GREATER _binlength) - IF(WIN32 AND rel MATCHES "^[a-zA-Z]:") # absolute path - STRING(REGEX REPLACE "^([a-zA-Z]):(.*)$" "\\1_\\2" rel "${rel}") - ENDIF(WIN32 AND rel MATCHES "^[a-zA-Z]:") - SET(_outfile "${CMAKE_CURRENT_BINARY_DIR}/${rel}") - STRING(REPLACE ".." "__" _outfile ${_outfile}) - GET_FILENAME_COMPONENT(outpath ${_outfile} PATH) - GET_FILENAME_COMPONENT(_outfile ${_outfile} NAME_WE) - FILE(MAKE_DIRECTORY ${outpath}) - SET(${outfile} ${outpath}/${prefix}${_outfile}.${ext}) -ENDMACRO (QT4_MAKE_OUTPUT_FILE ) - - -MACRO (QT4_GET_MOC_FLAGS _moc_flags) - SET(${_moc_flags}) - GET_DIRECTORY_PROPERTY(_inc_DIRS INCLUDE_DIRECTORIES) - - FOREACH(_current ${_inc_DIRS}) - IF("${_current}" MATCHES ".framework/?$") - STRING(REGEX REPLACE "/[^/]+.framework" "" framework_path "${_current}") - SET(${_moc_flags} ${${_moc_flags}} "-F${framework_path}") - ELSE("${_current}" MATCHES ".framework/?$") - SET(${_moc_flags} ${${_moc_flags}} "-I${_current}") - ENDIF("${_current}" MATCHES ".framework/?$") - ENDFOREACH(_current ${_inc_DIRS}) - - GET_DIRECTORY_PROPERTY(_defines COMPILE_DEFINITIONS) - FOREACH(_current ${_defines}) - SET(${_moc_flags} ${${_moc_flags}} "-D${_current}") - ENDFOREACH(_current ${_defines}) - - IF(Q_WS_WIN) - SET(${_moc_flags} ${${_moc_flags}} -DWIN32) - ENDIF(Q_WS_WIN) - -ENDMACRO(QT4_GET_MOC_FLAGS) - - -# helper macro to set up a moc rule -MACRO (QT4_CREATE_MOC_COMMAND infile outfile moc_flags moc_options) - # For Windows, create a parameters file to work around command line length limit - IF (WIN32) - # Pass the parameters in a file. Set the working directory to - # be that containing the parameters file and reference it by - # just the file name. This is necessary because the moc tool on - # MinGW builds does not seem to handle spaces in the path to the - # file given with the @ syntax. - GET_FILENAME_COMPONENT(_moc_outfile_name "${outfile}" NAME) - GET_FILENAME_COMPONENT(_moc_outfile_dir "${outfile}" PATH) - IF(_moc_outfile_dir) - SET(_moc_working_dir WORKING_DIRECTORY ${_moc_outfile_dir}) - ENDIF(_moc_outfile_dir) - SET (_moc_parameters_file ${outfile}_parameters) - SET (_moc_parameters ${moc_flags} ${moc_options} -o "${outfile}" "${infile}") - FILE (REMOVE ${_moc_parameters_file}) - FOREACH(arg ${_moc_parameters}) - FILE (APPEND ${_moc_parameters_file} "${arg}\n") - ENDFOREACH(arg) - ADD_CUSTOM_COMMAND(OUTPUT ${outfile} - COMMAND ${QT_MOC_EXECUTABLE} @${_moc_outfile_name}_parameters - DEPENDS ${infile} - ${_moc_working_dir} - VERBATIM) - ELSE (WIN32) - ADD_CUSTOM_COMMAND(OUTPUT ${outfile} - COMMAND ${QT_MOC_EXECUTABLE} - ARGS ${moc_flags} ${moc_options} -o ${outfile} ${infile} - DEPENDS ${infile}) - ENDIF (WIN32) -ENDMACRO (QT4_CREATE_MOC_COMMAND) - - -MACRO (QT4_GENERATE_MOC infile outfile ) -# get include dirs and flags - QT4_GET_MOC_FLAGS(moc_flags) - GET_FILENAME_COMPONENT(abs_infile ${infile} ABSOLUTE) - QT4_CREATE_MOC_COMMAND(${abs_infile} ${outfile} "${moc_flags}" "") - SET_SOURCE_FILES_PROPERTIES(${outfile} PROPERTIES SKIP_AUTOMOC TRUE) # dont run automoc on this file -ENDMACRO (QT4_GENERATE_MOC) - - -# QT4_WRAP_CPP(outfiles inputfile ... ) - -MACRO (QT4_WRAP_CPP outfiles ) - # get include dirs - QT4_GET_MOC_FLAGS(moc_flags) - QT4_EXTRACT_OPTIONS(moc_files moc_options ${ARGN}) - - FOREACH (it ${moc_files}) - GET_FILENAME_COMPONENT(it ${it} ABSOLUTE) - QT4_MAKE_OUTPUT_FILE(${it} moc_ cxx outfile) - QT4_CREATE_MOC_COMMAND(${it} ${outfile} "${moc_flags}" "${moc_options}") - SET(${outfiles} ${${outfiles}} ${outfile}) - ENDFOREACH(it) - -ENDMACRO (QT4_WRAP_CPP) - - -# QT4_WRAP_UI(outfiles inputfile ... ) - -MACRO (QT4_WRAP_UI outfiles ) - QT4_EXTRACT_OPTIONS(ui_files ui_options ${ARGN}) - - FOREACH (it ${ui_files}) - GET_FILENAME_COMPONENT(outfile ${it} NAME_WE) - GET_FILENAME_COMPONENT(infile ${it} ABSOLUTE) - SET(outfile ${CMAKE_CURRENT_BINARY_DIR}/ui_${outfile}.h) - ADD_CUSTOM_COMMAND(OUTPUT ${outfile} - COMMAND ${QT_UIC_EXECUTABLE} - ARGS ${ui_options} -o ${outfile} ${infile} - MAIN_DEPENDENCY ${infile}) - SET(${outfiles} ${${outfiles}} ${outfile}) - ENDFOREACH (it) - -ENDMACRO (QT4_WRAP_UI) - - -# QT4_ADD_RESOURCES(outfiles inputfile ... ) - -MACRO (QT4_ADD_RESOURCES outfiles ) - QT4_EXTRACT_OPTIONS(rcc_files rcc_options ${ARGN}) - - FOREACH (it ${rcc_files}) - GET_FILENAME_COMPONENT(outfilename ${it} NAME_WE) - GET_FILENAME_COMPONENT(infile ${it} ABSOLUTE) - GET_FILENAME_COMPONENT(rc_path ${infile} PATH) - SET(outfile ${CMAKE_CURRENT_BINARY_DIR}/qrc_${outfilename}.cxx) - # parse file for dependencies - # all files are absolute paths or relative to the location of the qrc file - FILE(READ "${infile}" _RC_FILE_CONTENTS) - STRING(REGEX MATCHALL "]*>" "" _RC_FILE "${_RC_FILE}") - STRING(REGEX MATCH "^/|([A-Za-z]:/)" _ABS_PATH_INDICATOR "${_RC_FILE}") - IF(NOT _ABS_PATH_INDICATOR) - SET(_RC_FILE "${rc_path}/${_RC_FILE}") - ENDIF(NOT _ABS_PATH_INDICATOR) - SET(_RC_DEPENDS ${_RC_DEPENDS} "${_RC_FILE}") - ENDFOREACH(_RC_FILE) - ADD_CUSTOM_COMMAND(OUTPUT ${outfile} - COMMAND ${QT_RCC_EXECUTABLE} - ARGS ${rcc_options} -name ${outfilename} -o ${outfile} ${infile} - MAIN_DEPENDENCY ${infile} - DEPENDS ${_RC_DEPENDS}) - SET(${outfiles} ${${outfiles}} ${outfile}) - ENDFOREACH (it) - -ENDMACRO (QT4_ADD_RESOURCES) - - -MACRO(QT4_ADD_DBUS_INTERFACE _sources _interface _basename) - GET_FILENAME_COMPONENT(_infile ${_interface} ABSOLUTE) - SET(_header ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.h) - SET(_impl ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.cpp) - SET(_moc ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.moc) - - # handling more arguments (as in FindQt4.cmake from KDE4) will come soon, then - # _params will be used for more than just -m - SET(_params -m) - - ADD_CUSTOM_COMMAND(OUTPUT ${_impl} ${_header} - COMMAND ${QT_DBUSXML2CPP_EXECUTABLE} ${_params} -p ${_basename} ${_infile} - DEPENDS ${_infile}) - - SET_SOURCE_FILES_PROPERTIES(${_impl} PROPERTIES SKIP_AUTOMOC TRUE) - - QT4_GENERATE_MOC(${_header} ${_moc}) - - SET(${_sources} ${${_sources}} ${_impl} ${_header} ${_moc}) - MACRO_ADD_FILE_DEPENDENCIES(${_impl} ${_moc}) - -ENDMACRO(QT4_ADD_DBUS_INTERFACE) - - -MACRO(QT4_ADD_DBUS_INTERFACES _sources) - FOREACH (_current_FILE ${ARGN}) - GET_FILENAME_COMPONENT(_infile ${_current_FILE} ABSOLUTE) - # get the part before the ".xml" suffix - STRING(REGEX REPLACE "(.*[/\\.])?([^\\.]+)\\.xml" "\\2" _basename ${_current_FILE}) - STRING(TOLOWER ${_basename} _basename) - QT4_ADD_DBUS_INTERFACE(${_sources} ${_infile} ${_basename}interface) - ENDFOREACH (_current_FILE) -ENDMACRO(QT4_ADD_DBUS_INTERFACES) - - -MACRO(QT4_GENERATE_DBUS_INTERFACE _header) # _customName OPTIONS -some -options ) - QT4_EXTRACT_OPTIONS(_customName _qt4_dbus_options ${ARGN}) - - GET_FILENAME_COMPONENT(_in_file ${_header} ABSOLUTE) - GET_FILENAME_COMPONENT(_basename ${_header} NAME_WE) - - IF (_customName) - SET(_target ${CMAKE_CURRENT_BINARY_DIR}/${_customName}) - ELSE (_customName) - SET(_target ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.xml) - ENDIF (_customName) - - ADD_CUSTOM_COMMAND(OUTPUT ${_target} - COMMAND ${QT_DBUSCPP2XML_EXECUTABLE} ${_qt4_dbus_options} ${_in_file} -o ${_target} - DEPENDS ${_in_file} - ) -ENDMACRO(QT4_GENERATE_DBUS_INTERFACE) - - -MACRO(QT4_ADD_DBUS_ADAPTOR _sources _xml_file _include _parentClass) # _optionalBasename _optionalClassName) - GET_FILENAME_COMPONENT(_infile ${_xml_file} ABSOLUTE) - - SET(_optionalBasename "${ARGV4}") - IF (_optionalBasename) - SET(_basename ${_optionalBasename} ) - ELSE (_optionalBasename) - STRING(REGEX REPLACE "(.*[/\\.])?([^\\.]+)\\.xml" "\\2adaptor" _basename ${_infile}) - STRING(TOLOWER ${_basename} _basename) - ENDIF (_optionalBasename) - - SET(_optionalClassName "${ARGV5}") - SET(_header ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.h) - SET(_impl ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.cpp) - SET(_moc ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.moc) - - IF(_optionalClassName) - ADD_CUSTOM_COMMAND(OUTPUT ${_impl} ${_header} - COMMAND ${QT_DBUSXML2CPP_EXECUTABLE} -m -a ${_basename} -c ${_optionalClassName} -i ${_include} -l ${_parentClass} ${_infile} - DEPENDS ${_infile} - ) - ELSE(_optionalClassName) - ADD_CUSTOM_COMMAND(OUTPUT ${_impl} ${_header} - COMMAND ${QT_DBUSXML2CPP_EXECUTABLE} -m -a ${_basename} -i ${_include} -l ${_parentClass} ${_infile} - DEPENDS ${_infile} - ) - ENDIF(_optionalClassName) - - QT4_GENERATE_MOC(${_header} ${_moc}) - SET_SOURCE_FILES_PROPERTIES(${_impl} PROPERTIES SKIP_AUTOMOC TRUE) - MACRO_ADD_FILE_DEPENDENCIES(${_impl} ${_moc}) - - SET(${_sources} ${${_sources}} ${_impl} ${_header} ${_moc}) -ENDMACRO(QT4_ADD_DBUS_ADAPTOR) - - -MACRO(QT4_AUTOMOC) - QT4_GET_MOC_FLAGS(_moc_INCS) - - SET(_matching_FILES ) - FOREACH (_current_FILE ${ARGN}) - - GET_FILENAME_COMPONENT(_abs_FILE ${_current_FILE} ABSOLUTE) - # if "SKIP_AUTOMOC" is set to true, we will not handle this file here. - # This is required to make uic work correctly: - # we need to add generated .cpp files to the sources (to compile them), - # but we cannot let automoc handle them, as the .cpp files don't exist yet when - # cmake is run for the very first time on them -> however the .cpp files might - # exist at a later run. at that time we need to skip them, so that we don't add two - # different rules for the same moc file - GET_SOURCE_FILE_PROPERTY(_skip ${_abs_FILE} SKIP_AUTOMOC) - - IF ( NOT _skip AND EXISTS ${_abs_FILE} ) - - FILE(READ ${_abs_FILE} _contents) - - GET_FILENAME_COMPONENT(_abs_PATH ${_abs_FILE} PATH) - - STRING(REGEX MATCHALL "# *include +[^ ]+\\.moc[\">]" _match "${_contents}") - IF(_match) - FOREACH (_current_MOC_INC ${_match}) - STRING(REGEX MATCH "[^ <\"]+\\.moc" _current_MOC "${_current_MOC_INC}") - - GET_FILENAME_COMPONENT(_basename ${_current_MOC} NAME_WE) - IF(EXISTS ${_abs_PATH}/${_basename}.hpp) - SET(_header ${_abs_PATH}/${_basename}.hpp) - ELSE(EXISTS ${_abs_PATH}/${_basename}.hpp) - SET(_header ${_abs_PATH}/${_basename}.h) - ENDIF(EXISTS ${_abs_PATH}/${_basename}.hpp) - SET(_moc ${CMAKE_CURRENT_BINARY_DIR}/${_current_MOC}) - QT4_CREATE_MOC_COMMAND(${_header} ${_moc} "${_moc_INCS}" "") - MACRO_ADD_FILE_DEPENDENCIES(${_abs_FILE} ${_moc}) - ENDFOREACH (_current_MOC_INC) - ENDIF(_match) - ENDIF ( NOT _skip AND EXISTS ${_abs_FILE} ) - ENDFOREACH (_current_FILE) -ENDMACRO(QT4_AUTOMOC) - - -MACRO(QT4_CREATE_TRANSLATION _qm_files) - QT4_EXTRACT_OPTIONS(_lupdate_files _lupdate_options ${ARGN}) - SET(_my_sources) - SET(_my_dirs) - SET(_my_tsfiles) - SET(_ts_pro) - FOREACH (_file ${_lupdate_files}) - GET_FILENAME_COMPONENT(_ext ${_file} EXT) - GET_FILENAME_COMPONENT(_abs_FILE ${_file} ABSOLUTE) - IF(_ext MATCHES "ts") - LIST(APPEND _my_tsfiles ${_abs_FILE}) - ELSE(_ext MATCHES "ts") - IF(NOT _ext) - LIST(APPEND _my_dirs ${_abs_FILE}) - ELSE(NOT _ext) - LIST(APPEND _my_sources ${_abs_FILE}) - ENDIF(NOT _ext) - ENDIF(_ext MATCHES "ts") - ENDFOREACH(_file) - FOREACH(_ts_file ${_my_tsfiles}) - IF(_my_sources) - # make a .pro file to call lupdate on, so we don't make our commands too - # long for some systems - GET_FILENAME_COMPONENT(_ts_name ${_ts_file} NAME_WE) - SET(_ts_pro ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_ts_name}_lupdate.pro) - SET(_pro_srcs) - FOREACH(_pro_src ${_my_sources}) - SET(_pro_srcs "${_pro_srcs} \"${_pro_src}\"") - ENDFOREACH(_pro_src ${_my_sources}) - FILE(WRITE ${_ts_pro} "SOURCES = ${_pro_srcs}") - ENDIF(_my_sources) - ADD_CUSTOM_COMMAND(OUTPUT ${_ts_file} - COMMAND ${QT_LUPDATE_EXECUTABLE} - ARGS ${_lupdate_options} ${_ts_pro} ${_my_dirs} -ts ${_ts_file} - DEPENDS ${_my_sources} ${_ts_pro}) - ENDFOREACH(_ts_file) - QT4_ADD_TRANSLATION(${_qm_files} ${_my_tsfiles}) -ENDMACRO(QT4_CREATE_TRANSLATION) - - -MACRO(QT4_ADD_TRANSLATION _qm_files) - FOREACH (_current_FILE ${ARGN}) - GET_FILENAME_COMPONENT(_abs_FILE ${_current_FILE} ABSOLUTE) - GET_FILENAME_COMPONENT(qm ${_abs_FILE} NAME_WE) - GET_SOURCE_FILE_PROPERTY(output_location ${_abs_FILE} OUTPUT_LOCATION) - IF(output_location) - FILE(MAKE_DIRECTORY "${output_location}") - SET(qm "${output_location}/${qm}.qm") - ELSE(output_location) - SET(qm "${CMAKE_CURRENT_BINARY_DIR}/${qm}.qm") - ENDIF(output_location) - - ADD_CUSTOM_COMMAND(OUTPUT ${qm} - COMMAND ${QT_LRELEASE_EXECUTABLE} - ARGS ${_abs_FILE} -qm ${qm} - DEPENDS ${_abs_FILE} - ) - SET(${_qm_files} ${${_qm_files}} ${qm}) - ENDFOREACH (_current_FILE) -ENDMACRO(QT4_ADD_TRANSLATION) diff --git a/Installation/cmake/modules/2.6.2-to-2.8.1/UseQt4.cmake b/Installation/cmake/modules/2.6.2-to-2.8.1/UseQt4.cmake deleted file mode 100644 index a18beaf86e4..00000000000 --- a/Installation/cmake/modules/2.6.2-to-2.8.1/UseQt4.cmake +++ /dev/null @@ -1,93 +0,0 @@ -# - Use Module for QT4 -# Sets up C and C++ to use Qt 4. It is assumed that FindQt.cmake -# has already been loaded. See FindQt.cmake for information on -# how to load Qt 4 into your CMake project. - -#============================================================================= -# Copyright 2005-2009 Kitware, Inc. -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distributed this file outside of CMake, substitute the full -# License text for the above reference.) - -ADD_DEFINITIONS(${QT_DEFINITIONS}) -SET_PROPERTY(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG QT_DEBUG) -SET_PROPERTY(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELEASE QT_NO_DEBUG) -SET_PROPERTY(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELWITHDEBINFO QT_NO_DEBUG) -SET_PROPERTY(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_MINSIZEREL QT_NO_DEBUG) - -INCLUDE_DIRECTORIES(${QT_INCLUDE_DIR}) - -SET(QT_LIBRARIES "") - -IF (QT_USE_QTMAIN) - IF (WIN32) - SET(QT_LIBRARIES ${QT_LIBRARIES} ${QT_QTMAIN_LIBRARY}) - ENDIF (WIN32) -ENDIF (QT_USE_QTMAIN) - -IF(QT_DONT_USE_QTGUI) - SET(QT_USE_QTGUI 0) -ELSE(QT_DONT_USE_QTGUI) - SET(QT_USE_QTGUI 1) -ENDIF(QT_DONT_USE_QTGUI) - -IF(QT_DONT_USE_QTCORE) - SET(QT_USE_QTCORE 0) -ELSE(QT_DONT_USE_QTCORE) - SET(QT_USE_QTCORE 1) -ENDIF(QT_DONT_USE_QTCORE) - -IF (QT_USE_QT3SUPPORT) - ADD_DEFINITIONS(-DQT3_SUPPORT) -ENDIF (QT_USE_QT3SUPPORT) - -# list dependent modules, so dependent libraries are added -SET(QT_QT3SUPPORT_MODULE_DEPENDS QTGUI QTSQL QTXML QTNETWORK QTCORE) -SET(QT_QTSVG_MODULE_DEPENDS QTGUI QTXML QTCORE) -SET(QT_QTUITOOLS_MODULE_DEPENDS QTGUI QTXML QTCORE) -SET(QT_QTHELP_MODULE_DEPENDS QTGUI QTSQL QTXML QTNETWORK QTCORE) -IF(QT_QTDBUS_FOUND) - SET(QT_PHONON_MODULE_DEPENDS QTGUI QTDBUS QTCORE) -ELSE(QT_QTDBUS_FOUND) - SET(QT_PHONON_MODULE_DEPENDS QTGUI QTCORE) -ENDIF(QT_QTDBUS_FOUND) -SET(QT_QTDBUS_MODULE_DEPENDS QTXML QTCORE) -SET(QT_QTXMLPATTERNS_MODULE_DEPENDS QTNETWORK QTCORE) -SET(QT_QAXCONTAINER_MODULE_DEPENDS QTGUI QTCORE) -SET(QT_QAXSERVER_MODULE_DEPENDS QTGUI QTCORE) -SET(QT_QTSCRIPTTOOLS_MODULE_DEPENDS QTGUI QTCORE) - -# Qt modules (in order of dependence) -FOREACH(module QT3SUPPORT QTOPENGL QTASSISTANT QTDESIGNER QTMOTIF QTNSPLUGIN - QAXSERVER QAXCONTAINER QTSCRIPT QTSVG QTUITOOLS QTHELP - QTWEBKIT PHONON QTSCRIPTTOOLS QTGUI QTTEST QTDBUS QTXML QTSQL - QTXMLPATTERNS QTNETWORK QTCORE) - - IF (QT_USE_${module} OR QT_USE_${module}_DEPENDS) - IF (QT_${module}_FOUND) - IF(QT_USE_${module}) - STRING(REPLACE "QT" "" qt_module_def "${module}") - ADD_DEFINITIONS(-DQT_${qt_module_def}_LIB) - INCLUDE_DIRECTORIES(${QT_${module}_INCLUDE_DIR}) - ENDIF(QT_USE_${module}) - SET(QT_LIBRARIES ${QT_LIBRARIES} ${QT_${module}_LIBRARY}) - IF(QT_IS_STATIC) - SET(QT_LIBRARIES ${QT_LIBRARIES} ${QT_${module}_LIB_DEPENDENCIES}) - ENDIF(QT_IS_STATIC) - FOREACH(depend_module ${QT_${module}_MODULE_DEPENDS}) - SET(QT_USE_${depend_module}_DEPENDS 1) - ENDFOREACH(depend_module ${QT_${module}_MODULE_DEPENDS}) - ELSE (QT_${module}_FOUND) - MESSAGE("Qt ${module} library not found.") - ENDIF (QT_${module}_FOUND) - ENDIF (QT_USE_${module} OR QT_USE_${module}_DEPENDS) - -ENDFOREACH(module) - diff --git a/Installation/cmake/modules/CGALConfig_binary.cmake.in b/Installation/cmake/modules/CGALConfig_binary.cmake.in index d9225f861a1..70c6c304956 100644 --- a/Installation/cmake/modules/CGALConfig_binary.cmake.in +++ b/Installation/cmake/modules/CGALConfig_binary.cmake.in @@ -8,6 +8,58 @@ set(CGAL_CONFIG_LOADED TRUE) +get_filename_component(CGAL_CONFIG_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) + +# The else condition of this code is intentionally not present in +# CGALConfig_install.cmake.in since it cannot happen there. +# Note also that for CMake<=2.8.11 (detected by the absence of CMP0024), +# the else() condition is never used. +if(NOT POLICY CMP0024 OR NOT CGAL_BUILDING_LIBS) + include("${CGAL_CONFIG_DIR}/CGALExports.cmake") + + macro(CGAL_get_property_optional VAR TARGET PROPERTY) + if(TARGET ${TARGET}) + get_property(${VAR} TARGET ${TARGET} PROPERTY ${PROPERTY}) + else() + set(${VAR} "") + endif() + endmacro() + + if(NOT MSVC) + CGAL_get_property_optional(CGAL_LIBRARY CGAL::CGAL LOCATION) + CGAL_get_property_optional(CGAL_Core_LIBRARY CGAL::CGAL_Core LOCATION) + CGAL_get_property_optional(CGAL_ImageIO_LIBRARY CGAL::CGAL_ImageIO LOCATION) + CGAL_get_property_optional(CGAL_Qt3_LIBRARY CGAL::CGAL_Qt3 LOCATION) + CGAL_get_property_optional(CGAL_Qt5_LIBRARY CGAL::CGAL_Qt5 LOCATION) + else() + set(CGAL_LIBRARY "") + set(CGAL_Core_LIBRARY "") + set(CGAL_ImageIO_LIBRARY "") + set(CGAL_Qt3_LIBRARY "") + set(CGAL_Qt5_LIBRARY "") + endif() +else() + # We are currently in a CGAL Build and CGALExports.cmake has not + # necessarily been created yet. Just alias the targets. Also don't + # access the LOCATION property here to set lib_LIBRARY, since those + # targets are not imported and this is disallowed by CMP0026. Just + # set it to the target name. + macro(CGAL_alias_library lib) + if(TARGET ${lib} AND NOT TARGET CGAL::${lib}) + add_library(CGAL::${lib} ALIAS ${lib}) + set(${lib}_LIBRARY CGAL::${lib}) + else() + set(${lib}_LIBRARY "") + endif() + endmacro() + + CGAL_alias_library(CGAL) + CGAL_alias_library(CGAL_Core) + CGAL_alias_library(CGAL_ImageIO) + CGAL_alias_library(CGAL_Qt3) + CGAL_alias_library(CGAL_Qt5) +endif() + set(CGAL_INSTALLATION_PACKAGE_DIR "@CGAL_INSTALLATION_PACKAGE_DIR@") set(CGAL_CORE_PACKAGE_DIR "@CGAL_CORE_PACKAGE_DIR@") @@ -39,13 +91,7 @@ set(WITH_CGAL "ON" ) set(WITH_CGAL_Core "@WITH_CGAL_Core@" ) set(WITH_CGAL_ImageIO "@WITH_CGAL_ImageIO@" ) set(WITH_CGAL_Qt3 "@WITH_CGAL_Qt3@" ) -set(WITH_CGAL_Qt4 "@WITH_CGAL_Qt4@" ) - -set(CGAL_LIBRARY "@CGAL_LIBRARY@" ) -set(CGAL_Core_LIBRARY "@CGAL_Core_LIBRARY@" ) -set(CGAL_ImageIO_LIBRARY "@CGAL_ImageIO_LIBRARY@" ) -set(CGAL_Qt3_LIBRARY "@CGAL_Qt3_LIBRARY@" ) -set(CGAL_Qt4_LIBRARY "@CGAL_Qt4_LIBRARY@" ) +set(WITH_CGAL_Qt5 "@WITH_CGAL_Qt5@" ) set(CGAL_3RD_PARTY_INCLUDE_DIRS "@CGAL_3RD_PARTY_INCLUDE_DIRS@" ) set(CGAL_3RD_PARTY_DEFINITIONS "@CGAL_3RD_PARTY_DEFINITIONS@" ) @@ -68,15 +114,14 @@ set(CGAL_Qt3_3RD_PARTY_DEFINITIONS "@CGAL_Qt3_3RD_PARTY_DEFINITIONS@" ) set(CGAL_Qt3_3RD_PARTY_LIBRARIES_DIRS "@CGAL_Qt3_3RD_PARTY_LIBRARIES_DIRS@" ) set(CGAL_Qt3_3RD_PARTY_LIBRARIES "@CGAL_Qt3_3RD_PARTY_LIBRARIES@" ) -set(CGAL_Qt4_3RD_PARTY_INCLUDE_DIRS "@CGAL_Qt4_3RD_PARTY_INCLUDE_DIRS@" ) -set(CGAL_Qt4_3RD_PARTY_DEFINITIONS "@CGAL_Qt4_3RD_PARTY_DEFINITIONS@" ) -set(CGAL_Qt4_3RD_PARTY_LIBRARIES_DIRS "@CGAL_Qt4_3RD_PARTY_LIBRARIES_DIRS@" ) -set(CGAL_Qt4_3RD_PARTY_LIBRARIES "@CGAL_Qt4_3RD_PARTY_LIBRARIES@" ) - +set(CGAL_Qt5_3RD_PARTY_INCLUDE_DIRS "@CGAL_Qt5_3RD_PARTY_INCLUDE_DIRS@" ) +set(CGAL_Qt5_3RD_PARTY_DEFINITIONS "@CGAL_Qt5_3RD_PARTY_DEFINITIONS@" ) +set(CGAL_Qt5_3RD_PARTY_LIBRARIES_DIRS "@CGAL_Qt5_3RD_PARTY_LIBRARIES_DIRS@" ) +set(CGAL_Qt5_3RD_PARTY_LIBRARIES "@CGAL_Qt5_3RD_PARTY_LIBRARIES@" ) set(CGAL_VERSION "${CGAL_MAJOR_VERSION}.${CGAL_MINOR_VERSION}.${CGAL_BUILD_VERSION}") -set(CGAL_USE_FILE "${CGAL_MODULES_DIR}/UseCGAL.cmake" ) +set(CGAL_USE_FILE "${CGAL_MODULES_DIR}/UseCGAL.cmake" ) set(CGAL_ALLOW_ALL_PRECONFIGURED_LIBS_COMPONENT "@CGAL_ALLOW_ALL_PRECONFIGURED_LIBS_COMPONENT@") @@ -106,11 +151,16 @@ macro(check_cgal_component COMPONENT) set( CHECK_CGAL_ERROR_TAIL "" ) else() if ( WITH_${CGAL_LIB} ) - set( ${CGAL_LIB}_FOUND TRUE ) + if(TARGET CGAL::${CGAL_LIB}) + set( ${CGAL_LIB}_FOUND TRUE ) + else() + set( ${CGAL_LIB}_FOUND FALSE ) + set( CHECK_${CGAL_LIB}_ERROR_TAIL " CGAL was configured with WITH_${CGAL_LIB}=ON, but one of the dependencies of ${CGAL_LIB} was not configured properly." ) + endif() else() set( ${CGAL_LIB}_FOUND FALSE ) + set( CHECK_${CGAL_LIB}_ERROR_TAIL " Please configure CGAL using WITH_${CGAL_LIB}=ON." ) endif() - set( CHECK_${CGAL_LIB}_ERROR_TAIL " Please configure CGAL using WITH_${CGAL_LIB}=ON." ) endif() if ( NOT ${CGAL_LIB}_FOUND AND CHECK_CGAL_COMPONENT_MSG_ON_ERROR ) diff --git a/Installation/cmake/modules/CGALConfig_install.cmake.in b/Installation/cmake/modules/CGALConfig_install.cmake.in index 18cea4bfeda..f54cb7e8a41 100644 --- a/Installation/cmake/modules/CGALConfig_install.cmake.in +++ b/Installation/cmake/modules/CGALConfig_install.cmake.in @@ -8,6 +8,9 @@ set(CGAL_CONFIG_LOADED TRUE) +get_filename_component(CGAL_CONFIG_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) +include("${CGAL_CONFIG_DIR}/CGALExports.cmake") + # CGAL_DIR is the directory where this CGALConfig.cmake is installed set(CGAL_INSTALL_PREFIX "@CMAKE_INSTALL_PREFIX@") @@ -39,13 +42,29 @@ set(WITH_CGAL "ON" ) set(WITH_CGAL_Core "@WITH_CGAL_Core@" ) set(WITH_CGAL_ImageIO "@WITH_CGAL_ImageIO@" ) set(WITH_CGAL_Qt3 "@WITH_CGAL_Qt3@" ) -set(WITH_CGAL_Qt4 "@WITH_CGAL_Qt4@" ) +set(WITH_CGAL_Qt5 "@WITH_CGAL_Qt5@" ) -set(CGAL_LIBRARY "@CGAL_LIBRARY_INSTALLED@") -set(CGAL_Core_LIBRARY "@CGAL_Core_LIBRARY_INSTALLED@") -set(CGAL_ImageIO_LIBRARY "@CGAL_ImageIO_LIBRARY_INSTALLED@") -set(CGAL_Qt3_LIBRARY "@CGAL_Qt3_LIBRARY_INSTALLED@") -set(CGAL_Qt4_LIBRARY "@CGAL_Qt4_LIBRARY_INSTALLED@") +macro(CGAL_get_property_optional VAR TARGET PROPERTY) + if(TARGET ${TARGET}) + get_property(${VAR} TARGET ${TARGET} PROPERTY ${PROPERTY}) + else() + set(${VAR} "") + endif() +endmacro() + +if(NOT MSVC) + CGAL_get_property_optional(CGAL_LIBRARY CGAL::CGAL LOCATION) + CGAL_get_property_optional(CGAL_Core_LIBRARY CGAL::CGAL_Core LOCATION) + CGAL_get_property_optional(CGAL_ImageIO_LIBRARY CGAL::CGAL_ImageIO LOCATION) + CGAL_get_property_optional(CGAL_Qt3_LIBRARY CGAL::CGAL_Qt3 LOCATION) + CGAL_get_property_optional(CGAL_Qt5_LIBRARY CGAL::CGAL_Qt5 LOCATION) +else() + set(CGAL_LIBRARY "") + set(CGAL_Core_LIBRARY "") + set(CGAL_ImageIO_LIBRARY "") + set(CGAL_Qt3_LIBRARY "") + set(CGAL_Qt5_LIBRARY "") +endif() set(CGAL_3RD_PARTY_INCLUDE_DIRS "@CGAL_3RD_PARTY_INCLUDE_DIRS@" ) set(CGAL_3RD_PARTY_DEFINITIONS "@CGAL_3RD_PARTY_DEFINITIONS@" ) @@ -68,10 +87,10 @@ set(CGAL_Qt3_3RD_PARTY_DEFINITIONS "@CGAL_Qt3_3RD_PARTY_DEFINITIONS@" ) set(CGAL_Qt3_3RD_PARTY_LIBRARIES_DIRS "@CGAL_Qt3_3RD_PARTY_LIBRARIES_DIRS@" ) set(CGAL_Qt3_3RD_PARTY_LIBRARIES "@CGAL_Qt3_3RD_PARTY_LIBRARIES@" ) -set(CGAL_Qt4_3RD_PARTY_INCLUDE_DIRS "@CGAL_Qt4_3RD_PARTY_INCLUDE_DIRS@" ) -set(CGAL_Qt4_3RD_PARTY_DEFINITIONS "@CGAL_Qt4_3RD_PARTY_DEFINITIONS@" ) -set(CGAL_Qt4_3RD_PARTY_LIBRARIES_DIRS "@CGAL_Qt4_3RD_PARTY_LIBRARIES_DIRS@" ) -set(CGAL_Qt4_3RD_PARTY_LIBRARIES "@CGAL_Qt4_3RD_PARTY_LIBRARIES@" ) +set(CGAL_Qt5_3RD_PARTY_INCLUDE_DIRS "@CGAL_Qt5_3RD_PARTY_INCLUDE_DIRS@" ) +set(CGAL_Qt5_3RD_PARTY_DEFINITIONS "@CGAL_Qt5_3RD_PARTY_DEFINITIONS@" ) +set(CGAL_Qt5_3RD_PARTY_LIBRARIES_DIRS "@CGAL_Qt5_3RD_PARTY_LIBRARIES_DIRS@" ) +set(CGAL_Qt5_3RD_PARTY_LIBRARIES "@CGAL_Qt5_3RD_PARTY_LIBRARIES@" ) set(CGAL_VERSION "${CGAL_MAJOR_VERSION}.${CGAL_MINOR_VERSION}.${CGAL_BUILD_VERSION}") @@ -105,11 +124,16 @@ macro(check_cgal_component COMPONENT) set( CHECK_CGAL_ERROR_TAIL "" ) else() if ( WITH_${CGAL_LIB} ) - set( ${CGAL_LIB}_FOUND TRUE ) + if(TARGET CGAL::${CGAL_LIB}) + set( ${CGAL_LIB}_FOUND TRUE ) + else() + set( ${CGAL_LIB}_FOUND FALSE ) + set( CHECK_${CGAL_LIB}_ERROR_TAIL " CGAL was configured with WITH_${CGAL_LIB}=ON, but one of the dependencies of ${CGAL_LIB} was not configured properly." ) + endif() else() set( ${CGAL_LIB}_FOUND FALSE ) + set( CHECK_${CGAL_LIB}_ERROR_TAIL " Please configure CGAL using WITH_${CGAL_LIB}=ON." ) endif() - set( CHECK_${CGAL_LIB}_ERROR_TAIL " Please configure CGAL using WITH_${CGAL_LIB}=ON." ) endif() if ( NOT ${CGAL_LIB}_FOUND AND CHECK_CGAL_COMPONENT_MSG_ON_ERROR ) diff --git a/Installation/cmake/modules/CGAL_Macros.cmake b/Installation/cmake/modules/CGAL_Macros.cmake index e2b3264e0d9..2400480c77b 100644 --- a/Installation/cmake/modules/CGAL_Macros.cmake +++ b/Installation/cmake/modules/CGAL_Macros.cmake @@ -222,7 +222,7 @@ if( NOT CGAL_MACROS_FILE_INCLUDED ) message (STATUS "Configured ${lib} from UseLIB-file: ${usefile}") # UseLIB-file has to set ${vlib}_SETUP to TRUE - # TODO EBEB what about Qt4, Qt3, zlib? + # TODO EBEB what about Qt5, Qt3, zlib? else() @@ -282,18 +282,18 @@ if( NOT CGAL_MACROS_FILE_INCLUDED ) # Nothing to add for Core if (${component} STREQUAL "ImageIO") - find_package( OpenGL ) - find_package( ZLIB ) + find_package( OpenGL QUIET ) + find_package( ZLIB QUIET ) endif() if (${component} STREQUAL "Qt3") - find_package( OpenGL ) - find_package( Qt3-patched ) + find_package( OpenGL QUIET ) + find_package( Qt3-patched QUIET ) endif() - if (${component} STREQUAL "Qt4") - find_package( OpenGL ) - find_package( Qt4 ) + if (${component} STREQUAL "Qt5") + find_package( OpenGL QUIET ) + find_package( Qt5 QUIET COMPONENTS OpenGL Svg ) endif() else(WITH_CGAL_${component}) @@ -332,7 +332,20 @@ if( NOT CGAL_MACROS_FILE_INCLUDED ) else() ####message( STATUS "External library ${component} has not been preconfigured") - find_package( ${component} ) + if (${component} STREQUAL "ImageIO") + find_package( OpenGL ) + find_package( ZLIB ) + endif() + + if (${component} STREQUAL "Qt3") + find_package( OpenGL ) + find_package( Qt3-patched ) + endif() + if (${component} STREQUAL "Qt5") + set(CGAL_${component}_FOUND TRUE) + find_package( OpenGL ) + find_package (Qt5 COMPONENTS OpenGL Gui Core Script ScriptTools) + endif() ####message( STATUS "External library ${vlib} after find") if (${vlib}_FOUND) ####message( STATUS "External library ${vlib} about to be used") @@ -399,20 +412,6 @@ if( NOT CGAL_MACROS_FILE_INCLUDED ) # Where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked set(CGAL_CMAKE_MODULE_PATH ${CGAL_MODULES_DIR}) - # Use FindQt4 from CMake-2.8.1 if 2.6.2 <= CMake <= 2.8.1 - if(CMAKE_VERSION) - is_version_less("2.6.1" "${CMAKE_VERSION}" CMAKE_VERSION_BETWEEN_2_6_2_AND_2_8_1) - else() - # It seems CMake <= 2.6.1 does not has that CMAKE_VERSION - set(CMAKE_VERSION_BETWEEN_2_6_2_AND_2_8_1 FALSE) - endif() - if(CMAKE_VERSION_BETWEEN_2_6_2_AND_2_8_1) - is_version_less(${CMAKE_VERSION} "2.8.2" CMAKE_VERSION_BETWEEN_2_6_2_AND_2_8_1) - if(CMAKE_VERSION_BETWEEN_2_6_2_AND_2_8_1) - set(CGAL_CMAKE_MODULE_PATH ${CGAL_CMAKE_MODULE_PATH} ${CGAL_MODULES_DIR}/2.6.2-to-2.8.1) - endif() - endif() - set(ORIGINAL_CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} PARENT_SCOPE) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CGAL_CMAKE_MODULE_PATH}) diff --git a/Installation/cmake/modules/CGAL_SetupDependencies.cmake b/Installation/cmake/modules/CGAL_SetupDependencies.cmake index f4697fc332f..f15626f2a70 100644 --- a/Installation/cmake/modules/CGAL_SetupDependencies.cmake +++ b/Installation/cmake/modules/CGAL_SetupDependencies.cmake @@ -38,7 +38,7 @@ foreach (lib ${CGAL_SUPPORTING_3RD_PARTY_LIBRARIES}) use_lib( ${vlib} ${${vlib}_USE_FILE}) endif() - # TODO EBEB what about Qt3, Qt4, zlib etc? + # TODO EBEB what about Qt3, Qt5, zlib etc? set ( CGAL_USE_${vlib} TRUE ) diff --git a/Mesh_3/demo/Mesh_3/cmake/modules/FindGLEW.cmake b/Installation/cmake/modules/FindGLEW.cmake similarity index 85% rename from Mesh_3/demo/Mesh_3/cmake/modules/FindGLEW.cmake rename to Installation/cmake/modules/FindGLEW.cmake index cc659f5a2b1..43d2de75abb 100644 --- a/Mesh_3/demo/Mesh_3/cmake/modules/FindGLEW.cmake +++ b/Installation/cmake/modules/FindGLEW.cmake @@ -1,8 +1,8 @@ -# Copyright (c) 2009 Boudewijn Rempt -# -# Redistribution and use is allowed according to the terms of the BSD license. -# For details see the accompanying COPYING-CMAKE-SCRIPTS file. -# +# Copyright (c) 2009 Boudewijn Rempt +# +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. +# # - try to find glew library and include files # GLEW_INCLUDE_DIR, where to find GL/glew.h, etc. # GLEW_LIBRARIES, the libraries to link against @@ -24,7 +24,7 @@ IF (WIN32) ELSE(CYGWIN) - + FIND_PATH( GLEW_INCLUDE_DIR GL/glew.h $ENV{GLEW_ROOT_PATH}/include ) diff --git a/Installation/cmake/modules/FindQGLViewer.cmake b/Installation/cmake/modules/FindQGLViewer.cmake index 65723d675cc..e769d9e196f 100644 --- a/Installation/cmake/modules/FindQGLViewer.cmake +++ b/Installation/cmake/modules/FindQGLViewer.cmake @@ -7,33 +7,47 @@ # QGLVIEWER_DEFINITIONS - Compiler switches required for using QGLViewer # -find_path(QGLVIEWER_INCLUDE_DIR +# first look in user defined locations +find_path(QGLVIEWER_INCLUDE_DIR NAMES QGLViewer/qglviewer.h - PATHS /usr/include + NO_DEFAULT_PATH + PATHS ENV QGLVIEWERROOT /usr/local/include - ENV QGLVIEWERROOT ) -find_library(QGLVIEWER_LIBRARY_RELEASE - NAMES qglviewer-qt4 qglviewer QGLViewer QGLViewer2 - PATHS /usr/lib - /usr/local/lib - ENV QGLVIEWERROOT +find_library(QGLVIEWER_LIBRARY_RELEASE + NAMES qglviewer-qt5 qglviewer QGLViewer-qt5 QGLViewer QGLViewer2-qt5 QGLViewer2 + NO_DEFAULT_PATH + PATHS ENV QGLVIEWERROOT ENV LD_LIBRARY_PATH ENV LIBRARY_PATH + /usr/local/lib PATH_SUFFIXES QGLViewer QGLViewer/release ) find_library(QGLVIEWER_LIBRARY_DEBUG - NAMES dqglviewer dQGLViewer dQGLViewer2 QGLViewerd2 - PATHS /usr/lib - /usr/local/lib + NAMES dqglviewer dQGLViewer-qt5 dQGLViewer dQGLViewer2-qt5 dQGLViewer2 QGLViewerd2-qt5 QGLViewerd2 + NO_DEFAULT_PATH + PATHS /usr/local/lib ENV QGLVIEWERROOT ENV LD_LIBRARY_PATH ENV LIBRARY_PATH - PATH_SUFFIXES QGLViewer QGLViewer/debug + PATH_SUFFIXES QGLViewer QGLViewer/debug ) +#now try the standard paths +if (NOT QGLVIEWER_INCLUDE_DIR OR NOT QGLVIEWER_LIBRARY_RELEASE OR NOT QGLVIEWER_LIBRARY_DEBUG) +find_path(QGLVIEWER_INCLUDE_DIR + NAMES QGLViewer/qglviewer.h) + +find_library(QGLVIEWER_LIBRARY_RELEASE + NAMES qglviewer-qt5 qglviewer QGLViewer-qt5 QGLViewer QGLViewer2-qt5 QGLViewer2) + +find_library(QGLVIEWER_LIBRARY_DEBUG + NAMES dqglviewer dQGLViewer-qt5 dQGLViewer dQGLViewer2-qt5 dQGLViewer2 QGLViewerd2-qt5 QGLViewerd2) + +endif() + if(QGLVIEWER_LIBRARY_RELEASE) if(QGLVIEWER_LIBRARY_DEBUG) set(QGLVIEWER_LIBRARIES_ optimized ${QGLVIEWER_LIBRARY_RELEASE} debug ${QGLVIEWER_LIBRARY_DEBUG}) diff --git a/Installation/cmake/modules/Qt3Macros-patched.cmake b/Installation/cmake/modules/Qt3Macros-patched.cmake index b630cc4f85b..b1384d5ac80 100644 --- a/Installation/cmake/modules/Qt3Macros-patched.cmake +++ b/Installation/cmake/modules/Qt3Macros-patched.cmake @@ -3,7 +3,7 @@ # macro QT3_AUTOMOC(inputfile ... ) # macro QT3_GENERATE_MOC(inputfile outputfile ) # -# Adapted to Qt3 and CGAL from FindQt4.cmake (included in CMake 2.4) +# Adapted to Qt3 for compatibility with Qt5 and CGAL INCLUDE(AddFileDependencies) diff --git a/Installation/cmake/modules/UseCGAL.cmake b/Installation/cmake/modules/UseCGAL.cmake index 38846676fa0..5e0f63a5ada 100644 --- a/Installation/cmake/modules/UseCGAL.cmake +++ b/Installation/cmake/modules/UseCGAL.cmake @@ -42,10 +42,6 @@ if(NOT USE_CGAL_FILE_INCLUDED) include_directories( "${CMAKE_CURRENT_BINARY_DIR}" ) - # need to get variable from cache while compiling CGAL, while in a demo it is set in CGALConfig.cmake - if ( NOT CGAL_LIBRARY ) - cache_get(CGAL_LIBRARY) - endif() if(TARGET CGAL) add_to_list( CGAL_LIBRARIES CGAL ) else() diff --git a/Installation/config/support/print_QT4_version.cpp b/Installation/config/support/print_QT4_version.cpp index 2398f507795..b472210f151 100644 --- a/Installation/config/support/print_QT4_version.cpp +++ b/Installation/config/support/print_QT4_version.cpp @@ -14,7 +14,7 @@ // $URL$ // $Id$ -// Tests if QT4 is available and prints its version string. +// Tests if QT5 is available and prints its version string. #include #include diff --git a/Installation/demo/CMakeLists.txt b/Installation/demo/CMakeLists.txt index b68c7281df9..4f63a6f4b22 100644 --- a/Installation/demo/CMakeLists.txt +++ b/Installation/demo/CMakeLists.txt @@ -1,6 +1,6 @@ project(CGAL_DEMOS) -cmake_minimum_required(VERSION 2.6.2) +cmake_minimum_required(VERSION 2.8.11) if (CGAL_BRANCH_BUILD) diff --git a/Installation/examples/CMakeLists.txt b/Installation/examples/CMakeLists.txt index ace7a8c86b9..dff3deb7300 100644 --- a/Installation/examples/CMakeLists.txt +++ b/Installation/examples/CMakeLists.txt @@ -1,6 +1,6 @@ project(CGAL_EXAMPLES) -cmake_minimum_required(VERSION 2.6.2) +cmake_minimum_required(VERSION 2.8.11) if (CGAL_BRANCH_BUILD) diff --git a/Installation/src/CMakeLists.txt b/Installation/src/CMakeLists.txt index ff31b802b6c..e63014b3ac4 100644 --- a/Installation/src/CMakeLists.txt +++ b/Installation/src/CMakeLists.txt @@ -47,14 +47,7 @@ function (collect_cgal_library LIBRARY_NAME ADDITIONAL_FILES) SOVERSION "${CGAL_SONAME_VERSION}") endif() - if (NOT CGAL_AUTO_LINK_ENABLED ) - get_target_property( ${LIBRARY_NAME}_LIBRARY_FULL_PATH ${LIBRARY_NAME} LOCATION ) - - set(${LIBRARY_NAME}_LIBRARY ${${LIBRARY_NAME}_LIBRARY_FULL_PATH} CACHE STRING "The ${LIBRARY_NAME} library" FORCE) - mark_as_advanced(${LIBRARY_NAME}_LIBRARY) - else(NOT CGAL_AUTO_LINK_ENABLED) - set(${LIBRARY_NAME}_LIBRARY) - + if(CGAL_AUTO_LINK_ENABLED) set_target_properties( ${LIBRARY_NAME} PROPERTIES OUTPUT_NAME_DEBUG "${DEBUG_MANGLED_NAME}" OUTPUT_NAME_RELEASE "${RELEASE_MANGLED_NAME}" @@ -67,9 +60,9 @@ function (collect_cgal_library LIBRARY_NAME ADDITIONAL_FILES) add_custom_command(TARGET ${LIBRARY_NAME} POST_BUILD COMMAND if exist \"$(TargetDir)$(TargetName).pdb\" copy /Y \"$(TargetDir)$(TargetName).pdb\" \"$(TargetDir)..\" ) add_custom_command(TARGET ${LIBRARY_NAME} POST_BUILD COMMAND if exist \"$(SolutionDir)lib\\$(ConfigurationName)\\$(TargetName).lib\" copy /Y \"$(SolutionDir)lib\\$(ConfigurationName)\\$(TargetName).lib\" \"$(SolutionDir)lib\" ) endif() - endif(NOT CGAL_AUTO_LINK_ENABLED) + endif() - install(TARGETS ${LIBRARY_NAME} + install(TARGETS ${LIBRARY_NAME} EXPORT CGALExports RUNTIME DESTINATION ${CGAL_INSTALL_BIN_DIR} LIBRARY DESTINATION ${CGAL_INSTALL_LIB_DIR} ARCHIVE DESTINATION ${CGAL_INSTALL_LIB_DIR}) @@ -164,5 +157,26 @@ list(REMOVE_DUPLICATES CGAL_CONFIGURED_LIBRARIES) list(SORT CGAL_CONFIGURED_LIBRARIES) cache_set(CGAL_CONFIGURED_LIBRARIES "${CGAL_CONFIGURED_LIBRARIES}") +# CGAL_CONFIGURED_LIBRARIES is a virtually useless variable, because +# we do not know if those components actually created a target. It +# might seem bad that we hardcode the target names here, but they have +# always been hardcoded in the CGALConfig files, so we do not make it +# any worse. We can also not use export(EXPORT) since that is only +# available in newer CMake versions. +set(CGAL_ACTUAL_CONFIGURED_LIBRARIES "") +macro(CGAL_add_if_target TARGET) + if(TARGET ${TARGET}) + list(APPEND CGAL_ACTUAL_CONFIGURED_LIBRARIES ${TARGET}) + endif() +endmacro() + +CGAL_add_if_target(CGAL) +CGAL_add_if_target(CGAL_Core) +CGAL_add_if_target(CGAL_ImageIO) +CGAL_add_if_target(CGAL_Qt3) +CGAL_add_if_target(CGAL_Qt5) + +export(TARGETS ${CGAL_ACTUAL_CONFIGURED_LIBRARIES} NAMESPACE CGAL:: FILE "${CMAKE_BINARY_DIR}/CGALExports.cmake") + message(STATUS "Sources for CGAL component libraries '${CGAL_CONFIGURED_LIBRARIES}' detected") diff --git a/Installation/test/CMakeLists.txt b/Installation/test/CMakeLists.txt index f60aa41f777..c2ae63e9335 100644 --- a/Installation/test/CMakeLists.txt +++ b/Installation/test/CMakeLists.txt @@ -1,6 +1,6 @@ project(CGAL_TESTS) -cmake_minimum_required(VERSION 2.6.2) +cmake_minimum_required(VERSION 2.8.11) if (CGAL_BRANCH_BUILD) diff --git a/Installation/test/Installation/CMakeLists.txt b/Installation/test/Installation/CMakeLists.txt index 4d28a023356..b3cfaa73b75 100644 --- a/Installation/test/Installation/CMakeLists.txt +++ b/Installation/test/Installation/CMakeLists.txt @@ -4,12 +4,8 @@ project( Installation_test ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) -endif() +cmake_minimum_required(VERSION 2.8.11) + macro(create_link_to_program COMPONENT ) @@ -25,7 +21,7 @@ macro(create_link_to_program COMPONENT ) if ( CGAL_AUTO_LINK_ENABLED ) target_link_libraries(link_to_${COMPONENT} ${CGAL_3RD_PARTY_LIBRARIES} ${${COMPONENT}_3RD_PARTY_LIBRARIES} ) else() - target_link_libraries(link_to_${COMPONENT} ${${COMPONENT}_LIBRARY} ${CGAL_3RD_PARTY_LIBRARIES} ${${COMPONENT}_3RD_PARTY_LIBRARIES} ) + target_link_libraries(link_to_${COMPONENT} CGAL::${COMPONENT} ${CGAL_3RD_PARTY_LIBRARIES} ${${COMPONENT}_3RD_PARTY_LIBRARIES} ) endif() endmacro() @@ -73,6 +69,14 @@ if ( CGAL_FOUND ) endif() endif() + if ( WITH_CGAL_Qt5 ) + find_package(Qt5 QUIET) + if( Qt5_FOUND ) + create_link_to_program(CGAL_Qt5) + qt5_use_modules(link_to_CGAL_Qt5) + endif() + endif() + if(WIN32) add_executable(test_gmp_mpfr_dll test_gmp_mpfr_dll.cpp) target_link_libraries(test_gmp_mpfr_dll Version) diff --git a/Installation/test/Installation/link_to_CGAL_Qt5.cpp b/Installation/test/Installation/link_to_CGAL_Qt5.cpp new file mode 100644 index 00000000000..f83cad15705 --- /dev/null +++ b/Installation/test/Installation/link_to_CGAL_Qt5.cpp @@ -0,0 +1,11 @@ +// Use something defined not in headers but in the CGAL library to test that is was indeed properly built and linked to, + +#include + +typedef QRectF (*mapToSceneFunction)(const QGraphicsView* , const QRect); + +int main() +{ + mapToSceneFunction f = CGAL::Qt::mapToScene; + return (&f > 0) ? 0 : 1; +} diff --git a/Interpolation/demo/Interpolation/CMakeLists.txt b/Interpolation/demo/Interpolation/CMakeLists.txt index 00dd4384629..a10b1d78f46 100644 --- a/Interpolation/demo/Interpolation/CMakeLists.txt +++ b/Interpolation/demo/Interpolation/CMakeLists.txt @@ -4,11 +4,9 @@ project( Interpolation_ ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() find_package(CGAL QUIET COMPONENTS Core ) diff --git a/Jet_fitting_3/examples/Jet_fitting_3/CMakeLists.txt b/Jet_fitting_3/examples/Jet_fitting_3/CMakeLists.txt index 6f13a4a4e52..c75cc60aed3 100644 --- a/Jet_fitting_3/examples/Jet_fitting_3/CMakeLists.txt +++ b/Jet_fitting_3/examples/Jet_fitting_3/CMakeLists.txt @@ -4,12 +4,8 @@ project( Jet_fitting_3_example ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) -endif() +cmake_minimum_required(VERSION 2.8.11) + find_package(CGAL QUIET COMPONENTS Core ) diff --git a/Jet_fitting_3/test/Jet_fitting_3/CMakeLists.txt b/Jet_fitting_3/test/Jet_fitting_3/CMakeLists.txt index 1f4dcd55358..902df27f4aa 100644 --- a/Jet_fitting_3/test/Jet_fitting_3/CMakeLists.txt +++ b/Jet_fitting_3/test/Jet_fitting_3/CMakeLists.txt @@ -4,12 +4,8 @@ project( Jet_fitting_3_test ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) -endif() +cmake_minimum_required(VERSION 2.8.11) + find_package(CGAL QUIET COMPONENTS Core ) diff --git a/Kinetic_data_structures/demo/Kinetic_data_structures/CMakeLists.txt b/Kinetic_data_structures/demo/Kinetic_data_structures/CMakeLists.txt index ec53a19c986..446f4ed3fbf 100644 --- a/Kinetic_data_structures/demo/Kinetic_data_structures/CMakeLists.txt +++ b/Kinetic_data_structures/demo/Kinetic_data_structures/CMakeLists.txt @@ -2,11 +2,9 @@ project( Kinetic_data_structures_demo ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() find_package(CGAL COMPONENTS Qt3 Core) @@ -19,7 +17,7 @@ if ( CGAL_FOUND ) find_package(Qt3-patched ) # FindQt3-patched.cmake is FindQt3.cmake patched by CGAL developers, so - # that it can be used together with FindQt4: all its variables are prefixed + # that it can be used together with Qt5: all its variables are prefixed # by "QT3_" instead of "QT_". if(CGAL_Qt3_FOUND AND QT3_FOUND) diff --git a/Linear_cell_complex/benchmark/Linear_cell_complex_2/CMakeLists.txt b/Linear_cell_complex/benchmark/Linear_cell_complex_2/CMakeLists.txt index 2d0b326423d..3baf4250adc 100644 --- a/Linear_cell_complex/benchmark/Linear_cell_complex_2/CMakeLists.txt +++ b/Linear_cell_complex/benchmark/Linear_cell_complex_2/CMakeLists.txt @@ -1,6 +1,6 @@ project(LCC_performance_2) -cmake_minimum_required(VERSION 2.6.2) +cmake_minimum_required(VERSION 2.8.11) set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/) diff --git a/Linear_cell_complex/benchmark/Linear_cell_complex_3/CMakeLists.txt b/Linear_cell_complex/benchmark/Linear_cell_complex_3/CMakeLists.txt index 82698c9694e..5d328b3c7e1 100644 --- a/Linear_cell_complex/benchmark/Linear_cell_complex_3/CMakeLists.txt +++ b/Linear_cell_complex/benchmark/Linear_cell_complex_3/CMakeLists.txt @@ -1,6 +1,9 @@ project(LCC_performance_3) -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) +endif() find_package(CGAL REQUIRED) include(${CGAL_USE_FILE}) diff --git a/Linear_cell_complex/demo/Linear_cell_complex/CMakeLists.txt b/Linear_cell_complex/demo/Linear_cell_complex/CMakeLists.txt index 0e631ae48d5..00a9cb20db1 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/CMakeLists.txt +++ b/Linear_cell_complex/demo/Linear_cell_complex/CMakeLists.txt @@ -4,11 +4,14 @@ project (Linear_cell_complex_3_demo) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +# Find includes in corresponding build directories +set(CMAKE_INCLUDE_CURRENT_DIR ON) +# Instruct CMake to run moc automatically when needed. +set(CMAKE_AUTOMOC ON) + +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() ## To add expensive tests @@ -27,40 +30,34 @@ endif() add_definitions(-DCGAL_PROFILE_LCC_DEMO) ################## -find_package(CGAL COMPONENTS Qt4) +find_package(CGAL COMPONENTS Qt5) include(${CGAL_USE_FILE}) -set( QT_USE_QTXML TRUE ) -set( QT_USE_QTMAIN TRUE ) -set( QT_USE_QTSCRIPT TRUE ) -set( QT_USE_QTOPENGL TRUE ) -find_package(Qt4) +find_package(Qt5 QUIET COMPONENTS Xml Script OpenGL Svg) find_package(OpenGL) find_package(QGLViewer) -if ( NOT (CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND AND +if ( NOT (CGAL_FOUND AND CGAL_Qt5_FOUND AND Qt5_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) ) MESSAGE(STATUS "NOTICE: This demo requires CGAL, QGLViewer, OpenGL " - "and Qt4, and will not be compiled.") + "and Qt5, and will not be compiled.") else() add_definitions(-DQT_NO_KEYWORDS) -include(${QT_USE_FILE}) include_directories(${QGLVIEWER_INCLUDE_DIR}) include_directories(BEFORE . ../../include/) # ui file, created wih Qt Designer -qt4_wrap_ui(uis MainWindow.ui CreateMesh.ui CreateMenger.ui +qt5_wrap_ui(uis MainWindow.ui CreateMesh.ui CreateMenger.ui CreateSierpinskiCarpet.ui CreateSierpinskiTriangle.ui) # qrc files (resources files, that contain icons, at least) -qt4_add_resources (RESOURCE_FILES ./Linear_cell_complex_3.qrc) +qt5_add_resources (RESOURCE_FILES ./Linear_cell_complex_3.qrc) -qt4_automoc(MainWindow.cpp Viewer.cpp) add_executable(Linear_cell_complex_3_demo Linear_cell_complex_3_demo.cpp MainWindow.cpp @@ -68,6 +65,7 @@ add_executable(Linear_cell_complex_3_demo Linear_cell_complex_pqq_subdivision.cpp ${uis} ${RESOURCE_FILES} ) +qt5_use_modules(Linear_cell_complex_3_demo Xml Script OpenGL Svg) add_to_cached_list(CGAL_EXECUTABLE_TARGETS Linear_cell_complex_3_demo) target_link_libraries(Linear_cell_complex_3_demo ${CGAL_LIBRARIES} diff --git a/Linear_cell_complex/demo/Linear_cell_complex/Linear_cell_complex_3_demo.cpp b/Linear_cell_complex/demo/Linear_cell_complex/Linear_cell_complex_3_demo.cpp index 52a205c5053..76f8b42843e 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/Linear_cell_complex_3_demo.cpp +++ b/Linear_cell_complex/demo/Linear_cell_complex/Linear_cell_complex_3_demo.cpp @@ -36,11 +36,14 @@ int main(int argc, char** argv) application.setOrganizationDomain("cgal.org"); application.setOrganizationName("CNRS and LIRIS' Establishments"); application.setApplicationName("3D Linear Cell Complex"); + //for windows + application.setAttribute(Qt::AA_UseDesktopOpenGL); - // Import resources from libCGALQt4. - // See http://doc.trolltech.com/4.4/qdir.html#Q_INIT_RESOURCE - CGAL_Qt4_init_resources(); // that function is in a DLL + // Import resources from libCGALQt5 + // See http://doc.qt.io/qt-5/qdir.html#Q_INIT_RESOURCE + CGAL_Qt_init_resources();// that function is in a DLL Q_INIT_RESOURCE(Linear_cell_complex_3); + MainWindow mw; mw.show(); diff --git a/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp b/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp index 85a65cb06cc..6d69509b8bf 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp +++ b/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp @@ -44,7 +44,7 @@ MainWindow::MainWindow (QWidget * parent):CGAL::Qt::DemosMainWindow (parent), setupUi (this); scene.lcc = new LCC; - + volumeListDock = new QDockWidget(QString(tr("Volume List")),this); volumeListDock->setAllowedAreas(Qt::RightDockWidgetArea | Qt::LeftDockWidgetArea); @@ -63,7 +63,9 @@ MainWindow::MainWindow (QWidget * parent):CGAL::Qt::DemosMainWindow (parent), /* volumeList->setColumnWidth(0,85); volumeList->setColumnWidth(1,35); volumeList->setColumnWidth(2,35);*/ - volumeList->horizontalHeader()->setResizeMode(QHeaderView::Stretch); + + volumeList->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); + volumeList->setSelectionMode(QAbstractItemView::NoSelection); //volumeList->setSelectionBehavior(QAbstractItemView::SelectRows); volumeListDock->setWidget(volumeList); diff --git a/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp b/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp index 2840bb5b4f9..6f3a9cab35e 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp +++ b/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp @@ -24,10 +24,640 @@ #include #include +#include +#include +#include +#include +#include +#include +#include +#include + +typedef LCC::Traits Traits; +typedef CGAL::Triangulation_2_filtered_projection_traits_3 P_traits; +struct Face_info { + LCC::Dart_handle e[3]; + bool is_external; +}; +typedef CGAL::Triangulation_vertex_base_with_info_2 Vb; +typedef CGAL::Triangulation_face_base_with_info_2 Fb1; +typedef CGAL::Constrained_triangulation_face_base_2 Fb; +typedef CGAL::Triangulation_data_structure_2 TDS; +typedef CGAL::No_intersection_tag Itag; +typedef CGAL::Constrained_Delaunay_triangulation_2 CDTbase; +typedef CGAL::Constrained_triangulation_plus_2 CDT; + +Viewer::Viewer(QWidget* parent) + : QGLViewer(CGAL::Qt::createOpenGLContext(),parent), wireframe(false), flatShading(true), + edges(true), vertices(true), m_displayListCreated(false) +{ + QGLFormat newFormat = this->format(); + newFormat.setSampleBuffers(true); + newFormat.setSamples(16); + this->setFormat(newFormat); + are_buffers_initialized = false; +} +//Make sure all the facets are triangles +bool +Viewer::is_Triangulated() +{ + + LCC &lcc = *scene->lcc; + for (LCC::Attribute_range<3>::type::iterator + it=lcc.attributes<3>().begin(), + itend=lcc.attributes<3>().end(); it!=itend; ++it ) + { + + for(LCC::One_dart_per_incident_cell_range<2,3>::iterator + dartIter=lcc.one_dart_per_incident_cell<2,3> + (lcc.dart_of_attribute<3>(it)).begin(); dartIter.cont(); ++dartIter) + { + int nb_points_per_facet =0; + for (LCC::Dart_of_orbit_range<1>::const_iterator + orbitIter = lcc.darts_of_orbit<1>(dartIter).begin(); + orbitIter.cont(); ++orbitIter) + { + nb_points_per_facet++; + } + if(nb_points_per_facet != 3) + { + return false; + } + + } + } + return true; +} + +void Viewer::triangulate_facet() +{ + + + pos_facets.resize(0); + flat_normals.resize(0); + smooth_normals.resize(0); + colors.resize(0); + + LCC &lcc = *scene->lcc; + + for (LCC::Attribute_range<3>::type::iterator + it=lcc.attributes<3>().begin(), + itend=lcc.attributes<3>().end(); it!=itend; ++it ) + { + if ( it->info().is_visible() ) + { + for(LCC::One_dart_per_incident_cell_range<2,3>::iterator + dartIter=lcc.one_dart_per_incident_cell<2,3> + (lcc.dart_of_attribute<3>(it)).begin(); dartIter.cont(); ++dartIter) + { + + //Computes the normal of the facet + Traits::Vector_3 normal = CGAL::compute_normal_of_cell_2(lcc,dartIter); + normal = normal/(CGAL::sqrt(normal*normal)); + + P_traits cdt_traits(normal); + CDT cdt(cdt_traits); + + LCC::Dart_of_orbit_range<1>::const_iterator + he_circ = lcc.darts_of_orbit<1>(dartIter).begin(), + he_circ_end(he_circ); + + // Iterates on the vector of facet handles + CDT::Vertex_handle previous, first; + do { + CDT::Vertex_handle vh = cdt.insert(lcc.point(he_circ)); + if(first == 0) { + first = vh; + } + //vh->info() = he_circ; + if(previous != 0 && previous != vh) { + cdt.insert_constraint(previous, vh); + } + previous = vh; + } while( ++he_circ != he_circ_end ); + cdt.insert_constraint(previous, first); + + // sets mark is_external + for(CDT::All_faces_iterator + fit = cdt.all_faces_begin(), + end = cdt.all_faces_end(); + fit != end; ++fit) + { + fit->info().is_external = false; + } + //check if the facet is external or internal + std::queue face_queue; + face_queue.push(cdt.infinite_vertex()->face()); + while(! face_queue.empty() ) { + CDT::Face_handle fh = face_queue.front(); + face_queue.pop(); + if(fh->info().is_external) continue; + fh->info().is_external = true; + for(int i = 0; i <3; ++i) { + if(!cdt.is_constrained(std::make_pair(fh, i))) + { + face_queue.push(fh->neighbor(i)); + } + } + } + + //iterates on the internal faces to add the vertices to the positions + //and the normals to the appropriate vectors + for(CDT::Finite_faces_iterator + ffit = cdt.finite_faces_begin(), + end = cdt.finite_faces_end(); + ffit != end; ++ffit) + { + if(ffit->info().is_external) + continue; + + //compute normals (no smooth for non-triangle facets objects + LCC::Vector normal = CGAL::compute_normal_of_cell_2(lcc,dartIter); + normal = normal/(CGAL::sqrt(normal*normal)); + + smooth_normals.push_back(normal.x());smooth_normals.push_back(normal.y());smooth_normals.push_back(normal.z()); + smooth_normals.push_back(normal.x());smooth_normals.push_back(normal.y());smooth_normals.push_back(normal.z()); + smooth_normals.push_back(normal.x());smooth_normals.push_back(normal.y());smooth_normals.push_back(normal.z()); + + flat_normals.push_back(normal.x());flat_normals.push_back(normal.y());flat_normals.push_back(normal.z()); + flat_normals.push_back(normal.x());flat_normals.push_back(normal.y());flat_normals.push_back(normal.z()); + flat_normals.push_back(normal.x());flat_normals.push_back(normal.y());flat_normals.push_back(normal.z()); + + + + pos_facets.push_back(ffit->vertex(0)->point().x()); pos_facets.push_back(ffit->vertex(0)->point().y()); pos_facets.push_back(ffit->vertex(0)->point().z()); + pos_facets.push_back(ffit->vertex(1)->point().x()); pos_facets.push_back(ffit->vertex(1)->point().y()); pos_facets.push_back(ffit->vertex(1)->point().z()); + pos_facets.push_back(ffit->vertex(2)->point().x()); pos_facets.push_back(ffit->vertex(2)->point().y()); pos_facets.push_back(ffit->vertex(2)->point().z()); + + double r = (double)lcc.info<3>(dartIter).color().r()/255.0; + double g = (double)lcc.info<3>(dartIter).color().g()/255.0; + double b = (double)lcc.info<3>(dartIter).color().b()/255.0; + if ( !lcc.is_free(dartIter, 3) ) + { + r += (double)lcc.info<3>(lcc.beta(dartIter,3)).color().r()/255.0; + g += (double)lcc.info<3>(lcc.beta(dartIter,3)).color().g()/255.0; + b += (double)lcc.info<3>(lcc.beta(dartIter,3)).color().b()/255.0; + r /= 2; g /= 2; b /= 2; + } + colors.push_back(r);colors.push_back(g);colors.push_back(b); + colors.push_back(r);colors.push_back(g);colors.push_back(b); + colors.push_back(r);colors.push_back(g);colors.push_back(b); + + + } + } + } + } +} + +void Viewer::compile_shaders() +{ + if(! buffers[0].create() || !buffers[1].create() || !buffers[2].create() || !buffers[3].create() + || !buffers[4].create() || !buffers[5].create() || !buffers[6].create() + || !buffers[7].create()) + { + std::cerr<<"VBO Creation FAILED"<compileSourceCode(vertex_source)) + { + std::cerr<<"Compiling vertex source FAILED"<compileSourceCode(fragment_source)) + { + std::cerr<<"Compiling fragmentsource FAILED"<compileSourceCode(vertex_source_p_l)) + { + std::cerr<<"Compiling vertex source FAILED"<compileSourceCode(fragment_source_p_l)) + { + std::cerr<<"Compiling fragmentsource FAILED"<(pos_facets.size()*sizeof(float))); + vertexLocation[0] = rendering_program.attributeLocation("vertex"); + rendering_program.bind(); + rendering_program.enableAttributeArray(vertexLocation[0]); + rendering_program.setAttributeBuffer(vertexLocation[0],GL_FLOAT,0,3); + rendering_program.release(); + buffers[0].release(); + //normals of the facets + buffers[1].bind(); + buffers[1].allocate(flat_normals.data(), static_cast(flat_normals.size()*sizeof(float))); + normalsLocation = rendering_program.attributeLocation("normal"); + rendering_program.bind(); + rendering_program.enableAttributeArray(normalsLocation); + rendering_program.setAttributeBuffer(normalsLocation,GL_FLOAT,0,3); + buffers[1].release(); + //colors of the facets + buffers[2].bind(); + buffers[2].allocate(colors.data(), static_cast(colors.size()*sizeof(float))); + colorsLocation = rendering_program.attributeLocation("color"); + rendering_program.bind(); + rendering_program.enableAttributeArray(colorsLocation); + rendering_program.setAttributeBuffer(colorsLocation,GL_FLOAT,0,3); + buffers[2].release(); + rendering_program.release(); + vao[0].release(); + + vao[1].bind(); + //points of the facets + buffers[3].bind(); + buffers[3].allocate(pos_facets.data(), static_cast(pos_facets.size()*sizeof(float))); + vertexLocation[0] = rendering_program.attributeLocation("vertex"); + rendering_program.bind(); + rendering_program.enableAttributeArray(vertexLocation[0]); + rendering_program.setAttributeBuffer(vertexLocation[0],GL_FLOAT,0,3); + rendering_program.release(); + buffers[3].release(); + //normals of the facets + buffers[4].bind(); + buffers[4].allocate(smooth_normals.data(), static_cast(smooth_normals.size()*sizeof(float))); + normalsLocation = rendering_program.attributeLocation("normal"); + rendering_program.bind(); + rendering_program.enableAttributeArray(normalsLocation); + rendering_program.setAttributeBuffer(normalsLocation,GL_FLOAT,0,3); + buffers[4].release(); + //colors of the facets + buffers[5].bind(); + buffers[5].allocate(colors.data(), static_cast(colors.size()*sizeof(float))); + colorsLocation = rendering_program.attributeLocation("color"); + rendering_program.bind(); + rendering_program.enableAttributeArray(colorsLocation); + rendering_program.setAttributeBuffer(colorsLocation,GL_FLOAT,0,3); + buffers[5].release(); + rendering_program.release(); + vao[1].release(); + + //The lines + vao[2].bind(); + buffers[6].bind(); + buffers[6].allocate(pos_lines.data(), static_cast(pos_lines.size()*sizeof(float))); + vertexLocation[2] = rendering_program_p_l.attributeLocation("vertex"); + rendering_program_p_l.bind(); + rendering_program_p_l.enableAttributeArray(vertexLocation[2]); + rendering_program_p_l.setAttributeBuffer(vertexLocation[2],GL_FLOAT,0,3); + buffers[6].release(); + rendering_program_p_l.release(); + vao[2].release(); + + //The points + vao[3].bind(); + buffers[7].bind(); + buffers[7].allocate(pos_points.data(), static_cast(pos_points.size()*sizeof(float))); + vertexLocation[2] = rendering_program_p_l.attributeLocation("vertex"); + rendering_program_p_l.bind(); + rendering_program_p_l.enableAttributeArray(vertexLocation[2]); + rendering_program_p_l.setAttributeBuffer(vertexLocation[2],GL_FLOAT,0,3); + buffers[7].release(); + rendering_program_p_l.release(); + vao[3].release(); + + are_buffers_initialized = true; + +} + +void Viewer::compute_elements() +{ + + //Facets + if(is_Triangulated()) + { + pos_facets.resize(0); + flat_normals.resize(0); + smooth_normals.resize(0); + colors.resize(0); + LCC &lcc = *scene->lcc; + + for (LCC::Attribute_range<3>::type::iterator + it=lcc.attributes<3>().begin(), + itend=lcc.attributes<3>().end(); it!=itend; ++it ) + { + if ( it->info().is_visible() ) + { + for(LCC::One_dart_per_incident_cell_range<2,3>::iterator + dartIter=lcc.one_dart_per_incident_cell<2,3> + (lcc.dart_of_attribute<3>(it)).begin(); dartIter.cont(); ++dartIter) + { + // We draw the polygon + + + // double r = (double)dartIter->attribute<3>()->info().r()/255.0; + float r = (float)lcc.info<3>(dartIter).color().r()/255.0; + float g = (float)lcc.info<3>(dartIter).color().g()/255.0; + float b = (float)lcc.info<3>(dartIter).color().b()/255.0; + if ( !lcc.is_free(dartIter, 3) ) + { + r += (float)lcc.info<3>(lcc.beta(dartIter,3)).color().r()/255.0; + g += (float)lcc.info<3>(lcc.beta(dartIter,3)).color().g()/255.0; + b += (float)lcc.info<3>(lcc.beta(dartIter,3)).color().b()/255.0; + r /= 2; g /= 2; b /= 2; + } + + colors.push_back(r);colors.push_back(g);colors.push_back(b); + colors.push_back(r);colors.push_back(g);colors.push_back(b); + colors.push_back(r);colors.push_back(g);colors.push_back(b); + //compute flat normals + LCC::Vector normal = CGAL::compute_normal_of_cell_2(lcc,dartIter); + normal = normal/(CGAL::sqrt(normal*normal)); + flat_normals.push_back(normal.x());flat_normals.push_back(normal.y());flat_normals.push_back(normal.z()); + flat_normals.push_back(normal.x());flat_normals.push_back(normal.y());flat_normals.push_back(normal.z()); + flat_normals.push_back(normal.x());flat_normals.push_back(normal.y());flat_normals.push_back(normal.z()); + + + + for (LCC::Dart_of_orbit_range<1>::const_iterator + orbitIter = lcc.darts_of_orbit<1>(dartIter).begin(); + orbitIter.cont(); ++orbitIter) + { + //compute Smooth normals + LCC::Vector normal = CGAL::compute_normal_of_cell_0(lcc,orbitIter); + normal = normal/(CGAL::sqrt(normal*normal)); + smooth_normals.push_back(normal.x());smooth_normals.push_back(normal.y());smooth_normals.push_back(normal.z()); + + const LCC::Point& p = lcc.point(orbitIter); + pos_facets.push_back(p.x()); pos_facets.push_back(p.y()); pos_facets.push_back(p.z()); + } + + } + } + } + + } + else + triangulate_facet(); + + //Edges + { + pos_lines.resize(0); + LCC &lcc = *scene->lcc; + + if ( !lcc.is_empty() ) + { + + for (LCC::Attribute_range<3>::type::iterator + it=lcc.attributes<3>().begin(), + itend=lcc.attributes<3>().end(); it!=itend; ++it ) + { + if ( it->info().is_visible() ) + { + for(LCC::One_dart_per_incident_cell_range<1,3>::iterator + dartIter=lcc.one_dart_per_incident_cell<1,3> + (lcc.dart_of_attribute<3>(it)).begin(); dartIter.cont(); ++dartIter) + { + const LCC::Point& p = lcc.point(dartIter); + Dart_handle d2 = lcc.other_extremity(dartIter); + if ( d2!=NULL ) + { + const LCC::Point& p2 = lcc.point(d2); + pos_lines.push_back(p.x()); pos_lines.push_back(p.y()); pos_lines.push_back(p.z()); + pos_lines.push_back(p2.x()); pos_lines.push_back(p2.y()); pos_lines.push_back(p2.z()); + } + } + } + } + + } + } + //Points + { + pos_points.resize(0); + LCC &lcc = *scene->lcc; + + if ( lcc.is_empty() ) + { + bb = LCC::Point(CGAL::ORIGIN).bbox(); + bb = bb + LCC::Point(1,1,1).bbox(); // To avoid a warning from Qglviewer + return; + } + + bool empty = true; + for (LCC::Attribute_range<3>::type::iterator + it=lcc.attributes<3>().begin(), + itend=lcc.attributes<3>().end(); it!=itend; ++it ) + { + if ( it->info().is_visible() ) + { + for(LCC::One_dart_per_incident_cell_range<0,3>::iterator + dartIter=lcc.one_dart_per_incident_cell<0,3> + (lcc.dart_of_attribute<3>(it)).begin(); + dartIter.cont(); ++dartIter) + { + const LCC::Point& p = lcc.point(dartIter); + pos_points.push_back(p.x()); pos_points.push_back(p.y()); pos_points.push_back(p.z()); + + if ( empty ) + { + bb = p.bbox(); + empty = false; + } + else + bb = bb + p.bbox(); + } + } + } + + + if ( lcc.is_empty() ) + { + bb = LCC::Point(CGAL::ORIGIN).bbox(); + bb = bb + LCC::Point(1,1,1).bbox(); // To avoid a warning from Qglviewer + } + + } + +} + +void Viewer::attrib_buffers(QGLViewer* viewer) +{ + QMatrix4x4 mvpMatrix; + QMatrix4x4 mvMatrix; + double mat[16]; + viewer->camera()->getModelViewProjectionMatrix(mat); + for(int i=0; i < 16; i++) + { + mvpMatrix.data()[i] = (float)mat[i]; + } + viewer->camera()->getModelViewMatrix(mat); + for(int i=0; i < 16; i++) + { + mvMatrix.data()[i] = (float)mat[i]; + } + // define material + QVector4D ambient(0.1f, 0.1f, 0.1f, 1.0f); + QVector4D diffuse( 0.9f, + 0.9f, + 0.9f, + 0.0f ); + + QVector4D specular( 0.0f, + 0.0f, + 0.0f, + 0.0f ); + + QVector4D position( 0.0f, -10.0f, -10.0f, 0.0f ); + GLfloat shininess = 1.0f; + + + rendering_program.bind(); + mvpLocation[0] = rendering_program.uniformLocation("mvp_matrix"); + mvLocation = rendering_program.uniformLocation("mv_matrix"); + lightLocation[0] = rendering_program.uniformLocation("light_pos"); + lightLocation[1] = rendering_program.uniformLocation("light_diff"); + lightLocation[2] = rendering_program.uniformLocation("light_spec"); + lightLocation[3] = rendering_program.uniformLocation("light_amb"); + lightLocation[4] = rendering_program.uniformLocation("spec_power"); + + rendering_program.setUniformValue(lightLocation[0], position); + rendering_program.setUniformValue(lightLocation[1], diffuse); + rendering_program.setUniformValue(lightLocation[2], specular); + rendering_program.setUniformValue(lightLocation[3], ambient); + rendering_program.setUniformValue(lightLocation[4], shininess); + rendering_program.setUniformValue(mvpLocation[0], mvpMatrix); + rendering_program.setUniformValue(mvLocation, mvMatrix); + + + rendering_program.release(); + rendering_program_p_l.bind(); + mvpLocation[1] = rendering_program_p_l.uniformLocation("mvp_matrix"); + colorLocation = rendering_program_p_l.uniformLocation("color"); + rendering_program.setUniformValue(mvpLocation[1], mvpMatrix); + rendering_program_p_l.release(); + are_buffers_initialized = true; +} + void Viewer::sceneChanged() { - this->initDraw(); this->camera()->setSceneBoundingBox(qglviewer::Vec(bb.xmin(), bb.ymin(), @@ -35,203 +665,63 @@ Viewer::sceneChanged() qglviewer::Vec(bb.xmax(), bb.ymax(), bb.zmax())); + compute_elements(); + are_buffers_initialized = false; this->showEntireScene(); } -void Viewer::drawAllFaces(bool flat) -{ - LCC &lcc = *scene->lcc; - - for (LCC::Attribute_range<3>::type::iterator - it=lcc.attributes<3>().begin(), - itend=lcc.attributes<3>().end(); it!=itend; ++it ) - { - if ( it->info().is_visible() ) - { - for(LCC::One_dart_per_incident_cell_range<2,3>::iterator - dartIter=lcc.one_dart_per_incident_cell<2,3> - (lcc.dart_of_attribute<3>(it)).begin(); dartIter.cont(); ++dartIter) - { - // We draw the polygon - ::glBegin(GL_POLYGON); - - // double r = (double)dartIter->attribute<3>()->info().r()/255.0; - double r = (double)lcc.info<3>(dartIter).color().r()/255.0; - double g = (double)lcc.info<3>(dartIter).color().g()/255.0; - double b = (double)lcc.info<3>(dartIter).color().b()/255.0; - if ( !lcc.is_free(dartIter, 3) ) - { - r += (double)lcc.info<3>(lcc.beta(dartIter,3)).color().r()/255.0; - g += (double)lcc.info<3>(lcc.beta(dartIter,3)).color().g()/255.0; - b += (double)lcc.info<3>(lcc.beta(dartIter,3)).color().b()/255.0; - r /= 2; g /= 2; b /= 2; - } - - ::glColor3f(r,g,b); - - if(flat) - { - LCC::Vector normal = CGAL::compute_normal_of_cell_2(lcc,dartIter); - normal = normal/(CGAL::sqrt(normal*normal)); - ::glNormal3d(normal.x(), normal.y(), normal.z()); - } - - for (LCC::Dart_of_orbit_range<1>::const_iterator - orbitIter = lcc.darts_of_orbit<1>(dartIter).begin(); - orbitIter.cont(); ++orbitIter) - { - if(!flat) - { - // If Gouraud shading: 1 normal per vertex - LCC::Vector normal = CGAL::compute_normal_of_cell_0(lcc,orbitIter); - normal = normal/(CGAL::sqrt(normal*normal)); - ::glNormal3d(normal.x(), normal.y(), normal.z()); - } - - const LCC::Point& p = lcc.point(orbitIter); - ::glVertex3d(p.x(),p.y(),p.z()); - } - - ::glEnd(); - } - } - } -} - -void Viewer::drawAllEdges() -{ - LCC &lcc = *scene->lcc; - - if ( lcc.is_empty() ) return; - - // ::glDepthRange(0.0, 1.0-0.005); - ::glBegin(GL_LINES); - //::glColor3f(0.0f, 0.0f, 0.0f); - ::glColor3f(.2f,.2f,.6f); - - for (LCC::Attribute_range<3>::type::iterator - it=lcc.attributes<3>().begin(), - itend=lcc.attributes<3>().end(); it!=itend; ++it ) - { - if ( it->info().is_visible() ) - { - for(LCC::One_dart_per_incident_cell_range<1,3>::iterator - dartIter=lcc.one_dart_per_incident_cell<1,3> - (lcc.dart_of_attribute<3>(it)).begin(); dartIter.cont(); ++dartIter) - { - const LCC::Point& p = lcc.point(dartIter); - Dart_handle d2 = lcc.other_extremity(dartIter); - if ( d2!=NULL ) - { - const LCC::Point& p2 = lcc.point(d2); - glVertex3f( p.x(),p.y(),p.z()); - glVertex3f( p2.x(),p2.y(),p2.z()); - } - } - } - } - - ::glEnd(); -} - -void Viewer::drawAllVertices() -{ - LCC &lcc = *scene->lcc; - - if ( lcc.is_empty() ) - { - bb = LCC::Point(CGAL::ORIGIN).bbox(); - bb = bb + LCC::Point(1,1,1).bbox(); // To avoid a warning from Qglviewer - return; - } - - // ::glDepthRange(0.0, 1.0-0.005); - ::glPointSize(7.0); - ::glBegin(GL_POINTS); - ::glColor3f(0.2f, 0.2f, 0.7f); - - bool empty = true; - for (LCC::Attribute_range<3>::type::iterator - it=lcc.attributes<3>().begin(), - itend=lcc.attributes<3>().end(); it!=itend; ++it ) - { - if ( it->info().is_visible() ) - { - for(LCC::One_dart_per_incident_cell_range<0,3>::iterator - dartIter=lcc.one_dart_per_incident_cell<0,3> - (lcc.dart_of_attribute<3>(it)).begin(); - dartIter.cont(); ++dartIter) - { - const LCC::Point& p = lcc.point(dartIter); - ::glVertex3f(p.x(), p.y(), p.z()); - - if ( empty ) - { - bb = p.bbox(); - empty = false; - } - else - bb = bb + p.bbox(); - } - } - } - - ::glEnd(); - - if ( lcc.is_empty() ) - { - bb = LCC::Point(CGAL::ORIGIN).bbox(); - bb = bb + LCC::Point(1,1,1).bbox(); // To avoid a warning from Qglviewer - } -} - -void Viewer::initDraw() -{ - //Compile drawFacet - // std::cout << "Compile Display Lists : Faces, " << std::flush; - m_dlFaces = ::glGenLists(1); - ::glNewList(m_dlFaces, GL_COMPILE); - drawAllFaces(false); - ::glEndList(); - - //Compile drawFacet with flat shading - // std::cout << "Faces (flat shading), " << std::flush; - m_dlFacesFlat = ::glGenLists(1); - ::glNewList(m_dlFacesFlat, GL_COMPILE); - drawAllFaces(true); - ::glEndList(); - - //Compile drawEdge - // std::cout << "edges, " << std::flush; - m_dlEdges = ::glGenLists(1); - ::glNewList(m_dlEdges, GL_COMPILE); - drawAllEdges(); - ::glEndList(); - - //Compile drawvertices - // std::cout << "vertices" << std::flush; - m_dlVertices = ::glGenLists(1); - ::glNewList(m_dlVertices, GL_COMPILE); - drawAllVertices(); - ::glEndList(); - - // std::cout << ". DONE." << std::endl; - m_displayListCreated = true; -} - void Viewer::draw() { - if(!m_displayListCreated) initDraw(); +if(!are_buffers_initialized) + initialize_buffers(); - if ( !wireframe ) - { - if(flatShading) ::glCallList(m_dlFacesFlat); - else ::glCallList(m_dlFaces); - } - if(edges) ::glCallList(m_dlEdges); +QColor color; + if ( !wireframe ) + { + if(flatShading) + { - if(vertices) ::glCallList(m_dlVertices); + vao[0].bind(); + attrib_buffers(this); + rendering_program.bind(); + glDrawArrays(GL_TRIANGLES, 0, static_cast(pos_facets.size()/3)); + rendering_program.release(); + vao[0].release(); + } + else + { + vao[1].bind(); + attrib_buffers(this); + rendering_program.bind(); + glDrawArrays(GL_TRIANGLES, 0, static_cast(pos_facets.size()/3)); + rendering_program.release(); + vao[1].release(); + } + } + if(edges) + { + vao[2].bind(); + attrib_buffers(this); + color.setRgbF(0.2f, 0.2f, 0.7f); + rendering_program_p_l.bind(); + rendering_program_p_l.setAttributeValue(colorLocation,color); + glDrawArrays(GL_LINES, 0, static_cast(pos_lines.size()/3)); + rendering_program_p_l.release(); + vao[2].release(); + } + if(vertices) + { + ::glPointSize(7.f); + vao[3].bind(); + attrib_buffers(this); + color.setRgbF(.2f,.2f,.6f); + rendering_program_p_l.bind(); + rendering_program_p_l.setAttributeValue(colorLocation,color); + glDrawArrays(GL_POINTS, 0, static_cast(pos_points.size()/3)); + rendering_program_p_l.release(); + vao[3].release(); + } } void Viewer::init() @@ -272,12 +762,15 @@ void Viewer::init() } else { - ::glShadeModel(GL_SMOOTH); - ::glEnable(GL_BLEND); - ::glEnable(GL_LINE_SMOOTH); - ::glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); - ::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + ::glShadeModel(GL_FLAT); + ::glDisable(GL_BLEND); + ::glDisable(GL_LINE_SMOOTH); + ::glDisable(GL_POLYGON_SMOOTH_HINT); + ::glBlendFunc(GL_ONE, GL_ZERO); + ::glHint(GL_LINE_SMOOTH_HINT, GL_FASTEST); } + initializeOpenGLFunctions(); + compile_shaders(); } void Viewer::keyPressEvent(QKeyEvent *e) @@ -309,11 +802,12 @@ void Viewer::keyPressEvent(QKeyEvent *e) } else { - ::glShadeModel(GL_SMOOTH); - ::glEnable(GL_BLEND); - ::glEnable(GL_LINE_SMOOTH); - ::glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); - ::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + ::glShadeModel(GL_FLAT); + ::glDisable(GL_BLEND); + ::glDisable(GL_LINE_SMOOTH); + ::glDisable(GL_POLYGON_SMOOTH_HINT); + ::glBlendFunc(GL_ONE, GL_ZERO); + ::glHint(GL_LINE_SMOOTH_HINT, GL_FASTEST); } handled = true; updateGL(); diff --git a/Linear_cell_complex/demo/Linear_cell_complex/Viewer.h b/Linear_cell_complex/demo/Linear_cell_complex/Viewer.h index c8daaa5c117..e5dc086f76f 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/Viewer.h +++ b/Linear_cell_complex/demo/Linear_cell_complex/Viewer.h @@ -25,7 +25,11 @@ #include #include -class Viewer : public QGLViewer +#include +#include +#include +#include +class Viewer : public QGLViewer, QOpenGLFunctions_3_3_Core { Q_OBJECT @@ -48,16 +52,23 @@ class Viewer : public QGLViewer public: - Viewer(QWidget* parent) - : QGLViewer(parent), wireframe(false), flatShading(true), - edges(true), vertices(true), m_displayListCreated(false) + Viewer(QWidget* parent); + ~Viewer() { - QGLFormat newFormat = this->format(); - newFormat.setSampleBuffers(true); - newFormat.setSamples(16); - this->setFormat(newFormat); - } + buffers[0].destroy(); + buffers[1].destroy(); + buffers[2].destroy(); + buffers[3].destroy(); + buffers[4].destroy(); + buffers[5].destroy(); + buffers[6].destroy(); + buffers[7].destroy(); + vao[0].destroy(); + vao[1].destroy(); + vao[2].destroy(); + vao[3].destroy(); + } void setScene(Scene* scene_) { scene = scene_; @@ -76,11 +87,38 @@ public Q_SLOTS: void sceneChanged(); -protected: - void initDraw(); - void drawAllFaces(bool flat); - void drawAllEdges(); - void drawAllVertices(); -}; +private: + + bool are_buffers_initialized; + //Shaders elements + + int vertexLocation[3]; + int normalsLocation; + int mvpLocation[2]; + int mvLocation; + int colorLocation; + int colorsLocation; + int lightLocation[5]; + + + std::vector pos_points; + std::vector pos_lines; + std::vector pos_facets; + std::vector smooth_normals; + std::vector flat_normals; + std::vector colors; + + QGLBuffer buffers[10]; + QOpenGLVertexArrayObject vao[10]; + QOpenGLShaderProgram rendering_program; + QOpenGLShaderProgram rendering_program_p_l; + + void initialize_buffers(); + void compute_elements(); + void attrib_buffers(QGLViewer*); + void compile_shaders(); + void triangulate_facet(); + bool is_Triangulated(); +}; #endif diff --git a/Linear_cell_complex/examples/Linear_cell_complex/CMakeLists.txt b/Linear_cell_complex/examples/Linear_cell_complex/CMakeLists.txt index 6be728b43f6..5dd98ca2759 100644 --- a/Linear_cell_complex/examples/Linear_cell_complex/CMakeLists.txt +++ b/Linear_cell_complex/examples/Linear_cell_complex/CMakeLists.txt @@ -3,12 +3,8 @@ project( Linear_cell_complex_examples ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) -endif() +cmake_minimum_required(VERSION 2.8.11) + # If you want to visualize a linear cell complex, there are 2 viewers # based on qt and vtk. Just uncomment the corresponding lines diff --git a/Matrix_search/demo/Matrix_search/CMakeLists.txt b/Matrix_search/demo/Matrix_search/CMakeLists.txt index 25866439682..25b766fe695 100644 --- a/Matrix_search/demo/Matrix_search/CMakeLists.txt +++ b/Matrix_search/demo/Matrix_search/CMakeLists.txt @@ -2,11 +2,9 @@ project( Matrix_search_Demo ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() find_package(CGAL COMPONENTS Qt3 ) @@ -14,7 +12,7 @@ include( ${CGAL_USE_FILE} ) find_package(Qt3-patched) # FindQt3-patched.cmake is FindQt3.cmake patched by CGAL developers, so -# that it can be used together with FindQt4: all its variables are prefixed +# that it can be used together with Qt5: all its variables are prefixed # by "QT3_" instead of "QT_". if ( CGAL_FOUND AND QT3_FOUND AND CGAL_Qt3_FOUND) diff --git a/Mesh_2/demo/Mesh_2/CMakeLists.txt b/Mesh_2/demo/Mesh_2/CMakeLists.txt index 9d6fbe70050..2b34c25097f 100644 --- a/Mesh_2/demo/Mesh_2/CMakeLists.txt +++ b/Mesh_2/demo/Mesh_2/CMakeLists.txt @@ -3,11 +3,9 @@ project( mesh_2_demo ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() add_subdirectory(Qt3) diff --git a/Mesh_2/demo/Mesh_2/Qt3/CMakeLists.txt b/Mesh_2/demo/Mesh_2/Qt3/CMakeLists.txt index 699d65005aa..d00e8d57a56 100644 --- a/Mesh_2/demo/Mesh_2/Qt3/CMakeLists.txt +++ b/Mesh_2/demo/Mesh_2/Qt3/CMakeLists.txt @@ -4,11 +4,9 @@ project( mesh_2_qt3_demo ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() find_package(CGAL COMPONENTS Core Qt3 ) @@ -16,7 +14,7 @@ include( ${CGAL_USE_FILE} ) find_package(Qt3-patched ) # FindQt3-patched.cmake is FindQt3.cmake patched by CGAL developers, so -# that it can be used together with FindQt4: all its variables are prefixed +# that it can be used together with Qt5: all its variables are prefixed # by "QT3_" instead of "QT_". if ( CGAL_FOUND AND QT3_FOUND AND CGAL_Qt3_FOUND) diff --git a/Mesh_2/demo/Mesh_2/README.txt b/Mesh_2/demo/Mesh_2/README.txt index 2e91b85208e..96596b0fef1 100644 --- a/Mesh_2/demo/Mesh_2/README.txt +++ b/Mesh_2/demo/Mesh_2/README.txt @@ -1,5 +1,5 @@ This directory contains non-graphical demos of the 2D Mesh Generator package. An old Qt3-based demos lies in the qt3/ sub-directory. The -Constrained Delaunay triangulation Qt4 demos has a 2D meshing feature that +Constrained Delaunay triangulation Qt5 demos has a 2D meshing feature that demonstrates the 2D Mesh Generator package. See in the directory demo/Triangulation_2/ of the CGAL tarball. diff --git a/Mesh_3/benchmark/Mesh_3/CMakeLists.txt b/Mesh_3/benchmark/Mesh_3/CMakeLists.txt index dbed680fb42..77e16344a65 100644 --- a/Mesh_3/benchmark/Mesh_3/CMakeLists.txt +++ b/Mesh_3/benchmark/Mesh_3/CMakeLists.txt @@ -4,14 +4,8 @@ project( Mesh_3_benchmark ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 2.6) - if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) - else() - cmake_policy(VERSION 2.6) - endif() -endif() +cmake_minimum_required(VERSION 2.8.11) + # Creates a new CMake option, turned ON by default option(ACTIVATE_MSVC_PRECOMPILED_HEADERS diff --git a/Mesh_3/demo/Mesh_3/C3t3_rib_exporter_plugin.cpp b/Mesh_3/demo/Mesh_3/C3t3_rib_exporter_plugin.cpp index 0e2193bc4ec..6881495f62c 100644 --- a/Mesh_3/demo/Mesh_3/C3t3_rib_exporter_plugin.cpp +++ b/Mesh_3/demo/Mesh_3/C3t3_rib_exporter_plugin.cpp @@ -34,6 +34,7 @@ class C3t3_rib_exporter_plugin : { Q_OBJECT Q_INTERFACES(Plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") public: C3t3_rib_exporter_plugin(); @@ -208,8 +209,8 @@ C3t3_rib_exporter_plugin::create_rib() // Get Scene_c3t3_item Scene_interface::Item_id index = scene->mainSelectionIndex(); - const Scene_c3t3_item* c3t3_item = - qobject_cast(scene->item(index)); + Scene_c3t3_item* c3t3_item = + qobject_cast(scene->item(index)); if ( NULL == c3t3_item ) { @@ -331,6 +332,7 @@ get_parameters_from_dialog() ui.isPreview->setChecked(parameters_.is_preview); // Update mask + update_mask(); // ----------------------------------- @@ -714,8 +716,6 @@ void C3t3_rib_exporter_plugin:: write_surface_cells(const C3t3& c3t3, const Plane& plane, std::ofstream& out) { - typedef Kernel::Oriented_side Side; - for ( C3t3::Cells_in_complex_iterator it_cell = c3t3.cells_in_complex_begin(), end = c3t3.cells_in_complex_end() ; it_cell != end ; ++it_cell ) { @@ -786,6 +786,8 @@ write_surface_cells(const C3t3& c3t3, const Plane& plane, std::ofstream& out) QColor edgecolor = facecolor.darker(150); /* + typedef Kernel::Oriented_side Side; + // Transparency on the negative side of the plane const Side s0 = plane.oriented_side(c->vertex(0)->point()); const Side s1 = plane.oriented_side(c->vertex(1)->point()); @@ -1177,7 +1179,4 @@ write_background(const QColor& color, std::ofstream& out) out << "]" << std::endl; } - -#include -Q_EXPORT_PLUGIN2(C3t3_rib_exporter_plugin, C3t3_rib_exporter_plugin) #include "C3t3_rib_exporter_plugin.moc" diff --git a/Mesh_3/demo/Mesh_3/CMakeLists.txt b/Mesh_3/demo/Mesh_3/CMakeLists.txt index a70c8437d0a..9c46df44a78 100644 --- a/Mesh_3/demo/Mesh_3/CMakeLists.txt +++ b/Mesh_3/demo/Mesh_3/CMakeLists.txt @@ -2,11 +2,15 @@ project( Mesh_3_demo ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +# Find includes in corresponding build directories +set(CMAKE_INCLUDE_CURRENT_DIR ON) +# Instruct CMake to run moc automatically when needed. +set(CMAKE_AUTOMOC ON) + + +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() # Compatibility with CMake 3.0 @@ -16,6 +20,7 @@ if(POLICY CMP0042) cmake_policy(SET CMP0042 OLD) endif() + # Creates a new CMake option, turned ON by default option(ACTIVATE_MSVC_PRECOMPILED_HEADERS "Activate precompiled headers in MSVC" @@ -66,10 +71,9 @@ option(ACTIVATE_CONCURRENT_MESH_3 "Activate parallelism in Mesh_3" OFF) -# Find CGAL and CGAL Qt4 -find_package(CGAL COMPONENTS Qt4 ImageIO) +# Find CGAL and CGAL Qt5 +find_package(CGAL COMPONENTS Qt5 ImageIO) include( ${CGAL_USE_FILE} ) - # And add -DCGAL_CONCURRENT_MESH_3 if that option is ON if( ACTIVATE_CONCURRENT_MESH_3 ) add_definitions( -DCGAL_CONCURRENT_MESH_3 ) @@ -87,53 +91,39 @@ if( TBB_FOUND ) include(${TBB_USE_FILE}) endif() -# Find Qt4 itself -set( QT_USE_QTXML TRUE ) -set( QT_USE_QTMAIN TRUE ) -set( QT_USE_QTSCRIPT TRUE ) -set( QT_USE_QTOPENGL TRUE ) -find_package(Qt4) +# Find Qt5 itself +find_package(Qt5 QUIET COMPONENTS Xml Script OpenGL) # Find OpenGL find_package(OpenGL) -# Find GLEW (for OpenGL-1.5 and OpenGL extensions) -find_package(GLEW) - # Find everybodies darling find_package(Boost COMPONENTS thread system) # Find QGLViewer -if(QT4_FOUND) - include(${QT_USE_FILE}) + +if(Qt5_FOUND) add_definitions(-DQT_NO_KEYWORDS) + add_definitions(-DSCENE_SEGMENTED_IMAGE_GL_BUFFERS_AVAILABLE) - find_package(QGLViewer ) -endif(QT4_FOUND) + find_package(QGLViewer ) +endif(Qt5_FOUND) -if(CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND AND Boost_FOUND) +if(CGAL_Qt5_FOUND AND Qt5_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND AND Boost_FOUND) # Add directory containing implicit function plugin source files add_subdirectory("implicit_functions") - if(GLEW_FOUND) - include_directories ( ${GLEW_INCLUDE_DIR} ) - add_definitions(-DSCENE_SEGMENTED_IMAGE_GL_BUFFERS_AVAILABLE) - else(GLEW_FOUND) - message(STATUS "NOTICE: GLEW library is not found. 3D images rendering will not be available.") - endif(GLEW_FOUND) - - include_directories ( ${QGLVIEWER_INCLUDE_DIR} ) - qt4_wrap_ui( UI_FILES ui_files/MainWindow.ui ) - qt4_wrap_ui( meshingUI_FILES ui_files/Meshing_dialog.ui) - qt4_wrap_ui( optimUI_FILES ui_files/Smoother_dialog.ui ui_files/LocalOptim_dialog.ui) - qt4_wrap_ui( ribUI_FILES ui_files/Rib_dialog.ui) - qt4_wrap_ui( funcUI_FILES ui_files/Function_dialog.ui) - qt4_wrap_ui( imgUI_FILES ui_files/Image_res_dialog.ui) + qt5_wrap_ui( UI_FILES ui_files/MainWindow.ui ) + qt5_wrap_ui( meshingUI_FILES ui_files/Meshing_dialog.ui) + qt5_wrap_ui( optimUI_FILES ui_files/Smoother_dialog.ui ui_files/LocalOptim_dialog.ui) + qt5_wrap_ui( ribUI_FILES ui_files/Rib_dialog.ui) + qt5_wrap_ui( funcUI_FILES ui_files/Function_dialog.ui) + qt5_wrap_ui( imgUI_FILES ui_files/Image_res_dialog.ui) include(AddFileDependencies) @@ -141,31 +131,22 @@ if(CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND AND Boost_F set(DEMO_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/CGAL_demo") set(DEMO_H_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include/CGAL_demo") - qt4_generate_moc( "MainWindow.h" "${CMAKE_CURRENT_BINARY_DIR}/MainWindow_moc.cpp" ) + qt5_generate_moc( "MainWindow.h" "${CMAKE_CURRENT_BINARY_DIR}/MainWindow_moc.cpp" ) add_file_dependencies( MainWindow_moc.cpp "${CMAKE_CURRENT_SOURCE_DIR}/MainWindow.h" ) - qt4_generate_moc( "${DEMO_H_DIR}/Viewer.h" Viewer_moc.cpp ) + qt5_generate_moc( "${DEMO_H_DIR}/Viewer.h" Viewer_moc.cpp ) add_file_dependencies( Viewer_moc.cpp "${DEMO_H_DIR}/Viewer.h" ) - qt4_generate_moc( "${DEMO_H_DIR}/Scene.h" Scene_moc.cpp ) + qt5_generate_moc( "${DEMO_H_DIR}/Scene.h" Scene_moc.cpp ) add_file_dependencies( Scene_moc.cpp "${DEMO_H_DIR}/Scene.h" ) - qt4_generate_moc( "${DEMO_H_DIR}/Scene_item.h" Scene_item_moc.cpp ) + qt5_generate_moc( "${DEMO_H_DIR}/Scene_item.h" Scene_item_moc.cpp ) add_file_dependencies( Scene_item_moc.cpp "${DEMO_H_DIR}/Scene_item.h" ) - qt4_wrap_cpp( VOLUME_MOC_OUTFILES ${CMAKE_CURRENT_SOURCE_DIR}/Volume_plane_thread.h ) - qt4_wrap_cpp( VOLUME_MOC_OUTFILES ${CMAKE_CURRENT_SOURCE_DIR}/Volume_plane_interface.h ) + qt5_wrap_cpp( VOLUME_MOC_OUTFILES ${CMAKE_CURRENT_SOURCE_DIR}/Volume_plane_thread.h ) + qt5_wrap_cpp( VOLUME_MOC_OUTFILES ${CMAKE_CURRENT_SOURCE_DIR}/Volume_plane_interface.h ) - qt4_add_resources ( RESOURCE_FILES Mesh_3.qrc ) - - qt4_automoc( Scene_polyhedron_item.cpp ) - qt4_automoc( Scene_polygon_soup.cpp ) - qt4_automoc( Scene_segmented_image_item.cpp ) - qt4_automoc( Scene_c3t3_item.cpp ) - qt4_automoc( Scene_implicit_function_item.cpp ) - qt4_automoc( Optimizer_thread.cpp ) - qt4_automoc( Meshing_thread.cpp ) - qt4_automoc( Volume_plane_intersection.cpp ) + qt5_add_resources ( RESOURCE_FILES Mesh_3.qrc ) # put plugins (which are shared libraries) at the same location as # executable files @@ -178,6 +159,7 @@ if(CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND AND Boost_F set(VIEWER_LIB "${MESH_3_LIB_PREFIX}viewer") add_library(${VIEWER_LIB} SHARED ${DEMO_SRC_DIR}/Viewer.cpp Viewer_moc.cpp) + qt5_use_modules(${VIEWER_LIB} Xml Script OpenGL Svg) target_link_libraries(${VIEWER_LIB} ${QGLVIEWER_LIBRARIES} ${QT_LIBRARIES} ${OPENGL_LIBRARIES}) set_target_properties(${VIEWER_LIB} PROPERTIES DEFINE_SYMBOL viewer_EXPORTS) @@ -187,43 +169,45 @@ if(CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND AND Boost_F Scene_item_moc.cpp ${DEMO_SRC_DIR}/Scene_item_with_display_list.cpp ${DEMO_SRC_DIR}/Plugin_helper.cpp) + qt5_use_modules(${SCENE_ITEM_LIB} Xml Script OpenGL Svg) set_target_properties(${SCENE_ITEM_LIB} PROPERTIES DEFINE_SYMBOL scene_item_EXPORTS) target_link_libraries(${SCENE_ITEM_LIB} ${QT_LIBRARIES} ${OPENGL_LIBRARIES}) set(SCENE_SEGMENTED_IMAGE_ITEM_LIB "${MESH_3_LIB_PREFIX}scene_segmented_image_item") add_library(${SCENE_SEGMENTED_IMAGE_ITEM_LIB} SHARED - Scene_segmented_image_item.cpp Scene_segmented_image_item.moc) - target_link_libraries(${SCENE_SEGMENTED_IMAGE_ITEM_LIB} ${SCENE_ITEM_LIB} ${CGAL_LIBRARIES} ${TBB_LIBRARIES}) + Scene_segmented_image_item.cpp)# Scene_segmented_image_item.moc) + qt5_use_modules(${SCENE_SEGMENTED_IMAGE_ITEM_LIB} Xml Script OpenGL Svg) + target_link_libraries(${SCENE_SEGMENTED_IMAGE_ITEM_LIB} ${SCENE_ITEM_LIB} ${QGLVIEWER_LIBRARIES} ${CGAL_LIBRARIES} ${TBB_LIBRARIES}) set_target_properties(${SCENE_SEGMENTED_IMAGE_ITEM_LIB} PROPERTIES DEFINE_SYMBOL scene_segmented_image_item_EXPORTS) - if(GLEW_FOUND) - target_link_libraries(${SCENE_SEGMENTED_IMAGE_ITEM_LIB} ${GLEW_LIBRARIES}) - endif() - set(SCENE_POLYHEDRON_ITEM_LIB "${MESH_3_LIB_PREFIX}scene_polyhedron_item") add_library(${SCENE_POLYHEDRON_ITEM_LIB} SHARED - Scene_polyhedron_item.cpp Scene_polyhedron_item.moc) - target_link_libraries(${SCENE_POLYHEDRON_ITEM_LIB} ${SCENE_ITEM_LIB} ${CGAL_LIBRARIES} ${TBB_LIBRARIES}) + Scene_polyhedron_item.cpp )#Scene_polyhedron_item.moc) + qt5_use_modules(${SCENE_POLYHEDRON_ITEM_LIB} Xml Script OpenGL Svg) + target_link_libraries(${SCENE_POLYHEDRON_ITEM_LIB} ${SCENE_ITEM_LIB} ${QGLVIEWER_LIBRARIES} ${CGAL_LIBRARIES} ${TBB_LIBRARIES}) set_target_properties(${SCENE_POLYHEDRON_ITEM_LIB} PROPERTIES DEFINE_SYMBOL scene_polyhedron_item_EXPORTS) set(POLYGON_SOUP_LIB "${MESH_3_LIB_PREFIX}polygon_soup") add_library(${POLYGON_SOUP_LIB} SHARED - Scene_polygon_soup.cpp Scene_polygon_soup.moc) - target_link_libraries(${POLYGON_SOUP_LIB} ${SCENE_ITEM_LIB} ${CGAL_LIBRARIES} ${TBB_LIBRARIES}) + Scene_polygon_soup.cpp )#Scene_polygon_soup.moc) + qt5_use_modules(${POLYGON_SOUP_LIB} Xml Script OpenGL Svg) + target_link_libraries(${POLYGON_SOUP_LIB} ${SCENE_ITEM_LIB} ${QGLVIEWER_LIBRARIES} ${CGAL_LIBRARIES} ${TBB_LIBRARIES}) set_target_properties(${POLYGON_SOUP_LIB} PROPERTIES DEFINE_SYMBOL polygon_soup_EXPORTS) set(SCENE_C3T3_ITEM_LIB "${MESH_3_LIB_PREFIX}scene_c3t3_item") set (SCENE_C3T3_ITEM_LIB_SOURCE_FILES Scene_c3t3_item.cpp) ADD_MSVC_PRECOMPILED_HEADER("StdAfx.h" "StdAfx.cpp" SCENE_C3T3_ITEM_LIB_SOURCE_FILES) - LIST(APPEND SCENE_C3T3_ITEM_LIB_SOURCE_FILES Scene_c3t3_item.moc) + # LIST(APPEND SCENE_C3T3_ITEM_LIB_SOURCE_FILES Scene_c3t3_item.moc) add_library(${SCENE_C3T3_ITEM_LIB} SHARED ${SCENE_C3T3_ITEM_LIB_SOURCE_FILES}) + qt5_use_modules(${SCENE_C3T3_ITEM_LIB} Xml Script OpenGL Svg) target_link_libraries(${SCENE_C3T3_ITEM_LIB} ${SCENE_ITEM_LIB} ${QGLVIEWER_LIBRARIES} ${QT_LIBRARIES} ${CGAL_LIBRARIES} ${Boost_LIBRARIES} ${TBB_LIBRARIES}) set_target_properties(${SCENE_C3T3_ITEM_LIB} PROPERTIES DEFINE_SYMBOL scene_c3t3_item_EXPORTS) set(SCENE_IMPLICIT_FUNCTION_ITEM_LIB "${MESH_3_LIB_PREFIX}scene_implicit_function_item") add_library(${SCENE_IMPLICIT_FUNCTION_ITEM_LIB} SHARED - Scene_implicit_function_item.cpp Scene_implicit_function_item.moc Color_ramp.cpp) + Scene_implicit_function_item.cpp Color_ramp.cpp)#Scene_implicit_function_item.moc) + qt5_use_modules(${SCENE_IMPLICIT_FUNCTION_ITEM_LIB} Xml Script OpenGL Svg) target_link_libraries(${SCENE_IMPLICIT_FUNCTION_ITEM_LIB} ${SCENE_ITEM_LIB} ${QGLVIEWER_LIBRARIES} ${QT_LIBRARIES} ${TBB_LIBRARIES}) set_target_properties(${SCENE_IMPLICIT_FUNCTION_ITEM_LIB} PROPERTIES DEFINE_SYMBOL scene_implicit_function_item_EXPORTS) @@ -234,11 +218,12 @@ if(CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND AND Boost_F MainWindow.cpp Mesh_3.cpp ${DEMO_SRC_DIR}/Scene.cpp - MainWindow_moc.cpp + # MainWindow_moc.cpp Scene_moc.cpp) #ADD_MSVC_PRECOMPILED_HEADER("StdAfx.h" "StdAfx.cpp" MESH_3_SOURCE_FILES) LIST(APPEND MESH_3_SOURCE_FILES ${UI_FILES} ${RESOURCE_FILES}) add_executable( Mesh_3 ${MESH_3_SOURCE_FILES} ) + qt5_use_modules(Mesh_3 Xml Script OpenGL Svg) add_to_cached_list( CGAL_EXECUTABLE_TARGETS Mesh_3 ) # Link with Qt libraries @@ -273,10 +258,11 @@ if(CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND AND Boost_F else() set(other_sources ${ARGN_TAIL}) endif() - qt4_generate_moc( "${CMAKE_CURRENT_SOURCE_DIR}/${plugin_implementation_base_name}.cpp" ${plugin_implementation_base_name}.moc ) + qt5_generate_moc( "${CMAKE_CURRENT_SOURCE_DIR}/${plugin_implementation_base_name}.cpp" ${plugin_implementation_base_name}.moc ) add_file_dependencies( ${plugin_implementation_base_name}.moc "${CMAKE_CURRENT_SOURCE_DIR}/${plugin_implementation_base_name}.cpp" ) add_library(${plugin_name} MODULE ${option} ${plugin_implementation_base_name}.moc ${plugin_implementation_base_name}.cpp ${other_sources}) + qt5_use_modules(${plugin_name} Xml Script OpenGL Svg) add_to_cached_list( CGAL_EXECUTABLE_TARGETS ${plugin_name} ) # Link with Qt target_link_libraries( ${plugin_name} ${QT_LIBRARIES} ) @@ -290,29 +276,23 @@ if(CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND AND Boost_F polyhedron_demo_plugin(${IO_IMAGE_PLUGIN_LIB} Io_image_plugin ${imgUI_FILES}) target_link_libraries(${IO_IMAGE_PLUGIN_LIB} ${SCENE_SEGMENTED_IMAGE_ITEM_LIB}) - if(GLEW_FOUND) - target_link_libraries(${IO_IMAGE_PLUGIN_LIB} ${GLEW_LIBRARIES}) - endif() - set(IO_OFF_PLUGIN_LIB "${MESH_3_LIB_PREFIX}io_off_plugin") polyhedron_demo_plugin(${IO_OFF_PLUGIN_LIB} Io_off_plugin) target_link_libraries(${IO_OFF_PLUGIN_LIB} ${SCENE_POLYHEDRON_ITEM_LIB} ${POLYGON_SOUP_LIB}) - if(GLEW_FOUND) + if(Qt5_FOUND) set(VOLUME_PLANES_PLUGIN_LIB "${MESH_3_LIB_PREFIX}volume_planes_plugin") polyhedron_demo_plugin(${VOLUME_PLANES_PLUGIN_LIB} Volume_planes_plugin ${VOLUME_MOC_OUTFILES} - Volume_plane_intersection.cpp) + Volume_plane_intersection.cpp) target_link_libraries(${VOLUME_PLANES_PLUGIN_LIB} ${SCENE_SEGMENTED_IMAGE_ITEM_LIB} ${VIEWER_LIB}) - else() - message(STATUS "NOTICE: The Volume_plane plugin requires GLEW and will not be compiled.") endif() set(IO_C3T3_PLUGIN_LIB "${MESH_3_LIB_PREFIX}io_c3t3_plugin") polyhedron_demo_plugin(${IO_C3T3_PLUGIN_LIB} Io_c3t3_plugin) target_link_libraries(${IO_C3T3_PLUGIN_LIB} ${SCENE_C3T3_ITEM_LIB}) - if ( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/c3t3_rib_exporter_plugin.cpp" ) + if ( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/C3t3_rib_exporter_plugin.cpp" ) set(C3T3_RIB_EXPORTER_PLUGIN_LIB "${MESH_3_LIB_PREFIX}c3t3_rib_exporter_plugin") polyhedron_demo_plugin(${C3T3_RIB_EXPORTER_PLUGIN_LIB} C3t3_rib_exporter_plugin ${ribUI_FILES}) target_link_libraries(${C3T3_RIB_EXPORTER_PLUGIN_LIB} ${SCENE_C3T3_ITEM_LIB} ${VIEWER_LIB}) @@ -331,7 +311,7 @@ if(CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND AND Boost_F Meshing_thread.cpp) ADD_MSVC_PRECOMPILED_HEADER("StdAfx.h" "StdAfx.cpp" MESH_3_PLUGIN_SOURCE_FILES) LIST(REMOVE_AT MESH_3_PLUGIN_SOURCE_FILES 0) # Remove Mesh_3_plugin.cpp since it's added by polyhedron_demo_plugin - LIST(APPEND MESH_3_PLUGIN_SOURCE_FILES "Scene_c3t3_item.moc" ${meshingUI_FILES}) + LIST(APPEND MESH_3_PLUGIN_SOURCE_FILES ${meshingUI_FILES}) polyhedron_demo_plugin(${MESH_3_PLUGIN_LIB} Mesh_3_plugin ${MESH_3_PLUGIN_SOURCE_FILES}) # set(MESH_3_PLUGIN_LIB "${MESH_3_LIB_PREFIX}mesh_3_plugin") @@ -360,7 +340,7 @@ if(CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND AND Boost_F Optimizer_thread.cpp) ADD_MSVC_PRECOMPILED_HEADER("StdAfx.h" "StdAfx.cpp" MESH_3_OPTIMIZATION_PLUGIN_SOURCE_FILES) LIST(REMOVE_AT MESH_3_OPTIMIZATION_PLUGIN_SOURCE_FILES 0) # Remove Mesh_3_optimization_plugin.cpp since it's added by polyhedron_demo_plugin - LIST(APPEND MESH_3_OPTIMIZATION_PLUGIN_SOURCE_FILES "Scene_c3t3_item.moc" ${optimUI_FILES}) + LIST(APPEND MESH_3_OPTIMIZATION_PLUGIN_SOURCE_FILES ${optimUI_FILES}) polyhedron_demo_plugin(${MESH_3_OPTIMIZATION_PLUGIN_LIB} Mesh_3_optimization_plugin ${MESH_3_OPTIMIZATION_PLUGIN_SOURCE_FILES}) target_link_libraries(${MESH_3_OPTIMIZATION_PLUGIN_LIB} @@ -374,16 +354,16 @@ if(CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND AND Boost_F ${TBB_LIBRARIES}) -else (CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND AND Boost_FOUND) +else (CGAL_Qt5_FOUND AND Qt5_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND AND Boost_FOUND) set(MESH_3_MISSING_DEPS "") - if(NOT CGAL_Qt4_FOUND) - set(MESH_3_MISSING_DEPS "the CGAL Qt4 library, ${MESH_3_MISSING_DEPS}") + if(NOT CGAL_Qt5_FOUND) + set(MESH_3_MISSING_DEPS "the CGAL Qt5 library, ${MESH_3_MISSING_DEPS}") endif() - if(NOT QT4_FOUND) - set(MESH_3_MISSING_DEPS "Qt4, ${MESH_3_MISSING_DEPS}") + if(NOT Qt5_FOUND) + set(MESH_3_MISSING_DEPS "Qt5, ${MESH_3_MISSING_DEPS}") endif() if(NOT OPENGL_FOUND) @@ -408,7 +388,7 @@ else (CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND AND Boos message(STATUS "NOTICE: This demo requires ${MESH_3_MISSING_DEPS}and will not be compiled.") -endif (CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND AND Boost_FOUND) +endif (CGAL_Qt5_FOUND AND Qt5_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND AND Boost_FOUND) diff --git a/Mesh_3/demo/Mesh_3/Io_c3t3_plugin.cpp b/Mesh_3/demo/Mesh_3/Io_c3t3_plugin.cpp index 9039a0b68f8..a2ee2be0df1 100644 --- a/Mesh_3/demo/Mesh_3/Io_c3t3_plugin.cpp +++ b/Mesh_3/demo/Mesh_3/Io_c3t3_plugin.cpp @@ -5,12 +5,14 @@ #include #include + class Io_c3t3_plugin : public QObject, public Io_plugin_interface { Q_OBJECT Q_INTERFACES(Io_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.IOPluginInterface/1.0") public: virtual QStringList nameFilters() const; @@ -22,7 +24,6 @@ public: virtual bool save(const Scene_item*, QFileInfo, QString); }; - QStringList Io_c3t3_plugin::nameFilters() const { @@ -63,7 +64,4 @@ Io_c3t3_plugin::save(const Scene_item* item, QFileInfo fileInfo, QString selecte return true; } - -#include -Q_EXPORT_PLUGIN2(Io_c3t3_plugin, Io_c3t3_plugin) #include "Io_c3t3_plugin.moc" diff --git a/Mesh_3/demo/Mesh_3/Io_image_plugin.cpp b/Mesh_3/demo/Mesh_3/Io_image_plugin.cpp index 13b1b7495bf..dfeece7e1b8 100644 --- a/Mesh_3/demo/Mesh_3/Io_image_plugin.cpp +++ b/Mesh_3/demo/Mesh_3/Io_image_plugin.cpp @@ -1,8 +1,4 @@ #include "config.h" - -#ifdef SCENE_SEGMENTED_IMAGE_GL_BUFFERS_AVAILABLE -# include -#endif #include "Scene_segmented_image_item.h" #include "Image_type.h" #include "ui_Image_res_dialog.h" @@ -16,11 +12,12 @@ class Io_image_plugin : { Q_OBJECT Q_INTERFACES(Io_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.IOPluginInterface/1.0") public: Io_image_plugin() { #ifdef SCENE_SEGMENTED_IMAGE_GL_BUFFERS_AVAILABLE - glewInit(); + // glewInit(); #endif } @@ -32,6 +29,7 @@ public: bool save(const Scene_item*, QFileInfo, QString) { return false; } }; + QStringList Io_image_plugin::nameFilters() const { return QStringList() << "Inrimage files (*.inr *.inr.gz)" << "Analyze files (*.hdr *.img *img.gz)" @@ -89,6 +87,4 @@ bool Io_image_plugin::canSave(const Scene_item*) return false; } -#include -Q_EXPORT_PLUGIN2(Io_image_plugin, Io_image_plugin) #include "Io_image_plugin.moc" diff --git a/Mesh_3/demo/Mesh_3/Io_implicit_function_plugin.cpp b/Mesh_3/demo/Mesh_3/Io_implicit_function_plugin.cpp index 7df27c045ff..8ad0cba4c8d 100644 --- a/Mesh_3/demo/Mesh_3/Io_implicit_function_plugin.cpp +++ b/Mesh_3/demo/Mesh_3/Io_implicit_function_plugin.cpp @@ -40,13 +40,15 @@ #include #include + class Io_implicit_function_plugin : public QObject, protected Plugin_helper { Q_OBJECT Q_INTERFACES(Plugin_interface) - + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") + public: Io_implicit_function_plugin(); virtual ~Io_implicit_function_plugin() {} @@ -197,7 +199,4 @@ load_function_plugins() } } - -#include -Q_EXPORT_PLUGIN2(Io_implicit_function_plugin, Io_implicit_function_plugin) #include "Io_implicit_function_plugin.moc" diff --git a/Mesh_3/demo/Mesh_3/Io_off_plugin.cpp b/Mesh_3/demo/Mesh_3/Io_off_plugin.cpp index fb836f7df6c..b80b6639401 100644 --- a/Mesh_3/demo/Mesh_3/Io_off_plugin.cpp +++ b/Mesh_3/demo/Mesh_3/Io_off_plugin.cpp @@ -7,12 +7,14 @@ #include #include + class Io_off_plugin : public QObject, public Io_plugin_interface { Q_OBJECT Q_INTERFACES(Io_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.IOPluginInterface/1.0") public: QStringList nameFilters() const; @@ -88,7 +90,4 @@ bool Io_off_plugin::save(const Scene_item* item, QFileInfo fileinfo, return (poly_item && poly_item->save(out)) || (soup_item && soup_item->save(out)); } - -#include -Q_EXPORT_PLUGIN2(Io_off_plugin, Io_off_plugin) #include "Io_off_plugin.moc" diff --git a/Mesh_3/demo/Mesh_3/MainWindow.cpp b/Mesh_3/demo/Mesh_3/MainWindow.cpp index e65b725ae20..7fe570843b2 100644 --- a/Mesh_3/demo/Mesh_3/MainWindow.cpp +++ b/Mesh_3/demo/Mesh_3/MainWindow.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -61,12 +62,13 @@ MainWindow::MainWindow(QWidget* parent) treeView->setItemDelegate(new SceneDelegate(this)); treeView->header()->setStretchLastSection(false); - treeView->header()->setResizeMode(Scene::NameColumn, QHeaderView::Stretch); - treeView->header()->setResizeMode(Scene::NameColumn, QHeaderView::Stretch); - treeView->header()->setResizeMode(Scene::ColorColumn, QHeaderView::ResizeToContents); - treeView->header()->setResizeMode(Scene::RenderingModeColumn, QHeaderView::Fixed); - treeView->header()->setResizeMode(Scene::ABColumn, QHeaderView::Fixed); - treeView->header()->setResizeMode(Scene::VisibleColumn, QHeaderView::Fixed); + + treeView->header()->setSectionResizeMode(Scene::NameColumn, QHeaderView::Stretch); + treeView->header()->setSectionResizeMode(Scene::NameColumn, QHeaderView::Stretch); + treeView->header()->setSectionResizeMode(Scene::ColorColumn, QHeaderView::ResizeToContents); + treeView->header()->setSectionResizeMode(Scene::RenderingModeColumn, QHeaderView::Fixed); + treeView->header()->setSectionResizeMode(Scene::ABColumn, QHeaderView::Fixed); + treeView->header()->setSectionResizeMode(Scene::VisibleColumn, QHeaderView::Fixed); treeView->resizeColumnToContents(Scene::ColorColumn); treeView->resizeColumnToContents(Scene::RenderingModeColumn); @@ -164,7 +166,7 @@ MainWindow::MainWindow(QWidget* parent) #endif setWindowTitle(QApplication::translate( - "MainWindow", windowTitle, 0, QApplication::UnicodeUTF8)); + "MainWindow", windowTitle, 0));//UnicodeUTF8)); this->dumpObjectTree(); } diff --git a/Mesh_3/demo/Mesh_3/Mesh_3.cpp b/Mesh_3/demo/Mesh_3/Mesh_3.cpp index a8369b91fc8..6ddb04c34b0 100644 --- a/Mesh_3/demo/Mesh_3/Mesh_3.cpp +++ b/Mesh_3/demo/Mesh_3/Mesh_3.cpp @@ -10,10 +10,12 @@ int main(int argc, char **argv) app.setOrganizationDomain("geometryfactory.com"); app.setOrganizationName("GeometryFactory"); app.setApplicationName("Mesh_3 demo"); + //for windows + app.setAttribute(Qt::AA_UseDesktopOpenGL); - // Import resources from libCGALQt4. - // See http://doc.trolltech.com/4.4/qdir.html#Q_INIT_RESOURCE - CGAL_QT4_INIT_RESOURCES; + // Import resources from libCGALQt ( Qt5). + // See http://doc.qt.io/qt-5/qdir.html#Q_INIT_RESOURCE + CGAL_QT_INIT_RESOURCES; MainWindow mainWindow; mainWindow.show(); diff --git a/Mesh_3/demo/Mesh_3/Mesh_3_optimization_plugin.cpp b/Mesh_3/demo/Mesh_3/Mesh_3_optimization_plugin.cpp index e91f84b46c8..6ab101a12f3 100644 --- a/Mesh_3/demo/Mesh_3/Mesh_3_optimization_plugin.cpp +++ b/Mesh_3/demo/Mesh_3/Mesh_3_optimization_plugin.cpp @@ -32,7 +32,6 @@ #include #include // to get default values - // declare the CGAL function #ifndef CGAL_MESH_3_DEMO_DISABLE_ODT Optimizer_thread* cgal_code_odt_mesh_3(Scene_c3t3_item& c3t3_item, @@ -68,6 +67,7 @@ Optimizer_thread* cgal_code_exude_mesh_3(Scene_c3t3_item& c3t3_item, QString translate(CGAL::Mesh_optimization_return_code rc); + // Mesh_3_optimization_plugin class class Mesh_3_optimization_plugin : public QObject, @@ -75,7 +75,8 @@ class Mesh_3_optimization_plugin : { Q_OBJECT Q_INTERFACES(Plugin_interface) - + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") + typedef Plugin_helper Base; public: Mesh_3_optimization_plugin(); @@ -120,7 +121,6 @@ private: Scene_c3t3_item* source_item_; }; // end class Mesh_3_optimization_plugin - Mesh_3_optimization_plugin:: Mesh_3_optimization_plugin() : actionOdt(NULL) @@ -615,9 +615,6 @@ translate(CGAL::Mesh_optimization_return_code rc) return QString("ERROR"); } - -Q_EXPORT_PLUGIN2(Mesh_3_optimization_plugin, Mesh_3_optimization_plugin) - #include "Mesh_3_optimization_plugin.moc" #endif // CGAL_POLYHEDRON_DEMO_USE_SURFACE_MESHER diff --git a/Mesh_3/demo/Mesh_3/Mesh_3_plugin.cpp b/Mesh_3/demo/Mesh_3/Mesh_3_plugin.cpp index cba7050ae7b..a6118a9a18a 100644 --- a/Mesh_3/demo/Mesh_3/Mesh_3_plugin.cpp +++ b/Mesh_3/demo/Mesh_3/Mesh_3_plugin.cpp @@ -34,6 +34,7 @@ #include #include + // Constants const QColor default_mesh_color(45,169,70); @@ -67,14 +68,14 @@ Meshing_thread* cgal_code_mesh_3(const Implicit_function_interface*, double get_approximate(double d, int precision, int& decimals); - class Mesh_3_plugin : public QObject, protected Plugin_helper { Q_OBJECT Q_INTERFACES(Plugin_interface) - + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") + typedef Plugin_helper Base; public: Mesh_3_plugin(); @@ -117,6 +118,7 @@ private: }; // end class Mesh_3_plugin + Mesh_3_plugin:: Mesh_3_plugin() : actionMesh_3(NULL) @@ -425,7 +427,4 @@ get_approximate(double d, int precision, int& decimals) return std::floor(d)*std::pow(10.,decimals); } - -Q_EXPORT_PLUGIN2(Mesh_3_plugin, Mesh_3_plugin) - #include "Mesh_3_plugin.moc" diff --git a/Mesh_3/demo/Mesh_3/Scene_c3t3_item.cpp b/Mesh_3/demo/Mesh_3/Scene_c3t3_item.cpp index 98207c299b7..c2dd921c4c9 100644 --- a/Mesh_3/demo/Mesh_3/Scene_c3t3_item.cpp +++ b/Mesh_3/demo/Mesh_3/Scene_c3t3_item.cpp @@ -18,44 +18,13 @@ #include #include #include +struct Scene_c3t3_item_priv { + Scene_c3t3_item_priv() : c3t3() {} + Scene_c3t3_item_priv(const C3t3& c3t3_) : c3t3(c3t3_) {} -namespace { - void CGALglcolor(QColor c, int dv = 0) - { - if ( 0 != dv ) - { -// workaround for Qt-4.2. -#if QT_VERSION < 0x040300 -# define darker dark -#endif - c = c.darker(dv); -#undef darker - } - - ::glColor4f(c.red()/255.0, c.green()/255.0, c.blue()/255.0, c.alpha()/255.0); - } -} - -template -std::vector -create_histogram(const C3t3& c3t3, double& min_value, double& max_value); - - -enum { DRAW = 0, DRAW_EDGES = 1 }; - -void draw_triangle(const Kernel::Point_3& pa, - const Kernel::Point_3& pb, - const Kernel::Point_3& pc) { - Kernel::Vector_3 n = cross_product(pb - pa, pc -pa); - n = n / CGAL::sqrt(n*n); - - ::glNormal3d(n.x(),n.y(),n.z()); - - ::glVertex3d(pa.x(),pa.y(),pa.z()); - ::glVertex3d(pb.x(),pb.y(),pb.z()); - ::glVertex3d(pc.x(),pc.y(),pc.z()); -} - + C3t3 c3t3; + QVector colors; +}; double complex_diag(const Scene_item* item) { const Scene_item::Bbox& bbox = item->bbox(); const double& xdelta = bbox.xmax-bbox.xmin; @@ -68,13 +37,652 @@ double complex_diag(const Scene_item* item) { } -struct Scene_c3t3_item_priv { - Scene_c3t3_item_priv() : c3t3() {} - Scene_c3t3_item_priv(const C3t3& c3t3_) : c3t3(c3t3_) {} - C3t3 c3t3; - QVector colors; -}; +/************************************************** +****************SHADER FUNCTIONS******************/ + +void Scene_c3t3_item::compile_shaders() +{ + //The mesh + for(int i=0; i< vboSize; i++) + buffers[i].create(); + for(int i=0; i< vaoSize; i++) + vao[i].create(); + + //Vertex source code + const char vertex_source[] = + { + "#version 330 \n" + "in highp vec4 vertex;\n" + "in highp vec3 normal;\n" + "in highp vec3 inColor; \n" + + "uniform highp mat4 mvp_matrix;\n" + "uniform highp mat4 mv_matrix; \n" + "out highp vec4 fP; \n" + "out highp vec3 fN; \n" + "out highp vec4 color; \n" + "void main(void)\n" + "{\n" + " color = vec4(inColor, 1.0); \n" + " fP = mv_matrix * vertex; \n" + " fN = mat3(mv_matrix)* normal; \n" + " gl_Position = mvp_matrix * vertex; \n" + "}" + }; + //Fragment source code + const char fragment_source[] = + { + "#version 330 \n" + "in highp vec4 fP; \n" + "in highp vec3 fN; \n" + "in vec4 color; \n" + "uniform highp vec4 light_pos; \n" + "uniform highp vec4 light_diff; \n" + "uniform highp vec4 light_spec; \n" + "uniform highp vec4 light_amb; \n" + "uniform float spec_power ; \n" + + "void main(void) { \n" + + " vec3 L = light_pos.xyz - fP.xyz; \n" + " vec3 V = -fP.xyz; \n" + " vec3 N; \n" + " if(fN == vec3(0.0,0.0,0.0)) \n" + " N = vec3(0.0,0.0,0.0); \n" + " else \n" + " N = normalize(fN); \n" + " L = normalize(L); \n" + " V = normalize(V); \n" + " vec3 R = reflect(-L, N); \n" + " vec4 diffuse = max(abs(dot(N,L)),0) * light_diff*color; \n" + " vec4 specular = pow(max(dot(R,V), 0.0), spec_power) * light_spec; \n" + + "gl_FragColor = color*light_amb + diffuse + specular; \n" + "} \n" + "\n" + }; + QOpenGLShader *vertex_shader = new QOpenGLShader(QOpenGLShader::Vertex); + if(!vertex_shader->compileSourceCode(vertex_source)) + { + std::cerr<<"Compiling vertex source FAILED"<compileSourceCode(fragment_source)) + { + std::cerr<<"Compiling fragmentsource FAILED"<compileSourceCode(vertex_source_grid)) + { + std::cerr<<"Compiling vertex source FAILED"<compileSourceCode(fragment_source_grid )) + { + std::cerr<<"Compiling fragmentsource FAILED"<plane(); +//TRIANGLES + for(C3t3::Facets_in_complex_iterator + fit = c3t3().facets_in_complex_begin(), + end = c3t3().facets_in_complex_end(); + fit != end; ++fit) + { + const Tr::Cell_handle& cell = fit->first; + const int& index = fit->second; + if(cell->subdomain_index() != 0 && + cell->neighbor(index)->subdomain_index() != 0) + { + continue; + } + + const Kernel::Point_3& pa = cell->vertex((index+1)&3)->point(); + const Kernel::Point_3& pb = cell->vertex((index+2)&3)->point(); + const Kernel::Point_3& pc = cell->vertex((index+3)&3)->point(); + typedef Kernel::Oriented_side Side; + using CGAL::ON_ORIENTED_BOUNDARY; + using CGAL::ON_NEGATIVE_SIDE; + const Side sa = plane.oriented_side(pa); + const Side sb = plane.oriented_side(pb); + const Side sc = plane.oriented_side(pc); + if(sa == ON_NEGATIVE_SIDE && + sb == ON_NEGATIVE_SIDE && + sc == ON_NEGATIVE_SIDE) + { + #ifdef SHOW_REMAINING_BAD_ELEMENT_IN_RED + + Tr::Facet mirror_facet = c3t3().triangulation().mirror_facet(*fit); + bool blueOrRed = false; + if(cell->mark == index || mirror_facet.first->mark == mirror_facet.second) + { + std::cerr << "================== BAD TRIANGLE =================" << std::endl; + blueOrRed = true; + + if(cell->mark2 != -1) + { + const Kernel::Point_3& pa2 = cell->vertex((cell->mark2+1)&3)->point(); + const Kernel::Point_3& pb2 = cell->vertex((cell->mark2+2)&3)->point(); + const Kernel::Point_3& pc2 = cell->vertex((cell->mark2+3)&3)->point(); + + std::cerr << "================== BLUE =================" << std::endl; + + Kernel::Vector_3 n = cross_product(pb2 - pa2, pc2 -pa2); + n = n / CGAL::sqrt(n*n); + + normal.push_back(n.x()); normal.push_back(n.y()); normal.push_back(n.z()); + normal.push_back(n.x()); normal.push_back(n.y()); normal.push_back(n.z()); + normal.push_back(n.x()); normal.push_back(n.y()); normal.push_back(n.z()); + v_poly.push_back(pa2.x()); v_poly.push_back(pa2.y()); v_poly.push_back(pa2.z()); + v_poly.push_back(pb2.x()); v_poly.push_back(pb2.y()); v_poly.push_back(pb2.z()); + v_poly.push_back(pc2.x()); v_poly.push_back(pc2.y()); v_poly.push_back(pc2.z()); + color_triangles.push_back(0.0); color_triangles.push_back(0.0); color_triangles.push_back(1.0); + color_triangles.push_back(0.0); color_triangles.push_back(0.0); color_triangles.push_back(1.0); + color_triangles.push_back(0.0); color_triangles.push_back(0.0); color_triangles.push_back(1.0); + + const Tr::Facet f_blue(cell, cell->mark2); + Tr::Facet mirror_f_blue = c3t3().triangulation().mirror_facet(f_blue); + const Kernel::Point_3& dual_edge_pa = c3t3().triangulation().dual(f_blue.first); + const Kernel::Point_3& dual_edge_pb = c3t3().triangulation().dual(mirror_f_blue.first); + const Kernel::Point_3& dual_edge_pc = dual_edge_pa + Kernel::Vector_3(0.001, 0., 0.); + Kernel::Vector_3 n = cross_product(dual_edge_pb - dual_edge_pa, dual_edge_pc -dual_edge_pa); + n = n / CGAL::sqrt(n*n); + + normal.push_back(n.x()); normal.push_back(n.y()); normal.push_back(n.z()); + normal.push_back(n.x()); normal.push_back(n.y()); normal.push_back(n.z()); + normal.push_back(n.x()); normal.push_back(n.y()); normal.push_back(n.z()); + + v_poly.push_back(dual_edge_pa.x()); v_poly.push_back(dual_edge_pa.y()); v_poly.push_back(dual_edge_pa.z()); + v_poly.push_back(dual_edge_pb.x()); v_poly.push_back(dual_edge_pb.y()); v_poly.push_back(dual_edge_pb.z()); + v_poly.push_back(dual_edge_pc.x()); v_poly.push_back(dual_edge_pc.y()); v_poly.push_back(dual_edge_pc.z()); + + color_triangles.push_back(1.0); color_triangles.push_back(1.0); color_triangles.push_back(0.0); + color_triangles.push_back(1.0); color_triangles.push_back(1.0); color_triangles.push_back(0.0); + color_triangles.push_back(1.0); color_triangles.push_back(1.0); color_triangles.push_back(0.0); + + else if(mirror_facet.first->mark2 != -1) + { + const Kernel::Point_3& pa2 = mirror_facet.first->vertex((mirror_facet.first->mark2+1)&3)->point(); + const Kernel::Point_3& pb2 = mirror_facet.first->vertex((mirror_facet.first->mark2+2)&3)->point(); + const Kernel::Point_3& pc2 = mirror_facet.first->vertex((mirror_facet.first->mark2+3)&3)->point(); + + + std::cerr << "================== BLUE =================" << std::endl; + Kernel::Vector_3 n = cross_product(pb2 - pa2, pc2 -pa2); + n = n / CGAL::sqrt(n*n); + + normal.push_back(n.x()); normal.push_back(n.y()); normal.push_back(n.z()); + normal.push_back(n.x()); normal.push_back(n.y()); normal.push_back(n.z()); + normal.push_back(n.x()); normal.push_back(n.y()); normal.push_back(n.z()); + v_poly.push_back(pa2.x()); v_poly.push_back(pa2.y()); v_poly.push_back(pa2.z()); + v_poly.push_back(pb2.x()); v_poly.push_back(pb2.y()); v_poly.push_back(pb2.z()); + v_poly.push_back(pc2.x()); v_poly.push_back(pc2.y()); v_poly.push_back(pc2.z()); + color_triangles.push_back(0.0); color_triangles.push_back(0.0); color_triangles.push_back(1.0); + color_triangles.push_back(0.0); color_triangles.push_back(0.0); color_triangles.push_back(1.0); + color_triangles.push_back(0.0); color_triangles.push_back(0.0); color_triangles.push_back(1.0); + + + const Tr::Facet f_blue(mirror_facet.first, mirror_facet.first->mark2); + Tr::Facet mirror_f_blue = c3t3().triangulation().mirror_facet(f_blue); + const Kernel::Point_3& dual_edge_pa = c3t3().triangulation().dual(f_blue.first); + const Kernel::Point_3& dual_edge_pb = c3t3().triangulation().dual(mirror_f_blue.first); + const Kernel::Point_3& dual_edge_pc = dual_edge_pa + Kernel::Vector_3(0.001, 0., 0.); + + Kernel::Vector_3 n = cross_product(dual_edge_pb - dual_edge_pa, dual_edge_pc -dual_edge_pa); + n = n / CGAL::sqrt(n*n); + + normal.push_back(n.x()); normal.push_back(n.y()); normal.push_back(n.z()); + normal.push_back(n.x()); normal.push_back(n.y()); normal.push_back(n.z()); + normal.push_back(n.x()); normal.push_back(n.y()); normal.push_back(n.z()); + + v_poly.push_back(dual_edge_pa.x()); v_poly.push_back(dual_edge_pa.y()); v_poly.push_back(dual_edge_pa.z()); + v_poly.push_back(dual_edge_pb.x()); v_poly.push_back(dual_edge_pb.y()); v_poly.push_back(dual_edge_pb.z()); + v_poly.push_back(dual_edge_pc.x()); v_poly.push_back(dual_edge_pc.y()); v_poly.push_back(dual_edge_pc.z()); + + color_triangles.push_back(1.0); color_triangles.push_back(1.0); color_triangles.push_back(0.0); + color_triangles.push_back(1.0); color_triangles.push_back(1.0); color_triangles.push_back(0.0); + color_triangles.push_back(1.0); color_triangles.push_back(1.0); color_triangles.push_back(0.0); + } + } + else + { + Kernel::Vector_3 n = cross_product(pb - pa, pc - pa); + n = n / CGAL::sqrt(n*n); + + normal.push_back(n.x()); normal.push_back(n.y()); normal.push_back(n.z()); + normal.push_back(n.x()); normal.push_back(n.y()); normal.push_back(n.z()); + normal.push_back(n.x()); normal.push_back(n.y()); normal.push_back(n.z()); + + v_poly.push_back(pa.x()); v_poly.push_back(pa.y()); v_poly.push_back(pa.z()); + v_poly.push_back(pb.x()); v_poly.push_back(pb.y()); v_poly.push_back(pb.z()); + v_poly.push_back(pc.x()); v_poly.push_back(pc.y()); v_poly.push_back(pc.z()); + + if(cell->subdomain_index() == 0) { + color_triangles.push_back(d->colors[cell->neighbor(index)->subdomain_index()].redF()); + color_triangles.push_back(d->colors[cell->neighbor(index)->subdomain_index()].greenF()); + color_triangles.push_back(d->colors[cell->neighbor(index)->subdomain_index()].blueF()); + color_triangles.push_back(d->colors[cell->neighbor(index)->subdomain_index()].redF()); + color_triangles.push_back(d->colors[cell->neighbor(index)->subdomain_index()].greenF()); + color_triangles.push_back(d->colors[cell->neighbor(index)->subdomain_index()].blueF()); + color_triangles.push_back(d->colors[cell->neighbor(index)->subdomain_index()].redF()); + color_triangles.push_back(d->colors[cell->neighbor(index)->subdomain_index()].greenF()); + color_triangles.push_back(d->colors[cell->neighbor(index)->subdomain_index()].blueF()); + + } + else { + CGALglcolor(d->colors[cell->subdomain_index()]); + color_triangles.push_back(d->colors[cell->subdomain_index()].redF()); + color_triangles.push_back(d->colors[cell->subdomain_index()].greenF()); + color_triangles.push_back(d->colors[cell->subdomain_index()].blueF()); + color_triangles.push_back(d->colors[cell->subdomain_index()].redF()); + color_triangles.push_back(d->colors[cell->subdomain_index()].greenF()); + color_triangles.push_back(d->colors[cell->subdomain_index()].blueF()); + color_triangles.push_back(d->colors[cell->subdomain_index()].redF()); + color_triangles.push_back(d->colors[cell->subdomain_index()].greenF()); + color_triangles.push_back(d->colors[cell->subdomain_index()].blueF()); + } + } + } + + + #else + Kernel::Vector_3 n = cross_product(pb - pa, pc - pa); + n = n / CGAL::sqrt(n*n); + + normal.push_back(n.x()); normal.push_back(n.y()); normal.push_back(n.z()); + normal.push_back(n.x()); normal.push_back(n.y()); normal.push_back(n.z()); + normal.push_back(n.x()); normal.push_back(n.y()); normal.push_back(n.z()); + + v_poly.push_back(pa.x()); v_poly.push_back(pa.y()); v_poly.push_back(pa.z()); + v_poly.push_back(pb.x()); v_poly.push_back(pb.y()); v_poly.push_back(pb.z()); + v_poly.push_back(pc.x()); v_poly.push_back(pc.y()); v_poly.push_back(pc.z()); + + if(cell->subdomain_index() == 0) { + color_triangles.push_back(d->colors[cell->neighbor(index)->subdomain_index()].redF()); + color_triangles.push_back(d->colors[cell->neighbor(index)->subdomain_index()].greenF()); + color_triangles.push_back(d->colors[cell->neighbor(index)->subdomain_index()].blueF()); + color_triangles.push_back(d->colors[cell->neighbor(index)->subdomain_index()].redF()); + color_triangles.push_back(d->colors[cell->neighbor(index)->subdomain_index()].greenF()); + color_triangles.push_back(d->colors[cell->neighbor(index)->subdomain_index()].blueF()); + color_triangles.push_back(d->colors[cell->neighbor(index)->subdomain_index()].redF()); + color_triangles.push_back(d->colors[cell->neighbor(index)->subdomain_index()].greenF()); + color_triangles.push_back(d->colors[cell->neighbor(index)->subdomain_index()].blueF()); + + } + else { + color_triangles.push_back(d->colors[cell->subdomain_index()].redF()); + color_triangles.push_back(d->colors[cell->subdomain_index()].greenF()); + color_triangles.push_back(d->colors[cell->subdomain_index()].blueF()); + color_triangles.push_back(d->colors[cell->subdomain_index()].redF()); + color_triangles.push_back(d->colors[cell->subdomain_index()].greenF()); + color_triangles.push_back(d->colors[cell->subdomain_index()].blueF()); + color_triangles.push_back(d->colors[cell->subdomain_index()].redF()); + color_triangles.push_back(d->colors[cell->subdomain_index()].greenF()); + color_triangles.push_back(d->colors[cell->subdomain_index()].blueF()); + } + #endif + } + } + +//end TRIANGLES + //re TRIANGLES + for(Tr::Finite_cells_iterator + cit = c3t3().triangulation().finite_cells_begin(), + end = c3t3().triangulation().finite_cells_end(); + cit != end; ++cit) + { + if(! c3t3().is_in_complex(cit) ) + continue; + + const Kernel::Point_3& pa = cit->vertex(0)->point(); + const Kernel::Point_3& pb = cit->vertex(1)->point(); + const Kernel::Point_3& pc = cit->vertex(2)->point(); + const Kernel::Point_3& pd = cit->vertex(3)->point(); + typedef Kernel::Oriented_side Side; + using CGAL::ON_ORIENTED_BOUNDARY; + const Side sa = plane.oriented_side(pa); + const Side sb = plane.oriented_side(pb); + const Side sc = plane.oriented_side(pc); + const Side sd = plane.oriented_side(pd); + + if( sa == ON_ORIENTED_BOUNDARY || + sb == ON_ORIENTED_BOUNDARY || + sc == ON_ORIENTED_BOUNDARY || + sd == ON_ORIENTED_BOUNDARY || + sb != sa || sc != sa || sd != sa) + { + QColor temp = d->colors[cit->subdomain_index()].darker(150); + color_triangles.push_back(temp.redF()); + color_triangles.push_back(temp.greenF()); + color_triangles.push_back(temp.blueF()); + color_triangles.push_back(temp.redF()); + color_triangles.push_back(temp.greenF()); + color_triangles.push_back(temp.blueF()); + color_triangles.push_back(temp.redF()); + color_triangles.push_back(temp.greenF()); + color_triangles.push_back(temp.blueF()); + + color_triangles.push_back(temp.redF()); + color_triangles.push_back(temp.greenF()); + color_triangles.push_back(temp.blueF()); + color_triangles.push_back(temp.redF()); + color_triangles.push_back(temp.greenF()); + color_triangles.push_back(temp.blueF()); + color_triangles.push_back(temp.redF()); + color_triangles.push_back(temp.greenF()); + color_triangles.push_back(temp.blueF()); + + color_triangles.push_back(temp.redF()); + color_triangles.push_back(temp.greenF()); + color_triangles.push_back(temp.blueF()); + color_triangles.push_back(temp.redF()); + color_triangles.push_back(temp.greenF()); + color_triangles.push_back(temp.blueF()); + color_triangles.push_back(temp.redF()); + color_triangles.push_back(temp.greenF()); + color_triangles.push_back(temp.blueF()); + + color_triangles.push_back(temp.redF()); + color_triangles.push_back(temp.greenF()); + color_triangles.push_back(temp.blueF()); + color_triangles.push_back(temp.redF()); + color_triangles.push_back(temp.greenF()); + color_triangles.push_back(temp.blueF()); + color_triangles.push_back(temp.redF()); + color_triangles.push_back(temp.greenF()); + color_triangles.push_back(temp.blueF()); + + + Kernel::Vector_3 n = cross_product(pb - pa, pc - pa); + n = n / CGAL::sqrt(n*n); + + normal.push_back(n.x()); normal.push_back(n.y()); normal.push_back(n.z()); + normal.push_back(n.x()); normal.push_back(n.y()); normal.push_back(n.z()); + normal.push_back(n.x()); normal.push_back(n.y()); normal.push_back(n.z()); + + v_poly.push_back(pa.x()); v_poly.push_back(pa.y()); v_poly.push_back(pa.z()); + v_poly.push_back(pb.x()); v_poly.push_back(pb.y()); v_poly.push_back(pb.z()); + v_poly.push_back(pc.x()); v_poly.push_back(pc.y()); v_poly.push_back(pc.z()); + + n = cross_product(pb - pa, pd - pa); + n = n / CGAL::sqrt(n*n); + + normal.push_back(n.x()); normal.push_back(n.y()); normal.push_back(n.z()); + normal.push_back(n.x()); normal.push_back(n.y()); normal.push_back(n.z()); + normal.push_back(n.x()); normal.push_back(n.y()); normal.push_back(n.z()); + + v_poly.push_back(pa.x()); v_poly.push_back(pa.y()); v_poly.push_back(pa.z()); + v_poly.push_back(pb.x()); v_poly.push_back(pb.y()); v_poly.push_back(pb.z()); + v_poly.push_back(pd.x()); v_poly.push_back(pd.y()); v_poly.push_back(pd.z()); + + n = cross_product(pc - pa, pd - pa); + n = n / CGAL::sqrt(n*n); + + normal.push_back(n.x()); normal.push_back(n.y()); normal.push_back(n.z()); + normal.push_back(n.x()); normal.push_back(n.y()); normal.push_back(n.z()); + normal.push_back(n.x()); normal.push_back(n.y()); normal.push_back(n.z()); + + v_poly.push_back(pa.x()); v_poly.push_back(pa.y()); v_poly.push_back(pa.z()); + v_poly.push_back(pc.x()); v_poly.push_back(pc.y()); v_poly.push_back(pc.z()); + v_poly.push_back(pd.x()); v_poly.push_back(pd.y()); v_poly.push_back(pd.z()); + + n = cross_product(pc - pb, pd - pb); + n = n / CGAL::sqrt(n*n); + + normal.push_back(n.x()); normal.push_back(n.y()); normal.push_back(n.z()); + normal.push_back(n.x()); normal.push_back(n.y()); normal.push_back(n.z()); + normal.push_back(n.x()); normal.push_back(n.y()); normal.push_back(n.z()); + + v_poly.push_back(pb.x()); v_poly.push_back(pb.y()); v_poly.push_back(pb.z()); + v_poly.push_back(pc.x()); v_poly.push_back(pc.y()); v_poly.push_back(pc.z()); + v_poly.push_back(pd.x()); v_poly.push_back(pd.y()); v_poly.push_back(pd.z()); + } + } +//re end TRIANGLES + +} + +void Scene_c3t3_item::initialize_buffers() const +{ + rendering_program.bind(); + + vao[0].bind(); + buffers[0].bind(); + buffers[0].allocate(v_poly.data(), static_cast(v_poly.size()*sizeof(float))); + poly_vertexLocation[0] = rendering_program.attributeLocation("vertex"); + rendering_program.enableAttributeArray(poly_vertexLocation[0]); + rendering_program.setAttributeBuffer(poly_vertexLocation[0],GL_FLOAT,0,3); + buffers[0].release(); + + buffers[1].bind(); + buffers[1].allocate(normal.data(), static_cast(normal.size()*sizeof(float))); + normalsLocation[0] = rendering_program.attributeLocation("normal"); + rendering_program.enableAttributeArray(normalsLocation[0]); + rendering_program.setAttributeBuffer(normalsLocation[0],GL_FLOAT,0,3); + buffers[1].release(); + + buffers[2].bind(); + buffers[2].allocate(color_triangles.data(), static_cast(color_triangles.size()*sizeof(float))); + colorLocation[0] = rendering_program.attributeLocation("inColor"); + rendering_program.enableAttributeArray(colorLocation[0]); + rendering_program.setAttributeBuffer(colorLocation[0],GL_FLOAT,0,3); + buffers[2].release(); + + vao[0].release(); + + rendering_program.release(); + + rendering_program_grid.bind(); + + vao[1].bind(); + buffers[3].bind(); + buffers[3].allocate(v_grid->data(), static_cast(v_grid->size()*sizeof(float))); + poly_vertexLocation[1] = rendering_program.attributeLocation("vertex"); + rendering_program.enableAttributeArray(poly_vertexLocation[1]); + rendering_program.setAttributeBuffer(poly_vertexLocation[1],GL_FLOAT,0,3); + buffers[3].release(); + vao[1].release(); + + rendering_program_grid.release(); + are_buffers_initialized = true; + +} + +void Scene_c3t3_item::attrib_buffers(QGLViewer* viewer) const +{ + QMatrix4x4 mvpMatrix; + QMatrix4x4 mvMatrix; + QMatrix4x4 fMatrix; + double mat[16]; + viewer->camera()->getModelViewProjectionMatrix(mat); + for(int i=0; i < 16; i++) + { + mvpMatrix.data()[i] = (float)mat[i]; + } + viewer->camera()->getModelViewMatrix(mat); + for(int i=0; i < 16; i++) + { + mvMatrix.data()[i] = (float)mat[i]; + } + frame->getMatrix(mat); + for(int i=0; i < 16; i++) + { + fMatrix.data()[i] = (float)mat[i]; + } + + + QVector4D position(0.0f,0.0f,1.0f,1.0f ); + GLboolean isTwoSide; + gl.glGetBooleanv(GL_LIGHT_MODEL_TWO_SIDE,&isTwoSide); + // define material + QVector4D ambient; + QVector4D diffuse; + QVector4D specular; + GLfloat shininess ; + // Ambient + ambient[0] = 0.29225f; + ambient[1] = 0.29225f; + ambient[2] = 0.29225f; + ambient[3] = 1.0f; + // Diffuse + diffuse[0] = 0.50754f; + diffuse[1] = 0.50754f; + diffuse[2] = 0.50754f; + diffuse[3] = 1.0f; + // Specular + specular[0] = 0.0f; + specular[1] = 0.0f; + specular[2] = 0.0f; + specular[3] = 0.0f; + // Shininess + shininess = 51.2f; + + + rendering_program.bind(); + mvpLocation[0] = rendering_program.uniformLocation("mvp_matrix"); + mvLocation[0] = rendering_program.uniformLocation("mv_matrix"); + lightLocation[0] = rendering_program.uniformLocation("light_pos"); + lightLocation[1] = rendering_program.uniformLocation("light_diff"); + lightLocation[2] = rendering_program.uniformLocation("light_spec"); + lightLocation[3] = rendering_program.uniformLocation("light_amb"); + lightLocation[4] = rendering_program.uniformLocation("spec_power"); + + rendering_program.release(); + rendering_program_grid.bind(); + + mvpLocation[1] = rendering_program_grid.uniformLocation("mvp_matrix"); + fmatLocation = rendering_program_grid.uniformLocation("f_matrix"); + colorLocation[1] = rendering_program_grid.uniformLocation("color"); + rendering_program_grid.release(); + + rendering_program.bind(); + rendering_program.setUniformValue(lightLocation[0], position); + rendering_program.setUniformValue(twosideLocation, isTwoSide); + rendering_program.setUniformValue(mvpLocation[0], mvpMatrix); + rendering_program.setUniformValue(mvLocation[0], mvMatrix); + rendering_program.setUniformValue(lightLocation[1], diffuse); + rendering_program.setUniformValue(lightLocation[2], specular); + rendering_program.setUniformValue(lightLocation[3], ambient); + rendering_program.setUniformValue(lightLocation[4], shininess); + rendering_program.release(); + + rendering_program_grid.bind(); + rendering_program_grid.setUniformValue(mvpLocation[1], mvpMatrix); + rendering_program_grid.setUniformValue(fmatLocation, fMatrix); + rendering_program_grid.release(); + +} + +enum { DRAW = 0, DRAW_EDGES = 1 }; + +void +Scene_c3t3_item::draw(QGLViewer *viewer)const { + if(!are_ogfunctions_initialized) + { + gl.initializeOpenGLFunctions(); + are_ogfunctions_initialized = true; + } + if(!are_buffers_initialized) + initialize_buffers(); + vao[0].bind(); + attrib_buffers(viewer); + rendering_program.bind(); + gl.glDrawArrays(GL_TRIANGLES, 0, static_cast(v_poly.size()/3)); + rendering_program.release(); + vao[0].release(); +} + +void +Scene_c3t3_item::draw_edges(QGLViewer* viewer) const { + if(!are_ogfunctions_initialized) + { + gl.initializeOpenGLFunctions(); + are_ogfunctions_initialized = true; + } + if(!are_buffers_initialized) + initialize_buffers(); + vao[1].bind(); + attrib_buffers(viewer); + rendering_program_grid.bind(); + QColor color; + color.setRgbF(this->color().redF(), this->color().greenF(), this->color().blueF()); + rendering_program_grid.setUniformValue(colorLocation[1], color); + gl.glDrawArrays(GL_LINES, 0, static_cast(v_grid->size()/3)); + rendering_program_grid.release(); + vao[1].release(); +} + + + +template +std::vector +create_histogram(const C3t3& c3t3, double& min_value, double& max_value); Scene_c3t3_item:: @@ -85,6 +693,8 @@ Scene_c3t3_item() , data_item_(NULL) , indices_() { + v_grid = new std::vector(); + compile_shaders(); connect(frame, SIGNAL(modified()), this, SLOT(changed())); c3t3_changed(); } @@ -93,12 +703,17 @@ Scene_c3t3_item::Scene_c3t3_item(const C3t3& c3t3) : d(new Scene_c3t3_item_priv(c3t3)), frame(new ManipulatedFrame()) , histogram_(), data_item_(NULL), indices_() { + compile_shaders(); connect(frame, SIGNAL(modified()), this, SLOT(changed())); c3t3_changed(); } Scene_c3t3_item::~Scene_c3t3_item() { + for(int i=0; iname()); } -void -Scene_c3t3_item::direct_draw() const { - direct_draw(DRAW); -} - -void -Scene_c3t3_item::direct_draw_edges() const { - direct_draw(DRAW_EDGES); -} - -void -Scene_c3t3_item::direct_draw(int mode) const { - ::glPushMatrix(); - ::glMultMatrixd(frame->matrix()); - QGLViewer::drawGrid((float)complex_diag(this)); - ::glPopMatrix(); - - if(isEmpty()) - return; - - CGALglcolor(QColor(0,0,0)); - - //std::cerr << "Direct_draw " << mode << "\n"; - GLboolean lighting = ::glIsEnabled(GL_LIGHTING); - GLboolean two_side; - ::glGetBooleanv(GL_LIGHT_MODEL_TWO_SIDE, &two_side); - ::glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); - if(!lighting) - ::glDisable(GL_LIGHTING); - - const Kernel::Plane_3& plane = this->plane(); - - ::glBegin(GL_TRIANGLES); - for(C3t3::Facets_in_complex_iterator - fit = c3t3().facets_in_complex_begin(), - end = c3t3().facets_in_complex_end(); - fit != end; ++fit) - { - const Tr::Cell_handle& cell = fit->first; - const int& index = fit->second; - if(cell->subdomain_index() != 0 && - cell->neighbor(index)->subdomain_index() != 0) - { - continue; - } - - const Kernel::Point_3& pa = cell->vertex((index+1)&3)->point(); - const Kernel::Point_3& pb = cell->vertex((index+2)&3)->point(); - const Kernel::Point_3& pc = cell->vertex((index+3)&3)->point(); - typedef Kernel::Oriented_side Side; - using CGAL::ON_ORIENTED_BOUNDARY; - using CGAL::ON_NEGATIVE_SIDE; - const Side sa = plane.oriented_side(pa); - const Side sb = plane.oriented_side(pb); - const Side sc = plane.oriented_side(pc); - if(sa == ON_NEGATIVE_SIDE && - sb == ON_NEGATIVE_SIDE && - sc == ON_NEGATIVE_SIDE) - { -#ifdef SHOW_REMAINING_BAD_ELEMENT_IN_RED - if(mode != DRAW_EDGES) - { - Tr::Facet mirror_facet = c3t3().triangulation().mirror_facet(*fit); - //int mirror_index = c3t3().triangulation().mirror_index(cell, index); - bool blueOrRed = false; - if(cell->mark == index || mirror_facet.first->mark == mirror_facet.second) - { - std::cerr << "================== BAD TRIANGLE =================" << std::endl; - blueOrRed = true; - - if(cell->mark2 != -1) - { - const Kernel::Point_3& pa2 = cell->vertex((cell->mark2+1)&3)->point(); - const Kernel::Point_3& pb2 = cell->vertex((cell->mark2+2)&3)->point(); - const Kernel::Point_3& pc2 = cell->vertex((cell->mark2+3)&3)->point(); - - CGALglcolor(QColor("blue")); - std::cerr << "================== BLUE =================" << std::endl; - draw_triangle(pa2, pb2, pc2); - - const Tr::Facet f_blue(cell, cell->mark2); - Tr::Facet mirror_f_blue = c3t3().triangulation().mirror_facet(f_blue); - const Kernel::Point_3& dual_edge_pa = c3t3().triangulation().dual(f_blue.first); - const Kernel::Point_3& dual_edge_pb = c3t3().triangulation().dual(mirror_f_blue.first); - const Kernel::Point_3& dual_edge_pc = dual_edge_pa + Kernel::Vector_3(0.001, 0., 0.); - CGALglcolor(QColor("yellow")); - draw_triangle(dual_edge_pa, dual_edge_pb, dual_edge_pc); - } - else if(mirror_facet.first->mark2 != -1) - { - const Kernel::Point_3& pa2 = mirror_facet.first->vertex((mirror_facet.first->mark2+1)&3)->point(); - const Kernel::Point_3& pb2 = mirror_facet.first->vertex((mirror_facet.first->mark2+2)&3)->point(); - const Kernel::Point_3& pc2 = mirror_facet.first->vertex((mirror_facet.first->mark2+3)&3)->point(); - - CGALglcolor(QColor("blue")); - std::cerr << "================== BLUE =================" << std::endl; - draw_triangle(pa2, pb2, pc2); - - const Tr::Facet f_blue(mirror_facet.first, mirror_facet.first->mark2); - Tr::Facet mirror_f_blue = c3t3().triangulation().mirror_facet(f_blue); - const Kernel::Point_3& dual_edge_pa = c3t3().triangulation().dual(f_blue.first); - const Kernel::Point_3& dual_edge_pb = c3t3().triangulation().dual(mirror_f_blue.first); - const Kernel::Point_3& dual_edge_pc = dual_edge_pa + Kernel::Vector_3(0.001, 0., 0.); - CGALglcolor(QColor("yellow")); - draw_triangle(dual_edge_pa, dual_edge_pb, dual_edge_pc); - } - - /* - //const Kernel::Point_3& dual_edge_pa = cell->circumcenter(); - //const Kernel::Point_3& dual_edge_pb = mirror_facet.first->circumcenter(); - const Kernel::Point_3& dual_edge_pa = c3t3().triangulation().dual(cell); - const Kernel::Point_3& dual_edge_pb = c3t3().triangulation().dual(mirror_facet.first); - const Kernel::Point_3& dual_edge_pc = dual_edge_pa + Kernel::Vector_3(0.001, 0., 0.); - CGALglcolor(QColor("yellow")); - draw_triangle(dual_edge_pa, dual_edge_pb, dual_edge_pc); - */ - } - else - { - if(cell->subdomain_index() == 0) { - CGALglcolor(d->colors[cell->neighbor(index)->subdomain_index()]); - } - else { - CGALglcolor(d->colors[cell->subdomain_index()]); - } - draw_triangle(pa, pb, pc); - } - } - - /*if(mode != DRAW_EDGES) { - - Tr::Facet mirror_facet = c3t3().triangulation().mirror_facet(*fit); - //int mirror_index = c3t3().triangulation().mirror_index(cell, index); - bool blueOrRed = false; - if(cell->mark == index || mirror_facet.first->mark == mirror_facet.second) { - //if (cell->mark != -1 || cell->neighbor(index)->mark != -1) { - CGALglcolor(QColor("red")); - std::cerr << "================== RED =================" << std::endl; - blueOrRed = true; - } - - if(cell->mark2 == index || mirror_facet.first->mark2 == mirror_facet.second) { - //if(cell->mark2 != -1 || mirror_facet.first->mark2 != -1) { - CGALglcolor(QColor("blue")); - std::cerr << "================== BLUE =================" << std::endl; - blueOrRed = true; - } - - if (!blueOrRed) - { - if(cell->subdomain_index() == 0) { - CGALglcolor(d->colors[cell->neighbor(index)->subdomain_index()]); - } - else { - CGALglcolor(d->colors[cell->subdomain_index()]); - } - } - } - draw_triangle(pa, pb, pc);*/ - -#else - if(mode != DRAW_EDGES) { - if(cell->subdomain_index() == 0) { - CGALglcolor(d->colors[cell->neighbor(index)->subdomain_index()]); - } - else { - CGALglcolor(d->colors[cell->subdomain_index()]); - } - } - draw_triangle(pa, pb, pc); -#endif - } - } - ::glEnd(); - - ::glBegin(GL_TRIANGLES); - for(Tr::Finite_cells_iterator - cit = c3t3().triangulation().finite_cells_begin(), - end = c3t3().triangulation().finite_cells_end(); - cit != end; ++cit) - { - if(! c3t3().is_in_complex(cit) ) - continue; - - const Kernel::Point_3& pa = cit->vertex(0)->point(); - const Kernel::Point_3& pb = cit->vertex(1)->point(); - const Kernel::Point_3& pc = cit->vertex(2)->point(); - const Kernel::Point_3& pd = cit->vertex(3)->point(); - typedef Kernel::Oriented_side Side; - using CGAL::ON_ORIENTED_BOUNDARY; - const Side sa = plane.oriented_side(pa); - const Side sb = plane.oriented_side(pb); - const Side sc = plane.oriented_side(pc); - const Side sd = plane.oriented_side(pd); - - if( sa == ON_ORIENTED_BOUNDARY || - sb == ON_ORIENTED_BOUNDARY || - sc == ON_ORIENTED_BOUNDARY || - sd == ON_ORIENTED_BOUNDARY || - sb != sa || sc != sa || sd != sa) - { - if(mode != DRAW_EDGES) { - CGALglcolor(d->colors[cit->subdomain_index()],150); - } - else - { - CGALglcolor(d->colors[cit->subdomain_index()],250); - } - draw_triangle(pa, pb, pc); - draw_triangle(pa, pb, pd); - draw_triangle(pa, pc, pd); - draw_triangle(pb, pc, pd); - } - } - ::glEnd(); - - if(!two_side) - ::glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE); - if(lighting) - ::glEnable(GL_LIGHTING); - else - ::glDisable(GL_LIGHTING); -} - - QPixmap Scene_c3t3_item::graphicalToolTip() const { @@ -490,7 +880,6 @@ Scene_c3t3_item::build_histogram() painter.drawText(max_text_rect, Qt::AlignCenter, tr("%1").arg(max_value,0,'f',1)); } - template std::vector create_histogram(const C3t3& c3t3, double& min_value, double& max_value) @@ -598,6 +987,8 @@ Scene_c3t3_item::c3t3_changed() // Rebuild histogram build_histogram(); + compute_elements(); + are_buffers_initialized = false; } void @@ -616,4 +1007,38 @@ Scene_c3t3_item::compute_color_map(const QColor& c) } } +void Scene_c3t3_item::draw_grid(float diag, std::vector *positions_grid) +{ + positions_grid->resize(0); + float x = (2*(float)diag)/10.0; + float y = (2*(float)diag)/10.0; + for(int u = 0; u < 11; u++) + { + + positions_grid->push_back(-(float)diag + x* u); + positions_grid->push_back(-(float)diag); + positions_grid->push_back(0.0); + + positions_grid->push_back(-(float)diag + x* u); + positions_grid->push_back((float)diag); + positions_grid->push_back(0.0); + } + for(int v=0; v<11; v++) + { + + positions_grid->push_back(-(float)diag); + positions_grid->push_back(-(float)diag + v * y); + positions_grid->push_back(0.0); + + positions_grid->push_back((float)diag); + positions_grid->push_back(-(float)diag + v * y); + positions_grid->push_back(0.0); + } + } + +void Scene_c3t3_item::contextual_changed() +{ + if(frame->isInMouseGrabberPool()) + c3t3_changed(); +} #include "Scene_c3t3_item.moc" diff --git a/Mesh_3/demo/Mesh_3/Scene_c3t3_item.h b/Mesh_3/demo/Mesh_3/Scene_c3t3_item.h index 24b71c48602..ae6ed6a5a44 100644 --- a/Mesh_3/demo/Mesh_3/Scene_c3t3_item.h +++ b/Mesh_3/demo/Mesh_3/Scene_c3t3_item.h @@ -3,7 +3,7 @@ #include "Scene_c3t3_item_config.h" #include "C3t3_type.h" -#include +#include #include #include @@ -13,11 +13,14 @@ #include #include #include +#include +#include +#include struct Scene_c3t3_item_priv; class SCENE_C3T3_ITEM_EXPORT Scene_c3t3_item - : public Scene_item_with_display_list + : public Scene_item { Q_OBJECT public: @@ -67,8 +70,8 @@ public: return (m != Gouraud); // CHECK THIS! } - void direct_draw() const; - void direct_draw_edges() const; + void draw(QGLViewer* viewer) const; + void draw_edges(QGLViewer* viewer) const; // data item inline const Scene_item* data_item() const; @@ -79,6 +82,7 @@ public: // Call this if c3t3 has been modified void c3t3_changed(); + void contextual_changed(); public Q_SLOTS: inline void data_item_destroyed(); @@ -90,7 +94,6 @@ private: QColor get_histogram_color(const double v) const; protected: - void direct_draw(int) const; Scene_c3t3_item_priv* d; qglviewer::ManipulatedFrame* frame; @@ -101,6 +104,35 @@ private: typedef std::set Indices; Indices indices_; + + static const int vaoSize = 2; + static const int vboSize = 4; + mutable bool are_buffers_initialized; + mutable int poly_vertexLocation[2]; + mutable int normalsLocation[2]; + mutable int mvpLocation[2]; + mutable int mvLocation[2]; + mutable int fmatLocation; + mutable int colorLocation[2]; + mutable int lightLocation[5*2]; + mutable int twosideLocation; + + std::vector v_poly; + std::vector normal; + std::vector color_triangles; + std::vector *v_grid; + + + + mutable QOpenGLBuffer buffers[vboSize]; + mutable QOpenGLVertexArrayObject vao[vaoSize]; + mutable QOpenGLShaderProgram rendering_program; + mutable QOpenGLShaderProgram rendering_program_grid; + void initialize_buffers() const; + void compute_elements(); + void attrib_buffers(QGLViewer*) const; + void compile_shaders(); + void draw_grid(float diag, std::vector *positions_grid); }; inline @@ -137,4 +169,6 @@ Scene_c3t3_item::data_item_destroyed() set_data_item(NULL); } + + #endif // SCENE_C3T3_ITEM_H diff --git a/Mesh_3/demo/Mesh_3/Scene_c3t3_item_config.h b/Mesh_3/demo/Mesh_3/Scene_c3t3_item_config.h index 9fb00f60c93..2e03e1f4ba6 100644 --- a/Mesh_3/demo/Mesh_3/Scene_c3t3_item_config.h +++ b/Mesh_3/demo/Mesh_3/Scene_c3t3_item_config.h @@ -2,6 +2,10 @@ #define SCENE_C3T3_ITEM_CONFIG_H #ifdef scene_c3t3_item_EXPORTS +# define mesh_3_demo_scene_c3t3_item_EXPORTS 1 +#endif + +#ifdef mesh_3_demo_scene_c3t3_item_EXPORTS # define SCENE_C3T3_ITEM_EXPORT Q_DECL_EXPORT #else # define SCENE_C3T3_ITEM_EXPORT Q_DECL_IMPORT diff --git a/Mesh_3/demo/Mesh_3/Scene_implicit_function_item.cpp b/Mesh_3/demo/Mesh_3/Scene_implicit_function_item.cpp index f302f8252e7..4bcbbba1769 100644 --- a/Mesh_3/demo/Mesh_3/Scene_implicit_function_item.cpp +++ b/Mesh_3/demo/Mesh_3/Scene_implicit_function_item.cpp @@ -22,17 +22,26 @@ Scene_implicit_function_item(Implicit_function_interface* f) , blue_color_ramp_() , red_color_ramp_() { + compile_shaders(); + texture = new Texture(grid_size_,grid_size_); blue_color_ramp_.build_blue(); red_color_ramp_.build_red(); compute_min_max(); compute_function_grid(); - connect(frame_, SIGNAL(modified()), this, SLOT(compute_function_grid())); + are_buffers_initialized = false; } Scene_implicit_function_item::~Scene_implicit_function_item() { + for(int i=0; ibbox(); } -void -Scene_implicit_function_item::direct_draw() const + +/************************************************** +****************SHADER FUNCTIONS******************/ + +void Scene_implicit_function_item::compile_shaders() { - - draw_function_grid(red_color_ramp_, blue_color_ramp_); - draw_bbox(); + + for(int i=0; i< vboSize; i++) + buffers[i].create(); + for(int i=0; i< vaoSize; i++) + vao[i].create(); + + //Vertex source code + const char vertex_source[] = + { + "#version 330 \n" + "in highp vec4 vertex;\n" + + "uniform highp mat4 mvp_matrix;\n" + "void main(void)\n" + "{\n" + " gl_Position = mvp_matrix * vertex; \n" + "}" + }; + //Fragment source code + const char fragment_source[] = + { + "#version 330 \n" + "uniform vec4 color; \n" + "void main(void) { \n" + "gl_FragColor = color; \n" + "} \n" + "\n" + }; + QOpenGLShader *vertex_shader = new QOpenGLShader(QOpenGLShader::Vertex); + if(!vertex_shader->compileSourceCode(vertex_source)) + { + std::cerr<<"Compiling vertex source FAILED"<compileSourceCode(fragment_source)) + { + std::cerr<<"Compiling fragmentsource FAILED"<compileSourceCode(tex_vertex_source)) + { + std::cerr<<"Compiling vertex source FAILED"<compileSourceCode(tex_fragment_source)) + { + std::cerr<<"Compiling fragmentsource FAILED"<getWidth(); i++) + for( int j=0 ; j < texture->getHeight() ; j++) + { + compute_texture(i,j); + } +} + +void Scene_implicit_function_item::initialize_buffers() const +{ + + rendering_program.bind(); + + vao[0].bind(); + buffers[0].bind(); + buffers[0].allocate(v_cube.data(), static_cast(v_cube.size()*sizeof(float))); + vertexLocation[0] = rendering_program.attributeLocation("vertex"); + rendering_program.enableAttributeArray(vertexLocation[0]); + rendering_program.setAttributeBuffer(vertexLocation[0],GL_FLOAT,0,3); + buffers[0].release(); + vao[0].release(); + rendering_program.release(); + tex_rendering_program.bind(); + //cutting plane + vao[1].bind(); + buffers[1].bind(); + buffers[1].allocate(v_plan.data(), static_cast(v_plan.size()*sizeof(float))); + vertexLocation[1] = tex_rendering_program.attributeLocation("vertex"); + tex_rendering_program.bind(); + tex_rendering_program.setAttributeBuffer(vertexLocation[1],GL_FLOAT,0,3); + tex_rendering_program.enableAttributeArray(vertexLocation[1]); + buffers[1].release(); + tex_rendering_program.release(); + + buffers[2].bind(); + buffers[2].allocate(texture_map.data(), static_cast(texture_map.size()*sizeof(float))); + tex_Location = tex_rendering_program.attributeLocation("tex_coord"); + tex_rendering_program.bind(); + tex_rendering_program.setAttributeBuffer(tex_Location,GL_FLOAT,0,2); + tex_rendering_program.enableAttributeArray(tex_Location); + buffers[2].release(); + tex_rendering_program.release(); + + gl.glBindTexture(GL_TEXTURE_2D, textureId); + gl.glTexImage2D(GL_TEXTURE_2D, + 0, + GL_RGB, + texture->getWidth(), + texture->getHeight(), + 0, + GL_RGB, + GL_UNSIGNED_BYTE, + texture->getData()); + gl.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE ); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE ); + vao[1].release(); + tex_rendering_program.release(); + are_buffers_initialized = true; +} + +void Scene_implicit_function_item::attrib_buffers(QGLViewer* viewer) const +{ + QMatrix4x4 mvpMatrix; + QMatrix4x4 fMatrix; + double mat[16]; + viewer->camera()->getModelViewProjectionMatrix(mat); + for(int i=0; i < 16; i++) + { + mvpMatrix.data()[i] = (float)mat[i]; + } + frame_->getMatrix(mat); + for(int i=0; i < 16; i++) + { + fMatrix.data()[i] = (float)mat[i]; + } + + rendering_program.bind(); + colorLocation[0] = rendering_program.uniformLocation("color"); + mvpLocation[0] = rendering_program.uniformLocation("mvp_matrix"); + rendering_program.setUniformValue(mvpLocation[0], mvpMatrix);; + rendering_program.release(); + + tex_rendering_program.bind(); + colorLocation[1] = tex_rendering_program.uniformLocation("color"); + f_Location = tex_rendering_program.uniformLocation("f_matrix"); + mvpLocation[1] = tex_rendering_program.uniformLocation("mvp_matrix"); + tex_rendering_program.setUniformValue(mvpLocation[1], mvpMatrix);; + tex_rendering_program.setUniformValue(f_Location, fMatrix);; + tex_rendering_program.release(); + +} + +void +Scene_implicit_function_item::draw(QGLViewer* viewer) const +{ + if(!are_ogfunctions_initialized) + { + gl.initializeOpenGLFunctions(); + gl.glGenTextures(1, &textureId); + are_ogfunctions_initialized = true; + } + if(!are_buffers_initialized) + initialize_buffers(); + QColor color; + vao[0].bind(); + attrib_buffers(viewer); + rendering_program.bind(); + color.setRgbF(0.0,0.0,0.0); + rendering_program.setUniformValue(colorLocation[0], color); + glDrawArrays(GL_LINES, 0, static_cast(v_cube.size()/3)); + rendering_program.release(); + vao[0].release(); + + gl.glActiveTexture(GL_TEXTURE0); + gl.glBindTexture(GL_TEXTURE_2D, textureId); + + vao[1].bind(); + tex_rendering_program.bind(); + glDrawArrays(GL_TRIANGLES, 0, static_cast(v_plan.size()/3)); + tex_rendering_program.release(); + vao[1].release(); + +} + QString Scene_implicit_function_item::toolTip() const { @@ -81,103 +483,6 @@ Scene_implicit_function_item::supportsRenderingMode(RenderingMode m) const return false; } -void -Scene_implicit_function_item:: -draw_bbox() const -{ - const Bbox& b = bbox(); - - ::glDisable(GL_LIGHTING); - ::glColor3f(0.f,0.f,0.f); - ::glBegin(GL_LINES); - - ::glVertex3d(b.xmin,b.ymin,b.zmin); - ::glVertex3d(b.xmin,b.ymin,b.zmax); - - ::glVertex3d(b.xmin,b.ymin,b.zmin); - ::glVertex3d(b.xmin,b.ymax,b.zmin); - - ::glVertex3d(b.xmin,b.ymin,b.zmin); - ::glVertex3d(b.xmax,b.ymin,b.zmin); - - ::glVertex3d(b.xmax,b.ymin,b.zmin); - ::glVertex3d(b.xmax,b.ymax,b.zmin); - - ::glVertex3d(b.xmax,b.ymin,b.zmin); - ::glVertex3d(b.xmax,b.ymin,b.zmax); - - ::glVertex3d(b.xmin,b.ymax,b.zmin); - ::glVertex3d(b.xmin,b.ymax,b.zmax); - - ::glVertex3d(b.xmin,b.ymax,b.zmin); - ::glVertex3d(b.xmax,b.ymax,b.zmin); - - ::glVertex3d(b.xmax,b.ymax,b.zmin); - ::glVertex3d(b.xmax,b.ymax,b.zmax); - - ::glVertex3d(b.xmin,b.ymin,b.zmax); - ::glVertex3d(b.xmin,b.ymax,b.zmax); - - ::glVertex3d(b.xmin,b.ymin,b.zmax); - ::glVertex3d(b.xmax,b.ymin,b.zmax); - - ::glVertex3d(b.xmax,b.ymax,b.zmax); - ::glVertex3d(b.xmin,b.ymax,b.zmax); - - ::glVertex3d(b.xmax,b.ymax,b.zmax); - ::glVertex3d(b.xmax,b.ymin,b.zmax); - - ::glEnd(); -} - -void -Scene_implicit_function_item:: -draw_function_grid(const Color_ramp& ramp_pos, - const Color_ramp& ramp_neg) const -{ - ::glDisable(GL_LIGHTING); - ::glShadeModel(GL_SMOOTH); - - ::glBegin(GL_QUADS); - const int nb_quads = grid_size_ - 1; - for( int i=0 ; i < nb_quads ; i++ ) - { - for( int j=0 ; j < nb_quads ; j++) - { - draw_grid_vertex(implicit_grid_[i][j], ramp_pos, ramp_neg); - draw_grid_vertex(implicit_grid_[i][j+1], ramp_pos, ramp_neg); - draw_grid_vertex(implicit_grid_[i+1][j+1], ramp_pos, ramp_neg); - draw_grid_vertex(implicit_grid_[i+1][j], ramp_pos, ramp_neg); - } - } - ::glEnd(); -} - - -void -Scene_implicit_function_item:: -draw_grid_vertex(const Point_value& pv, - const Color_ramp& ramp_positive, - const Color_ramp& ramp_negative) const -{ - const Point& p = pv.first; - double v = pv.second; - - // determines grey level - if ( v > 0 ) - { - v = v/max_value_; - ::glColor3d(ramp_positive.r(v),ramp_positive.g(v),ramp_positive.b(v)); - } - else - { - v = v/min_value_; - ::glColor3d(ramp_negative.r(v),ramp_negative.g(v),ramp_negative.b(v)); - } - - ::glVertex3d(p.x,p.y,p.z); -} - void Scene_implicit_function_item:: @@ -252,6 +557,30 @@ compute_min_max() } } +void Scene_implicit_function_item::changed() +{ + compute_elements(); + are_buffers_initialized = false; +} + +void Scene_implicit_function_item::compute_texture(int i, int j) +{ + + double v =(implicit_grid_[i][j]).second; + // determines grey level + if ( v > 0 ) + { + v = v/max_value_; + GLdouble r = red_color_ramp_.r(v), g = red_color_ramp_.g(v), b = red_color_ramp_.b(v); + texture->setData(i,j,255*r,255*g,255*b); + } + else + { + v = v/min_value_; + GLdouble r = blue_color_ramp_.r(v), g = blue_color_ramp_.g(v), b = blue_color_ramp_.b(v); + texture->setData(i,j,255*r,255*g,255*b); + } +} #include "Scene_implicit_function_item.moc" diff --git a/Mesh_3/demo/Mesh_3/Scene_implicit_function_item.h b/Mesh_3/demo/Mesh_3/Scene_implicit_function_item.h index fc2a229ccbd..8a0a7822c8c 100644 --- a/Mesh_3/demo/Mesh_3/Scene_implicit_function_item.h +++ b/Mesh_3/demo/Mesh_3/Scene_implicit_function_item.h @@ -1,7 +1,7 @@ #ifndef SCENE_IMPLICIT_FUNCTION_ITEM_H #define SCENE_IMPLICIT_FUNCTION_ITEM_H -#include +#include #include #include "Scene_implicit_function_item_config.h" #include "implicit_functions/Implicit_function_interface.h" @@ -9,12 +9,39 @@ #include #include +#include +#include +#include #define SCENE_IMPLICIT_GRID_SIZE 120 +class Texture{ +private: + int Width; + int Height; + int size; + GLubyte *data; +public: + Texture(int w, int h) + { + Width = w; + Height = h; + size = 3*Height*Width; + data = new GLubyte[size]; + } + int getWidth() const {return Width;} + int getHeight() const {return Height;} + int getSize() const {return size;} + void setData(int i, int j, int r, int g, int b){ + data[j*Width*3 +i*3] = r; + data[j*Width*3 +i*3+1] = g; + data[j*Width*3 +i*3+2] = b;} + GLubyte* getData(){return data; } + +}; class SCENE_IMPLICIT_FUNCTION_ITEM_EXPORT Scene_implicit_function_item - : public Scene_item_with_display_list + : public Scene_item { Q_OBJECT @@ -38,7 +65,7 @@ public: virtual ManipulatedFrame* manipulatedFrame() { return frame_; } // draw (overload only direct_draw() to use display list of base class) - virtual void direct_draw() const; + virtual void draw(QGLViewer* viewer) const; virtual QString toolTip() const; @@ -49,11 +76,6 @@ private: typedef qglviewer::Vec Point; typedef std::pair Point_value; - void draw_bbox() const; - void draw_function_grid(const Color_ramp&, const Color_ramp&) const; - void draw_grid_vertex(const Point_value&, - const Color_ramp&, const Color_ramp&) const; - void compute_min_max(); private: @@ -67,6 +89,38 @@ private: Color_ramp blue_color_ramp_; Color_ramp red_color_ramp_; + + mutable bool are_buffers_initialized; + + static const int vaoSize = 2; + static const int vboSize = 3; + mutable int vertexLocation[2]; + mutable int mvpLocation[2]; + mutable int colorLocation[2]; + mutable int tex_Location; + mutable int f_Location; + + + std::vector v_cube; + std::vector v_plan; + + std::vector texture_map; + Texture *texture; + mutable GLuint textureId; + GLint sampler_location; + + mutable QOpenGLBuffer buffers[vboSize]; + mutable QOpenGLVertexArrayObject vao[vaoSize]; + mutable QOpenGLShaderProgram rendering_program; + mutable QOpenGLShaderProgram tex_rendering_program; + void initialize_buffers() const; + void compute_elements(); + void attrib_buffers(QGLViewer*) const; + void compile_shaders(); + void compute_texture(int, int); + +public Q_SLOTS: + void changed(); }; #endif // SCENE_IMPLICIT_FUNCTION_ITEM diff --git a/Mesh_3/demo/Mesh_3/Scene_polygon_soup.cpp b/Mesh_3/demo/Mesh_3/Scene_polygon_soup.cpp index 5eb9defce07..2b86fbabe2b 100644 --- a/Mesh_3/demo/Mesh_3/Scene_polygon_soup.cpp +++ b/Mesh_3/demo/Mesh_3/Scene_polygon_soup.cpp @@ -91,17 +91,391 @@ struct Polygon_soup { }; Scene_polygon_soup::Scene_polygon_soup() - : Scene_item_with_display_list(), + : Scene_item(), soup(0), oriented(false) { + compile_shaders(); + are_buffers_initialized = false; } Scene_polygon_soup::~Scene_polygon_soup() { + for(int i=0; icompileSourceCode(vertex_source)) + { + std::cerr<<"Compiling vertex source FAILED"<compileSourceCode(fragment_source)) + { + std::cerr<<"Compiling fragmentsource FAILED"<polygons.begin(); + it != soup->polygons.end(); ++it) + { + const Point_3& pa = soup->points[it->at(0)]; + const Point_3& pb = soup->points[it->at(1)]; + const Point_3& pc = soup->points[it->at(2)]; + + Kernel::Vector_3 n = CGAL::cross_product(pb-pa, pc -pa); + n = n / std::sqrt(n * n); + + for(size_type i = 0; i < it->size(); ++i) { + const Point_3& p = soup->points[it->at(i)]; + normal.push_back(n.x()); normal.push_back(n.y()); normal.push_back(n.z()); + v_poly.push_back(p.x()); v_poly.push_back(p.y()); v_poly.push_back(p.z()); + } + } + + //edges + for(size_type i = 0; i < soup->polygons.size(); ++i) + { + const size_type size = soup->polygons[i].size(); + for(size_type j = 0; j < size; ++j) { + const std::size_t& i0 = soup->polygons[i][j]; + const std::size_t& i1 = soup->polygons[i][ j+1 < size ? j+1: 0]; + Polygon_soup::Edge edge; + edge[0] = i0; + edge[1] = i1; + const Point_3& a = soup->points[edge[0]]; + const Point_3& b = soup->points[edge[1]]; + v_edge.push_back(a.x()); v_edge.push_back(a.y()); v_edge.push_back(a.z()); + v_edge.push_back(b.x()); v_edge.push_back(b.y()); v_edge.push_back(b.z()); + } + } + + //non_manifold_edges + + for(Polygon_soup::size_type + i = 0, + end = soup->non_manifold_edges.size(); + i < end; ++i) + { + const Polygon_soup::Edge& edge = soup->non_manifold_edges[i]; + const Point_3& a = soup->points[edge[0]]; + const Point_3& b = soup->points[edge[1]]; + + vertex_nm.push_back(a.x()); vertex_nm.push_back(a.y()); vertex_nm.push_back(a.z()); + vertex_nm.push_back(b.x()); vertex_nm.push_back(b.y()); vertex_nm.push_back(b.z()); + } +} + +void Scene_polygon_soup::initialize_buffers() const +{ + rendering_program.bind(); + + vao[0].bind(); + buffers[0].bind(); + buffers[0].allocate(v_poly.data(), static_cast(v_poly.size()*sizeof(float))); + poly_vertexLocation[0] = rendering_program.attributeLocation("vertex"); + rendering_program.enableAttributeArray(poly_vertexLocation[0]); + rendering_program.setAttributeBuffer(poly_vertexLocation[0],GL_FLOAT,0,3); + buffers[0].release(); + + buffers[1].bind(); + buffers[1].allocate(normal.data(), static_cast(normal.size()*sizeof(float))); + normalsLocation[0] = rendering_program.attributeLocation("normal"); + rendering_program.enableAttributeArray(normalsLocation[0]); + rendering_program.setAttributeBuffer(normalsLocation[0],GL_FLOAT,0,3); + buffers[1].release(); + + vao[0].release(); + + vao[1].bind(); + buffers[2].bind(); + buffers[2].allocate(v_edge.data(), static_cast(v_edge.size()*sizeof(float))); + poly_vertexLocation[0] = rendering_program.attributeLocation("vertex"); + rendering_program.enableAttributeArray(poly_vertexLocation[0]); + rendering_program.setAttributeBuffer(poly_vertexLocation[0],GL_FLOAT,0,3); + buffers[2].release(); + std::vector empty_array; + empty_array.resize(0); + for(std::size_t i=0; i(empty_array.size()*sizeof(float))); + normalsLocation[0] = rendering_program.attributeLocation("normal"); + rendering_program.enableAttributeArray(normalsLocation[0]); + rendering_program.setAttributeBuffer(normalsLocation[0],GL_FLOAT,0,3); + buffers[3].release(); + + vao[1].release(); + + vao[2].bind(); + buffers[4].bind(); + buffers[4].allocate(v_edge.data(), static_cast(v_edge.size()*sizeof(float))); + poly_vertexLocation[0] = rendering_program.attributeLocation("vertex"); + rendering_program.enableAttributeArray(poly_vertexLocation[0]); + rendering_program.setAttributeBuffer(poly_vertexLocation[0],GL_FLOAT,0,3); + buffers[4].release(); + empty_array.resize(0); + for(std::size_t i=0; i(empty_array.size()*sizeof(float))); + normalsLocation[0] = rendering_program.attributeLocation("normal"); + rendering_program.enableAttributeArray(normalsLocation[0]); + rendering_program.setAttributeBuffer(normalsLocation[0],GL_FLOAT,0,3); + buffers[5].release(); + + vao[2].release(); + + rendering_program.release(); + are_buffers_initialized = true; + +} + +void Scene_polygon_soup::attrib_buffers(QGLViewer* viewer) const +{ + QMatrix4x4 mvpMatrix; + QMatrix4x4 mvMatrix; + double mat[16]; + viewer->camera()->getModelViewProjectionMatrix(mat); + for(int i=0; i < 16; i++) + { + mvpMatrix.data()[i] = (float)mat[i]; + } + viewer->camera()->getModelViewMatrix(mat); + for(int i=0; i < 16; i++) + { + mvMatrix.data()[i] = (float)mat[i]; + } + QVector4D position(0.0f,0.0f,1.0f,1.0f ); + GLboolean isTwoSide; + gl.glGetBooleanv(GL_LIGHT_MODEL_TWO_SIDE,&isTwoSide); + // define material + QVector4D ambient; + QVector4D diffuse; + QVector4D specular; + GLfloat shininess ; + // Ambient + ambient[0] = 0.29225f; + ambient[1] = 0.29225f; + ambient[2] = 0.29225f; + ambient[3] = 1.0f; + // Diffuse + diffuse[0] = 0.50754f; + diffuse[1] = 0.50754f; + diffuse[2] = 0.50754f; + diffuse[3] = 1.0f; + // Specular + specular[0] = 0.0f; + specular[1] = 0.0f; + specular[2] = 0.0f; + specular[3] = 0.0f; + // Shininess + shininess = 51.2f; + + + rendering_program.bind(); + colorLocation[0] = rendering_program.uniformLocation("color"); + twosideLocation = rendering_program.uniformLocation("is_two_side"); + mvpLocation[0] = rendering_program.uniformLocation("mvp_matrix"); + mvLocation[0] = rendering_program.uniformLocation("mv_matrix"); + lightLocation[0] = rendering_program.uniformLocation("light_pos"); + lightLocation[1] = rendering_program.uniformLocation("light_diff"); + lightLocation[2] = rendering_program.uniformLocation("light_spec"); + lightLocation[3] = rendering_program.uniformLocation("light_amb"); + lightLocation[4] = rendering_program.uniformLocation("spec_power"); + + rendering_program.setUniformValue(lightLocation[0], position); + rendering_program.setUniformValue(twosideLocation, isTwoSide); + rendering_program.setUniformValue(mvpLocation[0], mvpMatrix); + rendering_program.setUniformValue(mvLocation[0], mvMatrix); + rendering_program.setUniformValue(lightLocation[1], diffuse); + rendering_program.setUniformValue(lightLocation[2], specular); + rendering_program.setUniformValue(lightLocation[3], ambient); + rendering_program.setUniformValue(lightLocation[4], shininess); + + rendering_program.release(); +} + +void +Scene_polygon_soup::draw(QGLViewer * viewer) const { + if(!are_ogfunctions_initialized) + { + gl.initializeOpenGLFunctions(); + are_ogfunctions_initialized = true; + } + if(!are_buffers_initialized) + initialize_buffers(); + + QColor color; + vao[0].bind(); + float current_color[4]; + gl.glGetFloatv(GL_CURRENT_COLOR, current_color); + color.setRgbF(current_color[0],current_color[1],current_color[2],current_color[3]); + attrib_buffers(viewer); + rendering_program.bind(); + rendering_program.setUniformValue(colorLocation[0], color); + gl.glDrawArrays(GL_TRIANGLES, 0, static_cast(v_poly.size()/3)); + rendering_program.release(); + vao[0].release(); +} + +void +Scene_polygon_soup::draw_edges(QGLViewer * viewer) const { + if(!are_ogfunctions_initialized) + { + gl.initializeOpenGLFunctions(); + are_ogfunctions_initialized = true; + } + if(!are_buffers_initialized) + initialize_buffers(); + QColor color; + vao[1].bind(); + float current_color[4]; + glGetFloatv(GL_CURRENT_COLOR, current_color); + color.setRgbF(current_color[0],current_color[1],current_color[2],current_color[3]); + attrib_buffers(viewer); + rendering_program.bind(); + rendering_program.setUniformValue(colorLocation[0], color); + glDrawArrays(GL_LINES, 0, static_cast(v_edge.size()/3)); + rendering_program.release(); + vao[1].release(); + + if(soup->display_non_manifold_edges) + { + vao[2].bind(); + color.setRgbF(1.0,0.0,0.0); + attrib_buffers(viewer); + rendering_program.bind(); + rendering_program.setUniformValue(colorLocation[0], color); + glDrawArrays(GL_LINES, 0, static_cast(v_edge.size()/3)); + rendering_program.release(); + vao[2].release(); + } +} + +void +Scene_polygon_soup::draw_points(QGLViewer * viewer) const { + + if(!are_ogfunctions_initialized) + { + gl.initializeOpenGLFunctions(); + are_ogfunctions_initialized = true; + } + if(!are_buffers_initialized) + initialize_buffers(); + QColor color; + vao[0].bind(); + float current_color[4]; + gl.glGetFloatv(GL_CURRENT_COLOR, current_color); + color.setRgbF(current_color[0],current_color[1],current_color[2],current_color[3]); + attrib_buffers(viewer); + rendering_program.bind(); + rendering_program.setUniformValue(colorLocation[0], color); + gl.glDrawArrays(GL_POINTS, 0, static_cast(v_poly.size()/3)); + rendering_program.release(); + vao[0].release(); + +} + + Scene_polygon_soup* Scene_polygon_soup::clone() const { Scene_polygon_soup* new_soup = new Scene_polygon_soup(); @@ -145,6 +519,7 @@ Scene_polygon_soup::load(std::istream& in) } soup->fill_edges(); oriented = false; + changed(); return ! in.fail(); } @@ -340,51 +715,6 @@ Scene_polygon_soup::toolTip() const .arg(this->color().name()); } -void -Scene_polygon_soup::direct_draw() const { - typedef Polygon_soup::Polygons::const_iterator Polygons_iterator; - typedef Polygon_soup::Polygons::size_type size_type; - for(Polygons_iterator it = soup->polygons.begin(); - it != soup->polygons.end(); ++it) - { - const Point_3& pa = soup->points[it->at(0)]; - const Point_3& pb = soup->points[it->at(1)]; - const Point_3& pc = soup->points[it->at(2)]; - - Kernel::Vector_3 n = CGAL::cross_product(pb-pa, pc -pa); - n = n / std::sqrt(n * n); - - ::glBegin(GL_POLYGON); - ::glNormal3d(n.x(),n.y(),n.z()); - - for(size_type i = 0; i < it->size(); ++i) { - const Point_3& p = soup->points[it->at(i)]; - ::glVertex3d(p.x(),p.y(),p.z()); - } - ::glEnd(); - } - if(soup->display_non_manifold_edges) { - double current_color[4]; - ::glGetDoublev(GL_CURRENT_COLOR, current_color); - ::glColor3d(1., 0., 0.); // red - - for(Polygon_soup::size_type - i = 0, - end = soup->non_manifold_edges.size(); - i < end; ++i) - { - const Polygon_soup::Edge& edge = soup->non_manifold_edges[i]; - const Point_3& a = soup->points[edge[0]]; - const Point_3& b = soup->points[edge[1]]; - ::glBegin(GL_LINES); - ::glVertex3d(a.x(), a.y(), a.z()); - ::glVertex3d(b.x(), b.y(), b.z()); - ::glEnd(); - } - ::glColor4dv(current_color); - } -} - bool Scene_polygon_soup::isEmpty() const { return (soup == 0 || soup->points.empty()); @@ -403,4 +733,10 @@ Scene_polygon_soup::bbox() const { bbox.xmax(),bbox.ymax(),bbox.zmax()); } +void Scene_polygon_soup::changed() +{ + // Scene_item::changed(); + compute_elements(); + are_buffers_initialized = false; +} #include "Scene_polygon_soup.moc" diff --git a/Mesh_3/demo/Mesh_3/Scene_polygon_soup.h b/Mesh_3/demo/Mesh_3/Scene_polygon_soup.h index 98bd763e398..f2acdecdcd2 100644 --- a/Mesh_3/demo/Mesh_3/Scene_polygon_soup.h +++ b/Mesh_3/demo/Mesh_3/Scene_polygon_soup.h @@ -2,13 +2,17 @@ #define SCENE_POLYGON_SOUP_H #include "Scene_polygon_soup_config.h" -#include +#include #include +#include +#include +#include +#include struct Polygon_soup; class SCENE_POLYGON_SOUP_EXPORT Scene_polygon_soup - : public Scene_item_with_display_list + : public Scene_item { Q_OBJECT public: @@ -24,7 +28,9 @@ public: // Indicate if rendering mode is supported virtual bool supportsRenderingMode(RenderingMode m) const { return m != Gouraud; } // CHECK THIS! // OpenGL drawing in a display list - void direct_draw() const; + void draw(QGLViewer*) const; + void draw_edges(QGLViewer*) const; + void draw_points(QGLViewer*) const; bool isFinite() const { return true; } bool isEmpty() const; @@ -39,6 +45,37 @@ public: private: Polygon_soup* soup; bool oriented; + + + static const int vaoSize = 3; + static const int vboSize = 6; + + mutable int poly_vertexLocation[1]; + mutable int normalsLocation[1]; + mutable int mvpLocation[1]; + mutable int mvLocation[1]; + mutable int colorLocation[1]; + mutable int lightLocation[5]; + mutable int twosideLocation; + + std::vector v_poly; + std::vector v_edge; + std::vector v_points; + std::vector normal; + std::vector vertex_nm; + + mutable bool are_buffers_initialized; + mutable QOpenGLBuffer buffers[vboSize]; + mutable QOpenGLVertexArrayObject vao[vaoSize]; + mutable QOpenGLShaderProgram rendering_program; + void initialize_buffers() const; + void compute_elements(); + void attrib_buffers(QGLViewer*) const; + void compile_shaders(); + +public Q_SLOTS: + void changed(); + }; // end class Scene_polygon_soup #endif // SCENE_POLYGON_SOUP_H diff --git a/Mesh_3/demo/Mesh_3/Scene_polyhedron_item.cpp b/Mesh_3/demo/Mesh_3/Scene_polyhedron_item.cpp index 2ed00f46906..a26263cee29 100644 --- a/Mesh_3/demo/Mesh_3/Scene_polyhedron_item.cpp +++ b/Mesh_3/demo/Mesh_3/Scene_polyhedron_item.cpp @@ -3,26 +3,32 @@ #include "Scene_polyhedron_item.h" #include "Polyhedron_type.h" #include - +#include #include -#include + Scene_polyhedron_item::Scene_polyhedron_item() - : Scene_item_with_display_list(), + : Scene_item(), poly(new Polyhedron) { + are_buffers_initialized = false; + compile_shaders(); } Scene_polyhedron_item::Scene_polyhedron_item(Polyhedron* const p) - : Scene_item_with_display_list(), + : Scene_item(), poly(p) { + are_buffers_initialized = false; + compile_shaders(); } Scene_polyhedron_item::Scene_polyhedron_item(const Polyhedron& p) - : Scene_item_with_display_list(), + : Scene_item(), poly(new Polyhedron(p)) { + are_buffers_initialized = false; + compile_shaders(); } // Scene_polyhedron_item::Scene_polyhedron_item(const Scene_polyhedron_item& item) @@ -33,9 +39,379 @@ Scene_polyhedron_item::Scene_polyhedron_item(const Polyhedron& p) Scene_polyhedron_item::~Scene_polyhedron_item() { + for(int i=0; icompileSourceCode(vertex_source)) + { + std::cerr<<"Compiling vertex source FAILED"<compileSourceCode(fragment_source)) + { + std::cerr<<"Compiling fragmentsource FAILED"<(*f); + + normal_flat.push_back(n.x()); normal_flat.push_back(n.y()); normal_flat.push_back(n.z()); + normal_flat.push_back(n.x()); normal_flat.push_back(n.y()); normal_flat.push_back(n.z()); + normal_flat.push_back(n.x()); normal_flat.push_back(n.y()); normal_flat.push_back(n.z()); + + + // revolve around current face to get vertices + HF_circulator he = f->facet_begin(); + HF_circulator end = he; + CGAL_For_all(he,end) + { + + Vector n = compute_vertex_normal(*he->vertex()); + normal_smooth.push_back(n.x()); normal_smooth.push_back(n.y()); normal_smooth.push_back(n.z()); + + const Point& p = he->vertex()->point(); + v_poly.push_back(p.x()); v_poly.push_back(p.y()); v_poly.push_back(p.z()); + } + } + + //EDGES + + typedef Polyhedron::Edge_iterator Edge_iterator; + + + Edge_iterator he; + for(he = polyhedron.edges_begin(); + he != polyhedron.edges_end(); + he++) + { + const Point& a = he->vertex()->point(); + const Point& b = he->opposite()->vertex()->point(); + v_edge.push_back(a.x()); v_edge.push_back(a.y()); v_edge.push_back(a.z()); + v_edge.push_back(b.x()); v_edge.push_back(b.y()); v_edge.push_back(b.z()); + } + +} + +void Scene_polyhedron_item::initialize_buffers() const +{ + rendering_program.bind(); + + vao[0].bind(); + buffers[0].bind(); + buffers[0].allocate(v_poly.data(), static_cast(v_poly.size()*sizeof(float))); + poly_vertexLocation[0] = rendering_program.attributeLocation("vertex"); + rendering_program.enableAttributeArray(poly_vertexLocation[0]); + rendering_program.setAttributeBuffer(poly_vertexLocation[0],GL_FLOAT,0,3); + buffers[0].release(); + + buffers[1].bind(); + buffers[1].allocate(normal_flat.data(), static_cast(normal_flat.size()*sizeof(float))); + normalsLocation[0] = rendering_program.attributeLocation("normal"); + rendering_program.enableAttributeArray(normalsLocation[0]); + rendering_program.setAttributeBuffer(normalsLocation[0],GL_FLOAT,0,3); + buffers[1].release(); + + vao[0].release(); + + vao[1].bind(); + buffers[2].bind(); + buffers[2].allocate(v_poly.data(), static_cast(v_poly.size()*sizeof(float))); + poly_vertexLocation[0] = rendering_program.attributeLocation("vertex"); + rendering_program.enableAttributeArray(poly_vertexLocation[0]); + rendering_program.setAttributeBuffer(poly_vertexLocation[0],GL_FLOAT,0,3); + buffers[2].release(); + + buffers[3].bind(); + buffers[3].allocate(normal_smooth.data(), static_cast(normal_smooth.size()*sizeof(float))); + normalsLocation[0] = rendering_program.attributeLocation("normal"); + rendering_program.enableAttributeArray(normalsLocation[0]); + rendering_program.setAttributeBuffer(normalsLocation[0],GL_FLOAT,0,3); + buffers[3].release(); + + vao[1].release(); + + vao[2].bind(); + buffers[4].bind(); + buffers[4].allocate(v_edge.data(), static_cast(v_edge.size()*sizeof(float))); + poly_vertexLocation[0] = rendering_program.attributeLocation("vertex"); + rendering_program.enableAttributeArray(poly_vertexLocation[0]); + rendering_program.setAttributeBuffer(poly_vertexLocation[0],GL_FLOAT,0,3); + buffers[4].release(); + std::vector empty_array; + empty_array.resize(0); + for(std::size_t i=0; i(empty_array.size()*sizeof(float))); + normalsLocation[0] = rendering_program.attributeLocation("normal"); + rendering_program.enableAttributeArray(normalsLocation[0]); + rendering_program.setAttributeBuffer(normalsLocation[0],GL_FLOAT,0,3); + buffers[5].release(); + + vao[2].release(); + rendering_program.release(); + are_buffers_initialized = true; + +} + +void Scene_polyhedron_item::attrib_buffers(QGLViewer* viewer) const +{ + QMatrix4x4 mvpMatrix; + QMatrix4x4 mvMatrix; + double mat[16]; + viewer->camera()->getModelViewProjectionMatrix(mat); + for(int i=0; i < 16; i++) + { + mvpMatrix.data()[i] = (float)mat[i]; + } + viewer->camera()->getModelViewMatrix(mat); + for(int i=0; i < 16; i++) + { + mvMatrix.data()[i] = (float)mat[i]; + } + QVector4D position(0.0f,0.0f,1.0f,1.0f ); + GLboolean isTwoSide; + gl.glGetBooleanv(GL_LIGHT_MODEL_TWO_SIDE,&isTwoSide); + // define material + QVector4D ambient; + QVector4D diffuse; + QVector4D specular; + GLfloat shininess ; + // Ambient + ambient[0] = 0.29225f; + ambient[1] = 0.29225f; + ambient[2] = 0.29225f; + ambient[3] = 1.0f; + // Diffuse + diffuse[0] = 0.50754f; + diffuse[1] = 0.50754f; + diffuse[2] = 0.50754f; + diffuse[3] = 1.0f; + // Specular + specular[0] = 0.0f; + specular[1] = 0.0f; + specular[2] = 0.0f; + specular[3] = 0.0f; + // Shininess + shininess = 51.2f; + + + rendering_program.bind(); + colorLocation[0] = rendering_program.uniformLocation("color"); + twosideLocation = rendering_program.uniformLocation("is_two_side"); + mvpLocation[0] = rendering_program.uniformLocation("mvp_matrix"); + mvLocation[0] = rendering_program.uniformLocation("mv_matrix"); + lightLocation[0] = rendering_program.uniformLocation("light_pos"); + lightLocation[1] = rendering_program.uniformLocation("light_diff"); + lightLocation[2] = rendering_program.uniformLocation("light_spec"); + lightLocation[3] = rendering_program.uniformLocation("light_amb"); + lightLocation[4] = rendering_program.uniformLocation("spec_power"); + + rendering_program.setUniformValue(lightLocation[0], position); + rendering_program.setUniformValue(twosideLocation, isTwoSide); + rendering_program.setUniformValue(mvpLocation[0], mvpMatrix); + rendering_program.setUniformValue(mvLocation[0], mvMatrix); + rendering_program.setUniformValue(lightLocation[1], diffuse); + rendering_program.setUniformValue(lightLocation[2], specular); + rendering_program.setUniformValue(lightLocation[3], ambient); + rendering_program.setUniformValue(lightLocation[4], shininess); + + rendering_program.release(); +} + +// Points/Wireframe/Flat/Gouraud OpenGL drawing in a display list +void Scene_polyhedron_item::draw(QGLViewer *viewer) const { + + if(!are_ogfunctions_initialized) + { + gl.initializeOpenGLFunctions(); + are_ogfunctions_initialized = true; + } + if(!are_buffers_initialized) + initialize_buffers(); + QColor color; + GLint shading; + gl.glGetIntegerv(GL_SHADE_MODEL, &shading); + if(shading == GL_FLAT) + vao[0].bind(); + else if(shading == GL_SMOOTH) + vao[1].bind(); + else + return; + attrib_buffers(viewer); + + rendering_program.bind(); + float current_color[4]; + gl.glGetFloatv(GL_CURRENT_COLOR, current_color); + color.setRgbF(current_color[0],current_color[1],current_color[2],current_color[3]); + rendering_program.setUniformValue(colorLocation[0], color); + gl.glDrawArrays(GL_TRIANGLES, 0, static_cast(v_poly.size()/3)); + rendering_program.release(); + if(shading == GL_FLAT) + vao[0].release(); + else if(shading == GL_SMOOTH) + vao[1].release(); + + +} +void Scene_polyhedron_item::draw_edges(QGLViewer *viewer) const { + if(!are_ogfunctions_initialized) + { + gl.initializeOpenGLFunctions(); + are_ogfunctions_initialized = true; + } + if(!are_buffers_initialized) + initialize_buffers(); + QColor color; + + vao[2].bind(); + attrib_buffers(viewer); + rendering_program.bind(); + float current_color[4]; + gl.glGetFloatv(GL_CURRENT_COLOR, current_color); + color.setRgbF(current_color[0],current_color[1],current_color[2],current_color[3]); + rendering_program.setUniformValue(colorLocation[0], color); + gl.glDrawArrays(GL_LINES, 0, static_cast(v_edge.size()/3)); + rendering_program.release(); + vao[2].release(); + +} +void Scene_polyhedron_item::draw_points(QGLViewer *viewer) const { + if(!are_ogfunctions_initialized) + { + gl.initializeOpenGLFunctions(); + are_ogfunctions_initialized = true; + } + if(!are_buffers_initialized) + initialize_buffers(); + QColor color; + + vao[0].bind(); + attrib_buffers(viewer); + rendering_program.bind(); + float current_color[4]; + gl.glGetFloatv(GL_CURRENT_COLOR, current_color); + color.setRgbF(current_color[0],current_color[1],current_color[2],current_color[3]); + rendering_program.setUniformValue(colorLocation[0], color); + gl.glDrawArrays(GL_POINTS, 0, static_cast(v_poly.size()/3)); + rendering_program.release(); + vao[0].release(); +} + Scene_polyhedron_item* Scene_polyhedron_item::clone() const { return new Scene_polyhedron_item(*poly); @@ -46,6 +422,7 @@ bool Scene_polyhedron_item::load(std::istream& in) { in >> *poly; + changed(); return in && !isEmpty(); } @@ -75,10 +452,7 @@ Scene_polyhedron_item::toolTip() const .arg(this->color().name()); } -// Points/Wireframe/Flat/Gouraud OpenGL drawing in a display list -void Scene_polyhedron_item::direct_draw() const { - gl_render_facets(*poly); -} + Polyhedron* Scene_polyhedron_item::polyhedron() { return poly; } @@ -103,4 +477,10 @@ Scene_polyhedron_item::bbox() const { bbox.xmax(),bbox.ymax(),bbox.zmax()); } +void Scene_polyhedron_item::changed() +{ + compute_elements(); + are_buffers_initialized = false; +} + #include "Scene_polyhedron_item.moc" diff --git a/Mesh_3/demo/Mesh_3/Scene_polyhedron_item.h b/Mesh_3/demo/Mesh_3/Scene_polyhedron_item.h index 9d00099905e..b873f6a89dc 100644 --- a/Mesh_3/demo/Mesh_3/Scene_polyhedron_item.h +++ b/Mesh_3/demo/Mesh_3/Scene_polyhedron_item.h @@ -2,13 +2,17 @@ #define SCENE_POLYHEDRON_ITEM_H #include "Scene_polyhedron_item_config.h" -#include +#include #include "Polyhedron_type_fwd.h" #include +#include +#include +#include +#include // This class represents a polyhedron in the OpenGL scene class SCENE_POLYHEDRON_ITEM_EXPORT Scene_polyhedron_item - : public Scene_item_with_display_list { + : public Scene_item{ Q_OBJECT public: Scene_polyhedron_item(); @@ -29,7 +33,9 @@ public: // Indicate if rendering mode is supported virtual bool supportsRenderingMode(RenderingMode) const { return true; } // Points/Wireframe/Flat/Gouraud OpenGL drawing in a display list - virtual void direct_draw() const; + virtual void draw(QGLViewer*) const ; + virtual void draw_edges(QGLViewer*) const ; + virtual void draw_points(QGLViewer*) const ; // Get wrapped polyhedron Polyhedron* polyhedron(); @@ -42,6 +48,37 @@ public: private: Polyhedron* poly; + mutable + bool are_buffers_initialized; + + static const int vaoSize = 3; + static const int vboSize = 6; + mutable int poly_vertexLocation[1]; + mutable int normalsLocation[1]; + mutable int mvpLocation[1]; + mutable int mvLocation[1]; + mutable int colorLocation[1]; + mutable int lightLocation[5]; + mutable int twosideLocation; + + std::vector v_poly; + std::vector v_edge; + std::vector v_points; + std::vector normal_flat; + std::vector normal_smooth; + std::vector vertex_nm; + + + mutable QOpenGLBuffer buffers[vboSize]; + mutable QOpenGLVertexArrayObject vao[vaoSize]; + mutable QOpenGLShaderProgram rendering_program; + void initialize_buffers() const; + void compute_elements(); + void attrib_buffers(QGLViewer*) const; + void compile_shaders(); + +public Q_SLOTS: + void changed(); }; // end class Scene_polyhedron_item diff --git a/Mesh_3/demo/Mesh_3/Scene_segmented_image_item.cpp b/Mesh_3/demo/Mesh_3/Scene_segmented_image_item.cpp index f8ba4b73811..f3dceda9a1c 100644 --- a/Mesh_3/demo/Mesh_3/Scene_segmented_image_item.cpp +++ b/Mesh_3/demo/Mesh_3/Scene_segmented_image_item.cpp @@ -1,8 +1,5 @@ #include "config.h" -#ifdef SCENE_SEGMENTED_IMAGE_GL_BUFFERS_AVAILABLE -# include -#endif #include "Scene_segmented_image_item.h" #include "Image_type.h" #include @@ -11,18 +8,6 @@ #include #include -//#define SCENE_SEGMENTED_IMAGE_GL_BUFFERS_AVAILABLE - -#ifdef SCENE_SEGMENTED_IMAGE_GL_BUFFERS_AVAILABLE -bool gl_vbo_available() { - return glewIsSupported("GL_VERSION_1_4"); -} -#else -bool gl_vbo_available() { - return false; -} -#endif - // ----------------------------------- @@ -372,6 +357,7 @@ Vertex_buffer_helper::push_vertex(std::size_t i, std::size_t j, std::size_t k) vertices_.push_back(i*data_.vx()); vertices_.push_back(j*data_.vy()); vertices_.push_back(k*data_.vz()); + } void @@ -404,7 +390,9 @@ Vertex_buffer_helper::push_quad(int pos1, int pos2, int pos3, int pos4) quads_.push_back(pos1); quads_.push_back(pos2); quads_.push_back(pos3); - quads_.push_back(pos4); + quads_.push_back(pos1); + quads_.push_back(pos3); + quads_.push_back(pos4); } } @@ -467,7 +455,6 @@ create_array(T*& destination, std::size_t& size, const std::vector& source) } // namespace internal - // ----------------------------------- // Scene_segmented_image_item // ----------------------------------- @@ -475,18 +462,13 @@ Scene_segmented_image_item::Scene_segmented_image_item(Image* im, int display_scale) : m_image(im) , m_initialized(false) -#ifdef SCENE_SEGMENTED_IMAGE_GL_BUFFERS_AVAILABLE , m_voxel_scale(display_scale) -#endif // SCENE_SEGMENTED_IMAGE_GL_BUFFERS_AVAILABLE + { CGAL_USE(display_scale); -#ifdef SCENE_SEGMENTED_IMAGE_GL_BUFFERS_AVAILABLE - if(gl_vbo_available()) { - ::glGenBuffers(3,m_vbo); - ::glGenBuffers(1,&m_ibo); - } -#endif // SCENE_SEGMENTED_IMAGE_GL_BUFFERS_AVAILABLE - + + v_box = new std::vector(); + compile_shaders(); initialize_buffers(); setRenderingMode(Flat); } @@ -494,14 +476,174 @@ Scene_segmented_image_item::Scene_segmented_image_item(Image* im, Scene_segmented_image_item::~Scene_segmented_image_item() { -#ifdef SCENE_SEGMENTED_IMAGE_GL_BUFFERS_AVAILABLE - if(gl_vbo_available()) { - ::glDeleteBuffers(3,m_vbo); - ::glDeleteBuffers(1,&m_ibo); - } -#endif // SCENE_SEGMENTED_IMAGE_GL_BUFFERS_AVAILABLE + for(int i=0; icreate(); + //Vertex source code + const char vertex_source[] = + { + "#version 330 \n" + "in highp vec4 vertex;\n" + "in highp vec3 normal;\n" + "in highp vec4 inColor;\n" + + "uniform highp mat4 mvp_matrix;\n" + "uniform highp mat4 mv_matrix; \n" + "out highp vec4 fP; \n" + "out highp vec3 fN; \n" + "out highp vec4 color; \n" + "void main(void)\n" + "{\n" + " color=inColor; \n" + " fP = mv_matrix * vertex; \n" + " fN = mat3(mv_matrix)* normal; \n" + " gl_Position = mvp_matrix * vertex; \n" + "}" + }; + //Fragment source code + const char fragment_source[] = + { + "#version 330 \n" + "in highp vec4 fP; \n" + "in highp vec3 fN; \n" + "in highp vec4 color; \n" + "uniform bool is_two_side; \n" + "uniform highp vec4 light_pos; \n" + "uniform highp vec4 light_diff; \n" + "uniform highp vec4 light_spec; \n" + "uniform highp vec4 light_amb; \n" + "uniform float spec_power ; \n" + + "void main(void) { \n" + + " vec3 L = light_pos.xyz - fP.xyz; \n" + " vec3 V = -fP.xyz; \n" + + " vec3 N; \n" + " if(fN == vec3(0.0,0.0,0.0)) \n" + " N = vec3(0.0,0.0,0.0); \n" + " else \n" + " N = normalize(fN); \n" + " L = normalize(L); \n" + " V = normalize(V); \n" + + " vec3 R = reflect(-L, N); \n" + " vec4 diffuse; \n" + " if(!is_two_side) \n" + " diffuse = max(dot(N,L),0) * light_diff*color; \n" + " else \n" + " diffuse = max(abs(dot(N,L)),0) * light_diff*color; \n" + " vec4 specular = pow(max(dot(R,V), 0.0), spec_power) * light_spec; \n" + + "gl_FragColor = color*light_amb + diffuse + specular; \n" + "} \n" + "\n" + }; + QOpenGLShader *vertex_shader = new QOpenGLShader(QOpenGLShader::Vertex); + if(!vertex_shader->compileSourceCode(vertex_source)) + { + std::cerr<<"Compiling vertex source FAILED"<compileSourceCode(fragment_source)) + { + std::cerr<<"Compiling fragmentsource FAILED"<camera()->getModelViewProjectionMatrix(mat); + for(int i=0; i < 16; i++) + { + mvpMatrix.data()[i] = (float)mat[i]; + } + viewer->camera()->getModelViewMatrix(mat); + for(int i=0; i < 16; i++) + { + mvMatrix.data()[i] = (float)mat[i]; + } + QVector4D position(0.0f,0.0f,1.0f,1.0f ); + GLboolean isTwoSide; + gl.glGetBooleanv(GL_LIGHT_MODEL_TWO_SIDE,&isTwoSide); + // define material + QVector4D ambient; + QVector4D diffuse; + QVector4D specular; + GLfloat shininess ; + // Ambient + ambient[0] = 0.29225f; + ambient[1] = 0.29225f; + ambient[2] = 0.29225f; + ambient[3] = 1.0f; + // Diffuse + diffuse[0] = 0.50754f; + diffuse[1] = 0.50754f; + diffuse[2] = 0.50754f; + diffuse[3] = 1.0f; + // Specular + specular[0] = 0.0f; + specular[1] = 0.0f; + specular[2] = 0.0f; + specular[3] = 0.0f; + // Shininess + shininess = 51.2f; + + + rendering_program.bind(); + colorLocation[0] = rendering_program.uniformLocation("color"); + twosideLocation = rendering_program.uniformLocation("is_two_side"); + mvpLocation[0] = rendering_program.uniformLocation("mvp_matrix"); + mvLocation[0] = rendering_program.uniformLocation("mv_matrix"); + lightLocation[0] = rendering_program.uniformLocation("light_pos"); + lightLocation[1] = rendering_program.uniformLocation("light_diff"); + lightLocation[2] = rendering_program.uniformLocation("light_spec"); + lightLocation[3] = rendering_program.uniformLocation("light_amb"); + lightLocation[4] = rendering_program.uniformLocation("spec_power"); + + rendering_program.setUniformValue(lightLocation[0], position); + rendering_program.setUniformValue(twosideLocation, isTwoSide); + rendering_program.setUniformValue(mvpLocation[0], mvpMatrix); + rendering_program.setUniformValue(mvLocation[0], mvMatrix); + rendering_program.setUniformValue(lightLocation[1], diffuse); + rendering_program.setUniformValue(lightLocation[2], specular); + rendering_program.setUniformValue(lightLocation[3], ambient); + rendering_program.setUniformValue(lightLocation[4], shininess); + + rendering_program.release(); +} Scene_segmented_image_item::Bbox Scene_segmented_image_item::bbox() const @@ -513,18 +655,17 @@ Scene_segmented_image_item::bbox() const m_image->zdim() * m_image->vz()); } - void -Scene_segmented_image_item::draw() const +Scene_segmented_image_item::draw(QGLViewer* viewer) const { if(m_image) { - m_image->gl_draw_bbox(3.0f,0,0,0); - draw_gl(); + + //m_image->gl_draw_bbox(3.0f,0,0,0); + draw_gl(viewer); } } - QString Scene_segmented_image_item::toolTip() const { @@ -566,12 +707,6 @@ Scene_segmented_image_item::supportsRenderingMode(RenderingMode m) const void Scene_segmented_image_item::initialize_buffers() { -#ifdef SCENE_SEGMENTED_IMAGE_GL_BUFFERS_AVAILABLE - if(!gl_vbo_available()) { - m_initialized = true; - return; - } - internal::Image_accessor image_data_accessor (*m_image, m_voxel_scale, m_voxel_scale, @@ -579,114 +714,210 @@ Scene_segmented_image_item::initialize_buffers() internal::Vertex_buffer_helper helper (image_data_accessor); helper.fill_buffer_data(); - - // Vertex buffer - ::glBindBuffer(GL_ARRAY_BUFFER, m_vbo[0]); - ::glBufferData(GL_ARRAY_BUFFER, helper.vertex_size(), helper.vertices(), GL_STATIC_DRAW); - - ::glBindBuffer(GL_ARRAY_BUFFER, m_vbo[1]); - ::glBufferData(GL_ARRAY_BUFFER, helper.normal_size(), helper.normals(), GL_STATIC_DRAW); - - ::glBindBuffer(GL_ARRAY_BUFFER, m_vbo[2]); - ::glBufferData(GL_ARRAY_BUFFER, helper.color_size(), helper.colors(), GL_STATIC_DRAW); - - // Indices buffer - ::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ibo); - ::glBufferData(GL_ELEMENT_ARRAY_BUFFER, helper.quad_size(), helper.quads(), GL_STATIC_DRAW); - - // Close buffers - ::glBindBuffer(GL_ARRAY_BUFFER, 0); - ::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - -#endif // SCENE_SEGMENTED_IMAGE_GL_BUFFERS_AVAILABLE + + draw_Bbox(bbox(), v_box); + std::vector nul_vec(0); + for(std::size_t i=0; isize(); i++) + nul_vec.push_back(0.0); + + rendering_program.bind(); + vao[0].bind(); + m_vbo[0].bind(); + m_vbo[0].allocate(helper.vertices(), static_cast(helper.vertex_size())); + poly_vertexLocation[0] = rendering_program.attributeLocation("vertex"); + rendering_program.enableAttributeArray(poly_vertexLocation[0]); + rendering_program.setAttributeBuffer(poly_vertexLocation[0],GL_FLOAT,0,3); + m_vbo[0].release(); + + m_vbo[1].bind(); + m_vbo[1].allocate(helper.normals(), static_cast(helper.normal_size())); + normalsLocation[0] = rendering_program.attributeLocation("normal"); + rendering_program.enableAttributeArray(normalsLocation[0]); + rendering_program.setAttributeBuffer(normalsLocation[0],GL_FLOAT,0,3); + m_vbo[1].release(); + + m_vbo[2].bind(); + m_vbo[2].allocate(helper.colors(), static_cast(helper.color_size())); + colorLocation[0] = rendering_program.attributeLocation("inColor"); + rendering_program.enableAttributeArray(colorLocation[0]); + rendering_program.setAttributeBuffer(colorLocation[0],GL_FLOAT,0,3); + m_vbo[2].release(); + + m_ibo->bind(); + m_ibo->allocate(helper.quads(), static_cast(helper.quad_size())); + vao[0].release(); + + color.resize(0); + for(std::size_t i=0; idata(), static_cast(v_box->size()*sizeof(float))); + poly_vertexLocation[0] = rendering_program.attributeLocation("vertex"); + rendering_program.enableAttributeArray(poly_vertexLocation[0]); + rendering_program.setAttributeBuffer(poly_vertexLocation[0],GL_FLOAT,0,3); + m_vbo[3].release(); + + m_vbo[4].bind(); + m_vbo[3].allocate(nul_vec.data(), static_cast(nul_vec.size()*sizeof(float))); + normalsLocation[0] = rendering_program.attributeLocation("normal"); + rendering_program.enableAttributeArray(normalsLocation[0]); + rendering_program.setAttributeBuffer(normalsLocation[0],GL_FLOAT,0,3); + m_vbo[4].release(); + + m_vbo[5].bind(); + m_vbo[5].allocate(nul_vec.data(), static_cast(nul_vec.size()*sizeof(float))); + colorLocation[0] = rendering_program.attributeLocation("inColor"); + rendering_program.enableAttributeArray(colorLocation[0]); + rendering_program.setAttributeBuffer(colorLocation[0],GL_FLOAT,0,3); + m_vbo[5].release(); + + m_ibo->bind(); + vao[1].release(); + rendering_program.release(); m_initialized = true; } void -Scene_segmented_image_item::draw_gl() const +Scene_segmented_image_item::draw_gl(QGLViewer *viewer) const { -#ifdef SCENE_SEGMENTED_IMAGE_GL_BUFFERS_AVAILABLE - if(!gl_vbo_available()) return; + if(!are_ogfunctions_initialized) + { + gl.initializeOpenGLFunctions(); + are_ogfunctions_initialized = true; + } + attrib_buffers(viewer); + rendering_program.bind(); + vao[0].bind(); + gl.glDrawElements(GL_TRIANGLES, m_ibo->size()/sizeof(GLuint), GL_UNSIGNED_INT, 0); + vao[0].release(); - ::glShadeModel(GL_SMOOTH); - - // Draw faces - ::glEnableClientState( GL_VERTEX_ARRAY ); - ::glEnableClientState( GL_NORMAL_ARRAY ); - ::glEnableClientState( GL_COLOR_ARRAY ); - - // Get buffers - ::glBindBuffer(GL_ARRAY_BUFFER, m_vbo[0]); - ::glVertexPointer(3, GL_FLOAT, 0, 0); - - ::glBindBuffer(GL_ARRAY_BUFFER, m_vbo[1]); - ::glNormalPointer(GL_FLOAT, 0, 0); - - ::glBindBuffer(GL_ARRAY_BUFFER, m_vbo[2]); - ::glColorPointer(3, GL_FLOAT, 0, 0); - - // Render - ::glDrawElements(GL_QUADS, ibo_size(), GL_UNSIGNED_INT, 0); - - // Cleanup - ::glBindBuffer(GL_ARRAY_BUFFER, 0); - ::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - - ::glDisableClientState( GL_COLOR_ARRAY ); - ::glDisableClientState( GL_NORMAL_ARRAY ); - ::glDisableClientState( GL_VERTEX_ARRAY ); -#endif // SCENE_SEGMENTED_IMAGE_GL_BUFFERS_AVAILABLE + vao[1].bind(); + gl.glLineWidth(3); + gl.glDrawArrays(GL_LINES, 0, static_cast(v_box->size()/3)); + vao[1].release(); + rendering_program.release(); } - -void -Scene_segmented_image_item::draw_gl_edges() const -{ -#ifdef SCENE_SEGMENTED_IMAGE_GL_BUFFERS_AVAILABLE - if(!gl_vbo_available()) return; - - // Ensure edges are drawn in black - ::glColor3f( 0.f, 0.f, 0.f ); - - // Draw edges - ::glEnableClientState( GL_VERTEX_ARRAY ); - - // Get buffers - ::glBindBuffer(GL_ARRAY_BUFFER, m_vbo[0]); - ::glVertexPointer(3, GL_FLOAT, 0, 0); - - ::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ibo); - - // Render - ::glDrawElements(GL_QUADS, ibo_size(), GL_UNSIGNED_INT, 0); - - // Cleanup - ::glBindBuffer(GL_ARRAY_BUFFER, 0); - ::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - - ::glDisableClientState( GL_VERTEX_ARRAY ); -#endif // SCENE_SEGMENTED_IMAGE_GL_BUFFERS_AVAILABLE -} - - GLint Scene_segmented_image_item::ibo_size() const { -#ifdef SCENE_SEGMENTED_IMAGE_GL_BUFFERS_AVAILABLE - if(gl_vbo_available()) { - GLint nb_elts = 0; - ::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ibo); - ::glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &nb_elts); + m_ibo->bind(); + GLint nb_elts = m_ibo->size(); + m_ibo->release(); return nb_elts/sizeof(GLuint); - } -#endif // SCENE_SEGMENTED_IMAGE_GL_BUFFERS_AVAILABLE return 0; } +void Scene_segmented_image_item::changed() +{ + initialize_buffers(); +} + +void Scene_segmented_image_item::draw_Bbox(Bbox bbox, std::vector *vertices) +{ + vertices->push_back(bbox.xmin); + vertices->push_back(bbox.ymin); + vertices->push_back(bbox.zmin); + + vertices->push_back(bbox.xmin); + vertices->push_back(bbox.ymin); + vertices->push_back(bbox.zmax); + + vertices->push_back(bbox.xmin); + vertices->push_back(bbox.ymin); + vertices->push_back(bbox.zmin); + + vertices->push_back(bbox.xmin); + vertices->push_back(bbox.ymax); + vertices->push_back(bbox.zmin); + + vertices->push_back(bbox.xmin); + vertices->push_back(bbox.ymin); + vertices->push_back(bbox.zmin); + + vertices->push_back(bbox.xmax); + vertices->push_back(bbox.ymin); + vertices->push_back(bbox.zmin); + + vertices->push_back(bbox.xmax); + vertices->push_back(bbox.ymin); + vertices->push_back(bbox.zmin); + + vertices->push_back(bbox.xmax); + vertices->push_back(bbox.ymax); + vertices->push_back(bbox.zmin); + + vertices->push_back(bbox.xmax); + vertices->push_back(bbox.ymin); + vertices->push_back(bbox.zmin); + + vertices->push_back(bbox.xmax); + vertices->push_back(bbox.ymin); + vertices->push_back(bbox.zmax); + + vertices->push_back(bbox.xmin); + vertices->push_back(bbox.ymax); + vertices->push_back(bbox.zmin); + + vertices->push_back(bbox.xmin); + vertices->push_back(bbox.ymax); + vertices->push_back(bbox.zmax); + + vertices->push_back(bbox.xmin); + vertices->push_back(bbox.ymax); + vertices->push_back(bbox.zmin); + + vertices->push_back(bbox.xmax); + vertices->push_back(bbox.ymax); + vertices->push_back(bbox.zmin); + + vertices->push_back(bbox.xmax); + vertices->push_back(bbox.ymax); + vertices->push_back(bbox.zmin); + + vertices->push_back(bbox.xmax); + vertices->push_back(bbox.ymax); + vertices->push_back(bbox.zmax); + + vertices->push_back(bbox.xmin); + vertices->push_back(bbox.ymin); + vertices->push_back(bbox.zmax); + + vertices->push_back(bbox.xmin); + vertices->push_back(bbox.ymax); + vertices->push_back(bbox.zmax); + + vertices->push_back(bbox.xmin); + vertices->push_back(bbox.ymin); + vertices->push_back(bbox.zmax); + + vertices->push_back(bbox.xmax); + vertices->push_back(bbox.ymin); + vertices->push_back(bbox.zmax); + + vertices->push_back(bbox.xmax); + vertices->push_back(bbox.ymax); + vertices->push_back(bbox.zmax); + + vertices->push_back(bbox.xmin); + vertices->push_back(bbox.ymax); + vertices->push_back(bbox.zmax); + + vertices->push_back(bbox.xmax); + vertices->push_back(bbox.ymax); + vertices->push_back(bbox.zmax); + + vertices->push_back(bbox.xmax); + vertices->push_back(bbox.ymin); + vertices->push_back(bbox.zmax); + +} #include "Scene_segmented_image_item.moc" diff --git a/Mesh_3/demo/Mesh_3/Scene_segmented_image_item.h b/Mesh_3/demo/Mesh_3/Scene_segmented_image_item.h index fe11991a316..527f910b63a 100644 --- a/Mesh_3/demo/Mesh_3/Scene_segmented_image_item.h +++ b/Mesh_3/demo/Mesh_3/Scene_segmented_image_item.h @@ -6,7 +6,10 @@ #include "Image_type_fwd.h" #include "Scene_segmented_image_item_config.h" #include - +#include +#include +#include +#include typedef CGAL::Image_3 Image; class SCENE_SEGMENTED_IMAGE_ITEM_EXPORT Scene_segmented_image_item @@ -28,18 +31,17 @@ public: virtual bool supportsRenderingMode(RenderingMode m) const; // draw - virtual void direct_draw() const { draw(); } - virtual void direct_draw_edges() const { draw_edges(); } - virtual void draw() const; - virtual void draw_edges() const { draw_gl_edges(); } + virtual void direct_draw(QGLViewer* viewer) const { draw(viewer); } + virtual void direct_draw_edges(QGLViewer* viewer) const { draw_edges(viewer); } + virtual void draw(QGLViewer*) const; + virtual void draw_edges(QGLViewer* viewer) const { draw_gl(viewer); } virtual QString toolTip() const; const Image* image() const { return m_image; } private: - void draw_gl() const; - void draw_gl_edges() const; + void draw_gl(QGLViewer* viewer) const; void initialize_buffers(); GLint ibo_size() const; @@ -51,8 +53,30 @@ private: bool m_initialized; #ifdef SCENE_SEGMENTED_IMAGE_GL_BUFFERS_AVAILABLE int m_voxel_scale; - GLuint m_vbo[3]; - GLuint m_ibo; + static const int vaoSize = 2; + static const int vboSize = 6; + mutable int poly_vertexLocation[1]; + mutable int normalsLocation[1]; + mutable int mvpLocation[1]; + mutable int mvLocation[1]; + mutable int colorLocation[1]; + mutable int lightLocation[5]; + mutable int twosideLocation; + + std::vector *v_box; + std::vector color; + + + mutable QOpenGLBuffer m_vbo[vboSize]; + mutable QOpenGLBuffer *m_ibo; + mutable QOpenGLVertexArrayObject vao[vaoSize]; + mutable QOpenGLShaderProgram rendering_program; + void draw_bbox(); + void attrib_buffers(QGLViewer*) const; + void compile_shaders(); + void draw_Bbox(Bbox bbox, std::vector *vertices); +public Q_SLOTS: + void changed(); #endif // SCENE_SEGMENTED_IMAGE_GL_BUFFERS_AVAILABLE }; diff --git a/Mesh_3/demo/Mesh_3/Volume_plane.h b/Mesh_3/demo/Mesh_3/Volume_plane.h index 94f2222ae1a..6484f8d0612 100644 --- a/Mesh_3/demo/Mesh_3/Volume_plane.h +++ b/Mesh_3/demo/Mesh_3/Volume_plane.h @@ -1,11 +1,6 @@ #ifndef CGAL_VOLUME_PLANE_H #define CGAL_VOLUME_PLANE_H - -#if SCENE_SEGMENTED_IMAGE_GL_BUFFERS_AVAILABLE - #include -#endif - #include #include @@ -15,6 +10,9 @@ #include #include "Volume_plane_interface.h" +#include +#include +#include #if !defined(NDEBUG) inline @@ -34,7 +32,7 @@ class Length_constraint : public qglviewer::WorldConstraint { public: Length_constraint(double max_) : max_(max_) { } - void constrainTranslation(qglviewer::Vec& t, qglviewer::Frame* frame) { + void constrainTranslation(qglviewer::Vec& t, qglviewer::Frame* const frame) { WorldConstraint::constrainTranslation(t, frame); qglviewer::Vec pos = frame->position(); double start = pos[Dim]; @@ -76,13 +74,14 @@ public: unsigned int cube() {return currentCube; } - void draw() const; + void draw(QGLViewer* viewer)const; unsigned int aDim() const { return adim_; } unsigned int bDim() const { return bdim_; } unsigned int cDim() const { return cdim_; } qglviewer::Vec translationVector() const { return translationVector(*this); } + unsigned int getCurrentCube() const { return currentCube; } // uses a public init function to make enable construction in @@ -90,9 +89,14 @@ public: void init(); private: - static const char* vertexShader; + static const char* vertexShader_source; + + static const char* fragmentShader_source; + + static const char* vertexShader_bordures_source; + + static const char* fragmentShader_bordures_source; - static const char* fragmentShader; qglviewer::Vec translationVector(x_tag) const { return qglviewer::Vec(xscale_, 0.0, 0.0); @@ -132,9 +136,13 @@ private: const double xscale_, yscale_, zscale_; mutable int currentCube; - GLuint vVBO; - GLuint program; - std::vector< std::pair > ebos; + mutable QOpenGLBuffer vVBO; + mutable QOpenGLBuffer cbuffer; + mutable QOpenGLBuffer rectBuffer; + mutable std::vector v_rec; + mutable QOpenGLShaderProgram program_bordures; + mutable QOpenGLShaderProgram program; + mutable std::vector< std::pair > ebos; std::vector< float > colors_; QString name(x_tag) const { return tr("X Slice for %1").arg(name_); } @@ -142,24 +150,27 @@ private: QString name(z_tag) const { return tr("Z Slice for %2").arg(name_); } void drawRectangle(x_tag) const { - glVertex3f(0.0f, 0.0f, 0.0f); - glVertex3f(0.0f, (adim_ - 1) * yscale_, 0.0f); - glVertex3f(0.0f, (adim_ - 1) * yscale_, (bdim_ - 1) * zscale_); - glVertex3f(0.0f, 0.0f, (bdim_ - 1) * zscale_); + + + v_rec.push_back(0.0f); v_rec.push_back(0.0f); v_rec.push_back(0.0f); + v_rec.push_back(0.0f); v_rec.push_back((adim_ - 1) * yscale_); v_rec.push_back(0.0f); + v_rec.push_back(0.0f); v_rec.push_back((adim_ - 1) * yscale_); v_rec.push_back((bdim_ - 1) * zscale_); + v_rec.push_back(0.0f); v_rec.push_back(0.0f); v_rec.push_back((bdim_ - 1) * zscale_); + } void drawRectangle(y_tag) const { - glVertex3f(0.0f, 0.0f, 0.0f); - glVertex3f((adim_ - 1) * xscale_, 0.0f, 0.0f); - glVertex3f((adim_ - 1) * xscale_, 0.0f, (bdim_ - 1) * zscale_); - glVertex3f(0.0f, 0.0f, (bdim_ - 1) * zscale_); + v_rec.push_back(0.0f); v_rec.push_back(0.0f); v_rec.push_back(0.0f); + v_rec.push_back((adim_ - 1) * xscale_);v_rec.push_back(0.0f); v_rec.push_back(0.0f); + v_rec.push_back((adim_ - 1) * xscale_);v_rec.push_back(0.0f);v_rec.push_back( (bdim_ - 1) * zscale_); + v_rec.push_back(0.0f); v_rec.push_back(0.0f); v_rec.push_back((bdim_ - 1) * zscale_); } void drawRectangle(z_tag) const { - glVertex3f(0.0f, 0.0f, 0.0f); - glVertex3f((adim_ - 1) * xscale_, 0.0f, 0.0f); - glVertex3f((adim_ - 1) * xscale_, (bdim_ - 1) * yscale_, 0.0f); - glVertex3f(0.0f, (bdim_ - 1) * yscale_, 0.0f); + v_rec.push_back(0.0f); v_rec.push_back(0.0f); v_rec.push_back(0.0f); + v_rec.push_back((adim_ - 1) * xscale_); v_rec.push_back(0.0f); v_rec.push_back(0.0f); + v_rec.push_back((adim_ - 1) * xscale_); v_rec.push_back((bdim_ - 1) * yscale_); v_rec.push_back(0.0f); + v_rec.push_back(0.0f); v_rec.push_back((bdim_ - 1) * yscale_); v_rec.push_back(0.0f); } qglviewer::Constraint* setConstraint(x_tag) { @@ -193,20 +204,42 @@ private: }; template -const char* Volume_plane::vertexShader = - "#version 120 \n" - "attribute float color;" - "varying vec4 fullColor; \n" +const char* Volume_plane::vertexShader_source = + "#version 330 \n" + "in vec4 vertex; \n" + "in float color; \n" + "uniform highp mat4 mvp_matrix; \n" + "uniform highp mat4 f_matrix; \n" + "out vec4 fullColor; \n" "void main() \n" - "{ gl_Position = ftransform(); \n" - " fullColor = vec4(color, color, color, 1.0f); } \n"; + "{ gl_Position = mvp_matrix * f_matrix * vertex; \n" + " fullColor = vec4(color, color, color, 1.0f); } \n"; template -const char* Volume_plane::fragmentShader = - "#version 120 \n" +const char* Volume_plane::fragmentShader_source = + "#version 330\n" "in vec4 fullColor; \n" "void main() { gl_FragColor = fullColor; } \n"; +template +const char* Volume_plane::vertexShader_bordures_source = + "#version 330 \n" + "in vec4 vertex; \n" + "uniform vec4 color; \n" + "uniform highp mat4 mvp_matrix; \n" + "uniform highp mat4 f_matrix; \n" + "out vec4 fullColor; \n" + "void main() \n" + "{ gl_Position = mvp_matrix * f_matrix * vertex; \n" + " fullColor = color; } \n"; + +template +const char* Volume_plane::fragmentShader_bordures_source = + "#version 330\n" + "in vec4 fullColor; \n" + "void main() { gl_FragColor = fullColor; } \n"; + + template Volume_plane::Volume_plane(unsigned int adim, unsigned int bdim, unsigned int cdim, @@ -220,71 +253,89 @@ Volume_plane::Volume_plane(unsigned int adim, unsigned int bdim, unsigned int template Volume_plane::~Volume_plane() { - for(std::vector< std::pair< GLuint, unsigned int> >::const_iterator it = ebos.begin(); + for(std::vector< std::pair< QOpenGLBuffer, unsigned int> >::iterator it = ebos.begin(); it != ebos.end(); ++it) { - glDeleteBuffers(1, &(it->first)); + it->first.destroy(); } - glDeleteProgram(program); + program.release(); } template -void Volume_plane::draw() const { +void Volume_plane::draw(QGLViewer *viewer) const { updateCurrentCube(); - glDisable(GL_LIGHTING); - glPushMatrix(); - glMultMatrixd(mFrame_->matrix()); + GLdouble mat[16]; + viewer->camera()->getModelViewProjectionMatrix(mat); + QMatrix4x4 mvp; + QMatrix4x4 f; + for(int i=0; i<16; i++) + { + mvp.data()[i] = (float)mat[i]; + f.data()[i] = (float)mFrame_->matrix()[i]; + } + + + program_bordures.bind(); + program_bordures.setUniformValue("mvp_matrix", mvp); + program_bordures.setUniformValue("f_matrix", f); + program_bordures.release(); GLint renderMode; glGetIntegerv(GL_RENDER_MODE, &renderMode); printGlError(__LINE__); - if(renderMode == GL_SELECT) { - // draw a quick bounding box - glBegin(GL_QUADS); - drawRectangle(*this); - glEnd(); - glPopMatrix(); - glEnable(GL_LIGHTING); - return; - } - glLineWidth(3.0f); - glBegin(GL_LINE_LOOP); + glLineWidth(4.0f); + v_rec.resize(0); drawRectangle(*this); - glEnd(); + + program_bordures.bind(); + rectBuffer.create(); + rectBuffer.bind(); + rectBuffer.allocate(v_rec.data(), static_cast(v_rec.size()*sizeof(float))); + program_bordures.setAttributeBuffer("vertex",GL_FLOAT,0,3); + program_bordures.enableAttributeArray("vertex"); + float current_color[4]; + glGetFloatv(GL_CURRENT_COLOR, current_color); + QColor color; + color.setRgbF(current_color[0], current_color[1], current_color[2]); + program_bordures.setUniformValue("color",color); + glDrawArrays(GL_LINE_LOOP, 0, static_cast(v_rec.size()/3)); + rectBuffer.release(); + program_bordures.release(); glLineWidth(1.0f); - glUseProgram(program); + program.bind(); + int mvpLoc = program.uniformLocation("mvp_matrix"); + int fLoc = program.uniformLocation("f_matrix"); + program.setUniformValue(mvpLoc, mvp); + program.setUniformValue(fLoc, f); + vVBO.bind(); + int vloc = program.attributeLocation("vertex"); + program.enableAttributeArray(vloc); + program.setAttributeBuffer(vloc, GL_FLOAT, 0, 3); + vVBO.release(); - glBindBuffer(GL_ARRAY_BUFFER, vVBO); - glVertexPointer(3, GL_FLOAT, 0, 0); - glEnableClientState(GL_VERTEX_ARRAY); + cbuffer.bind(); + int colorLoc = program.attributeLocation("color"); + program.enableAttributeArray(colorLoc); + program.setAttributeBuffer(colorLoc, GL_FLOAT, (currentCube*sizeof(float)) * (bdim_) * (adim_), 1, 0 ); + cbuffer.release(); - glBindBuffer(GL_ARRAY_BUFFER, 0); - glVertexAttribPointer(7, 1, GL_FLOAT, GL_FALSE, 0, &(colors_[ currentCube * adim_ * bdim_ ])); - glEnableVertexAttribArray(7); printGlError(__LINE__); - for(unsigned int i = 0; i < ebos.size(); ++i) + for(unsigned int i = 0; i < ebos.size(); ++i) { - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebos[i].first); - glDrawElements(GL_QUADS, ebos[i].second, GL_UNSIGNED_INT, 0); + ebos[i].first.bind(); + glDrawElements(GL_TRIANGLES, ebos[i].second, GL_UNSIGNED_INT, 0); + ebos[i].first.release(); } + cbuffer.release(); printGlError(__LINE__); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableVertexAttribArray(7); - glPopMatrix(); - - glUseProgram(0); - glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - - glEnable(GL_LIGHTING); + program.release(); printGlError(__LINE__); } @@ -311,90 +362,89 @@ void Volume_plane::init() { glGetIntegerv(GL_MAX_ELEMENTS_INDICES, &maxi); glGetIntegerv(GL_MAX_ELEMENTS_VERTICES, &maxv); assert((vertices.size( ) / 3) < (unsigned int)maxi); - - glGenBuffers(1, &vVBO); - glBindBuffer(GL_ARRAY_BUFFER, vVBO); - - glBufferData(GL_ARRAY_BUFFER, sizeof(float) * vertices.size(), &vertices[0], GL_STATIC_DRAW); - glBindBuffer(GL_ARRAY_BUFFER, 0); + vVBO.create(); + vVBO.bind(); + vVBO.allocate(vertices.data(),static_cast(sizeof(float) * vertices.size())); + vVBO.release(); printGlError(__LINE__); // for each patch std::vector indices; for(unsigned int j = 0; j < adim_ - 1; ++j) { for(unsigned int k = 0; k < bdim_ - 1; ++k) { - indices.push_back( j * bdim_ + k ); - assert(indices.back() < (vertices.size() / 3)); - - indices.push_back( j * bdim_ + (k + 1) ); - assert(indices.back() < (vertices.size() / 3)); - - indices.push_back( (j+1) * bdim_ + (k+1) ); - assert(indices.back() < (vertices.size() / 3)); - - indices.push_back( (j+1) * bdim_ + (k) ); - assert(indices.back() < (vertices.size() / 3)); + //0 + indices.push_back( j * bdim_ + k ); + assert(indices.back() < (vertices.size() / 3)); + + //1 + indices.push_back( j * bdim_ + (k + 1) ); + assert(indices.back() < (vertices.size() / 3)); + + //3 + indices.push_back( (j+1) * bdim_ + (k+1) ); + assert(indices.back() < (vertices.size() / 3)); + + //0 + indices.push_back( j * bdim_ + k ); + assert(indices.back() < (vertices.size() / 3)); + + //3 + indices.push_back( (j+1) * bdim_ + (k+1) ); + assert(indices.back() < (vertices.size() / 3)); + + //2 + indices.push_back( (j+1) * bdim_ + (k) ); + assert(indices.back() < (vertices.size() / 3)); + } } - assert((indices.size() / 4) == (adim_ - 1) * (bdim_ - 1)); - - const unsigned int slice = 64000; + assert((indices.size() / 6) == (adim_ - 1) * (bdim_ - 1)); + //slice must be multiple of 3. + const unsigned int slice = 63399; for(unsigned int i = 0; i < indices.size(); i+=slice) { - GLuint ebo; + QOpenGLBuffer ebo = QOpenGLBuffer(QOpenGLBuffer::IndexBuffer); unsigned int left_over = (i + slice) > indices.size() ? std::distance(indices.begin() + i, indices.end()) : slice; - glGenBuffers(1, &ebo); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * left_over, &indices[i], GL_STATIC_DRAW); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + ebo.create(); + ebo.bind(); + ebo.allocate(&indices[i],static_cast(sizeof(unsigned int) * left_over)); + ebo.release(); ebos.push_back(std::make_pair(ebo, left_over)); } + cbuffer.create(); + cbuffer.bind(); + cbuffer.allocate(colors_.data(),static_cast(colors_.size()*sizeof(float))); + cbuffer.release(); + printGlError(__LINE__); } template void Volume_plane::initShaders() { - program = glCreateProgram(); - GLint status; - char buffer[1024]; - int len; + program.create(); - GLuint vertex = glCreateShader(GL_VERTEX_SHADER); - GLint* lengths = { 0 }; - glShaderSource(vertex, 1, &vertexShader, lengths); - glCompileShader(vertex); - glGetShaderiv(vertex, GL_COMPILE_STATUS, &status); - glGetShaderInfoLog(vertex, 1024, &len, buffer); - std::cout << "VertexShader: " << buffer << std::endl; - assert(status == GL_TRUE); + QOpenGLShader *vertex = new QOpenGLShader(QOpenGLShader::Vertex); - printGlError(__LINE__); + vertex->compileSourceCode(vertexShader_source); + QOpenGLShader *fragment= new QOpenGLShader(QOpenGLShader::Fragment); + fragment->compileSourceCode(fragmentShader_source); + program.addShader(vertex); + program.addShader(fragment); + program.link(); - GLuint fragment = glCreateShader(GL_FRAGMENT_SHADER); - glShaderSource(fragment, 1, &fragmentShader, lengths); - glCompileShader(fragment); - glGetShaderiv(fragment, GL_COMPILE_STATUS, &status); - glGetShaderInfoLog(fragment, 1024, &len, buffer); - std::cout << "FragmentShader: " << buffer << std::endl; + program_bordures.create(); + QOpenGLShader *vertex_bordures = new QOpenGLShader(QOpenGLShader::Vertex); - assert(status == GL_TRUE); - - printGlError(__LINE__); - - glAttachShader(program, vertex); - glAttachShader(program, fragment); - - glBindAttribLocation(program, 7, "color"); - - glLinkProgram(program); - glGetProgramiv(program, GL_LINK_STATUS, &status); - assert(status == GL_TRUE); - - printGlError(__LINE__); + vertex_bordures->compileSourceCode(vertexShader_bordures_source); + QOpenGLShader *fragment_bordures= new QOpenGLShader(QOpenGLShader::Fragment); + fragment_bordures->compileSourceCode(fragmentShader_bordures_source); + program_bordures.addShader(vertex_bordures); + program_bordures.addShader(fragment_bordures); + program_bordures.link(); } diff --git a/Mesh_3/demo/Mesh_3/Volume_plane_intersection.cpp b/Mesh_3/demo/Mesh_3/Volume_plane_intersection.cpp index f691a7d38ee..edc21a6fdc5 100644 --- a/Mesh_3/demo/Mesh_3/Volume_plane_intersection.cpp +++ b/Mesh_3/demo/Mesh_3/Volume_plane_intersection.cpp @@ -5,58 +5,203 @@ #include +void Volume_plane_intersection::compile_shaders() +{ -void Volume_plane_intersection::draw() const { - glDisable(GL_LIGHTING); - glLineWidth(4.0f); + for(int i=0; i< vboSize; i++) + buffers[i].create(); + for(int i=0; i< vaoSize; i++) + vao[i].create(); - if(b && c) { - glPushMatrix(); - glMultMatrixd(b->manipulatedFrame()->matrix()); - glMultMatrixd(c->manipulatedFrame()->matrix()); - - glBegin(GL_LINES); + //Vertex source code + const char vertex_source[] = { - glVertex3f(0.0f, 0.0f, 0.0f); - glVertex3f(x, 0.0f, 0.0f); + "#version 330 \n" + "in highp vec4 vertex;\n" + "uniform highp mat4 mvp_matrix;\n" + "uniform highp mat4 f_matrix; \n" + "void main(void)\n" + "{\n" + " gl_Position = mvp_matrix* f_matrix * vertex; \n" + "}" + }; + //Fragment source code + const char fragment_source[] = + { + "#version 330 \n" + "void main(void) { \n" + "gl_FragColor = vec4(1.0,0.0,0.0,1.0); \n" + "} \n" + "\n" + }; + QOpenGLShader *vertex_shader = new QOpenGLShader(QOpenGLShader::Vertex); + if(!vertex_shader->compileSourceCode(vertex_source)) + { + std::cerr<<"Compiling vertex source FAILED"<compileSourceCode(fragment_source)) + { + std::cerr<<"Compiling fragmentsource FAILED"<camera()->getModelViewProjectionMatrix(mat); + for(int i=0; i < 16; i++) + { + mvpMatrix.data()[i] = (float)mat[i]; + } + + rendering_program.bind(); + mvpLocation[0] = rendering_program.uniformLocation("mvp_matrix"); + rendering_program.setUniformValue(mvpLocation[0], mvpMatrix); + rendering_program.release(); +} + +void Volume_plane_intersection::draw(QGLViewer *viewer) const { + if(!are_ogfunctions_initialized) + { + gl.initializeOpenGLFunctions(); + are_ogfunctions_initialized = true; + } + gl.glLineWidth(4.0f); + attrib_buffers(viewer); + if(b && c) { + + vao[0].bind(); + rendering_program.bind(); + GLdouble mat[16]; + b->manipulatedFrame()->getMatrix(mat); + QMatrix4x4 b_mat, c_mat; + for(int i=0; i<16; i++) + { + b_mat.data()[i] = (float)mat[i]; + } + c->manipulatedFrame()->getMatrix(mat); + for(int i=0; i<16; i++) + { + c_mat.data()[i] = (float)mat[i]; + } + rendering_program.setUniformValue("f_matrix", b_mat*c_mat); + gl.glDrawArrays(GL_LINES, 0, 2); + rendering_program.release(); + vao[0].release(); } if(a && c) { - glPushMatrix(); - glMultMatrixd(a->manipulatedFrame()->matrix()); - glMultMatrixd(c->manipulatedFrame()->matrix()); - - glBegin(GL_LINES); - { - glVertex3f(0.0f, 0.0f, 0.0f); - glVertex3f(0.0f, y, 0.0f); - } - glEnd(); - - glPopMatrix(); + vao[1].bind(); + rendering_program.bind(); + GLdouble mat[16]; + a->manipulatedFrame()->getMatrix(mat); + QMatrix4x4 a_mat, c_mat; + for(int i=0; i<16; i++) + { + a_mat.data()[i] = (float)mat[i]; + } + c->manipulatedFrame()->getMatrix(mat); + for(int i=0; i<16; i++) + { + c_mat.data()[i] = (float)mat[i]; + } + rendering_program.setUniformValue("f_matrix", a_mat*c_mat); + gl.glDrawArrays(GL_LINES, 0, 2); + rendering_program.release(); + vao[1].release(); } - if(a && b) { - glPushMatrix(); - glMultMatrixd(a->manipulatedFrame()->matrix()); - glMultMatrixd(b->manipulatedFrame()->matrix()); - - glBegin(GL_LINES); - { - glVertex3f(0.0f, 0.0f, 0.0f); - glVertex3f(0.0f, 0.0f, z); - } - glEnd(); - - glPopMatrix(); + if(a && b) { + vao[2].bind(); + rendering_program.bind(); + GLdouble mat[16]; + a->manipulatedFrame()->getMatrix(mat); + QMatrix4x4 a_mat, b_mat; + for(int i=0; i<16; i++) + { + a_mat.data()[i] = (float)mat[i]; + } + b->manipulatedFrame()->getMatrix(mat); + for(int i=0; i<16; i++) + { + b_mat.data()[i] = (float)mat[i]; + } + rendering_program.setUniformValue("f_matrix", a_mat*b_mat); + gl.glDrawArrays(GL_LINES, 0, 2); + rendering_program.release(); + vao[2].release(); } - glLineWidth(1.0f); - glEnable(GL_LIGHTING); + gl.glLineWidth(1.0f); } #include "Volume_plane_intersection.moc" diff --git a/Mesh_3/demo/Mesh_3/Volume_plane_intersection.h b/Mesh_3/demo/Mesh_3/Volume_plane_intersection.h index c872dc71941..0e0dcc5d196 100644 --- a/Mesh_3/demo/Mesh_3/Volume_plane_intersection.h +++ b/Mesh_3/demo/Mesh_3/Volume_plane_intersection.h @@ -5,6 +5,10 @@ #include #include +#include +#include +#include +#include class Volume_plane_interface; @@ -17,6 +21,9 @@ public: : a(NULL), b(NULL), c(NULL), x(x), y(y), z(z) { setColor(QColor(255, 0, 0)); setName("Volume plane intersection"); + compile_shaders(); + compute_elements(); + init_buffers(); } bool isFinite() const { return true; } @@ -26,7 +33,7 @@ public: bool supportsRenderingMode(RenderingMode) const { return true; } QString toolTip() const { return "Tooling"; } - void draw() const; + void draw(QGLViewer*)const; void setX(Volume_plane_interface* x) { a = x; } void setY(Volume_plane_interface* x) { b = x; } @@ -46,6 +53,24 @@ public Q_SLOTS: private: Volume_plane_interface *a, *b, *c; float x, y, z; + + static const int vaoSize = 3; + static const int vboSize = 3; + + mutable int vertexLocation[1]; + mutable int mvpLocation[1]; + + std::vector a_vertex; + std::vector b_vertex; + std::vector c_vertex; + + mutable QOpenGLBuffer buffers[vboSize]; + mutable QOpenGLVertexArrayObject vao[vaoSize]; + mutable QOpenGLShaderProgram rendering_program; + void compute_elements(); + void init_buffers(); + void attrib_buffers(QGLViewer*) const; + void compile_shaders(); }; #endif /* CGAL_VOLUME_PLANE_INTERSECTION_H_ */ diff --git a/Mesh_3/demo/Mesh_3/Volume_plane_thread.h b/Mesh_3/demo/Mesh_3/Volume_plane_thread.h index 5e68c18ce85..f2f80146216 100644 --- a/Mesh_3/demo/Mesh_3/Volume_plane_thread.h +++ b/Mesh_3/demo/Mesh_3/Volume_plane_thread.h @@ -80,7 +80,7 @@ void X_plane_thread::run() { } } } - item = new Volume_plane(img->ydim(), img->zdim(), img->xdim(), + item = new Volume_plane(static_cast(img->ydim()), static_cast(img->zdim()), static_cast(img->xdim()), img->vx(), img->vy(), img->vz(), buffer); item->setName(name); @@ -100,7 +100,7 @@ void Y_plane_thread::run() { } } } - item = new Volume_plane(img->xdim(), img->zdim(), img->ydim(), + item = new Volume_plane(static_cast(img->xdim()), static_cast(img->zdim()), static_cast(img->ydim()), img->vx(), img->vy(), img->vz(), buffer); item->setName(name); item->moveToThread(QApplication::instance()->thread()); @@ -118,7 +118,7 @@ void Z_plane_thread::run() { } } } - item = new Volume_plane(img->xdim(), img->ydim(), img->zdim(), + item = new Volume_plane(static_cast(img->xdim()), static_cast(img->ydim()), static_cast(img->zdim()), img->vx(), img->vy(), img->vz(), buffer); item->setName(name); item->moveToThread(QApplication::instance()->thread()); diff --git a/Mesh_3/demo/Mesh_3/Volume_planes_plugin.cpp b/Mesh_3/demo/Mesh_3/Volume_planes_plugin.cpp index 529c209addc..5e734dd5286 100644 --- a/Mesh_3/demo/Mesh_3/Volume_planes_plugin.cpp +++ b/Mesh_3/demo/Mesh_3/Volume_planes_plugin.cpp @@ -69,18 +69,26 @@ Q_SIGNALS: void x(int); public: + PixelReader():are_glfunctions_initialized(false){} void setIC(const IntConverter& x) { ic = x; fc = boost::optional(); } void setFC(const DoubleConverter& x) { fc = x; ic = boost::optional(); } private: boost::optional ic; boost::optional fc; + QOpenGLFunctions_3_3_Core gl; + bool are_glfunctions_initialized; void getPixel(const QPoint& e) { + if(!are_glfunctions_initialized) + { + gl.initializeOpenGLFunctions(); + are_glfunctions_initialized = true; + } float data[3]; int vp[4]; - glGetIntegerv(GL_VIEWPORT, vp); - glReadPixels(e.x(), vp[3] - e.y(), 1, 1, GL_RGB, GL_FLOAT, data); + gl.glGetIntegerv(GL_VIEWPORT, vp); + gl.glReadPixels(e.x(), vp[3] - e.y(), 1, 1, GL_RGB, GL_FLOAT, data); if(fc) { Q_EMIT x( (*fc)(data[0]) ); @@ -149,6 +157,8 @@ class Volume_plane_plugin : { Q_OBJECT Q_INTERFACES(Plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") + public: Volume_plane_plugin() : planeSwitch(NULL), sc(NULL), mw(NULL) { @@ -340,7 +350,7 @@ private: const Word* begin = (const Word*)img->data(); const Word* end = (const Word*)img->data() + img->size(); - std::pair minmax = std::make_pair(*std::min_element(begin, end), *std::max_element(begin, end)); + std::pair minmax(*std::min_element(begin, end), *std::max_element(begin, end)); Clamp_to_one_zero_range clamper = { minmax }; @@ -378,9 +388,4 @@ private: } }; - - - -Q_EXPORT_PLUGIN2(Volume_plane_plugin, Volume_plane_plugin) - #include "Volume_planes_plugin.moc" diff --git a/Mesh_3/demo/Mesh_3/cgal_test_with_cmake b/Mesh_3/demo/Mesh_3/cgal_test_with_cmake index 8b3e2a2d4a7..f84ac21c545 100755 --- a/Mesh_3/demo/Mesh_3/cgal_test_with_cmake +++ b/Mesh_3/demo/Mesh_3/cgal_test_with_cmake @@ -149,6 +149,6 @@ fi # if [ -n "${NEED_CLEAN}" ]; then if ! ( uname | grep -q "CYGWIN" ) ; then - ${MAKE_CMD} -fMakefile clean + ${MAKE_CMD} -fMakefile clean || true fi fi diff --git a/Mesh_3/demo/Mesh_3/implicit_functions/CMakeLists.txt b/Mesh_3/demo/Mesh_3/implicit_functions/CMakeLists.txt index 77fe6e57cc0..5eb15b4e69a 100644 --- a/Mesh_3/demo/Mesh_3/implicit_functions/CMakeLists.txt +++ b/Mesh_3/demo/Mesh_3/implicit_functions/CMakeLists.txt @@ -2,11 +2,9 @@ project( Mesh_3_implicit_functions ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() # Let plugins be compiled in the same directory as the executable. @@ -15,20 +13,15 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}") # Include directory of demo includes include_directories( BEFORE ${Mesh_3_implicit_functions_BINARY_DIR} ../include ) -# Find CGAL and CGAL Qt4 -find_package(CGAL COMPONENTS Qt4) +# Find CGAL and CGAL Qt5 +find_package(CGAL COMPONENTS Qt5) include( ${CGAL_USE_FILE} ) -# Find Qt4 itself -set( QT_USE_QTXML TRUE ) -set( QT_USE_QTMAIN TRUE ) -set( QT_USE_QTSCRIPT TRUE ) -set( QT_USE_QTOPENGL TRUE ) -find_package(Qt4) +# Find Qt5 itself +find_package(Qt5 QUIET COMPONENTS Xml Script OpenGL) -if(CGAL_Qt4_FOUND AND QT4_FOUND) - include(${QT_USE_FILE}) +if(CGAL_Qt5_FOUND AND Qt5_FOUND) # put plugins (which are shared libraries) at the same location as # executable files @@ -49,10 +42,11 @@ if(CGAL_Qt4_FOUND AND QT4_FOUND) else() set(other_sources ${ARGN_TAIL}) endif() - qt4_generate_moc( "${CMAKE_CURRENT_SOURCE_DIR}/${plugin_implementation_base_name}.cpp" ${plugin_implementation_base_name}.moc ) + qt5_generate_moc( "${CMAKE_CURRENT_SOURCE_DIR}/${plugin_implementation_base_name}.cpp" ${plugin_implementation_base_name}.moc ) add_file_dependencies( ${plugin_implementation_base_name}.moc "${CMAKE_CURRENT_SOURCE_DIR}/${plugin_implementation_base_name}.cpp" ) add_library(${plugin_name} MODULE ${option} ${plugin_implementation_base_name}.moc ${plugin_implementation_base_name}.cpp ${other_sources}) + qt5_use_modules(${plugin_name} Xml Script OpenGL) add_to_cached_list( CGAL_EXECUTABLE_TARGETS ${plugin_name} ) # Link with Qt target_link_libraries( ${plugin_name} ${QT_LIBRARIES} ) @@ -64,18 +58,18 @@ if(CGAL_Qt4_FOUND AND QT4_FOUND) polyhedron_demo_plugin(tanglecube_function_plugin Tanglecube_implicit_function) polyhedron_demo_plugin(klein_function_plugin Klein_implicit_function) -else (CGAL_Qt4_FOUND AND QT4_FOUND) +else (CGAL_Qt5_FOUND AND Qt5_FOUND) set(MESH_3_MISSING_DEPS "") - if(NOT CGAL_Qt4_FOUND) - set(MESH_3_MISSING_DEPS "the CGAL Qt4 library, ${MESH_3_MISSING_DEPS}") + if(NOT CGAL_Qt5_FOUND) + set(MESH_3_MISSING_DEPS "the CGAL Qt5 library, ${MESH_3_MISSING_DEPS}") endif() - if(NOT QT4_FOUND) - set(MESH_3_MISSING_DEPS "Qt4, ${MESH_3_MISSING_DEPS}") + if(NOT Qt5_FOUND) + set(MESH_3_MISSING_DEPS "Qt5, ${MESH_3_MISSING_DEPS}") endif() message(STATUS "NOTICE: This demo requires ${MESH_3_MISSING_DEPS}and will not be compiled.") -endif (CGAL_Qt4_FOUND AND QT4_FOUND) +endif (CGAL_Qt5_FOUND AND Qt5_FOUND) diff --git a/Mesh_3/demo/Mesh_3/implicit_functions/Klein_implicit_function.cpp b/Mesh_3/demo/Mesh_3/implicit_functions/Klein_implicit_function.cpp index aa480e952df..09878a4e1f9 100644 --- a/Mesh_3/demo/Mesh_3/implicit_functions/Klein_implicit_function.cpp +++ b/Mesh_3/demo/Mesh_3/implicit_functions/Klein_implicit_function.cpp @@ -31,7 +31,9 @@ class Klein_implicit_function : { Q_OBJECT Q_INTERFACES(Implicit_function_interface) - + Q_PLUGIN_METADATA(IID "com.geometryfactory.Mesh3Demo.Implicit_function_interface/1.0") + + public: virtual QString name() const { return "Klein function"; } @@ -50,6 +52,4 @@ public: } }; -#include -Q_EXPORT_PLUGIN2(Klein_implicit_function, Klein_implicit_function) #include "Klein_implicit_function.moc" diff --git a/Mesh_3/demo/Mesh_3/implicit_functions/Sphere_implicit_function.cpp b/Mesh_3/demo/Mesh_3/implicit_functions/Sphere_implicit_function.cpp index bb02a0887ac..e8496c36722 100644 --- a/Mesh_3/demo/Mesh_3/implicit_functions/Sphere_implicit_function.cpp +++ b/Mesh_3/demo/Mesh_3/implicit_functions/Sphere_implicit_function.cpp @@ -25,7 +25,6 @@ #include #include "Implicit_function_interface.h" - const double radius = 1.; class Sphere_implicit_function : @@ -34,7 +33,8 @@ class Sphere_implicit_function : { Q_OBJECT Q_INTERFACES(Implicit_function_interface) - + Q_PLUGIN_METADATA(IID "com.geometryfactory.Mesh3Demo.Implicit_function_interface/1.0") + public: virtual QString name() const { return "Sphere function"; } @@ -50,8 +50,4 @@ public: } }; - - -#include -Q_EXPORT_PLUGIN2(Sphere_implicit_function, Sphere_implicit_function) #include "Sphere_implicit_function.moc" diff --git a/Mesh_3/demo/Mesh_3/implicit_functions/Tanglecube_implicit_function.cpp b/Mesh_3/demo/Mesh_3/implicit_functions/Tanglecube_implicit_function.cpp index b092fa25fb6..82c89fef3f0 100644 --- a/Mesh_3/demo/Mesh_3/implicit_functions/Tanglecube_implicit_function.cpp +++ b/Mesh_3/demo/Mesh_3/implicit_functions/Tanglecube_implicit_function.cpp @@ -25,7 +25,6 @@ #include #include "Implicit_function_interface.h" - const double radius = 4.; class Tanglecube_implicit_function : @@ -34,7 +33,8 @@ class Tanglecube_implicit_function : { Q_OBJECT Q_INTERFACES(Implicit_function_interface) - + Q_PLUGIN_METADATA(IID "com.geometryfactory.Mesh3Demo.Implicit_function_interface/1.0") + public: virtual QString name() const { return "Tanglecube function"; } @@ -52,8 +52,4 @@ public: } }; - - -#include -Q_EXPORT_PLUGIN2(Tanglecube_implicit_function, Tanglecube_implicit_function) #include "Tanglecube_implicit_function.moc" diff --git a/Mesh_3/demo/Mesh_3/include/CGAL/gl_render.h b/Mesh_3/demo/Mesh_3/include/CGAL/gl_render.h deleted file mode 100644 index 8a99078415f..00000000000 --- a/Mesh_3/demo/Mesh_3/include/CGAL/gl_render.h +++ /dev/null @@ -1,83 +0,0 @@ -#ifndef _GL_RENDER_ -#define _GL_RENDER_ - -#include -#include - -template -void gl_render_facets(Polyhedron& polyhedron) -{ - typedef typename Polyhedron::Traits Kernel; - typedef typename Kernel::Point_3 Point; - typedef typename Kernel::Vector_3 Vector; - typedef typename Polyhedron::Facet Facet; - typedef typename Polyhedron::Facet_handle Facet_handle; - typedef typename Polyhedron::Facet_iterator Facet_iterator; - typedef typename Polyhedron::Halfedge_around_facet_circulator HF_circulator; - - // Get current shading model - GLint shading; - ::glGetIntegerv(GL_SHADE_MODEL, &shading); - - Facet_iterator f; - for(f = polyhedron.facets_begin(); - f != polyhedron.facets_end(); - f++) - { - ::glBegin(GL_POLYGON); - - // If Flat shading: 1 normal per polygon - if (shading == GL_FLAT) - { - Vector n = - CGAL::Polygon_mesh_processing::compute_face_normal(f, polyhedron); - ::glNormal3d(n.x(),n.y(),n.z()); - } - - // revolve around current face to get vertices - HF_circulator he = f->facet_begin(); - HF_circulator end = he; - CGAL_For_all(he,end) - { - // If Gouraud shading: 1 normal per vertex - if (shading == GL_SMOOTH) - { - Vector n = - CGAL::Polygon_mesh_processing::compute_vertex_normal(he->vertex(), polyhedron); - ::glNormal3d(n.x(),n.y(),n.z()); - } - - const Point& p = he->vertex()->point(); - ::glVertex3d(p.x(),p.y(),p.z()); - } - ::glEnd(); - } -} // end gl_render_facets - -template -void gl_render_edges(Polyhedron& polyhedron) -{ - typedef typename Polyhedron::Traits Kernel; - typedef typename Kernel::Point_3 Point; - typedef typename Polyhedron::Edge_iterator Edge_iterator; - - ::glBegin(GL_LINES); - Edge_iterator he; - for(he = polyhedron.edges_begin(); - he != polyhedron.edges_end(); - he++) - { - const Point& a = he->vertex()->point(); - const Point& b = he->opposite()->vertex()->point(); - ::glVertex3d(a.x(),a.y(),a.z()); - ::glVertex3d(b.x(),b.y(),b.z()); - } - ::glEnd(); -} // end gl_render_edges - - -#endif // _GL_RENDER_ - - - - diff --git a/Mesh_3/demo/Mesh_3/include/CGAL_demo/Io_plugin_interface.h b/Mesh_3/demo/Mesh_3/include/CGAL_demo/Io_plugin_interface.h index 1ec16bfb936..c5cde32b484 100644 --- a/Mesh_3/demo/Mesh_3/include/CGAL_demo/Io_plugin_interface.h +++ b/Mesh_3/demo/Mesh_3/include/CGAL_demo/Io_plugin_interface.h @@ -4,6 +4,7 @@ #include #include + class Scene_item; class Io_plugin_interface diff --git a/Mesh_3/demo/Mesh_3/include/CGAL_demo/Scene.h b/Mesh_3/demo/Mesh_3/include/CGAL_demo/Scene.h index 3b3dc98072a..070b3b47f16 100644 --- a/Mesh_3/demo/Mesh_3/include/CGAL_demo/Scene.h +++ b/Mesh_3/demo/Mesh_3/include/CGAL_demo/Scene.h @@ -16,6 +16,9 @@ #include #include #include +#include + + class QEvent; class QMouseEvent; @@ -58,8 +61,8 @@ public: // initializeGL() is called by Viewer::initializeGL() void initializeGL(); // draw() is called by Viewer::draw() - void draw(); - void drawWithNames(); + void draw(QGLViewer *viewer); + void drawWithNames(QGLViewer *viewer); // Get scene bounding box Bbox bbox() const; @@ -106,7 +109,7 @@ Q_SIGNALS: void selectionChanged(); private: - void draw_aux(bool with_names); + void draw_aux(bool with_names, QGLViewer *viewer); typedef QList Entries; Entries entries; int selected_item; diff --git a/Mesh_3/demo/Mesh_3/include/CGAL_demo/Scene_draw_interface.h b/Mesh_3/demo/Mesh_3/include/CGAL_demo/Scene_draw_interface.h index 394ea7ebfd7..4ca11fc1f8d 100644 --- a/Mesh_3/demo/Mesh_3/include/CGAL_demo/Scene_draw_interface.h +++ b/Mesh_3/demo/Mesh_3/include/CGAL_demo/Scene_draw_interface.h @@ -1,12 +1,12 @@ #ifndef SCENE_DRAW_INTERFACE_H #define SCENE_DRAW_INTERFACE_H - +#include class Scene_draw_interface { public: virtual ~Scene_draw_interface(){} virtual void initializeGL() = 0; - virtual void draw() = 0; - virtual void drawWithNames() = 0; + virtual void draw(QGLViewer*) = 0; + virtual void drawWithNames(QGLViewer*) = 0; }; #endif // SCENE_DRAW_INTERFACE_H; diff --git a/Mesh_3/demo/Mesh_3/include/CGAL_demo/Scene_item.h b/Mesh_3/demo/Mesh_3/include/CGAL_demo/Scene_item.h index 7cff7080e01..abaccd5c0f8 100644 --- a/Mesh_3/demo/Mesh_3/include/CGAL_demo/Scene_item.h +++ b/Mesh_3/demo/Mesh_3/include/CGAL_demo/Scene_item.h @@ -6,6 +6,8 @@ #include #include #include +#include +#include namespace qglviewer { class ManipulatedFrame; @@ -30,18 +32,20 @@ public: color_(defaultColor), visible_(true), rendering_mode(FlatPlusEdges) - {}; + { + are_ogfunctions_initialized = false; + } virtual ~Scene_item(); virtual Scene_item* clone() const = 0; // Indicate if rendering mode is supported virtual bool supportsRenderingMode(RenderingMode m) const = 0; // Flat/Gouraud OpenGL drawing - virtual void draw() const = 0; + virtual void draw(QGLViewer *viewer) const = 0; // Wireframe OpenGL drawing - virtual void draw_edges() const { draw(); } + virtual void draw_edges(QGLViewer *viewer) const { draw(viewer); } // Points OpenGL drawing - virtual void draw_points() const { draw(); } + virtual void draw_points(QGLViewer *viewer) const { draw(viewer); } // Functions for displaying meta-data of the item virtual QString toolTip() const = 0; @@ -68,6 +72,7 @@ public Q_SLOTS: // Call that once you have finished changing something in the item // (either the properties or internal data) virtual void changed() {} + virtual void contextual_changed() {} // Setters for the four basic properties virtual void setColor(QColor c) { color_ = c; } @@ -84,6 +89,8 @@ Q_SIGNALS: void aboutToBeDestroyed(); protected: + mutable QOpenGLFunctions_3_3_Core gl; + mutable bool are_ogfunctions_initialized; // The four basic properties QString name_; QColor color_; diff --git a/Mesh_3/demo/Mesh_3/include/CGAL_demo/Scene_item_with_display_list.h b/Mesh_3/demo/Mesh_3/include/CGAL_demo/Scene_item_with_display_list.h index ef4a00b674d..39eed562c90 100644 --- a/Mesh_3/demo/Mesh_3/include/CGAL_demo/Scene_item_with_display_list.h +++ b/Mesh_3/demo/Mesh_3/include/CGAL_demo/Scene_item_with_display_list.h @@ -3,6 +3,7 @@ #include #include +#include // This class represents an object in the scene with an OpenGL rendering using display lists class SCENE_ITEM_EXPORT Scene_item_with_display_list @@ -14,19 +15,20 @@ public: ~Scene_item_with_display_list(); // Points/Wireframe/Flat/Gouraud OpenGL drawing in a display list - virtual void direct_draw() const = 0; - virtual void direct_draw_edges() const { draw(); }; + virtual void direct_draw(QGLViewer*) = 0; + virtual void direct_draw_edges(QGLViewer* viewer) { draw(viewer); } // OpenGL drawing using a display list - virtual void draw() const; - virtual void draw_edges() const; + virtual void draw(QGLViewer* viewer) ; + virtual void draw_edges(QGLViewer* viewer) ; public Q_SLOTS: + // Call that once you have finished changing something in the item // (either the properties or internal data). virtual void changed(); protected: enum { DRAW = 0, DRAW_EDGES = 1, NB_OF_DISPLAY_LISTS = 2}; - void draw(int) const; + void draw(QGLViewer* viewer,int) ; // display lists mutable GLuint display_list[NB_OF_DISPLAY_LISTS]; mutable bool display_list_built[NB_OF_DISPLAY_LISTS]; diff --git a/Mesh_3/demo/Mesh_3/include/CGAL_demo/Viewer.h b/Mesh_3/demo/Mesh_3/include/CGAL_demo/Viewer.h index 16f762f2049..3e590acd239 100644 --- a/Mesh_3/demo/Mesh_3/include/CGAL_demo/Viewer.h +++ b/Mesh_3/demo/Mesh_3/include/CGAL_demo/Viewer.h @@ -4,12 +4,13 @@ #include #include #include +#include // forward declarations class QWidget; class Scene_draw_interface; -class VIEWER_EXPORT Viewer : public QGLViewer { +class VIEWER_EXPORT Viewer : public QGLViewer, public QOpenGLFunctions_3_3_Core { Q_OBJECT diff --git a/Mesh_3/demo/Mesh_3/src/CGAL_demo/Plugin_helper.cpp b/Mesh_3/demo/Mesh_3/src/CGAL_demo/Plugin_helper.cpp index 8b9535be8f1..0417694bb04 100644 --- a/Mesh_3/demo/Mesh_3/src/CGAL_demo/Plugin_helper.cpp +++ b/Mesh_3/demo/Mesh_3/src/CGAL_demo/Plugin_helper.cpp @@ -54,8 +54,8 @@ void Plugin_helper::autoConnectActions() i < metaObject->methodCount(); ++i) { - const int pos = QString(metaObject->method(i).signature()).indexOf('('); - methodsNames << QString(metaObject->method(i).signature()).left(pos); + const int pos = QString(metaObject->method(i).methodSignature()).indexOf('('); + methodsNames << QString(metaObject->method(i).methodSignature()).left(pos); methods << metaObject->method(i); } @@ -72,24 +72,26 @@ void Plugin_helper::autoConnectActions() if(action_method.methodType() == QMetaMethod::Signal) { - const int pos = QString(action_method.signature()).indexOf('('); - QString methodName = QString(action_method.signature()).left(pos); + const int pos = QString(action_method.methodSignature()).indexOf('('); + QString methodName = QString(action_method.methodSignature()).left(pos); QString slotName = QString("on_%1_%2").arg(action->objectName()).arg(methodName); // qDebug() << thisObject->tr("Slot %1 (%2)...").arg(slotName).arg(i); int index = methodsNames.indexOf(slotName); - if(index>=0 && !connected.contains(slotName)) { + + if(index>=0 && !connected.contains(slotName)) + { const bool ok = QObject::connect(action, - qPrintable(QString("2%1").arg(action_method.signature())), + qPrintable(QString("2%1").arg(QString(action_method.methodSignature()))), thisObject, - qPrintable(QString("1%1").arg(methods[index].signature()))); + qPrintable(QString("1%1").arg(QString(methods[index].methodSignature())))); if(!ok) { qDebug() << thisObject->tr("Cannot connect method %1.%2 to slot %3!") .arg(action->objectName()) - .arg(action_method.signature()) - .arg(methods[index].signature()); + .arg(QString(action_method.methodSignature())) + .arg(QString(methods[index].methodSignature())); } else { // qDebug(" ->Connected!"); diff --git a/Mesh_3/demo/Mesh_3/src/CGAL_demo/Scene.cpp b/Mesh_3/demo/Mesh_3/src/CGAL_demo/Scene.cpp index d1f3c55ec62..c075ba28a9d 100644 --- a/Mesh_3/demo/Mesh_3/src/CGAL_demo/Scene.cpp +++ b/Mesh_3/demo/Mesh_3/src/CGAL_demo/Scene.cpp @@ -9,7 +9,7 @@ #include #include #include - +#include namespace { void CGALglcolor(QColor c) { @@ -32,9 +32,11 @@ Scene::addItem(Scene_item* item) connect(this, SIGNAL(itemAboutToBeDestroyed(Scene_item*)), item, SLOT(itemAboutToBeDestroyed(Scene_item*))); + QAbstractListModel::beginResetModel(); Q_EMIT updated_bbox(); Q_EMIT updated(); - QAbstractListModel::reset(); + QAbstractListModel::endResetModel(); + return entries.size() - 1; } @@ -45,13 +47,15 @@ Scene::erase(int index) return -1; Scene_item* item = entries[index]; + + QAbstractListModel::beginResetModel(); Q_EMIT itemAboutToBeDestroyed(item); delete item; entries.removeAt(index); selected_item = -1; Q_EMIT updated(); - QAbstractListModel::reset(); + QAbstractListModel::endResetModel(); if(--index >= 0) return index; @@ -106,24 +110,19 @@ void Scene::initializeGL() { } -// workaround for Qt-4.2. -#if QT_VERSION < 0x040300 -# define lighter light -#endif - void -Scene::draw() +Scene::draw(QGLViewer* viewer) { - draw_aux(false); + draw_aux(false, viewer); } void -Scene::drawWithNames() +Scene::drawWithNames(QGLViewer *viewer) { - draw_aux(true); + draw_aux(true,viewer); } void -Scene::draw_aux(bool with_names) +Scene::draw_aux(bool with_names, QGLViewer *viewer) { // Flat/Gouraud OpenGL drawing for(int index = 0; index < entries.size(); ++index) @@ -134,22 +133,21 @@ Scene::draw_aux(bool with_names) Scene_item& item = *entries[index]; if(item.visible()) { + item.contextual_changed(); if(item.renderingMode() == Flat || item.renderingMode() == FlatPlusEdges || item.renderingMode() == Gouraud) - { - ::glEnable(GL_LIGHTING); - ::glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); + { ::glPointSize(2.f); ::glLineWidth(1.0f); - if(index == selected_item) - CGALglcolor(item.color().lighter(120)); - else - CGALglcolor(item.color()); - if(item.renderingMode() == Gouraud) - ::glShadeModel(GL_SMOOTH); - else - ::glShadeModel(GL_FLAT); + if(index == selected_item) + CGALglcolor(item.color().lighter(120)); + else + CGALglcolor(item.color()); + if(item.renderingMode() == Gouraud) + ::glShadeModel(GL_SMOOTH); + else + ::glShadeModel(GL_FLAT); - item.draw(); + item.draw(viewer); } } if(with_names) { @@ -168,16 +166,15 @@ Scene::draw_aux(bool with_names) { if(item.renderingMode() == FlatPlusEdges || item.renderingMode() == Wireframe) { - ::glDisable(GL_LIGHTING); - ::glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); + ::glPointSize(2.f); ::glLineWidth(1.0f); if(index == selected_item) CGALglcolor(Qt::black); else CGALglcolor(item.color().lighter(50)); - - item.draw_edges(); + + item.draw_edges(viewer); } if(with_names) { ::glPopName(); @@ -196,8 +193,7 @@ Scene::draw_aux(bool with_names) { if(item.renderingMode() == Points) { - ::glDisable(GL_LIGHTING); - ::glPolygonMode(GL_FRONT_AND_BACK,GL_POINT); + ::glEnable(GL_POINT_SMOOTH); ::glPointSize(2.f); ::glLineWidth(1.0f); if(index == selected_item) @@ -205,7 +201,8 @@ Scene::draw_aux(bool with_names) else CGALglcolor(item.color().lighter(50)); - item.draw_points(); + item.draw_points(viewer); + ::glDisable(GL_POINT_SMOOTH); } if(with_names) { ::glPopName(); diff --git a/Mesh_3/demo/Mesh_3/src/CGAL_demo/Scene_item_with_display_list.cpp b/Mesh_3/demo/Mesh_3/src/CGAL_demo/Scene_item_with_display_list.cpp index 28ea8288ab3..7a5d03a11dd 100644 --- a/Mesh_3/demo/Mesh_3/src/CGAL_demo/Scene_item_with_display_list.cpp +++ b/Mesh_3/demo/Mesh_3/src/CGAL_demo/Scene_item_with_display_list.cpp @@ -27,15 +27,15 @@ Scene_item_with_display_list::~Scene_item_with_display_list() // Points/Wireframe/Flat/Gouraud OpenGL drawing in a display list -void Scene_item_with_display_list::draw() const { - draw(DRAW); +void Scene_item_with_display_list::draw(QGLViewer *viewer) { + draw(viewer, DRAW); } -void Scene_item_with_display_list::draw_edges() const { - draw(DRAW_EDGES); +void Scene_item_with_display_list::draw_edges(QGLViewer *viewer) { + draw(viewer, DRAW_EDGES); } -void Scene_item_with_display_list::draw(int i) const +void Scene_item_with_display_list::draw(QGLViewer *viewer, int i) { if(!display_list_built[i]) { @@ -50,10 +50,10 @@ void Scene_item_with_display_list::draw(int i) const // draw the item in a display list ::glNewList(display_list[i],GL_COMPILE_AND_EXECUTE); if(i == 0) { - direct_draw(); + direct_draw(viewer); } else { - direct_draw_edges(); + direct_draw_edges(viewer); } ::glEndList(); display_list_built[i] = true; @@ -69,4 +69,6 @@ void Scene_item_with_display_list::changed() for(int i = 0; i < NB_OF_DISPLAY_LISTS; ++i) { display_list_built[i] = false; } + + } diff --git a/Mesh_3/demo/Mesh_3/src/CGAL_demo/Viewer.cpp b/Mesh_3/demo/Mesh_3/src/CGAL_demo/Viewer.cpp index 027aa896f28..564ec702e70 100644 --- a/Mesh_3/demo/Mesh_3/src/CGAL_demo/Viewer.cpp +++ b/Mesh_3/demo/Mesh_3/src/CGAL_demo/Viewer.cpp @@ -1,15 +1,15 @@ #include #include +#include Viewer::Viewer(QWidget* parent, bool antialiasing) - : QGLViewer(parent), + : QGLViewer(CGAL::Qt::createOpenGLContext(), parent), scene(0), antialiasing(antialiasing), twosides(false), mask_(false), ratio_(1.) { - setBackgroundColor(::Qt::white); setMouseTracking(true); } @@ -46,6 +46,8 @@ void Viewer::initializeGL() { QGLViewer::initializeGL(); scene->initializeGL(); + initializeOpenGLFunctions(); + setBackgroundColor(::Qt::white); } void Viewer::draw_aux(bool with_names) @@ -82,9 +84,9 @@ void Viewer::draw_aux(bool with_names) ::glHint(GL_LINE_SMOOTH_HINT, GL_FASTEST); } if(with_names) - scene->drawWithNames(); + scene->drawWithNames(this); else - scene->draw(); + scene->draw(this); } void Viewer::drawWithNames() diff --git a/Mesh_3/examples/Mesh_3/CMakeLists.txt b/Mesh_3/examples/Mesh_3/CMakeLists.txt index 1938440b8d8..da5d7e073ce 100644 --- a/Mesh_3/examples/Mesh_3/CMakeLists.txt +++ b/Mesh_3/examples/Mesh_3/CMakeLists.txt @@ -4,12 +4,8 @@ project( Mesh_3_example ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) -endif() +cmake_minimum_required(VERSION 2.8.11) + include_directories(../../include) include_directories(../../../Triangulation_3/include) diff --git a/Mesh_3/test/Mesh_3/CMakeLists.txt b/Mesh_3/test/Mesh_3/CMakeLists.txt index ef893683917..7cf30f717fc 100644 --- a/Mesh_3/test/Mesh_3/CMakeLists.txt +++ b/Mesh_3/test/Mesh_3/CMakeLists.txt @@ -4,12 +4,8 @@ project( Mesh_3_test ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) -endif() +cmake_minimum_required(VERSION 2.8.11) + find_package(CGAL QUIET COMPONENTS ImageIO) diff --git a/Nef_2/demo/Nef_2/CMakeLists.txt b/Nef_2/demo/Nef_2/CMakeLists.txt index d4cabd58e03..5582e3d8f97 100644 --- a/Nef_2/demo/Nef_2/CMakeLists.txt +++ b/Nef_2/demo/Nef_2/CMakeLists.txt @@ -2,11 +2,9 @@ project( Nef_2 ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() find_package(CGAL COMPONENTS Qt3 ) @@ -14,7 +12,7 @@ include( ${CGAL_USE_FILE} ) find_package(Qt3-patched) # FindQt3-patched.cmake is FindQt3.cmake patched by CGAL developers, so -# that it can be used together with FindQt4: all its variables are prefixed +# that it can be used together with Qt5: all its variables are prefixed # by "QT3_" instead of "QT_". if ( CGAL_FOUND AND CGAL_Qt3_FOUND AND QT3_FOUND ) diff --git a/Nef_3/demo/Nef_3/CMakeLists.txt b/Nef_3/demo/Nef_3/CMakeLists.txt index 8dbb8576d2c..06312d95059 100644 --- a/Nef_3/demo/Nef_3/CMakeLists.txt +++ b/Nef_3/demo/Nef_3/CMakeLists.txt @@ -2,11 +2,9 @@ project (Nef_3_Demo) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() find_package(CGAL COMPONENTS Qt3) @@ -14,7 +12,7 @@ include(${CGAL_USE_FILE}) find_package(Qt3-patched ) # FindQt3-patched.cmake is FindQt3.cmake patched by CGAL developers, so -# that it can be used together with FindQt4: all its variables are prefixed +# that it can be used together with Qt5: all its variables are prefixed # by "QT3_" instead of "QT_". macro(create_single_source_cgal_qt3_program first ) diff --git a/Nef_S2/demo/Nef_S2/CMakeLists.txt b/Nef_S2/demo/Nef_S2/CMakeLists.txt index 32b3a4a41f8..99fd2a6b1cb 100644 --- a/Nef_S2/demo/Nef_S2/CMakeLists.txt +++ b/Nef_S2/demo/Nef_S2/CMakeLists.txt @@ -2,11 +2,9 @@ project( Nef_S2 ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() find_package(CGAL COMPONENTS Qt3 ) @@ -14,7 +12,7 @@ include( ${CGAL_USE_FILE} ) find_package(Qt3-patched) # FindQt3-patched.cmake is FindQt3.cmake patched by CGAL developers, so -# that it can be used together with FindQt4: all its variables are prefixed +# that it can be used together with Qt5: all its variables are prefixed # by "QT3_" instead of "QT_". if ( CGAL_FOUND AND CGAL_Qt3_FOUND AND QT3_FOUND ) diff --git a/NewKernel_d/test/NewKernel_d/CMakeLists.txt b/NewKernel_d/test/NewKernel_d/CMakeLists.txt index 7b03a381806..975538465b8 100644 --- a/NewKernel_d/test/NewKernel_d/CMakeLists.txt +++ b/NewKernel_d/test/NewKernel_d/CMakeLists.txt @@ -5,14 +5,8 @@ project( NewKernel_d_test ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 2.6) - if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) - else() - cmake_policy(VERSION 2.6) - endif() -endif() +cmake_minimum_required(VERSION 2.8.11) + find_package(CGAL QUIET) diff --git a/Number_types/test/Number_types/CMakeLists.txt b/Number_types/test/Number_types/CMakeLists.txt index a2a84d91a07..176889375d4 100644 --- a/Number_types/test/Number_types/CMakeLists.txt +++ b/Number_types/test/Number_types/CMakeLists.txt @@ -5,12 +5,8 @@ project( Number_types_test ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) -endif() +cmake_minimum_required(VERSION 2.8.11) + find_package( CGAL QUIET COMPONENTS Core ) diff --git a/Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/CMakeLists.txt b/Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/CMakeLists.txt index 30714dbb5bd..1b85f8b8d0f 100644 --- a/Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/CMakeLists.txt +++ b/Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/CMakeLists.txt @@ -1,48 +1,44 @@ + # Created by the script cgal_create_cmake_script # This is the CMake script for compiling a CGAL application. -project( Periodic_3_triangulation_3_demo ) +project( Periodic_3_triangulation_3_demo ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() # Find CGAL -find_package(CGAL) +find_package(CGAL COMPONENTS Qt5) include( ${CGAL_USE_FILE} ) -# Find Qt4 itself -set ( QT_USE_QTXML TRUE ) -set ( QT_USE_QTMAIN TRUE ) -set ( QT_USE_QTOPENGL TRUE ) -find_package(Qt4) +# Find Qt5 itself +find_package(Qt5 QUIET COMPONENTS Xml OpenGL Help Core) # Find OpenGL find_package(OpenGL) # Find QGLViewer -if(QT4_FOUND) +if(Qt5_FOUND) add_definitions(-DQT_NO_KEYWORDS) - include( ${QT_USE_FILE} ) find_package(QGLViewer) -endif(QT4_FOUND) +endif(Qt5_FOUND) -if (CGAL_FOUND AND OPENGL_FOUND AND QT4_FOUND AND QGLVIEWER_FOUND AND QT_QCOLLECTIONGENERATOR_EXECUTABLE) +if (CGAL_FOUND AND OPENGL_FOUND AND Qt5_FOUND AND QGLVIEWER_FOUND AND TARGET Qt5::qcollectiongenerator) include_directories( ${QGLVIEWER_INCLUDE_DIR} ) # UI files (Qt Designer files) - qt4_wrap_ui ( UI_FILES MainWindow.ui ) + qt5_wrap_ui ( UI_FILES MainWindow.ui ) # qrc files (resource files) - qt4_add_resources( RESOURCE_FILES ./Periodic_3_triangulation_3.qrc ) + qt5_add_resources( RESOURCE_FILES ./Periodic_3_triangulation_3.qrc ) # use the Qt MOC preprocessor on classes that derive from QObject - qt4_generate_moc( "Scene.h" "${CMAKE_CURRENT_BINARY_DIR}/moc_Scene.cpp" ) - qt4_generate_moc( "MainWindow.h" "${CMAKE_CURRENT_BINARY_DIR}/moc_MainWindow.cpp" ) + qt5_generate_moc( "Scene.h" "${CMAKE_CURRENT_BINARY_DIR}/moc_Scene.cpp" ) + qt5_generate_moc( "MainWindow.h" "${CMAKE_CURRENT_BINARY_DIR}/moc_MainWindow.cpp" ) + qt5_generate_moc( "Viewer.h" "${CMAKE_CURRENT_BINARY_DIR}/moc_Viewer.cpp" ) if(DEFINED QT_QCOLLECTIONGENERATOR_EXECUTABLE) else() @@ -52,7 +48,7 @@ if (CGAL_FOUND AND OPENGL_FOUND AND QT4_FOUND AND QGLVIEWER_FOUND AND QT_QCOLLEC # generate QtAssistant collection file add_custom_command ( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Periodic_3_triangulation_3.qhc DEPENDS Periodic_3_triangulation_3.qhp Periodic_3_triangulation_3.qhcp - COMMAND ${QT_QCOLLECTIONGENERATOR_EXECUTABLE} + COMMAND Qt5::qcollectiongenerator ${CMAKE_CURRENT_SOURCE_DIR}/Periodic_3_triangulation_3.qhcp -o ${CMAKE_CURRENT_BINARY_DIR}/Periodic_3_triangulation_3.qhc ) @@ -60,30 +56,33 @@ if (CGAL_FOUND AND OPENGL_FOUND AND QT4_FOUND AND QGLVIEWER_FOUND AND QT_QCOLLEC # Make sure the compiler can find generated .moc files include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR}) include_directories( ${QT_INCLUDE_DIR} ) - include_directories( ../../include ) + include_directories( ../../include .) # The executable itself add_executable ( periodic_3_triangulation_3_demo - Scene.cpp moc_Scene.cpp - periodic_3_triangulation_3_demo.cpp - MainWindow.ui moc_MainWindow.cpp - ${UI_FILES} ${RESOURCE_FILES} Periodic_3_triangulation_3.qhc) + Scene.cpp moc_Scene.cpp + Viewer.cpp moc_Viewer.cpp + periodic_3_triangulation_3_demo.cpp + MainWindow.ui moc_MainWindow.cpp + ${UI_FILES} ${RESOURCE_FILES} Periodic_3_triangulation_3.qhc) + + qt5_use_modules(periodic_3_triangulation_3_demo Xml Help OpenGL) add_to_cached_list( CGAL_EXECUTABLE_TARGETS periodic_3_triangulation_3_demo) # Link the executable to CGAL and third-party libraries target_link_libraries(periodic_3_triangulation_3_demo ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES} ${QT_LIBRARIES} ${QGLVIEWER_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} ) -else (CGAL_FOUND AND OPENGL_FOUND AND QT4_FOUND AND QGLVIEWER_FOUND AND QT_QCOLLECTIONGENERATOR_EXECUTABLE) +else () set(PERIODIC_TRIANGULATION_MISSING_DEPS "") if(NOT CGAL_FOUND) - set(PERIODIC_TRIANGULATION_MISSING_DEPS "the CGAL Qt4 library, ${PERIODIC_TRIANGULATION_MISSING_DEPS}") + set(PERIODIC_TRIANGULATION_MISSING_DEPS "the CGAL Qt5 library, ${PERIODIC_TRIANGULATION_MISSING_DEPS}") endif() - if(NOT QT4_FOUND) - set(PERIODIC_TRIANGULATION_MISSING_DEPS "Qt4, ${PERIODIC_TRIANGULATION_MISSING_DEPS}") + if(NOT Qt5_FOUND) + set(PERIODIC_TRIANGULATION_MISSING_DEPS "Qt5, ${PERIODIC_TRIANGULATION_MISSING_DEPS}") endif() if(NOT OPENGL_FOUND) @@ -94,10 +93,10 @@ else (CGAL_FOUND AND OPENGL_FOUND AND QT4_FOUND AND QGLVIEWER_FOUND AND QT_QCOLL set(PERIODIC_TRIANGULATION_MISSING_DEPS "QGLViewer, ${PERIODIC_TRIANGULATION_MISSING_DEPS}") endif() - if (NOT QT_QCOLLECTIONGENERATOR_EXECUTABLE) + if (NOT TARGET Qt5::qcollectiongenerator) set(PERIODIC_TRIANGULATION_MISSING_DEPS "qcollectiongenerator, ${PERIODIC_TRIANGULATION_MISSING_DEPS}") endif() message(STATUS "NOTICE: This demo requires ${PERIODIC_TRIANGULATION_MISSING_DEPS}and will not be compiled.") -endif (CGAL_FOUND AND OPENGL_FOUND AND QT4_FOUND AND QGLVIEWER_FOUND AND QT_QCOLLECTIONGENERATOR_EXECUTABLE) +endif () diff --git a/Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/MainWindow.h b/Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/MainWindow.h index e990deb3e60..eb40c51f6c2 100644 --- a/Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/MainWindow.h +++ b/Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/MainWindow.h @@ -6,6 +6,9 @@ #include #include +#include + + class MainWindow : public QMainWindow { diff --git a/Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/MainWindow.ui b/Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/MainWindow.ui index 598f9d502f9..9dd9403ec49 100644 --- a/Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/MainWindow.ui +++ b/Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/MainWindow.ui @@ -1,7 +1,8 @@ - + + MainWindow - - + + 0 0 @@ -9,21 +10,21 @@ 750 - - + + 0 0 - + CGAL Periodic Delaunay Triangulation - - + + - - - + + + 0 0 @@ -32,562 +33,562 @@ - - + + 0 0 962 - 22 + 20 - - + + &File - - - + + + - - + + &Options - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - + + &Initialization - - - - - + + + + + - - + + &Features - - + + - - + + &Actions - - - - - - - + + + + + + + - - + + Help - - - - + + + + - - - - - - + + + + + + - - - + + + toolBar - + TopToolBarArea - + false - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + :/cgal/Periodic_3_triangulation_3/icons/fileOpen.png:/cgal/Periodic_3_triangulation_3/icons/fileOpen.png - + Load Points - + Ctrl+O - - + + Exit - + Ctrl+Q - - + + true - - + + :/cgal/Periodic_3_triangulation_3/icons/wireframe.png :/cgal/Periodic_3_triangulation_3/icons/wireframeOff.png:/cgal/Periodic_3_triangulation_3/icons/wireframe.png - + Wireframe - + Switches wireframe rendering on and off - + X - - + + true - - + + :/cgal/Periodic_3_triangulation_3/icons/planar.png:/cgal/Periodic_3_triangulation_3/icons/planar.png - + Planar triangulation - + Shows only simplices for which z=0 everywhere - + Z - - + + true - + true - - + + :/cgal/Periodic_3_triangulation_3/icons/cover1.png :/cgal/Periodic_3_triangulation_3/icons/cover27.png:/cgal/Periodic_3_triangulation_3/icons/cover1.png - + Draw 1-sheeted covering - + toggles between displaying only one periodic copy of each simplex and the internal representation - + 1 - - + + true - + true - - + + :/cgal/Periodic_3_triangulation_3/icons/multiple.png :/cgal/Periodic_3_triangulation_3/icons/multipleOff.png:/cgal/Periodic_3_triangulation_3/icons/multiple.png - + Draw bordering cells multiply - + Draws each simplex for which the intersection with the fundamental cube is non-empty - + M - - + + true - - + + :/cgal/Periodic_3_triangulation_3/icons/clipping.png :/cgal/Periodic_3_triangulation_3/icons/clippingOff.png:/cgal/Periodic_3_triangulation_3/icons/clipping.png - + Clip along the cube/square - - + + true - + false - - + + :/cgal/Periodic_3_triangulation_3/icons/twoColorClipping.png:/cgal/Periodic_3_triangulation_3/icons/twoColorClipping.png - + 2-color clipping - + show the clipped part of all clipped edges in a different color - - - + + + :/cgal/Periodic_3_triangulation_3/icons/initGrid.png:/cgal/Periodic_3_triangulation_3/icons/initGrid.png - + Point grid - + pg - + A grid of 36 points that can be triangulated in 1-sheeted covering space - + F5 - - - + + + :/cgal/Periodic_3_triangulation_3/icons/init1.png:/cgal/Periodic_3_triangulation_3/icons/init1.png - + Single point - + F2 - - - + + + :/cgal/Periodic_3_triangulation_3/icons/initRandPlanar.png:/cgal/Periodic_3_triangulation_3/icons/initRandPlanar.png - + Random planar point set - + Initial triangulation of 10 points chosen at random with z=0 - + F4 - - - + + + :/cgal/Periodic_3_triangulation_3/icons/initRand.png:/cgal/Periodic_3_triangulation_3/icons/initRand.png - + Random point set - + Initial triangulation of 30 points chosen at random - + F3 - - - + + + :/cgal/Periodic_3_triangulation_3/icons/init0.png:/cgal/Periodic_3_triangulation_3/icons/init0.png - + Empty scene - + F1 - - + + true - + true - + Draw domain (cube/square) - + D - - + + true - - + + :/cgal/Periodic_3_triangulation_3/icons/locate.png:/cgal/Periodic_3_triangulation_3/icons/locate.png - + Point location - + Marks the tetrahedron that currently contains the flying ball - + L - - + + true - - + + :/cgal/Periodic_3_triangulation_3/icons/conflict.png:/cgal/Periodic_3_triangulation_3/icons/conflict.png - + Conflict region - + Shows all tetrahedra in whose circumcircle the flying ball is contained - + C - - + + true - + Hole* - + H - - + + true - + Star* - + S - - + + true - - + + :/cgal/Periodic_3_triangulation_3/icons/ball.png:/cgal/Periodic_3_triangulation_3/icons/ball.png - + Flying ball - + Shows a ball flying through the cube, showing the periodicity - + B - - + + true - - + + :/cgal/Periodic_3_triangulation_3/icons/pause.png :/cgal/Periodic_3_triangulation_3/icons/play.png:/cgal/Periodic_3_triangulation_3/icons/pause.png - + Pause - + Pauses the flying ball - + P - - - + + + :/cgal/Periodic_3_triangulation_3/icons/inputPointBall.png:/cgal/Periodic_3_triangulation_3/icons/inputPointBall.png - + Insert point - + Insert point at the position of the flying ball (whether it is shown or not) - + I - - - + + + :/cgal/Periodic_3_triangulation_3/icons/inputPointRandom.png:/cgal/Periodic_3_triangulation_3/icons/inputPointRandom.png - + Insert random point - + Insert one point at random position (within the cube) - + R - - + + true - + false - + Draw segments - + 2 - - + + true - + Draw triangles - + 3 - - + + true - + true - + Draw tetrahedra - + 4 - - + + false - - + + :/cgal/Periodic_3_triangulation_3/icons/camera.png:/cgal/Periodic_3_triangulation_3/icons/camera.png - + Grab image - + G - - + + Export pov - + Ctrl+E - - + + Demo Manual - + H - - + + About - + A - - + + About CGAL - + - QGLViewer + Viewer QWidget -
QGLViewer/qglviewer.h
+
Viewer.h
- + @@ -596,11 +597,11 @@ action2_color_clipping setEnabled(bool) - + -1 -1 - + -1 -1 diff --git a/Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/Scene.cpp b/Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/Scene.cpp index 67dd01d6f7a..e922b37f0f3 100644 --- a/Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/Scene.cpp +++ b/Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/Scene.cpp @@ -1,605 +1,1268 @@ #include "Scene.h" + +void Scene::compile_shaders() +{ + + if(! buffers[0].create() || !buffers[1].create() || !buffers[2].create() || !buffers[3].create() + || !buffers[4].create() || !buffers[5].create() || !buffers[6].create() + || !buffers[7].create() || !buffers[8].create() || !buffers[9].create() + || !buffers[10].create() || !buffers[11].create() || !buffers[12].create() + || !buffers[13].create() || !buffers[14].create() || !buffers[15].create() + || !buffers[16].create() || !buffers[17].create() || !buffers[18].create() + || !buffers[19].create() || !buffers[20].create() + || !buffers[21].create() || !buffers[22].create() || !buffers[23].create()) + { + std::cerr<<"VBO Creation FAILED"<compileSourceCode(vertex_source)) + { + std::cerr<<"Compiling vertex source FAILED"<compileSourceCode(fragment_source)) + { + std::cerr<<"Compiling fragmentsource FAILED"<compileSourceCode(vertex_source_spheres)) + { + std::cerr<<"Compiling vertex source FAILED"<compileSourceCode(fragment_source_spheres)) + { + std::cerr<<"Compiling fragmentsource FAILED"<compileSourceCode(vertex_source_cylinders)) + { + std::cerr<<"Compiling vertex source FAILED"<first.z()!=0 && in_plane) + { + continue; + } + pos_points.push_back(pit->first.x());pos_points.push_back(pit->first.y());pos_points.push_back(pit->first.z()); + } + + } + + // Draw segments + { + Segment_set segments_to_draw; + primitives_from_geom_it(segments_to_draw); + if (cube_clipping && !two_color_clipping) segment_clipping(segments_to_draw); + pos_tube.resize(0); + + for (Segment_set::iterator it = segments_to_draw.begin() ; + it != segments_to_draw.end(); it++) + { + Point p1 = it->source(), p2 = it->target(); + if (in_plane && (p1.z()!=0. || p2.z()!=0.)) continue; + pos_tube.push_back(p1.x()); pos_tube.push_back(p1.y()); pos_tube.push_back(p1.z()); + pos_tube.push_back(p2.x()); pos_tube.push_back(p2.y()); pos_tube.push_back(p2.z()); + + Point p = p1; + Vector v = p2-p1; + + FT len = (FT)std::sqrt(CGAL_NTS to_double(v*v)); + + // normalize + v = v / len; + double angle = 0.0; + if(std::sqrt(CGAL_NTS to_double(v.x()*v.x()+v.y()*v.y())) > 1) + angle = 90.0f; + else + angle =acos(v.y()/std::sqrt(v.x()*v.x()+v.y()*v.y()+v.z()*v.z()))*180.0/M_PI;//asin(std::sqrt(CGAL_NTS to_double(v.x()*v.x()+v.y()*v.y())))/M_PI*180.0; + + Vector axis; + axis = Vector(v.z(), 0, -v.x()); + + + QMatrix4x4 matrix; + matrix.setToIdentity(); + + matrix.translate(CGAL_NTS to_double(p.x()), + CGAL_NTS to_double(p.y()), + CGAL_NTS to_double(p.z())); + + matrix.rotate(angle,CGAL_NTS to_double(axis.x()), + CGAL_NTS to_double(axis.y()), + CGAL_NTS to_double(axis.z())); + matrix.scale(1,CGAL_NTS to_double(len),1); + + for(int i=0; i<4; i++) + transfo1_cylinder.push_back((float)matrix.data()[i]); + for(int i=4; i<8; i++) + transfo2_cylinder.push_back((float)matrix.data()[i]); + for(int i=8; i<12; i++) + transfo3_cylinder.push_back((float)matrix.data()[i]); + for(int i=12; i<16; i++) + transfo4_cylinder.push_back((float)matrix.data()[i]); + + } + } + // Draw cube + { + + QMatrix4x4 matrix; + matrix.setToIdentity(); + + for (float x=0.0; x<2.0; x+=1.0) { + for (float y=0.0; y<2.0; y+=1.0) { + matrix.translate(x,0,y); + // matrix = matrix.transposed(); + for(int i=0; i<4; i++) + transfo1_cube.push_back((float)matrix.data()[i]); + for(int i=4; i<8; i++) + transfo2_cube.push_back((float)matrix.data()[i]); + for(int i=8; i<12; i++) + transfo3_cube.push_back((float)matrix.data()[i]); + for(int i=12; i<16; i++) + transfo4_cube.push_back((float)matrix.data()[i]); + matrix.translate(-x,0,-y); + } + } + + for (float x=0.0; x<2.0; x+=1.0) { + for (float y=0.0; y<2.0; y+=1.0) { + matrix.translate(x,y,0); + matrix.rotate(90,1.0,0.0,0.0); + for(int i=0; i<4; i++) + transfo1_cube.push_back((float)matrix.data()[i]); + for(int i=4; i<8; i++) + transfo2_cube.push_back((float)matrix.data()[i]); + for(int i=8; i<12; i++) + transfo3_cube.push_back((float)matrix.data()[i]); + for(int i=12; i<16; i++) + transfo4_cube.push_back((float)matrix.data()[i]); + matrix.rotate(90,-1.0,0.0,0.0); + matrix.translate(-x,-y,0); + } + } + + for (float x=0.0; x<2.0; x+=1.0) { + for (float y=0.0; y<2.0; y+=1.0) { + matrix.translate(0.0,x,y); + matrix.rotate(90,0.0,0.0,-1.0); + for(int i=0; i<4; i++) + transfo1_cube.push_back((float)matrix.data()[i]); + for(int i=4; i<8; i++) + transfo2_cube.push_back((float)matrix.data()[i]); + for(int i=8; i<12; i++) + transfo3_cube.push_back((float)matrix.data()[i]); + for(int i=12; i<16; i++) + transfo4_cube.push_back((float)matrix.data()[i]); + matrix.rotate(90,0.0,0.0,1.0); + matrix.translate(0.0,-x,-y); + } + } + + + pos_cube.resize(24*3); + + pos_cube[0]=0.0; pos_cube[3]=1.0; pos_cube[6]=0.0; pos_cube[9]= 1.0; + pos_cube[1]=0.0; pos_cube[4]=0.0; pos_cube[7]=1.0; pos_cube[10]=1.0; + pos_cube[2]=0.0; pos_cube[5]=0.0; pos_cube[8]=0.0; pos_cube[11]=0.0; + + pos_cube[12]=0.0; pos_cube[15]=1.0; pos_cube[18]=0.0; pos_cube[21]=1.0; + pos_cube[13]=0.0; pos_cube[16]=0.0; pos_cube[19]=1.0; pos_cube[22]=1.0; + pos_cube[14]=1.0; pos_cube[17]=1.0; pos_cube[20]=1.0; pos_cube[23]=1.0; + + pos_cube[24]=0.0; pos_cube[27]=0.0; pos_cube[30]=1.0; pos_cube[33]=1.0; + pos_cube[25]=0.0; pos_cube[28]=1.0; pos_cube[31]=0.0; pos_cube[34]=1.0; + pos_cube[26]=0.0; pos_cube[29]=0.0; pos_cube[32]=0.0; pos_cube[35]=0.0; + + pos_cube[36]=0.0; pos_cube[39]=0.0; pos_cube[42]=1.0; pos_cube[45]=1.0; + pos_cube[37]=0.0; pos_cube[40]=1.0; pos_cube[43]=0.0; pos_cube[46]=1.0; + pos_cube[38]=1.0; pos_cube[41]=1.0; pos_cube[44]=1.0; pos_cube[47]=1.0; + + pos_cube[48]=0.0; pos_cube[51]=0.0; pos_cube[54]=1.0; pos_cube[57]=1.0; + pos_cube[49]=0.0; pos_cube[52]=0.0; pos_cube[55]=0.0; pos_cube[58]=0.0; + pos_cube[50]=0.0; pos_cube[53]=1.0; pos_cube[56]=0.0; pos_cube[59]=1.0; + + pos_cube[60]=0.0; pos_cube[63]=0.0; pos_cube[66]=1.0; pos_cube[69]=1.0; + pos_cube[61]=1.0; pos_cube[64]=1.0; pos_cube[67]=1.0; pos_cube[70]=1.0; + pos_cube[62]=0.0; pos_cube[65]=1.0; pos_cube[68]=0.0; pos_cube[71]=1.0; + } + //Draw square + { + pos_square.resize(24); + pos_square[0]=0.0; pos_square[3]=1.0; pos_square[6]=0.0; pos_square[9]=1.0; + pos_square[1]=0.0; pos_square[4]=0.0; pos_square[7]=1.0; pos_square[10]=1.0; + pos_square[2]=0.0; pos_square[5]=0.0; pos_square[8]=0.0; pos_square[11]=0.0; + + pos_square[12]=0.0; pos_square[15]=0.0; pos_square[18]=1.0; pos_square[21]=1.0; + pos_square[13]=0.0; pos_square[16]=1.0; pos_square[19]=0.0; pos_square[22]=1.0; + pos_square[14]=0.0; pos_square[17]=0.0; pos_square[20]=0.0; pos_square[23]=0.0; + + QMatrix4x4 matrix; + matrix.setToIdentity(); + + for (float x=0.0; x<2.0; x+=1.0) { + + matrix.translate(x,0,0); + for(int i=0; i<4; i++) + transfo1_square.push_back((float)matrix.data()[i]); + for(int i=4; i<8; i++) + transfo2_square.push_back((float)matrix.data()[i]); + for(int i=8; i<12; i++) + transfo3_square.push_back((float)matrix.data()[i]); + for(int i=12; i<16; i++) + transfo4_square.push_back((float)matrix.data()[i]); + matrix.translate(-x,0,0); + } + + for (float y=0.0; y<2.0; y+=1.0) { + + matrix.translate(0,y,0); + matrix.rotate(90,0,0,-1); + for(int i=0; i<4; i++) + transfo1_square.push_back((float)matrix.data()[i]); + for(int i=4; i<8; i++) + transfo2_square.push_back((float)matrix.data()[i]); + for(int i=8; i<12; i++) + transfo3_square.push_back((float)matrix.data()[i]); + for(int i=12; i<16; i++) + transfo4_square.push_back((float)matrix.data()[i]); + matrix.rotate(90,0,0,1); + matrix.translate(0,-y,0); + } + + + + } +} + +void Scene::initialize_buffers() +{ + rendering_program.bind(); + + vao[0].bind(); + buffers[0].bind(); + buffers[0].allocate(pos_points.data(), static_cast(pos_points.size()*sizeof(float))); + poly_vertexLocation[0] = rendering_program.attributeLocation("vertex"); + rendering_program.enableAttributeArray(poly_vertexLocation[0]); + rendering_program.setAttributeBuffer(poly_vertexLocation[0],GL_FLOAT,0,3); + buffers[0].release(); + + vao[0].release(); + + vao[1].bind(); + buffers[1].bind(); + buffers[1].allocate(pos_tube.data(), static_cast(pos_tube.size()*sizeof(float))); + poly_vertexLocation[0] = rendering_program.attributeLocation("vertex"); + rendering_program.enableAttributeArray(poly_vertexLocation[0]); + rendering_program.setAttributeBuffer(poly_vertexLocation[0],GL_FLOAT,0,3); + buffers[1].release(); + vao[1].release(); + + vao[11].bind(); + buffers[23].bind(); + buffers[23].allocate(pos_square.data(), static_cast(pos_square.size()*sizeof(float))); + poly_vertexLocation[0] = rendering_program.attributeLocation("vertex"); + rendering_program.enableAttributeArray(poly_vertexLocation[0]); + rendering_program.setAttributeBuffer(poly_vertexLocation[0],GL_FLOAT,0,3); + buffers[23].release(); + vao[11].release(); + + vao[2].bind(); + buffers[2].bind(); + buffers[2].allocate(pos_cube.data(), static_cast(pos_cube.size()*sizeof(float))); + poly_vertexLocation[0] = rendering_program.attributeLocation("vertex"); + rendering_program.enableAttributeArray(poly_vertexLocation[0]); + rendering_program.setAttributeBuffer(poly_vertexLocation[0],GL_FLOAT,0,3); + buffers[2].release(); + vao[2].release(); + + rendering_program.release(); + + rendering_program_spheres.bind(); + + vao[3].bind(); + buffers[3].bind(); + buffers[3].allocate(points_spheres.data(), static_cast(points_spheres.size()*sizeof(float))); + poly_vertexLocation[1] = rendering_program_spheres.attributeLocation("vertex"); + rendering_program_spheres.enableAttributeArray(poly_vertexLocation[1]); + rendering_program_spheres.setAttributeBuffer(poly_vertexLocation[1],GL_FLOAT,0,3); + buffers[3].release(); + + buffers[4].bind(); + buffers[4].allocate(normals_spheres.data(), static_cast(normals_spheres.size()*sizeof(float))); + rendering_program_spheres.bind(); + normalsLocation[0] = rendering_program_spheres.attributeLocation("normal"); + rendering_program_spheres.enableAttributeArray(normalsLocation[0]); + rendering_program_spheres.setAttributeBuffer(normalsLocation[0],GL_FLOAT,0,3); + buffers[4].release(); + + + buffers[0].bind(); + rendering_program_spheres.bind(); + centerLocation[0] = rendering_program_spheres.attributeLocation("center"); + rendering_program_spheres.enableAttributeArray(centerLocation[0]); + rendering_program_spheres.setAttributeBuffer(centerLocation[0],GL_FLOAT,0,3); + buffers[0].release(); + glVertexAttribDivisor(centerLocation[0],1); + glVertexAttribDivisor(normalsLocation[0],0); + vao[3].release(); + rendering_program_spheres.release(); + + rendering_program_cylinders.bind(); + vao[8].bind(); + buffers[8].bind(); + buffers[8].allocate(points_cube->data(), static_cast(points_cube->size()*sizeof(float))); + poly_vertexLocation[2] = rendering_program_cylinders.attributeLocation("vertex"); + rendering_program_cylinders.enableAttributeArray(poly_vertexLocation[2]); + rendering_program_cylinders.setAttributeBuffer(poly_vertexLocation[2],GL_FLOAT,0,3); + buffers[8].release(); + + buffers[9].bind(); + buffers[9].allocate(normals_cylinder->data(), static_cast(normals_cylinder->size()*sizeof(float))); + normalsLocation[1] = rendering_program_cylinders.attributeLocation("normal"); + rendering_program_cylinders.enableAttributeArray(normalsLocation[1]); + rendering_program_cylinders.setAttributeBuffer(normalsLocation[1],GL_FLOAT,0,3); + buffers[9].release(); + + buffers[10].bind(); + buffers[10].allocate(transfo1_cube.data(), static_cast(transfo1_cube.size()*sizeof(float))); + centerLocation[1] = rendering_program_cylinders.attributeLocation("transfo1"); + rendering_program_cylinders.enableAttributeArray(centerLocation[1]); + rendering_program_cylinders.setAttributeBuffer(centerLocation[1],GL_FLOAT,0,4); + buffers[10].release(); + + buffers[11].bind(); + buffers[11].allocate(transfo2_cube.data(), static_cast(transfo2_cube.size()*sizeof(float))); + centerLocation[2] = rendering_program_cylinders.attributeLocation("transfo2"); + rendering_program_cylinders.enableAttributeArray(centerLocation[2]); + rendering_program_cylinders.setAttributeBuffer(centerLocation[2],GL_FLOAT,0,4); + buffers[11].release(); + + + buffers[12].bind(); + buffers[12].allocate(transfo3_cube.data(), static_cast(transfo3_cube.size()*sizeof(float))); + centerLocation[3] = rendering_program_cylinders.attributeLocation("transfo3"); + rendering_program_cylinders.enableAttributeArray(centerLocation[3]); + rendering_program_cylinders.setAttributeBuffer(centerLocation[3],GL_FLOAT,0,4); + buffers[12].release(); + + buffers[13].bind(); + buffers[13].allocate(transfo4_cube.data(), static_cast(transfo4_cube.size()*sizeof(float))); + centerLocation[4] = rendering_program_cylinders.attributeLocation("transfo4"); + rendering_program_cylinders.enableAttributeArray(centerLocation[4]); + rendering_program_cylinders.setAttributeBuffer(centerLocation[4],GL_FLOAT,0,4); + buffers[13].release(); + + + glVertexAttribDivisor(centerLocation[1],1); + glVertexAttribDivisor(centerLocation[2],1); + glVertexAttribDivisor(centerLocation[3],1); + glVertexAttribDivisor(centerLocation[4],1); + + glVertexAttribDivisor(normalsLocation[1],0); + + vao[8].release(); + vao[9].bind(); + buffers[14].bind(); + buffers[14].allocate(points_cylinder->data(), static_cast(points_cylinder->size()*sizeof(float))); + poly_vertexLocation[2] = rendering_program_cylinders.attributeLocation("vertex"); + rendering_program_cylinders.enableAttributeArray(poly_vertexLocation[2]); + rendering_program_cylinders.setAttributeBuffer(poly_vertexLocation[2],GL_FLOAT,0,3); + buffers[14].release(); + + buffers[9].bind(); + normalsLocation[1] = rendering_program_cylinders.attributeLocation("normal"); + rendering_program_cylinders.enableAttributeArray(normalsLocation[1]); + rendering_program_cylinders.setAttributeBuffer(normalsLocation[1],GL_FLOAT,0,3); + buffers[9].release(); + + buffers[15].bind(); + buffers[15].allocate(transfo1_cylinder.data(), static_cast(transfo1_cylinder.size()*sizeof(float))); + centerLocation[1] = rendering_program_cylinders.attributeLocation("transfo1"); + rendering_program_cylinders.enableAttributeArray(centerLocation[1]); + rendering_program_cylinders.setAttributeBuffer(centerLocation[1],GL_FLOAT,0,4); + buffers[15].release(); + + buffers[16].bind(); + buffers[16].allocate(transfo2_cylinder.data(), static_cast(transfo2_cylinder.size()*sizeof(float))); + centerLocation[2] = rendering_program_cylinders.attributeLocation("transfo2"); + rendering_program_cylinders.enableAttributeArray(centerLocation[2]); + rendering_program_cylinders.setAttributeBuffer(centerLocation[2],GL_FLOAT,0,4); + buffers[16].release(); + + + buffers[17].bind(); + buffers[17].allocate(transfo3_cylinder.data(), static_cast(transfo3_cylinder.size()*sizeof(float))); + centerLocation[3] = rendering_program_cylinders.attributeLocation("transfo3"); + rendering_program_cylinders.enableAttributeArray(centerLocation[3]); + rendering_program_cylinders.setAttributeBuffer(centerLocation[3],GL_FLOAT,0,4); + buffers[17].release(); + + buffers[18].bind(); + buffers[18].allocate(transfo4_cylinder.data(), static_cast(transfo4_cylinder.size()*sizeof(float))); + centerLocation[4] = rendering_program_cylinders.attributeLocation("transfo4"); + rendering_program_cylinders.enableAttributeArray(centerLocation[4]); + rendering_program_cylinders.setAttributeBuffer(centerLocation[4],GL_FLOAT,0,4); + buffers[18].release(); + + + glVertexAttribDivisor(centerLocation[1],1); + glVertexAttribDivisor(centerLocation[2],1); + glVertexAttribDivisor(centerLocation[3],1); + glVertexAttribDivisor(centerLocation[4],1); + + glVertexAttribDivisor(normalsLocation[1],0); + + vao[9].release(); + + vao[10].bind(); + buffers[8].bind(); + poly_vertexLocation[2] = rendering_program_cylinders.attributeLocation("vertex"); + rendering_program_cylinders.enableAttributeArray(poly_vertexLocation[2]); + rendering_program_cylinders.setAttributeBuffer(poly_vertexLocation[2],GL_FLOAT,0,3); + buffers[8].release(); + + buffers[9].bind(); + normalsLocation[1] = rendering_program_cylinders.attributeLocation("normal"); + rendering_program_cylinders.enableAttributeArray(normalsLocation[1]); + rendering_program_cylinders.setAttributeBuffer(normalsLocation[1],GL_FLOAT,0,3); + buffers[9].release(); + + buffers[19].bind(); + buffers[19].allocate(transfo1_square.data(), static_cast(transfo1_square.size()*sizeof(float))); + centerLocation[1] = rendering_program_cylinders.attributeLocation("transfo1"); + rendering_program_cylinders.enableAttributeArray(centerLocation[1]); + rendering_program_cylinders.setAttributeBuffer(centerLocation[1],GL_FLOAT,0,4); + buffers[19].release(); + + buffers[20].bind(); + buffers[20].allocate(transfo2_square.data(), static_cast(transfo2_square.size()*sizeof(float))); + centerLocation[2] = rendering_program_cylinders.attributeLocation("transfo2"); + rendering_program_cylinders.enableAttributeArray(centerLocation[2]); + rendering_program_cylinders.setAttributeBuffer(centerLocation[2],GL_FLOAT,0,4); + buffers[20].release(); + + + buffers[21].bind(); + buffers[21].allocate(transfo3_square.data(), static_cast(transfo3_square.size()*sizeof(float))); + centerLocation[3] = rendering_program_cylinders.attributeLocation("transfo3"); + rendering_program_cylinders.enableAttributeArray(centerLocation[3]); + rendering_program_cylinders.setAttributeBuffer(centerLocation[3],GL_FLOAT,0,4); + buffers[21].release(); + + buffers[22].bind(); + buffers[22].allocate(transfo4_square.data(), static_cast(transfo4_square.size()*sizeof(float))); + centerLocation[4] = rendering_program_cylinders.attributeLocation("transfo4"); + rendering_program_cylinders.enableAttributeArray(centerLocation[4]); + rendering_program_cylinders.setAttributeBuffer(centerLocation[4],GL_FLOAT,0,4); + buffers[22].release(); + + + glVertexAttribDivisor(centerLocation[1],1); + glVertexAttribDivisor(centerLocation[2],1); + glVertexAttribDivisor(centerLocation[3],1); + glVertexAttribDivisor(centerLocation[4],1); + + glVertexAttribDivisor(normalsLocation[1],0); + + vao[10].release(); + + rendering_program_cylinders.release(); + are_buffers_initialized = true; + +} + +void Scene::attrib_buffers(QGLViewer* viewer) +{ + QMatrix4x4 mvpMatrix; + QMatrix4x4 mvMatrix; + double mat[16]; + viewer->camera()->getModelViewProjectionMatrix(mat); + for(int i=0; i < 16; i++) + { + mvpMatrix.data()[i] = (float)mat[i]; + } + viewer->camera()->getModelViewMatrix(mat); + for(int i=0; i < 16; i++) + { + mvMatrix.data()[i] = (float)mat[i]; + } + QVector4D position(0.0f,0.0f,1.0f,1.0f ); + + + rendering_program.bind(); + mvpLocation[0] = rendering_program.uniformLocation("mvp_matrix"); + colorLocation[0] = rendering_program.uniformLocation("color"); + rendering_program.setUniformValue(mvpLocation[0], mvpMatrix); + + rendering_program.release(); + + + rendering_program_spheres.bind(); + mvpLocation[1] = rendering_program_spheres.uniformLocation("mvp_matrix"); + mvLocation[0] = rendering_program_spheres.uniformLocation("mv_matrix"); + lightLocation[0] = rendering_program_spheres.uniformLocation("light_pos"); + lightLocation[1] = rendering_program_spheres.uniformLocation("light_diff"); + lightLocation[2] = rendering_program_spheres.uniformLocation("light_spec"); + lightLocation[3] = rendering_program_spheres.uniformLocation("light_amb"); + lightLocation[4] = rendering_program_spheres.uniformLocation("spec_power"); + + rendering_program_spheres.setUniformValue(lightLocation[0], position); + rendering_program_spheres.setUniformValue(mvpLocation[1], mvpMatrix); + rendering_program_spheres.setUniformValue(mvLocation[0], mvMatrix); + rendering_program_spheres.setUniformValue(lightLocation[1], diffuse); + rendering_program_spheres.setUniformValue(lightLocation[2], specular); + rendering_program_spheres.setUniformValue(lightLocation[3], ambient); + rendering_program_spheres.setUniformValue(lightLocation[4], shininess); + + rendering_program_spheres.release(); + + rendering_program_cylinders.bind(); + mvpLocation[2] = rendering_program_cylinders.uniformLocation("mvp_matrix"); + mvLocation[1] = rendering_program_cylinders.uniformLocation("mv_matrix"); + lightLocation[5] = rendering_program_cylinders.uniformLocation("light_pos"); + lightLocation[6] = rendering_program_cylinders.uniformLocation("light_diff"); + lightLocation[7] = rendering_program_cylinders.uniformLocation("light_spec"); + lightLocation[8] = rendering_program_cylinders.uniformLocation("light_amb"); + lightLocation[9] = rendering_program_cylinders.uniformLocation("spec_power"); + + rendering_program_cylinders.setUniformValue(lightLocation[5], position); + rendering_program_cylinders.setUniformValue(lightLocation[6], diffuse); + rendering_program_cylinders.setUniformValue(lightLocation[7], specular); + rendering_program_cylinders.setUniformValue(lightLocation[8], ambient); + rendering_program_cylinders.setUniformValue(lightLocation[9], shininess); + rendering_program_cylinders.setUniformValue(mvpLocation[2], mvpMatrix); + rendering_program_cylinders.setUniformValue(mvLocation[1], mvMatrix); + + + rendering_program_cylinders.release(); +} + void Scene::init() { - // undo from QGLViewer internal initializeGL function - glDisable(GL_COLOR_MATERIAL); + // undo from QGLViewer internal initializeGL function + // glDisable(GL_COLOR_MATERIAL); + initializeOpenGLFunctions(); + // camera + // only 2.7 gets an 'f' as VC++ warns if we don't + ui->viewer->camera()->setPosition(Vec(0.5,0.5,2.7f)); + ui->viewer->camera()->lookAt(Vec(0.5,0.5,0.5)); - // camera - // only 2.7 gets an 'f' as VC++ warns if we don't - ui->viewer->camera()->setPosition(Vec(0.5,0.5,2.7f)); - ui->viewer->camera()->lookAt(Vec(0.5,0.5,0.5)); + // scene inits + ui->viewer->setSceneCenter(qglviewer::Vec(0.5,0.5,0.5)); + ui->viewer->setSceneRadius(2.0); + ui->viewer->setBackgroundColor(Qt::white); + ui->viewer->setForegroundColor(Qt::red); - // scene inits - ui->viewer->setSceneCenter(qglviewer::Vec(0.5,0.5,0.5)); - ui->viewer->setSceneRadius(2.0); - ui->viewer->setBackgroundColor(Qt::white); - ui->viewer->setForegroundColor(Qt::red); - pQuadric = gluNewQuadric(); + // OpenGL inits + glPointSize(10.0); + glLineWidth(1.0); + glEnable(GL_POINT_SMOOTH); + glEnable(GL_LINE_SMOOTH); - // OpenGL inits - glPointSize(10.0); - glLineWidth(1.0); - glEnable(GL_POINT_SMOOTH); - glEnable(GL_LINE_SMOOTH); + // Scene OpenGL state + compile_shaders(); + init_scene(EMPTY); - l_triangulation = glGenLists(1); - l_domain = glGenLists(2); - // Scene OpenGL state - gl_draw_domain(); - init_scene(EMPTY); } // Draws the triangulation void Scene::draw() { + if(!are_buffers_initialized) + initialize_buffers(); + gl_draw_location(); - // Draw the triangulation itself that is stored in the list. - glCallList(l_triangulation); + gl_draw_conflict(); - if (flying_ball) { - change_material(materials[FLYING_BALL_COLOR]); - if (wireframe) { - glBegin(GL_POINTS); - glVertex3f(moving_point.x(),moving_point.y(),moving_point.z()); - glEnd(); - } else { - // draw the moving point - glPushMatrix(); - glTranslated(moving_point.x(),moving_point.y(),moving_point.z()); - gluSphere(pQuadric, 0.02,15,15); - glFlush(); - glPopMatrix(); + //// Draw the triangulation itself that is stored in the list. + + if(wireframe) + { + //draw the points + vao[0].bind(); + change_material(materials[VERTEX_COLOR]); + attrib_buffers(ui->viewer); + rendering_program.bind(); + + glPointSize(5); + ::glEnable(GL_POINT_SMOOTH); + + rendering_program.setUniformValue(colorLocation[0], color); + glDrawArrays(GL_POINTS, 0, static_cast(pos_points.size()/3)); + rendering_program.release(); + vao[0].release(); + //draw the moving ball + if (flying_ball) { + vao[4].bind(); + change_material(materials[FLYING_BALL_COLOR]); + attrib_buffers(ui->viewer); + rendering_program.bind(); + + glPointSize(5); + ::glEnable(GL_POINT_SMOOTH); + rendering_program.setUniformValue(colorLocation[0], color); + glDrawArrays(GL_POINTS, 0, 1); + rendering_program.release(); + vao[4].release(); + } + //draw the lines + vao[1].bind(); + change_material(materials[EDGE_COLOR]); + attrib_buffers(ui->viewer); + rendering_program.bind(); + + rendering_program.setUniformValue(colorLocation[0], color); + glDrawArrays(GL_LINES, 0, static_cast(pos_tube.size()/3)); + rendering_program.release(); + vao[1].release(); + + //draw the cube + if(!in_plane) + { + vao[2].bind(); + change_material(materials[DOMAIN_COLOR]); + attrib_buffers(ui->viewer); + rendering_program.bind(); + rendering_program.setUniformValue(colorLocation[0], color); + glDrawArrays(GL_LINES, 0, static_cast(pos_cube.size()/3)); + rendering_program.release(); + vao[2].release(); + } + else + { + vao[11].bind(); + change_material(materials[DOMAIN_COLOR]); + attrib_buffers(ui->viewer); + rendering_program.bind(); + rendering_program.setUniformValue(colorLocation[0], color); + glDrawArrays(GL_LINES, 0, static_cast(pos_square.size()/3)); + rendering_program.release(); + vao[11].release(); + } } - } + else + { + if(!in_plane) + { + //cube + vao[8].bind(); + change_material(materials[DOMAIN_COLOR]); + attrib_buffers(ui->viewer); + rendering_program_cylinders.bind(); + glDrawArraysInstanced(GL_TRIANGLES, 0, static_cast(points_cube->size()/3), static_cast(transfo1_cube.size()/4)); + rendering_program_cylinders.release(); + vao[8].release(); + } + else + { + //square + vao[10].bind(); + change_material(materials[DOMAIN_COLOR]); + attrib_buffers(ui->viewer); + rendering_program_cylinders.bind(); + glDrawArraysInstanced(GL_TRIANGLES, 0, static_cast(points_cube->size()/3), static_cast(transfo1_square.size()/4)); + rendering_program_cylinders.release(); + vao[10].release(); + } + //draw the spheres + vao[3].bind(); + change_material(materials[VERTEX_COLOR]); + attrib_buffers(ui->viewer); + rendering_program_spheres.bind(); + glDrawArraysInstanced(GL_TRIANGLES, 0, static_cast(points_spheres.size()/3), static_cast(pos_points.size()/3)); + rendering_program_spheres.release(); + vao[3].release(); + + //draw the moving ball + if (flying_ball) { + vao[7].bind(); + change_material(materials[FLYING_BALL_COLOR]); + attrib_buffers(ui->viewer); + rendering_program_spheres.bind(); + glDrawArraysInstanced(GL_TRIANGLES, 0, static_cast(points_spheres.size()/3),1); + rendering_program_spheres.release(); + vao[7].release(); + } + //draw the triangulation + vao[9].bind(); + change_material(materials[EDGE_COLOR]); + attrib_buffers(ui->viewer); + rendering_program_cylinders.bind(); + glDrawArraysInstanced(GL_TRIANGLES, 0, static_cast(points_cylinder->size()/3), static_cast(transfo1_cylinder.size()/4)); + rendering_program_cylinders.release(); + vao[9].release(); + } + //draw the triangles + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + if(dlocate) + { + vao[5].bind(); + rendering_program.bind(); + color.setRgbF(0.f, 0.f , 0.5f, 0.5f); + rendering_program.setUniformValue(colorLocation[0], color); + glDrawArrays(GL_TRIANGLES, 0, static_cast(pos_location.size()/3)); + rendering_program.release(); + vao[5].release(); + } + if(dconflict) + { + vao[6].bind(); + rendering_program.bind(); + color.setRgbF(0.69f, 0.18f , 0.26f, 0.6f); + rendering_program.setUniformValue(colorLocation[0], color); + glDrawArrays(GL_TRIANGLES, 0, static_cast(pos_conflict.size()/3)); + rendering_program.release(); + vao[6].release(); + } + glDisable(GL_BLEND); - // draw the domain (unit square / cube) - if (ddomain) glCallList(l_domain); - glDisable(GL_LIGHTING); - if (dlocate) gl_draw_location(); - if (dconflict) gl_draw_conflict(); - if (!wireframe) glEnable(GL_LIGHTING); - glFlush(); } void Scene::load_points(const QString& fileName) { - p3dt.clear(); - std::vector points; - std::ifstream ifs(fileName.toAscii().data() ); - std::copy(std::istream_iterator(ifs), - std::istream_iterator(), - std::back_inserter(points)); - std::random_shuffle(points.begin(), points.end()); - p3dt.insert(points.begin(), points.end()); + p3dt.clear(); + std::vector points; + std::ifstream ifs(fileName.toLatin1().data() ); + std::copy(std::istream_iterator(ifs), + std::istream_iterator(), + std::back_inserter(points)); + std::random_shuffle(points.begin(), points.end()); + p3dt.insert(points.begin(), points.end()); - make_draw_list(); + QString snv; + int nv = static_cast(p3dt.number_of_vertices()); + snv.setNum(nv); + changed(); + Q_EMIT message(QString("|V| = ") + snv, 0); - QString snv; - int nv = static_cast(p3dt.number_of_vertices()); - snv.setNum(nv); - Q_EMIT message(QString("|V| = ") + snv, 0); - draw(); + draw(); } // update the position of the moving point void Scene::update_position() { - double x = moving_point.x() +0.01023; - double y = moving_point.y() +0.003123; - double z = (in_plane ? 0.0 : moving_point.z() +0.02567); - if(x>1.)x-=1.; - if(y>1.)y-=1.; - if(z>1.)z-=1.; - moving_point = Point(x,y,z); - // TODO try to find a better possibility - ui->viewer->update(); -} + double x = moving_point.x() +0.01023; + double y = moving_point.y() +0.003123; + double z = (in_plane ? 0.0 : moving_point.z() +0.02567); + if(x>1.)x-=1.; + if(y>1.)y-=1.; + if(z>1.)z-=1.; + moving_point = Point(x,y,z); + float moving_ball[] = {float(moving_point.x()), + float(moving_point.y()), + float(moving_point.z())}; + vao[4].bind(); + buffers[5].bind(); + buffers[5].allocate(moving_ball, 3*sizeof(float)); + rendering_program.bind(); + poly_vertexLocation[0] = rendering_program.attributeLocation("vertex"); + rendering_program.enableAttributeArray(poly_vertexLocation[0]); + rendering_program.setAttributeBuffer(poly_vertexLocation[0],GL_FLOAT,0,3); + buffers[5].release(); -void Scene::make_draw_list() -{ - // Prepare set of segments - Segment_set segments_to_draw; - primitives_from_geom_it(segments_to_draw); - if (cube_clipping && !two_color_clipping) segment_clipping(segments_to_draw); + rendering_program.release(); + vao[4].release(); - // Create new list - glNewList(l_triangulation, GL_COMPILE); + vao[7].bind(); + buffers[3].bind(); + poly_vertexLocation[1] = rendering_program_spheres.attributeLocation("vertex"); + rendering_program_spheres.enableAttributeArray(poly_vertexLocation[1]); + rendering_program_spheres.setAttributeBuffer(poly_vertexLocation[1],GL_FLOAT,0,3); + buffers[3].release(); - // Draw vertices - change_material(materials[VERTEX_COLOR]); - if (wireframe) glBegin(GL_POINTS); - for (Point_iterator pit = p3dt.periodic_points_begin(it_type) ; - pit != p3dt.periodic_points_end(it_type) ; pit++) - gl_draw_vertex(pit->first, 0.02); - if (wireframe) glEnd(); + buffers[4].bind(); + rendering_program_spheres.bind(); + normalsLocation[1] = rendering_program_spheres.attributeLocation("normal"); + rendering_program_spheres.enableAttributeArray(normalsLocation[1]); + rendering_program_spheres.setAttributeBuffer(normalsLocation[1],GL_FLOAT,0,3); + buffers[4].release(); - // Draw segments - if (wireframe) glBegin(GL_LINES); - if (cube_clipping && two_color_clipping) { - change_material(materials[CLIPPING_COLOR]); - segment_2color_clipping(segments_to_draw); - } - change_material(materials[EDGE_COLOR]); - for (Segment_set::iterator it = segments_to_draw.begin() ; - it != segments_to_draw.end(); it++) - gl_draw_edge(it->source(),it->target(),0.005); - if (wireframe) glEnd(); - glFlush(); - glEndList(); + buffers[5].bind(); + rendering_program_spheres.bind(); + centerLocation[0] = rendering_program_spheres.attributeLocation("center"); + rendering_program_spheres.enableAttributeArray(centerLocation[0]); + rendering_program_spheres.setAttributeBuffer(centerLocation[0],GL_FLOAT,0,3); + buffers[5].release(); + glVertexAttribDivisor(centerLocation[0],1); + glVertexAttribDivisor(normalsLocation[1],0); + vao[7].release(); - // TODO: viewer should be specialized and then the respective - // viewer->paintGL should be called. - ui->viewer->update(); + ui->viewer->update(); } // some initialization templates void Scene::init_scene(Init ID) { - bool temp_flags[] = {dlocate, dconflict}; - dlocate = false; - dconflict = false; - p3dt.clear(); - make_draw_list(); - RandPts rp(0.5); - Point pt2; - switch (ID) { - case GRID: - p3dt.insert_dummy_points(); - break; - case SINGLE: - p3dt.insert(Point(0.3,0.4,0.5)); - break; - case PLANE: - for (int i=0 ; i<10 ; i++) { - pt2 = *rp+Vector(0.5,0.5,0.5); - rp++; - p3dt.insert(Point(pt2.x(),pt2.y(),0.0)); + bool temp_flags[] = {dlocate, dconflict}; + dlocate = false; + dconflict = false; + p3dt.clear(); + RandPts rp(0.5); + Point pt2; + switch (ID) { + case GRID: + p3dt.insert_dummy_points(); + break; + case SINGLE: + p3dt.insert(Point(0.3,0.4,0.5)); + break; + case PLANE: + for (int i=0 ; i<10 ; i++) { + pt2 = *rp+Vector(0.5,0.5,0.5); + rp++; + p3dt.insert(Point(pt2.x(),pt2.y(),0.0)); + } + break; + case RANDOM: + do { + p3dt.insert(*rp+Vector(0.5,0.5,0.5)); + rp++; + } + while (p3dt.number_of_vertices()<30); + default: + break; } - break; - case RANDOM: - do { - p3dt.insert(*rp+Vector(0.5,0.5,0.5)); - rp++; - } - while (p3dt.number_of_vertices()<30); - default: - break; - } - dlocate = temp_flags[0]; - dconflict = temp_flags[1]; - make_draw_list(); -} - -// Draw a unit square in the x/y-plane -void Scene::gl_draw_square() { - glNewList(l_domain, GL_COMPILE); - change_material(materials[DOMAIN_COLOR]); - if (!wireframe) { - glPushMatrix(); - glTranslated(0.5,0.5,0.5); - glRotated(90,1.0,0.0,0.0); - glTranslated(-0.5,-0.5,-0.5); - for (float x=0.0; x<2.0; x+=1.0) { - for (float y=0.0; y<1.0; y+=1.0) { - glPushMatrix(); - glTranslated(x,y,0.0); - gluCylinder(pQuadric,0.01,0.01,1.0,25,2); - glPopMatrix(); - } - } - glPopMatrix(); - glPushMatrix(); - glTranslated(0.5,0.5,0.5); - glRotated(90,0.0,1.0,0.0); - glTranslated(-0.5,-0.5,-0.5); - for (float x=1.0; x<2.0; x+=1.0) { - for (float y=0.0; y<2.0; y+=1.0) { - glPushMatrix(); - glTranslated(x,y,0.0); - gluCylinder(pQuadric,0.01,0.01,1.0,25,2); - glPopMatrix(); - } - } - glPopMatrix(); - } else { - glBegin(GL_LINES); - glVertex3d(0.0,0.0,0.0); - glVertex3d(1.0,0.0,0.0); - glVertex3d(0.0,1.0,0.0); - glVertex3d(1.0,1.0,0.0); - glVertex3d(0.0,0.0,0.0); - glVertex3d(0.0,1.0,0.0); - glVertex3d(1.0,0.0,0.0); - glVertex3d(1.0,1.0,0.0); - glEnd(); - } - glEndList(); -} - -// Draw a unit cube -void Scene::gl_draw_cube() { - glNewList(l_domain, GL_COMPILE); - change_material(materials[DOMAIN_COLOR]); - if (!wireframe) { - glPushMatrix(); - for (float x=0.0; x<2.0; x+=1.0) { - for (float y=0.0; y<2.0; y+=1.0) { - glPushMatrix(); - glTranslated(x,y,0.0); - gluCylinder(pQuadric,0.01,0.01,1.0,25,2); - glPopMatrix(); - } - } - glPopMatrix(); - glPushMatrix(); - glTranslated(0.5,0.5,0.5); - glRotated(90,1.0,0.0,0.0); - glTranslated(-0.5,-0.5,-0.5); - for (float x=0.0; x<2.0; x+=1.0) { - for (float y=0.0; y<2.0; y+=1.0) { - glPushMatrix(); - glTranslated(x,y,0.0); - gluCylinder(pQuadric,0.01,0.01,1.0,25,2); - glPopMatrix(); - } - } - glPopMatrix(); - glPushMatrix(); - glTranslated(0.5,0.5,0.5); - glRotated(90,0.0,1.0,0.0); - glTranslated(-0.5,-0.5,-0.5); - for (float x=0.0; x<2.0; x+=1.0) { - for (float y=0.0; y<2.0; y+=1.0) { - glPushMatrix(); - glTranslated(x,y,0.0); - gluCylinder(pQuadric,0.01,0.01,1.0,25,2); - glPopMatrix(); - } - } - glPopMatrix(); - } else { - glBegin(GL_LINES); - glVertex3d(0.0,0.0,0.0); - glVertex3d(1.0,0.0,0.0); - glVertex3d(0.0,1.0,0.0); - glVertex3d(1.0,1.0,0.0); - glVertex3d(0.0,0.0,1.0); - glVertex3d(1.0,0.0,1.0); - glVertex3d(0.0,1.0,1.0); - glVertex3d(1.0,1.0,1.0); - - glVertex3d(0.0,0.0,0.0); - glVertex3d(0.0,1.0,0.0); - glVertex3d(1.0,0.0,0.0); - glVertex3d(1.0,1.0,0.0); - glVertex3d(0.0,0.0,1.0); - glVertex3d(0.0,1.0,1.0); - glVertex3d(1.0,0.0,1.0); - glVertex3d(1.0,1.0,1.0); - - glVertex3d(0.0,0.0,0.0); - glVertex3d(0.0,0.0,1.0); - glVertex3d(1.0,0.0,0.0); - glVertex3d(1.0,0.0,1.0); - glVertex3d(0.0,1.0,0.0); - glVertex3d(0.0,1.0,1.0); - glVertex3d(1.0,1.0,0.0); - glVertex3d(1.0,1.0,1.0); - glEnd(); - } - glEndList(); + dlocate = temp_flags[0]; + dconflict = temp_flags[1]; + changed(); } // get the offset that is common to all points of a triangle in the // triangulation inline void Scene::get_tri_offsets(const Cell_handle ch, int i, - Offset &off0, Offset &off1, Offset &off2) const { - off0 = p3dt.get_offset(ch,(i+1)&3); - off1 = p3dt.get_offset(ch,(i+2)&3); - off2 = p3dt.get_offset(ch,(i+3)&3); - if (it_type == P3DT::UNIQUE || it_type == P3DT::UNIQUE_COVER_DOMAIN) { - int diff_offx = (std::min)((std::min)(off0.x(),off1.x()),off2.x()); - int diff_offy = (std::min)((std::min)(off0.y(),off1.y()),off2.y()); - int diff_offz = (std::min)((std::min)(off0.z(),off1.z()),off2.z()); - Offset diff_off(diff_offx, diff_offy, diff_offz); - off0 -= diff_off; - off1 -= diff_off; - off2 -= diff_off; - } + Offset &off0, Offset &off1, Offset &off2) const { + off0 = p3dt.get_offset(ch,(i+1)&3); + off1 = p3dt.get_offset(ch,(i+2)&3); + off2 = p3dt.get_offset(ch,(i+3)&3); + if (it_type == P3DT::UNIQUE || it_type == P3DT::UNIQUE_COVER_DOMAIN) { + int diff_offx = (std::min)((std::min)(off0.x(),off1.x()),off2.x()); + int diff_offy = (std::min)((std::min)(off0.y(),off1.y()),off2.y()); + int diff_offz = (std::min)((std::min)(off0.z(),off1.z()),off2.z()); + Offset diff_off(diff_offx, diff_offy, diff_offz); + off0 -= diff_off; + off1 -= diff_off; + off2 -= diff_off; + } } // get the offset that is common to all points of a tetrahedron in the // triangulation inline void Scene::get_tet_offsets(const Cell_handle ch, - Offset &off0, Offset &off1, Offset &off2, Offset &off3) const { - off0 = p3dt.get_offset(ch,0); - off1 = p3dt.get_offset(ch,1); - off2 = p3dt.get_offset(ch,2); - off3 = p3dt.get_offset(ch,3); - if (it_type == P3DT::UNIQUE || it_type == P3DT::UNIQUE_COVER_DOMAIN) { - int diff_offx = (std::min)((std::min)(off0.x(),off1.x()), - (std::min)(off2.x(),off3.x())); - int diff_offy = (std::min)((std::min)(off0.y(),off1.y()), - (std::min)(off2.y(),off3.y())); - int diff_offz = (std::min)((std::min)(off0.z(),off1.z()), - (std::min)(off2.z(),off3.z())); - Offset diff_off(diff_offx, diff_offy, diff_offz); - off0 -= diff_off; - off1 -= diff_off; - off2 -= diff_off; - off3 -= diff_off; - } + Offset &off0, Offset &off1, Offset &off2, Offset &off3) const { + off0 = p3dt.get_offset(ch,0); + off1 = p3dt.get_offset(ch,1); + off2 = p3dt.get_offset(ch,2); + off3 = p3dt.get_offset(ch,3); + if (it_type == P3DT::UNIQUE || it_type == P3DT::UNIQUE_COVER_DOMAIN) { + int diff_offx = (std::min)((std::min)(off0.x(),off1.x()), + (std::min)(off2.x(),off3.x())); + int diff_offy = (std::min)((std::min)(off0.y(),off1.y()), + (std::min)(off2.y(),off3.y())); + int diff_offz = (std::min)((std::min)(off0.z(),off1.z()), + (std::min)(off2.z(),off3.z())); + Offset diff_off(diff_offx, diff_offy, diff_offz); + off0 -= diff_off; + off1 -= diff_off; + off2 -= diff_off; + off3 -= diff_off; + } } // return an integer that encodes the translations which have to be // applied to the triangle to draw inline int Scene::get_tri_drawing_offsets(const Cell_handle ch, int i) const { - Offset off0, off1, off2; - // if drawing boundary cells multiply is not activated then there is - // nothing to do. - switch( it_type ) { - case P3DT::UNIQUE_COVER_DOMAIN: - get_tri_offsets(ch,i,off0,off1,off2); - break; - case P3DT::STORED_COVER_DOMAIN: - off0 = p3dt.int_to_off(ch->offset((i+1)&3)); - off1 = p3dt.int_to_off(ch->offset((i+2)&3)); - off2 = p3dt.int_to_off(ch->offset((i+3)&3)); - break; - default: - return 0; - } + Offset off0, off1, off2; + // if drawing boundary cells multiply is not activated then there is + // nothing to do. + switch( it_type ) { + case P3DT::UNIQUE_COVER_DOMAIN: + get_tri_offsets(ch,i,off0,off1,off2); + break; + case P3DT::STORED_COVER_DOMAIN: + off0 = p3dt.int_to_off(ch->offset((i+1)&3)); + off1 = p3dt.int_to_off(ch->offset((i+2)&3)); + off2 = p3dt.int_to_off(ch->offset((i+3)&3)); + break; + default: + return 0; + } - CGAL_assertion(off0.x() == 0 || off0.x() == 1); - CGAL_assertion(off0.y() == 0 || off0.y() == 1); - CGAL_assertion(off0.z() == 0 || off0.z() == 1); - CGAL_assertion(off1.x() == 0 || off1.x() == 1); - CGAL_assertion(off1.y() == 0 || off1.y() == 1); - CGAL_assertion(off1.z() == 0 || off1.z() == 1); - CGAL_assertion(off2.x() == 0 || off2.x() == 1); - CGAL_assertion(off2.y() == 0 || off2.y() == 1); - CGAL_assertion(off2.z() == 0 || off2.z() == 1); - - int offx = ( ((off0.x() == 0 && off1.x() == 0 && off2.x() == 0) - || (off0.x() == 1 && off1.x() == 1 && off2.x() == 1)) ? 0 : 1); - int offy = ( ((off0.y() == 0 && off1.y() == 0 && off2.y() == 0) - || (off0.y() == 1 && off1.y() == 1 && off2.y() == 1)) ? 0 : 1); - int offz = ( ((off0.z() == 0 && off1.z() == 0 && off2.z() == 0) - || (off0.z() == 1 && off1.z() == 1 && off2.z() == 1)) ? 0 : 1); - - return( 4*offx + 2*offy + offz ); + CGAL_assertion(off0.x() == 0 || off0.x() == 1); + CGAL_assertion(off0.y() == 0 || off0.y() == 1); + CGAL_assertion(off0.z() == 0 || off0.z() == 1); + CGAL_assertion(off1.x() == 0 || off1.x() == 1); + CGAL_assertion(off1.y() == 0 || off1.y() == 1); + CGAL_assertion(off1.z() == 0 || off1.z() == 1); + CGAL_assertion(off2.x() == 0 || off2.x() == 1); + CGAL_assertion(off2.y() == 0 || off2.y() == 1); + CGAL_assertion(off2.z() == 0 || off2.z() == 1); + + int offx = ( ((off0.x() == 0 && off1.x() == 0 && off2.x() == 0) + || (off0.x() == 1 && off1.x() == 1 && off2.x() == 1)) ? 0 : 1); + int offy = ( ((off0.y() == 0 && off1.y() == 0 && off2.y() == 0) + || (off0.y() == 1 && off1.y() == 1 && off2.y() == 1)) ? 0 : 1); + int offz = ( ((off0.z() == 0 && off1.z() == 0 && off2.z() == 0) + || (off0.z() == 1 && off1.z() == 1 && off2.z() == 1)) ? 0 : 1); + + return( 4*offx + 2*offy + offz ); } // return an integer that encodes the translations which have to be // applied to the tetrahedron to draw inline int Scene::get_tet_drawing_offsets(const Cell_handle ch) const { - Offset off0, off1, off2, off3; - // if drawing boundary cells multiply is not activated then there is - // nothing to do. - switch( it_type ) { - case P3DT::UNIQUE_COVER_DOMAIN: - get_tet_offsets(ch,off0,off1,off2,off3); - break; - case P3DT::STORED_COVER_DOMAIN: - off0 = p3dt.int_to_off(ch->offset(0)); - off1 = p3dt.int_to_off(ch->offset(1)); - off2 = p3dt.int_to_off(ch->offset(2)); - off3 = p3dt.int_to_off(ch->offset(3)); - break; - default: - return 0; - } + Offset off0, off1, off2, off3; + // if drawing boundary cells multiply is not activated then there is + // nothing to do. + switch( it_type ) { + case P3DT::UNIQUE_COVER_DOMAIN: + get_tet_offsets(ch,off0,off1,off2,off3); + break; + case P3DT::STORED_COVER_DOMAIN: + off0 = p3dt.int_to_off(ch->offset(0)); + off1 = p3dt.int_to_off(ch->offset(1)); + off2 = p3dt.int_to_off(ch->offset(2)); + off3 = p3dt.int_to_off(ch->offset(3)); + break; + default: + return 0; + } - CGAL_assertion(off0.x() == 0 || off0.x() == 1); - CGAL_assertion(off0.y() == 0 || off0.y() == 1); - CGAL_assertion(off0.z() == 0 || off0.z() == 1); - CGAL_assertion(off1.x() == 0 || off1.x() == 1); - CGAL_assertion(off1.y() == 0 || off1.y() == 1); - CGAL_assertion(off1.z() == 0 || off1.z() == 1); - CGAL_assertion(off2.x() == 0 || off2.x() == 1); - CGAL_assertion(off2.y() == 0 || off2.y() == 1); - CGAL_assertion(off2.z() == 0 || off2.z() == 1); - CGAL_assertion(off3.x() == 0 || off3.x() == 1); - CGAL_assertion(off3.y() == 0 || off3.y() == 1); - CGAL_assertion(off3.z() == 0 || off3.z() == 1); - - int offx = ( ((off0.x() == 0 && off1.x() == 0 - && off2.x() == 0 && off3.x() == 0) - || (off0.x() == 1 && off1.x() == 1 - && off2.x() == 1 && off3.x() == 1)) ? 0 : 1); - int offy = ( ((off0.y() == 0 && off1.y() == 0 - && off2.y() == 0 && off3.y() == 0) - || (off0.y() == 1 && off1.y() == 1 - && off2.y() == 1 && off3.y() == 1)) ? 0 : 1); - int offz = ( ((off0.z() == 0 && off1.z() == 0 - && off2.z() == 0 && off3.z() == 0) - || (off0.z() == 1 && off1.z() == 1 - && off2.z() == 1 && off3.z() == 1)) ? 0 : 1); - - return( 4*offx + 2*offy + offz ); + CGAL_assertion(off0.x() == 0 || off0.x() == 1); + CGAL_assertion(off0.y() == 0 || off0.y() == 1); + CGAL_assertion(off0.z() == 0 || off0.z() == 1); + CGAL_assertion(off1.x() == 0 || off1.x() == 1); + CGAL_assertion(off1.y() == 0 || off1.y() == 1); + CGAL_assertion(off1.z() == 0 || off1.z() == 1); + CGAL_assertion(off2.x() == 0 || off2.x() == 1); + CGAL_assertion(off2.y() == 0 || off2.y() == 1); + CGAL_assertion(off2.z() == 0 || off2.z() == 1); + CGAL_assertion(off3.x() == 0 || off3.x() == 1); + CGAL_assertion(off3.y() == 0 || off3.y() == 1); + CGAL_assertion(off3.z() == 0 || off3.z() == 1); + + int offx = ( ((off0.x() == 0 && off1.x() == 0 + && off2.x() == 0 && off3.x() == 0) + || (off0.x() == 1 && off1.x() == 1 + && off2.x() == 1 && off3.x() == 1)) ? 0 : 1); + int offy = ( ((off0.y() == 0 && off1.y() == 0 + && off2.y() == 0 && off3.y() == 0) + || (off0.y() == 1 && off1.y() == 1 + && off2.y() == 1 && off3.y() == 1)) ? 0 : 1); + int offz = ( ((off0.z() == 0 && off1.z() == 0 + && off2.z() == 0 && off3.z() == 0) + || (off0.z() == 1 && off1.z() == 1 + && off2.z() == 1 && off3.z() == 1)) ? 0 : 1); + + return( 4*offx + 2*offy + offz ); } // construct a triangle from a given facet, given vertex offsets and a // common offset inline Triangle Scene::construct_triangle(const Cell_handle ch, int i, - const Offset& off0, const Offset& off1, const Offset& off2, int off) const { - if (it_type == P3DT::STORED || it_type == P3DT::UNIQUE) { - CGAL_assertion( off == 0 ); - return p3dt.construct_triangle( - ch->vertex((i+1)&3)->point(), ch->vertex((i+2)&3)->point(), - ch->vertex((i+3)&3)->point(), off0, off1, off2); - } - Offset diff_off((off>>2)&1,(off>>1)&1,off&1); - switch (it_type) { - case P3DT::STORED_COVER_DOMAIN: - return p3dt.construct_triangle( - ch->vertex((i+1)&3)->point(), ch->vertex((i+2)&3)->point(), - ch->vertex((i+3)&3)->point(), - p3dt.combine_offsets(off0,-diff_off), - p3dt.combine_offsets(off1,-diff_off), - p3dt.combine_offsets(off2,-diff_off)); - break; - case P3DT::UNIQUE_COVER_DOMAIN: - return p3dt.construct_triangle( - ch->vertex((i+1)&3)->point(), ch->vertex((i+2)&3)->point(), - ch->vertex((i+3)&3)->point(), - off0-diff_off, off1-diff_off, off2-diff_off); - break; - default: - CGAL_assertion(false); - return Triangle(); - } + const Offset& off0, const Offset& off1, const Offset& off2, int off) const { + if (it_type == P3DT::STORED || it_type == P3DT::UNIQUE) { + CGAL_assertion( off == 0 ); + return p3dt.construct_triangle( + ch->vertex((i+1)&3)->point(), ch->vertex((i+2)&3)->point(), + ch->vertex((i+3)&3)->point(), off0, off1, off2); + } + Offset diff_off((off>>2)&1,(off>>1)&1,off&1); + switch (it_type) { + case P3DT::STORED_COVER_DOMAIN: + return p3dt.construct_triangle( + ch->vertex((i+1)&3)->point(), ch->vertex((i+2)&3)->point(), + ch->vertex((i+3)&3)->point(), + p3dt.combine_offsets(off0,-diff_off), + p3dt.combine_offsets(off1,-diff_off), + p3dt.combine_offsets(off2,-diff_off)); + break; + case P3DT::UNIQUE_COVER_DOMAIN: + return p3dt.construct_triangle( + ch->vertex((i+1)&3)->point(), ch->vertex((i+2)&3)->point(), + ch->vertex((i+3)&3)->point(), + off0-diff_off, off1-diff_off, off2-diff_off); + break; + default: + CGAL_assertion(false); + return Triangle(); + } } // construct a triangle from a given cell, given vertex offsets and a // common offset inline Tetrahedron Scene::construct_tetrahedron(const Cell_handle ch, - const Offset& off0, const Offset& off1, const Offset& off2, - const Offset& off3, int off) const { - if (it_type == P3DT::STORED || it_type == P3DT::UNIQUE) { - CGAL_assertion( off == 0 ); - return p3dt.construct_tetrahedron( - ch->vertex(0)->point(), ch->vertex(1)->point(), - ch->vertex(2)->point(), ch->vertex(3)->point(), - off0, off1, off2, off3); - } - Offset diff_off((off>>2)&1,(off>>1)&1,off&1); - switch (it_type) { - case P3DT::STORED_COVER_DOMAIN: - return p3dt.construct_tetrahedron( - ch->vertex(0)->point(), ch->vertex(1)->point(), - ch->vertex(2)->point(), ch->vertex(3)->point(), - p3dt.combine_offsets(off0,-diff_off), - p3dt.combine_offsets(off1,-diff_off), - p3dt.combine_offsets(off2,-diff_off), - p3dt.combine_offsets(off3,-diff_off)); - break; - case P3DT::UNIQUE_COVER_DOMAIN: - return p3dt.construct_tetrahedron( - ch->vertex(0)->point(), ch->vertex(1)->point(), - ch->vertex(2)->point(), ch->vertex(3)->point(), - off0-diff_off, off1-diff_off, off2-diff_off, off3-diff_off); - break; - default: - CGAL_assertion(false); - return Tetrahedron(); - } + const Offset& off0, const Offset& off1, const Offset& off2, + const Offset& off3, int off) const { + if (it_type == P3DT::STORED || it_type == P3DT::UNIQUE) { + CGAL_assertion( off == 0 ); + return p3dt.construct_tetrahedron( + ch->vertex(0)->point(), ch->vertex(1)->point(), + ch->vertex(2)->point(), ch->vertex(3)->point(), + off0, off1, off2, off3); + } + Offset diff_off((off>>2)&1,(off>>1)&1,off&1); + switch (it_type) { + case P3DT::STORED_COVER_DOMAIN: + return p3dt.construct_tetrahedron( + ch->vertex(0)->point(), ch->vertex(1)->point(), + ch->vertex(2)->point(), ch->vertex(3)->point(), + p3dt.combine_offsets(off0,-diff_off), + p3dt.combine_offsets(off1,-diff_off), + p3dt.combine_offsets(off2,-diff_off), + p3dt.combine_offsets(off3,-diff_off)); + break; + case P3DT::UNIQUE_COVER_DOMAIN: + return p3dt.construct_tetrahedron( + ch->vertex(0)->point(), ch->vertex(1)->point(), + ch->vertex(2)->point(), ch->vertex(3)->point(), + off0-diff_off, off1-diff_off, off2-diff_off, off3-diff_off); + break; + default: + CGAL_assertion(false); + return Tetrahedron(); + } } -// Draw a point, either es vertex or as sphere -inline void Scene::gl_draw_vertex(const Point& p, const FT& radius) const { - if (p.z()!=0 && in_plane) return; - if (wireframe) { - glVertex3f(p.x(),p.y(),p.z()); - } else { - glPushMatrix(); - glTranslated(p.x(),p.y(),p.z()); - gluSphere(pQuadric,radius,15,15); - glFlush(); - glPopMatrix(); - } -} - -// Draw an edge, either as line or as cylinder -inline void Scene::gl_draw_edge(Point p1, Point p2, FT radius ) { - if (in_plane && (p1.z()!=0. || p2.z()!=0.)) return; - if (wireframe) { - glVertex3d(p1.x(),p1.y(),p1.z()); - glVertex3d(p2.x(),p2.y(),p2.z()); - return; - } - - Point p = p1; - Vector v = p2-p1; - - FT len = (FT)std::sqrt(CGAL_NTS to_double(v*v)); - - // normalize - v = v / len; - double angle = 0.0; - if(std::sqrt(CGAL_NTS to_double(v.x()*v.x()+v.y()*v.y())) > 1) - angle = 90.0f; - else - angle = asin(std::sqrt(CGAL_NTS to_double(v.x()*v.x()+v.y()*v.y())))/3.14159*180.0; - if(v.z() < 0) - angle = 180.0-angle; - Vector axis; - if (v.x() == 0.0 && v.y() == 0.0) - axis = Vector(1.0,0.0,0.0); - else - axis = Vector(v.y(),-v.x(),0.0); - - glPushMatrix(); - glTranslated(CGAL_NTS to_double(p.x()), - CGAL_NTS to_double(p.y()), - CGAL_NTS to_double(p.z())); - glPushMatrix(); - glRotated(-angle,CGAL_NTS to_double(axis.x()), - CGAL_NTS to_double(axis.y()), - CGAL_NTS to_double(axis.z())); - - // draw a cylinder - gluCylinder(pQuadric,CGAL_NTS to_double(radius), - CGAL_NTS to_double(radius), - CGAL_NTS to_double(len),25,2); - glPopMatrix(); - glPopMatrix(); - glPopMatrix(); -} // collect primitives (segments, triangles, tetrahedra) from the // triangulation using the geometric iterators and store them in the // given segment set inline void Scene::primitives_from_geom_it(Segment_set& sset) { - Point p0,p1,p2,p3; - switch(draw_type) { - case SEGMENT: - for ( Segment_iterator sit = p3dt.periodic_segments_begin(it_type) ; - sit != p3dt.periodic_segments_end(it_type) ; ++sit ) { - sset.insert(p3dt.segment(*sit)); + Point p0,p1,p2,p3; + switch(draw_type) { + case SEGMENT: + for ( Segment_iterator sit = p3dt.periodic_segments_begin(it_type) ; + sit != p3dt.periodic_segments_end(it_type) ; ++sit ) { + sset.insert(p3dt.segment(*sit)); + } + break; + case TRIANGLE: + for ( Triangle_iterator tit = p3dt.periodic_triangles_begin(it_type) ; + tit != p3dt.periodic_triangles_end(it_type) ; ++tit ) { + p0 = p3dt.point(tit->at(0)); + p1 = p3dt.point(tit->at(1)); + p2 = p3dt.point(tit->at(2)); + sset.insert(p0 < p1 ? Segment(p0,p1) : Segment(p1,p0)); + sset.insert(p0 < p2 ? Segment(p0,p2) : Segment(p2,p0)); + sset.insert(p1 < p2 ? Segment(p1,p2) : Segment(p2,p1)); + } + break; + case TETRAHEDRON: + for ( Tetrahedron_iterator tit = p3dt.periodic_tetrahedra_begin(it_type) ; + tit != p3dt.periodic_tetrahedra_end(it_type) ; ++tit ) { + p0 = p3dt.point(tit->at(0)); + p1 = p3dt.point(tit->at(1)); + p2 = p3dt.point(tit->at(2)); + p3 = p3dt.point(tit->at(3)); + sset.insert((p0 < p1) ? Segment(p0,p1) : Segment(p1,p0)); + sset.insert((p0 < p2) ? Segment(p0,p2) : Segment(p2,p0)); + sset.insert((p0 < p3) ? Segment(p0,p3) : Segment(p3,p0)); + sset.insert((p1 < p2) ? Segment(p1,p2) : Segment(p2,p1)); + sset.insert((p1 < p3) ? Segment(p1,p3) : Segment(p3,p1)); + sset.insert((p2 < p3) ? Segment(p2,p3) : Segment(p3,p2)); + } + break; } - break; - case TRIANGLE: - for ( Triangle_iterator tit = p3dt.periodic_triangles_begin(it_type) ; - tit != p3dt.periodic_triangles_end(it_type) ; ++tit ) { - p0 = p3dt.point(tit->at(0)); - p1 = p3dt.point(tit->at(1)); - p2 = p3dt.point(tit->at(2)); - sset.insert(p0 < p1 ? Segment(p0,p1) : Segment(p1,p0)); - sset.insert(p0 < p2 ? Segment(p0,p2) : Segment(p2,p0)); - sset.insert(p1 < p2 ? Segment(p1,p2) : Segment(p2,p1)); - } - break; - case TETRAHEDRON: - for ( Tetrahedron_iterator tit = p3dt.periodic_tetrahedra_begin(it_type) ; - tit != p3dt.periodic_tetrahedra_end(it_type) ; ++tit ) { - p0 = p3dt.point(tit->at(0)); - p1 = p3dt.point(tit->at(1)); - p2 = p3dt.point(tit->at(2)); - p3 = p3dt.point(tit->at(3)); - sset.insert((p0 < p1) ? Segment(p0,p1) : Segment(p1,p0)); - sset.insert((p0 < p2) ? Segment(p0,p2) : Segment(p2,p0)); - sset.insert((p0 < p3) ? Segment(p0,p3) : Segment(p3,p0)); - sset.insert((p1 < p2) ? Segment(p1,p2) : Segment(p2,p1)); - sset.insert((p1 < p3) ? Segment(p1,p3) : Segment(p3,p1)); - sset.insert((p2 < p3) ? Segment(p2,p3) : Segment(p3,p2)); - } - break; - } } // clip segments from the given segment set that are partially outside // of the unit cube/square. Eliminate those who are completely outside inline void Scene::segment_clipping(Segment_set& sset) { - Segment_clipper clipper; - Segment_set sset_tmp; - for (Segment_set::iterator it = sset.begin() ; it != sset.end() ; ++it) { - Point s = it->source(); - Point t = it->target(); - if (clipper(s,t)) sset_tmp.insert((ssource(); + Point t = it->target(); + if (clipper(s,t)) sset_tmp.insert((ssource(); - Point t = it->target(); - if (clipper(s,t)) { - sset_tmp.insert((ssource(); - Point q = it->target(); - if (Segment(p,s).squared_length() > Segment(p,t).squared_length()) - std::swap(s,t); - if (p!=s) sset_out.insert((psource(); + Point t = it->target(); + if (clipper(s,t)) { + sset_tmp.insert((ssource(); + Point q = it->target(); + if (Segment(p,s).squared_length() > Segment(p,t).squared_length()) + std::swap(s,t); + if (p!=s) sset_out.insert((psource(), sit->target(), 0.005); - std::swap(sset, sset_tmp); + std::swap(sset, sset_tmp); } // Draw the faces of the tetrahedron in which the moving point is currently @@ -636,93 +1296,99 @@ inline void Scene::segment_2color_clipping (Segment_set& sset) { // of the respective cell will be drawn. In general it will be all // cells that occur in the draw list void Scene::gl_draw_location() { - if (p3dt.number_of_vertices() == 0) return; - // Do the point location - Cell_handle ch = p3dt.locate(moving_point); - std::vector cf; + pos_location.resize(0); + if (p3dt.number_of_vertices() == 0) return; + // Do the point location + Cell_handle ch = p3dt.locate(moving_point); + std::vector cf; - // Transparency - glEnable(GL_BLEND); - glColor4f(0.f, 0.f , 0.5f, 0.5f); - glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + // Transparency - if (in_plane) { - int i=0; - int count = 0; - // Figure out whether there is a facet that is completly contained - // in the z=0 plane - for (int j=0 ; j<4 ; j++) { - if (ch->vertex(j)->point().z() != 0.0 || - p3dt.get_offset(ch,j).z() != 0) { - i=j; - count++; - } - } - // If so, compute its triangle(s) and insert it in cf - if (count==1) { - Offset off0, off1, off2; - get_tri_offsets(ch, i, off0, off1, off2); - int diff_off = get_tri_drawing_offsets(ch, i); - for (int offs=0 ; offs<=diff_off ; offs++) { - if ((((~offs)|diff_off)&7)!=7) continue; - Triangle tri_to_draw = construct_triangle(ch,i,off0,off1,off2,offs); - Point p = tri_to_draw.vertex(0); - Point q = tri_to_draw.vertex(1); - Point r = tri_to_draw.vertex(2); - cf.push_back(Projected_triangle(.0,Triangle(p,q,r))); - } - } - } else { - double modelMatrix[16]; - double projMatrix[16]; - int viewport[4]; - glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix); - glGetDoublev(GL_PROJECTION_MATRIX, projMatrix); - glGetIntegerv(GL_VIEWPORT, viewport); + if (in_plane) { + int i=0; + int count = 0; + // Figure out whether there is a facet that is completly contained + // in the z=0 plane + for (int j=0 ; j<4 ; j++) { + if (ch->vertex(j)->point().z() != 0.0 || + p3dt.get_offset(ch,j).z() != 0) { + i=j; + count++; + } + } + // If so, compute its triangle(s) and insert it in cf + if (count==1) { + Offset off0, off1, off2; + get_tri_offsets(ch, i, off0, off1, off2); + int diff_off = get_tri_drawing_offsets(ch, i); + for (int offs=0 ; offs<=diff_off ; offs++) { + if ((((~offs)|diff_off)&7)!=7) continue; + Triangle tri_to_draw = construct_triangle(ch,i,off0,off1,off2,offs); + Point p = tri_to_draw.vertex(0); + Point q = tri_to_draw.vertex(1); + Point r = tri_to_draw.vertex(2); + cf.push_back(Projected_triangle(.0,Triangle(p,q,r))); + } + } + } else { + double modelMatrix[16]; + double projMatrix[16]; + int viewport[4]; + glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix); + glGetDoublev(GL_PROJECTION_MATRIX, projMatrix); + glGetIntegerv(GL_VIEWPORT, viewport); - // Compute the triangles that are the facets of the cell and - // insert them in cf - Offset off0,off1,off2,off3; - get_tet_offsets(ch, off0, off1, off2, off3); - int diff_off = get_tet_drawing_offsets(ch); + // Compute the triangles that are the facets of the cell and + // insert them in cf + Offset off0,off1,off2,off3; + get_tet_offsets(ch, off0, off1, off2, off3); + int diff_off = get_tet_drawing_offsets(ch); - for (int offs=0 ; offs<=diff_off ; offs++) { - if ((((~offs)|diff_off)&7)!=7) continue; - Tetrahedron tet_to_draw = construct_tetrahedron( - ch, off0, off1, off2, off3, offs); + for (int offs=0 ; offs<=diff_off ; offs++) { + if ((((~offs)|diff_off)&7)!=7) continue; + Tetrahedron tet_to_draw = construct_tetrahedron( + ch, off0, off1, off2, off3, offs); - for(int i=0; i < 4; i++){ - Point p = tet_to_draw.vertex((i+1)&3); - Point q = tet_to_draw.vertex((i+2)&3); - Point r = tet_to_draw.vertex((i+3)&3); - Vector c= (Vector(Point(),p)+Vector(Point(),q)+Vector(Point(),r))/3.; - Point cp = Point(c.x(),c.y(),c.z()); - // project facet center - double px,py,pz; - gluProject(cp.x(),cp.y(),cp.z(), - modelMatrix, projMatrix, viewport, - &px,&py,&pz); - cf.push_back(Projected_triangle(pz,Triangle(p,q,r))); - } + for(int i=0; i < 4; i++){ + Point p = tet_to_draw.vertex((i+1)&3); + Point q = tet_to_draw.vertex((i+2)&3); + Point r = tet_to_draw.vertex((i+3)&3); + Vector c= (Vector(Point(),p)+Vector(Point(),q)+Vector(Point(),r))/3.; + Point cp = Point(c.x(),c.y(),c.z()); + // project facet center + double px,py,pz; + gluProject(cp.x(),cp.y(),cp.z(), + modelMatrix, projMatrix, viewport, + &px,&py,&pz); + cf.push_back(Projected_triangle(pz,Triangle(p,q,r))); + } + } + + // Sort cf according to their z coordinates to enable transparency + std::sort(cf.begin(), cf.end(), Projected_triangle::closer); } - // Sort cf according to their z coordinates to enable transparency - std::sort(cf.begin(), cf.end(), Projected_triangle::closer); - } + // Draw all triangles from cf + for (std::vector::iterator cfit = cf.begin() ; cfit != cf.end() ; cfit++) { + Point p = cfit->t().vertex(0); + Point q = cfit->t().vertex(1); + Point r = cfit->t().vertex(2); + pos_location.push_back(p.x()); pos_location.push_back(p.y()); pos_location.push_back(p.z()); + pos_location.push_back(q.x()); pos_location.push_back(q.y()); pos_location.push_back(q.z()); + pos_location.push_back(r.x()); pos_location.push_back(r.y()); pos_location.push_back(r.z()); - // Draw all triangles from cf - glBegin(GL_TRIANGLES); - for (std::vector::iterator cfit = cf.begin() ; cfit != cf.end() ; cfit++) { - Point p = cfit->t().vertex(0); - Point q = cfit->t().vertex(1); - Point r = cfit->t().vertex(2); - glVertex3d(p.x(), p.y(), p.z()); - glVertex3d(q.x(), q.y(), q.z()); - glVertex3d(r.x(), r.y(), r.z()); - } - glEnd(); + } + vao[5].bind(); + buffers[6].bind(); + buffers[6].allocate(pos_location.data(), static_cast(pos_location.size()*sizeof(float))); + rendering_program.bind(); + poly_vertexLocation[0] = rendering_program.attributeLocation("vertex"); + rendering_program.enableAttributeArray(poly_vertexLocation[0]); + rendering_program.setAttributeBuffer(poly_vertexLocation[0],GL_FLOAT,0,3); + buffers[6].release(); - glDisable(GL_BLEND); + rendering_program.release(); + vao[5].release(); } // Draw the boundary faces of the current conflict region of the @@ -730,111 +1396,122 @@ void Scene::gl_draw_location() { // copies of the respective cell will be drawn. In general it will be // all cells that occur in the draw list. void Scene::gl_draw_conflict() { - if (p3dt.number_of_vertices() == 0) return; - Cell_handle ch; - std::vector cic; - std::vector boundary_facets; - // Find the conflict region - Cell_handle c = p3dt.locate(moving_point); - p3dt.find_conflicts(moving_point,c,std::back_inserter(boundary_facets),std::back_inserter(cic),CGAL::Emptyset_iterator()); + pos_conflict.resize(0); + if (p3dt.number_of_vertices() == 0) return; + Cell_handle ch; + std::vector cic; + std::vector boundary_facets; + // Find the conflict region + Cell_handle c = p3dt.locate(moving_point); + p3dt.find_conflicts(moving_point,c,std::back_inserter(boundary_facets),std::back_inserter(cic),CGAL::Emptyset_iterator()); - std::vector bfm; + std::vector bfm; - // Transparency - glEnable(GL_BLEND); - glColor4f(.69f, 0.18f , 0.26f, 0.6f); - glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + // Transparency + //glEnable(GL_BLEND); + //glColor4f(.69f, 0.18f , 0.26f, 0.6f); + //glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); - if (in_plane) { - for (unsigned int k=0 ; kvertex(j)->point().z() != 0.0 || - p3dt.get_offset(ch,j).z() != 0) { - i=j; - count++; - } - } - // If so, compute its triangle(s) and insert it in bfm - if (count==1) { - Offset off0, off1, off2; - get_tri_offsets(ch, i, off0, off1, off2); - int diff_off = get_tri_drawing_offsets(ch,i); - for (int offs = 0 ; offs<=diff_off ; offs++) { - if ((((~offs)|diff_off)&7)!=7) continue; - Triangle tri_to_draw = construct_triangle(ch,i,off0,off1,off2,offs); - Point p = tri_to_draw.vertex(0); - Point q = tri_to_draw.vertex(1); - Point r = tri_to_draw.vertex(2); - bfm.push_back(Projected_triangle(.0,Triangle(p,q,r))); - } - } + int i = 0; + int count = 0; + // Figure out whether there is a facet that is completely + // contained in the z=0 plane + for (int j=0 ; j<4 ; j++) { + if (ch->vertex(j)->point().z() != 0.0 || + p3dt.get_offset(ch,j).z() != 0) { + i=j; + count++; + } + } + // If so, compute its triangle(s) and insert it in bfm + if (count==1) { + Offset off0, off1, off2; + get_tri_offsets(ch, i, off0, off1, off2); + int diff_off = get_tri_drawing_offsets(ch,i); + for (int offs = 0 ; offs<=diff_off ; offs++) { + if ((((~offs)|diff_off)&7)!=7) continue; + Triangle tri_to_draw = construct_triangle(ch,i,off0,off1,off2,offs); + Point p = tri_to_draw.vertex(0); + Point q = tri_to_draw.vertex(1); + Point r = tri_to_draw.vertex(2); + bfm.push_back(Projected_triangle(.0,Triangle(p,q,r))); + } + } + } + } else { + double modelMatrix[16]; + double projMatrix[16]; + int viewport[4]; + glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix); + glGetDoublev(GL_PROJECTION_MATRIX, projMatrix); + glGetIntegerv(GL_VIEWPORT, viewport); + + for (unsigned int i=0 ; i::iterator bfmit = bfm.begin() ; + bfmit != bfm.end() ; bfmit++) { + Point p = bfmit->t().vertex(0); + Point q = bfmit->t().vertex(1); + Point r = bfmit->t().vertex(2); + + pos_conflict.push_back(p.x()); pos_conflict.push_back(p.y()); pos_conflict.push_back(p.z()); + pos_conflict.push_back(q.x()); pos_conflict.push_back(q.y()); pos_conflict.push_back(q.z()); + pos_conflict.push_back(r.x()); pos_conflict.push_back(r.y()); pos_conflict.push_back(r.z()); - // Compute the triangle(s) of the facet and insert them in bfm - Offset off0, off1, off2; - get_tri_offsets(ch, j, off0, off1, off2); - int diff_off = get_tri_drawing_offsets(ch, j); - for (int offs=0 ; offs<=diff_off ; offs++) { - if ((((~offs)|diff_off)&7)!=7) continue; - Triangle tri_to_draw = construct_triangle(ch,j,off0,off1,off2,offs); - Point p = tri_to_draw.vertex(0); - Point q = tri_to_draw.vertex(1); - Point r = tri_to_draw.vertex(2); - Vector c= (Vector(Point(),p)+Vector(Point(),q)+Vector(Point(),r))/3.; - Point cp = Point(c.x(),c.y(),c.z()); - // project facet center - double px,py,pz; - gluProject(cp.x(),cp.y(),cp.z(), - modelMatrix, projMatrix, viewport, - &px,&py,&pz); - bfm.push_back(Projected_triangle(pz,Triangle(p,q,r))); - } } - - // Sort bfm according to their z coordinates to enable transparency - std::sort(bfm.begin(), bfm.end(), Projected_triangle::closer); - } + // glEnd(); + vao[6].bind(); + buffers[7].bind(); + buffers[7].allocate(pos_conflict.data(), static_cast(pos_conflict.size()*sizeof(float))); + rendering_program.bind(); + poly_vertexLocation[0] = rendering_program.attributeLocation("vertex"); + rendering_program.enableAttributeArray(poly_vertexLocation[0]); + rendering_program.setAttributeBuffer(poly_vertexLocation[0],GL_FLOAT,0,3); + buffers[7].release(); - // Draw all triangles from bfm - glBegin(GL_TRIANGLES); - for (std::vector::iterator bfmit = bfm.begin() ; - bfmit != bfm.end() ; bfmit++) { - Point p = bfmit->t().vertex(0); - Point q = bfmit->t().vertex(1); - Point r = bfmit->t().vertex(2); - glVertex3d(p.x(), p.y(), p.z()); - glVertex3d(q.x(), q.y(), q.z()); - glVertex3d(r.x(), r.y(), r.z()); - } - glEnd(); - - glDisable(GL_BLEND); + rendering_program.release(); + vao[6].release(); + // glEnd(); + // + // glDisable(GL_BLEND); } // provide some color constants for the GLU primitive appearance. void Scene::change_material(const QString &string) { - float ambient[] = {0.0f,0.0f,0.0f,1.0f}; - float diffuse[] = {0.0f,0.0f,0.0f,1.0f}; - float specular[] = {0.0f,0.0f,0.0f,1.0f}; - float emission[] = {0.3f,0.3f,0.3f,1.0f}; - float shininess[] = {0.0f}; + // Change if(string == "Silver") @@ -855,546 +1532,622 @@ void Scene::change_material(const QString &string) { specular[2] = 0.508273f; specular[3] = 1.0f; // Shininess - shininess[0] = 51.2f; + shininess = 51.2f; } - else + else if(string == "Gold") + { + // Ambient + ambient[0] = 0.24725f; + ambient[1] = 0.1995f; + ambient[2] = 0.0745f; + ambient[3] = 1.0f; + // Diffuse + diffuse[0] = 0.75164f; + diffuse[1] = 0.60648f; + diffuse[2] = 0.22648f; + diffuse[3] = 1.0f; + // Specular + specular[0] = 0.928281f; + specular[1] = 0.855802f; + specular[2] = 0.666065f; + specular[3] = 1.0f; + // Shininess + shininess = 51.2f; + } - // Change - if(string == "Light silver") - { - // Ambient - ambient[0] = 0.49225f; - ambient[1] = 0.49225f; - ambient[2] = 0.49225f; - ambient[3] = 1.0f; - // Diffuse - diffuse[0] = 0.80754f; - diffuse[1] = 0.80754f; - diffuse[2] = 0.80754f; - diffuse[3] = 1.0f; - // Specular - specular[0] = 0.808273f; - specular[1] = 0.808273f; - specular[2] = 0.808273f; - specular[3] = 1.0f; - // Shininess - shininess[0] = 51.2f; - } - else + else if(string == "Red") + { + // Ambient + ambient[0] = 0.75f; + ambient[1] = 0.0f; + ambient[2] = 0.0f; + ambient[3] = 1.0f; + // Diffuse + diffuse[0] = 1.0f; + diffuse[1] = 0.0f; + diffuse[2] = 0.0f; + diffuse[3] = 1.0f; + // Specular + specular[0] = 0.75f; + specular[1] = 0.75f; + specular[2] = 0.75f; + specular[3] = 1.0f; + // Shininess + shininess = 64.0f; + } - // Change - if(string == "Gold") - { - // Ambient - ambient[0] = 0.24725f; - ambient[1] = 0.1995f; - ambient[2] = 0.0745f; - ambient[3] = 1.0f; - // Diffuse - diffuse[0] = 0.75164f; - diffuse[1] = 0.60648f; - diffuse[2] = 0.22648f; - diffuse[3] = 1.0f; - // Specular - specular[0] = 0.928281f; - specular[1] = 0.855802f; - specular[2] = 0.666065f; - specular[3] = 1.0f; - // Shininess - shininess[0] = 51.2f; - } + else if(string == "Green") + { + // Ambient + ambient[0] = 0.0225f; + ambient[1] = 0.19125f; + ambient[2] = 0.0735f; + ambient[3] = 1.0f; + // Diffuse + diffuse[0] = 0.0828f; + diffuse[1] = 0.3038f; + diffuse[2] = 0.14048f; + diffuse[3] = 1.0f; + // Specular + specular[0] = 0.086014f; + specular[1] = 0.306777f; + specular[2] = 0.117622f; + specular[3] = 1.0f; + // Shininess + shininess = 12.8f; + } - else + else if(string == "Black plastic") + { + // Ambient + ambient[0] = 0.0f; + ambient[1] = 0.0f; + ambient[2] = 0.0f; + ambient[3] = 1.0f; + // Diffuse + diffuse[0] = 0.01f; + diffuse[1] = 0.01f; + diffuse[2] = 0.01f; + diffuse[3] = 1.0f; + // Specular + specular[0] = 0.5f; + specular[1] = 0.5f; + specular[2] = 0.5f; + specular[3] = 1.0f; + // Shininess + shininess = 32.0f; + } + + color.setRgbF(diffuse[0],diffuse[1],diffuse[2],diffuse[3]); + +} + +void Scene::changed() +{ + compute_elements(); + are_buffers_initialized = false; +} + +void Scene::draw_sphere(float R, int prec) +{ + + points_spheres.resize(0); + int rings=prec, sectors=prec; + float T, P; + float x[4],y[4],z[4]; + + + //Top of the sphere + for(int t=0; t<360; t+=sectors) + { + + points_spheres.push_back(0); + points_spheres.push_back(0); + points_spheres.push_back(R); + + + normals_spheres.push_back(0); + normals_spheres.push_back(0); + normals_spheres.push_back(1); + + + + P = rings*M_PI/180.0; + T = t*M_PI/180.0; + x[1] = sin(P) * cos(T) ; + y[1] = sin(P) * sin(T) ; + z[1] = cos(P); + points_spheres.push_back(R * x[1]); + points_spheres.push_back(R * y[1]); + points_spheres.push_back(R * z[1]); + + + normals_spheres.push_back(x[1]); + normals_spheres.push_back(y[1]); + normals_spheres.push_back(z[1]); + + // + P = rings*M_PI/180.0; + T = (t+sectors)*M_PI/180.0; + x[2] = sin(P) * cos(T) ; + y[2] = sin(P) * sin(T) ; + z[2] = cos(P); + points_spheres.push_back(R * x[2]); + points_spheres.push_back(R * y[2]); + points_spheres.push_back(R * z[2]); + + normals_spheres.push_back(x[2]); + normals_spheres.push_back(y[2]); + normals_spheres.push_back(z[2]); + + } + + //Body of the sphere + for (int p=rings; p<180-rings; p+=rings) + for(int t=0; t<360; t+=sectors) + { + //A + P = p*M_PI/180.0; + T = t*M_PI/180.0; + x[0] = sin(P) * cos(T) ; + y[0] = sin(P) * sin(T) ; + z[0] = cos(P); + + points_spheres.push_back(R * x[0]); + points_spheres.push_back(R * y[0]); + points_spheres.push_back(R * z[0]); + + + normals_spheres.push_back(x[0]); + normals_spheres.push_back(y[0]); + normals_spheres.push_back(z[0]); + + //B + P = (p+rings)*M_PI/180.0; + T = t*M_PI/180.0; + x[1] = sin(P) * cos(T) ; + y[1] = sin(P) * sin(T) ; + z[1] = cos(P); + points_spheres.push_back(R * x[1]); + points_spheres.push_back(R * y[1]); + points_spheres.push_back(R * z[1]); + + + normals_spheres.push_back(x[1]); + normals_spheres.push_back(y[1]); + normals_spheres.push_back(z[1]); + + //C + P = p*M_PI/180.0; + T = (t+sectors)*M_PI/180.0; + x[2] = sin(P) * cos(T) ; + y[2] = sin(P) * sin(T) ; + z[2] = cos(P); + points_spheres.push_back(R * x[2]); + points_spheres.push_back(R * y[2]); + points_spheres.push_back(R * z[2]); + + + normals_spheres.push_back(x[2]); + normals_spheres.push_back(y[2]); + normals_spheres.push_back(z[2]); + //D + P = (p+rings)*M_PI/180.0; + T = (t+sectors)*M_PI/180.0; + x[3] = sin(P) * cos(T) ; + y[3] = sin(P) * sin(T) ; + z[3] = cos(P); + points_spheres.push_back(R * x[3]); + points_spheres.push_back(R * y[3]); + points_spheres.push_back(R * z[3]); + + + normals_spheres.push_back(x[3]); + normals_spheres.push_back(y[3]); + normals_spheres.push_back(z[3]); + + + + points_spheres.push_back(R * x[1]); + points_spheres.push_back(R * y[1]); + points_spheres.push_back(R * z[1]); + + + normals_spheres.push_back(x[1]); + normals_spheres.push_back(y[1]); + normals_spheres.push_back(z[1]); + + points_spheres.push_back(R * x[2]); + points_spheres.push_back(R * y[2]); + points_spheres.push_back(R * z[2]); + + + normals_spheres.push_back(x[2]); + normals_spheres.push_back(y[2]); + normals_spheres.push_back(z[2]); + + } + //Bottom of the sphere + for(int t=0; t<360; t+=sectors) + { + + + points_spheres.push_back(0); + points_spheres.push_back(0); + points_spheres.push_back(-R); + + + normals_spheres.push_back(0); + normals_spheres.push_back(0); + normals_spheres.push_back(-1); + + + P = (180-rings)*M_PI/180.0; + T = t*M_PI/180.0; + x[1] = sin(P) * cos(T) ; + y[1] = sin(P) * sin(T) ; + z[1] = cos(P); + points_spheres.push_back(R * x[1]); + points_spheres.push_back(R * y[1]); + points_spheres.push_back(R * z[1]); + + + normals_spheres.push_back(x[1]); + normals_spheres.push_back(y[1]); + normals_spheres.push_back(z[1]); + + + P = (180-rings)*M_PI/180.0; + T = (t+sectors)*M_PI/180.0; + x[2] = sin(P) * cos(T) ; + y[2] = sin(P) * sin(T) ; + z[2] = cos(P); + points_spheres.push_back(R * x[2]); + points_spheres.push_back(R * y[2]); + points_spheres.push_back(R * z[2]); + + + normals_spheres.push_back(x[2]); + normals_spheres.push_back(y[2]); + normals_spheres.push_back(z[2]); + + } + +} +void Scene::draw_cylinder(float R, int prec, std::vector *vertices, std::vector *normals) +{ + vertices->resize(0); + int rings=360/prec, sectors=360/prec; + float T, P; + float x[4],y[4],z[4]; + //Closing nicely the tubes will cause z-fighting and the spherical parts will get all messy + + //top of the cylinder + for(int t=0; t<360; t+=sectors) + { + + vertices->push_back(0); + vertices->push_back(R+1); + vertices->push_back(0); + + + normals->push_back(0); + normals->push_back(1); + normals->push_back(0); + + + + P = rings*M_PI/180.0; + T = t*M_PI/180.0; + x[1] = sin(P) * cos(T) ; + z[1] = sin(P) * sin(T) ; + y[1] = cos(P); + vertices->push_back(R * x[1]); + vertices->push_back(R * y[1]+1); + vertices->push_back(R * z[1]); + + + normals->push_back(x[1]); + normals->push_back(y[1]); + normals->push_back(z[1]); + + // + P = rings*M_PI/180.0; + T = (t+sectors)*M_PI/180.0; + x[2] = sin(P) * cos(T) ; + z[2] = sin(P) * sin(T) ; + y[2] = cos(P); + vertices->push_back(R * x[2]); + vertices->push_back(R * y[2]+1); + vertices->push_back(R * z[2]); + + normals->push_back(x[2]); + normals->push_back(y[2]); + normals->push_back(z[2]); + + } + //Body of the sphere + for (int p=rings; p<90; p+=rings) + for(int t=0; t<360; t+=sectors) + { + //A + P = p*M_PI/180.0; + T = t*M_PI/180.0; + x[0] = sin(P) * cos(T) ; + z[0] = sin(P) * sin(T) ; + y[0] = cos(P); + + vertices->push_back(R * x[0]); + vertices->push_back(R * y[0]+1); + vertices->push_back(R * z[0]); + + + normals->push_back(x[0]); + normals->push_back(y[0]); + normals->push_back(z[0]); + + //B + P = (p+rings)*M_PI/180.0; + T = t*M_PI/180.0; + x[1] = sin(P) * cos(T) ; + z[1] = sin(P) * sin(T) ; + y[1] = cos(P); + vertices->push_back(R * x[1]); + vertices->push_back(R * y[1]+1); + vertices->push_back(R * z[1]); + + + normals->push_back(x[1]); + normals->push_back(y[1]); + normals->push_back(z[1]); + + //C + P = p*M_PI/180.0; + T = (t+sectors)*M_PI/180.0; + x[2] = sin(P) * cos(T) ; + z[2] = sin(P) * sin(T) ; + y[2] = cos(P); + vertices->push_back(R * x[2]); + vertices->push_back(R * y[2]+1); + vertices->push_back(R * z[2]); + + + normals->push_back(x[2]); + normals->push_back(y[2]); + normals->push_back(z[2]); + //D + P = (p+rings)*M_PI/180.0; + T = (t+sectors)*M_PI/180.0; + x[3] = sin(P) * cos(T) ; + z[3] = sin(P) * sin(T) ; + y[3] = cos(P); + vertices->push_back(R * x[3]); + vertices->push_back(R * y[3]+1); + vertices->push_back(R * z[3]); + + + normals->push_back(x[3]); + normals->push_back(y[3]); + normals->push_back(z[3]); + + + + vertices->push_back(R * x[1]); + vertices->push_back(R * y[1]+1); + vertices->push_back(R * z[1]); + + + normals->push_back(x[1]); + normals->push_back(y[1]); + normals->push_back(z[1]); + + vertices->push_back(R * x[2]); + vertices->push_back(R * y[2]+1); + vertices->push_back(R * z[2]); + + + normals->push_back(x[2]); + normals->push_back(y[2]); + normals->push_back(z[2]); + + } + + + //body of the cylinder + for(int d = 0; d<360; d+= 360/prec) + { + + //point A1 + float D = d*M_PI/180.0; + vertices->push_back(R * sin(D)); + vertices->push_back(0); + vertices->push_back(R * cos(D)); + + normals->push_back(sin(D)); + normals->push_back(0); + normals->push_back(cos(D)); + + //point B1 + vertices->push_back(R * sin(D)); + vertices->push_back(1); + vertices->push_back(R * cos(D)); + + normals->push_back(sin(D)); + normals->push_back(0); + normals->push_back(cos(D)); + + //point C1 + D = (d+360/prec)*M_PI/180.0; + vertices->push_back(R * sin(D)); + vertices->push_back(1); + vertices->push_back(R * cos(D)); + + normals->push_back(sin(D)); + normals->push_back(0); + normals->push_back(cos(D)); + + //point A2 + D = (d+360/prec)*M_PI/180.0; + vertices->push_back(R * sin(D)); + vertices->push_back(1); + vertices->push_back(R * cos(D)); + + normals->push_back(sin(D)); + normals->push_back(0); + normals->push_back(cos(D)); + + //point B2 + vertices->push_back(R * sin(D)); + vertices->push_back(0); + vertices->push_back(R * cos(D)); + + normals->push_back(sin(D)); + normals->push_back(0); + normals->push_back(cos(D)); + + //point C2 + D = d*M_PI/180.0; + vertices->push_back(R * sin(D)); + vertices->push_back(0); + vertices->push_back(R * cos(D)); + + normals->push_back(sin(D)); + normals->push_back(0); + normals->push_back(cos(D)); + + } + + //bottom of the cylinder + for(int t=0; t<360; t+=sectors) + { + + vertices->push_back(0); + vertices->push_back(-R); + vertices->push_back(0); + + + normals->push_back(0); + normals->push_back(-1); + normals->push_back(0); + + + + P = rings*M_PI/180.0; + T = t*M_PI/180.0; + x[1] = sin(P) * cos(T) ; + z[1] = sin(P) * sin(T) ; + y[1] = cos(P); + vertices->push_back(R * x[1]); + vertices->push_back(R * y[1]); + vertices->push_back(R * z[1]); + + + normals->push_back(x[1]); + normals->push_back(y[1]); + normals->push_back(z[1]); + + // + P = rings*M_PI/180.0; + T = (t+sectors)*M_PI/180.0; + x[2] = sin(P) * cos(T) ; + z[2] = sin(P) * sin(T) ; + y[2] = cos(P); + vertices->push_back(R * x[2]); + vertices->push_back(R * y[2]); + vertices->push_back(R * z[2]); + + normals->push_back(x[2]); + normals->push_back(y[2]); + normals->push_back(z[2]); + + } + //Body of the sphere + for (int p=90; p<180; p+=rings) + for(int t=0; t<360; t+=sectors) + { + //A + P = p*M_PI/180.0; + T = t*M_PI/180.0; + x[0] = sin(P) * cos(T) ; + z[0] = sin(P) * sin(T) ; + y[0] = cos(P); + + vertices->push_back(R * x[0]); + vertices->push_back(R * y[0]); + vertices->push_back(R * z[0]); + + + normals->push_back(x[0]); + normals->push_back(y[0]); + normals->push_back(z[0]); + + //B + P = (p+rings)*M_PI/180.0; + T = t*M_PI/180.0; + x[1] = sin(P) * cos(T) ; + z[1] = sin(P) * sin(T) ; + y[1] = cos(P); + vertices->push_back(R * x[1]); + vertices->push_back(R * y[1]); + vertices->push_back(R * z[1]); + + + normals->push_back(x[1]); + normals->push_back(y[1]); + normals->push_back(z[1]); + + //C + P = p*M_PI/180.0; + T = (t+sectors)*M_PI/180.0; + x[2] = sin(P) * cos(T) ; + z[2] = sin(P) * sin(T) ; + y[2] = cos(P); + vertices->push_back(R * x[2]); + vertices->push_back(R * y[2]); + vertices->push_back(R * z[2]); + + + normals->push_back(x[2]); + normals->push_back(y[2]); + normals->push_back(z[2]); + //D + P = (p+rings)*M_PI/180.0; + T = (t+sectors)*M_PI/180.0; + x[3] = sin(P) * cos(T) ; + z[3] = sin(P) * sin(T) ; + y[3] = cos(P); + vertices->push_back(R * x[3]); + vertices->push_back(R * y[3]); + vertices->push_back(R * z[3]); + + + normals->push_back(x[3]); + normals->push_back(y[3]); + normals->push_back(z[3]); + + + + vertices->push_back(R * x[1]); + vertices->push_back(R * y[1]); + vertices->push_back(R * z[1]); + + + normals->push_back(x[1]); + normals->push_back(y[1]); + normals->push_back(z[1]); + + vertices->push_back(R * x[2]); + vertices->push_back(R * y[2]); + vertices->push_back(R * z[2]); + + + normals->push_back(x[2]); + normals->push_back(y[2]); + normals->push_back(z[2]); + + } - // Change - if(string == "Jade") - { - // Ambient - ambient[0] = 0.135f; - ambient[1] = 0.2225f; - ambient[2] = 0.1575f; - ambient[3] = 0.95f; - // Diffuse - diffuse[0] = 0.54f; - diffuse[1] = 0.89f; - diffuse[2] = 0.63f; - diffuse[3] = 0.95f; - // Specular - specular[0] = 0.316228f; - specular[1] = 0.316228f; - specular[2] = 0.316228f; - specular[3] = 0.95f; - // Shininess - shininess[0] = 12.8f; - } - else - - // Change - if(string == "Light blue") - { - // Ambient - ambient[0] = 0.0f; - ambient[1] = 0.5f; - ambient[2] = 0.75f; - ambient[3] = 1.0f; - // Diffuse - diffuse[0] = 0.0f; - diffuse[1] = 0.5f; - diffuse[2] = 1.0f; - diffuse[3] = 1.0f; - // Specular - specular[0] = 0.75f; - specular[1] = 0.75f; - specular[2] = 0.75f; - specular[3] = 1.0f; - // Shininess - shininess[0] = 64.0f; - } - - else - - // Change - if(string == "Pink") - { - // Ambient - ambient[0] = 0.75f; - ambient[1] = 0.0f; - ambient[2] = 0.5f; - ambient[3] = 1.0f; - // Diffuse - diffuse[0] = 1.0f; - diffuse[1] = 0.0f; - diffuse[2] = 0.5f; - diffuse[3] = 1.0f; - // Specular - specular[0] = 0.75f; - specular[1] = 0.75f; - specular[2] = 0.75f; - specular[3] = 1.0f; - // Shininess - shininess[0] = 64.0f; - } - - else - - // Change - if(string == "Red") - { - // Ambient - ambient[0] = 0.75f; - ambient[1] = 0.0f; - ambient[2] = 0.0f; - ambient[3] = 1.0f; - // Diffuse - diffuse[0] = 1.0f; - diffuse[1] = 0.0f; - diffuse[2] = 0.0f; - diffuse[3] = 1.0f; - // Specular - specular[0] = 0.75f; - specular[1] = 0.75f; - specular[2] = 0.75f; - specular[3] = 1.0f; - // Shininess - shininess[0] = 64.0f; - } - - else - - // Change - if(string == "Emerald") - { - // Ambient - ambient[0] = 0.0215f; - ambient[1] = 0.1745f; - ambient[2] = 0.0215f; - ambient[3] = 0.55f; - // Diffuse - diffuse[0] = 0.07568f; - diffuse[1] = 0.61424f; - diffuse[2] = 0.07568f; - diffuse[3] = 0.55f; - // Specular - specular[0] = 0.633f; - specular[1] = 0.727811f; - specular[2] = 0.633f; - specular[3] = 0.55f; - // Shininess - shininess[0] = 76.8f; - } - - else - - // Change - if(string == "Polished silver") - { - // Ambient - ambient[0] = 0.23125f; - ambient[1] = 0.23125f; - ambient[2] = 0.23125f; - ambient[3] = 1.0f; - // Diffuse - diffuse[0] = 0.2775f; - diffuse[1] = 0.2775f; - diffuse[2] = 0.2775f; - diffuse[3] = 1.0f; - // Specular - specular[0] = 0.773911f; - specular[1] = 0.773911f; - specular[2] = 0.773911f; - specular[3] = 1.0f; - // Shininess - shininess[0] = 89.6f; - } - - else - - // Change - if(string == "Chrome") - { - // Ambient - ambient[0] = 0.25f; - ambient[1] = 0.25f; - ambient[2] = 0.25f; - ambient[3] = 1.0f; - // Diffuse - diffuse[0] = 0.4f; - diffuse[1] = 0.4f; - diffuse[2] = 0.4f; - diffuse[3] = 1.0f; - // Specular - specular[0] = 0.774597f; - specular[1] = 0.774597f; - specular[2] = 0.774597f; - specular[3] = 1.0f; - // Shininess - shininess[0] = 76.8f; - } - - else - - // Change - if(string == "Copper") - { - // Ambient - ambient[0] = 0.19125f; - ambient[1] = 0.0735f; - ambient[2] = 0.0225f; - ambient[3] = 1.0f; - // Diffuse - diffuse[0] = 0.7038f; - diffuse[1] = 0.27048f; - diffuse[2] = 0.0828f; - diffuse[3] = 1.0f; - // Specular - specular[0] = 0.256777f; - specular[1] = 0.137622f; - specular[2] = 0.086014f; - specular[3] = 1.0f; - // Shininess - shininess[0] = 12.8f; - } - - else - - // Change - if(string == "Green") - { - // Ambient - ambient[0] = 0.0225f; - ambient[1] = 0.19125f; - ambient[2] = 0.0735f; - ambient[3] = 1.0f; - // Diffuse - diffuse[0] = 0.0828f; - diffuse[1] = 0.3038f; - diffuse[2] = 0.14048f; - diffuse[3] = 1.0f; - // Specular - specular[0] = 0.086014f; - specular[1] = 0.306777f; - specular[2] = 0.117622f; - specular[3] = 1.0f; - // Shininess - shininess[0] = 12.8f; - } - - else - - // Change - if(string == "Blue") - { - // Ambient - ambient[0] = 0.0225f; - ambient[1] = 0.0735f; - ambient[2] = 0.19125f; - ambient[3] = 1.0f; - // Diffuse - diffuse[0] = 0.0828f; - diffuse[1] = 0.14048f; - diffuse[2] = 0.6038f; - diffuse[3] = 1.0f; - // Specular - specular[0] = 0.086014f; - specular[1] = 0.117622f; - specular[2] = 0.306777f; - specular[3] = 1.0f; - // Shininess - shininess[0] = 12.8f; - } - - else - - // Change - if(string == "Polished gold") - { - // Ambient - ambient[0] = 0.24725f; - ambient[1] = 0.2245f; - ambient[2] = 0.0645f; - ambient[3] = 1.0f; - // Diffuse - diffuse[0] = 0.34615f; - diffuse[1] = 0.3143f; - diffuse[2] = 0.0903f; - diffuse[3] = 1.0f; - // Specular - specular[0] = 0.797357f; - specular[1] = 0.723991f; - specular[2] = 0.208006f; - specular[3] = 1.0f; - // Shininess - shininess[0] = 83.2f; - } - - else - - // Change - if(string == "Pewter") - { - // Ambient - ambient[0] = 0.105882f; - ambient[1] = 0.058824f; - ambient[2] = 0.113725f; - ambient[3] = 1.0f; - // Diffuse - diffuse[0] = 0.427451f; - diffuse[1] = 0.470588f; - diffuse[2] = 0.541176f; - diffuse[3] = 1.0f; - // Specular - specular[0] = 0.333333f; - specular[1] = 0.333333f; - specular[2] = 0.521569f; - specular[3] = 1.0f; - // Shininess - shininess[0] = 9.84615f; - } - - else - - // Change - if(string == "Obsidian") - { - // Ambient - ambient[0] = 0.05375f; - ambient[1] = 0.05f; - ambient[2] = 0.06625f; - ambient[3] = 0.82f; - // Diffuse - diffuse[0] = 0.18275f; - diffuse[1] = 0.17f; - diffuse[2] = 0.22525f; - diffuse[3] = 0.82f; - // Specular - specular[0] = 0.332741f; - specular[1] = 0.328634f; - specular[2] = 0.346435f; - specular[3] = 0.82f; - // Shininess - shininess[0] = 38.4f; - } - - else - - // Change - if(string == "Black plastic") - { - // Ambient - ambient[0] = 0.0f; - ambient[1] = 0.0f; - ambient[2] = 0.0f; - ambient[3] = 1.0f; - // Diffuse - diffuse[0] = 0.01f; - diffuse[1] = 0.01f; - diffuse[2] = 0.01f; - diffuse[3] = 1.0f; - // Specular - specular[0] = 0.5f; - specular[1] = 0.5f; - specular[2] = 0.5f; - specular[3] = 1.0f; - // Shininess - shininess[0] = 32.0f; - } - - else - - // Change - if(string == "Polished bronze") - { - // Ambient - ambient[0] = 0.25f; - ambient[1] = 0.148f; - ambient[2] = 0.006475f; - ambient[3] = 1.0f; - // Diffuse - diffuse[0] = 0.4f; - diffuse[1] = 0.2368f; - diffuse[2] = 0.1036f; - diffuse[3] = 1.0f; - // Specular - specular[0] = 0.774597f; - specular[1] = 0.458561f; - specular[2] = 0.200621f; - specular[3] = 1.0f; - // Shininess - shininess[0] = 76.8f; - } - - - else - - // Change - if(string == "Polished copper") - { - // Ambient - ambient[0] = 0.2295f; - ambient[1] = 0.08825f; - ambient[2] = 0.0275f; - ambient[3] = 1.0f; - // Diffuse - diffuse[0] = 0.5508f; - diffuse[1] = 0.2118f; - diffuse[2] = 0.066f; - diffuse[3] = 1.0f; - // Specular - specular[0] = 0.580594f; - specular[1] = 0.223257f; - specular[2] = 0.0695701f; - specular[3] = 1.0f; - // Shininess - shininess[0] = 51.2f; - } - - else - - // Change - if(string == "Pearl") - { - // Ambient - ambient[0] = 0.25f; - ambient[1] = 0.20725f; - ambient[2] = 0.20725f; - ambient[3] = 0.922f; - // Diffuse - diffuse[0] = 1.0f; - diffuse[1] = 0.829f; - diffuse[2] = 0.829f; - diffuse[3] = 0.922f; - // Specular - specular[0] = 0.296648f; - specular[1] = 0.296648f; - specular[2] = 0.296648f; - specular[3] = 0.922f; - // Shininess - shininess[0] = 11.264f; - } - - else - - // Change - if(string == "Ruby") - { - // Ambient - ambient[0] = 0.1745f; - ambient[1] = 0.01175f; - ambient[2] = 0.01175f; - ambient[3] = 0.55f; - // Diffuse - diffuse[0] = 0.61424f; - diffuse[1] = 0.04136f; - diffuse[2] = 0.04136f; - diffuse[3] = 0.55f; - // Specular - specular[0] = 0.727811f; - specular[1] = 0.626959f; - specular[2] = 0.626959f; - specular[3] = 0.55f; - // Shininess - shininess[0] = 76.8f; - } - - else - - // Change - if(string == "Turquoise") - { - // Ambient - ambient[0] = 0.1f; - ambient[1] = 0.18725f; - ambient[2] = 0.1745f; - ambient[3] = 0.8f; - // Diffuse - diffuse[0] = 0.396f; - diffuse[1] = 0.74151f; - diffuse[2] = 0.69102f; - diffuse[3] = 0.8f; - // Specular - specular[0] = 0.297254f; - specular[1] = 0.30829f; - specular[2] = 0.306678f; - specular[3] = 0.8f; - // Shininess - shininess[0] = 12.8f; - } - - else - - // Change - if(string == "Brass") - { - // Ambient - ambient[0] = 0.329412f; - ambient[1] = 0.223529f; - ambient[2] = 0.027451f; - ambient[3] = 1.0f; - // Diffuse - diffuse[0] = 0.780392f; - diffuse[1] = 0.268627f; - diffuse[2] = 0.113725f; - diffuse[3] = 1.0f; - // Specular - specular[0] = 0.992157f; - specular[1] = 0.741176f; - specular[2] = 0.807843f; - specular[3] = 1.0f; - // Shininess - shininess[0] = 27.8974f; - } - - // apply - if (wireframe) { - glColor4f(diffuse[0],diffuse[1],diffuse[2],diffuse[3]); - } else { - glMaterialfv( GL_FRONT, GL_AMBIENT, ambient); - glMaterialfv( GL_FRONT, GL_DIFFUSE, diffuse); - glMaterialfv( GL_FRONT, GL_SPECULAR, specular); - glMaterialfv( GL_FRONT, GL_SHININESS, shininess); - glMaterialfv( GL_FRONT, GL_EMISSION, emission); - } } diff --git a/Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/Scene.h b/Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/Scene.h index f91da042735..4f0db183696 100644 --- a/Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/Scene.h +++ b/Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/Scene.h @@ -6,9 +6,12 @@ #include #include #include -#include +#include +#include +#include +#include -class Scene : public QObject +class Scene : public QObject, QOpenGLFunctions_3_3_Core { Q_OBJECT @@ -30,7 +33,7 @@ private: public: Scene(Ui::MainWindow* ui_) : ui(ui_), p3dt(), - moving_point(Point(0.2,0.2,0.2)) { + moving_point(Point(0.2,0.2,0.2)) { flying_ball = ui->actionFlying_ball->isChecked(); @@ -65,15 +68,23 @@ public: timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(update_position())); timer->start(100); + + points_cube = new std::vector(); + points_cylinder= new std::vector(); + normals_cylinder= new std::vector(); } ~Scene() { - gluDeleteQuadric(pQuadric); + for(int i=0; i<24; i++) + buffers[i].destroy(); + for(int i=0; i<12; i++) + vao[i].destroy(); } public Q_SLOTS: void init(); void draw(); + void changed(); void load_points(const QString& fileName); void update_position(); @@ -96,7 +107,8 @@ public Q_SLOTS: insert_point(moving_point); QString str; ui->viewer->displayMessage(str.sprintf("Added point (%f, %f, %f)", - moving_point.x(),moving_point.y(),moving_point.z())); + moving_point.x(),moving_point.y(),moving_point.z())); + changed(); } void insert_random() { @@ -106,39 +118,39 @@ public Q_SLOTS: insert_point(Point(pt.x(),pt.y(),(in_plane? 0.0:pt.z()))); QString str; ui->viewer->displayMessage(str.sprintf("Added point (%f, %f, %f)", - pt.x(),pt.y(),(in_plane? 0.0:pt.z()))); + pt.x(),pt.y(),(in_plane? 0.0:pt.z()))); + changed(); } void insert_point(Point p) { bool temp_flags[] = {dlocate, dconflict}; dlocate = dconflict = false; - make_draw_list(); p3dt.insert(p); dlocate = temp_flags[0]; dconflict = temp_flags[1]; - make_draw_list(); + changed(); } void grab_image() { ui->viewer->openSnapshotFormatDialog(); ui->viewer->saveSnapshot(false); } - void toggle_dlocate(bool on) { + void toggle_dlocate(bool on) { dlocate = on; + changed(); ui->viewer->update(); } void toggle_dconflict(bool on) { - dconflict = on; + dconflict = on; + changed(); ui->viewer->update(); } void toggle_wireframe(bool on) { wireframe = on; ( on ? glDisable(GL_LIGHTING) : glEnable(GL_LIGHTING) ); - gl_draw_domain(); - make_draw_list(); + changed(); } void toggle_in_plane(bool on) { in_plane = on; - gl_draw_domain(); - make_draw_list(); + changed(); } // TODO: find radio button functionality within menus in QtDesigner void toggle_force_1cover(bool on) { @@ -146,37 +158,37 @@ public Q_SLOTS: it_type = ( on ? P3DT::UNIQUE_COVER_DOMAIN : P3DT::STORED_COVER_DOMAIN ); else it_type = ( on ? P3DT::UNIQUE : P3DT::STORED); - make_draw_list(); + changed(); } void toggle_multiple_cells(bool on) { if (ui->actionDraw_1_sheeted_covering->isChecked()) it_type = ( on ? P3DT::UNIQUE_COVER_DOMAIN : P3DT::UNIQUE ); else it_type = ( on ? P3DT::STORED_COVER_DOMAIN : P3DT::STORED ); - make_draw_list(); + changed(); } void trigger_draw_type_segment() { ui->actionDraw_segments->setChecked(true); ui->actionDraw_triangles->setChecked(false); ui->actionDraw_tetrahedra->setChecked(false); draw_type = SEGMENT; - make_draw_list(); + changed(); } void trigger_draw_type_triangle() { ui->actionDraw_segments->setChecked(false); ui->actionDraw_triangles->setChecked(true); ui->actionDraw_tetrahedra->setChecked(false); draw_type = TRIANGLE; - make_draw_list(); + changed(); } void trigger_draw_type_tetrahedron() { ui->actionDraw_segments->setChecked(false); ui->actionDraw_triangles->setChecked(false); ui->actionDraw_tetrahedra->setChecked(true); draw_type = TETRAHEDRON; - make_draw_list(); + changed(); } - void toggle_ddomain(bool on) { ddomain = on; } + void toggle_ddomain(bool on) { ddomain = on; changed(); } void toggle_cube_clipping(bool on) { ui->action2_color_clipping->setEnabled(on); if (!on) ui->action2_color_clipping->setChecked(false); @@ -185,16 +197,16 @@ public Q_SLOTS: if (on && ui->action2_color_clipping->isChecked()) toggle_two_color_clipping(true); else - make_draw_list(); + changed(); } void toggle_two_color_clipping(bool on) { two_color_clipping = on; - make_draw_list(); + changed(); } - bool load_points() { + bool load_points() { QString fileName = QFileDialog ::getOpenFileName(ui->centralWidget, tr("Open point set"), - ".", tr("All files (*)")); + ".", tr("All files (*)")); if(! fileName.isEmpty()){ load_points(fileName); } @@ -202,36 +214,27 @@ public Q_SLOTS: } Q_SIGNALS: - void message(const QString & message, int timeout = 0 ); + void message(const QString & message, int timeout = 0 ); void loaded_points(const QString &n); private: // Scene management helpers - void make_draw_list(); void init_scene(Init sceneID); - void gl_draw_square(); - void gl_draw_cube(); - void gl_draw_domain() { - if (in_plane) gl_draw_square(); - else gl_draw_cube(); - } + // Helper functions void get_tri_offsets(const Cell_handle ch, int i, - Offset& off0, Offset& off1, Offset& off2) const; + Offset& off0, Offset& off1, Offset& off2) const; void get_tet_offsets(const Cell_handle ch, Offset& off0, Offset& off1, - Offset& off2, Offset& off3) const; + Offset& off2, Offset& off3) const; int get_tri_drawing_offsets(const Cell_handle ch, int i) const; int get_tet_drawing_offsets(const Cell_handle ch) const; Tetrahedron construct_tetrahedron(const Cell_handle ch, const Offset& off0, const Offset& off1,const Offset& off2,const Offset& off3, int off) const; - Triangle construct_triangle(const Cell_handle ch, int i, + Triangle construct_triangle(const Cell_handle ch, int i, const Offset& off0,const Offset& off1,const Offset& off2, int off) const; // Drawing functions - void gl_draw_vertex(const Point& p, const FT& radius) const; - void gl_draw_edge(Point p1, Point p2, FT radius ); - void primitives_from_geom_it(Segment_set& sset); void segment_clipping(Segment_set& sset); void segment_2color_clipping (Segment_set& sset); @@ -241,6 +244,61 @@ private: void change_material(const QString& string); + //Shaders elements + + QColor color; + // define material + QVector4D ambient; + QVector4D diffuse; + QVector4D specular; + GLfloat shininess ; + int poly_vertexLocation[3]; + int normalsLocation[3]; + int mvpLocation[3]; + int mvLocation[2]; + int centerLocation[5]; + int colorLocation[3]; + int lightLocation[5*2]; + + + std::vector pos_points; + std::vector pos_tube; + std::vector pos_cube; + std::vector pos_square; + std::vector pos_location; + std::vector pos_conflict; + std::vector points_spheres; + std::vector normals_spheres; + std::vector *points_cylinder; + std::vector *normals_cylinder; + std::vector *points_cube; + std::vector transfo1_cylinder; + std::vector transfo2_cylinder; + std::vector transfo3_cylinder; + std::vector transfo4_cylinder; + std::vector transfo1_cube; + std::vector transfo2_cube; + std::vector transfo3_cube; + std::vector transfo4_cube; + + std::vector transfo1_square; + std::vector transfo2_square; + std::vector transfo3_square; + std::vector transfo4_square; + + bool are_buffers_initialized; + QOpenGLBuffer buffers[24]; + QOpenGLVertexArrayObject vao[12]; + QOpenGLShaderProgram rendering_program; + QOpenGLShaderProgram rendering_program_spheres; + QOpenGLShaderProgram rendering_program_cylinders; + void initialize_buffers(); + void compute_elements(); + void attrib_buffers(QGLViewer*); + void compile_shaders(); + void draw_sphere(float R, int prec); + void draw_cylinder(float R, int prec, std::vector *vertices, std::vector *normals); + private: Ui::MainWindow * ui; P3DT p3dt; @@ -249,7 +307,6 @@ private: QString materials[6]; QTimer* timer; GLuint l_triangulation, l_domain; - GLUquadricObj* pQuadric; bool flying_ball; bool dlocate, dconflict; diff --git a/Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/Viewer.cpp b/Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/Viewer.cpp new file mode 100644 index 00000000000..51521874203 --- /dev/null +++ b/Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/Viewer.cpp @@ -0,0 +1,8 @@ + #include "Viewer.h" + #include + +Viewer::Viewer(QWidget *parent) +: QGLViewer(CGAL::Qt::createOpenGLContext(),parent) +{} +Viewer::~Viewer() +{} diff --git a/Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/Viewer.h b/Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/Viewer.h new file mode 100644 index 00000000000..9daa7985656 --- /dev/null +++ b/Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/Viewer.h @@ -0,0 +1,13 @@ +#ifndef VIEWER_H +#define VIEWER_H + +#include + +class Viewer : public QGLViewer{ + Q_OBJECT + + public: + Viewer(QWidget* parent); + virtual ~Viewer(); +}; +#endif //VIEWER_H diff --git a/Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/data/points b/Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/data/points old mode 100644 new mode 100755 diff --git a/Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/periodic_3_triangulation_3_demo.cpp b/Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/periodic_3_triangulation_3_demo.cpp index 673141e864a..5e4a5df1429 100644 --- a/Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/periodic_3_triangulation_3_demo.cpp +++ b/Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/periodic_3_triangulation_3_demo.cpp @@ -1,11 +1,12 @@ #include "MainWindow.h" -#include + +#include int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; - + //w.ui->setupUi(w); w.ui->viewer->restoreStateFromFile(); w.show(); diff --git a/Periodic_3_triangulation_3/demo/Periodic_Lloyd_3/CMakeLists.txt b/Periodic_3_triangulation_3/demo/Periodic_Lloyd_3/CMakeLists.txt index 25d87153cb2..ceb4ec01f70 100644 --- a/Periodic_3_triangulation_3/demo/Periodic_Lloyd_3/CMakeLists.txt +++ b/Periodic_3_triangulation_3/demo/Periodic_Lloyd_3/CMakeLists.txt @@ -3,43 +3,39 @@ project (Periodic_Lloyd_3) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +# Find includes in corresponding build directories +set(CMAKE_INCLUDE_CURRENT_DIR ON) +# Instruct CMake to run moc automatically when needed. +set(CMAKE_AUTOMOC ON) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() -find_package(CGAL COMPONENTS Qt4) +find_package(CGAL COMPONENTS Qt5) include(${CGAL_USE_FILE}) -set( QT_USE_QTXML TRUE ) -set( QT_USE_QTMAIN TRUE ) -set( QT_USE_QTSCRIPT TRUE ) -set( QT_USE_QTOPENGL TRUE ) -find_package(Qt4) + +find_package(Qt5 QUIET COMPONENTS Xml Script Help OpenGL Svg) find_package(OpenGL) -if(QT4_FOUND) - include( ${QT_USE_FILE} ) +if(Qt5_FOUND) find_package(QGLViewer) -endif(QT4_FOUND) +endif(Qt5_FOUND) -if ( CGAL_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND AND QT_QCOLLECTIONGENERATOR_EXECUTABLE ) +if ( CGAL_FOUND AND Qt5_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND AND TARGET Qt5::qcollectiongenerator ) - include(${QT_USE_FILE}) include_directories (${QGLVIEWER_INCLUDE_DIR}) include_directories (BEFORE ../../include ./ ) # ui file, created wih Qt Designer - qt4_wrap_ui( uis MainWindow.ui ) + qt5_wrap_ui( uis MainWindow.ui ) # qrc files (resources files, that contain icons, at least) - qt4_add_resources ( RESOURCE_FILES ./Periodic_Lloyd_3.qrc ) + qt5_add_resources ( RESOURCE_FILES ./Periodic_Lloyd_3.qrc ) - qt4_automoc( MainWindow.cpp Viewer.cpp) if(DEFINED QT_QCOLLECTIONGENERATOR_EXECUTABLE) else() @@ -49,7 +45,7 @@ if ( CGAL_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND AND QT_QCOLLE # generate QtAssistant collection file add_custom_command ( OUTPUT Periodic_Lloyd_3.qhc DEPENDS Periodic_Lloyd_3.qhp Periodic_Lloyd_3.qhcp - COMMAND ${QT_QCOLLECTIONGENERATOR_EXECUTABLE} + COMMAND Qt5::qcollectiongenerator ${CMAKE_CURRENT_SOURCE_DIR}/Periodic_Lloyd_3.qhcp -o ${CMAKE_CURRENT_BINARY_DIR}/Periodic_Lloyd_3.qhc WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} @@ -57,22 +53,23 @@ if ( CGAL_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND AND QT_QCOLLE add_executable ( Periodic_Lloyd_3 Periodic_Lloyd_3.qhc Periodic_Lloyd_3.cpp MainWindow.cpp Viewer.cpp ${uis} ${RESOURCE_FILES} ) + qt5_use_modules(Periodic_Lloyd_3 Xml Script Help OpenGL Svg) add_to_cached_list( CGAL_EXECUTABLE_TARGETS Periodic_Lloyd_3 ) target_link_libraries( Periodic_Lloyd_3 ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES}) target_link_libraries( Periodic_Lloyd_3 ${QT_LIBRARIES} ${QGLVIEWER_LIBRARIES} ) target_link_libraries( Periodic_Lloyd_3 ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} ) -else( CGAL_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND AND QT_QCOLLECTIONGENERATOR_EXECUTABLE ) +else( CGAL_FOUND AND Qt5_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND AND QT_QCOLLECTIONGENERATOR_EXECUTABLE ) set(PERIODIC_LLOYD_MISSING_DEPS "") if(NOT CGAL_FOUND) - set(PERIODIC_LLOYD_MISSING_DEPS "the CGAL Qt4 library, ${PERIODIC_LLOYD_MISSING_DEPS}") + set(PERIODIC_LLOYD_MISSING_DEPS "the CGAL Qt5 library, ${PERIODIC_LLOYD_MISSING_DEPS}") endif() - if(NOT QT4_FOUND) - set(PERIODIC_LLOYD_MISSING_DEPS "Qt4, ${PERIODIC_LLOYD_MISSING_DEPS}") + if(NOT Qt5_FOUND) + set(PERIODIC_LLOYD_MISSING_DEPS "Qt5, ${PERIODIC_LLOYD_MISSING_DEPS}") endif() if(NOT OPENGL_FOUND) @@ -90,4 +87,4 @@ else( CGAL_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND AND QT_QCOLL message(STATUS "NOTICE: This demo requires ${PERIODIC_LLOYD_MISSING_DEPS}and will not be compiled.") -endif( CGAL_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND AND QT_QCOLLECTIONGENERATOR_EXECUTABLE ) +endif() diff --git a/Periodic_3_triangulation_3/demo/Periodic_Lloyd_3/MainWindow.cpp b/Periodic_3_triangulation_3/demo/Periodic_Lloyd_3/MainWindow.cpp index 3cd1ad76ca5..8b822f4c70d 100644 --- a/Periodic_3_triangulation_3/demo/Periodic_Lloyd_3/MainWindow.cpp +++ b/Periodic_3_triangulation_3/demo/Periodic_Lloyd_3/MainWindow.cpp @@ -89,7 +89,8 @@ void MainWindow::newPointSet() { bool ok; - int numberOfPoints = QInputDialog::getInteger(this, + + int numberOfPoints = QInputDialog::getInt(this, "Periodic Lloyd", "Number of points: ", 100, 0, 2147483647, 1, &ok ); if (ok) newPoints(numberOfPoints); @@ -103,7 +104,7 @@ MainWindow::loadPoints() ".", tr("All files (*)")); if(fileName.isEmpty()) return; - std::ifstream ifs(fileName.toAscii().data() ); + std::ifstream ifs(fileName.toLatin1().data() ); scene.points.clear(); Iso_cuboid_3 dom; ifs >> dom; @@ -141,7 +142,7 @@ MainWindow::savePoints() ".", tr("*.pts")); if(fileName.isEmpty()) return; - std::ofstream ofs(fileName.toAscii().data() ); + std::ofstream ofs(fileName.toLatin1().data() ); ofs << scene.periodic_triangulation.domain() << '\n'; for (std::list::iterator pit = scene.points.begin() ; pit != scene.points.end() ; ++pit) ofs << *pit << '\n'; @@ -150,6 +151,7 @@ MainWindow::savePoints() void MainWindow::lloydStep() { scene.lloyd_step(); viewer->updateGL(); + viewer->changed(); } void diff --git a/Periodic_3_triangulation_3/demo/Periodic_Lloyd_3/MainWindow.h b/Periodic_3_triangulation_3/demo/Periodic_Lloyd_3/MainWindow.h index d39cea89a87..18b8bd1814a 100644 --- a/Periodic_3_triangulation_3/demo/Periodic_Lloyd_3/MainWindow.h +++ b/Periodic_3_triangulation_3/demo/Periodic_Lloyd_3/MainWindow.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include diff --git a/Periodic_3_triangulation_3/demo/Periodic_Lloyd_3/Periodic_Lloyd_3.cpp b/Periodic_3_triangulation_3/demo/Periodic_Lloyd_3/Periodic_Lloyd_3.cpp index 3bd16d35fa9..789f308b1f2 100644 --- a/Periodic_3_triangulation_3/demo/Periodic_Lloyd_3/Periodic_Lloyd_3.cpp +++ b/Periodic_3_triangulation_3/demo/Periodic_Lloyd_3/Periodic_Lloyd_3.cpp @@ -9,10 +9,12 @@ int main(int argc, char** argv) application.setOrganizationDomain("inria.fr"); application.setOrganizationName("INRIA"); application.setApplicationName("3D Periodic Lloyd"); + //for windows + application.setAttribute(Qt::AA_UseDesktopOpenGL); - // Import resources from libCGALQt4. - // See http://doc.trolltech.com/4.4/qdir.html#Q_INIT_RESOURCE - CGAL_QT4_INIT_RESOURCES; + // Import resources from libCGAL (QT5). + // See http://doc.qt.io/qt-5/qdir.html#Q_INIT_RESOURCE + CGAL_QT_INIT_RESOURCES; Q_INIT_RESOURCE(Periodic_Lloyd_3); MainWindow mw; diff --git a/Periodic_3_triangulation_3/demo/Periodic_Lloyd_3/Viewer.cpp b/Periodic_3_triangulation_3/demo/Periodic_Lloyd_3/Viewer.cpp index 84fc2bd4e84..eabf845b13d 100644 --- a/Periodic_3_triangulation_3/demo/Periodic_Lloyd_3/Viewer.cpp +++ b/Periodic_3_triangulation_3/demo/Periodic_Lloyd_3/Viewer.cpp @@ -7,160 +7,90 @@ void Viewer::init() { + initializeOpenGLFunctions(); setBackgroundColor(::Qt::white); this->camera()->setSceneBoundingBox( qglviewer::Vec(-1.,-1.,-1.), qglviewer::Vec( 1., 1., 1.)); + glEnable(GL_LINE_SMOOTH); + compile_shaders(); + are_buffers_initialized = false; } - void Viewer::sceneChanged() { + changed(); this->showEntireScene(); } void Viewer::draw() { - - // define material - float ambient[] = { 0.25f, - 0.20725f, - 0.20725f, - 0.922f }; - float diffuse[] = { 1.0f, - 0.829f, - 0.829f, - 0.922f }; - - float specular[] = { 0.296648f, - 0.296648f, - 0.296648f, - 0.522f }; - - float emission[] = { 0.3f, - 0.3f, - 0.3f, - 1.0f }; - float shininess[] = { 11.264f }; - - // apply material - ::glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT, ambient); - ::glMaterialfv( GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse); - ::glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, specular); - ::glMaterialfv( GL_FRONT_AND_BACK, GL_SHININESS, shininess); - ::glMaterialfv( GL_FRONT_AND_BACK, GL_EMISSION, emission); - - // anti-aliasing (if the OpenGL driver permits that) - ::glEnable(GL_LINE_SMOOTH); - - ::glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); - // draw surface mesh - bool m_view_surface = true; - bool draw_triangles_edges = true; - - if(m_view_surface) - { - ::glEnable(GL_LIGHTING); - ::glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); - ::glColor3f(0.2f, 0.2f, 1.f); - ::glEnable(GL_POLYGON_OFFSET_FILL); - ::glPolygonOffset(3.0f,-3.0f); - gl_draw_surface(); - - if(draw_triangles_edges) - { - ::glDisable(GL_LIGHTING); - ::glLineWidth(1.); - ::glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); - ::glColor3ub(0,0,0); - ::glDisable(GL_POLYGON_OFFSET_FILL); - gl_draw_surface(); - } - } -} - -void -Viewer::gl_draw_surface() -{ - ::glColor3f(1.0f, 0.72f, 0.06f); - ::glDisable(GL_LIGHTING); - + if(!are_buffers_initialized) + initialize_buffers(); + QColor color; + //the points ::glEnable(GL_BLEND); ::glEnable(GL_POINT_SMOOTH); ::glHint(GL_POINT_SMOOTH_HINT, GL_NICEST); ::glEnable(GL_LINE_SMOOTH); ::glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); ::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - ::glPointSize(5); - ::glBegin(GL_POINTS); - for(Periodic_point_iterator ppit - = scene->periodic_triangulation.periodic_points_begin( - P3DT3::UNIQUE) ; - ppit != scene->periodic_triangulation.periodic_points_end(P3DT3::UNIQUE); - ++ppit){ - Point_3 p(scene->periodic_triangulation.point(*ppit)); - ::glVertex3d(p.x(), p.y(), p.z()); - } - ::glEnd(); - ::glBegin(GL_LINES); + ::glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); + ::glColor3f(0.2f, 0.2f, 1.f); + ::glEnable(GL_POLYGON_OFFSET_FILL); + ::glPolygonOffset(3.0f,-3.0f); - ::glColor3f(0.27f, 0.51f, 0.7f); - for (Periodic_triangle_iterator ptit - = scene->periodic_triangulation.periodic_triangles_begin( - P3DT3::UNIQUE); - ptit != scene->periodic_triangulation.periodic_triangles_end( - P3DT3::UNIQUE); - ++ptit) { - for (int i=0 ; i<4 ; i++) { - Segment_3 dual = scene->periodic_triangulation.segment( - scene->periodic_triangulation.dual(*(ptit.get_facet()))); + attrib_buffers(this); + vao[0].bind(); + color.setRgbF(1.0f, 0.72f, 0.06f); + rendering_program.bind(); + rendering_program.setUniformValue(colorLocation[0], color); + glDrawArrays(GL_POINTS, 0, static_cast(pos_points.size()/3)); + rendering_program.release(); + vao[0].release(); - FT sz = dual.source().z(); - FT tz = dual.target().z(); + //The Lines + ::glLineWidth(1.); + ::glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); + ::glColor3ub(0,0,0); + ::glDisable(GL_POLYGON_OFFSET_FILL); - if (scene->two_dimensional && ((sz-tz > 0.5) || (sz-tz < -0.5))) continue; - - if (scene->two_dimensional) { sz = 0.; tz = 0.; } - FT sx = dual.source().x(); - FT tx = dual.target().x(); - FT sy = dual.source().y(); - FT ty = dual.target().y(); + vao[1].bind(); + color.setRgbF(0.27f, 0.51f, 0.7f); + rendering_program.bind(); + rendering_program.setUniformValue(colorLocation[0], color); + glDrawArrays(GL_LINES, 0, static_cast(pos_lines.size()/3)); + rendering_program.release(); + vao[1].release(); - ::glVertex3d(sx,sy,sz); ::glVertex3d(tx,ty,tz); - Iso_cuboid_3 d = scene->periodic_triangulation.domain(); - if (scene->eight_copies) { - ::glColor3f(0.69f, 0.77f, 0.87f); - ::glVertex3d(sx+0.,sy+d.ymax()-d.ymin(),sz+0.); - ::glVertex3d(tx+0.,ty+d.ymax()-d.ymin(),tz+0.); - ::glVertex3d(sx+d.xmax()-d.xmin(),sy+0.,sz+0.); - ::glVertex3d(tx+d.xmax()-d.xmin(),ty+0.,tz+0.); - ::glVertex3d(sx+d.xmax()-d.xmin(),sy+d.ymax()-d.ymin(),sz+0.); - ::glVertex3d(tx+d.xmax()-d.xmin(),ty+d.ymax()-d.ymin(),tz+0.); - if (!scene->two_dimensional) { - ::glVertex3d(sx+0.,sy+0.,sz+d.zmax()-d.zmin()); - ::glVertex3d(tx+0.,ty+0.,tz+d.zmax()-d.zmin()); - ::glVertex3d(sx+0.,sy+d.ymax()-d.ymin(),sz+d.zmax()-d.zmin()); - ::glVertex3d(tx+0.,ty+d.ymax()-d.ymin(),tz+d.zmax()-d.zmin()); - ::glVertex3d(sx+d.xmax()-d.xmin(),sy+0.,sz+d.zmax()-d.zmin()); - ::glVertex3d(tx+d.xmax()-d.xmin(),ty+0.,tz+d.zmax()-d.zmin()); - ::glVertex3d(sx+d.xmax()-d.xmin(),sy+d.ymax()-d.ymin(),sz+d.zmax()-d.zmin()); - ::glVertex3d(tx+d.xmax()-d.xmin(),ty+d.ymax()-d.ymin(),tz+d.zmax()-d.zmin()); - } - ::glColor3f(0.27f, 0.51f, 0.7f); + if (scene->eight_copies) { + vao[2].bind(); + color.setRgbF(0.69f, 0.77f, 0.87f); + rendering_program.bind(); + rendering_program.setUniformValue(colorLocation[0], color); + glDrawArrays(GL_LINES, 0, static_cast(pos_8lines2D.size()/3)); + rendering_program.release(); + vao[2].release(); + + if (!scene->two_dimensional) { + vao[3].bind(); + color.setRgbF(0.69f, 0.77f, 0.87f); + rendering_program.bind(); + rendering_program.setUniformValue(colorLocation[0], color); + glDrawArrays(GL_LINES, 0, static_cast(pos_8lines.size()/3)); + rendering_program.release(); + vao[3].release(); } - } } - - ::glEnd(); - ::glEnable(GL_LIGHTING); } + Viewer::Vec Viewer::next_around_circle(const float& phi, const Vec& pos, const Vec& ori) { Vec cam = pos-ori; @@ -196,5 +126,194 @@ Viewer::render_video() } } +void Viewer::initialize_buffers() +{ + rendering_program.bind(); + vao[0].bind(); + buffers[0].bind(); + buffers[0].allocate(pos_points.data(), static_cast(pos_points.size()*sizeof(float))); + vertexLocation[0] = rendering_program.attributeLocation("vertex"); + rendering_program.enableAttributeArray(vertexLocation[0]); + rendering_program.setAttributeBuffer(vertexLocation[0],GL_FLOAT,0,3); + buffers[0].release(); + + vao[0].release(); + + vao[1].bind(); + buffers[1].bind(); + buffers[1].allocate(pos_lines.data(), static_cast(pos_lines.size()*sizeof(float))); + vertexLocation[0] = rendering_program.attributeLocation("vertex"); + rendering_program.enableAttributeArray(vertexLocation[0]); + rendering_program.setAttributeBuffer(vertexLocation[0],GL_FLOAT,0,3); + buffers[1].release(); + vao[1].release(); + + vao[2].bind(); + buffers[2].bind(); + buffers[2].allocate(pos_8lines2D.data(), static_cast(pos_8lines2D.size()*sizeof(float))); + vertexLocation[0] = rendering_program.attributeLocation("vertex"); + rendering_program.enableAttributeArray(vertexLocation[0]); + rendering_program.setAttributeBuffer(vertexLocation[0],GL_FLOAT,0,3); + buffers[2].release(); + vao[2].release(); + + vao[3].bind(); + buffers[3].bind(); + buffers[3].allocate(pos_8lines.data(), static_cast(pos_8lines.size()*sizeof(float))); + vertexLocation[0] = rendering_program.attributeLocation("vertex"); + rendering_program.enableAttributeArray(vertexLocation[0]); + rendering_program.setAttributeBuffer(vertexLocation[0],GL_FLOAT,0,3); + buffers[3].release(); + vao[3].release(); + rendering_program.release(); + are_buffers_initialized = true; +} + +void Viewer::compute_elements() +{ + //::glColor3f(1.0f, 0.72f, 0.06f); + pos_points.resize(0); + pos_lines.resize(0); + pos_8lines.resize(0); + pos_8lines2D.resize(0); + + for(Periodic_point_iterator ppit + = scene->periodic_triangulation.periodic_points_begin( + P3DT3::UNIQUE) ; + ppit != scene->periodic_triangulation.periodic_points_end(P3DT3::UNIQUE); + ++ppit){ + Point_3 p(scene->periodic_triangulation.point(*ppit)); + pos_points.push_back(p.x()); pos_points.push_back(p.y()); pos_points.push_back(p.z()); + } + + //::glColor3f(0.27f, 0.51f, 0.7f); + for (Periodic_triangle_iterator ptit + = scene->periodic_triangulation.periodic_triangles_begin( + P3DT3::UNIQUE); + ptit != scene->periodic_triangulation.periodic_triangles_end( + P3DT3::UNIQUE); + ++ptit) { + for (int i=0 ; i<4 ; i++) { + Segment_3 dual = scene->periodic_triangulation.segment( + scene->periodic_triangulation.dual(*(ptit.get_facet()))); + + FT sz = dual.source().z(); + FT tz = dual.target().z(); + + if (scene->two_dimensional && ((sz-tz > 0.5) || (sz-tz < -0.5))) continue; + + if (scene->two_dimensional) { sz = 0.; tz = 0.; } + FT sx = dual.source().x(); + FT tx = dual.target().x(); + FT sy = dual.source().y(); + FT ty = dual.target().y(); + pos_lines.push_back(sx); pos_lines.push_back(sy); pos_lines.push_back(sz); + pos_lines.push_back(tx); pos_lines.push_back(ty); pos_lines.push_back(tz); + Iso_cuboid_3 d = scene->periodic_triangulation.domain(); + + pos_8lines2D.push_back(sx+0.); pos_8lines2D.push_back(sy+d.ymax()-d.ymin()); pos_8lines2D.push_back(sz+0.); + pos_8lines2D.push_back(tx+0.); pos_8lines2D.push_back(ty+d.ymax()-d.ymin()); pos_8lines2D.push_back(tz+0.); + pos_8lines2D.push_back(sx+d.xmax()-d.xmin()); pos_8lines2D.push_back(sy+0.); pos_8lines2D.push_back(sz+0.); + pos_8lines2D.push_back(tx+d.xmax()-d.xmin()); pos_8lines2D.push_back(ty+0.); pos_8lines2D.push_back(tz+0.); + pos_8lines2D.push_back(sx+d.xmax()-d.xmin()); pos_8lines2D.push_back(sy+d.ymax()-d.ymin()); pos_8lines2D.push_back(sz+0.); + pos_8lines2D.push_back(tx+d.xmax()-d.xmin()); pos_8lines2D.push_back(ty+d.ymax()-d.ymin()); pos_8lines2D.push_back(tz+0.); + + pos_8lines.push_back(sx+0.); pos_8lines.push_back(sy+0.); pos_8lines.push_back(sz+d.zmax()-d.zmin()); + pos_8lines.push_back(tx+0.); pos_8lines.push_back(ty+0.); pos_8lines.push_back(tz+d.zmax()-d.zmin()); + pos_8lines.push_back(sx+0.); pos_8lines.push_back(sy+d.ymax()-d.ymin()); pos_8lines.push_back(sz+d.zmax()-d.zmin()); + pos_8lines.push_back(tx+0.); pos_8lines.push_back(ty+d.ymax()-d.ymin()); pos_8lines.push_back(tz+d.zmax()-d.zmin()); + pos_8lines.push_back(sx+d.xmax()-d.xmin()); pos_8lines.push_back(sy+0.); pos_8lines.push_back(sz+d.zmax()-d.zmin()); + pos_8lines.push_back(tx+d.xmax()-d.xmin()); pos_8lines.push_back(ty+0.); pos_8lines.push_back(tz+d.zmax()-d.zmin()); + pos_8lines.push_back(sx+d.xmax()-d.xmin()); pos_8lines.push_back(sy+d.ymax()-d.ymin()); pos_8lines.push_back(sz+d.zmax()-d.zmin()); + pos_8lines.push_back(tx+d.xmax()-d.xmin()); pos_8lines.push_back(ty+d.ymax()-d.ymin()); pos_8lines.push_back(tz+d.zmax()-d.zmin()); + } + + } +} + +void Viewer::attrib_buffers(QGLViewer* viewer) +{ + QMatrix4x4 mvpMatrix; + double mat[16]; + viewer->camera()->getModelViewProjectionMatrix(mat); + for(int i=0; i < 16; i++) + { + mvpMatrix.data()[i] = (float)mat[i]; + } + + rendering_program.bind(); + mvpLocation[0] = rendering_program.uniformLocation("mvp_matrix"); + colorLocation[0] = rendering_program.uniformLocation("color"); + rendering_program.setUniformValue(mvpLocation[0], mvpMatrix); + + rendering_program.release(); +} + +void Viewer::compile_shaders() +{ + if(! buffers[0].create() || !buffers[1].create() || !buffers[2].create() || !buffers[3].create()) + { + std::cerr<<"VBO Creation FAILED"<compileSourceCode(vertex_source)) + { + std::cerr<<"Compiling vertex source FAILED"<compileSourceCode(fragment_source)) + { + std::cerr<<"Compiling fragmentsource FAILED"< +#include +#include +#include +#include +#include -class Viewer : public QGLViewer { +class Viewer : public QGLViewer, QOpenGLFunctions_3_3_Core { typedef qglviewer::Vec Vec; @@ -17,8 +22,16 @@ class Viewer : public QGLViewer { int nr_of_facets; public: Viewer(QWidget* parent) - : QGLViewer(parent) + : QGLViewer(CGAL::Qt::createOpenGLContext(), parent) {} + ~Viewer() + { + for(int i=0; i<4; i++) + { + buffers[i].destroy(); + vao[i].destroy(); + } + } void setScene(Scene* scene_) { @@ -31,11 +44,9 @@ public: public: void draw(); - void gl_draw_surface(); - public slots : - + void changed(); void sceneChanged(); void render_video(); @@ -44,6 +55,25 @@ signals: private: Vec next_around_circle(const float& phi, const Vec& pos, const Vec& ori); + + int vertexLocation[3]; + int mvpLocation[3]; + int colorLocation[3]; + + bool are_buffers_initialized; + std::vector pos_points; + std::vector pos_lines; + std::vector pos_8lines2D; + std::vector pos_8lines; + + + QOpenGLBuffer buffers[4]; + QOpenGLVertexArrayObject vao[4]; + QOpenGLShaderProgram rendering_program; + void initialize_buffers(); + void compute_elements(); + void attrib_buffers(QGLViewer*); + void compile_shaders(); }; #endif diff --git a/Point_set_processing_3/examples/Point_set_processing_3/CMakeLists.txt b/Point_set_processing_3/examples/Point_set_processing_3/CMakeLists.txt index e131f62a7af..770761fa4cb 100644 --- a/Point_set_processing_3/examples/Point_set_processing_3/CMakeLists.txt +++ b/Point_set_processing_3/examples/Point_set_processing_3/CMakeLists.txt @@ -2,12 +2,8 @@ project( Point_set_processing_3_example ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) -endif() +cmake_minimum_required(VERSION 2.8.11) + # Require packages new or improved since CGAL 3.4 include_directories (BEFORE ../../../Installation/include/) diff --git a/Point_set_processing_3/test/Point_set_processing_3/CMakeLists.txt b/Point_set_processing_3/test/Point_set_processing_3/CMakeLists.txt index 96fba597c2c..6ee5d8641b6 100644 --- a/Point_set_processing_3/test/Point_set_processing_3/CMakeLists.txt +++ b/Point_set_processing_3/test/Point_set_processing_3/CMakeLists.txt @@ -2,12 +2,8 @@ project( Point_set_processing_3_test ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) -endif() +cmake_minimum_required(VERSION 2.8.11) + # Require packages new or improved since CGAL 3.4 include_directories (BEFORE ../../../Installation/include/) diff --git a/Polyhedron/demo/Polyhedron/CGAL_demo/Scene_interface.h b/Polyhedron/demo/Polyhedron/CGAL_demo/Scene_interface.h index 9ac8df9842a..1cae5d3f22b 100644 --- a/Polyhedron/demo/Polyhedron/CGAL_demo/Scene_interface.h +++ b/Polyhedron/demo/Polyhedron/CGAL_demo/Scene_interface.h @@ -12,7 +12,6 @@ class Scene_item; // OpenGL rendering mode enum RenderingMode { Points = 0, PointsPlusNormals, - Splatting, Wireframe, Flat, FlatPlusEdges, diff --git a/Polyhedron/demo/Polyhedron/CGAL_demo/Scene_item_with_display_list.h b/Polyhedron/demo/Polyhedron/CGAL_demo/Scene_item_with_display_list.h index f93eb11f4a4..821e51e37e0 100644 --- a/Polyhedron/demo/Polyhedron/CGAL_demo/Scene_item_with_display_list.h +++ b/Polyhedron/demo/Polyhedron/CGAL_demo/Scene_item_with_display_list.h @@ -3,11 +3,8 @@ #include "Scene_item.h" #include -#ifdef CGAL_GLEW_ENABLED -# include -#else # include -#endif + class Viewer_interface; diff --git a/Polyhedron/demo/Polyhedron/CGAL_demo/Viewer_interface.h b/Polyhedron/demo/Polyhedron/CGAL_demo/Viewer_interface.h index 62dc559216c..fc61ad892a0 100644 --- a/Polyhedron/demo/Polyhedron/CGAL_demo/Viewer_interface.h +++ b/Polyhedron/demo/Polyhedron/CGAL_demo/Viewer_interface.h @@ -4,7 +4,7 @@ #include #include #include - +#include // forward declarations class QWidget; class Scene_draw_interface; @@ -18,8 +18,8 @@ class VIEWER_EXPORT Viewer_interface : public QGLViewer { Q_OBJECT public: - Viewer_interface(QWidget* parent) : QGLViewer(parent) {}; - virtual ~Viewer_interface() {}; + Viewer_interface(QWidget* parent) : QGLViewer(CGAL::Qt::createOpenGLContext(), parent) {} + virtual ~Viewer_interface() {} virtual void setScene(Scene_draw_interface* scene) = 0; virtual bool antiAliasing() const = 0; diff --git a/Polyhedron/demo/Polyhedron/CMakeLists.txt b/Polyhedron/demo/Polyhedron/CMakeLists.txt index b30f37230d6..2022a2ea6eb 100644 --- a/Polyhedron/demo/Polyhedron/CMakeLists.txt +++ b/Polyhedron/demo/Polyhedron/CMakeLists.txt @@ -1,12 +1,13 @@ # This is the CMake script for compiling the CGAL Polyhedron demo. project( Polyhedron ) - -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +# Find includes in corresponding build directories +set(CMAKE_INCLUDE_CURRENT_DIR ON) +# Instruct CMake to run moc automatically when needed. +set(CMAKE_AUTOMOC ON) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() # Compatibility with CMake 3.0 @@ -39,14 +40,12 @@ include_directories( BEFORE ./ ./include ../../include ./CGAL_demo ../../../Adva add_subdirectory( implicit_functions ) -# Find CGAL and CGAL Qt4 -find_package(CGAL COMPONENTS Qt4) -include( ${CGAL_USE_FILE} ) +# Find CGAL option( POLYHEDRON_QTSCRIPT_DEBUGGER "Activate the use of Qt Script Debugger in Polyhedron_3 demo" OFF) -# Find Qt4 itself +# Find Qt5 itself set( QT_USE_QTXML TRUE ) set( QT_USE_QTMAIN TRUE ) set( QT_USE_QTSCRIPT TRUE ) @@ -54,96 +53,66 @@ set( QT_USE_QTOPENGL TRUE ) if( POLYHEDRON_QTSCRIPT_DEBUGGER) set( QT_USE_QTSCRIPTTOOLS TRUE ) endif() -find_package(Qt4) - -# Find Glew (optional), for splatting -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/GlSplat/cmake) -find_package(GLEW) +find_package(CGAL COMPONENTS Qt5) +include( ${CGAL_USE_FILE} ) +find_package(Qt5 QUIET COMPONENTS OpenGL Script Svg Xml ScriptTools) # Find OpenGL find_package(OpenGL) # Find QGLViewer -if(QT4_FOUND) +if(Qt5_FOUND) add_definitions(-DQT_NO_KEYWORDS) - - include(${QT_USE_FILE}) include_directories( ${QT_INCLUDE_DIR}/QtScriptTools ) find_package(QGLViewer ) -endif(QT4_FOUND) -if(GLEW_FOUND) - include_directories ( ${GLEW_INCLUDE_DIR} ) - add_definitions(-DCGAL_GLEW_ENABLED) -else(GLEW_FOUND) - message(STATUS "NOTICE: GLEW library is not found. Splat rendering will not be available.") -endif(GLEW_FOUND) +endif(Qt5_FOUND) find_package(Eigen3 3.1.0) #(requires 3.1.0 or greater) if (EIGEN3_FOUND) include( ${EIGEN3_USE_FILE} ) endif(EIGEN3_FOUND) -if(CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) + +if(CGAL_Qt5_FOUND AND Qt5_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) set(Boost_USE_MULTITHREADED ON) find_package(Boost COMPONENTS thread system) include_directories ( ${QGLVIEWER_INCLUDE_DIR} ) - qt4_wrap_ui( MainWindowUI_files MainWindow.ui ) - qt4_wrap_ui( FileLoaderDialogUI_files FileLoaderDialog.ui ) - qt4_wrap_ui( Show_point_dialogUI_FILES Show_point_dialog.ui ) - qt4_wrap_ui( remeshingUI_FILES Remeshing_dialog.ui) - qt4_wrap_ui( Mean_curvature_flow_skeleton_pluginUI_FILES Mean_curvature_flow_skeleton_plugin.ui) - qt4_wrap_ui( meshingUI_FILES Meshing_dialog.ui ) - qt4_wrap_ui( cameraUI_FILES Camera_positions_list.ui ) - qt4_wrap_ui( PreferencesUI_FILES Preferences.ui ) - qt4_wrap_ui( point_inside_polyhedronUI_FILES Point_inside_polyhedron_widget.ui) - qt4_wrap_ui( polyhedron_slicerUI_FILES Polyhedron_slicer_widget.ui) - qt4_wrap_ui( segmentationUI_FILES Mesh_segmentation_widget.ui) - qt4_wrap_ui( hole_fillingUI_FILES Hole_filling_widget.ui) - qt4_wrap_ui( fairingUI_FILES Fairing_widget.ui) - qt4_wrap_ui( selectionUI_FILES Selection_widget.ui) - qt4_wrap_ui( funcUI_FILES Function_dialog.ui ) - qt4_wrap_ui( shortestPathUI_FILES Shortest_path_widget.ui ) + qt5_wrap_ui( MainWindowUI_files MainWindow.ui ) + qt5_wrap_ui( FileLoaderDialogUI_files FileLoaderDialog.ui ) + qt5_wrap_ui( Show_point_dialogUI_FILES Show_point_dialog.ui ) + qt5_wrap_ui( remeshingUI_FILES Remeshing_dialog.ui) + qt5_wrap_ui( Mean_curvature_flow_skeleton_pluginUI_FILES Mean_curvature_flow_skeleton_plugin.ui) + qt5_wrap_ui( meshingUI_FILES Meshing_dialog.ui ) + qt5_wrap_ui( cameraUI_FILES Camera_positions_list.ui ) + qt5_wrap_ui( PreferencesUI_FILES Preferences.ui ) + qt5_wrap_ui( point_inside_polyhedronUI_FILES Point_inside_polyhedron_widget.ui) + qt5_wrap_ui( polyhedron_slicerUI_FILES Polyhedron_slicer_widget.ui) + qt5_wrap_ui( segmentationUI_FILES Mesh_segmentation_widget.ui) + qt5_wrap_ui( hole_fillingUI_FILES Hole_filling_widget.ui) + qt5_wrap_ui( fairingUI_FILES Fairing_widget.ui) + qt5_wrap_ui( selectionUI_FILES Selection_widget.ui) + qt5_wrap_ui( funcUI_FILES Function_dialog.ui ) + qt5_wrap_ui( shortestPathUI_FILES Shortest_path_widget.ui ) - qt4_generate_moc( "MainWindow.h" "${CMAKE_CURRENT_BINARY_DIR}/MainWindow_moc.cpp" ) - qt4_generate_moc( "File_loader_dialog.h" "${CMAKE_CURRENT_BINARY_DIR}/File_loader_dialog_moc.cpp" ) + qt5_generate_moc( "MainWindow.h" "${CMAKE_CURRENT_BINARY_DIR}/MainWindow_moc.cpp" ) + qt5_generate_moc( "File_loader_dialog.h" "${CMAKE_CURRENT_BINARY_DIR}/File_loader_dialog_moc.cpp" ) add_file_dependencies( MainWindow_moc.cpp "${CMAKE_CURRENT_SOURCE_DIR}/MainWindow.h" ) add_file_dependencies( File_loader_dialog_moc_moc.cpp "${CMAKE_CURRENT_SOURCE_DIR}/File_loader_dialog.h" ) - qt4_generate_moc( "Viewer.h" "${CMAKE_CURRENT_BINARY_DIR}/Viewer_moc.cpp" ) + qt5_generate_moc( "Viewer.h" "${CMAKE_CURRENT_BINARY_DIR}/Viewer_moc.cpp" ) add_file_dependencies( Viewer_moc.cpp "${CMAKE_CURRENT_SOURCE_DIR}/Viewer.h" ) include( ${CMAKE_CURRENT_SOURCE_DIR}/polyhedron_demo_macros.cmake ) - qt4_add_resources ( RESOURCE_FILES Polyhedron_3.qrc ) - qt4_generate_moc( "CGAL_demo/Viewer_interface.h" "${CMAKE_CURRENT_BINARY_DIR}/Viewer_interface_moc.cpp" ) + qt5_add_resources ( RESOURCE_FILES Polyhedron_3.qrc ) - qt4_automoc(Scene.cpp - Scene_item.cpp - Scene_plane_item.cpp - Scene_combinatorial_map_item.cpp - Scene_polygon_soup_item.cpp - Scene_polyhedron_item.cpp - Scene_polyhedron_transform_item.cpp - Scene_polylines_item.cpp - Scene_textured_polyhedron_item.cpp - Scene_c2t3_item.cpp - Scene_nef_polyhedron_item.cpp - Show_point_dialog.cpp - Mesher_base.cpp - Camera_positions_list.cpp - Scene_points_with_normal_item.cpp - Scene_polyhedron_item_decorator.cpp - Scene_polyhedron_selection_item.cpp - Scene_polyhedron_item_k_ring_selection.cpp - Scene_polyhedron_shortest_path_item.cpp - ) - qt4_automoc( Scene_implicit_function_item.cpp ) + qt5_generate_moc( "CGAL_demo/Viewer_interface.h" "${CMAKE_CURRENT_BINARY_DIR}/Viewer_interface_moc.cpp" ) # AUXILIARY LIBRARIES @@ -155,10 +124,12 @@ if(CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) add_library(demo_framework SHARED Scene.cpp - Viewer.cpp Viewer_moc.cpp Viewer_interface_moc.cpp - Scene_item.cpp Scene_item.moc - Scene_item_with_display_list.cpp + Viewer.cpp #Viewer_moc.cpp + Viewer_interface_moc.cpp + Scene_item.cpp #Scene_item.moc + #Scene_item_with_display_list.cpp Polyhedron_demo_plugin_helper.cpp) + qt5_use_modules(demo_framework OpenGL Gui Widgets Script Xml) target_link_libraries(demo_framework ${QGLVIEWER_LIBRARIES} @@ -168,7 +139,9 @@ if(CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) ) add_library(scene_basic_objects SHARED - Scene_plane_item.cpp Scene_plane_item.moc) + Scene_plane_item.cpp + #Scene_plane_item.moc +) target_link_libraries(scene_basic_objects demo_framework ${CGAL_LIBRARIES} @@ -177,62 +150,55 @@ if(CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} ) - + qt5_use_modules(scene_basic_objects OpenGL Gui Xml Script Widgets) add_library(point_dialog SHARED Show_point_dialog.cpp Show_point_dialog.ui ${Show_point_dialogUI_FILES}) + qt5_use_modules(point_dialog OpenGL Gui Xml Script Widgets) target_link_libraries(point_dialog ${QT_LIBRARIES}) macro(add_item item_name) add_library(${item_name} SHARED ${ARGN}) + qt5_use_modules(${item_name} OpenGL Gui Xml Script Widgets) target_link_libraries(${item_name} demo_framework ${QT_LIBRARIES} ${CGAL_LIBRARIES} ${Boost_LIBRARIES}) endmacro(add_item) - add_item(scene_c2t3_item Scene_c2t3_item.cpp Scene_c2t3_item.moc) - add_item(scene_polyhedron_item Scene_polyhedron_item.cpp Scene_polyhedron_item.moc) - add_item(scene_polyhedron_transform_item Scene_polyhedron_transform_item.cpp Scene_polyhedron_transform_item.moc) + add_item(scene_c2t3_item Scene_c2t3_item.cpp)# Scene_c2t3_item.moc) + add_item(scene_polyhedron_item Scene_polyhedron_item.cpp)# Scene_polyhedron_item.moc) + add_item(scene_polyhedron_transform_item Scene_polyhedron_transform_item.cpp )#Scene_polyhedron_transform_item.moc) # special target_link_libraries(scene_polyhedron_transform_item scene_polyhedron_item) - if(GLEW_FOUND) - qt4_add_resources(gl_splat_rc GlSplat/glsplat.qrc) - add_library(gl_splat SHARED - GlSplat/GlSplat.cpp GlSplat/Shader.cpp ${gl_splat_rc}) - target_link_libraries(gl_splat ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTOPENGL_LIBRARY} ${GLEW_LIBRARIES}) - endif(GLEW_FOUND) - - add_item(scene_combinatorial_map_item Scene_combinatorial_map_item.cpp Scene_combinatorial_map_item.moc) + add_item(scene_combinatorial_map_item Scene_combinatorial_map_item.cpp)# Scene_combinatorial_map_item.moc) # special target_link_libraries(scene_combinatorial_map_item scene_polyhedron_item) - add_item(scene_polylines_item Scene_polylines_item.cpp Scene_polylines_item.moc) + add_item(scene_polylines_item Scene_polylines_item.cpp)# Scene_polylines_item.moc) - add_item(scene_polyhedron_item_decorator Scene_polyhedron_item_decorator.cpp Scene_polyhedron_item_decorator.moc) + add_item(scene_polyhedron_item_decorator Scene_polyhedron_item_decorator.cpp )#Scene_polyhedron_item_decorator.moc) target_link_libraries(scene_polyhedron_item_decorator scene_polyhedron_item) - add_item(scene_polyhedron_item_k_ring_selection Scene_polyhedron_item_k_ring_selection.cpp Scene_polyhedron_item_k_ring_selection.moc) + add_item(scene_polyhedron_item_k_ring_selection Scene_polyhedron_item_k_ring_selection.cpp)# Scene_polyhedron_item_k_ring_selection.moc) target_link_libraries(scene_polyhedron_item_k_ring_selection scene_polyhedron_item) - add_item(scene_polyhedron_selection_item Scene_polyhedron_selection_item.cpp Scene_polyhedron_selection_item.moc) + add_item(scene_polyhedron_selection_item Scene_polyhedron_selection_item.cpp)# Scene_polyhedron_selection_item.moc) target_link_libraries(scene_polyhedron_selection_item scene_polyhedron_item_decorator scene_polyhedron_item_k_ring_selection) - add_item(scene_polyhedron_shortest_path_item Scene_polyhedron_shortest_path_item.cpp Scene_polyhedron_shortest_path_item.moc) + add_item(scene_polyhedron_shortest_path_item Scene_polyhedron_shortest_path_item.cpp) + target_link_libraries(scene_polyhedron_shortest_path_item scene_polyhedron_item_decorator scene_polyhedron_item scene_polylines_item) if(EIGEN3_FOUND ) - add_item(scene_textured_polyhedron_item Scene_textured_polyhedron_item.cpp texture.cpp Scene_textured_polyhedron_item.moc) + add_item(scene_textured_polyhedron_item Scene_textured_polyhedron_item.cpp texture.cpp)# Scene_textured_polyhedron_item.moc) endif() - add_item(scene_implicit_function_item Scene_implicit_function_item.cpp Scene_implicit_function_item.moc Color_ramp.cpp) + add_item(scene_implicit_function_item Scene_implicit_function_item.cpp Color_ramp.cpp )#Scene_implicit_function_item.moc) - add_item(scene_polygon_soup_item Scene_polygon_soup_item.cpp Scene_polygon_soup_item.moc) + add_item(scene_polygon_soup_item Scene_polygon_soup_item.cpp)# Scene_polygon_soup_item.moc) target_link_libraries(scene_polygon_soup_item scene_polyhedron_item) - add_item(scene_nef_polyhedron_item Scene_nef_polyhedron_item.cpp Scene_nef_polyhedron_item.moc + add_item(scene_nef_polyhedron_item Scene_nef_polyhedron_item.cpp# Scene_nef_polyhedron_item.moc + Scene_nef_rendering.cpp) target_link_libraries(scene_nef_polyhedron_item scene_polyhedron_item) - add_item(scene_points_with_normal_item Scene_points_with_normal_item.cpp Scene_points_with_normal_item.moc) - if(GLEW_FOUND) - target_link_libraries( scene_points_with_normal_item gl_splat ${GLEW_LIBRARIES} ) - target_link_libraries( demo_framework gl_splat ${GLEW_LIBRARIES} ) - endif(GLEW_FOUND) + add_item(scene_points_with_normal_item Scene_points_with_normal_item.cpp)# Scene_points_with_normal_item.moc) foreach( lib demo_framework @@ -247,15 +213,13 @@ if(CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) # if(POLYHEDRON_DEMO_ENABLE_FORWARD_DECL) set(CGAL_POLYHEDRON_DEMO_DEFINITIONS "-DUSE_FORWARD_DECL") add_definitions(${CGAL_POLYHEDRON_DEMO_DEFINITIONS}) - add_executable ( Polyhedron_3 MainWindow.cpp + add_executable ( Polyhedron_3 + MainWindow.cpp Polyhedron_3.cpp -# Viewer.cpp -# Scene.cpp - MainWindow_moc.cpp File_loader_dialog_moc.cpp -# Viewer_moc.cpp ${FileLoaderDialogUI_files} ${MainWindowUI_files} ${PreferencesUI_FILES} ${RESOURCE_FILES} ) add_to_cached_list( CGAL_EXECUTABLE_TARGETS Polyhedron_3 ) + qt5_use_modules(Polyhedron_3 Gui OpenGL Xml Widgets Script Svg ) if(EIGEN3_FOUND) # add_executable( Polyhedron_3 Scene_tex_rendering.cpp Scene_tex_polyhedron_operations.cpp ) endif() @@ -277,10 +241,6 @@ if(CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) target_link_libraries( Polyhedron_3 demo_framework ) target_link_libraries( Polyhedron_3 point_dialog ) - if(GLEW_FOUND) - target_link_libraries( Polyhedron_3 gl_splat ${GLEW_LIBRARIES} ) - endif(GLEW_FOUND) - # Link with CGAL target_link_libraries( Polyhedron_3 ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES} ) @@ -301,16 +261,16 @@ if(CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) polyhedron_demo_plugin(camera_positions_plugin Polyhedron_demo_camera_positions_plugin Camera_positions_list - Camera_positions_list.moc + #Camera_positions_list.moc ${cameraUI_FILES}) target_link_libraries( camera_positions_plugin ${QGLVIEWER_LIBRARIES} demo_framework) if ( Boost_VERSION GREATER 103400 ) - qt4_generate_moc( "Polyhedron_demo_mesh_3_plugin_cgal_code.cpp" "${CMAKE_CURRENT_BINARY_DIR}/Scene_c3t3_item.moc" ) + qt5_generate_moc( "Polyhedron_demo_mesh_3_plugin_cgal_code.cpp" "${CMAKE_CURRENT_BINARY_DIR}/Scene_c3t3_item.moc" ) polyhedron_demo_plugin(mesh_3_plugin Polyhedron_demo_mesh_3_plugin - Polyhedron_demo_mesh_3_plugin_cgal_code.cpp Scene_c3t3_item.moc + Polyhedron_demo_mesh_3_plugin_cgal_code.cpp #Scene_c3t3_item.moc ${meshingUI_FILES}) target_link_libraries(mesh_3_plugin scene_polyhedron_item scene_polygon_soup_item ${QGLVIEWER_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}) else( Boost_VERSION GREATER 103400 ) @@ -365,31 +325,31 @@ if(CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) polyhedron_demo_plugin(pca_plugin Polyhedron_demo_pca_plugin) target_link_libraries(pca_plugin scene_polyhedron_item scene_basic_objects) - qt4_wrap_ui( advancing_frontUI_FILES Polyhedron_demo_advancing_front_plugin.ui) + qt5_wrap_ui( advancing_frontUI_FILES Polyhedron_demo_advancing_front_plugin.ui) polyhedron_demo_plugin(advancing_front_plugin Polyhedron_demo_advancing_front_plugin ${advancing_frontUI_FILES}) target_link_libraries(advancing_front_plugin scene_polygon_soup_item scene_points_with_normal_item) if(EIGEN3_FOUND) - qt4_wrap_ui( scale_spaceUI_FILES Polyhedron_demo_scale_space_reconstruction_plugin.ui) + qt5_wrap_ui( scale_spaceUI_FILES Polyhedron_demo_scale_space_reconstruction_plugin.ui) polyhedron_demo_plugin(scale_space_reconstruction_plugin Polyhedron_demo_scale_space_reconstruction_plugin ${scale_spaceUI_FILES}) target_link_libraries(scale_space_reconstruction_plugin scene_polygon_soup_item scene_polyhedron_item scene_points_with_normal_item) polyhedron_demo_plugin(parameterization_plugin Polyhedron_demo_parameterization_plugin) target_link_libraries(parameterization_plugin scene_polyhedron_item scene_textured_polyhedron_item ) - qt4_wrap_ui( poissonUI_FILES Polyhedron_demo_poisson_plugin.ui) + qt5_wrap_ui( poissonUI_FILES Polyhedron_demo_poisson_plugin.ui) polyhedron_demo_plugin(poisson_plugin Polyhedron_demo_poisson_plugin Polyhedron_demo_poisson_plugin_impl.cpp ${poissonUI_FILES}) target_link_libraries(poisson_plugin scene_polyhedron_item scene_points_with_normal_item) - qt4_wrap_ui( normal_estimationUI_FILES Polyhedron_demo_normal_estimation_plugin.ui) + qt5_wrap_ui( normal_estimationUI_FILES Polyhedron_demo_normal_estimation_plugin.ui) polyhedron_demo_plugin(normal_estimation_plugin Polyhedron_demo_normal_estimation_plugin ${normal_estimationUI_FILES}) target_link_libraries(normal_estimation_plugin scene_points_with_normal_item) - qt4_wrap_ui( vcm_normal_estimationUI_FILES Polyhedron_demo_vcm_normal_estimation_plugin.ui) + qt5_wrap_ui( vcm_normal_estimationUI_FILES Polyhedron_demo_vcm_normal_estimation_plugin.ui) polyhedron_demo_plugin(vcm_normal_estimation_plugin Polyhedron_demo_vcm_normal_estimation_plugin ${vcm_normal_estimationUI_FILES}) target_link_libraries(vcm_normal_estimation_plugin scene_points_with_normal_item) - qt4_wrap_ui( features_detection_pluginUI_FILES Polyhedron_demo_features_detection_plugin.ui) + qt5_wrap_ui( features_detection_pluginUI_FILES Polyhedron_demo_features_detection_plugin.ui) polyhedron_demo_plugin(features_detection_plugin Polyhedron_demo_features_detection_plugin ${features_detection_pluginUI_FILES}) target_link_libraries(features_detection_plugin scene_points_with_normal_item) @@ -456,9 +416,10 @@ if(CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) # Edit polyhedron scene item and plugin if ( EIGEN3_FOUND AND "${EIGEN3_VERSION}" VERSION_GREATER "3.1.90" ) - qt4_wrap_ui( editionUI_FILES Deform_mesh.ui ) - qt4_automoc( Scene_edit_polyhedron_item.cpp ) - add_item(scene_edit_polyhedron_item Scene_edit_polyhedron_item.cpp Scene_edit_polyhedron_item.moc ${editionUI_FILES}) + qt5_wrap_ui( editionUI_FILES Deform_mesh.ui ) + #qt5_automoc( Scene_edit_polyhedron_item.cpp ) + add_item(scene_edit_polyhedron_item Scene_edit_polyhedron_item.cpp #Scene_edit_polyhedron_item.moc + ${editionUI_FILES}) target_link_libraries(scene_edit_polyhedron_item scene_polyhedron_item scene_polyhedron_item_k_ring_selection) @@ -474,11 +435,11 @@ if(CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) polyhedron_demo_plugin(point_inside_polyhedron_plugin Polyhedron_demo_point_inside_polyhedron_plugin ${point_inside_polyhedronUI_FILES}) target_link_libraries(point_inside_polyhedron_plugin scene_polyhedron_item scene_points_with_normal_item) - qt4_wrap_ui(point_set_simplificationUI_FILES Polyhedron_demo_point_set_simplification_plugin.ui) + qt5_wrap_ui(point_set_simplificationUI_FILES Polyhedron_demo_point_set_simplification_plugin.ui) polyhedron_demo_plugin(point_set_simplification_plugin Polyhedron_demo_point_set_simplification_plugin ${point_set_simplificationUI_FILES}) target_link_libraries(point_set_simplification_plugin scene_points_with_normal_item) - qt4_wrap_ui( ps_outliers_removal_UI_FILES Polyhedron_demo_point_set_outliers_removal_plugin.ui) + qt5_wrap_ui( ps_outliers_removal_UI_FILES Polyhedron_demo_point_set_outliers_removal_plugin.ui) polyhedron_demo_plugin(point_set_outliers_removal_plugin Polyhedron_demo_point_set_outliers_removal_plugin ${ps_outliers_removal_UI_FILES}) target_link_libraries(point_set_outliers_removal_plugin scene_points_with_normal_item) @@ -503,9 +464,9 @@ if(CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) # # Exporting # - if(TARGET CGAL_Qt4) - export(TARGETS CGAL_Qt4 FILE polyhedron_demo_targets.cmake NAMESPACE Polyhedron_) - export(TARGETS CGAL CGAL_Qt4 FILE polyhedron_demo_targets.cmake NAMESPACE Polyhedron_) + if(TARGET CGAL_Qt5) + export(TARGETS CGAL_Qt5 FILE polyhedron_demo_targets.cmake NAMESPACE Polyhedron_) + export(TARGETS CGAL CGAL_Qt5 FILE polyhedron_demo_targets.cmake NAMESPACE Polyhedron_) else() export(TARGETS FILE polyhedron_demo_targets.cmake) endif() @@ -519,26 +480,18 @@ if(CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) NAMESPACE Polyhedron_ APPEND FILE polyhedron_demo_targets.cmake) - if(GLEW_FOUND) - export( - TARGETS - gl_splat - NAMESPACE Polyhedron_ - APPEND FILE polyhedron_demo_targets.cmake) - endif(GLEW_FOUND) - configure_file(CGAL_polyhedron_demoConfig.cmake.in CGAL_polyhedron_demoConfig.cmake) -else (CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) +else (CGAL_Qt5_FOUND AND Qt5_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) set(POLYHEDRON_MISSING_DEPS "") - if(NOT CGAL_Qt4_FOUND) - set(POLYHEDRON_MISSING_DEPS "the CGAL Qt4 library, ${POLYHEDRON_MISSING_DEPS}") + if(NOT CGAL_Qt5_FOUND) + set(POLYHEDRON_MISSING_DEPS "the CGAL Qt5 library, ${POLYHEDRON_MISSING_DEPS}") endif() - if(NOT QT4_FOUND) - set(POLYHEDRON_MISSING_DEPS "Qt4, ${POLYHEDRON_MISSING_DEPS}") + if(NOT Qt5_FOUND) + set(POLYHEDRON_MISSING_DEPS "Qt5, ${POLYHEDRON_MISSING_DEPS}") endif() if(NOT OPENGL_FOUND) @@ -551,4 +504,5 @@ else (CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) message(STATUS "NOTICE: This demo requires ${POLYHEDRON_MISSING_DEPS}and will not be compiled.") -endif (CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) + +endif (CGAL_Qt5_FOUND AND Qt5_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) diff --git a/Polyhedron/demo/Polyhedron/Color_ramp.cpp b/Polyhedron/demo/Polyhedron/Color_ramp.cpp index c8d74b8f0fd..40c55a9c2d9 100644 --- a/Polyhedron/demo/Polyhedron/Color_ramp.cpp +++ b/Polyhedron/demo/Polyhedron/Color_ramp.cpp @@ -35,10 +35,11 @@ interpolate(const double v) const { return prev->second; } - + const double& a = prev->first; const double& b = next->first; return (b-v)/(b-a) * prev->second + (v-a)/(b-a) * next->second; + } void diff --git a/Polyhedron/demo/Polyhedron/GlSplat/CMakeLists.txt b/Polyhedron/demo/Polyhedron/GlSplat/CMakeLists.txt deleted file mode 100644 index c6e51f95e9d..00000000000 --- a/Polyhedron/demo/Polyhedron/GlSplat/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ - -project(GlSplat) - -cmake_minimum_required(VERSION 2.6.0) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) -endif() -set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) - -find_package(Qt4 REQUIRED) -find_package(GLEW REQUIRED) - -set(QT_USE_QTOPENGL TRUE) -set(QT_USE_QTXML TRUE) -include(${QT_USE_FILE}) -include_directories( ${QT_QTOPENGL_INCLUDE_DIR} ${QT_QTXML_INCLUDE_DIR} ${GLEW_INCLUDE_DIR}) - -set(srcs Shader.cpp GlSplat.cpp) - -qt4_automoc( ${srcs}) -qt4_add_resources(srcs glsplat.qrc) - -add_library(GlSplat SHARED ${srcs}) -target_link_libraries(GlSplat ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTOPENGL_LIBRARY} ${GLEW_LIBRARIES}) - -find_package(QGLViewer) -if(QGLVIEWER_FOUND) - include_directories( ${QGLViewer_INCLUDES}) - add_executable(demo demo.cpp) - target_link_libraries(demo ${QT_QTXML_LIBRARY} ${QGLViewer_LIBRARIES} GlSplat) -else() - message("QGLViewer not found, demo won't be built") -endif() diff --git a/Polyhedron/demo/Polyhedron/GlSplat/GlSplat.cpp b/Polyhedron/demo/Polyhedron/GlSplat/GlSplat.cpp deleted file mode 100644 index c589008c9b2..00000000000 --- a/Polyhedron/demo/Polyhedron/GlSplat/GlSplat.cpp +++ /dev/null @@ -1,514 +0,0 @@ -// This file is part of GlSplat, a simple splatting C++ library -// -// Copyright (C) 2008-2009 Gael Guennebaud -// -// GlSplat is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// GlSplat is distributed in the hope that it will be useful, but WITHOUT ANY -// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with GlSplat. If not, see . - -#include - -#include -#include -#include -#include - -#include "GlSplat.h" -#include "Shader.h" - -#include -#include -#include - - -namespace GlSplat { - -SplatRenderer::SplatRenderer() -{ - mNormalTextureID = 0; - mDepthTextureID = 0; - mIsSupported = false; - mRenderBuffer = 0; - mWorkaroundATI = false; - mBuggedAtiBlending = false; - mDummyTexId = 0; - mIsInitialized = false; - - mFlags = DEFERRED_SHADING_BIT | DEPTH_CORRECTION_BIT | FLOAT_BUFFER_BIT | OUTPUT_DEPTH_BIT; - mCachedFlags = ~mFlags; - // union of bits which controls the render buffer - mRenderBufferMask = DEFERRED_SHADING_BIT | FLOAT_BUFFER_BIT; -} - -QString SplatRenderer::loadSource(const QString& func,const QString& filename) -{ - QString res; - QFile f(":/SplatRenderer/shaders/" + filename); - if (!f.open(QFile::ReadOnly)) - { - std::cerr << "failed to load shader file " << filename.toAscii().data() << "\n"; - return res; - } - else qDebug("Succesfully loaded shader func '%s' in file '%s'",qPrintable(func),qPrintable(filename)); - QTextStream stream(&f); - res = stream.readAll(); - f.close(); - res = QString("#define GLSPLAT__%1__ 1\n").arg(func) - + QString("#define %1 main\n").arg(func) - + res; - return res; -} - -void SplatRenderer::configureShaders() -{ - // const char* passNames[3] = {"Visibility","Attribute","Finalization"}; - QString defines = ""; - if (mFlags & DEFERRED_SHADING_BIT) - defines += "#define ES_DEFERRED_SHADING\n"; - if (mFlags & DEPTH_CORRECTION_BIT) - defines += "#define ES_DEPTH_CORRECTION\n"; - if (mFlags & OUTPUT_DEPTH_BIT) - defines += "#define ES_OUTPUT_DEPTH 1\n"; - if (mFlags & BACKFACE_SHADING_BIT) - defines += "#define ES_BACKFACE_SHADING\n"; - if (mWorkaroundATI) - defines += "#define ES_ATI_WORKAROUND\n"; - - QString shading = -"vec4 meshlabLighting(vec4 color, vec3 eyePos, vec3 normal)" -"{" -" normal = normalize(normal);" -" vec3 lightVec = normalize(gl_LightSource[0].position.xyz);" -" vec3 halfVec = normalize( lightVec - normalize(eyePos) );" -" float aux_dot = dot(normal,lightVec);" -" float diffuseCoeff = clamp(aux_dot, 0.0, 1.0);" -" float specularCoeff = aux_dot>0.0 ? clamp(pow(clamp(dot(halfVec, normal),0.0,1.0),gl_FrontMaterial.shininess), 0.0, 1.0) : 0.0;" -" return vec4(color.rgb * ( gl_FrontLightProduct[0].ambient.rgb + diffuseCoeff * gl_FrontLightProduct[0].diffuse.rgb) + specularCoeff * gl_FrontLightProduct[0].specular.rgb, 1.0);" -"}\n"; - - for (int k=0;k<3;++k) - { - QString vsrc = shading + defines + mShaderSrcs[k*2+0]; - QString fsrc = shading + defines + mShaderSrcs[k*2+1]; - if(!mShaders[k].loadSources(mShaderSrcs[k*2+0]!="" ? vsrc.toAscii().data() : 0, - mShaderSrcs[k*2+1]!="" ? fsrc.toAscii().data() : 0/*, - Shader::Warnings*/)) - mIsSupported = false; - } -} - -void SplatRenderer::init(QGLWidget *qglw) -{ - mIsSupported = true; - if(qglw) - qglw->makeCurrent(); - glewInit(); - - const char* rs = (const char*)glGetString(GL_RENDERER); - QString rendererString(""); - if(rs) - rendererString = QString(rs); - mWorkaroundATI = rendererString.startsWith("ATI") || rendererString.startsWith("AMD"); - // FIXME: maybe some recent HW correctly supports floating point blending... - mBuggedAtiBlending = rendererString.startsWith("ATI") || rendererString.startsWith("AMD"); - - if (mWorkaroundATI && mDummyTexId==0) - { - glActiveTexture(GL_TEXTURE0); - glGenTextures(1,&mDummyTexId); - glBindTexture(GL_TEXTURE_2D, mDummyTexId); - glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 4, 4, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, 0); - } - - // let's check the GPU capabilities - mSupportedMask = DEPTH_CORRECTION_BIT | BACKFACE_SHADING_BIT; - if (!QGLFramebufferObject::hasOpenGLFramebufferObjects ()) - { - std::cout << "SplatRenderer: error OpenGL frame buffer objects are not supported. (please, try to update your drivers)\n"; - mIsSupported = false; - return; - } - if (GLEW_ARB_texture_float) - mSupportedMask |= FLOAT_BUFFER_BIT; - else - std::cout << "SplatRenderer: warning floating point textures are not supported.\n"; - - if (GLEW_ARB_draw_buffers && (!mBuggedAtiBlending)) - mSupportedMask |= DEFERRED_SHADING_BIT; - else - std::cout << "SplatRenderer: warning deferred shading is not supported.\n"; - - if (GLEW_ARB_shadow) - mSupportedMask |= OUTPUT_DEPTH_BIT; - else - std::cerr << "SplatRenderer: warning copy of the depth buffer is not supported.\n"; - - mFlags = mFlags & mSupportedMask; - - // load shader source - mShaderSrcs[0] = loadSource("VisibilityVP","Raycasting.glsl"); - mShaderSrcs[1] = loadSource("VisibilityFP","Raycasting.glsl"); - mShaderSrcs[2] = loadSource("AttributeVP","Raycasting.glsl"); - mShaderSrcs[3] = loadSource("AttributeFP","Raycasting.glsl"); - mShaderSrcs[4] = ""; - mShaderSrcs[5] = loadSource("Finalization","Finalization.glsl"); - - mCurrentPass = 2; - mBindedPass = -1; - mIsInitialized = true; - GL_TEST_ERR -} - -void SplatRenderer::updateRenderBuffer() -{ - if ( (!mRenderBuffer) - || (mRenderBuffer->width()!=mCachedVP[2]) - || (mRenderBuffer->height()!=mCachedVP[3]) - || ( (mCachedFlags & mRenderBufferMask) != (mFlags & mRenderBufferMask) )) - { - delete mRenderBuffer; - GLenum fmt = (mFlags&FLOAT_BUFFER_BIT) ? GL_RGBA16F_ARB : GL_RGBA; - mRenderBuffer = new QGLFramebufferObject(mCachedVP[2], mCachedVP[3], - (mFlags&OUTPUT_DEPTH_BIT) ? QGLFramebufferObject::NoAttachment : QGLFramebufferObject::Depth, - GL_TEXTURE_RECTANGLE_ARB, fmt); - - if (!mRenderBuffer->isValid()) - { - std::cout << "SplatRenderer: invalid FBO\n"; - } - - GL_TEST_ERR - if (mFlags&DEFERRED_SHADING_BIT) - { - // in deferred shading mode we need an additional buffer to accumulate the normals - if (mNormalTextureID==0) - glGenTextures(1,&mNormalTextureID); - glBindTexture(GL_TEXTURE_RECTANGLE_ARB, mNormalTextureID); - glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, fmt, mCachedVP[2], mCachedVP[3], 0, GL_RGBA, GL_FLOAT, 0); - glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - mRenderBuffer->bind(); - glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_RECTANGLE_ARB, mNormalTextureID, 0); - mRenderBuffer->release(); - GL_TEST_ERR - } - - if (mFlags&OUTPUT_DEPTH_BIT) - { - // to output the depth values to the final depth buffer we need to - // attach a depth buffer as a texture - if (mDepthTextureID==0) - glGenTextures(1,&mDepthTextureID); - glBindTexture(GL_TEXTURE_RECTANGLE_ARB, mDepthTextureID); - glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_DEPTH_COMPONENT24_ARB, mCachedVP[2], mCachedVP[3], 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0); - glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - mRenderBuffer->bind(); - glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_RECTANGLE_ARB, mDepthTextureID, 0); - mRenderBuffer->release(); - GL_TEST_ERR - } - } -} - -bool SplatRenderer::beginVisibilityPass() -{ - if (!mIsInitialized) - { - init(); - } - if (!isSupported()) - { - std::cerr << "SplatRenderer error: not supported hardware\n"; - return false; - } - if (mCurrentPass!=2) - { - std::cerr << "SplatRenderer error: programming error when calling beginVisibilityPass\n"; - return false; - } - - glPushAttrib(GL_ALL_ATTRIB_BITS); - - mCurrentPass = 0; - - // grab projection info - glGetIntegerv(GL_VIEWPORT, mCachedVP); - glGetFloatv(GL_MODELVIEW_MATRIX, mCachedMV); - glGetFloatv(GL_PROJECTION_MATRIX, mCachedProj); - - updateRenderBuffer(); - if (mCachedFlags != mFlags) - configureShaders(); - - // configureShaders may detect that shaders are actually not supported. - if (!isSupported()) - { - std::cerr << "SplatRenderer error: not supported hardware\n"; - return false; - } - - mCachedFlags = mFlags; - - mParams.update(mCachedMV, mCachedProj, mCachedVP); - mParams.loadTo(mShaders[mCurrentPass]); - - mRenderBuffer->bind(); - if (mFlags & DEFERRED_SHADING_BIT) - { - GLenum buf[2] = {GL_COLOR_ATTACHMENT0_EXT,GL_COLOR_ATTACHMENT1_EXT}; - glDrawBuffersARB(2, buf); - } - glViewport(mCachedVP[0],mCachedVP[1],mCachedVP[2],mCachedVP[3]); - glClearColor(0,0,0,0); - glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); - enablePass(mCurrentPass); - GL_TEST_ERR; - return true; -} -bool SplatRenderer::beginAttributePass() -{ - if (!isSupported()) - { - std::cerr << "SplatRenderer error: not supported hardware\n"; - return false; - } - if (mCurrentPass!=0) - { - std::cerr << "SplatRenderer error: programming error when calling beginAttributePass (must be called after the visiblity pass)\n"; - return false; - } - - mCurrentPass = 1; - mParams.loadTo(mShaders[mCurrentPass]); - enablePass(mCurrentPass); - GL_TEST_ERR; - return true; -} -bool SplatRenderer::finalize() -{ - if (!isSupported()) - { - std::cerr << "SplatRenderer error: not supported hardware\n"; - return false; - } - - // this is the last pass: normalization by the sum of weights + deferred shading - mShaders[mCurrentPass].release(); - mRenderBuffer->release(); - - if ( (mCurrentPass!=0) && (mCurrentPass!=1)) - { - std::cerr << "SplatRenderer error: programming error when calling finalize (must be called after the visiblity or attribute pass)\n"; - return false; - } - - mCurrentPass = 2; - - if (mFlags&DEFERRED_SHADING_BIT) - glDrawBuffer(GL_BACK); - - enablePass(mCurrentPass);GL_TEST_ERR - - // switch to normalized 2D rendering mode - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glLoadIdentity(); - - - GL_TEST_ERR - mShaders[2].setUniform("viewport",float(mCachedVP[0]),float(mCachedVP[1]),float(mCachedVP[2]),float(mCachedVP[3]));GL_TEST_ERR - mShaders[2].setUniform("ColorWeight",0); GL_TEST_ERR // this is a texture unit - glActiveTexture(GL_TEXTURE0);GL_TEST_ERR - glBindTexture(GL_TEXTURE_RECTANGLE_ARB,mRenderBuffer->texture());GL_TEST_ERR - - if (mFlags&DEFERRED_SHADING_BIT) - { - mShaders[2].setUniform("unproj", mCachedProj[10], mCachedProj[14]);GL_TEST_ERR - mShaders[2].setUniform("NormalWeight",1);GL_TEST_ERR // this is a texture unit - glActiveTexture(GL_TEXTURE1);GL_TEST_ERR - glBindTexture(GL_TEXTURE_RECTANGLE_ARB,mNormalTextureID);GL_TEST_ERR - GL_TEST_ERR - } - - if (mFlags&OUTPUT_DEPTH_BIT) - { - mShaders[2].setUniform("Depth",2);GL_TEST_ERR // this is a texture unit - glActiveTexture(GL_TEXTURE2);GL_TEST_ERR - glBindTexture(GL_TEXTURE_RECTANGLE_ARB,mDepthTextureID);GL_TEST_ERR - GL_TEST_ERR - } - else - { - glDisable(GL_DEPTH_TEST); - glDepthMask(GL_FALSE); - } - - // draw a quad covering the whole screen - float viewVec[] = {1.f/mCachedProj[0], 1.f/mCachedProj[5], -1}; - - glBegin(GL_QUADS); - glColor3f(1, 0, 0); - glTexCoord3f(viewVec[0],viewVec[1],viewVec[2]); - glMultiTexCoord2f(GL_TEXTURE1,1.,1.); - glVertex3f(1,1,0); - - glColor3f(1, 1, 0); - glTexCoord3f(-viewVec[0],viewVec[1],viewVec[2]); - glMultiTexCoord2f(GL_TEXTURE1,0.,1.); - glVertex3f(-1,1,0); - - glColor3f(0, 1, 1); - glTexCoord3f(-viewVec[0],-viewVec[1],viewVec[2]); - glMultiTexCoord2f(GL_TEXTURE1,0.,0.); - glVertex3f(-1,-1,0); - - glColor3f(1, 0, 1); - glTexCoord3f(viewVec[0],-viewVec[1],viewVec[2]); - glMultiTexCoord2f(GL_TEXTURE1,1.,0.); - glVertex3f(1,-1,0); - glEnd(); - if (!(mFlags&OUTPUT_DEPTH_BIT)) - { - glEnable(GL_DEPTH_TEST); - glDepthMask(GL_TRUE); - } - - mShaders[mCurrentPass].release(); - - // restore matrices - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); - - glPopAttrib(); - return true; -} - -void SplatRenderer::enablePass(int n) -{ - if (!isSupported()) - { - return; - } - if (mBindedPass!=n) - { - if (mBindedPass>=0) - mShaders[mBindedPass].release(); - mShaders[n].activate(); - mBindedPass = n; - - // set GL states - if (n==0) - { - glDisable(GL_LIGHTING); -// glDisable(GL_POINT_SMOOTH); - glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); - - glAlphaFunc(GL_LESS,1); - glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE); - glDepthMask(GL_TRUE); - glDisable(GL_BLEND); - glEnable(GL_ALPHA_TEST); - glEnable(GL_DEPTH_TEST); - -// glActiveTexture(GL_TEXTURE0); -// glTexEnvf(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE); -// glEnable(GL_POINT_SPRITE_ARB); - } - if (n==1) - { - glDisable(GL_LIGHTING); - glEnable(GL_POINT_SMOOTH); - glActiveTexture(GL_TEXTURE0); - glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); - - glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE); - glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_ONE,GL_ONE); -// //glBlendFuncSeparate(GL_ONE, GL_ZERO, GL_ONE,GL_ZERO); -// glBlendFunc(GL_ONE,GL_ZERO); - glDepthMask(GL_FALSE); - glEnable(GL_BLEND); - glEnable(GL_DEPTH_TEST); - glDisable(GL_ALPHA_TEST); - -// glActiveTexture(GL_TEXTURE0); - - } - if ( (n==0) || (n==1) ) - { - // enable point sprite rendering mode - glActiveTexture(GL_TEXTURE0); - if (mWorkaroundATI) - { - glBindTexture(GL_TEXTURE_2D, mDummyTexId); - glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 2, 2, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, 0); - glPointParameterf(GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT); - // hm... ^^^^ - } - glTexEnvf(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE); - glEnable(GL_POINT_SPRITE_ARB); - } - if (n==2) - { - glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE); - glDepthMask(GL_TRUE); - glDisable(GL_LIGHTING); - glDisable(GL_BLEND); - } - } -} - -void SplatRenderer::UniformParameters::update(float* mv, float* proj, GLint* vp) -{ - // extract the uniform scale - float scale = sqrtf(mv[0]*mv[0]+mv[1]*mv[1]+mv[2]*mv[2]); - - radiusScale = scale; - preComputeRadius = - (std::max)(proj[0]*vp[2], proj[5]*vp[3]); - depthOffset = 2.0; - oneOverEwaRadius = (float)0.70710678118654; - halfVp[0] = 0.5*vp[2]; - halfVp[1] = 0.5*vp[3]; - rayCastParameter1[0] = 2./(proj[0]*vp[2]); - rayCastParameter1[1] = 2./(proj[5]*vp[3]); - rayCastParameter1[2] = 0.0; - rayCastParameter2[0] = -1./proj[0]; - rayCastParameter2[1] = -1./proj[5]; - rayCastParameter2[2] = -1.0; - depthParameterCast[0] = 0.5*proj[14]; - depthParameterCast[1] = 0.5-0.5*proj[10]; -} - -void SplatRenderer::UniformParameters::loadTo(Shader& prg) -{ - prg.activate(); - prg.setUniform("expeRadiusScale", radiusScale); - prg.setUniform("expePreComputeRadius", preComputeRadius); - prg.setUniform("expeDepthOffset", depthOffset); - prg.setUniform("oneOverEwaRadius", oneOverEwaRadius); - prg.setUniform2("halfVp", halfVp); - prg.setUniform3("rayCastParameter1", rayCastParameter1); - prg.setUniform3("rayCastParameter2", rayCastParameter2); - prg.setUniform2("depthParameterCast", depthParameterCast); -} - -void SplatRenderer::setRadiusScale(float v) -{ - mParams.radiusScale = v; -} - -} // namepsace GlSplat - diff --git a/Polyhedron/demo/Polyhedron/GlSplat/GlSplat.h b/Polyhedron/demo/Polyhedron/GlSplat/GlSplat.h deleted file mode 100644 index 47c40eba921..00000000000 --- a/Polyhedron/demo/Polyhedron/GlSplat/GlSplat.h +++ /dev/null @@ -1,144 +0,0 @@ -// This file is part of GlSplat, a simple splatting C++ library -// -// Copyright (C) 2008-2009 Gael Guennebaud -// -// GlSplat is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// GlSplat is distributed in the hope that it will be useful, but WITHOUT ANY -// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with GlSplat. If not, see . - -#ifndef _GLSPLAT_SPLATRENDERER_H_ -#define _GLSPLAT_SPLATRENDERER_H_ - -#include "GlSplat_config.h" -#include "Shader.h" -#include -#include -#include -#include - -class QGLFramebufferObject; -class QGLWidget; - -namespace GlSplat { - -/** \class SplatRenderer - * \brief Helper class to render a set of points using a splatting alogirthm - * - * This class aims to render a set of oriented point with radius (called splats) using an - * OpenGL based splating algorithm. This class is only responsible for the managing of the - * OpenGL stats and shaders related to the splatting. The drawing of the geometry, i.e., - * sending the point data to the GPU has to be done by the user. - * - * Here is an example: - * \code - * SplatRenderer renderer; - * renderer.init(); - * - * renderer.beginVisibilityPass(); - * drawpoints(); - * renderer.beginAttributePass(); - * drawpoints(); - * renderer.finalize(); - * \endcode - * - * Have a look at the demo to see a complete example based on QGLviewer. - */ -class GLSPLAT_EXPORT SplatRenderer -{ - bool mIsSupported; - enum { - DEFERRED_SHADING_BIT = 0x000001, - DEPTH_CORRECTION_BIT = 0x000002, - OUTPUT_DEPTH_BIT = 0x000004, - BACKFACE_SHADING_BIT = 0x000008, - FLOAT_BUFFER_BIT = 0x000010 - }; - int mFlags; - int mCachedFlags; - int mRenderBufferMask; - int mSupportedMask; - - int mCurrentPass; - int mBindedPass; - GLuint mDummyTexId; // on ATI graphics card we need to bind a texture to get point sprite working ! - bool mWorkaroundATI; - bool mBuggedAtiBlending; - bool mIsInitialized; - GLuint mNormalTextureID; - GLuint mDepthTextureID; - Shader mShaders[3]; - QString mShaderSrcs[6]; - QGLFramebufferObject* mRenderBuffer; - float mCachedMV[16]; // modelview matrix - float mCachedProj[16]; // projection matrix - GLint mCachedVP[4]; // viewport - - struct UniformParameters - { - float radiusScale; - float preComputeRadius; - float depthOffset; - float oneOverEwaRadius; - float halfVp[2]; - float rayCastParameter1[3]; - float rayCastParameter2[3]; - float depthParameterCast[2]; - - void loadTo(Shader& prg); - void update(float* mv, float* proj, GLint* vp); - }; - - UniformParameters mParams; - - QString loadSource(const QString& func,const QString& file); - void configureShaders(); - void updateRenderBuffer(); - void enablePass(int n); - -public: - - SplatRenderer(); - - /** Must be called once an OpenGL context has been activated. - * The main OpenGL context must be enabled, or, if you are using a QGLwiget, - * you can pass it to this function without caring about the OpenGL context. - */ - void init(QGLWidget *qglw = 0); - - /** \returns true is the hardware is supported - * Must be called after init. - */ - bool isSupported() { return mIsSupported; } - - /** Starts the first rendering pass - * \returns false if an error occured - */ - bool beginVisibilityPass(); - /** Starts the (optional) second rendering pass - * \returns false if an error occured - */ - bool beginAttributePass(); - /** Draw the rendered splats inside the main render target. - * \returns false if an error occured - */ - bool finalize(); - - /** Sets a global scale factor for the splat radii - * Default value is 1 - */ - void setRadiusScale(float v); - -}; - -} // namepsace GlSplat - -#endif // _GLSPLAT_SPLATRENDERER_H_ - diff --git a/Polyhedron/demo/Polyhedron/GlSplat/GlSplat_config.h b/Polyhedron/demo/Polyhedron/GlSplat/GlSplat_config.h deleted file mode 100644 index b64e4065a68..00000000000 --- a/Polyhedron/demo/Polyhedron/GlSplat/GlSplat_config.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef GLSPLAT_CONFIG_H -#define GLSPLAT_CONFIG_H - -#include - -#ifdef gl_splat_EXPORTS - #define GLSPLAT_EXPORT CGAL_DLL_EXPORT -#else - #define GLSPLAT_EXPORT CGAL_DLL_IMPORT -#endif - -#endif // GLSPLAT_CONFIG_H diff --git a/Polyhedron/demo/Polyhedron/GlSplat/Shader.cpp b/Polyhedron/demo/Polyhedron/GlSplat/Shader.cpp deleted file mode 100644 index c91f7367bab..00000000000 --- a/Polyhedron/demo/Polyhedron/GlSplat/Shader.cpp +++ /dev/null @@ -1,136 +0,0 @@ -// This file is part of GlSplat, a simple splatting C++ library -// -// Copyright (C) 2008-2009 Gael Guennebaud -// -// GlSplat is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// GlSplat is distributed in the hope that it will be useful, but WITHOUT ANY -// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with GlSplat. If not, see . - -#include "Shader.h" -#include - -#include -#include -#include - -namespace GlSplat { - -void Shader::define(const char* name, const char* value) -{ - mDefines[std::string(name)] = value; -} -//-------------------------------------------------------------------------------- -bool Shader::loadSources(const char* vsrc, const char* fsrc) -{ - bool allIsOk = true; - - mProgramID = glCreateProgram(); - - std::string defineStr = ""; - for(DefineMap::iterator it = mDefines.begin() ; it!=mDefines.end() ; ++it) - { - defineStr += "#define " + it->first + " " + it->second + "\n"; - } - - if(vsrc) - { - GLuint shaderID = glCreateShader(GL_VERTEX_SHADER); - - std::string source = defineStr + std::string(vsrc); - const GLchar * arbSource = source.c_str(); - - glShaderSource(shaderID, 1, (const GLchar **)&arbSource, 0); - glCompileShader(shaderID); - - int compiled; - glGetShaderiv(shaderID,GL_COMPILE_STATUS,&compiled); - allIsOk = allIsOk && compiled; - //printInfoLog(shaderID); - - glAttachShader(mProgramID, shaderID); - } - - if(fsrc) - { - GLuint shaderID = glCreateShader(GL_FRAGMENT_SHADER); - - std::string source = defineStr + std::string(fsrc); - const GLchar * arbSource = source.c_str(); - - glShaderSource(shaderID, 1, (const GLchar **)&arbSource, 0); - glCompileShader(shaderID); - - int compiled; - glGetShaderiv(shaderID,GL_COMPILE_STATUS,&compiled); - allIsOk = allIsOk && compiled; - //printInfoLog(shaderID); - - glAttachShader(mProgramID, shaderID); - } - - glLinkProgram(mProgramID); - - int isLinked; - glGetProgramiv(mProgramID, GL_LINK_STATUS, &isLinked); - allIsOk = allIsOk && isLinked; - mIsValid = isLinked == GL_TRUE; - printInfoLog(mProgramID); - - return allIsOk; -} -//-------------------------------------------------------------------------------- -void Shader::activate(void) const -{ - assert(mIsValid); - glUseProgram(mProgramID); -} -void Shader::release(void) const -{ - glUseProgram(0); -} -//-------------------------------------------------------------------------------- -int Shader::getUniformLocation(const char* name) const -{ - assert(mIsValid); - int loc = glGetUniformLocation(mProgramID, name); - return loc; -} -//-------------------------------------------------------------------------------- -void Shader::setSamplerUnit(const char* sampler, int unit) const -{ - activate(); - glUniform1i(getUniformLocation(sampler), unit); - release(); -} -//-------------------------------------------------------------------------------- -int Shader::getAttribLocation(const char* name) const -{ - assert(mIsValid); - int loc = glGetAttribLocation(mProgramID, name); - return loc; -} -//-------------------------------------------------------------------------------- -void Shader::printInfoLog(GLuint objectID) -{ - int infologLength, charsWritten; - GLchar *infoLog; - glGetProgramiv(objectID,GL_INFO_LOG_LENGTH, &infologLength); - if(infologLength > 0) - { - infoLog = new GLchar[infologLength]; - glGetProgramInfoLog(objectID, infologLength, &charsWritten, infoLog); - if (charsWritten>0) - std::cerr << "Shader info : \n" << infoLog << std::endl; - delete[] infoLog; - } -} - -} // namepsace GlSplat diff --git a/Polyhedron/demo/Polyhedron/GlSplat/Shader.h b/Polyhedron/demo/Polyhedron/GlSplat/Shader.h deleted file mode 100644 index 669d23727db..00000000000 --- a/Polyhedron/demo/Polyhedron/GlSplat/Shader.h +++ /dev/null @@ -1,148 +0,0 @@ -// This file is part of GlSplat, a simple splatting C++ library -// -// Copyright (C) 2008-2009 Gael Guennebaud -// -// GlSplat is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// GlSplat is distributed in the hope that it will be useful, but WITHOUT ANY -// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with GlSplat. If not, see . - -#ifndef _GLSPLAT_Shader_h_ -#define _GLSPLAT_Shader_h_ - -#include -#include - -#ifndef NDEBUG - #define GL_TEST_ERR\ - {\ - GLenum eCode;\ - if((eCode=glGetError())!=GL_NO_ERROR)\ - std::cerr << "OpenGL error : " << gluErrorString(eCode) << " in " << __FILE__ << " : " << __LINE__ << std::endl;\ - } -#else - #define GL_TEST_ERR -#endif - -#include -#include - -namespace GlSplat { - -/** Permet de manipuler des shaders en GLSL (OpenGL2.0) - Exemple d'utilisation: - \code - // shader creation: - Shader* myShader = new Shader(); - // loading from files (compilation + linking): - myShader->loadFromFiles("myShaderFile.vtx", "myShaderFile.frg"); - - // ... - - // at rending time: - myShader->enable(); - // draw objects - myShader->disable(); - \endcode -*/ - -class Shader -{ -public: - Shader(void) - : mIsValid(false) - { } - - /** add a \#define - */ - void define(const char* name, const char* value); - - /** Compiles and links the shader from 2 source files - \param fileV vertex shader ("" if no vertex shader) - \param fileF fragment shader ("" if no fragment shader) - \return true if no error occurs - */ -// bool loadFromFiles(const std::string& fileV, const std::string& fileF); - - bool loadSources(const char* vsrc, const char* fsrc); - - /** Enable the shader - */ - void activate() const; - - /** Releases the shader - */ - void release() const; - - /** \return the index of the uniform variable \a name - */ - int getUniformLocation(const char* name) const; - - /** Forces a sampler to a given unit - Example: - \code - glActiveTexture(GL_TEXTURE2); - glBindTexture(GL_TEXTURE2D, myTextureID); - myShader->setSamplerUnit("mySampler", 2); - \endcode - */ - void setSamplerUnit(const char* samplerName, int textureUnit) const; - - /** \returns the index of the generic attribute \a name - Tp be used with glVertexAttrib*(...) ou glVertexAttribPointer(...) - Example: - \code - int tangentAttribID = myShader->getAttribLocation("tangent"); - Vector3 tangent(...); - glVertexAttrib3fv(tangentAttribID, tangent); - // ou - Vector3* tangents = new Vector3[...]; - glVertexAttribPointer(tangentAttribID, 3, GL_FLOAT, GL_FALSE, 0, tangents); - glEnableVertexAttribArray(tangentAttribID); - \endcode - */ - int getAttribLocation(const char* name) const; - - inline void setUniform(const char* name, float a) const - { glUniform1f(glGetUniformLocation(mProgramID, name), a); } - - inline void setUniform(const char* name, int a) const - { glUniform1i(glGetUniformLocation(mProgramID, name), a); } - - inline void setUniform2(const char* name, float* a) const - { glUniform2fv(glGetUniformLocation(mProgramID, name), 1, a); } - - inline void setUniform3(const char* name, float* a) const - { glUniform3fv(glGetUniformLocation(mProgramID, name), 1, a); } - - inline void setUniform4(const char* name, float* a) const - { glUniform4fv(glGetUniformLocation(mProgramID, name), 1, a); } - - inline void setUniform(const char* name, float a, float b) const - { glUniform2f(glGetUniformLocation(mProgramID, name), a, b); } - - inline void setUniform(const char* name, float a, float b, float c) const - { glUniform3f(glGetUniformLocation(mProgramID, name), a, b, c); } - - inline void setUniform(const char* name, float a, float b, float c, float d) const - { glUniform4f(glGetUniformLocation(mProgramID, name), a, b, c, d); } - -protected: - - bool mIsValid; - typedef std::map DefineMap; - DefineMap mDefines; - static void printInfoLog(GLuint objectID); - GLuint mProgramID; -}; - -} // namepsace GlSplat - -#endif diff --git a/Polyhedron/demo/Polyhedron/GlSplat/cmake/FindGLEW.cmake b/Polyhedron/demo/Polyhedron/GlSplat/cmake/FindGLEW.cmake deleted file mode 100644 index 54da20f12bd..00000000000 --- a/Polyhedron/demo/Polyhedron/GlSplat/cmake/FindGLEW.cmake +++ /dev/null @@ -1,105 +0,0 @@ -# Copyright (c) 2009 Boudewijn Rempt -# -# Redistribution and use is allowed according to the terms of the BSD license. -# For details see the accompanying COPYING-CMAKE-SCRIPTS file. -# -# - try to find glew library and include files -# GLEW_INCLUDE_DIR, where to find GL/glew.h, etc. -# GLEW_LIBRARIES, the libraries to link against -# GLEW_FOUND, If false, do not try to use GLEW. -# Also defined, but not for general use are: -# GLEW_GLEW_LIBRARY = the full path to the glew library. - -IF (WIN32) - - IF(CYGWIN) - - FIND_PATH( GLEW_INCLUDE_DIR GL/glew.h) - - FIND_LIBRARY( GLEW_GLEW_LIBRARY glew32 - ${OPENGL_LIBRARY_DIR} - /usr/lib/w32api - /usr/X11R6/lib - ) - - - ELSE(CYGWIN) - - FIND_PATH( GLEW_INCLUDE_DIR GL/glew.h - $ENV{GLEW_ROOT_PATH}/include - ) - - FIND_LIBRARY( GLEW_GLEW_LIBRARY - NAMES glew glew32 - PATHS - $ENV{GLEW_ROOT_PATH}/lib - ${OPENGL_LIBRARY_DIR} - ) - - ENDIF(CYGWIN) - -ELSE (WIN32) - - IF (APPLE) -# These values for Apple could probably do with improvement. - FIND_PATH( GLEW_INCLUDE_DIR glew.h - /System/Library/Frameworks/GLEW.framework/Versions/A/Headers - ${OPENGL_LIBRARY_DIR} - ) - SET(GLEW_GLEW_LIBRARY "-framework GLEW" CACHE STRING "GLEW library for OSX") - SET(GLEW_cocoa_LIBRARY "-framework Cocoa" CACHE STRING "Cocoa framework for OSX") - ELSE (APPLE) - - FIND_PATH( GLEW_INCLUDE_DIR GL/glew.h - /usr/include/GL - /usr/openwin/share/include - /usr/openwin/include - /usr/X11R6/include - /usr/include/X11 - /opt/graphics/OpenGL/include - /opt/graphics/OpenGL/contrib/libglew - ) - - FIND_LIBRARY( GLEW_GLEW_LIBRARY GLEW - /usr/openwin/lib - /usr/X11R6/lib - ) - - ENDIF (APPLE) - -ENDIF (WIN32) - -SET( GLEW_FOUND "NO" ) -IF(GLEW_INCLUDE_DIR) - IF(GLEW_GLEW_LIBRARY) - # Is -lXi and -lXmu required on all platforms that have it? - # If not, we need some way to figure out what platform we are on. - SET( GLEW_LIBRARIES - ${GLEW_GLEW_LIBRARY} - ${GLEW_cocoa_LIBRARY} - ) - SET( GLEW_FOUND "YES" ) - -#The following deprecated settings are for backwards compatibility with CMake1.4 - SET (GLEW_LIBRARY ${GLEW_LIBRARIES}) - SET (GLEW_INCLUDE_PATH ${GLEW_INCLUDE_DIR}) - - ENDIF(GLEW_GLEW_LIBRARY) -ENDIF(GLEW_INCLUDE_DIR) - -IF(GLEW_FOUND) - IF(NOT GLEW_FIND_QUIETLY) - MESSAGE(STATUS "Found Glew: ${GLEW_LIBRARIES}") - ENDIF(NOT GLEW_FIND_QUIETLY) -ELSE(GLEW_FOUND) - IF(GLEW_FIND_REQUIRED) - MESSAGE(FATAL_ERROR "Could not find Glew") - ENDIF(GLEW_FIND_REQUIRED) -ENDIF(GLEW_FOUND) - -MARK_AS_ADVANCED( - GLEW_INCLUDE_DIR - GLEW_GLEW_LIBRARY - GLEW_Xmu_LIBRARY - GLEW_Xi_LIBRARY -) diff --git a/Polyhedron/demo/Polyhedron/GlSplat/cmake/FindQGLViewer.cmake b/Polyhedron/demo/Polyhedron/GlSplat/cmake/FindQGLViewer.cmake deleted file mode 100644 index 5e5bab0c1c8..00000000000 --- a/Polyhedron/demo/Polyhedron/GlSplat/cmake/FindQGLViewer.cmake +++ /dev/null @@ -1,20 +0,0 @@ - -if (QGLViewer_INCLUDES AND QGLViewer_LIBRARIES) - set(QGLViewer_FIND_QUIETLY TRUE) -endif (QGLViewer_INCLUDES AND QGLViewer_LIBRARIES) - -find_path(QGLViewer_INCLUDES - NAMES - QGLViewer/qglviewer.h - PATHS - $ENV{QGLViewerDIR} - ${INCLUDE_INSTALL_DIR} -) - -find_library(QGLViewer_LIBRARIES QGLViewer PATHS $ENV{QGLVIEWER_DIR} ${LIB_INSTALL_DIR}) - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(QGLViewer DEFAULT_MSG - QGLViewer_INCLUDES QGLViewer_LIBRARIES) - -mark_as_advanced(QGLViewer_INCLUDES QGLViewer_LIBRARIES) diff --git a/Polyhedron/demo/Polyhedron/GlSplat/demo.cpp b/Polyhedron/demo/Polyhedron/GlSplat/demo.cpp deleted file mode 100644 index 39514a225dc..00000000000 --- a/Polyhedron/demo/Polyhedron/GlSplat/demo.cpp +++ /dev/null @@ -1,131 +0,0 @@ -// This file is part of GlSplat, a simple splatting C++ library -// -// Copyright (C) 2008-2009 Gael Guennebaud -// -// GlSplat is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// GlSplat is distributed in the hope that it will be useful, but WITHOUT ANY -// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with GlSplat. If not, see . - -#include "GlSplat.h" -#include - -class Viewer : public QGLViewer -{ -protected : - virtual void draw(); - virtual void init(); - virtual QString helpString() const; - - virtual void drawpoints(); - GlSplat::SplatRenderer mRenderer; - std::vector mNormals; - std::vector mPositions; - std::vector mRadii; - std::vector mColors; - int mNbPoints; -}; - -void Viewer::draw() -{ - mRenderer.beginVisibilityPass(); - drawpoints(); - mRenderer.beginAttributePass(); - drawpoints(); - mRenderer.finalize(); -} - -void Viewer::drawpoints() -{ - glBegin(GL_POINTS); - for (int i=0; iS i m p l e V i e w e r"); - text += "Use the mouse to move the camera around the object. "; - text += "You can respectively revolve around, zoom and translate with the three mouse buttons. "; - text += "Left and middle buttons pressed together rotate around the camera view direction axis

"; - text += "Pressing Alt and one of the function keys (F1..F12) defines a camera keyFrame. "; - text += "Simply press the function key again to restore it. Several keyFrames define a "; - text += "camera path. Paths are saved when you quit the application and restored at next start.

"; - text += "Press F to display the frame rate, A for the world axis, "; - text += "Alt+Return for full screen mode and Control+S to save a snapshot. "; - text += "See the Keyboard tab in this window for a complete shortcut list.

"; - text += "Double clicks automates single click actions: A left button double click aligns the closer axis with the camera (if close enough). "; - text += "A middle button double click fits the zoom of the camera and the right button re-centers the scene.

"; - text += "A left button double click while holding right button pressed defines the camera Revolve Around Point. "; - text += "See the Mouse tab and the documentation web pages for details.

"; - text += "Press Escape to exit the viewer."; - return text; -} - - -#include - -int main(int argc, char** argv) -{ - // Read command lines arguments. - QApplication application(argc,argv); - - // Instantiate the viewer. - Viewer viewer; - - viewer.setWindowTitle("simpleViewer"); - - // Make the viewer window visible on screen. - viewer.show(); - - // Run main loop. - return application.exec(); -} - diff --git a/Polyhedron/demo/Polyhedron/GlSplat/glsplat.qrc b/Polyhedron/demo/Polyhedron/GlSplat/glsplat.qrc deleted file mode 100644 index 2aa027c792b..00000000000 --- a/Polyhedron/demo/Polyhedron/GlSplat/glsplat.qrc +++ /dev/null @@ -1,6 +0,0 @@ - - - shaders/Raycasting.glsl - shaders/Finalization.glsl - - diff --git a/Polyhedron/demo/Polyhedron/GlSplat/shaders/Finalization.glsl b/Polyhedron/demo/Polyhedron/GlSplat/shaders/Finalization.glsl deleted file mode 100644 index d587a28056f..00000000000 --- a/Polyhedron/demo/Polyhedron/GlSplat/shaders/Finalization.glsl +++ /dev/null @@ -1,106 +0,0 @@ -// This file is part of GlSplat, a simple splatting C++ library -// -// Copyright (C) 2008-2009 Gael Guennebaud -// -// GlSplat is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// GlSplat is distributed in the hope that it will be useful, but WITHOUT ANY -// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with GlSplat. If not, see . - -#extension GL_ARB_texture_rectangle : enable - -#ifndef ES_DEPTH_INTERPOLATION - #define ES_DEPTH_INTERPOLATION 0 -#endif - -#ifndef ES_OUTPUT_DEPTH - #define ES_OUTPUT_DEPTH 0 -#endif - -// avoid an annoying bug with the nvidia driver 87XX serie. -#define epsilon 0.000001 - -uniform vec4 viewport; - -#ifndef ES_DEFERRED_SHADING - -uniform sampler2DRect ColorWeight; -#if (ES_OUTPUT_DEPTH==1) -uniform sampler2DRect Depth; -#endif - -void Finalization(void) -{ - vec4 color = texture2DRect(ColorWeight, gl_FragCoord.st - viewport.xy + epsilon); - #if (ES_OUTPUT_DEPTH==1) - gl_FragDepth = texture2DRect(Depth, gl_FragCoord.st + epsilon).x; - #endif - if (color.w<0.001) - discard; - gl_FragColor = color/color.w; - gl_FragColor.a = 1.; -} - -#else - -uniform vec2 unproj; - -uniform sampler2DRect ColorWeight; -uniform sampler2DRect NormalWeight; - -#if ( (ES_DEPTH_INTERPOLATION==0) || (ES_OUTPUT_DEPTH==1)) -uniform sampler2DRect Depth; -#endif - -void Finalization(void) -{ - vec4 color = texture2DRect(ColorWeight, gl_FragCoord.st - viewport.xy + epsilon); - - if (color.w<0.001) - discard; - - - if(color.w>0.001) - color.xyz /= color.w; - - vec3 viewVec = normalize(gl_TexCoord[0].xyz); - vec4 normaldepth = texture2DRect(NormalWeight, gl_FragCoord.st + epsilon); - - normaldepth.xyz = normaldepth.xyz/normaldepth.w; - - #if (ES_OUTPUT_DEPTH==1) - gl_FragDepth = texture2DRect(Depth, gl_FragCoord.st + epsilon).x; - #endif - - #if ES_DEPTH_INTERPOLATION==2 - float depth = -normaldepth.z; - #elif ES_DEPTH_INTERPOLATION==1 - float depth = unproj.y/(2.0*normaldepth.z+unproj.x-1.0); - #else - float depth = texture2DRect(Depth, gl_FragCoord.st + epsilon).x; - depth = unproj.y/(2.0*depth+unproj.x-1.0); - #endif - - vec3 normal = normaldepth.xyz; - #if ES_DEPTH_INTERPOLATION!=0 - normal.z = sqrt(1. - dot(vec3(normal.xy,0),vec3(normal.xy,0))); - #endif - normal = normalize(normal); - vec3 eyePos = gl_TexCoord[0].xyz * depth; - - gl_FragColor = meshlabLighting(color, eyePos, normal); - gl_FragColor.a = 1.0; -} - -#endif - - - diff --git a/Polyhedron/demo/Polyhedron/GlSplat/shaders/Raycasting.glsl b/Polyhedron/demo/Polyhedron/GlSplat/shaders/Raycasting.glsl deleted file mode 100644 index c2b4cc0539f..00000000000 --- a/Polyhedron/demo/Polyhedron/GlSplat/shaders/Raycasting.glsl +++ /dev/null @@ -1,335 +0,0 @@ -// This file is part of GlSplat, a simple splatting C++ library -// -// Copyright (C) 2008-2009 Gael Guennebaud -// -// GlSplat is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// GlSplat is distributed in the hope that it will be useful, but WITHOUT ANY -// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with GlSplat. If not, see . - -#pragma optimize(on) - -#ifndef ES_EWA_HINT - #define ES_EWA_HINT 0 -#endif - -#ifndef ES_DEPTH_INTERPOLATION - #define ES_DEPTH_INTERPOLATION 0 -#endif - -//-------------------------------------------------------------------------------- -// shared variables -//-------------------------------------------------------------------------------- - -// custom vertex attributes -//attribute float radius; - -#ifdef CLIPPED_SPLAT -attribute vec3 secondNormal; -varying vec4 clipLine; -#endif - -// standard uniforms -uniform float expeRadiusScale; -uniform float expePreComputeRadius; -uniform float expeDepthOffset; - -// varying -varying vec4 covmat; -varying vec3 fragNormal; - -varying vec3 fragNoverCdotN; -varying vec3 fragCenter; -varying float scaleSquaredDistance; - -#ifdef ES_ATI_WORKAROUND -varying vec4 fragCenterAndRadius; -#endif - -#ifdef ES_DEPTH_CORRECTION -varying float depthOffset; -#endif - -uniform vec2 halfVp; -uniform float oneOverEwaRadius; - - -#ifdef ES_BACKFACE_SHADING - #undef ES_EARLY_BACK_FACE_CULLING - //#define ES_EWA_HINT 2 -#endif - -//-------------------------------------------------------------------------------- -// Visibility Splatting -// Vertex Shader -//-------------------------------------------------------------------------------- - -#ifdef GLSPLAT__VisibilityVP__ -varying vec2 scaledFragCenter2d; -void VisibilityVP(void) -{ - vec3 normal = normalize(gl_NormalMatrix * gl_Normal); - // Point in eye space - vec4 ePos = gl_ModelViewMatrix * gl_Vertex; - - float dotpn = dot(normal.xyz,ePos.xyz); - - vec4 oPos; - - #ifdef ES_EARLY_BACK_FACE_CULLING - // back_face culling - oPos = vec4(0,0,1,0); - if(dotpn<0.) - { - #endif - - float radius = gl_MultiTexCoord2.x * expeRadiusScale; - - vec4 pointSize; - pointSize.x = radius * expePreComputeRadius / ePos.z; - gl_PointSize = max(1.0, pointSize.x); - - scaleSquaredDistance = 1.0 / (radius * radius); - //fragNormal = normal; - fragCenter = ePos.xyz; - fragNoverCdotN = normal/dot(ePos.xyz,normal); - - #ifndef ES_DEPTH_CORRECTION - ePos.xyz += normalize(ePos.xyz) * expeDepthOffset * radius; - #else - //ePos.xyz += normalize(ePos.xyz) * expeDepthOffset * radius; - depthOffset = expeDepthOffset * radius; - #endif - - oPos = gl_ProjectionMatrix * ePos; - - #if (ES_EWA_HINT>0) - scaledFragCenter2d = 0.5*((oPos.xy/oPos.w)+1.0)*halfVp*oneOverEwaRadius; - #endif - - #ifdef ES_ATI_WORKAROUND - fragCenterAndRadius.xyz = (oPos.xyz/oPos.w) + 1.0; - fragCenterAndRadius.xy = fragCenterAndRadius.xy*halfVp; - fragCenterAndRadius.z = fragCenterAndRadius.z*0.5; - fragCenterAndRadius.w = pointSize.x; - #endif - - #ifndef ES_EARLY_BACK_FACE_CULLING - oPos.w = oPos.w * (dotpn<0.0 ? 1.0 : 0.0); - #else - } - #endif - - gl_Position = oPos; -} - -#endif - -//-------------------------------------------------------------------------------- -// Visibility Splatting -// Fragment Shader -//-------------------------------------------------------------------------------- - -#ifdef GLSPLAT__VisibilityFP__ -varying vec2 scaledFragCenter2d; -uniform vec3 rayCastParameter1; -uniform vec3 rayCastParameter2; -uniform vec2 depthParameterCast; - -void VisibilityFP(void) -{ - #ifdef ES_ATI_WORKAROUND - vec3 fragCoord; - fragCoord.xy = fragCenterAndRadius.xy + (gl_TexCoord[0].st-0.5) * fragCenterAndRadius.w; - fragCoord.z = fragCenterAndRadius.z; - #else - vec3 fragCoord = gl_FragCoord.xyz; - #endif - // compute q in object space - vec3 qOne = rayCastParameter1 * fragCoord + rayCastParameter2; - float oneOverDepth = dot(qOne,-fragNoverCdotN); - float depth = (1.0/oneOverDepth); - vec3 diff = fragCenter + qOne * depth; - float r2 = dot(diff,diff); - - #if (ES_EWA_HINT>0) - vec2 d2 = oneOverEwaRadius*gl_FragCoord.xy - scaledFragCenter2d; - float r2d = dot(d2,d2); - gl_FragColor = vec4(min(r2d,r2*scaleSquaredDistance)); - #else - gl_FragColor = vec4(r2*scaleSquaredDistance); - #endif - - #ifdef ES_DEPTH_CORRECTION - oneOverDepth = 1.0/(-depth+depthOffset); - gl_FragDepth = depthParameterCast.x * oneOverDepth + depthParameterCast.y; - #endif -} - -#endif - -#ifdef GLSPLAT__AttributeVP__ - -varying vec2 scaledFragCenter2d; - -void AttributeVP(void) -{ - // transform normal - vec3 normal = normalize(gl_NormalMatrix * gl_Normal); - // Point in eye space - vec4 ePos = gl_ModelViewMatrix * gl_Vertex; - - float dotpn = dot(normal.xyz,ePos.xyz); - - vec4 oPos; - - #ifdef ES_EARLY_BACK_FACE_CULLING - // back_face culling - oPos = vec4(0,0,1,0); - if(dotpn<0.) - { - #endif - - #ifdef ES_BACKFACE_SHADING - if(dotpn>0.) - { - dotpn = -dotpn; - normal = -normal; - } - #endif - - float radius = gl_MultiTexCoord2.x * expeRadiusScale * 1.1; - - vec4 pointSize; - pointSize.x = radius * expePreComputeRadius / ePos.z; - - #if (ES_EWA_HINT>0) - gl_PointSize = max(2.0, pointSize.x); - #else - gl_PointSize = max(1.0, pointSize.x); - #endif - - scaleSquaredDistance = 1. / (radius * radius); - fragNormal = normal; - fragCenter = ePos.xyz; - fragNoverCdotN = normal/dot(ePos.xyz,normal); - - // Output color - #ifdef ES_DEFERRED_SHADING - fragNormal.xyz = normal.xyz; - gl_FrontColor = gl_Color; - #else - // Output color - #ifdef ES_LIGHTING - gl_FrontColor = expeLighting(gl_Color, ePos.xyz, normal.xyz, 1.); - #else - gl_FrontColor = meshlabLighting(gl_Color, ePos.xyz, normal.xyz); - #endif - #endif - - oPos = gl_ModelViewProjectionMatrix * gl_Vertex; - - #ifdef ES_ATI_WORKAROUND - fragCenterAndRadius.xyz = (oPos.xyz/oPos.w) + 1.0; - fragCenterAndRadius.xy = fragCenterAndRadius.xy*halfVp; - fragCenterAndRadius.z = fragCenterAndRadius.z*0.5; - fragCenterAndRadius.w = pointSize.x; - #endif - - #if (ES_EWA_HINT>0) - scaledFragCenter2d = ((oPos.xy/oPos.w)+1.0)*halfVp*oneOverEwaRadius; - #endif - - #ifndef ES_EARLY_BACK_FACE_CULLING - oPos.w = oPos.w * (dotpn<0. ? 1.0 : 0.0); - #else - } - #endif - - gl_Position = oPos; -} - -#endif - -//-------------------------------------------------------------------------------- -// EWA Splatting -// Fragment Shader -//-------------------------------------------------------------------------------- - -#ifdef GLSPLAT__AttributeFP__ -// this sampler is only used by this fragment shader - -varying vec2 scaledFragCenter2d; -uniform vec3 rayCastParameter1; -uniform vec3 rayCastParameter2; -uniform vec2 depthParameterCast; - -// uniform sampler1D Kernel1dMap; - -void AttributeFP(void) -{ - #ifdef ES_ATI_WORKAROUND - vec3 fragCoord; - fragCoord.xy = fragCenterAndRadius.xy + (gl_TexCoord[0].st-0.5) * fragCenterAndRadius.w; - fragCoord.z = fragCenterAndRadius.z; - #else - vec3 fragCoord = gl_FragCoord.xyz; - #endif - -#if 1 - vec3 qOne = rayCastParameter1 * fragCoord + rayCastParameter2; - float oneOverDepth = dot(qOne,fragNoverCdotN); - float depth = (1.0/oneOverDepth); - vec3 diff = fragCenter - qOne * depth; - float r2 = dot(diff,diff); - - #if (ES_EWA_HINT>0) - vec2 d2 = oneOverEwaRadius*gl_FragCoord.xy - scaledFragCenter2d; - float r2d = dot(d2,d2); -// float weight = texture1D(Kernel1dMap, min(r2d,r2*scaleSquaredDistance)).a; - float weight = min(r2d,r2*scaleSquaredDistance); - weight = clamp(1.-weight,0,1); - weight = weight*weight; - #else - //float weight = texture1D(Kernel1dMap, r2*scaleSquaredDistance).a; - float weight = clamp(1.-r2*scaleSquaredDistance,0.0,1.0); - weight = weight*weight; - #endif - weight *= 0.1; // limits overflow - - #ifdef ES_DEPTH_CORRECTION - gl_FragDepth = depthParameterCast.x * oneOverDepth + depthParameterCast.y; - #endif - - #ifdef ES_DEFERRED_SHADING - gl_FragData[0].rgb = gl_Color.rgb; - gl_FragData[1].xyz = fragNormal.xyz; - gl_FragData[1].w = weight; - gl_FragData[0].w = weight; - - #if ES_DEPTH_INTERPOLATION==2 // linear space - gl_FragData[1].z = -depth; - #elif ES_DEPTH_INTERPOLATION==1 // window space - #ifdef ES_DEPTH_CORRECTION - gl_FragData[1].z = gl_FragDepth; - #else - gl_FragData[1].z = fragCoord.z; - #endif - #endif - - #else - gl_FragColor.rgb = gl_Color.rgb; - gl_FragColor.w = weight; - #endif -#endif -} - -#endif diff --git a/Polyhedron/demo/Polyhedron/Io_implicit_function_plugin.cpp b/Polyhedron/demo/Polyhedron/Io_implicit_function_plugin.cpp index 132a19a195d..fcf3c3dc4c2 100644 --- a/Polyhedron/demo/Polyhedron/Io_implicit_function_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Io_implicit_function_plugin.cpp @@ -49,6 +49,7 @@ class Io_implicit_function_plugin : { Q_OBJECT Q_INTERFACES(Polyhedron_demo_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") public: Io_implicit_function_plugin(); @@ -209,7 +210,4 @@ load_function_plugins() } } - -#include -Q_EXPORT_PLUGIN2(Io_implicit_function_plugin, Io_implicit_function_plugin) #include "Io_implicit_function_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/MainWindow.cpp b/Polyhedron/demo/Polyhedron/MainWindow.cpp index 71f2dc77100..838d966d03b 100644 --- a/Polyhedron/demo/Polyhedron/MainWindow.cpp +++ b/Polyhedron/demo/Polyhedron/MainWindow.cpp @@ -157,13 +157,12 @@ MainWindow::MainWindow(QWidget* parent) sceneView->setItemDelegate(new SceneDelegate(this)); sceneView->header()->setStretchLastSection(false); - sceneView->header()->setResizeMode(Scene::NameColumn, QHeaderView::Stretch); - sceneView->header()->setResizeMode(Scene::NameColumn, QHeaderView::Stretch); - sceneView->header()->setResizeMode(Scene::ColorColumn, QHeaderView::ResizeToContents); - sceneView->header()->setResizeMode(Scene::RenderingModeColumn, QHeaderView::Fixed); - sceneView->header()->setResizeMode(Scene::ABColumn, QHeaderView::Fixed); - sceneView->header()->setResizeMode(Scene::VisibleColumn, QHeaderView::Fixed); - + sceneView->header()->setSectionResizeMode(Scene::NameColumn, QHeaderView::Stretch); + sceneView->header()->setSectionResizeMode(Scene::NameColumn, QHeaderView::Stretch); + sceneView->header()->setSectionResizeMode(Scene::ColorColumn, QHeaderView::ResizeToContents); + sceneView->header()->setSectionResizeMode(Scene::RenderingModeColumn, QHeaderView::Fixed); + sceneView->header()->setSectionResizeMode(Scene::ABColumn, QHeaderView::Fixed); + sceneView->header()->setSectionResizeMode(Scene::VisibleColumn, QHeaderView::Fixed); sceneView->resizeColumnToContents(Scene::ColorColumn); sceneView->resizeColumnToContents(Scene::RenderingModeColumn); sceneView->resizeColumnToContents(Scene::ABColumn); @@ -180,7 +179,7 @@ MainWindow::MainWindow(QWidget* parent) viewer, SLOT(updateGL())); connect(scene, SIGNAL(updated()), - viewer, SLOT(update())); + viewer, SLOT(updateGL())); connect(scene, SIGNAL(updated()), this, SLOT(selectionChanged())); diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_3.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_3.cpp index b1a835e8c3e..01e69f2b6bb 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_3.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_3.cpp @@ -38,10 +38,11 @@ int main(int argc, char **argv) app.setOrganizationDomain("geometryfactory.com"); app.setOrganizationName("GeometryFactory"); app.setApplicationName("Polyhedron_3 demo"); + //for windows + app.setAttribute(Qt::AA_UseDesktopOpenGL); - // Import resources from libCGALQt4. - // See http://doc.trolltech.com/4.4/qdir.html#Q_INIT_RESOURCE - CGAL_QT4_INIT_RESOURCES; + // Import resources from libCGAL (Qt5). + CGAL_QT_INIT_RESOURCES; MainWindow mainWindow; mainWindow.show(); @@ -59,7 +60,10 @@ int main(int argc, char **argv) mainWindow.enableScriptDebugger(); args.removeAt(0); } - mainWindow.load_script(QFileInfo("autostart.js")); + QFileInfo autostart_js("autostart.js"); + if(autostart_js.exists()) { + mainWindow.load_script(autostart_js); + } #endif Q_FOREACH(QString filename, args) { mainWindow.open(filename); diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_3.qrc b/Polyhedron/demo/Polyhedron/Polyhedron_3.qrc index e1953204d5b..2a7c7539ed8 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_3.qrc +++ b/Polyhedron/demo/Polyhedron/Polyhedron_3.qrc @@ -1,19 +1,28 @@ - - resources/cgal_logo.xpm - resources/boolean-union.png - resources/kernel.png - resources/boolean-diff.png - resources/boolean-intersection.png - resources/convex-hull.png - resources/simplification.png - resources/editcopy.png - resources/check-on.png - resources/plus.png - resources/check-off.png - resources/minus.png - - - resources/about.html - + + resources/cgal_logo.xpm + resources/boolean-union.png + resources/kernel.png + resources/boolean-diff.png + resources/boolean-intersection.png + resources/convex-hull.png + resources/simplification.png + resources/editcopy.png + resources/check-on.png + resources/plus.png + resources/check-off.png + resources/minus.png + + + resources/about.html + resources/shader_with_light.v + resources/shader_with_light.f + resources/shader_without_light.f + resources/shader_without_light.v + resources/shader_with_texture.f + resources/shader_with_textured_edges.f + resources/shader_with_textured_edges.v + resources/shader_with_texture.v + resources/shader_instanced.v + diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_advancing_front_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_advancing_front_plugin.cpp index 5f6aa369511..98e04f54846 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_advancing_front_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_advancing_front_plugin.cpp @@ -45,6 +45,8 @@ class Polyhedron_demo_advancing_front_plugin : { Q_OBJECT Q_INTERFACES(Polyhedron_demo_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") + QAction* actionAdvancingFrontReconstruction; public: @@ -130,6 +132,4 @@ void Polyhedron_demo_advancing_front_plugin::on_actionAdvancingFrontReconstructi } } -Q_EXPORT_PLUGIN2(Polyhedron_demo_advancing_front_plugin, Polyhedron_demo_advancing_front_plugin) - #include "Polyhedron_demo_advancing_front_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_camera_positions_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_camera_positions_plugin.cpp index d78b5079c8f..b31f94c1373 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_camera_positions_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_camera_positions_plugin.cpp @@ -15,6 +15,9 @@ class Polyhedron_demo_camera_positions_plugin : { Q_OBJECT Q_INTERFACES(Polyhedron_demo_plugin_interface Polyhedron_demo_io_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.IOPluginInterface/1.0") + public: void init(QMainWindow* mainWindow, Scene_interface* scene_interface); QList actions() const; @@ -44,6 +47,4 @@ Polyhedron_demo_camera_positions_plugin::actions() const return QList(); } -Q_EXPORT_PLUGIN2(Polyhedron_demo_camera_positions_plugin, Polyhedron_demo_camera_positions_plugin) - #include "Polyhedron_demo_camera_positions_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_convex_hull_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_convex_hull_plugin.cpp index 6a99c0db637..d1e486d3aae 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_convex_hull_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_convex_hull_plugin.cpp @@ -22,6 +22,7 @@ class Polyhedron_demo_convex_hull_plugin : { Q_OBJECT Q_INTERFACES(Polyhedron_demo_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") public: // used by Polyhedron_demo_plugin_helper @@ -118,6 +119,4 @@ void Polyhedron_demo_convex_hull_plugin::on_actionConvexHull_triggered() } } -Q_EXPORT_PLUGIN2(Polyhedron_demo_convex_hull_plugin, Polyhedron_demo_convex_hull_plugin) - #include "Polyhedron_demo_convex_hull_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_corefinement_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_corefinement_plugin.cpp index 1043cfe2434..7b07e76c561 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_corefinement_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_corefinement_plugin.cpp @@ -25,6 +25,7 @@ class Polyhedron_demo_corefinement_plugin : { Q_OBJECT Q_INTERFACES(Polyhedron_demo_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") public: @@ -166,7 +167,8 @@ void Polyhedron_demo_corefinement_plugin::corefinement() new_item->setName(tr("boundary intersection")); new_item->setColor(Qt::green); new_item->setRenderingMode(Wireframe); - scene->addItem(new_item); + scene->addItem(new_item); + new_item->changed(); std::cout << "ok (" << time.elapsed() << " ms)" << std::endl; } @@ -174,6 +176,4 @@ void Polyhedron_demo_corefinement_plugin::corefinement() QApplication::restoreOverrideCursor(); } -Q_EXPORT_PLUGIN2(Polyhedron_demo_corefinement_plugin, Polyhedron_demo_corefinement_plugin) - #include "Polyhedron_demo_corefinement_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_cut_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_cut_plugin.cpp index 286ee92dbef..1cf0186ed72 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_cut_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_cut_plugin.cpp @@ -4,7 +4,6 @@ #include #include "Messages_interface.h" -#include "Scene_item_with_display_list.h" #include "Scene_plane_item.h" #include "Scene_polyhedron_item.h" #include "Polyhedron_demo_plugin_interface.h" @@ -26,6 +25,7 @@ #include #include #include +#include "Scene_item.h" //typedef CGAL::Simple_cartesian Epic_kernel; typedef CGAL::Exact_predicates_inexact_constructions_kernel Epic_kernel; @@ -34,11 +34,19 @@ typedef CGAL::AABB_face_graph_triangle_primitive AABB_primitive; typedef CGAL::AABB_traits AABB_traits; typedef CGAL::AABB_tree AABB_tree; -class Q_DECL_EXPORT Scene_aabb_item : public Scene_item_with_display_list +class Q_DECL_EXPORT Scene_aabb_item : public Scene_item { Q_OBJECT public: - Scene_aabb_item(const AABB_tree& tree_) : tree(tree_) {} + Scene_aabb_item(const AABB_tree& tree_) : Scene_item(1,1), tree(tree_) + { + positions_lines.resize(0); + qFunc.initializeOpenGLFunctions(); + } + + ~Scene_aabb_item() + { + } bool isFinite() const { return true; } bool isEmpty() const { return tree.empty(); } @@ -74,20 +82,74 @@ public: } // Wireframe OpenGL drawing in a display list - void direct_draw() const { - CGAL::AABB_drawing_traits > traits; - tree.traversal(0, traits); + void changed() + { + compute_elements(); + are_buffers_filled = false; } - public: const AABB_tree& tree; +private: + std::vector positions_lines; + + mutable QOpenGLShaderProgram *program; + + using Scene_item::initialize_buffers; + void initialize_buffers(Viewer_interface *viewer)const + { + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT, viewer); + program->bind(); + vaos[0]->bind(); + + buffers[0].bind(); + buffers[0].allocate(positions_lines.data(), + static_cast(positions_lines.size()*sizeof(float))); + program->enableAttributeArray("vertex"); + program->setAttributeBuffer("vertex",GL_FLOAT,0,3); + buffers[0].release(); + program->release(); + + vaos[0]->release(); + are_buffers_filled = true; + } + + void compute_elements() + { + positions_lines.clear(); + + CGAL::AABB_drawing_traits > traits; + traits.v_edges = &positions_lines; + + tree.traversal(0, traits); + } + void draw_edges(Viewer_interface* viewer) const + { + if(!are_buffers_filled) + initialize_buffers(viewer); + vaos[0]->bind(); + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT); + attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT); + program->bind(); + program->setAttributeValue("colors",this->color()); + qFunc.glDrawArrays(GL_LINES, 0, static_cast(positions_lines.size()/3)); + program->release(); + vaos[0]->release(); + } }; // end class Scene_aabb_item class Q_DECL_EXPORT Scene_edges_item : public Scene_item { Q_OBJECT public: - bool isFinite() const { return true; } + Scene_edges_item():Scene_item(1,1) + { + positions_lines.resize(0); + qFunc.initializeOpenGLFunctions(); + } + ~Scene_edges_item() + { + } + bool isFinite() const { return true; } bool isEmpty() const { return edges.empty(); } Bbox bbox() const { if(isEmpty()) @@ -103,9 +165,14 @@ public: bbox.ymax(), bbox.zmax()); } + void changed() + { + compute_elements(); + are_buffers_filled = false; + } Scene_edges_item* clone() const { - Scene_edges_item* item = new Scene_edges_item; + Scene_edges_item* item = new Scene_edges_item(); item->edges = edges; return item; } @@ -126,22 +193,7 @@ public: return (m == Wireframe); } - // Flat/Gouraud OpenGL drawing - void draw() const {} - // Wireframe OpenGL drawing - void draw_edges() const { - ::glBegin(GL_LINES); - for(size_t i = 0, end = edges.size(); - i < end; ++i) - { - const Epic_kernel::Point_3& a = edges[i].source(); - const Epic_kernel::Point_3& b = edges[i].target(); - ::glVertex3d(a.x(), a.y(), a.z()); - ::glVertex3d(b.x(), b.y(), b.z()); - } - ::glEnd(); - } bool save(std::ostream& os) const { @@ -154,6 +206,58 @@ public: public: std::vector edges; + +private: + std::vector positions_lines; + + mutable QOpenGLShaderProgram *program; + + using Scene_item::initialize_buffers; + void initialize_buffers(Viewer_interface *viewer)const + { + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT, viewer); + program->bind(); + vaos[0]->bind(); + + buffers[0].bind(); + buffers[0].allocate(positions_lines.data(), + static_cast(positions_lines.size()*sizeof(float))); + program->enableAttributeArray("vertex"); + program->setAttributeBuffer("vertex",GL_FLOAT,0,3); + buffers[0].release(); + program->release(); + + vaos[0]->release(); + are_buffers_filled = true; + } + void compute_elements() + { + positions_lines.clear(); + + for(size_t i = 0, end = edges.size(); + i < end; ++i) + { + const Epic_kernel::Point_3& a = edges[i].source(); + const Epic_kernel::Point_3& b = edges[i].target(); + positions_lines.push_back(a.x()); positions_lines.push_back(a.y()); positions_lines.push_back(a.z()); + positions_lines.push_back(b.x()); positions_lines.push_back(b.y()); positions_lines.push_back(b.z()); + } + } + void draw_edges(Viewer_interface* viewer) const + { + if(!are_buffers_filled) + initialize_buffers(viewer); + vaos[0]->bind(); + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT); + attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT); + program->bind(); + program->setAttributeValue("colors",this->color()); + qFunc.glDrawArrays(GL_LINES, 0, static_cast(positions_lines.size()/3)); + vaos[0]->release(); + program->release(); + + } + }; // end class Scene_edges_item @@ -165,6 +269,7 @@ class Polyhedron_demo_cut_plugin : Q_OBJECT Q_INTERFACES(Polyhedron_demo_plugin_interface) Q_INTERFACES(Polyhedron_demo_io_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") public: Polyhedron_demo_cut_plugin() : QObject(), edges_item(0) { @@ -360,7 +465,7 @@ void Polyhedron_demo_cut_plugin::cut() { edges_item->edges.push_back(*inter_seg); } } - + messages->information(QString("cut (%1 ms). %2 edges.").arg(time.elapsed()).arg(edges_item->edges.size())); scene->itemChanged(edges_item); QApplication::restoreOverrideCursor(); @@ -370,6 +475,4 @@ void Polyhedron_demo_cut_plugin::enableAction() { actionCreateCutPlane->setEnabled(true); } -Q_EXPORT_PLUGIN2(Polyhedron_demo_cut_plugin, Polyhedron_demo_cut_plugin) - #include "Polyhedron_demo_cut_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_edit_polyhedron_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_edit_polyhedron_plugin.cpp index ab26c3d5d82..fbf0f337fcf 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_edit_polyhedron_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_edit_polyhedron_plugin.cpp @@ -16,6 +16,7 @@ class Polyhedron_demo_edit_polyhedron_plugin : { Q_OBJECT Q_INTERFACES(Polyhedron_demo_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") public: Polyhedron_demo_edit_polyhedron_plugin() @@ -390,8 +391,4 @@ Polyhedron_demo_edit_polyhedron_plugin::convert_to_plain_polyhedron(Item_id i, return poly_item; } - - -Q_EXPORT_PLUGIN2(Polyhedron_demo_edit_polyhedron_plugin, Polyhedron_demo_edit_polyhedron_plugin) - #include "Polyhedron_demo_edit_polyhedron_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_features_detection_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_features_detection_plugin.cpp index c89acca3f64..859573f6b17 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_features_detection_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_features_detection_plugin.cpp @@ -18,6 +18,7 @@ class Polyhedron_demo_features_detection_plugin : { Q_OBJECT Q_INTERFACES(Polyhedron_demo_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.IOPluginInterface/1.0") QAction* actionDetectFeatures; public: QList actions() const { return QList() << actionDetectFeatures; } @@ -111,6 +112,4 @@ void Polyhedron_demo_features_detection_plugin::on_actionDetectFeatures_triggere } -Q_EXPORT_PLUGIN2(Polyhedron_demo_features_detection_plugin, Polyhedron_demo_features_detection_plugin) - #include "Polyhedron_demo_features_detection_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_gocad_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_gocad_plugin.cpp index b18955a74ce..31f7514cbf4 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_gocad_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_gocad_plugin.cpp @@ -17,6 +17,7 @@ class Polyhedron_demo_gocad_plugin : { Q_OBJECT Q_INTERFACES(Polyhedron_demo_io_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.IOPluginInterface/1.0") public: QString nameFilters() const; @@ -105,6 +106,4 @@ bool Polyhedron_demo_gocad_plugin::save(const Scene_item* item, QFileInfo filein } -#include -Q_EXPORT_PLUGIN2(Polyhedron_demo_gocad_plugin, Polyhedron_demo_gocad_plugin) #include "Polyhedron_demo_gocad_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_inside_out_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_inside_out_plugin.cpp index 44a9ef84397..6c2c5fd3829 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_inside_out_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_inside_out_plugin.cpp @@ -16,6 +16,7 @@ class Polyhedron_demo_inside_out_plugin : { Q_OBJECT Q_INTERFACES(Polyhedron_demo_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") public: // used by Polyhedron_demo_plugin_helper @@ -67,6 +68,4 @@ void Polyhedron_demo_inside_out_plugin::on_actionInsideOut_triggered() } } -Q_EXPORT_PLUGIN2(Polyhedron_demo_inside_out_plugin, Polyhedron_demo_inside_out_plugin) - #include "Polyhedron_demo_inside_out_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_intersection_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_intersection_plugin.cpp index 3728ac55595..63bae2e5fb4 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_intersection_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_intersection_plugin.cpp @@ -30,6 +30,7 @@ class Polyhedron_demo_intersection_plugin : { Q_OBJECT Q_INTERFACES(Polyhedron_demo_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") public: @@ -209,10 +210,9 @@ void Polyhedron_demo_intersection_plugin::intersection() new_item->setColor(Qt::green); new_item->setRenderingMode(Wireframe); scene->addItem(new_item); + new_item->changed(); QApplication::restoreOverrideCursor(); } -Q_EXPORT_PLUGIN2(Polyhedron_demo_intersection_plugin, Polyhedron_demo_intersection_plugin) - #include "Polyhedron_demo_intersection_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_io_nef_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_io_nef_plugin.cpp index d5db71f7658..8ee3bdeaab8 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_io_nef_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_io_nef_plugin.cpp @@ -9,6 +9,7 @@ class Polyhedron_demo_io_nef_plugin : { Q_OBJECT Q_INTERFACES(Polyhedron_demo_io_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") public: QString nameFilters() const; @@ -73,6 +74,4 @@ bool Polyhedron_demo_io_nef_plugin::save(const Scene_item* item, QFileInfo filei return (nef_item && nef_item->save(out)); } -#include -Q_EXPORT_PLUGIN2(Polyhedron_demo_io_nef_plugin, Polyhedron_demo_io_nef_plugin) #include "Polyhedron_demo_io_nef_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_jet_fitting_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_jet_fitting_plugin.cpp index fd15f541d14..26cdf588dac 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_jet_fitting_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_jet_fitting_plugin.cpp @@ -18,6 +18,7 @@ class Polyhedron_demo_jet_fitting_plugin : { Q_OBJECT Q_INTERFACES(Polyhedron_demo_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") public: // used by Polyhedron_demo_plugin_helper @@ -56,7 +57,6 @@ void Polyhedron_demo_jet_fitting_plugin::on_actionEstimateCurvature_triggered() Scene_polylines_item* max_curv = new Scene_polylines_item; max_curv->setColor(Qt::red); max_curv->setName(tr("%1 (max curvatures)").arg(poly_item->name())); - Scene_polylines_item* min_curv = new Scene_polylines_item; min_curv->setColor(Qt::green); min_curv->setName(tr("%1 (min curvatures)").arg(poly_item->name())); @@ -121,11 +121,11 @@ void Polyhedron_demo_jet_fitting_plugin::on_actionEstimateCurvature_triggered() scene->addItem(max_curv); scene->addItem(min_curv); + max_curv->changed(); + min_curv->changed(); // default cursor QApplication::restoreOverrideCursor(); } -Q_EXPORT_PLUGIN2(Polyhedron_demo_jet_fitting_plugin, Polyhedron_demo_jet_fitting_plugin) - #include "Polyhedron_demo_jet_fitting_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_join_and_split_polyhedra_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_join_and_split_polyhedra_plugin.cpp index d4fea813239..eaa9e130ee3 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_join_and_split_polyhedra_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_join_and_split_polyhedra_plugin.cpp @@ -21,6 +21,7 @@ class Polyhedron_demo_join_and_split_polyhedra_plugin: public Polyhedron_demo_plugin_helper { Q_OBJECT + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") Q_INTERFACES(Polyhedron_demo_plugin_interface) QAction* actionJoinPolyhedra, *actionSplitPolyhedra, *actionColorConnectedComponents; Messages_interface* msg_interface; @@ -166,6 +167,5 @@ void Polyhedron_demo_join_and_split_polyhedra_plugin::on_actionColorConnectedCom } } -Q_EXPORT_PLUGIN2(Polyhedron_demo_join_and_split_polyhedra_plugin, Polyhedron_demo_join_and_split_polyhedra_plugin) #include "Polyhedron_demo_join_and_split_polyhedra_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_kernel_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_kernel_plugin.cpp index a5faa67ba1d..2c80136600c 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_kernel_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_kernel_plugin.cpp @@ -30,6 +30,7 @@ class Polyhedron_demo_kernel_plugin : { Q_OBJECT Q_INTERFACES(Polyhedron_demo_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") public: // used by Polyhedron_demo_plugin_helper @@ -133,6 +134,4 @@ void Polyhedron_demo_kernel_plugin::on_actionKernel_triggered() } } -Q_EXPORT_PLUGIN2(Polyhedron_demo_kernel_plugin, Polyhedron_demo_kernel_plugin) - #include "Polyhedron_demo_kernel_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_mean_curvature_flow_skeleton_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_mean_curvature_flow_skeleton_plugin.cpp index e52a7740c4a..e8d3625ef3a 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_mean_curvature_flow_skeleton_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_mean_curvature_flow_skeleton_plugin.cpp @@ -103,6 +103,7 @@ class Polyhedron_demo_mean_curvature_flow_skeleton_plugin : { Q_OBJECT Q_INTERFACES(Polyhedron_demo_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") QAction* actionMCFSkeleton; QAction* actionConvert_to_medial_skeleton; @@ -117,13 +118,43 @@ public: dockWidget = NULL; ui = NULL; - actionMCFSkeleton = new QAction(tr("Mean Curvature Skeleton"), mainWindow); + actionMCFSkeleton = new QAction(tr("Mean Curvature Skeleton (Advanced)"), mainWindow); actionMCFSkeleton->setObjectName("actionMCFSkeleton"); actionConvert_to_medial_skeleton = new QAction(tr("Extract Medial Skeleton"), mainWindow); actionConvert_to_medial_skeleton->setObjectName("actionConvert_to_medial_skeleton"); Polyhedron_demo_plugin_helper::init(mainWindow, scene_interface); + + dockWidget = new QDockWidget(mw); + dockWidget->setVisible(false); + ui = new Ui::Mean_curvature_flow_skeleton_plugin(); + ui->setupUi(dockWidget); + dockWidget->setFeatures(QDockWidget::DockWidgetMovable + | QDockWidget::DockWidgetFloatable + | QDockWidget::DockWidgetClosable); + dockWidget->setWindowTitle("Mean Curvature Flow Skeleton"); + add_dock_widget(dockWidget); + + connect(ui->pushButton_contract, SIGNAL(clicked()), + this, SLOT(on_actionContract())); + connect(ui->pushButton_collapse, SIGNAL(clicked()), + this, SLOT(on_actionCollapse())); + connect(ui->pushButton_split, SIGNAL(clicked()), + this, SLOT(on_actionSplit())); + connect(ui->pushButton_degeneracy, SIGNAL(clicked()), + this, SLOT(on_actionDegeneracy())); + connect(ui->pushButton_run, SIGNAL(clicked()), + this, SLOT(on_actionRun())); + connect(ui->pushButton_skeletonize, SIGNAL(clicked()), + this, SLOT(on_actionSkeletonize())); + connect(ui->pushButton_converge, SIGNAL(clicked()), + this, SLOT(on_actionConverge())); + connect(dynamic_cast(scene), SIGNAL(updated_bbox()), + this, SLOT(on_actionUpdateBBox())); + connect(ui->pushButton_segment, SIGNAL(clicked()), + this, SLOT(on_actionSegment())); + } QList actions() const { @@ -348,6 +379,9 @@ private: void Polyhedron_demo_mean_curvature_flow_skeleton_plugin::on_actionMCFSkeleton_triggered() { + dockWidget->show(); + dockWidget->raise(); + const Scene_interface::Item_id index = scene->mainSelectionIndex(); Scene_polyhedron_item* item = @@ -359,36 +393,6 @@ void Polyhedron_demo_mean_curvature_flow_skeleton_plugin::on_actionMCFSkeleton_t if(!pMesh) return; - dockWidget = new QDockWidget(mw); - ui = new Ui::Mean_curvature_flow_skeleton_plugin(); - ui->setupUi(dockWidget); - dockWidget->setFeatures(QDockWidget::DockWidgetMovable - | QDockWidget::DockWidgetFloatable - | QDockWidget::DockWidgetClosable); - dockWidget->setWindowTitle("Mean Curvature Flow Skeleton"); - mw->addDockWidget(Qt::LeftDockWidgetArea, dockWidget); - dockWidget->show(); - dockWidget->raise(); - - connect(ui->pushButton_contract, SIGNAL(clicked()), - this, SLOT(on_actionContract())); - connect(ui->pushButton_collapse, SIGNAL(clicked()), - this, SLOT(on_actionCollapse())); - connect(ui->pushButton_split, SIGNAL(clicked()), - this, SLOT(on_actionSplit())); - connect(ui->pushButton_degeneracy, SIGNAL(clicked()), - this, SLOT(on_actionDegeneracy())); - connect(ui->pushButton_run, SIGNAL(clicked()), - this, SLOT(on_actionRun())); - connect(ui->pushButton_skeletonize, SIGNAL(clicked()), - this, SLOT(on_actionSkeletonize())); - connect(ui->pushButton_converge, SIGNAL(clicked()), - this, SLOT(on_actionConverge())); - connect(dynamic_cast(scene), SIGNAL(updated_bbox()), - this, SLOT(on_actionUpdateBBox())); - connect(ui->pushButton_segment, SIGNAL(clicked()), - this, SLOT(on_actionSegment())); - double diag = scene->len_diagonal(); init_ui(diag); @@ -503,6 +507,7 @@ void Polyhedron_demo_mean_curvature_flow_skeleton_plugin::on_actionConvert_to_me skeleton_item->setName(QString("Medial skeleton curve of %1").arg(item->name())); scene->addItem(skeleton_item); + skeleton_item->changed(); item->setPointsMode(); @@ -820,19 +825,23 @@ void Polyhedron_demo_mean_curvature_flow_skeleton_plugin::on_actionSkeletonize() skeleton->setName(QString("skeleton curve of %1").arg(item->name())); scene->addItem(skeleton); + skeleton->changed(); // set the fixed points and contracted mesh as invisible if (fixedPointsItemIndex >= 0) { scene->item(fixedPointsItemIndex)->setVisible(false); + scene->itemChanged(fixedPointsItemIndex); } scene->item(contractedItemIndex)->setVisible(false); + scene->itemChanged(contractedItemIndex); // display the original mesh in transparent mode item->setVisible(false); if (InputMeshItemIndex >= 0) { scene->item(InputMeshItemIndex)->setVisible(true); scene->item(InputMeshItemIndex)->setPointsMode(); + scene->itemChanged(InputMeshItemIndex); } // update scene @@ -903,6 +912,4 @@ void Polyhedron_demo_mean_curvature_flow_skeleton_plugin::on_actionItemAboutToBe } } -Q_EXPORT_PLUGIN2(Polyhedron_demo_mean_curvature_flow_skeleton_plugin, Polyhedron_demo_mean_curvature_flow_skeleton_plugin) - #include "Polyhedron_demo_mean_curvature_flow_skeleton_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_mesh_3_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_mesh_3_plugin.cpp index 518c4aa03a8..6d51453d1a9 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_mesh_3_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_mesh_3_plugin.cpp @@ -20,17 +20,15 @@ Scene_item* cgal_code_mesh_3(const Polyhedron*, const double angle, const double sizing, const double approx, - const double tets_sizing, - const double tet_shape, - const bool protect_features, - Scene_interface* scene); + const double tets_sizing); -class Polyhedron_demo_mesh_3_plugin : +class Polyhedron_demo_mesh_3_plugin : public QObject, protected Polyhedron_demo_plugin_helper { Q_OBJECT Q_INTERFACES(Polyhedron_demo_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") public: void init(QMainWindow* mainWindow, Scene_interface* scene_interface) { @@ -47,9 +45,11 @@ public: return QList() << actionMesh_3; } + bool applicable(QAction*) const { - return qobject_cast(scene->item(scene->mainSelectionIndex())); + return qobject_cast(scene->item(scene->mainSelectionIndex())); } + public Q_SLOTS: void mesh_3(); @@ -57,133 +57,86 @@ private: QAction* actionMesh_3; }; // end class Polyhedron_demo_mesh_3_plugin -double -get_approximate(double d, int precision, int& decimals) -{ - if ( d<0 ) { return 0; } - - double i = std::pow(10.,precision-1); - - decimals = 0; - while ( d > i*10 ) { d = d/10.; ++decimals; } - while ( d < i ) { d = d*10.; --decimals; } - - return std::floor(d)*std::pow(10.,decimals); -} - void Polyhedron_demo_mesh_3_plugin::mesh_3() { const Scene_interface::Item_id index = scene->mainSelectionIndex(); - - Scene_polyhedron_item* item = + + Scene_polyhedron_item* item = qobject_cast(scene->item(index)); - if(!item) return; + if(item) + { + Polyhedron* pMesh = item->polyhedron(); - Polyhedron* pMesh = item->polyhedron(); + if(!pMesh) return; - if(!pMesh) return; + // TODO: get parameters using ONE dialog box + // sizing and approximation parameters should be expressed as ratio of + // scene bbox diagonal. - // ----------------------------------- - // Create Mesh dialog - // ----------------------------------- - QDialog dialog(mw); - Ui::Meshing_dialog ui; - ui.setupUi(&dialog); - connect(ui.buttonBox, SIGNAL(accepted()), - &dialog, SLOT(accept())); - connect(ui.buttonBox, SIGNAL(rejected()), - &dialog, SLOT(reject())); + double diag = scene->len_diagonal(); - // Connect checkboxes to spinboxes - connect(ui.noApprox, SIGNAL(toggled(bool)), - ui.approx, SLOT(setEnabled(bool))); + bool ok; + const double angle = + QInputDialog::getDouble(mw, tr("Min triangle angle"), + tr("Angle:"), + 25., // default value + 1., // min + 30., // max + 2, // decimals + &ok); + if(!ok) return; - connect(ui.noFacetSizing, SIGNAL(toggled(bool)), - ui.facetSizing, SLOT(setEnabled(bool))); + const double sizing = + QInputDialog::getDouble(mw, "Facets sizing", + "Facets size bound:", + diag * 0.05, // default value + diag * 10e-6, // min + diag, // max + 4, // decimals + &ok); + if(!ok) return; - connect(ui.noAngle, SIGNAL(toggled(bool)), - ui.facetAngle, SLOT(setEnabled(bool))); + const double tets_sizing = + QInputDialog::getDouble(mw, "Tetrahedra sizing", + "Tetrahedra size bound:", + diag * 0.05, // default value + diag * 10e-6, // min + diag, // max + 4, // decimals + &ok); + if(!ok) return; - connect(ui.noTetSizing, SIGNAL(toggled(bool)), - ui.tetSizing, SLOT(setEnabled(bool))); + const double approx = + QInputDialog::getDouble(mw, "Approximation error", + "Error:", + diag * 0.005, // default value + diag * 10e-7, // min + diag, // max + 6, // decimals + &ok); + if(!ok) return; - connect(ui.noTetShape, SIGNAL(toggled(bool)), - ui.tetShape, SLOT(setEnabled(bool))); + QApplication::setOverrideCursor(Qt::WaitCursor); - // Set default parameters - Scene_interface::Bbox bbox = item->bbox(); - ui.objectName->setText(item->name()); - ui.objectNameSize->setText(tr("Object bbox size (w,h,d): %1, %2, %3") - .arg(bbox.width(),0,'g',3) - .arg(bbox.height(),0,'g',3) - .arg(bbox.depth(),0,'g',3) ); - - double diag = bbox.diagonal_length(); - int decimals = 0; - double sizing_default = get_approximate(diag * 0.05, 2, decimals); - ui.facetSizing->setDecimals(-decimals+2); - ui.facetSizing->setSingleStep(std::pow(10.,decimals)); - ui.facetSizing->setRange(diag * 10e-6, // min - diag); // max - ui.facetSizing->setValue(sizing_default); // default value - - ui.tetSizing->setDecimals(-decimals+2); - ui.tetSizing->setSingleStep(std::pow(10.,decimals)); - ui.tetSizing->setRange(diag * 10e-6, // min - diag); // max - ui.tetSizing->setValue(sizing_default); // default value - - double approx_default = get_approximate(diag * 0.005, 2, decimals); - ui.approx->setDecimals(-decimals+2); - ui.approx->setSingleStep(std::pow(10.,decimals)); - ui.approx->setRange(diag * 10e-7, // min - diag); // max - ui.approx->setValue(approx_default); - - // ----------------------------------- - // Get values - // ----------------------------------- - int i = dialog.exec(); - if( i == QDialog::Rejected ) { return; } - - // 0 means parameter is not considered - const double angle = !ui.noAngle->isChecked() ? 0 : ui.facetAngle->value(); - const double approx = !ui.noApprox->isChecked() ? 0 : ui.approx->value(); - const double facet_sizing = !ui.noFacetSizing->isChecked() ? 0 : ui.facetSizing->value(); - const double radius_edge = !ui.noTetShape->isChecked() ? 0 : ui.tetShape->value(); - const double tet_sizing = !ui.noTetSizing->isChecked() ? 0 : ui.tetSizing->value(); - const bool protect_features = ui.protect->isChecked(); - - QApplication::setOverrideCursor(Qt::WaitCursor); - - Scene_item* result_item = cgal_code_mesh_3(pMesh, - item->name(), - angle, - facet_sizing, - approx, - tet_sizing, - radius_edge, - protect_features, - scene); - if(result_item) { - result_item->setName(tr("%1 3d mesh (%2 %3 %4 %5)") - .arg(item->name()) - .arg(angle) - .arg(facet_sizing) - .arg(tet_sizing) - .arg(approx)); - result_item->setColor(Qt::magenta); - result_item->setRenderingMode(item->renderingMode()); - item->setVisible(false); - scene->itemChanged(index); - scene->addItem(result_item); + Scene_item* result_item = cgal_code_mesh_3(pMesh, item->name(), angle, sizing, approx, tets_sizing); + if(result_item) { + result_item->setName(tr("%1 3d mesh (%2 %3 %4 %5)") + .arg(item->name()) + .arg(angle) + .arg(sizing) + .arg(tets_sizing) + .arg(approx)); + result_item->setColor(Qt::magenta); + result_item->setRenderingMode(item->renderingMode()); + item->setVisible(false); + scene->itemChanged(index); + scene->addItem(result_item); + } + QApplication::restoreOverrideCursor(); } - QApplication::restoreOverrideCursor(); } -Q_EXPORT_PLUGIN2(Polyhedron_demo_mesh_3_plugin, Polyhedron_demo_mesh_3_plugin) - #include "Polyhedron_demo_mesh_3_plugin.moc" #endif // CGAL_POLYHEDRON_DEMO_USE_SURFACE_MESHER diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_mesh_3_plugin_cgal_code.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_mesh_3_plugin_cgal_code.cpp index 7d934afe33b..1c7d9d30dd3 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_mesh_3_plugin_cgal_code.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_mesh_3_plugin_cgal_code.cpp @@ -20,7 +20,7 @@ #include typedef CGAL::Polyhedral_mesh_domain_with_features_3 Mesh_domain; +Polyhedron> Mesh_domain; // Triangulation typedef CGAL::Mesh_triangulation_3::type Tr; @@ -42,356 +42,622 @@ typedef Tr::Point Point_3; #include #include -namespace { - void CGALglcolor(QColor c) - { - ::glColor4d(c.red()/255.0, c.green()/255.0, c.blue()/255.0, c.alpha()/255.0); - } -} class Q_DECL_EXPORT Scene_c3t3_item : public Scene_item { - Q_OBJECT + Q_OBJECT public: - typedef qglviewer::ManipulatedFrame ManipulatedFrame; + typedef qglviewer::ManipulatedFrame ManipulatedFrame; - Scene_c3t3_item(const C3t3& c3t3) - : c3t3_(c3t3), frame(new ManipulatedFrame()), last_known_scene(NULL) - {} - - ~Scene_c3t3_item() - { - delete frame; - } - - const C3t3& c3t3() const { - return c3t3_; - } - - bool manipulatable() const { - return true; - } - ManipulatedFrame* manipulatedFrame() { - return frame; - } - - void setPosition(float x, float y, float z) { - frame->setPosition(x, y, z); - } - - void setNormal(float x, float y, float z) { - frame->setOrientation(x, y, z, 0.f); - } - - Kernel::Plane_3 plane() const { - const qglviewer::Vec& pos = frame->position(); - const qglviewer::Vec& n = - frame->inverseTransformOf(qglviewer::Vec(0.f, 0.f, 1.f)); - return Kernel::Plane_3(n[0], n[1], n[2], - n * pos); - } - - bool isFinite() const { return true; } - bool isEmpty() const { - return c3t3().triangulation().number_of_vertices() == 0; - } - - Bbox bbox() const { - if(isEmpty()) - return Bbox(); - else { - CGAL::Bbox_3 result = c3t3().triangulation().finite_vertices_begin()->point().bbox(); - for(Tr::Finite_vertices_iterator - vit = ++c3t3().triangulation().finite_vertices_begin(), - end = c3t3().triangulation().finite_vertices_end(); - vit != end; ++vit) - { - result = result + vit->point().bbox(); - } - return Bbox(result.xmin(), result.ymin(), result.zmin(), - result.xmax(), result.ymax(), result.zmax()); - } - } - - Scene_c3t3_item* clone() const { - return 0; - } - - QString toolTip() const { - int number_of_tets = 0; - for(Tr::Finite_cells_iterator - cit = c3t3().triangulation().finite_cells_begin(), - end = c3t3().triangulation().finite_cells_end(); - cit != end; ++cit) + Scene_c3t3_item(const C3t3& c3t3) + : Scene_item(7,3), c3t3_(c3t3), frame(new ManipulatedFrame()), last_known_scene(NULL) { - if( c3t3().is_in_complex(cit) ) - ++number_of_tets; + positions_lines.resize(0); + positions_poly.resize(0); + color_lines.resize(0); + color_poly.resize(0); + color_grid.resize(0); + normals.resize(0); + qFunc.initializeOpenGLFunctions(); + //Generates an integer which will be used as ID for each buffer } - return tr("

3D complex in a 3D triangulation

" - "

Number of vertices: %1
" - "Number of surface facets: %2
" - "Number of volume tetrahedra: %3

") - .arg(c3t3().triangulation().number_of_vertices()) - .arg(c3t3().number_of_facets()) - .arg(number_of_tets); - } - // Indicate if rendering mode is supported - bool supportsRenderingMode(RenderingMode m) const { - return (m != Gouraud && m!=PointsPlusNormals && m!=Splatting); // CHECK THIS! - } - - void draw() const { - ::glPushMatrix(); - ::glMultMatrixd(frame->matrix()); - QGLViewer::drawGrid((float)complex_diag()); - ::glPopMatrix(); - - if(isEmpty()) - return; - - GLboolean two_side; - ::glGetBooleanv(GL_LIGHT_MODEL_TWO_SIDE, &two_side); - ::glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); - - const Kernel::Plane_3& plane = this->plane(); - GLdouble clip_plane[4]; - clip_plane[0] = -plane.a(); - clip_plane[1] = -plane.b(); - clip_plane[2] = -plane.c(); - clip_plane[3] = -plane.d(); - - ::glClipPlane(GL_CLIP_PLANE0, clip_plane); - ::glEnable(GL_CLIP_PLANE0); - ::glBegin(GL_TRIANGLES); - for(C3t3::Facet_iterator - fit = c3t3().facets_begin(), - end = c3t3().facets_end(); - fit != end; ++fit) + ~Scene_c3t3_item() { - const Tr::Cell_handle& cell = fit->first; - const int& index = fit->second; - const Kernel::Point_3& pa = cell->vertex((index+1)&3)->point(); - const Kernel::Point_3& pb = cell->vertex((index+2)&3)->point(); - const Kernel::Point_3& pc = cell->vertex((index+3)&3)->point(); - typedef Kernel::Oriented_side Side; - using CGAL::ON_ORIENTED_BOUNDARY; - const Side sa = plane.oriented_side(pa); - const Side sb = plane.oriented_side(pb); - const Side sc = plane.oriented_side(pc); - if( sa != ON_ORIENTED_BOUNDARY && - sb != ON_ORIENTED_BOUNDARY && - sc != ON_ORIENTED_BOUNDARY && - sb == sa && sc == sa ) - { - draw_triangle(pa, pb, pc); - } + delete frame; } - ::glEnd(); - ::glDisable(GL_CLIP_PLANE0); - ::glBegin(GL_TRIANGLES); -// workaround for Qt-4.2. -#if QT_VERSION < 0x040300 -# define darker dark -#endif - CGALglcolor(this->color().darker(150)); -#undef darker - for(Tr::Finite_cells_iterator - cit = c3t3().triangulation().finite_cells_begin(), - end = c3t3().triangulation().finite_cells_end(); - cit != end; ++cit) + void changed() { - if(! c3t3().is_in_complex(cit) ) - continue; + compute_elements(); + are_buffers_filled = false; + } - const Kernel::Point_3& pa = cit->vertex(0)->point(); - const Kernel::Point_3& pb = cit->vertex(1)->point(); - const Kernel::Point_3& pc = cit->vertex(2)->point(); - const Kernel::Point_3& pd = cit->vertex(3)->point(); - typedef Kernel::Oriented_side Side; - using CGAL::ON_ORIENTED_BOUNDARY; - const Side sa = plane.oriented_side(pa); - const Side sb = plane.oriented_side(pb); - const Side sc = plane.oriented_side(pc); - const Side sd = plane.oriented_side(pd); + void contextual_changed() + { + if(frame->isManipulated()||frame->isSpinning()) + changed(); + } + const C3t3& c3t3() const { + return c3t3_; + } - if( sa == ON_ORIENTED_BOUNDARY || - sb == ON_ORIENTED_BOUNDARY || - sc == ON_ORIENTED_BOUNDARY || - sd == ON_ORIENTED_BOUNDARY || - sb != sa || sc != sa || sd != sa) - { - draw_triangle(pa, pb, pc); - draw_triangle(pa, pb, pd); - draw_triangle(pa, pc, pd); - draw_triangle(pb, pc, pd); + bool manipulatable() const { + return true; + } + ManipulatedFrame* manipulatedFrame() { + return frame; + } + + void setPosition(float x, float y, float z) { + frame->setPosition(x, y, z); + } + + void setNormal(float x, float y, float z) { + frame->setOrientation(x, y, z, 0.f); + } + + Kernel::Plane_3 plane() const { + const qglviewer::Vec& pos = frame->position(); + const qglviewer::Vec& n = + frame->inverseTransformOf(qglviewer::Vec(0.f, 0.f, 1.f)); + return Kernel::Plane_3(n[0], n[1], n[2], - n * pos); + } + + bool isFinite() const { return true; } + bool isEmpty() const { + return c3t3().triangulation().number_of_vertices() == 0; + } + + Bbox bbox() const { + if(isEmpty()) + return Bbox(); + else { + CGAL::Bbox_3 result = c3t3().triangulation().finite_vertices_begin()->point().bbox(); + for(Tr::Finite_vertices_iterator + vit = ++c3t3().triangulation().finite_vertices_begin(), + end = c3t3().triangulation().finite_vertices_end(); + vit != end; ++vit) + { + result = result + vit->point().bbox(); + } + return Bbox(result.xmin(), result.ymin(), result.zmin(), + result.xmax(), result.ymax(), result.zmax()); } - -// for(int i = 0; i < 4; ++i) { -// if(c3t3().is_in_complex(cit, i)) continue; -// const Point_3& pa = cit->vertex((i+1)&3)->point(); -// const Point_3& pb = cit->vertex((i+2)&3)->point(); -// const Point_3& pc= cit->vertex((i+3)&3)->point(); -// typedef Kernel::Oriented_side Side; -// using CGAL::ON_ORIENTED_BOUNDARY; -// const Side sa = plane.oriented_side(pa); -// const Side sb = plane.oriented_side(pb); -// const Side sc = plane.oriented_side(pc); - -// if( sa == ON_ORIENTED_BOUNDARY || -// sb == ON_ORIENTED_BOUNDARY || -// sc == ON_ORIENTED_BOUNDARY || -// sb != sa || sc != sa ) -// { -// draw_triangle(pa, pb, pc); -// } -// } } - ::glEnd(); - if(!two_side) - ::glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE); - }; + Scene_c3t3_item* clone() const { + return 0; + } + + QString toolTip() const { + int number_of_tets = 0; + for(Tr::Finite_cells_iterator + cit = c3t3().triangulation().finite_cells_begin(), + end = c3t3().triangulation().finite_cells_end(); + cit != end; ++cit) + { + if( c3t3().is_in_complex(cit) ) + ++number_of_tets; + } + return tr("

3D complex in a 3D triangulation

" + "

Number of vertices: %1
" + "Number of surface facets: %2
" + "Number of volume tetrahedra: %3

") + .arg(c3t3().triangulation().number_of_vertices()) + .arg(c3t3().number_of_facets()) + .arg(number_of_tets); + } + + // Indicate if rendering mode is supported + bool supportsRenderingMode(RenderingMode m) const { + return (m != Gouraud && m!=PointsPlusNormals); // CHECK THIS! + } + + void draw(Viewer_interface* viewer) const { + if(!are_buffers_filled) + initialize_buffers(viewer); + vaos[0]->bind(); + program = getShaderProgram(PROGRAM_WITH_LIGHT); + attrib_buffers(viewer, PROGRAM_WITH_LIGHT); + program->bind(); + qFunc.glDrawArrays(GL_TRIANGLES, 0, static_cast(positions_poly.size()/3)); + program->release(); + vaos[0]->release(); + + + } + void draw_edges(Viewer_interface* viewer) const { + if(!are_buffers_filled) + initialize_buffers(viewer); + vaos[2]->bind(); + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT); + attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT); + program->bind(); + QMatrix4x4 f_mat; + for(int i=0; i<16; i++) + f_mat.data()[i]=frame->matrix()[i]; + program->setUniformValue("f_matrix",f_mat); + qFunc.glDrawArrays(GL_LINES, 0, static_cast(positions_grid.size()/3)); + program->release(); + vaos[2]->release(); + + vaos[1]->bind(); + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT); + attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT); + program->bind(); + qFunc.glDrawArrays(GL_LINES, 0, static_cast(positions_lines.size()/3)); + program->release(); + vaos[1]->release(); + + } + void draw_points(Viewer_interface * viewer) const + { + if(!are_buffers_filled) + initialize_buffers(viewer); + vaos[1]->bind(); + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT); + attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT); + program->bind(); + qFunc.glDrawArrays(GL_POINTS, 0, static_cast(positions_lines.size()/3)); + vaos[1]->release(); + program->release(); + + vaos[2]->bind(); + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT); + attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT); + program->bind(); + QMatrix4x4 f_mat; + for(int i=0; i<16; i++) + f_mat.data()[i]=frame->matrix()[i]; + program->setUniformValue("f_matrix",f_mat); + qFunc.glDrawArrays(GL_LINES, 0, static_cast(positions_grid.size()/3)); + program->release(); + vaos[2]->release(); + } private: - static void draw_triangle(const Kernel::Point_3& pa, - const Kernel::Point_3& pb, - const Kernel::Point_3& pc) { - Kernel::Vector_3 n = cross_product(pb - pa, pc -pa); - n = n / CGAL::sqrt(n*n); + void draw_triangle(const Kernel::Point_3& pa, + const Kernel::Point_3& pb, + const Kernel::Point_3& pc, bool is_cut) { - ::glNormal3d(n.x(),n.y(),n.z()); +#undef darker + Kernel::Vector_3 n = cross_product(pb - pa, pc - pa); + n = n / CGAL::sqrt(n*n); - ::glVertex3d(pa.x(),pa.y(),pa.z()); - ::glVertex3d(pb.x(),pb.y(),pb.z()); - ::glVertex3d(pc.x(),pc.y(),pc.z()); - } +if(!is_cut) +{ + for(int i=0; i<3; i++) + { - double complex_diag() const { - const Bbox& bbox = this->bbox(); - const double& xdelta = bbox.xmax-bbox.xmin; - const double& ydelta = bbox.ymax-bbox.ymin; - const double& zdelta = bbox.zmax-bbox.zmin; - const double diag = std::sqrt(xdelta*xdelta + - ydelta*ydelta + - zdelta*zdelta); - return diag * 0.7; - } + color_poly.push_back(this->color().redF()); + color_poly.push_back(this->color().greenF()); + color_poly.push_back(this->color().blueF()); + } +} +else +{ + for(int i=0; i<3; i++) + { + color_poly.push_back(this->color().darker(150).redF()); + color_poly.push_back(this->color().darker(150).greenF()); + color_poly.push_back(this->color().darker(150).blueF()); + } +} + for(int i=0; i<3; i++) + { + normals.push_back(n.x()); + normals.push_back(n.y()); + normals.push_back(n.z()); + } + positions_poly.push_back(pa.x()); + positions_poly.push_back(pa.y()); + positions_poly.push_back(pa.z()); + + positions_poly.push_back(pb.x()); + positions_poly.push_back(pb.y()); + positions_poly.push_back(pb.z()); + + positions_poly.push_back(pc.x()); + positions_poly.push_back(pc.y()); + positions_poly.push_back(pc.z()); + + } + + void draw_triangle_edges(const Kernel::Point_3& pa, + const Kernel::Point_3& pb, + const Kernel::Point_3& pc) { + +#undef darker + Kernel::Vector_3 n = cross_product(pb - pa, pc - pa); + n = n / CGAL::sqrt(n*n); + for(int i=0; i<6; i++) + { + color_lines.push_back(0.0); + color_lines.push_back(0.0); + color_lines.push_back(0.0); + } + positions_lines.push_back(pa.x()); + positions_lines.push_back(pa.y()); + positions_lines.push_back(pa.z()); + + positions_lines.push_back(pb.x()); + positions_lines.push_back(pb.y()); + positions_lines.push_back(pb.z()); + + positions_lines.push_back(pb.x()); + positions_lines.push_back(pb.y()); + positions_lines.push_back(pb.z()); + + positions_lines.push_back(pc.x()); + positions_lines.push_back(pc.y()); + positions_lines.push_back(pc.z()); + + positions_lines.push_back(pc.x()); + positions_lines.push_back(pc.y()); + positions_lines.push_back(pc.z()); + + positions_lines.push_back(pa.x()); + positions_lines.push_back(pa.y()); + positions_lines.push_back(pa.z()); + + } + + + + double complex_diag() const { + const Bbox& bbox = this->bbox(); + const double& xdelta = bbox.xmax-bbox.xmin; + const double& ydelta = bbox.ymax-bbox.ymin; + const double& zdelta = bbox.zmax-bbox.zmin; + const double diag = std::sqrt(xdelta*xdelta + + ydelta*ydelta + + zdelta*zdelta); + return diag * 0.7; + } public Q_SLOTS: - void export_facets_in_complex() - { - std::stringstream off_sstream; - c3t3().output_facets_in_complex_to_off(off_sstream); - std::string backup = off_sstream.str(); - // Try to read .off in a polyhedron - Scene_polyhedron_item* item = new Scene_polyhedron_item(); - if(!item->load(off_sstream)) + void export_facets_in_complex() { - delete item; - off_sstream.clear(); - off_sstream.str(backup); + std::stringstream off_sstream; + c3t3().output_facets_in_complex_to_off(off_sstream); + std::string backup = off_sstream.str(); + // Try to read .off in a polyhedron + Scene_polyhedron_item* item = new Scene_polyhedron_item(); + if(!item->load(off_sstream)) + { + delete item; + off_sstream.str(backup); - // Try to read .off in a polygon soup - Scene_polygon_soup_item* soup_item = new Scene_polygon_soup_item; + // Try to read .off in a polygon soup + Scene_polygon_soup_item* soup_item = new Scene_polygon_soup_item; - if(!soup_item->load(off_sstream)) { - delete soup_item; - return; - } + if(!soup_item->load(off_sstream)) { + delete soup_item; + return; + } - soup_item->setName(QString("%1_%2").arg(this->name()).arg("facets")); - last_known_scene->addItem(soup_item); + soup_item->setName(QString("%1_%2").arg(this->name()).arg("facets")); + last_known_scene->addItem(soup_item); + } + else{ + item->setName(QString("%1_%2").arg(this->name()).arg("facets")); + last_known_scene->addItem(item); + } } - else{ - item->setName(QString("%1_%2").arg(this->name()).arg("facets")); - last_known_scene->addItem(item); - } - } public: - QMenu* contextMenu() - { - const char* prop_name = "Menu modified by Scene_c3t3_item."; + QMenu* contextMenu() + { + const char* prop_name = "Menu modified by Scene_c3t3_item."; - QMenu* menu = Scene_item::contextMenu(); + QMenu* menu = Scene_item::contextMenu(); - // Use dynamic properties: - // http://doc.trolltech.com/lastest/qobject.html#property - bool menuChanged = menu->property(prop_name).toBool(); + // Use dynamic properties: + // http://doc.qt.io/qt-5/qobject.html#property + bool menuChanged = menu->property(prop_name).toBool(); - if(!menuChanged) { - QAction* actionExportFacetsInComplex = - menu->addAction(tr("Export facets in complex")); - actionExportFacetsInComplex->setObjectName("actionExportFacetsInComplex"); - connect(actionExportFacetsInComplex, - SIGNAL(triggered()),this, - SLOT(export_facets_in_complex())); - menu->setProperty(prop_name, true); + if(!menuChanged) { + QAction* actionExportFacetsInComplex = + menu->addAction(tr("Export facets in complex")); + actionExportFacetsInComplex->setObjectName("actionExportFacetsInComplex"); + connect(actionExportFacetsInComplex, + SIGNAL(triggered()),this, + SLOT(export_facets_in_complex())); + } + return menu; } - return menu; - } - void set_scene(Scene_interface* scene){ last_known_scene=scene; } + void set_scene(Scene_interface* scene){ last_known_scene=scene; } private: - C3t3 c3t3_; - qglviewer::ManipulatedFrame* frame; - Scene_interface* last_known_scene; + + struct light_info + { + //position + GLfloat position[4]; + + //ambient + GLfloat ambient[4]; + + //diffuse + GLfloat diffuse[4]; + + //specular + GLfloat specular[4]; + GLfloat spec_power; + + }; + C3t3 c3t3_; + qglviewer::ManipulatedFrame* frame; + Scene_interface* last_known_scene; + + + std::vector positions_lines; + std::vector positions_grid; + std::vector positions_poly; + std::vector normals; + std::vector color_lines; + std::vector color_poly; + std::vector color_grid; + + mutable QOpenGLShaderProgram *program; + + using Scene_item::initialize_buffers; + void initialize_buffers(Viewer_interface *viewer)const + { + //vao containing the data for the facets + { + program = getShaderProgram(PROGRAM_WITH_LIGHT, viewer); + program->bind(); + + vaos[0]->bind(); + buffers[0].bind(); + buffers[0].allocate(positions_poly.data(), + static_cast(positions_poly.size()*sizeof(float))); + program->enableAttributeArray("vertex"); + program->setAttributeBuffer("vertex",GL_FLOAT,0,3); + buffers[0].release(); + + buffers[1].bind(); + buffers[1].allocate(normals.data(), + static_cast(normals.size()*sizeof(float))); + program->enableAttributeArray("normals"); + program->setAttributeBuffer("normals",GL_FLOAT,0,3); + buffers[1].release(); + + buffers[2].bind(); + buffers[2].allocate(color_poly.data(), + static_cast(color_poly.size()*sizeof(float))); + program->enableAttributeArray("colors"); + program->setAttributeBuffer("colors",GL_FLOAT,0,3); + buffers[2].release(); + vaos[0]->release(); + program->release(); + + } + + //vao containing the data for the lines + { + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT, viewer); + program->bind(); + + vaos[1]->bind(); + buffers[3].bind(); + buffers[3].allocate(positions_lines.data(), + static_cast(positions_lines.size()*sizeof(float))); + program->enableAttributeArray("vertex"); + program->setAttributeBuffer("vertex",GL_FLOAT,0,3); + buffers[3].release(); + + buffers[4].bind(); + buffers[4].allocate(color_lines.data(), + static_cast(color_lines.size()*sizeof(float))); + program->enableAttributeArray("colors"); + program->setAttributeBuffer("colors",GL_FLOAT,0,3); + buffers[4].release(); + vaos[1]->release(); + program->release(); + + } + + //vao containing the data for the grid + { + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT, viewer); + program->bind(); + + vaos[2]->bind(); + buffers[5].bind(); + buffers[5].allocate(positions_grid.data(), + static_cast(positions_grid.size()*sizeof(float))); + program->enableAttributeArray("vertex"); + program->setAttributeBuffer("vertex",GL_FLOAT,0,3); + buffers[5].release(); + + buffers[6].bind(); + buffers[6].allocate(color_grid.data(), + static_cast(color_grid.size()*sizeof(float))); + program->enableAttributeArray("colors"); + program->setAttributeBuffer("colors",GL_FLOAT,0,3); + buffers[6].release(); + vaos[2]->release(); + program->release(); + } + are_buffers_filled = true; + } + void compute_elements() + { + positions_lines.clear(); + positions_poly.clear(); + color_lines.clear(); + color_grid.clear(); + color_poly.clear(); + normals.clear(); + + //The grid + { + float x = (2*(float)complex_diag())/10.0; + float y = (2*(float)complex_diag())/10.0; + for(int u = 0; u < 11; u++) + { + + positions_grid.push_back(-(float)complex_diag() + x* u); + positions_grid.push_back(-(float)complex_diag()); + positions_grid.push_back(0.0); + + positions_grid.push_back(-(float)complex_diag() + x* u); + positions_grid.push_back((float)complex_diag()); + positions_grid.push_back(0.0); + } + for(int v=0; v<11; v++) + { + + positions_grid.push_back(-(float)complex_diag()); + positions_grid.push_back(-(float)complex_diag() + v * y); + positions_grid.push_back(0.0); + + positions_grid.push_back((float)complex_diag()); + positions_grid.push_back(-(float)complex_diag() + v * y); + positions_grid.push_back(0.0); + } + float colors[3]; + colors[0] = this->color().redF(); + colors[1] = this->color().greenF(); + colors[2] = this->color().blueF(); + + for(int i=0; i< 132; i++) + { + color_grid.push_back(colors[i%3]); + } + } + + //The facets + { + if(isEmpty()) + return; + + const Kernel::Plane_3& plane = this->plane(); + GLdouble clip_plane[4]; + clip_plane[0] = -plane.a(); + clip_plane[1] = -plane.b(); + clip_plane[2] = -plane.c(); + clip_plane[3] = -plane.d(); + + + + for(C3t3::Facet_iterator + fit = c3t3().facets_begin(), + end = c3t3().facets_end(); + fit != end; ++fit) + { + const Tr::Cell_handle& cell = fit->first; + const int& index = fit->second; + const Kernel::Point_3& pa = cell->vertex((index+1)&3)->point(); + const Kernel::Point_3& pb = cell->vertex((index+2)&3)->point(); + const Kernel::Point_3& pc = cell->vertex((index+3)&3)->point(); + typedef Kernel::Oriented_side Side; + using CGAL::ON_ORIENTED_BOUNDARY; + const Side sa = plane.oriented_side(pa); + const Side sb = plane.oriented_side(pb); + const Side sc = plane.oriented_side(pc); + bool is_showned = false; + if(pa.x() * clip_plane[0] + pa.y() * clip_plane[1] + pa.z() * clip_plane[2] + clip_plane[3] > 0 + && pb.x() * clip_plane[0] + pb.y() * clip_plane[1] + pb.z() * clip_plane[2] + clip_plane[3] > 0 + && pc.x() * clip_plane[0] + pc.y() * clip_plane[1] + pc.z() * clip_plane[2] + clip_plane[3] > 0) + is_showned = true; + + if(is_showned && sa != ON_ORIENTED_BOUNDARY && + sb != ON_ORIENTED_BOUNDARY && + sc != ON_ORIENTED_BOUNDARY && + sb == sa && sc == sa ) + { + draw_triangle(pa, pb, pc, false); + draw_triangle_edges(pa, pb, pc); + } + + } + + + for(Tr::Finite_cells_iterator + cit = c3t3().triangulation().finite_cells_begin(), + end = c3t3().triangulation().finite_cells_end(); + cit != end; ++cit) + { + if(! c3t3().is_in_complex(cit) ) + continue; + + const Kernel::Point_3& pa = cit->vertex(0)->point(); + const Kernel::Point_3& pb = cit->vertex(1)->point(); + const Kernel::Point_3& pc = cit->vertex(2)->point(); + const Kernel::Point_3& pd = cit->vertex(3)->point(); + typedef Kernel::Oriented_side Side; + using CGAL::ON_ORIENTED_BOUNDARY; + const Side sa = plane.oriented_side(pa); + const Side sb = plane.oriented_side(pb); + const Side sc = plane.oriented_side(pc); + const Side sd = plane.oriented_side(pd); + + if( sa == ON_ORIENTED_BOUNDARY || + sb == ON_ORIENTED_BOUNDARY || + sc == ON_ORIENTED_BOUNDARY || + sd == ON_ORIENTED_BOUNDARY || + sb != sa || sc != sa || sd != sa) + { + draw_triangle(pa,pb,pc, true); + draw_triangle(pa,pb,pd, true); + draw_triangle(pa,pc,pd, true); + draw_triangle(pb,pc,pd, true); + + draw_triangle_edges(pa,pb,pc); + draw_triangle_edges(pa,pb,pd); + draw_triangle_edges(pa,pc,pd); + draw_triangle_edges(pb,pc,pd); + } + } + } + } + }; Scene_item* cgal_code_mesh_3(const Polyhedron* pMesh, - QString filename, + const QString filename, const double angle, - const double facet_sizing, + const double sizing, const double approx, - const double tet_sizing, - const double tet_shape, - const bool protect_features, - Scene_interface* scene) + const double tets_sizing) { if(!pMesh) return 0; // remesh // Set mesh criteria - Edge_criteria edge_criteria(facet_sizing); - Facet_criteria facet_criteria(angle, facet_sizing, approx); // angle, size, approximation - Cell_criteria cell_criteria(tet_shape, tet_sizing); // radius-edge ratio, size - Mesh_criteria criteria(edge_criteria, facet_criteria, cell_criteria); + Facet_criteria facet_criteria(angle, sizing, approx); // angle, size, approximation + Cell_criteria cell_criteria(4, tets_sizing); // radius-edge ratio, size + Mesh_criteria criteria(facet_criteria, cell_criteria); CGAL::Timer timer; timer.start(); std::cerr << "Meshing file \"" << qPrintable(filename) << "\"\n"; std::cerr << " angle: " << angle << std::endl - << " facets size bound: " << facet_sizing << std::endl + << " facets size bound: " << sizing << std::endl << " approximation bound: " << approx << std::endl - << " tetrahedra size bound: " << tet_sizing << std::endl; + << " tetrahedra size bound: " << tets_sizing << std::endl; std::cerr << "Build AABB tree..."; // Create domain Mesh_domain domain(*pMesh); - if(protect_features) { - domain.detect_features(); - } std::cerr << "done (" << timer.time() << " ms)" << std::endl; // Meshing std::cerr << "Mesh..."; - CGAL::parameters::internal::Features_options features = - protect_features ? - CGAL::parameters::features(domain) : - CGAL::parameters::no_features(); + Scene_c3t3_item* new_item = + new Scene_c3t3_item(CGAL::make_mesh_3(domain, criteria)); - Scene_c3t3_item* new_item = - new Scene_c3t3_item(CGAL::make_mesh_3(domain, criteria, features)); - new_item->set_scene(scene); std::cerr << "done (" << timer.time() << " ms, " << new_item->c3t3().triangulation().number_of_vertices() << " vertices)" << std::endl; if(new_item->c3t3().triangulation().number_of_vertices() > 0) { std::ofstream medit_out("out.mesh"); new_item->c3t3().output_to_medit(medit_out); - const Scene_item::Bbox& bbox = new_item->bbox(); new_item->setPosition((float)(bbox.xmin + bbox.xmax)/2.f, (float)(bbox.ymin + bbox.ymax)/2.f, @@ -404,4 +670,6 @@ Scene_item* cgal_code_mesh_3(const Polyhedron* pMesh, } } -#include "Scene_c3t3_item.moc" +#include "Polyhedron_demo_mesh_3_plugin_cgal_code.moc" +//#include "Scene_c3t3_item.moc" //Check this one, it's strange moc include. + diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_mesh_segmentation_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_mesh_segmentation_plugin.cpp index 652dbd46857..57e59b3bd88 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_mesh_segmentation_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_mesh_segmentation_plugin.cpp @@ -48,7 +48,9 @@ class Polyhedron_demo_mesh_segmentation_plugin : public Polyhedron_demo_plugin_helper { Q_OBJECT - Q_INTERFACES(Polyhedron_demo_plugin_interface) + Q_INTERFACES(Polyhedron_demo_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") + private: typedef std::map > Item_sdf_map; public: @@ -348,6 +350,4 @@ void Polyhedron_demo_mesh_segmentation_plugin::colorize_segmentation( } } -Q_EXPORT_PLUGIN2(Polyhedron_demo_mesh_segmentation_plugin, Polyhedron_demo_mesh_segmentation_plugin) - #include "Polyhedron_demo_mesh_segmentation_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_mesh_simplification_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_mesh_simplification_plugin.cpp index 2b3af02f7ca..f0bc7b35b2d 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_mesh_simplification_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_mesh_simplification_plugin.cpp @@ -19,6 +19,7 @@ class Polyhedron_demo_mesh_simplification_plugin : { Q_OBJECT Q_INTERFACES(Polyhedron_demo_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") public: // used by Polyhedron_demo_plugin_helper @@ -47,8 +48,9 @@ void Polyhedron_demo_mesh_simplification_plugin::on_actionSimplify_triggered() // get option (#edges) bool ok; + const int nb_edges = - QInputDialog::getInteger(mw, tr("Stop condition"), + QInputDialog::getInt(mw, tr("Stop condition"), tr("Number of edges:"), (int)(pMesh->size_of_halfedges () / 4), // default value: current #edges / 2 3, // min = one triangle @@ -79,6 +81,4 @@ void Polyhedron_demo_mesh_simplification_plugin::on_actionSimplify_triggered() } } -Q_EXPORT_PLUGIN2(Polyhedron_demo_mesh_simplification_plugin, Polyhedron_demo_mesh_simplification_plugin) - #include "Polyhedron_demo_mesh_simplification_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_nef_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_nef_plugin.cpp index c56cc2cf1e9..445708afc7e 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_nef_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_nef_plugin.cpp @@ -18,6 +18,7 @@ class Polyhedron_demo_nef_plugin : { Q_OBJECT Q_INTERFACES(Polyhedron_demo_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") public: QStringList actionsNames() const { @@ -288,6 +289,4 @@ void Polyhedron_demo_nef_plugin::boolean_operation(const Boolean_operation opera QApplication::restoreOverrideCursor(); } -Q_EXPORT_PLUGIN2(Polyhedron_demo_nef_plugin, Polyhedron_demo_nef_plugin) - #include "Polyhedron_demo_nef_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_normal_estimation_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_normal_estimation_plugin.cpp index b1511858d52..2d8ce678ada 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_normal_estimation_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_normal_estimation_plugin.cpp @@ -31,6 +31,8 @@ class Polyhedron_demo_normal_estimation_plugin : { Q_OBJECT Q_INTERFACES(Polyhedron_demo_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") + QAction* actionNormalEstimation; QAction* actionNormalInversion; @@ -98,6 +100,7 @@ void Polyhedron_demo_normal_estimation_plugin::on_actionNormalInversion_triggere for(Point_set::iterator it = points->begin(); it != points->end(); ++it){ it->normal() = -1 * it->normal(); } + item->changed(); } } @@ -214,6 +217,4 @@ void Polyhedron_demo_normal_estimation_plugin::on_actionNormalEstimation_trigger #endif // !CGAL_DISABLE_NORMAL_ESTIMATION_PLUGIN } -Q_EXPORT_PLUGIN2(Polyhedron_demo_normal_estimation_plugin, Polyhedron_demo_normal_estimation_plugin) - #include "Polyhedron_demo_normal_estimation_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_off_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_off_plugin.cpp index 44758bff0b8..01bc86868bb 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_off_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_off_plugin.cpp @@ -11,6 +11,7 @@ class Polyhedron_demo_off_plugin : { Q_OBJECT Q_INTERFACES(Polyhedron_demo_io_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.IOPluginInterface/1.0") public: QString name() const { return "off_plugin"; } @@ -83,6 +84,4 @@ bool Polyhedron_demo_off_plugin::save(const Scene_item* item, QFileInfo fileinfo (soup_item && soup_item->save(out)); } -#include -Q_EXPORT_PLUGIN2(Polyhedron_demo_off_plugin, Polyhedron_demo_off_plugin) #include "Polyhedron_demo_off_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_off_to_nef_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_off_to_nef_plugin.cpp index c16261c1b3e..68d476a9835 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_off_to_nef_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_off_to_nef_plugin.cpp @@ -10,6 +10,7 @@ class Polyhedron_demo_off_to_nef_plugin : { Q_OBJECT Q_INTERFACES(Polyhedron_demo_io_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.IOPluginInterface/1.0") public: QString name() const { return "off_to_nef_plugin"; } @@ -53,6 +54,4 @@ bool Polyhedron_demo_off_to_nef_plugin::save(const Scene_item*, QFileInfo) return false; } -#include -Q_EXPORT_PLUGIN2(Polyhedron_demo_off_to_nef_plugin, Polyhedron_demo_off_to_nef_plugin) #include "Polyhedron_demo_off_to_nef_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_off_to_xyz_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_off_to_xyz_plugin.cpp index b07e6bfe03e..cc32c58e245 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_off_to_xyz_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_off_to_xyz_plugin.cpp @@ -12,6 +12,7 @@ class Polyhedron_demo_off_to_xyz_plugin : { Q_OBJECT Q_INTERFACES(Polyhedron_demo_io_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.IOPluginInterface/1.0") public: QString name() const { return "off_to_xyz_plugin"; } @@ -65,6 +66,5 @@ bool Polyhedron_demo_off_to_xyz_plugin::save(const Scene_item*, QFileInfo) return false; } -#include -Q_EXPORT_PLUGIN2(Polyhedron_demo_off_to_xyz_plugin, Polyhedron_demo_off_to_xyz_plugin) + #include "Polyhedron_demo_off_to_xyz_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_orient_soup_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_orient_soup_plugin.cpp index 9792eca66e9..40ddf8b6d6f 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_orient_soup_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_orient_soup_plugin.cpp @@ -17,6 +17,7 @@ class Polyhedron_demo_orient_soup_plugin : { Q_OBJECT Q_INTERFACES(Polyhedron_demo_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") public: void init(QMainWindow* mainWindow, @@ -138,12 +139,12 @@ void Polyhedron_demo_orient_soup_plugin::shuffle() if(poly_item) { item = new Scene_polygon_soup_item(); item->setName(poly_item->name()); - item->setColor(poly_item->color()); item->setRenderingMode(poly_item->renderingMode()); item->setVisible(poly_item->visible()); item->setProperty("source filename", poly_item->property("source filename")); item->load(poly_item); item->shuffle_orientations(); + item->setColor(poly_item->color()); scene->replaceItem(index, item); delete poly_item; } @@ -165,6 +166,4 @@ void Polyhedron_demo_orient_soup_plugin::displayNonManifoldEdges() } } -Q_EXPORT_PLUGIN2(Polyhedron_demo_orient_soup_plugin, Polyhedron_demo_orient_soup_plugin) - #include "Polyhedron_demo_orient_soup_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_parameterization_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_parameterization_plugin.cpp index 3eb0654e16f..9d76eb00f1f 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_parameterization_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_parameterization_plugin.cpp @@ -29,6 +29,7 @@ class Polyhedron_demo_parameterization_plugin : { Q_OBJECT Q_INTERFACES(Polyhedron_demo_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") public: // used by Polyhedron_demo_plugin_helper @@ -145,6 +146,4 @@ void Polyhedron_demo_parameterization_plugin::on_actionDCP_triggered() parameterize(PARAM_DCP); } -Q_EXPORT_PLUGIN2(Polyhedron_demo_parameterization_plugin, Polyhedron_demo_parameterization_plugin) - #include "Polyhedron_demo_parameterization_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_pca_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_pca_plugin.cpp index 4f4b0b48a9f..8ef2df2bfe6 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_pca_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_pca_plugin.cpp @@ -30,6 +30,7 @@ class Polyhedron_demo_pca_plugin : { Q_OBJECT Q_INTERFACES(Polyhedron_demo_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") public: // used by Polyhedron_demo_plugin_helper @@ -207,6 +208,4 @@ void Polyhedron_demo_pca_plugin::on_actionFitLine_triggered() } } -Q_EXPORT_PLUGIN2(Polyhedron_demo_pca_plugin, Polyhedron_demo_pca_plugin) - #include "Polyhedron_demo_pca_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_plugin_helper.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_plugin_helper.cpp index 00e9158d6b1..719670bf915 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_plugin_helper.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_plugin_helper.cpp @@ -55,8 +55,9 @@ void Polyhedron_demo_plugin_helper::autoConnectActions() i < metaObject->methodCount(); ++i) { - const int pos = QString(metaObject->method(i).signature()).indexOf('('); - methodsNames << QString(metaObject->method(i).signature()).left(pos); + const int pos = QString(metaObject->method(i).methodSignature()).indexOf('('); + methodsNames << QString(metaObject->method(i).methodSignature()).left(pos); + methods << metaObject->method(i); } @@ -73,24 +74,26 @@ void Polyhedron_demo_plugin_helper::autoConnectActions() if(action_method.methodType() == QMetaMethod::Signal) { - const int pos = QString(action_method.signature()).indexOf('('); - QString methodName = QString(action_method.signature()).left(pos); + const int pos = QString(action_method.methodSignature()).indexOf('('); + QString methodName = QString(action_method.methodSignature()).left(pos); + QString slotName = QString("on_%1_%2").arg(action->objectName()).arg(methodName); // qDebug() << thisObject->tr("Slot %1 (%2)...").arg(slotName).arg(i); int index = methodsNames.indexOf(slotName); - if(index>=0 && !connected.contains(slotName)) { - const bool ok = - QObject::connect(action, - qPrintable(QString("2%1").arg(action_method.signature())), + if(index>=0 && !connected.contains(slotName)) + { + const bool ok = QObject::connect(action, + qPrintable(QString("2%1").arg(QString(action_method.methodSignature()))), thisObject, - qPrintable(QString("1%1").arg(methods[index].signature()))); + qPrintable(QString("1%1").arg(QString(methods[index].methodSignature())))); + if(!ok) { qDebug() << thisObject->tr("Cannot connect method %1.%2 to slot %3!") .arg(action->objectName()) - .arg(action_method.signature()) - .arg(methods[index].signature()); + .arg(QString(action_method.methodSignature())) + .arg(QString(methods[index].methodSignature())); } else { // qDebug(" ->Connected!"); diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_point_inside_polyhedron_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_point_inside_polyhedron_plugin.cpp index 40903d45f29..69bec658c3e 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_point_inside_polyhedron_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_point_inside_polyhedron_plugin.cpp @@ -34,6 +34,7 @@ class Polyhedron_demo_point_inside_polyhedron_plugin : { Q_OBJECT Q_INTERFACES(Polyhedron_demo_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") public: bool applicable(QAction*) const @@ -204,7 +205,7 @@ public Q_SLOTS: // take number of points param bool ok; const int nb_points = - QInputDialog::getInteger(mw, tr("Number of Points"), + QInputDialog::getInt(mw, tr("Number of Points"), tr("Number of Points:"), 100000, // default value 1, // min @@ -242,6 +243,4 @@ private: }; // end Polyhedron_demo_point_inside_polyhedron_plugin -Q_EXPORT_PLUGIN2(Polyhedron_demo_point_inside_polyhedron_plugin, Polyhedron_demo_point_inside_polyhedron_plugin) - #include "Polyhedron_demo_point_inside_polyhedron_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_point_set_average_spacing_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_point_set_average_spacing_plugin.cpp index 8714fe4de39..a4e8236e9c3 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_point_set_average_spacing_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_point_set_average_spacing_plugin.cpp @@ -21,6 +21,7 @@ class Polyhedron_demo_point_set_average_spacing_plugin : { Q_OBJECT Q_INTERFACES(Polyhedron_demo_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") private: QAction* actionAverageSpacing; @@ -63,8 +64,9 @@ void Polyhedron_demo_point_set_average_spacing_plugin::on_actionAverageSpacing_t // Gets options bool ok; + const int nb_neighbors = - QInputDialog::getInteger((QWidget*)mw, + QInputDialog::getInt((QWidget*)mw, tr("Average Spacing"), // dialog title tr("Number of neighbors:"), // field label 6, // default value = 1 ring @@ -104,6 +106,5 @@ void Polyhedron_demo_point_set_average_spacing_plugin::on_actionAverageSpacing_t } } -Q_EXPORT_PLUGIN2(Polyhedron_demo_point_set_average_spacing_plugin, Polyhedron_demo_point_set_average_spacing_plugin) #include "Polyhedron_demo_point_set_average_spacing_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_point_set_outliers_removal_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_point_set_outliers_removal_plugin.cpp index a28e8cc0bfe..696e8e574aa 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_point_set_outliers_removal_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_point_set_outliers_removal_plugin.cpp @@ -23,6 +23,7 @@ class Polyhedron_demo_point_set_outliers_removal_plugin : { Q_OBJECT Q_INTERFACES(Polyhedron_demo_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") private: QAction* actionOutlierRemoval; @@ -102,7 +103,7 @@ void Polyhedron_demo_point_set_outliers_removal_plugin::on_actionOutlierRemoval_ << std::endl; // Selects points to delete - points->select(points->begin(), points->end(), false); + points->select(points->begin(), first_point_to_remove, false); points->select(first_point_to_remove, points->end(), true); // Updates scene @@ -112,6 +113,4 @@ void Polyhedron_demo_point_set_outliers_removal_plugin::on_actionOutlierRemoval_ } } -Q_EXPORT_PLUGIN2(Polyhedron_demo_point_set_outliers_removal_plugin, Polyhedron_demo_point_set_outliers_removal_plugin) - #include "Polyhedron_demo_point_set_outliers_removal_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_point_set_simplification_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_point_set_simplification_plugin.cpp index 30390192dfe..b7478151bf5 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_point_set_simplification_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_point_set_simplification_plugin.cpp @@ -24,6 +24,8 @@ class Polyhedron_demo_point_set_simplification_plugin : { Q_OBJECT Q_INTERFACES(Polyhedron_demo_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") + QAction* actionSimplify; public: @@ -119,7 +121,7 @@ void Polyhedron_demo_point_set_simplification_plugin::on_actionSimplify_triggere << std::endl; // Selects points to delete - points->select(points->begin(), points->end(), false); + points->select(points->begin(), first_point_to_remove, false); points->select(first_point_to_remove, points->end(), true); // Updates scene @@ -138,6 +140,4 @@ void Polyhedron_demo_point_set_simplification_plugin::on_actionSimplify_triggere } } -Q_EXPORT_PLUGIN2(Polyhedron_demo_point_set_simplification_plugin, Polyhedron_demo_point_set_simplification_plugin) - #include "Polyhedron_demo_point_set_simplification_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_point_set_smoothing_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_point_set_smoothing_plugin.cpp index a181e78965d..5b131aed60b 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_point_set_smoothing_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_point_set_smoothing_plugin.cpp @@ -18,6 +18,8 @@ class Polyhedron_demo_point_set_smoothing_plugin : { Q_OBJECT Q_INTERFACES(Polyhedron_demo_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") + QAction* actionJetSmoothing; public: @@ -55,15 +57,16 @@ void Polyhedron_demo_point_set_smoothing_plugin::on_actionJetSmoothing_triggered // Gets options bool ok; + const unsigned int nb_neighbors = - QInputDialog::getInteger((QWidget*)mw, - tr("Jet Smoothing"), // dialog title - tr("Number of neighbors:"), // field label - 24, // default value = fast - 6, // min - 1000, // max - 1, // step - &ok); + QInputDialog::getInt((QWidget*)mw, + tr("Jet Smoothing"), // dialog title + tr("Number of neighbors:"), // field label + 24, // default value = fast + 6, // min + 1000, // max + 1, // step + &ok); if(!ok) return; QApplication::setOverrideCursor(Qt::WaitCursor); @@ -79,6 +82,4 @@ void Polyhedron_demo_point_set_smoothing_plugin::on_actionJetSmoothing_triggered } } -Q_EXPORT_PLUGIN2(Polyhedron_demo_point_set_smoothing_plugin, Polyhedron_demo_point_set_smoothing_plugin) - #include "Polyhedron_demo_point_set_smoothing_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_poisson_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_poisson_plugin.cpp index a8e21c144e2..90daec0432c 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_poisson_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_poisson_plugin.cpp @@ -28,6 +28,8 @@ class Polyhedron_demo_poisson_plugin : { Q_OBJECT Q_INTERFACES(Polyhedron_demo_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") + QAction* actionPoissonReconstruction; public: @@ -115,6 +117,7 @@ void Polyhedron_demo_poisson_plugin::on_actionPoissonReconstruction_triggered() new_item->setColor(Qt::lightGray); scene->addItem(new_item); + // Hide point set point_set_item->setVisible(false); scene->itemChanged(index); @@ -124,6 +127,4 @@ void Polyhedron_demo_poisson_plugin::on_actionPoissonReconstruction_triggered() } } -Q_EXPORT_PLUGIN2(Polyhedron_demo_poisson_plugin, Polyhedron_demo_poisson_plugin) - #include "Polyhedron_demo_poisson_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_poisson_plugin_impl.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_poisson_plugin_impl.cpp index c1232ec2e40..d0204b23ebd 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_poisson_plugin_impl.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_poisson_plugin_impl.cpp @@ -75,8 +75,9 @@ Polyhedron* poisson_reconstruct(const Point_set& points, // Computes implicit function //*************************************** + std::cerr << "Computes Poisson implicit function " - << "using " << solver_name.toAscii().data() << " solver...\n"; + << "using " << solver_name.toLatin1().data() << " solver...\n"; // Creates implicit function from the point set. diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_polyhedron_slicer_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_polyhedron_slicer_plugin.cpp index df01b48c009..a8825d7659b 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_polyhedron_slicer_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_polyhedron_slicer_plugin.cpp @@ -2,7 +2,6 @@ #include #include "Messages_interface.h" -#include "Scene_item_with_display_list.h" #include "Scene_plane_item.h" #include "Scene_polyhedron_item.h" #include "Scene_polylines_item.h" @@ -34,6 +33,7 @@ class Polyhedron_demo_polyhedron_slicer_plugin : { Q_OBJECT Q_INTERFACES(Polyhedron_demo_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") public: bool applicable(QAction*) const { return qobject_cast(scene->item(scene->mainSelectionIndex())); } @@ -305,6 +305,7 @@ void Polyhedron_demo_polyhedron_slicer_plugin::on_Generate_button_clicked() new_polylines_item->setColor(Qt::green); new_polylines_item->setRenderingMode(Wireframe); scene->addItem(new_polylines_item); + new_polylines_item->changed(); } } } @@ -337,6 +338,5 @@ void Polyhedron_demo_polyhedron_slicer_plugin::intersection_of_plane_Polyhedra_3 slicer(*plane_it, std::front_inserter(polylines)); } -Q_EXPORT_PLUGIN2(Polyhedron_demo_polyhedron_slicer_plugin, Polyhedron_demo_polyhedron_slicer_plugin) #include "Polyhedron_demo_polyhedron_slicer_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_polyhedron_stitching_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_polyhedron_stitching_plugin.cpp index 86d49f411cc..a46cc764f9e 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_polyhedron_stitching_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_polyhedron_stitching_plugin.cpp @@ -36,6 +36,8 @@ class Polyhedron_demo_polyhedron_stitching_plugin : { Q_OBJECT Q_INTERFACES(Polyhedron_demo_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") + QAction* actionDetectBorders; QAction* actionStitchBorders; public: @@ -132,6 +134,7 @@ void Polyhedron_demo_polyhedron_stitching_plugin::on_actionDetectBorders_trigger new_item->setName(tr("Boundary of %1").arg(item->name())); new_item->setColor(Qt::red); scene->addItem(new_item); + new_item->changed(); } } } @@ -153,6 +156,4 @@ void Polyhedron_demo_polyhedron_stitching_plugin::on_actionStitchBorders_trigger } } -Q_EXPORT_PLUGIN2(Polyhedron_demo_polyhedron_stitching_plugin, Polyhedron_demo_polyhedron_stitching_plugin) - #include "Polyhedron_demo_polyhedron_stitching_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_polylines_io_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_polylines_io_plugin.cpp index f6e3e36c7e7..e902ccdeec6 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_polylines_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_polylines_io_plugin.cpp @@ -11,6 +11,8 @@ class Polyhedron_demo_polylines_io_plugin : { Q_OBJECT Q_INTERFACES(Polyhedron_demo_io_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.IOPluginInterface/1.0") + public: QString name() const { return "polylines_io_plugin"; } @@ -74,6 +76,7 @@ Polyhedron_demo_polylines_io_plugin::load(QFileInfo fileinfo) { item->setColor(Qt::black); item->setProperty("polylines metadata", polylines_metadata); std::cerr << "Number of polylines in item: " << item->polylines.size() << std::endl; + item->changed(); return item; } @@ -119,6 +122,4 @@ bool Polyhedron_demo_polylines_io_plugin::save(const Scene_item* item, QFileInfo return (bool) out; } -#include -Q_EXPORT_PLUGIN2(Polyhedron_demo_polylines_io_plugin, Polyhedron_demo_polylines_io_plugin) #include "Polyhedron_demo_polylines_io_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_remeshing_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_remeshing_plugin.cpp index 6ccd7f8c9d6..7afcf2185d2 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_remeshing_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_remeshing_plugin.cpp @@ -28,6 +28,8 @@ class Polyhedron_demo_remeshing_plugin : { Q_OBJECT Q_INTERFACES(Polyhedron_demo_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") + public: void init(QMainWindow* mainWindow, Scene_interface* scene_interface) { this->scene = scene_interface; @@ -56,8 +58,8 @@ private: void Polyhedron_demo_remeshing_plugin::remesh() { const Scene_interface::Item_id index = scene->mainSelectionIndex(); - - Scene_polyhedron_item* item = + + Scene_polyhedron_item* item = qobject_cast(scene->item(index)); if(item) @@ -66,8 +68,8 @@ void Polyhedron_demo_remeshing_plugin::remesh() if(!pMesh) return; - // TODO: - // sizing and approximation parameters should be expressed as ratio of + // TODO: + // sizing and approximation parameters should be expressed as ratio of // scene bbox diagonal. QDialog dialog(mw); @@ -109,7 +111,7 @@ void Polyhedron_demo_remeshing_plugin::remesh() << "\n tag=" << tag_index << std::boolalpha << std::endl; - Scene_item* new_item = cgal_code_remesh(mw, + Scene_item* new_item = cgal_code_remesh(mw, pMesh, angle, sizing, @@ -134,8 +136,6 @@ void Polyhedron_demo_remeshing_plugin::remesh() } } -Q_EXPORT_PLUGIN2(Polyhedron_demo_remeshing_plugin, Polyhedron_demo_remeshing_plugin) - #include "Polyhedron_demo_remeshing_plugin.moc" #endif // CGAL_POLYHEDRON_DEMO_USE_SURFACE_MESHER diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_remeshing_plugin_cgal_code.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_remeshing_plugin_cgal_code.cpp index 4b11f8551d1..3d2397fa784 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_remeshing_plugin_cgal_code.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_remeshing_plugin_cgal_code.cpp @@ -3,9 +3,6 @@ #include "Polyhedron_type.h" #include "Scene_item.h" -#ifdef CGAL_GLEW_ENABLED -# include -#endif #include #include "Scene_polyhedron_item.h" #include "Scene_polygon_soup_item.h" @@ -60,7 +57,7 @@ public: curvature_size_criterion(distance_bound), uniform_size_criterion(radius_bound), aspect_ratio_criterion(angle_bound) - + { } @@ -96,7 +93,7 @@ private: CGAL::Surface_mesher::Uniform_size_criterion uniform_size_criterion; // bound on radii of surface Delaunay balls - + CGAL::Surface_mesher::Aspect_ratio_criterion aspect_ratio_criterion; // lower bound on minimum angle in degrees @@ -131,11 +128,11 @@ class Mesher : public Mesher_base const Input_surface& surface; CGAL::Null_mesh_visitor visitor; public: - Mesher(QObject* parent, - C2t3& c2t3, + Mesher(QObject* parent, + C2t3& c2t3, const Input_surface& surface, const Criteria& criteria) - : Mesher_base(parent), + : Mesher_base(parent), mesher(c2t3, surface, surface, criteria), c2t3(c2t3), surface(surface) @@ -148,7 +145,7 @@ public: 20); mesher.init(); } - + void mesh() { int global_nbsteps = 0; @@ -168,12 +165,12 @@ public: ++global_nbsteps; if(timer.time() > 1) { - std::cerr - << boost::format("\r \r" - "(%1%,%2%,%3%) (%|4$.1f| vertices/s)") - % c2t3.triangulation().number_of_vertices() - % global_nbsteps % mesher.debug_info() - % (nbsteps / timer.time()); + std::cerr + << boost::format("\r \r" + "(%1%,%2%,%3%) (%|4$.1f| vertices/s)") + % c2t3.triangulation().number_of_vertices() + % global_nbsteps % mesher.debug_info() + % (nbsteps / timer.time()); qApp->processEvents(); nbsteps = 0; timer.reset(); @@ -189,11 +186,11 @@ public: // That thread takes a Mesher_base* as parent. It just launches the meshing // process. -struct Meshing_thread : QThread +struct Meshing_thread : QThread { Mesher_base* mesher; - Meshing_thread(Mesher_base* parent) + Meshing_thread(Mesher_base* parent) : QThread(parent), mesher(parent) { } @@ -207,7 +204,7 @@ struct Meshing_thread : QThread typedef Tr::Geom_traits GT; typedef Tr::Geom_traits::FT FT; -Scene_item* cgal_code_remesh(QWidget* parent, +Scene_item* cgal_code_remesh(QWidget* parent, Polyhedron* pMesh, const double angle, const double sizing, @@ -226,7 +223,7 @@ Scene_item* cgal_code_remesh(QWidget* parent, // int tag; // public: -// Mesh_process(QWidget* parent, +// Mesh_process(QWidget* parent, // Polyhedron* pMesh, // const double angle, // const double sizing, @@ -241,7 +238,7 @@ Scene_item* cgal_code_remesh(QWidget* parent, // { // } -// Scene_item* launch() +// Scene_item* launch() if(!pMesh) return 0; @@ -277,14 +274,14 @@ Scene_item* cgal_code_remesh(QWidget* parent, std::vector polyhedron_points; polyhedron_points.reserve(pMesh->size_of_vertices()); - std::copy(pMesh->points_begin(), pMesh->points_end(), + std::copy(pMesh->points_begin(), pMesh->points_end(), std::back_inserter(polyhedron_points)); typedef std::vector::size_type size_type; size_type nb_initial_points = 10; nb_initial_points = (std::min)(nb_initial_points, polyhedron_points.size()); for(size_type n = 0; - n < nb_initial_points || (n < 10 * nb_initial_points && + n < nb_initial_points || (n < 10 * nb_initial_points && triangulation.dimension() < 3 ); n = triangulation.number_of_vertices()) { @@ -308,17 +305,17 @@ Scene_item* cgal_code_remesh(QWidget* parent, QMessageBox::Cancel, parent); switch(tag) { - case 0: - mesher = new Mesher(0, c2t3, input, facets_criteria); ; break; case 1: - mesher = new Mesher(0, c2t3, input, facets_criteria); break; default: - mesher = new Mesher(0, c2t3, input, facets_criteria); } QObject::connect(message_box, SIGNAL(buttonClicked( QAbstractButton *)), @@ -326,7 +323,7 @@ Scene_item* cgal_code_remesh(QWidget* parent, message_box->show(); qApp->processEvents(); - + Meshing_thread* thread = new Meshing_thread(mesher); mesher->moveToThread(thread); thread->start(); diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_scale_space_reconstruction_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_scale_space_reconstruction_plugin.cpp index 34fec046108..d086c4bdadb 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_scale_space_reconstruction_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_scale_space_reconstruction_plugin.cpp @@ -37,6 +37,8 @@ class Polyhedron_demo_scale_space_reconstruction_plugin : public Polyhedron_demo_plugin_helper { Q_OBJECT + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") + Q_INTERFACES(Polyhedron_demo_plugin_interface) QAction* actionScaleSpaceReconstruction; @@ -158,6 +160,4 @@ void Polyhedron_demo_scale_space_reconstruction_plugin::on_actionScaleSpaceRecon } } -Q_EXPORT_PLUGIN2(Polyhedron_demo_scale_space_reconstruction_plugin, Polyhedron_demo_scale_space_reconstruction_plugin) - #include "Polyhedron_demo_scale_space_reconstruction_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_selection_io_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_selection_io_plugin.cpp index 2825b22f398..92e19d8442e 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_selection_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_selection_io_plugin.cpp @@ -3,40 +3,40 @@ #include class Polyhedron_demo_selection_io_plugin : - public QObject, - public Polyhedron_demo_io_plugin_interface + public QObject, + public Polyhedron_demo_io_plugin_interface { - Q_OBJECT - Q_INTERFACES(Polyhedron_demo_io_plugin_interface) - + Q_OBJECT + Q_INTERFACES(Polyhedron_demo_io_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") public: - QString name() const { return "selection_io_plugin"; } - QString nameFilters() const { return "Selection files (*.selection.txt)"; } + QString name() const { return "selection_io_plugin"; } + QString nameFilters() const { return "Selection files (*.selection.txt)"; } - bool canLoad() const { return true; } - Scene_item* load(QFileInfo fileinfo) { - if(fileinfo.suffix().toLower() != "txt") return 0; - // There will be no actual loading at this step. - // Polyhedron_demo_selection_plugin will trigger load when item in new_item_created - Scene_polyhedron_selection_item* item = new Scene_polyhedron_selection_item(); - if(!item->load(fileinfo.filePath().toStdString())) { - delete item; - return NULL; + bool canLoad() const { return true; } + Scene_item* load(QFileInfo fileinfo) { + if(fileinfo.suffix().toLower() != "txt") return 0; + // There will be no actual loading at this step. + // Polyhedron_demo_selection_plugin will trigger load when item in new_item_created + Scene_polyhedron_selection_item* item = new Scene_polyhedron_selection_item(); + if(!item->load(fileinfo.filePath().toStdString())) { + delete item; + return NULL; + } + return item; } - return item; - } - - bool canSave(const Scene_item* scene_item) { - return qobject_cast(scene_item); - } - bool save(const Scene_item* scene_item, QFileInfo fileinfo) { - const Scene_polyhedron_selection_item* item = qobject_cast(scene_item); - if(item == NULL) { return false; } - return item->save(fileinfo.filePath().toStdString()); - } + bool canSave(const Scene_item* scene_item) { + return qobject_cast(scene_item); + } + bool save(const Scene_item* scene_item, QFileInfo fileinfo) { + const Scene_polyhedron_selection_item* item = qobject_cast(scene_item); + if(item == NULL) { return false; } + + return item->save(fileinfo.filePath().toStdString()); + } }; #include -Q_EXPORT_PLUGIN2(Polyhedron_demo_selection_io_plugin, Polyhedron_demo_selection_io_plugin) +//Q_EXPORT_PLUGIN2(Polyhedron_demo_selection_io_plugin, Polyhedron_demo_selection_io_plugin) #include "Polyhedron_demo_selection_io_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_selection_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_selection_plugin.cpp index 31a1554e3ec..43f71c09b3e 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_selection_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_selection_plugin.cpp @@ -60,7 +60,7 @@ class Polyhedron_demo_selection_plugin : { Q_OBJECT Q_INTERFACES(Polyhedron_demo_plugin_interface) - + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") public: bool applicable(QAction*) const { return qobject_cast(scene->item(scene->mainSelectionIndex())) @@ -73,7 +73,6 @@ public: mw = mainWindow; scene = scene_interface; messages = m; - actionSelection = new QAction(tr("Selection"), mw); connect(actionSelection, SIGNAL(triggered()), this, SLOT(selection_action())); @@ -382,6 +381,6 @@ typedef std::multimap Selection_item_map selection_item_map; }; // end Polyhedron_demo_selection_plugin -Q_EXPORT_PLUGIN2(Polyhedron_demo_selection_plugin, Polyhedron_demo_selection_plugin) +//Q_EXPORT_PLUGIN2(Polyhedron_demo_selection_plugin, Polyhedron_demo_selection_plugin) #include "Polyhedron_demo_selection_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_self_intersection_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_self_intersection_plugin.cpp index 894837ead17..bf3bc02131b 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_self_intersection_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_self_intersection_plugin.cpp @@ -25,6 +25,7 @@ class Polyhedron_demo_self_intersection_plugin : { Q_OBJECT Q_INTERFACES(Polyhedron_demo_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") public: // used by Polyhedron_demo_plugin_helper @@ -83,6 +84,4 @@ void Polyhedron_demo_self_intersection_plugin::on_actionSelfIntersection_trigger } } -Q_EXPORT_PLUGIN2(Polyhedron_demo_self_intersection_plugin, Polyhedron_demo_self_intersection_plugin) - #include "Polyhedron_demo_self_intersection_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_shortest_path_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_shortest_path_plugin.cpp index 063e5ec61ff..4fc951ad8fb 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_shortest_path_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_shortest_path_plugin.cpp @@ -29,6 +29,7 @@ class Polyhedron_demo_shortest_path_plugin : { Q_OBJECT Q_INTERFACES(Polyhedron_demo_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") private: typedef boost::property_map::type VertexIndexMap; @@ -217,7 +218,6 @@ void Polyhedron_demo_shortest_path_plugin::new_item(int itemIndex) void Polyhedron_demo_shortest_path_plugin::on_actionMakeShortestPaths_triggered() { Scene_polyhedron_item* polyhedronItem = get_selected_item(); - if (polyhedronItem) { if (m_shortestPathsMap.find(polyhedronItem) == m_shortestPathsMap.end()) @@ -300,6 +300,4 @@ void Polyhedron_demo_shortest_path_plugin::check_and_set_ids(Polyhedron* polyhed } } -Q_EXPORT_PLUGIN2(Polyhedron_demo_shortest_path_plugin, Polyhedron_demo_shortest_path_plugin) - #include "Polyhedron_demo_shortest_path_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_stl_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_stl_plugin.cpp index 07f23e5c9ce..cc49cbd9cd5 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_stl_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_stl_plugin.cpp @@ -17,6 +17,7 @@ class Polyhedron_demo_stl_plugin : { Q_OBJECT Q_INTERFACES(Polyhedron_demo_io_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.IOPluginInterface/1.0") public: QString nameFilters() const; @@ -87,6 +88,4 @@ bool Polyhedron_demo_stl_plugin::save(const Scene_item*, QFileInfo) return false; } -#include -Q_EXPORT_PLUGIN2(Polyhedron_demo_stl_plugin, Polyhedron_demo_stl_plugin) #include "Polyhedron_demo_stl_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_subdivision_methods_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_subdivision_methods_plugin.cpp index f84a9983abc..eec02ffc4db 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_subdivision_methods_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_subdivision_methods_plugin.cpp @@ -14,7 +14,7 @@ class Polyhedron_demo_subdivision_methods_plugin : { Q_OBJECT Q_INTERFACES(Polyhedron_demo_plugin_interface) - + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") public: // used by Polyhedron_demo_plugin_helper QStringList actionsNames() const { @@ -91,6 +91,4 @@ void Polyhedron_demo_subdivision_methods_plugin::on_actionSqrt3_triggered() scene->itemChanged(item); } -Q_EXPORT_PLUGIN2(Polyhedron_demo_subdivision_methods_plugin, Polyhedron_demo_subdivision_methods_plugin) - #include "Polyhedron_demo_subdivision_methods_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_transform_polyhedron_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_transform_polyhedron_plugin.cpp index e50e33cfcd2..05a7d56a5e9 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_transform_polyhedron_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_transform_polyhedron_plugin.cpp @@ -21,6 +21,7 @@ class Polyhedron_demo_transform_polyhedron_plugin : { Q_OBJECT Q_INTERFACES(Polyhedron_demo_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") public: @@ -137,8 +138,5 @@ void Polyhedron_demo_transform_polyhedron_plugin::end(){ scene->replaceItem(tr_item_index,new_item); delete transform_item; } - - -Q_EXPORT_PLUGIN2(Polyhedron_demo_transform_polyhedron_plugin, Polyhedron_demo_transform_polyhedron_plugin) #include "Polyhedron_demo_transform_polyhedron_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_triangulate_facets_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_triangulate_facets_plugin.cpp index 4cfdbe8cd43..69ba951bfc3 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_triangulate_facets_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_triangulate_facets_plugin.cpp @@ -15,6 +15,7 @@ class Polyhedron_demo_triangulate_facets_plugin : { Q_OBJECT Q_INTERFACES(Polyhedron_demo_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") public: // To silent a warning -Woverloaded-virtual @@ -138,6 +139,4 @@ private: Messages_interface* messages; }; -Q_EXPORT_PLUGIN2(Polyhedron_demo_triangulate_facets_plugin, Polyhedron_demo_triangulate_facets_plugin) - #include "Polyhedron_demo_triangulate_facets_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_trivial_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_trivial_plugin.cpp index 208b501d9f8..a4de4e1580f 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_trivial_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_trivial_plugin.cpp @@ -4,148 +4,195 @@ #include "Scene_interface.h" #include +#include "Viewer_interface.h" #include #include class Q_DECL_EXPORT Scene_bbox_item : public Scene_item { - Q_OBJECT + Q_OBJECT public: - Scene_bbox_item(const Scene_interface* scene_interface) - : scene(scene_interface) - {} + Scene_bbox_item(const Scene_interface* scene_interface) + : Scene_item(1,1), scene(scene_interface) - bool isFinite() const { return true; } - bool isEmpty() const { return true; } - Bbox bbox() const { return Bbox(); } + { - Scene_bbox_item* clone() const { - return 0; - } + positions_lines.resize(0); + qFunc.initializeOpenGLFunctions(); + //Generates an integer which will be used as ID for each buffer + } + ~Scene_bbox_item() + { + } + bool isFinite() const { return true; } + bool isEmpty() const { return true; } + Bbox bbox() const { return Bbox(); } - QString toolTip() const { - const Bbox& bb = scene->bbox(); - return QString("

Scene bounding box

" - "

x range: (%1, %2)
" - "y range: (%3, %4)
" - "z range: (%5, %6)

") - .arg(bb.xmin).arg(bb.xmax) - .arg(bb.ymin).arg(bb.ymax) - .arg(bb.zmin).arg(bb.zmax); - } + Scene_bbox_item* clone() const { + return 0; + } - // Indicate if rendering mode is supported - bool supportsRenderingMode(RenderingMode m) const { - return (m == Wireframe); - } + QString toolTip() const { + const Bbox& bb = scene->bbox(); + return QString("

Scene bounding box

" + "

x range: (%1, %2)
" + "y range: (%3, %4)
" + "z range: (%5, %6)

") + .arg(bb.xmin).arg(bb.xmax) + .arg(bb.ymin).arg(bb.ymax) + .arg(bb.zmin).arg(bb.zmax); + } - // Flat/Gouraud OpenGL drawing - void draw() const {} + // Indicate if rendering mode is supported + bool supportsRenderingMode(RenderingMode m) const { + return (m == Wireframe); + } - // Wireframe OpenGL drawing - void draw_edges() const { - const Bbox& bb = scene->bbox(); - ::glBegin(GL_LINES); - gl_draw_edge(bb.xmin, bb.ymin, bb.zmin, - bb.xmax, bb.ymin, bb.zmin); - gl_draw_edge(bb.xmin, bb.ymin, bb.zmin, - bb.xmin, bb.ymax, bb.zmin); - gl_draw_edge(bb.xmin, bb.ymin, bb.zmin, - bb.xmin, bb.ymin, bb.zmax); - - gl_draw_edge(bb.xmax, bb.ymin, bb.zmin, - bb.xmax, bb.ymax, bb.zmin); - gl_draw_edge(bb.xmax, bb.ymin, bb.zmin, - bb.xmax, bb.ymin, bb.zmax); - - gl_draw_edge(bb.xmin, bb.ymax, bb.zmin, - bb.xmax, bb.ymax, bb.zmin); - gl_draw_edge(bb.xmin, bb.ymax, bb.zmin, - bb.xmin, bb.ymax, bb.zmax); - - gl_draw_edge(bb.xmin, bb.ymin, bb.zmax, - bb.xmax, bb.ymin, bb.zmax); - gl_draw_edge(bb.xmin, bb.ymin, bb.zmax, - bb.xmin, bb.ymax, bb.zmax); - - gl_draw_edge(bb.xmax, bb.ymax, bb.zmax, - bb.xmin, bb.ymax, bb.zmax); - gl_draw_edge(bb.xmax, bb.ymax, bb.zmax, - bb.xmax, bb.ymin, bb.zmax); - gl_draw_edge(bb.xmax, bb.ymax, bb.zmax, - bb.xmax, bb.ymax, bb.zmin); - ::glEnd(); - } + void draw_edges(Viewer_interface* viewer) const + { + if(!are_buffers_filled) + initialize_buffers(viewer); + vaos[0]->bind(); + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT); + attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT); + program->bind(); + program->setAttributeValue("colors", this->color()); + qFunc.glDrawArrays(GL_LINES, 0, static_cast(positions_lines.size()/3)); + vaos[0]->release(); + program->release(); + + } + + void changed() + { + compute_elements(); + are_buffers_filled = false; + } private: - static void gl_draw_edge(double px, double py, double pz, - double qx, double qy, double qz) - { - ::glVertex3d(px,py,pz); - ::glVertex3d(qx,qy,qz); - } - const Scene_interface* scene; + std::vector positions_lines; + mutable QOpenGLShaderProgram *program; + using Scene_item::initialize_buffers; + void initialize_buffers(Viewer_interface *viewer)const + { + + //vao containing the data for the lines + { + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT, viewer); + program->bind(); + + vaos[0]->bind(); + buffers[0].bind(); + buffers[0].allocate(positions_lines.data(), + static_cast(positions_lines.size()*sizeof(float))); + program->enableAttributeArray("vertex"); + program->setAttributeBuffer("vertex",GL_FLOAT,0,3); + buffers[0].release(); + + vaos[0]->release(); + program->release(); + + } + are_buffers_filled = true; + } + + void compute_elements() + { + positions_lines.clear(); + const Bbox& bb = scene->bbox(); + positions_lines.push_back(bb.xmin); positions_lines.push_back(bb.ymin); positions_lines.push_back(bb.zmin); + positions_lines.push_back(bb.xmax); positions_lines.push_back(bb.ymin); positions_lines.push_back(bb.zmin); + positions_lines.push_back(bb.xmin); positions_lines.push_back(bb.ymin); positions_lines.push_back(bb.zmin); + positions_lines.push_back(bb.xmin); positions_lines.push_back(bb.ymax); positions_lines.push_back(bb.zmin); + positions_lines.push_back(bb.xmin); positions_lines.push_back(bb.ymin); positions_lines.push_back(bb.zmin); + positions_lines.push_back(bb.xmin); positions_lines.push_back(bb.ymin); positions_lines.push_back(bb.zmax); + + positions_lines.push_back(bb.xmax); positions_lines.push_back(bb.ymin); positions_lines.push_back(bb.zmin); + positions_lines.push_back(bb.xmax); positions_lines.push_back(bb.ymax); positions_lines.push_back(bb.zmin); + positions_lines.push_back(bb.xmax); positions_lines.push_back(bb.ymin); positions_lines.push_back(bb.zmin); + positions_lines.push_back(bb.xmax); positions_lines.push_back(bb.ymin); positions_lines.push_back(bb.zmax); + + positions_lines.push_back(bb.xmin); positions_lines.push_back(bb.ymax); positions_lines.push_back(bb.zmin); + positions_lines.push_back(bb.xmax); positions_lines.push_back(bb.ymax); positions_lines.push_back(bb.zmin); + positions_lines.push_back(bb.xmin); positions_lines.push_back(bb.ymax); positions_lines.push_back(bb.zmin); + positions_lines.push_back(bb.xmin); positions_lines.push_back(bb.ymax); positions_lines.push_back(bb.zmax); + + positions_lines.push_back(bb.xmin); positions_lines.push_back(bb.ymin); positions_lines.push_back(bb.zmax); + positions_lines.push_back(bb.xmax); positions_lines.push_back(bb.ymin); positions_lines.push_back(bb.zmax); + positions_lines.push_back(bb.xmin); positions_lines.push_back(bb.ymin); positions_lines.push_back(bb.zmax); + positions_lines.push_back(bb.xmin); positions_lines.push_back(bb.ymax); positions_lines.push_back(bb.zmax); + + positions_lines.push_back(bb.xmax); positions_lines.push_back(bb.ymax); positions_lines.push_back(bb.zmax); + positions_lines.push_back(bb.xmin); positions_lines.push_back(bb.ymax); positions_lines.push_back(bb.zmax); + positions_lines.push_back(bb.xmax); positions_lines.push_back(bb.ymax); positions_lines.push_back(bb.zmax); + positions_lines.push_back(bb.xmax); positions_lines.push_back(bb.ymin); positions_lines.push_back(bb.zmax); + positions_lines.push_back(bb.xmax); positions_lines.push_back(bb.ymax); positions_lines.push_back(bb.zmax); + positions_lines.push_back(bb.xmax); positions_lines.push_back(bb.ymax); positions_lines.push_back(bb.zmin); + } + + const Scene_interface* scene; }; #include "Polyhedron_demo_plugin_interface.h" class Polyhedron_demo_trivial_plugin : - public QObject, - public Polyhedron_demo_plugin_interface + public QObject, + public Polyhedron_demo_plugin_interface { - Q_OBJECT - Q_INTERFACES(Polyhedron_demo_plugin_interface) + Q_OBJECT + Q_INTERFACES(Polyhedron_demo_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") public: - void init(QMainWindow* mainWindow, Scene_interface* scene_interface); - QList actions() const { - return QList() << actionBbox; - } + void init(QMainWindow* mainWindow, Scene_interface* scene_interface); + QList actions() const { + return QList() << actionBbox; + } - bool applicable(QAction*) const { - return true; - } + bool applicable(QAction*) const { + return true; + } public Q_SLOTS: - void bbox(); - void enableAction(); + + void bbox(); + void enableAction(); private: - Scene_interface* scene; - QAction* actionBbox; + Scene_interface* scene; + QAction* actionBbox; + }; // end Polyhedron_demo_trivial_plugin void Polyhedron_demo_trivial_plugin::init(QMainWindow* mainWindow, Scene_interface* scene_interface) { - scene = scene_interface; - actionBbox = new QAction(tr("Create bbox"), mainWindow); - connect(actionBbox, SIGNAL(triggered()), - this, SLOT(bbox())); + scene = scene_interface; + actionBbox = new QAction(tr("Create bbox"), mainWindow); + connect(actionBbox, SIGNAL(triggered()), + this, SLOT(bbox())); } void Polyhedron_demo_trivial_plugin::bbox() { - for(int i = 0, end = scene->numberOfEntries(); - i < end; ++i) - { - if(qobject_cast(scene->item(i))) - return; - } - Scene_item* item = new Scene_bbox_item(scene); - connect(item, SIGNAL(destroyed()), - this, SLOT(enableAction())); - item->setName("Scene bbox"); - item->setColor(Qt::black); - item->setRenderingMode(Wireframe); - scene->addItem(item); - actionBbox->setEnabled(false); + for(int i = 0, end = scene->numberOfEntries(); + i < end; ++i) + { + if(qobject_cast(scene->item(i))) + return; + } + Scene_item* item = new Scene_bbox_item(scene); + connect(item, SIGNAL(destroyed()), + this, SLOT(enableAction())); + item->setName("Scene bbox"); + item->setColor(Qt::black); + item->setRenderingMode(Wireframe); + scene->addItem(item); + actionBbox->setEnabled(false); } void Polyhedron_demo_trivial_plugin::enableAction() { - actionBbox->setEnabled(true); + actionBbox->setEnabled(true); } -Q_EXPORT_PLUGIN2(Polyhedron_demo_trivial_plugin, Polyhedron_demo_trivial_plugin) - #include "Polyhedron_demo_trivial_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_vcm_normal_estimation_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_vcm_normal_estimation_plugin.cpp index 5e9278c64c6..91bc305f133 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_vcm_normal_estimation_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_vcm_normal_estimation_plugin.cpp @@ -30,6 +30,7 @@ class Polyhedron_demo_vcm_normal_estimation_plugin : { Q_OBJECT Q_INTERFACES(Polyhedron_demo_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.PluginInterface/1.0") QAction* actionVCMNormalEstimation; public: @@ -161,6 +162,4 @@ void Polyhedron_demo_vcm_normal_estimation_plugin::on_actionVCMNormalEstimation_ #endif // !CGAL_DISABLE_NORMAL_ESTIMATION_PLUGIN } -Q_EXPORT_PLUGIN2(Polyhedron_demo_vcm_normal_estimation_plugin, Polyhedron_demo_vcm_normal_estimation_plugin) - #include "Polyhedron_demo_vcm_normal_estimation_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_xyz_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_xyz_plugin.cpp index f77ee9a6ad0..1f6d0b4d0f0 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_xyz_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_xyz_plugin.cpp @@ -13,6 +13,7 @@ class Polyhedron_demo_xyz_plugin : { Q_OBJECT Q_INTERFACES(Polyhedron_demo_io_plugin_interface) + Q_PLUGIN_METADATA(IID "com.geometryfactory.PolyhedronDemo.IOPluginInterface/1.0") public: QString name() const { return "xyz_plugin"; } @@ -75,6 +76,4 @@ bool Polyhedron_demo_xyz_plugin::save(const Scene_item* item, QFileInfo fileinfo return point_set_item->write_xyz_point_set(out); } -#include -Q_EXPORT_PLUGIN2(Polyhedron_demo_xyz_plugin, Polyhedron_demo_xyz_plugin) #include "Polyhedron_demo_xyz_plugin.moc" diff --git a/Polyhedron/demo/Polyhedron/Scene.cpp b/Polyhedron/demo/Polyhedron/Scene.cpp index 779c5989309..1863ee0602e 100644 --- a/Polyhedron/demo/Polyhedron/Scene.cpp +++ b/Polyhedron/demo/Polyhedron/Scene.cpp @@ -1,9 +1,3 @@ - -#ifdef CGAL_GLEW_ENABLED -# include "GlSplat/GlSplat.h" -#endif - - #include #include "config.h" #include "Scene.h" @@ -22,128 +16,122 @@ #include #include -namespace { - void CGALglcolor(QColor c) - { - ::glColor4d(c.red()/255.0, c.green()/255.0, c.blue()/255.0, c.alpha()/255.0); - } -} -#ifdef CGAL_GLEW_ENABLED -GlSplat::SplatRenderer* Scene::ms_splatting = 0; -int Scene::ms_splattingCounter = 0; -GlSplat::SplatRenderer* Scene::splatting() +namespace { +void CGALglcolor(QColor c) { - assert(ms_splatting!=0 && "A Scene object must be created before requesting the splatting object"); - return ms_splatting; + ::glColor4d(c.red()/255.0, c.green()/255.0, c.blue()/255.0, c.alpha()/255.0); +} } -#endif Scene::Scene(QObject* parent) - : QAbstractListModel(parent), - selected_item(-1), - item_A(-1), - item_B(-1) + : QAbstractListModel(parent), + selected_item(-1), + item_A(-1), + item_B(-1) { - connect(this, SIGNAL(selectionRay(double, double, double, - double, double, double)), - this, SLOT(setSelectionRay(double, double, double, - double, double, double))); -#ifdef CGAL_GLEW_ENABLED - if(ms_splatting==0) - ms_splatting = new GlSplat::SplatRenderer(); - ms_splattingCounter++; -#endif + + connect(this, SIGNAL(selectionRay(double, double, double, + double, double, double)), + this, SLOT(setSelectionRay(double, double, double, + double, double, double))); } Scene::Item_id Scene::addItem(Scene_item* item) { - Bbox bbox_before = bbox(); - m_entries.push_back(item); - connect(item, SIGNAL(itemChanged()), - this, SLOT(itemChanged())); - if(bbox_before + item->bbox() != bbox_before) - { Q_EMIT updated_bbox(); } - Q_EMIT updated(); - QAbstractListModel::reset(); - Item_id id = m_entries.size() - 1; + + Bbox bbox_before = bbox(); + m_entries.push_back(item); + connect(item, SIGNAL(itemChanged()), + this, SLOT(itemChanged())); + if(bbox_before + item->bbox() != bbox_before) +{ Q_EMIT updated_bbox(); } + QAbstractListModel::beginResetModel(); + Q_EMIT updated(); + QAbstractListModel::endResetModel(); + Item_id id = m_entries.size() - 1; Q_EMIT newItem(id); - return id; + return id; } Scene_item* Scene::replaceItem(Scene::Item_id index, Scene_item* item, bool emit_item_about_to_be_destroyed) { - if(index < 0 || index >= m_entries.size()) - return 0; + item->changed(); + if(index < 0 || index >= m_entries.size()) + return 0; - if(emit_item_about_to_be_destroyed) { + if(emit_item_about_to_be_destroyed) { Q_EMIT itemAboutToBeDestroyed(m_entries[index]); - } + } - connect(item, SIGNAL(itemChanged()), - this, SLOT(itemChanged())); - std::swap(m_entries[index], item); - - if ( item->isFinite() && !item->isEmpty() && - m_entries[index]->isFinite() && !m_entries[index]->isEmpty() && - item->bbox()!=m_entries[index]->bbox() ) - { + connect(item, SIGNAL(itemChanged()), + this, SLOT(itemChanged())); + std::swap(m_entries[index], item); + if ( item->isFinite() && !item->isEmpty() && + m_entries[index]->isFinite() && !m_entries[index]->isEmpty() && + item->bbox()!=m_entries[index]->bbox() ) + { Q_EMIT updated_bbox(); - } + } Q_EMIT updated(); - itemChanged(index); - // QAbstractListModel::reset(); - return item; + itemChanged(index); + // QAbstractListModel::reset(); + return item; } int Scene::erase(int index) { - if(index < 0 || index >= m_entries.size()) - return -1; + if(index < 0 || index >= m_entries.size()) + return -1; - Scene_item* item = m_entries[index]; + Scene_item* item = m_entries[index]; Q_EMIT itemAboutToBeDestroyed(item); - delete item; - m_entries.removeAt(index); + delete item; + m_entries.removeAt(index); selected_item = -1; - Q_EMIT updated(); - QAbstractListModel::reset(); - if(--index >= 0) - return index; - if(!m_entries.isEmpty()) - return 0; - return -1; + QAbstractListModel::beginResetModel(); + Q_EMIT updated(); + QAbstractListModel::endResetModel(); + + if(--index >= 0) + return index; + if(!m_entries.isEmpty()) + return 0; + return -1; } int Scene::erase(QList indices) { - QList to_be_removed; + QList to_be_removed; - int max_index = -1; - Q_FOREACH(int index, indices) { - if(index < 0 || index >= m_entries.size()) - continue; - max_index = (std::max)(max_index, index); - Scene_item* item = m_entries[index]; - to_be_removed.push_back(item); + int max_index = -1; + Q_FOREACH(int index, indices) { + if(index < 0 || index >= m_entries.size()) + continue; + max_index = (std::max)(max_index, index); + Scene_item* item = m_entries[index]; + to_be_removed.push_back(item); Q_EMIT itemAboutToBeDestroyed(item); - delete item; - } + delete item; + } + + Q_FOREACH(Scene_item* item, to_be_removed) { m_entries.removeAll(item); } selected_item = -1; + QAbstractListModel::beginResetModel(); Q_EMIT updated(); - QAbstractListModel::reset(); - + QAbstractListModel::endResetModel(); + int index = max_index + 1 - indices.size(); if(index >= m_entries.size()) { index = m_entries.size() - 1; @@ -153,38 +141,34 @@ Scene::erase(QList indices) if(!m_entries.isEmpty()) return 0; return -1; + } Scene::~Scene() { - Q_FOREACH(Scene_item* item_ptr, m_entries) - { - delete item_ptr; - } - m_entries.clear(); - -#ifdef CGAL_GLEW_ENABLED - if((--ms_splattingCounter)==0) - delete ms_splatting; -#endif + Q_FOREACH(Scene_item* item_ptr, m_entries) + { + delete item_ptr; + } + m_entries.clear(); } Scene_item* Scene::item(Item_id index) const { - return m_entries.value(index); // QList::value checks bounds + return m_entries.value(index); // QList::value checks bounds } Scene::Item_id Scene::item_id(Scene_item* scene_item) const { - return m_entries.indexOf(scene_item); + return m_entries.indexOf(scene_item); } int Scene::numberOfEntries() const { - return m_entries.size(); + return m_entries.size(); } // Duplicate a scene item. @@ -192,581 +176,566 @@ Scene::numberOfEntries() const Scene::Item_id Scene::duplicate(Item_id index) { - if(index < 0 || index >= m_entries.size()) - return -1; + if(index < 0 || index >= m_entries.size()) + return -1; - const Scene_item* item = m_entries[index]; - Scene_item* new_item = item->clone(); - if(new_item) { - new_item->setName(tr("%1 (copy)").arg(item->name())); - new_item->setColor(item->color()); - new_item->setVisible(item->visible()); - addItem(new_item); - return m_entries.size() - 1; - } - else - return -1; + const Scene_item* item = m_entries[index]; + Scene_item* new_item = item->clone(); + if(new_item) { + new_item->setName(tr("%1 (copy)").arg(item->name())); + new_item->setColor(item->color()); + new_item->setVisible(item->visible()); + addItem(new_item); + return m_entries.size() - 1; + } + else + return -1; } void Scene::initializeGL() { -#ifdef CGAL_GLEW_ENABLED - ms_splatting->init(); -#endif -} + //Setting the light options -// workaround for Qt-4.2. -#if QT_VERSION < 0x040300 -# define lighter light -#endif + // Create light components + GLfloat ambientLight[] = { 0.4f, 0.4f, 0.4f, 1.0f }; + GLfloat diffuseLight[] = { 1.0f, 1.0f, 1.0, 1.0f }; + GLfloat specularLight[] = { 0.0f, 0.0f, 0.0f, 1.0f }; + GLfloat position[] = { 0.0f, 0.0f, 1.0f, 1.0f }; + + // Assign created components to GL_LIGHT0 + glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight); + glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight); + glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight); + glLightfv(GL_LIGHT0, GL_POSITION, position); + +} bool Scene::keyPressEvent(QKeyEvent* e){ - bool res=false; - for (QList::iterator it=selected_items_list.begin(),endit=selected_items_list.end(); - it!=endit;++it) - { - Scene_item* item=m_entries[*it]; - res |= item->keyPressEvent(e); - } - return res; + bool res=false; + for (QList::iterator it=selected_items_list.begin(),endit=selected_items_list.end(); + it!=endit;++it) + { + Scene_item* item=m_entries[*it]; + res |= item->keyPressEvent(e); + } + return res; } void Scene::draw() { - draw_aux(false, 0); + draw_aux(false, 0); } void Scene::draw(Viewer_interface* viewer) { - draw_aux(false, viewer); + draw_aux(false, viewer); } void Scene::drawWithNames() { - draw_aux(true, 0); + draw_aux(true, 0); } void Scene::drawWithNames(Viewer_interface* viewer) { - draw_aux(true, viewer); + draw_aux(true, viewer); } void Scene::draw_aux(bool with_names, Viewer_interface* viewer) { - // Flat/Gouraud OpenGL drawing - for(int index = 0; index < m_entries.size(); ++index) - { - if(with_names) { - ::glPushName(index); - } - Scene_item& item = *m_entries[index]; - if(item.visible()) - { - if(item.renderingMode() == Flat || item.renderingMode() == FlatPlusEdges || item.renderingMode() == Gouraud) - { - ::glEnable(GL_LIGHTING); - ::glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); - ::glPointSize(2.f); - ::glLineWidth(1.0f); - if(index == selected_item) - CGALglcolor(item.color().lighter(120)); - else - CGALglcolor(item.color()); - if(item.renderingMode() == Gouraud) - ::glShadeModel(GL_SMOOTH); - else - ::glShadeModel(GL_FLAT); - - if(CGAL::check_gl_error(__FILE__, __LINE__)) { - std::cerr << "GL error was before the drawing of the item \"" - << qPrintable(item.name()) << "\"\n" - << " with_name = " << std::boolalpha << with_names - << std::endl; - } - if(viewer) - item.draw(viewer); - else - item.draw(); - if(CGAL::check_gl_error(__FILE__, __LINE__)) { - std::cerr << "GL error was after the drawing of the item \"" - << qPrintable(item.name()) << "\"\n" - << " with_name = " << std::boolalpha << with_names - << std::endl; - } - } - } - if(with_names) { - ::glPopName(); - } - } - - // Wireframe OpenGL drawing - for(int index = 0; index < m_entries.size(); ++index) - { - if(with_names) { - ::glPushName(index); - } - Scene_item& item = *m_entries[index]; - if(item.visible()) - { - if(item.renderingMode() == FlatPlusEdges || item.renderingMode() == Wireframe) - { - ::glDisable(GL_LIGHTING); - ::glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); - ::glPointSize(2.f); - ::glLineWidth(1.0f); - if(index == selected_item) - CGALglcolor(Qt::black); - else - CGALglcolor(item.color().lighter(50)); - - if(viewer) - item.draw_edges(viewer); - else - item.draw_edges(); - } - else{ - if( item.renderingMode() == PointsPlusNormals ){ - ::glDisable(GL_LIGHTING); - ::glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); - ::glPointSize(2.f); - ::glLineWidth(1.0f); - if(index == selected_item) - CGALglcolor(item.color().lighter(120)); - else - CGALglcolor(item.color()); - if(viewer) - item.draw_edges(viewer); - else - item.draw_edges(); - } - } - } - if(with_names) { - ::glPopName(); - } - } - - // Points OpenGL drawing - for(int index = 0; index < m_entries.size(); ++index) - { - if(with_names) { - ::glPushName(index); - } - Scene_item& item = *m_entries[index]; - if(item.visible()) - { - if(item.renderingMode() == Points || item.renderingMode() == PointsPlusNormals) - { - ::glDisable(GL_LIGHTING); - ::glPolygonMode(GL_FRONT_AND_BACK,GL_POINT); - ::glPointSize(2.f); - ::glLineWidth(1.0f); - CGALglcolor(item.color()); - - if(viewer) - item.draw_points(viewer); - else - item.draw_points(); - } - } - if(with_names) { - ::glPopName(); - } - } - -#ifdef CGAL_GLEW_ENABLED - // Splatting - if(!with_names && ms_splatting->isSupported()) - { - ms_splatting->beginVisibilityPass(); + // Flat/Gouraud OpenGL drawing for(int index = 0; index < m_entries.size(); ++index) { - Scene_item& item = *m_entries[index]; - if(item.visible() && item.renderingMode() == Splatting) - { - item.draw_splats(); - } + if(with_names) { + ::glPushName(index); + } + Scene_item& item = *m_entries[index]; + if(item.visible()) + { + if(item.renderingMode() == Flat || item.renderingMode() == FlatPlusEdges || item.renderingMode() == Gouraud) + { + ::glEnable(GL_LIGHTING); + ::glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); + ::glPointSize(2.f); + ::glLineWidth(1.0f); + if(index == selected_item) + { + item.selection_changed(true); + CGALglcolor(item.color().lighter(120)); + } + else + + { + item.selection_changed(false); + CGALglcolor(item.color()); + } + + if(item.renderingMode() == Gouraud) + ::glShadeModel(GL_SMOOTH); + else + ::glShadeModel(GL_FLAT); + + item.contextual_changed(); + if(viewer) + item.draw(viewer); + else + item.draw(); + } + } + if(with_names) { + ::glPopName(); + } } - ms_splatting->beginAttributePass(); + + // Wireframe OpenGL drawing for(int index = 0; index < m_entries.size(); ++index) { - Scene_item& item = *m_entries[index]; - if(item.visible() && item.renderingMode() == Splatting) - { - CGALglcolor(item.color()); - item.draw_splats(); - } - } - ms_splatting->finalize(); - } -#endif + if(with_names) { + ::glPushName(index); + } + Scene_item& item = *m_entries[index]; + if(item.visible()) + { + if(item.renderingMode() == FlatPlusEdges || item.renderingMode() == Wireframe) + { + ::glDisable(GL_LIGHTING); + ::glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); + ::glPointSize(2.f); + ::glLineWidth(1.0f); + if(index == selected_item) + { + CGALglcolor(Qt::black); + item.selection_changed(true); + } + else + { + CGALglcolor(item.color().lighter(50)); + item.selection_changed(false); + } + + + if(viewer) + item.draw_edges(viewer); + else + item.draw_edges(); + } + else{ + if( item.renderingMode() == PointsPlusNormals ){ + ::glDisable(GL_LIGHTING); + ::glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); + ::glPointSize(2.f); + ::glLineWidth(1.0f); + if(index == selected_item) + { + + item.selection_changed(true); + CGALglcolor(item.color().lighter(120)); + } + else + { + + item.selection_changed(false); + CGALglcolor(item.color()); + } + if(viewer) + item.draw_edges(viewer); + else + item.draw_edges(); + } + } + } + item.contextual_changed(); + if(with_names) { + ::glPopName(); + } + } + + // Points OpenGL drawing + for(int index = 0; index < m_entries.size(); ++index) + { + if(with_names) { + ::glPushName(index); + } + Scene_item& item = *m_entries[index]; + if(item.visible()) + { + if(item.renderingMode() == Points || item.renderingMode() == PointsPlusNormals) + { + ::glDisable(GL_LIGHTING); + ::glPolygonMode(GL_FRONT_AND_BACK,GL_POINT); + ::glPointSize(2.f); + ::glLineWidth(1.0f); + CGALglcolor(item.color()); + + if(viewer) + item.draw_points(viewer); + else + item.draw_points(); + } + } + item.contextual_changed(); + if(with_names) { + ::glPopName(); + } + } } -// workaround for Qt-4.2 (see above) -#undef lighter - int Scene::rowCount(const QModelIndex & parent) const { - if (parent.isValid()) - return 0; - else - return m_entries.size(); + if (parent.isValid()) + return 0; + else + return m_entries.size(); } int Scene::columnCount(const QModelIndex & parent) const { - if (parent.isValid()) - return 0; - else - return NumberOfColumns; + if (parent.isValid()) + return 0; + else + return NumberOfColumns; } QVariant Scene::data(const QModelIndex &index, int role) const { - if (!index.isValid()) - return QVariant(); + if (!index.isValid()) + return QVariant(); - if(index.row() < 0 || index.row() >= m_entries.size()) - return QVariant(); + if(index.row() < 0 || index.row() >= m_entries.size()) + return QVariant(); - if(role == ::Qt::ToolTipRole) - { - return m_entries[index.row()]->toolTip(); - } - switch(index.column()) - { - case ColorColumn: - if(role == ::Qt::DisplayRole || role == ::Qt::EditRole) - return m_entries.value(index.row())->color(); - else if(role == ::Qt::DecorationRole) - return m_entries.value(index.row())->color(); - break; - case NameColumn: - if(role == ::Qt::DisplayRole || role == ::Qt::EditRole) - return m_entries.value(index.row())->name(); - if(role == ::Qt::FontRole) - return m_entries.value(index.row())->font(); - break; - case RenderingModeColumn: - if(role == ::Qt::DisplayRole) { - return m_entries.value(index.row())->renderingModeName(); + if(role == ::Qt::ToolTipRole) + { + return m_entries[index.row()]->toolTip(); } - else if(role == ::Qt::EditRole) { - return static_cast(m_entries.value(index.row())->renderingMode()); + switch(index.column()) + { + case ColorColumn: + if(role == ::Qt::DisplayRole || role == ::Qt::EditRole) + return m_entries.value(index.row())->color(); + else if(role == ::Qt::DecorationRole) + return m_entries.value(index.row())->color(); + break; + case NameColumn: + if(role == ::Qt::DisplayRole || role == ::Qt::EditRole) + return m_entries.value(index.row())->name(); + if(role == ::Qt::FontRole) + return m_entries.value(index.row())->font(); + break; + case RenderingModeColumn: + if(role == ::Qt::DisplayRole) { + return m_entries.value(index.row())->renderingModeName(); + } + else if(role == ::Qt::EditRole) { + return static_cast(m_entries.value(index.row())->renderingMode()); + } + else if(role == ::Qt::TextAlignmentRole) { + return ::Qt::AlignCenter; + } + break; + case ABColumn: + if(role == ::Qt::DisplayRole) { + if(index.row() == item_A) + return "A"; + if(index.row() == item_B) + return "B"; + } + else if(role == ::Qt::TextAlignmentRole) { + return ::Qt::AlignCenter; + } + break; + case VisibleColumn: + if(role == ::Qt::DisplayRole || role == ::Qt::EditRole) + return m_entries.value(index.row())->visible(); + break; + default: + return QVariant(); } - else if(role == ::Qt::TextAlignmentRole) { - return ::Qt::AlignCenter; - } - break; - case ABColumn: - if(role == ::Qt::DisplayRole) { - if(index.row() == item_A) - return "A"; - if(index.row() == item_B) - return "B"; - } - else if(role == ::Qt::TextAlignmentRole) { - return ::Qt::AlignCenter; - } - break; - case VisibleColumn: - if(role == ::Qt::DisplayRole || role == ::Qt::EditRole) - return m_entries.value(index.row())->visible(); - break; - default: return QVariant(); - } - return QVariant(); } QVariant Scene::headerData ( int section, ::Qt::Orientation orientation, int role ) const { - if(orientation == ::Qt::Horizontal) { - if (role == ::Qt::DisplayRole) - { - switch(section) - { - case NameColumn: - return tr("Name"); - break; - case ColorColumn: - return tr("Color"); - break; - case RenderingModeColumn: - return tr("Mode"); - case ABColumn: - return tr("A/B"); - break; - case VisibleColumn: - return tr("View"); - break; - default: - return QVariant(); - } + if(orientation == ::Qt::Horizontal) { + if (role == ::Qt::DisplayRole) + { + switch(section) + { + case NameColumn: + return tr("Name"); + break; + case ColorColumn: + return tr("Color"); + break; + case RenderingModeColumn: + return tr("Mode"); + case ABColumn: + return tr("A/B"); + break; + case VisibleColumn: + return tr("View"); + break; + default: + return QVariant(); + } + } + else if(role == ::Qt::ToolTipRole) { + if(section == RenderingModeColumn) { + return tr("Rendering mode (points/wireframe/flat/flat+edges/Gouraud)"); + } + else if(section == ABColumn) { + return tr("Selection A/Selection B"); + } + } } - else if(role == ::Qt::ToolTipRole) { - if(section == RenderingModeColumn) { - return tr("Rendering mode (points/wireframe/flat/flat+edges/Gouraud)"); - } - else if(section == ABColumn) { - return tr("Selection A/Selection B"); - } - } - } - return QAbstractListModel::headerData(section, orientation, role); + return QAbstractListModel::headerData(section, orientation, role); } Qt::ItemFlags Scene::flags ( const QModelIndex & index ) const { - if (index.isValid() && index.column() == NameColumn) { - return QAbstractListModel::flags(index) | ::Qt::ItemIsEditable; - } - else { - return QAbstractListModel::flags(index); - } + if (index.isValid() && index.column() == NameColumn) { + return QAbstractListModel::flags(index) | ::Qt::ItemIsEditable; + } + else { + return QAbstractListModel::flags(index); + } } bool Scene::setData(const QModelIndex &index, - const QVariant &value, - int role) + const QVariant &value, + int role) { - if( role != ::Qt::EditRole || !index.isValid() ) - return false; + if( role != ::Qt::EditRole || !index.isValid() ) + return false; - if(index.row() < 0 || index.row() >= m_entries.size()) - return false; + if(index.row() < 0 || index.row() >= m_entries.size()) + return false; - Scene_item* item = m_entries[index.row()]; - if(!item) return false; - switch(index.column()) - { - case NameColumn: - item->setName(value.toString()); - item->changed(); - Q_EMIT dataChanged(index, index); - return true; - break; - case ColorColumn: - item->setColor(value.value()); - item->changed(); - Q_EMIT dataChanged(index, index); - return true; - break; - case RenderingModeColumn: - { - RenderingMode rendering_mode = static_cast(value.toInt()); - // Find next supported rendering mode - while ( ! item->supportsRenderingMode(rendering_mode) -#ifdef CGAL_GLEW_ENABLED - || (rendering_mode==Splatting && !Scene::splatting()->isSupported()) -#endif - ) + Scene_item* item = m_entries[index.row()]; + if(!item) return false; + switch(index.column()) { - rendering_mode = static_cast( (rendering_mode+1) % NumberOfRenderingMode ); + case NameColumn: + item->setName(value.toString()); + item->changed(); + Q_EMIT dataChanged(index, index); + return true; + break; + case ColorColumn: + item->setColor(value.value()); + item->changed(); + Q_EMIT dataChanged(index, index); + return true; + break; + case RenderingModeColumn: + { + RenderingMode rendering_mode = static_cast(value.toInt()); + // Find next supported rendering mode + while ( ! item->supportsRenderingMode(rendering_mode) ) + { + rendering_mode = static_cast( (rendering_mode+1) % NumberOfRenderingMode ); + } + item->setRenderingMode(rendering_mode); + item->changed(); + Q_EMIT dataChanged(index, index); + return true; + break; } - item->setRenderingMode(rendering_mode); - item->changed(); + case VisibleColumn: + item->setVisible(value.toBool()); Q_EMIT dataChanged(index, index); - return true; - break; - } - case VisibleColumn: - item->setVisible(value.toBool()); - item->changed(); - Q_EMIT dataChanged(index, index); - return true; - default: + return true; + default: + return false; + } return false; - } - return false; } Scene::Item_id Scene::mainSelectionIndex() const { - return selected_item; + return selected_item; } QList Scene::selectionIndices() const { - return selected_items_list; + return selected_items_list; } int Scene::selectionAindex() const { - return item_A; + return item_A; } int Scene::selectionBindex() const { - return item_B; + return item_B; } QItemSelection Scene::createSelection(int i) { - return QItemSelection(this->createIndex(i, 0), - this->createIndex(i, LastColumn)); + return QItemSelection(this->createIndex(i, 0), + this->createIndex(i, LastColumn)); } QItemSelection Scene::createSelectionAll() { - return QItemSelection(this->createIndex(0, 0), - this->createIndex(m_entries.size() - 1 , LastColumn)); + return QItemSelection(this->createIndex(0, 0), + this->createIndex(m_entries.size() - 1 , LastColumn)); } void Scene::itemChanged() { - Scene_item* item = qobject_cast(sender()); - if(item) - itemChanged(item); + Scene_item* item = qobject_cast(sender()); + if(item) + itemChanged(item); } void Scene::itemChanged(Item_id i) { - if(i < 0 || i >= m_entries.size()) - return; + if(i < 0 || i >= m_entries.size()) + return; - m_entries[i]->changed(); + m_entries[i]->changed(); Q_EMIT dataChanged(this->createIndex(i, 0), - this->createIndex(i, LastColumn)); + this->createIndex(i, LastColumn)); } void Scene::itemChanged(Scene_item* item) { - item->changed(); + item->changed(); Q_EMIT dataChanged(this->createIndex(0, 0), - this->createIndex(m_entries.size() - 1, LastColumn)); + this->createIndex(m_entries.size() - 1, LastColumn)); } bool SceneDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, - const QStyleOptionViewItem &option, - const QModelIndex &index) + const QStyleOptionViewItem &option, + const QModelIndex &index) { - QAbstractProxyModel* proxyModel = dynamic_cast(model); - Q_ASSERT(proxyModel); - Scene *scene = dynamic_cast(proxyModel->sourceModel()); - Q_ASSERT(scene); - switch(index.column()) { - case Scene::VisibleColumn: - if (event->type() == QEvent::MouseButtonPress) { - QMouseEvent *mouseEvent = static_cast(event); - if(mouseEvent->button() == ::Qt::LeftButton) { - int x = mouseEvent->pos().x() - option.rect.x(); - if(x >= (option.rect.width() - size)/2 && - x <= (option.rect.width() + size)/2) { - model->setData(index, ! model->data(index).toBool() ); - } - } - return false; //so that the selection can change - } - return true; - break; - case Scene::ColorColumn: - if (event->type() == QEvent::MouseButtonPress) { - QMouseEvent *mouseEvent = static_cast(event); - if(mouseEvent->button() == ::Qt::LeftButton) { - QColor color = - QColorDialog::getColor(model->data(index).value(), - 0/*, - tr("Select color"), - QColorDialog::ShowAlphaChannel*/); - if (color.isValid()) { - model->setData(index, color ); + QAbstractProxyModel* proxyModel = dynamic_cast(model); + Q_ASSERT(proxyModel); + Scene *scene = dynamic_cast(proxyModel->sourceModel()); + Q_ASSERT(scene); + switch(index.column()) { + case Scene::VisibleColumn: + if (event->type() == QEvent::MouseButtonPress) { + QMouseEvent *mouseEvent = static_cast(event); + if(mouseEvent->button() == ::Qt::LeftButton) { + int x = mouseEvent->pos().x() - option.rect.x(); + if(x >= (option.rect.width() - size)/2 && + x <= (option.rect.width() + size)/2) { + model->setData(index, ! model->data(index).toBool() ); + } + } + return false; //so that the selection can change } - } + return true; + break; + case Scene::ColorColumn: + if (event->type() == QEvent::MouseButtonPress) { + QMouseEvent *mouseEvent = static_cast(event); + if(mouseEvent->button() == ::Qt::LeftButton) { + QColor color = + QColorDialog::getColor(model->data(index).value(), + 0/*, + tr("Select color"), + QColorDialog::ShowAlphaChannel*/); + if (color.isValid()) { + model->setData(index, color ); + } + } + } + else if(event->type() == QEvent::MouseButtonDblClick) { + return true; // block double-click + } + return false; + break; + case Scene::RenderingModeColumn: + if (event->type() == QEvent::MouseButtonPress) { + QMouseEvent *mouseEvent = static_cast(event); + if(mouseEvent->button() == ::Qt::LeftButton) { + // Switch rendering mode + /*RenderingMode*/int rendering_mode = model->data(index, ::Qt::EditRole).toInt(); + rendering_mode = (rendering_mode+1) % NumberOfRenderingMode; + model->setData(index, rendering_mode); + } + } + else if(event->type() == QEvent::MouseButtonDblClick) { + return true; // block double-click + } + return false; + break; + case Scene::ABColumn: + if (event->type() == QEvent::MouseButtonPress) { + if(index.row() == scene->item_B) { + scene->item_A = index.row(); + scene->item_B = -1; + } + else if(index.row() == scene->item_A) { + scene->item_B = index.row(); + scene->item_A = -1; + } + else if(scene->item_A == -1) { + scene->item_A = index.row(); + } + else { + scene->item_B = index.row(); + } + scene->dataChanged(scene->createIndex(0, Scene::ABColumn), + scene->createIndex(scene->rowCount() - 1, Scene::ABColumn)); + } + return false; + break; + default: + return QItemDelegate::editorEvent(event, model, option, index); } - else if(event->type() == QEvent::MouseButtonDblClick) { - return true; // block double-click - } - return false; - break; - case Scene::RenderingModeColumn: - if (event->type() == QEvent::MouseButtonPress) { - QMouseEvent *mouseEvent = static_cast(event); - if(mouseEvent->button() == ::Qt::LeftButton) { - // Switch rendering mode - /*RenderingMode*/int rendering_mode = model->data(index, ::Qt::EditRole).toInt(); - rendering_mode = (rendering_mode+1) % NumberOfRenderingMode; - model->setData(index, rendering_mode); - } - } - else if(event->type() == QEvent::MouseButtonDblClick) { - return true; // block double-click - } - return false; - break; - case Scene::ABColumn: - if (event->type() == QEvent::MouseButtonPress) { - if(index.row() == scene->item_B) { - scene->item_A = index.row(); - scene->item_B = -1; - } - else if(index.row() == scene->item_A) { - scene->item_B = index.row(); - scene->item_A = -1; - } - else if(scene->item_A == -1) { - scene->item_A = index.row(); - } - else { - scene->item_B = index.row(); - } - scene->dataChanged(scene->createIndex(0, Scene::ABColumn), - scene->createIndex(scene->rowCount() - 1, Scene::ABColumn)); - } - return false; - break; - default: - return QItemDelegate::editorEvent(event, model, option, index); - } } void SceneDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, - const QModelIndex &index) const + const QModelIndex &index) const { - if (index.column() != Scene::VisibleColumn) { - QItemDelegate::paint(painter, option, index); - } else { - const QAbstractItemModel *model = index.model(); - QPalette::ColorGroup cg = (option.state & QStyle::State_Enabled) ? - (option.state & QStyle::State_Active) ? QPalette::Normal : QPalette::Inactive : QPalette::Disabled; + if (index.column() != Scene::VisibleColumn) { + QItemDelegate::paint(painter, option, index); + } else { + const QAbstractItemModel *model = index.model(); + QPalette::ColorGroup cg = (option.state & QStyle::State_Enabled) ? + (option.state & QStyle::State_Active) ? QPalette::Normal : QPalette::Inactive : QPalette::Disabled; - if (option.state & QStyle::State_Selected) - painter->fillRect(option.rect, option.palette.color(cg, QPalette::Highlight)); + if (option.state & QStyle::State_Selected) + painter->fillRect(option.rect, option.palette.color(cg, QPalette::Highlight)); - bool checked = model->data(index, ::Qt::DisplayRole).toBool(); - int width = option.rect.width(); - int height = option.rect.height(); - size = (std::min)(width, height); - int x = option.rect.x() + (option.rect.width() / 2) - (size / 2);; - int y = option.rect.y() + (option.rect.height() / 2) - (size / 2); - if(checked) { - painter->drawPixmap(x, y, checkOnPixmap.scaled(QSize(size, size), - ::Qt::KeepAspectRatio, - ::Qt::SmoothTransformation)); + bool checked = model->data(index, ::Qt::DisplayRole).toBool(); + int width = option.rect.width(); + int height = option.rect.height(); + size = (std::min)(width, height); + int x = option.rect.x() + (option.rect.width() / 2) - (size / 2);; + int y = option.rect.y() + (option.rect.height() / 2) - (size / 2); + if(checked) { + painter->drawPixmap(x, y, checkOnPixmap.scaled(QSize(size, size), + ::Qt::KeepAspectRatio, + ::Qt::SmoothTransformation)); + } + else { + painter->drawPixmap(x, y, checkOffPixmap.scaled(QSize(size, size), + ::Qt::KeepAspectRatio, + ::Qt::SmoothTransformation)); + } + drawFocus(painter, option, option.rect); // since we draw the grid ourselves } - else { - painter->drawPixmap(x, y, checkOffPixmap.scaled(QSize(size, size), - ::Qt::KeepAspectRatio, - ::Qt::SmoothTransformation)); - } - drawFocus(painter, option, option.rect); // since we draw the grid ourselves - } } void Scene::setItemVisible(int index, bool b) { - if( index < 0 || index >= m_entries.size() ) - return; - m_entries[index]->setVisible(b); + if( index < 0 || index >= m_entries.size() ) + return; + m_entries[index]->setVisible(b); Q_EMIT dataChanged(this->createIndex(index, VisibleColumn), - this->createIndex(index, VisibleColumn)); + this->createIndex(index, VisibleColumn)); } void Scene::setSelectionRay(double orig_x, @@ -776,58 +745,58 @@ void Scene::setSelectionRay(double orig_x, double dir_y, double dir_z) { - Scene_item* item = this->item(selected_item); - if(item) item->select(orig_x, - orig_y, - orig_z, - dir_x, - dir_y, - dir_z); + Scene_item* item = this->item(selected_item); + if(item) item->select(orig_x, + orig_y, + orig_z, + dir_x, + dir_y, + dir_z); } void Scene::setItemA(int i) { - item_A = i; - if(item_A == item_B) - { - item_B = -1; - } + item_A = i; + if(item_A == item_B) + { + item_B = -1; + } Q_EMIT dataChanged(this->createIndex(0, ABColumn), - this->createIndex(m_entries.size()-1, ABColumn)); + this->createIndex(m_entries.size()-1, ABColumn)); } void Scene::setItemB(int i) { - item_B = i; - if(item_A == item_B) - { - item_A = -1; - } + item_B = i; + if(item_A == item_B) + { + item_A = -1; + } Q_EMIT updated(); Q_EMIT dataChanged(this->createIndex(0, ABColumn), - this->createIndex(m_entries.size()-1, ABColumn)); + this->createIndex(m_entries.size()-1, ABColumn)); } Scene::Bbox Scene::bbox() const { - if(m_entries.empty()) - return Bbox(); + if(m_entries.empty()) + return Bbox(); - bool bbox_initialized = false; - Bbox bbox; - Q_FOREACH(Scene_item* item, m_entries) - { - if(item->isFinite() && !item->isEmpty()) { - if(bbox_initialized) { - bbox = bbox + item->bbox(); - } - else { - bbox = item->bbox(); - bbox_initialized = true; - } + bool bbox_initialized = false; + Bbox bbox; + Q_FOREACH(Scene_item* item, m_entries) + { + if(item->isFinite() && !item->isEmpty()) { + if(bbox_initialized) { + bbox = bbox + item->bbox(); + } + else { + bbox = item->bbox(); + bbox_initialized = true; + } + } } - } - return bbox; + return bbox; } #include "Scene_find_items.h" @@ -839,13 +808,13 @@ Scene_item* findItem(const Scene_interface* scene_interface, const QMetaObject& metaobj, QString name, Scene_item_name_fn_ptr fn) { - const Scene* scene = dynamic_cast(scene_interface); - if(!scene) return 0; - Q_FOREACH(Scene_item* item, scene->entries()) { - Scene_item* ptr = qobject_cast(metaobj.cast(item)); - if(ptr && ((ptr->*fn)() == name)) return ptr; - } - return 0; + const Scene* scene = dynamic_cast(scene_interface); + if(!scene) return 0; + Q_FOREACH(Scene_item* item, scene->entries()) { + Scene_item* ptr = qobject_cast(metaobj.cast(item)); + if(ptr && ((ptr->*fn)() == name)) return ptr; + } + return 0; } Q_DECL_EXPORT @@ -854,20 +823,20 @@ findItems(const Scene_interface* scene_interface, const QMetaObject&, QString name, Scene_item_name_fn_ptr fn) { - const Scene* scene = dynamic_cast(scene_interface); - QList list; - if(!scene) return list; + const Scene* scene = dynamic_cast(scene_interface); + QList list; + if(!scene) return list; - Q_FOREACH(Scene_item* item, scene->entries()) { - Scene_item* ptr = qobject_cast(item); - if(ptr && ((ptr->*fn)() == name)) { - list << ptr; + Q_FOREACH(Scene_item* item, scene->entries()) { + Scene_item* ptr = qobject_cast(item); + if(ptr && ((ptr->*fn)() == name)) { + list << ptr; + } } - } - return list; + return list; } } // end namespace details -} // end namespace scene + } // end namespace scene #include "Scene.moc" diff --git a/Polyhedron/demo/Polyhedron/Scene.h b/Polyhedron/demo/Polyhedron/Scene.h index ba570323e69..b3d87a56813 100644 --- a/Polyhedron/demo/Polyhedron/Scene.h +++ b/Polyhedron/demo/Polyhedron/Scene.h @@ -21,7 +21,6 @@ class QEvent; class QMouseEvent; -namespace GlSplat { class SplatRenderer; } class Viewer_interface; @@ -149,12 +148,6 @@ private: QList selected_items_list; int item_A; int item_B; -#ifdef CGAL_GLEW_ENABLED - static GlSplat::SplatRenderer* ms_splatting; - static int ms_splattingCounter; -public: - static GlSplat::SplatRenderer* splatting(); -#endif }; // end class Scene class SCENE_EXPORT SceneDelegate : public QItemDelegate diff --git a/Polyhedron/demo/Polyhedron/Scene_c2t3_item.h b/Polyhedron/demo/Polyhedron/Scene_c2t3_item.h index ff6b79af22d..3e355c2819e 100644 --- a/Polyhedron/demo/Polyhedron/Scene_c2t3_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_c2t3_item.h @@ -2,10 +2,9 @@ #define SCENE_C2T3_ITEM_H #include "Scene_c2t3_item_config.h" -#include "Scene_item_with_display_list.h" #include "C2t3_type.h" #include - +#include "Scene_item.h" #include #include #include @@ -74,7 +73,7 @@ public: // Indicate if rendering mode is supported bool supportsRenderingMode(RenderingMode m) const { - return (m != Gouraud && m!=PointsPlusNormals && m!=Splatting); // CHECK THIS! + return (m != Gouraud && m!=PointsPlusNormals); // CHECK THIS! } void draw() const { @@ -104,7 +103,6 @@ private: const Tr::Point& pc) { Tr::Geom_traits::Vector_3 n = cross_product(pb - pa, pc -pa); n = n / CGAL::sqrt(n*n); - ::glNormal3d(n.x(),n.y(),n.z()); ::glVertex3d(pa.x(),pa.y(),pa.z()); diff --git a/Polyhedron/demo/Polyhedron/Scene_combinatorial_map_item.cpp b/Polyhedron/demo/Polyhedron/Scene_combinatorial_map_item.cpp index e2031ea694c..4926419b188 100644 --- a/Polyhedron/demo/Polyhedron/Scene_combinatorial_map_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_combinatorial_map_item.cpp @@ -6,8 +6,101 @@ #include #include #include - #include +#include #include +void Scene_combinatorial_map_item::initialize_buffers() +{ + qFunc.glBindVertexArray(vao); + buffer[0] = QOpenGLBuffer(QOpenGLBuffer::VertexBuffer); + if(!(buffer[0].create())) + std::cout<<"ERROR lors de la creation"<(positions.size()*sizeof(float))); + /* + qFunc.glVertexAttribPointer(0, //number of the buffer + 4, //number of floats to be taken + GL_FLOAT, // type of data + GL_FALSE, //not normalized + 0, //compact data (not in a struct) + NULL //no offset (seperated in several buffers) + ); + qFunc.glEnableVertexAttribArray(0);*/ + + // Clean-up + qFunc.glBindVertexArray(0); + +} + +void Scene_combinatorial_map_item::compile_shaders(void) +{ + + //fill the vertex shader + static const char* vertex_shader_source = + { + "#version 300 es \n" + " \n" + "layout (location = 0) in vec3 positions; \n" + + "out highp vec3 fColors; \n" + " \n" + + "void main(void) \n" + "{ \n" + " fColors = vec3(1.0,0.0,0.0); \n" + " gl_Position = mvp_matrix * vec4(positions, 1.0); \n" + "} \n" + }; + //fill the fragment shader + static const char* fragment_shader_source = + { + "#version 300 es \n" + " \n" + "in highp vec3 fColors; \n" + + "out highp vec4 color; \n" + " \n" + "void main(void) \n" + "{ \n" + " color = vec4(fColors, 1.0); \n" + "} \n" + }; + + QOpenGLShader *vertex_shader = new QOpenGLShader(QOpenGLShader::Vertex); + if(!vertex_shader->compileSourceCode(vertex_shader_source)) + std::cout<log().toStdString()<compileSourceCode(fragment_shader_source)) + std::cout<log().toStdString()<addShader(vertex_shader)) + std::cout<log().toStdString()<addShader(fragment_shader)) + std::cout<log().toStdString()<link(); + +} + +void Scene_combinatorial_map_item::compute_normals_and_vertices(void) +{ + positions.push_back(-1.0); + positions.push_back(-1.0); + positions.push_back(0.0); + + positions.push_back(0.0); + positions.push_back(1.0); + positions.push_back(0.0); + + positions.push_back(1.0); + positions.push_back(-1.0); + positions.push_back(0.0); + +} + Scene_combinatorial_map_item::Scene_combinatorial_map_item(Scene_interface* scene,void* address):last_known_scene(scene),volume_to_display(0),exportSelectedVolume(NULL),address_of_A(address){m_combinatorial_map=NULL;} Scene_combinatorial_map_item::~Scene_combinatorial_map_item(){if (m_combinatorial_map!=NULL) delete m_combinatorial_map;} @@ -16,384 +109,384 @@ Scene_combinatorial_map_item* Scene_combinatorial_map_item::clone() const{return Kernel::Vector_3 Scene_combinatorial_map_item::compute_face_normal(Combinatorial_map_3::Dart_const_handle adart) const { - typedef Combinatorial_map_3::Dart_of_orbit_const_range<1> Dart_in_facet_range; - typedef Kernel::Vector_3 Vector_3; - Vector_3 normal = CGAL::NULL_VECTOR; - - Dart_in_facet_range vertices=combinatorial_map().darts_of_orbit<1>(adart); - Kernel::Point_3 points[3]; - int index=0; - Dart_in_facet_range::const_iterator pit=vertices.begin(); - for (;pit!=vertices.end() && index!=3;++pit,++index ){ - points[index]=pit->attribute<0>()->point(); - } - - if (index!=3) return normal; - - do{ - Vector_3 n = CGAL::cross_product(points[2]-points[1],points[0]-points[1]); - if (n != Vector_3(0,0,0) ) - normal = normal + (n / std::sqrt(n*n)); - points[0]=points[1]; - points[1]=points[2]; - if ( pit==vertices.end() ) break; - - points[2]=pit->attribute<0>()->point(); - ++pit; - }while(true); - - return normal == Vector_3(0,0,0)? normal : normal / std::sqrt(normal * normal); + typedef Combinatorial_map_3::Dart_of_orbit_const_range<1> Dart_in_facet_range; + typedef Kernel::Vector_3 Vector_3; + Vector_3 normal = CGAL::NULL_VECTOR; + + Dart_in_facet_range vertices=combinatorial_map().darts_of_orbit<1>(adart); + Kernel::Point_3 points[3]; + int index=0; + Dart_in_facet_range::const_iterator pit=vertices.begin(); + for (;pit!=vertices.end() && index!=3;++pit,++index ){ + points[index]=pit->attribute<0>()->point(); + } + + if (index!=3) return normal; + + do{ + Vector_3 n = CGAL::cross_product(points[2]-points[1],points[0]-points[1]); + if (n != Vector_3(0,0,0) ) + normal = normal + (n / std::sqrt(n*n)); + points[0]=points[1]; + points[1]=points[2]; + if ( pit==vertices.end() ) break; + + points[2]=pit->attribute<0>()->point(); + ++pit; + }while(true); + + return normal == Vector_3(0,0,0)? normal : normal / std::sqrt(normal * normal); } void Scene_combinatorial_map_item::set_next_volume(){ - ++volume_to_display; - volume_to_display=volume_to_display%(combinatorial_map().attributes<3>().size()+1); + ++volume_to_display; + volume_to_display=volume_to_display%(combinatorial_map().attributes<3>().size()+1); Q_EMIT itemChanged(); - if (exportSelectedVolume!=NULL && ( volume_to_display==1 || volume_to_display==0 ) ) - exportSelectedVolume->setEnabled(!exportSelectedVolume->isEnabled()); + if (exportSelectedVolume!=NULL && ( volume_to_display==1 || volume_to_display==0 ) ) + exportSelectedVolume->setEnabled(!exportSelectedVolume->isEnabled()); } template void Scene_combinatorial_map_item::export_as_polyhedron(Predicate pred,const QString& name) const { - typedef Combinatorial_map_3::Dart_const_handle Dart_handle; - typedef Combinatorial_map_3::One_dart_per_cell_const_range<3> One_dart_per_vol_range; - typedef CGAL::internal::Import_volume_as_polyhedron Volume_import_modifier; - - std::vector darts; - One_dart_per_vol_range cell_range=combinatorial_map().template one_dart_per_cell<3>(); + typedef Combinatorial_map_3::Dart_const_handle Dart_handle; + typedef Combinatorial_map_3::One_dart_per_cell_const_range<3> One_dart_per_vol_range; + typedef CGAL::internal::Import_volume_as_polyhedron Volume_import_modifier; - - for (One_dart_per_vol_range::const_iterator it = cell_range.begin();it!= cell_range.end() ; ++it ) - if ( pred(it) ){ - darts.push_back(it); - if (Predicate::only_one_run) break; + std::vector darts; + One_dart_per_vol_range cell_range=combinatorial_map().template one_dart_per_cell<3>(); + + + for (One_dart_per_vol_range::const_iterator it = cell_range.begin();it!= cell_range.end() ; ++it ) + if ( pred(it) ){ + darts.push_back(it); + if (Predicate::only_one_run) break; + } + + if (!darts.empty()) + { + Volume_import_modifier modifier=Predicate::swap_orientation? + Volume_import_modifier(combinatorial_map(),darts.begin(),darts.end(),Predicate::swap_orientation): + Volume_import_modifier(combinatorial_map(),darts.begin(),darts.end()); + + Polyhedron* new_poly=new Polyhedron(); + new_poly->delegate(modifier); + Scene_polyhedron_item* new_item = new Scene_polyhedron_item(new_poly); + new_item->setName(name); + last_known_scene->addItem(new_item); } - - if (!darts.empty()) - { - Volume_import_modifier modifier=Predicate::swap_orientation? - Volume_import_modifier(combinatorial_map(),darts.begin(),darts.end(),Predicate::swap_orientation): - Volume_import_modifier(combinatorial_map(),darts.begin(),darts.end()); - - Polyhedron* new_poly=new Polyhedron(); - new_poly->delegate(modifier); - Scene_polyhedron_item* new_item = new Scene_polyhedron_item(new_poly); - new_item->setName(name); - last_known_scene->addItem(new_item); - } } struct Select_volume{ - static const bool only_one_run=true; - static const bool swap_orientation=false; - Select_volume(std::size_t i):volume_to_select(i),index(0){} - template - bool operator() (Dart_handle){ - return ++index==volume_to_select; - } + static const bool only_one_run=true; + static const bool swap_orientation=false; + Select_volume(std::size_t i):volume_to_select(i),index(0){} + template + bool operator() (Dart_handle){ + return ++index==volume_to_select; + } private: - std::size_t volume_to_select; - std::size_t index; + std::size_t volume_to_select; + std::size_t index; }; void Scene_combinatorial_map_item::export_current_volume_as_polyhedron() const { - if (volume_to_display==0) return; //no volume selected - - Select_volume predicate(volume_to_display); - export_as_polyhedron(predicate,QString("%1_%2").arg(this->name()).arg(volume_to_display-1)); + if (volume_to_display==0) return; //no volume selected + + Select_volume predicate(volume_to_display); + export_as_polyhedron(predicate,QString("%1_%2").arg(this->name()).arg(volume_to_display-1)); } struct Select_union{ - static const bool only_one_run=false; - static const bool swap_orientation=true; - template - bool operator() (Dart_handle d){ return d->template attribute<3>()->info().outside.size()==2; } + static const bool only_one_run=false; + static const bool swap_orientation=true; + template + bool operator() (Dart_handle d){ return d->template attribute<3>()->info().outside.size()==2; } }; struct Select_inter{ - static const bool only_one_run=false; - static const bool swap_orientation=false; - template - bool operator() (Dart_handle d){ return d->template attribute<3>()->info().inside.size()==2; } + static const bool only_one_run=false; + static const bool swap_orientation=false; + template + bool operator() (Dart_handle d){ return d->template attribute<3>()->info().inside.size()==2; } }; struct Select_A_minus_B{ - static const bool only_one_run=false; - static const bool swap_orientation=false; - Select_A_minus_B(void* address):address_of_A(address){} - template - bool operator() (Dart_handle d){ - return d->template attribute<3>()->info().inside.size()==1 && - static_cast(*d->template attribute<3>()->info().inside.begin())==address_of_A; - } + static const bool only_one_run=false; + static const bool swap_orientation=false; + Select_A_minus_B(void* address):address_of_A(address){} + template + bool operator() (Dart_handle d){ + return d->template attribute<3>()->info().inside.size()==1 && + static_cast(*d->template attribute<3>()->info().inside.begin())==address_of_A; + } private: - void* address_of_A; + void* address_of_A; }; struct Select_B_minus_A{ - static const bool only_one_run=false; - static const bool swap_orientation=false; - Select_B_minus_A(void* address):address_of_A(address){} - template - bool operator() (Dart_handle d){ - return d->template attribute<3>()->info().inside.size()==1 && - static_cast(*d->template attribute<3>()->info().inside.begin())!=address_of_A; - } + static const bool only_one_run=false; + static const bool swap_orientation=false; + Select_B_minus_A(void* address):address_of_A(address){} + template + bool operator() (Dart_handle d){ + return d->template attribute<3>()->info().inside.size()==1 && + static_cast(*d->template attribute<3>()->info().inside.begin())!=address_of_A; + } private: - void* address_of_A; + void* address_of_A; }; void Scene_combinatorial_map_item::export_union_as_polyhedron() const { - export_as_polyhedron(Select_union(),QString("%1_union_%2").arg("A").arg("B")); + export_as_polyhedron(Select_union(),QString("%1_union_%2").arg("A").arg("B")); } void Scene_combinatorial_map_item::export_intersection_as_polyhedron() const{ - export_as_polyhedron(Select_inter(),QString("%1_inter_%2").arg("A").arg("B")); + export_as_polyhedron(Select_inter(),QString("%1_inter_%2").arg("A").arg("B")); } void Scene_combinatorial_map_item::export_A_minus_B_as_polyhedron() const{ - Select_A_minus_B predicate(address_of_A); - export_as_polyhedron(predicate,QString("%1_minus_%2").arg("A").arg("B")); + Select_A_minus_B predicate(address_of_A); + export_as_polyhedron(predicate,QString("%1_minus_%2").arg("A").arg("B")); } void Scene_combinatorial_map_item::export_B_minus_A_as_polyhedron() const{ - Select_B_minus_A predicate(address_of_A); - export_as_polyhedron(predicate,QString("%1_minus_%2").arg("B").arg("A")); + Select_B_minus_A predicate(address_of_A); + export_as_polyhedron(predicate,QString("%1_minus_%2").arg("B").arg("A")); } QMenu* Scene_combinatorial_map_item::contextMenu() { - const char* prop_name = "Menu modified by Scene_combinatorial_map_item."; + const char* prop_name = "Menu modified by Scene_combinatorial_map_item."; - QMenu* menu = Scene_item::contextMenu(); + QMenu* menu = Scene_item::contextMenu(); - // Use dynamic properties: - // http://doc.trolltech.com/lastest/qobject.html#property - bool menuChanged = menu->property(prop_name).toBool(); + // Use dynamic properties: + // http://doc.qt.io/qt-5/qobject.html#property + bool menuChanged = menu->property(prop_name).toBool(); - if(!menuChanged) { - QAction* actionSelectNextVolume = - menu->addAction(tr("Iterate over volumes")); - actionSelectNextVolume->setObjectName("actionSelectNextVolume"); - connect(actionSelectNextVolume, SIGNAL(triggered()),this, SLOT(set_next_volume())); + if(!menuChanged) { + QAction* actionSelectNextVolume = + menu->addAction(tr("Iterate over volumes")); + actionSelectNextVolume->setObjectName("actionSelectNextVolume"); + connect(actionSelectNextVolume, SIGNAL(triggered()),this, SLOT(set_next_volume())); - exportSelectedVolume = - menu->addAction(tr("Export current volume as polyhedron")); - exportSelectedVolume->setObjectName("exportSelectedVolume"); - connect(exportSelectedVolume, SIGNAL(triggered()),this, SLOT(export_current_volume_as_polyhedron())); - exportSelectedVolume->setEnabled(volume_to_display!=0); - menu->setProperty(prop_name, true); - - if(is_from_corefinement()){ - //Export union as polyhedron - QAction* exportUnion = - menu->addAction(tr("Export union as polyhedron")); - exportUnion->setObjectName("exportUnion"); - connect(exportUnion, SIGNAL(triggered()),this, SLOT(export_union_as_polyhedron())); + exportSelectedVolume = + menu->addAction(tr("Export current volume as polyhedron")); + exportSelectedVolume->setObjectName("exportSelectedVolume"); + connect(exportSelectedVolume, SIGNAL(triggered()),this, SLOT(export_current_volume_as_polyhedron())); + exportSelectedVolume->setEnabled(volume_to_display!=0); + menu->setProperty(prop_name, true); - //Export intersection as polyhedron - QAction* exportIntersection = - menu->addAction(tr("Export intersection as polyhedron")); - exportIntersection->setObjectName("exportIntersection"); - connect(exportIntersection, SIGNAL(triggered()),this, SLOT(export_intersection_as_polyhedron())); + if(is_from_corefinement()){ + //Export union as polyhedron + QAction* exportUnion = + menu->addAction(tr("Export union as polyhedron")); + exportUnion->setObjectName("exportUnion"); + connect(exportUnion, SIGNAL(triggered()),this, SLOT(export_union_as_polyhedron())); - //Export A minus B as polyhedron - QAction* exportAMinusB = - menu->addAction(tr("Export A minus B as polyhedron")); - exportAMinusB->setObjectName("exportAMinusB"); - connect(exportAMinusB, SIGNAL(triggered()),this, SLOT(export_A_minus_B_as_polyhedron())); + //Export intersection as polyhedron + QAction* exportIntersection = + menu->addAction(tr("Export intersection as polyhedron")); + exportIntersection->setObjectName("exportIntersection"); + connect(exportIntersection, SIGNAL(triggered()),this, SLOT(export_intersection_as_polyhedron())); - //Export B minus A as polyhedron - QAction* exportBMinusA = - menu->addAction(tr("Export B minus A as polyhedron")); - exportBMinusA->setObjectName("exportBMinusA"); - connect(exportBMinusA, SIGNAL(triggered()),this, SLOT(export_B_minus_A_as_polyhedron())); - + //Export A minus B as polyhedron + QAction* exportAMinusB = + menu->addAction(tr("Export A minus B as polyhedron")); + exportAMinusB->setObjectName("exportAMinusB"); + connect(exportAMinusB, SIGNAL(triggered()),this, SLOT(export_A_minus_B_as_polyhedron())); + + //Export B minus A as polyhedron + QAction* exportBMinusA = + menu->addAction(tr("Export B minus A as polyhedron")); + exportBMinusA->setObjectName("exportBMinusA"); + connect(exportBMinusA, SIGNAL(triggered()),this, SLOT(export_B_minus_A_as_polyhedron())); + + } } - } - return menu; + return menu; } bool Scene_combinatorial_map_item::keyPressEvent(QKeyEvent* e){ - if (e->key()==Qt::Key_N){ - set_next_volume(); - return true; - } - return false; + if (e->key()==Qt::Key_N){ + set_next_volume(); + return true; + } + return false; } void Scene_combinatorial_map_item::direct_draw() const { - #if 0 - typedef Combinatorial_map_3::One_dart_per_cell_const_range<3> Volume_dart_range; - typedef Combinatorial_map_3::One_dart_per_incident_cell_const_range<2,3> Facet_in_volume_drange; - typedef Combinatorial_map_3::Dart_of_orbit_const_range<1> Dart_in_facet_range; - Volume_dart_range dart_per_volume_range = combinatorial_map().one_dart_per_cell<3>(); - - std::size_t index = 0; - for (Volume_dart_range::const_iterator vit=dart_per_volume_range.begin();vit!=dart_per_volume_range.end();++vit) - { - if (++index!=volume_to_display && volume_to_display!=0) continue; - Facet_in_volume_drange facet_range=combinatorial_map().one_dart_per_incident_cell<2,3>(vit); - - for(Facet_in_volume_drange::const_iterator fit=facet_range.begin();fit!=facet_range.end();++fit){ - Dart_in_facet_range vertices=combinatorial_map().darts_of_orbit<1>(fit); - Kernel::Vector_3 normal = compute_face_normal(fit); - - ::glBegin(GL_POLYGON); - ::glNormal3d(normal.x(),normal.y(),normal.z()); - - for (Dart_in_facet_range::const_iterator pit=vertices.begin();pit!=vertices.end();++pit ){ - const Kernel::Point_3& p= pit->attribute<0>()->point(); - ::glVertex3d(p.x(),p.y(),p.z()); - } - ::glEnd(); - } - } - #else - std::size_t index = 0; - int voltreated = combinatorial_map().get_new_mark(); - int facetreated = combinatorial_map().get_new_mark(); - Combinatorial_map_3::Dart_const_range::const_iterator - darts_it=combinatorial_map().darts().begin(), darts_end=combinatorial_map().darts().end(); - for( ; darts_it!=darts_end; ++darts_it) - { - if ( !combinatorial_map().is_marked(darts_it,voltreated) ) +#if 0 + typedef Combinatorial_map_3::One_dart_per_cell_const_range<3> Volume_dart_range; + typedef Combinatorial_map_3::One_dart_per_incident_cell_const_range<2,3> Facet_in_volume_drange; + typedef Combinatorial_map_3::Dart_of_orbit_const_range<1> Dart_in_facet_range; + Volume_dart_range dart_per_volume_range = combinatorial_map().one_dart_per_cell<3>(); + std::cout<<"COUCOU"<::const_iterator - vol_it=combinatorial_map().darts_of_cell<3>(darts_it).begin(), - vol_end=combinatorial_map().darts_of_cell<3>(darts_it).end(); - if ( volume_to_display!=0 && index!=volume_to_display ) - { - //only mark darts if the volume is not the one to display - for ( ;vol_it!=vol_end; ++vol_it ) - { - combinatorial_map().mark(vol_it,facetreated); - combinatorial_map().mark(vol_it, voltreated); - } - } - else - { - for ( ;vol_it!=vol_end; ++vol_it ) - { - if ( !combinatorial_map().is_marked(vol_it,facetreated) ) - { - Kernel::Vector_3 normal = compute_face_normal(vol_it); + if (++index!=volume_to_display && volume_to_display!=0) continue; + Facet_in_volume_drange facet_range=combinatorial_map().one_dart_per_incident_cell<2,3>(vit); + + for(Facet_in_volume_drange::const_iterator fit=facet_range.begin();fit!=facet_range.end();++fit){ + Dart_in_facet_range vertices=combinatorial_map().darts_of_orbit<1>(fit); + Kernel::Vector_3 normal = compute_face_normal(fit); + ::glBegin(GL_POLYGON); ::glNormal3d(normal.x(),normal.y(),normal.z()); - //iterate over all darts of facets - for ( Combinatorial_map_3::Dart_of_orbit_const_range<1>::const_iterator - face_it=combinatorial_map().darts_of_orbit<1>(vol_it).begin(), - face_end=combinatorial_map().darts_of_orbit<1>(vol_it).end(); - face_it!=face_end; ++face_it) - { - const Kernel::Point_3& p= face_it->attribute<0>()->point(); - ::glVertex3d(p.x(),p.y(),p.z()); - combinatorial_map().mark(face_it,facetreated); - combinatorial_map().mark(face_it, voltreated); + for (Dart_in_facet_range::const_iterator pit=vertices.begin();pit!=vertices.end();++pit ){ + const Kernel::Point_3& p= pit->attribute<0>()->point(); + ::glVertex3d(p.x(),p.y(),p.z()); } ::glEnd(); - } } - } - if ( index==volume_to_display ) break; } - } - //mark remaining darts to have an O(1) free_mark - for( ; darts_it!=darts_end; ++darts_it) - { - combinatorial_map().mark(darts_it, facetreated); - combinatorial_map().mark(darts_it, voltreated); - } +#else + std::size_t index = 0; + int voltreated = combinatorial_map().get_new_mark(); + int facetreated = combinatorial_map().get_new_mark(); + Combinatorial_map_3::Dart_const_range::const_iterator + darts_it=combinatorial_map().darts().begin(), darts_end=combinatorial_map().darts().end(); + for( ; darts_it!=darts_end; ++darts_it) + { + if ( !combinatorial_map().is_marked(darts_it,voltreated) ) + { + ++index; + //iterate over all the darts of the volume + Combinatorial_map_3::Dart_of_cell_const_range<3>::const_iterator + vol_it=combinatorial_map().darts_of_cell<3>(darts_it).begin(), + vol_end=combinatorial_map().darts_of_cell<3>(darts_it).end(); + if ( volume_to_display!=0 && index!=volume_to_display ) + { + //only mark darts if the volume is not the one to display + for ( ;vol_it!=vol_end; ++vol_it ) + { + combinatorial_map().mark(vol_it,facetreated); + combinatorial_map().mark(vol_it, voltreated); + } + } + else + { + for ( ;vol_it!=vol_end; ++vol_it ) + { + if ( !combinatorial_map().is_marked(vol_it,facetreated) ) + { + Kernel::Vector_3 normal = compute_face_normal(vol_it); + ::glBegin(GL_POLYGON); + ::glNormal3d(normal.x(),normal.y(),normal.z()); - combinatorial_map().free_mark(facetreated); - combinatorial_map().free_mark(voltreated); - #endif + //iterate over all darts of facets + for ( Combinatorial_map_3::Dart_of_orbit_const_range<1>::const_iterator + face_it=combinatorial_map().darts_of_orbit<1>(vol_it).begin(), + face_end=combinatorial_map().darts_of_orbit<1>(vol_it).end(); + face_it!=face_end; ++face_it) + { + const Kernel::Point_3& p= face_it->attribute<0>()->point(); + ::glVertex3d(p.x(),p.y(),p.z()); + combinatorial_map().mark(face_it,facetreated); + combinatorial_map().mark(face_it, voltreated); + } + ::glEnd(); + } + } + } + if ( index==volume_to_display ) break; + } + } + //mark remaining darts to have an O(1) free_mark + for( ; darts_it!=darts_end; ++darts_it) + { + combinatorial_map().mark(darts_it, facetreated); + combinatorial_map().mark(darts_it, voltreated); + } + + combinatorial_map().free_mark(facetreated); + combinatorial_map().free_mark(voltreated); +#endif } void Scene_combinatorial_map_item::direct_draw_edges() const { - typedef Combinatorial_map_3::One_dart_per_cell_const_range<1> Edge_darts; - Edge_darts darts=combinatorial_map().one_dart_per_cell<1>(); - ::glBegin(GL_LINES); - for (Edge_darts::const_iterator dit=darts.begin();dit!=darts.end();++dit){ - CGAL_assertion(!dit->is_free(1)); - const Kernel::Point_3& a = dit->attribute<0>()->point(); - const Kernel::Point_3& b = dit->beta(1)->attribute<0>()->point(); - ::glVertex3d(a.x(),a.y(),a.z()); - ::glVertex3d(b.x(),b.y(),b.z()); - } - ::glEnd(); + typedef Combinatorial_map_3::One_dart_per_cell_const_range<1> Edge_darts; + Edge_darts darts=combinatorial_map().one_dart_per_cell<1>(); + ::glBegin(GL_LINES); + for (Edge_darts::const_iterator dit=darts.begin();dit!=darts.end();++dit){ + CGAL_assertion(!dit->is_free(1)); + const Kernel::Point_3& a = dit->attribute<0>()->point(); + const Kernel::Point_3& b = dit->beta(1)->attribute<0>()->point(); + ::glVertex3d(a.x(),a.y(),a.z()); + ::glVertex3d(b.x(),b.y(),b.z()); + } + ::glEnd(); } void Scene_combinatorial_map_item::draw_points() const{ - typedef Combinatorial_map_3::Attribute_const_range<0>::type Point_range; - const Point_range& points=combinatorial_map().attributes<0>(); - ::glBegin(GL_POINTS); - for(Point_range::const_iterator pit=boost::next(points.begin());pit!=points.end();++pit){ - const Kernel::Point_3& p=pit->point(); - ::glVertex3d(p.x(),p.y(),p.z()); - } - ::glEnd(); + typedef Combinatorial_map_3::Attribute_const_range<0>::type Point_range; + const Point_range& points=combinatorial_map().attributes<0>(); + ::glBegin(GL_POINTS); + for(Point_range::const_iterator pit=boost::next(points.begin());pit!=points.end();++pit){ + const Kernel::Point_3& p=pit->point(); + ::glVertex3d(p.x(),p.y(),p.z()); + } + ::glEnd(); } bool Scene_combinatorial_map_item::isEmpty() const {return combinatorial_map().number_of_darts()==0;} Scene_combinatorial_map_item::Bbox Scene_combinatorial_map_item::bbox() const { - typedef Combinatorial_map_3::Attribute_const_range<0>::type Point_range; - const Point_range& points=combinatorial_map().attributes<0>(); - CGAL::Bbox_3 bbox=points.begin()->point().bbox(); - for(Point_range::const_iterator pit=boost::next(points.begin());pit!=points.end();++pit) - bbox=bbox+pit->point().bbox(); - return Bbox(bbox.xmin(),bbox.ymin(),bbox.zmin(), - bbox.xmax(),bbox.ymax(),bbox.zmax()); + typedef Combinatorial_map_3::Attribute_const_range<0>::type Point_range; + const Point_range& points=combinatorial_map().attributes<0>(); + CGAL::Bbox_3 bbox=points.begin()->point().bbox(); + for(Point_range::const_iterator pit=boost::next(points.begin());pit!=points.end();++pit) + bbox=bbox+pit->point().bbox(); + return Bbox(bbox.xmin(),bbox.ymin(),bbox.zmin(), + bbox.xmax(),bbox.ymax(),bbox.zmax()); } QString Scene_combinatorial_map_item::toolTip() const{ - if(!m_combinatorial_map) - return QString(); + if(!m_combinatorial_map) + return QString(); - std::vector cells(5); - for (unsigned int i=0; i<=4; ++i) - cells[i]=i; - std::vector res = combinatorial_map().count_cells(cells); - if (volume_to_display==0) + std::vector cells(5); + for (unsigned int i=0; i<=4; ++i) + cells[i]=i; + std::vector res = combinatorial_map().count_cells(cells); + if (volume_to_display==0) + return QObject::tr("

Combinatorial_map_3 %1 (mode: %8, color: %9)

" + "

Number of darts: %2
" + "Number of vertices: %3
" + "Number of edges: %4
" + "Number of facets: %5
" + "Number of volumes: %6
" + "Number of connected components: %7

") + .arg(this->name()) + .arg(combinatorial_map().number_of_darts()) + .arg(res[0]) + .arg(res[1]) + .arg(res[2]) + .arg(res[3]) + .arg(res[4]) + .arg(this->renderingModeName()) + .arg(this->color().name()); return QObject::tr("

Combinatorial_map_3 %1 (mode: %8, color: %9)

" "

Number of darts: %2
" "Number of vertices: %3
" "Number of edges: %4
" "Number of facets: %5
" "Number of volumes: %6
" - "Number of connected components: %7

") - .arg(this->name()) - .arg(combinatorial_map().number_of_darts()) - .arg(res[0]) - .arg(res[1]) - .arg(res[2]) - .arg(res[3]) - .arg(res[4]) - .arg(this->renderingModeName()) - .arg(this->color().name()); - return QObject::tr("

Combinatorial_map_3 %1 (mode: %8, color: %9)

" - "

Number of darts: %2
" - "Number of vertices: %3
" - "Number of edges: %4
" - "Number of facets: %5
" - "Number of volumes: %6
" - "Number of connected components: %7
" - "Currently Displaying facets of volume: %10

") - .arg(this->name()) - .arg(combinatorial_map().number_of_darts()) - .arg(res[0]) - .arg(res[1]) - .arg(res[2]) - .arg(res[3]) - .arg(res[4]) - .arg(this->renderingModeName()) - .arg(this->color().name()) - .arg(volume_to_display-1); + "Number of connected components: %7
" + "Currently Displaying facets of volume: %10

") + .arg(this->name()) + .arg(combinatorial_map().number_of_darts()) + .arg(res[0]) + .arg(res[1]) + .arg(res[2]) + .arg(res[3]) + .arg(res[4]) + .arg(this->renderingModeName()) + .arg(this->color().name()) + .arg(volume_to_display-1); } diff --git a/Polyhedron/demo/Polyhedron/Scene_combinatorial_map_item.h b/Polyhedron/demo/Polyhedron/Scene_combinatorial_map_item.h index 241526bb76b..c6dbe60d799 100644 --- a/Polyhedron/demo/Polyhedron/Scene_combinatorial_map_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_combinatorial_map_item.h @@ -4,11 +4,12 @@ //========= #include #include "Scene_combinatorial_map_item_config.h" -#include "Scene_item_with_display_list.h" #include - +#include +#include +#include #include "Polyhedron_type.h" - +#include "Scene_item.h" typedef CGAL::internal_IOP::Item_with_points_and_volume_info Items; typedef CGAL::Combinatorial_map<3,Items> Combinatorial_map_3; //========= @@ -19,64 +20,79 @@ class Scene_interface; class Scene_polyhedron_item; class SCENE_COMBINATORIAL_MAP_ITEM_EXPORT Scene_combinatorial_map_item - : public Scene_item_with_display_list + : public Scene_item { - Q_OBJECT + Q_OBJECT public: - Scene_combinatorial_map_item(Scene_interface*,void* ad_A=NULL); - ~Scene_combinatorial_map_item(); + Scene_combinatorial_map_item(Scene_interface*,void* ad_A=NULL); + ~Scene_combinatorial_map_item(); - Scene_combinatorial_map_item* clone() const; - // Function to override the context menu - QMenu* contextMenu(); + Scene_combinatorial_map_item* clone() const; + // Function to override the context menu + QMenu* contextMenu(); -// bool load(std::istream& in); -// void load(Scene_polyhedron_item*); -// bool save(std::ostream& out) const; + // bool load(std::istream& in); + // void load(Scene_polyhedron_item*); + // bool save(std::ostream& out) const; - QString toolTip() const; + QString toolTip() const; - // Indicate if rendering mode is supported - virtual bool supportsRenderingMode(RenderingMode m) const { return (m != Gouraud && m!=PointsPlusNormals && m!=Splatting); } // CHECK THIS! - //Event handling - virtual bool keyPressEvent(QKeyEvent*); - // OpenGL drawing in a display list - void direct_draw() const; - void direct_draw_edges() const; - void draw_points() const; + // Indicate if rendering mode is supported + virtual bool supportsRenderingMode(RenderingMode m) const { return (m != Gouraud && m!=PointsPlusNormals); } // CHECK THIS! + //Event handling + virtual bool keyPressEvent(QKeyEvent*); + // OpenGL drawing in a display list + void direct_draw() const; + void direct_draw_edges() const; + void draw_points() const; - bool isFinite() const { return true; } - bool is_from_corefinement() const {return address_of_A!=NULL;} - bool isEmpty() const; - Bbox bbox() const; - - const Combinatorial_map_3& combinatorial_map() const - { - return *m_combinatorial_map; - } + bool isFinite() const { return true; } + bool is_from_corefinement() const {return address_of_A!=NULL;} + bool isEmpty() const; + Bbox bbox() const; + + const Combinatorial_map_3& combinatorial_map() const + { + return *m_combinatorial_map; + } + + Combinatorial_map_3& combinatorial_map() + { + return *m_combinatorial_map; + } + + Combinatorial_map_3* m_combinatorial_map; - Combinatorial_map_3& combinatorial_map() - { - return *m_combinatorial_map; - } - - Combinatorial_map_3* m_combinatorial_map; - private: - Kernel::Vector_3 compute_face_normal(Combinatorial_map_3::Dart_const_handle adart) const; - Scene_interface* last_known_scene; - std::size_t volume_to_display; - QAction* exportSelectedVolume; - void* address_of_A; - template void export_as_polyhedron(Predicate,const QString&) const; + Kernel::Vector_3 compute_face_normal(Combinatorial_map_3::Dart_const_handle adart) const; + Scene_interface* last_known_scene; + std::size_t volume_to_display; + QAction* exportSelectedVolume; + void* address_of_A; + template void export_as_polyhedron(Predicate,const QString&) const; + + std::vector positions; + std::vector normals; + std::vector color_lines; + std::vector color_facets; + + QOpenGLShaderProgram *rendering_program; + GLint location[9]; + + GLuint vao; + QOpenGLBuffer buffer[5]; + void initialize_buffers(); + void compile_shaders(void); + void compute_normals_and_vertices(void); public Q_SLOTS: - void set_next_volume(); - void export_current_volume_as_polyhedron() const; - void export_union_as_polyhedron() const; - void export_intersection_as_polyhedron() const; - void export_A_minus_B_as_polyhedron() const; - void export_B_minus_A_as_polyhedron() const; + void set_next_volume(); + void export_current_volume_as_polyhedron() const; + void export_union_as_polyhedron() const; + void export_intersection_as_polyhedron() const; + void export_A_minus_B_as_polyhedron() const; + void export_B_minus_A_as_polyhedron() const; + }; // end class Scene_combinatorial_map_item #endif // SCENE_COMBINATORIAL_MAP_ITEM_H diff --git a/Polyhedron/demo/Polyhedron/Scene_edit_polyhedron_item.cpp b/Polyhedron/demo/Polyhedron/Scene_edit_polyhedron_item.cpp index 1e21e6c9252..eeb7137985a 100644 --- a/Polyhedron/demo/Polyhedron/Scene_edit_polyhedron_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_edit_polyhedron_item.cpp @@ -5,12 +5,26 @@ #include +struct light_info +{ + //position + GLfloat position[4]; + //ambient + GLfloat ambient[4]; + + //diffuse + GLfloat diffuse[4]; + + //specular + GLfloat specular[4]; +}; Scene_edit_polyhedron_item::Scene_edit_polyhedron_item (Scene_polyhedron_item* poly_item, Ui::DeformMesh* ui_widget, QMainWindow* mw) - : ui_widget(ui_widget), + :Scene_item(20,8), + ui_widget(ui_widget), poly_item(poly_item), deform_mesh(*(poly_item->polyhedron()), Deform_mesh::Vertex_index_map(), Deform_mesh::Hedge_index_map(), Array_based_vertex_point_map(&positions)), is_rot_free(true), @@ -57,7 +71,6 @@ Scene_edit_polyhedron_item::Scene_edit_polyhedron_item normals[counter*3+1] = n.y(); normals[counter*3+2] = n.z(); } - tris.resize(polyhedron()->size_of_facets()*3); counter = 0; for(Polyhedron::Facet_handle fb = polyhedron()->facets_begin(); fb != polyhedron()->facets_end(); ++fb, ++counter) { @@ -72,6 +85,44 @@ Scene_edit_polyhedron_item::Scene_edit_polyhedron_item edges[counter*2] = static_cast(eb->vertex()->id()); edges[counter*2+1] = static_cast(eb->opposite()->vertex()->id()); } + qFunc.initializeOpenGLFunctions(); + //Generates an integer which will be used as ID for each buffer + + const char vertex_shader_source_bbox[] = + { + + "attribute highp vec3 vertex; \n" + "attribute highp vec3 colors; \n" + + "uniform highp mat4 mvp_matrix; \n" + "uniform highp mat4 rotations; \n" + "uniform highp vec3 translation; \n" + "uniform highp vec3 translation_2; \n" + "varying highp vec3 fColors; \n" + " \n" + + "void main(void) \n" + "{ \n" + " fColors = colors; \n" + " gl_Position = mvp_matrix * (rotations *(vec4(translation_2,0.0)+vec4(vertex,1.0) )+ vec4(translation,0.0)) ; \n" + "} \n" + }; + const char fragment_shader_source[]= + { + "varying vec3 fColors; \n" + " \n" + "void main(void) \n" + "{ \n" + " gl_FragColor = vec4(fColors, 1.0); \n" + "} \n" + }; + bbox_program.addShaderFromSourceCode(QOpenGLShader::Vertex,vertex_shader_source_bbox); + bbox_program.addShaderFromSourceCode(QOpenGLShader::Fragment,fragment_shader_source); + bbox_program.link(); + + //the spheres : + create_Sphere(length_of_axis/15.0); + changed(); } Scene_edit_polyhedron_item::~Scene_edit_polyhedron_item() @@ -82,6 +133,324 @@ Scene_edit_polyhedron_item::~Scene_edit_polyhedron_item() } gluDeleteQuadric(quadric); if (own_poly_item) delete poly_item; + +} +///////////////////////////// +/// For the Shader gestion/// +void Scene_edit_polyhedron_item::initialize_buffers(Viewer_interface *viewer =0) const +{ + //vao for the facets + { + program = getShaderProgram(PROGRAM_WITH_LIGHT, viewer); + program->bind(); + + vaos[0]->bind(); + buffers[0].bind(); + buffers[0].allocate(positions.data(), + static_cast(positions.size()*sizeof(double))); + program->enableAttributeArray("vertex"); + program->setAttributeBuffer("vertex",GL_DOUBLE,0,3); + buffers[0].release(); + + buffers[1].bind(); + buffers[1].allocate(normals.data(), + static_cast(normals.size()*sizeof(double))); + program->enableAttributeArray("normals"); + program->setAttributeBuffer("normals",GL_DOUBLE,0,3); + buffers[1].release(); + vaos[0]->release(); + program->release(); + } + //vao for the ROI points + { program = getShaderProgram(PROGRAM_WITHOUT_LIGHT, viewer); + program->bind(); + vaos[1]->bind(); + buffers[2].bind(); + buffers[2].allocate(ROI_points.data(), + static_cast(ROI_points.size()*sizeof(double))); + program->enableAttributeArray("vertex"); + program->setAttributeBuffer("vertex",GL_DOUBLE,0,3); + buffers[2].release(); + + buffers[3].bind(); + buffers[3].allocate(ROI_color.data(), + static_cast(ROI_color.size()*sizeof(double))); + program->enableAttributeArray("colors"); + program->setAttributeBuffer("colors",GL_DOUBLE,0,3); + buffers[3].release(); + vaos[1]->release(); + program->release(); + } + + + //vao for the edges + { + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT, viewer); + program->bind(); + vaos[2]->bind(); + buffers[4].bind(); + buffers[4].allocate(positions.data(), + static_cast(positions.size()*sizeof(double))); + program->enableAttributeArray("vertex"); + program->setAttributeBuffer("vertex",GL_DOUBLE,0,3); + buffers[4].release(); + + buffers[5].bind(); + buffers[5].allocate(color_edges.data(), + static_cast(color_edges.size()*sizeof(double))); + program->enableAttributeArray("colors"); + program->setAttributeBuffer("colors",GL_DOUBLE,0,3); + buffers[5].release(); + vaos[2]->release(); + program->release(); + } + //vao for the ROI spheres + { + program = getShaderProgram(PROGRAM_INSTANCED, viewer); + program->bind(); + vaos[3]->bind(); + buffers[6].bind(); + buffers[6].allocate(pos_sphere.data(), + static_cast(pos_sphere.size()*sizeof(double))); + program->enableAttributeArray("vertex"); + program->setAttributeBuffer("vertex",GL_DOUBLE,0,3); + buffers[6].release(); + + buffers[7].bind(); + buffers[7].allocate(normals_sphere.data(), + static_cast(normals_sphere.size()*sizeof(double))); + program->enableAttributeArray("normals"); + program->setAttributeBuffer("normals",GL_DOUBLE,0,3); + buffers[7].release(); + + buffers[8].bind(); + buffers[8].allocate(color_sphere_ROI.data(), + static_cast(color_sphere_ROI.size()*sizeof(double))); + program->enableAttributeArray("colors"); + program->setAttributeBuffer("colors",GL_DOUBLE,0,3); + buffers[8].release(); + + buffers[9].bind(); + buffers[9].allocate(centers_ROI.data(), + static_cast(centers_ROI.size()*sizeof(double))); + program->enableAttributeArray("center"); + program->setAttributeBuffer("center",GL_DOUBLE,0,3); + buffers[9].release(); + + qFunc.glVertexAttribDivisor(program->attributeLocation("center"), 1); + qFunc.glVertexAttribDivisor(program->attributeLocation("colors"), 1); + vaos[3]->release(); + } + //vao for the BBOX + { + bbox_program.bind(); + vaos[4]->bind(); + buffers[10].bind(); + buffers[10].allocate(pos_bbox.data(), + static_cast(pos_bbox.size()*sizeof(double))); + bbox_program.enableAttributeArray("vertex"); + bbox_program.setAttributeBuffer("vertex",GL_DOUBLE,0,3); + buffers[10].release(); + + buffers[11].bind(); + buffers[11].allocate(color_bbox.data(), + static_cast(color_bbox.size()*sizeof(double))); + bbox_program.enableAttributeArray("colors"); + bbox_program.setAttributeBuffer("colors",GL_DOUBLE,0,3); + buffers[11].release(); + vaos[4]->release(); + bbox_program.release(); + } + //vao for the control points + { + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT, viewer); + program->bind(); + vaos[5]->bind(); + buffers[12].bind(); + buffers[12].allocate(control_points.data(), + static_cast(control_points.size()*sizeof(double))); + program->enableAttributeArray("vertex"); + program->setAttributeBuffer("vertex",GL_DOUBLE,0,3); + buffers[12].release(); + + buffers[13].bind(); + buffers[13].allocate(control_color.data(), + static_cast(control_color.size()*sizeof(double))); + program->enableAttributeArray("colors"); + program->setAttributeBuffer("colors",GL_DOUBLE,0,3); + buffers[13].release(); + vaos[5]->release(); + program->release(); + } + //vao for the control spheres + { + program = getShaderProgram(PROGRAM_INSTANCED, viewer); + program->bind(); + vaos[6]->bind(); + buffers[14].bind(); + buffers[14].allocate(pos_sphere.data(), + static_cast(pos_sphere.size()*sizeof(double))); + program->enableAttributeArray("vertex"); + program->setAttributeBuffer("vertex",GL_DOUBLE,0,3); + buffers[14].release(); + + buffers[15].bind(); + buffers[15].allocate(normals_sphere.data(), + static_cast(normals_sphere.size()*sizeof(double))); + program->enableAttributeArray("normals"); + program->setAttributeBuffer("normals",GL_DOUBLE,0,3); + buffers[15].release(); + + buffers[16].bind(); + buffers[16].allocate(color_sphere_control.data(), + static_cast(color_sphere_control.size()*sizeof(double))); + program->enableAttributeArray("colors"); + program->setAttributeBuffer("colors",GL_DOUBLE,0,3); + buffers[16].release(); + + buffers[17].bind(); + buffers[17].allocate(centers_control.data(), + static_cast(centers_control.size()*sizeof(double))); + program->enableAttributeArray("center"); + program->setAttributeBuffer("center",GL_DOUBLE,0,3); + buffers[17].release(); + + qFunc.glVertexAttribDivisor(program->attributeLocation("center"), 1); + qFunc.glVertexAttribDivisor(program->attributeLocation("colors"), 1); + vaos[6]->release(); + } + //vao for the axis + { + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT, viewer); + program->bind(); + vaos[7]->bind(); + buffers[18].bind(); + buffers[18].allocate(pos_axis.data(), + static_cast(pos_axis.size()*sizeof(double))); + program->enableAttributeArray("vertex"); + program->setAttributeBuffer("vertex",GL_DOUBLE,0,3); + buffers[18].release(); + + buffers[19].bind(); + buffers[19].allocate(color_lines.data(), + static_cast(color_lines.size()*sizeof(double))); + program->enableAttributeArray("colors"); + program->setAttributeBuffer("colors",GL_DOUBLE,0,3); + buffers[19].release(); + vaos[7]->release(); + program->release(); + } + are_buffers_filled = true; +} + +void Scene_edit_polyhedron_item::compute_normals_and_vertices(void) +{ + ROI_points.resize(0); + control_points.resize(0); + BOOST_FOREACH(vertex_descriptor vd, deform_mesh.roi_vertices()) + { + if(!deform_mesh.is_control_vertex(vd)) + {//gl_draw_point( vd->point() ); + ROI_points.push_back(vd->point().x()); + ROI_points.push_back(vd->point().y()); + ROI_points.push_back(vd->point().z()); + } + } + centers_ROI.resize(ROI_points.size()); + ROI_color.resize(ROI_points.size()); + color_sphere_ROI.resize(ROI_points.size()); + for(int i=0; i<(int)centers_ROI.size(); i++) + { + centers_ROI[i] = ROI_points[i]; + } + for(int i=0; i<(int)ROI_color.size(); i++) + { + if(i%3==1) + { + ROI_color[i]=1.0; + color_sphere_ROI[i]=1.0; + + } + else + { + ROI_color[i]=0.0; + color_sphere_ROI[i]=0.0; + } + } + QGLViewer* viewer = *QGLViewer::QGLViewerPool().begin(); + for(Ctrl_vertices_group_data_list::const_iterator hgb_data = ctrl_vertex_frame_map.begin(); hgb_data != ctrl_vertex_frame_map.end(); ++hgb_data) + { + if(hgb_data->frame == viewer->manipulatedFrame()) + { + // draw axis + + if(ui_widget->ActivatePivotingCheckBox->isChecked()) + { + // draw bbox + compute_bbox(hgb_data->bbox); + } + } + // draw control vertices + if(hgb_data == active_group) + { + //set color to red + control_color.push_back(1.0); + control_color.push_back(0.0); + control_color.push_back(0.0); + } + else + { + //set color to blue + control_color.push_back(0.0); + control_color.push_back(0.0); + control_color.push_back(1.0); + } + for(std::vector::const_iterator hb = hgb_data->ctrl_vertices_group.begin(); hb != hgb_data->ctrl_vertices_group.end(); ++hb) + { + control_points.push_back((*hb)->point().x()); + control_points.push_back((*hb)->point().y()); + control_points.push_back((*hb)->point().z()); + + } + centers_control.resize(control_points.size()); + for(int i=0; i<(int)centers_control.size(); i++) + { + centers_control[i]=control_points[i]; + } + } + color_sphere_control.resize(control_color.size()); + for(int i=0; i<(int)color_sphere_control.size(); i++) + { + color_sphere_control[i] = control_color[i]; + } + + //The edges color + color_edges.resize(edges.size()); + for(int i =0; i< (int)edges.size(); i++) + color_edges[i]=0.0; + + //The box color + color_bbox.resize(pos_bbox.size()); + for(int i =0; i< (int)pos_bbox.size(); i++) + color_bbox[i]=0.0; + + for(int i =0; i< (int)pos_bbox.size(); i+=3) + color_bbox[i]=1.0; + + //The axis + + pos_axis.resize(18); + for(int i =0; i< 18; i++) + pos_axis[i]=0.0; + pos_axis[3] = length_of_axis; pos_axis[10] = length_of_axis; pos_axis[17] = length_of_axis; + color_lines.resize(18); + for(int i =0; i< 18; i++) + color_lines[i]=0.0; + + color_lines[2] = 1.0; color_lines[5] = 1.0; + color_lines[6] = 1.0; color_lines[9] = 1.0; + color_lines[13] = 1.0; color_lines[16] = 1.0; + } ///////////////////////////////////////////////////////// @@ -155,149 +524,197 @@ bool Scene_edit_polyhedron_item::eventFilter(QObject* /*target*/, QEvent *event) } #include "opengl_tools.h" -void Scene_edit_polyhedron_item::draw_edges() const { - - glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(3, GL_DOUBLE, 0, positions.data()); - glDrawElements(GL_LINES, (GLsizei) edges.size(), GL_UNSIGNED_INT, edges.data()); - glDisableClientState(GL_VERTEX_ARRAY); +void Scene_edit_polyhedron_item::draw_edges(Viewer_interface* viewer) const { + if(!are_buffers_filled) + initialize_buffers(viewer); + vaos[2]->bind(); + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT); + attrib_buffers(viewer,PROGRAM_WITHOUT_LIGHT); + program->bind(); + qFunc.glDrawElements(GL_LINES, (GLsizei) edges.size(), GL_UNSIGNED_INT, edges.data()); + program->release(); + vaos[2]->release(); if(rendering_mode == Wireframe) { - draw_ROI_and_control_vertices(); + draw_ROI_and_control_vertices(viewer); } } -void Scene_edit_polyhedron_item::draw() const { - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_NORMAL_ARRAY); +void Scene_edit_polyhedron_item::draw(Viewer_interface* viewer) const { + if(!are_buffers_filled) + initialize_buffers(viewer); + vaos[0]->bind(); + program = getShaderProgram(PROGRAM_WITH_LIGHT); + attrib_buffers(viewer,PROGRAM_WITH_LIGHT); + program->bind(); + QColor color = this->color(); + program->setAttributeValue("colors", color); + qFunc.glDrawElements(GL_TRIANGLES, (GLsizei) tris.size(), GL_UNSIGNED_INT, tris.data()); + program->release(); + vaos[0]->release(); + draw_edges(viewer); + draw_ROI_and_control_vertices(viewer); - glVertexPointer(3, GL_DOUBLE, 0, positions.data()); - glNormalPointer(GL_DOUBLE, 0, normals.data()); - glDrawElements(GL_TRIANGLES, (GLsizei) tris.size(), GL_UNSIGNED_INT, tris.data()); - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_NORMAL_ARRAY); - - CGAL::GL::Color color; - color.set_rgb_color(0, 0, 0); - draw_edges(); - - draw_ROI_and_control_vertices(); } -void Scene_edit_polyhedron_item::draw_ROI_and_control_vertices() const { - GLboolean enable_back_lighting = glIsEnabled(GL_LIGHTING); - glDisable(GL_LIGHTING); +void Scene_edit_polyhedron_item::draw_ROI_and_control_vertices(Viewer_interface* viewer) const { CGAL::GL::Color color; CGAL::GL::Point_size point_size; point_size.set_point_size(5); + color.set_rgb_color(0, 1.f, 0); - // draw ROI if(ui_widget->ShowROICheckBox->isChecked()) { - BOOST_FOREACH(vertex_descriptor vd, deform_mesh.roi_vertices()) - { - if(!deform_mesh.is_control_vertex(vd)) - gl_draw_point( vd->point() ); + + if(!ui_widget->ShowAsSphereCheckBox->isChecked()) { + + vaos[1]->bind(); + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT); + attrib_buffers(viewer,PROGRAM_WITHOUT_LIGHT); + program->bind(); + qFunc.glDrawArrays(GL_POINTS, 0, static_cast(ROI_points.size()/3)); + program->release(); + vaos[1]->release(); + } + else{ + vaos[3]->bind(); + program = getShaderProgram(PROGRAM_INSTANCED); + attrib_buffers(viewer,PROGRAM_INSTANCED); + program->bind(); + qFunc.glDrawArraysInstanced(GL_TRIANGLES, 0, + static_cast(pos_sphere.size()/3), + static_cast(ROI_points.size()/3)); + program->release(); + vaos[3]->release(); } } - // draw control vertices related things - QGLViewer* viewer = *QGLViewer::QGLViewerPool().begin(); + if(!ui_widget->ShowAsSphereCheckBox->isChecked()) { + vaos[5]->bind(); + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT); + attrib_buffers(viewer,PROGRAM_WITHOUT_LIGHT); + program->bind(); + qFunc.glDrawArrays(GL_POINTS, 0, static_cast(control_points.size()/3)); + program->release(); + vaos[5]->release(); + } + else{ + vaos[6]->bind(); + program = getShaderProgram(PROGRAM_INSTANCED); + attrib_buffers(viewer,PROGRAM_INSTANCED); + program->bind(); + qFunc.glDrawArraysInstanced(GL_TRIANGLES, 0, + static_cast(pos_sphere.size()/3), + static_cast(control_points.size()/3)); + program->release(); + vaos[6]->release(); + } + + QGLViewer* viewerB = *QGLViewer::QGLViewerPool().begin(); for(Ctrl_vertices_group_data_list::const_iterator hgb_data = ctrl_vertex_frame_map.begin(); hgb_data != ctrl_vertex_frame_map.end(); ++hgb_data) { - if(hgb_data->frame == viewer->manipulatedFrame()) + if(hgb_data->frame == viewerB->manipulatedFrame()) { - // draw axis - ::glPushMatrix(); - ::glMultMatrixd(hgb_data->frame->matrix()); - QGLViewer::drawAxis(length_of_axis); - ::glPopMatrix(); + GLfloat f_matrix[16]; + for(int i =0; i<16; i++) + f_matrix[i] = hgb_data->frame->matrix()[i]; + QMatrix4x4 f_mat; + for(int i=0; i<16; i++) + f_mat.data()[i] = (float)f_matrix[i]; + vaos[7]->bind(); + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT); + attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT); + program->bind(); + program->setUniformValue("f_matrix", f_mat); + qFunc.glDrawArrays(GL_LINES, 0, static_cast(pos_axis.size()/3)); + program->release(); + vaos[7]->release(); + + //QGLViewer::drawAxis(length_of_axis); // draw bbox if(!ui_widget->ActivatePivotingCheckBox->isChecked()) { - color.set_rgb_color(1.0f, 0, 0); - ::glPushMatrix(); - ::glTranslated(hgb_data->frame->position().x, hgb_data->frame->position().y, hgb_data->frame->position().z); - ::glMultMatrixd(hgb_data->frame->orientation().matrix()); - ::glTranslated(-hgb_data->frame_initial_center.x, -hgb_data->frame_initial_center.y, -hgb_data->frame_initial_center.z); - draw_bbox(hgb_data->bbox); - ::glPopMatrix(); - } + GLfloat f_matrix[16]; + GLfloat trans[3]; + GLfloat trans2[3]; + + trans[0] = hgb_data->frame->position().x; + trans[1] = hgb_data->frame->position().y; + trans[2] = hgb_data->frame->position().z; + + trans2[0] = -hgb_data->frame_initial_center.x; + trans2[1] = -hgb_data->frame_initial_center.y; + trans2[2] = -hgb_data->frame_initial_center.z; + + for(int i =0; i<16; i++) + f_matrix[i] = hgb_data->frame->orientation().matrix()[i]; + QMatrix4x4 f_mat; + QMatrix4x4 mvp_mat; + + QVector3D vec(trans[0], trans[1], trans[2]); + QVector3D vec2(trans2[0], trans2[1], trans2[2]); + for(int i=0; i<16; i++) + f_mat.data()[i] = (float)f_matrix[i]; + GLdouble temp_mat[16]; + viewer->camera()->getModelViewProjectionMatrix(temp_mat); + for(int i=0; i<16; i++) + mvp_mat.data()[i] = (float)temp_mat[i]; + vaos[4]->bind(); + bbox_program.bind(); + bbox_program.setUniformValue("rotations", f_mat); + bbox_program.setUniformValue("translation", vec); + bbox_program.setUniformValue("translation_2", vec2); + bbox_program.setUniformValue("mvp_matrix", mvp_mat); + qFunc.glDrawArrays(GL_LINES, 0, static_cast(pos_bbox.size()/3)); + bbox_program.release(); + vaos[4]->release(); } - // draw control vertices - if(hgb_data == active_group) { color.set_rgb_color(1.0f, 0, 0); } - else { color.set_rgb_color(0, 0, 1.0f); } - for(std::vector::const_iterator hb = hgb_data->ctrl_vertices_group.begin(); hb != hgb_data->ctrl_vertices_group.end(); ++hb) - { gl_draw_point( (*hb)->point() ); } } - if(enable_back_lighting) { glEnable(GL_LIGHTING); } -} -void Scene_edit_polyhedron_item::gl_draw_point(const Point& p) const -{ - if(!ui_widget->ShowAsSphereCheckBox->isChecked()) { - ::glBegin(GL_POINTS); - ::glVertex3d(p.x(), p.y(), p.z()); - ::glEnd(); } - else { - GLint shading; - ::glGetIntegerv(GL_SHADE_MODEL, &shading); - ::glShadeModel(GL_SMOOTH); - ::glPushMatrix(); - ::glTranslated(p.x(), p.y(), p.z()); - ::gluSphere(quadric, length_of_axis/15, 8, 8); - ::glPopMatrix(); - ::glShadeModel(shading); - } -} -////////////////////////////////////////////////////////// +void Scene_edit_polyhedron_item::compute_bbox(const Scene_interface::Bbox& bb){ + pos_bbox.resize(24*3); -/////////////// from trivial_plugin ////////////////////// -void Scene_edit_polyhedron_item::draw_bbox(const Scene_interface::Bbox& bb ) const { - ::glBegin(GL_LINES); - gl_draw_edge(bb.xmin, bb.ymin, bb.zmin, - bb.xmax, bb.ymin, bb.zmin); - gl_draw_edge(bb.xmin, bb.ymin, bb.zmin, - bb.xmin, bb.ymax, bb.zmin); - gl_draw_edge(bb.xmin, bb.ymin, bb.zmin, - bb.xmin, bb.ymin, bb.zmax); + pos_bbox[0]=bb.xmin; pos_bbox[1]=bb.ymin; pos_bbox[2]=bb.zmin; + pos_bbox[3]=bb.xmax; pos_bbox[4]=bb.ymin; pos_bbox[5]=bb.zmin; + pos_bbox[6]=bb.xmin; pos_bbox[7]=bb.ymin; pos_bbox[8]=bb.zmin; + pos_bbox[9]=bb.xmin; pos_bbox[10]=bb.ymax; pos_bbox[11]=bb.zmin; - gl_draw_edge(bb.xmax, bb.ymin, bb.zmin, - bb.xmax, bb.ymax, bb.zmin); - gl_draw_edge(bb.xmax, bb.ymin, bb.zmin, - bb.xmax, bb.ymin, bb.zmax); + pos_bbox[12]=bb.xmin; pos_bbox[13]=bb.ymin; pos_bbox[14]=bb.zmin; + pos_bbox[15]=bb.xmin; pos_bbox[16]=bb.ymin; pos_bbox[17]=bb.zmax; + pos_bbox[18]= bb.xmax; pos_bbox[19]=bb.ymin; pos_bbox[20]=bb.zmin; + pos_bbox[21]= bb.xmax; pos_bbox[22]=bb.ymax; pos_bbox[23]=bb.zmin; - gl_draw_edge(bb.xmin, bb.ymax, bb.zmin, - bb.xmax, bb.ymax, bb.zmin); - gl_draw_edge(bb.xmin, bb.ymax, bb.zmin, - bb.xmin, bb.ymax, bb.zmax); + pos_bbox[24]= bb.xmax; pos_bbox[25]=bb.ymin; pos_bbox[26]=bb.zmin; + pos_bbox[27]= bb.xmax; pos_bbox[28]=bb.ymin; pos_bbox[29]=bb.zmax; + pos_bbox[30]=bb.xmin; pos_bbox[31]=bb.ymax; pos_bbox[32]=bb.zmin; + pos_bbox[33]=bb.xmax; pos_bbox[34]=bb.ymax; pos_bbox[35]=bb.zmin; - gl_draw_edge(bb.xmin, bb.ymin, bb.zmax, - bb.xmax, bb.ymin, bb.zmax); - gl_draw_edge(bb.xmin, bb.ymin, bb.zmax, - bb.xmin, bb.ymax, bb.zmax); + pos_bbox[36]=bb.xmin; pos_bbox[37]=bb.ymax; pos_bbox[38]=bb.zmin; + pos_bbox[39]=bb.xmin; pos_bbox[40]=bb.ymax; pos_bbox[41]=bb.zmax; + pos_bbox[42]=bb.xmin; pos_bbox[43]=bb.ymin; pos_bbox[44]=bb.zmax; + pos_bbox[45]=bb.xmax; pos_bbox[46]=bb.ymin; pos_bbox[47]=bb.zmax; + + pos_bbox[48]=bb.xmin; pos_bbox[49]=bb.ymin; pos_bbox[50]=bb.zmax; + pos_bbox[51]=bb.xmin; pos_bbox[52]=bb.ymax; pos_bbox[53]=bb.zmax; + pos_bbox[54]=bb.xmax; pos_bbox[55]=bb.ymax; pos_bbox[56]=bb.zmax; + pos_bbox[57]=bb.xmin; pos_bbox[58]=bb.ymax; pos_bbox[59]=bb.zmax; + + pos_bbox[60]=bb.xmax; pos_bbox[61]=bb.ymax; pos_bbox[62]=bb.zmax; + pos_bbox[63]=bb.xmax; pos_bbox[64]=bb.ymin; pos_bbox[65]=bb.zmax; + pos_bbox[66]=bb.xmax; pos_bbox[67]=bb.ymax; pos_bbox[68]=bb.zmax; + pos_bbox[69]=bb.xmax; pos_bbox[70]=bb.ymax; pos_bbox[71]=bb.zmin; - gl_draw_edge(bb.xmax, bb.ymax, bb.zmax, - bb.xmin, bb.ymax, bb.zmax); - gl_draw_edge(bb.xmax, bb.ymax, bb.zmax, - bb.xmax, bb.ymin, bb.zmax); - gl_draw_edge(bb.xmax, bb.ymax, bb.zmax, - bb.xmax, bb.ymax, bb.zmin); - ::glEnd(); } -void Scene_edit_polyhedron_item::gl_draw_edge(double px, double py, double pz, - double qx, double qy, double qz) const -{ - ::glVertex3d(px,py,pz); - ::glVertex3d(qx,qy,qz); -} -///////////////////////////////////////////////////////////// void Scene_edit_polyhedron_item::changed() -{ update_normals(); } +{ + compute_normals_and_vertices(); + update_normals(); + are_buffers_filled = false; +} Scene_polyhedron_item* Scene_edit_polyhedron_item::to_polyhedron_item() { Scene_polyhedron_item* poly_item_tmp = poly_item; @@ -389,7 +806,183 @@ bool Scene_edit_polyhedron_item::keyPressEvent(QKeyEvent* e) qglviewer::AxisPlaneConstraint::AXIS); return true; } + return false; } -#include "Scene_edit_polyhedron_item.moc" +void Scene_edit_polyhedron_item::create_Sphere(double R) +{ + + float T, P; + float x[4],y[4],z[4]; + int rings = 22, sectors = 45; + + + //Top of the sphere + for(int t=0; t<360; t+=sectors) + { + + pos_sphere.push_back(0); + pos_sphere.push_back(0); + pos_sphere.push_back(R); + + + normals_sphere.push_back(0); + normals_sphere.push_back(0); + normals_sphere.push_back(1); + + + + P = rings*M_PI/180.0; + T = t*M_PI/180.0; + x[1] = sin(P) * cos(T) ; + y[1] = sin(P) * sin(T) ; + z[1] = cos(P); + pos_sphere.push_back(R * x[1]); + pos_sphere.push_back(R * y[1]); + pos_sphere.push_back(R * z[1]); + + normals_sphere.push_back(x[1]); + normals_sphere.push_back(y[1]); + normals_sphere.push_back(z[1]); + + // + P = rings*M_PI/180.0; + T = (t+sectors)*M_PI/180.0; + x[2] = sin(P) * cos(T) ; + y[2] = sin(P) * sin(T) ; + z[2] = cos(P); + pos_sphere.push_back(R * x[2]); + pos_sphere.push_back(R * y[2]); + pos_sphere.push_back(R * z[2]); + + normals_sphere.push_back(x[2]); + normals_sphere.push_back(y[2]); + normals_sphere.push_back(z[2]); + + } + + //Body of the sphere + for (int p=rings; p<180-rings; p+=rings) + for(int t=0; t<360; t+=sectors) + { + //A + P = p*M_PI/180.0; + T = t*M_PI/180.0; + x[0] = sin(P) * cos(T) ; + y[0] = sin(P) * sin(T) ; + z[0] = cos(P); + + pos_sphere.push_back(R * x[0]); + pos_sphere.push_back(R * y[0]); + pos_sphere.push_back(R * z[0]); + + normals_sphere.push_back(x[0]); + normals_sphere.push_back(y[0]); + normals_sphere.push_back(z[0]); + + //B + P = (p+rings)*M_PI/180.0; + T = t*M_PI/180.0; + x[1] = sin(P) * cos(T) ; + y[1] = sin(P) * sin(T) ; + z[1] = cos(P); + pos_sphere.push_back(R * x[1]); + pos_sphere.push_back(R * y[1]); + pos_sphere.push_back(R * z[1]); + + normals_sphere.push_back(x[1]); + normals_sphere.push_back(y[1]); + normals_sphere.push_back(z[1]); + + //C + P = p*M_PI/180.0; + T = (t+sectors)*M_PI/180.0; + x[2] = sin(P) * cos(T) ; + y[2] = sin(P) * sin(T) ; + z[2] = cos(P); + pos_sphere.push_back(R * x[2]); + pos_sphere.push_back(R * y[2]); + pos_sphere.push_back(R * z[2]); + + normals_sphere.push_back(x[2]); + normals_sphere.push_back(y[2]); + normals_sphere.push_back(z[2]); + //D + P = (p+rings)*M_PI/180.0; + T = (t+sectors)*M_PI/180.0; + x[3] = sin(P) * cos(T) ; + y[3] = sin(P) * sin(T) ; + z[3] = cos(P); + pos_sphere.push_back(R * x[3]); + pos_sphere.push_back(R * y[3]); + pos_sphere.push_back(R * z[3]); + + normals_sphere.push_back(x[3]); + normals_sphere.push_back(y[3]); + normals_sphere.push_back(z[3]); + + + + pos_sphere.push_back(R * x[1]); + pos_sphere.push_back(R * y[1]); + pos_sphere.push_back(R * z[1]); + + normals_sphere.push_back(x[1]); + normals_sphere.push_back(y[1]); + normals_sphere.push_back(z[1]); + + pos_sphere.push_back(R * x[2]); + pos_sphere.push_back(R * y[2]); + pos_sphere.push_back(R * z[2]); + + normals_sphere.push_back(x[2]); + normals_sphere.push_back(y[2]); + normals_sphere.push_back(z[2]); + + } + //Bottom of the sphere + for(int t=0; t<360; t+=sectors) + { + + + pos_sphere.push_back(0); + pos_sphere.push_back(0); + pos_sphere.push_back(-R); + + normals_sphere.push_back(0); + normals_sphere.push_back(0); + normals_sphere.push_back(-1); + + + P = (180-rings)*M_PI/180.0; + T = t*M_PI/180.0; + x[1] = sin(P) * cos(T) ; + y[1] = sin(P) * sin(T) ; + z[1] = cos(P); + pos_sphere.push_back(R * x[1]); + pos_sphere.push_back(R * y[1]); + pos_sphere.push_back(R * z[1]); + + normals_sphere.push_back(x[1]); + normals_sphere.push_back(y[1]); + normals_sphere.push_back(z[1]); + + + P = (180-rings)*M_PI/180.0; + T = (t+sectors)*M_PI/180.0; + x[2] = sin(P) * cos(T) ; + y[2] = sin(P) * sin(T) ; + z[2] = cos(P); + pos_sphere.push_back(R * x[2]); + pos_sphere.push_back(R * y[2]); + pos_sphere.push_back(R * z[2]); + + normals_sphere.push_back(x[2]); + normals_sphere.push_back(y[2]); + normals_sphere.push_back(z[2]); + + } +} + +//#include "Scene_edit_polyhedron_item.moc" diff --git a/Polyhedron/demo/Polyhedron/Scene_edit_polyhedron_item.h b/Polyhedron/demo/Polyhedron/Scene_edit_polyhedron_item.h index 9a3624addf3..72a4d4af6d2 100644 --- a/Polyhedron/demo/Polyhedron/Scene_edit_polyhedron_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_edit_polyhedron_item.h @@ -21,6 +21,9 @@ #include "ui_Deform_mesh.h" #include #include +#include +#include +#include typedef Polyhedron::Vertex_handle Vertex_handle; @@ -41,12 +44,14 @@ public: }; +inline Array_based_vertex_point_map::value_type get(Array_based_vertex_point_map, Array_based_vertex_point_map::key_type key) { return key->point(); } +inline void put(Array_based_vertex_point_map pmap, Array_based_vertex_point_map::key_type key, @@ -195,12 +200,11 @@ public: return m == Gouraud; } // Points/Wireframe/Flat/Gouraud OpenGL drawing in a display list - void draw() const; - void draw_edges() const; - void draw_bbox(const Scene_interface::Bbox& bb ) const; - void gl_draw_edge(double px, double py, double pz, - double qx, double qy, double qz) const; - void gl_draw_point(const Point& p) const; + void draw() const{} + void draw(Viewer_interface*) const; + void draw_edges(Viewer_interface*) const; + void draw_bbox(const Scene_interface::Bbox&) const; + void draw_ROI_and_control_vertices(Viewer_interface *viewer) const; // Get wrapped polyhedron Polyhedron* polyhedron(); @@ -225,7 +229,7 @@ public: protected: void timerEvent(QTimerEvent *event); - void draw_ROI_and_control_vertices() const; + public Q_SLOTS: void changed(); @@ -262,10 +266,37 @@ private: Ui::DeformMesh* ui_widget; Scene_polyhedron_item* poly_item; // For drawing - std::vector positions; + std::vector positions; std::vector tris; std::vector edges; - std::vector normals; + std::vector color_lines; + std::vector color_bbox; + std::vector color_edges; + std::vector ROI_points; + std::vector control_points; + std::vector ROI_color; + std::vector control_color; + std::vector normals; + std::vector pos_bbox; + std::vector pos_axis; + std::vector pos_sphere; + std::vector normals_sphere; + std::vector centers_control; + std::vector centers_ROI; + std::vector color_sphere_ROI; + std::vector color_sphere_control; + mutable QOpenGLShaderProgram *program; + mutable QOpenGLShaderProgram bbox_program; + + mutable QOpenGLBuffer *in_bu; + using Scene_item::initialize_buffers; + void initialize_buffers(Viewer_interface *viewer) const; + void compute_normals_and_vertices(void); + void compute_bbox(const Scene_interface::Bbox&); + void create_Sphere(double); + + + Deform_mesh deform_mesh; typedef std::list Ctrl_vertices_group_data_list; @@ -662,6 +693,7 @@ protected: normals[id*3] = n.x(); normals[id*3+1] = n.y(); normals[id*3+2] = n.z(); + } } protected: diff --git a/Polyhedron/demo/Polyhedron/Scene_implicit_function_item.cpp b/Polyhedron/demo/Polyhedron/Scene_implicit_function_item.cpp index 83557e29feb..9469becb304 100644 --- a/Polyhedron/demo/Polyhedron/Scene_implicit_function_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_implicit_function_item.cpp @@ -3,228 +3,494 @@ #include #include #include - #include -#include #include "Color_ramp.h" #include #include + inline bool is_nan(double d) { - return !CGAL::Is_valid()( d ); + return !CGAL::Is_valid()( d ); +} + +void Scene_implicit_function_item::initialize_buffers(Viewer_interface *viewer = 0) const +{ + //vao fot the cutting plane + { + program = getShaderProgram(PROGRAM_WITH_TEXTURE, viewer); + program->bind(); + vaos[0]->bind(); + + + buffers[0].bind(); + buffers[0].allocate(positions_tex_quad.data(), + static_cast(positions_tex_quad.size()*sizeof(float))); + program->enableAttributeArray("vertex"); + program->setAttributeBuffer("vertex",GL_FLOAT,0,3); + buffers[0].release(); + + buffers[1].bind(); + buffers[1].allocate(texture_map.data(), + static_cast(texture_map.size()*sizeof(float))); + program->enableAttributeArray("v_texCoord"); + program->setAttributeBuffer("v_texCoord",GL_FLOAT,0,2); + buffers[1].release(); + program->setAttributeValue("normal", QVector3D(0,0,0)); + + program->release(); + vaos[0]->release(); + } + //vao fot the bbox + { + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT, viewer); + program->bind(); + vaos[1]->bind(); + + + buffers[2].bind(); + buffers[2].allocate(positions_cube.data(), + static_cast(positions_cube.size()*sizeof(float))); + program->enableAttributeArray("vertex"); + program->setAttributeBuffer("vertex",GL_FLOAT,0,3); + buffers[2].release(); + + program->setAttributeValue("colors", QVector3D(0,0,0)); + program->release(); + vaos[1]->release(); + } + //vao fot the grid + { + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT, viewer); + program->bind(); + vaos[2]->bind(); + + + buffers[3].bind(); + buffers[3].allocate(positions_grid.data(), + static_cast(positions_grid.size()*sizeof(float))); + program->enableAttributeArray("vertex"); + program->setAttributeBuffer("vertex",GL_FLOAT,0,3); + buffers[3].release(); + program->setAttributeValue("colors", QVector3D(0.6f, 0.6f, 0.6f)); + program->release(); + vaos[2]->release(); + } + + + + qFunc.glBindTexture(GL_TEXTURE_2D, textureId); + qFunc.glTexImage2D(GL_TEXTURE_2D, + 0, + GL_RGB, + texture->getWidth(), + texture->getHeight(), + 0, + GL_RGB, + GL_UNSIGNED_BYTE, + texture->getData()); + qFunc.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + qFunc.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + qFunc.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE ); + qFunc.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE ); + + are_buffers_filled = true; +} + +void Scene_implicit_function_item::compute_vertices_and_texmap(void) +{ + positions_tex_quad.resize(0); + positions_cube.resize(0); + positions_grid.resize(0); + texture_map.resize(0); + + const Bbox& b = bbox(); + float x,y,z; + z = 0; + x = (b.xmax-b.xmin)/10.0; + y = (b.ymax-b.ymin)/10.0; + // The Quad + { + + + //A + positions_tex_quad.push_back(b.xmin); + positions_tex_quad.push_back(b.ymin); + positions_tex_quad.push_back(z); + + + //B + positions_tex_quad.push_back(b.xmin); + positions_tex_quad.push_back(b.ymax); + positions_tex_quad.push_back(z); + + + //C + positions_tex_quad.push_back(b.xmax); + positions_tex_quad.push_back(b.ymax); + positions_tex_quad.push_back(z); + + + + //A + positions_tex_quad.push_back(b.xmin); + positions_tex_quad.push_back(b.ymin); + positions_tex_quad.push_back(z); + + + //C + positions_tex_quad.push_back(b.xmax); + positions_tex_quad.push_back(b.ymax); + positions_tex_quad.push_back(z); + + + //D + positions_tex_quad.push_back(b.xmax); + positions_tex_quad.push_back(b.ymin); + positions_tex_quad.push_back(z); + + + //UV Mapping x2 but I don't know why. + texture_map.push_back(0.0); + texture_map.push_back(0.0); + + texture_map.push_back(0.0); + texture_map.push_back(1.0); + + texture_map.push_back(1.0); + texture_map.push_back(1.0); + + texture_map.push_back(0.0); + texture_map.push_back(0.0); + + texture_map.push_back(1.0); + texture_map.push_back(1.0); + + texture_map.push_back(1.0); + texture_map.push_back(0.0); + + + + } + //The grid + { + + for(int u = 0; u < 11; u++) + { + + positions_grid.push_back(b.xmin + x* u); + positions_grid.push_back(b.ymin); + positions_grid.push_back(z); + + positions_grid.push_back(b.xmin + x* u); + positions_grid.push_back(b.ymax); + positions_grid.push_back(z); + } + for(int v=0; v<11; v++) + { + + positions_grid.push_back(b.xmin); + positions_grid.push_back(b.ymin + v * y); + positions_grid.push_back(z); + + positions_grid.push_back(b.xmax); + positions_grid.push_back(b.ymin + v * y); + positions_grid.push_back(z); + } + + } + //the Box + { + + positions_cube.push_back(b.xmin); + positions_cube.push_back(b.ymin); + positions_cube.push_back(b.zmin); + + positions_cube.push_back(b.xmin); + positions_cube.push_back(b.ymin); + positions_cube.push_back(b.zmax); + + + positions_cube.push_back(b.xmin); + positions_cube.push_back(b.ymin); + positions_cube.push_back(b.zmin); + + + positions_cube.push_back(b.xmin); + positions_cube.push_back(b.ymax); + positions_cube.push_back(b.zmin); + + + positions_cube.push_back(b.xmin); + positions_cube.push_back(b.ymin); + positions_cube.push_back(b.zmin); + + + positions_cube.push_back(b.xmax); + positions_cube.push_back(b.ymin); + positions_cube.push_back(b.zmin); + + + positions_cube.push_back(b.xmax); + positions_cube.push_back(b.ymin); + positions_cube.push_back(b.zmin); + + + positions_cube.push_back(b.xmax); + positions_cube.push_back(b.ymax); + positions_cube.push_back(b.zmin); + + + positions_cube.push_back(b.xmax); + positions_cube.push_back(b.ymin); + positions_cube.push_back(b.zmin); + + + positions_cube.push_back(b.xmax); + positions_cube.push_back(b.ymin); + positions_cube.push_back(b.zmax); + + + positions_cube.push_back(b.xmin); + positions_cube.push_back(b.ymax); + positions_cube.push_back(b.zmin); + + + positions_cube.push_back(b.xmin); + positions_cube.push_back(b.ymax); + positions_cube.push_back(b.zmax); + + + positions_cube.push_back(b.xmin); + positions_cube.push_back(b.ymax); + positions_cube.push_back(b.zmin); + + + positions_cube.push_back(b.xmax); + positions_cube.push_back(b.ymax); + positions_cube.push_back(b.zmin); + + + positions_cube.push_back(b.xmax); + positions_cube.push_back(b.ymax); + positions_cube.push_back(b.zmin); + + + positions_cube.push_back(b.xmax); + positions_cube.push_back(b.ymax); + positions_cube.push_back(b.zmax); + + + positions_cube.push_back(b.xmin); + positions_cube.push_back(b.ymin); + positions_cube.push_back(b.zmax); + + + positions_cube.push_back(b.xmin); + positions_cube.push_back(b.ymax); + positions_cube.push_back(b.zmax); + + + positions_cube.push_back(b.xmin); + positions_cube.push_back(b.ymin); + positions_cube.push_back(b.zmax); + + + positions_cube.push_back(b.xmax); + positions_cube.push_back(b.ymin); + positions_cube.push_back(b.zmax); + + + positions_cube.push_back(b.xmax); + positions_cube.push_back(b.ymax); + positions_cube.push_back(b.zmax); + + + positions_cube.push_back(b.xmin); + positions_cube.push_back(b.ymax); + positions_cube.push_back(b.zmax); + + + positions_cube.push_back(b.xmax); + positions_cube.push_back(b.ymax); + positions_cube.push_back(b.zmax); + + + positions_cube.push_back(b.xmax); + positions_cube.push_back(b.ymin); + positions_cube.push_back(b.zmax); + + } + + //The texture + for( int i=0 ; i < texture->getWidth() ; i++ ) + { + for( int j=0 ; j < texture->getHeight() ; j++) + { + compute_texture(i,j); + } + } } Scene_implicit_function_item:: Scene_implicit_function_item(Implicit_function_interface* f) - : function_(f) - , frame_(new ManipulatedFrame()) - , need_update_(true) - , grid_size_(SCENE_IMPLICIT_GRID_SIZE) - , max_value_(0.) - , min_value_(0.) - , blue_color_ramp_() - , red_color_ramp_() + :Scene_item(4,3) + , function_(f) + , frame_(new ManipulatedFrame()) + , need_update_(true) + , grid_size_(SCENE_IMPLICIT_GRID_SIZE) + , max_value_(0.) + , min_value_(0.) + , blue_color_ramp_() + , red_color_ramp_() + { - blue_color_ramp_.build_blue(); - red_color_ramp_.build_red(); - compute_min_max(); - compute_function_grid(); - double offset_x = (bbox().xmin + bbox().xmax) / 2; - double offset_y = (bbox().ymin + bbox().ymax) / 2; - double offset_z = (bbox().zmin + bbox().zmax) / 2; - frame_->setPosition(offset_x, offset_y, offset_z); - frame_->setOrientation(1., 0, 0, 0); - connect(frame_, SIGNAL(modified()), this, SLOT(plane_was_moved())); + texture = new Texture(grid_size_-1,grid_size_-1); + blue_color_ramp_.build_blue(); + red_color_ramp_.build_red(); + qFunc.initializeOpenGLFunctions(); + // + //Generates an integer which will be used as ID for each buffer + + qFunc.glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + qFunc.glGenTextures(1, &textureId); + compute_min_max(); + compute_function_grid(); + double offset_x = (bbox().xmin + bbox().xmax) / 2; + double offset_y = (bbox().ymin + bbox().ymax) / 2; + double offset_z = (bbox().zmin + bbox().zmax) / 2; + frame_->setPosition(offset_x, offset_y, offset_z); + frame_->setOrientation(1., 0, 0, 0); + connect(frame_, SIGNAL(modified()), this, SLOT(plane_was_moved())); + + changed(); } Scene_implicit_function_item::~Scene_implicit_function_item() { - delete frame_; + + delete frame_; + } Scene_implicit_function_item::Bbox Scene_implicit_function_item::bbox() const { - return function_->bbox(); + return function_->bbox(); } void Scene_implicit_function_item::draw(Viewer_interface* viewer) const { - draw_aux(viewer, false); + if(!are_buffers_filled) + initialize_buffers(viewer); + + if(frame_->isManipulated()) { + if(need_update_) { + compute_function_grid(); + need_update_ = false; + } + } + vaos[0]->bind(); + qFunc.glActiveTexture(GL_TEXTURE0); + qFunc.glBindTexture(GL_TEXTURE_2D, textureId); + attrib_buffers(viewer, PROGRAM_WITH_TEXTURE); + QMatrix4x4 f_mat; + GLdouble d_mat[16]; + frame_->getMatrix(d_mat); + //Convert the GLdoubles matrices in GLfloats + for (int i=0; i<16; ++i){ + f_mat.data()[i] = GLfloat(d_mat[i]); + } + program = getShaderProgram(PROGRAM_WITH_TEXTURE); + program->bind(); + program->setUniformValue("f_matrix", f_mat); + program->setUniformValue("light_amb", QVector4D(1.0,1.0,1.0,1.0)); + program->setUniformValue("light_diff", QVector4D(0,0,0,1)); + program->setAttributeValue("color_facets", QVector3D(1.0,1.0,1.0)); + qFunc.glDrawArrays(GL_TRIANGLES, 0, static_cast(positions_tex_quad.size()/3)); + vaos[0]->release(); + program->release(); } void Scene_implicit_function_item::draw_edges(Viewer_interface* viewer) const { - draw_aux(viewer, true); -} - -void -Scene_implicit_function_item::draw_aux(Viewer_interface* viewer, bool edges) const -{ - if(edges) { - draw_bbox(); - ::glPushMatrix(); - ::glMultMatrixd(frame_->matrix()); - QGLViewer::drawGrid((float)bbox().diagonal_length() * 0.3); - ::glPopMatrix(); - } - - if(!frame_->isManipulated()) { - if(need_update_) { - compute_function_grid(); - need_update_ = false; + if(!are_buffers_filled) + initialize_buffers(viewer); + // draw_aux(viewer, true); + vaos[1]->bind(); + attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT); + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT); + program->bind(); + qFunc.glDrawArrays(GL_LINES, 0, static_cast(positions_cube.size()/3)); + vaos[1]->release(); + vaos[2]->bind(); + QMatrix4x4 f_mat; + GLdouble d_mat[16]; + frame_->getMatrix(d_mat); + //Convert the GLdoubles matrices in GLfloats + for (int i=0; i<16; ++i){ + f_mat.data()[i] = GLfloat(d_mat[i]); } - if(!viewer->inFastDrawing()) { - if(edges) - Scene_item_with_display_list::draw_edges(viewer); - else - Scene_item_with_display_list::draw(viewer); - } - } + program->setUniformValue("f_matrix", f_mat); + qFunc.glDrawArrays(GL_LINES, 0, static_cast(positions_grid.size()/3)); + vaos[2]->release(); + program->release(); } -void -Scene_implicit_function_item::direct_draw() const -{ - draw_function_grid(red_color_ramp_, blue_color_ramp_); -} - - - QString Scene_implicit_function_item::toolTip() const { - return tr("

Function %1") - .arg(this->name()); + return tr("

Function %1") + .arg(this->name()); } bool Scene_implicit_function_item::supportsRenderingMode(RenderingMode m) const -{ - switch ( m ) - { - case Splatting: +{ + switch ( m ) + { case Gouraud: - return false; - + return false; + case Points: case Wireframe: case Flat: case FlatPlusEdges: - return true; - + return true; + default: - return false; - } - - return false; -} - -void -Scene_implicit_function_item:: -draw_bbox() const -{ - const Bbox& b = bbox(); - - ::glDisable(GL_LIGHTING); - ::glColor3f(0.f,0.f,0.f); - ::glBegin(GL_LINES); - - ::glVertex3d(b.xmin,b.ymin,b.zmin); - ::glVertex3d(b.xmin,b.ymin,b.zmax); - - ::glVertex3d(b.xmin,b.ymin,b.zmin); - ::glVertex3d(b.xmin,b.ymax,b.zmin); - - ::glVertex3d(b.xmin,b.ymin,b.zmin); - ::glVertex3d(b.xmax,b.ymin,b.zmin); - - ::glVertex3d(b.xmax,b.ymin,b.zmin); - ::glVertex3d(b.xmax,b.ymax,b.zmin); - - ::glVertex3d(b.xmax,b.ymin,b.zmin); - ::glVertex3d(b.xmax,b.ymin,b.zmax); - - ::glVertex3d(b.xmin,b.ymax,b.zmin); - ::glVertex3d(b.xmin,b.ymax,b.zmax); - - ::glVertex3d(b.xmin,b.ymax,b.zmin); - ::glVertex3d(b.xmax,b.ymax,b.zmin); - - ::glVertex3d(b.xmax,b.ymax,b.zmin); - ::glVertex3d(b.xmax,b.ymax,b.zmax); - - ::glVertex3d(b.xmin,b.ymin,b.zmax); - ::glVertex3d(b.xmin,b.ymax,b.zmax); - - ::glVertex3d(b.xmin,b.ymin,b.zmax); - ::glVertex3d(b.xmax,b.ymin,b.zmax); - - ::glVertex3d(b.xmax,b.ymax,b.zmax); - ::glVertex3d(b.xmin,b.ymax,b.zmax); - - ::glVertex3d(b.xmax,b.ymax,b.zmax); - ::glVertex3d(b.xmax,b.ymin,b.zmax); - - ::glEnd(); -} - -void -Scene_implicit_function_item:: -draw_function_grid(const Color_ramp& ramp_pos, - const Color_ramp& ramp_neg) const -{ - ::glDisable(GL_LIGHTING); - ::glShadeModel(GL_SMOOTH); - - ::glBegin(GL_QUADS); - const int nb_quads = grid_size_ - 1; - for( int i=0 ; i < nb_quads ; i++ ) - { - for( int j=0 ; j < nb_quads ; j++) - { - draw_grid_vertex(implicit_grid_[i][j], ramp_pos, ramp_neg); - draw_grid_vertex(implicit_grid_[i][j+1], ramp_pos, ramp_neg); - draw_grid_vertex(implicit_grid_[i+1][j+1], ramp_pos, ramp_neg); - draw_grid_vertex(implicit_grid_[i+1][j], ramp_pos, ramp_neg); + return false; } - } - ::glEnd(); + + return false; } - -void -Scene_implicit_function_item:: -draw_grid_vertex(const Point_value& pv, - const Color_ramp& ramp_positive, - const Color_ramp& ramp_negative) const +void Scene_implicit_function_item::compute_texture(int i, int j) { - const Point& p = pv.first; - double v = pv.second; + double v = (implicit_grid_[i][j]).second; - if(is_nan(v)) { - ::glColor3f(0.2f, 0.2f, 0.2f); - } else - // determines grey level - if ( v > 0 ) - { - v = v/max_value_; - ::glColor3d(ramp_positive.r(v),ramp_positive.g(v),ramp_positive.b(v)); - } - else - { - v = v/min_value_; - ::glColor3d(ramp_negative.r(v),ramp_negative.g(v),ramp_negative.b(v)); - } - - ::glVertex3d(p.x,p.y,p.z); + if(is_nan(v)) { + texture->setData(i,j,51,51,51); + } else + // determines grey level + if ( v > 0 ) + { + v = v/max_value_; + GLdouble r = red_color_ramp_.r(v), g = red_color_ramp_.g(v), b = red_color_ramp_.b(v); + texture->setData(i,j,255*r,255*g,255*b); + } + else + { + v = v/min_value_; + GLdouble r = blue_color_ramp_.r(v), g = blue_color_ramp_.g(v), b = blue_color_ramp_.b(v); + texture->setData(i,j,255*r,255*g,255*b); + } } @@ -232,78 +498,97 @@ void Scene_implicit_function_item:: compute_function_grid() const { - typedef CGAL::Simple_cartesian K; - typedef K::Aff_transformation_3 Aff_transformation; - typedef K::Point_3 Point_3; - - // Get transformation - const ::GLdouble* m = frame_->matrix(); - - // OpenGL matrices are row-major matrices - Aff_transformation t (m[0], m[4], m[8], m[12], - m[1], m[5], m[9], m[13], - m[2], m[6], m[10], m[14]); - - double diag = bbox().diagonal_length() * .6; - - const double dx = diag; - const double dy = diag; - const double z (0); + typedef CGAL::Simple_cartesian K; + typedef K::Aff_transformation_3 Aff_transformation; + typedef K::Point_3 Point_3; - int nb_quad = grid_size_ - 1; - - for(int i=0 ; imatrix(); + + // OpenGL matrices are row-major matrices + Aff_transformation t (m[0], m[4], m[8], m[12], + m[1], m[5], m[9], m[13], + m[2], m[6], m[10], m[14]); + + double diag = bbox().diagonal_length() * .6; + + const double dx = diag; + const double dy = diag; + const double z (0); + + int nb_quad = grid_size_ - 1; + + for(int i=0 ; ioperator()(query.x(), query.y(), query.z()); - - implicit_grid_[i][j] = Point_value(Point(query.x(),query.y(),query.z()),v); + double x = -diag/2. + double(i)/double(nb_quad) * dx; + + for(int j=0 ; joperator()(query.x(), query.y(), query.z()); + + implicit_grid_[i][j] = Point_value(Point(query.x(),query.y(),query.z()),v); + } } - } - - // Update display list - const_cast(this)->changed(); + + // Update + const_cast(this)->changed(); + } void Scene_implicit_function_item:: compute_min_max() { - if(function_->get_min_max(min_value_, max_value_)) - return; + if(function_->get_min_max(min_value_, max_value_)) + return; - double probes_nb = double(grid_size_) / 2; - - // Probe bounding box - const Bbox& b = bbox(); - - for ( int i = 0 ; i <= probes_nb ; ++i ) - { - double x = b.xmin + double(i) * (b.xmax - b.xmin) / probes_nb; - - for ( int j = 0 ; j <= probes_nb ; ++j ) + double probes_nb = double(grid_size_) / 2; + + // Probe bounding box + const Bbox& b = bbox(); + + for ( int i = 0 ; i <= probes_nb ; ++i ) { - double y = b.ymin + double(j) * (b.ymax - b.ymin) / probes_nb; - - for ( int k = 0 ; k <= probes_nb ; ++k ) - { - double z = b.zmin + double(k) * (b.zmax - b.zmin) / probes_nb; - - double v = (*function_)(x,y,z); - if(is_nan(v)) continue; - max_value_ = (std::max)(v,max_value_); - min_value_ = (std::min)(v,min_value_); - } + double x = b.xmin + double(i) * (b.xmax - b.xmin) / probes_nb; + + for ( int j = 0 ; j <= probes_nb ; ++j ) + { + double y = b.ymin + double(j) * (b.ymax - b.ymin) / probes_nb; + + for ( int k = 0 ; k <= probes_nb ; ++k ) + { + double z = b.zmin + double(k) * (b.zmax - b.zmin) / probes_nb; + + double v = (*function_)(x,y,z); + if(is_nan(v)) continue; + max_value_ = (std::max)(v,max_value_); + min_value_ = (std::min)(v,min_value_); + } + } } - } } +void +Scene_implicit_function_item::changed() +{ + Scene_item::changed(); + compute_vertices_and_texmap(); + are_buffers_filled = false; +} + +void Scene_implicit_function_item::contextual_changed() +{ + if(!frame_->isManipulated()) { + if(need_update_) { + compute_function_grid(); + compute_vertices_and_texmap(); + need_update_ = false; + } + } +} #include "Scene_implicit_function_item.moc" diff --git a/Polyhedron/demo/Polyhedron/Scene_implicit_function_item.h b/Polyhedron/demo/Polyhedron/Scene_implicit_function_item.h index eca5fa16762..0e8a3700766 100644 --- a/Polyhedron/demo/Polyhedron/Scene_implicit_function_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_implicit_function_item.h @@ -1,22 +1,44 @@ #ifndef SCENE_IMPLICIT_FUNCTION_ITEM_H #define SCENE_IMPLICIT_FUNCTION_ITEM_H -#include +#include #include #include "Scene_implicit_function_item_config.h" #include "implicit_functions/Implicit_function_interface.h" #include "Color_ramp.h" - #include -#include +#include #define SCENE_IMPLICIT_GRID_SIZE 120 class Viewer_interface; +class Texture{ +private: + int Width; + int Height; + int size; + GLubyte *data; +public: + Texture(int w, int h) + { + Width = w; + Height = h; + size = 3*Height*Width; + data = new GLubyte[size]; + } + int getWidth() const {return Width;} + int getHeight() const {return Height;} + int getSize() const {return size;} + void setData(int i, int j, int r, int g, int b){ + data[j*Width*3 +i*3] = r; + data[j*Width*3 +i*3+1] = g; + data[j*Width*3 +i*3+2] = b;} + GLubyte* getData(){return data; } +}; class SCENE_IMPLICIT_FUNCTION_ITEM_EXPORT Scene_implicit_function_item - : public Scene_item_with_display_list + : public Scene_item { Q_OBJECT @@ -39,14 +61,16 @@ public: virtual bool manipulatable() const { return true; } virtual ManipulatedFrame* manipulatedFrame() { return frame_; } - // draw (overload only direct_draw() to use display list of base class) - virtual void direct_draw() const; + + // actually draw() is also overloaded to detect when the cut plane is moved + virtual void draw()const {} virtual void draw(Viewer_interface*) const; virtual void draw_edges(Viewer_interface*) const; virtual QString toolTip() const; - + virtual void contextual_changed(); + virtual void changed(); public Q_SLOTS: void plane_was_moved() { need_update_ = true; } void compute_function_grid() const; @@ -54,15 +78,6 @@ public Q_SLOTS: private: typedef qglviewer::Vec Point; typedef std::pair Point_value; - - // common implementation of draw() and draw_edges() - void draw_aux(Viewer_interface*,bool) const; - - void draw_bbox() const; - void draw_function_grid(const Color_ramp&, const Color_ramp&) const; - void draw_grid_vertex(const Point_value&, - const Color_ramp&, const Color_ramp&) const; - void compute_min_max(); private: @@ -77,6 +92,25 @@ private: Color_ramp blue_color_ramp_; Color_ramp red_color_ramp_; + + std::vector positions_cube; + std::vector positions_grid; + std::vector positions_tex_quad; + std::vector texture_map; + Texture *texture; + + + mutable QOpenGLShaderProgram *program; + GLuint textureId; + + + + GLuint vao; + GLuint buffer[4]; + using Scene_item::initialize_buffers; + void initialize_buffers(Viewer_interface *viewer) const; + void compute_vertices_and_texmap(void); + void compute_texture(int, int); }; #endif // SCENE_IMPLICIT_FUNCTION_ITEM diff --git a/Polyhedron/demo/Polyhedron/Scene_item.cpp b/Polyhedron/demo/Polyhedron/Scene_item.cpp index 3040399f209..90d8729c51b 100644 --- a/Polyhedron/demo/Polyhedron/Scene_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_item.cpp @@ -1,103 +1,114 @@ #include "Scene_item.h" #include "Scene_interface.h" #include - +#include +#include +#include "Viewer_interface.h" const QColor Scene_item::defaultColor = QColor(100, 100, 255); Scene_item::~Scene_item() { - delete defaultContextMenu; + delete defaultContextMenu; + for(int i=0; idestroy(); + } } void Scene_item::itemAboutToBeDestroyed(Scene_item* item) { - if(this == item) + if(this == item) Q_EMIT aboutToBeDestroyed(); } QString modeName(RenderingMode mode) { - switch(mode) - { + switch(mode) + { case Points: - return QObject::tr("points"); + return QObject::tr("points"); case Wireframe: - return QObject::tr("wire"); + return QObject::tr("wire"); case Flat: - return QObject::tr("flat"); + return QObject::tr("flat"); case FlatPlusEdges: - return QObject::tr("flat+edges"); + return QObject::tr("flat+edges"); case Gouraud: - return QObject::tr("Gouraud"); + return QObject::tr("Gouraud"); case PointsPlusNormals: - return QObject::tr("pts+normals"); - case Splatting: - return QObject::tr("splats"); + return QObject::tr("pts+normals"); default: - Q_ASSERT(false); - return QObject::tr("unknown"); - } + Q_ASSERT(false); + return QObject::tr("unknown"); + } } const char* slotName(RenderingMode mode) { - switch(mode) - { + switch(mode) + { case Points: - return SLOT(setPointsMode()); + return SLOT(setPointsMode()); case Wireframe: - return SLOT(setWireframeMode()); + return SLOT(setWireframeMode()); case Flat: - return SLOT(setFlatMode()); + return SLOT(setFlatMode()); case FlatPlusEdges: - return SLOT(setFlatPlusEdgesMode()); + return SLOT(setFlatPlusEdgesMode()); case Gouraud: - return SLOT(setGouraudMode()); + return SLOT(setGouraudMode()); case PointsPlusNormals: - return SLOT(setPointsPlusNormalsMode()); - case Splatting: - return SLOT(setSplattingMode()); + return SLOT(setPointsPlusNormalsMode()); default: - Q_ASSERT(false); - return ""; - } + Q_ASSERT(false); + return ""; + } } // Rendering mode as a human readable string QString Scene_item::renderingModeName() const { - return modeName(renderingMode()); + return modeName(renderingMode()); } QMenu* Scene_item::contextMenu() { - if(defaultContextMenu) { - defaultContextMenu->setTitle(name()); - return defaultContextMenu; - } + if(defaultContextMenu) { + defaultContextMenu->setTitle(name()); + return defaultContextMenu; + } - defaultContextMenu = new QMenu(name()); - // defaultContextMenu->addAction(name()); - // defaultContextMenu->addSeparator(); - // QMenu* modeMenu = new QMenu(QObject::tr("Rendering mode"), - // defaultContextMenu); - for(unsigned int mode = 0; mode < NumberOfRenderingMode; - ++mode) - { - if(!supportsRenderingMode(RenderingMode(mode))) continue; - QString mName = modeName(RenderingMode(mode)); - QAction* action = - defaultContextMenu->addAction(tr("Set %1 mode") - .arg(mName), - this, - slotName(RenderingMode(mode))); - QObject::connect(action, SIGNAL(triggered()), - this, SIGNAL(itemChanged())); - } - // defaultContextMenu->addAction(modeMenu->menuAction()); - return defaultContextMenu; + defaultContextMenu = new QMenu(name()); + // defaultContextMenu->addAction(name()); + // defaultContextMenu->addSeparator(); + // QMenu* modeMenu = new QMenu(QObject::tr("Rendering mode"), + // defaultContextMenu); + for(unsigned int mode = 0; mode < NumberOfRenderingMode; + ++mode) + { + if(!supportsRenderingMode(RenderingMode(mode))) continue; + QString mName = modeName(RenderingMode(mode)); + QAction* action = + defaultContextMenu->addAction(tr("Set %1 mode") + .arg(mName), + this, + slotName(RenderingMode(mode))); + QObject::connect(action, SIGNAL(triggered()), + this, SIGNAL(itemChanged())); + } + // defaultContextMenu->addAction(modeMenu->menuAction()); + return defaultContextMenu; } void Scene_item::changed() { // Q_EMIT itemChanged(); } +void Scene_item::selection_changed(bool) { + // emit itemChanged(); +} + + void Scene_item::select(double /*orig_x*/, double /*orig_y*/, double /*orig_z*/, @@ -107,5 +118,269 @@ void Scene_item::select(double /*orig_x*/, { } +// set-up the uniform attributes of the shader programs. +void Scene_item::attrib_buffers(Viewer_interface* viewer, int program_name) const +{ + GLint is_both_sides = 0; + QMatrix4x4 mvp_mat; + QMatrix4x4 mv_mat; + QMatrix4x4 f_mat; + f_mat.setToIdentity(); + //fills the MVP and MV matrices. + GLdouble d_mat[16]; + viewer->camera()->getModelViewProjectionMatrix(d_mat); + //Convert the GLdoubles matrices in GLfloats + for (int i=0; i<16; ++i){ + mvp_mat.data()[i] = GLfloat(d_mat[i]); + } + viewer->camera()->getModelViewMatrix(d_mat); + for (int i=0; i<16; ++i) + mv_mat.data()[i] = GLfloat(d_mat[i]); + + qFunc.glGetIntegerv(GL_LIGHT_MODEL_TWO_SIDE, &is_both_sides); + + QVector4D position(0.0f,0.0f,1.0f, 1.0f ); + QVector4D ambient(0.4f, 0.4f, 0.4f, 0.4f); + // Diffuse + QVector4D diffuse(1.0f, 1.0f, 1.0f, 1.0f); + // Specular + QVector4D specular(0.0f, 0.0f, 0.0f, 1.0f); + QColor temp = this->color(); + switch(program_name) + { + case PROGRAM_WITH_LIGHT: + shader_programs[PROGRAM_WITH_LIGHT]->bind(); + shader_programs[PROGRAM_WITH_LIGHT]->setUniformValue("mvp_matrix", mvp_mat); + shader_programs[PROGRAM_WITH_LIGHT]->setUniformValue("mv_matrix", mv_mat); + shader_programs[PROGRAM_WITH_LIGHT]->setUniformValue("light_pos", position); + shader_programs[PROGRAM_WITH_LIGHT]->setUniformValue("light_diff",diffuse); + shader_programs[PROGRAM_WITH_LIGHT]->setUniformValue("light_spec", specular); + shader_programs[PROGRAM_WITH_LIGHT]->setUniformValue("light_amb", ambient); + shader_programs[PROGRAM_WITH_LIGHT]->setUniformValue("spec_power", 51.8f); + shader_programs[PROGRAM_WITH_LIGHT]->setUniformValue("is_two_side", is_both_sides); + shader_programs[PROGRAM_WITH_LIGHT]->release(); + break; + case PROGRAM_WITHOUT_LIGHT: + shader_programs[PROGRAM_WITHOUT_LIGHT]->bind(); + shader_programs[PROGRAM_WITHOUT_LIGHT]->setUniformValue("mvp_matrix", mvp_mat); + shader_programs[PROGRAM_WITHOUT_LIGHT]->setUniformValue("mv_matrix", mv_mat); + + shader_programs[PROGRAM_WITHOUT_LIGHT]->setUniformValue("light_pos", position); + shader_programs[PROGRAM_WITHOUT_LIGHT]->setUniformValue("light_diff", diffuse); + shader_programs[PROGRAM_WITHOUT_LIGHT]->setUniformValue("light_spec", specular); + shader_programs[PROGRAM_WITHOUT_LIGHT]->setUniformValue("light_amb", ambient); + shader_programs[PROGRAM_WITHOUT_LIGHT]->setUniformValue("spec_power", 51.8f); + shader_programs[PROGRAM_WITHOUT_LIGHT]->setUniformValue("is_two_side", is_both_sides); + shader_programs[PROGRAM_WITHOUT_LIGHT]->setAttributeValue("normals", 0.0,0.0,0.0); + shader_programs[PROGRAM_WITHOUT_LIGHT]->setUniformValue("f_matrix",f_mat); + + + shader_programs[PROGRAM_WITHOUT_LIGHT]->release(); + break; + case PROGRAM_WITH_TEXTURE: + if(is_selected) + { + + shader_programs[PROGRAM_WITH_TEXTURE]->setAttributeValue("color_facets", temp.lighter(120).redF(),temp.lighter(120).greenF(), temp.lighter(120).blueF()); + } + else + { + shader_programs[PROGRAM_WITH_TEXTURE]->setAttributeValue("color_facets", temp.redF(),temp.greenF(), temp.blueF()); + } + + shader_programs[PROGRAM_WITH_TEXTURE]->bind(); + shader_programs[PROGRAM_WITH_TEXTURE]->setUniformValue("mvp_matrix", mvp_mat); + shader_programs[PROGRAM_WITH_TEXTURE]->setUniformValue("mv_matrix", mv_mat); + shader_programs[PROGRAM_WITH_TEXTURE]->setUniformValue("light_pos", position); + shader_programs[PROGRAM_WITH_TEXTURE]->setUniformValue("light_diff",diffuse); + shader_programs[PROGRAM_WITH_TEXTURE]->setUniformValue("light_spec", specular); + shader_programs[PROGRAM_WITH_TEXTURE]->setUniformValue("light_amb", ambient); + shader_programs[PROGRAM_WITH_TEXTURE]->setUniformValue("spec_power", 51.8f); + shader_programs[PROGRAM_WITH_TEXTURE]->setUniformValue("s_texture",0); + shader_programs[PROGRAM_WITH_TEXTURE]->setUniformValue("f_matrix",f_mat); + + + shader_programs[PROGRAM_WITH_TEXTURE]->release(); + break; + case PROGRAM_WITH_TEXTURED_EDGES: + shader_programs[PROGRAM_WITH_TEXTURED_EDGES]->bind(); + if(is_selected) + { + shader_programs[PROGRAM_WITH_TEXTURED_EDGES]->setUniformValue("color_lines",QVector3D(0.0,0.0,0.0)); + } + else + { + shader_programs[PROGRAM_WITH_TEXTURED_EDGES]->setUniformValue("color_lines", QVector3D(temp.lighter(50).redF(), temp.lighter(50).greenF(), temp.lighter(50).blueF())); + + } + + shader_programs[PROGRAM_WITH_TEXTURED_EDGES]->setUniformValue("mvp_matrix", mvp_mat); + shader_programs[PROGRAM_WITH_TEXTURED_EDGES]->setUniformValue("s_texture",0); + shader_programs[PROGRAM_WITH_TEXTURED_EDGES]->release(); + break; + case PROGRAM_INSTANCED: + + shader_programs[PROGRAM_INSTANCED]->bind(); + shader_programs[PROGRAM_INSTANCED]->setUniformValue("mvp_matrix", mvp_mat); + shader_programs[PROGRAM_INSTANCED]->setUniformValue("mv_matrix", mv_mat); + + shader_programs[PROGRAM_INSTANCED]->setUniformValue("light_pos", position); + shader_programs[PROGRAM_INSTANCED]->setUniformValue("light_diff",diffuse); + shader_programs[PROGRAM_INSTANCED]->setUniformValue("light_spec", specular); + shader_programs[PROGRAM_INSTANCED]->setUniformValue("light_amb", ambient); + shader_programs[PROGRAM_INSTANCED]->setUniformValue("spec_power", 51.8f); + shader_programs[PROGRAM_INSTANCED]->setUniformValue("is_two_side", is_both_sides); + shader_programs[PROGRAM_INSTANCED]->release(); + + break; + case PROGRAM_INSTANCED_WIRE: + shader_programs[PROGRAM_INSTANCED_WIRE]->bind(); + shader_programs[PROGRAM_INSTANCED_WIRE]->setUniformValue("mvp_matrix", mvp_mat); + shader_programs[PROGRAM_INSTANCED_WIRE]->release(); + break; + } +} + + +QOpenGLShaderProgram* Scene_item::getShaderProgram(int name, Viewer_interface * viewer) const +{ + switch(name) + { + case PROGRAM_WITH_LIGHT: + if(shader_programs[PROGRAM_WITH_LIGHT]) + { + return shader_programs[PROGRAM_WITH_LIGHT]; + } + + else + { + + QOpenGLShaderProgram *program = new QOpenGLShaderProgram(viewer); + if(!program->addShaderFromSourceFile(QOpenGLShader::Vertex,":/cgal/Polyhedron_3/resources/shader_with_light.v")) + { + std::cerr<<"adding vertex shader FAILED"<addShaderFromSourceFile(QOpenGLShader::Fragment,":/cgal/Polyhedron_3/resources/shader_with_light.f")) + { + std::cerr<<"adding fragment shader FAILED"<link(); + shader_programs[PROGRAM_WITH_LIGHT] = program; + return program; + } + break; + case PROGRAM_WITHOUT_LIGHT: + if( shader_programs[PROGRAM_WITHOUT_LIGHT]) + { + return shader_programs[PROGRAM_WITHOUT_LIGHT]; + } + else + { + QOpenGLShaderProgram *program = new QOpenGLShaderProgram(viewer); + if(!program->addShaderFromSourceFile(QOpenGLShader::Vertex,":/cgal/Polyhedron_3/resources/shader_without_light.v")) + { + std::cerr<<"adding vertex shader FAILED"<addShaderFromSourceFile(QOpenGLShader::Fragment,":/cgal/Polyhedron_3/resources/shader_without_light.f")) + { + std::cerr<<"adding fragment shader FAILED"<link(); + shader_programs[PROGRAM_WITHOUT_LIGHT] = program; + return program; + } + break; + case PROGRAM_WITH_TEXTURE: + if( shader_programs[PROGRAM_WITH_TEXTURE]) + { + return shader_programs[PROGRAM_WITH_TEXTURE]; + } + else + { + QOpenGLShaderProgram *program = new QOpenGLShaderProgram(viewer); + if(!program->addShaderFromSourceFile(QOpenGLShader::Vertex,":/cgal/Polyhedron_3/resources/shader_with_texture.v")) + { + std::cerr<<"adding vertex shader FAILED"<addShaderFromSourceFile(QOpenGLShader::Fragment,":/cgal/Polyhedron_3/resources/shader_with_texture.f")) + { + std::cerr<<"adding fragment shader FAILED"<link(); + shader_programs[PROGRAM_WITH_TEXTURE] = program; + return program; + } + break; + case PROGRAM_WITH_TEXTURED_EDGES: + if( shader_programs[PROGRAM_WITH_TEXTURED_EDGES]) + { + return shader_programs[PROGRAM_WITH_TEXTURED_EDGES]; + } + else + { + QOpenGLShaderProgram *program = new QOpenGLShaderProgram(viewer); + if(!program->addShaderFromSourceFile(QOpenGLShader::Vertex,":/cgal/Polyhedron_3/resources/shader_with_textured_edges.v" )) + { + std::cerr<<"adding vertex shader FAILED"<addShaderFromSourceFile(QOpenGLShader::Fragment,":/cgal/Polyhedron_3/resources/shader_with_textured_edges.f" )) + { + std::cerr<<"adding fragment shader FAILED"<link(); + shader_programs[PROGRAM_WITH_TEXTURED_EDGES] = program; + return program; + + } + break; + case PROGRAM_INSTANCED: + if( shader_programs[PROGRAM_INSTANCED]) + { + return shader_programs[PROGRAM_INSTANCED]; + } + else + { + QOpenGLShaderProgram *program = new QOpenGLShaderProgram(viewer); + if(!program->addShaderFromSourceFile(QOpenGLShader::Vertex,":/cgal/Polyhedron_3/resources/shader_instanced.v" )) + { + std::cerr<<"adding vertex shader FAILED"<addShaderFromSourceFile(QOpenGLShader::Fragment,":/cgal/Polyhedron_3/resources/shader_with_light.f" )) + { + std::cerr<<"adding fragment shader FAILED"<link(); + shader_programs[PROGRAM_INSTANCED] = program; + return program; + + } + break; + case PROGRAM_INSTANCED_WIRE: + if( shader_programs[PROGRAM_INSTANCED_WIRE]) + { + return shader_programs[PROGRAM_INSTANCED_WIRE]; + } + else + { + QOpenGLShaderProgram *program = new QOpenGLShaderProgram(viewer); + if(!program->addShaderFromSourceFile(QOpenGLShader::Vertex,":/cgal/Polyhedron_3/resources/shader_instanced.v" )) + { + std::cerr<<"adding vertex shader FAILED"<addShaderFromSourceFile(QOpenGLShader::Fragment,":/cgal/Polyhedron_3/resources/shader_without_light.f" )) + { + std::cerr<<"adding fragment shader FAILED"<link(); + shader_programs[PROGRAM_INSTANCED_WIRE] = program; + return program; + + } + break; + default: + std::cerr<<"ERROR : Program not found."< #include #include +#include +#include +#include +#include +#include +#include +#define PROGRAM_WITH_LIGHT 0 +#define PROGRAM_WITHOUT_LIGHT 1 +#define PROGRAM_WITH_TEXTURE 2 +#define PROGRAM_WITH_TEXTURED_EDGES 3 +#define PROGRAM_INSTANCED 4 +#define PROGRAM_INSTANCED_WIRE 5 + namespace qglviewer { class ManipulatedFrame; @@ -33,26 +45,66 @@ public: : name_("unamed"), color_(defaultColor), visible_(true), + are_buffers_filled(false), rendering_mode(FlatPlusEdges), - defaultContextMenu(0) - {} + defaultContextMenu(0), + buffersSize(20), + vaosSize(10) + { + + nbVaos = 0; + for(int i=0; icreate(); + } + + for(int i=0; icreate(); + } + + for(int i=0; i buffers; + //not allowed to use vectors of VAO for some reason + //mutable QOpenGLVertexArrayObject vaos[10]; + QMap vaos; + int nbVaos; + void addVaos(int i) + { + QOpenGLVertexArrayObject* n_vao = new QOpenGLVertexArrayObject(); + vaos[i] = n_vao; + nbVaos ++; + } + + + mutable QMap shader_programs; + QOpenGLShaderProgram* getShaderProgram(int , Viewer_interface *viewer = 0) const; + + int vertexLoc; + int normalLoc; + int colorLoc; + + virtual void initialize_buffers(){} + virtual void compute_elements(){} + virtual void attrib_buffers(Viewer_interface*, int program_name) const; + + + }; // end class Scene_item diff --git a/Polyhedron/demo/Polyhedron/Scene_item_with_display_list.cpp b/Polyhedron/demo/Polyhedron/Scene_item_with_display_list.cpp index ffee6904970..486aa8e6427 100644 --- a/Polyhedron/demo/Polyhedron/Scene_item_with_display_list.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_item_with_display_list.cpp @@ -1,4 +1,4 @@ -#include "Scene_item_with_display_list.h" +include "Scene_item_with_display_list.h" #include Scene_item_with_display_list::Scene_item_with_display_list() diff --git a/Polyhedron/demo/Polyhedron/Scene_nef_polyhedron_item.cpp b/Polyhedron/demo/Polyhedron/Scene_nef_polyhedron_item.cpp index 70a900c23f1..72c5d6d49ce 100644 --- a/Polyhedron/demo/Polyhedron/Scene_nef_polyhedron_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_nef_polyhedron_item.cpp @@ -1,3 +1,4 @@ +#include #include "Scene_nef_polyhedron_item.h" #include "Scene_polyhedron_item.h" #include "Nef_type.h" @@ -12,25 +13,77 @@ #include "Scene_nef_rendering.h" #include -#include +#include +#include +#include +#include -Scene_nef_polyhedron_item::Scene_nef_polyhedron_item() - : Scene_item_with_display_list(), - nef_poly(new Nef_polyhedron) +typedef Nef_polyhedron::Traits Traits; +typedef Nef_polyhedron::Halffacet Facet; +typedef CGAL::Triangulation_2_filtered_projection_traits_3 P_traits; +typedef Nef_polyhedron::Halfedge_const_handle Halfedge_handle; +struct Face_info { + Nef_polyhedron::Halfedge_const_handle e[3]; + bool is_external; +}; +typedef CGAL::Triangulation_vertex_base_with_info_2 Vb; +typedef CGAL::Triangulation_face_base_with_info_2 Fb1; +typedef CGAL::Constrained_triangulation_face_base_2 Fb; +typedef CGAL::Triangulation_data_structure_2 TDS; +typedef CGAL::No_intersection_tag Itag; +typedef CGAL::Constrained_Delaunay_triangulation_2 CDTbase; +typedef CGAL::Constrained_triangulation_plus_2 CDT; + +struct light_info { + //position + GLfloat position[4]; + + //ambient + GLfloat ambient[4]; + + //diffuse + GLfloat diffuse[4]; + + //specular + GLfloat specular[4]; +}; +struct DPoint { + DPoint(GLdouble x, GLdouble y, GLdouble z) + { + coords[0] = x; + coords[1] = y; + coords[2] = z; + } + GLdouble coords[3]; +}; +Scene_nef_polyhedron_item::Scene_nef_polyhedron_item() + : Scene_item(7,3), + nef_poly(new Nef_polyhedron) +{ + is_selected = true; + qFunc.initializeOpenGLFunctions(); } Scene_nef_polyhedron_item::Scene_nef_polyhedron_item(Nef_polyhedron* const p) - : Scene_item_with_display_list(), - nef_poly(p) + : Scene_item(7,3), + nef_poly(p) { + is_selected = true; + qFunc.initializeOpenGLFunctions(); } Scene_nef_polyhedron_item::Scene_nef_polyhedron_item(const Nef_polyhedron& p) - : Scene_item_with_display_list(), - nef_poly(new Nef_polyhedron(p)) + : Scene_item(7,3), + nef_poly(new Nef_polyhedron(p)) { + is_selected = true; + qFunc.initializeOpenGLFunctions(); } // Scene_nef_polyhedron_item::Scene_nef_polyhedron_item(const Scene_nef_polyhedron_item& item) @@ -41,251 +94,619 @@ Scene_nef_polyhedron_item::Scene_nef_polyhedron_item(const Nef_polyhedron& p) Scene_nef_polyhedron_item::~Scene_nef_polyhedron_item() { - delete nef_poly; + delete nef_poly; } +void Scene_nef_polyhedron_item::initialize_buffers(Viewer_interface *viewer) const +{ + //vao for the facets + { + program = getShaderProgram(PROGRAM_WITH_LIGHT, viewer); + program->bind(); + + vaos[0]->bind(); + buffers[0].bind(); + buffers[0].allocate(positions_facets.data(), + static_cast(positions_facets.size()*sizeof(double))); + program->enableAttributeArray("vertex"); + program->setAttributeBuffer("vertex",GL_DOUBLE,0,3); + buffers[0].release(); + + + + buffers[1].bind(); + buffers[1].allocate(normals.data(), + static_cast(normals.size()*sizeof(double))); + program->enableAttributeArray("normals"); + program->setAttributeBuffer("normals",GL_DOUBLE,0,3); + buffers[1].release(); + + buffers[2].bind(); + buffers[2].allocate(color_facets.data(), + static_cast(color_facets.size()*sizeof(double))); + program->enableAttributeArray("colors"); + program->setAttributeBuffer("colors",GL_DOUBLE,0,3); + buffers[2].release(); + vaos[0]->release(); + program->release(); + + } + //vao for the edges + { + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT, viewer); + program->bind(); + + vaos[1]->bind(); + buffers[3].bind(); + buffers[3].allocate(positions_lines.data(), + static_cast(positions_lines.size()*sizeof(double))); + program->enableAttributeArray("vertex"); + program->setAttributeBuffer("vertex",GL_DOUBLE,0,3); + buffers[3].release(); + + + + buffers[4].bind(); + buffers[4].allocate(color_lines.data(), + static_cast(color_lines.size()*sizeof(double))); + program->enableAttributeArray("colors"); + program->setAttributeBuffer("colors",GL_DOUBLE,0,3); + buffers[4].release(); + + vaos[1]->release(); + program->release(); + } + //vao for the points + { + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT, viewer); + program->bind(); + + vaos[2]->bind(); + buffers[5].bind(); + buffers[5].allocate(positions_points.data(), + static_cast(positions_points.size()*sizeof(double))); + program->enableAttributeArray("vertex"); + program->setAttributeBuffer("vertex",GL_DOUBLE,0,3); + buffers[5].release(); + + + + buffers[6].bind(); + buffers[6].allocate(color_points.data(), + static_cast(color_points.size()*sizeof(double))); + program->enableAttributeArray("colors"); + program->setAttributeBuffer("colors",GL_DOUBLE,0,3); + buffers[6].release(); + + vaos[2]->release(); + program->release(); + } + are_buffers_filled = true; +} +void Scene_nef_polyhedron_item::compute_normals_and_vertices(void) +{ + int count = 0; + positions_facets.resize(0); + positions_points.resize(0); + color_lines.resize(0); + color_facets.resize(0); + color_points.resize(0); + normals.resize(0); + positions_lines.resize(0); + //The Facets + { + for(Nef_polyhedron::Halffacet_const_iterator + f = nef_poly->halffacets_begin (), + end = nef_poly->halffacets_end(); + f != end; ++f) + { + if(f->is_twin()) continue; + count++; + Nef_polyhedron::Vector_3 v = f->plane().orthogonal_vector(); + P_traits cdt_traits(v); + CDT cdt(cdt_traits); + + for(Nef_polyhedron::Halffacet_cycle_const_iterator + fc = f->facet_cycles_begin(), + end = f->facet_cycles_end(); + fc != end; ++fc) + { + if ( fc.is_shalfedge() ) + { + + Nef_polyhedron::SHalfedge_const_handle h = fc; + Nef_polyhedron::SHalfedge_around_facet_const_circulator hc(h), he(hc); + + CDT::Vertex_handle previous, first; + + do { + Nef_polyhedron::SVertex_const_handle v = hc->source(); + const Nef_polyhedron::Point_3& point = v->source()->point(); + CDT::Vertex_handle vh = cdt.insert(point); + if(first == 0) { + first = vh; + } + vh->info() = hc->source(); + if(previous != 0 && previous != vh) { + cdt.insert_constraint(previous, vh); + } + previous = vh; + } while( ++hc != he ); + + cdt.insert_constraint(previous, first); + + // sets mark is_external + for(CDT::All_faces_iterator + fit = cdt.all_faces_begin(), + end = cdt.all_faces_end(); + fit != end; ++fit) + { + fit->info().is_external = false; + + } + //check if the facet is external or internal + std::queue face_queue; + face_queue.push(cdt.infinite_vertex()->face()); + + while(! face_queue.empty() ) { + CDT::Face_handle fh = face_queue.front(); + face_queue.pop(); + if(fh->info().is_external) continue; + fh->info().is_external = true; + for(int i = 0; i <3; ++i) { + if(!cdt.is_constrained(std::make_pair(fh, i))) + { + face_queue.push(fh->neighbor(i)); + } + } + + } + //iterates on the internal faces to add the vertices to the positions + //and the normals to the appropriate vectors + + for(CDT::Finite_faces_iterator + ffit = cdt.finite_faces_begin(), + end = cdt.finite_faces_end(); + ffit != end; ++ffit) + { + + + if(ffit->info().is_external){ continue;} + for(int i = 0; i<3; i++) + { + positions_facets.push_back(CGAL::to_double(ffit->vertex(i)->point().x())); + positions_facets.push_back(CGAL::to_double(ffit->vertex(i)->point().y())); + positions_facets.push_back(CGAL::to_double(ffit->vertex(i)->point().z())); + + } + + + + Nef_polyhedron::Vector_3 v = f->plane().orthogonal_vector(); + GLdouble normal[3]; + normal[0] = CGAL::to_double(v.x()); + normal[1] = CGAL::to_double(v.y()); + normal[2] = CGAL::to_double(v.z()); + GLdouble norm = normal[0]*normal[0] + + normal[1]*normal[1] + + normal[2]*normal[2]; + norm = CGAL::sqrt(norm); + normal[0] /= norm; + normal[1] /= norm; + normal[2] /= norm; + + normals.push_back(normal[0]); + normals.push_back(normal[1]); + normals.push_back(normal[2]); + + normals.push_back(normal[0]); + normals.push_back(normal[1]); + normals.push_back(normal[2]); + + normals.push_back(normal[0]); + normals.push_back(normal[1]); + normals.push_back(normal[2]); + + if(is_selected) + { + color_facets.push_back(this->color().lighter(120).redF()); + color_facets.push_back(this->color().lighter(120).greenF()); + color_facets.push_back(this->color().lighter(120).blueF()); + + color_facets.push_back(this->color().lighter(120).redF()); + color_facets.push_back(this->color().lighter(120).greenF()); + color_facets.push_back(this->color().lighter(120).blueF()); + + color_facets.push_back(this->color().lighter(120).redF()); + color_facets.push_back(this->color().lighter(120).greenF()); + color_facets.push_back(this->color().lighter(120).blueF()); + } + else + { + color_facets.push_back(this->color().redF()); + color_facets.push_back(this->color().greenF()); + color_facets.push_back(this->color().blueF()); + + color_facets.push_back(this->color().redF()); + color_facets.push_back(this->color().greenF()); + color_facets.push_back(this->color().blueF()); + + color_facets.push_back(this->color().redF()); + color_facets.push_back(this->color().greenF()); + color_facets.push_back(this->color().blueF()); + + } + + } + } + } + } + + } // end facets + + //The Lines + { + for(Nef_polyhedron::Halfedge_const_iterator + e = nef_poly->halfedges_begin(), + end = nef_poly->halfedges_end(); + e != end; ++e) + { + if (e->is_twin()) continue; + const Nef_polyhedron::Vertex_const_handle& s = e->source(); + const Nef_polyhedron::Vertex_const_handle& t = e->twin()->source(); + const Nef_polyhedron::Point_3& a = s->point(); + const Nef_polyhedron::Point_3& b = t->point(); + + positions_lines.push_back(CGAL::to_double(a.x())); + positions_lines.push_back(CGAL::to_double(a.y())); + positions_lines.push_back(CGAL::to_double(a.z())); + + positions_lines.push_back(CGAL::to_double(b.x())); + positions_lines.push_back(CGAL::to_double(b.y())); + positions_lines.push_back(CGAL::to_double(b.z())); + + if(is_selected) + { + color_lines.push_back(this->color().lighter(50).redF()); + color_lines.push_back(this->color().lighter(50).greenF()); + color_lines.push_back(this->color().lighter(50).blueF()); + + color_lines.push_back(this->color().lighter(50).redF()); + color_lines.push_back(this->color().lighter(50).greenF()); + color_lines.push_back(this->color().lighter(50).blueF()); + } + else + { + color_lines.push_back(0.0); + color_lines.push_back(0.0); + color_lines.push_back(0.0); + + color_lines.push_back(0.0); + color_lines.push_back(0.0); + color_lines.push_back(0.0); + } + } + } + //The points + { + for(Nef_polyhedron::Vertex_const_iterator + v = nef_poly->vertices_begin(), + end = nef_poly->vertices_end(); + v != end; ++v) + { + const Nef_polyhedron::Point_3& p = v->point(); + positions_points.push_back(CGAL::to_double(p.x())); + positions_points.push_back(CGAL::to_double(p.y())); + positions_points.push_back(CGAL::to_double(p.z())); + + color_points.push_back(this->color().lighter(50).redF()); + color_points.push_back(this->color().lighter(50).greenF()); + color_points.push_back(this->color().lighter(50).blueF()); + + color_points.push_back(this->color().lighter(50).redF()); + color_points.push_back(this->color().lighter(50).greenF()); + color_points.push_back(this->color().lighter(50).blueF()); + + } + + } //end points +} Scene_nef_polyhedron_item* Scene_nef_polyhedron_item::clone() const { - return new Scene_nef_polyhedron_item(*nef_poly); + return new Scene_nef_polyhedron_item(*nef_poly); } bool Scene_nef_polyhedron_item::load_from_off(std::istream& in) { -// const std::size_t discarded = CGAL::OFF_to_nef_3(in, *nef_poly); -// return discarded != 0; + // const std::size_t discarded = CGAL::OFF_to_nef_3(in, *nef_poly); + // return discarded != 0; - Exact_polyhedron exact_poly; - in >> exact_poly; - *nef_poly = Nef_polyhedron(exact_poly); + Exact_polyhedron exact_poly; + in >> exact_poly; + *nef_poly = Nef_polyhedron(exact_poly); -// Polyhedron poly; -// in >> poly; -// *nef_poly = Nef_polyhedron(poly); - return (bool) in; + // Polyhedron poly; + // in >> poly; + // *nef_poly = Nef_polyhedron(poly); + changed(); + return (bool) in; } QFont Scene_nef_polyhedron_item::font() const { - QFont font; - font.setItalic(!font.italic()); - return font; + QFont font; + font.setItalic(!font.italic()); + return font; } bool Scene_nef_polyhedron_item::load(std::istream& in) { - in >> *nef_poly; - return (bool) in; + in >> *nef_poly; + changed(); + return (bool) in; } bool Scene_nef_polyhedron_item::save(std::ostream& in) const { - in << *nef_poly; - return (bool) in; + in << *nef_poly; + return (bool) in; } QString Scene_nef_polyhedron_item::toolTip() const { - if(!nef_poly) - return QString(); + if(!nef_poly) + return QString(); - return QObject::tr("

%1 (mode: %5, color: %6)
" - "Nef_3 polyhedron

" - "

Number of vertices: %2
" - "Number of edges: %3
" - "Number of facets: %4
" - "number of volumes: %7

") - .arg(this->name()) - .arg(nef_poly->number_of_vertices()) - .arg(nef_poly->number_of_edges()) - .arg(nef_poly->number_of_facets()) - .arg(this->renderingModeName()) - .arg(this->color().name()) - .arg(nef_poly->number_of_volumes()); + return QObject::tr("

%1 (mode: %5, color: %6)
" + "Nef_3 polyhedron

" + "

Number of vertices: %2
" + "Number of edges: %3
" + "Number of facets: %4
" + "number of volumes: %7

") + .arg(this->name()) + .arg(nef_poly->number_of_vertices()) + .arg(nef_poly->number_of_edges()) + .arg(nef_poly->number_of_facets()) + .arg(this->renderingModeName()) + .arg(this->color().name()) + .arg(nef_poly->number_of_volumes()); } void Scene_nef_polyhedron_item::direct_draw() const { - gl_render_nef_facets(nef_poly); + gl_render_nef_facets(nef_poly); - GLboolean lighting; - glGetBooleanv(GL_LIGHTING, &lighting); - glDisable(GL_LIGHTING); + GLboolean lighting; + qFunc.glGetBooleanv(GL_LIGHTING, &lighting); + qFunc.glDisable(GL_LIGHTING); - GLfloat point_size; - glGetFloatv(GL_POINT_SIZE, &point_size); - glPointSize(10.f); + GLfloat point_size; + qFunc.glGetFloatv(GL_POINT_SIZE, &point_size); + qFunc.glPointSize(10.f); - gl_render_nef_vertices(nef_poly); + gl_render_nef_vertices(nef_poly); + + if(lighting) { + qFunc.glEnable(GL_LIGHTING); + } + qFunc.glPointSize(point_size); +} +void Scene_nef_polyhedron_item::draw(Viewer_interface* viewer) const +{ + if(!are_buffers_filled) + initialize_buffers(viewer); + vaos[0]->bind(); + + // tells the GPU to use the program just created + program=getShaderProgram(PROGRAM_WITH_LIGHT); + attrib_buffers(viewer,PROGRAM_WITH_LIGHT); + program->bind(); + qFunc.glDrawArrays(GL_TRIANGLES, 0, static_cast(positions_facets.size()/3)); + vaos[0]->release(); + program->release(); + GLfloat point_size; + qFunc.glGetFloatv(GL_POINT_SIZE, &point_size); + qFunc.glPointSize(10.f); + + draw_points(viewer); + qFunc.glPointSize(point_size); + +} +void Scene_nef_polyhedron_item::draw_edges(Viewer_interface* viewer) const +{ + if(!are_buffers_filled) + initialize_buffers(viewer); + + vaos[1]->bind(); + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT); + attrib_buffers(viewer ,PROGRAM_WITHOUT_LIGHT); + program->bind(); + qFunc.glDrawArrays(GL_LINES,0,static_cast(positions_lines.size()/3)); + vaos[1]->release(); + program->release(); + if(renderingMode() == PointsPlusNormals) + { + GLfloat point_size; + qFunc.glGetFloatv(GL_POINT_SIZE, &point_size); + qFunc.glPointSize(10.f); + + draw_points(viewer); + qFunc.glPointSize(point_size); + } +} +void Scene_nef_polyhedron_item::draw_points(Viewer_interface* viewer) const +{ + if(!are_buffers_filled) + initialize_buffers(viewer); + vaos[2]->bind(); + program=getShaderProgram(PROGRAM_WITHOUT_LIGHT); + attrib_buffers(viewer ,PROGRAM_WITHOUT_LIGHT); + program->bind(); + qFunc.glDrawArrays(GL_POINTS,0,static_cast(positions_points.size()/3)); + vaos[2]->release(); + program->release(); - if(lighting) { - glEnable(GL_LIGHTING); - } - glPointSize(point_size); } -void -Scene_nef_polyhedron_item::draw_edges() const { - gl_render_nef_edges(nef_poly); -} Nef_polyhedron* Scene_nef_polyhedron_item::nef_polyhedron() { - return nef_poly; + return nef_poly; } bool Scene_nef_polyhedron_item::isEmpty() const { - return (nef_poly == 0) || nef_poly->is_empty(); + return (nef_poly == 0) || nef_poly->is_empty(); } Scene_nef_polyhedron_item::Bbox Scene_nef_polyhedron_item::bbox() const { - if(isEmpty()) - return Bbox(); - CGAL::Bbox_3 bbox(nef_poly->vertices_begin()->point().bbox()); - for(Nef_polyhedron::Vertex_const_iterator it = nef_poly->vertices_begin(); - it != nef_poly->vertices_end(); - ++it) { - bbox = bbox + it->point().bbox(); - } - return Bbox(bbox.xmin(),bbox.ymin(),bbox.zmin(), - bbox.xmax(),bbox.ymax(),bbox.zmax()); + if(isEmpty()) + return Bbox(); + CGAL::Bbox_3 bbox(nef_poly->vertices_begin()->point().bbox()); + for(Nef_polyhedron::Vertex_const_iterator it = nef_poly->vertices_begin(); + it != nef_poly->vertices_end(); + ++it) { + bbox = bbox + it->point().bbox(); + } + return Bbox(bbox.xmin(),bbox.ymin(),bbox.zmin(), + bbox.xmax(),bbox.ymax(),bbox.zmax()); } // quick hacks to convert polyhedra from exact to inexact and vice-versa template + class Polyhedron_output> struct Copy_polyhedron_to - : public CGAL::Modifier_base + : public CGAL::Modifier_base { - Copy_polyhedron_to(const Polyhedron_input& in_poly) - : in_poly(in_poly) {} + Copy_polyhedron_to(const Polyhedron_input& in_poly) + : in_poly(in_poly) {} - void operator()(typename Polyhedron_output::HalfedgeDS& out_hds) - { - typedef typename Polyhedron_output::HalfedgeDS Output_HDS; - - CGAL::Polyhedron_incremental_builder_3 builder(out_hds); - - typedef typename Polyhedron_input::Vertex_const_iterator Vertex_const_iterator; - typedef typename Polyhedron_input::Facet_const_iterator Facet_const_iterator; - typedef typename Polyhedron_input::Halfedge_around_facet_const_circulator HFCC; - - builder.begin_surface(in_poly.size_of_vertices(), - in_poly.size_of_facets(), - in_poly.size_of_halfedges()); - - for(Vertex_const_iterator - vi = in_poly.vertices_begin(), end = in_poly.vertices_end(); - vi != end ; ++vi) + void operator()(typename Polyhedron_output::HalfedgeDS& out_hds) { - typename Polyhedron_output::Point_3 p(::CGAL::to_double( vi->point().x()), - ::CGAL::to_double( vi->point().y()), - ::CGAL::to_double( vi->point().z())); - builder.add_vertex(p); - } + typedef typename Polyhedron_output::HalfedgeDS Output_HDS; - typedef CGAL::Inverse_index Index; - Index index( in_poly.vertices_begin(), in_poly.vertices_end()); + CGAL::Polyhedron_incremental_builder_3 builder(out_hds); - for(Facet_const_iterator - fi = in_poly.facets_begin(), end = in_poly.facets_end(); - fi != end; ++fi) - { - HFCC hc = fi->facet_begin(); - HFCC hc_end = hc; - // std::size_t n = circulator_size( hc); - // CGAL_assertion( n >= 3); - builder.begin_facet (); - do { - builder.add_vertex_to_facet(index[hc->vertex()]); - ++hc; - } while( hc != hc_end); - builder.end_facet(); - } - builder.end_surface(); - } // end operator()(..) + typedef typename Polyhedron_input::Vertex_const_iterator Vertex_const_iterator; + typedef typename Polyhedron_input::Facet_const_iterator Facet_const_iterator; + typedef typename Polyhedron_input::Halfedge_around_facet_const_circulator HFCC; + + builder.begin_surface(in_poly.size_of_vertices(), + in_poly.size_of_facets(), + in_poly.size_of_halfedges()); + + for(Vertex_const_iterator + vi = in_poly.vertices_begin(), end = in_poly.vertices_end(); + vi != end ; ++vi) + { + typename Polyhedron_output::Point_3 p(::CGAL::to_double( vi->point().x()), + ::CGAL::to_double( vi->point().y()), + ::CGAL::to_double( vi->point().z())); + builder.add_vertex(p); + } + + typedef CGAL::Inverse_index Index; + Index index( in_poly.vertices_begin(), in_poly.vertices_end()); + + for(Facet_const_iterator + fi = in_poly.facets_begin(), end = in_poly.facets_end(); + fi != end; ++fi) + { + HFCC hc = fi->facet_begin(); + HFCC hc_end = hc; + // std::size_t n = circulator_size( hc); + // CGAL_assertion( n >= 3); + builder.begin_facet (); + do { + builder.add_vertex_to_facet(index[hc->vertex()]); + ++hc; + } while( hc != hc_end); + builder.end_facet(); + } + builder.end_surface(); + } // end operator()(..) private: - const Polyhedron_input& in_poly; + const Polyhedron_input& in_poly; }; // end Copy_polyhedron_to<> template void copy_to(const Poly_A& poly_a, Poly_B& poly_b) { - Copy_polyhedron_to modifier(poly_a); - poly_b.delegate(modifier); + Copy_polyhedron_to modifier(poly_a); + poly_b.delegate(modifier); } void from_exact(Exact_polyhedron& in, - Polyhedron& out) + Polyhedron& out) { - copy_to(in, out); - CGAL_assertion(out.is_valid()); + copy_to(in, out); + CGAL_assertion(out.is_valid()); } void to_exact(Polyhedron& in, - Exact_polyhedron& out) + Exact_polyhedron& out) { - copy_to(in, out); - CGAL_assertion(out.is_valid()); + copy_to(in, out); + CGAL_assertion(out.is_valid()); } bool Scene_nef_polyhedron_item::is_simple() const { - return nef_poly->is_simple(); + return nef_poly->is_simple(); } // [static] Scene_nef_polyhedron_item* Scene_nef_polyhedron_item::from_polyhedron(Scene_polyhedron_item* item) { - Polyhedron* poly = item->polyhedron(); - if(!poly) return 0; + Polyhedron* poly = item->polyhedron(); + if(!poly) return 0; - Exact_polyhedron exact_poly; - to_exact(*poly, exact_poly); - Nef_polyhedron* nef_poly = new Nef_polyhedron(exact_poly); - exact_poly.clear(); + Exact_polyhedron exact_poly; + to_exact(*poly, exact_poly); + Nef_polyhedron* nef_poly = new Nef_polyhedron(exact_poly); + exact_poly.clear(); - return new Scene_nef_polyhedron_item(nef_poly); + return new Scene_nef_polyhedron_item(nef_poly); } Scene_polyhedron_item* Scene_nef_polyhedron_item::convert_to_polyhedron() const { - Exact_polyhedron exact_poly; - nef_poly->convert_to_Polyhedron(exact_poly); - Polyhedron* poly = new Polyhedron; - from_exact(exact_poly, *poly); - exact_poly.clear(); - return new Scene_polyhedron_item(poly); + Exact_polyhedron exact_poly; + nef_poly->convert_to_Polyhedron(exact_poly); + Polyhedron* poly = new Polyhedron; + from_exact(exact_poly, *poly); + exact_poly.clear(); + return new Scene_polyhedron_item(poly); } Scene_nef_polyhedron_item& Scene_nef_polyhedron_item:: operator+=(const Scene_nef_polyhedron_item& other) { - (*nef_poly) += (*other.nef_poly); - return *this; + (*nef_poly) += (*other.nef_poly); + return *this; } Scene_nef_polyhedron_item& Scene_nef_polyhedron_item:: operator*=(const Scene_nef_polyhedron_item& other) { - (*nef_poly) *= (*other.nef_poly); - return *this; + (*nef_poly) *= (*other.nef_poly); + return *this; } Scene_nef_polyhedron_item& Scene_nef_polyhedron_item:: operator-=(const Scene_nef_polyhedron_item& other) { - (*nef_poly) -= (*other.nef_poly); - return *this; + (*nef_poly) -= (*other.nef_poly); + return *this; } Scene_nef_polyhedron_item* @@ -293,31 +714,52 @@ Scene_nef_polyhedron_item:: sum(const Scene_nef_polyhedron_item& a, const Scene_nef_polyhedron_item& b) { - return new Scene_nef_polyhedron_item(CGAL::minkowski_sum_3(*a.nef_poly, - *b.nef_poly)); + return new Scene_nef_polyhedron_item(CGAL::minkowski_sum_3(*a.nef_poly, + *b.nef_poly)); } void Scene_nef_polyhedron_item:: convex_decomposition(std::list< Scene_polyhedron_item*>& convex_parts) { - // copy the Nef polyhedron, as markers are added - Nef_polyhedron N(*nef_poly); - CGAL::convex_decomposition_3(N); - - typedef Nef_polyhedron::Volume_const_iterator Volume_const_iterator; - - Volume_const_iterator ci = ++N.volumes_begin(); - for( ; ci != N.volumes_end(); ++ci) { - if(ci->mark()) { - Exact_polyhedron P; - N.convert_inner_shell_to_polyhedron(ci->shells_begin(), P); - Polyhedron* poly = new Polyhedron; - from_exact(P, *poly); - convex_parts.push_back(new Scene_polyhedron_item(poly)); + // copy the Nef polyhedron, as markers are added + Nef_polyhedron N(*nef_poly); + CGAL::convex_decomposition_3(N); + + typedef Nef_polyhedron::Volume_const_iterator Volume_const_iterator; + + Volume_const_iterator ci = ++N.volumes_begin(); + for( ; ci != N.volumes_end(); ++ci) { + if(ci->mark()) { + Exact_polyhedron P; + N.convert_inner_shell_to_polyhedron(ci->shells_begin(), P); + Polyhedron* poly = new Polyhedron; + from_exact(P, *poly); + Scene_polyhedron_item *spoly = new Scene_polyhedron_item(poly); + convex_parts.push_back(spoly); + spoly->changed(); + } } - } } +void +Scene_nef_polyhedron_item:: +changed() +{ + // init(); + Base::changed(); + compute_normals_and_vertices(); + are_buffers_filled = false; +} +void +Scene_nef_polyhedron_item::selection_changed(bool p_is_selected) +{ + if(p_is_selected != is_selected) + { + is_selected = p_is_selected; + changed(); + } + +} #include "Scene_nef_polyhedron_item.moc" diff --git a/Polyhedron/demo/Polyhedron/Scene_nef_polyhedron_item.h b/Polyhedron/demo/Polyhedron/Scene_nef_polyhedron_item.h index 8f37c43c85d..2efed5ae4a7 100644 --- a/Polyhedron/demo/Polyhedron/Scene_nef_polyhedron_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_nef_polyhedron_item.h @@ -1,18 +1,17 @@ #ifndef SCENE_NEF_POLYHEDRON_ITEM_H #define SCENE_NEF_POLYHEDRON_ITEM_H - +#include "Scene_item.h" #include "Scene_nef_polyhedron_item_config.h" -#include "Scene_item_with_display_list.h" #include "Nef_type_fwd.h" #include - +#include class Scene_polyhedron_item; class SCENE_NEF_POLYHEDRON_ITEM_EXPORT Scene_nef_polyhedron_item - : public Scene_item_with_display_list + : public Scene_item { Q_OBJECT -public: +public: Scene_nef_polyhedron_item(); // Scene_nef_polyhedron_item(const Scene_nef_polyhedron_item&); Scene_nef_polyhedron_item(const Nef_polyhedron& p); @@ -27,12 +26,18 @@ public: QFont font() const; QString toolTip() const; + virtual void changed(); + virtual void selection_changed(bool); // Indicate if rendering mode is supported - virtual bool supportsRenderingMode(RenderingMode m) const { return m != Gouraud && m!=Splatting; } // CHECK THIS! + virtual bool supportsRenderingMode(RenderingMode m) const { return m != Gouraud; } // CHECK THIS! // OpenGL drawing in a display list void direct_draw() const; + + virtual void draw(Viewer_interface*) const; + virtual void draw_edges() const {} + virtual void draw_edges(Viewer_interface* viewer) const; + virtual void draw_points(Viewer_interface*) const; // Wireframe OpenGL drawing - void draw_edges() const; bool isFinite() const { return true; } bool isEmpty() const; @@ -42,7 +47,7 @@ public: const Nef_polyhedron* nef_polyhedron() const; bool is_simple() const; - + bool is_Triangle; // conversion operations static Scene_nef_polyhedron_item* from_polyhedron(Scene_polyhedron_item*); Scene_polyhedron_item* convert_to_polyhedron() const; @@ -64,7 +69,28 @@ public: void convex_decomposition(std::list< Scene_polyhedron_item*>&); private: + typedef Scene_item Base; + typedef std::vector Color_vector; + Nef_polyhedron* nef_poly; + + + std::vector positions_lines; + std::vector positions_facets; + std::vector positions_points; + std::vector normals; + std::vector color_lines; + std::vector color_facets; + std::vector color_points; + + mutable QOpenGLShaderProgram *program; + + using Scene_item::initialize_buffers; + void initialize_buffers(Viewer_interface *viewer) const; + void compute_normals_and_vertices(void); + + void triangulate_facet(); + void triangulate_facet_color(); }; // end class Scene_nef_polyhedron_item #endif // SCENE_NEF_POLYHEDRON_ITEM_H diff --git a/Polyhedron/demo/Polyhedron/Scene_plane_item.cpp b/Polyhedron/demo/Polyhedron/Scene_plane_item.cpp index 92c1d9c4c4d..6e9f9d8ad91 100644 --- a/Polyhedron/demo/Polyhedron/Scene_plane_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_plane_item.cpp @@ -1,3 +1,130 @@ #include "Scene_plane_item.h" #include "Scene_plane_item.moc" + + +void Scene_plane_item::initialize_buffers(Viewer_interface *viewer) const +{ + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT, viewer); + program->bind(); + vaos[0]->bind(); + + buffers[0].bind(); + buffers[0].allocate(positions_quad.data(), + static_cast(positions_quad.size()*sizeof(float))); + program->enableAttributeArray("vertex"); + program->setAttributeBuffer("vertex",GL_FLOAT,0,3); + buffers[0].release(); + vaos[0]->release(); + + + vaos[1]->bind(); + buffers[1].bind(); + buffers[1].allocate(positions_lines.data(), + static_cast(positions_lines.size()*sizeof(float))); + program->enableAttributeArray("vertex"); + program->setAttributeBuffer("vertex",GL_FLOAT,0,3); + buffers[1].release(); + vaos[1]->release(); + + program->release(); + are_buffers_filled = true; + +} + +void Scene_plane_item::compute_normals_and_vertices(void) +{ + positions_quad.resize(0); + positions_lines.resize(0); + + const double diag = scene_diag(); + //The quad + { + + positions_quad.push_back(-diag); + positions_quad.push_back(-diag); + positions_quad.push_back(0.0); + positions_quad.push_back(-diag); + positions_quad.push_back(diag); + positions_quad.push_back(0.0); + positions_quad.push_back(diag); + positions_quad.push_back(-diag); + positions_quad.push_back(0.0); + + positions_quad.push_back(-diag); + positions_quad.push_back(diag); + positions_quad.push_back(0.0); + positions_quad.push_back(diag); + positions_quad.push_back(-diag); + positions_quad.push_back(0.0); + positions_quad.push_back(diag); + positions_quad.push_back(diag); + positions_quad.push_back(0.0); + +} + //The grid + float x = (2*diag)/10.0; + float y = (2*diag)/10.0; + { + for(int u = 0; u < 11; u++) + { + + positions_lines.push_back(-diag + x* u); + positions_lines.push_back(-diag); + positions_lines.push_back(0.0); + + positions_lines.push_back(-diag + x* u); + positions_lines.push_back(diag); + positions_lines.push_back(0.0); + } + for(int v=0; v<11; v++) + { + + positions_lines.push_back(-diag); + positions_lines.push_back(-diag + v * y); + positions_lines.push_back(0.0); + + positions_lines.push_back(diag); + positions_lines.push_back(-diag + v * y); + positions_lines.push_back(0.0); + } + + } +} + +void Scene_plane_item::draw(Viewer_interface* viewer)const +{ + if(!are_buffers_filled) + initialize_buffers(viewer); + vaos[0]->bind(); + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT); + attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT); + QMatrix4x4 f_matrix; + for(int i=0; i<16; i++) + f_matrix.data()[i] = (float)frame->matrix()[i]; + program->bind(); + program->setUniformValue("f_matrix", f_matrix); + program->setAttributeValue("colors",this->color()); + qFunc.glDrawArrays(GL_TRIANGLES, 0, static_cast(positions_quad.size()/3)); + program->release(); + vaos[0]->release(); + +} + +void Scene_plane_item::draw_edges(Viewer_interface* viewer)const +{ + if(!are_buffers_filled) + initialize_buffers(viewer); + vaos[1]->bind(); + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT); + attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT); + QMatrix4x4 f_matrix; + for(int i=0; i<16; i++) + f_matrix.data()[i] = (float)frame->matrix()[i]; + program->bind(); + program->setUniformValue("f_matrix", f_matrix); + program->setAttributeValue("colors",QVector3D(0,0,0)); + qFunc.glDrawArrays(GL_LINES, 0, static_cast(positions_lines.size()/3)); + program->release(); + vaos[1]->release(); +} diff --git a/Polyhedron/demo/Polyhedron/Scene_plane_item.h b/Polyhedron/demo/Polyhedron/Scene_plane_item.h index c03c9f15859..b9b45d28903 100644 --- a/Polyhedron/demo/Polyhedron/Scene_plane_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_plane_item.h @@ -1,6 +1,7 @@ #ifndef SCENE_PLANE_ITEM_H #define SCENE_PLANE_ITEM_H + #include "Scene_item.h" #include "Scene_interface.h" @@ -8,6 +9,7 @@ #include #include +#include #include @@ -23,12 +25,16 @@ public: typedef qglviewer::ManipulatedFrame ManipulatedFrame; Scene_plane_item(const Scene_interface* scene_interface) - : scene(scene_interface), + :Scene_item(2,2), + scene(scene_interface), manipulable(false), can_clone(true), frame(new ManipulatedFrame()) { setNormal(0., 0., 1.); + qFunc.initializeOpenGLFunctions(); + //Generates an integer which will be used as ID for each buffer + changed(); } ~Scene_plane_item() { @@ -89,34 +95,8 @@ public: bool supportsRenderingMode(RenderingMode m) const { return (m == Wireframe || m == Flat); } - - // Flat OpenGL drawing - void draw() const { - const double diag = scene_diag(); - ::glPushMatrix(); - ::glMultMatrixd(frame->matrix()); - GLboolean lighting; - ::glGetBooleanv(GL_LIGHTING, &lighting); - ::glDisable(GL_LIGHTING); - ::glBegin(GL_POLYGON); - ::glVertex3d(-diag, -diag, 0.); - ::glVertex3d(-diag, diag, 0.); - ::glVertex3d( diag, diag, 0.); - ::glVertex3d( diag, -diag, 0.); - ::glEnd(); - if(lighting) - ::glEnable(GL_LIGHTING); - ::glPopMatrix(); - }; - - // Wireframe OpenGL drawing - void draw_edges() const { - ::glPushMatrix(); - ::glMultMatrixd(frame->matrix()); - QGLViewer::drawGrid((float)scene_diag()); - ::glPopMatrix(); - } - + virtual void draw(Viewer_interface*) const; + virtual void draw_edges(Viewer_interface* viewer)const; Plane_3 plane() const { const qglviewer::Vec& pos = frame->position(); const qglviewer::Vec& n = @@ -137,6 +117,12 @@ private: } public Q_SLOTS: + virtual void changed() + { + compute_normals_and_vertices(); + are_buffers_filled = false; + } + void setPosition(float x, float y, float z) { frame->setPosition(x, y, z); } @@ -165,6 +151,16 @@ private: bool manipulable; bool can_clone; qglviewer::ManipulatedFrame* frame; + + mutable std::vector positions_lines; + mutable std::vector positions_quad; + mutable GLint sampler_location; + mutable bool smooth_shading; + mutable QOpenGLShaderProgram *program; + + using Scene_item::initialize_buffers; + void initialize_buffers(Viewer_interface*)const; + void compute_normals_and_vertices(void); }; #endif // SCENE_PLANE_ITEM_H diff --git a/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.cpp b/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.cpp index e1556e584c5..e4efe232a91 100644 --- a/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.cpp @@ -9,6 +9,7 @@ #include #include +#include "Viewer_interface.h" #include #include @@ -22,28 +23,39 @@ Scene_points_with_normal_item::Scene_points_with_normal_item() - : Scene_item_with_display_list(), + : Scene_item(3,3), m_points(new Point_set), m_has_normals(false) { setRenderingMode(Points); + is_selected = true; + qFunc.initializeOpenGLFunctions(); } // Copy constructor Scene_points_with_normal_item::Scene_points_with_normal_item(const Scene_points_with_normal_item& toCopy) - : Scene_item_with_display_list(), // do not call superclass' copy constructor + : Scene_item(3,3), // do not call superclass' copy constructor m_points(new Point_set(*toCopy.m_points)), m_has_normals(toCopy.m_has_normals) { if (m_has_normals) + { setRenderingMode(PointsPlusNormals); + is_selected = true; + qFunc.initializeOpenGLFunctions(); + } else + { setRenderingMode(Points); + is_selected = true; + qFunc.initializeOpenGLFunctions(); + } + changed(); } // Converts polyhedron to point set Scene_points_with_normal_item::Scene_points_with_normal_item(const Polyhedron& input_mesh) - : Scene_item_with_display_list(), + : Scene_item(6,3), m_points(new Point_set), m_has_normals(true) { @@ -61,6 +73,9 @@ Scene_points_with_normal_item::Scene_points_with_normal_item(const Polyhedron& i } setRenderingMode(PointsPlusNormals); + is_selected = true; + qFunc.initializeOpenGLFunctions(); + changed(); } Scene_points_with_normal_item::~Scene_points_with_normal_item() @@ -69,6 +84,162 @@ Scene_points_with_normal_item::~Scene_points_with_normal_item() delete m_points; m_points = NULL; } + + +void Scene_points_with_normal_item::initialize_buffers(Viewer_interface *viewer) const +{ + //vao for the edges + { + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT, viewer); + program->bind(); + + vaos[0]->bind(); + buffers[0].bind(); + buffers[0].allocate(positions_lines.data(), + static_cast(positions_lines.size()*sizeof(double))); + program->enableAttributeArray("vertex"); + program->setAttributeBuffer("vertex",GL_DOUBLE,0,3); + buffers[0].release(); + + vaos[0]->release(); + program->release(); + } + //vao for the points + { + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT, viewer); + program->bind(); + + vaos[1]->bind(); + buffers[1].bind(); + buffers[1].allocate(positions_points.data(), + static_cast(positions_points.size()*sizeof(double))); + program->enableAttributeArray("vertex"); + program->setAttributeBuffer("vertex",GL_DOUBLE,0,3); + buffers[1].release(); + vaos[1]->release(); + program->release(); + } + //vao for the selected points + { + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT, viewer); + program->bind(); + + vaos[2]->bind(); + buffers[2].bind(); + buffers[2].allocate(positions_selected_points.data(), + static_cast(positions_selected_points.size()*sizeof(double))); + program->enableAttributeArray("vertex"); + program->setAttributeBuffer("vertex",GL_DOUBLE,0,3); + buffers[2].release(); + + vaos[2]->release(); + program->release(); + } + are_buffers_filled = true; + + +} +void Scene_points_with_normal_item::compute_normals_and_vertices(void) +{ + positions_points.resize(0); + positions_lines.resize(0); + positions_selected_points.resize(0); + normals.resize(0); + + positions_points.reserve(m_points->size() * 3); + positions_lines.reserve(m_points->size() * 3 * 2); + + //The points + { + // The *non-selected* points + if (m_points->nb_selected_points()< m_points->size()) + { + + for (Point_set_3::const_iterator it = m_points->begin(); it != m_points->end(); it++) + { + const UI_point& p = *it; + if ( ! p.is_selected() ) + { + positions_points.push_back(p.x()); + positions_points.push_back(p.y()); + positions_points.push_back(p.z()); + } + } + + } + + // Draw *selected* points + if (m_points->nb_selected_points() > 0) + { + ::glPointSize(4.f); // selected => bigger + for (Point_set_3::const_iterator it = m_points->begin(); it != m_points->end(); it++) + { + const UI_point& p = *it; + if (p.is_selected()) + { + positions_selected_points.push_back(p.x()); + positions_selected_points.push_back(p.y()); + positions_selected_points.push_back(p.z()); + } + } + + } + } + + //The lines + { + // Stock normals + Kernel::Sphere_3 region_of_interest = m_points->region_of_interest(); + float normal_length = (float)std::sqrt(region_of_interest.squared_radius() / 1000.); + + // Stock normals of *non-selected* points + if (m_points->nb_selected_points() < m_points->size()) + { + // Stock normals + for (Point_set_3::const_iterator it = m_points->begin(); it != m_points->end(); it++) + { + const UI_point& p = *it; + const Point_set_3::Vector& n = p.normal(); + if (!p.is_selected()) + { + Point_set_3::Point q = p + normal_length * n; + positions_lines.push_back(p.x()); + positions_lines.push_back(p.y()); + positions_lines.push_back(p.z()); + + positions_lines.push_back(q.x()); + positions_lines.push_back(q.y()); + positions_lines.push_back(q.z()); + + } + } + } + + // Stock normals of *selected* points + if (m_points->nb_selected_points() > 0) + { + for (Point_set_3::const_iterator it = m_points->begin(); it != m_points->end(); it++) + { + const UI_point& p = *it; + const Point_set_3::Vector& n = p.normal(); + if (p.is_selected()) + { + Point_set_3::Point q = p + normal_length * n; + positions_lines.push_back(p.x()); + positions_lines.push_back(p.y()); + positions_lines.push_back(p.z()); + + positions_lines.push_back(q.x()); + positions_lines.push_back(q.y()); + positions_lines.push_back(q.z()); + + + } + } + } + } +} + // Duplicates scene item Scene_points_with_normal_item* Scene_points_with_normal_item::clone() const @@ -126,7 +297,7 @@ bool Scene_points_with_normal_item::read_off_point_set(std::istream& stream) std::back_inserter(*m_points), CGAL::make_normal_of_point_with_normal_pmap(Point_set::value_type())) && !isEmpty(); - + changed(); return ok; } @@ -166,6 +337,7 @@ bool Scene_points_with_normal_item::read_xyz_point_set(std::istream& stream) } } } + changed(); return ok; } @@ -196,46 +368,50 @@ Scene_points_with_normal_item::toolTip() const bool Scene_points_with_normal_item::supportsRenderingMode(RenderingMode m) const { return m==Points || - ( has_normals() && - ( m==PointsPlusNormals || m==Splatting ) ); + ( has_normals() && m==PointsPlusNormals ); } -// Points OpenGL drawing in a display list -void Scene_points_with_normal_item::direct_draw() const +void Scene_points_with_normal_item::draw_edges(Viewer_interface* viewer) const { - Q_ASSERT(m_points != NULL); - - // Draw points - m_points->gl_draw_vertices(); + if(!are_buffers_filled) + initialize_buffers(viewer); + vaos[0]->bind(); + program=getShaderProgram(PROGRAM_WITHOUT_LIGHT); + attrib_buffers(viewer,PROGRAM_WITHOUT_LIGHT); + program->bind(); + program->setAttributeValue("colors", this->color()); + qFunc.glDrawArrays(GL_LINES, 0, static_cast(positions_lines.size()/3)); + vaos[0]->release(); + program->release(); } - -// Normals OpenGL drawing -void Scene_points_with_normal_item::draw_normals() const +void Scene_points_with_normal_item::draw_points(Viewer_interface* viewer) const { - Q_ASSERT(m_points != NULL); + if(!are_buffers_filled) + initialize_buffers(viewer); - // Draw normals - Kernel::Sphere_3 region_of_interest = m_points->region_of_interest(); - float normal_length = (float)std::sqrt(region_of_interest.squared_radius() / 1000.); + vaos[1]->bind(); + program=getShaderProgram(PROGRAM_WITHOUT_LIGHT); + attrib_buffers(viewer,PROGRAM_WITHOUT_LIGHT); + program->bind(); + program->setAttributeValue("colors", this->color()); + qFunc.glDrawArrays(GL_POINTS, 0, static_cast(positions_points.size()/3)); + vaos[1]->release(); + program->release(); + GLfloat point_size; + qFunc.glGetFloatv(GL_POINT_SIZE, &point_size); + qFunc.glPointSize(4.f); - m_points->gl_draw_normals(normal_length); + vaos[2]->bind(); + program=getShaderProgram(PROGRAM_WITHOUT_LIGHT); + attrib_buffers(viewer,PROGRAM_WITHOUT_LIGHT); + program->bind(); + program->setAttributeValue("colors", QColor(255,0,0)); + qFunc.glDrawArrays(GL_POINTS, 0, + static_cast(positions_selected_points.size()/3)); + vaos[2]->release(); + program->release(); + qFunc.glPointSize(point_size); } - -void Scene_points_with_normal_item::draw_splats() const -{ - Q_ASSERT(m_points != NULL); - - // Draw splats - bool points_have_normals = (m_points->begin() != m_points->end() && - m_points->begin()->normal() != CGAL::NULL_VECTOR); - bool points_have_radii = (m_points->begin() != m_points->end() && - m_points->begin()->radius() != 0); - if(points_have_normals && points_have_radii) - { - m_points->gl_draw_splats(); - } -} - // Gets wrapped point set Point_set* Scene_points_with_normal_item::point_set() { @@ -298,7 +474,7 @@ QMenu* Scene_points_with_normal_item::contextMenu() QMenu* menu = Scene_item::contextMenu(); // Use dynamic properties: - // http://doc.trolltech.com/lastest/qobject.html#property + // http://doc.qt.io/qt-5/qobject.html#property bool menuChanged = menu->property(prop_name).toBool(); if(!menuChanged) { @@ -333,11 +509,7 @@ QMenu* Scene_points_with_normal_item::contextMenu() void Scene_points_with_normal_item::setRenderingMode(RenderingMode m) { - Scene_item_with_display_list::setRenderingMode(m); - if (rendering_mode==Splatting && (!m_points->are_radii_uptodate())) - { - computes_local_spacing(6); // default value = small - } + Scene_item::setRenderingMode(m); } bool Scene_points_with_normal_item::has_normals() const { return m_has_normals; } @@ -351,5 +523,10 @@ void Scene_points_with_normal_item::set_has_normals(bool b) { } } +void Scene_points_with_normal_item::changed() +{ + compute_normals_and_vertices(); + are_buffers_filled = false; +} #include "Scene_points_with_normal_item.moc" diff --git a/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.h b/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.h index 869f905d83d..2b7ca2a214b 100644 --- a/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.h @@ -1,11 +1,10 @@ #ifndef POINT_SET_ITEM_H #define POINT_SET_ITEM_H - +#include "Scene_item.h" #include "Scene_points_with_normal_item_config.h" #include "Polyhedron_type_fwd.h" #include "Kernel_type.h" #include "Point_set_3.h" -#include "Scene_item_with_display_list.h" #include @@ -19,7 +18,7 @@ class QAction; // This class represents a point set in the OpenGL scene class SCENE_POINTS_WITH_NORMAL_ITEM_EXPORT Scene_points_with_normal_item - : public Scene_item_with_display_list + : public Scene_item { Q_OBJECT @@ -45,17 +44,14 @@ public: // Function for displaying meta-data of the item virtual QString toolTip() const; + virtual void changed(); + // Indicate if rendering mode is supported virtual bool supportsRenderingMode(RenderingMode m) const; - // Points OpenGL drawing in a display list - virtual void direct_draw() const; - // Normals OpenGL drawing - void draw_normals() const; - virtual void draw_edges() const { draw_normals(); }//to tweak scene - // Splat OpenGL drawing - virtual void draw_splats() const; - + virtual void draw_edges(Viewer_interface* viewer) const; + virtual void draw_points(Viewer_interface*) const; + // Gets wrapped point set Point_set* point_set(); const Point_set* point_set() const; @@ -88,6 +84,21 @@ private: QAction* actionDeleteSelection; QAction* actionResetSelection; QAction* actionSelectDuplicatedPoints; + + + std::vector positions_lines; + std::vector positions_points; + std::vector positions_selected_points; + std::vector normals; + + mutable QOpenGLShaderProgram *program; + + using Scene_item::initialize_buffers; + void initialize_buffers(Viewer_interface *viewer) const; + + void compute_normals_and_vertices(void); + + }; // end class Scene_points_with_normal_item diff --git a/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.cpp b/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.cpp index b6882e8dc99..409928f9c01 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.cpp @@ -1,3 +1,6 @@ +#include +#include + #include "Scene_polygon_soup_item.h" #include "Scene_polyhedron_item.h" #include @@ -19,6 +22,17 @@ #include #include +#include +#include +#include +#include +#include + +#include + + + + struct Polyhedron_to_polygon_soup_writer { typedef Kernel::Point_3 Point_3; @@ -62,15 +76,265 @@ struct Polyhedron_to_polygon_soup_writer { } }; // end struct Polyhedron_to_soup_writer +void +Scene_polygon_soup_item::initialize_buffers(Viewer_interface* viewer) const +{ + //vao containing the data for the facets + { + program = getShaderProgram(PROGRAM_WITH_LIGHT, viewer); + program->bind(); + + vaos[0]->bind(); + buffers[0].bind(); + buffers[0].allocate(positions_poly.data(), + static_cast(positions_poly.size()*sizeof(float))); + program->enableAttributeArray("vertex"); + program->setAttributeBuffer("vertex",GL_FLOAT,0,4); + buffers[0].release(); + + + + buffers[1].bind(); + buffers[1].allocate(normals.data(), + static_cast(normals.size()*sizeof(float))); + program->enableAttributeArray("normals"); + program->setAttributeBuffer("normals",GL_FLOAT,0,3); + buffers[1].release(); + + program->release(); + vaos[0]->release(); + + } + //vao containing the data for the edges + { + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT, viewer); + program->bind(); + vaos[1]->bind(); + + buffers[3].bind(); + buffers[3].allocate(positions_lines.data(), + static_cast(positions_lines.size()*sizeof(float))); + program->enableAttributeArray("vertex"); + program->setAttributeBuffer("vertex",GL_FLOAT,0,4); + buffers[3].release(); + + program->release(); + + vaos[1]->release(); + + } + are_buffers_filled = true; +} + +typedef Polyhedron::Traits Traits; +typedef Polygon_soup::Polygon_3 Facet; +typedef CGAL::Triangulation_2_filtered_projection_traits_3 P_traits; +typedef Polyhedron::Halfedge_handle Halfedge_handle; +struct Face_info { + Polyhedron::Halfedge_handle e[3]; + bool is_external; +}; +typedef CGAL::Triangulation_vertex_base_with_info_2 Vb; +typedef CGAL::Triangulation_face_base_with_info_2 Fb1; +typedef CGAL::Constrained_triangulation_face_base_2 Fb; +typedef CGAL::Triangulation_data_structure_2 TDS; +typedef CGAL::No_intersection_tag Itag; +typedef CGAL::Constrained_Delaunay_triangulation_2 CDTbase; +typedef CGAL::Constrained_triangulation_plus_2 CDT; +void +Scene_polygon_soup_item::triangulate_polygon(Polygons_iterator pit) +{ + //Computes the normal of the facet + const Point_3& pa = soup->points[pit->at(0)]; + const Point_3& pb = soup->points[pit->at(1)]; + const Point_3& pc = soup->points[pit->at(2)]; + Traits::Vector_3 normal = CGAL::cross_product(pb-pa, pc -pa); + normal = normal / std::sqrt(normal * normal); + + P_traits cdt_traits(normal); + + CDT cdt(cdt_traits); + + std::size_t it = 0; + std::size_t it_end =pit->size(); + + // Iterates the vector of facet handles + CDT::Vertex_handle previous, first; + do { + + CDT::Vertex_handle vh = cdt.insert(soup->points[pit->at(it)]); + if(first == 0) { + first = vh; + } + if(previous != 0 && previous != vh) { + cdt.insert_constraint(previous, vh); + } + previous = vh; + } while( ++it != it_end ); + + cdt.insert_constraint(previous, first); + + // sets mark is_external + for(CDT::All_faces_iterator + pitt = cdt.all_faces_begin(), + end = cdt.all_faces_end(); + pitt != end; ++pitt) + { + pitt->info().is_external = false; + } + + //check if the facet is external or internal + std::queue face_queue; + face_queue.push(cdt.infinite_vertex()->face()); + while(! face_queue.empty() ) { + CDT::Face_handle fh = face_queue.front(); + face_queue.pop(); + if(fh->info().is_external) continue; + fh->info().is_external = true; + for(int i = 0; i <3; ++i) { + if(!cdt.is_constrained(std::make_pair(fh, i))) + { + face_queue.push(fh->neighbor(i)); + } + } + } + + + //iterates on the internal faces to add the vertices to the positions + //and the normals to the appropriate vectors + int count =0; + for(CDT::Finite_faces_iterator + ffit = cdt.finite_faces_begin(), + end = cdt.finite_faces_end(); + ffit != end; ++ffit) + { + count ++; + if(ffit->info().is_external) + continue; + + positions_poly.push_back(ffit->vertex(0)->point().x()); + positions_poly.push_back(ffit->vertex(0)->point().y()); + positions_poly.push_back(ffit->vertex(0)->point().z()); + positions_poly.push_back(1.0); + + positions_poly.push_back(ffit->vertex(1)->point().x()); + positions_poly.push_back(ffit->vertex(1)->point().y()); + positions_poly.push_back(ffit->vertex(1)->point().z()); + positions_poly.push_back(1.0); + + positions_poly.push_back(ffit->vertex(2)->point().x()); + positions_poly.push_back(ffit->vertex(2)->point().y()); + positions_poly.push_back(ffit->vertex(2)->point().z()); + positions_poly.push_back(1.0); + + + const Point_3& pa = soup->points[pit->at(0)]; + const Point_3& pb = soup->points[pit->at(1)]; + const Point_3& pc = soup->points[pit->at(2)]; + + Kernel::Vector_3 n = CGAL::cross_product(pb-pa, pc -pa); + n = n / std::sqrt(n * n); + + normals.push_back(n.x()); + normals.push_back(n.y()); + normals.push_back(n.z()); + + normals.push_back(n.x()); + normals.push_back(n.y()); + normals.push_back(n.z()); + + + normals.push_back(n.x()); + normals.push_back(n.y()); + normals.push_back(n.z()); + + + } +} +void +Scene_polygon_soup_item::compute_normals_and_vertices(){ + //get the vertices and normals + + typedef Polygon_soup::Polygons::size_type size_type; + positions_poly.resize(0); + positions_lines.resize(0); + normals.resize(0); + for(Polygons_iterator it = soup->polygons.begin(); + it != soup->polygons.end(); ++it) + { + if(it->size()!=3) + { + triangulate_polygon(it); + } + else{ + + const Point_3& pa = soup->points[it->at(0)]; + const Point_3& pb = soup->points[it->at(1)]; + const Point_3& pc = soup->points[it->at(2)]; + + Kernel::Vector_3 n = CGAL::cross_product(pb-pa, pc -pa); + n = n / std::sqrt(n * n); + + normals.push_back(n.x()); + normals.push_back(n.y()); + normals.push_back(n.z()); + + normals.push_back(n.x()); + normals.push_back(n.y()); + normals.push_back(n.z()); + + + normals.push_back(n.x()); + normals.push_back(n.y()); + normals.push_back(n.z()); + + + for(size_type i = 0; i < it->size(); ++i) + { + const Point_3& p = soup->points[it->at(i)]; + positions_poly.push_back(p.x()); + positions_poly.push_back(p.y()); + positions_poly.push_back(p.z()); + positions_poly.push_back(1.0); + } + } + + //Lines + for(size_type i = 0; i < it->size(); ++i) + { + + const Point_3& pa = soup->points[it->at(i)]; + const Point_3& pb = soup->points[it->at((i+1)%it->size())]; + positions_lines.push_back(pa.x()); + positions_lines.push_back(pa.y()); + positions_lines.push_back(pa.z()); + positions_lines.push_back(1.0); + + positions_lines.push_back(pb.x()); + positions_lines.push_back(pb.y()); + positions_lines.push_back(pb.z()); + positions_lines.push_back(1.0); + } + } + +} + + Scene_polygon_soup_item::Scene_polygon_soup_item() - : Scene_item_with_display_list(), + : Scene_item(4,2), soup(0), oriented(false) { + qFunc.initializeOpenGLFunctions(); } Scene_polygon_soup_item::~Scene_polygon_soup_item() { + delete soup; } @@ -82,12 +346,16 @@ Scene_polygon_soup_item::clone() const { return new_soup; } + bool Scene_polygon_soup_item::load(std::istream& in) { if (!soup) soup=new Polygon_soup(); else soup->clear(); - return CGAL::read_OFF(in, soup->points, soup->polygons); + + bool result = CGAL::read_OFF(in, soup->points, soup->polygons); + Q_EMIT changed(); + return result; } void Scene_polygon_soup_item::init_polygon_soup(std::size_t nb_pts, std::size_t nb_polygons){ @@ -121,12 +389,14 @@ void Scene_polygon_soup_item::load(Scene_polyhedron_item* poly_item) { void Scene_polygon_soup_item::setDisplayNonManifoldEdges(const bool b) { + soup->display_non_manifold_edges = b; changed(); } bool Scene_polygon_soup_item::displayNonManifoldEdges() const { + return soup->display_non_manifold_edges; } @@ -155,7 +425,8 @@ void Scene_polygon_soup_item::inside_out() bool Scene_polygon_soup_item::orient() { - if(isEmpty() || oriented) + + if(isEmpty() || this->oriented) return true; // nothing to do oriented=true; @@ -186,6 +457,7 @@ Scene_polygon_soup_item::orient() bool Scene_polygon_soup_item::save(std::ostream& out) const { + typedef Polygon_soup::size_type size_type; CGAL::File_writer_OFF writer; writer.write_header(out, @@ -231,10 +503,10 @@ Scene_polygon_soup_item::exportAsPolyhedron(Polyhedron* out_polyhedron) } return false; } - QString Scene_polygon_soup_item::toolTip() const { + if(!soup) return QString(); @@ -250,71 +522,89 @@ Scene_polygon_soup_item::toolTip() const } void -Scene_polygon_soup_item::direct_draw() const { - typedef Polygon_soup::Polygons::const_iterator Polygons_iterator; - typedef Polygon_soup::Polygons::size_type size_type; - for(Polygons_iterator it = soup->polygons.begin(); - it != soup->polygons.end(); ++it) +Scene_polygon_soup_item::draw(Viewer_interface* viewer) const { + if(!are_buffers_filled) { - const Point_3& pa = soup->points[it->at(0)]; - const Point_3& pb = soup->points[it->at(1)]; - const Point_3& pc = soup->points[it->at(2)]; - - Kernel::Vector_3 n = CGAL::cross_product(pb-pa, pc -pa); - n = n / std::sqrt(n * n); - - ::glBegin(GL_POLYGON); - ::glNormal3d(n.x(),n.y(),n.z()); - - for(size_type i = 0; i < it->size(); ++i) { - const Point_3& p = soup->points[it->at(i)]; - ::glVertex3d(p.x(),p.y(),p.z()); + initialize_buffers(viewer); } - ::glEnd(); - } - if(soup->display_non_manifold_edges) { - double current_color[4]; - GLboolean lightning; - ::glGetDoublev(GL_CURRENT_COLOR, current_color); - ::glColor3d(1., 0., 0.); // red - ::glGetBooleanv(GL_LIGHTING, &lightning); - ::glDisable(GL_LIGHTING); + if(soup == 0) return; + //Calls the buffer info again so that it's the right one used even if + //there are several objects drawn + vaos[0]->bind(); + attrib_buffers(viewer,PROGRAM_WITH_LIGHT); + //fills the arraw of colors with the current color - BOOST_FOREACH(const Polygon_soup::Edge& edge, - soup->non_manifold_edges) + QColor v_colors = this->color(); + // tells the GPU to use the program just created + program = getShaderProgram(PROGRAM_WITH_LIGHT); + program->bind(); + program->setAttributeValue("colors", v_colors); + //draw the polygons + // the third argument is the number of vec4 that will be entered + qFunc.glDrawArrays(GL_TRIANGLES, 0, static_cast(positions_poly.size()/4)); + // Clean-up + program->release(); + vaos[0]->release(); + + } + +void +Scene_polygon_soup_item::draw_points(Viewer_interface* viewer) const { + if(!are_buffers_filled) { - const Point_3& a = soup->points[edge[0]]; - const Point_3& b = soup->points[edge[1]]; - ::glBegin(GL_LINES); - ::glVertex3d(a.x(), a.y(), a.z()); - ::glVertex3d(b.x(), b.y(), b.z()); - ::glEnd(); - } - if(lightning) glEnable(GL_LIGHTING); - ::glColor4dv(current_color); + initialize_buffers(viewer); } + if(soup == 0) return; + vaos[1]->bind(); + attrib_buffers(viewer,PROGRAM_WITHOUT_LIGHT); + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT); + program->bind(); + QColor color = this->color(); + program->setAttributeValue("colors", color); + //draw the points + qFunc.glDrawArrays(GL_POINTS, 0, static_cast(positions_lines.size()/4)); + // Clean-up + program->release(); + vaos[1]->release(); } void -Scene_polygon_soup_item::draw_points() const { - if(soup == 0) return; - ::glBegin(GL_POINTS); - for(Polygon_soup::Points::const_iterator pit = soup->points.begin(), - end = soup->points.end(); - pit != end; ++pit) +Scene_polygon_soup_item::draw_edges(Viewer_interface* viewer) const { + if(!are_buffers_filled) { - ::glVertex3d(pit->x(), pit->y(), pit->z()); + initialize_buffers(viewer); } - ::glEnd(); + if(soup == 0) return; + + vaos[1]->bind(); + attrib_buffers(viewer,PROGRAM_WITHOUT_LIGHT); + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT); + program->bind(); + QColor color=QColor(0,0,0); + + program->setAttributeValue("colors", color); + //draw the edges + qFunc.glDrawArrays(GL_LINES, 0,static_cast( positions_lines.size()/4)); + // Clean-up + program->release(); + vaos[1]->release(); } bool Scene_polygon_soup_item::isEmpty() const { + return (soup == 0 || soup->points.empty()); } +void +Scene_polygon_soup_item::changed() +{ + compute_normals_and_vertices(); + are_buffers_filled = false; +} Scene_polygon_soup_item::Bbox Scene_polygon_soup_item::bbox() const { + const Point_3& p = *(soup->points.begin()); CGAL::Bbox_3 bbox(p.x(), p.y(), p.z(), p.x(), p.y(), p.z()); for(Polygon_soup::Points::const_iterator it = soup->points.begin(); @@ -340,6 +630,7 @@ Scene_polygon_soup_item::new_triangle(const std::size_t i, const std::size_t j, const std::size_t k) { + Polygon_soup::Polygon_3 new_polygon(3); new_polygon[0] = i; new_polygon[1] = j; @@ -348,3 +639,8 @@ Scene_polygon_soup_item::new_triangle(const std::size_t i, } #include "Scene_polygon_soup_item.moc" + +// Local Variables: +// c-basic-offset: 4 +// End: + diff --git a/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.h b/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.h index 4c45bc95979..ce5b20df643 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.h @@ -1,8 +1,8 @@ #ifndef SCENE_POLYGON_SOUP_ITEM_H #define SCENE_POLYGON_SOUP_ITEM_H - #include "Scene_polygon_soup_item_config.h" -#include "Scene_item_with_display_list.h" +#include "Scene_item.h" +#include "Viewer.h" #include "Polyhedron_type.h" #include @@ -13,154 +13,169 @@ struct Polygon_soup { - typedef Kernel::Point_3 Point_3; - typedef std::vector Points; - typedef std::vector Polygon_3; - typedef std::map, std::set > Edges_map; - typedef boost::array Edge; - typedef std::vector Polygons; - typedef std::set Edges; - typedef Polygons::size_type size_type; - Points points; - Polygons polygons; - Edges_map edges; - Edges non_manifold_edges; - bool display_non_manifold_edges; + typedef Kernel::Point_3 Point_3; + typedef std::vector Points; + typedef std::vector Polygon_3; + typedef std::map, std::set > Edges_map; + typedef boost::array Edge; + typedef std::vector Polygons; + typedef std::set Edges; + typedef Polygons::size_type size_type; + Points points; + Polygons polygons; + Edges_map edges; + Edges non_manifold_edges; + bool display_non_manifold_edges; - Polygon_soup(): - display_non_manifold_edges(false){} + Polygon_soup(): + display_non_manifold_edges(false){} - Polygon_soup* clone() const { - Polygon_soup* result = new Polygon_soup(); - result->points = points; - result->polygons = polygons; - result->edges = edges; - result->non_manifold_edges = non_manifold_edges; - result->display_non_manifold_edges = display_non_manifold_edges; - return result; - } - - void clear() { - points.clear(); - polygons.clear(); - edges.clear(); - non_manifold_edges.clear(); - } - - void fill_edges() { - // Fill edges - edges.clear(); - for(size_type i = 0; i < polygons.size(); ++i) - { - const size_type size = polygons[i].size(); - for(size_type j = 0; j < size; ++j) { - const std::size_t& i0 = polygons[i][j]; - const std::size_t& i1 = polygons[i][ j+1 < size ? j+1: 0]; - edges[std::make_pair(i0, i1)].insert(i); -// qDebug() << tr("edges[std::make_pair(%1, %2)].insert(%3). Size=%4") -// .arg(i0).arg(i1).arg(i).arg(edges[std::make_pair(i0, i1)].size()); - } + Polygon_soup* clone() const { + Polygon_soup* result = new Polygon_soup(); + result->points = points; + result->polygons = polygons; + result->edges = edges; + result->non_manifold_edges = non_manifold_edges; + result->display_non_manifold_edges = display_non_manifold_edges; + return result; } - // Fill non-manifold edges - non_manifold_edges.clear(); - for(size_type i = 0; i < polygons.size(); ++i) - { - const size_type size = polygons[i].size(); - for(size_type j = 0; j < size; ++j) { - const std::size_t& i0 = polygons[i][j]; - const std::size_t& i1 = polygons[i][ j+1 < size ? j+1: 0]; - if( (i0 < i1) && - (edges[std::make_pair(i0, i1)].size() + - edges[std::make_pair(i1, i0)].size() > 2) ) + void clear() { + points.clear(); + polygons.clear(); + edges.clear(); + non_manifold_edges.clear(); + } + + void fill_edges() { + // Fill edges + edges.clear(); + for(size_type i = 0; i < polygons.size(); ++i) { - Edge edge; - edge[0] = i0; - edge[1] = i1; - if(i0 > i1) std::swap(edge[0], edge[1]); - non_manifold_edges.insert(edge); + const size_type size = polygons[i].size(); + for(size_type j = 0; j < size; ++j) { + const std::size_t& i0 = polygons[i][j]; + const std::size_t& i1 = polygons[i][ j+1 < size ? j+1: 0]; + edges[std::make_pair(i0, i1)].insert(i); + // qDebug() << tr("edges[std::make_pair(%1, %2)].insert(%3). Size=%4") + // .arg(i0).arg(i1).arg(i).arg(edges[std::make_pair(i0, i1)].size()); + } } - } - } - } - void inverse_orientation(const std::size_t index) { - std::reverse(polygons[index].begin(), polygons[index].end()); - } + // Fill non-manifold edges + non_manifold_edges.clear(); + for(size_type i = 0; i < polygons.size(); ++i) + { + const size_type size = polygons[i].size(); + for(size_type j = 0; j < size; ++j) { + const std::size_t& i0 = polygons[i][j]; + const std::size_t& i1 = polygons[i][ j+1 < size ? j+1: 0]; + + if( (i0 < i1) && + (edges[std::make_pair(i0, i1)].size() + + edges[std::make_pair(i1, i0)].size() > 2) ) + { + Edge edge; + edge[0] = i0; + edge[1] = i1; + if(i0 > i1) std::swap(edge[0], edge[1]); + non_manifold_edges.insert(edge); + + } + } + } + } + + void inverse_orientation(const std::size_t index) { + std::reverse(polygons[index].begin(), polygons[index].end()); + } }; class Scene_polyhedron_item; class SCENE_POLYGON_SOUP_ITEM_EXPORT Scene_polygon_soup_item - : public Scene_item_with_display_list + : public Scene_item { - typedef Kernel::Point_3 Point_3; + typedef Kernel::Point_3 Point_3; - Q_OBJECT + Q_OBJECT public: - Scene_polygon_soup_item(); - ~Scene_polygon_soup_item(); + Scene_polygon_soup_item(); + ~Scene_polygon_soup_item(); - Scene_polygon_soup_item* clone() const; - bool load(std::istream& in); - void load(Scene_polyhedron_item*); + Scene_polygon_soup_item* clone() const; + bool load(std::istream& in); + void load(Scene_polyhedron_item*); - template - inline void load(const std::vector& points, const std::vector& polygons) - { - if(!soup) - soup = new Polygon_soup; - soup->clear(); + template + inline void load(const std::vector& points, const std::vector& polygons) + { + if(!soup) + soup = new Polygon_soup; + soup->clear(); - /// add points - soup->points.reserve(points.size()); - BOOST_FOREACH(const Point& p, points) - soup->points.push_back( Point_3(p[0], p[1], p[2]) ); + /// add points + soup->points.reserve(points.size()); + BOOST_FOREACH(const Point& p, points) + soup->points.push_back( Point_3(p[0], p[1], p[2]) ); - /// add polygons - std::size_t nb_polygons=polygons.size(); - soup->polygons.resize(nb_polygons); - for(std::size_t i=0; ipolygons[i].assign(polygons[i].begin(), polygons[i].end()); + /// add polygons + std::size_t nb_polygons=polygons.size(); + soup->polygons.resize(nb_polygons); + for(std::size_t i=0; ipolygons[i].assign(polygons[i].begin(), polygons[i].end()); - /// fill non-manifold edges container - soup->fill_edges(); - oriented = false; - } + /// fill non-manifold edges container + soup->fill_edges(); + oriented = false; + } - bool save(std::ostream& out) const; + bool save(std::ostream& out) const; - QString toolTip() const; + QString toolTip() const; - // Indicate if rendering mode is supported - virtual bool supportsRenderingMode(RenderingMode m) const { return (m!=Gouraud && m!=PointsPlusNormals && m!=Splatting); } // CHECK THIS! - // OpenGL drawing in a display list - void direct_draw() const; - void draw_points() const; + // Indicate if rendering mode is supported + virtual bool supportsRenderingMode(RenderingMode m) const { return (m!=Gouraud && m!=PointsPlusNormals); } // CHECK THIS! + // OpenGL drawing in a display list + virtual void draw() const {} + virtual void draw(Viewer_interface*) const; + virtual void draw_points(Viewer_interface*) const; + virtual void draw_edges(Viewer_interface* viewer) const; + void changed(); + bool isFinite() const { return true; } + bool isEmpty() const; + Bbox bbox() const; - bool isFinite() const { return true; } - bool isEmpty() const; - Bbox bbox() const; + void new_vertex(const double&, const double&, const double&); + void new_triangle(const std::size_t, const std::size_t, const std::size_t); - void new_vertex(const double&, const double&, const double&); - void new_triangle(const std::size_t, const std::size_t, const std::size_t); - - void init_polygon_soup(std::size_t nb_pts, std::size_t nb_polygons); - void finalize_polygon_soup(); + void init_polygon_soup(std::size_t nb_pts, std::size_t nb_polygons); + void finalize_polygon_soup(); public Q_SLOTS: - void shuffle_orientations(); - bool orient(); - bool exportAsPolyhedron(Polyhedron*); - void inside_out(); + void shuffle_orientations(); + bool orient(); + bool exportAsPolyhedron(Polyhedron*); + void inside_out(); - void setDisplayNonManifoldEdges(const bool); - bool displayNonManifoldEdges() const; + void setDisplayNonManifoldEdges(const bool); + bool displayNonManifoldEdges() const; private: - Polygon_soup* soup; - bool oriented; + typedef Polygon_soup::Polygons::const_iterator Polygons_iterator; + Polygon_soup* soup; + bool oriented; + std::vector positions_poly; + std::vector positions_lines; + std::vector normals; + + using Scene_item::initialize_buffers; + void initialize_buffers(Viewer_interface *viewer) const; + void compute_normals_and_vertices(void); + void triangulate_polygon(Polygons_iterator ); + mutable QOpenGLShaderProgram *program; + }; // end class Scene_polygon_soup_item #endif // SCENE_POLYGON_SOUP_ITEM_H diff --git a/Polyhedron/demo/Polyhedron/Scene_polyhedron_item.cpp b/Polyhedron/demo/Polyhedron/Scene_polyhedron_item.cpp index 5eb882ca054..f1cba5c3193 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polyhedron_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_polyhedron_item.cpp @@ -1,58 +1,303 @@ -#include +#include #include "Scene_polyhedron_item.h" +#include #include "Kernel_type.h" -#include "Polyhedron_type.h" #include #include #include #include + + +#include +#include +#include +#include +#include +#include + #include #include +#include +#include +#include + #include typedef CGAL::AABB_face_graph_triangle_primitive Primitive; typedef CGAL::AABB_traits AABB_traits; typedef CGAL::AABB_tree Input_facets_AABB_tree; - const char* aabb_property_name = "Scene_polyhedron_item aabb tree"; Input_facets_AABB_tree* get_aabb_tree(Scene_polyhedron_item* item) { - QVariant aabb_tree_property = item->property(aabb_property_name); - if(aabb_tree_property.isValid()) { - void* ptr = aabb_tree_property.value(); - return static_cast(ptr); - } - else { - Polyhedron* poly = item->polyhedron(); - if(poly) { - Input_facets_AABB_tree* tree = - new Input_facets_AABB_tree(faces(*poly).first, - faces(*poly).second, - *poly); - item->setProperty(aabb_property_name, - QVariant::fromValue(tree)); - return tree; + QVariant aabb_tree_property = item->property(aabb_property_name); + if(aabb_tree_property.isValid()) { + void* ptr = aabb_tree_property.value(); + return static_cast(ptr); + } + else { + Polyhedron* poly = item->polyhedron(); + if(poly) { + Input_facets_AABB_tree* tree = + new Input_facets_AABB_tree(faces(*poly).first, + faces(*poly).second, + *poly); + item->setProperty(aabb_property_name, + QVariant::fromValue(tree)); + return tree; + } + else return 0; } - else return 0; - } } void delete_aabb_tree(Scene_polyhedron_item* item) { - QVariant aabb_tree_property = item->property(aabb_property_name); - if(aabb_tree_property.isValid()) { - void* ptr = aabb_tree_property.value(); - Input_facets_AABB_tree* tree = static_cast(ptr); - if(tree) { - delete tree; - tree = 0; + QVariant aabb_tree_property = item->property(aabb_property_name); + if(aabb_tree_property.isValid()) { + void* ptr = aabb_tree_property.value(); + Input_facets_AABB_tree* tree = static_cast(ptr); + if(tree) { + delete tree; + tree = 0; + } + item->setProperty(aabb_property_name, QVariant()); + } +} + +typedef Polyhedron::Traits Traits; +typedef Polyhedron::Facet Facet; +typedef CGAL::Triangulation_2_filtered_projection_traits_3 P_traits; +typedef Polyhedron::Halfedge_handle Halfedge_handle; +struct Face_info { + Polyhedron::Halfedge_handle e[3]; + bool is_external; +}; +typedef CGAL::Triangulation_vertex_base_with_info_2 Vb; +typedef CGAL::Triangulation_face_base_with_info_2 Fb1; +typedef CGAL::Constrained_triangulation_face_base_2 Fb; +typedef CGAL::Triangulation_data_structure_2 TDS; +typedef CGAL::No_intersection_tag Itag; +typedef CGAL::Constrained_Delaunay_triangulation_2 CDTbase; +typedef CGAL::Constrained_triangulation_plus_2 CDT; + +//Make sure all the facets are triangles +void +Scene_polyhedron_item::is_Triangulated() +{ + typedef Polyhedron::Halfedge_around_facet_circulator HF_circulator; + Facet_iterator f = poly->facets_begin(); + int nb_points_per_facet =0; + + for(f = poly->facets_begin(); + f != poly->facets_end(); + f++) + { + HF_circulator he = f->facet_begin(); + HF_circulator end = he; + CGAL_For_all(he,end) + { + nb_points_per_facet++; + } + + if(nb_points_per_facet !=3) + { + is_Triangle = false; + break; + } + + nb_points_per_facet = 0; + } +} +void +Scene_polyhedron_item::triangulate_facet(Facet_iterator fit) +{ + //Computes the normal of the facet + Traits::Vector_3 normal = + compute_facet_normal(*fit); + + P_traits cdt_traits(normal); + CDT cdt(cdt_traits); + + Facet::Halfedge_around_facet_circulator + he_circ = fit->facet_begin(), + he_circ_end(he_circ); + + // Iterates on the vector of facet handles + CDT::Vertex_handle previous, first; + do { + CDT::Vertex_handle vh = cdt.insert(he_circ->vertex()->point()); + if(first == 0) { + first = vh; + } + vh->info() = he_circ; + if(previous != 0 && previous != vh) { + cdt.insert_constraint(previous, vh); + } + previous = vh; + } while( ++he_circ != he_circ_end ); + cdt.insert_constraint(previous, first); + + // sets mark is_external + for(CDT::All_faces_iterator + fit2 = cdt.all_faces_begin(), + end = cdt.all_faces_end(); + fit2 != end; ++fit2) + { + fit2->info().is_external = false; + } + //check if the facet is external or internal + std::queue face_queue; + face_queue.push(cdt.infinite_vertex()->face()); + while(! face_queue.empty() ) { + CDT::Face_handle fh = face_queue.front(); + face_queue.pop(); + if(fh->info().is_external) continue; + fh->info().is_external = true; + for(int i = 0; i <3; ++i) { + if(!cdt.is_constrained(std::make_pair(fh, i))) + { + face_queue.push(fh->neighbor(i)); + } + } + } + + //iterates on the internal faces to add the vertices to the positions + //and the normals to the appropriate vectors + for(CDT::Finite_faces_iterator + ffit = cdt.finite_faces_begin(), + end = cdt.finite_faces_end(); + ffit != end; ++ffit) + { + if(ffit->info().is_external) + continue; + + positions_facets.push_back(ffit->vertex(0)->point().x()); + positions_facets.push_back(ffit->vertex(0)->point().y()); + positions_facets.push_back(ffit->vertex(0)->point().z()); + positions_facets.push_back(1.0); + + positions_facets.push_back(ffit->vertex(1)->point().x()); + positions_facets.push_back(ffit->vertex(1)->point().y()); + positions_facets.push_back(ffit->vertex(1)->point().z()); + positions_facets.push_back(1.0); + + positions_facets.push_back(ffit->vertex(2)->point().x()); + positions_facets.push_back(ffit->vertex(2)->point().y()); + positions_facets.push_back(ffit->vertex(2)->point().z()); + positions_facets.push_back(1.0); + + if (cur_shading == Flat || cur_shading == FlatPlusEdges || cur_shading == Gouraud) + { + + typedef Kernel::Vector_3 Vector; + Vector n = compute_facet_normal(*fit); + normals.push_back(n.x()); + normals.push_back(n.y()); + normals.push_back(n.z()); + + normals.push_back(n.x()); + normals.push_back(n.y()); + normals.push_back(n.z()); + + normals.push_back(n.x()); + normals.push_back(n.y()); + normals.push_back(n.z()); + } + + } +} + +void +Scene_polyhedron_item::triangulate_facet_color(Facet_iterator fit) +{ + Traits::Vector_3 normal = + compute_facet_normal(*fit); + + P_traits cdt_traits(normal); + CDT cdt(cdt_traits); + + Facet::Halfedge_around_facet_circulator + he_circ = fit->facet_begin(), + he_circ_end(he_circ); + + // Iterates on the vector of facet handles + CDT::Vertex_handle previous, first; + do { + CDT::Vertex_handle vh = cdt.insert(he_circ->vertex()->point()); + if(first == 0) { + first = vh; + } + vh->info() = he_circ; + if(previous != 0 && previous != vh) { + cdt.insert_constraint(previous, vh); + } + previous = vh; + } while( ++he_circ != he_circ_end ); + cdt.insert_constraint(previous, first); + + // sets mark is_external + for(CDT::All_faces_iterator + afit = cdt.all_faces_begin(), + end = cdt.all_faces_end(); + afit != end; ++afit) + { + afit->info().is_external = false; + } + //check if the facet is external or internal + std::queue face_queue; + face_queue.push(cdt.infinite_vertex()->face()); + while(! face_queue.empty() ) { + CDT::Face_handle fh = face_queue.front(); + face_queue.pop(); + if(fh->info().is_external) continue; + fh->info().is_external = true; + for(int i = 0; i <3; ++i) { + if(!cdt.is_constrained(std::make_pair(fh, i))) + { + face_queue.push(fh->neighbor(i)); + } + } + } + + //iterates on the internal faces to add the vertices to the positions vector + for(CDT::Finite_faces_iterator + ffit = cdt.finite_faces_begin(), + end = cdt.finite_faces_end(); + ffit != end; ++ffit) + { + if(ffit->info().is_external) + continue; + //Add Colors + for(int i = 0; i<3; ++i) + { + const int this_patch_id = fit->patch_id(); + + color_facets_selected.push_back(colors_[this_patch_id].lighter(120).redF()); + color_facets_selected.push_back(colors_[this_patch_id].lighter(120).greenF()); + color_facets_selected.push_back(colors_[this_patch_id].lighter(120).blueF()); + + color_facets_selected.push_back(colors_[this_patch_id].lighter(120).redF()); + color_facets_selected.push_back(colors_[this_patch_id].lighter(120).greenF()); + color_facets_selected.push_back(colors_[this_patch_id].lighter(120).blueF()); + + color_facets.push_back(colors_[this_patch_id].redF()); + color_facets.push_back(colors_[this_patch_id].greenF()); + color_facets.push_back(colors_[this_patch_id].blueF()); + + color_facets.push_back(colors_[this_patch_id].redF()); + color_facets.push_back(colors_[this_patch_id].greenF()); + color_facets.push_back(colors_[this_patch_id].blueF()); + + + } } - item->setProperty(aabb_property_name, QVariant()); - } } #include @@ -60,50 +305,383 @@ void delete_aabb_tree(Scene_polyhedron_item* item) #include #include -Scene_polyhedron_item::Scene_polyhedron_item() - : Scene_item_with_display_list(), - poly(new Polyhedron), - show_only_feature_edges_m(false), - facet_picking_m(false), - erase_next_picked_facet_m(false), - plugin_has_set_color_vector_m(false) + +void +Scene_polyhedron_item::initialize_buffers(Viewer_interface* viewer) const { - //init(); + //vao containing the data for the unselected facets + { + program = getShaderProgram(PROGRAM_WITH_LIGHT, viewer); + program->bind(); + vaos[0]->bind(); + buffers[0].bind(); + buffers[0].allocate(positions_facets.data(), + static_cast(positions_facets.size()*sizeof(float))); + program->enableAttributeArray("vertex"); + program->setAttributeBuffer("vertex",GL_FLOAT,0,4); + buffers[0].release(); + + + + buffers[1].bind(); + buffers[1].allocate(normals.data(), + static_cast(normals.size()*sizeof(float))); + program->enableAttributeArray("normals"); + program->setAttributeBuffer("normals",GL_FLOAT,0,3); + buffers[1].release(); + + buffers[2].bind(); + buffers[2].allocate(color_facets.data(), + static_cast(color_facets.size()*sizeof(float))); + program->enableAttributeArray("colors"); + program->setAttributeBuffer("colors",GL_FLOAT,0,3); + buffers[2].release(); + vaos[0]->release(); + program->release(); + + } + //vao containing the data for the unselected lines + { + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT, viewer); + program->bind(); + vaos[1]->bind(); + + buffers[3].bind(); + buffers[3].allocate(positions_lines.data(), + static_cast(positions_lines.size()*sizeof(float))); + program->enableAttributeArray("vertex"); + program->setAttributeBuffer("vertex",GL_FLOAT,0,4); + buffers[3].release(); + + buffers[4].bind(); + buffers[4].allocate(color_lines.data(), + static_cast(color_lines.size()*sizeof(float))); + program->enableAttributeArray("colors"); + program->setAttributeBuffer("colors",GL_FLOAT,0,3); + buffers[4].release(); + program->release(); + + vaos[1]->release(); + + } + //vao containing the data for the selected facets + { + program = getShaderProgram(PROGRAM_WITH_LIGHT, viewer); + program->bind(); + vaos[2]->bind(); + + + buffers[5].bind(); + buffers[5].allocate(positions_facets.data(), + static_cast(positions_facets.size()*sizeof(float))); + program->enableAttributeArray("vertex"); + program->setAttributeBuffer("vertex",GL_FLOAT,0,4); + buffers[5].release(); + + buffers[6].bind(); + buffers[6].allocate(normals.data(), + static_cast(normals.size()*sizeof(float))); + program->enableAttributeArray("normals"); + program->setAttributeBuffer("normals",GL_FLOAT,0,3); + buffers[6].release(); + + + buffers[7].bind(); + buffers[7].allocate(color_facets_selected.data(), + static_cast(color_facets_selected.size()*sizeof(float))); + program->enableAttributeArray("colors"); + program->setAttributeBuffer("colors",GL_FLOAT,0,3); + buffers[7].release(); + program->release(); + + vaos[2]->release(); + } + //vao containing the data for the selected lines + { + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT, viewer); + vaos[3]->bind(); + program->bind(); + buffers[8].bind(); + buffers[8].allocate(positions_lines.data(), + static_cast(positions_lines.size()*sizeof(float))); + program->enableAttributeArray("vertex"); + program->setAttributeBuffer("vertex",GL_FLOAT,0,4); + buffers[8].release(); + + buffers[9].bind(); + buffers[9].allocate(color_lines_selected.data(), + static_cast(color_lines_selected.size()*sizeof(float))); + program->enableAttributeArray("colors"); + program->setAttributeBuffer("colors",GL_FLOAT,0,3); + buffers[9].release(); + program->release(); + + vaos[3]->release(); + } + are_buffers_filled = true; +} + +void +Scene_polyhedron_item::compute_normals_and_vertices(void) +{ + positions_facets.resize(0); + positions_lines.resize(0); + normals.resize(0); + + + //Facets + typedef Polyhedron::Traits Kernel; + typedef Kernel::Point_3 Point; + typedef Kernel::Vector_3 Vector; + typedef Polyhedron::Facet Facet; + typedef Polyhedron::Facet_iterator Facet_iterator; + typedef Polyhedron::Halfedge_around_facet_circulator HF_circulator; + + + + Facet_iterator f = poly->facets_begin(); + + for(f = poly->facets_begin(); + f != poly->facets_end(); + f++) + { + + if(!is_Triangle) + triangulate_facet(f); + else + { + HF_circulator he = f->facet_begin(); + HF_circulator end = he; + CGAL_For_all(he,end) + { + + // If Flat shading:1 normal per polygon added once per vertex + if (cur_shading == FlatPlusEdges || cur_shading == Flat ) + { + + Vector n = compute_facet_normal(*f); + normals.push_back(n.x()); + normals.push_back(n.y()); + normals.push_back(n.z()); + } + + // If Gouraud shading: 1 normal per vertex + else if (cur_shading == Gouraud) + { + + Vector n = compute_vertex_normal(*he->vertex()); + normals.push_back(n.x()); + normals.push_back(n.y()); + normals.push_back(n.z()); + } + + //position + const Point& p = he->vertex()->point(); + positions_facets.push_back(p.x()); + positions_facets.push_back(p.y()); + positions_facets.push_back(p.z()); + positions_facets.push_back(1.0); + } + } + } + //Lines + typedef Kernel::Point_3 Point; + typedef Polyhedron::Edge_iterator Edge_iterator; + + Edge_iterator he; + if(!show_only_feature_edges_m) { + for(he = poly->edges_begin(); + he != poly->edges_end(); + he++) + { + if(he->is_feature_edge()) continue; + const Point& a = he->vertex()->point(); + const Point& b = he->opposite()->vertex()->point(); + positions_lines.push_back(a.x()); + positions_lines.push_back(a.y()); + positions_lines.push_back(a.z()); + positions_lines.push_back(1.0); + + positions_lines.push_back(b.x()); + positions_lines.push_back(b.y()); + positions_lines.push_back(b.z()); + positions_lines.push_back(1.0); + + } + } + for(he = poly->edges_begin(); + he != poly->edges_end(); + he++) + { + if(!he->is_feature_edge()) continue; + const Point& a = he->vertex()->point(); + const Point& b = he->opposite()->vertex()->point(); + + positions_lines.push_back(a.x()); + positions_lines.push_back(a.y()); + positions_lines.push_back(a.z()); + positions_lines.push_back(1.0); + + positions_lines.push_back(b.x()); + positions_lines.push_back(b.y()); + positions_lines.push_back(b.z()); + positions_lines.push_back(1.0); + + + } + + + //set the colors + compute_colors(); +} + +void +Scene_polyhedron_item::compute_colors() +{ + color_lines.resize(0); + color_facets.resize(0); + color_lines_selected.resize(0); + color_facets_selected.resize(0); + //Facets + typedef Polyhedron::Facet_iterator Facet_iterator; + typedef Polyhedron::Halfedge_around_facet_circulator HF_circulator; + + + + // int patch_id = -1; + // Facet_iterator f = poly->facets_begin(); + + for(Facet_iterator f = poly->facets_begin(); + f != poly->facets_end(); + f++) + { + if(!is_Triangle) + triangulate_facet_color(f); + else + { + HF_circulator he = f->facet_begin(); + HF_circulator end = he; + CGAL_For_all(he,end) + { + + const int this_patch_id = f->patch_id(); + + color_facets_selected.push_back(colors_[this_patch_id].lighter(120).redF()); + color_facets_selected.push_back(colors_[this_patch_id].lighter(120).greenF()); + color_facets_selected.push_back(colors_[this_patch_id].lighter(120).blueF()); + + color_facets.push_back(colors_[this_patch_id].redF()); + color_facets.push_back(colors_[this_patch_id].greenF()); + color_facets.push_back(colors_[this_patch_id].blueF()); + + } + + } + } + //Lines + typedef Polyhedron::Edge_iterator Edge_iterator; + + Edge_iterator he; + if(!show_only_feature_edges_m) { + for(he = poly->edges_begin(); + he != poly->edges_end(); + he++) + { + if(he->is_feature_edge()) continue; + + color_lines_selected.push_back(0.0); + color_lines_selected.push_back(0.0); + color_lines_selected.push_back(0.0); + + color_lines_selected.push_back(0.0); + color_lines_selected.push_back(0.0); + color_lines_selected.push_back(0.0); + + color_lines.push_back(this->color().lighter(50).redF()); + color_lines.push_back(this->color().lighter(50).greenF()); + color_lines.push_back(this->color().lighter(50).blueF()); + + color_lines.push_back(this->color().lighter(50).redF()); + color_lines.push_back(this->color().lighter(50).greenF()); + color_lines.push_back(this->color().lighter(50).blueF()); + + + + + } + } + for(he = poly->edges_begin(); + he != poly->edges_end(); + he++) + { + if(!he->is_feature_edge()) continue; + color_lines.push_back(1.0); + color_lines.push_back(0.0); + color_lines.push_back(0.0); + + color_lines.push_back(1.0); + color_lines.push_back(0.0); + color_lines.push_back(0.0); + + color_lines_selected.push_back(1.0); + color_lines_selected.push_back(0.0); + color_lines_selected.push_back(0.0); + + color_lines_selected.push_back(1.0); + color_lines_selected.push_back(0.0); + color_lines_selected.push_back(0.0); + } +} + +Scene_polyhedron_item::Scene_polyhedron_item() + : Scene_item(10,4), + is_Triangle(true), + poly(new Polyhedron), + show_only_feature_edges_m(false), + facet_picking_m(false), + erase_next_picked_facet_m(false), + plugin_has_set_color_vector_m(false) +{ + cur_shading=FlatPlusEdges; + is_selected = true; + init(); + } Scene_polyhedron_item::Scene_polyhedron_item(Polyhedron* const p) - : Scene_item_with_display_list(), - poly(p), - show_only_feature_edges_m(false), - facet_picking_m(false), - erase_next_picked_facet_m(false), - plugin_has_set_color_vector_m(false) + : Scene_item(10,4), + is_Triangle(true), + poly(p), + show_only_feature_edges_m(false), + facet_picking_m(false), + erase_next_picked_facet_m(false), + plugin_has_set_color_vector_m(false) { - init(); + cur_shading=FlatPlusEdges; + is_selected = true; + init(); + changed(); } Scene_polyhedron_item::Scene_polyhedron_item(const Polyhedron& p) - : Scene_item_with_display_list(), - poly(new Polyhedron(p)), - show_only_feature_edges_m(false), - facet_picking_m(false), - erase_next_picked_facet_m(false), - plugin_has_set_color_vector_m(false) + : Scene_item(10,4), + is_Triangle(true), + poly(new Polyhedron(p)), + show_only_feature_edges_m(false), + facet_picking_m(false), + erase_next_picked_facet_m(false), + plugin_has_set_color_vector_m(false) { - init(); + cur_shading=FlatPlusEdges; + is_selected=true; + init(); + changed(); } -// Scene_polyhedron_item::Scene_polyhedron_item(const Scene_polyhedron_item& item) -// : Scene_item_with_display_list(item), -// poly(new Polyhedron(*item.poly)), -// show_only_feature_edges_m(false) -// { -// } - Scene_polyhedron_item::~Scene_polyhedron_item() { - delete_aabb_tree(this); - delete poly; + delete_aabb_tree(this); + delete poly; } #include "Color_map.h" @@ -112,22 +690,23 @@ void Scene_polyhedron_item:: init() { - typedef Polyhedron::Facet_iterator Facet_iterator; - - if ( !plugin_has_set_color_vector_m ) - { - // Fill indices map and get max subdomain value - int max = 0; - for(Facet_iterator fit = poly->facets_begin(), end = poly->facets_end() ; - fit != end; ++fit) + typedef Polyhedron::Facet_iterator Facet_iterator; + + if ( !plugin_has_set_color_vector_m ) { - max = (std::max)(max, fit->patch_id()); + // Fill indices map and get max subdomain value + int max = 0; + for(Facet_iterator fit = poly->facets_begin(), end = poly->facets_end() ; + fit != end; ++fit) + { + max = (std::max)(max, fit->patch_id()); + } + + colors_.resize(0); + compute_color_map(this->color(), max + 1, + std::back_inserter(colors_)); + qFunc.initializeOpenGLFunctions(); } - - colors_.clear(); - compute_color_map(this->color(), max + 1, - std::back_inserter(colors_)); - } volume=-std::numeric_limits::infinity(); area=-std::numeric_limits::infinity(); @@ -158,55 +737,55 @@ init() ); } } - } -Scene_polyhedron_item* +Scene_polyhedron_item* Scene_polyhedron_item::clone() const { - return new Scene_polyhedron_item(*poly); -} + return new Scene_polyhedron_item(*poly);} // Load polyhedron from .OFF file bool Scene_polyhedron_item::load(std::istream& in) { - in >> *poly; - - if ( in && !isEmpty() ) - { - changed(); - return true; - } - return false; + + + in >> *poly; + + if ( in && !isEmpty() ) + { + changed(); + return true; + } + return false; } // Write polyhedron to .OFF file -bool +bool Scene_polyhedron_item::save(std::ostream& out) const { out.precision(17); - out << *poly; - return (bool) out; + out << *poly; + return (bool) out; } -QString +QString Scene_polyhedron_item::toolTip() const { - if(!poly) - return QString(); + if(!poly) + return QString(); QString str = QObject::tr("

Polyhedron %1 (mode: %5, color: %6)

" - "

Number of vertices: %2
" - "Number of edges: %3
" + "

Number of vertices: %2
" + "Number of edges: %3
" "Number of facets: %4") - .arg(this->name()) - .arg(poly->size_of_vertices()) - .arg(poly->size_of_halfedges()/2) - .arg(poly->size_of_facets()) - .arg(this->renderingModeName()) - .arg(this->color().name()); + .arg(this->name()) + .arg(poly->size_of_vertices()) + .arg(poly->size_of_halfedges()/2) + .arg(poly->size_of_facets()) + .arg(this->renderingModeName()) + .arg(this->color().name()); if (volume!=-std::numeric_limits::infinity()) str+=QObject::tr("
Volume: %1").arg(volume); if (area!=-std::numeric_limits::infinity()) @@ -218,122 +797,143 @@ Scene_polyhedron_item::toolTip() const QMenu* Scene_polyhedron_item::contextMenu() { - const char* prop_name = "Menu modified by Scene_polyhedron_item."; + const char* prop_name = "Menu modified by Scene_polyhedron_item."; - QMenu* menu = Scene_item::contextMenu(); + QMenu* menu = Scene_item::contextMenu(); - // Use dynamic properties: - // http://doc.trolltech.com/lastest/qobject.html#property - bool menuChanged = menu->property(prop_name).toBool(); + // Use dynamic properties: + // http://doc.qt.io/qt-5/qobject.html#property + bool menuChanged = menu->property(prop_name).toBool(); - if(!menuChanged) { + if(!menuChanged) { - QAction* actionShowOnlyFeatureEdges = - menu->addAction(tr("Show only &feature edges")); - actionShowOnlyFeatureEdges->setCheckable(true); - actionShowOnlyFeatureEdges->setObjectName("actionShowOnlyFeatureEdges"); - connect(actionShowOnlyFeatureEdges, SIGNAL(toggled(bool)), - this, SLOT(show_only_feature_edges(bool))); + QAction* actionShowOnlyFeatureEdges = + menu->addAction(tr("Show only &feature edges")); + actionShowOnlyFeatureEdges->setCheckable(true); + actionShowOnlyFeatureEdges->setObjectName("actionShowOnlyFeatureEdges"); + connect(actionShowOnlyFeatureEdges, SIGNAL(toggled(bool)), + this, SLOT(show_only_feature_edges(bool))); - QAction* actionPickFacets = - menu->addAction(tr("Facets picking")); - actionPickFacets->setCheckable(true); - actionPickFacets->setObjectName("actionPickFacets"); - connect(actionPickFacets, SIGNAL(toggled(bool)), - this, SLOT(enable_facets_picking(bool))); + QAction* actionPickFacets = + menu->addAction(tr("Facets picking")); + actionPickFacets->setCheckable(true); + actionPickFacets->setObjectName("actionPickFacets"); + connect(actionPickFacets, SIGNAL(toggled(bool)), + this, SLOT(enable_facets_picking(bool))); - QAction* actionEraseNextFacet = - menu->addAction(tr("Erase next picked facet")); - actionEraseNextFacet->setCheckable(true); - actionEraseNextFacet->setObjectName("actionEraseNextFacet"); - connect(actionEraseNextFacet, SIGNAL(toggled(bool)), - this, SLOT(set_erase_next_picked_facet(bool))); + QAction* actionEraseNextFacet = + menu->addAction(tr("Erase next picked facet")); + actionEraseNextFacet->setCheckable(true); + actionEraseNextFacet->setObjectName("actionEraseNextFacet"); + connect(actionEraseNextFacet, SIGNAL(toggled(bool)), + this, SLOT(set_erase_next_picked_facet(bool))); - menu->setProperty(prop_name, true); - } - QAction* action = menu->findChild("actionPickFacets"); - if(action) action->setChecked(facet_picking_m); - action = menu->findChild("actionEraseNextFacet"); - if(action) action->setChecked(erase_next_picked_facet_m); - return menu; + menu->setProperty(prop_name, true); + } + QAction* action = menu->findChild("actionPickFacets"); + if(action) action->setChecked(facet_picking_m); + action = menu->findChild("actionEraseNextFacet"); + if(action) action->setChecked(erase_next_picked_facet_m); + return menu; } void Scene_polyhedron_item::show_only_feature_edges(bool b) { - show_only_feature_edges_m = b; + show_only_feature_edges_m = b; Q_EMIT itemChanged(); } void Scene_polyhedron_item::enable_facets_picking(bool b) { - facet_picking_m = b; + facet_picking_m = b; } void Scene_polyhedron_item::set_erase_next_picked_facet(bool b) { - if(b) { facet_picking_m = true; } // automatically activate facet_picking - erase_next_picked_facet_m = b; + if(b) { facet_picking_m = true; } // automatically activate facet_picking + erase_next_picked_facet_m = b; } -// Points/Wireframe/Flat/Gouraud OpenGL drawing in a display list -void Scene_polyhedron_item::direct_draw() const { - gl_render_facets(*poly,colors_); -} +void Scene_polyhedron_item::draw(Viewer_interface* viewer) const { + if(!are_buffers_filled) + initialize_buffers(viewer); -// Points/Wireframe/Flat/Gouraud OpenGL drawing in a display list -void Scene_polyhedron_item::direct_draw_edges() const { - typedef Kernel::Point_3 Point; - typedef Polyhedron::Edge_iterator Edge_iterator; - ::glBegin(GL_LINES); - Edge_iterator he; - if(!show_only_feature_edges_m) { - for(he = poly->edges_begin(); - he != poly->edges_end(); - he++) + if(!is_selected) + vaos[0]->bind(); + else { - if(he->is_feature_edge()) continue; - const Point& a = he->vertex()->point(); - const Point& b = he->opposite()->vertex()->point(); - ::glVertex3d(a.x(),a.y(),a.z()); - ::glVertex3d(b.x(),b.y(),b.z()); + vaos[2]->bind(); } - } - ::glColor3d(1.0, 0.0, 0.0); - for(he = poly->edges_begin(); - he != poly->edges_end(); - he++) - { - if(!he->is_feature_edge()) continue; - const Point& a = he->vertex()->point(); - const Point& b = he->opposite()->vertex()->point(); - ::glVertex3d(a.x(),a.y(),a.z()); - ::glVertex3d(b.x(),b.y(),b.z()); - } - ::glEnd(); + attrib_buffers(viewer, PROGRAM_WITH_LIGHT); + program = getShaderProgram(PROGRAM_WITH_LIGHT); + program->bind(); + qFunc.glDrawArrays(GL_TRIANGLES, 0, static_cast(positions_facets.size()/4)); + program->release(); + if(!is_selected) + vaos[0]->release(); + else + vaos[2]->release(); } -Polyhedron* +// Points/Wireframe/Flat/Gouraud OpenGL drawing in a display list +void Scene_polyhedron_item::draw_edges(Viewer_interface* viewer) const { + + if(!is_selected) + { + vaos[1]->bind(); + } + else + { + vaos[3]->bind(); + } + attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT); + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT); + program->bind(); + //draw the edges + qFunc.glDrawArrays(GL_LINES, 0, static_cast(positions_lines.size()/4)); + program->release(); + if(!is_selected) + vaos[1]->release(); + else + vaos[3]->release(); +} + +void +Scene_polyhedron_item::draw_points(Viewer_interface* viewer) const { + + vaos[1]->bind(); + attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT); + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT); + program->bind(); + //draw the points + qFunc.glDrawArrays(GL_POINTS, 0, static_cast(positions_lines.size()/4)); + // Clean-up + program->release(); + vaos[1]->release(); +} + +Polyhedron* Scene_polyhedron_item::polyhedron() { return poly; } -const Polyhedron* +const Polyhedron* Scene_polyhedron_item::polyhedron() const { return poly; } bool Scene_polyhedron_item::isEmpty() const { - return (poly == 0) || poly->empty(); + return (poly == 0) || poly->empty(); } Scene_polyhedron_item::Bbox Scene_polyhedron_item::bbox() const { - const Kernel::Point_3& p = *(poly->points_begin()); - CGAL::Bbox_3 bbox(p.x(), p.y(), p.z(), p.x(), p.y(), p.z()); - for(Polyhedron::Point_iterator it = poly->points_begin(); - it != poly->points_end(); - ++it) { - bbox = bbox + it->bbox(); - } - return Bbox(bbox.xmin(),bbox.ymin(),bbox.zmin(), - bbox.xmax(),bbox.ymax(),bbox.zmax()); + const Kernel::Point_3& p = *(poly->points_begin()); + CGAL::Bbox_3 bbox(p.x(), p.y(), p.z(), p.x(), p.y(), p.z()); + for(Polyhedron::Point_iterator it = poly->points_begin(); + it != poly->points_end(); + ++it) { + bbox = bbox + it->bbox(); + } + return Bbox(bbox.xmin(),bbox.ymin(),bbox.zmin(), + bbox.xmax(),bbox.ymax(),bbox.zmax()); } @@ -342,12 +942,42 @@ Scene_polyhedron_item:: changed() { Q_EMIT item_is_about_to_be_changed(); - delete_aabb_tree(this); - init(); - Base::changed(); + delete_aabb_tree(this); + init(); + Base::changed(); + is_Triangulated(); + compute_normals_and_vertices(); + are_buffers_filled = false; + +} +void +Scene_polyhedron_item:: +contextual_changed() +{ + GLint new_shading; + qFunc.glGetIntegerv(GL_SHADE_MODEL, &new_shading); + prev_shading = cur_shading; + cur_shading = renderingMode(); + if(prev_shading != cur_shading) + if(cur_shading == Flat || cur_shading == FlatPlusEdges ||cur_shading == Gouraud) + { + //Change the normals + changed(); + } + +} +void +Scene_polyhedron_item::selection_changed(bool p_is_selected) +{ + if(p_is_selected != is_selected) + { + is_selected = p_is_selected; + are_buffers_filled = false; + } + } -void +void Scene_polyhedron_item::select(double orig_x, double orig_y, double orig_z, @@ -355,140 +985,141 @@ Scene_polyhedron_item::select(double orig_x, double dir_y, double dir_z) { - if(facet_picking_m) { - typedef Input_facets_AABB_tree Tree; - typedef Tree::Object_and_primitive_id Object_and_primitive_id; + if(facet_picking_m) { + typedef Input_facets_AABB_tree Tree; + typedef Tree::Object_and_primitive_id Object_and_primitive_id; - Tree* aabb_tree = get_aabb_tree(this); - if(aabb_tree) { - const Kernel::Point_3 ray_origin(orig_x, orig_y, orig_z); - const Kernel::Vector_3 ray_dir(dir_x, dir_y, dir_z); - const Kernel::Ray_3 ray(ray_origin, ray_dir); + Tree* aabb_tree = get_aabb_tree(this); + if(aabb_tree) { + const Kernel::Point_3 ray_origin(orig_x, orig_y, orig_z); + const Kernel::Vector_3 ray_dir(dir_x, dir_y, dir_z); + const Kernel::Ray_3 ray(ray_origin, ray_dir); - typedef std::list Intersections; - Intersections intersections; + typedef std::list Intersections; + Intersections intersections; - aabb_tree->all_intersections(ray, std::back_inserter(intersections)); + aabb_tree->all_intersections(ray, std::back_inserter(intersections)); - Intersections::iterator closest = intersections.begin(); - if(closest != intersections.end()) { - const Kernel::Point_3* closest_point = - CGAL::object_cast(&closest->first); + Intersections::iterator closest = intersections.begin(); + if(closest != intersections.end()) { + const Kernel::Point_3* closest_point = + CGAL::object_cast(&closest->first); - for(Intersections::iterator - it = boost::next(intersections.begin()), - end = intersections.end(); - it != end; ++it) - { - if(! closest_point) { - closest = it; - } - else { - const Kernel::Point_3* it_point = - CGAL::object_cast(&it->first); - if(it_point && - (ray_dir * (*it_point - *closest_point)) < 0) - { - closest = it; - closest_point = it_point; - } - } - } - if(closest_point) { - Polyhedron::Facet_handle selected_fh = closest->second; + for(Intersections::iterator + it = boost::next(intersections.begin()), + end = intersections.end(); + it != end; ++it) + { + if(! closest_point) { + closest = it; + } + else { + const Kernel::Point_3* it_point = + CGAL::object_cast(&it->first); + if(it_point && + (ray_dir * (*it_point - *closest_point)) < 0) + { + closest = it; + closest_point = it_point; + } + } + } + if(closest_point) { + Polyhedron::Facet_handle selected_fh = closest->second; - // The computation of the nearest vertex may be costly. Only - // do it if some objects are connected to the signal - // 'selected_vertex'. - if(QObject::receivers(SIGNAL(selected_vertex(void*))) > 0) - { - Polyhedron::Halfedge_around_facet_circulator - he_it = selected_fh->facet_begin(), - around_end = he_it; + // The computation of the nearest vertex may be costly. Only + // do it if some objects are connected to the signal + // 'selected_vertex'. + if(QObject::receivers(SIGNAL(selected_vertex(void*))) > 0) + { + Polyhedron::Halfedge_around_facet_circulator + he_it = selected_fh->facet_begin(), + around_end = he_it; - Polyhedron::Vertex_handle v = he_it->vertex(), nearest_v = v; + Polyhedron::Vertex_handle v = he_it->vertex(), nearest_v = v; - Kernel::FT sq_dist = CGAL::squared_distance(*closest_point, - v->point()); + Kernel::FT sq_dist = CGAL::squared_distance(*closest_point, + v->point()); - while(++he_it != around_end) { - v = he_it->vertex(); - Kernel::FT new_sq_dist = CGAL::squared_distance(*closest_point, - v->point()); - if(new_sq_dist < sq_dist) { - sq_dist = new_sq_dist; - nearest_v = v; - } - } + while(++he_it != around_end) { + v = he_it->vertex(); + Kernel::FT new_sq_dist = CGAL::squared_distance(*closest_point, + v->point()); + if(new_sq_dist < sq_dist) { + sq_dist = new_sq_dist; + nearest_v = v; + } + } Q_EMIT selected_vertex((void*)(&*nearest_v)); - } + } - if(QObject::receivers(SIGNAL(selected_edge(void*))) > 0 - || QObject::receivers(SIGNAL(selected_halfedge(void*))) > 0) - { - Polyhedron::Halfedge_around_facet_circulator - he_it = selected_fh->facet_begin(), - around_end = he_it; + if(QObject::receivers(SIGNAL(selected_edge(void*))) > 0 + || QObject::receivers(SIGNAL(selected_halfedge(void*))) > 0) + { + Polyhedron::Halfedge_around_facet_circulator + he_it = selected_fh->facet_begin(), + around_end = he_it; - Polyhedron::Halfedge_handle nearest_h = he_it; - Kernel::FT sq_dist = CGAL::squared_distance(*closest_point, - Kernel::Segment_3(he_it->vertex()->point(), he_it->opposite()->vertex()->point())); + Polyhedron::Halfedge_handle nearest_h = he_it; + Kernel::FT sq_dist = CGAL::squared_distance(*closest_point, + Kernel::Segment_3(he_it->vertex()->point(), he_it->opposite()->vertex()->point())); - while(++he_it != around_end) { - Kernel::FT new_sq_dist = CGAL::squared_distance(*closest_point, - Kernel::Segment_3(he_it->vertex()->point(), he_it->opposite()->vertex()->point())); - if(new_sq_dist < sq_dist) { - sq_dist = new_sq_dist; - nearest_h = he_it; - } - } + while(++he_it != around_end) { + Kernel::FT new_sq_dist = CGAL::squared_distance(*closest_point, + Kernel::Segment_3(he_it->vertex()->point(), he_it->opposite()->vertex()->point())); + if(new_sq_dist < sq_dist) { + sq_dist = new_sq_dist; + nearest_h = he_it; + } + } Q_EMIT selected_halfedge((void*)(&*nearest_h)); Q_EMIT selected_edge((void*)(std::min)(&*nearest_h, &*nearest_h->opposite())); - } - + } + Q_EMIT selected_facet((void*)(&*selected_fh)); - if(erase_next_picked_facet_m) { - polyhedron()->erase_facet(selected_fh->halfedge()); - polyhedron()->normalize_border(); - //set_erase_next_picked_facet(false); - changed(); + if(erase_next_picked_facet_m) { + polyhedron()->erase_facet(selected_fh->halfedge()); + polyhedron()->normalize_border(); + //set_erase_next_picked_facet(false); + changed(); Q_EMIT itemChanged(); - } + } + } + } } - } } - } - Base::select(orig_x, orig_y, orig_z, dir_x, dir_y, dir_z); + Base::select(orig_x, orig_y, orig_z, dir_x, dir_y, dir_z); } void Scene_polyhedron_item::update_vertex_indices() { - std::size_t id=0; - for (Polyhedron::Vertex_iterator vit = polyhedron()->vertices_begin(), - vit_end = polyhedron()->vertices_end(); vit != vit_end; ++vit) - { - vit->id()=id++; - } + std::size_t id=0; + for (Polyhedron::Vertex_iterator vit = polyhedron()->vertices_begin(), + vit_end = polyhedron()->vertices_end(); vit != vit_end; ++vit) + { + vit->id()=id++; + } } void Scene_polyhedron_item::update_facet_indices() { - std::size_t id=0; - for (Polyhedron::Facet_iterator fit = polyhedron()->facets_begin(), - fit_end = polyhedron()->facets_end(); fit != fit_end; ++fit) - { - fit->id()=id++; - } + std::size_t id=0; + for (Polyhedron::Facet_iterator fit = polyhedron()->facets_begin(), + fit_end = polyhedron()->facets_end(); fit != fit_end; ++fit) + { + fit->id()=id++; + } } void Scene_polyhedron_item::update_halfedge_indices() { - std::size_t id=0; - for (Polyhedron::Halfedge_iterator hit = polyhedron()->halfedges_begin(), - hit_end = polyhedron()->halfedges_end(); hit != hit_end; ++hit) - { - hit->id()=id++; - } + std::size_t id=0; + for (Polyhedron::Halfedge_iterator hit = polyhedron()->halfedges_begin(), + hit_end = polyhedron()->halfedges_end(); hit != hit_end; ++hit) + { + hit->id()=id++; + } } #include "Scene_polyhedron_item.moc" + diff --git a/Polyhedron/demo/Polyhedron/Scene_polyhedron_item.h b/Polyhedron/demo/Polyhedron/Scene_polyhedron_item.h index 9ed0d56fde6..8b9e6c8f8b0 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polyhedron_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_polyhedron_item.h @@ -2,9 +2,15 @@ #define SCENE_POLYHEDRON_ITEM_H #include "Scene_polyhedron_item_config.h" -#include "Scene_item_with_display_list.h" +#include "Scene_item.h" //<- modif ? #include "Polyhedron_type_fwd.h" +#include "Polyhedron_type.h" +#include "Viewer.h" #include +#include +#include +#include +#include #include #include @@ -15,87 +21,114 @@ class QMenu; // This class represents a polyhedron in the OpenGL scene class SCENE_POLYHEDRON_ITEM_EXPORT Scene_polyhedron_item - : public Scene_item_with_display_list { - Q_OBJECT + : public Scene_item{ + Q_OBJECT public: - Scene_polyhedron_item(); -// Scene_polyhedron_item(const Scene_polyhedron_item&); - Scene_polyhedron_item(const Polyhedron& p); - Scene_polyhedron_item(Polyhedron* const p); - ~Scene_polyhedron_item(); + Scene_polyhedron_item(); + // Scene_polyhedron_item(const Scene_polyhedron_item&); + Scene_polyhedron_item(const Polyhedron& p); + Scene_polyhedron_item(Polyhedron* const p); + ~Scene_polyhedron_item(); - Scene_polyhedron_item* clone() const; - - // IO - bool load(std::istream& in); - bool save(std::ostream& out) const; + Scene_polyhedron_item* clone() const; - // Function for displaying meta-data of the item - virtual QString toolTip() const; + // IO + bool load(std::istream& in); + bool save(std::ostream& out) const; + bool is_Triangle; - // Function to override the context menu - QMenu* contextMenu(); - - // Indicate if rendering mode is supported - virtual bool supportsRenderingMode(RenderingMode m) const { return (m!=PointsPlusNormals && m!=Splatting); } - // Points/Wireframe/Flat/Gouraud OpenGL drawing in a display list - virtual void direct_draw() const; - virtual void direct_draw_edges() const; + // Function for displaying meta-data of the item + virtual QString toolTip() const; - // Get wrapped polyhedron - Polyhedron* polyhedron(); - const Polyhedron* polyhedron() const; + // Function to override the context menu + QMenu* contextMenu(); + + // Indicate if rendering mode is supported + virtual bool supportsRenderingMode(RenderingMode m) const { return (m!=PointsPlusNormals); } + // Points/Wireframe/Flat/Gouraud OpenGL drawing in a display list + void draw() const {} + virtual void draw(Viewer_interface*) const; + virtual void draw_edges() const {} + virtual void draw_edges(Viewer_interface* viewer) const; + virtual void draw_points(Viewer_interface*) const; + + // Get wrapped polyhedron + Polyhedron* polyhedron(); + const Polyhedron* polyhedron() const; + + // Get dimensions + bool isFinite() const { return true; } + bool isEmpty() const; + Bbox bbox() const; + std::vector& color_vector() {return colors_;} + void set_color_vector_read_only(bool on_off) {plugin_has_set_color_vector_m=on_off;} - // Get dimensions - bool isFinite() const { return true; } - bool isEmpty() const; - Bbox bbox() const; - std::vector& color_vector() {return colors_;} - void set_color_vector_read_only(bool on_off) {plugin_has_set_color_vector_m=on_off;} - public Q_SLOTS: - virtual void changed(); - void show_only_feature_edges(bool); - void enable_facets_picking(bool); - void set_erase_next_picked_facet(bool); + virtual void changed(); + virtual void contextual_changed(); + virtual void selection_changed(bool); + void show_only_feature_edges(bool); + void enable_facets_picking(bool); + void set_erase_next_picked_facet(bool); - void select(double orig_x, - double orig_y, - double orig_z, - double dir_x, - double dir_y, - double dir_z); + void select(double orig_x, + double orig_y, + double orig_z, + double dir_x, + double dir_y, + double dir_z); - void update_vertex_indices(); - void update_facet_indices(); - void update_halfedge_indices(); + void update_vertex_indices(); + void update_facet_indices(); + void update_halfedge_indices(); Q_SIGNALS: - void selected_vertex(void*); - void selected_facet(void*); - void selected_edge(void*); - void selected_halfedge(void*); - void item_is_about_to_be_changed(); // emitted in changed() + void selected_vertex(void*); + void selected_facet(void*); + void selected_edge(void*); + void selected_halfedge(void*); + void item_is_about_to_be_changed(); // emitted in changed() private: - // Initialization - void init(); - -private: - Polyhedron* poly; + // Initialization + void init(); private: - typedef Scene_item_with_display_list Base; - typedef std::vector Color_vector; - - Color_vector colors_; + Polyhedron* poly; + +private: + typedef Scene_item Base; + typedef std::vector Color_vector; + typedef Polyhedron::Facet_iterator Facet_iterator; + + Color_vector colors_; + + bool show_only_feature_edges_m; + bool facet_picking_m; + bool erase_next_picked_facet_m; + //the following variable is used to indicate if the color vector must not be automatically updated. + bool plugin_has_set_color_vector_m; + + + std::vector positions_lines; + std::vector positions_facets; + std::vector normals; + std::vector color_lines; + std::vector color_facets; + std::vector color_lines_selected; + std::vector color_facets_selected; + + mutable QOpenGLShaderProgram *program; + + using Scene_item::initialize_buffers; + void initialize_buffers(Viewer_interface *viewer = 0) const; + void compute_normals_and_vertices(void); + void compute_colors(); + void triangulate_facet(Facet_iterator ); + void triangulate_facet_color(Facet_iterator ); + void is_Triangulated(); + double volume, area; - bool show_only_feature_edges_m; - bool facet_picking_m; - bool erase_next_picked_facet_m; - //the following variable is used to indicate if the color vector must not be automatically updated. - bool plugin_has_set_color_vector_m; - double volume, area; }; // end class Scene_polyhedron_item #endif // SCENE_POLYHEDRON_ITEM_H diff --git a/Polyhedron/demo/Polyhedron/Scene_polyhedron_item_decorator.cpp b/Polyhedron/demo/Polyhedron/Scene_polyhedron_item_decorator.cpp index f3302589c1d..c71d7e23278 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polyhedron_item_decorator.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_polyhedron_item_decorator.cpp @@ -3,7 +3,7 @@ Scene_polyhedron_item_decorator::Scene_polyhedron_item_decorator (Scene_polyhedron_item* poly_item, bool delete_item) - : poly_item(poly_item), delete_poly_item(delete_item) + :Scene_item(), poly_item(poly_item), delete_poly_item(delete_item) { } Scene_polyhedron_item_decorator::~Scene_polyhedron_item_decorator() diff --git a/Polyhedron/demo/Polyhedron/Scene_polyhedron_item_decorator.h b/Polyhedron/demo/Polyhedron/Scene_polyhedron_item_decorator.h index c385815b03c..2377fd00a79 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polyhedron_item_decorator.h +++ b/Polyhedron/demo/Polyhedron/Scene_polyhedron_item_decorator.h @@ -27,7 +27,7 @@ public: // QMenu* contextMenu(); // Indicate if rendering mode is supported - bool supportsRenderingMode(RenderingMode m) const { return (m!=PointsPlusNormals && m!=Splatting); } + bool supportsRenderingMode(RenderingMode m) const { return m!=PointsPlusNormals; } // Points/Wireframe/Flat/Gouraud OpenGL drawing in a display list // dispatch to poly_item direct_draw and direct_draw_edges void draw() const; diff --git a/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.cpp b/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.cpp index 8a104dd5966..ae08525f1d1 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.cpp @@ -1,2 +1,206 @@ #include "Scene_polyhedron_selection_item.h" #include "Scene_polyhedron_selection_item.moc" + + +void Scene_polyhedron_selection_item::initialize_buffers(Viewer_interface *viewer)const +{ + //vao containing the data for the unselected facets + { + program = getShaderProgram(PROGRAM_WITH_LIGHT, viewer); + program->bind(); + + vaos[0]->bind(); + buffers[0].bind(); + buffers[0].allocate(positions_facets.data(), + static_cast(positions_facets.size()*sizeof(float))); + program->enableAttributeArray("vertex"); + program->setAttributeBuffer("vertex",GL_FLOAT,0,3); + buffers[0].release(); + + + + buffers[1].bind(); + buffers[1].allocate(normals.data(), + static_cast(normals.size()*sizeof(float))); + program->enableAttributeArray("normals"); + program->setAttributeBuffer("normals",GL_FLOAT,0,3); + buffers[1].release(); + + program->setAttributeValue("colors",facet_color); + vaos[0]->release(); + program->release(); + + } + //vao containing the data for the unselected lines + { + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT, viewer); + program->bind(); + vaos[1]->bind(); + + buffers[2].bind(); + buffers[2].allocate(positions_lines.data(), + static_cast(positions_lines.size()*sizeof(float))); + program->enableAttributeArray("vertex"); + program->setAttributeBuffer("vertex",GL_FLOAT,0,3); + buffers[2].release(); + + program->setAttributeValue("colors",edge_color); + program->release(); + + vaos[1]->release(); + + } + //vao containing the data for the points + { + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT, viewer); + program->bind(); + vaos[2]->bind(); + + buffers[3].bind(); + buffers[3].allocate(positions_points.data(), + static_cast(positions_points.size()*sizeof(float))); + program->enableAttributeArray("vertex"); + program->setAttributeBuffer("vertex",GL_FLOAT,0,3); + buffers[3].release(); + + + program->setAttributeValue("colors",vertex_color); + buffers[6].release(); + program->release(); + + vaos[2]->release(); + } + + are_buffers_filled = true; +} + +void Scene_polyhedron_selection_item::compute_elements() +{ + positions_facets.clear(); + positions_lines.clear(); + positions_points.clear(); + normals.clear(); + //The facets + { + + + for(Selection_set_facet::iterator + it = selected_facets.begin(), + end = selected_facets.end(); + it != end; ++it) + { + const Kernel::Vector_3 n = + compute_facet_normal(**it); + + normals.push_back(n.x()); + normals.push_back(n.y()); + normals.push_back(n.z()); + + normals.push_back(n.x()); + normals.push_back(n.y()); + normals.push_back(n.z()); + + normals.push_back(n.x()); + normals.push_back(n.y()); + normals.push_back(n.z()); + + + Polyhedron::Halfedge_around_facet_circulator + he = (*it)->facet_begin(), + cend = he; + + CGAL_For_all(he,cend) + { + const Kernel::Point_3& p = he->vertex()->point(); + positions_facets.push_back(p.x()); + positions_facets.push_back(p.y()); + positions_facets.push_back(p.z()); + } + } + } + + //The Lines + { + + for(Selection_set_edge::iterator it = selected_edges.begin(); it != selected_edges.end(); ++it) { + const Kernel::Point_3& a = (it->halfedge())->vertex()->point(); + const Kernel::Point_3& b = (it->halfedge())->opposite()->vertex()->point(); + positions_lines.push_back(a.x()); + positions_lines.push_back(a.y()); + positions_lines.push_back(a.z()); + + positions_lines.push_back(b.x()); + positions_lines.push_back(b.y()); + positions_lines.push_back(b.z()); + } + + } + + //The points + { + for(Selection_set_vertex::iterator + it = selected_vertices.begin(), + end = selected_vertices.end(); + it != end; ++it) + { + const Kernel::Point_3& p = (*it)->point(); + positions_points.push_back(p.x()); + positions_points.push_back(p.y()); + positions_points.push_back(p.z()); + } + } +} + +void Scene_polyhedron_selection_item::draw(Viewer_interface* viewer) const +{ + + if(!are_buffers_filled) + initialize_buffers(viewer); + + draw_points(viewer); + GLfloat offset_factor; + GLfloat offset_units; + qFunc.glGetFloatv( GL_POLYGON_OFFSET_FACTOR, &offset_factor); + qFunc.glGetFloatv(GL_POLYGON_OFFSET_UNITS, &offset_units); + glPolygonOffset(-1.f, 1.f); + + vaos[0]->bind(); + program = getShaderProgram(PROGRAM_WITH_LIGHT); + attrib_buffers(viewer,PROGRAM_WITH_LIGHT); + program->bind(); + qFunc.glDrawArrays(GL_TRIANGLES, 0, static_cast(positions_facets.size()/3)); + program->release(); + vaos[0]->release(); + glPolygonOffset(offset_factor, offset_units); + draw_edges(viewer); + + +} + +void Scene_polyhedron_selection_item::draw_edges(Viewer_interface* viewer) const +{ + + qFunc.glLineWidth(3.f); + vaos[1]->bind(); + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT); + attrib_buffers(viewer,PROGRAM_WITHOUT_LIGHT); + program->bind(); + qFunc.glDrawArrays(GL_LINES, 0, static_cast(positions_lines.size()/3)); + program->release(); + vaos[1]->release(); + qFunc.glLineWidth(1.f); +} + +void Scene_polyhedron_selection_item::draw_points(Viewer_interface* viewer) const +{ + qFunc.glPointSize(5.f); + vaos[2]->bind(); + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT); + attrib_buffers(viewer,PROGRAM_WITHOUT_LIGHT); + program->bind(); + qFunc.glDrawArrays(GL_POINTS, 0, static_cast(positions_points.size()/3)); + program->release(); + vaos[2]->release(); + qFunc.glPointSize(1.f); + +} diff --git a/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.h b/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.h index 9cc4f97dc0b..ac689c90b84 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.h @@ -172,11 +172,41 @@ public: // To be used inside loader Scene_polyhedron_selection_item() : Scene_polyhedron_item_decorator(NULL, false) - { } + { + nbVaos = 0; + for(int i=0; i<3; i++) + { + addVaos(i); + vaos[i]->create(); + } + + for(int i=0; i<7; i++) + { + buffers[i].create(); + } + } Scene_polyhedron_selection_item(Scene_polyhedron_item* poly_item, QMainWindow* mw) : Scene_polyhedron_item_decorator(NULL, false) - { init(poly_item, mw); } + { + nbVaos = 0; + for(int i=0; i<3; i++) + { + addVaos(i); + vaos[i]->create(); + } + + for(int i=0; i<7; i++) + { + buffers[i].create(); + } + init(poly_item, mw); + changed(); + } + + ~Scene_polyhedron_selection_item() + { + } protected: void init(Scene_polyhedron_item* poly_item, QMainWindow* mw) @@ -199,6 +229,7 @@ protected: facet_color = QColor(87,87,87); edge_color = QColor(173,35,35); vertex_color = QColor(255,205,243); + qFunc.initializeOpenGLFunctions(); } Active_handle::Type get_active_handle_type() @@ -217,84 +248,12 @@ public: typedef boost::unordered_set Selection_set_facet; typedef boost::unordered_set Selection_set_edge; -// drawing - void draw() const { - draw_selected_vertices(); - draw_selected_facets(); - draw_selected_edges(); - } - void draw_edges() const { } - void draw_selected_vertices() const { - GLboolean enable_back_lighting = glIsEnabled(GL_LIGHTING); - glDisable(GL_LIGHTING); - - - CGAL::GL::Point_size point_size; point_size.set_point_size(5); - CGALglcolor(vertex_color); - - ::glBegin(GL_POINTS); - for(Selection_set_vertex::iterator - it = selected_vertices.begin(), - end = selected_vertices.end(); - it != end; ++it) - { - const Kernel::Point_3& p = (*it)->point(); - ::glVertex3d(p.x(), p.y(), p.z()); - } - ::glEnd(); - - if(enable_back_lighting) { glEnable(GL_LIGHTING); } - } - void draw_selected_facets() const { - CGALglcolor(facet_color); - - GLfloat offset_factor; - GLfloat offset_units; - ::glGetFloatv(GL_POLYGON_OFFSET_FACTOR, &offset_factor); - ::glGetFloatv(GL_POLYGON_OFFSET_UNITS, &offset_units); - - ::glPolygonOffset(-1.f, 1.f); - ::glBegin(GL_TRIANGLES); - for(Selection_set_facet::iterator - it = selected_facets.begin(), - end = selected_facets.end(); - it != end; ++it) - { - const Kernel::Vector_3 n = - CGAL::Polygon_mesh_processing::compute_face_normal(*it, *this->poly_item->polyhedron()); - ::glNormal3d(n.x(),n.y(),n.z()); - - Polyhedron::Halfedge_around_facet_circulator - he = (*it)->facet_begin(), - cend = he; - - CGAL_For_all(he,cend) - { - const Kernel::Point_3& p = he->vertex()->point(); - ::glVertex3d(p.x(),p.y(),p.z()); - } - } - ::glEnd(); - ::glPolygonOffset(offset_factor, offset_units); - } - void draw_selected_edges() const { - GLboolean enable_back_lighting = glIsEnabled(GL_LIGHTING); - glDisable(GL_LIGHTING); - - CGALglcolor(edge_color); - ::glLineWidth(3.f); - ::glBegin(GL_LINES); - for(Selection_set_edge::iterator it = selected_edges.begin(); it != selected_edges.end(); ++it) { - const Kernel::Point_3& a = (it->halfedge())->vertex()->point(); - const Kernel::Point_3& b = (it->halfedge())->opposite()->vertex()->point(); - ::glVertex3d(a.x(),a.y(),a.z()); - ::glVertex3d(b.x(),b.y(),b.z()); - } - ::glEnd(); - - if(enable_back_lighting) { glEnable(GL_LIGHTING); } - } + using Scene_polyhedron_item_decorator::draw; + virtual void draw(Viewer_interface*) const; + virtual void draw_edges() const { } + virtual void draw_edges(Viewer_interface*) const; + virtual void draw_points(Viewer_interface*) const; bool supportsRenderingMode(RenderingMode m) const { return (m==Flat); } @@ -709,6 +668,9 @@ public: public Q_SLOTS: void changed() { // do not use decorator function, which calls changed on poly_item which cause deletion of AABB + // poly_item->changed(); + compute_elements(); + are_buffers_filled = false; } // slots are called by signals of polyhedron_k_ring_selector void selected(const std::set& m) @@ -804,6 +766,19 @@ public: Selection_set_edge selected_edges; // stores one halfedge for each pair (halfedge with minimum address) // QColor vertex_color, facet_color, edge_color; + +private: + + std::vector positions_facets; + std::vector normals; + std::vector positions_lines; + std::vector positions_points; + + mutable QOpenGLShaderProgram *program; + using Scene_item::initialize_buffers; + void initialize_buffers(Viewer_interface *viewer) const; + void compute_elements(); + }; #endif diff --git a/Polyhedron/demo/Polyhedron/Scene_polyhedron_shortest_path_item.cpp b/Polyhedron/demo/Polyhedron/Scene_polyhedron_shortest_path_item.cpp index e515c612b87..f376eff9db1 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polyhedron_shortest_path_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_polyhedron_shortest_path_item.cpp @@ -9,20 +9,22 @@ #include -Scene_polyhedron_shortest_path_item::Scene_polyhedron_shortest_path_item() - : Scene_polyhedron_item_decorator(NULL, false) +Scene_polyhedron_shortest_path_item::Scene_polyhedron_shortest_path_item() + :Scene_polyhedron_item_decorator(NULL, false) , m_shortestPaths(NULL) , m_isTreeCached(false) , m_shiftHeld(false) { + qFunc.initializeOpenGLFunctions(); } Scene_polyhedron_shortest_path_item::Scene_polyhedron_shortest_path_item(Scene_polyhedron_item* polyhedronItem, Scene_interface* sceneInterface, Messages_interface* messages, QMainWindow* mainWindow) - : Scene_polyhedron_item_decorator(polyhedronItem, false) + :Scene_polyhedron_item_decorator(polyhedronItem, false) , m_shortestPaths(NULL) , m_isTreeCached(false) , m_shiftHeld(false) { + qFunc.initializeOpenGLFunctions(); initialize(polyhedronItem, sceneInterface, messages, mainWindow); } @@ -30,7 +32,40 @@ Scene_polyhedron_shortest_path_item::~Scene_polyhedron_shortest_path_item() { deinitialize(); } - + +void Scene_polyhedron_shortest_path_item::compute_elements() +{ + + vertices.resize(0); + + for(Surface_mesh_shortest_path::Source_point_iterator it = m_shortestPaths->source_points_begin(); it != m_shortestPaths->source_points_end(); ++it) + { + const Point_3& p = m_shortestPaths->point(it->first, it->second); + vertices.push_back(p.x()); + vertices.push_back(p.y()); + vertices.push_back(p.z()); + } + + + +} + +void Scene_polyhedron_shortest_path_item::initialize_buffers(Viewer_interface* viewer)const +{ + //vao containing the data for the selected lines + { + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT, viewer); + vaos[0]->bind(); + program->bind(); + buffers[0].bind(); + buffers[0].allocate(vertices.data(), vertices.size()*sizeof(float)); + program->enableAttributeArray("vertex"); + program->setAttributeBuffer("vertex",GL_FLOAT,0,3); + buffers[0].release(); + vaos[0]->release(); + } + are_buffers_filled = true; +} bool Scene_polyhedron_shortest_path_item::supportsRenderingMode(RenderingMode m) const { switch (m) @@ -52,55 +87,29 @@ bool Scene_polyhedron_shortest_path_item::supportsRenderingMode(RenderingMode m) } } -void Scene_polyhedron_shortest_path_item::draw() const +void Scene_polyhedron_shortest_path_item::draw(Viewer_interface* viewer) const { - if (supportsRenderingMode(renderingMode())) - { - draw_points(); - } + if (supportsRenderingMode(renderingMode())) + { + draw_points(viewer); + } } -void Scene_polyhedron_shortest_path_item::draw(Viewer_interface*) const + +void Scene_polyhedron_shortest_path_item::draw_points(Viewer_interface* viewer) const { - draw(); -} - -// Wireframe OpenGL drawing -void Scene_polyhedron_shortest_path_item::draw_edges() const -{ -} - -void Scene_polyhedron_shortest_path_item::draw_edges(Viewer_interface*) const -{ - draw_edges(); -} - // Points OpenGL drawing -void Scene_polyhedron_shortest_path_item::draw_points() const -{ - glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT); - - glDisable(GL_LIGHTING); - - CGAL::GL::Point_size point_size; - point_size.set_point_size(5); - CGALglcolor(Qt::green); - - ::glBegin(GL_POINTS); - - for(Surface_mesh_shortest_path::Source_point_iterator it = m_shortestPaths->source_points_begin(); it != m_shortestPaths->source_points_end(); ++it) - { - const Point_3& p = m_shortestPaths->point(it->first, it->second); - ::glVertex3d(p.x(), p.y(), p.z()); - } - - ::glEnd(); - - glPopAttrib(); -} - -void Scene_polyhedron_shortest_path_item::draw_points(Viewer_interface*) const -{ - draw_points(); + if(!are_buffers_filled) + { + initialize_buffers(viewer); + } + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT); + attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT); + vaos[0]->bind(); + program->bind(); + program->setAttributeValue("colors", QColor(Qt::green)); + qFunc.glDrawArrays(GL_POINTS, 0, vertices.size()/3); + program->release(); + vaos[0]->release(); } Scene_polyhedron_shortest_path_item* Scene_polyhedron_shortest_path_item::clone() const @@ -172,7 +181,9 @@ void Scene_polyhedron_shortest_path_item::poly_item_changed() void Scene_polyhedron_shortest_path_item::changed() { - // Supposedly, this is not the correct 'changed' callback to use + compute_elements(); + are_buffers_filled = false; + } bool Scene_polyhedron_shortest_path_item::get_mouse_ray(QMouseEvent* mouseEvent, Ray_3& outRay) @@ -369,7 +380,7 @@ bool Scene_polyhedron_shortest_path_item::run_point_select(const Ray_3& ray) } break; } - + changed(); return true; } } @@ -477,13 +488,10 @@ void Scene_polyhedron_shortest_path_item::initialize(Scene_polyhedron_item* poly this->m_messages = messages; this->poly_item = polyhedronItem; this->m_sceneInterface = sceneInterface; - connect(polyhedronItem, SIGNAL(item_is_about_to_be_changed()), this, SLOT(poly_item_changed())); - QGLViewer* viewer = *QGLViewer::QGLViewerPool().begin(); viewer->installEventFilter(this); m_mainWindow->installEventFilter(this); - recreate_shortest_path_object(); } diff --git a/Polyhedron/demo/Polyhedron/Scene_polyhedron_shortest_path_item.h b/Polyhedron/demo/Polyhedron/Scene_polyhedron_shortest_path_item.h index 970a55b2f1a..6a51bbcb1f6 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polyhedron_shortest_path_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_polyhedron_shortest_path_item.h @@ -100,6 +100,13 @@ private: void remove_nearest_point(const Face_location& ray); void get_as_edge_point(Face_location& inOutLocation); void get_as_vertex_point(Face_location& inOutLocation); + + std::vector vertices; + mutable QOpenGLShaderProgram *program; + + using Scene_polyhedron_item_decorator::initialize_buffers; + void initialize_buffers(Viewer_interface *viewer = 0) const; + void compute_elements(void); public: @@ -114,13 +121,9 @@ public: Primitives_mode get_primitives_mode() const; virtual bool supportsRenderingMode(RenderingMode m) const; - virtual void draw() const; + using Scene_polyhedron_item_decorator::draw; virtual void draw(Viewer_interface*) const; - // Wireframe OpenGL drawing - virtual void draw_edges() const; - virtual void draw_edges(Viewer_interface*) const; // Points OpenGL drawing - virtual void draw_points() const; virtual void draw_points(Viewer_interface*) const; virtual Scene_polyhedron_shortest_path_item* clone() const; diff --git a/Polyhedron/demo/Polyhedron/Scene_polyhedron_transform_item.cpp b/Polyhedron/demo/Polyhedron/Scene_polyhedron_transform_item.cpp index 2f8a438de54..6ebd27208af 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polyhedron_transform_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_polyhedron_transform_item.cpp @@ -3,65 +3,117 @@ #include "Polyhedron_type.h" Scene_polyhedron_transform_item::Scene_polyhedron_transform_item(const qglviewer::Vec& pos,const Scene_polyhedron_item* poly_item_,const Scene_interface*): - poly_item(poly_item_), - manipulable(false), - frame(new ManipulatedFrame()), - poly(poly_item->polyhedron()), - center_(pos) { frame->setPosition(pos); } + Scene_item(1,1), + poly_item(poly_item_), + manipulable(false), + frame(new ManipulatedFrame()), + poly(poly_item->polyhedron()), + center_(pos) -void Scene_polyhedron_transform_item::draw() const{ - glPushMatrix(); - glMultMatrixd(frame->matrix()); - direct_draw_edges(); - //Scene_item_with_display_list::draw(); - glPopMatrix(); +{ + frame->setPosition(pos); + qFunc.initializeOpenGLFunctions(); } - -void Scene_polyhedron_transform_item::direct_draw_edges() const { - typedef Kernel::Point_3 Point; - typedef Polyhedron::Edge_const_iterator Edge_iterator; - ::glDisable(GL_LIGHTING); - ::glBegin(GL_LINES); - Edge_iterator he; - for(he = poly->edges_begin(); - he != poly->edges_end(); - he++) - { - const Point& a = he->vertex()->point(); - const Point& b = he->opposite()->vertex()->point(); - ::glVertex3d(a.x()-center_.x,a.y()-center_.y,a.z()-center_.z); - ::glVertex3d(b.x()-center_.x,b.y()-center_.y,b.z()-center_.z); - } - ::glEnd(); - ::glEnable(GL_LIGHTING); +void Scene_polyhedron_transform_item::initialize_buffers(Viewer_interface *viewer =0) const +{ + //vao for the edges + { + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT, viewer); + program->bind(); + + vaos[0]->bind(); + buffers[0].bind(); + buffers[0].allocate(positions_lines.data(), + static_cast(positions_lines.size()*sizeof(float))); + program->enableAttributeArray("vertex"); + program->setAttributeBuffer("vertex",GL_FLOAT,0,3); + buffers[0].release(); + + QColor color = this->color(); + program->setAttributeValue("colors",color); + vaos[0]->release(); + program->release(); + } + are_buffers_filled = true; } + +void Scene_polyhedron_transform_item::compute_elements() +{ + positions_lines.resize(0); + typedef Kernel::Point_3 Point; + typedef Polyhedron::Edge_const_iterator Edge_iterator; + + Edge_iterator he; + for(he = poly->edges_begin(); + he != poly->edges_end(); + he++) + { + const Point& a = he->vertex()->point(); + const Point& b = he->opposite()->vertex()->point(); + positions_lines.push_back(a.x()-center_.x); + positions_lines.push_back(a.y()-center_.y); + positions_lines.push_back(a.z()-center_.z); + + positions_lines.push_back(b.x()-center_.x); + positions_lines.push_back(b.y()-center_.y); + positions_lines.push_back(b.z()-center_.z); + + } + +} + +void Scene_polyhedron_transform_item::draw_edges(Viewer_interface* viewer) const +{ + if(!are_buffers_filled) + initialize_buffers(viewer); + vaos[0]->bind(); + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT); + attrib_buffers(viewer,PROGRAM_WITHOUT_LIGHT); + program->bind(); + QMatrix4x4 f_matrix; + for (int i=0; i<16; ++i){ + f_matrix.data()[i] = (float)frame->matrix()[i]; + } + program->setUniformValue("f_matrix", f_matrix); + qFunc.glDrawArrays(GL_LINES, 0, static_cast(positions_lines.size()/3)); + vaos[0]->release(); + program->release(); + +} + QString Scene_polyhedron_transform_item::toolTip() const { - return QObject::tr("

Affine transformation of %1

" - "

Keep Ctrl pressed and use the arcball to define an affine transformation.
" - "Press S to apply the affine transformation to a copy of %1.

") - .arg(getBase()->name()); + return QObject::tr("

Affine transformation of %1

" + "

Keep Ctrl pressed and use the arcball to define an affine transformation.
" + "Press S to apply the affine transformation to a copy of %1.

") + .arg(getBase()->name()); } bool Scene_polyhedron_transform_item::keyPressEvent(QKeyEvent* e){ - if (e->key()==Qt::Key_S){ + if (e->key()==Qt::Key_S){ Q_EMIT stop(); - return true; - } - return false; + return true; + } + return false; } Scene_polyhedron_transform_item::Bbox Scene_polyhedron_transform_item::bbox() const { - const Kernel::Point_3& p = *(poly->points_begin()); - CGAL::Bbox_3 bbox(p.x(), p.y(), p.z(), p.x(), p.y(), p.z()); - for(Polyhedron::Point_const_iterator it = poly->points_begin(); - it != poly->points_end(); - ++it) { - bbox = bbox + it->bbox(); - } - return Bbox(bbox.xmin(),bbox.ymin(),bbox.zmin(), - bbox.xmax(),bbox.ymax(),bbox.zmax()); + const Kernel::Point_3& p = *(poly->points_begin()); + CGAL::Bbox_3 bbox(p.x(), p.y(), p.z(), p.x(), p.y(), p.z()); + for(Polyhedron::Point_const_iterator it = poly->points_begin(); + it != poly->points_end(); + ++it) { + bbox = bbox + it->bbox(); + } + return Bbox(bbox.xmin(),bbox.ymin(),bbox.zmin(), + bbox.xmax(),bbox.ymax(),bbox.zmax()); } + +void Scene_polyhedron_transform_item::changed() +{ + compute_elements(); + are_buffers_filled = false; +} #include "Scene_polyhedron_transform_item.moc" diff --git a/Polyhedron/demo/Polyhedron/Scene_polyhedron_transform_item.h b/Polyhedron/demo/Polyhedron/Scene_polyhedron_transform_item.h index a18542efcad..274fa999d1c 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polyhedron_transform_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_polyhedron_transform_item.h @@ -9,41 +9,42 @@ // This class represents a polyhedron in the OpenGL scene class SCENE_POLYHEDRON_TRANSFORM_ITEM_EXPORT Scene_polyhedron_transform_item - : public Scene_item { -// : public Scene_item_with_display_list { - Q_OBJECT + : public Scene_item { + Q_OBJECT - typedef Scene_polyhedron_item Base; + typedef Scene_polyhedron_item Base; public: - Scene_polyhedron_transform_item(const qglviewer::Vec& pos,const Scene_polyhedron_item* poly_item,const Scene_interface* scene_interface); - void direct_draw_edges() const; - Scene_item* clone() const{return NULL;} - QString toolTip() const; - void direct_draw() const {} - void draw() const; - Bbox bbox() const; - ~Scene_polyhedron_transform_item() {delete frame; Q_EMIT killed();} + Scene_polyhedron_transform_item(const qglviewer::Vec& pos,const Scene_polyhedron_item* poly_item,const Scene_interface* scene_interface); + Scene_item* clone() const{return NULL;} + QString toolTip() const; + void draw_edges(Viewer_interface*) const; + Bbox bbox() const; + ~Scene_polyhedron_transform_item() {delete frame; Q_EMIT killed();} + bool manipulatable() const { return manipulable; } + ManipulatedFrame* manipulatedFrame() { return frame; } + void setManipulatable(bool b = true) { manipulable = b;} + const Scene_polyhedron_item* getBase() const{ return poly_item; }; + const qglviewer::Vec& center() const { return center_; } + virtual bool supportsRenderingMode(RenderingMode m) const { return m==Wireframe ; } + virtual void changed(); + virtual bool keyPressEvent(QKeyEvent*); - bool manipulatable() const { return manipulable; } - ManipulatedFrame* manipulatedFrame() { return frame; } - void setManipulatable(bool b = true) { manipulable = b;} - const Scene_polyhedron_item* getBase() const{ return poly_item; }; - const qglviewer::Vec& center() const { return center_; } - virtual bool supportsRenderingMode(RenderingMode m) const { return m==Wireframe ; } - - virtual bool keyPressEvent(QKeyEvent*); - private: - const Scene_polyhedron_item* poly_item; - bool manipulable; - qglviewer::ManipulatedFrame* frame; - const Polyhedron* poly; - qglviewer::Vec center_; - + const Scene_polyhedron_item* poly_item; + bool manipulable; + qglviewer::ManipulatedFrame* frame; + const Polyhedron* poly; + qglviewer::Vec center_; + mutable QOpenGLShaderProgram *program; + std::vector positions_lines; + using Scene_item::initialize_buffers; + void initialize_buffers(Viewer_interface *viewer) const; + void compute_elements(); + Q_SIGNALS: - void stop(); - void killed(); + void stop(); + void killed(); }; // end class Scene_polyhedron_transform_item #endif // SCENE_POLYHEDRON_TRANSFORM_ITEM_H diff --git a/Polyhedron/demo/Polyhedron/Scene_polylines_item.cpp b/Polyhedron/demo/Polyhedron/Scene_polylines_item.cpp index d27f1551aa4..a2d89050653 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polylines_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_polylines_item.cpp @@ -8,468 +8,866 @@ #include -namespace { - void CGALglcolor(QColor c, int dv = 0) - { - if ( 0 != dv ) + +typedef Scene_polylines_item::K K; +typedef K::Point_3 Point_3; +//Fill the VBO with coordinates of the vertices composing a sphere +void Scene_polylines_item::create_Sphere(double R) +{ + float T, P; + float x[4],y[4],z[4]; + + + //Top of the sphere + for(int t=0; t<360; t+=sectors) { -// workaround for Qt-4.2. -#if QT_VERSION < 0x040300 -# define darker dark -#endif - c = c.darker(dv); -#undef darker + + positions_spheres.push_back(0); + positions_spheres.push_back(0); + positions_spheres.push_back(R); + positions_spheres.push_back(1.0); + + + normals_spheres.push_back(0); + normals_spheres.push_back(0); + normals_spheres.push_back(1); + + + + P = rings*M_PI/180.0; + T = t*M_PI/180.0; + x[1] = sin(P) * cos(T) ; + y[1] = sin(P) * sin(T) ; + z[1] = cos(P); + positions_spheres.push_back(R * x[1]); + positions_spheres.push_back(R * y[1]); + positions_spheres.push_back(R * z[1]); + positions_spheres.push_back(1.0); + + normals_spheres.push_back(x[1]); + normals_spheres.push_back(y[1]); + normals_spheres.push_back(z[1]); + + // + P = rings*M_PI/180.0; + T = (t+sectors)*M_PI/180.0; + x[2] = sin(P) * cos(T) ; + y[2] = sin(P) * sin(T) ; + z[2] = cos(P); + positions_spheres.push_back(R * x[2]); + positions_spheres.push_back(R * y[2]); + positions_spheres.push_back(R * z[2]); + positions_spheres.push_back(1.0); + + normals_spheres.push_back(x[2]); + normals_spheres.push_back(y[2]); + normals_spheres.push_back(z[2]); + + } + + //Body of the sphere + for (int p=rings; p<180-rings; p+=rings) + for(int t=0; t<360; t+=sectors) + { + //A + P = p*M_PI/180.0; + T = t*M_PI/180.0; + x[0] = sin(P) * cos(T) ; + y[0] = sin(P) * sin(T) ; + z[0] = cos(P); + + positions_spheres.push_back(R * x[0]); + positions_spheres.push_back(R * y[0]); + positions_spheres.push_back(R * z[0]); + positions_spheres.push_back(1.0); + + normals_spheres.push_back(x[0]); + normals_spheres.push_back(y[0]); + normals_spheres.push_back(z[0]); + + //B + P = (p+rings)*M_PI/180.0; + T = t*M_PI/180.0; + x[1] = sin(P) * cos(T) ; + y[1] = sin(P) * sin(T) ; + z[1] = cos(P); + positions_spheres.push_back(R * x[1]); + positions_spheres.push_back(R * y[1]); + positions_spheres.push_back(R * z[1]); + positions_spheres.push_back(1.0); + + normals_spheres.push_back(x[1]); + normals_spheres.push_back(y[1]); + normals_spheres.push_back(z[1]); + + //C + P = p*M_PI/180.0; + T = (t+sectors)*M_PI/180.0; + x[2] = sin(P) * cos(T) ; + y[2] = sin(P) * sin(T) ; + z[2] = cos(P); + positions_spheres.push_back(R * x[2]); + positions_spheres.push_back(R * y[2]); + positions_spheres.push_back(R * z[2]); + positions_spheres.push_back(1.0); + + normals_spheres.push_back(x[2]); + normals_spheres.push_back(y[2]); + normals_spheres.push_back(z[2]); + //D + P = (p+rings)*M_PI/180.0; + T = (t+sectors)*M_PI/180.0; + x[3] = sin(P) * cos(T) ; + y[3] = sin(P) * sin(T) ; + z[3] = cos(P); + positions_spheres.push_back(R * x[3]); + positions_spheres.push_back(R * y[3]); + positions_spheres.push_back(R * z[3]); + positions_spheres.push_back(1.0); + + normals_spheres.push_back(x[3]); + normals_spheres.push_back(y[3]); + normals_spheres.push_back(z[3]); + + + + positions_spheres.push_back(R * x[1]); + positions_spheres.push_back(R * y[1]); + positions_spheres.push_back(R * z[1]); + positions_spheres.push_back(1.0); + + normals_spheres.push_back(x[1]); + normals_spheres.push_back(y[1]); + normals_spheres.push_back(z[1]); + + positions_spheres.push_back(R * x[2]); + positions_spheres.push_back(R * y[2]); + positions_spheres.push_back(R * z[2]); + positions_spheres.push_back(1.0); + + normals_spheres.push_back(x[2]); + normals_spheres.push_back(y[2]); + normals_spheres.push_back(z[2]); + + } + //Bottom of the sphere + for(int t=0; t<360; t+=sectors) + { + + + positions_spheres.push_back(0); + positions_spheres.push_back(0); + positions_spheres.push_back(-R); + positions_spheres.push_back(1.0); + + normals_spheres.push_back(0); + normals_spheres.push_back(0); + normals_spheres.push_back(-1); + + + P = (180-rings)*M_PI/180.0; + T = t*M_PI/180.0; + x[1] = sin(P) * cos(T) ; + y[1] = sin(P) * sin(T) ; + z[1] = cos(P); + positions_spheres.push_back(R * x[1]); + positions_spheres.push_back(R * y[1]); + positions_spheres.push_back(R * z[1]); + positions_spheres.push_back(1.0); + + normals_spheres.push_back(x[1]); + normals_spheres.push_back(y[1]); + normals_spheres.push_back(z[1]); + + + P = (180-rings)*M_PI/180.0; + T = (t+sectors)*M_PI/180.0; + x[2] = sin(P) * cos(T) ; + y[2] = sin(P) * sin(T) ; + z[2] = cos(P); + positions_spheres.push_back(R * x[2]); + positions_spheres.push_back(R * y[2]); + positions_spheres.push_back(R * z[2]); + positions_spheres.push_back(1.0); + + normals_spheres.push_back(x[2]); + normals_spheres.push_back(y[2]); + normals_spheres.push_back(z[2]); + } - ::glColor4d(c.red()/255.0, c.green()/255.0, c.blue()/255.0, c.alpha()/255.0); - } } class Scene_polylines_item_private { public: - typedef Scene_polylines_item::K K; - typedef K::Point_3 Point_3; + typedef Scene_polylines_item::K K; + typedef K::Point_3 Point_3; - Scene_polylines_item_private() : - draw_extremities(false), - spheres_drawn_radius(0), - sphere_display_list(0), - quadric(0) - {} + Scene_polylines_item_private() : + draw_extremities(false), + spheres_drawn_radius(0), + sphere_display_list(0), + quadric(0) + {} - ~Scene_polylines_item_private() - { - if(quadric != 0) - gluDeleteQuadric(quadric); - if(sphere_display_list != 0) - glDeleteLists(sphere_display_list, 1); - } + ~Scene_polylines_item_private() + { + if(quadric != 0) + gluDeleteQuadric(quadric); + if(sphere_display_list != 0) + glDeleteLists(sphere_display_list, 1); + } - void draw_sphere(const K::Point_3&, double) const; - void draw_spheres(const Scene_polylines_item*) const; + void draw_sphere(const K::Point_3&, double) const; + void draw_spheres(const Scene_polylines_item*) const; - bool draw_extremities; - double spheres_drawn_radius; + bool draw_extremities; + double spheres_drawn_radius; private: - mutable GLuint sphere_display_list; - mutable GLUquadric* quadric; + mutable GLuint sphere_display_list; + mutable GLUquadric* quadric; }; -Scene_polylines_item::Scene_polylines_item() - : d(new Scene_polylines_item_private()) +void +Scene_polylines_item::initialize_buffers(Viewer_interface *viewer = 0) const { +//vao for the lines + { + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT, viewer); + program->bind(); + + vaos[0]->bind(); + buffers[0].bind(); + buffers[0].allocate(positions_lines.data(), + static_cast(positions_lines.size()*sizeof(float))); + program->enableAttributeArray("vertex"); + program->setAttributeBuffer("vertex",GL_FLOAT,0,4); + buffers[0].release(); + vaos[0]->release(); + program->release(); + } + //vao for the spheres + { + program = getShaderProgram(PROGRAM_INSTANCED, viewer); + program->bind(); + + vaos[1]->bind(); + buffers[1].bind(); + buffers[1].allocate(positions_spheres.data(), + static_cast(positions_spheres.size()*sizeof(float))); + program->enableAttributeArray("vertex"); + program->setAttributeBuffer("vertex",GL_FLOAT,0,4); + buffers[1].release(); + + buffers[2].bind(); + buffers[2].allocate(normals_spheres.data(), + static_cast(normals_spheres.size()*sizeof(float))); + program->enableAttributeArray("normals"); + program->setAttributeBuffer("normals",GL_FLOAT,0,3); + buffers[2].release(); + + buffers[3].bind(); + buffers[3].allocate(color_spheres.data(), + static_cast(color_spheres.size()*sizeof(float))); + program->enableAttributeArray("colors"); + program->setAttributeBuffer("colors",GL_FLOAT,0,3); + buffers[3].release(); + + buffers[4].bind(); + buffers[4].allocate(positions_center.data(), + static_cast(positions_center.size()*sizeof(float))); + program->enableAttributeArray("center"); + program->setAttributeBuffer("center",GL_FLOAT,0,3); + buffers[4].release(); + + qFunc.glVertexAttribDivisor(program->attributeLocation("center"), 1); + qFunc.glVertexAttribDivisor(program->attributeLocation("colors"), 1); + vaos[1]->release(); + + program->release(); + } + +//vao for the wired spheres + { + program = getShaderProgram(PROGRAM_INSTANCED_WIRE, viewer); + program->bind(); + + vaos[2]->bind(); + buffers[5].bind(); + buffers[5].allocate(positions_wire_spheres.data(), + static_cast(positions_wire_spheres.size()*sizeof(float))); + program->enableAttributeArray("vertex"); + program->setAttributeBuffer("vertex",GL_FLOAT,0,4); + buffers[5].release(); + QColor temp = this->color(); + program->setAttributeValue("colors", temp); + + program->setAttributeValue("normals",QVector3D(0.0,0.0,0.0)); + + buffers[6].bind(); + buffers[6].allocate(color_spheres.data(), + static_cast(color_spheres.size()*sizeof(float))); + program->enableAttributeArray("colors"); + program->setAttributeBuffer("colors",GL_FLOAT,0,3); + buffers[6].release(); + + buffers[7].bind(); + buffers[7].allocate(positions_center.data(), + static_cast(positions_center.size()*sizeof(float))); + program->enableAttributeArray("center"); + program->setAttributeBuffer("center",GL_FLOAT,0,3); + buffers[7].release(); + + qFunc.glVertexAttribDivisor(program->attributeLocation("center"), 1); + vaos[2]->release(); + program->release(); + } + + are_buffers_filled = true; + +} +void +Scene_polylines_item::compute_elements() +{ + positions_spheres.resize(0); + positions_wire_spheres.resize(0); + positions_lines.resize(0); + color_spheres.resize(0); + normals_spheres.resize(0); + positions_center.resize(0); + nbSpheres = 0; + + //Fills the VBO with the lines + for(std::list >::const_iterator it = polylines.begin(); + it != polylines.end(); + ++it){ + if(it->empty()) continue; + for(size_t i = 0, end = it->size()-1; + i < end; ++i) + { + const Point_3& a = (*it)[i]; + const Point_3& b = (*it)[i+1]; + positions_lines.push_back(a.x()); + positions_lines.push_back(a.y()); + positions_lines.push_back(a.z()); + positions_lines.push_back(1.0); + + positions_lines.push_back(b.x()); + positions_lines.push_back(b.y()); + positions_lines.push_back(b.z()); + positions_lines.push_back(1.0); + + } + + } + //Fills the VBO with the spheres + if(d->draw_extremities) + { + + // FIRST, count the number of incident cycles and polylines + // for all extremities. + typedef std::map Point_to_int_map; + typedef Point_to_int_map::iterator iterator; + Point_to_int_map corner_polyline_nb; + + { // scope to fill corner_polyline_nb' + Point_to_int_map corner_cycles_nb; + + for(std::list >::const_iterator + it = this->polylines.begin(), + end = this->polylines.end(); + it != end; ++it) + { + const K::Point_3& a = *it->begin(); + const K::Point_3& b = *it->rbegin(); + if(a == b) { + if ( it->size()>1 ) + ++corner_cycles_nb[a]; + else + ++corner_polyline_nb[a]; + } + else { + ++corner_polyline_nb[a]; + ++corner_polyline_nb[b]; + } + } + // THEN, ignore points that are incident to one cycle only. + for(iterator + c_it = corner_cycles_nb.begin(), + end = corner_cycles_nb.end(); + c_it != end; ++c_it) + { + const Point_3& a = c_it->first; + + iterator p_it = corner_polyline_nb.find(a); + + // If the point 'a'=c_it->first has only incident cycles... + if(p_it == corner_polyline_nb.end()) { + // ...then count it as a corner only if it has two incident cycles + // or more. + if(c_it->second > 1) { + corner_polyline_nb[a] = c_it->second; + } + } else { + // else add the number of cycles. + p_it->second += c_it->second; + } + } + } + // At this point, 'corner_polyline_nb' gives the multiplicity of all + // corners. + //Finds the centers of the spheres and their color + for(iterator + p_it = corner_polyline_nb.begin(), + end = corner_polyline_nb.end(); + p_it != end; ++p_it) + { + nbSpheres++; + const K::Point_3& centre = p_it->first; + positions_center.push_back(centre.x()); + positions_center.push_back(centre.y()); + positions_center.push_back(centre.z()); + + float colors[3]; + switch(p_it->second) { + case 1: + colors[0] = 0.0; // black + colors[1] = 0.0; + colors[2] = 0.0; + break; + case 2: + colors[0] = 0.0; // green + colors[1] = 0.8f; + colors[2] = 0.0; + break; + case 3: + colors[0] = 0.0; // blue + colors[1] = 0.0; + colors[2] = 0.8f; + break; + case 4: + colors[0] = 0.8f; //red + colors[1] = 0.0; + colors[2] = 0.0; + break; + default: + colors[0] = 0.8f; //fuschia + colors[1] = 0.0; + colors[2] = 0.8f; + } + + color_spheres.push_back(colors[0]); + color_spheres.push_back(colors[1]); + color_spheres.push_back(colors[2]); + } + create_Sphere(d->spheres_drawn_radius); + + //Convert the triangle coordinates to lines coordinates for the + //Wiremode in the spheres + for(int i=0; i< (int) positions_spheres.size();) + { + //draw triangles + if(i< (360/sectors)*12) + { + //AB + for(int j=i; j boxes; - for(std::list >::const_iterator it = polylines.begin(); - it != polylines.end(); - ++it){ - if(it->begin() != it->end()) { - Iso_cuboid_3 cub = CGAL::bounding_box(it->begin(), it->end()); - boxes.push_back((cub.min)()); - boxes.push_back((cub.max)()); + if(isEmpty()) + return Bbox(); + std::list boxes; + for(std::list >::const_iterator it = polylines.begin(); + it != polylines.end(); + ++it){ + if(it->begin() != it->end()) { + Iso_cuboid_3 cub = CGAL::bounding_box(it->begin(), it->end()); + boxes.push_back((cub.min)()); + boxes.push_back((cub.max)()); + } } - } - Iso_cuboid_3 bbox = - boxes.begin() != boxes.end() ? - CGAL::bounding_box(boxes.begin(), boxes.end()) : - Iso_cuboid_3(); + Iso_cuboid_3 bbox = + boxes.begin() != boxes.end() ? + CGAL::bounding_box(boxes.begin(), boxes.end()) : + Iso_cuboid_3(); - return Bbox(bbox.xmin(), - bbox.ymin(), - bbox.zmin(), - bbox.xmax(), - bbox.ymax(), - bbox.zmax()); + return Bbox(bbox.xmin(), + bbox.ymin(), + bbox.zmin(), + bbox.xmax(), + bbox.ymax(), + bbox.zmax()); } Scene_polylines_item* Scene_polylines_item::clone() const { - Scene_polylines_item* item = new Scene_polylines_item; - item->polylines = polylines; - QVariant metadata_variant = property("polylines metadata"); - if(metadata_variant.type() == QVariant::StringList) - { - item->setProperty("polylines metadata", metadata_variant); - } - return item; + Scene_polylines_item* item = new Scene_polylines_item; + item->polylines = polylines; + QVariant metadata_variant = property("polylines metadata"); + if(metadata_variant.type() == QVariant::StringList) + { + item->setProperty("polylines metadata", metadata_variant); + } + return item; } QString Scene_polylines_item::toolTip() const { - QString s = - tr("

%1 (mode: %2, color: %3)
" - "Polylines

" - "

Number of polylines: %4

") - .arg(this->name()) - .arg(this->renderingModeName()) - .arg(this->color().name()) - .arg(polylines.size()); - if(d->draw_extremities) { - s += tr("

Legende of endpoints colors:

    " - "
  • black: one incident polyline
  • " - "
  • green: two incident polylines
  • " - "
  • blue: three incident polylines
  • " - "
  • red: four incident polylines
  • " - "
  • fuchsia: five or more incident polylines
  • " - "

"); - } - return s; + QString s = + tr("

%1 (mode: %2, color: %3)
" + "Polylines

" + "

Number of polylines: %4

") + .arg(this->name()) + .arg(this->renderingModeName()) + .arg(this->color().name()) + .arg(polylines.size()); + if(d->draw_extremities) { + s += tr("

Legende of endpoints colors:

    " + "
  • black: one incident polyline
  • " + "
  • green: two incident polylines
  • " + "
  • blue: three incident polylines
  • " + "
  • red: four incident polylines
  • " + "
  • fuchsia: five or more incident polylines
  • " + "

"); + } + return s; } bool Scene_polylines_item::supportsRenderingMode(RenderingMode m) const { - return (m == Wireframe || + return (m == Wireframe || m == FlatPlusEdges || m == Points); } // Shaded OpenGL drawing: only draw spheres void -Scene_polylines_item::draw() const { - if(d->draw_extremities) - d->draw_spheres(this); +Scene_polylines_item::draw(Viewer_interface* viewer) const { + + if(!are_buffers_filled) + initialize_buffers(viewer); + if(d->draw_extremities) + { + vaos[1]->bind(); + program = getShaderProgram(PROGRAM_INSTANCED); + attrib_buffers(viewer, PROGRAM_INSTANCED); + program->bind(); + qFunc.glDrawArraysInstanced(GL_TRIANGLES, 0, + static_cast(positions_spheres.size()/4), nbSpheres); + program->release(); + vaos[1]->release(); + } } // Wireframe OpenGL drawing void -Scene_polylines_item::draw_edges() const { - CGALglcolor(this->color()); - ::glBegin(GL_LINES); - for(std::list >::const_iterator it = polylines.begin(); - it != polylines.end(); - ++it){ - if(it->empty()) continue; - for(size_t i = 0, end = it->size()-1; - i < end; ++i) +Scene_polylines_item::draw_edges(Viewer_interface* viewer) const { + + if(!are_buffers_filled) + initialize_buffers(viewer); + + vaos[0]->bind(); + attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT); + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT); + program->bind(); + QColor temp = this->color(); + program->setAttributeValue("colors", temp); + qFunc.glDrawArrays(GL_LINES, 0, static_cast(positions_lines.size()/4)); + program->release(); + vaos[0]->release(); + if(d->draw_extremities) { - const Point_3& a = (*it)[i]; - const Point_3& b = (*it)[i+1]; - ::glVertex3d(a.x(), a.y(), a.z()); - ::glVertex3d(b.x(), b.y(), b.z()); + vaos[2]->bind(); + attrib_buffers(viewer, PROGRAM_INSTANCED_WIRE); + program = getShaderProgram(PROGRAM_INSTANCED_WIRE); + program->bind(); + qFunc.glDrawArraysInstanced(GL_LINES, 0, + static_cast(positions_wire_spheres.size()/4), nbSpheres); + program->release(); + vaos[2]->release(); } - } - ::glEnd(); - if(d->draw_extremities) - { - d->draw_spheres(this); - } + } void -Scene_polylines_item::draw_points() const { - ::glBegin(GL_POINTS); - // draw all points but endpoints - for(std::list >::const_iterator it = polylines.begin(); - it != polylines.end(); - ++it) - { - if(it->empty()) continue; - for(size_t i = 1, end = it->size()-1; - i < end; ++i) - { - const Point_3& a = (*it)[i]; - ::glVertex3d(a.x(), a.y(), a.z()); - } - } - ::glEnd(); +Scene_polylines_item::draw_points(Viewer_interface* viewer) const { + if(!are_buffers_filled) + initialize_buffers(viewer); - ::glColor3d(1., 0., 0.); //red - // draw endpoints - ::glBegin(GL_POINTS); - for(std::list >::const_iterator it = polylines.begin(); - it != polylines.end(); - ++it){ - if(it->empty()) continue; - const Point_3& a = (*it)[0]; - const Point_3& b = (*it)[it->size()-1]; - ::glVertex3d(a.x(), a.y(), a.z()); - ::glVertex3d(b.x(), b.y(), b.z()); - } - ::glEnd(); -} - -void -Scene_polylines_item_private:: -draw_spheres(const Scene_polylines_item* item) const { - // FIRST, count the number of incident cycles and polylines - // for all extremities. - typedef std::map Point_to_int_map; - typedef Point_to_int_map::iterator iterator; - Point_to_int_map corner_polyline_nb; - - { // scope to fill corner_polyline_nb' - Point_to_int_map corner_cycles_nb; - - for(std::list >::const_iterator - it = item->polylines.begin(), - end = item->polylines.end(); - it != end; ++it) - { - const K::Point_3& a = *it->begin(); - const K::Point_3& b = *it->rbegin(); - if(a == b) { - if ( it->size()>1 ) - ++corner_cycles_nb[a]; - else - ++corner_polyline_nb[a]; - } - else { - ++corner_polyline_nb[a]; - ++corner_polyline_nb[b]; - } - } - // THEN, ignore points that are incident to one cycle only. - for(iterator - c_it = corner_cycles_nb.begin(), - end = corner_cycles_nb.end(); - c_it != end; ++c_it) - { - const Point_3& a = c_it->first; - - iterator p_it = corner_polyline_nb.find(a); - - // If the point 'a'=c_it->first has only incident cycles... - if(p_it == corner_polyline_nb.end()) { - // ...then count it as a corner only if it has two incident cycles - // or more. - if(c_it->second > 1) { - corner_polyline_nb[a] = c_it->second; - } - } else { - // else add the number of cycles. - p_it->second += c_it->second; - } - } - } - // At this point, 'corner_polyline_nb' gives the multiplicity of all - // corners. - for(iterator - p_it = corner_polyline_nb.begin(), - end = corner_polyline_nb.end(); - p_it != end; ++p_it) - { - switch(p_it->second) { - case 1: - ::glColor3d(0.0, 0.0, 0.0); // black - break; - case 2: - ::glColor3d(0.0, 0.8, 0.0); // green - break; - case 3: - ::glColor3d(0.0, 0.0, 0.8); // blue - break; - case 4: - ::glColor3d(0.8, 0.0, 0.0); //red - break; - default: - ::glColor3d(0.8, 0.0, 0.8); //fuschia - } - this->draw_sphere(p_it->first, this->spheres_drawn_radius); - } -} - -void -Scene_polylines_item_private::draw_sphere(const K::Point_3& p, - double r) const -{ - if(sphere_display_list == 0) { - sphere_display_list = glGenLists(1); - if(sphere_display_list == 0) - std::cerr << "ERROR: Cannot create display list!\n"; - if(quadric == 0) - quadric = gluNewQuadric(); - if(quadric == 0) - std::cerr << "ERROR: Cannot create GLU quadric!\n"; - glNewList(sphere_display_list, GL_COMPILE); - gluSphere(quadric, 1., 10, 10); - glEndList(); - if(glGetError() != GL_NO_ERROR) - std::cerr << gluErrorString(glGetError()); - } - glPushMatrix(); - glTranslated(CGAL::to_double(p.x()), - CGAL::to_double(p.y()), - CGAL::to_double(p.z())); - - glScaled(r, r, r); - glCallList(sphere_display_list); - glPopMatrix(); + vaos[0]->bind(); + attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT); + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT); + program->bind(); + qFunc.glDrawArrays(GL_POINTS, 0, static_cast(positions_lines.size()/4)); + // Clean-up + vaos[0]->release(); + program->release(); } QMenu* Scene_polylines_item::contextMenu() { - const char* prop_name = "Menu modified by Scene_polylines_item."; + const char* prop_name = "Menu modified by Scene_polylines_item."; - QMenu* menu = Scene_item::contextMenu(); + QMenu* menu = Scene_item::contextMenu(); - // Use dynamic properties: - // http://doc.trolltech.com/lastest/qobject.html#property - bool menuChanged = menu->property(prop_name).toBool(); + // Use dynamic properties: + // http://doc.qt.io/qt-5/qobject.html#property + bool menuChanged = menu->property(prop_name).toBool(); + + if(!menuChanged) { + menu->addSeparator(); + // TODO: add actions to display corners + QAction* action = menu->addAction(tr("Display corners with radius...")); + connect(action, SIGNAL(triggered()), + this, SLOT(change_corner_radii())); + + QAction* actionSmoothPolylines = + menu->addAction(tr("Smooth polylines")); + actionSmoothPolylines->setObjectName("actionSmoothPolylines"); + connect(actionSmoothPolylines, SIGNAL(triggered()),this, SLOT(smooth())); + menu->setProperty(prop_name, true); + } + return menu; +} + +void Scene_polylines_item::changed() +{ + compute_elements(); + are_buffers_filled = false; - if(!menuChanged) { - menu->addSeparator(); - // TODO: add actions to display corners - QAction* action = menu->addAction(tr("Display corners with radius...")); - connect(action, SIGNAL(triggered()), - this, SLOT(change_corner_radii())); - QAction* actionSmoothPolylines = - menu->addAction(tr("Smooth polylines")); - actionSmoothPolylines->setObjectName("actionSmoothPolylines"); - connect(actionSmoothPolylines, SIGNAL(triggered()),this, SLOT(smooth())); - menu->setProperty(prop_name, true); - } - return menu; } void Scene_polylines_item::change_corner_radii() { - bool ok = true; - double proposed_radius = d->spheres_drawn_radius; - if(proposed_radius == 0) { - Scene_interface::Bbox b = bbox(); - proposed_radius = (std::max)(b.xmax - b.xmin, - proposed_radius); - proposed_radius = (std::max)(b.ymax - b.ymin, - proposed_radius); - proposed_radius = (std::max)(b.zmax - b.zmin, - proposed_radius); - proposed_radius /= 100; - } - double r = QInputDialog::getDouble(NULL, - tr("Display corners with new radius..."), - tr("Radius:"), - proposed_radius, // value - 0., // min - 2147483647., // max - 10, // decimals - &ok); - if(ok) { - change_corner_radii(r); - } + bool ok = true; + double proposed_radius = d->spheres_drawn_radius; + if(proposed_radius == 0) { + Scene_interface::Bbox b = bbox(); + proposed_radius = (std::max)(b.xmax - b.xmin, + proposed_radius); + proposed_radius = (std::max)(b.ymax - b.ymin, + proposed_radius); + proposed_radius = (std::max)(b.zmax - b.zmin, + proposed_radius); + proposed_radius /= 100; + } + double r = QInputDialog::getDouble(NULL, + tr("Display corners with new radius..."), + tr("Radius:"), + proposed_radius, // value + 0., // min + 2147483647., // max + 10, // decimals + &ok); + if(ok) { + change_corner_radii(r); + } } void Scene_polylines_item::change_corner_radii(double r) { - if(r >= 0) { - d->spheres_drawn_radius = r; - d->draw_extremities = (r > 0); - this->changed(); + if(r >= 0) { + d->spheres_drawn_radius = r; + d->draw_extremities = (r > 0); + this->changed(); Q_EMIT itemChanged(); - } + } } void Scene_polylines_item::split_at_sharp_angles() { - typedef Polylines_container Bare_polyline_container; - typedef Polyline Bare_polyline; - Polylines_container& bare_polylines = polylines; + typedef Polylines_container Bare_polyline_container; + typedef Polyline Bare_polyline; + Polylines_container& bare_polylines = polylines; - int counter = 0; - for(Bare_polyline_container::iterator + int counter = 0; + for(Bare_polyline_container::iterator bare_polyline_it = bare_polylines.begin(); - bare_polyline_it != bare_polylines.end(); // the end changes - // during the loop - ++counter /* bare_polyline_it is incremented in the loop */) - { - Bare_polyline_container::iterator current_polyline_it = - bare_polyline_it; - Bare_polyline& bare_polyline = *bare_polyline_it; - Bare_polyline::iterator it = boost::next(bare_polyline.begin()); - - if(boost::next(bare_polyline.begin()) == bare_polyline.end()) + bare_polyline_it != bare_polylines.end(); // the end changes + // during the loop + ++counter /* bare_polyline_it is incremented in the loop */) { - std::cerr << "WARNING: Isolated point in polylines\n"; - bare_polyline_it = bare_polylines.erase(bare_polyline_it); - continue; - } - else - ++bare_polyline_it; - if(it != bare_polyline.end()) { - for(; it != boost::prior(bare_polyline.end()); ++it) { - const Point_3 pv = *it; - const Point_3 pa = *boost::prior(it); - const Point_3 pb = *boost::next(it); - const K::Vector_3 av = pv - pa; - const K::Vector_3 bv = pv - pb; - const K::FT sc_prod = av * bv; - if( sc_prod >= 0 || - (sc_prod < 0 && - CGAL::square(sc_prod) < (av * av) * (bv * bv) / 4 ) ) + Bare_polyline_container::iterator current_polyline_it = + bare_polyline_it; + Bare_polyline& bare_polyline = *bare_polyline_it; + Bare_polyline::iterator it = boost::next(bare_polyline.begin()); + + if(boost::next(bare_polyline.begin()) == bare_polyline.end()) { -#ifdef PROTECTION_DEBUG - std::cerr << "Split polyline (small angle) " - << std::acos(sqrt(CGAL::square(sc_prod) / - ((av*av) * (bv*bv)))) * 180 /CGAL_PI - << " degres\n"; -#endif - Bare_polyline new_polyline; - std::copy(it, bare_polyline.end(), - std::back_inserter(new_polyline)); - - if(*bare_polyline.begin() == *bare_polyline.rbegin()) { - // if the polyline is a cycle, test if its beginning is a sharp - // angle... - const Point_3 pv = *bare_polyline.begin(); - const Point_3 pa = *boost::prior(boost::prior(bare_polyline.end())); - const Point_3 pb = *boost::next(bare_polyline.begin()); - const K::Vector_3 av = pv - pa; - const K::Vector_3 bv = pv - pb; - const K::FT sc_prod = av * bv; - if( sc_prod >= 0 || - (sc_prod < 0 && - CGAL::square(sc_prod) < (av * av) * (bv * bv) / 4 ) ) - { - // if its beginning is a sharp angle, then split - bare_polyline.erase(boost::next(it), bare_polyline.end()); - } - else { - // ...if not, modifies its beginning - std::copy(boost::next(bare_polyline.begin()), - boost::next(it), - std::back_inserter(new_polyline)); - bare_polylines.erase(current_polyline_it); - } - } - else { - bare_polyline.erase(boost::next(it), bare_polyline.end()); - } - bare_polylines.push_back(new_polyline); - break; + std::cerr << "WARNING: Isolated point in polylines\n"; + bare_polyline_it = bare_polylines.erase(bare_polyline_it); + continue; + } + else + ++bare_polyline_it; + if(it != bare_polyline.end()) { + for(; it != boost::prior(bare_polyline.end()); ++it) { + const Point_3 pv = *it; + const Point_3 pa = *boost::prior(it); + const Point_3 pb = *boost::next(it); + const K::Vector_3 av = pv - pa; + const K::Vector_3 bv = pv - pb; + const K::FT sc_prod = av * bv; + if( sc_prod >= 0 || + (sc_prod < 0 && + CGAL::square(sc_prod) < (av * av) * (bv * bv) / 4 ) ) + { +#ifdef PROTECTION_DEBUG + std::cerr << "Split polyline (small angle) " + << std::acos(sqrt(CGAL::square(sc_prod) / + ((av*av) * (bv*bv)))) * 180 /CGAL_PI + << " degres\n"; +#endif + Bare_polyline new_polyline; + std::copy(it, bare_polyline.end(), + std::back_inserter(new_polyline)); + + if(*bare_polyline.begin() == *bare_polyline.rbegin()) { + // if the polyline is a cycle, test if its beginning is a sharp + // angle... + const Point_3 pv = *bare_polyline.begin(); + const Point_3 pa = *boost::prior(boost::prior(bare_polyline.end())); + const Point_3 pb = *boost::next(bare_polyline.begin()); + const K::Vector_3 av = pv - pa; + const K::Vector_3 bv = pv - pb; + const K::FT sc_prod = av * bv; + if( sc_prod >= 0 || + (sc_prod < 0 && + CGAL::square(sc_prod) < (av * av) * (bv * bv) / 4 ) ) + { + // if its beginning is a sharp angle, then split + bare_polyline.erase(boost::next(it), bare_polyline.end()); + } + else { + // ...if not, modifies its beginning + std::copy(boost::next(bare_polyline.begin()), + boost::next(it), + std::back_inserter(new_polyline)); + bare_polylines.erase(current_polyline_it); + } + } + else { + bare_polyline.erase(boost::next(it), bare_polyline.end()); + } + bare_polylines.push_back(new_polyline); + break; + } + } } - } } - } Q_EMIT itemChanged(); } void Scene_polylines_item::merge(Scene_polylines_item* other_item) { - if(other_item == 0) return; - std::copy(other_item->polylines.begin(), - other_item->polylines.end(), - std::back_inserter(polylines)); - QVariant other_metadata_variant = other_item->property("polylines metadata"); - if(other_metadata_variant.type() == QVariant::StringList) - { - QStringList metadata = property("polylines metadata").toStringList(); - metadata.append(other_metadata_variant.toStringList()); - setProperty("polylines metadata", metadata); - } - changed(); + if(other_item == 0) return; + std::copy(other_item->polylines.begin(), + other_item->polylines.end(), + std::back_inserter(polylines)); + QVariant other_metadata_variant = other_item->property("polylines metadata"); + if(other_metadata_variant.type() == QVariant::StringList) + { + QStringList metadata = property("polylines metadata").toStringList(); + metadata.append(other_metadata_variant.toStringList()); + setProperty("polylines metadata", metadata); + } + changed(); } #include "Scene_polylines_item.moc" diff --git a/Polyhedron/demo/Polyhedron/Scene_polylines_item.h b/Polyhedron/demo/Polyhedron/Scene_polylines_item.h index b2e29fc1e31..bd5059f0499 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polylines_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_polylines_item.h @@ -1,8 +1,7 @@ #ifndef SCENE_POLYLINES_ITEM_H #define SCENE_POLYLINES_ITEM_H - #include "Scene_polylines_item_config.h" - +#include "Viewer_interface.h" #include #include "Scene_item.h" @@ -16,77 +15,104 @@ class Scene_polylines_item_private; class SCENE_POLYLINES_ITEM_EXPORT Scene_polylines_item : public Scene_item { - Q_OBJECT + Q_OBJECT public: - typedef CGAL::Exact_predicates_inexact_constructions_kernel K; - typedef K::Point_3 Point_3; - typedef std::vector Polyline; - typedef std::list Polylines_container; + typedef CGAL::Exact_predicates_inexact_constructions_kernel K; + typedef K::Point_3 Point_3; + typedef std::vector Polyline; + typedef std::list Polylines_container; - typedef K::Iso_cuboid_3 Iso_cuboid_3; + typedef K::Iso_cuboid_3 Iso_cuboid_3; - Scene_polylines_item(); - virtual ~Scene_polylines_item(); + Scene_polylines_item(); + virtual ~Scene_polylines_item(); - bool isFinite() const { return true; } - bool isEmpty() const; - Bbox bbox() const; + bool isFinite() const { return true; } + bool isEmpty() const; + Bbox bbox() const; - Scene_polylines_item* clone() const; + Scene_polylines_item* clone() const; - QString toolTip() const; + QString toolTip() const; - // Indicate if rendering mode is supported - bool supportsRenderingMode(RenderingMode m) const; + // Indicate if rendering mode is supported + bool supportsRenderingMode(RenderingMode m) const; - QMenu* contextMenu(); - - // Flat/Gouraud OpenGL drawing - void draw() const; + QMenu* contextMenu(); - // Wireframe OpenGL drawing - void draw_edges() const; + // Flat/Gouraud OpenGL drawing + void draw() const {} + void draw(Viewer_interface*) const; - void draw_points() const; - - void smooth(std::vector& polyline){ - bool is_closed = polyline.front()==polyline.back(); - typedef K::Vector_3 Vector_3; - - std::size_t start = is_closed ? 0:1; - std::size_t end = polyline.size()-1; - - Vector_3 prev = (is_closed ? polyline[end-1] : polyline[0]) - CGAL::ORIGIN; - - for (std::size_t i=start; i!=end; ++i) - { - Vector_3 curr = polyline[i] - CGAL::ORIGIN; - Vector_3 next = polyline[i+1] - CGAL::ORIGIN; - - polyline[i] = CGAL::ORIGIN+(prev+2*curr+next)/4; - prev=curr; + // Wireframe OpenGL drawing + void draw_edges() const{} + void draw_edges(Viewer_interface*) const; + + void draw_points() const{} + void draw_points(Viewer_interface*) const; + + + void smooth(std::vector& polyline){ + bool is_closed = polyline.front()==polyline.back(); + typedef K::Vector_3 Vector_3; + + std::size_t start = is_closed ? 0:1; + std::size_t end = polyline.size()-1; + + Vector_3 prev = (is_closed ? polyline[end-1] : polyline[0]) - CGAL::ORIGIN; + + for (std::size_t i=start; i!=end; ++i) + { + Vector_3 curr = polyline[i] - CGAL::ORIGIN; + Vector_3 next = polyline[i+1] - CGAL::ORIGIN; + + polyline[i] = CGAL::ORIGIN+(prev+2*curr+next)/4; + prev=curr; + } + + if (is_closed) polyline[end]=polyline[0]; } - - if (is_closed) polyline[end]=polyline[0]; - } - + public Q_SLOTS: - void change_corner_radii(double); - void change_corner_radii(); - void split_at_sharp_angles(); + virtual void changed(); + void change_corner_radii(double); + void change_corner_radii(); + void split_at_sharp_angles(); - void merge(Scene_polylines_item*); + void merge(Scene_polylines_item*); - void smooth(){ - for (Polylines_container::iterator pit=polylines.begin(),pit_end=polylines.end();pit!=pit_end;++pit) - smooth(*pit); + void smooth(){ + for (Polylines_container::iterator pit=polylines.begin(),pit_end=polylines.end();pit!=pit_end;++pit) + smooth(*pit); Q_EMIT itemChanged(); - } + } public: - Polylines_container polylines; + Polylines_container polylines; + + // http://en.wikipedia.org/wiki/D-pointer + Scene_polylines_item_private* d; +private: + std::vector positions_lines; + std::vector positions_spheres; + std::vector positions_wire_spheres; + std::vector positions_center; + std::vector normals_spheres; + std::vector color_spheres; + + + mutable QOpenGLShaderProgram *program; + mutable GLuint nbSpheres; + //The more small they are, the more precise the Sphere will be. + // Must be a multiple of 360 and 180. + int rings; + int sectors; + typedef std::map Point_to_int_map; + typedef Point_to_int_map::iterator iterator; + void create_Sphere(double); + using Scene_item::initialize_buffers; + void initialize_buffers(Viewer_interface *viewer) const; + void compute_elements(); - // http://en.wikipedia.org/wiki/D-pointer - Scene_polylines_item_private* d; }; // end class Scene_polylines_item diff --git a/Polyhedron/demo/Polyhedron/Scene_textured_polyhedron_item.cpp b/Polyhedron/demo/Polyhedron/Scene_textured_polyhedron_item.cpp index 11074c77f43..01d4db6dc1c 100644 --- a/Polyhedron/demo/Polyhedron/Scene_textured_polyhedron_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_textured_polyhedron_item.cpp @@ -7,25 +7,218 @@ typedef EPIC_kernel::Point_3 Point; -Scene_textured_polyhedron_item::Scene_textured_polyhedron_item() - : Scene_item_with_display_list(), - poly(new Textured_polyhedron) + +void Scene_textured_polyhedron_item::initialize_buffers(Viewer_interface *viewer = 0) const { - texture.GenerateCheckerBoard(2048,2048,128,0,0,0,250,250,255); + //vao for the facets + { + program = getShaderProgram(PROGRAM_WITH_TEXTURE, viewer); + program->bind(); + vaos[0]->bind(); + buffers[0].bind(); + buffers[0].allocate(positions_facets.data(), + static_cast(positions_facets.size()*sizeof(float))); + program->enableAttributeArray("vertex"); + program->setAttributeBuffer("vertex",GL_FLOAT,0,4); + buffers[0].release(); + + buffers[1].bind(); + buffers[1].allocate(normals.data(), + static_cast(normals.size()*sizeof(float))); + program->enableAttributeArray("normal"); + program->setAttributeBuffer("normal",GL_FLOAT,0,3); + buffers[1].release(); + + + buffers[2].bind(); + buffers[2].allocate(textures_map_facets.data(), + static_cast(textures_map_facets.size()*sizeof(float))); + program->enableAttributeArray("v_texCoord"); + program->setAttributeBuffer("v_texCoord",GL_FLOAT,0,2); + buffers[2].release(); + vaos[0]->release(); + program->release(); + } + + //vao for the lines + { + program = getShaderProgram(PROGRAM_WITH_TEXTURED_EDGES, viewer); + program->bind(); + vaos[1]->bind(); + buffers[3].bind(); + buffers[3].allocate(positions_lines.data(), + static_cast(positions_lines.size()*sizeof(float))); + program->enableAttributeArray("vertex"); + program->setAttributeBuffer("vertex",GL_FLOAT,0,4); + buffers[3].release(); + + + buffers[4].bind(); + buffers[4].allocate(textures_map_lines.data(), + static_cast(textures_map_lines.size()*sizeof(float))); + program->enableAttributeArray("v_texCoord"); + program->setAttributeBuffer("v_texCoord",GL_FLOAT,0,2); + buffers[4].release(); + vaos[1]->release(); + program->release(); + } + qFunc.glActiveTexture(GL_TEXTURE0); + qFunc.glBindTexture(GL_TEXTURE_2D, textureId); + qFunc.glTexImage2D(GL_TEXTURE_2D, + 0, + GL_RGB, + texture.GetWidth(), + texture.GetHeight(), + 0, + GL_RGB, + GL_UNSIGNED_BYTE, + texture.GetData()); + qFunc.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + qFunc.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + qFunc.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + qFunc.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + + are_buffers_filled = true; +} + +void +Scene_textured_polyhedron_item::compute_normals_and_vertices(void) +{ + positions_facets.resize(0); + positions_lines.resize(0); + textures_map_facets.resize(0); + textures_map_lines.resize(0); + normals.resize(0); + + typedef ::EPIC_kernel Kernel; + typedef CGAL::Textured_items Items; + typedef Kernel::Point_3 Point; + typedef Kernel::Vector_3 Vector; + typedef CGAL::Polyhedron_3 Base; + + typedef Base::Halfedge_around_facet_circulator Halfedge_around_facet_circulator; + typedef Base::Edge_iterator Edge_iterator; + typedef Base::Facet Facet; + typedef Base::Facet_iterator Facet_iterator; + + //Facets + Facet_iterator f = poly->facets_begin(); + + for(f = poly->facets_begin(); + f != poly->facets_end(); + f++) + { + + Halfedge_around_facet_circulator he = f->facet_begin(); + Halfedge_around_facet_circulator end = he; + CGAL_For_all(he,end) + { + + // If Flat shading:1 normal per polygon added once per vertex + if (cur_shading == Flat || cur_shading == FlatPlusEdges) + { + + Vector n = compute_facet_normal(*f); + normals.push_back(n[0]); + normals.push_back(n[1]); + normals.push_back(n[2]); + } + + // If Gouraud shading: 1 normal per vertex + else if(cur_shading == Gouraud) + { + + const Facet::Normal_3& n = he->vertex()->normal(); + normals.push_back(n[0]); + normals.push_back(n[1]); + normals.push_back(n[2]); + } + + //position + const Point& p = he->vertex()->point(); + positions_facets.push_back(p.x()); + positions_facets.push_back(p.y()); + positions_facets.push_back(p.z()); + positions_facets.push_back(1.0); + + const double u = he->vertex()->u(); + const double v = he->vertex()->v(); + textures_map_facets.push_back(u); + textures_map_facets.push_back(v); + } + + + } + //Lines + typedef Kernel::Point_3 Point; + typedef Base::Edge_iterator Edge_iterator; + + Edge_iterator he; + + for(he = poly->edges_begin(); + he != poly->edges_end(); + he++) + { + + const Point& a = he->vertex()->point(); + const Point& b = he->opposite()->vertex()->point(); + positions_lines.push_back(a.x()); + positions_lines.push_back(a.y()); + positions_lines.push_back(a.z()); + positions_lines.push_back(1.0); + + const double u = he->vertex()->u(); + const double v = he->vertex()->v(); + textures_map_lines.push_back(u); + textures_map_lines.push_back(v); + + positions_lines.push_back(b.x()); + positions_lines.push_back(b.y()); + positions_lines.push_back(b.z()); + positions_lines.push_back(1.0); + + const double ou = he->opposite()->vertex()->u(); + const double ov = he->opposite()->vertex()->v(); + textures_map_lines.push_back(ou); + textures_map_lines.push_back(ov); + + } + +} + +Scene_textured_polyhedron_item::Scene_textured_polyhedron_item() + : Scene_item(5,2),poly(new Textured_polyhedron) +{ + texture.GenerateCheckerBoard(2048,2048,128,0,0,0,250,250,255); + cur_shading=FlatPlusEdges; + is_selected=false; + qFunc.initializeOpenGLFunctions(); + qFunc.glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + qFunc.glGenTextures(1, &textureId); + changed(); } Scene_textured_polyhedron_item::Scene_textured_polyhedron_item(Textured_polyhedron* const p) - : Scene_item_with_display_list(), - poly(p) + : Scene_item(5,2),poly(p),smooth_shading(true) { - texture.GenerateCheckerBoard(2048,2048,128,0,0,0,250,250,255); + cur_shading=FlatPlusEdges; + is_selected=false; + texture.GenerateCheckerBoard(2048,2048,128,0,0,0,250,250,255); + qFunc.initializeOpenGLFunctions(); + qFunc.glGenTextures(1, &textureId); + changed(); } Scene_textured_polyhedron_item::Scene_textured_polyhedron_item(const Textured_polyhedron& p) - : Scene_item_with_display_list(), - poly(new Textured_polyhedron(p)) + : Scene_item(5,2), poly(new Textured_polyhedron(p)),smooth_shading(true) { - texture.GenerateCheckerBoard(2048,2048,128,0,0,0,250,250,255); + texture.GenerateCheckerBoard(2048,2048,128,0,0,0,250,250,255); + cur_shading=FlatPlusEdges; + is_selected=false; + qFunc.initializeOpenGLFunctions(); + qFunc.glGenTextures(1, &textureId); + changed(); } // Scene_textured_polyhedron_item::Scene_textured_polyhedron_item(const Scene_textured_polyhedron_item& item) @@ -36,68 +229,82 @@ Scene_textured_polyhedron_item::Scene_textured_polyhedron_item(const Textured_po Scene_textured_polyhedron_item::~Scene_textured_polyhedron_item() { - delete poly; + delete poly; } Scene_textured_polyhedron_item* Scene_textured_polyhedron_item::clone() const { - return new Scene_textured_polyhedron_item(*poly); + return new Scene_textured_polyhedron_item(*poly); } // Load textured_polyhedron from .OFF file bool Scene_textured_polyhedron_item::load(std::istream& in) { - in >> *poly; - return in && !isEmpty(); + std::cout<<"LOAD"<> *poly; + changed(); + return in && !isEmpty(); } // Write textured_polyhedron to .OFF file bool Scene_textured_polyhedron_item::save(std::ostream& out) const { - out << *poly; - return (bool) out; + out << *poly; + return (bool) out; } QString Scene_textured_polyhedron_item::toolTip() const { - if(!poly) - return QString(); + if(!poly) + return QString(); - return QObject::tr("

Textured polyhedron %1 (mode: %5, color: %6)

" - "

Number of vertices: %2
" - "Number of edges: %3
" - "Number of facets: %4

") - .arg(this->name()) - .arg(poly->size_of_vertices()) - .arg(poly->size_of_halfedges()/2) - .arg(poly->size_of_facets()) - .arg(this->renderingModeName()) - .arg(this->color().name()); + return QObject::tr("

Textured polyhedron %1 (mode: %5, color: %6)

" + "

Number of vertices: %2
" + "Number of edges: %3
" + "Number of facets: %4

") + .arg(this->name()) + .arg(poly->size_of_vertices()) + .arg(poly->size_of_halfedges()/2) + .arg(poly->size_of_facets()) + .arg(this->renderingModeName()) + .arg(this->color().name()); } // Points/Wireframe/Flat/Gouraud OpenGL drawing in a display list -void Scene_textured_polyhedron_item::direct_draw() const { - glTexImage2D(GL_TEXTURE_2D, - 0, - GL_RGB, - texture.GetWidth(), - texture.GetHeight(), - 0, - GL_RGB, - GL_UNSIGNED_BYTE, - texture.GetData()); - glEnable(GL_TEXTURE_2D); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); +void Scene_textured_polyhedron_item::draw(Viewer_interface* viewer) const { - poly->gl_draw_textured_triangles(true, true, 1.0); - glDisable(GL_TEXTURE_2D); + if(!are_buffers_filled) + initialize_buffers(viewer); + + vaos[0]->bind(); + qFunc.glActiveTexture(GL_TEXTURE0); + qFunc.glBindTexture(GL_TEXTURE_2D, textureId); + attrib_buffers(viewer, PROGRAM_WITH_TEXTURE); + program=getShaderProgram(PROGRAM_WITH_TEXTURE); + program->bind(); + qFunc.glDrawArrays(GL_TRIANGLES, 0, static_cast(positions_facets.size()/4)); + //Clean-up + program->release(); + vaos[0]->release(); +} +void Scene_textured_polyhedron_item::draw_edges(Viewer_interface* viewer) const { + if(!are_buffers_filled) + initialize_buffers(viewer); + + vaos[1]->bind(); + qFunc.glActiveTexture(GL_TEXTURE0); + qFunc.glBindTexture(GL_TEXTURE_2D, textureId); + attrib_buffers(viewer, PROGRAM_WITH_TEXTURED_EDGES); + + program=getShaderProgram(PROGRAM_WITH_TEXTURED_EDGES); + program->bind(); + qFunc.glDrawArrays(GL_LINES, 0, static_cast(positions_lines.size()/4)); + //Clean-up + program->release(); + vaos[1]->release(); } Textured_polyhedron* @@ -107,20 +314,48 @@ Scene_textured_polyhedron_item::textured_polyhedron() const { return poly; } bool Scene_textured_polyhedron_item::isEmpty() const { - return (poly == 0) || poly->empty(); + return (poly == 0) || poly->empty(); } Scene_textured_polyhedron_item::Bbox Scene_textured_polyhedron_item::bbox() const { - const Point& p = *(poly->points_begin()); - CGAL::Bbox_3 bbox(p.x(), p.y(), p.z(), p.x(), p.y(), p.z()); - for(Textured_polyhedron::Point_iterator it = poly->points_begin(); - it != poly->points_end(); - ++it) { - bbox = bbox + it->bbox(); - } - return Bbox(bbox.xmin(),bbox.ymin(),bbox.zmin(), - bbox.xmax(),bbox.ymax(),bbox.zmax()); + const Point& p = *(poly->points_begin()); + CGAL::Bbox_3 bbox(p.x(), p.y(), p.z(), p.x(), p.y(), p.z()); + for(Textured_polyhedron::Point_iterator it = poly->points_begin(); + it != poly->points_end(); + ++it) { + bbox = bbox + it->bbox(); + } + return Bbox(bbox.xmin(),bbox.ymin(),bbox.zmin(), + bbox.xmax(),bbox.ymax(),bbox.zmax()); +} +void +Scene_textured_polyhedron_item::changed() +{ + compute_normals_and_vertices(); + are_buffers_filled = false;} +void +Scene_textured_polyhedron_item:: +contextual_changed() +{ + GLint new_shading; + qFunc.glGetIntegerv(GL_SHADE_MODEL, &new_shading); + prev_shading = cur_shading; + cur_shading = renderingMode(); + if(prev_shading != cur_shading) + { + changed(); + } +} +void +Scene_textured_polyhedron_item::selection_changed(bool p_is_selected) +{ + if(p_is_selected != is_selected) + { + is_selected = p_is_selected; + initialize_buffers(); + } + else + is_selected = p_is_selected; } - #include "Scene_textured_polyhedron_item.moc" diff --git a/Polyhedron/demo/Polyhedron/Scene_textured_polyhedron_item.h b/Polyhedron/demo/Polyhedron/Scene_textured_polyhedron_item.h index f2c9355dbde..a3e4a4b26e5 100644 --- a/Polyhedron/demo/Polyhedron/Scene_textured_polyhedron_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_textured_polyhedron_item.h @@ -1,15 +1,15 @@ #ifndef SCENE_TEXTURED_POLYHEDRON_ITEM_H #define SCENE_TEXTURED_POLYHEDRON_ITEM_H - #include "Scene_textured_polyhedron_item_config.h" -#include "Scene_item_with_display_list.h" +#include "Scene_item.h" +#include "Viewer_interface.h" #include "Textured_polyhedron_type_fwd.h" #include #include "texture.h" // This class represents a textured polyhedron in the OpenGL scene class SCENE_TEXTURED_POLYHEDRON_ITEM_EXPORT Scene_textured_polyhedron_item - : public Scene_item_with_display_list { + : public Scene_item { Q_OBJECT public: Scene_textured_polyhedron_item(); @@ -28,9 +28,12 @@ public: virtual QString toolTip() const; // Indicate if rendering mode is supported - virtual bool supportsRenderingMode(RenderingMode m) const { return m != Splatting; } + virtual bool supportsRenderingMode(RenderingMode) const { return true; } // Points/Wireframe/Flat/Gouraud OpenGL drawing in a display list - virtual void direct_draw() const; + void draw() const {} + virtual void draw(Viewer_interface*) const; + virtual void draw_edges() const {} + virtual void draw_edges(Viewer_interface* viewer) const; // Get wrapped textured_polyhedron Textured_polyhedron* textured_polyhedron(); @@ -41,9 +44,29 @@ public: bool isEmpty() const; Bbox bbox() const; + virtual void changed(); + virtual void contextual_changed(); + virtual void selection_changed(bool); + private: Textured_polyhedron* poly; Texture texture; + std::vector positions_lines; + std::vector positions_facets; + std::vector normals; + std::vector textures_map_facets; + std::vector textures_map_lines; + + + GLuint textureId; + mutable QOpenGLShaderProgram* program; + + bool smooth_shading; + + using Scene_item::initialize_buffers; + void initialize_buffers(Viewer_interface *viewer) const; + void compute_normals_and_vertices(void); + }; // end class Scene_textured_polyhedron_item diff --git a/Polyhedron/demo/Polyhedron/Viewer.cpp b/Polyhedron/demo/Polyhedron/Viewer.cpp index 85e07669c80..6d471541026 100644 --- a/Polyhedron/demo/Polyhedron/Viewer.cpp +++ b/Polyhedron/demo/Polyhedron/Viewer.cpp @@ -1,11 +1,10 @@ +#include #include "Viewer.h" #include -#include #include "Scene_draw_interface.h" #include #include #include - class Viewer_impl { public: Scene_draw_interface* scene; @@ -84,34 +83,24 @@ bool Viewer::inFastDrawing() const { void Viewer::draw() { d->inFastDrawing = false; - // ::glFogf(GL_FOG_END, 2*sceneRadius()); - // ::glEnable(GL_FOG); QGLViewer::draw(); d->draw_aux(false, this); - // drawLight(GL_LIGHT0); } void Viewer::fastDraw() { d->inFastDrawing = true; - // ::glFogf(GL_FOG_END, 2*sceneRadius()); - // ::glEnable(GL_FOG); QGLViewer::fastDraw(); d->draw_aux(false, this); - // drawLight(GL_LIGHT0); } void Viewer::initializeGL() { QGLViewer::initializeGL(); + initializeOpenGLFunctions(); setBackgroundColor(::Qt::white); d->scene->initializeGL(); - // ::glFogf(GL_FOG_DENSITY, 0.05f); - // ::glHint(GL_FOG_HINT, GL_NICEST); - // ::glFogi(GL_FOG_MODE, GL_LINEAR); - // static const GLfloat fogColor[] = {0.5f, 0.5f, 0.5f, 1}; - // ::glFogfv(GL_FOG_COLOR, fogColor); } #include @@ -139,13 +128,17 @@ void Viewer::keyPressEvent(QKeyEvent* e) } else if(e->key() == Qt::Key_M) { d->macro_mode = ! d->macro_mode; + if(d->macro_mode) { - camera()->setZNearCoefficient(0.0005f); + camera()->setZNearCoefficient(0.0005f); } else { camera()->setZNearCoefficient(0.005f); } this->displayMessage(tr("Macro mode: %1"). arg(d->macro_mode ? tr("on") : tr("off"))); + + + return; } } @@ -202,7 +195,6 @@ void Viewer_impl::draw_aux(bool with_names, Viewer* viewer) scene->drawWithNames(viewer); else scene->draw(viewer); - CGAL::check_gl_error(__FILE__, __LINE__); } void Viewer::drawWithNames() diff --git a/Polyhedron/demo/Polyhedron/Viewer.h b/Polyhedron/demo/Polyhedron/Viewer.h index 65b75098b98..17e3f6b40f2 100644 --- a/Polyhedron/demo/Polyhedron/Viewer.h +++ b/Polyhedron/demo/Polyhedron/Viewer.h @@ -6,6 +6,7 @@ #include #include +#include // forward declarations class QWidget; @@ -15,7 +16,7 @@ class QKeyEvent; class Viewer_impl; -class VIEWER_EXPORT Viewer : public Viewer_interface { +class VIEWER_EXPORT Viewer : public Viewer_interface, public QOpenGLFunctions_3_3_Core { Q_OBJECT diff --git a/Polyhedron/demo/Polyhedron/cgal_test_with_cmake b/Polyhedron/demo/Polyhedron/cgal_test_with_cmake index a1ae9d9b49e..c11be271e54 100755 --- a/Polyhedron/demo/Polyhedron/cgal_test_with_cmake +++ b/Polyhedron/demo/Polyhedron/cgal_test_with_cmake @@ -182,6 +182,6 @@ fi # if [ -n "${NEED_CLEAN}" ]; then if ! ( uname | grep -q "CYGWIN" ) ; then - ${MAKE_CMD} -fMakefile clean + ${MAKE_CMD} -fMakefile clean || true fi fi diff --git a/Polyhedron/demo/Polyhedron/data/cube-shuffled.off b/Polyhedron/demo/Polyhedron/data/cube-shuffled.off new file mode 100644 index 00000000000..dee198272cf --- /dev/null +++ b/Polyhedron/demo/Polyhedron/data/cube-shuffled.off @@ -0,0 +1,47 @@ +# Output of a CGAL tool +#CBP +# polyhedral_surface 0 +# halfedges 0 +# triangulated 0 +# non_empty_facets 0 +# terrain 0 +# normalized_to_sphere 0 +# radius 0 +# rounded 0 +# rounded_bits 0 +# ENDCBP + +OFF +8 12 0 + +# 8 vertices +# ------------------------------------------ + + +-1 -1 -1 +-1 1 -1 +1 1 -1 +1 -1 -1 +-1 -1 1 +-1 1 1 +1 1 1 +1 -1 1 + +# 12 facets +# ------------------------------------------ + +3 3 1 0 +3 3 1 2 +3 1 4 0 +3 1 4 5 +3 3 2 7 +3 7 2 6 +3 3 0 4 +3 7 4 3 +3 7 4 6 +3 6 5 4 +3 6 5 1 +3 2 1 6 + + +# End of OFF # diff --git a/Polyhedron/demo/Polyhedron/data/cube4-shuffled.off b/Polyhedron/demo/Polyhedron/data/cube4-shuffled.off new file mode 100644 index 00000000000..e4c11b5fe03 --- /dev/null +++ b/Polyhedron/demo/Polyhedron/data/cube4-shuffled.off @@ -0,0 +1,41 @@ +# Output of a CGAL tool +#CBP +# polyhedral_surface 0 +# halfedges 0 +# triangulated 0 +# non_empty_facets 0 +# terrain 0 +# normalized_to_sphere 0 +# radius 0 +# rounded 0 +# rounded_bits 0 +# ENDCBP + +OFF +8 6 0 + +# 8 vertices +# ------------------------------------------ + + +-1 -1 -1 +-1 1 -1 +1 1 -1 +1 -1 -1 +-1 -1 1 +-1 1 1 +1 1 1 +1 -1 1 + +# 6 facets +# ------------------------------------------ + +4 1 2 3 0 +4 0 1 5 4 +4 2 6 7 3 +4 3 7 4 0 +4 6 5 4 7 +4 6 2 1 5 + + +# End of OFF # diff --git a/Polyhedron/demo/Polyhedron/data/oblong-shuffled.off b/Polyhedron/demo/Polyhedron/data/oblong-shuffled.off new file mode 100644 index 00000000000..9027280ffb7 --- /dev/null +++ b/Polyhedron/demo/Polyhedron/data/oblong-shuffled.off @@ -0,0 +1,1291 @@ +# Output of a CGAL tool +#CBP +# polyhedral_surface 0 +# halfedges 0 +# triangulated 0 +# non_empty_facets 0 +# terrain 0 +# normalized_to_sphere 0 +# radius 0 +# rounded 0 +# rounded_bits 0 +# ENDCBP + +OFF +424 840 0 + +# 424 vertices +# ------------------------------------------ + + +68.7865 31.8449 54 +68.99 29 54 +78 52 54 +57.3041 47.1835 54 +59.8074 45.8167 54 +0 58 54 +0 6 54 +4 6 54 +4 0 54 +27.99 0 54 +27.99 6 54 +29 48.99 54 +49 48.99 54 +50 52 54 +51.8449 48.7865 54 +54.6318 48.1803 54 +62.0907 44.1074 54 +64.1074 42.0907 54 +65.8167 39.8074 54 +54.6318 9.81973 54 +51.8449 9.21347 54 +50.0065 6 54 +49 9.01 54 +68.1803 23.3682 54 +67.1835 20.6959 54 +78 6 54 +65.8167 18.1926 54 +74 6 54 +64.1074 15.9093 54 +74 0 54 +62.0907 13.8926 54 +59.8074 12.1833 54 +68.7865 26.1551 54 +67.1835 37.3041 54 +68.1803 34.6318 54 +9.81974 34.6318 54 +10.8165 37.3041 54 +23.3682 48.1803 54 +26.1551 48.7865 54 +50.0065 0 54 +57.3041 10.8165 54 +9.21347 31.8449 54 +50 58 54 +23.3682 9.81973 54 +26.1551 9.21347 54 +29 9.01 54 +20.6959 10.8165 54 +18.1926 12.1833 54 +15.9093 13.8926 54 +13.8926 15.9093 54 +12.1833 18.1926 54 +10.8165 20.6959 54 +12.1833 39.8074 54 +13.8926 42.0907 54 +15.9093 44.1074 54 +9.81974 23.3682 54 +9.21347 26.1551 54 +9.01 29 54 +18.1926 45.8167 54 +20.6959 47.1835 54 +50.0065 0 0 +74 0 0 +0 58 0 +0 6 0 +4 0 0 +27.99 0 0 +78 6 0 +78 52 0 +50 58 0 +17.9479 46.6482 0 +17 46.2062 0 +16.1433 45.6063 0 +15.4037 44.8667 0 +14.8039 44.01 0 +14.3618 43.0621 0 +74 6 0 +50.0065 6 0 +50 52 0 +20 47.01 0 +18.9581 46.9188 0 +14.3618 14.9379 0 +14.8039 13.99 0 +4 6 0 +15.4037 13.1333 0 +16.1433 12.3937 0 +17 11.7938 0 +14.0912 42.0519 0 +14 41.01 0 +14 16.99 0 +14.0912 15.9481 0 +63.1962 13.99 0 +63.6382 14.9379 0 +63.9088 15.9481 0 +78 6 0 +64 16.99 0 +78 52 0 +64 41.01 0 +63.9088 42.0519 0 +63.6382 43.0621 0 +63.1962 44.01 0 +17.9479 11.3518 0 +27.99 6 0 +60.0521 11.3518 0 +61 11.7938 0 +62.5963 44.8667 0 +61.8567 45.6063 0 +61 46.2062 0 +60.0521 46.6482 0 +59.0419 46.9188 0 +58 47.01 0 +61.8567 12.3937 0 +62.5963 13.1333 0 +18.9581 11.0812 0 +20 10.99 0 +58 10.99 0 +59.0419 11.0812 0 +64 41.01 3 +64 16.99 3 +20 47.01 3 +58 47.01 3 +14 41.01 3 +14 16.99 3 +58 10.99 3 +20 10.99 3 +19.3 31.9445 3 +18.8145 31.6045 3 +22.7 26.0555 3 +56.4791 31.9544 3 +22.1629 25.805 3 +21.5904 25.6516 3 +23.9445 27.3 3 +24.195 27.8371 3 +24.3484 28.4096 3 +55.9739 31.8191 3 +55.5 31.5981 3 +55.0716 31.2981 3 +54.1809 30.0261 3 +54.0456 29.5209 3 +18.3955 31.1855 3 +18.0555 30.7 3 +17.805 30.1629 3 +23.1855 26.3955 3 +23.6045 26.8145 3 +54.7019 30.9284 3 +54.4019 30.5 3 +59.2981 27.0716 3 +59.5981 27.5 3 +24.4 29 3 +24.3484 29.5904 3 +57 32 3 +24.195 30.1629 3 +17.6517 29.5904 3 +17.6 29 3 +17.6517 28.4096 3 +17.805 27.8371 3 +18.0555 27.3 3 +18.3955 26.8145 3 +59.8191 27.9739 3 +59.9544 28.4791 3 +60 29 3 +59.9544 29.5209 3 +59.8191 30.0261 3 +59.5981 30.5 3 +59.2981 30.9284 3 +57.521 31.9544 3 +60.0521 46.6482 3 +59.0419 46.9188 3 +23.9445 30.7 3 +23.6045 31.1855 3 +54 29 3 +54.0456 28.4791 3 +54.1809 27.9739 3 +58.9284 31.2981 3 +58.5 31.5981 3 +63.9088 42.0519 3 +58.0261 31.8191 3 +63.6382 43.0621 3 +63.1962 44.01 3 +62.5963 44.8667 3 +61.8567 45.6063 3 +61 46.2062 3 +23.1855 31.6045 3 +22.7 31.9445 3 +22.1629 32.195 3 +21.5904 32.3484 3 +21 32.4 3 +18.9581 46.9188 3 +20.4096 32.3484 3 +17.9479 46.6482 3 +18.8145 26.3955 3 +19.3 26.0555 3 +14.0912 15.9481 3 +19.8371 25.805 3 +14.3618 14.9379 3 +14.8039 13.99 3 +15.4037 13.1333 3 +16.1433 12.3937 3 +20.4096 25.6516 3 +21 25.6 3 +17.9479 11.3518 3 +17 11.7938 3 +55.9739 26.1809 3 +55.5 26.4019 3 +55.0716 26.7019 3 +17 46.2062 3 +16.1433 45.6063 3 +15.4037 44.8667 3 +19.8371 32.195 3 +14.8039 44.01 3 +14.3618 43.0621 3 +14.0912 42.0519 3 +18.9581 11.0812 3 +54.4019 27.5 3 +54.7019 27.0716 3 +58.0261 26.1809 3 +62.5963 13.1333 3 +57.521 26.0456 3 +61.8567 12.3937 3 +56.4791 26.0456 3 +57 26 3 +59.0419 11.0812 3 +60.0521 11.3518 3 +61 11.7938 3 +63.1962 13.99 3 +63.6382 14.9379 3 +63.9088 15.9481 3 +58.5 26.4019 3 +58.9284 26.7019 3 +17.6517 29.5904 26.25 +17.805 30.1629 26.25 +18.0555 30.7 26.25 +18.3955 31.1855 26.25 +18.8145 31.6045 26.25 +19.3 31.9445 26.25 +19.8371 32.195 26.25 +20.4096 32.3484 26.25 +21 32.4 26.25 +21.5904 32.3484 26.25 +22.1629 32.195 26.25 +22.7 31.9445 26.25 +23.1855 31.6045 26.25 +23.6045 31.1855 26.25 +23.9445 30.7 26.25 +24.195 30.1629 26.25 +24.3484 29.5904 26.25 +24.4 29 26.25 +24.3484 28.4096 26.25 +24.195 27.8371 26.25 +23.9445 27.3 26.25 +23.6045 26.8145 26.25 +23.1855 26.3955 26.25 +22.7 26.0555 26.25 +22.1629 25.805 26.25 +21.5904 25.6516 26.25 +21 25.6 26.25 +20.4096 25.6516 26.25 +19.8371 25.805 26.25 +19.3 26.0555 26.25 +18.8145 26.3955 26.25 +18.3955 26.8145 26.25 +18.0555 27.3 26.25 +17.805 27.8371 26.25 +17.6517 28.4096 26.25 +17.6 29 26.25 +21 29 28.2929 +54.0456 29.5209 29 +54.1809 30.0261 29 +54.4019 30.5 29 +54.7019 30.9284 29 +55.0716 31.2981 29 +55.5 31.5981 29 +55.9739 31.8191 29 +56.4791 31.9544 29 +57 32 29 +57.521 31.9544 29 +58.0261 31.8191 29 +58.5 31.5981 29 +58.9284 31.2981 29 +59.2981 30.9284 29 +59.5981 30.5 29 +59.8191 30.0261 29 +59.9544 29.5209 29 +60 29 29 +59.9544 28.4791 29 +59.8191 27.9739 29 +59.5981 27.5 29 +59.2981 27.0716 29 +58.9284 26.7019 29 +58.5 26.4019 29 +58.0261 26.1809 29 +57.521 26.0456 29 +57 26 29 +56.4791 26.0456 29 +55.9739 26.1809 29 +55.5 26.4019 29 +55.0716 26.7019 29 +54.7019 27.0716 29 +54.4019 27.5 29 +54.1809 27.9739 29 +54.0456 28.4791 29 +54 29 29 +57 29 30.8026 +29 9.01 58 +26.1551 9.21347 58 +23.3682 9.81973 58 +20.6959 10.8165 58 +18.1926 12.1833 58 +15.9093 13.8926 58 +13.8926 15.9093 58 +12.1833 18.1926 58 +10.8165 20.6959 58 +9.81974 23.3682 58 +9.21347 26.1551 58 +9.01 29 58 +9.21347 31.8449 58 +9.81974 34.6318 58 +10.8165 37.3041 58 +12.1833 39.8074 58 +13.8926 42.0907 58 +15.9093 44.1074 58 +18.1926 45.8167 58 +20.6959 47.1835 58 +23.3682 48.1803 58 +26.1551 48.7865 58 +29 48.99 58 +49 9.01 58 +49 48.99 58 +51.8449 48.7865 58 +54.6318 48.1803 58 +57.3041 47.1835 58 +59.8074 45.8167 58 +62.0907 44.1074 58 +64.1074 42.0907 58 +65.8167 39.8074 58 +67.1835 37.3041 58 +68.1803 34.6318 58 +68.7865 31.8449 58 +68.99 29 58 +68.7865 26.1551 58 +68.1803 23.3682 58 +67.1835 20.6959 58 +65.8167 18.1926 58 +64.1074 15.9093 58 +62.0907 13.8926 58 +59.8074 12.1833 58 +57.3041 10.8165 58 +54.6318 9.81973 58 +51.8449 9.21347 58 +55.01 29 58 +54.7916 26.3648 58 +47.7566 15.597 58 +45.4311 14.3385 58 +54.7916 31.6352 58 +54.1425 34.1984 58 +53.0804 21.3801 58 +54.1425 23.8016 58 +53.0804 36.6199 58 +51.6341 38.8335 58 +49.8433 40.7789 58 +42.9302 13.4799 58 +40.3221 13.0447 58 +37.6779 13.0447 58 +35.0698 13.4799 58 +32.5689 14.3385 58 +30.2434 15.597 58 +28.1567 17.2211 58 +51.6341 19.1665 58 +49.8433 17.2211 58 +24.9196 21.3801 58 +26.3659 19.1665 58 +23.8575 23.8016 58 +22.99 29 58 +23.2083 31.6352 58 +30.2434 42.403 58 +32.5689 43.6615 58 +23.2083 26.3648 58 +35.0698 44.5201 58 +37.6779 44.9553 58 +40.3221 44.9553 58 +24.9196 36.6199 58 +23.8575 34.1984 58 +26.3659 38.8335 58 +28.1567 40.7789 58 +47.7566 42.403 58 +45.4311 43.6615 58 +42.9302 44.5201 58 +54.7916 31.6352 54 +54.1425 34.1984 54 +53.0804 36.6199 54 +51.6341 38.8335 54 +49.8433 40.7789 54 +47.7566 42.403 54 +45.4311 43.6615 54 +42.9302 44.5201 54 +40.3221 44.9553 54 +37.6779 44.9553 54 +35.0698 44.5201 54 +32.5689 43.6615 54 +30.2434 42.403 54 +28.1567 40.7789 54 +26.3659 38.8335 54 +24.9196 36.6199 54 +23.8575 34.1984 54 +23.2083 31.6352 54 +22.99 29 54 +23.2083 26.3648 54 +23.8575 23.8016 54 +24.9196 21.3801 54 +26.3659 19.1665 54 +28.1567 17.2211 54 +30.2434 15.597 54 +32.5689 14.3385 54 +35.0698 13.4799 54 +37.6779 13.0447 54 +40.3221 13.0447 54 +42.9302 13.4799 54 +45.4311 14.3385 54 +47.7566 15.597 54 +49.8433 17.2211 54 +51.6341 19.1665 54 +53.0804 21.3801 54 +54.1425 23.8016 54 +54.7916 26.3648 54 +55.01 29 54 + +# 840 facets +# ------------------------------------------ + +3 0 1 2 +3 2 4 3 +3 7 6 5 +3 8 9 7 +3 10 9 7 +3 11 12 13 +3 13 12 14 +3 2 14 13 +3 2 14 15 +3 2 15 3 +3 4 16 2 +3 2 16 17 +3 2 17 18 +3 19 20 21 +3 21 20 22 +3 21 22 10 +3 25 24 23 +3 25 24 26 +3 25 26 27 +3 28 26 27 +3 27 28 29 +3 29 28 30 +3 31 30 29 +3 2 1 25 +3 25 1 32 +3 23 32 25 +3 18 33 2 +3 34 33 2 +3 2 34 0 +3 5 36 35 +3 38 37 5 +3 19 39 21 +3 29 39 19 +3 40 29 19 +3 40 29 31 +3 35 5 41 +3 11 13 38 +3 38 13 42 +3 38 42 5 +3 44 7 43 +3 10 7 44 +3 45 10 44 +3 45 10 22 +3 43 46 7 +3 7 46 47 +3 48 47 7 +3 7 49 48 +3 50 49 7 +3 7 50 51 +3 36 52 5 +3 53 52 5 +3 5 53 54 +3 7 55 51 +3 7 55 56 +3 5 56 7 +3 5 56 57 +3 5 57 41 +3 54 58 5 +3 59 58 5 +3 37 59 5 +3 39 60 29 +3 61 60 29 +3 5 62 6 +3 63 62 6 +3 9 64 8 +3 65 64 9 +3 25 66 2 +3 2 66 67 +3 42 68 5 +3 62 68 5 +3 62 70 69 +3 71 70 62 +3 71 72 62 +3 62 72 73 +3 62 73 74 +3 75 60 61 +3 76 60 75 +3 78 77 68 +3 62 78 68 +3 62 78 79 +3 62 79 69 +3 80 81 82 +3 83 81 82 +3 64 83 82 +3 84 83 64 +3 85 84 64 +3 74 86 62 +3 62 86 87 +3 63 87 62 +3 63 87 88 +3 63 88 82 +3 82 88 89 +3 82 89 80 +3 75 91 90 +3 75 91 92 +3 75 92 93 +3 93 92 94 +3 95 94 93 +3 95 94 96 +3 95 97 96 +3 95 97 98 +3 95 98 99 +3 85 101 100 +3 65 101 85 +3 64 65 85 +3 75 103 102 +3 95 104 99 +3 105 104 95 +3 106 105 95 +3 106 107 95 +3 108 107 95 +3 95 108 77 +3 109 108 77 +3 78 109 77 +3 103 110 75 +3 111 110 75 +3 75 111 90 +3 100 112 101 +3 101 112 113 +3 101 113 76 +3 114 113 76 +3 75 114 76 +3 115 114 75 +3 102 115 75 +3 13 77 42 +3 68 77 42 +3 2 95 13 +3 77 95 13 +3 8 82 7 +3 64 82 8 +3 7 63 6 +3 7 63 82 +3 21 76 39 +3 39 76 60 +3 9 65 10 +3 101 65 10 +3 10 101 21 +3 76 101 21 +3 27 61 29 +3 27 61 75 +3 27 75 25 +3 93 75 25 +3 116 94 96 +3 116 94 117 +3 78 109 118 +3 119 109 118 +3 120 121 87 +3 88 121 87 +3 114 113 122 +3 123 113 122 +3 124 125 120 +3 126 127 128 +3 129 127 128 +3 130 131 127 +3 127 131 132 +3 127 133 129 +3 129 133 134 +3 129 134 135 +3 129 136 137 +3 120 138 125 +3 120 138 139 +3 140 139 120 +3 126 141 127 +3 127 141 142 +3 127 142 130 +3 135 143 129 +3 129 143 144 +3 136 144 129 +3 145 146 117 +3 132 147 127 +3 127 147 148 +3 149 148 127 +3 150 148 149 +3 140 151 120 +3 120 151 152 +3 120 152 121 +3 121 152 153 +3 121 154 153 +3 121 154 155 +3 156 155 121 +3 117 157 146 +3 158 157 117 +3 116 158 117 +3 159 158 116 +3 116 159 160 +3 160 161 116 +3 162 161 116 +3 116 162 163 +3 165 149 164 +3 165 149 150 +3 165 150 166 +3 167 150 166 +3 166 167 119 +3 168 167 119 +3 137 169 129 +3 170 169 129 +3 129 170 171 +3 116 172 163 +3 173 172 116 +3 174 173 116 +3 174 173 175 +3 174 175 176 +3 178 176 177 +3 178 176 175 +3 178 175 179 +3 179 175 164 +3 180 164 179 +3 165 164 180 +3 168 181 119 +3 119 181 182 +3 119 182 118 +3 118 182 183 +3 183 184 118 +3 118 184 185 +3 186 185 118 +3 186 185 187 +3 188 187 186 +3 121 189 156 +3 190 189 121 +3 121 190 191 +3 191 190 192 +3 191 192 193 +3 194 193 195 +3 195 193 192 +3 195 192 196 +3 197 192 196 +3 198 199 197 +3 197 199 200 +3 196 200 197 +3 202 122 201 +3 202 122 123 +3 202 123 203 +3 204 188 205 +3 187 188 205 +3 205 187 206 +3 207 187 206 +3 206 207 208 +3 208 207 124 +3 208 124 209 +3 209 124 120 +3 209 120 210 +3 199 129 198 +3 171 129 199 +3 211 171 199 +3 211 171 212 +3 123 212 211 +3 123 212 213 +3 123 213 203 +3 216 215 214 +3 216 215 217 +3 122 218 201 +3 219 218 122 +3 220 219 122 +3 220 219 216 +3 220 216 221 +3 217 216 221 +3 221 217 222 +3 224 215 223 +3 224 215 214 +3 224 214 225 +3 226 214 225 +3 117 226 225 +3 117 226 227 +3 145 227 117 +3 79 118 78 +3 186 118 79 +3 69 186 79 +3 188 186 69 +3 69 188 70 +3 70 188 204 +3 70 204 71 +3 205 204 71 +3 71 205 72 +3 72 205 206 +3 72 206 73 +3 208 206 73 +3 74 208 73 +3 209 208 74 +3 86 209 74 +3 210 209 86 +3 87 210 86 +3 120 210 87 +3 97 116 96 +3 174 116 97 +3 98 174 97 +3 98 174 176 +3 99 176 98 +3 99 176 177 +3 104 177 99 +3 104 177 178 +3 104 178 105 +3 179 178 105 +3 106 179 105 +3 180 179 106 +3 107 180 106 +3 165 180 107 +3 108 165 107 +3 108 165 166 +3 109 166 108 +3 109 166 119 +3 115 122 114 +3 115 122 220 +3 102 220 115 +3 221 220 102 +3 102 221 103 +3 103 221 222 +3 110 222 103 +3 110 222 217 +3 110 217 111 +3 215 217 111 +3 111 215 90 +3 90 215 223 +3 90 223 91 +3 224 223 91 +3 92 224 91 +3 92 224 225 +3 92 225 94 +3 117 225 94 +3 89 121 88 +3 89 121 191 +3 80 191 89 +3 80 191 193 +3 81 193 80 +3 194 193 81 +3 81 194 83 +3 195 194 83 +3 84 195 83 +3 84 195 196 +3 84 196 85 +3 85 196 200 +3 85 200 100 +3 199 200 100 +3 112 199 100 +3 112 199 211 +3 113 211 112 +3 113 211 123 +3 229 151 228 +3 140 151 229 +3 230 140 229 +3 230 140 139 +3 230 139 231 +3 138 139 231 +3 231 138 232 +3 125 138 232 +3 233 125 232 +3 233 125 124 +3 233 124 234 +3 234 124 207 +3 234 207 235 +3 235 207 187 +3 235 187 236 +3 236 187 185 +3 236 185 237 +3 237 185 184 +3 237 184 238 +3 183 184 238 +3 238 183 239 +3 182 183 239 +3 240 182 239 +3 240 182 181 +3 240 181 241 +3 241 181 168 +3 241 168 242 +3 242 168 167 +3 243 167 242 +3 243 167 150 +3 243 150 244 +3 148 150 244 +3 244 148 245 +3 245 148 147 +3 245 147 246 +3 132 147 246 +3 246 132 247 +3 131 132 247 +3 248 131 247 +3 248 131 130 +3 248 130 249 +3 249 130 142 +3 249 142 250 +3 250 142 141 +3 250 141 251 +3 126 141 251 +3 252 126 251 +3 128 126 252 +3 252 128 253 +3 129 128 253 +3 254 129 253 +3 198 129 254 +3 255 198 254 +3 197 198 255 +3 255 197 256 +3 256 197 192 +3 256 192 257 +3 190 192 257 +3 258 190 257 +3 258 190 189 +3 258 189 259 +3 259 189 156 +3 259 156 260 +3 260 156 155 +3 260 155 261 +3 261 155 154 +3 261 154 262 +3 153 154 262 +3 262 153 263 +3 152 153 263 +3 228 152 263 +3 228 152 151 +3 263 228 264 +3 232 264 231 +3 264 230 229 +3 234 264 235 +3 232 233 264 +3 237 264 238 +3 264 236 235 +3 240 264 241 +3 264 239 238 +3 244 264 243 +3 264 242 241 +3 246 264 247 +3 244 245 264 +3 249 264 250 +3 247 248 264 +3 253 264 252 +3 264 251 250 +3 255 264 256 +3 264 254 253 +3 258 264 259 +3 256 257 264 +3 261 264 262 +3 259 260 264 +3 264 263 262 +3 264 260 261 +3 258 257 264 +3 264 254 255 +3 252 251 264 +3 249 248 264 +3 264 245 246 +3 264 242 243 +3 240 239 264 +3 237 236 264 +3 264 233 234 +3 231 230 264 +3 264 228 229 +3 266 137 265 +3 266 137 136 +3 266 136 267 +3 144 136 267 +3 268 144 267 +3 268 144 143 +3 268 143 269 +3 269 143 135 +3 269 135 270 +3 134 135 270 +3 271 134 270 +3 133 134 271 +3 272 133 271 +3 272 133 127 +3 273 127 272 +3 149 127 273 +3 273 149 274 +3 274 149 164 +3 275 164 274 +3 175 164 275 +3 275 175 276 +3 276 175 173 +3 277 173 276 +3 172 173 277 +3 278 172 277 +3 163 172 278 +3 279 163 278 +3 162 163 279 +3 279 162 280 +3 161 162 280 +3 280 161 281 +3 281 161 160 +3 281 160 282 +3 159 160 282 +3 283 159 282 +3 283 159 158 +3 284 158 283 +3 284 158 157 +3 284 157 285 +3 285 157 146 +3 285 146 286 +3 286 146 145 +3 286 145 287 +3 227 145 287 +3 288 227 287 +3 288 227 226 +3 289 226 288 +3 289 226 214 +3 290 214 289 +3 216 214 290 +3 290 216 291 +3 219 216 291 +3 292 219 291 +3 218 219 292 +3 293 218 292 +3 201 218 293 +3 294 201 293 +3 202 201 294 +3 294 202 295 +3 295 202 203 +3 296 203 295 +3 213 203 296 +3 296 213 297 +3 212 213 297 +3 297 212 298 +3 298 212 171 +3 298 171 299 +3 299 171 170 +3 300 170 299 +3 169 170 300 +3 265 169 300 +3 265 169 137 +3 301 265 300 +3 268 301 269 +3 266 267 301 +3 271 301 272 +3 269 270 301 +3 275 301 274 +3 301 273 272 +3 277 301 278 +3 301 276 275 +3 281 301 280 +3 301 279 278 +3 283 301 284 +3 281 282 301 +3 286 301 287 +3 301 285 284 +3 290 301 289 +3 301 288 287 +3 293 301 292 +3 290 291 301 +3 295 301 296 +3 301 294 293 +3 298 301 299 +3 301 297 296 +3 299 300 301 +3 301 297 298 +3 295 294 301 +3 292 291 301 +3 301 288 289 +3 286 285 301 +3 283 282 301 +3 280 279 301 +3 277 276 301 +3 274 273 301 +3 271 270 301 +3 301 267 268 +3 266 265 301 +3 45 302 44 +3 44 302 303 +3 43 303 44 +3 43 303 304 +3 46 304 43 +3 305 304 46 +3 46 305 47 +3 306 305 47 +3 48 306 47 +3 307 306 48 +3 48 307 49 +3 308 307 49 +3 49 308 50 +3 309 308 50 +3 51 309 50 +3 51 309 310 +3 55 310 51 +3 55 310 311 +3 56 311 55 +3 56 311 312 +3 56 312 57 +3 313 312 57 +3 41 313 57 +3 41 313 314 +3 41 314 35 +3 35 314 315 +3 36 315 35 +3 36 315 316 +3 36 316 52 +3 52 316 317 +3 52 317 53 +3 318 317 53 +3 54 318 53 +3 54 318 319 +3 58 319 54 +3 320 319 58 +3 58 320 59 +3 59 320 321 +3 37 321 59 +3 37 321 322 +3 37 322 38 +3 323 322 38 +3 38 323 11 +3 11 323 324 +3 22 302 325 +3 45 302 22 +3 14 326 12 +3 14 326 327 +3 14 327 15 +3 15 327 328 +3 3 328 15 +3 329 328 3 +3 3 329 4 +3 4 329 330 +3 4 330 16 +3 331 330 16 +3 17 331 16 +3 17 331 332 +3 18 332 17 +3 18 332 333 +3 33 333 18 +3 33 333 334 +3 33 334 34 +3 335 334 34 +3 34 335 0 +3 0 335 336 +3 0 336 1 +3 337 336 1 +3 1 337 32 +3 32 337 338 +3 23 338 32 +3 339 338 23 +3 23 339 24 +3 24 339 340 +3 24 340 26 +3 341 340 26 +3 26 341 28 +3 342 341 28 +3 28 342 30 +3 343 342 30 +3 30 343 31 +3 31 343 344 +3 40 344 31 +3 345 344 40 +3 19 345 40 +3 346 345 19 +3 19 346 20 +3 347 346 20 +3 20 347 22 +3 22 347 325 +3 324 326 11 +3 12 326 11 +3 349 348 338 +3 350 351 325 +3 348 337 338 +3 348 337 336 +3 352 336 348 +3 352 336 335 +3 353 335 352 +3 354 341 355 +3 355 341 340 +3 349 340 355 +3 339 340 349 +3 338 339 349 +3 356 331 357 +3 357 331 330 +3 358 330 357 +3 335 334 353 +3 353 334 333 +3 353 333 356 +3 356 333 332 +3 331 332 356 +3 351 359 325 +3 360 359 325 +3 325 360 302 +3 302 360 361 +3 302 362 361 +3 363 362 302 +3 303 363 302 +3 303 363 364 +3 303 364 304 +3 304 364 365 +3 366 343 354 +3 354 343 342 +3 341 342 354 +3 350 347 325 +3 350 347 346 +3 350 346 367 +3 367 346 345 +3 367 345 366 +3 344 345 366 +3 343 344 366 +3 368 307 369 +3 306 307 369 +3 369 306 365 +3 305 306 365 +3 304 305 365 +3 370 309 368 +3 368 309 308 +3 368 308 307 +3 314 371 372 +3 373 374 324 +3 371 313 314 +3 312 313 371 +3 371 312 375 +3 375 312 311 +3 375 311 370 +3 370 311 310 +3 370 310 309 +3 374 376 324 +3 377 376 324 +3 326 377 324 +3 326 377 378 +3 380 317 379 +3 380 317 316 +3 380 316 372 +3 315 316 372 +3 314 315 372 +3 379 319 381 +3 379 319 318 +3 379 318 317 +3 324 323 373 +3 322 323 373 +3 382 322 373 +3 382 322 321 +3 382 321 381 +3 381 321 320 +3 381 320 319 +3 358 329 330 +3 328 329 358 +3 358 328 383 +3 383 328 327 +3 383 327 384 +3 384 327 326 +3 384 326 385 +3 378 326 385 +3 387 352 386 +3 387 352 353 +3 387 353 388 +3 388 353 356 +3 389 356 388 +3 357 356 389 +3 389 357 390 +3 390 357 358 +3 391 358 390 +3 383 358 391 +3 391 383 392 +3 384 383 392 +3 392 384 393 +3 393 384 385 +3 393 385 394 +3 378 385 394 +3 395 378 394 +3 395 378 377 +3 395 377 396 +3 376 377 396 +3 397 376 396 +3 374 376 397 +3 397 374 398 +3 398 374 373 +3 399 373 398 +3 382 373 399 +3 400 382 399 +3 381 382 400 +3 400 381 401 +3 379 381 401 +3 402 379 401 +3 402 379 380 +3 402 380 403 +3 372 380 403 +3 404 372 403 +3 404 372 371 +3 405 371 404 +3 405 371 375 +3 405 375 406 +3 370 375 406 +3 407 370 406 +3 368 370 407 +3 408 368 407 +3 408 368 369 +3 408 369 409 +3 409 369 365 +3 409 365 410 +3 364 365 410 +3 410 364 411 +3 363 364 411 +3 412 363 411 +3 412 363 362 +3 413 362 412 +3 413 362 361 +3 414 361 413 +3 414 361 360 +3 415 360 414 +3 415 360 359 +3 415 359 416 +3 416 359 351 +3 416 351 417 +3 417 351 350 +3 417 350 418 +3 367 350 418 +3 418 367 419 +3 419 367 366 +3 419 366 420 +3 420 366 354 +3 420 354 421 +3 355 354 421 +3 421 355 422 +3 422 355 349 +3 423 349 422 +3 423 349 348 +3 386 348 423 +3 352 348 386 +3 392 393 394 +3 411 412 413 +3 419 418 417 +3 410 409 397 +3 394 414 413 +3 415 414 394 +3 394 415 416 +3 397 411 410 +3 397 411 413 +3 396 413 397 +3 396 413 394 +3 396 394 395 +3 398 399 397 +3 405 399 397 +3 408 409 407 +3 397 409 407 +3 406 397 407 +3 405 397 406 +3 405 400 399 +3 405 400 401 +3 405 401 404 +3 404 401 402 +3 404 402 403 +3 419 388 387 +3 389 388 419 +3 390 389 419 +3 419 420 387 +3 421 420 387 +3 386 421 387 +3 386 421 422 +3 423 422 386 +3 416 417 394 +3 394 417 419 +3 392 419 394 +3 392 419 390 +3 392 390 391 + + +# End of OFF # diff --git a/Polyhedron/demo/Polyhedron/implicit_functions/CMakeLists.txt b/Polyhedron/demo/Polyhedron/implicit_functions/CMakeLists.txt index 79b3492ad1b..ad72844a01c 100644 --- a/Polyhedron/demo/Polyhedron/implicit_functions/CMakeLists.txt +++ b/Polyhedron/demo/Polyhedron/implicit_functions/CMakeLists.txt @@ -2,11 +2,9 @@ project( Mesh_3_implicit_functions ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() # Let plugins be compiled in the same directory as the executable. @@ -15,21 +13,19 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}") # Include directory of demo includes include_directories( BEFORE ${Mesh_3_implicit_functions_BINARY_DIR} ../include ) -# Find CGAL and CGAL Qt4 -find_package(CGAL COMPONENTS Qt4) +# Find CGAL and CGAL Qt5 +find_package(CGAL COMPONENTS Qt5) include( ${CGAL_USE_FILE} ) -# Find Qt4 itself +# Find Qt5 itself set( QT_USE_QTXML TRUE ) set( QT_USE_QTMAIN TRUE ) set( QT_USE_QTSCRIPT TRUE ) set( QT_USE_QTOPENGL TRUE ) -find_package(Qt4) +find_package(Qt5 QUIET COMPONENTS Xml Script OpenGL ScriptTools ) -if(CGAL_Qt4_FOUND AND QT4_FOUND) - include(${QT_USE_FILE}) - +if(CGAL_Qt5_FOUND AND Qt5_FOUND) # put plugins (which are shared libraries) at the same location as # executable files set(LIBRARY_OUTPUT_PATH ${RUNTIME_OUTPUT_PATH}) @@ -49,10 +45,11 @@ if(CGAL_Qt4_FOUND AND QT4_FOUND) else() set(other_sources ${ARGN_TAIL}) endif() - qt4_generate_moc( "${CMAKE_CURRENT_SOURCE_DIR}/${plugin_implementation_base_name}.cpp" ${plugin_implementation_base_name}.moc ) + qt5_generate_moc( "${CMAKE_CURRENT_SOURCE_DIR}/${plugin_implementation_base_name}.cpp" ${plugin_implementation_base_name}.moc ) add_file_dependencies( ${plugin_implementation_base_name}.moc "${CMAKE_CURRENT_SOURCE_DIR}/${plugin_implementation_base_name}.cpp" ) add_library(${plugin_name} MODULE ${option} ${plugin_implementation_base_name}.moc ${plugin_implementation_base_name}.cpp ${other_sources}) + qt5_use_modules(${plugin_name} Widgets Script OpenGL Gui Xml) add_to_cached_list( CGAL_EXECUTABLE_TARGETS ${plugin_name} ) # Link with Qt target_link_libraries( ${plugin_name} ${QT_LIBRARIES} ) @@ -64,18 +61,18 @@ if(CGAL_Qt4_FOUND AND QT4_FOUND) polyhedron_demo_plugin(p_tanglecube_function_plugin Tanglecube_implicit_function) polyhedron_demo_plugin(p_klein_function_plugin Klein_implicit_function) -else (CGAL_Qt4_FOUND AND QT4_FOUND) +else (CGAL_Qt5_FOUND AND Qt5_FOUND) set(MESH_3_MISSING_DEPS "") - if(NOT CGAL_Qt4_FOUND) - set(MESH_3_MISSING_DEPS "the CGAL Qt4 library, ${MESH_3_MISSING_DEPS}") + if(NOT CGAL_Qt5_FOUND) + set(MESH_3_MISSING_DEPS "the CGAL Qt5 library, ${MESH_3_MISSING_DEPS}") endif() - if(NOT QT4_FOUND) - set(MESH_3_MISSING_DEPS "Qt4, ${MESH_3_MISSING_DEPS}") + if(NOT Qt5_FOUND) + set(MESH_3_MISSING_DEPS "Qt5, ${MESH_3_MISSING_DEPS}") endif() message(STATUS "NOTICE: This demo requires ${MESH_3_MISSING_DEPS}and will not be compiled.") -endif (CGAL_Qt4_FOUND AND QT4_FOUND) +endif (CGAL_Qt5_FOUND AND Qt5_FOUND) diff --git a/Polyhedron/demo/Polyhedron/implicit_functions/Klein_implicit_function.cpp b/Polyhedron/demo/Polyhedron/implicit_functions/Klein_implicit_function.cpp index aa480e952df..6c861106050 100644 --- a/Polyhedron/demo/Polyhedron/implicit_functions/Klein_implicit_function.cpp +++ b/Polyhedron/demo/Polyhedron/implicit_functions/Klein_implicit_function.cpp @@ -31,7 +31,8 @@ class Klein_implicit_function : { Q_OBJECT Q_INTERFACES(Implicit_function_interface) - + Q_PLUGIN_METADATA(IID "com.geometryfactory.Mesh3Demo.Implicit_function_interface/1.0") + public: virtual QString name() const { return "Klein function"; } @@ -50,6 +51,4 @@ public: } }; -#include -Q_EXPORT_PLUGIN2(Klein_implicit_function, Klein_implicit_function) #include "Klein_implicit_function.moc" diff --git a/Polyhedron/demo/Polyhedron/implicit_functions/Sphere_implicit_function.cpp b/Polyhedron/demo/Polyhedron/implicit_functions/Sphere_implicit_function.cpp index bb02a0887ac..28a5c88f2fd 100644 --- a/Polyhedron/demo/Polyhedron/implicit_functions/Sphere_implicit_function.cpp +++ b/Polyhedron/demo/Polyhedron/implicit_functions/Sphere_implicit_function.cpp @@ -34,7 +34,8 @@ class Sphere_implicit_function : { Q_OBJECT Q_INTERFACES(Implicit_function_interface) - + Q_PLUGIN_METADATA(IID "com.geometryfactory.Mesh3Demo.Implicit_function_interface/1.0") + public: virtual QString name() const { return "Sphere function"; } @@ -50,8 +51,4 @@ public: } }; - - -#include -Q_EXPORT_PLUGIN2(Sphere_implicit_function, Sphere_implicit_function) #include "Sphere_implicit_function.moc" diff --git a/Polyhedron/demo/Polyhedron/implicit_functions/Tanglecube_implicit_function.cpp b/Polyhedron/demo/Polyhedron/implicit_functions/Tanglecube_implicit_function.cpp index b092fa25fb6..566d61ac9aa 100644 --- a/Polyhedron/demo/Polyhedron/implicit_functions/Tanglecube_implicit_function.cpp +++ b/Polyhedron/demo/Polyhedron/implicit_functions/Tanglecube_implicit_function.cpp @@ -34,7 +34,8 @@ class Tanglecube_implicit_function : { Q_OBJECT Q_INTERFACES(Implicit_function_interface) - + Q_PLUGIN_METADATA(IID "com.geometryfactory.Mesh3Demo.Implicit_function_interface/1.0") + public: virtual QString name() const { return "Tanglecube function"; } @@ -52,8 +53,4 @@ public: } }; - - -#include -Q_EXPORT_PLUGIN2(Tanglecube_implicit_function, Tanglecube_implicit_function) #include "Tanglecube_implicit_function.moc" diff --git a/Polyhedron/demo/Polyhedron/include/CGAL/check_gl_error.h b/Polyhedron/demo/Polyhedron/include/CGAL/check_gl_error.h index c2325f283b3..81384917ca9 100644 --- a/Polyhedron/demo/Polyhedron/include/CGAL/check_gl_error.h +++ b/Polyhedron/demo/Polyhedron/include/CGAL/check_gl_error.h @@ -16,12 +16,12 @@ // $Id$ // // Author: Laurent Rineau - #ifndef CGAL_GL_CHECK_ERROR_H #define CGAL_GL_CHECK_ERROR_H - +#include #include -#include +#include +/* namespace CGAL { @@ -41,6 +41,41 @@ inline bool check_gl_error(const char* filename, long line) return false; } -} // end namespace CGAL +inline bool gl_check_compilation(GLuint shader) +{ + GLint result; + glGetShaderiv(shader,GL_COMPILE_STATUS,&result); + if(result == GL_TRUE){ + std::cout<<"Vertex compilation OK"<facet_begin()); - } + + // normals (per facet, then per vertex) + void compute_normals_per_facet() + { + std::for_each(this->facets_begin(),this->facets_end(),Facet_normal()); + } + void compute_normals_per_vertex() + { + std::for_each(this->vertices_begin(),this->vertices_end(),Vertex_normal()); + } + void compute_normals() + { + compute_normals_per_facet(); + compute_normals_per_vertex(); + } + + void gl_draw_textured_triangles(bool smooth_shading, + bool use_normals, + const double scaling_tex_coordinates) + { + ::glBegin(GL_TRIANGLES); + Facet_iterator f = this->facets_begin(); + for(;f!= this->facets_end();f++) + gl_draw_textured_facet(f,smooth_shading,use_normals,scaling_tex_coordinates); + ::glEnd(); + } + + void gl_draw_textured_facet(Facet_handle f, + bool smooth_shading, + bool use_normals, + const double scaling_tex_coordinates) + { + // one normal per face + if(use_normals && !smooth_shading) + { + const typename Facet::Normal_3& n = f->normal(); + ::glNormal3f(n[0],n[1],n[2]); + } + + // revolve around current face to get vertices + Halfedge_around_facet_circulator he = f->facet_begin(); + do + { + // one normal per vertex + if(use_normals && smooth_shading) + { + const typename Facet::Normal_3& n = he->vertex()->normal(); + ::glNormal3d(n[0],n[1],n[2]); + } + + // polygon assembly is performed per vertex + const Point& p = he->vertex()->point(); + const double u = he->vertex()->u(); + const double v = he->vertex()->v(); + // std::cout << u << " " << v << std::endl; + ::glTexCoord2d(u * scaling_tex_coordinates, v * scaling_tex_coordinates); + ::glVertex3d(p[0],p[1],p[2]); + } + while(++he != f->facet_begin()); + } }; // end class Textured_polyhedron } // end namespace CGAL diff --git a/Polyhedron/demo/Polyhedron/include/Point_set_3.h b/Polyhedron/demo/Polyhedron/include/Point_set_3.h index 357c75b8fc9..bc987f60f8c 100644 --- a/Polyhedron/demo/Polyhedron/include/Point_set_3.h +++ b/Polyhedron/demo/Polyhedron/include/Point_set_3.h @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -12,11 +13,10 @@ #include #include -#ifdef CGAL_GLEW_ENABLED -# include -#else +//#ifdef CGAL_GLEW_ENABLED +//#else # include -#endif +//#endif /// The Point_set_3 class is array of points + normals of type @@ -280,24 +280,6 @@ public: ::glEnd(); } } - - // Draw oriented points with radius using OpenGL calls. - // Preconditions: must be used inbetween calls to GlSplat library - void gl_draw_splats() const - { - // TODO add support for selection - ::glBegin(GL_POINTS); - for (const_iterator it = begin(); it != end(); it++) - { - const UI_point& p = *it; - ::glNormal3dv(&p.normal().x()); -#ifdef CGAL_GLEW_ENABLED - ::glMultiTexCoord1d(GL_TEXTURE2, p.radius()); -#endif - ::glVertex3dv(&p.x()); - } - ::glEnd(); - } bool are_radii_uptodate() const { return m_radii_are_uptodate; } void set_radii_uptodate(bool /*on*/) { m_radii_are_uptodate = false; } @@ -342,17 +324,11 @@ private: m_barycenter = CGAL::ORIGIN + v / norm; // Computes bounding sphere - typedef CGAL::Min_sphere_of_spheres_d_traits_3 Traits; + typedef CGAL::Min_sphere_of_points_d_traits_3 Traits; typedef CGAL::Min_sphere_of_spheres_d Min_sphere; - typedef typename Traits::Sphere Traits_sphere; - // - // Represents points by a set of spheres with 0 radius - std::vector spheres; - for (Point_const_iterator it = begin(); it != end(); it++) - spheres.push_back(Traits_sphere(*it,0)); - // - // Computes min sphere - Min_sphere ms(spheres.begin(),spheres.end()); + + Min_sphere ms(begin(),end()); + typename Min_sphere::Cartesian_const_iterator coord = ms.center_cartesian_begin(); FT cx = *coord++; FT cy = *coord++; diff --git a/Polyhedron/demo/Polyhedron/opengl_tools.h b/Polyhedron/demo/Polyhedron/opengl_tools.h index a1383fdbba0..f468ca9a191 100644 --- a/Polyhedron/demo/Polyhedron/opengl_tools.h +++ b/Polyhedron/demo/Polyhedron/opengl_tools.h @@ -25,11 +25,10 @@ #ifndef CGAL_OPENGL_TOOLS_H #define CGAL_OPENGL_TOOLS_H -#ifdef CGAL_GLEW_ENABLED -# include -#else +//#ifdef CGAL_GLEW_ENABLED +//#else # include -#endif +//#endif namespace CGAL { namespace GL { diff --git a/Polyhedron/demo/Polyhedron/polyhedron_demo_macros.cmake b/Polyhedron/demo/Polyhedron/polyhedron_demo_macros.cmake index f7d5ed89516..3fc82ea322a 100644 --- a/Polyhedron/demo/Polyhedron/polyhedron_demo_macros.cmake +++ b/Polyhedron/demo/Polyhedron/polyhedron_demo_macros.cmake @@ -17,11 +17,12 @@ include(AddFileDependencies) set(moc_file_name "") else() set(moc_file_name ${plugin_implementation_base_name}.moc ) - qt4_generate_moc( ${plugin_implementation_base_name}.cpp "${CMAKE_CURRENT_BINARY_DIR}/${moc_file_name}" ) + qt5_generate_moc( ${plugin_implementation_base_name}.cpp "${CMAKE_CURRENT_BINARY_DIR}/${moc_file_name}" ) add_file_dependencies( ${moc_file_name} "${CMAKE_CURRENT_SOURCE_DIR}/${plugin_implementation_base_name}.cpp" ) endif() add_library(${plugin_name} MODULE ${option} ${moc_file_name} ${plugin_implementation_base_name}.cpp ${other_sources}) + qt5_use_modules(${plugin_name} Widgets Script OpenGL Gui Xml ) set_property(TARGET ${plugin_name} PROPERTY LIBRARY_OUTPUT_DIRECTORY "${CGAL_POLYHEDRON_DEMO_PLUGINS_DIR}") diff --git a/Polyhedron/demo/Polyhedron/resources/shader_instanced.v b/Polyhedron/demo/Polyhedron/resources/shader_instanced.v new file mode 100644 index 00000000000..e96e5f5d344 --- /dev/null +++ b/Polyhedron/demo/Polyhedron/resources/shader_instanced.v @@ -0,0 +1,18 @@ +attribute highp vec4 vertex; +attribute highp vec3 normals; +attribute highp vec3 colors; +attribute highp vec3 center; +uniform highp mat4 mvp_matrix; +uniform highp mat4 mv_matrix; +varying highp vec4 fP; +varying highp vec3 fN; +varying highp vec4 color; + + +void main(void) +{ +color = vec4(colors, 1.0); +fP = mv_matrix * vertex; +fN = mat3(mv_matrix)* normals; + gl_Position = mvp_matrix * vec4(vertex.x + center.x, vertex.y + center.y, vertex.z + center.z, 1.0) ; +} diff --git a/Polyhedron/demo/Polyhedron/resources/shader_with_light.f b/Polyhedron/demo/Polyhedron/resources/shader_with_light.f new file mode 100644 index 00000000000..07e8b787d55 --- /dev/null +++ b/Polyhedron/demo/Polyhedron/resources/shader_with_light.f @@ -0,0 +1,28 @@ +varying highp vec4 color; +varying highp vec4 fP; +varying highp vec3 fN; +uniform highp vec4 light_pos; +uniform highp vec4 light_diff; +uniform highp vec4 light_spec; +uniform highp vec4 light_amb; +uniform highp float spec_power ; +uniform int is_two_side; +void main(void) { + highp vec3 L = light_pos.xyz - fP.xyz; + highp vec3 V = -fP.xyz; + highp vec3 N; + if(fN == highp vec3(0.0,0.0,0.0)) + N = highp vec3(0.0,0.0,0.0); + else + N = normalize(fN); + L = normalize(L); + V = normalize(V); + highp vec3 R = reflect(-L, N); + vec4 diffuse; + if(is_two_side == 1) + diffuse = abs(dot(N,L)) * light_diff * color; + else + diffuse = max(dot(N,L), 0.0) * light_diff * color; + highp vec4 specular = pow(max(dot(R,V), 0.0), spec_power) * light_spec; +gl_FragColor = vec4((color*light_amb).xyz + diffuse.xyz + specular.xyz,1); +} diff --git a/Polyhedron/demo/Polyhedron/resources/shader_with_light.v b/Polyhedron/demo/Polyhedron/resources/shader_with_light.v new file mode 100644 index 00000000000..2e3e994cb93 --- /dev/null +++ b/Polyhedron/demo/Polyhedron/resources/shader_with_light.v @@ -0,0 +1,15 @@ +attribute highp vec4 vertex; +attribute highp vec3 normals; +attribute highp vec3 colors; +uniform highp mat4 mvp_matrix; +uniform highp mat4 mv_matrix; +varying highp vec4 fP; +varying highp vec3 fN; +varying highp vec4 color; +void main(void) +{ + color = vec4(colors, 1.0); + fP = mv_matrix * vertex; + fN = mat3(mv_matrix)* normals; + gl_Position = mvp_matrix * vertex; +} diff --git a/Polyhedron/demo/Polyhedron/resources/shader_with_texture.f b/Polyhedron/demo/Polyhedron/resources/shader_with_texture.f new file mode 100644 index 00000000000..6e110799929 --- /dev/null +++ b/Polyhedron/demo/Polyhedron/resources/shader_with_texture.f @@ -0,0 +1,8 @@ +varying highp vec3 fColors; +varying highp vec2 f_texCoord; +uniform sampler2D s_texture; + +void main(void) +{ + gl_FragColor = vec4(vec3(texture(s_texture, f_texCoord))*fColors, 1.0); +} diff --git a/Polyhedron/demo/Polyhedron/resources/shader_with_texture.v b/Polyhedron/demo/Polyhedron/resources/shader_with_texture.v new file mode 100644 index 00000000000..044c3a28553 --- /dev/null +++ b/Polyhedron/demo/Polyhedron/resources/shader_with_texture.v @@ -0,0 +1,33 @@ +attribute highp vec4 vertex; +attribute highp vec3 normal; +attribute highp vec3 color_facets; +attribute highp vec2 v_texCoord; + +uniform highp mat4 mvp_matrix; +uniform highp mat4 mv_matrix; +uniform highp mat4 f_matrix; +uniform highp int is_two_side; +uniform highp vec4 light_pos; +uniform highp vec4 light_diff; +uniform highp vec3 light_spec; +uniform highp vec4 light_amb; +uniform highp float spec_power; +varying highp vec3 fColors; +varying highp vec2 f_texCoord; + +void main(void) +{ + vec4 P = mv_matrix * vertex; + vec3 N = mat3(mv_matrix)* normal; + vec3 L = light_pos.xyz - P.xyz; + N = normalize(N); + L = normalize(L); + vec3 diffuse; + if(is_two_side == 1) + diffuse = abs(dot(N,L)) * light_diff.xyz; + else + diffuse = max(dot(N,L), 0.0) * light_diff.xyz; + f_texCoord = v_texCoord; + fColors = color_facets * (light_amb.xyz + diffuse); + gl_Position = mvp_matrix * f_matrix * vertex; +} diff --git a/Polyhedron/demo/Polyhedron/resources/shader_with_textured_edges.f b/Polyhedron/demo/Polyhedron/resources/shader_with_textured_edges.f new file mode 100644 index 00000000000..48f6f627d5b --- /dev/null +++ b/Polyhedron/demo/Polyhedron/resources/shader_with_textured_edges.f @@ -0,0 +1,8 @@ +varying highp vec3 fColors; +varying highp vec2 f_texCoord; +uniform highp sampler2D s_texture; + +void main(void) +{ + gl_FragColor = vec4(vec3(texture(s_texture, f_texCoord))*fColors, 1.0); +} \ No newline at end of file diff --git a/Polyhedron/demo/Polyhedron/resources/shader_with_textured_edges.v b/Polyhedron/demo/Polyhedron/resources/shader_with_textured_edges.v new file mode 100644 index 00000000000..fd4dd21131d --- /dev/null +++ b/Polyhedron/demo/Polyhedron/resources/shader_with_textured_edges.v @@ -0,0 +1,13 @@ + attribute highp vec4 vertex; + attribute highp vec2 v_texCoord; + uniform highp vec3 color_lines; + uniform highp mat4 mvp_matrix; + varying highp vec3 fColors; + varying highp vec2 f_texCoord; + + void main(void) + { + f_texCoord = v_texCoord; + fColors = color_lines; + gl_Position = mvp_matrix * vertex; + } diff --git a/Polyhedron/demo/Polyhedron/resources/shader_without_light.f b/Polyhedron/demo/Polyhedron/resources/shader_without_light.f new file mode 100644 index 00000000000..d0fc39f941d --- /dev/null +++ b/Polyhedron/demo/Polyhedron/resources/shader_without_light.f @@ -0,0 +1,5 @@ +varying highp vec4 color; +void main(void) +{ + gl_FragColor = color; +} diff --git a/Polyhedron/demo/Polyhedron/resources/shader_without_light.v b/Polyhedron/demo/Polyhedron/resources/shader_without_light.v new file mode 100644 index 00000000000..010abbf570b --- /dev/null +++ b/Polyhedron/demo/Polyhedron/resources/shader_without_light.v @@ -0,0 +1,11 @@ + attribute highp vec4 vertex; + attribute highp vec3 colors; + uniform highp mat4 mvp_matrix; + uniform highp mat4 f_matrix; + varying highp vec4 color; + void main(void) + { + color = vec4(colors, 1.0); + gl_Position = mvp_matrix * f_matrix * vertex; + } + diff --git a/Polyhedron_IO/demo/Polyhedron_IO/CMakeLists.txt b/Polyhedron_IO/demo/Polyhedron_IO/CMakeLists.txt index d7f11185887..1e91cdc1144 100644 --- a/Polyhedron_IO/demo/Polyhedron_IO/CMakeLists.txt +++ b/Polyhedron_IO/demo/Polyhedron_IO/CMakeLists.txt @@ -4,11 +4,9 @@ project( Polyhedron_IO_Demo ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() find_package(CGAL QUIET COMPONENTS Core ) diff --git a/Polyline_simplification_2/demo/Polyline_simplification_2/CMakeLists.txt b/Polyline_simplification_2/demo/Polyline_simplification_2/CMakeLists.txt index 9f6319be551..808265d6f8f 100644 --- a/Polyline_simplification_2/demo/Polyline_simplification_2/CMakeLists.txt +++ b/Polyline_simplification_2/demo/Polyline_simplification_2/CMakeLists.txt @@ -3,55 +3,49 @@ project (Polyline_simplification_2) -cmake_minimum_required(VERSION 2.4.5) - -set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) - -if ( COMMAND cmake_policy ) - cmake_policy( SET CMP0003 NEW ) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() -find_package(CGAL COMPONENTS Qt4) +find_package(CGAL COMPONENTS Qt5) include(${CGAL_USE_FILE}) -set( QT_USE_QTXML TRUE ) -set( QT_USE_QTMAIN TRUE ) -set( QT_USE_QTSCRIPT TRUE ) -set( QT_USE_QTOPENGL TRUE ) - -find_package(Qt4) +find_package(Qt5 QUIET COMPONENTS Xml Script OpenGL Widgets Svg) include_directories (BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/include) include_directories (BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/../../include ) include_directories (BEFORE ${CMAKE_CURRENT_BINARY_DIR}) -if ( CGAL_FOUND AND CGAL_Qt4_FOUND AND QT4_FOUND ) +if ( CGAL_FOUND AND CGAL_Qt5_FOUND AND Qt5_FOUND ) add_definitions(-DQT_NO_KEYWORDS) -include(${QT_USE_FILE}) # UI files (Qt Designer files) -qt4_wrap_ui( CDT_UI_FILES Polyline_simplification_2.ui ) +qt5_wrap_ui( CDT_UI_FILES Polyline_simplification_2.ui ) # qrc files (resources files, that contain icons, at least) -qt4_add_resources ( CDT_RESOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/Polyline_simplification_2.qrc ) +qt5_add_resources ( CDT_RESOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/Polyline_simplification_2.qrc ) # use the Qt MOC preprocessor on classes that derives from QObject -qt4_generate_moc( ${CMAKE_CURRENT_SOURCE_DIR}/Polyline_simplification_2.cpp Polyline_simplification_2.moc ) +qt5_generate_moc( ${CMAKE_CURRENT_SOURCE_DIR}/Polyline_simplification_2.cpp Polyline_simplification_2.moc ) # The executable itself. add_executable ( Polyline_simplification_2 ${CMAKE_CURRENT_SOURCE_DIR}/Polyline_simplification_2.cpp Polyline_simplification_2.moc ${CDT_UI_FILES} ${CDT_RESOURCE_FILES} ) +qt5_use_modules(Polyline_simplification_2 Xml Script OpenGL Widgets Svg) # Link with Qt libraries target_link_libraries( Polyline_simplification_2 ${QT_LIBRARIES} ) # Link with CGAL target_link_libraries( Polyline_simplification_2 ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES}) +add_to_cached_list( CGAL_EXECUTABLE_TARGETS Polyline_simplification_2 ) + else() - message(STATUS "NOTICE: This demo requires CGAL and Qt4, and will not be compiled.") + message(STATUS "NOTICE: This demo requires CGAL and Qt5, and will not be compiled.") endif() diff --git a/Polyline_simplification_2/demo/Polyline_simplification_2/Polyline_simplification_2.cpp b/Polyline_simplification_2/demo/Polyline_simplification_2/Polyline_simplification_2.cpp index fdb924c8fd9..907e79fae8f 100644 --- a/Polyline_simplification_2/demo/Polyline_simplification_2/Polyline_simplification_2.cpp +++ b/Polyline_simplification_2/demo/Polyline_simplification_2/Polyline_simplification_2.cpp @@ -162,7 +162,7 @@ MainWindow::MainWindow() // and the input they generate is passed to the triangulation with // the signal/slot mechanism mPI = new CGAL::Qt::GraphicsViewPolylineInput(this, &mScene, 0, true); // inputs polylines which are not closed - + this->on_actionInsertPolyline_toggled(true); QObject::connect(mPI, SIGNAL(generate(CGAL::Object)), this, SLOT(processInput(CGAL::Object))); @@ -172,8 +172,8 @@ MainWindow::MainWindow() QObject::connect(this->actionQuit, SIGNAL(triggered()), this, SLOT(close())); // We put mutually exclusive actions in an QActionGroup - QActionGroup* ag = new QActionGroup(this); - ag->addAction(this->actionInsertPolyline); + // QActionGroup* ag = new QActionGroup(this); + // ag->addAction(this->actionInsertPolyline); this->actionShowTriangulation->setChecked(false); @@ -247,7 +247,7 @@ MainWindow::processInput(CGAL::Object o) /* * Qt Automatic Connections - * http://doc.trolltech.com/4.4/designer-using-a-component.html#automatic-connections + * http://doc.qt.io/qt-5/designer-using-a-ui-file.html#automatic-connections * * setupUi(this) generates connections to the slots named * "on__" @@ -544,9 +544,8 @@ int main(int argc, char **argv) app.setOrganizationName("GeometryFactory"); app.setApplicationName("Polyline_simplification_2 demo"); - // Import resources from libCGALQt4. - // See http://doc.trolltech.com/4.4/qdir.html#Q_INIT_RESOURCE - CGAL_QT4_INIT_RESOURCES; + // Import resources from libCGALQt5. + CGAL_QT_INIT_RESOURCES; MainWindow mainWindow; mainWindow.show(); diff --git a/Polyline_simplification_2/demo/Polyline_simplification_2/about_Polyline_simplification_2.html b/Polyline_simplification_2/demo/Polyline_simplification_2/about_Polyline_simplification_2.html index 51dbfb1c7c7..84243e92931 100644 --- a/Polyline_simplification_2/demo/Polyline_simplification_2/about_Polyline_simplification_2.html +++ b/Polyline_simplification_2/demo/Polyline_simplification_2/about_Polyline_simplification_2.html @@ -1,10 +1,10 @@ -

Constrained Delaunay Triangulation

-

Copyright © 2008 GeometryFactory

-

This application illustrates the 2D Constrained Delaunay +

Polyline Simplification

+

Copyright © 2014 GeometryFactory

+

This application illustrates the 2D polyline simplification of CGAL.

-

See also the online +

See also the online manual.

diff --git a/Polyline_simplification_2/test/Polyline_simplification_2/CMakeLists.txt b/Polyline_simplification_2/test/Polyline_simplification_2/CMakeLists.txt index 9d65a2d3099..2a39d4ce3da 100644 --- a/Polyline_simplification_2/test/Polyline_simplification_2/CMakeLists.txt +++ b/Polyline_simplification_2/test/Polyline_simplification_2/CMakeLists.txt @@ -4,14 +4,8 @@ project( Polyline_simplification_2 ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 2.6) - if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) - else() - cmake_policy(VERSION 2.6) - endif() -endif() +cmake_minimum_required(VERSION 2.8.11) + set( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true ) @@ -36,7 +30,7 @@ include( ${CGAL_USE_FILE} ) # Boost and its components -find_package( Boost REQUIRED ) +find_package( Boost ) if ( NOT Boost_FOUND ) diff --git a/Principal_component_analysis/demo/Principal_component_analysis/CMakeLists.txt b/Principal_component_analysis/demo/Principal_component_analysis/CMakeLists.txt index 5f39801b913..60863f5c1f1 100644 --- a/Principal_component_analysis/demo/Principal_component_analysis/CMakeLists.txt +++ b/Principal_component_analysis/demo/Principal_component_analysis/CMakeLists.txt @@ -2,11 +2,9 @@ project( PCA_demo ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() foreach(INCDIR ../../include ../../../STL_Extension/include ../../../GraphicsView/include ../../../filtered_kernel/include ) @@ -17,46 +15,41 @@ endforeach() include_directories( ./ ) -# Find CGAL and CGAL Qt4 -find_package(CGAL COMPONENTS Qt4) +# Find CGAL and CGAL Qt5 +find_package(CGAL COMPONENTS Qt5) include( ${CGAL_USE_FILE} ) -# Find Qt4 itself -set( QT_USE_QTXML TRUE ) -set( QT_USE_QTMAIN TRUE ) -set( QT_USE_QTSCRIPT TRUE ) -set( QT_USE_QTOPENGL TRUE ) -find_package(Qt4) +# Find Qt5 itself +find_package(Qt5 QUIET COMPONENTS Xml Script OpenGL) # Find OpenGL find_package(OpenGL) # Find QGLViewer -if(QT4_FOUND) - include(${QT_USE_FILE}) +if(Qt5_FOUND) find_package(QGLViewer ) -endif(QT4_FOUND) +endif(Qt5_FOUND) -if(CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) +if(CGAL_Qt5_FOUND AND Qt5_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) include_directories ( ${QGLVIEWER_INCLUDE_DIR} ) - qt4_wrap_ui( UI_FILES MainWindow.ui ) + qt5_wrap_ui( UI_FILES MainWindow.ui ) include(AddFileDependencies) - qt4_generate_moc( "MainWindow.h" "${CMAKE_CURRENT_BINARY_DIR}/MainWindow_moc.cpp" ) + qt5_generate_moc( "MainWindow.h" "${CMAKE_CURRENT_BINARY_DIR}/MainWindow_moc.cpp" ) add_file_dependencies( MainWindow_moc.cpp "${CMAKE_CURRENT_SOURCE_DIR}/MainWindow.h" ) - qt4_generate_moc( "Viewer.h" "${CMAKE_CURRENT_BINARY_DIR}/Viewer_moc.cpp" ) + qt5_generate_moc( "Viewer.h" "${CMAKE_CURRENT_BINARY_DIR}/Viewer_moc.cpp" ) add_file_dependencies( Viewer_moc.cpp "${CMAKE_CURRENT_SOURCE_DIR}/Viewer.h" ) - qt4_add_resources ( RESOURCE_FILES PCA_demo.qrc ) + qt5_add_resources ( RESOURCE_FILES PCA_demo.qrc ) add_file_dependencies( PCA_demo.cpp "${CMAKE_CURRENT_BINARY_DIR}/MainWindow_moc.cpp" "${CMAKE_CURRENT_BINARY_DIR}/Viewer_moc.cpp" ) add_executable ( PCA_demo PCA_demo.cpp ${UI_FILES} ${RESOURCE_FILES} ) - + qt5_use_modules( PCA_demo Xml Script OpenGL) # Link with Qt libraries target_link_libraries( PCA_demo ${QT_LIBRARIES} ) @@ -69,16 +62,16 @@ if(CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) add_to_cached_list( CGAL_EXECUTABLE_TARGETS PCA_demo ) -else (CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) +else (CGAL_Qt5_FOUND AND Qt5_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) set(PCA_MISSING_DEPS "") - if(NOT CGAL_Qt4_FOUND) - set(PCA_MISSING_DEPS "the CGAL Qt4 library, ${PCA_MISSING_DEPS}") + if(NOT CGAL_Qt5_FOUND) + set(PCA_MISSING_DEPS "the CGAL Qt5 library, ${PCA_MISSING_DEPS}") endif() - if(NOT QT4_FOUND) - set(PCA_MISSING_DEPS "Qt4, ${PCA_MISSING_DEPS}") + if(NOT Qt5_FOUND) + set(PCA_MISSING_DEPS "Qt5, ${PCA_MISSING_DEPS}") endif() if(NOT OPENGL_FOUND) @@ -91,4 +84,4 @@ else (CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) message(STATUS "NOTICE: This demo requires ${PCA_MISSING_DEPS} and will not be compiled.") -endif (CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) +endif (CGAL_Qt5_FOUND AND Qt5_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) diff --git a/Principal_component_analysis/demo/Principal_component_analysis/MainWindow.cpp b/Principal_component_analysis/demo/Principal_component_analysis/MainWindow.cpp index a4b984c5880..16fc1b8aca1 100644 --- a/Principal_component_analysis/demo/Principal_component_analysis/MainWindow.cpp +++ b/Principal_component_analysis/demo/Principal_component_analysis/MainWindow.cpp @@ -13,6 +13,9 @@ #include "ui_MainWindow.h" +#include + + MainWindow::MainWindow(QWidget* parent) : CGAL::Qt::DemosMainWindow(parent) { diff --git a/Principal_component_analysis/demo/Principal_component_analysis/PCA_demo.cpp b/Principal_component_analysis/demo/Principal_component_analysis/PCA_demo.cpp index 4a5c6c08663..eac8974765b 100644 --- a/Principal_component_analysis/demo/Principal_component_analysis/PCA_demo.cpp +++ b/Principal_component_analysis/demo/Principal_component_analysis/PCA_demo.cpp @@ -34,9 +34,10 @@ int main(int argc, char **argv) app.setOrganizationName("INRIA"); app.setApplicationName("PCA demo"); - // Import resources from libCGALQt4. - // See http://doc.trolltech.com/4.4/qdir.html#Q_INIT_RESOURCE - CGAL_QT4_INIT_RESOURCES; + // Import resources from libCGALQt. + // See http://doc.qt.io/qt-5/qdir.html#Q_INIT_RESOURCE + + CGAL_QT_INIT_RESOURCES; MainWindow mainWindow; mainWindow.show(); diff --git a/Principal_component_analysis/demo/Principal_component_analysis/Viewer.cpp b/Principal_component_analysis/demo/Principal_component_analysis/Viewer.cpp index ede6ff45682..4b74ad3093c 100644 --- a/Principal_component_analysis/demo/Principal_component_analysis/Viewer.cpp +++ b/Principal_component_analysis/demo/Principal_component_analysis/Viewer.cpp @@ -5,7 +5,6 @@ Viewer::Viewer(QWidget* parent) : QGLViewer(parent), m_pScene(NULL) { - setBackgroundColor(::Qt::white); } void Viewer::setScene(Scene* pScene) @@ -26,5 +25,6 @@ void Viewer::draw() void Viewer::initializeGL() { QGLViewer::initializeGL(); + setBackgroundColor(::Qt::white); } diff --git a/Qt_widget/src/CGAL_Qt3/CMakeLists.txt b/Qt_widget/src/CGAL_Qt3/CMakeLists.txt index ef24865e3ae..abeb440d19c 100644 --- a/Qt_widget/src/CGAL_Qt3/CMakeLists.txt +++ b/Qt_widget/src/CGAL_Qt3/CMakeLists.txt @@ -8,7 +8,7 @@ ENABLE_LANGUAGE(C) find_package(OpenGL QUIET ) find_package(Qt3-patched QUIET ) # FindQt3-patched.cmake is FindQt3.cmake patched by CGAL developers, so -# that it can be used together with FindQt4: all its variables are prefixed +# that it can be used together with FindQt5: all its variables are prefixed # by "QT3_" instead of "QT_". if( QT3_FOUND ) @@ -71,7 +71,7 @@ if( QT3_FOUND ) add_dependencies( CGAL_Qt3 CGAL ) - target_link_libraries( CGAL_Qt3 ${CGAL_LIBRARY} ${CGAL_3RD_PARTY_LIBRARIES} ${CGAL_Qt3_3RD_PARTY_LIBRARIES} ) + target_link_libraries( CGAL_Qt3 CGAL ${CGAL_3RD_PARTY_LIBRARIES} ${CGAL_Qt3_3RD_PARTY_LIBRARIES} ) add_definitions( ${CGAL_3RD_PARTY_DEFINITIONS} ${CGAL_Qt3_3RD_PARTY_DEFINITIONS} ) diff --git a/Qt_widget/test/Qt_widget/CMakeLists.txt b/Qt_widget/test/Qt_widget/CMakeLists.txt index b23358a1d75..b0aee523914 100644 --- a/Qt_widget/test/Qt_widget/CMakeLists.txt +++ b/Qt_widget/test/Qt_widget/CMakeLists.txt @@ -2,19 +2,15 @@ project( Qt_widget_test ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) -endif() +cmake_minimum_required(VERSION 2.8.11) + find_package(CGAL QUIET COMPONENTS Qt3 ) include( ${CGAL_USE_FILE} ) find_package(Qt3-patched QUIET) # FindQt3-patched.cmake is FindQt3.cmake patched by CGAL developers, so -# that it can be used together with FindQt4: all its variables are prefixed +# that it can be used together with Qt5: all its variables are prefixed # by "QT3_" instead of "QT_". if ( CGAL_FOUND AND CGAL_Qt3_FOUND AND QT3_FOUND ) diff --git a/Ridges_3/examples/Ridges_3/CMakeLists.txt b/Ridges_3/examples/Ridges_3/CMakeLists.txt index fe049fc0cdd..a816d716828 100644 --- a/Ridges_3/examples/Ridges_3/CMakeLists.txt +++ b/Ridges_3/examples/Ridges_3/CMakeLists.txt @@ -1,12 +1,8 @@ # This is the CMake script for compiling a CGAL application. project( Ridges_3_example ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) -endif() +cmake_minimum_required(VERSION 2.8.11) + find_package(CGAL QUIET ) diff --git a/Ridges_3/test/Ridges_3/CMakeLists.txt b/Ridges_3/test/Ridges_3/CMakeLists.txt index 7c59548de98..a6385196714 100644 --- a/Ridges_3/test/Ridges_3/CMakeLists.txt +++ b/Ridges_3/test/Ridges_3/CMakeLists.txt @@ -4,12 +4,8 @@ project( Ridges_3_test ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) -endif() +cmake_minimum_required(VERSION 2.8.11) + find_package(CGAL QUIET COMPONENTS Core ) diff --git a/STL_Extension/benchmark/compact_container_benchmark/CMakeLists.txt b/STL_Extension/benchmark/compact_container_benchmark/CMakeLists.txt index 3fd60ef3cec..6a289eda421 100644 --- a/STL_Extension/benchmark/compact_container_benchmark/CMakeLists.txt +++ b/STL_Extension/benchmark/compact_container_benchmark/CMakeLists.txt @@ -3,14 +3,8 @@ project( Compact_container_benchmark ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 2.6) - if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) - else() - cmake_policy(VERSION 2.6) - endif() -endif() +cmake_minimum_required(VERSION 2.8.11) + find_package(CGAL QUIET COMPONENTS Core ) diff --git a/STL_Extension/benchmark/copy_n_benchmark/CMakeLists.txt b/STL_Extension/benchmark/copy_n_benchmark/CMakeLists.txt index 3171042da61..66aaabf1bf9 100644 --- a/STL_Extension/benchmark/copy_n_benchmark/CMakeLists.txt +++ b/STL_Extension/benchmark/copy_n_benchmark/CMakeLists.txt @@ -4,12 +4,8 @@ project( copy_n_benchmark_example ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) -endif() +cmake_minimum_required(VERSION 2.8.11) + find_package(CGAL QUIET COMPONENTS Core ) diff --git a/STL_Extension/test/STL_Extension/CMakeLists.txt b/STL_Extension/test/STL_Extension/CMakeLists.txt index a831c6e08d8..6856027a210 100644 --- a/STL_Extension/test/STL_Extension/CMakeLists.txt +++ b/STL_Extension/test/STL_Extension/CMakeLists.txt @@ -4,14 +4,8 @@ project( STL_Extension_test ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 2.6) - if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) - else() - cmake_policy(VERSION 2.6) - endif() -endif() +cmake_minimum_required(VERSION 2.8.11) + find_package(CGAL QUIET COMPONENTS Core ) diff --git a/Scale_space_reconstruction_3/examples/Scale_space_reconstruction_3/CMakeLists.txt b/Scale_space_reconstruction_3/examples/Scale_space_reconstruction_3/CMakeLists.txt index 658bbd10609..6661ec8204d 100644 --- a/Scale_space_reconstruction_3/examples/Scale_space_reconstruction_3/CMakeLists.txt +++ b/Scale_space_reconstruction_3/examples/Scale_space_reconstruction_3/CMakeLists.txt @@ -1,14 +1,6 @@ project( Scale_space ) -# Check CMake version -cmake_minimum_required( VERSION 2.6.2 ) -if( "${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 2.6 ) - if( "${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3 ) - cmake_policy( VERSION 2.8.4 ) - else() - cmake_policy( VERSION 2.6 ) - endif() -endif() +cmake_minimum_required(VERSION 2.8.11) find_package( CGAL QUIET COMPONENTS Core ) diff --git a/Scripts/scripts/cgal_create_CMakeLists b/Scripts/scripts/cgal_create_CMakeLists index 311bd5a553c..e56fb93df2d 100755 --- a/Scripts/scripts/cgal_create_CMakeLists +++ b/Scripts/scripts/cgal_create_CMakeLists @@ -112,22 +112,7 @@ EOF cat << 'EOF' -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 2.6) - if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) - else() - cmake_policy(VERSION 2.6) - endif() -endif() - -set( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true ) - -if ( COMMAND cmake_policy ) - - cmake_policy( SET CMP0003 NEW ) - -endif() +cmake_minimum_required(VERSION 2.8.11) # CGAL and its components EOF diff --git a/Scripts/scripts/cgal_create_cmake_script b/Scripts/scripts/cgal_create_cmake_script index 2a29e1ec9fb..b6afcacd3c5 100755 --- a/Scripts/scripts/cgal_create_cmake_script +++ b/Scripts/scripts/cgal_create_cmake_script @@ -44,14 +44,7 @@ project( ${PROJECT}_${TYPE} ) EOF cat <<'EOF' -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 2.6) - if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) - else() - cmake_policy(VERSION 2.6) - endif() -endif() +cmake_minimum_required(VERSION 2.8.10) EOF diff --git a/Segment_Delaunay_graph_2/benchmark/Segment_Delaunay_graph_2/CMakeLists.txt b/Segment_Delaunay_graph_2/benchmark/Segment_Delaunay_graph_2/CMakeLists.txt index 2fdfef6595f..08152286d2b 100644 --- a/Segment_Delaunay_graph_2/benchmark/Segment_Delaunay_graph_2/CMakeLists.txt +++ b/Segment_Delaunay_graph_2/benchmark/Segment_Delaunay_graph_2/CMakeLists.txt @@ -4,12 +4,8 @@ project( Segment_Delaunay_graph_2_example ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) -endif() +cmake_minimum_required(VERSION 2.8.11) + find_package(CGAL QUIET COMPONENTS Core ) diff --git a/Segment_Delaunay_graph_2/demo/README.txt b/Segment_Delaunay_graph_2/demo/README.txt index 88aab284bf0..c6be5034547 100644 --- a/Segment_Delaunay_graph_2/demo/README.txt +++ b/Segment_Delaunay_graph_2/demo/README.txt @@ -1,2 +1,2 @@ This directory is no longer in CGAL tarballs (see ../dont_submit). A new -Qt4 demo is in GraphicsView/demo/Segment_Delaunay_graph_2/ +Qt5 demo is in GraphicsView/demo/Segment_Delaunay_graph_2/ diff --git a/Segment_Delaunay_graph_2/demo/Segment_Delaunay_graph_2/Qt3/CMakeLists.txt b/Segment_Delaunay_graph_2/demo/Segment_Delaunay_graph_2/Qt3/CMakeLists.txt index 209eff0468a..3e54440fbcf 100644 --- a/Segment_Delaunay_graph_2/demo/Segment_Delaunay_graph_2/Qt3/CMakeLists.txt +++ b/Segment_Delaunay_graph_2/demo/Segment_Delaunay_graph_2/Qt3/CMakeLists.txt @@ -9,7 +9,7 @@ include( ${CGAL_USE_FILE} ) find_package(Qt3-patched) # FindQt3-patched.cmake is FindQt3.cmake patched by CGAL developers, so -# that it can be used together with FindQt4: all its variables are prefixed +# that it can be used together with Qt5: all its variables are prefixed # by "QT3_" instead of "QT_". if ( CGAL_FOUND AND CGAL_Qt3_FOUND AND QT3_FOUND ) diff --git a/Segment_Delaunay_graph_Linf_2/benchmark/Segment_Delaunay_graph_Linf_2/CMakeLists.txt b/Segment_Delaunay_graph_Linf_2/benchmark/Segment_Delaunay_graph_Linf_2/CMakeLists.txt index 44b603d27ef..21ffaa6736c 100644 --- a/Segment_Delaunay_graph_Linf_2/benchmark/Segment_Delaunay_graph_Linf_2/CMakeLists.txt +++ b/Segment_Delaunay_graph_Linf_2/benchmark/Segment_Delaunay_graph_Linf_2/CMakeLists.txt @@ -4,12 +4,8 @@ project( Segment_Delaunay_graph_2_example ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) -endif() +cmake_minimum_required(VERSION 2.8.11) + find_package(CGAL QUIET COMPONENTS Core ) diff --git a/Segment_Delaunay_graph_Linf_2/examples/Segment_Delaunay_graph_Linf_2/CMakeLists.txt b/Segment_Delaunay_graph_Linf_2/examples/Segment_Delaunay_graph_Linf_2/CMakeLists.txt index a3b510335dd..84632aa1f3c 100644 --- a/Segment_Delaunay_graph_Linf_2/examples/Segment_Delaunay_graph_Linf_2/CMakeLists.txt +++ b/Segment_Delaunay_graph_Linf_2/examples/Segment_Delaunay_graph_Linf_2/CMakeLists.txt @@ -4,14 +4,8 @@ project( Segment_Delaunay_graph_Linf_2_example ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 2.6) - if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) - else() - cmake_policy(VERSION 2.6) - endif() -endif() +cmake_minimum_required(VERSION 2.8.11) + find_package(CGAL QUIET COMPONENTS Core ) diff --git a/Skin_surface_3/examples/Skin_surface_3/CMakeLists.txt b/Skin_surface_3/examples/Skin_surface_3/CMakeLists.txt index 09f28747f67..d7f5d603a4f 100644 --- a/Skin_surface_3/examples/Skin_surface_3/CMakeLists.txt +++ b/Skin_surface_3/examples/Skin_surface_3/CMakeLists.txt @@ -3,12 +3,8 @@ project( Skin_surface_3_example ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) -endif() +cmake_minimum_required(VERSION 2.8.11) + find_package(CGAL) diff --git a/Snap_rounding_2/demo/Snap_rounding_2/Qt3/CMakeLists.txt b/Snap_rounding_2/demo/Snap_rounding_2/Qt3/CMakeLists.txt index b945d0d1f7a..b469895d732 100644 --- a/Snap_rounding_2/demo/Snap_rounding_2/Qt3/CMakeLists.txt +++ b/Snap_rounding_2/demo/Snap_rounding_2/Qt3/CMakeLists.txt @@ -9,7 +9,7 @@ include( ${CGAL_USE_FILE} ) find_package(Qt3-patched) # FindQt3-patched.cmake is FindQt3.cmake patched by CGAL developers, so -# that it can be used together with FindQt4: all its variables are prefixed +# that it can be used together with Qt5: all its variables are prefixed # by "QT3_" instead of "QT_". if ( CGAL_FOUND AND CGAL_Qt3_FOUND AND QT3_FOUND ) diff --git a/Snap_rounding_2/test/Snap_rounding_2/cgal_test_base b/Snap_rounding_2/test/Snap_rounding_2/cgal_test_base index 128d0dcadfe..27104f23a44 100755 --- a/Snap_rounding_2/test/Snap_rounding_2/cgal_test_base +++ b/Snap_rounding_2/test/Snap_rounding_2/cgal_test_base @@ -128,8 +128,8 @@ run() fi - compile test - run test + compile test_snap_rounding_2 + run test_snap_rounding_2 if [ "${TEST_WITH_CMAKE}" != "FALSE" ]; then # diff --git a/Snap_rounding_2/test/Snap_rounding_2/test.cpp b/Snap_rounding_2/test/Snap_rounding_2/test_snap_rounding_2.cpp similarity index 100% rename from Snap_rounding_2/test/Snap_rounding_2/test.cpp rename to Snap_rounding_2/test/Snap_rounding_2/test_snap_rounding_2.cpp diff --git a/Spatial_searching/benchmark/Spatial_searching/CMakeLists.txt b/Spatial_searching/benchmark/Spatial_searching/CMakeLists.txt index 5a22d66694a..054019dad04 100644 --- a/Spatial_searching/benchmark/Spatial_searching/CMakeLists.txt +++ b/Spatial_searching/benchmark/Spatial_searching/CMakeLists.txt @@ -4,14 +4,8 @@ project( Spatial_searching_ ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 2.6) - if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) - else() - cmake_policy(VERSION 2.6) - endif() -endif() +cmake_minimum_required(VERSION 2.8.11) + find_package(CGAL QUIET COMPONENTS Core ) diff --git a/Spatial_searching/benchmark/Spatial_searching/tools/CMakeLists.txt b/Spatial_searching/benchmark/Spatial_searching/tools/CMakeLists.txt index 91dd87900a9..2528a0e25c1 100644 --- a/Spatial_searching/benchmark/Spatial_searching/tools/CMakeLists.txt +++ b/Spatial_searching/benchmark/Spatial_searching/tools/CMakeLists.txt @@ -4,14 +4,8 @@ project( tools_ ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 2.6) - if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) - else() - cmake_policy(VERSION 2.6) - endif() -endif() +cmake_minimum_required(VERSION 2.8.11) + find_package(CGAL QUIET COMPONENTS Core ) diff --git a/Spatial_searching/demo/Spatial_searching/Qt3/CMakeLists.txt b/Spatial_searching/demo/Spatial_searching/Qt3/CMakeLists.txt index cecb0d44ff9..c4c2232dce7 100644 --- a/Spatial_searching/demo/Spatial_searching/Qt3/CMakeLists.txt +++ b/Spatial_searching/demo/Spatial_searching/Qt3/CMakeLists.txt @@ -9,7 +9,7 @@ include( ${CGAL_USE_FILE} ) find_package(Qt3-patched) # FindQt3-patched.cmake is FindQt3.cmake patched by CGAL developers, so -# that it can be used together with FindQt4: all its variables are prefixed +# that it can be used together with Qt5: all its variables are prefixed # by "QT3_" instead of "QT_". if ( CGAL_FOUND AND CGAL_Qt3_FOUND AND QT3_FOUND ) diff --git a/Spatial_searching/examples/Spatial_searching/CMakeLists.txt b/Spatial_searching/examples/Spatial_searching/CMakeLists.txt index a0d74876886..074ab36bd76 100644 --- a/Spatial_searching/examples/Spatial_searching/CMakeLists.txt +++ b/Spatial_searching/examples/Spatial_searching/CMakeLists.txt @@ -4,14 +4,8 @@ project( Spatial_searching ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 2.6) - if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) - else() - cmake_policy(VERSION 2.6) - endif() -endif() +cmake_minimum_required(VERSION 2.8.11) + set( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true ) diff --git a/Spatial_sorting/benchmark/Spatial_sorting/CMakeLists.txt b/Spatial_sorting/benchmark/Spatial_sorting/CMakeLists.txt index e669ef52267..4d382d5db54 100644 --- a/Spatial_sorting/benchmark/Spatial_sorting/CMakeLists.txt +++ b/Spatial_sorting/benchmark/Spatial_sorting/CMakeLists.txt @@ -4,14 +4,8 @@ project( Spatial_sorting_ ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 2.6) - if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) - else() - cmake_policy(VERSION 2.6) - endif() -endif() +cmake_minimum_required(VERSION 2.8.11) + find_package(CGAL QUIET COMPONENTS Core ) diff --git a/Straight_skeleton_2/demo/Straight_skeleton_2/CMakeLists.txt b/Straight_skeleton_2/demo/Straight_skeleton_2/CMakeLists.txt index 14b91c486f1..07882d57a15 100644 --- a/Straight_skeleton_2/demo/Straight_skeleton_2/CMakeLists.txt +++ b/Straight_skeleton_2/demo/Straight_skeleton_2/CMakeLists.txt @@ -2,11 +2,9 @@ project( straight_skeleton_2 ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() find_package(CGAL COMPONENTS Qt3 Core ) @@ -14,7 +12,7 @@ include( ${CGAL_USE_FILE} ) find_package(Qt3-patched) # FindQt3-patched.cmake is FindQt3.cmake patched by CGAL developers, so -# that it can be used together with FindQt4: all its variables are prefixed +# that it can be used together with Qt5: all its variables are prefixed # by "QT3_" instead of "QT_". if ( CGAL_FOUND AND CGAL_Qt3_FOUND AND QT3_FOUND ) diff --git a/Stream_lines_2/demo/Stream_lines_2/Qt3/CMakeLists.txt b/Stream_lines_2/demo/Stream_lines_2/Qt3/CMakeLists.txt index c1f39cfa4b5..291c708615c 100644 --- a/Stream_lines_2/demo/Stream_lines_2/Qt3/CMakeLists.txt +++ b/Stream_lines_2/demo/Stream_lines_2/Qt3/CMakeLists.txt @@ -9,7 +9,7 @@ include( ${CGAL_USE_FILE} ) find_package(Qt3-patched) # FindQt3-patched.cmake is FindQt3.cmake patched by CGAL developers, so -# that it can be used together with FindQt4: all its variables are prefixed +# that it can be used together with Qt5: all its variables are prefixed # by "QT3_" instead of "QT_". find_package(OpenGL) diff --git a/Stream_support/benchmark/Stream_support/CMakeLists.txt b/Stream_support/benchmark/Stream_support/CMakeLists.txt index d18e998483d..ee9dc640454 100644 --- a/Stream_support/benchmark/Stream_support/CMakeLists.txt +++ b/Stream_support/benchmark/Stream_support/CMakeLists.txt @@ -4,14 +4,8 @@ project( Stream_support ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 2.6) - if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) - else() - cmake_policy(VERSION 2.6) - endif() -endif() +cmake_minimum_required(VERSION 2.8.11) + set( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true ) diff --git a/Surface_mesh/benchmark/CMakeLists.txt b/Surface_mesh/benchmark/CMakeLists.txt index d92911e7dda..267a8115d9b 100644 --- a/Surface_mesh/benchmark/CMakeLists.txt +++ b/Surface_mesh/benchmark/CMakeLists.txt @@ -1,6 +1,6 @@ project(Surface_mesh_performance) -cmake_minimum_required(VERSION 2.6.2) +cmake_minimum_required(VERSION 2.8.11) find_package(CGAL REQUIRED) include(${CGAL_USE_FILE}) diff --git a/Surface_mesh/examples/Surface_mesh/CMakeLists.txt b/Surface_mesh/examples/Surface_mesh/CMakeLists.txt index 6889357d7b8..d8b3eeaba36 100644 --- a/Surface_mesh/examples/Surface_mesh/CMakeLists.txt +++ b/Surface_mesh/examples/Surface_mesh/CMakeLists.txt @@ -4,14 +4,8 @@ project( Surface_mesh_ ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 2.6) - if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) - else() - cmake_policy(VERSION 2.6) - endif() -endif() +cmake_minimum_required(VERSION 2.8.11) + find_package(CGAL QUIET COMPONENTS Core ) diff --git a/Surface_mesh_parameterization/examples/Surface_mesh_parameterization/CMakeLists.txt b/Surface_mesh_parameterization/examples/Surface_mesh_parameterization/CMakeLists.txt index 2130b342647..fa3cdc67ac6 100644 --- a/Surface_mesh_parameterization/examples/Surface_mesh_parameterization/CMakeLists.txt +++ b/Surface_mesh_parameterization/examples/Surface_mesh_parameterization/CMakeLists.txt @@ -3,12 +3,8 @@ project( Surface_mesh_parameterization_example ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) -endif() +cmake_minimum_required(VERSION 2.8.11) + # Require packages new or improved since CGAL 3.4 include_directories (BEFORE ../../../Installation/include/) diff --git a/Surface_mesh_parameterization/test/Surface_mesh_parameterization/CMakeLists.txt b/Surface_mesh_parameterization/test/Surface_mesh_parameterization/CMakeLists.txt index 6cdad13b851..59346d09e9c 100644 --- a/Surface_mesh_parameterization/test/Surface_mesh_parameterization/CMakeLists.txt +++ b/Surface_mesh_parameterization/test/Surface_mesh_parameterization/CMakeLists.txt @@ -3,12 +3,8 @@ project( Surface_mesh_parameterization_test ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) -endif() +cmake_minimum_required(VERSION 2.8.11) + # Require packages new or improved since CGAL 3.4 include_directories (BEFORE ../../../Installation/include/) diff --git a/Surface_mesh_segmentation/examples/Surface_mesh_segmentation/CMakeLists.txt b/Surface_mesh_segmentation/examples/Surface_mesh_segmentation/CMakeLists.txt index 66401c6d404..efbdeeb97be 100644 --- a/Surface_mesh_segmentation/examples/Surface_mesh_segmentation/CMakeLists.txt +++ b/Surface_mesh_segmentation/examples/Surface_mesh_segmentation/CMakeLists.txt @@ -4,14 +4,8 @@ project( Surface_mesh_segmentation ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 2.6) - if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) - else() - cmake_policy(VERSION 2.6) - endif() -endif() +cmake_minimum_required(VERSION 2.8.11) + set( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true ) @@ -36,7 +30,7 @@ include( ${CGAL_USE_FILE} ) # Boost and its components -find_package( Boost REQUIRED ) +find_package( Boost ) if ( NOT Boost_FOUND ) diff --git a/Surface_mesh_shortest_path/examples/Surface_mesh_shortest_path/CMakeLists.txt b/Surface_mesh_shortest_path/examples/Surface_mesh_shortest_path/CMakeLists.txt index 8907356fd80..ff2cb1194cd 100644 --- a/Surface_mesh_shortest_path/examples/Surface_mesh_shortest_path/CMakeLists.txt +++ b/Surface_mesh_shortest_path/examples/Surface_mesh_shortest_path/CMakeLists.txt @@ -4,14 +4,8 @@ project( Surface_mesh_shortest_path_ ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 2.6) - if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) - else() - cmake_policy(VERSION 2.6) - endif() -endif() +cmake_minimum_required(VERSION 2.8.11) + find_package(CGAL QUIET COMPONENTS Core ) diff --git a/Surface_mesh_shortest_path/test/Surface_mesh_shortest_path/CMakeLists.txt b/Surface_mesh_shortest_path/test/Surface_mesh_shortest_path/CMakeLists.txt index 901c6190518..c3e7c22cbeb 100644 --- a/Surface_mesh_shortest_path/test/Surface_mesh_shortest_path/CMakeLists.txt +++ b/Surface_mesh_shortest_path/test/Surface_mesh_shortest_path/CMakeLists.txt @@ -4,14 +4,8 @@ project( Surface_mesh_shortest_path_ ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 2.6) - if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) - else() - cmake_policy(VERSION 2.6) - endif() -endif() +cmake_minimum_required(VERSION 2.8.11) + find_package(CGAL QUIET COMPONENTS Core ) diff --git a/Surface_mesh_simplification/examples/Surface_mesh_simplification/CMakeLists.txt b/Surface_mesh_simplification/examples/Surface_mesh_simplification/CMakeLists.txt index bb408d278f5..5eaf608f919 100644 --- a/Surface_mesh_simplification/examples/Surface_mesh_simplification/CMakeLists.txt +++ b/Surface_mesh_simplification/examples/Surface_mesh_simplification/CMakeLists.txt @@ -4,14 +4,8 @@ project( Surface_mesh_simplification ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 2.6) - if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) - else() - cmake_policy(VERSION 2.6) - endif() -endif() +cmake_minimum_required(VERSION 2.8.11) + set( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true ) @@ -36,7 +30,7 @@ include( ${CGAL_USE_FILE} ) # Boost and its components -find_package( Boost REQUIRED ) +find_package( Boost ) if ( NOT Boost_FOUND ) diff --git a/Surface_mesh_skeletonization/benchmark/Surface_mesh_skeletonization/CMakeLists.txt b/Surface_mesh_skeletonization/benchmark/Surface_mesh_skeletonization/CMakeLists.txt index e42e3308b1d..72377a6abf9 100644 --- a/Surface_mesh_skeletonization/benchmark/Surface_mesh_skeletonization/CMakeLists.txt +++ b/Surface_mesh_skeletonization/benchmark/Surface_mesh_skeletonization/CMakeLists.txt @@ -7,14 +7,8 @@ project( Mean_curvature_skeleton ) #SET(GCC_COVERAGE_COMPILE_FLAGS "-fprofile-arcs -ftest-coverage") #SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}" ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 2.6) - if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) - else() - cmake_policy(VERSION 2.6) - endif() -endif() +cmake_minimum_required(VERSION 2.8.11) + set( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true ) diff --git a/Surface_mesh_skeletonization/examples/Surface_mesh_skeletonization/CMakeLists.txt b/Surface_mesh_skeletonization/examples/Surface_mesh_skeletonization/CMakeLists.txt index 7146aa58bda..b27bc6a45ec 100644 --- a/Surface_mesh_skeletonization/examples/Surface_mesh_skeletonization/CMakeLists.txt +++ b/Surface_mesh_skeletonization/examples/Surface_mesh_skeletonization/CMakeLists.txt @@ -4,14 +4,8 @@ project( Surface_mesh_skeletonization_ ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 2.6) - if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) - else() - cmake_policy(VERSION 2.6) - endif() -endif() +cmake_minimum_required(VERSION 2.8.11) + find_package(CGAL QUIET COMPONENTS Core ) diff --git a/Surface_mesh_skeletonization/test/Surface_mesh_skeletonization/CMakeLists.txt b/Surface_mesh_skeletonization/test/Surface_mesh_skeletonization/CMakeLists.txt index a59292aa28e..a540e401b5d 100644 --- a/Surface_mesh_skeletonization/test/Surface_mesh_skeletonization/CMakeLists.txt +++ b/Surface_mesh_skeletonization/test/Surface_mesh_skeletonization/CMakeLists.txt @@ -4,14 +4,8 @@ project( Mean_curvature_skeleton_ ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 2.6) - if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) - else() - cmake_policy(VERSION 2.6) - endif() -endif() +cmake_minimum_required(VERSION 2.8.11) + find_package(CGAL QUIET COMPONENTS Core ) diff --git a/Surface_mesher/demo/Surface_mesher/CMakeLists.txt b/Surface_mesher/demo/Surface_mesher/CMakeLists.txt index d6373074f8e..be927698eb9 100644 --- a/Surface_mesher/demo/Surface_mesher/CMakeLists.txt +++ b/Surface_mesher/demo/Surface_mesher/CMakeLists.txt @@ -2,11 +2,14 @@ set ( prj Surface_mesher ) project ( ${prj} ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +# Find includes in corresponding build directories +set(CMAKE_INCLUDE_CURRENT_DIR ON) +# Instruct CMake to run moc automatically when needed. +set(CMAKE_AUTOMOC ON) + +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() set(PACKAGE_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..) @@ -18,7 +21,7 @@ foreach(INC_DIR ${PACKAGE_ROOT}/include ${PACKAGE_ROOT}/../Mesh_2/include ${PACK include_directories (BEFORE ${INC_DIR}) endif() endforeach() -foreach(LIB_DIR ${PACKAGE_ROOT}/../CGAL_ImageIO/src/CGAL_ImageIO ${PACKAGE_ROOT}/../GraphicsView/src/CGALQt4) +foreach(LIB_DIR ${PACKAGE_ROOT}/../CGAL_ImageIO/src/CGAL_ImageIO ${PACKAGE_ROOT}/../GraphicsView/src/CGALQt5) if (EXISTS ${LIB_DIR}) link_directories (${LIB_DIR}) endif() @@ -26,25 +29,24 @@ endforeach() include_directories( ./ ) -# QGLViwer needs Qt4 configured with QtOpenGL and QtXml support +# QGLViwer needs Qt5 configured with QtOpenGL and QtXml support set( QT_USE_QTOPENGL TRUE ) set( QT_USE_QTXML TRUE ) set( QT_USE_QTMAIN TRUE ) -find_package(CGAL COMPONENTS ImageIO Qt4) -if ( CGAL_FOUND AND CGAL_Qt4_FOUND) +find_package(CGAL COMPONENTS ImageIO Qt5) +if ( CGAL_FOUND AND CGAL_Qt5_FOUND AND CGAL_ImageIO_FOUND) add_definitions(-DQT_NO_KEYWORDS) include( ${CGAL_USE_FILE} ) - find_package(Qt4 ) + find_package(Qt5 QUIET COMPONENTS OpenGL Xml ) find_package(QGLViewer ) find_package(OpenGL ) - if ( QGLVIEWER_FOUND ) + if ( QGLVIEWER_FOUND AND Qt5_FOUND) - include( ${QT_USE_FILE}) include_directories( ${QGLVIEWER_INCLUDE_DIR} ) add_definitions(${QGLVIEWER_DEFINITIONS}) @@ -79,17 +81,18 @@ if ( CGAL_FOUND AND CGAL_Qt4_FOUND) add_definitions(-DCGAL_SURFACE_MESH_DEMO_USE_MARCHING_CUBE) endif() - qt4_automoc( ${sources} ) - qt4_generate_moc( "surface.h" "${CMAKE_CURRENT_BINARY_DIR}/moc_surface.cpp" ) + qt5_generate_moc( "surface.h" "${CMAKE_CURRENT_BINARY_DIR}/moc_surface.cpp" ) set( sources ${sources} moc_surface.cpp) - qt4_wrap_ui( uis ui/values_list.ui ui/mainwindow.ui ui/optionsdialog.ui ui/raw_image.ui ) + qt5_wrap_ui( uis ui/values_list.ui ui/mainwindow.ui ui/optionsdialog.ui ui/raw_image.ui ) - qt4_add_resources( qrc_sources values_list.qrc surface_mesher.qrc ) + qt5_add_resources( qrc_sources values_list.qrc surface_mesher.qrc ) add_executable ( ${prj} ${sources} ${uis} ${qrc_sources} ) + + qt5_use_modules(${prj} OpenGL Xml ) add_to_cached_list( CGAL_EXECUTABLE_TARGETS ${prj} ) @@ -98,13 +101,13 @@ if ( CGAL_FOUND AND CGAL_Qt4_FOUND) target_link_libraries( ${prj} ${QT_LIBRARIES} ${QGLVIEWER_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} ) - else( QGLVIEWER_FOUND) + else( QGLVIEWER_FOUND AND Qt5_FOUND) message(STATUS "NOTICE: This demo needs libQGLViewer, and will not be compiled.") - endif( QGLVIEWER_FOUND) -else(CGAL_FOUND AND CGAL_Qt4_FOUND) + endif( QGLVIEWER_FOUND AND Qt5_FOUND) +else(CGAL_FOUND AND CGAL_Qt5_FOUND AND CGAL_ImageIO_FOUND) if(RUNNING_CGAL_AUTO_TEST) # Just to avoid a warning from CMake if that variable is set on the command line... endif() - message(STATUS "NOTICE: This demo needs Qt4, and will not be compiled.") -endif(CGAL_FOUND AND CGAL_Qt4_FOUND) + message(STATUS "NOTICE: This demo needs Qt5, and will not be compiled.") +endif(CGAL_FOUND AND CGAL_Qt5_FOUND AND CGAL_ImageIO_FOUND) diff --git a/Surface_mesher/demo/Surface_mesher/Surface_mesher.cpp b/Surface_mesher/demo/Surface_mesher/Surface_mesher.cpp index eae66cac600..ab73dab89c4 100644 --- a/Surface_mesher/demo/Surface_mesher/Surface_mesher.cpp +++ b/Surface_mesher/demo/Surface_mesher/Surface_mesher.cpp @@ -8,7 +8,7 @@ int main(int argc, char** argv) application.setOrganizationDomain("geometryfactory.com"); application.setOrganizationName("GeometryFactory"); - application.setApplicationName("Surface mesher Qt4 demo"); + application.setApplicationName("Surface mesher Qt5 demo"); MainWindow w; diff --git a/Surface_mesher/demo/Surface_mesher/VTK/mesh_a_3D_image.cpp b/Surface_mesher/demo/Surface_mesher/VTK/mesh_a_3D_image.cpp index a81bf50809b..8ad8caad397 100644 --- a/Surface_mesher/demo/Surface_mesher/VTK/mesh_a_3D_image.cpp +++ b/Surface_mesher/demo/Surface_mesher/VTK/mesh_a_3D_image.cpp @@ -82,10 +82,6 @@ int main(int argc, char** argv) { QVTKWidget widget; widget.resize(256,256); - -#if QT_VERSION < 0x040000 - app.setMainWidget(&widget); -#endif // vtkImageData* vtk_image = CGAL::vtk_image_sharing_same_data_pointer(image); diff --git a/Surface_mesher/demo/Surface_mesher/colorlisteditor.cpp b/Surface_mesher/demo/Surface_mesher/colorlisteditor.cpp index 94b71051c79..4191b731c23 100644 --- a/Surface_mesher/demo/Surface_mesher/colorlisteditor.cpp +++ b/Surface_mesher/demo/Surface_mesher/colorlisteditor.cpp @@ -45,7 +45,7 @@ ColorListEditor::ColorListEditor(QWidget *widget) : QComboBox(widget) QColor ColorListEditor::color() const { - return qVariantValue(itemData(currentIndex(), Qt::DecorationRole)); + return itemData(currentIndex(), Qt::DecorationRole).value(); } void ColorListEditor::setColor(QColor color) diff --git a/Surface_mesher/demo/Surface_mesher/mainwindow.cpp b/Surface_mesher/demo/Surface_mesher/mainwindow.cpp index feb90c8b8b7..dfa63fb4be6 100644 --- a/Surface_mesher/demo/Surface_mesher/mainwindow.cpp +++ b/Surface_mesher/demo/Surface_mesher/mainwindow.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include @@ -153,4 +154,4 @@ void MainWindow::on_action_Clone_triggered() other->show(); } -#include "mainwindow.moc" +#include "mainwindow.moc" \ No newline at end of file diff --git a/Surface_mesher/demo/Surface_mesher/surface.h b/Surface_mesher/demo/Surface_mesher/surface.h index 76469f4247c..bc414e70084 100644 --- a/Surface_mesher/demo/Surface_mesher/surface.h +++ b/Surface_mesher/demo/Surface_mesher/surface.h @@ -13,7 +13,8 @@ class Surface : public QObject protected: Surface(QObject* parent) { - viewer = qFindChild(parent, "viewer"); + viewer = parent->findChild("viewer"); + if(viewer) connect(this, SIGNAL(changed()), viewer, SLOT(updateGL())); viewer->set_surface(this); diff --git a/Surface_mesher/demo/Surface_mesher/ui/optionsdialog.ui b/Surface_mesher/demo/Surface_mesher/ui/optionsdialog.ui index 715c83c0d43..2ea13d120e1 100644 --- a/Surface_mesher/demo/Surface_mesher/ui/optionsdialog.ui +++ b/Surface_mesher/demo/Surface_mesher/ui/optionsdialog.ui @@ -13,7 +13,7 @@ Set options
- :/icons/cgal_logo.xpm + :/icons/cgal_logo.xpm @@ -89,7 +89,7 @@
- + diff --git a/Surface_mesher/demo/Surface_mesher/values_list.cpp b/Surface_mesher/demo/Surface_mesher/values_list.cpp index d32855a9147..0a058de18cd 100644 --- a/Surface_mesher/demo/Surface_mesher/values_list.cpp +++ b/Surface_mesher/demo/Surface_mesher/values_list.cpp @@ -106,7 +106,9 @@ Values_list::Values_list(QWidget* parent): Q_ASSERT_X(treeWidget, "Values_list constructor", "cannot find widget \"treeWidget\""); treeWidget->sortByColumn(Value, Qt::AscendingOrder); - treeWidget->header()->setClickable(false); + + treeWidget->header()->setSectionsClickable(false); + Values_delegate* values_delegate = new Values_delegate(parent); diff --git a/Surface_mesher/demo/Surface_mesher/volume.cpp b/Surface_mesher/demo/Surface_mesher/volume.cpp index 8a795409699..335e4135788 100644 --- a/Surface_mesher/demo/Surface_mesher/volume.cpp +++ b/Surface_mesher/demo/Surface_mesher/volume.cpp @@ -622,8 +622,10 @@ void Volume::export_off() { QFileDialog filedialog(mw, tr("Export surface to file")); filedialog.setFileMode(QFileDialog::AnyFile); - filedialog.setFilter(tr("OFF files (*.off);;" - "All files (*)")); + + filedialog.setNameFilter(tr("OFF files (*.off);;" + "All files (*)")); + filedialog.setAcceptMode(QFileDialog::AcceptSave); filedialog.setDefaultSuffix("off"); if(filedialog.exec()) @@ -651,8 +653,11 @@ void Volume::save_image_to_inr() { QFileDialog filedialog(mw, tr("Export image to Inrimage format")); filedialog.setFileMode(QFileDialog::AnyFile); - filedialog.setFilter(tr("Inrimage files (*.inr);;" - "Compressed Inrimage files (*.inr.gz)")); + + filedialog.setNameFilter(tr("Inrimage files (*.inr);;" + "Compressed Inrimage files (*.inr.gz)")); + + filedialog.setAcceptMode(QFileDialog::AcceptSave); filedialog.setDefaultSuffix("inr.gz"); if(filedialog.exec()) diff --git a/Surface_mesher/examples/Surface_mesher/CMakeLists.txt b/Surface_mesher/examples/Surface_mesher/CMakeLists.txt index ea0a7f36771..36413fc32e0 100644 --- a/Surface_mesher/examples/Surface_mesher/CMakeLists.txt +++ b/Surface_mesher/examples/Surface_mesher/CMakeLists.txt @@ -3,12 +3,8 @@ project( Surface_mesher_example ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) -endif() +cmake_minimum_required(VERSION 2.8.11) + include_directories(../../include) diff --git a/Surface_modeling/benchmark/Surface_modeling/optimal_rotation/CMakeLists.txt b/Surface_modeling/benchmark/Surface_modeling/optimal_rotation/CMakeLists.txt index 9dc44ebbe04..619a3b5eea0 100644 --- a/Surface_modeling/benchmark/Surface_modeling/optimal_rotation/CMakeLists.txt +++ b/Surface_modeling/benchmark/Surface_modeling/optimal_rotation/CMakeLists.txt @@ -1,13 +1,7 @@ project( benchmark_for_closest_rotation ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 2.6) - if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) - else() - cmake_policy(VERSION 2.6) - endif() -endif() +cmake_minimum_required(VERSION 2.8.11) + find_package(CGAL QUIET COMPONENTS Core ) diff --git a/Surface_modeling/demo/Surface_modeling/CMakeLists.txt b/Surface_modeling/demo/Surface_modeling/CMakeLists.txt index d7748ff981e..8ba25e2e5c4 100644 --- a/Surface_modeling/demo/Surface_modeling/CMakeLists.txt +++ b/Surface_modeling/demo/Surface_modeling/CMakeLists.txt @@ -4,13 +4,9 @@ project( Surface_modeling_demo ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 2.6) - if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) - else() - cmake_policy(VERSION 2.6) - endif() +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() find_package(CGAL QUIET COMPONENTS Core ) diff --git a/Surface_modeling/examples/Surface_modeling/CMakeLists.txt b/Surface_modeling/examples/Surface_modeling/CMakeLists.txt index 66a5f51114a..6a691dd6259 100644 --- a/Surface_modeling/examples/Surface_modeling/CMakeLists.txt +++ b/Surface_modeling/examples/Surface_modeling/CMakeLists.txt @@ -4,14 +4,8 @@ project( Surface_modeling_ ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 2.6) - if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) - else() - cmake_policy(VERSION 2.6) - endif() -endif() +cmake_minimum_required(VERSION 2.8.11) + find_package(CGAL QUIET COMPONENTS Core ) diff --git a/Surface_modeling/test/Surface_modeling/CMakeLists.txt b/Surface_modeling/test/Surface_modeling/CMakeLists.txt index 62e19c4a735..b2dc1944da5 100644 --- a/Surface_modeling/test/Surface_modeling/CMakeLists.txt +++ b/Surface_modeling/test/Surface_modeling/CMakeLists.txt @@ -4,14 +4,8 @@ project( Surface_modeling_test ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 2.6) - if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) - else() - cmake_policy(VERSION 2.6) - endif() -endif() +cmake_minimum_required(VERSION 2.8.11) + find_package(CGAL QUIET COMPONENTS Core ) diff --git a/Surface_reconstruction_points_3/examples/Surface_reconstruction_points_3/CMakeLists.txt b/Surface_reconstruction_points_3/examples/Surface_reconstruction_points_3/CMakeLists.txt index a633ce8b4b8..1e604b13c97 100644 --- a/Surface_reconstruction_points_3/examples/Surface_reconstruction_points_3/CMakeLists.txt +++ b/Surface_reconstruction_points_3/examples/Surface_reconstruction_points_3/CMakeLists.txt @@ -2,12 +2,8 @@ project( Surface_reconstruction_points_3_example ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) -endif() +cmake_minimum_required(VERSION 2.8.11) + # Require packages new or improved since CGAL 3.5 beta 1 include_directories (BEFORE ../../../Installation/include) diff --git a/Surface_reconstruction_points_3/test/Surface_reconstruction_points_3/CMakeLists.txt b/Surface_reconstruction_points_3/test/Surface_reconstruction_points_3/CMakeLists.txt index a316ddce626..7b010918717 100644 --- a/Surface_reconstruction_points_3/test/Surface_reconstruction_points_3/CMakeLists.txt +++ b/Surface_reconstruction_points_3/test/Surface_reconstruction_points_3/CMakeLists.txt @@ -2,12 +2,8 @@ project( Surface_reconstruction_points_3_test ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) -endif() +cmake_minimum_required(VERSION 2.8.11) + # Require packages new or improved since CGAL 3.5 beta 1 include_directories (BEFORE ../../../Installation/include/) diff --git a/Triangulation/benchmark/Triangulation/CMakeLists.txt b/Triangulation/benchmark/Triangulation/CMakeLists.txt index 187e084ef51..9529aed0791 100644 --- a/Triangulation/benchmark/Triangulation/CMakeLists.txt +++ b/Triangulation/benchmark/Triangulation/CMakeLists.txt @@ -4,14 +4,8 @@ project( Triangulation_benchmark ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 2.6) - if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) - else() - cmake_policy(VERSION 2.6) - endif() -endif() +cmake_minimum_required(VERSION 2.8.11) + find_package(CGAL QUIET COMPONENTS Core ) diff --git a/Triangulation/examples/Triangulation/CMakeLists.txt b/Triangulation/examples/Triangulation/CMakeLists.txt index d8c08e4e624..a11f3ea2687 100644 --- a/Triangulation/examples/Triangulation/CMakeLists.txt +++ b/Triangulation/examples/Triangulation/CMakeLists.txt @@ -4,14 +4,8 @@ project( Triangulation_example ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 2.6) - if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) - else() - cmake_policy(VERSION 2.6) - endif() -endif() +cmake_minimum_required(VERSION 2.8.11) + find_package(CGAL QUIET COMPONENTS Core ) diff --git a/Triangulation/test/Triangulation/CMakeLists.txt b/Triangulation/test/Triangulation/CMakeLists.txt index 89abb618ce7..0e38ed3a80a 100644 --- a/Triangulation/test/Triangulation/CMakeLists.txt +++ b/Triangulation/test/Triangulation/CMakeLists.txt @@ -4,14 +4,8 @@ project( Triangulation_test ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 2.6) - if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) - else() - cmake_policy(VERSION 2.6) - endif() -endif() +cmake_minimum_required(VERSION 2.8.11) + find_package(CGAL QUIET COMPONENTS Core ) diff --git a/Triangulation_2/demo/Triangulation_2/README_for_developers.txt b/Triangulation_2/demo/Triangulation_2/README_for_developers.txt index 4aab67ff6d2..539f142b0bb 100644 --- a/Triangulation_2/demo/Triangulation_2/README_for_developers.txt +++ b/Triangulation_2/demo/Triangulation_2/README_for_developers.txt @@ -1,5 +1,5 @@ The demos for Triangulation_2 were written using Qt3, which is deprecated for a long time. They have been moved in the qt3/ sub-directory. -New demos using Qt4 has been written. You can found them in +New demos using Qt5 has been written. You can found them in ../../../GraphicsView/demo/Triangulation_2 diff --git a/Triangulation_2/demo/Triangulation_2/qt3/CMakeLists.txt b/Triangulation_2/demo/Triangulation_2/qt3/CMakeLists.txt index ad3f11a8078..3d1ea66e663 100644 --- a/Triangulation_2/demo/Triangulation_2/qt3/CMakeLists.txt +++ b/Triangulation_2/demo/Triangulation_2/qt3/CMakeLists.txt @@ -16,7 +16,7 @@ if ( CGAL_FOUND ) find_package(Qt3-patched QUIET ) # FindQt3-patched.cmake is FindQt3.cmake patched by CGAL developers, so - # that it can be used together with FindQt4: all its variables are prefixed + # that it can be used together with Qt5: all its variables are prefixed # by "QT3_" instead of "QT_". if(CGAL_Qt3_FOUND AND QT3_FOUND) diff --git a/Triangulation_3/demo/Triangulation_3/CMakeLists.txt b/Triangulation_3/demo/Triangulation_3/CMakeLists.txt index 6453ee641b1..27928a808fc 100644 --- a/Triangulation_3/demo/Triangulation_3/CMakeLists.txt +++ b/Triangulation_3/demo/Triangulation_3/CMakeLists.txt @@ -3,30 +3,28 @@ project (Triangulation_demo_3) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +# Find includes in corresponding build directories +set(CMAKE_INCLUDE_CURRENT_DIR ON) +# Instruct CMake to run moc automatically when needed. +set(CMAKE_AUTOMOC ON) + +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() -find_package(CGAL COMPONENTS Qt4) +find_package(CGAL COMPONENTS Qt5) include(${CGAL_USE_FILE}) -set( QT_USE_QTXML TRUE ) -set( QT_USE_QTMAIN TRUE ) -set( QT_USE_QTSCRIPT TRUE ) -set( QT_USE_QTOPENGL TRUE ) -find_package(Qt4) +find_package(Qt5 QUIET COMPONENTS Xml Script OpenGL) find_package(OpenGL) -if(QT4_FOUND) +if(Qt5_FOUND) add_definitions(-DQT_NO_KEYWORDS) - include( ${QT_USE_FILE} ) find_package(QGLViewer) -endif(QT4_FOUND) +endif(Qt5_FOUND) # Activate concurrency ? (turned OFF by default) option(ACTIVATE_CONCURRENT_TRIANGULATION_3 @@ -50,21 +48,16 @@ if( TBB_FOUND ) include(${TBB_USE_FILE}) endif() -if ( CGAL_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND ) - - include(${QT_USE_FILE}) +if ( CGAL_FOUND AND Qt5_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND ) include_directories (${QGLVIEWER_INCLUDE_DIR}) include_directories (BEFORE ../../include ./ ) # ui files, created with Qt Designer - qt4_wrap_ui( uis MainWindow.ui ) + qt5_wrap_ui( uis MainWindow.ui ) # qrc files (resources files, that contain icons, at least) - qt4_add_resources ( RESOURCE_FILES ./T3_demo.qrc ) - - # moc files (meta object compiler files, run moc preprocessor on the files with Widget defs) - qt4_automoc( MainWindow.cpp Viewer.cpp PreferenceDlg.cpp ) + qt5_add_resources ( RESOURCE_FILES ./T3_demo.qrc ) # cpp files @@ -73,22 +66,23 @@ if ( CGAL_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND ) PreferenceDlg.cpp Scene.cpp ${uis} ${RESOURCE_FILES} ) + qt5_use_modules(T3_demo Xml Script OpenGL) add_to_cached_list( CGAL_EXECUTABLE_TARGETS T3_demo ) target_link_libraries( T3_demo ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES}) target_link_libraries( T3_demo ${QT_LIBRARIES} ${QGLVIEWER_LIBRARIES} ${TBB_LIBRARIES}) target_link_libraries( T3_demo ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} ) -else( CGAL_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND ) +else( CGAL_FOUND AND Qt5_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND ) set(TRIANGULATION_3_MISSING_DEPS "") if(NOT CGAL_FOUND) - set(TRIANGULATION_3_MISSING_DEPS "the CGAL Qt4 library, ${TRIANGULATION_3_MISSING_DEPS}") + set(TRIANGULATION_3_MISSING_DEPS "the CGAL Qt5 library, ${TRIANGULATION_3_MISSING_DEPS}") endif() - if(NOT QT4_FOUND) - set(TRIANGULATION_3_MISSING_DEPS "Qt4, ${TRIANGULATION_3_MISSING_DEPS}") + if(NOT Qt5_FOUND) + set(TRIANGULATION_3_MISSING_DEPS "Qt5, ${TRIANGULATION_3_MISSING_DEPS}") endif() if(NOT OPENGL_FOUND) @@ -102,4 +96,4 @@ else( CGAL_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND ) message(STATUS "NOTICE: This demo requires ${TRIANGULATION_3_MISSING_DEPS}and will not be compiled.") -endif( CGAL_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND ) +endif( CGAL_FOUND AND Qt5_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND ) diff --git a/Triangulation_3/demo/Triangulation_3/MainWindow.cpp b/Triangulation_3/demo/Triangulation_3/MainWindow.cpp index f1bd753605b..54f47ad2c9c 100644 --- a/Triangulation_3/demo/Triangulation_3/MainWindow.cpp +++ b/Triangulation_3/demo/Triangulation_3/MainWindow.cpp @@ -7,7 +7,7 @@ MainWindow::MainWindow(QWidget* parent) : CGAL::Qt::DemosMainWindow(parent) { // Qt Automatic Connections - // http://doc.trolltech.com/4.4/designer-using-a-component.html#automatic-connections + // http://doc.qt.io/qt-5/designer-using-a-ui-file.html#automatic-connections // setupUi(this) automatically generates connections to the slots named // "on__" setupUi(this); @@ -125,7 +125,7 @@ void MainWindow::on_actionLoad_Points_triggered() viewer->clear(); // parse fileName to get the file type - std::string fname = fileName.toAscii().data(); + std::string fname = fileName.toLatin1().data(); std::string ftype = fname.substr( fname.find_last_of('.')+1 ); if ( ftype.compare("off")==0 || ftype.compare("OFF")==0 ) { // read from OFF file @@ -158,7 +158,7 @@ void MainWindow::on_actionSave_Points_triggered() if( fileName.isEmpty() ) return; // parse fileName to get the file type - std::string fname = fileName.toAscii().data(); + std::string fname = fileName.toLatin1().data();//toAscii() std::string ftype = fname.substr( fname.find_last_of('.')+1 ); if ( ftype.compare("off")==0 || ftype.compare("OFF")==0 ) { // save to OFF file @@ -173,13 +173,15 @@ void MainWindow::on_actionSave_Points_triggered() void MainWindow::on_actionGenerate_Points_triggered() { bool isOk; - int nPoints = QInputDialog::getInteger(this, - "3D Triangulation demo", "Number of points: ", // caption and label - 100, // default value - 4, // min value - 2147483647, // max value - 1, // step value of arrow button - &isOk); // if OK is pressed + + int nPoints = QInputDialog::getInt(this, + "3D Triangulation demo", "Number of points: ", // caption and label + 100, // default value + 4, // min value + 2147483647, // max value + 1, // step value of arrow button + &isOk); // if OK is pressed + if ( isOk) { // erase old data @@ -192,6 +194,9 @@ void MainWindow::on_actionGenerate_Points_triggered() // update viewer Q_EMIT( sceneChanged() ); + viewer->changed(); + + }// if(isOk) } diff --git a/Triangulation_3/demo/Triangulation_3/PreferenceDlg.h b/Triangulation_3/demo/Triangulation_3/PreferenceDlg.h index 7dad4ad205b..8751a9883bb 100644 --- a/Triangulation_3/demo/Triangulation_3/PreferenceDlg.h +++ b/Triangulation_3/demo/Triangulation_3/PreferenceDlg.h @@ -2,6 +2,20 @@ #define PREFERENCE_DLG_H #include +#include + +#include +#include + +#include +#include + +#include + +#include + +#include + class QLabel; class QSpinBox; diff --git a/Triangulation_3/demo/Triangulation_3/T3_demo.cpp b/Triangulation_3/demo/Triangulation_3/T3_demo.cpp index 75c2aadc4a9..e321286cfab 100644 --- a/Triangulation_3/demo/Triangulation_3/T3_demo.cpp +++ b/Triangulation_3/demo/Triangulation_3/T3_demo.cpp @@ -30,6 +30,8 @@ int main(int argc, char** argv) app.setOrganizationDomain("inria.fr"); app.setOrganizationName("INRIA"); app.setApplicationName("3D Triangulation Demo"); + //for windows + app.setAttribute(Qt::AA_UseDesktopOpenGL); MainWindow mw; mw.show(); diff --git a/Triangulation_3/demo/Triangulation_3/Viewer.cpp b/Triangulation_3/demo/Triangulation_3/Viewer.cpp index ef6a38e4b6a..5905714d9e2 100644 --- a/Triangulation_3/demo/Triangulation_3/Viewer.cpp +++ b/Triangulation_3/demo/Triangulation_3/Viewer.cpp @@ -1,13 +1,14 @@ #include +#include #if defined(BOOST_MSVC) - // Avoid warning concerning spatial_sort(QList::begin(), QList.end() QT "bug" +// Avoid warning concerning spatial_sort(QList::begin(), QList.end() QT "bug" # pragma warning(disable: 4267 ) # pragma warning(disable: 4244 ) #endif #include "Viewer.h" -#include + @@ -17,193 +18,1606 @@ using namespace std; void Viewer::init() { - /* Initial timer for playing incremental construction */ - m_pTimer = new QTimer(this); - connect(m_pTimer, SIGNAL(timeout()), this, SLOT(incremental_insert())); + initializeOpenGLFunctions(); + /* Initial timer for playing incremental construction */ + m_pTimer = new QTimer(this); + connect(m_pTimer, SIGNAL(timeout()), this, SLOT(incremental_insert())); - /* Scene inits */ - setBackgroundColor(::Qt::white); - // scene are defined by a sphere of 2.0, camera at the center, i.e. (0, 0, 0) - setSceneCenter( qglviewer::Vec(-0.,-0.,-0.) ); - setSceneRadius( 2. ); - // show text message - setTextIsEnabled(true); - setForegroundColor(::Qt::red); - setFont(QFont("Arial Black", 16, QFont::Bold)); + /* Scene inits */ + setBackgroundColor(::Qt::white); + // scene are defined by a sphere of 2.0, camera at the center, i.e. (0, 0, 0) + setSceneCenter( qglviewer::Vec(-0.,-0.,-0.) ); + setSceneRadius( 2. ); + // show text message + setTextIsEnabled(true); + setForegroundColor(::Qt::red); + setFont(QFont("Arial Black", 16, QFont::Bold)); - /* OpenGL inits */ - // Increase the material shininess, so that the difference between - // the two versions of the spiral is more visible. - glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 50.0); - GLfloat specular_color[4] = { 0.8f, 0.8f, 0.8f, 1.0 }; - glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular_color); - // Set Smooth Shading - ::glShadeModel(GL_SMOOTH); + /* OpenGL inits */ + // Increase the material shininess, so that the difference between + // the two versions of the spiral is more visible. + glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 50.0); + GLfloat specular_color[4] = { 0.8f, 0.8f, 0.8f, 1.0 }; + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular_color); + // Set Smooth Shading + ::glShadeModel(GL_SMOOTH); - // depth buffer setup - ::glClearDepth(1.0f); - ::glEnable(GL_DEPTH_TEST); - ::glDepthFunc(GL_LEQUAL); - ::glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); + // depth buffer setup + ::glClearDepth(1.0f); + ::glEnable(GL_DEPTH_TEST); + ::glDepthFunc(GL_LEQUAL); + ::glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); - // enable semi-transparent culling planes - ::glEnable(GL_BLEND); - ::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + // enable semi-transparent culling planes + ::glEnable(GL_BLEND); + ::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - // anti-aliasing, i.e. reduce jaggedness (if the OpenGL driver permits that) - ::glEnable(GL_POINT_SMOOTH); - ::glHint(GL_POINT_SMOOTH_HINT, GL_NICEST); - ::glEnable(GL_LINE_SMOOTH); - ::glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); + // anti-aliasing, i.e. reduce jaggedness (if the OpenGL driver permits that) + ::glEnable(GL_POINT_SMOOTH); + ::glHint(GL_POINT_SMOOTH_HINT, GL_NICEST); + ::glEnable(GL_LINE_SMOOTH); + ::glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); - /* Add mouse and key description */ - setKeyDescription( Qt::CTRL + Qt::Key_G, tr("Generate points") ); - setKeyDescription( Qt::CTRL + Qt::Key_O, tr("Load points") ); - setKeyDescription( Qt::CTRL + Qt::Key_S, tr("Save points") ); - setKeyDescription( Qt::CTRL + Qt::Key_Comma, tr("Preference") ); - setKeyDescription( Qt::CTRL + Qt::Key_H, tr("Hide Kernel Demo") ); - setKeyDescription( Qt::CTRL + Qt::Key_Q, tr("Quit Kernel Demo") ); - setKeyDescription( Qt::Key_Return, - tr("Insert new point to triangulation in Input-Point mode") ); - setKeyDescription( Qt::Key_Escape, - tr("Cancel insertion in Input-Point mode;
") - + tr("Cancel current selection in Select mode") ); - setKeyDescription( Qt::Key_Delete, tr("Delete selected vertices in Select mode") ); + /* Add mouse and key description */ + setKeyDescription( Qt::CTRL + Qt::Key_G, tr("Generate points") ); + setKeyDescription( Qt::CTRL + Qt::Key_O, tr("Load points") ); + setKeyDescription( Qt::CTRL + Qt::Key_S, tr("Save points") ); + setKeyDescription( Qt::CTRL + Qt::Key_Comma, tr("Preference") ); + setKeyDescription( Qt::CTRL + Qt::Key_H, tr("Hide Kernel Demo") ); + setKeyDescription( Qt::CTRL + Qt::Key_Q, tr("Quit Kernel Demo") ); + setKeyDescription( Qt::Key_Return, + tr("Insert new point to triangulation in Input-Point mode") ); + setKeyDescription( Qt::Key_Escape, + tr("Cancel insertion in Input-Point mode;
") + + tr("Cancel current selection in Select mode") ); + setKeyDescription( Qt::Key_Delete, tr("Delete selected vertices in Select mode") ); #if QGLVIEWER_VERSION >= 0x020500 - setMouseBindingDescription(Qt::NoModifier, Qt::LeftButton, - tr("Hold to move new point in Input-Point mode;
") - + tr("Hold to move a vertex in Move mode") ); - setMouseBindingDescription(Qt::ShiftModifier, Qt::LeftButton, - tr("Click to insert a vertex in Input-Vertex mode;
") - + tr("Click to insert a point in Input-Point mode;
") - + tr("Click or Drag to select multiple points in Select mode;
") - + tr("Click to place a query point in Find-Nearest-Neighbor mode;
") - + tr("Click to place a query point in Show-Empty-Sphere mode") ); - setMouseBindingDescription(Qt::ControlModifier, Qt::LeftButton, - tr("Drag to add vertices to current selection in Select mode") ); + setMouseBindingDescription(Qt::NoModifier, Qt::LeftButton, + tr("Hold to move new point in Input-Point mode;
") + + tr("Hold to move a vertex in Move mode") ); + setMouseBindingDescription(Qt::ShiftModifier, Qt::LeftButton, + tr("Click to insert a vertex in Input-Vertex mode;
") + + tr("Click to insert a point in Input-Point mode;
") + + tr("Click or Drag to select multiple points in Select mode;
") + + tr("Click to place a query point in Find-Nearest-Neighbor mode;
") + + tr("Click to place a query point in Show-Empty-Sphere mode") ); + setMouseBindingDescription(Qt::ControlModifier, Qt::LeftButton, + tr("Drag to add vertices to current selection in Select mode") ); #else - setMouseBindingDescription( Qt::LeftButton, - tr("Hold to move new point in Input-Point mode;
") - + tr("Hold to move a vertex in Move mode") ); - setMouseBindingDescription( Qt::SHIFT + Qt::LeftButton, - tr("Click to insert a vertex in Input-Vertex mode;
") - + tr("Click to insert a point in Input-Point mode;
") - + tr("Click or Drag to select multiple points in Select mode;
") - + tr("Click to place a query point in Find-Nearest-Neighbor mode;
") - + tr("Click to place a query point in Show-Empty-Sphere mode") ); - setMouseBindingDescription( Qt::CTRL + Qt::LeftButton, - tr("Drag to add vertices to current selection in Select mode") ); + setMouseBindingDescription( Qt::LeftButton, + tr("Hold to move new point in Input-Point mode;
") + + tr("Hold to move a vertex in Move mode") ); + setMouseBindingDescription( Qt::SHIFT + Qt::LeftButton, + tr("Click to insert a vertex in Input-Vertex mode;
") + + tr("Click to insert a point in Input-Point mode;
") + + tr("Click or Drag to select multiple points in Select mode;
") + + tr("Click to place a query point in Find-Nearest-Neighbor mode;
") + + tr("Click to place a query point in Show-Empty-Sphere mode") ); + setMouseBindingDescription( Qt::CTRL + Qt::LeftButton, + tr("Drag to add vertices to current selection in Select mode") ); #endif + compile_shaders(); + are_buffers_initialized = false; } QString Viewer::helpString() const { - QString text("

3D Triangulation Demo

"); + QString text("

3D Triangulation Demo

"); - text += "This example illustrates a generic interactive demo for 3D Triangulation in CGAL. "; - text += "This demo could be used as a simple skeleton "; - text += "for potential demos of other 3D packages or for teaching CGAL.

"; + text += "This example illustrates a generic interactive demo for 3D Triangulation in CGAL. "; + text += "This demo could be used as a simple skeleton "; + text += "for potential demos of other 3D packages or for teaching CGAL.

"; - text += "The key feature is to edit vertices/points with mouse."; - text += "There are several modes:

"; + text += "The key feature is to edit vertices/points with mouse."; + text += "There are several modes:

"; - text += " - Normal Mode: "; - text += "Rotate, zoom, or translate camera using mouse.
"; - text += " - Insert Vertex: "; - text += "Insert a vertex on the surface of the trackball "; - text += "and the triangulation will be updated correspondingly.
"; - text += " - Insert Point: "; - text += "Insert a point on the surface of the trackball. "; - text += "Its conflict region will be highlighted. "; - text += "When the new point is moving, "; - text += "its conflict region will be updated correspondingly.
"; - text += " - Select: "; - text += "Click or drag mouse left button to select multiple points.
"; - text += " - Move: Hold mouse left button to move a vertex "; - text += "and the triangulation will be updated correspondingly.
"; - text += " - Find Nearest Neighbor: "; - text += "Place a query point and its nearest neighbor will be highlighted.
"; - text += " - Show Empty Sphere: "; - text += "Place a query point, locate the point in a cell "; - text += "and then show the empty sphere of that cell. "; - text += "An empty sphere of a cell is a sphere "; - text += "with all four vertices of the cell lying on it "; - text += "and no other vertices inside it.

"; - text += "Shift+Wheel to resize the trackball when it exists. "; - text += "See Mouse page for more details.

"; + text += " - Normal Mode: "; + text += "Rotate, zoom, or translate camera using mouse.
"; + text += " - Insert Vertex: "; + text += "Insert a vertex on the surface of the trackball "; + text += "and the triangulation will be updated correspondingly.
"; + text += " - Insert Point: "; + text += "Insert a point on the surface of the trackball. "; + text += "Its conflict region will be highlighted. "; + text += "When the new point is moving, "; + text += "its conflict region will be updated correspondingly.
"; + text += " - Select: "; + text += "Click or drag mouse left button to select multiple points.
"; + text += " - Move: Hold mouse left button to move a vertex "; + text += "and the triangulation will be updated correspondingly.
"; + text += " - Find Nearest Neighbor: "; + text += "Place a query point and its nearest neighbor will be highlighted.
"; + text += " - Show Empty Sphere: "; + text += "Place a query point, locate the point in a cell "; + text += "and then show the empty sphere of that cell. "; + text += "An empty sphere of a cell is a sphere "; + text += "with all four vertices of the cell lying on it "; + text += "and no other vertices inside it.

"; + text += "Shift+Wheel to resize the trackball when it exists. "; + text += "See Mouse page for more details.

"; - text += "Other basic features include:
"; - text += " - Randomly generate points,
"; - text += " - Read/Write files,
"; - text += " - Show vertices, Voronoi edges, Delaunay edges, and/or facets,
"; - text += " - Incremental Construct: "; - text += "Re-construct the current triangulation incrementally. "; - text += "If no triangulation exists yet, randomly generate 100 points "; - text += "and construct a Delaunay triangulation of those points.
"; + text += "Other basic features include:
"; + text += " - Randomly generate points,
"; + text += " - Read/Write files,
"; + text += " - Show vertices, Voronoi edges, Delaunay edges, and/or facets,
"; + text += " - Incremental Construct: "; + text += "Re-construct the current triangulation incrementally. "; + text += "If no triangulation exists yet, randomly generate 100 points "; + text += "and construct a Delaunay triangulation of those points.
"; - return text; + return text; } +/*************************************************************/ +/* Shaders functions */ + +void Viewer::compile_shaders() +{ + + for(int i=0; i< vboSize; i++) + buffers[i].create(); + for(int i=0; i< vaoSize; i++) + vao[i].create(); + + draw_cylinder(m_fSizeDEdge,25,points_cylinder,normals_cylinder); + draw_sphere(m_fSizeVertex, 15, points_sphere, normals_sphere); + //Vertex source code + const char vertex_source[] = + { + "#version 330 \n" + "in highp vec4 vertex;\n" + "uniform highp mat4 mvp_matrix;\n" + "void main(void)\n" + "{\n" + " gl_Position = mvp_matrix * vertex; \n" + "}" + }; + //Fragment source code + const char fragment_source[] = + { + "#version 330 \n" + "uniform highp vec4 color; \n" + "void main(void) { \n" + "gl_FragColor = color; \n" + "} \n" + "\n" + }; + QOpenGLShader *vertex_shader = new QOpenGLShader(QOpenGLShader::Vertex); + if(!vertex_shader->compileSourceCode(vertex_source)) + { + std::cerr<<"Compiling vertex source FAILED"<compileSourceCode(fragment_source)) + { + std::cerr<<"Compiling fragmentsource FAILED"<compileSourceCode(vertex_source_spheres)) + { + std::cerr<<"Compiling vertex source FAILED"<compileSourceCode(fragment_source_spheres)) + { + std::cerr<<"Compiling fragmentsource FAILED"<compileSourceCode(vertex_source_cylinders)) + { + std::cerr<<"Compiling vertex source FAILED"<resize(0); + pos_delaunay->resize(0); + pos_voronoi->resize(0); + pos_facets->resize(0); + pos_newPoint->resize(0); + pos_newFacet->resize(0); + pos_selectedVertex->resize(0); + pos_movingPoint->resize(0); + pos_queryPoint->resize(0); + pos_nearest_neighbor->resize(0); + pos_emptyFacet->resize(0); + transfo1_delaunay->resize(0); + transfo2_delaunay->resize(0); + transfo3_delaunay->resize(0); + transfo4_delaunay->resize(0); + + pos_trackBall->resize(0); + draw_sphere(m_fRadius, 35,points_trackBall, normals_trackBall); + for(int i=0; i<3; i++) + pos_trackBall->push_back(0.0); + pos_emptySphere->resize(0); + // Draw vertices + if ( m_pScene->m_dt.number_of_vertices()>0 ) { + + for(QList::iterator vit = m_pScene->m_vhArray.begin(); + vit < m_pScene->m_vhArray.end(); ++vit) { + if( m_curMode == SELECT && (*vit)->isSeled() ) continue; + if( (*vit) == m_nearestNb ) continue; + drawVertex( (*vit)->point(), m_colorVertex, m_fSizeVertex, pos_points ); + }//end-for-points + }//end-if-points + //Draw Delaunay Edges + for(edges_iterator eit = m_pScene->m_dt.finite_edges_begin(); + eit != m_pScene->m_dt.finite_edges_end(); ++eit) { + Segment_3 seg = m_pScene->m_dt.segment(*eit); + drawEdge( seg.vertex(0), seg.vertex(1), m_colorDEdge, m_fSizeDEdge, pos_delaunay ); + + Vector_3 v = seg.vertex(1) - seg.vertex(0); + float length = sqrt( v.squared_length() ); + // normalize + v = v / length; + // compute the angle: cos theta = v.z/1.0 + GLfloat angle = acos( v.y() ) / M_PI * 180; + QMatrix4x4 matrix; + matrix.setToIdentity(); + // move to "from" point + matrix.translate( seg.vertex(0).x(), seg.vertex(0).y(), seg.vertex(0).z() ); + // rotate from z-axis to from-->to + // axis: cross product of z-axis and from-->to + matrix.rotate( angle, v.z(), 0.0f,-v.x()); + matrix.scale(1,length,1); + // stock the transformation + for(int i=0; i<4; i++) + transfo1_delaunay->push_back((float)matrix.data()[i]); + for(int i=4; i<8; i++) + transfo2_delaunay->push_back((float)matrix.data()[i]); + for(int i=8; i<12; i++) + transfo3_delaunay->push_back((float)matrix.data()[i]); + for(int i=12; i<16; i++) + transfo4_delaunay->push_back((float)matrix.data()[i]); + }//end-for-edges + // Draw Voronoi edges + for(facets_iterator fit = m_pScene->m_dt.finite_facets_begin(); + fit != m_pScene->m_dt.finite_facets_end(); ++fit) { + Object_3 o = m_pScene->m_dt.dual(*fit); + if (const Segment_3 *s = CGAL::object_cast(&o)) { + drawEdge( s->vertex(0), s->vertex(1), m_colorVEdge, m_fSizeVEdge, pos_voronoi ); + + Vector_3 v = s->vertex(1) - s->vertex(0); + float length = sqrt( v.squared_length() ); + // normalize + v = v / length; + // compute the angle: cos theta = v.z/1.0 + GLfloat angle = acos( v.y() ) / M_PI * 180; + QMatrix4x4 matrix; + matrix.setToIdentity(); + // move to "from" point + matrix.translate( s->vertex(0).x(), s->vertex(0).y(), s->vertex(0).z() ); + // rotate from z-axis to from-->to + // axis: cross product of z-axis and from-->to + matrix.rotate( angle, v.z(), 0.0f,-v.x()); + matrix.scale(1,length,1); + // stock the transformation + for(int i=0; i<4; i++) + transfo1_voronoi->push_back((float)matrix.data()[i]); + for(int i=4; i<8; i++) + transfo2_voronoi->push_back((float)matrix.data()[i]); + for(int i=8; i<12; i++) + transfo3_voronoi->push_back((float)matrix.data()[i]); + for(int i=12; i<16; i++) + transfo4_voronoi->push_back((float)matrix.data()[i]); + } else if (const Ray_3 *r = CGAL::object_cast(&o)) { + drawEdge( r->point(0), // the source of the ray + r->point(1), // another point on the ray, different from the source + m_colorVEdge, m_fSizeVEdge, pos_voronoi ); + Vector_3 v = r->point(1) - r->point(0); + float length = sqrt( v.squared_length() ); + // normalize + v = v / length; + // compute the angle: cos theta = v.z/1.0 + GLfloat angle = acos( v.y() ) / M_PI * 180; + QMatrix4x4 matrix; + matrix.setToIdentity(); + // move to "from" point + matrix.translate(r->point(0).x(), r->point(0).y(), r->point(0).z() ); + // rotate from z-axis to from-->to + // axis: cross product of z-axis and from-->to + matrix.rotate( angle, v.z(), 0.0f,-v.x()); + matrix.scale(1,length,1); + // stock the transformation + for(int i=0; i<4; i++) + transfo1_voronoi->push_back((float)matrix.data()[i]); + for(int i=4; i<8; i++) + transfo2_voronoi->push_back((float)matrix.data()[i]); + for(int i=8; i<12; i++) + transfo3_voronoi->push_back((float)matrix.data()[i]); + for(int i=12; i<16; i++) + transfo4_voronoi->push_back((float)matrix.data()[i]); + } + }//end-for-edges + // Draw facets + for(facets_iterator fit = m_pScene->m_dt.finite_facets_begin(); + fit != m_pScene->m_dt.finite_facets_end(); ++fit) { + drawFacet( m_pScene->m_dt.triangle(*fit), m_colorFacet, pos_facets); + }//end-for-facets + // Draw the newly inserted point + drawVertex( m_newPt, ::Qt::red, m_fSizeVertex, pos_newPoint); + // Draw conflict region + for(QList::iterator fit = m_boundaryFacets.begin(); + fit < m_boundaryFacets.end(); ++fit) { + if( m_pScene->m_dt.is_infinite(*fit) ) continue; + drawFacet( m_pScene->m_dt.triangle(*fit), QColor(215, 80, 0, 96) , pos_newFacet); //semi-transparent purple + }//end-for-facets + // Highlight the selected vertices + for(QList::iterator vit=m_vidSeled.begin(); vitm_vhArray.at(*vit)->point(), ::Qt::red, m_fSizeVertex, pos_selectedVertex ); + }//end-for-seledpts + if( m_isMoving ) { + // Highlight the moving point + drawVertex( m_pScene->m_vhArray.at( m_vidMoving )->point(), ::Qt::red, m_fSizeVertex, pos_movingPoint ); + }//end-if-v + // Draw the nearest neighbor + if( m_nearestNb != NULL ) { + drawVertex( m_queryPt, ::Qt::red, m_fSizeVertex, pos_queryPoint); + drawVertex( m_nearestNb->point(), ::Qt::red, m_fSizeVertex, pos_nearest_neighbor); + } + if( m_hasEmptyS ) { + // Draw the query point + drawVertex( m_queryPt, ::Qt::red, m_fSizeVertex, pos_queryPoint ); + // Draw the cell containing that point + for(int i=0; i<4; ++i) { + if( m_pScene->m_dt.is_infinite(m_cellContain, i) ) continue; + drawFacet( m_pScene->m_dt.triangle( m_cellContain, i ), m_colorFacet, pos_emptyFacet ); + }//end-for-facets + // Draw the sphere + pos_emptySphere->push_back(m_centerPt.x()); + pos_emptySphere->push_back(m_centerPt.y()); + pos_emptySphere->push_back(m_centerPt.z()); + draw_sphere(m_fREmptyS, 35, points_emptySphere, normals_emptySphere); + } + + + + // Draw all points during incremental mode + if( !m_incrementalPts.isEmpty() ) { + // draw the rest to-be-inserted vertices + for(QList::iterator pit=m_incrementalPts.begin(); + pit < m_incrementalPts.end(); ++pit) { + drawVertex( (*pit), ::Qt::gray, m_fSizeVertex, incremental_points); + } + + switch( m_curStep ) { + case NEWPT: + + // Highlight the next-to-insert point + drawVertex( m_curIncPt, ::Qt::red, m_fSizeVertex, incremental_next_point ); + break; + case CELL: // show the tetrahedron that contains the point + // Highlight the next-to-insert vertex + drawVertex( m_curIncPt, ::Qt::red, m_fSizeVertex, incremental_next_point ); + // Draw the cell containing that point + for(int i=0; i<4; ++i) { + if( m_pScene->m_dt.is_infinite(m_cellContain, i) ) continue; + drawFacet( m_pScene->m_dt.triangle( m_cellContain, i ), m_colorFacet, incremental_facet ); + }//end-for-facets + break; + case CONFLICT: // show the conflict region + // Highlight the next-to-insert vertex + drawVertex( m_curIncPt, ::Qt::red, m_fSizeVertex, incremental_next_point ); + // Draw conflict region + for(QList::iterator fit = m_boundaryFacets.begin(); + fit < m_boundaryFacets.end(); ++fit) { + if( m_pScene->m_dt.is_infinite(*fit) ) continue; + drawFacet( m_pScene->m_dt.triangle(*fit), QColor(215, 80, 0, 96), incremental_conflict ); //semi-transparent purple + }//end-for-facets + break; + default: + break; + }//end-of=switch + }//end-if-incpts + + + +} + +void Viewer::initialize_buffers() +{ + rendering_program.bind(); + { + //Points + vao[0].bind(); + buffers[0].bind(); + buffers[0].allocate(pos_points->data(), pos_points->size()*sizeof(float)); + poly_vertexLocation[0] = rendering_program.attributeLocation("vertex"); + rendering_program.enableAttributeArray(poly_vertexLocation[0]); + rendering_program.setAttributeBuffer(poly_vertexLocation[0],GL_FLOAT,0,3); + buffers[0].release(); + vao[0].release(); + //Delaunay Edges + vao[1].bind(); + buffers[1].bind(); + buffers[1].allocate(pos_delaunay->data(), pos_delaunay->size()*sizeof(float)); + poly_vertexLocation[0] = rendering_program.attributeLocation("vertex"); + rendering_program.enableAttributeArray(poly_vertexLocation[0]); + rendering_program.setAttributeBuffer(poly_vertexLocation[0],GL_FLOAT,0,3); + buffers[1].release(); + vao[1].release(); + + //Voronoi Edges + vao[2].bind(); + buffers[2].bind(); + buffers[2].allocate(pos_voronoi->data(), pos_voronoi->size()*sizeof(float)); + poly_vertexLocation[0] = rendering_program.attributeLocation("vertex"); + rendering_program.enableAttributeArray(poly_vertexLocation[0]); + rendering_program.setAttributeBuffer(poly_vertexLocation[0],GL_FLOAT,0,3); + buffers[2].release(); + vao[2].release(); + + //Facets + vao[3].bind(); + buffers[3].bind(); + buffers[3].allocate(pos_facets->data(), pos_facets->size()*sizeof(float)); + poly_vertexLocation[0] = rendering_program.attributeLocation("vertex"); + rendering_program.enableAttributeArray(poly_vertexLocation[0]); + rendering_program.setAttributeBuffer(poly_vertexLocation[0],GL_FLOAT,0,3); + buffers[3].release(); + vao[3].release(); + + //New point + vao[4].bind(); + buffers[4].bind(); + buffers[4].allocate(pos_newPoint->data(), pos_newPoint->size()*sizeof(float)); + poly_vertexLocation[0] = rendering_program.attributeLocation("vertex"); + rendering_program.enableAttributeArray(poly_vertexLocation[0]); + rendering_program.setAttributeBuffer(poly_vertexLocation[0],GL_FLOAT,0,3); + buffers[4].release(); + vao[4].release(); + //New Facet + vao[5].bind(); + buffers[5].bind(); + buffers[5].allocate(pos_newFacet->data(), pos_newFacet->size()*sizeof(float)); + poly_vertexLocation[0] = rendering_program.attributeLocation("vertex"); + rendering_program.enableAttributeArray(poly_vertexLocation[0]); + rendering_program.setAttributeBuffer(poly_vertexLocation[0],GL_FLOAT,0,3); + buffers[5].release(); + vao[5].release(); + + //Selected Point + vao[6].bind(); + buffers[6].bind(); + buffers[6].allocate(pos_selectedVertex->data(), pos_selectedVertex->size()*sizeof(float)); + poly_vertexLocation[0] = rendering_program.attributeLocation("vertex"); + rendering_program.enableAttributeArray(poly_vertexLocation[0]); + rendering_program.setAttributeBuffer(poly_vertexLocation[0],GL_FLOAT,0,3); + buffers[6].release(); + vao[6].release(); + + //Moving Point + vao[7].bind(); + buffers[7].bind(); + buffers[7].allocate(pos_movingPoint->data(), pos_movingPoint->size()*sizeof(float)); + poly_vertexLocation[0] = rendering_program.attributeLocation("vertex"); + rendering_program.enableAttributeArray(poly_vertexLocation[0]); + rendering_program.setAttributeBuffer(poly_vertexLocation[0],GL_FLOAT,0,3); + buffers[7].release(); + vao[7].release(); + + //Querry Point + vao[8].bind(); + buffers[8].bind(); + buffers[8].allocate(pos_queryPoint->data(), pos_queryPoint->size()*sizeof(float)); + poly_vertexLocation[0] = rendering_program.attributeLocation("vertex"); + rendering_program.enableAttributeArray(poly_vertexLocation[0]); + rendering_program.setAttributeBuffer(poly_vertexLocation[0],GL_FLOAT,0,3); + buffers[8].release(); + vao[8].release(); + + //Nearest Neighbor + vao[9].bind(); + buffers[9].bind(); + buffers[9].allocate(pos_nearest_neighbor->data(), pos_nearest_neighbor->size()*sizeof(float)); + poly_vertexLocation[0] = rendering_program.attributeLocation("vertex"); + rendering_program.enableAttributeArray(poly_vertexLocation[0]); + rendering_program.setAttributeBuffer(poly_vertexLocation[0],GL_FLOAT,0,3); + buffers[9].release(); + vao[9].release(); + + //Facet empty Sphere + vao[10].bind(); + buffers[10].bind(); + buffers[10].allocate(pos_emptyFacet->data(), pos_emptyFacet->size()*sizeof(float)); + poly_vertexLocation[0] = rendering_program.attributeLocation("vertex"); + rendering_program.enableAttributeArray(poly_vertexLocation[0]); + rendering_program.setAttributeBuffer(poly_vertexLocation[0],GL_FLOAT,0,3); + buffers[10].release(); + vao[10].release(); + + vao[21].bind(); + buffers[28].bind(); + buffers[28].allocate(incremental_next_point->data(), incremental_next_point->size()*sizeof(float)); + poly_vertexLocation[0] = rendering_program.attributeLocation("vertex"); + rendering_program.enableAttributeArray(poly_vertexLocation[0]); + rendering_program.setAttributeBuffer(poly_vertexLocation[0],GL_FLOAT,0,3); + buffers[28].release(); + vao[21].release(); + + vao[22].bind(); + buffers[29].bind(); + buffers[29].allocate(incremental_facet->data(), incremental_facet->size()*sizeof(float)); + poly_vertexLocation[0] = rendering_program.attributeLocation("vertex"); + rendering_program.enableAttributeArray(poly_vertexLocation[0]); + rendering_program.setAttributeBuffer(poly_vertexLocation[0],GL_FLOAT,0,3); + buffers[29].release(); + vao[22].release(); + + vao[23].bind(); + buffers[30].bind(); + buffers[30].allocate(incremental_conflict->data(), incremental_conflict->size()*sizeof(float)); + poly_vertexLocation[0] = rendering_program.attributeLocation("vertex"); + rendering_program.enableAttributeArray(poly_vertexLocation[0]); + rendering_program.setAttributeBuffer(poly_vertexLocation[0],GL_FLOAT,0,3); + buffers[30].release(); + vao[23].release(); + + vao[24].bind(); + buffers[31].bind(); + buffers[31].allocate(incremental_points->data(), incremental_points->size()*sizeof(float)); + poly_vertexLocation[0] = rendering_program.attributeLocation("vertex"); + rendering_program.enableAttributeArray(poly_vertexLocation[0]); + rendering_program.setAttributeBuffer(poly_vertexLocation[0],GL_FLOAT,0,3); + buffers[31].release(); + vao[24].release(); + } + + rendering_program.release(); + rendering_program_spheres.bind(); + { + //Track Ball + vao[11].bind(); + buffers[11].bind(); + buffers[11].allocate(pos_trackBall->data(), pos_trackBall->size()*sizeof(float)); + centerLocation[0] = rendering_program_spheres.attributeLocation("center"); + rendering_program_spheres.enableAttributeArray(centerLocation[0]); + rendering_program_spheres.setAttributeBuffer(centerLocation[0],GL_FLOAT,0,3); + buffers[11].release(); + + buffers[12].bind(); + buffers[12].allocate(normals_trackBall->data(), normals_trackBall->size()*sizeof(float)); + normalsLocation[0] = rendering_program_spheres.attributeLocation("normal"); + rendering_program_spheres.enableAttributeArray(normalsLocation[0]); + rendering_program_spheres.setAttributeBuffer(normalsLocation[0],GL_FLOAT,0,3); + buffers[12].release(); + + buffers[13].bind(); + buffers[13].allocate(points_trackBall->data(), points_trackBall->size()*sizeof(float)); + poly_vertexLocation[1] = rendering_program_spheres.attributeLocation("vertex"); + rendering_program_spheres.enableAttributeArray(poly_vertexLocation[1]); + rendering_program_spheres.setAttributeBuffer(poly_vertexLocation[1],GL_FLOAT,0,3); + buffers[13].release(); + + glVertexAttribDivisor(centerLocation[0],1); + glVertexAttribDivisor(normalsLocation[0],0); + vao[11].release(); + + //Empty Sphere + vao[12].bind(); + buffers[14].bind(); + buffers[14].allocate(pos_emptySphere->data(), pos_emptySphere->size()*sizeof(float)); + centerLocation[0] = rendering_program_spheres.attributeLocation("center"); + rendering_program_spheres.enableAttributeArray(centerLocation[0]); + rendering_program_spheres.setAttributeBuffer(centerLocation[0],GL_FLOAT,0,3); + buffers[14].release(); + + buffers[32].bind(); + buffers[32].allocate(normals_emptySphere->data(), normals_emptySphere->size()*sizeof(float)); + normalsLocation[0] = rendering_program_spheres.attributeLocation("normal"); + rendering_program_spheres.enableAttributeArray(normalsLocation[0]); + rendering_program_spheres.setAttributeBuffer(normalsLocation[0],GL_FLOAT,0,3); + buffers[32].release(); + + buffers[16].bind(); + buffers[16].allocate(points_emptySphere->data(), points_emptySphere->size()*sizeof(float)); + poly_vertexLocation[1] = rendering_program_spheres.attributeLocation("vertex"); + rendering_program_spheres.enableAttributeArray(poly_vertexLocation[1]); + rendering_program_spheres.setAttributeBuffer(poly_vertexLocation[1],GL_FLOAT,0,3); + buffers[16].release(); + + glVertexAttribDivisor(centerLocation[0],1); + glVertexAttribDivisor(normalsLocation[0],0); + vao[12].release(); + + //Vertex Sphere + vao[13].bind(); + buffers[0].bind(); + centerLocation[0] = rendering_program_spheres.attributeLocation("center"); + rendering_program_spheres.enableAttributeArray(centerLocation[0]); + rendering_program_spheres.setAttributeBuffer(centerLocation[0],GL_FLOAT,0,3); + buffers[0].release(); + + buffers[15].bind(); + buffers[15].allocate(normals_sphere->data(), normals_sphere->size()*sizeof(float)); + normalsLocation[0] = rendering_program_spheres.attributeLocation("normal"); + rendering_program_spheres.enableAttributeArray(normalsLocation[0]); + rendering_program_spheres.setAttributeBuffer(normalsLocation[0],GL_FLOAT,0,3); + buffers[15].release(); + + buffers[17].bind(); + buffers[17].allocate(points_sphere->data(), points_sphere->size()*sizeof(float)); + poly_vertexLocation[1] = rendering_program_spheres.attributeLocation("vertex"); + rendering_program_spheres.enableAttributeArray(poly_vertexLocation[1]); + rendering_program_spheres.setAttributeBuffer(poly_vertexLocation[1],GL_FLOAT,0,3); + buffers[17].release(); + + glVertexAttribDivisor(centerLocation[0],1); + glVertexAttribDivisor(normalsLocation[0],0); + vao[13].release(); + + //New point Sphere + vao[14].bind(); + buffers[4].bind(); + centerLocation[0] = rendering_program_spheres.attributeLocation("center"); + rendering_program_spheres.enableAttributeArray(centerLocation[0]); + rendering_program_spheres.setAttributeBuffer(centerLocation[0],GL_FLOAT,0,3); + buffers[4].release(); + + buffers[15].bind(); + normalsLocation[0] = rendering_program_spheres.attributeLocation("normal"); + rendering_program_spheres.enableAttributeArray(normalsLocation[0]); + rendering_program_spheres.setAttributeBuffer(normalsLocation[0],GL_FLOAT,0,3); + buffers[15].release(); + + buffers[17].bind(); + poly_vertexLocation[1] = rendering_program_spheres.attributeLocation("vertex"); + rendering_program_spheres.enableAttributeArray(poly_vertexLocation[1]); + rendering_program_spheres.setAttributeBuffer(poly_vertexLocation[1],GL_FLOAT,0,3); + buffers[17].release(); + + glVertexAttribDivisor(centerLocation[0],1); + glVertexAttribDivisor(normalsLocation[0],0); + vao[14].release(); + + //Selected point Sphere + vao[15].bind(); + buffers[6].bind(); + centerLocation[0] = rendering_program_spheres.attributeLocation("center"); + rendering_program_spheres.enableAttributeArray(centerLocation[0]); + rendering_program_spheres.setAttributeBuffer(centerLocation[0],GL_FLOAT,0,3); + buffers[6].release(); + + buffers[15].bind(); + normalsLocation[0] = rendering_program_spheres.attributeLocation("normal"); + rendering_program_spheres.enableAttributeArray(normalsLocation[0]); + rendering_program_spheres.setAttributeBuffer(normalsLocation[0],GL_FLOAT,0,3); + buffers[15].release(); + + buffers[17].bind(); + poly_vertexLocation[1] = rendering_program_spheres.attributeLocation("vertex"); + rendering_program_spheres.enableAttributeArray(poly_vertexLocation[1]); + rendering_program_spheres.setAttributeBuffer(poly_vertexLocation[1],GL_FLOAT,0,3); + buffers[17].release(); + + glVertexAttribDivisor(centerLocation[0],1); + glVertexAttribDivisor(normalsLocation[0],0); + vao[15].release(); + + //Moving point Sphere + vao[16].bind(); + buffers[7].bind(); + centerLocation[0] = rendering_program_spheres.attributeLocation("center"); + rendering_program_spheres.enableAttributeArray(centerLocation[0]); + rendering_program_spheres.setAttributeBuffer(centerLocation[0],GL_FLOAT,0,3); + buffers[7].release(); + + buffers[15].bind(); + normalsLocation[0] = rendering_program_spheres.attributeLocation("normal"); + rendering_program_spheres.enableAttributeArray(normalsLocation[0]); + rendering_program_spheres.setAttributeBuffer(normalsLocation[0],GL_FLOAT,0,3); + buffers[15].release(); + + buffers[17].bind(); + poly_vertexLocation[1] = rendering_program_spheres.attributeLocation("vertex"); + rendering_program_spheres.enableAttributeArray(poly_vertexLocation[1]); + rendering_program_spheres.setAttributeBuffer(poly_vertexLocation[1],GL_FLOAT,0,3); + buffers[17].release(); + + glVertexAttribDivisor(centerLocation[0],1); + glVertexAttribDivisor(normalsLocation[0],0); + vao[16].release(); + + //Querry point Sphere + vao[17].bind(); + buffers[8].bind(); + centerLocation[0] = rendering_program_spheres.attributeLocation("center"); + rendering_program_spheres.enableAttributeArray(centerLocation[0]); + rendering_program_spheres.setAttributeBuffer(centerLocation[0],GL_FLOAT,0,3); + buffers[8].release(); + + buffers[15].bind(); + normalsLocation[0] = rendering_program_spheres.attributeLocation("normal"); + rendering_program_spheres.enableAttributeArray(normalsLocation[0]); + rendering_program_spheres.setAttributeBuffer(normalsLocation[0],GL_FLOAT,0,3); + buffers[15].release(); + + buffers[17].bind(); + poly_vertexLocation[1] = rendering_program_spheres.attributeLocation("vertex"); + rendering_program_spheres.enableAttributeArray(poly_vertexLocation[1]); + rendering_program_spheres.setAttributeBuffer(poly_vertexLocation[1],GL_FLOAT,0,3); + buffers[17].release(); + + glVertexAttribDivisor(centerLocation[0],1); + glVertexAttribDivisor(normalsLocation[0],0); + vao[17].release(); + + //Nearest neighbor Sphere + vao[18].bind(); + buffers[9].bind(); + centerLocation[0] = rendering_program_spheres.attributeLocation("center"); + rendering_program_spheres.enableAttributeArray(centerLocation[0]); + rendering_program_spheres.setAttributeBuffer(centerLocation[0],GL_FLOAT,0,3); + buffers[9].release(); + + buffers[15].bind(); + normalsLocation[0] = rendering_program_spheres.attributeLocation("normal"); + rendering_program_spheres.enableAttributeArray(normalsLocation[0]); + rendering_program_spheres.setAttributeBuffer(normalsLocation[0],GL_FLOAT,0,3); + buffers[15].release(); + + buffers[17].bind(); + poly_vertexLocation[1] = rendering_program_spheres.attributeLocation("vertex"); + rendering_program_spheres.enableAttributeArray(poly_vertexLocation[1]); + rendering_program_spheres.setAttributeBuffer(poly_vertexLocation[1],GL_FLOAT,0,3); + buffers[17].release(); + + glVertexAttribDivisor(centerLocation[0],1); + glVertexAttribDivisor(normalsLocation[0],0); + vao[18].release(); + + //incremental list + vao[25].bind(); + buffers[31].bind(); + rendering_program_spheres.enableAttributeArray(centerLocation[0]); + rendering_program_spheres.setAttributeBuffer(centerLocation[0],GL_FLOAT,0,3); + buffers[31].release(); + + buffers[15].bind(); + normalsLocation[0] = rendering_program_spheres.attributeLocation("normal"); + rendering_program_spheres.enableAttributeArray(normalsLocation[0]); + rendering_program_spheres.setAttributeBuffer(normalsLocation[0],GL_FLOAT,0,3); + buffers[15].release(); + + buffers[17].bind(); + poly_vertexLocation[1] = rendering_program_spheres.attributeLocation("vertex"); + rendering_program_spheres.enableAttributeArray(poly_vertexLocation[1]); + rendering_program_spheres.setAttributeBuffer(poly_vertexLocation[1],GL_FLOAT,0,3); + buffers[17].release(); + + glVertexAttribDivisor(centerLocation[0],1); + glVertexAttribDivisor(normalsLocation[0],0); + vao[25].release(); + + //incremental next point + vao[26].bind(); + buffers[28].bind(); + rendering_program_spheres.enableAttributeArray(centerLocation[0]); + rendering_program_spheres.setAttributeBuffer(centerLocation[0],GL_FLOAT,0,3); + buffers[28].release(); + + buffers[15].bind(); + normalsLocation[0] = rendering_program_spheres.attributeLocation("normal"); + rendering_program_spheres.enableAttributeArray(normalsLocation[0]); + rendering_program_spheres.setAttributeBuffer(normalsLocation[0],GL_FLOAT,0,3); + buffers[15].release(); + + buffers[17].bind(); + poly_vertexLocation[1] = rendering_program_spheres.attributeLocation("vertex"); + rendering_program_spheres.enableAttributeArray(poly_vertexLocation[1]); + rendering_program_spheres.setAttributeBuffer(poly_vertexLocation[1],GL_FLOAT,0,3); + buffers[17].release(); + + glVertexAttribDivisor(centerLocation[0],1); + glVertexAttribDivisor(normalsLocation[0],0); + vao[26].release(); + + } + rendering_program_spheres.release(); + rendering_program_cylinders.bind(); + { + vao[19].bind(); + buffers[18].bind(); + buffers[18].allocate(points_cylinder->data(), points_cylinder->size()*sizeof(float)); + poly_vertexLocation[2] = rendering_program_cylinders.attributeLocation("vertex"); + rendering_program_cylinders.enableAttributeArray(poly_vertexLocation[2]); + rendering_program_cylinders.setAttributeBuffer(poly_vertexLocation[2],GL_FLOAT,0,3); + buffers[18].release(); + + buffers[19].bind(); + buffers[19].allocate(normals_cylinder->data(), normals_cylinder->size()*sizeof(float)); + normalsLocation[1] = rendering_program_cylinders.attributeLocation("normal"); + rendering_program_cylinders.enableAttributeArray(normalsLocation[1]); + rendering_program_cylinders.setAttributeBuffer(normalsLocation[1],GL_FLOAT,0,3); + buffers[19].release(); + + buffers[20].bind(); + buffers[20].allocate(transfo1_delaunay->data(), transfo1_delaunay->size()*sizeof(float)); + centerLocation[1] = rendering_program_cylinders.attributeLocation("transfo1"); + rendering_program_cylinders.enableAttributeArray(centerLocation[1]); + rendering_program_cylinders.setAttributeBuffer(centerLocation[1],GL_FLOAT,0,4); + buffers[20].release(); + + buffers[21].bind(); + buffers[21].allocate(transfo2_delaunay->data(), transfo2_delaunay->size()*sizeof(float)); + centerLocation[2] = rendering_program_cylinders.attributeLocation("transfo2"); + rendering_program_cylinders.enableAttributeArray(centerLocation[2]); + rendering_program_cylinders.setAttributeBuffer(centerLocation[2],GL_FLOAT,0,4); + buffers[21].release(); + + + buffers[22].bind(); + buffers[22].allocate(transfo3_delaunay->data(), transfo3_delaunay->size()*sizeof(float)); + centerLocation[3] = rendering_program_cylinders.attributeLocation("transfo3"); + rendering_program_cylinders.enableAttributeArray(centerLocation[3]); + rendering_program_cylinders.setAttributeBuffer(centerLocation[3],GL_FLOAT,0,4); + buffers[22].release(); + + buffers[23].bind(); + buffers[23].allocate(transfo4_delaunay->data(), transfo4_delaunay->size()*sizeof(float)); + centerLocation[4] = rendering_program_cylinders.attributeLocation("transfo4"); + rendering_program_cylinders.enableAttributeArray(centerLocation[4]); + rendering_program_cylinders.setAttributeBuffer(centerLocation[4],GL_FLOAT,0,4); + buffers[23].release(); + + + glVertexAttribDivisor(centerLocation[1],1); + glVertexAttribDivisor(centerLocation[2],1); + glVertexAttribDivisor(centerLocation[3],1); + glVertexAttribDivisor(centerLocation[4],1); + glVertexAttribDivisor(normalsLocation[1],0); + + vao[19].release(); + + vao[20].bind(); + buffers[18].bind(); + poly_vertexLocation[2] = rendering_program_cylinders.attributeLocation("vertex"); + rendering_program_cylinders.enableAttributeArray(poly_vertexLocation[2]); + rendering_program_cylinders.setAttributeBuffer(poly_vertexLocation[2],GL_FLOAT,0,3); + buffers[18].release(); + + buffers[19].bind(); + normalsLocation[1] = rendering_program_cylinders.attributeLocation("normal"); + rendering_program_cylinders.enableAttributeArray(normalsLocation[1]); + rendering_program_cylinders.setAttributeBuffer(normalsLocation[1],GL_FLOAT,0,3); + buffers[19].release(); + + buffers[24].bind(); + buffers[24].allocate(transfo1_voronoi->data(), transfo1_voronoi->size()*sizeof(float)); + centerLocation[1] = rendering_program_cylinders.attributeLocation("transfo1"); + rendering_program_cylinders.enableAttributeArray(centerLocation[1]); + rendering_program_cylinders.setAttributeBuffer(centerLocation[1],GL_FLOAT,0,4); + buffers[24].release(); + + buffers[25].bind(); + buffers[25].allocate(transfo2_voronoi->data(), transfo2_voronoi->size()*sizeof(float)); + centerLocation[2] = rendering_program_cylinders.attributeLocation("transfo2"); + rendering_program_cylinders.enableAttributeArray(centerLocation[2]); + rendering_program_cylinders.setAttributeBuffer(centerLocation[2],GL_FLOAT,0,4); + buffers[25].release(); + + + buffers[26].bind(); + buffers[26].allocate(transfo3_voronoi->data(), transfo3_voronoi->size()*sizeof(float)); + centerLocation[3] = rendering_program_cylinders.attributeLocation("transfo3"); + rendering_program_cylinders.enableAttributeArray(centerLocation[3]); + rendering_program_cylinders.setAttributeBuffer(centerLocation[3],GL_FLOAT,0,4); + buffers[26].release(); + + buffers[27].bind(); + buffers[27].allocate(transfo4_voronoi->data(), transfo4_voronoi->size()*sizeof(float)); + centerLocation[4] = rendering_program_cylinders.attributeLocation("transfo4"); + rendering_program_cylinders.enableAttributeArray(centerLocation[4]); + rendering_program_cylinders.setAttributeBuffer(centerLocation[4],GL_FLOAT,0,4); + buffers[27].release(); + + + glVertexAttribDivisor(centerLocation[1],1); + glVertexAttribDivisor(centerLocation[2],1); + glVertexAttribDivisor(centerLocation[3],1); + glVertexAttribDivisor(centerLocation[4],1); + glVertexAttribDivisor(normalsLocation[1],0); + + vao[20].release(); + } + rendering_program_cylinders.release(); + are_buffers_initialized = true; +} + +void Viewer::attrib_buffers(QGLViewer* viewer) +{ + QMatrix4x4 mvpMatrix; + QMatrix4x4 mvMatrix; + double mat[16]; + viewer->camera()->getModelViewProjectionMatrix(mat); + for(int i=0; i < 16; i++) + { + mvpMatrix.data()[i] = (float)mat[i]; + } + viewer->camera()->getModelViewMatrix(mat); + for(int i=0; i < 16; i++) + { + mvMatrix.data()[i] = (float)mat[i]; + } + QVector4D position(0.0f,0.0f,1.0f,1.0f ); + // Ambient + ambient[0] = 0.29225f; + ambient[1] = 0.29225f; + ambient[2] = 0.29225f; + ambient[3] = 1.0f; + // Diffuse + diffuse[0] = 0.50754f; + diffuse[1] = 0.50754f; + diffuse[2] = 0.50754f; + diffuse[3] = 1.0f; + // Specular + specular[0] = 0.508273f; + specular[1] = 0.508273f; + specular[2] = 0.508273f; + specular[3] = 1.0f; + // Shininess + shininess = 51.2f; + + rendering_program.bind(); + mvpLocation[0] = rendering_program.uniformLocation("mvp_matrix"); + colorLocation[0] = rendering_program.uniformLocation("color"); + rendering_program.setUniformValue(mvpLocation[0], mvpMatrix); + + rendering_program.release(); + + + rendering_program_spheres.bind(); + colorLocation[1] = rendering_program_spheres.uniformLocation("color"); + mvpLocation[1] = rendering_program_spheres.uniformLocation("mvp_matrix"); + mvLocation[0] = rendering_program_spheres.uniformLocation("mv_matrix"); + lightLocation[0] = rendering_program_spheres.uniformLocation("light_pos"); + lightLocation[1] = rendering_program_spheres.uniformLocation("light_diff"); + lightLocation[2] = rendering_program_spheres.uniformLocation("light_spec"); + lightLocation[3] = rendering_program_spheres.uniformLocation("light_amb"); + lightLocation[4] = rendering_program_spheres.uniformLocation("spec_power"); + + rendering_program_spheres.setUniformValue(lightLocation[0], position); + rendering_program_spheres.setUniformValue(mvpLocation[1], mvpMatrix); + rendering_program_spheres.setUniformValue(mvLocation[0], mvMatrix); + rendering_program_spheres.setUniformValue(lightLocation[1], diffuse); + rendering_program_spheres.setUniformValue(lightLocation[2], specular); + rendering_program_spheres.setUniformValue(lightLocation[3], ambient); + rendering_program_spheres.setUniformValue(lightLocation[4], shininess); + + rendering_program_spheres.release(); + + rendering_program_cylinders.bind(); + colorLocation[2] = rendering_program_cylinders.uniformLocation("color"); + mvpLocation[2] = rendering_program_cylinders.uniformLocation("mvp_matrix"); + mvLocation[1] = rendering_program_cylinders.uniformLocation("mv_matrix"); + lightLocation[5] = rendering_program_cylinders.uniformLocation("light_pos"); + lightLocation[6] = rendering_program_cylinders.uniformLocation("light_diff"); + lightLocation[7] = rendering_program_cylinders.uniformLocation("light_spec"); + lightLocation[8] = rendering_program_cylinders.uniformLocation("light_amb"); + lightLocation[9] = rendering_program_cylinders.uniformLocation("spec_power"); + + rendering_program_cylinders.setUniformValue(lightLocation[5], position); + rendering_program_cylinders.setUniformValue(lightLocation[6], diffuse); + rendering_program_cylinders.setUniformValue(lightLocation[7], specular); + rendering_program_cylinders.setUniformValue(lightLocation[8], ambient); + rendering_program_cylinders.setUniformValue(lightLocation[9], shininess); + rendering_program_cylinders.setUniformValue(mvpLocation[2], mvpMatrix); + rendering_program_cylinders.setUniformValue(mvLocation[1], mvMatrix); + + + rendering_program_cylinders.release(); +} + /*************************************************************/ /* Draw functions */ void Viewer::draw() { - if( m_pScene == NULL ) return; + if(!are_buffers_initialized) + initialize_buffers(); + QFont fontPrompt("Arial", 8); + attrib_buffers(this); + if(m_isFlat) + { - QFont fontPrompt("Arial", 14); + if(m_showVertex) + { + rendering_program.bind(); + glPointSize(8.0); + vao[0].bind(); + rendering_program.setUniformValue(colorLocation[0], m_colorVertex); + glDrawArrays(GL_POINTS, 0, pos_points->size()/3); + vao[0].release(); + rendering_program.release(); + } + if(m_showDEdge) + { + rendering_program.bind(); + vao[1].bind(); + rendering_program.setUniformValue(colorLocation[0], m_colorDEdge); + glDrawArrays(GL_LINES, 0, pos_delaunay->size()/3); + vao[1].release(); + rendering_program.release(); + } + if(m_showVEdge) + { + rendering_program.bind(); + vao[2].bind(); + rendering_program.setUniformValue(colorLocation[0], m_colorVEdge); + glDrawArrays(GL_LINES, 0, pos_voronoi->size()/3); + vao[2].release(); + rendering_program.release(); + } + // Insert point mode + if( m_curMode == INSERT_PT) { + // Show prompt messages + qglColor( ::Qt::black ); + drawText( width()-200, 20, tr("Shift+Left: Insert a point"), fontPrompt ); + drawText( width()-200, 40, tr("Hold Left: Move the point"), fontPrompt ); + drawText( width()-200, 60, tr("Return: Insert to DT"), fontPrompt ); + drawText( width()-200, 80, tr("Escape: Cancel insertion"), fontPrompt ); + drawText( width()-200, 100, tr("Shift+Wheel: Resize trackball"), fontPrompt ); + if( m_hasNewPt ) { + rendering_program.bind(); + vao[4].bind(); + color.setRgbF(1.0,0.0,0.0); + rendering_program.setUniformValue(colorLocation[0], color); + glDrawArrays(GL_POINTS, 0, pos_newPoint->size()/3); + vao[4].release(); - if( m_showAxis ) { - qglColor(::Qt::black); - drawAxis( sceneRadius() ); - } + vao[5].bind(); + color.setRgb(215, 80, 0, 96); + rendering_program.setUniformValue(colorLocation[0], color); + glDrawArrays(GL_TRIANGLES, 0, pos_newFacet->size()/3); + vao[5].release(); + rendering_program.release(); + } + } + else if( m_curMode == SELECT) { + // Show prompt messages + qglColor( ::Qt::black ); + drawText( width()-200, 20, tr("Shift+Left: Select"), fontPrompt ); + drawText( width()-200, 40, tr("Ctrl+Left: Add selection"), + QFont("Arial", 14) ); + drawText( width()-200, 60, tr("Escape: Cancel selection"), fontPrompt ); + drawText( width()-200, 80, tr("DEL: Delete selected"), fontPrompt ); + rendering_program.bind(); + vao[6].bind(); + color.setRgbF(1.0,0.0,0.0); + rendering_program.setUniformValue(colorLocation[0], color); + glDrawArrays(GL_POINTS, 0, pos_selectedVertex->size()/3); + vao[6].release(); + rendering_program.release(); + } + else if( m_curMode == MOVE ) { + // Show prompt messages + qglColor( ::Qt::black ); + drawText( width()-200, 20, tr("Left Click: Select"), fontPrompt ); + if(m_isMoving) + drawText( width()-200, 40, tr("Shift+Wheel: Resize trackball"), fontPrompt ); + rendering_program.bind(); + vao[7].bind(); + color.setRgbF(1.0,0.0,0.0); + rendering_program.setUniformValue(colorLocation[0], color); + glDrawArrays(GL_POINTS, 0, pos_movingPoint->size()/3); + vao[7].release(); + rendering_program.release(); + } + else if( m_curMode == FINDNB ) { + // Show prompt messages + qglColor( ::Qt::black ); + drawText( width()-200, 20, tr("Shift+Left: Place query point"), fontPrompt ); + drawText( width()-200, 40, tr("Shift+Wheel: Resize trackball"), fontPrompt ); + rendering_program.bind(); + vao[8].bind(); + color.setRgbF(1.0,0.0,0.0); + rendering_program.setUniformValue(colorLocation[0], color); + glDrawArrays(GL_POINTS, 0, pos_queryPoint->size()/3); + vao[8].release(); - /* Draw vertices */ - if ( m_showVertex && m_pScene->m_dt.number_of_vertices()>0 ) { - for(QList::iterator vit = m_pScene->m_vhArray.begin(); - vit < m_pScene->m_vhArray.end(); ++vit) { - if( m_curMode == SELECT && (*vit)->isSeled() ) continue; - if( (*vit) == m_nearestNb ) continue; - drawVertex( (*vit)->point(), m_colorVertex, m_fSizeVertex ); - }//end-for-points - }//end-if-points + vao[9].bind(); + color.setRgbF(1.0,0.0,0.0); + rendering_program.setUniformValue(colorLocation[0], color); + glDrawArrays(GL_POINTS, 0, pos_nearest_neighbor->size()/3); + vao[9].release(); + rendering_program.release(); + } + else if(m_curMode == EMPTYSPH){ + // Show prompt messages + qglColor( ::Qt::black ); + drawText( width()-200, 20, tr("Shift+Left: Place query point"), fontPrompt ); + drawText( width()-200, 40, tr("Press S: Show/Hide trackball"), fontPrompt ); + drawText( width()-200, 60, tr("Shift+Wheel: Resize trackball"), fontPrompt ); + rendering_program.bind(); + vao[8].bind(); + color.setRgbF(1.0,0.0,0.0); + rendering_program.setUniformValue(colorLocation[0], color); + glDrawArrays(GL_POINTS, 0, pos_queryPoint->size()/3); + vao[8].release(); + vao[10].bind(); + rendering_program.setUniformValue(colorLocation[0], m_colorFacet); + glDrawArrays(GL_TRIANGLES, 0, pos_emptyFacet->size()/3); + vao[10].release(); + rendering_program.release(); + } + // Draw all points during incremental mode + if( !m_incrementalPts.isEmpty() ) { + // draw the rest to-be-inserted vertices + rendering_program.bind(); + glPointSize(8.0); + vao[24].bind(); + color.setRgbF(0.7,0.7,0.7); + rendering_program.setUniformValue(colorLocation[0],color); + glDrawArrays(GL_POINTS, 0, incremental_points->size()/3); + vao[24].release(); + rendering_program.release(); + switch( m_curStep ) { + case NEWPT: + // Show prompt messages + qglColor( ::Qt::black ); + drawText( 10, 20, tr("Highlight the next-to-insert point"), fontPrompt ); + // Highlight the next-to-insert point + rendering_program.bind(); + glPointSize(8.0); + vao[21].bind(); + color.setRgbF(1.0,0.0,0.0); + rendering_program.setUniformValue(colorLocation[0], color); + glDrawArrays(GL_POINTS, 0, incremental_next_point->size()/3); + vao[21].release(); + rendering_program.release(); + break; + case CELL: // show the tetrahedron that contains the point + // Show prompt messages + qglColor( ::Qt::black ); + drawText( 10, 20, tr("Show the tetrahedron containing the point"), fontPrompt ); + drawText( 10, 40, tr("(Only finite facets are drawn)"), fontPrompt ); + // Highlight the next-to-insert vertex + rendering_program.bind(); + glPointSize(8.0); + vao[21].bind(); + color.setRgbF(1.0,0.0,0.0); + rendering_program.setUniformValue(colorLocation[0], color); + glDrawArrays(GL_POINTS, 0, incremental_next_point->size()/3); + vao[21].release(); + rendering_program.release(); + // Draw the cell containing that point + rendering_program.bind(); + vao[22].bind(); + rendering_program.setUniformValue(colorLocation[0], m_colorFacet); + glDrawArrays(GL_TRIANGLES, 0, incremental_facet->size()/3); + vao[22].release(); + rendering_program.release(); + break; + case CONFLICT: // show the conflict region + // Show prompt messages + qglColor( ::Qt::black ); + drawText( 10, 20, tr("Show the conflict region"), fontPrompt ); + // Highlight the next-to-insert vertex + rendering_program.bind(); + glPointSize(8.0); + vao[21].bind(); + color.setRgbF(1.0,0.0,0.0); + rendering_program.setUniformValue(colorLocation[0], color); + glDrawArrays(GL_POINTS, 0, incremental_next_point->size()/3); + vao[21].release(); + rendering_program.release(); + // Draw conflict region + rendering_program.bind(); + vao[23].bind(); + color.setRgb(215, 80, 0, 96); + rendering_program.setUniformValue(colorLocation[0], color); + glDrawArrays(GL_TRIANGLES, 0, incremental_facet->size()/3); + vao[23].release(); + rendering_program.release(); - /* Draw all points during incremental mode */ + break; + default: + break; + }//end-of=switch + }//end-if-incpts + + } + else + { + if(m_showVertex) + { + rendering_program_spheres.bind(); + vao[13].bind(); + rendering_program_spheres.setUniformValue(colorLocation[1], m_colorVertex); + glDrawArraysInstanced(GL_TRIANGLES, 0, points_sphere->size()/3, pos_points->size()/3); + vao[13].release(); + rendering_program.release(); + } + if(m_showDEdge) + { + rendering_program_cylinders.bind(); + vao[19].bind(); + rendering_program_cylinders.setUniformValue(colorLocation[2], m_colorDEdge); + glDrawArraysInstanced(GL_TRIANGLES, 0, points_cylinder->size()/3, transfo1_delaunay->size()/4); + vao[19].release(); + rendering_program_cylinders.release(); + } + if(m_showVEdge) + { + rendering_program_cylinders.bind(); + vao[20].bind(); + rendering_program_cylinders.setUniformValue(colorLocation[2], m_colorVEdge); + glDrawArraysInstanced(GL_TRIANGLES, 0, points_cylinder->size()/3, transfo1_voronoi->size()/4); + vao[20].release(); + rendering_program_cylinders.release(); + } + + if( m_curMode == INSERT_PT) { + // Show prompt messages + qglColor( ::Qt::black ); + drawText( width()-200, 20, tr("Shift+Left: Insert a point"), fontPrompt ); + drawText( width()-200, 40, tr("Hold Left: Move the point"), fontPrompt ); + drawText( width()-200, 60, tr("Return: Insert to DT"), fontPrompt ); + drawText( width()-200, 80, tr("Escape: Cancel insertion"), fontPrompt ); + drawText( width()-200, 100, tr("Shift+Wheel: Resize trackball"), fontPrompt ); + if( m_hasNewPt ) { + rendering_program_spheres.bind(); + vao[14].bind(); + color.setRgbF(1.0,0.0,0.0); + rendering_program_spheres.setUniformValue(colorLocation[1], color); + glDrawArraysInstanced(GL_TRIANGLES, 0, points_sphere->size()/3, pos_newPoint->size()/3); + vao[14].release(); + rendering_program_spheres.release(); + rendering_program.bind(); + vao[5].bind(); + color.setRgb(215, 80, 0, 96); + rendering_program.setUniformValue(colorLocation[0], color); + glDrawArrays(GL_TRIANGLES, 0, pos_newFacet->size()/3); + vao[5].release(); + rendering_program.release(); + } + } + else if( m_curMode == SELECT) { + // Show prompt messages + qglColor( ::Qt::black ); + drawText( width()-200, 20, tr("Shift+Left: Select"), fontPrompt ); + drawText( width()-200, 40, tr("Ctrl+Left: Add selection"), + QFont("Arial", 14) ); + drawText( width()-200, 60, tr("Escape: Cancel selection"), fontPrompt ); + drawText( width()-200, 80, tr("DEL: Delete selected"), fontPrompt ); + rendering_program_spheres.bind(); + vao[15].bind(); + color.setRgbF(1.0,0.0,0.0); + rendering_program_spheres.setUniformValue(colorLocation[1], color); + glDrawArraysInstanced(GL_TRIANGLES, 0, points_sphere->size()/3, pos_selectedVertex->size()/3); + vao[15].release(); + rendering_program_spheres.release(); + } + else if( m_curMode == MOVE ) { + // Show prompt messages + qglColor( ::Qt::black ); + drawText( width()-200, 20, tr("Left Click: Select"), fontPrompt ); + if(m_isMoving) + drawText( width()-200, 40, tr("Shift+Wheel: Resize trackball"), fontPrompt ); + rendering_program_spheres.bind(); + vao[16].bind(); + color.setRgbF(1.0,0.0,0.0); + rendering_program_spheres.setUniformValue(colorLocation[1], color); + glDrawArraysInstanced(GL_TRIANGLES, 0, points_sphere->size()/3, pos_movingPoint->size()/3); + vao[16].release(); + rendering_program_spheres.release(); + } + else if( m_curMode == FINDNB ) { + // Show prompt messages + qglColor( ::Qt::black ); + drawText( width()-200, 20, tr("Shift+Left: Place query point"), fontPrompt ); + drawText( width()-200, 40, tr("Shift+Wheel: Resize trackball"), fontPrompt ); + rendering_program_spheres.bind(); + vao[17].bind(); + color.setRgbF(1.0,0.0,0.0); + rendering_program_spheres.setUniformValue(colorLocation[1], color); + glDrawArraysInstanced(GL_TRIANGLES, 0, points_sphere->size()/3, pos_queryPoint->size()/3); + vao[17].release(); + rendering_program_spheres.release(); + rendering_program_spheres.bind(); + vao[18].bind(); + color.setRgbF(1.0,0.0,0.0); + rendering_program_spheres.setUniformValue(colorLocation[1], color); + glDrawArraysInstanced(GL_TRIANGLES, 0, points_sphere->size()/3, pos_nearest_neighbor->size()/3); + vao[18].release(); + rendering_program_spheres.release(); + } + else if(m_curMode == EMPTYSPH){ + // Show prompt messages + qglColor( ::Qt::black ); + drawText( width()-200, 20, tr("Shift+Left: Place query point"), fontPrompt ); + drawText( width()-200, 40, tr("Press S: Show/Hide trackball"), fontPrompt ); + drawText( width()-200, 60, tr("Shift+Wheel: Resize trackball"), fontPrompt ); + rendering_program_spheres.bind(); + vao[17].bind(); + color.setRgbF(1.0,0.0,0.0); + rendering_program_spheres.setUniformValue(colorLocation[1], color); + glDrawArraysInstanced(GL_TRIANGLES, 0, points_sphere->size()/3, pos_queryPoint->size()/3); + vao[17].release(); + rendering_program_spheres.release(); + + rendering_program.bind(); + vao[10].bind(); + rendering_program.setUniformValue(colorLocation[0], m_colorFacet); + glDrawArrays(GL_TRIANGLES, 0, pos_emptyFacet->size()/3); + vao[10].release(); + rendering_program.release(); + } + // Draw all points during incremental mode + if( !m_incrementalPts.isEmpty() ) { + // draw the rest to-be-inserted vertices + rendering_program_spheres.bind(); + vao[25].bind(); + color.setRgbF(0.7,0.7,0.7); + rendering_program_spheres.setUniformValue(colorLocation[1],color); + glDrawArraysInstanced(GL_TRIANGLES, 0, points_sphere->size()/3, incremental_points->size()/3); + vao[25].release(); + rendering_program_spheres.release(); + switch( m_curStep ) { + case NEWPT: + // Show prompt messages + qglColor( ::Qt::black ); + drawText( 10, 20, tr("Highlight the next-to-insert point"), fontPrompt ); + // Highlight the next-to-insert point + rendering_program_spheres.bind(); + vao[26].bind(); + color.setRgbF(1.0,0.0,0.0); + rendering_program_spheres.setUniformValue(colorLocation[1],color); + glDrawArraysInstanced(GL_TRIANGLES, 0, points_sphere->size()/3, incremental_next_point->size()/3); + vao[26].release(); + rendering_program_spheres.release(); + break; + case CELL: // show the tetrahedron that contains the point + // Show prompt messages + qglColor( ::Qt::black ); + drawText( 10, 20, tr("Show the tetrahedron containing the point"), fontPrompt ); + drawText( 10, 40, tr("(Only finite facets are drawn)"), fontPrompt ); + // Highlight the next-to-insert vertex + rendering_program_spheres.bind(); + vao[26].bind(); + color.setRgbF(1.0,0.0,0.0); + rendering_program_spheres.setUniformValue(colorLocation[1], color); + glDrawArraysInstanced(GL_TRIANGLES, 0, points_sphere->size()/3, incremental_next_point->size()/3); + vao[26].release(); + rendering_program_spheres.release(); + // Draw the cell containing that point + rendering_program.bind(); + vao[22].bind(); + rendering_program.setUniformValue(colorLocation[0], m_colorFacet); + glDrawArrays(GL_TRIANGLES, 0, incremental_facet->size()/3); + vao[22].release(); + rendering_program.release(); + break; + case CONFLICT: // show the conflict region + // Show prompt messages + qglColor( ::Qt::black ); + drawText( 10, 20, tr("Show the conflict region"), fontPrompt ); + // Highlight the next-to-insert vertex + rendering_program_spheres.bind(); + vao[26].bind(); + color.setRgbF(1.0,0.0,0.0); + rendering_program_spheres.setUniformValue(colorLocation[1], color); + glDrawArraysInstanced(GL_TRIANGLES, 0, points_sphere->size()/3, incremental_next_point->size()/3); + vao[26].release(); + rendering_program_spheres.release(); + // Draw conflict region + rendering_program.bind(); + vao[23].bind(); + color.setRgb(215, 80, 0, 96); + rendering_program.setUniformValue(colorLocation[0], color); + glDrawArrays(GL_TRIANGLES, 0, incremental_facet->size()/3); + vao[23].release(); + rendering_program.release(); + + break; + default: + break; + }//end-of=switch + }//end-if-incpts + } + + if(m_showFacet) + { + rendering_program.bind(); + vao[3].bind(); + rendering_program.setUniformValue(colorLocation[0], m_colorFacet); + glDrawArrays(GL_TRIANGLES, 0, pos_facets->size()/3); + vao[3].release(); + rendering_program.release(); + } + if( m_curMode == INSERT_V ) { + // Show prompt messages + qglColor( ::Qt::black ); + drawText( width()-200, 20, tr("Shift+Left: Insert a vertex"), fontPrompt ); + drawText( width()-200, 40, tr("Shift+Wheel: Resize trackball"), fontPrompt ); + + } + if(m_selMode != NORMAL && m_showTrackball) + { + rendering_program_spheres.bind(); + vao[11].bind(); + rendering_program_spheres.setUniformValue(colorLocation[1], m_colorTrackball); + glDrawArraysInstanced(GL_TRIANGLES, 0, points_trackBall->size()/3, 1); + vao[11].release(); + rendering_program_spheres.release(); + } + if(m_curMode ==EMPTYSPH) + { + rendering_program_spheres.bind(); + vao[12].bind(); + rendering_program_spheres.setUniformValue(colorLocation[1], m_colorEmptySphere); + glDrawArraysInstanced(GL_TRIANGLES, 0, points_emptySphere->size()/3, pos_emptySphere->size()/3); + vao[12].release(); + rendering_program_spheres.release(); + } + + + + /* + + // Draw all points during incremental mode if( !m_incrementalPts.isEmpty() ) { - /* draw the rest to-be-inserted vertices */ + // draw the rest to-be-inserted vertices for(QList::iterator pit=m_incrementalPts.begin(); pit < m_incrementalPts.end(); ++pit) { drawVertex( (*pit), ::Qt::gray, m_fSizeVertex ); } - switch( m_curStep ) { - case NEWPT: - /* Show prompt messages */ + switch( m_curStep ) { + case NEWPT: + // Show prompt messages qglColor( ::Qt::black ); drawText( 10, 20, tr("Highlight the next-to-insert point"), fontPrompt ); - /* Highlight the next-to-insert point */ + // Highlight the next-to-insert point drawVertex( m_curIncPt, ::Qt::red, m_fSizeVertex ); break; case CELL: // show the tetrahedron that contains the point - /* Show prompt messages */ + // Show prompt messages qglColor( ::Qt::black ); drawText( 10, 20, tr("Show the tetrahedron containing the point"), fontPrompt ); drawText( 10, 40, tr("(Only finite facets are drawn)"), fontPrompt ); - /* Highlight the next-to-insert vertex */ + // Highlight the next-to-insert vertex drawVertex( m_curIncPt, ::Qt::red, m_fSizeVertex ); - /* Draw the cell containing that point */ + // Draw the cell containing that point for(int i=0; i<4; ++i) { if( m_pScene->m_dt.is_infinite(m_cellContain, i) ) continue; drawFacet( m_pScene->m_dt.triangle( m_cellContain, i ), m_colorFacet ); }//end-for-facets break; case CONFLICT: // show the conflict region - /* Show prompt messages */ + // Show prompt messages qglColor( ::Qt::black ); drawText( 10, 20, tr("Show the conflict region"), fontPrompt ); - /* Highlight the next-to-insert vertex */ + // Highlight the next-to-insert vertex drawVertex( m_curIncPt, ::Qt::red, m_fSizeVertex ); - /* Draw conflict region */ + // Draw conflict region for(QList::iterator fit = m_boundaryFacets.begin(); fit < m_boundaryFacets.end(); ++fit) { if( m_pScene->m_dt.is_infinite(*fit) ) continue; @@ -212,433 +1626,125 @@ void Viewer::draw() break; default: break; - }//end-of=switch + }//end-of=switch }//end-if-incpts - /* Draw Delaunay edges */ - if( m_showDEdge ) { - for(edges_iterator eit = m_pScene->m_dt.finite_edges_begin(); - eit != m_pScene->m_dt.finite_edges_end(); ++eit) { - Segment_3 seg = m_pScene->m_dt.segment(*eit); - drawEdge( seg.vertex(0), seg.vertex(1), m_colorDEdge, m_fSizeDEdge ); - }//end-for-edges - }//end-if-dt - - /* Draw Voronoi edges */ - if( m_showVEdge ) { - for(facets_iterator fit = m_pScene->m_dt.finite_facets_begin(); - fit != m_pScene->m_dt.finite_facets_end(); ++fit) { - Object_3 o = m_pScene->m_dt.dual(*fit); - if (const Segment_3 *s = CGAL::object_cast(&o)) { - drawEdge( s->vertex(0), s->vertex(1), m_colorVEdge, m_fSizeVEdge ); - } else if (const Ray_3 *r = CGAL::object_cast(&o)) { - drawEdge( r->point(0), // the source of the ray - r->point(1), // another point on the ray, different from the source - m_colorVEdge, m_fSizeVEdge ); - } - }//end-for-edges - }//end-if-vd - - /* Draw facets */ - if( m_showFacet ) { - for(facets_iterator fit = m_pScene->m_dt.finite_facets_begin(); - fit != m_pScene->m_dt.finite_facets_end(); ++fit) { - drawFacet( m_pScene->m_dt.triangle(*fit), m_colorFacet ); - }//end-for-facets - }//end-if-facets - - /* Insert vertex mode */ - if( m_curMode == INSERT_V ) { - /* Show prompt messages */ - qglColor( ::Qt::black ); - drawText( width()-200, 20, tr("Shift+Left: Insert a vertex"), fontPrompt ); - drawText( width()-200, 40, tr("Shift+Wheel: Resize trackball"), fontPrompt ); - /* Draw the trackball */ - drawSphere( m_fRadius, m_colorTrackball ); - }//end-if-insv - - /* Insert point mode */ - else if( m_curMode == INSERT_PT ) { - /* Show prompt messages */ - qglColor( ::Qt::black ); - drawText( width()-200, 20, tr("Shift+Left: Insert a point"), fontPrompt ); - drawText( width()-200, 40, tr("Hold Left: Move the point"), fontPrompt ); - drawText( width()-200, 60, tr("Return: Insert to DT"), fontPrompt ); - drawText( width()-200, 80, tr("Escape: Cancel insertion"), fontPrompt ); - drawText( width()-200, 100, tr("Shift+Wheel: Resize trackball"), fontPrompt ); - - /* Draw the trackball */ - drawSphere( m_fRadius, m_colorTrackball ); - - if( m_hasNewPt ) { - /* Draw the newly inserted point */ - drawVertex( m_newPt, ::Qt::red, m_fSizeVertex ); - /* Draw conflict region */ - for(QList::iterator fit = m_boundaryFacets.begin(); - fit < m_boundaryFacets.end(); ++fit) { - if( m_pScene->m_dt.is_infinite(*fit) ) continue; - drawFacet( m_pScene->m_dt.triangle(*fit), QColor(215, 80, 0, 96) ); //semi-transparent purple - }//end-for-facets - }//end-if-shown - }//end-if-inspt - - /* Select mode */ - else if( m_curMode == SELECT) { - /* Show prompt messages */ - qglColor( ::Qt::black ); - drawText( width()-200, 20, tr("Shift+Left: Select"), fontPrompt ); - drawText( width()-200, 40, tr("Ctrl+Left: Add selection"), - QFont("Arial", 14) ); - drawText( width()-200, 60, tr("Escape: Cancel selection"), fontPrompt ); - drawText( width()-200, 80, tr("DEL: Delete selected"), fontPrompt ); - /* Highlight the selected vertices */ - for(QList::iterator vit=m_vidSeled.begin(); vitm_vhArray.at(*vit)->point(), ::Qt::red, m_fSizeVertex ); - }//end-for-seledpts - /* Draw the multiple selection window */ - if( m_isPress ) { - ::glDisable( GL_LIGHTING ); - startScreenCoordinatesSystem(); - qglColor( QColor(80, 180, 180, 64) ); - ::glBegin(GL_QUADS); - ::glVertex2i(m_rectSel.left(), m_rectSel.top()); - ::glVertex2i(m_rectSel.right(), m_rectSel.top()); - ::glVertex2i(m_rectSel.right(), m_rectSel.bottom()); - ::glVertex2i(m_rectSel.left(), m_rectSel.bottom()); - ::glEnd(); - stopScreenCoordinatesSystem(); - ::glEnable( GL_LIGHTING ); - }//end-if-press - }//end-if-sel - - /* Move mode */ - else if( m_curMode == MOVE ) { - /* Show prompt messages */ - qglColor( ::Qt::black ); - drawText( width()-200, 20, tr("Left Click: Select"), fontPrompt ); - - if( m_isMoving ) { - drawText( width()-200, 40, tr("Shift+Wheel: Resize trackball"), fontPrompt ); - /* Draw the trackball */ - drawSphere( m_fRadius, m_colorTrackball ); - /* Highlight the moving point */ - drawVertex( m_pScene->m_vhArray.at( m_vidMoving )->point(), ::Qt::red, m_fSizeVertex ); - }//end-if-v - }//end-if-move - - /* FindNb mode */ - else if( m_curMode == FINDNB ) { - /* Show prompt messages */ - qglColor( ::Qt::black ); - drawText( width()-200, 20, tr("Shift+Left: Place query point"), fontPrompt ); - drawText( width()-200, 40, tr("Shift+Wheel: Resize trackball"), fontPrompt ); - /* Draw the trackball */ - drawSphere( m_fRadius, m_colorTrackball ); - /* Draw the nearest neighbor */ - if( m_nearestNb != NULL ) { - drawVertex( m_queryPt, ::Qt::red, m_fSizeVertex ); - drawVertex( m_nearestNb->point(), ::Qt::red, m_fSizeVertex ); - } - }//end-if-findnb - - /* EmptySphere mode */ - else if( m_curMode == EMPTYSPH ) { - /* Show prompt messages */ - qglColor( ::Qt::black ); - drawText( width()-200, 20, tr("Shift+Left: Place query point"), fontPrompt ); - drawText( width()-200, 40, tr("Press S: Show/Hide trackball"), fontPrompt ); - drawText( width()-200, 60, tr("Shift+Wheel: Resize trackball"), fontPrompt ); - /* Draw the trackball */ - if( m_showTrackball ) - drawSphere( m_fRadius, m_colorTrackball ); - - if( m_hasEmptyS ) { - /* Draw the query point */ - drawVertex( m_queryPt, ::Qt::red, m_fSizeVertex ); - /* Draw the cell containing that point */ - for(int i=0; i<4; ++i) { - if( m_pScene->m_dt.is_infinite(m_cellContain, i) ) continue; - drawFacet( m_pScene->m_dt.triangle( m_cellContain, i ), m_colorFacet ); - }//end-for-facets - /* Draw the sphere */ - drawSphere( m_fREmptyS, m_colorEmptySphere, m_centerPt ); - } - }//end-if-emptyS +*/ } -void Viewer::drawVertex(const Point_3& p, const QColor& clr, float r) +void Viewer::drawVertex(const Point_3& p, const QColor& clr, float r, std::vector *vertices) { - /* Draw regular points */ - if( m_isFlat ) { - // disable lighting - ::glDisable( GL_LIGHTING ); - ::glPointSize(8.0); - qglColor( clr ); + vertices->push_back(p.x()); vertices->push_back(p.y()); vertices->push_back(p.z()); - ::glBegin(GL_POINTS); - ::glVertex3f( p.x(), p.y(), p.z() ); - ::glEnd(); - // resume lighting - ::glEnable( GL_LIGHTING ); - - return; - } - - /* Draw vertices as 3D balls */ - GLboolean lighting, colorMaterial; - ::glGetBooleanv( GL_LIGHTING, &lighting ); - ::glGetBooleanv( GL_COLOR_MATERIAL, &colorMaterial ); - ::glEnable( GL_LIGHTING ); - ::glDisable(GL_COLOR_MATERIAL); - - float color[4]; - color[0] = clr.redF(); - color[1] = clr.greenF(); - color[2] = clr.blueF(); - color[3] = clr.alphaF(); - - // move to the point - ::glPushMatrix(); - ::glTranslatef( p.x(), p.y(), p.z() ); - - // draw - GLUquadricObj* quadratic = ::gluNewQuadric(); // Create A Pointer To The Quadric Object - ::gluQuadricNormals( quadratic, GLU_SMOOTH ); // Create Smooth Normals - ::glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color ); - ::gluSphere( quadratic, r, 16, 16 ); - - // move back to origin - ::glPopMatrix(); - - if ( colorMaterial ) - ::glEnable( GL_COLOR_MATERIAL ); - if ( !lighting ) - ::glDisable( GL_LIGHTING ); } -void Viewer::drawEdge(const Point_3& from, const Point_3& to, const QColor& clr, float r) +void Viewer::drawEdge(const Point_3& from, const Point_3& to, const QColor& clr, float r, std::vector *vertices) { - /* Draw regular lines */ - if( m_isFlat ) { - // disable lighting - ::glDisable( GL_LIGHTING ); - - ::glLineWidth(1.0); - qglColor( clr ); - - ::glBegin(GL_LINES); - ::glVertex3f( from.x(), from.y(), from.z() ); - ::glVertex3f( to.x(), to.y(), to.z() ); - ::glEnd(); - - // resume lighting - ::glEnable( GL_LIGHTING ); - - return; - } - - /* Draw edges as 3D cylinders */ - GLboolean lighting, colorMaterial; - ::glGetBooleanv( GL_LIGHTING, &lighting ); - ::glGetBooleanv( GL_COLOR_MATERIAL, &colorMaterial ); - ::glEnable( GL_LIGHTING ); - ::glDisable(GL_COLOR_MATERIAL); - - float color[4]; - color[0] = clr.redF(); - color[1] = clr.greenF(); - color[2] = clr.blueF(); - color[3] = clr.alphaF(); - - Vector_3 v = to - from; - - // compute the length of the edge - // method 1: -// float length = sqrt( CGAL::squared_distance( from, to ) ); - // method 2: - float length = sqrt( v.squared_length() ); - - // normalize - v = v / length; - // compute the angle: cos theta = v.z/1.0 - GLfloat angle = acos( v.z() ) / 3.1415927 * 180; - - ::glPushMatrix(); - - // move to "from" point - ::glTranslatef( from.x(), from.y(), from.z() ); - // rotate from z-axis to from-->to - // axis: cross product of z-axis and from-->to - ::glRotatef( angle, -v.y(), v.x(), 0.0f ); - // draw - GLUquadricObj* quadratic = ::gluNewQuadric(); // Create A Pointer To The Quadric Object - ::gluQuadricNormals( quadratic, GLU_SMOOTH ); // Create Smooth Normals - ::glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color ); - // gluCylinder draws a cylinder oriented along the z-axis - ::gluCylinder( quadratic, r, r, length, 16, 4 ); - - // move back to origin - ::glPopMatrix(); - - if ( colorMaterial ) - ::glEnable( GL_COLOR_MATERIAL ); - if ( !lighting ) - ::glDisable( GL_LIGHTING ); + vertices->push_back( from.x()); vertices->push_back(from.y()); vertices->push_back(from.z()); + vertices->push_back( to.x()); vertices->push_back(to.y()); vertices->push_back(to.z()); } -void Viewer::drawFacet(const Triangle_3& t, const QColor& /*clr*/) +void Viewer::drawFacet(const Triangle_3& t, const QColor&/*clr*/, std::vector *vertices) { - // disable lighting - ::glDisable( GL_LIGHTING ); + Point_3 p0 = t.vertex(0); + Point_3 p1 = t.vertex(1); + Point_3 p2 = t.vertex(2); + vertices->push_back( p0.x()); vertices->push_back(p0.y()); vertices->push_back(p0.z()); + vertices->push_back( p1.x()); vertices->push_back(p1.y()); vertices->push_back(p1.z()); + vertices->push_back( p2.x()); vertices->push_back(p2.y()); vertices->push_back(p2.z()); - // disable depth buffer writing - ::glDepthMask( GL_FALSE ); - - qglColor( m_colorFacet ); - - ::glBegin(GL_TRIANGLES); - Point_3 p0 = t.vertex(0); - Point_3 p1 = t.vertex(1); - Point_3 p2 = t.vertex(2); - ::glVertex3f( p0.x(), p0.y(), p0.z() ); - ::glVertex3f( p1.x(), p1.y(), p1.z() ); - ::glVertex3f( p2.x(), p2.y(), p2.z() ); - ::glEnd(); - - // resume depth buffer writing - ::glDepthMask( GL_TRUE ); - - // resume lighting - ::glEnable( GL_LIGHTING ); } -void Viewer::drawSphere(float r, const QColor& clr, const Point_3& center) -{ - GLboolean lighting, colorMaterial; - ::glGetBooleanv( GL_LIGHTING, &lighting ); - ::glGetBooleanv( GL_COLOR_MATERIAL, &colorMaterial ); - ::glEnable( GL_LIGHTING ); - ::glDisable(GL_COLOR_MATERIAL); - - float color[4]; - color[0] = clr.redF(); - color[1] = clr.greenF(); - color[2] = clr.blueF(); - color[3] = clr.alphaF(); - - ::glPushMatrix(); - - // move to the point - if( center != CGAL::ORIGIN ) ::glTranslatef( center.x(), center.y(), center.z() ); - - // disable depth buffer writing - ::glDepthMask( GL_FALSE ); - // draw - GLUquadricObj* quadratic = ::gluNewQuadric(); // Create A Pointer To The Quadric Object - ::gluQuadricNormals( quadratic, GLU_SMOOTH ); // Create Smooth Normals - ::glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color ); - ::gluSphere( quadratic, r, 32, 32 ); - // resume depth buffer writing - ::glDepthMask( GL_TRUE ); - - // move back to origin - ::glPopMatrix(); - - if ( colorMaterial ) - ::glEnable( GL_COLOR_MATERIAL ); - if ( !lighting ) - ::glDisable( GL_LIGHTING ); -} /*************************************************************/ /* Select functions */ void Viewer::drawWithNames() { - for(int i=0; im_vhArray.size(); ++i) { - // push a name for each point onto the name stack - // note: it can NOT be used between glBegin and glEnd - ::glPushName( i ); + for(int i=0; im_vhArray.size(); ++i) { + // push a name for each point onto the name stack + // note: it can NOT be used between glBegin and glEnd + ::glPushName( i ); - // draw the point - ::glBegin(GL_POINTS); - Point_3& p = m_pScene->m_vhArray.at(i)->point(); - ::glVertex3f(p.x(), p.y(), p.z()); - ::glEnd(); + // draw the point + ::glBegin(GL_POINTS); + Point_3& p = m_pScene->m_vhArray.at(i)->point(); + ::glVertex3f(p.x(), p.y(), p.z()); + ::glEnd(); - // pop one name off the top of the name stack - ::glPopName(); - }//end-for-points + // pop one name off the top of the name stack + ::glPopName(); + }//end-for-points - // push a name for the newly inserted point - if( m_curMode == INSERT_PT && m_hasNewPt ) { - ::glPushName( ::GLuint(-1) ); - ::glBegin(GL_POINTS); - ::glVertex3f(m_newPt.x(), m_newPt.y(), m_newPt.z()); - ::glEnd(); - ::glPopName(); - }//end-if-newPt + // push a name for the newly inserted point + if( m_curMode == INSERT_PT && m_hasNewPt ) { + ::glPushName( ::GLuint(-1) ); + ::glBegin(GL_POINTS); + ::glVertex3f(m_newPt.x(), m_newPt.y(), m_newPt.z()); + ::glEnd(); + ::glPopName(); + }//end-if-newPt } void Viewer::endSelection(const QPoint& /*point*/) { - // flush GL buffers - ::glFlush(); + // flush GL buffers + ::glFlush(); - // reset GL_RENDER mode (was GL_SELECT) and get the number of selected points - size_t nSel = ::glRenderMode(GL_RENDER); + // reset GL_RENDER mode (was GL_SELECT) and get the number of selected points + size_t nSel = ::glRenderMode(GL_RENDER); - /* No selection */ - if( nSel <= 0 ) { - if( m_curMode == SELECT ) - m_isPress = false; - }//end-if-notselected + /* No selection */ + if( nSel <= 0 ) { + if( m_curMode == SELECT ) + m_isPress = false; + }//end-if-notselected - // each hit record has 4 data: # of names in name stack, min and max depth of old hits, - // name stack contents [see glSelectBuffer man page for more details] - // i.e. (selectBuffer())[4*i+3] is the id pushed on the stack + // each hit record has 4 data: # of names in name stack, min and max depth of old hits, + // name stack contents [see glSelectBuffer man page for more details] + // i.e. (selectBuffer())[4*i+3] is the id pushed on the stack - /* Check whether the new point is clicked on */ - else if( m_curMode == INSERT_PT ) { - if( m_hasNewPt && (selectBuffer())[3] == ::GLuint(-1) ) - m_isMoving = true; - }//end-if-inspt + /* Check whether the new point is clicked on */ + else if( m_curMode == INSERT_PT ) { + if( m_hasNewPt && (selectBuffer())[3] == ::GLuint(-1) ) + m_isMoving = true; + }//end-if-inspt - /* Check whether vertex is clicked on */ - else if( m_curMode == MOVE ) { - m_isMoving = true; - m_vidMoving = (selectBuffer())[3]; - // compute the corresponding size of trackball, i.e. selectedV is on the ball - Point_3 p = m_pScene->m_vhArray.at( m_vidMoving )->point(); - m_fRadius = sqrt( p.x()*p.x() + p.y()*p.y() + p.z()*p.z() ); - }//end-if-move + /* Check whether vertex is clicked on */ + else if( m_curMode == MOVE ) { + m_isMoving = true; + m_vidMoving = (selectBuffer())[3]; + // compute the corresponding size of trackball, i.e. selectedV is on the ball + Point_3 p = m_pScene->m_vhArray.at( m_vidMoving )->point(); + m_fRadius = sqrt( p.x()*p.x() + p.y()*p.y() + p.z()*p.z() ); + }//end-if-move - /* Store current selections */ - else { // m_curMode == SELECT - if( m_selMode == NORMAL ) { - // remove the old selections - for(QList::iterator vit=m_vidSeled.begin(); - vit < m_vidSeled.end(); ++vit) { - m_pScene->m_vhArray.at(*vit)->setSeled( false ); - } - m_vidSeled.clear(); + /* Store current selections */ + else { // m_curMode == SELECT + if( m_selMode == NORMAL ) { + // remove the old selections + for(QList::iterator vit=m_vidSeled.begin(); + vit < m_vidSeled.end(); ++vit) { + m_pScene->m_vhArray.at(*vit)->setSeled( false ); + } + m_vidSeled.clear(); - // record the new selections - for(std::size_t i=0; im_vhArray.at( m_vidSeled.back() )->setSeled(); - } - } else { - for(std::size_t i=0; im_vhArray.at( (selectBuffer())[4*i+3] )->setSeled(); - }//end-if-contain - }//end-for - }//end-if-add - }//end-if-sel + // record the new selections + for(std::size_t i=0; im_vhArray.at( m_vidSeled.back() )->setSeled(); + } + } else { + for(std::size_t i=0; im_vhArray.at( (selectBuffer())[4*i+3] )->setSeled(); + }//end-if-contain + }//end-for + }//end-if-add + }//end-if-sel } /*************************************************************/ @@ -646,487 +1752,473 @@ void Viewer::endSelection(const QPoint& /*point*/) void Viewer::mousePressEvent(QMouseEvent *event) { - // button() holds the button that caused the event - // note: for mouse move event, button() always return Qt::NoButton - // modifiers() holds the keyboard modifier flags at the time of the event - // buttons() holds the button state when the event was generated, - // i.e. all buttons that are pressed down - // pos() holds the mouse cursor's position relative to the receiving widget + // button() holds the button that caused the event + // note: for mouse move event, button() always return Qt::NoButton + // modifiers() holds the keyboard modifier flags at the time of the event + // buttons() holds the button state when the event was generated, + // i.e. all buttons that are pressed down + // pos() holds the mouse cursor's position relative to the receiving widget - // Get event modifiers key -#if QT_VERSION < 0x040000 - // Bug in Qt : use 0x0f00 instead of Qt::KeyButtonMask with Qt versions < 3.1 - const Qt::ButtonState modifiers = (Qt::ButtonState)(event->state() & Qt::KeyButtonMask); -#else - const Qt::KeyboardModifiers modifiers = event->modifiers(); -#endif + // Get event modifiers key + const Qt::KeyboardModifiers modifiers = event->modifiers(); - if( m_curMode == INSERT_V - && event->button() == Qt::LeftButton && modifiers == Qt::SHIFT ) { - m_isPress = true; - }//end-if-insv - - else if(m_curMode == INSERT_PT && event->button() == Qt::LeftButton ) { - /* shift+left to insert */ - if( modifiers == Qt::SHIFT ) { - if( m_pScene->m_dt.is_valid() && m_pScene->m_dt.dimension() == 3 ) + if( m_curMode == INSERT_V + && event->button() == Qt::LeftButton && modifiers == Qt::SHIFT ) { m_isPress = true; - else - displayMessage( tr("There exists no triangulation yet.") ); - m_hasNewPt = false; - } else { /* left button to move */ - m_isMoving = false; - // define selection window (default was 3) - setSelectRegionWidth( 10 ); - setSelectRegionHeight( 10 ); - // perform the selection - select( event->pos() ); - if( m_isMoving ) - // redraw window - updateGL(); - else - // if no point is selected, then regular action (rotation) will be performed + }//end-if-insv + + else if(m_curMode == INSERT_PT && event->button() == Qt::LeftButton ) { + /* shift+left to insert */ + if( modifiers == Qt::SHIFT ) { + if( m_pScene->m_dt.is_valid() && m_pScene->m_dt.dimension() == 3 ) + m_isPress = true; + else + displayMessage( tr("There exists no triangulation yet.") ); + m_hasNewPt = false; + } else { /* left button to move */ + m_isMoving = false; + // define selection window (default was 3) + setSelectRegionWidth( 10 ); + setSelectRegionHeight( 10 ); + // perform the selection + select( event->pos() ); + if( m_isMoving ) + // redraw window + { changed(); updateGL();} + else + // if no point is selected, then regular action (rotation) will be performed + QGLViewer::mousePressEvent(event); + }//end-if-shift + }//end-if-inspt + + else if( m_curMode == SELECT && event->button() == Qt::LeftButton ) { + // set the selection mode + switch( modifiers ) { + case Qt::SHIFT : // select + m_isPress = true; + m_selMode = NORMAL; + // initialize multiple selection window + m_rectSel = QRect( event->pos(), event->pos() ); + // redraw window + updateGL(); + break; + case Qt::CTRL : // add selection + m_isPress = true; + m_selMode = ADD; + // initialize multiple selection window + m_rectSel = QRect( event->pos(), event->pos() ); + // redraw window + updateGL(); + break; + default: // rotate + QGLViewer::mousePressEvent(event); + break; + } + }//end-if-select + + else if(m_curMode == MOVE && event->button() == Qt::LeftButton ) { + m_isMoving = false; + // define selection window (default was 3) + setSelectRegionWidth( 10 ); + setSelectRegionHeight( 10 ); + // perform the selection + select( event->pos() ); + if( m_isMoving ) // redraw window + { changed(); updateGL();} + else // if no point is selected, then regular action (rotation) will be performed + QGLViewer::mousePressEvent(event); + }//end-if-move + + else if( m_curMode == FINDNB + && event->button() == Qt::LeftButton && modifiers == Qt::SHIFT ) { + if( m_pScene->m_dt.is_valid() && m_pScene->m_dt.dimension() == 3 ) + m_isPress = true; + else + displayMessage( tr("There exists no triangulation yet.") ); + }//end-if-findnb + + else if( m_curMode == EMPTYSPH + && event->button() == Qt::LeftButton && modifiers == Qt::SHIFT ) { + if( m_pScene->m_dt.is_valid() && m_pScene->m_dt.dimension() == 3 ) + m_isPress = true; + else + displayMessage( tr("There exists no triangulation yet.") ); + m_hasEmptyS = false; + }//end-if-emptyS + + else QGLViewer::mousePressEvent(event); - }//end-if-shift - }//end-if-inspt - else if( m_curMode == SELECT && event->button() == Qt::LeftButton ) { - // set the selection mode - switch( modifiers ) { - case Qt::SHIFT : // select - m_isPress = true; - m_selMode = NORMAL; - // initialize multiple selection window - m_rectSel = QRect( event->pos(), event->pos() ); - // redraw window - updateGL(); - break; - case Qt::CTRL : // add selection - m_isPress = true; - m_selMode = ADD; - // initialize multiple selection window - m_rectSel = QRect( event->pos(), event->pos() ); - // redraw window - updateGL(); - break; - default: // rotate - QGLViewer::mousePressEvent(event); - break; - } - }//end-if-select - - else if(m_curMode == MOVE && event->button() == Qt::LeftButton ) { - m_isMoving = false; - // define selection window (default was 3) - setSelectRegionWidth( 10 ); - setSelectRegionHeight( 10 ); - // perform the selection - select( event->pos() ); - if( m_isMoving ) // redraw window - updateGL(); - else // if no point is selected, then regular action (rotation) will be performed - QGLViewer::mousePressEvent(event); - }//end-if-move - - else if( m_curMode == FINDNB - && event->button() == Qt::LeftButton && modifiers == Qt::SHIFT ) { - if( m_pScene->m_dt.is_valid() && m_pScene->m_dt.dimension() == 3 ) - m_isPress = true; - else - displayMessage( tr("There exists no triangulation yet.") ); - }//end-if-findnb - - else if( m_curMode == EMPTYSPH - && event->button() == Qt::LeftButton && modifiers == Qt::SHIFT ) { - if( m_pScene->m_dt.is_valid() && m_pScene->m_dt.dimension() == 3 ) - m_isPress = true; - else - displayMessage( tr("There exists no triangulation yet.") ); - m_hasEmptyS = false; - }//end-if-emptyS - - else - QGLViewer::mousePressEvent(event); } void Viewer::mouseMoveEvent(QMouseEvent *event) { - if( m_curMode == INSERT_PT && m_isMoving ) { - Vec pt; - if( computeIntersect( event->pos(), pt ) ) { - m_newPt = Point_3(pt.x, pt.y, pt.z); - // compute the conflict hole induced by point p - computeConflict( m_newPt ); - }//end-if-compute + if( m_curMode == INSERT_PT && m_isMoving ) { + Vec pt; + if( computeIntersect( event->pos(), pt ) ) { + m_newPt = Point_3(pt.x, pt.y, pt.z); + // compute the conflict hole induced by point p + computeConflict( m_newPt ); + // redraw + changed(); updateGL(); + }//end-if-compute + }//end-if-inspt - // redraw - updateGL(); - }//end-if-inspt + else if( m_curMode == SELECT && m_isPress ) { + // update multiple selection window + m_rectSel.setBottomRight( event->pos() ); + // redraw + //changed(); updateGL(); + }//end-if-sel - else if( m_curMode == SELECT && m_isPress ) { - // update multiple selection window - m_rectSel.setBottomRight( event->pos() ); - // redraw - updateGL(); - }//end-if-sel + else if( m_curMode == MOVE && m_isMoving ) { + Vec pt; + if( computeIntersect( event->pos(), pt ) ) { + // note: QList::operator[] return a modifiable reference; + // while QList::at return a const reference + // move_if_no_collision moves the point stored in v to pt + // if there is not already another vertex placed on pt, + // the triangulation is modified s.t. the new position of v is pt; + // otherwise, the vertex at point pt is returned. + Vertex_handle vh = m_pScene->m_dt.move_if_no_collision( + m_pScene->m_vhArray.at( m_vidMoving ), + Point_3( pt.x, pt.y, pt.z ) ); + int id1 = m_pScene->m_vhArray.indexOf( vh ); + int id2 = m_pScene->m_vhArray.indexOf( vh, m_vidMoving+1 ); + // remove the duplicate in vhArray + if( id1 != m_vidMoving ) + m_pScene->m_vhArray.removeAt( id1 ); + else if( id2 != -1 ) + m_pScene->m_vhArray.removeAt( id2 ); + m_pScene->m_vhArray[m_vidMoving] = vh; + }//end-if-compute - else if( m_curMode == MOVE && m_isMoving ) { - Vec pt; - if( computeIntersect( event->pos(), pt ) ) { - // note: QList::operator[] return a modifiable reference; - // while QList::at return a const reference - // move_if_no_collision moves the point stored in v to pt - // if there is not already another vertex placed on pt, - // the triangulation is modified s.t. the new position of v is pt; - // otherwise, the vertex at point pt is returned. - Vertex_handle vh = m_pScene->m_dt.move_if_no_collision( - m_pScene->m_vhArray.at( m_vidMoving ), - Point_3( pt.x, pt.y, pt.z ) ); - int id1 = m_pScene->m_vhArray.indexOf( vh ); - int id2 = m_pScene->m_vhArray.indexOf( vh, m_vidMoving+1 ); - // remove the duplicate in vhArray - if( id1 != m_vidMoving ) - m_pScene->m_vhArray.removeAt( id1 ); - else if( id2 != -1 ) - m_pScene->m_vhArray.removeAt( id2 ); - m_pScene->m_vhArray[m_vidMoving] = vh; - }//end-if-compute + // redraw + // changed(); updateGL(); + }//end-if-move - // redraw - updateGL(); - }//end-if-move - - else - QGLViewer::mouseMoveEvent(event); + else + QGLViewer::mouseMoveEvent(event); } void Viewer::mouseReleaseEvent(QMouseEvent *event) { - /* INS_V mode - Shift+Left: compute and insert a vertex */ - if( m_curMode == INSERT_V && m_isPress ) { - m_isPress = false; - Vec pt; - if( computeIntersect( event->pos(), pt ) ) { - m_pScene->m_vhArray.push_back( m_pScene->m_dt.insert( Point_3( pt.x, pt.y, pt.z ) ) ); - }//end-if-compute - - // redraw - updateGL(); - }//end-if-ins - - /* INS_PT mode - Shift+Left: compute and insert a point */ - else if( m_curMode == INSERT_PT && m_isPress ) { - m_isPress = false; - Vec pt; - if( computeIntersect( event->pos(), pt ) ) { - m_hasNewPt = true; - m_newPt = Point_3(pt.x, pt.y, pt.z); - // compute the conflict hole induced by point p - computeConflict( m_newPt ); - }//end-if-compute - - // redraw - updateGL(); - }//end-if-inspt - - /* INS_PT mode - Left: compute and insert a point */ - else if( m_curMode == INSERT_PT && m_isMoving ) { - m_isMoving = false; - Vec pt; - if( computeIntersect( event->pos(), pt ) ) { - m_newPt = Point_3(pt.x, pt.y, pt.z); - // compute the conflict hole induced by point p - computeConflict( m_newPt ); - }//end-if-compute - - // redraw - updateGL(); - }//end-if-inspt - - /* SEL mode - Left: terminate multiple point selection */ - else if( m_curMode == SELECT && m_isPress ) { - // might swap left/right and top/bottom to make rectanle valid -#if QT_VERSION < 0x040000 - m_rectSel = m_rectSel.normalize(); -#else - m_rectSel = m_rectSel.normalized(); -#endif - - if( m_rectSel.width() == 1 && m_rectSel.height() == 1 ) { /* select a point */ - // set a default selection window - setSelectRegionWidth( 10 ); - setSelectRegionHeight( 10 ); - // compute rectangle center and perform selection - select( m_rectSel.center() ); - if( m_isPress ) { + /* INS_V mode - Shift+Left: compute and insert a vertex */ + if( m_curMode == INSERT_V && m_isPress ) { m_isPress = false; - } else { - displayMessage( tr("No point is selected.") ); - } - } else { /* select multiple points, ie. selection window > 1 */ - // define selection window - if( m_rectSel.width() < 10 ) - setSelectRegionWidth( 10 ); - else - setSelectRegionWidth( m_rectSel.width() ); - if( m_rectSel.height() < 10 ) - setSelectRegionHeight( 10 ); - else - setSelectRegionHeight( m_rectSel.height() ); - // compute rectangle center and perform selection - select( m_rectSel.center() ); - if( m_isPress ) { + Vec pt; + if( computeIntersect( event->pos(), pt ) ) { + m_pScene->m_vhArray.push_back( m_pScene->m_dt.insert( Point_3( pt.x, pt.y, pt.z ) ) ); + }//end-if-compute + + // redraw + changed(); updateGL(); + }//end-if-ins + + /* INS_PT mode - Shift+Left: compute and insert a point */ + else if( m_curMode == INSERT_PT && m_isPress ) { m_isPress = false; - displayMessage( QString::number(m_vidSeled.size()) + tr(" points are selected") ); - } else { // empty window will cancel the current selection - for(QList::iterator iit = m_vidSeled.begin(); iit < m_vidSeled.end(); ++iit) - m_pScene->m_vhArray.at(*iit)->setSeled( false ); - m_vidSeled.clear(); - } - }//end-if-selwindow + Vec pt; + if( computeIntersect( event->pos(), pt ) ) { + m_hasNewPt = true; + m_newPt = Point_3(pt.x, pt.y, pt.z); + // compute the conflict hole induced by point p + computeConflict( m_newPt ); + }//end-if-compute - // update display to show - updateGL(); - }//end-if-select + // redraw + changed(); updateGL(); + }//end-if-inspt - /* MOVE mode - Left: terminate point moving */ - else if( m_curMode == MOVE && m_isMoving ) { - Vec pt; - if( computeIntersect( event->pos(), pt ) ) { - // note: QList::operator[] return a modifiable reference; - // while QList::at return a const reference - // move_if_no_collision moves the point stored in v to pt - // if there is not already another vertex placed on pt, - // the triangulation is modified s.t. the new position of v is pt; - // otherwise, the vertex at point pt is returned. - Vertex_handle vh = m_pScene->m_dt.move_if_no_collision( - m_pScene->m_vhArray.at( m_vidMoving ), - Point_3( pt.x, pt.y, pt.z ) ); - int id1 = m_pScene->m_vhArray.indexOf( vh ); - int id2 = m_pScene->m_vhArray.indexOf( vh, m_vidMoving+1 ); - // remove the duplicate in vhArray - if( id1 != m_vidMoving ) - m_pScene->m_vhArray.removeAt( id1 ); - else if( id2 != -1 ) - m_pScene->m_vhArray.removeAt( id2 ); - m_pScene->m_vhArray[m_vidMoving] = vh; - }//end-if-compute + /* INS_PT mode - Left: compute and insert a point */ + else if( m_curMode == INSERT_PT && m_isMoving ) { + m_isMoving = false; + Vec pt; + if( computeIntersect( event->pos(), pt ) ) { + m_newPt = Point_3(pt.x, pt.y, pt.z); + // compute the conflict hole induced by point p + computeConflict( m_newPt ); + }//end-if-compute - // redraw - updateGL(); - }//end-if-move + // redraw + changed(); updateGL(); + }//end-if-inspt - /* FindNb mode - Shift+Left: find the nearest neighbor of the point */ - else if( m_curMode == FINDNB && m_isPress ) { - m_isPress = false; - Vec pt; - if( computeIntersect( event->pos(), pt ) ) { - m_queryPt = Point_3( pt.x, pt.y, pt.z ); - m_nearestNb = m_pScene->m_dt.nearest_vertex( m_queryPt ); - }//end-if-compute + /* SEL mode - Left: terminate multiple point selection */ + else if( m_curMode == SELECT && m_isPress ) { + // might swap left/right and top/bottom to make rectanle valid + m_rectSel = m_rectSel.normalized(); - // redraw - updateGL(); - }//end-if-findnb + if( m_rectSel.width() == 1 && m_rectSel.height() == 1 ) { /* select a point */ + // set a default selection window + setSelectRegionWidth( 10 ); + setSelectRegionHeight( 10 ); + // compute rectangle center and perform selection + select( m_rectSel.center() ); + if( m_isPress ) { + m_isPress = false; + } else { + displayMessage( tr("No point is selected.") ); + } + } else { /* select multiple points, ie. selection window > 1 */ + // define selection window + if( m_rectSel.width() < 10 ) + setSelectRegionWidth( 10 ); + else + setSelectRegionWidth( m_rectSel.width() ); + if( m_rectSel.height() < 10 ) + setSelectRegionHeight( 10 ); + else + setSelectRegionHeight( m_rectSel.height() ); + // compute rectangle center and perform selection + select( m_rectSel.center() ); + if( m_isPress ) { + m_isPress = false; + displayMessage( QString::number(m_vidSeled.size()) + tr(" points are selected") ); + } else { // empty window will cancel the current selection + for(QList::iterator iit = m_vidSeled.begin(); iit < m_vidSeled.end(); ++iit) + m_pScene->m_vhArray.at(*iit)->setSeled( false ); + m_vidSeled.clear(); + } + }//end-if-selwindow - /* EmptySphere mode - Shift+Left: show the empty sphere of the cell */ - else if( m_curMode == EMPTYSPH && m_isPress ) { - m_isPress = false; - Vec pt; - m_hasEmptyS = computeIntersect( event->pos(), pt ); - if( m_hasEmptyS ) { - m_queryPt = Point_3( pt.x, pt.y, pt.z ); - // find the cell that contains point p in its interior - m_cellContain = m_pScene->m_dt.locate( m_queryPt ); - // show error if point is outside the convex hull - if( m_pScene->m_dt.is_infinite( m_cellContain ) ) { - m_hasEmptyS = false; - displayMessage( tr("Query point is outside the convex hull!") ); - } else { /* compute the empty sphere */ - // find the circumcenter of the four vertices of c - m_centerPt = m_pScene->m_dt.dual( m_cellContain ); - // compute the radius of the empty sphere - m_fREmptyS = sqrt( CGAL::squared_distance( m_centerPt, - m_cellContain->vertex(0)->point() ) ); - } - }//end-if-compute - // redraw - updateGL(); - }//end-if-emptysphere + // update display to show + changed(); updateGL(); + }//end-if-select + + /* MOVE mode - Left: terminate point moving */ + else if( m_curMode == MOVE && m_isMoving ) { + Vec pt; + if( computeIntersect( event->pos(), pt ) ) { + // note: QList::operator[] return a modifiable reference; + // while QList::at return a const reference + // move_if_no_collision moves the point stored in v to pt + // if there is not already another vertex placed on pt, + // the triangulation is modified s.t. the new position of v is pt; + // otherwise, the vertex at point pt is returned. + Vertex_handle vh = m_pScene->m_dt.move_if_no_collision( + m_pScene->m_vhArray.at( m_vidMoving ), + Point_3( pt.x, pt.y, pt.z ) ); + int id1 = m_pScene->m_vhArray.indexOf( vh ); + int id2 = m_pScene->m_vhArray.indexOf( vh, m_vidMoving+1 ); + // remove the duplicate in vhArray + if( id1 != m_vidMoving ) + m_pScene->m_vhArray.removeAt( id1 ); + else if( id2 != -1 ) + m_pScene->m_vhArray.removeAt( id2 ); + m_pScene->m_vhArray[m_vidMoving] = vh; + }//end-if-compute + + // redraw + changed(); updateGL(); + }//end-if-move + + /* FindNb mode - Shift+Left: find the nearest neighbor of the point */ + else if( m_curMode == FINDNB && m_isPress ) { + m_isPress = false; + Vec pt; + if( computeIntersect( event->pos(), pt ) ) { + m_queryPt = Point_3( pt.x, pt.y, pt.z ); + m_nearestNb = m_pScene->m_dt.nearest_vertex( m_queryPt ); + }//end-if-compute + + // redraw + changed(); updateGL(); + }//end-if-findnb + + /* EmptySphere mode - Shift+Left: show the empty sphere of the cell */ + else if( m_curMode == EMPTYSPH && m_isPress ) { + m_isPress = false; + Vec pt; + m_hasEmptyS = computeIntersect( event->pos(), pt ); + if( m_hasEmptyS ) { + m_queryPt = Point_3( pt.x, pt.y, pt.z ); + // find the cell that contains point p in its interior + m_cellContain = m_pScene->m_dt.locate( m_queryPt ); + // show error if point is outside the convex hull + if( m_pScene->m_dt.is_infinite( m_cellContain ) ) { + m_hasEmptyS = false; + displayMessage( tr("Query point is outside the convex hull!") ); + } else { /* compute the empty sphere */ + // find the circumcenter of the four vertices of c + m_centerPt = m_pScene->m_dt.dual( m_cellContain ); + // compute the radius of the empty sphere + m_fREmptyS = sqrt( CGAL::squared_distance( m_centerPt, + m_cellContain->vertex(0)->point() ) ); + } + }//end-if-compute + // redraw + changed(); updateGL(); + }//end-if-emptysphere + + else + QGLViewer::mouseReleaseEvent(event); - else - QGLViewer::mouseReleaseEvent(event); } void Viewer::wheelEvent(QWheelEvent *event) { - // Get event modifiers key -#if QT_VERSION < 0x040000 - // Bug in Qt : use 0x0f00 instead of Qt::KeyButtonMask with Qt versions < 3.1 - const Qt::ButtonState modifiers = (Qt::ButtonState)(event->state() & Qt::KeyButtonMask); -#else - const Qt::KeyboardModifiers modifiers = event->modifiers(); -#endif + // Get event modifiers key + const Qt::KeyboardModifiers modifiers = event->modifiers(); - if( (m_curMode == INSERT_V || m_curMode == FINDNB || m_curMode == EMPTYSPH ) - && modifiers == Qt::SHIFT ) { - // delta() returns the distance that the wheel is rotated, in eighths of a degree. - // note: most mouse types work in steps of 15 degrees - // positive value: rotate forwards away from the user; - // negative value: rotate backwards toward the user. - m_fRadius += (event->delta()*1.f / m_iStep ); // inc-/decrease by 0.1 per step - if( m_fRadius < 0.1f ) - m_fRadius = 0.1f; + if( (m_curMode == INSERT_V || m_curMode == FINDNB || m_curMode == EMPTYSPH ) + && modifiers == Qt::SHIFT ) { + // delta() returns the distance that the wheel is rotated, in eighths of a degree. + // note: most mouse types work in steps of 15 degrees + // positive value: rotate forwards away from the user; + // negative value: rotate backwards toward the user. + m_fRadius += (event->delta()*1.f / m_iStep ); // inc-/decrease by 0.1 per step + if( m_fRadius < 0.1f ) + m_fRadius = 0.1f; - // redraw - updateGL(); - }//end-if-insv + // redraw + changed(); updateGL(); + }//end-if-insv - else if( m_curMode == INSERT_PT && modifiers == Qt::SHIFT ) { - // delta() returns the distance that the wheel is rotated, in eighths of a degree. - // note: most mouse types work in steps of 15 degrees - // positive value: rotate forwards away from the user; - // negative value: rotate backwards toward the user. - float origR = m_fRadius; - m_fRadius += (event->delta()*1.f / m_iStep ); // inc-/decrease by 0.1 per step - if( m_fRadius < 0.1f ) - m_fRadius = 0.1f; - // update the new point and its conflict region - if( m_hasNewPt ) { - origR = m_fRadius / origR; - m_newPt = Point_3( m_newPt.x()*origR, m_newPt.y()*origR, m_newPt.z()*origR ); - // compute the conflict hole induced by point p - computeConflict( m_newPt ); - }//end-if-conflict + else if( m_curMode == INSERT_PT && modifiers == Qt::SHIFT ) { + // delta() returns the distance that the wheel is rotated, in eighths of a degree. + // note: most mouse types work in steps of 15 degrees + // positive value: rotate forwards away from the user; + // negative value: rotate backwards toward the user. + float origR = m_fRadius; + m_fRadius += (event->delta()*1.f / m_iStep ); // inc-/decrease by 0.1 per step + if( m_fRadius < 0.1f ) + m_fRadius = 0.1f; + // update the new point and its conflict region + if( m_hasNewPt ) { + origR = m_fRadius / origR; + m_newPt = Point_3( m_newPt.x()*origR, m_newPt.y()*origR, m_newPt.z()*origR ); + // compute the conflict hole induced by point p + computeConflict( m_newPt ); + }//end-if-conflict - // redraw - updateGL(); - }//end-if-inspt + // redraw + changed(); updateGL(); + }//end-if-inspt - // resize the trackball when moving a point - else if( m_curMode == MOVE && modifiers == Qt::SHIFT && m_isMoving ) { - float origR = m_fRadius; - m_fRadius += (event->delta()*1.f / m_iStep ); // inc-/decrease by 0.1 per step - if( m_fRadius < 0.1f ) - m_fRadius = 0.1f; - origR = m_fRadius / origR; - Point_3 pt = m_pScene->m_vhArray.at( m_vidMoving )->point(); - // note: QList::operator[] return a modifiable reference; - // while QList::at return a const reference - // move_if_no_collision moves the point stored in v to pt - // if there is not already another vertex placed on pt, - // the triangulation is modified s.t. the new position of v is pt; - // otherwise, the vertex at point pt is returned. - Vertex_handle vh = m_pScene->m_dt.move_if_no_collision( - m_pScene->m_vhArray.at( m_vidMoving ), - Point_3( pt.x()*origR, pt.y()*origR, pt.z()*origR ) ); - int id1 = m_pScene->m_vhArray.indexOf( vh ); - int id2 = m_pScene->m_vhArray.indexOf( vh, m_vidMoving+1 ); - // remove the duplicate in vhArray - if( id1 != m_vidMoving ) - m_pScene->m_vhArray.removeAt( id1 ); - else if( id2 != -1 ) - m_pScene->m_vhArray.removeAt( id2 ); - m_pScene->m_vhArray[m_vidMoving] = vh; + // resize the trackball when moving a point + else if( m_curMode == MOVE && modifiers == Qt::SHIFT && m_isMoving ) { + float origR = m_fRadius; + m_fRadius += (event->delta()*1.f / m_iStep ); // inc-/decrease by 0.1 per step + if( m_fRadius < 0.1f ) + m_fRadius = 0.1f; + origR = m_fRadius / origR; + Point_3 pt = m_pScene->m_vhArray.at( m_vidMoving )->point(); + // note: QList::operator[] return a modifiable reference; + // while QList::at return a const reference + // move_if_no_collision moves the point stored in v to pt + // if there is not already another vertex placed on pt, + // the triangulation is modified s.t. the new position of v is pt; + // otherwise, the vertex at point pt is returned. + Vertex_handle vh = m_pScene->m_dt.move_if_no_collision( + m_pScene->m_vhArray.at( m_vidMoving ), + Point_3( pt.x()*origR, pt.y()*origR, pt.z()*origR ) ); + int id1 = m_pScene->m_vhArray.indexOf( vh ); + int id2 = m_pScene->m_vhArray.indexOf( vh, m_vidMoving+1 ); + // remove the duplicate in vhArray + if( id1 != m_vidMoving ) + m_pScene->m_vhArray.removeAt( id1 ); + else if( id2 != -1 ) + m_pScene->m_vhArray.removeAt( id2 ); + m_pScene->m_vhArray[m_vidMoving] = vh; - // redraw - updateGL(); - }//end-if-move + // redraw + changed(); updateGL(); + }//end-if-move - else - QGLViewer::wheelEvent(event); + else + QGLViewer::wheelEvent(event); } void Viewer::keyPressEvent(QKeyEvent *event) { - // Get event modifiers key -#if QT_VERSION < 0x040000 - // Bug in Qt : use 0x0f00 instead of Qt::KeyButtonMask with Qt versions < 3.1 - const Qt::ButtonState modifiers = (Qt::ButtonState)(event->state() & Qt::KeyButtonMask); -#else - const Qt::KeyboardModifiers modifiers = event->modifiers(); -#endif + // Get event modifiers key + const Qt::KeyboardModifiers modifiers = event->modifiers(); - /* Insert the newly inserted point as a vertex */ - if( m_curMode == INSERT_PT && m_hasNewPt - && ( event->key()==Qt::Key_Return || event->key()==Qt::Key_Enter ) - && modifiers==Qt::NoButton ) { - Facet& f = m_boundaryFacets.first(); // a boundary facet, i.e. a pair (cell_handle, i) - // insert_in_hole will create a new vertex by starring a hole - // i.e. delete all conflict cells, create a new vertex, - // and for each boundary facet, create a new cell with the new vertex - // it takes in an iterator range of conflict cells which specifies a hole - // and (begin, i) is a boundary facet that begin is one of the conflict cell - // but begin->neighbor(i) is not - // it returns the handle of the new vertex - m_pScene->m_vhArray.push_back( m_pScene->m_dt.insert_in_hole( m_newPt, // the point - m_conflictCells.begin(), // cell_begin - m_conflictCells.end(), // cell_end - f.first, // cell_handle begin - f.second ) ); // integer i + /* Insert the newly inserted point as a vertex */ + if( m_curMode == INSERT_PT && m_hasNewPt + && ( event->key()==Qt::Key_Return || event->key()==Qt::Key_Enter ) + && modifiers==Qt::NoButton ) { + Facet& f = m_boundaryFacets.first(); // a boundary facet, i.e. a pair (cell_handle, i) + // insert_in_hole will create a new vertex by starring a hole + // i.e. delete all conflict cells, create a new vertex, + // and for each boundary facet, create a new cell with the new vertex + // it takes in an iterator range of conflict cells which specifies a hole + // and (begin, i) is a boundary facet that begin is one of the conflict cell + // but begin->neighbor(i) is not + // it returns the handle of the new vertex + m_pScene->m_vhArray.push_back( m_pScene->m_dt.insert_in_hole( m_newPt, // the point + m_conflictCells.begin(), // cell_begin + m_conflictCells.end(), // cell_end + f.first, // cell_handle begin + f.second ) ); // integer i - m_hasNewPt = false; - // erase old conflict hole info - m_boundaryFacets.clear(); - m_conflictCells.clear(); + m_hasNewPt = false; + // erase old conflict hole info + m_boundaryFacets.clear(); + m_conflictCells.clear(); - // redraw - updateGL(); - }//end-if-insVertex + // redraw + changed(); updateGL(); + }//end-if-insVertex - /* Cancel the newly inserted point and its conflict region */ - else if( m_curMode == INSERT_PT && m_hasNewPt - && event->key()==Qt::Key_Escape && modifiers==Qt::NoButton ) { - m_hasNewPt = false; - // erase old conflict hole info - m_boundaryFacets.clear(); - m_conflictCells.clear(); + /* Cancel the newly inserted point and its conflict region */ + else if( m_curMode == INSERT_PT && m_hasNewPt + && event->key()==Qt::Key_Escape && modifiers==Qt::NoButton ) { + m_hasNewPt = false; + // erase old conflict hole info + m_boundaryFacets.clear(); + m_conflictCells.clear(); - // redraw - updateGL(); - }//end-if-escapeIns + // redraw + changed(); updateGL(); + }//end-if-escapeIns - /* Delete selected points */ - else if( m_curMode == SELECT - && event->key()==Qt::Key_Delete && modifiers==Qt::NoButton ) { - // sort selected id's in descending order - qSort(m_vidSeled.begin(), m_vidSeled.end(), qGreater()); - for(QList::iterator vit=m_vidSeled.begin(); vitm_dt.remove( m_pScene->m_vhArray.takeAt( *vit ) ); - } - // clear the selection buffer - m_vidSeled.clear(); + /* Delete selected points */ + else if( m_curMode == SELECT + && event->key()==Qt::Key_Delete && modifiers==Qt::NoButton ) { + // sort selected id's in descending order + qSort(m_vidSeled.begin(), m_vidSeled.end(), qGreater()); + for(QList::iterator vit=m_vidSeled.begin(); vitm_dt.remove( m_pScene->m_vhArray.takeAt( *vit ) ); + } + // clear the selection buffer + m_vidSeled.clear(); - // redraw - updateGL(); - }//end-if-del + // redraw + changed(); updateGL(); + }//end-if-del + + /* Cancel the selection */ + else if( m_curMode == SELECT + && event->key()==Qt::Key_Escape && modifiers==Qt::NoButton ) { + // clear the selection buffer + for(QList::iterator iit=m_vidSeled.begin(); iitm_vhArray.at(*iit)->setSeled( false ); + } + m_vidSeled.clear(); + + // redraw + changed(); updateGL(); + }//end-if-escapeSel + + + /* Show/hide the trackball when drawing the empty sphere */ + else if( m_curMode == EMPTYSPH + && event->key()==Qt::Key_S && modifiers==Qt::NoButton ) { + m_showTrackball = !m_showTrackball; + // redraw + changed(); updateGL(); + }//end-if-showBall + + else + QGLViewer::keyPressEvent(event); - /* Cancel the selection */ - else if( m_curMode == SELECT - && event->key()==Qt::Key_Escape && modifiers==Qt::NoButton ) { - // clear the selection buffer - for(QList::iterator iit=m_vidSeled.begin(); iitm_vhArray.at(*iit)->setSeled( false ); - } - m_vidSeled.clear(); // redraw - updateGL(); - }//end-if-escapeSel - - - /* Show/hide the trackball when drawing the empty sphere */ - else if( m_curMode == EMPTYSPH - && event->key()==Qt::Key_S && modifiers==Qt::NoButton ) { - m_showTrackball = !m_showTrackball; - // redraw - updateGL(); - }//end-if-showBall - - else - QGLViewer::keyPressEvent(event); + changed(); updateGL(); } /*************************************************************/ @@ -1134,161 +2226,687 @@ void Viewer::keyPressEvent(QKeyEvent *event) bool Viewer::computeIntersect( const QPoint & pos, Vec & pt ) { - Vec eye, dir; - // Compute eye position and direction to the clicked point, - // used to draw a representation of the intersecting line - camera()->convertClickToLine( pos, eye, dir ); - // Compute the intersection point with the sphere - // note that the center of the sphere is at the origin (0, 0, 0) - // thus, (1) pt = eye + t*dir and (2) dist( pt, origin ) = radius - // i.e. (x_eye + t*x_dir)^2 + (y_eye + t*y_dir)^2 + (z_eye + t*z_dir)^2 = r^2 - // --> t^2( dir*dir ) + 2t( eye*dir ) + eye*eye - r^2 = 0 - // where "dir*dir" is the dot product of vector dir - // we need to solve t and the smaller t (nearer to eye position) is what we want - float a = dir*dir; - float b = eye*dir; - float c = eye*eye - m_fRadius*m_fRadius; - float delta = b*b - a*c; - if( delta < 0 ) { - displayMessage( tr("Point is not on the sphere!") ); - return false; - } else { - float t = ( (-1.)*b - sqrt(delta) ) / a; - pt = eye + t*dir; - return true; - } + Vec eye, dir; + // Compute eye position and direction to the clicked point, + // used to draw a representation of the intersecting line + camera()->convertClickToLine( pos, eye, dir ); + // Compute the intersection point with the sphere + // note that the center of the sphere is at the origin (0, 0, 0) + // thus, (1) pt = eye + t*dir and (2) dist( pt, origin ) = radius + // i.e. (x_eye + t*x_dir)^2 + (y_eye + t*y_dir)^2 + (z_eye + t*z_dir)^2 = r^2 + // --> t^2( dir*dir ) + 2t( eye*dir ) + eye*eye - r^2 = 0 + // where "dir*dir" is the dot product of vector dir + // we need to solve t and the smaller t (nearer to eye position) is what we want + float a = dir*dir; + float b = eye*dir; + float c = eye*eye - m_fRadius*m_fRadius; + float delta = b*b - a*c; + if( delta < 0 ) { + displayMessage( tr("Point is not on the sphere!") ); + return false; + } else { + float t = ( (-1.)*b - sqrt(delta) ) / a; + pt = eye + t*dir; + return true; + } } void Viewer::computeConflict( Point_3 pt ) { - // find the cell that contains point p in its interior - m_cellContain = m_pScene->m_dt.locate( pt ); - // erase old conflict hole info - m_boundaryFacets.clear(); - m_conflictCells.clear(); - // show msg if point is outside the convex hull - if( m_pScene->m_dt.is_infinite( m_cellContain ) ) - displayMessage( tr("Note: point is outside the convex hull.") ); - // compute the conflict hole induced by point p - m_pScene->m_dt.find_conflicts( pt, // the point - m_cellContain, // starting cell that must be in conflict - std::back_inserter(m_boundaryFacets), // the facets on the boundary - std::back_inserter(m_conflictCells) ); // the cells in conflict + // find the cell that contains point p in its interior + m_cellContain = m_pScene->m_dt.locate( pt ); + // erase old conflict hole info + m_boundaryFacets.clear(); + m_conflictCells.clear(); + // show msg if point is outside the convex hull + if( m_pScene->m_dt.is_infinite( m_cellContain ) ) + displayMessage( tr("Note: point is outside the convex hull.") ); + // compute the conflict hole induced by point p + m_pScene->m_dt.find_conflicts( pt, // the point + m_cellContain, // starting cell that must be in conflict + std::back_inserter(m_boundaryFacets), // the facets on the boundary + std::back_inserter(m_conflictCells) ); // the cells in conflict } /*************************************************************/ /* Animation functions */ void Viewer::toggleIncremental(bool on) { - if( on ) { // play - if( m_incrementalPts.isEmpty() ) { - /* start play */ - if( m_pScene->m_dt.number_of_vertices() == 0 ) { - CGAL::Random_points_in_cube_3 pts_generator(1.0); - CGAL::cpp11::copy_n( pts_generator, 100, std::back_inserter(m_incrementalPts) ); - } else { - for(QList::iterator vit = m_pScene->m_vhArray.begin(); - vit < m_pScene->m_vhArray.end(); ++vit) { - m_incrementalPts.push_back( (*vit)->point() ); - }//end-for - // erase existing vertices - initClean(); - }//end-if-pts - // sorts points in a way that improves space locality - CGAL::spatial_sort( m_incrementalPts.begin(), m_incrementalPts.end() ); - // set the current to "hightlight the new point" - m_curStep = INIT; - }/* else resume play */ + if( on ) { // play + if( m_incrementalPts.isEmpty() ) { + /* start play */ + if( m_pScene->m_dt.number_of_vertices() == 0 ) { + CGAL::Random_points_in_cube_3 pts_generator(1.0); + CGAL::cpp11::copy_n( pts_generator, 100, std::back_inserter(m_incrementalPts) ); + } else { + for(QList::iterator vit = m_pScene->m_vhArray.begin(); + vit < m_pScene->m_vhArray.end(); ++vit) { + m_incrementalPts.push_back( (*vit)->point() ); + }//end-for + // erase existing vertices + initClean(); + }//end-if-pts + // sorts points in a way that improves space locality + CGAL::spatial_sort( m_incrementalPts.begin(), m_incrementalPts.end() ); + // set the current to "hightlight the new point" + m_curStep = INIT; + }/* else resume play */ - // set up the timer - m_pTimer->start(1000); - } else { // pause - m_pTimer->stop(); - } + // set up the timer + m_pTimer->start(1000); + } else { // pause + m_pTimer->stop(); + } - // redraw - updateGL(); + // redraw + changed(); updateGL(); } void Viewer::stopIncremental() { - if( !m_incrementalPts.isEmpty() ) { - // will call toggleIncremental to stop the timer + if( !m_incrementalPts.isEmpty() ) { + // will call toggleIncremental to stop the timer Q_EMIT( stopIncAnimation() ); - // insert the rest points - for(QList::iterator pit=m_incrementalPts.begin(); - pit < m_incrementalPts.end(); ++pit) { - Vertex_handle hint; - if( m_pScene->m_vhArray.isEmpty() ) { - hint = m_pScene->m_dt.insert( *pit ); - } else { - hint = m_pScene->m_vhArray.last(); - hint = m_pScene->m_dt.insert( *pit, hint ); - } - m_pScene->m_vhArray.push_back( hint ); + // insert the rest points + for(QList::iterator pit=m_incrementalPts.begin(); + pit < m_incrementalPts.end(); ++pit) { + Vertex_handle hint; + if( m_pScene->m_vhArray.isEmpty() ) { + hint = m_pScene->m_dt.insert( *pit ); + } else { + hint = m_pScene->m_vhArray.last(); + hint = m_pScene->m_dt.insert( *pit, hint ); + } + m_pScene->m_vhArray.push_back( hint ); + } + m_incrementalPts.clear(); } - m_incrementalPts.clear(); - } - // redraw - updateGL(); + // redraw + changed(); updateGL(); } void Viewer::incremental_insert() { - Vertex_handle hint; - if( !m_incrementalPts.isEmpty() ) { - switch( m_curStep ) { - case INIT: // end of INIT: get the next-to-insert point - m_curIncPt = m_incrementalPts.at(0); - m_curStep = NEWPT; - break; - case NEWPT: // end of NEWPT: locate the cell containing the point - if( m_pScene->m_dt.is_valid() && m_pScene->m_dt.dimension() == 3 ) { - computeConflict( m_curIncPt ); - m_curStep = CELL; - } - else { - // popup the first point and insert it - m_curIncPt = m_incrementalPts.takeFirst(); - if( m_pScene->m_vhArray.isEmpty() ) { - hint = m_pScene->m_dt.insert( m_curIncPt ); - } - else { - hint = m_pScene->m_vhArray.last(); - hint = m_pScene->m_dt.insert( m_curIncPt, hint ); - } - m_pScene->m_vhArray.push_back( hint ); + Vertex_handle hint; + if( !m_incrementalPts.isEmpty() ) { + switch( m_curStep ) { + case INIT: // end of INIT: get the next-to-insert point + m_curIncPt = m_incrementalPts.at(0); + m_curStep = NEWPT; + break; + case NEWPT: // end of NEWPT: locate the cell containing the point + if( m_pScene->m_dt.is_valid() && m_pScene->m_dt.dimension() == 3 ) { + computeConflict( m_curIncPt ); + m_curStep = CELL; + } + else { + // popup the first point and insert it + m_curIncPt = m_incrementalPts.takeFirst(); + if( m_pScene->m_vhArray.isEmpty() ) { + hint = m_pScene->m_dt.insert( m_curIncPt ); + } + else { + hint = m_pScene->m_vhArray.last(); + hint = m_pScene->m_dt.insert( m_curIncPt, hint ); + } + m_pScene->m_vhArray.push_back( hint ); + m_curStep = INIT; + } + break; + case CELL: // end of CELL: compute the conflict region + m_curStep = CONFLICT; + break; + case CONFLICT: // end of CONFLICT: do the insertion and go back to INIT + // popup the first point and insert it + m_curIncPt = m_incrementalPts.takeFirst(); + if( m_pScene->m_vhArray.isEmpty() ) { + hint = m_pScene->m_dt.insert( m_curIncPt ); + } else { + hint = m_pScene->m_vhArray.last(); + hint = m_pScene->m_dt.insert( m_curIncPt, hint ); + } + m_pScene->m_vhArray.push_back( hint ); + m_curStep = INIT; + break; + }//end-of-switch + } else { + /* if finished, then start over */ + for(QList::iterator vit = m_pScene->m_vhArray.begin(); + vit < m_pScene->m_vhArray.end(); ++vit) { + m_incrementalPts.push_back( (*vit)->point() ); + }//end-for + // erase existing vertices + initClean(); + // set the current to "hightlight the new point" m_curStep = INIT; - } - break; - case CELL: // end of CELL: compute the conflict region - m_curStep = CONFLICT; - break; - case CONFLICT: // end of CONFLICT: do the insertion and go back to INIT - // popup the first point and insert it - m_curIncPt = m_incrementalPts.takeFirst(); - if( m_pScene->m_vhArray.isEmpty() ) { - hint = m_pScene->m_dt.insert( m_curIncPt ); - } else { - hint = m_pScene->m_vhArray.last(); - hint = m_pScene->m_dt.insert( m_curIncPt, hint ); - } - m_pScene->m_vhArray.push_back( hint ); - m_curStep = INIT; - break; - }//end-of-switch - } else { - /* if finished, then start over */ - for(QList::iterator vit = m_pScene->m_vhArray.begin(); - vit < m_pScene->m_vhArray.end(); ++vit) { - m_incrementalPts.push_back( (*vit)->point() ); - }//end-for - // erase existing vertices - initClean(); - // set the current to "hightlight the new point" - m_curStep = INIT; - } + } + + // redraw + changed(); updateGL(); +} + + +void Viewer::draw_cylinder(float R, int prec, std::vector *vertices, std::vector *normals) +{ + vertices->resize(0); + normals->resize(0); + // int rings=360/prec, sectors=360/prec; + // float T, P; + // float x[4],y[4],z[4]; + //Closing nicely the tubes will cause z-fighting and the spherical parts will get all messy + /* +//top of the cylinder + for(int t=0; t<360; t+=sectors) + { + + vertices->push_back(0); + vertices->push_back(R+1); + vertices->push_back(0); + + + normals->push_back(0); + normals->push_back(1); + normals->push_back(0); + + + + P = rings*M_PI/180.0; + T = t*M_PI/180.0; + x[1] = sin(P) * cos(T) ; + z[1] = sin(P) * sin(T) ; + y[1] = cos(P); + vertices->push_back(R * x[1]); + vertices->push_back(R * y[1]+1); + vertices->push_back(R * z[1]); + + + normals->push_back(x[1]); + normals->push_back(y[1]); + normals->push_back(z[1]); + + // + P = rings*M_PI/180.0; + T = (t+sectors)*M_PI/180.0; + x[2] = sin(P) * cos(T) ; + z[2] = sin(P) * sin(T) ; + y[2] = cos(P); + vertices->push_back(R * x[2]); + vertices->push_back(R * y[2]+1); + vertices->push_back(R * z[2]); + + normals->push_back(x[2]); + normals->push_back(y[2]); + normals->push_back(z[2]); + + } + //Body of the sphere + for (int p=rings; p<90; p+=rings) + for(int t=0; t<360; t+=sectors) + { + //A + P = p*M_PI/180.0; + T = t*M_PI/180.0; + x[0] = sin(P) * cos(T) ; + z[0] = sin(P) * sin(T) ; + y[0] = cos(P); + + vertices->push_back(R * x[0]); + vertices->push_back(R * y[0]+1); + vertices->push_back(R * z[0]); + + + normals->push_back(x[0]); + normals->push_back(y[0]); + normals->push_back(z[0]); + + //B + P = (p+rings)*M_PI/180.0; + T = t*M_PI/180.0; + x[1] = sin(P) * cos(T) ; + z[1] = sin(P) * sin(T) ; + y[1] = cos(P); + vertices->push_back(R * x[1]); + vertices->push_back(R * y[1]+1); + vertices->push_back(R * z[1]); + + + normals->push_back(x[1]); + normals->push_back(y[1]); + normals->push_back(z[1]); + + //C + P = p*M_PI/180.0; + T = (t+sectors)*M_PI/180.0; + x[2] = sin(P) * cos(T) ; + z[2] = sin(P) * sin(T) ; + y[2] = cos(P); + vertices->push_back(R * x[2]); + vertices->push_back(R * y[2]+1); + vertices->push_back(R * z[2]); + + + normals->push_back(x[2]); + normals->push_back(y[2]); + normals->push_back(z[2]); + //D + P = (p+rings)*M_PI/180.0; + T = (t+sectors)*M_PI/180.0; + x[3] = sin(P) * cos(T) ; + z[3] = sin(P) * sin(T) ; + y[3] = cos(P); + vertices->push_back(R * x[3]); + vertices->push_back(R * y[3]+1); + vertices->push_back(R * z[3]); + + + normals->push_back(x[3]); + normals->push_back(y[3]); + normals->push_back(z[3]); + + + + vertices->push_back(R * x[1]); + vertices->push_back(R * y[1]+1); + vertices->push_back(R * z[1]); + + + normals->push_back(x[1]); + normals->push_back(y[1]); + normals->push_back(z[1]); + + vertices->push_back(R * x[2]); + vertices->push_back(R * y[2]+1); + vertices->push_back(R * z[2]); + + + normals->push_back(x[2]); + normals->push_back(y[2]); + normals->push_back(z[2]); + + } + +*/ + //body of the cylinder + for(int d = 0; d<360; d+= 360/prec) + { + + //point A1 + float D = d*M_PI/180.0; + vertices->push_back(R * sin(D)); + vertices->push_back(0); + vertices->push_back(R * cos(D)); + + normals->push_back(sin(D)); + normals->push_back(0); + normals->push_back(cos(D)); + + //point B1 + vertices->push_back(R * sin(D)); + vertices->push_back(1); + vertices->push_back(R * cos(D)); + + normals->push_back(sin(D)); + normals->push_back(0); + normals->push_back(cos(D)); + + //point C1 + D = (d+360/prec)*M_PI/180.0; + vertices->push_back(R * sin(D)); + vertices->push_back(1); + vertices->push_back(R * cos(D)); + + normals->push_back(sin(D)); + normals->push_back(0); + normals->push_back(cos(D)); + + //point A2 + D = (d+360/prec)*M_PI/180.0; + vertices->push_back(R * sin(D)); + vertices->push_back(1); + vertices->push_back(R * cos(D)); + + normals->push_back(sin(D)); + normals->push_back(0); + normals->push_back(cos(D)); + + //point B2 + vertices->push_back(R * sin(D)); + vertices->push_back(0); + vertices->push_back(R * cos(D)); + + normals->push_back(sin(D)); + normals->push_back(0); + normals->push_back(cos(D)); + + //point C2 + D = d*M_PI/180.0; + vertices->push_back(R * sin(D)); + vertices->push_back(0); + vertices->push_back(R * cos(D)); + + normals->push_back(sin(D)); + normals->push_back(0); + normals->push_back(cos(D)); + + } + /* + //bottom of the cylinder + for(int t=0; t<360; t+=sectors) + { + + vertices->push_back(0); + vertices->push_back(-R); + vertices->push_back(0); + + + normals->push_back(0); + normals->push_back(-1); + normals->push_back(0); + + + + P = rings*M_PI/180.0; + T = t*M_PI/180.0; + x[1] = sin(P) * cos(T) ; + z[1] = sin(P) * sin(T) ; + y[1] = cos(P); + vertices->push_back(R * x[1]); + vertices->push_back(R * y[1]); + vertices->push_back(R * z[1]); + + + normals->push_back(x[1]); + normals->push_back(y[1]); + normals->push_back(z[1]); + + // + P = rings*M_PI/180.0; + T = (t+sectors)*M_PI/180.0; + x[2] = sin(P) * cos(T) ; + z[2] = sin(P) * sin(T) ; + y[2] = cos(P); + vertices->push_back(R * x[2]); + vertices->push_back(R * y[2]); + vertices->push_back(R * z[2]); + + normals->push_back(x[2]); + normals->push_back(y[2]); + normals->push_back(z[2]); + + } + //Body of the sphere + for (int p=90; p<180; p+=rings) + for(int t=0; t<360; t+=sectors) + { + //A + P = p*M_PI/180.0; + T = t*M_PI/180.0; + x[0] = sin(P) * cos(T) ; + z[0] = sin(P) * sin(T) ; + y[0] = cos(P); + + vertices->push_back(R * x[0]); + vertices->push_back(R * y[0]); + vertices->push_back(R * z[0]); + + + normals->push_back(x[0]); + normals->push_back(y[0]); + normals->push_back(z[0]); + + //B + P = (p+rings)*M_PI/180.0; + T = t*M_PI/180.0; + x[1] = sin(P) * cos(T) ; + z[1] = sin(P) * sin(T) ; + y[1] = cos(P); + vertices->push_back(R * x[1]); + vertices->push_back(R * y[1]); + vertices->push_back(R * z[1]); + + + normals->push_back(x[1]); + normals->push_back(y[1]); + normals->push_back(z[1]); + + //C + P = p*M_PI/180.0; + T = (t+sectors)*M_PI/180.0; + x[2] = sin(P) * cos(T) ; + z[2] = sin(P) * sin(T) ; + y[2] = cos(P); + vertices->push_back(R * x[2]); + vertices->push_back(R * y[2]); + vertices->push_back(R * z[2]); + + + normals->push_back(x[2]); + normals->push_back(y[2]); + normals->push_back(z[2]); + //D + P = (p+rings)*M_PI/180.0; + T = (t+sectors)*M_PI/180.0; + x[3] = sin(P) * cos(T) ; + z[3] = sin(P) * sin(T) ; + y[3] = cos(P); + vertices->push_back(R * x[3]); + vertices->push_back(R * y[3]); + vertices->push_back(R * z[3]); + + + normals->push_back(x[3]); + normals->push_back(y[3]); + normals->push_back(z[3]); + + + + vertices->push_back(R * x[1]); + vertices->push_back(R * y[1]); + vertices->push_back(R * z[1]); + + + normals->push_back(x[1]); + normals->push_back(y[1]); + normals->push_back(z[1]); + + vertices->push_back(R * x[2]); + vertices->push_back(R * y[2]); + vertices->push_back(R * z[2]); + + + normals->push_back(x[2]); + normals->push_back(y[2]); + normals->push_back(z[2]); + + }*/ + + +} + +void Viewer::draw_sphere(float R, int prec, std::vector *vertices, std::vector *normals) +{ + + vertices->resize(0); + normals->resize(0); + int rings=180/prec, sectors=360/prec; + float T, P; + float x[4],y[4],z[4]; + + + //Top of the sphere + for(int t=0; t<360; t+=sectors) + { + + vertices->push_back(0); + vertices->push_back(0); + vertices->push_back(R); + + + normals->push_back(0); + normals->push_back(0); + normals->push_back(1); + + + + P = rings*M_PI/180.0; + T = t*M_PI/180.0; + x[1] = sin(P) * cos(T) ; + y[1] = sin(P) * sin(T) ; + z[1] = cos(P); + vertices->push_back(R * x[1]); + vertices->push_back(R * y[1]); + vertices->push_back(R * z[1]); + + + normals->push_back(x[1]); + normals->push_back(y[1]); + normals->push_back(z[1]); + + // + P = rings*M_PI/180.0; + T = (t+sectors)*M_PI/180.0; + x[2] = sin(P) * cos(T) ; + y[2] = sin(P) * sin(T) ; + z[2] = cos(P); + vertices->push_back(R * x[2]); + vertices->push_back(R * y[2]); + vertices->push_back(R * z[2]); + + normals->push_back(x[2]); + normals->push_back(y[2]); + normals->push_back(z[2]); + + } + + //Body of the sphere + for (int p=rings; p<180-rings; p+=rings) + for(int t=0; t<360; t+=sectors) + { + //A + P = p*M_PI/180.0; + T = t*M_PI/180.0; + x[0] = sin(P) * cos(T) ; + y[0] = sin(P) * sin(T) ; + z[0] = cos(P); + + vertices->push_back(R * x[0]); + vertices->push_back(R * y[0]); + vertices->push_back(R * z[0]); + + + normals->push_back(x[0]); + normals->push_back(y[0]); + normals->push_back(z[0]); + + //B + P = (p+rings)*M_PI/180.0; + T = t*M_PI/180.0; + x[1] = sin(P) * cos(T) ; + y[1] = sin(P) * sin(T) ; + z[1] = cos(P); + vertices->push_back(R * x[1]); + vertices->push_back(R * y[1]); + vertices->push_back(R * z[1]); + + + normals->push_back(x[1]); + normals->push_back(y[1]); + normals->push_back(z[1]); + + //C + P = p*M_PI/180.0; + T = (t+sectors)*M_PI/180.0; + x[2] = sin(P) * cos(T) ; + y[2] = sin(P) * sin(T) ; + z[2] = cos(P); + vertices->push_back(R * x[2]); + vertices->push_back(R * y[2]); + vertices->push_back(R * z[2]); + + + normals->push_back(x[2]); + normals->push_back(y[2]); + normals->push_back(z[2]); + //D + P = (p+rings)*M_PI/180.0; + T = (t+sectors)*M_PI/180.0; + x[3] = sin(P) * cos(T) ; + y[3] = sin(P) * sin(T) ; + z[3] = cos(P); + vertices->push_back(R * x[3]); + vertices->push_back(R * y[3]); + vertices->push_back(R * z[3]); + + + normals->push_back(x[3]); + normals->push_back(y[3]); + normals->push_back(z[3]); + + + + vertices->push_back(R * x[1]); + vertices->push_back(R * y[1]); + vertices->push_back(R * z[1]); + + + normals->push_back(x[1]); + normals->push_back(y[1]); + normals->push_back(z[1]); + + vertices->push_back(R * x[2]); + vertices->push_back(R * y[2]); + vertices->push_back(R * z[2]); + + + normals->push_back(x[2]); + normals->push_back(y[2]); + normals->push_back(z[2]); + + } + //Bottom of the sphere + for(int t=0; t<360; t+=sectors) + { + + + vertices->push_back(0); + vertices->push_back(0); + vertices->push_back(-R); + + + normals->push_back(0); + normals->push_back(0); + normals->push_back(-1); + + + P = (180-rings)*M_PI/180.0; + T = t*M_PI/180.0; + x[1] = sin(P) * cos(T) ; + y[1] = sin(P) * sin(T) ; + z[1] = cos(P); + vertices->push_back(R * x[1]); + vertices->push_back(R * y[1]); + vertices->push_back(R * z[1]); + + + normals->push_back(x[1]); + normals->push_back(y[1]); + normals->push_back(z[1]); + + + P = (180-rings)*M_PI/180.0; + T = (t+sectors)*M_PI/180.0; + x[2] = sin(P) * cos(T) ; + y[2] = sin(P) * sin(T) ; + z[2] = cos(P); + vertices->push_back(R * x[2]); + vertices->push_back(R * y[2]); + vertices->push_back(R * z[2]); + + + normals->push_back(x[2]); + normals->push_back(y[2]); + normals->push_back(z[2]); + + } - // redraw - updateGL(); } diff --git a/Triangulation_3/demo/Triangulation_3/Viewer.h b/Triangulation_3/demo/Triangulation_3/Viewer.h index a0e09c036ec..4384cc316bc 100644 --- a/Triangulation_3/demo/Triangulation_3/Viewer.h +++ b/Triangulation_3/demo/Triangulation_3/Viewer.h @@ -8,18 +8,23 @@ #include #include "PreferenceDlg.h" +#include +#include +#include +#include +#include #include using namespace qglviewer; class MainWindow; -class Viewer : public QGLViewer { +class Viewer : public QGLViewer, QOpenGLFunctions_3_3_Core { Q_OBJECT public: Viewer(QWidget* parent) - : QGLViewer(parent) + : QGLViewer(CGAL::Qt::createOpenGLContext(),parent) , m_showAxis(false) , m_showVertex(true) , m_showDEdge(true) @@ -36,8 +41,53 @@ public: , m_hasEmptyS(false) , m_showTrackball(true) , m_pDlgPrefer(NULL) - {} + { + pos_emptyFacet = new std::vector(); + pos_emptySphere= new std::vector(); + points_emptySphere = new std::vector(); + pos_points = new std::vector(); + pos_newPoint = new std::vector(); + pos_selectedVertex = new std::vector(); + pos_movingPoint = new std::vector(); + pos_queryPoint = new std::vector(); + pos_trackBall = new std::vector(); + pos_voronoi = new std::vector(); + pos_delaunay = new std::vector(); + pos_facets = new std::vector(); + pos_newFacet = new std::vector(); + pos_nearest_neighbor = new std::vector(); + points_locationSphere = new std::vector(); + points_cylinder = new std::vector(); + normals_cylinder = new std::vector(); + points_sphere = new std::vector(); + points_trackBall = new std::vector(); + normals_sphere = new std::vector(); + normals_emptySphere = new std::vector(); + normals_trackBall= new std::vector(); + transfo1_voronoi = new std::vector(); + transfo2_voronoi = new std::vector(); + transfo3_voronoi = new std::vector(); + transfo4_voronoi = new std::vector(); + transfo1_delaunay = new std::vector(); + transfo2_delaunay = new std::vector(); + transfo3_delaunay = new std::vector(); + transfo4_delaunay = new std::vector(); + incremental_points = new std::vector(); + incremental_next_point = new std::vector(); + incremental_facet = new std::vector(); + incremental_conflict = new std::vector(); + } + ~Viewer() + { + for(int i=0; i< vboSize; i++) + buffers[i].destroy(); + + for(int i=0; i< vaoSize; i++) + vao[i].destroy(); + + + } enum Mode { NONE, INSERT_V, INSERT_PT, MOVE, SELECT, FINDNB, EMPTYSPH }; public: @@ -71,23 +121,11 @@ public: // In other words, there is no toColor(), toImage(), or toPixmap() functions in QVariant. // Instead, use the QVariant::value() or the qVariantValue() template function m_colorVertex = settings.value( "Show/vertexcolor", QColor(255, 150, 0) ).value(); -#if QT_VERSION >= 0x040600 m_fSizeVertex = settings.value( "Show/vertexsize", 0.04f ).toFloat(); -#else - m_fSizeVertex = settings.value( "Show/vertexsize", 0.04f ).value(); -#endif m_colorDEdge = settings.value( "Show/dedgecolor", QColor(0, 255, 0) ).value(); -#if QT_VERSION >= 0x040600 m_fSizeDEdge = settings.value( "Show/dedgesize", 0.01f ).toFloat(); -#else - m_fSizeDEdge = settings.value( "Show/dedgesize", 0.01f ).value(); -#endif m_colorVEdge = settings.value( "Show/vedgecolor", QColor(0, 0, 255) ).value(); -#if QT_VERSION >= 0x040600 m_fSizeVEdge = settings.value( "Show/vedgesize", 0.01f ).toFloat(); -#else - m_fSizeVEdge = settings.value( "Show/vedgesize", 0.01f ).value(); -#endif m_colorFacet = settings.value( "Show/facetcolor", QColor(255, 255, 0, 96) ).value(); m_colorTrackball = settings.value( "Show/ballcolor", @@ -116,6 +154,11 @@ public: public Q_SLOTS: // clear scene + void changed() + { + compute_elements(); + are_buffers_initialized = false; + } void clear() { m_pScene->eraseOldData(); m_hasNewPt = false; @@ -212,14 +255,11 @@ protected: private: // draw a 3d effect vertex - void drawVertex(const Point_3& p, const QColor& clr, float r); + void drawVertex(const Point_3& p, const QColor& clr, float r, std::vector *vertices); // draw a 3d effect edge - void drawEdge(const Point_3& from, const Point_3& to, const QColor& clr, float r); + void drawEdge(const Point_3& from, const Point_3& to, const QColor& clr, float r, std::vector *vertices); // draw a facet - void drawFacet(const Triangle_3& t, const QColor& clr); - // draw a sphere with/without Axis - void drawSphere(float r, const QColor& clr, const Point_3& center=CGAL::ORIGIN); - + void drawFacet(const Triangle_3& t, const QColor& clr, std::vector *vertices); // test whether the give 3D point is on the sphere inline bool isOnSphere( const Point_3 & pt ) { return ( (pt.x()*pt.x() + pt.y()*pt.y() + pt.z()*pt.z()) == (m_fRadius*m_fRadius) ); @@ -230,6 +270,7 @@ private: // compute the conflict region void computeConflict( Point_3 pt ); + private: Scene* m_pScene; // play timer @@ -285,6 +326,71 @@ private: QColor m_colorEmptySphere; // trackball resizing fineness int m_iStep; + + + QColor color; + static const int vaoSize = 29; + static const int vboSize = 33; + // define material + QVector4D ambient; + QVector4D diffuse; + QVector4D specular; + GLfloat shininess ; + int poly_vertexLocation[3]; + int normalsLocation[3]; + int mvpLocation[3]; + int mvLocation[2]; + int centerLocation[5]; + int colorLocation[3]; + int lightLocation[5*2]; + + bool are_buffers_initialized; + std::vector *pos_emptyFacet; + std::vector *pos_emptySphere; + std::vector *points_emptySphere; + std::vector *pos_points; + std::vector *pos_newPoint; + std::vector *pos_selectedVertex; + std::vector *pos_movingPoint; + std::vector *pos_queryPoint; + std::vector *pos_trackBall; + std::vector *points_trackBall; + std::vector *pos_voronoi; + std::vector *pos_delaunay; + std::vector *pos_facets; + std::vector *pos_newFacet; + std::vector *pos_nearest_neighbor; + std::vector *points_locationSphere; + std::vector *points_cylinder; + std::vector *normals_cylinder; + std::vector *points_sphere; + std::vector *normals_sphere; + std::vector *normals_emptySphere; + std::vector *normals_trackBall; + std::vector *transfo1_voronoi; + std::vector *transfo2_voronoi; + std::vector *transfo3_voronoi; + std::vector *transfo4_voronoi; + std::vector *transfo1_delaunay; + std::vector *transfo2_delaunay; + std::vector *transfo3_delaunay; + std::vector *transfo4_delaunay; + std::vector *incremental_points; + std::vector *incremental_next_point; + std::vector *incremental_facet; + std::vector *incremental_conflict; + + QOpenGLBuffer buffers[vboSize]; + QOpenGLVertexArrayObject vao[vaoSize]; + QOpenGLShaderProgram rendering_program; + QOpenGLShaderProgram rendering_program_spheres; + QOpenGLShaderProgram rendering_program_cylinders; + void initialize_buffers(); + void compute_elements(); + void attrib_buffers(QGLViewer*); + void compile_shaders(); + void draw_cylinder(float R, int prec, std::vector *vertices, std::vector *normals); + void draw_sphere(float R, int prec, std::vector *vertices, std::vector *normals); }; #endif diff --git a/Triangulation_3/demo/Triangulation_3_Geomview_demos/CMakeLists.txt b/Triangulation_3/demo/Triangulation_3_Geomview_demos/CMakeLists.txt index 0550a778344..82989fc82de 100644 --- a/Triangulation_3/demo/Triangulation_3_Geomview_demos/CMakeLists.txt +++ b/Triangulation_3/demo/Triangulation_3_Geomview_demos/CMakeLists.txt @@ -4,11 +4,9 @@ project( Triangulation_3_Demo ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() find_package(CGAL QUIET COMPONENTS Core ) diff --git a/Triangulation_3/examples/Triangulation_3/CMakeLists.txt b/Triangulation_3/examples/Triangulation_3/CMakeLists.txt index 1ac7540f591..d14939667ae 100644 --- a/Triangulation_3/examples/Triangulation_3/CMakeLists.txt +++ b/Triangulation_3/examples/Triangulation_3/CMakeLists.txt @@ -4,14 +4,8 @@ project( Triangulation_3_example ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 2.6) - if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) - else() - cmake_policy(VERSION 2.6) - endif() -endif() +cmake_minimum_required(VERSION 2.8.11) + find_package(CGAL QUIET COMPONENTS Core ) diff --git a/Triangulation_3/test/Triangulation_3/CMakeLists.txt b/Triangulation_3/test/Triangulation_3/CMakeLists.txt index 81584049232..a045e1a5600 100644 --- a/Triangulation_3/test/Triangulation_3/CMakeLists.txt +++ b/Triangulation_3/test/Triangulation_3/CMakeLists.txt @@ -4,14 +4,8 @@ project( Triangulation_3_test ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 2.6) - if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) - else() - cmake_policy(VERSION 2.6) - endif() -endif() +cmake_minimum_required(VERSION 2.8.11) + find_package(CGAL QUIET COMPONENTS Core ) diff --git a/Voronoi_diagram_2/demo/Voronoi_diagram_2/CMakeLists.txt b/Voronoi_diagram_2/demo/Voronoi_diagram_2/CMakeLists.txt index 546f3fa861b..52df2086fd2 100644 --- a/Voronoi_diagram_2/demo/Voronoi_diagram_2/CMakeLists.txt +++ b/Voronoi_diagram_2/demo/Voronoi_diagram_2/CMakeLists.txt @@ -2,11 +2,9 @@ project( voronoi_diagram_2 ) -cmake_minimum_required(VERSION 2.6.2) -if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) - cmake_policy(VERSION 2.8.4) -else() - cmake_policy(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.11) +if(POLICY CMP0043) + cmake_policy(SET CMP0043 OLD) endif() find_package(CGAL COMPONENTS Qt3 ) @@ -16,7 +14,7 @@ include_directories( ./include ) find_package(Qt3-patched) # FindQt3-patched.cmake is FindQt3.cmake patched by CGAL developers, so -# that it can be used together with FindQt4: all its variables are prefixed +# that it can be used together with Qt5: all its variables are prefixed # by "QT3_" instead of "QT_". if ( CGAL_FOUND AND CGAL_Qt3_FOUND AND QT3_FOUND ) diff --git a/wininst/developer_scripts/script_cgal.nsi b/wininst/developer_scripts/script_cgal.nsi index 5ebf3853540..5bd3350fe47 100644 --- a/wininst/developer_scripts/script_cgal.nsi +++ b/wininst/developer_scripts/script_cgal.nsi @@ -292,7 +292,7 @@ SectionEnd ;Language strings LangString DESC_MAIN ${LANG_ENGLISH} "The main components of the CGAL Library." - LangString DESC_SAMPLES ${LANG_ENGLISH} "The CGAL demos and examples, for which you need Qt 4 in order to build them (and Qt 3 for some)." + LangString DESC_SAMPLES ${LANG_ENGLISH} "The CGAL demos and examples, for which you need Qt 5 in order to build them (and Qt 3 for some)." LangString DESC_GMP_LIB ${LANG_ENGLISH} "The precompiled GMP and MPFR libraries (needed for exact constructions)." LangString DESC_DOC ${LANG_ENGLISH} "The HTML manuals." LangString DESC_ENVSET ${LANG_ENGLISH} "already set"