From 990c05090c4f960564cfc10e4009e8481849d39a Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Mon, 13 Nov 2017 12:02:20 +0100 Subject: [PATCH 01/11] Bug fix in CMap operation --- .../CGAL/Combinatorial_map_operations.h | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map_operations.h b/Combinatorial_map/include/CGAL/Combinatorial_map_operations.h index 80a35dc0a79..cbe01516ab9 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map_operations.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map_operations.h @@ -712,18 +712,18 @@ namespace CGAL typename CMap::Dart_handle d1, d2; typename CMap::Dart_handle dg1=amap.null_handle, dg2=amap.null_handle; - typename CMap::size_type mark = amap.get_new_mark(); + typename CMap::size_type amark = amap.get_new_mark(); // First we store and mark all the darts of the 1-cell to contract. std::deque to_erase; - for ( CGAL::CMap_dart_iterator_basic_of_cell it(amap,adart,mark); + for ( CGAL::CMap_dart_iterator_basic_of_cell it(amap,adart,amark); it.cont(); ++it ) { to_erase.push_back(it); if ( dg1==amap.null_handle && !amap.template is_free<0>(it) && !amap.template is_free<1>(it) ) { dg1=amap.template beta<0>(it); dg2=amap.template beta<1>(it); } - amap.mark(it, mark); + amap.mark(it, amark); ++res; } @@ -756,7 +756,8 @@ namespace CGAL if ( (*it)->beta(0)!=(*it)->beta(1) )*/ if ( amap.are_attributes_automatically_managed() && update_attributes ) { - modified_darts.push_back(amap.template beta<1>(*it)); + if (!amap.is_marked(amap.template beta<1>(*it), amark)) + { modified_darts.push_back(amap.template beta<1>(*it)); } } amap.basic_link_beta_1(amap.template beta<0>(*it), amap.template beta<1>(*it)); @@ -766,7 +767,8 @@ namespace CGAL { if ( amap.are_attributes_automatically_managed() && update_attributes ) { - modified_darts2.push_back(amap.template beta<0>(*it)); + if (!amap.is_marked(amap.template beta<0>(*it), amark)) + { modified_darts2.push_back(amap.template beta<0>(*it)); } } amap.template dart_unlink_beta<1>(amap.template beta<0>(*it)); } @@ -777,7 +779,8 @@ namespace CGAL { if ( amap.are_attributes_automatically_managed() && update_attributes ) { - modified_darts.push_back(amap.template beta<1>(*it)); + if (!amap.is_marked(amap.template beta<1>(*it), amark)) + { modified_darts.push_back(amap.template beta<1>(*it)); } } amap.template dart_unlink_beta<0>(amap.template beta<1>(*it)); } @@ -788,8 +791,8 @@ namespace CGAL for ( it=to_erase.begin(); it!=to_erase.end(); ++it ) { amap.erase_dart(*it); } - CGAL_assertion( amap.is_whole_map_unmarked(mark) ); - amap.free_mark(mark); + CGAL_assertion( amap.is_whole_map_unmarked(amark) ); + amap.free_mark(amark); if ( amap.are_attributes_automatically_managed() && update_attributes ) { From 6c7f38445578f577a3f05ddb8f97b406023aa1c9 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Mon, 13 Nov 2017 12:14:37 +0100 Subject: [PATCH 02/11] Update CMap save/load in order to allow to save/load 2D lcc --- .../CGAL/Combinatorial_map_save_load.h | 98 ++++++++++++++++--- 1 file changed, 86 insertions(+), 12 deletions(-) diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map_save_load.h b/Combinatorial_map/include/CGAL/Combinatorial_map_save_load.h index 615fc65f395..0d5411f927a 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map_save_load.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map_save_load.h @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -39,6 +40,8 @@ namespace CGAL { + typedef Exact_predicates_inexact_constructions_kernel::Point_2 RPoint_2; + typedef Exact_predicates_exact_constructions_kernel::Point_2 EPoint_2; typedef Exact_predicates_inexact_constructions_kernel::Point_3 RPoint_3; typedef Exact_predicates_exact_constructions_kernel::Point_3 EPoint_3; @@ -125,6 +128,20 @@ namespace CGAL { const std::string& val) {node.add("v",val);} inline + void write_cmap_attribute_node(boost::property_tree::ptree & node, + const RPoint_2& val) + { + node.add("p.x",val.x()); + node.add("p.y",val.y()); + } + inline + void write_cmap_attribute_node(boost::property_tree::ptree & node, + const EPoint_2& val) + { + node.add("p.x",CGAL::to_double(val.x())); + node.add("p.y",CGAL::to_double(val.y())); + } + inline void write_cmap_attribute_node(boost::property_tree::ptree & node, const RPoint_3& val) { @@ -166,7 +183,7 @@ namespace CGAL { boost::property_tree::ptree& ndim = ptree.add("dimension", ""); ndim.put(".index", i); ndim.add("type", typeid(typename CMap::template Attribute_type::type::Info).name()); - ndim.add("type_point", typeid(RPoint_3).name()); + ndim.add("type_point", typeid(typename CMap::Point).name()); // for every attribute of the dimension for (; it_attrib!=itend_attrib; ++it_attrib) @@ -201,7 +218,7 @@ namespace CGAL { boost::property_tree::ptree& ndim = ptree.add("dimension", ""); ndim.put(".index", i); ndim.add("type", "void"); - ndim.add("type_point", typeid(RPoint_3).name()); + ndim.add("type_point", typeid(typename CMap::Point).name()); // for every attribute of the dimension for (; it_attrib!=itend_attrib; ++it_attrib) @@ -354,13 +371,26 @@ namespace CGAL { return pt; } - template < class CMap > - bool save_combinatorial_map(const CMap& amap, std::ostream & output) + struct EmptyFunctor + { + void operator() (boost::property_tree::ptree & /*node*/) const + { + // node.add("myinfo.myvalie",15); + } + }; + + template < class CMap, class Functor > + bool save_combinatorial_map(const CMap& amap, std::ostream & output, + const Functor& f) { using boost::property_tree::ptree; ptree tree; tree.put("data", ""); + /** First we save general information of the map (by default nothing, + the fuction can be specialized by users). */ + f(tree); + // map dart => number std::map myDarts; @@ -378,14 +408,29 @@ namespace CGAL { return true; } - template < class CMap > - bool save_combinatorial_map(const CMap& amap, const char* filename) + template < class CMap, class Functor > + bool save_combinatorial_map(const CMap& amap, const char* filename, + const Functor& f) { std::ofstream output(filename); if (!output) return false; - return save_combinatorial_map(amap, output); + return save_combinatorial_map(amap, output, f); } + template < class CMap > + bool save_combinatorial_map(const CMap& amap, std::ostream & output) + { + EmptyFunctor f; + return save_combinatorial_map(amap, output, f); + } + + template < class CMap > + bool save_combinatorial_map(const CMap& amap, const char* filename) + { + EmptyFunctor f; + return save_combinatorial_map(amap, filename, f); + } + // Here T is a Dart_handle so no need of & template void read_cmap_dart_node @@ -449,6 +494,14 @@ namespace CGAL { {val=boost::lexical_cast< std::string >(v.second.data());} template<> inline void read_cmap_attribute_node + (const boost::property_tree::ptree::value_type &v,RPoint_2 &val) + { + double x=v.second.get("x"); + double y=v.second.get("y"); + val = RPoint_2(x,y); + } + template<> inline + void read_cmap_attribute_node (const boost::property_tree::ptree::value_type &v,RPoint_3 &val) { double x=v.second.get("x"); @@ -770,26 +823,47 @@ namespace CGAL { >::run(pt, amap, myDarts); } - template < class CMap > - bool load_combinatorial_map(std::ifstream & input, CMap& amap) + template < class CMap, class Functor > + bool load_combinatorial_map(std::ifstream & input, CMap& amap, + Functor& f) { using boost::property_tree::ptree; ptree pt; read_xml(input, pt); + + /** First we load general information of the map (by default nothing, + the fuction can be specialized by users). */ + f(pt); + + // Then we load darts and attributes. std::vector myDarts; cmap_load_darts(pt,amap,myDarts); cmap_load_attributes(pt,amap,myDarts); return true; } - template < class CMap > - bool load_combinatorial_map(const char* filename, CMap& amap) + template < class CMap, class Functor > + bool load_combinatorial_map(const char* filename, CMap& amap, + Functor& f) { std::ifstream input(filename); if (!input) return false; - return load_combinatorial_map(input, amap); + return load_combinatorial_map(input, amap, f); } + template < class CMap > + bool load_combinatorial_map(std::ifstream & input, CMap& amap) + { + EmptyFunctor f; + return load_combinatorial_map(input, amap, f); + } + + template < class CMap > + bool load_combinatorial_map(const char* filename, CMap& amap) + { + EmptyFunctor f; + return load_combinatorial_map(filename, amap, f); + } } // namespace CGAL #endif // CGAL_COMBINATORIAL_MAP_SAVE_LOAD_H // From 5f939d33abdcb667201f32d1d4f216ac2bc238ee Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Mon, 13 Nov 2017 12:17:03 +0100 Subject: [PATCH 03/11] Bug fix in CMap/GMap/LCC dart methods --- Combinatorial_map/include/CGAL/Combinatorial_map_storages.h | 2 +- Generalized_map/include/CGAL/Generalized_map_storages.h | 2 +- .../include/CGAL/CMap_linear_cell_complex_storages.h | 2 +- .../include/CGAL/GMap_linear_cell_complex_storages.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map_storages.h b/Combinatorial_map/include/CGAL/Combinatorial_map_storages.h index 0edc5dec58b..59009e489e6 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map_storages.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map_storages.h @@ -346,7 +346,7 @@ namespace CGAL { // Get the dart of the i-cell attribute associated with the given dart template - Dart_handle & dart(Dart_handle adart) + Dart_handle dart(Dart_handle adart) { CGAL_assertion( adart!=NULL ); CGAL_assertion( attribute(adart)!=NULL ); diff --git a/Generalized_map/include/CGAL/Generalized_map_storages.h b/Generalized_map/include/CGAL/Generalized_map_storages.h index 4e682e2df74..501bc72a354 100644 --- a/Generalized_map/include/CGAL/Generalized_map_storages.h +++ b/Generalized_map/include/CGAL/Generalized_map_storages.h @@ -339,7 +339,7 @@ namespace CGAL { // Get the dart of the i-cell attribute associated with the given dart template - Dart_handle & dart(Dart_handle adart) + Dart_handle dart(Dart_handle adart) { CGAL_assertion( adart!=NULL ); CGAL_assertion( attribute(adart)!=NULL ); diff --git a/Linear_cell_complex/include/CGAL/CMap_linear_cell_complex_storages.h b/Linear_cell_complex/include/CGAL/CMap_linear_cell_complex_storages.h index 4b5e9109783..7c030092e27 100644 --- a/Linear_cell_complex/include/CGAL/CMap_linear_cell_complex_storages.h +++ b/Linear_cell_complex/include/CGAL/CMap_linear_cell_complex_storages.h @@ -366,7 +366,7 @@ namespace CGAL { // Get the dart of the i-cell attribute associated with the given dart template - Dart_handle & dart(Dart_handle adart) + Dart_handle dart(Dart_handle adart) { CGAL_assertion( adart!=NULL ); CGAL_assertion( attribute(adart)!=NULL ); diff --git a/Linear_cell_complex/include/CGAL/GMap_linear_cell_complex_storages.h b/Linear_cell_complex/include/CGAL/GMap_linear_cell_complex_storages.h index 54cafb2ce2f..d3cd09cbc25 100644 --- a/Linear_cell_complex/include/CGAL/GMap_linear_cell_complex_storages.h +++ b/Linear_cell_complex/include/CGAL/GMap_linear_cell_complex_storages.h @@ -358,7 +358,7 @@ namespace CGAL { // Get the dart of the i-cell attribute associated with the given dart template - Dart_handle & dart(Dart_handle adart) + Dart_handle dart(Dart_handle adart) { CGAL_assertion( adart!=NULL ); CGAL_assertion( attribute(adart)!=NULL ); From 0783fa824176adc1f368e9a19739a0a186856a84 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Mon, 13 Nov 2017 12:24:24 +0100 Subject: [PATCH 04/11] Do not clear model before loading something; this is more generic. --- .../demo/Linear_cell_complex/MainWindow.cpp | 28 +++++-------------- .../demo/Linear_cell_complex/MainWindow.h | 11 ++++---- .../demo/Linear_cell_complex/MainWindow.ui | 6 ---- 3 files changed, 12 insertions(+), 33 deletions(-) diff --git a/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp b/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp index 8a142efba25..2324fa94373 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp +++ b/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.cpp @@ -153,7 +153,6 @@ void MainWindow::connectVolumeListHandlers() void MainWindow::update_operations_entries(bool show) { actionImportOFF->setEnabled(show); - actionAddOFF->setEnabled(show); actionImport3DTDS->setEnabled(show); actionCompute_Voronoi_3D->setEnabled(show); actionClear->setEnabled(show); @@ -246,7 +245,7 @@ void MainWindow::on_actionLoad_triggered () if (!fileName.isEmpty ()) { - load(fileName, true); + load(fileName, false); } } @@ -259,7 +258,7 @@ void MainWindow::on_actionImportOFF_triggered () if (!fileName.isEmpty ()) { - load_off (fileName, true); + load_off (fileName, false); } } @@ -272,7 +271,7 @@ void MainWindow::on_actionImportMoka_triggered() if (!fileName.isEmpty ()) { - load_moka(fileName, true); + load_moka(fileName, false); } } @@ -285,25 +284,12 @@ void MainWindow::on_actionImport3DTDS_triggered () if (!fileName.isEmpty ()) { - load_3DTDS (fileName, true); + load_3DTDS (fileName, false); statusBar ()->showMessage (QString ("Import 3DTDS file") + fileName, DELAY_STATUSMSG); } } -void MainWindow::on_actionAddOFF_triggered() -{ - QString fileName = QFileDialog::getOpenFileName (this, - tr ("Add OFF"), - "./off", - tr ("off files (*.off)")); - - if (!fileName.isEmpty ()) - { - load_off (fileName, false); - } -} - void MainWindow::load_depend_on_extension(const QString & fileName, bool clear) { QString ext = QFileInfo(fileName).suffix(); @@ -467,7 +453,7 @@ void MainWindow::load_moka(const QString & fileName, bool clear) #ifdef CGAL_PROFILE_LCC_DEMO timer.stop(); - std::cout<<"Time to load off "<showMessage (QString ("Load off file") + fileName, + statusBar ()->showMessage (QString ("Load moka file") + fileName, DELAY_STATUSMSG); else - statusBar ()->showMessage (QString ("Add off file") + fileName, + statusBar ()->showMessage (QString ("Add moka file") + fileName, DELAY_STATUSMSG); Q_EMIT (sceneChanged ()); } diff --git a/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.h b/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.h index a423a4d3a43..dde5336c7d2 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.h +++ b/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.h @@ -113,7 +113,6 @@ public Q_SLOTS: void on_actionSave_triggered(); void on_actionLoad_triggered(); void on_actionImportOFF_triggered(); - void on_actionAddOFF_triggered(); void on_actionImport3DTDS_triggered(); void on_actionImportMoka_triggered(); void on_actionCompute_Voronoi_3D_triggered(); @@ -147,12 +146,12 @@ public Q_SLOTS: void on_actionExtend_hidden_volumes_triggered(); // Other slots - void load_depend_on_extension(const QString& fileName, bool clear=true); - void load(const QString& fileName, bool clear=true); + void load_depend_on_extension(const QString& fileName, bool clear=false); + void load(const QString& fileName, bool clear=false); void save(const QString& fileName); - void load_off(const QString& fileName, bool clear=true); - void load_3DTDS(const QString& fileName, bool clear=true); - void load_moka(const QString& fileName, bool clear=true); + void load_off(const QString& fileName, bool clear=false); + void load_3DTDS(const QString& fileName, bool clear=false); + void load_moka(const QString& fileName, bool clear=false); void onSceneChanged(); diff --git a/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.ui b/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.ui index aad48e3f81f..d63b9d7c9b1 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.ui +++ b/Linear_cell_complex/demo/Linear_cell_complex/MainWindow.ui @@ -44,7 +44,6 @@ - @@ -107,11 +106,6 @@ &Import OFF - - - Add &OFF - - &Quit From c9ba6c2950ded4958feffe342199d1eee5f21043 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Mon, 13 Nov 2017 12:27:48 +0100 Subject: [PATCH 05/11] Split the LCC viewer in two; to prepare a generic base for all cgal ds viewers. --- .../linear_cell_complex_3_viewer_qt.h | 1161 +---------------- 1 file changed, 52 insertions(+), 1109 deletions(-) diff --git a/Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_3_viewer_qt.h b/Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_3_viewer_qt.h index b8d957755d2..5851bf790c4 100644 --- a/Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_3_viewer_qt.h +++ b/Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_3_viewer_qt.h @@ -20,32 +20,11 @@ #ifndef CGAL_LCC_3_VIEWER_QT_H #define CGAL_LCC_3_VIEWER_QT_H -#include -#include -#include -#include -#include -#include -#include -#include -#include - +#include "basic_viewer.h" #include #include -#include -#include -#include -#include -#include -#include #include -#include -#include - -#define NB_VBO_BUFFERS 8 -#define NB_VAO_BUFFERS 4 - typedef CGAL::Exact_predicates_inexact_constructions_kernel Local_kernel; typedef Local_kernel::Point_3 Local_point; typedef Local_kernel::Vector_3 Local_vector; @@ -62,137 +41,18 @@ struct DefaultColorFunctor // Here dh is the smaller dart of its face CGAL::Random random(alcc.darts().index(dh)); - return CGAL::Color(random.get_int(0,256), - random.get_int(0,256), - random.get_int(0,256)); + CGAL::Color res; + do + { + res=CGAL::Color(random.get_int(0,256), + random.get_int(0,256), + random.get_int(0,256)); + } + while(res.red()==255 && res.green()==255 && res.blue()==255); + return res; } }; -//Vertex source code -const char vertex_source_mono[] = - { - "#version 120 \n" - "attribute highp vec4 vertex;\n" - "attribute highp vec3 normal;\n" - - "uniform highp mat4 mvp_matrix;\n" - "uniform highp mat4 mv_matrix; \n" - - "varying highp vec4 fP; \n" - "varying highp vec3 fN; \n" - "void main(void)\n" - "{\n" - " fP = mv_matrix * vertex; \n" - " fN = mat3(mv_matrix)* normal; \n" - " gl_Position = mvp_matrix * vertex;\n" - "}" - }; - -const char vertex_source_multi[] = - { - "#version 120 \n" - "attribute highp vec4 vertex;\n" - "attribute highp vec3 normal;\n" - "attribute highp vec3 color;\n" - - "uniform highp mat4 mvp_matrix;\n" - "uniform highp mat4 mv_matrix; \n" - - "varying highp vec4 fP; \n" - "varying highp vec3 fN; \n" - "varying highp vec4 fColor; \n" - "void main(void)\n" - "{\n" - " fP = mv_matrix * vertex; \n" - " fN = mat3(mv_matrix)* normal; \n" - " fColor = vec4(color, 1.0); \n" - " gl_Position = mvp_matrix * vertex;\n" - "}" - }; - -//Vertex source code -const char fragment_source_mono[] = - { - "#version 120 \n" - "varying highp vec4 fP; \n" - "varying highp vec3 fN; \n" - "uniform highp vec4 color; \n" - "uniform vec4 light_pos; \n" - "uniform vec4 light_diff; \n" - "uniform vec4 light_spec; \n" - "uniform 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 = normalize(fN); \n" - " L = normalize(L); \n" - " V = normalize(V); \n" - - " vec3 R = reflect(-L, N); \n" - " vec4 diffuse = max(dot(N,L), 0.0) * light_diff * color; \n" - " vec4 specular = pow(max(dot(R,V), 0.0), spec_power) * light_spec; \n" - - "gl_FragColor = light_amb*color + diffuse ; \n" - "} \n" - "\n" - }; - -const char fragment_source_multi[] = - { - "#version 120 \n" - "varying highp vec4 fP; \n" - "varying highp vec3 fN; \n" - "varying highp vec4 fColor; \n" - "uniform vec4 light_pos; \n" - "uniform vec4 light_diff; \n" - "uniform vec4 light_spec; \n" - "uniform 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 = normalize(fN); \n" - " L = normalize(L); \n" - " V = normalize(V); \n" - - " vec3 R = reflect(-L, N); \n" - " vec4 diffuse = max(dot(N,L), 0.0) * light_diff * fColor; \n" - " vec4 specular = pow(max(dot(R,V), 0.0), spec_power) * light_spec; \n" - - "gl_FragColor = light_amb*fColor + diffuse ; \n" - "} \n" - "\n" - }; - -//Vertex source code -const char vertex_source_p_l[] = - { - "#version 120 \n" - "attribute highp vec4 vertex;\n" - "uniform highp mat4 mvp_matrix;\n" - "void main(void)\n" - "{\n" - " gl_Position = mvp_matrix * vertex;\n" - "}" - }; -//Vertex source code -const char fragment_source_p_l[] = - { - "#version 120 \n" - "uniform highp vec4 color; \n" - "void main(void) { \n" - "gl_FragColor = color; \n" - "} \n" - "\n" - }; - template struct Geom_utils; @@ -206,14 +66,6 @@ struct Geom_utils Local_point get_point(const LCC& lcc, typename LCC::Dart_const_handle dh) { return converter(lcc.point(dh)); } - Local_vector get_facet_normal(const LCC& lcc, - typename LCC::Dart_const_handle dh) - { - Local_vector n = converter(CGAL::compute_normal_of_cell_2(lcc,dh)); - n = n/(CGAL::sqrt(n*n)); - return n; - } - Local_vector get_vertex_normal(const LCC& lcc, typename LCC::Dart_const_handle dh) { @@ -239,346 +91,38 @@ struct Geom_utils Local_point get_point(const LCC& lcc, typename LCC::Dart_const_handle dh) { return get_point(lcc, lcc.vertex_attribute(dh)); } - Local_vector get_facet_normal(const LCC&, typename LCC::Dart_const_handle) - { - Local_vector n(0,1,0); - return n; - } - Local_vector get_vertex_normal(const LCC&, typename LCC::Dart_const_handle) { - Local_vector n(0,1,0); + Local_vector n(0,-1,0); return n; } protected: CGAL::Cartesian_converter converter; }; -template -CGAL::Bbox_3 bbox(const LCC& lcc) -{ - CGAL::Bbox_3 bb; - Geom_utils geomutils; - - typename LCC::Vertex_attribute_range::const_iterator - it=lcc.vertex_attributes().begin(), itend=lcc.vertex_attributes().end(); - if ( it!=itend ) - { - bb = geomutils.get_point(lcc, it).bbox(); - for( ++it; it!=itend; ++it) - { - bb = bb + geomutils.get_point(lcc, it).bbox(); - } - } - - return bb; -} - +// Viewer class for LCC template -class SimpleLCCViewerQt : public QGLViewer, public QOpenGLFunctions_2_1 +class SimpleLCCViewerQt : public Basic_viewer { + typedef Basic_viewer Base; typedef typename LCC::Dart_const_handle Dart_const_handle; - - struct Vertex_info - { - Dart_const_handle dh; - Local_vector v; - }; - - struct Face_info - { - bool exist_edge[3]; - bool is_external; - bool is_process; - }; - - typedef CGAL::Triangulation_2_projection_traits_3 P_traits; - 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::Exact_predicates_tag Itag; - typedef CGAL::Constrained_Delaunay_triangulation_2 CDT; - + public: - // Constructor/Destructor - SimpleLCCViewerQt(const LCC& alcc) : - QGLViewer(CGAL::Qt::createOpenGLContext()), + /// Construct the viewer. + /// @param alcc the lcc to view + /// @param title the title of the window + /// @param anofaces if true, do not draw faces (faces are not computed; this can be + /// usefull for very big LCC where this time could be long) + SimpleLCCViewerQt(const LCC& alcc, const char* title="", bool anofaces=false) : + Base(title), lcc(alcc), - wireframe(false), - flatShading(true), - edges(true), - vertices(true), - mono(false), - inverse_normal(false), - size_points(7.), - size_edges(3.1), - ambient(0.6f, 0.5f, 0.5f, 0.5f), - are_buffers_initialized(false) + m_nofaces(anofaces) { - setWindowTitle("3D lcc viewer"); - resize(500, 450); - - QGLFormat newFormat = this->format(); - newFormat.setSampleBuffers(true); - newFormat.setSamples(16); - this->setFormat(newFormat); -} - - ~SimpleLCCViewerQt() - { - for (int i=0; icompileSourceCode(vertex_source_mono)) - { - std::cerr<<"Compiling vertex source FAILED"<compileSourceCode(vertex_source_multi)) - { - std::cerr<<"Compiling vertex source FAILED"<compileSourceCode(fragment_source_mono)) - { - std::cerr<<"Compiling fragmentsource FAILED"<compileSourceCode(fragment_source_multi)) - { - 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[vaon] = rendering_program.attributeLocation("vertex"); - rendering_program.bind(); - rendering_program.enableAttributeArray(vertexLocation[vaon]); - rendering_program.setAttributeBuffer(vertexLocation[vaon],GL_FLOAT,0,3); - rendering_program.release(); - - buffers[bufn].release(); - ++bufn; - - //normals of the facets - assert(bufn(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); - rendering_program.release(); - - buffers[bufn].release(); - ++bufn; - - if (!mono) - { - //colors of the facets - assert(bufn(colors.size()*sizeof(float))); - colorsLocation = rendering_program.attributeLocation("color"); - rendering_program.bind(); - rendering_program.enableAttributeArray(colorsLocation); - rendering_program.setAttributeBuffer(colorsLocation,GL_FLOAT,0,3); - rendering_program.release(); - - buffers[bufn].release(); - ++bufn; - } - - vao[vaon].release(); - ++vaon; - - assert(vaon(pos_facets.size()*sizeof(float))); - vertexLocation[vaon] = rendering_program.attributeLocation("vertex"); - rendering_program.bind(); - rendering_program.enableAttributeArray(vertexLocation[vaon]); - rendering_program.setAttributeBuffer(vertexLocation[vaon],GL_FLOAT,0,3); - rendering_program.release(); - - buffers[bufn].release(); - ++bufn; - - //normals of the facets - assert(bufn(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); - rendering_program.release(); - - buffers[bufn].release(); - ++bufn; - - if (!mono) - { - //colors of the facets - assert(bufn(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[bufn].release(); - - rendering_program.release(); - ++bufn; - } - - vao[vaon].release(); - ++vaon; - - //The lines - assert(vaon(pos_lines.size()*sizeof(float))); - vertexLocation[vaon] = rendering_program_p_l.attributeLocation("vertex"); - rendering_program_p_l.bind(); - rendering_program_p_l.enableAttributeArray(vertexLocation[vaon]); - rendering_program_p_l.setAttributeBuffer(vertexLocation[vaon],GL_FLOAT,0,3); - rendering_program_p_l.release(); - - buffers[bufn].release(); - ++bufn; - - vao[vaon].release(); - ++vaon; - - //The points - assert(vaon(pos_points.size()*sizeof(float))); - vertexLocation[vaon] = rendering_program_p_l.attributeLocation("vertex"); - rendering_program_p_l.bind(); - rendering_program_p_l.enableAttributeArray(vertexLocation[vaon]); - rendering_program_p_l.setAttributeBuffer(vertexLocation[vaon],GL_FLOAT,0,3); - rendering_program_p_l.release(); - - buffers[bufn].release(); - ++bufn; - - vao[vaon].release(); - ++vaon; - - are_buffers_initialized = true; - } - + void compute_face(Dart_const_handle dh) { // We fill only closed faces. @@ -592,252 +136,53 @@ protected: } while(cur!=dh); - double r=0.; - double g=0.; - double b=0.; - CGAL::Color c=ColorFunctor::run(lcc, dh); - r=(double)c.red()/(double)255; - g=(double)c.green()/(double)255; - b=(double)c.blue()/(double)255; - - //compute flat normals - Local_vector normal = geomutils.get_facet_normal(lcc, dh); - normal = normal/(CGAL::sqrt(normal*normal)); - if (inverse_normal) normal=normal*-1; - - if (lcc.next(lcc.next(lcc.next(dh)))!=dh) + + face_begin(c); + + cur=dh; + do { - try - { - P_traits cdt_traits(normal); - CDT cdt(cdt_traits); - - // Iterates on the vector of facet handles - typename CDT::Vertex_handle previous = NULL, first = NULL; - cur=dh; - do - { - typename CDT::Vertex_handle vh = cdt.insert(geomutils.get_point(lcc, cur)); - if(first==NULL) - { first=vh; } - vh->info().v = geomutils.get_vertex_normal(lcc, cur); - if (inverse_normal) vh->info().v=vh->info().v*-1; - - if(previous!=NULL && previous!=vh) - { cdt.insert_constraint(previous, vh); } - previous=vh; - cur=lcc.next(cur); - } - while(cur!=dh); - - if (previous!=NULL) - cdt.insert_constraint(previous, first); - - // sets mark is_external - for(typename CDT::All_faces_iterator fit = cdt.all_faces_begin(), - fitend = cdt.all_faces_end(); fit!=fitend; ++fit) - { - fit->info().is_external = true; - fit->info().is_process = false; - } - //check if the facet is external or internal - std::queue face_queue; - typename CDT::Face_handle face_internal = NULL; - face_queue.push(cdt.infinite_vertex()->face()); - while(! face_queue.empty() ) - { - typename CDT::Face_handle fh = face_queue.front(); - face_queue.pop(); - if(!fh->info().is_process) - { - fh->info().is_process = true; - for(int i = 0; i <3; ++i) - { - if(!cdt.is_constrained(std::make_pair(fh, i))) - { - face_queue.push(fh->neighbor(i)); - } - else if (face_internal==NULL) - { - face_internal = fh->neighbor(i); - } - } - } - } - - if ( face_internal!=NULL ) - face_queue.push(face_internal); - - while(! face_queue.empty() ) - { - typename CDT::Face_handle fh = face_queue.front(); - face_queue.pop(); - if(!fh->info().is_process) - { - fh->info().is_process = true; - fh->info().is_external = false; - 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(typename CDT::Finite_faces_iterator ffit = cdt.finite_faces_begin(), - ffitend = cdt.finite_faces_end(); ffit != ffitend; ++ffit) - { - if(!ffit->info().is_external) - { - 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()); - - smooth_normals.push_back(ffit->vertex(0)->info().v.x()); - smooth_normals.push_back(ffit->vertex(0)->info().v.y()); - smooth_normals.push_back(ffit->vertex(0)->info().v.z()); - - smooth_normals.push_back(ffit->vertex(1)->info().v.x()); - smooth_normals.push_back(ffit->vertex(1)->info().v.y()); - smooth_normals.push_back(ffit->vertex(1)->info().v.z()); - - smooth_normals.push_back(ffit->vertex(2)->info().v.x()); - smooth_normals.push_back(ffit->vertex(2)->info().v.y()); - smooth_normals.push_back(ffit->vertex(2)->info().v.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()); - - 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); - } - } - } - catch(...) - { // Triangulation crash: the face is not filled - } + add_point_in_face(geomutils.get_point(lcc, cur), + geomutils.get_vertex_normal(lcc, cur)); + cur=lcc.next(cur); } - else - { - 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); - - flat_normals.push_back(normal.x()); - flat_normals.push_back(normal.y()); - flat_normals.push_back(normal.z()); + while(cur!=dh); - 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()); - - //compute Smooth normals - cur=dh; - do - { - Local_vector normal = geomutils.get_vertex_normal(lcc, cur); - normal = normal/(CGAL::sqrt(normal*normal)); - if (inverse_normal) normal=normal*-1; - - smooth_normals.push_back(normal.x()); - smooth_normals.push_back(normal.y()); - smooth_normals.push_back(normal.z()); - - Local_point p = geomutils.get_point(lcc, cur); - pos_facets.push_back(p.x()); - pos_facets.push_back(p.y()); - pos_facets.push_back(p.z()); - cur=lcc.next(cur); - } - while(cur!=dh); - } + face_end(); } void compute_edge(Dart_const_handle dh) { - Local_point p = geomutils.get_point(lcc, dh); + Local_point p1 = geomutils.get_point(lcc, dh); Dart_const_handle d2 = lcc.other_extremity(dh); if ( d2!=NULL ) { Local_point p2 = geomutils.get_point(lcc, 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()); + add_segment(p1, p2); } } void compute_vertex(Dart_const_handle dh, bool& empty) { - Local_point p = geomutils.get_point(lcc, dh); - 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(); + Local_point p = geomutils.get_point(lcc, dh); + add_point(p); } void compute_elements() { - pos_facets.clear(); - flat_normals.clear(); - smooth_normals.clear(); - pos_lines.clear(); - pos_points.clear(); - colors.clear(); + clear(); - if ( lcc.is_empty() ) - { - bb = Local_point(CGAL::ORIGIN).bbox(); - bb = bb + Local_point(1,1,1).bbox(); // To avoid a warning from Qglviewer - return; - } - unsigned int markfaces = lcc.get_new_mark(); unsigned int markedges = lcc.get_new_mark(); unsigned int markvertices = lcc.get_new_mark(); bool empty = true; + for (typename LCC::Dart_range::const_iterator it=lcc.darts().begin(), - itend=lcc.darts().end(); it!=itend; ++it ) + itend=lcc.darts().end(); it!=itend; ++it ) { - if ( !lcc.is_marked(it, markfaces) ) + if ( !m_nofaces && !lcc.is_marked(it, markfaces) ) { compute_face(it); CGAL::mark_cell(lcc, it, markfaces); @@ -861,432 +206,30 @@ protected: lcc.free_mark(markvertices); } - void 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 diffuse( 0.9f, - 0.9f, - 0.9f, - 0.9f ); - - QVector4D specular( 0.0f, - 0.0f, - 0.0f, - 1.0f ); - - QVector4D position((bb.xmax()-bb.xmin())/2, (bb.ymax()-bb.ymin())/2,bb.zmax(), 0.0 ); - 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); - - if (mono) - colorLocation2 = rendering_program.uniformLocation("color"); - - 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(); - } - - virtual void draw() - { - glEnable(GL_DEPTH_TEST); - if(!are_buffers_initialized) - initialize_buffers(); - - QColor color; - if ( !wireframe ) - { - if(flatShading) - { - vao[0].bind(); - attrib_buffers(this); - rendering_program.bind(); - if (mono) - { - CGAL::Color c=ColorFunctor::run(lcc, NULL); - color.setRgbF((double)c.red()/(double)255, - (double)c.green()/(double)255, - (double)c.blue()/(double)255); - rendering_program.setUniformValue(colorLocation2,color); - } - 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(); - if (mono) - { - CGAL::Color c=ColorFunctor::run(lcc, NULL); - color.setRgbF((double)c.red()/(double)255, - (double)c.green()/(double)255, - (double)c.blue()/(double)255); - rendering_program.setUniformValue(colorLocation2,color); - } - 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); - ::glLineWidth(size_edges); - glDrawArrays(GL_LINES, 0, static_cast(pos_lines.size()/3)); - rendering_program_p_l.release(); - vao[2].release(); - } - if(vertices) - { - ::glPointSize(size_points); - 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(); - } - } - - virtual void init() - { - // Restore previous viewer state. - restoreStateFromFile(); - - // Define 'Control+Q' as the new exit shortcut (default was 'Escape') - setShortcut(EXIT_VIEWER, Qt::CTRL+Qt::Key_Q); - - // Add custom key description (see keyPressEvent). - setKeyDescription(Qt::Key_W, "Toggles wire frame display"); - setKeyDescription(Qt::Key_F, "Toggles flat shading display"); - setKeyDescription(Qt::Key_E, "Toggles edges display"); - setKeyDescription(Qt::Key_V, "Toggles vertices display"); - setKeyDescription(Qt::Key_M, "Toggles mono color for all faces"); - setKeyDescription(Qt::Key_N, "Inverse direction of normals"); - setKeyDescription(Qt::Key_Plus, "Increase size of edges"); - setKeyDescription(Qt::Key_Minus, "Decrease size of edges"); - setKeyDescription(Qt::Key_Plus+Qt::ShiftModifier, "Increase size of vertices"); - setKeyDescription(Qt::Key_Minus+Qt::ShiftModifier, "Decrease size of vertices"); - setKeyDescription(Qt::Key_PageDown, "Increase light (all colors, use shift/alt/ctrl for one rgb component)"); - setKeyDescription(Qt::Key_PageUp, "Decrease light (all colors, use shift/alt/ctrl for one rgb component)"); - - // Light default parameters - ::glLineWidth(size_edges); - ::glPointSize(size_points); - ::glEnable(GL_POLYGON_OFFSET_FILL); - ::glPolygonOffset(1.f,1.f); - ::glClearColor(1.0f,1.0f,1.0f,0.0f); - ::glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); - - ::glEnable(GL_LIGHTING); - - ::glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); - - ::glShadeModel(GL_FLAT); - ::glDisable(GL_BLEND); - ::glEnable(GL_LINE_SMOOTH); - ::glDisable(GL_POLYGON_SMOOTH_HINT); - ::glBlendFunc(GL_ONE, GL_ZERO); - ::glHint(GL_LINE_SMOOTH_HINT, GL_FASTEST); - - initializeOpenGLFunctions(); - compile_shaders(); - compute_elements(); - - this->camera()->setSceneBoundingBox(qglviewer::Vec(bb.xmin(), - bb.ymin(), - bb.zmin()), - qglviewer::Vec(bb.xmax(), - bb.ymax(), - bb.zmax())); - - this->showEntireScene(); - } - - void keyPressEvent(QKeyEvent *e) + virtual void keyPressEvent(QKeyEvent *e) { const Qt::KeyboardModifiers modifiers = e->modifiers(); - - if ((e->key()==Qt::Key_W) && (modifiers==Qt::NoButton)) - { - wireframe = !wireframe; - if (wireframe) - { - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); - displayMessage("Wireframe."); - } - else - { - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - displayMessage("Filled faces."); - } - updateGL(); - } - else if ((e->key()==Qt::Key_F) && (modifiers==Qt::NoButton)) - { - flatShading = !flatShading; - if (flatShading) - displayMessage("Flat shading."); - else - displayMessage("Gouraud shading."); - updateGL(); - } - else if ((e->key()==Qt::Key_E) && (modifiers==Qt::NoButton)) - { - edges = !edges; - displayMessage(QString("Draw edges=%1.").arg(edges?"true":"false")); - updateGL(); - } - else if ((e->key()==Qt::Key_V) && (modifiers==Qt::NoButton)) - { - vertices = !vertices; - displayMessage(QString("Draw vertices=%1.").arg(vertices?"true":"false")); - updateGL(); - } - else if ((e->key()==Qt::Key_M) && (modifiers==Qt::NoButton)) - { - mono = !mono; - initialize_buffers(); - compile_shaders(); - displayMessage(QString("Mono color=%1.").arg(mono?"true":"false")); - updateGL(); - } - else if ((e->key()==Qt::Key_N) && (modifiers==Qt::NoButton)) - { - inverse_normal = !inverse_normal; - compute_elements(); - initialize_buffers(); - compile_shaders(); - displayMessage(QString("Inverse normal=%1.").arg(inverse_normal?"true":"false")); - updateGL(); - } - else if ((e->key()==Qt::Key_Plus) && (modifiers==Qt::KeypadModifier)) - { - size_edges+=.5; - displayMessage(QString("Size of edges=%1.").arg(size_edges)); - updateGL(); - } - else if ((e->key()==Qt::Key_Minus) && (modifiers==Qt::KeypadModifier)) - { - if (size_edges>.5) size_edges-=.5; - displayMessage(QString("Size of edges=%1.").arg(size_edges)); - updateGL(); - } - else if ((e->key()==Qt::Key_Plus) && (modifiers==(Qt::ShiftModifier|Qt::KeypadModifier))) - { - size_points+=.5; - displayMessage(QString("Size of points=%1.").arg(size_points)); - updateGL(); - } - else if ((e->key()==Qt::Key_Minus) && (modifiers==(Qt::ShiftModifier|Qt::KeypadModifier))) - { - if (size_points>.5) size_points-=.5; - displayMessage(QString("Size of points=%1.").arg(size_points)); - updateGL(); - } - else if ((e->key()==Qt::Key_PageUp) && (modifiers==Qt::NoButton)) - { - ambient.setX(ambient.x()+.1); - if (ambient.x()>1.) ambient.setX(1.); - ambient.setY(ambient.x()+.1); - if (ambient.y()>1.) ambient.setY(1.); - ambient.setZ(ambient.x()+.1); - if (ambient.z()>1.) ambient.setZ(1.); - displayMessage(QString("Light color=(%1 %2 %3)."). - arg(ambient.x()).arg(ambient.y()).arg(ambient.z())); - updateGL(); - } - else if ((e->key()==Qt::Key_PageDown) && (modifiers==Qt::NoButton)) - { - ambient.setX(ambient.x()-.1); - if (ambient.x()<0.) ambient.setX(0.); - ambient.setY(ambient.y()-.1); - if (ambient.y()<0.) ambient.setY(0.); - ambient.setZ(ambient.z()-.1); - if (ambient.z()<0.) ambient.setZ(0.); - displayMessage(QString("Light color=(%1 %2 %3)."). - arg(ambient.x()).arg(ambient.y()).arg(ambient.z())); - updateGL(); - } - else if ((e->key()==Qt::Key_PageUp) && (modifiers==Qt::ShiftModifier)) - { - ambient.setX(ambient.x()+.1); - if (ambient.x()>1.) ambient.setX(1.); - displayMessage(QString("Light color=(%1 %2 %3)."). - arg(ambient.x()).arg(ambient.y()).arg(ambient.z())); - updateGL(); - } - else if ((e->key()==Qt::Key_PageUp) && (modifiers==Qt::AltModifier)) - { - ambient.setY(ambient.y()+.1); - if (ambient.y()>1.) ambient.setY(1.); - displayMessage(QString("Light color=(%1 %2 %3)."). - arg(ambient.x()).arg(ambient.y()).arg(ambient.z())); - updateGL(); - } - else if ((e->key()==Qt::Key_PageUp) && (modifiers==Qt::ControlModifier)) - { - ambient.setZ(ambient.z()+.1); - if (ambient.z()>1.) ambient.setZ(1.); - displayMessage(QString("Light color=(%1 %2 %3)."). - arg(ambient.x()).arg(ambient.y()).arg(ambient.z())); - updateGL(); - } - else if ((e->key()==Qt::Key_PageDown) && (modifiers==Qt::ShiftModifier)) - { - ambient.setX(ambient.x()-.1); - if (ambient.x()<0.) ambient.setX(0.); - displayMessage(QString("Light color=(%1 %2 %3)."). - arg(ambient.x()).arg(ambient.y()).arg(ambient.z())); - updateGL(); - } - else if ((e->key()==Qt::Key_PageDown) && (modifiers==Qt::AltModifier)) - { - ambient.setY(ambient.y()-.1); - if (ambient.y()<0.) ambient.setY(0.); - displayMessage(QString("Light color=(%1 %2 %3)."). - arg(ambient.x()).arg(ambient.y()).arg(ambient.z())); - updateGL(); - } - else if ((e->key()==Qt::Key_PageDown) && (modifiers==Qt::ControlModifier)) - { - ambient.setZ(ambient.z()-.1); - if (ambient.z()<0.) ambient.setZ(0.); - displayMessage(QString("Light color=(%1 %2 %3)."). - arg(ambient.x()).arg(ambient.y()).arg(ambient.z())); - updateGL(); - } - else - QGLViewer::keyPressEvent(e); + Base::keyPressEvent(e); } - - virtual QString helpString() const - { - QString text("

L C C 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; - } - -private: +protected: const LCC& lcc; - - bool wireframe; - bool flatShading; - bool edges; - bool vertices; - bool mono; - bool inverse_normal; - - double size_points; - double size_edges; - - QVector4D ambient; - - bool are_buffers_initialized; - - //Shaders elements - int vertexLocation[NB_VAO_BUFFERS]; - int normalsLocation; - int mvpLocation[2]; - int mvLocation; - int colorLocation; - int colorLocation2; - 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[NB_VBO_BUFFERS]; - QOpenGLVertexArrayObject vao[NB_VAO_BUFFERS]; - int colorsLocation; - - QOpenGLShaderProgram rendering_program; - QOpenGLShaderProgram rendering_program_p_l; - - CGAL::Bbox_3 bb; + bool m_nofaces; Geom_utils geomutils; }; + template -void display_lcc(const LCC& alcc) +void display_lcc(const LCC& alcc, + const char* title="", + bool nofill=false) { int argc=1; const char* argv[2]={"lccviewer","\0"}; QApplication app(argc,const_cast(argv)); - SimpleLCCViewerQt mainwindow(alcc); + SimpleLCCViewerQt mainwindow(alcc, title, nofill); mainwindow.show(); app.exec(); From 877e8783f56570d0d3d13747336b83219dc3324c Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Mon, 13 Nov 2017 13:33:05 +0100 Subject: [PATCH 06/11] Add new file for generic viewer. --- .../Linear_cell_complex/basic_viewer.h | 1200 +++++++++++++++++ 1 file changed, 1200 insertions(+) create mode 100644 Linear_cell_complex/examples/Linear_cell_complex/basic_viewer.h diff --git a/Linear_cell_complex/examples/Linear_cell_complex/basic_viewer.h b/Linear_cell_complex/examples/Linear_cell_complex/basic_viewer.h new file mode 100644 index 00000000000..21f88cfc1bd --- /dev/null +++ b/Linear_cell_complex/examples/Linear_cell_complex/basic_viewer.h @@ -0,0 +1,1200 @@ +// Copyright (c) 2011 CNRS and LIRIS' Establishments (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) : Guillaume Damiand + +#ifndef CGAL_BASIC_VIEWER_H +#define CGAL_BASIC_VIEWER_H + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +#define NB_VBO_BUFFERS 8 +#define NB_VAO_BUFFERS 4 + +typedef CGAL::Exact_predicates_inexact_constructions_kernel Local_kernel; +typedef Local_kernel::Point_3 Local_point; +typedef Local_kernel::Vector_3 Local_vector; + +//Vertex source code +const char vertex_source_mono[] = + { + "#version 120 \n" + "attribute highp vec4 vertex;\n" + "attribute highp vec3 normal;\n" + + "uniform highp mat4 mvp_matrix;\n" + "uniform highp mat4 mv_matrix; \n" + + "varying highp vec4 fP; \n" + "varying highp vec3 fN; \n" + "void main(void)\n" + "{\n" + " fP = mv_matrix * vertex; \n" + " fN = mat3(mv_matrix)* normal; \n" + " gl_Position = mvp_matrix * vertex;\n" + "}" + }; + +const char vertex_source_multi[] = + { + "#version 120 \n" + "attribute highp vec4 vertex;\n" + "attribute highp vec3 normal;\n" + "attribute highp vec3 color;\n" + + "uniform highp mat4 mvp_matrix;\n" + "uniform highp mat4 mv_matrix; \n" + + "varying highp vec4 fP; \n" + "varying highp vec3 fN; \n" + "varying highp vec4 fColor; \n" + "void main(void)\n" + "{\n" + " fP = mv_matrix * vertex; \n" + " fN = mat3(mv_matrix)* normal; \n" + " fColor = vec4(color, 1.0); \n" + " gl_Position = mvp_matrix * vertex;\n" + "}" + }; + +//Vertex source code +const char fragment_source_mono[] = + { + "#version 120 \n" + "varying highp vec4 fP; \n" + "varying highp vec3 fN; \n" + "uniform highp vec4 color; \n" + "uniform vec4 light_pos; \n" + "uniform vec4 light_diff; \n" + "uniform vec4 light_spec; \n" + "uniform 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 = normalize(fN); \n" + " L = normalize(L); \n" + " V = normalize(V); \n" + + " vec3 R = reflect(-L, N); \n" + " vec4 diffuse = max(dot(N,L), 0.0) * light_diff * color; \n" + " vec4 specular = pow(max(dot(R,V), 0.0), spec_power) * light_spec; \n" + + "gl_FragColor = light_amb*color + diffuse ; \n" + "} \n" + "\n" + }; + +const char fragment_source_multi[] = + { + "#version 120 \n" + "varying highp vec4 fP; \n" + "varying highp vec3 fN; \n" + "varying highp vec4 fColor; \n" + "uniform vec4 light_pos; \n" + "uniform vec4 light_diff; \n" + "uniform vec4 light_spec; \n" + "uniform 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 = normalize(fN); \n" + " L = normalize(L); \n" + " V = normalize(V); \n" + + " vec3 R = reflect(-L, N); \n" + " vec4 diffuse = max(dot(N,L), 0.0) * light_diff * fColor; \n" + " vec4 specular = pow(max(dot(R,V), 0.0), spec_power) * light_spec; \n" + + "gl_FragColor = light_amb*fColor + diffuse ; \n" + "} \n" + "\n" + }; + +//Vertex source code +const char vertex_source_p_l[] = + { + "#version 120 \n" + "attribute highp vec4 vertex;\n" + "uniform highp mat4 mvp_matrix;\n" + "void main(void)\n" + "{\n" + " gl_Position = mvp_matrix * vertex;\n" + "}" + }; +//Vertex source code +const char fragment_source_p_l[] = + { + "#version 120 \n" + "uniform highp vec4 color; \n" + "void main(void) { \n" + "gl_FragColor = color; \n" + "} \n" + "\n" + }; + +namespace internal { + template + void newell_single_step_3(const Point& p, const Point& q, Vector& n) + { + // Compute normal of the face by using Newell's method: for each edge PQ + // Nx += (Py - Qy) * (Pz + Qz); + // Ny += (Pz - Qz) * (Px + Qx); + // Nz += (Px - Qx) * (Py + Qy); + n = Vector(n.x()+((p.y()-q.y())*(p.z()+q.z())), + n.y()+((p.z()-q.z())*(p.x()+q.x())), + n.z()+((p.x()-q.x())*(p.y()+q.y()))); + } +} // End namespace internal + +template +typename K::Vector_3 compute_normal_of_face(const std::vector& points) +{ + typename K::Vector_3 normal(CGAL::NULL_VECTOR); + unsigned int nb = 0; + for (std::size_t i=0; i0); + return (typename K::Construct_scaled_vector_3()(normal, 1.0/nb)); +} + +class Basic_viewer : public QGLViewer, public QOpenGLFunctions_2_1 +{ + struct Vertex_info + { + Local_vector v; + }; + + struct Face_info + { + bool exist_edge[3]; + bool is_external; + bool is_process; + }; + + typedef CGAL::Triangulation_2_projection_traits_3 P_traits; + 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::Exact_predicates_tag Itag; + typedef CGAL::Constrained_Delaunay_triangulation_2 CDT; + +public: + // Constructor/Destructor + Basic_viewer(const char* title="") : + QGLViewer(CGAL::Qt::createOpenGLContext()), + m_draw_vertices(true), + m_draw_edges(true), + m_draw_faces(true), + m_flatShading(true), + m_use_mono_color(false), + m_inverse_normal(false), + m_size_points(7.), + m_size_edges(3.1), + m_vertices_mono_color(51, 51, 178), + m_edges_mono_color(51, 51, 148), + m_faces_mono_color(180, 125, 200), + m_ambient_color(0.6f, 0.5f, 0.5f, 0.5f), + m_are_buffers_initialized(false), + m_face_started(false) + { + if (title[0]==0) + setWindowTitle("CGAL Basic Viewer"); + else + setWindowTitle(title); + + resize(500, 450); + + if ( is_empty() ) + { + bb=Local_point(CGAL::ORIGIN).bbox(); + bb=bb + Local_point(1,1,1).bbox(); // To avoid a warning from Qglviewer + } + } + + ~Basic_viewer() + { + for (int i=0; i(points_of_face); + + double r=(double)color_of_face.red()/(double)255; + double g=(double)color_of_face.green()/(double)255; + double b=(double)color_of_face.blue()/(double)255; + + if (points_of_face.size()==3) // Triangle: no need to triangulate + { + for (int i=0; i<3; ++i) + { + // The point + pos_faces.push_back(points_of_face[i].x()); + pos_faces.push_back(points_of_face[i].y()); + pos_faces.push_back(points_of_face[i].z()); + + // Its color + colors.push_back(r); colors.push_back(g); colors.push_back(b); + + // Its flat normal + flat_normals.push_back(normal.x()); + flat_normals.push_back(normal.y()); + flat_normals.push_back(normal.z()); + + // Its smoth normal (if given by the user) + if (vertex_normals_for_face.size()==3) + { // Here we have 3 vertex normals; we can use Gourod + smooth_normals.push_back(vertex_normals_for_face[i].x()); + smooth_normals.push_back(vertex_normals_for_face[i].y()); + smooth_normals.push_back(vertex_normals_for_face[i].z()); + } + else + { // Here user does not provide all vertex normals: we use face normal istead + // and thus we will not be able to use Gourod + smooth_normals.push_back(normal.x()); + smooth_normals.push_back(normal.y()); + smooth_normals.push_back(normal.z()); + } + } + } + else + { // More than 3 points: we triangulate + try + { + P_traits cdt_traits(normal); + CDT cdt(cdt_traits); + + bool with_vertex_normal=(vertex_normals_for_face.size()==points_of_face.size()); + + // (1) We insert all the edges as contraint in the CDT. + typename CDT::Vertex_handle previous=NULL, first=NULL; + for (int i=0; iinfo().v=vertex_normals_for_face[i]; } + else + { vh->info().v=normal; } + + if(previous!=NULL && previous!=vh) + { cdt.insert_constraint(previous, vh); } + previous=vh; + } + + if (previous!=NULL && previous!=first) + cdt.insert_constraint(previous, first); + + // (2) We mark all external triangles + // (2.1) We initialize is_external and is_process values + for(typename CDT::All_faces_iterator fit = cdt.all_faces_begin(), + fitend = cdt.all_faces_end(); fit!=fitend; ++fit) + { + fit->info().is_external = true; + fit->info().is_process = false; + } + // (2.2) We check if the facet is external or internal + std::queue face_queue; + typename CDT::Face_handle face_internal = NULL; + if (cdt.infinite_vertex()->face()!=NULL) + face_queue.push(cdt.infinite_vertex()->face()); + while(! face_queue.empty() ) + { + typename CDT::Face_handle fh = face_queue.front(); + face_queue.pop(); + if(!fh->info().is_process) + { + fh->info().is_process = true; + for(int i=0; i<3; ++i) + { + if(!cdt.is_constrained(std::make_pair(fh, i))) + { + if (fh->neighbor(i)!=NULL) + face_queue.push(fh->neighbor(i)); + } + else if (face_internal==NULL) + { + face_internal = fh->neighbor(i); + } + } + } + } + + if ( face_internal!=NULL ) + face_queue.push(face_internal); + + while(! face_queue.empty() ) + { + typename CDT::Face_handle fh = face_queue.front(); + face_queue.pop(); + if(!fh->info().is_process) + { + fh->info().is_process = true; + fh->info().is_external = false; + for(int i=0; i<3; ++i) + { + if(!cdt.is_constrained(std::make_pair(fh, i))) + { + if (fh->neighbor(i)!=NULL) + face_queue.push(fh->neighbor(i)); + } + } + } + } + + // (3) Now we iterates on the internal faces to add the vertices to the + // positions and the normals to the appropriate vectors + for(typename CDT::Finite_faces_iterator ffit=cdt.finite_faces_begin(), + ffitend = cdt.finite_faces_end(); ffit!=ffitend; ++ffit) + { + if(!ffit->info().is_external) + { + for(int i=0; i<3; ++i) + { + // The point + pos_faces.push_back(ffit->vertex(i)->point().x()); + pos_faces.push_back(ffit->vertex(i)->point().y()); + pos_faces.push_back(ffit->vertex(i)->point().z()); + + // Its color + colors.push_back(r);colors.push_back(g);colors.push_back(b); + + // Its flat normal + flat_normals.push_back(normal.x()); + flat_normals.push_back(normal.y()); + flat_normals.push_back(normal.z()); + + // Its smoth normal (if given by the user) + smooth_normals.push_back(ffit->vertex(i)->info().v.x()); + smooth_normals.push_back(ffit->vertex(i)->info().v.y()); + smooth_normals.push_back(ffit->vertex(i)->info().v.z()); + } + } + } + } + catch(...) + { // Triangulation crash: the face is not filled + std::cout<<"Catch: face not filled."<compileSourceCode(vertex_source_mono)) + { + std::cerr<<"Compiling vertex source FAILED"<compileSourceCode(vertex_source_multi)) + { + std::cerr<<"Compiling vertex source FAILED"<compileSourceCode(fragment_source_mono)) + { + std::cerr<<"Compiling fragmentsource FAILED"<compileSourceCode(fragment_source_multi)) + { + 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_faces.size()*sizeof(float))); + vertexLocation[vaon] = rendering_program.attributeLocation("vertex"); + rendering_program.bind(); + rendering_program.enableAttributeArray(vertexLocation[vaon]); + rendering_program.setAttributeBuffer(vertexLocation[vaon],GL_FLOAT,0,3); + rendering_program.release(); + + buffers[bufn].release(); + ++bufn; + + //normals of the facets + assert(bufn(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); + rendering_program.release(); + + buffers[bufn].release(); + ++bufn; + + if (!m_use_mono_color) + { + //colors of the facets + assert(bufn(colors.size()*sizeof(float))); + colorsLocation = rendering_program.attributeLocation("color"); + rendering_program.bind(); + rendering_program.enableAttributeArray(colorsLocation); + rendering_program.setAttributeBuffer(colorsLocation,GL_FLOAT,0,3); + rendering_program.release(); + + buffers[bufn].release(); + ++bufn; + } + + vao[vaon].release(); + ++vaon; + + assert(vaon(pos_faces.size()*sizeof(float))); + vertexLocation[vaon] = rendering_program.attributeLocation("vertex"); + rendering_program.bind(); + rendering_program.enableAttributeArray(vertexLocation[vaon]); + rendering_program.setAttributeBuffer(vertexLocation[vaon],GL_FLOAT,0,3); + rendering_program.release(); + + buffers[bufn].release(); + ++bufn; + + //normals of the facets + assert(bufn(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); + rendering_program.release(); + + buffers[bufn].release(); + ++bufn; + + if (!m_use_mono_color) + { + //colors of the facets + assert(bufn(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[bufn].release(); + + rendering_program.release(); + ++bufn; + } + + vao[vaon].release(); + ++vaon; + + //The segments + assert(vaon(pos_segments.size()*sizeof(float))); + vertexLocation[vaon] = rendering_program_p_l.attributeLocation("vertex"); + rendering_program_p_l.bind(); + rendering_program_p_l.enableAttributeArray(vertexLocation[vaon]); + rendering_program_p_l.setAttributeBuffer(vertexLocation[vaon],GL_FLOAT,0,3); + rendering_program_p_l.release(); + + buffers[bufn].release(); + ++bufn; + + vao[vaon].release(); + ++vaon; + + //The points + assert(vaon(pos_points.size()*sizeof(float))); + vertexLocation[vaon] = rendering_program_p_l.attributeLocation("vertex"); + rendering_program_p_l.bind(); + rendering_program_p_l.enableAttributeArray(vertexLocation[vaon]); + rendering_program_p_l.setAttributeBuffer(vertexLocation[vaon],GL_FLOAT,0,3); + rendering_program_p_l.release(); + + buffers[bufn].release(); + ++bufn; + + vao[vaon].release(); + ++vaon; + + m_are_buffers_initialized = true; + } + + void 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 diffuse( 0.9f, + 0.9f, + 0.9f, + 0.9f ); + + QVector4D specular( 0.0f, + 0.0f, + 0.0f, + 1.0f ); + + QVector4D position((bb.xmax()-bb.xmin())/2, (bb.ymax()-bb.ymin())/2,bb.zmax(), 0.0 ); + 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], m_ambient_color); + rendering_program.setUniformValue(lightLocation[4], shininess); + rendering_program.setUniformValue(mvpLocation[0], mvpMatrix); + rendering_program.setUniformValue(mvLocation, mvMatrix); + + if (m_use_mono_color) + colorLocation2 = rendering_program.uniformLocation("color"); + + 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(); + } + + virtual void draw() + { + glEnable(GL_DEPTH_TEST); + if(!m_are_buffers_initialized) + initialize_buffers(); + + QColor color; + + if(m_draw_vertices) + { + ::glPointSize(m_size_points); + vao[3].bind(); + attrib_buffers(this); + color.setRgbF((double)m_vertices_mono_color.red()/(double)255, + (double)m_vertices_mono_color.green()/(double)255, + (double)m_vertices_mono_color.blue()/(double)255); + 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(); + } + + if(m_draw_edges) + { + vao[2].bind(); + attrib_buffers(this); + color.setRgbF((double)m_edges_mono_color.red()/(double)255, + (double)m_edges_mono_color.green()/(double)255, + (double)m_edges_mono_color.blue()/(double)255); + rendering_program_p_l.bind(); + rendering_program_p_l.setAttributeValue(colorLocation,color); + ::glLineWidth(m_size_edges); + glDrawArrays(GL_LINES, 0, static_cast(pos_segments.size()/3)); + rendering_program_p_l.release(); + vao[2].release(); + } + + if (m_draw_faces) + { + if(m_flatShading) + { vao[0].bind(); } + else + { vao[1].bind(); } + + attrib_buffers(this); + rendering_program.bind(); + if (m_use_mono_color) + { + color.setRgbF((double)m_faces_mono_color.red()/(double)255, + (double)m_faces_mono_color.green()/(double)255, + (double)m_faces_mono_color.blue()/(double)255); + rendering_program.setUniformValue(colorLocation2,color); + } + glDrawArrays(GL_TRIANGLES, 0, static_cast(pos_faces.size()/3)); + rendering_program.release(); + + if(m_flatShading) + { vao[0].release(); } + else + { vao[1].release(); } + } + } + + virtual void init() + { + // Restore previous viewer state. + restoreStateFromFile(); + initializeOpenGLFunctions(); + + // Define 'Control+Q' as the new exit shortcut (default was 'Escape') + setShortcut(EXIT_VIEWER, Qt::CTRL+Qt::Key_Q); + + // Add custom key description (see keyPressEvent). + setKeyDescription(Qt::Key_E, "Toggles edges display"); + setKeyDescription(Qt::Key_F, "Toggles faces display"); + setKeyDescription(Qt::Key_G, "Switch between flat/Gouraud shading display"); + setKeyDescription(Qt::Key_M, "Toggles mono color for all faces"); + setKeyDescription(Qt::Key_N, "Inverse direction of normals"); + setKeyDescription(Qt::Key_V, "Toggles vertices display"); + setKeyDescription(Qt::Key_Plus, "Increase size of edges"); + setKeyDescription(Qt::Key_Minus, "Decrease size of edges"); + setKeyDescription(Qt::Key_Plus+Qt::ShiftModifier, "Increase size of vertices"); + setKeyDescription(Qt::Key_Minus+Qt::ShiftModifier, "Decrease size of vertices"); + setKeyDescription(Qt::Key_PageDown, "Increase light (all colors, use shift/alt/ctrl for one rgb component)"); + setKeyDescription(Qt::Key_PageUp, "Decrease light (all colors, use shift/alt/ctrl for one rgb component)"); + + // Light default parameters + ::glLineWidth(m_size_edges); + ::glPointSize(m_size_points); + ::glEnable(GL_POLYGON_OFFSET_FILL); + ::glPolygonOffset(1.f,1.f); + ::glClearColor(1.0f,1.0f,1.0f,0.0f); + ::glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); + ::glEnable(GL_LIGHTING); + ::glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); + ::glShadeModel(GL_FLAT); + ::glDisable(GL_BLEND); + ::glEnable(GL_LINE_SMOOTH); + ::glDisable(GL_POLYGON_SMOOTH_HINT); + ::glBlendFunc(GL_ONE, GL_ZERO); + ::glHint(GL_LINE_SMOOTH_HINT, GL_FASTEST); + + compile_shaders(); + + this->camera()->setSceneBoundingBox(qglviewer::Vec(bb.xmin(), + bb.ymin(), + bb.zmin()), + qglviewer::Vec(bb.xmax(), + bb.ymax(), + bb.zmax())); + + this->showEntireScene(); + } + + void negate_all_normals() + { + for (std::size_t i=0; imodifiers(); + + if ((e->key()==Qt::Key_E) && (modifiers==Qt::NoButton)) + { + m_draw_edges=!m_draw_edges; + displayMessage(QString("Draw edges=%1.").arg(m_draw_edges?"true":"false")); + updateGL(); + } + else if ((e->key()==Qt::Key_F) && (modifiers==Qt::NoButton)) + { + m_draw_faces=!m_draw_faces; + displayMessage(QString("Draw faces=%1.").arg(m_draw_faces?"true":"false")); + updateGL(); + } + else if ((e->key()==Qt::Key_G) && (modifiers==Qt::NoButton)) + { + m_flatShading=!m_flatShading; + if (m_flatShading) + displayMessage("Flat shading."); + else + displayMessage("Gouraud shading."); + updateGL(); + } + else if ((e->key()==Qt::Key_M) && (modifiers==Qt::NoButton)) + { + m_use_mono_color=!m_use_mono_color; + initialize_buffers(); + compile_shaders(); + displayMessage(QString("Mono color=%1.").arg(m_use_mono_color?"true":"false")); + updateGL(); + } + else if ((e->key()==Qt::Key_N) && (modifiers==Qt::NoButton)) + { + m_inverse_normal=!m_inverse_normal; + negate_all_normals(); + initialize_buffers(); + compile_shaders(); + displayMessage(QString("Inverse normal=%1.").arg(m_inverse_normal?"true":"false")); + updateGL(); + } + else if ((e->key()==Qt::Key_V) && (modifiers==Qt::NoButton)) + { + m_draw_vertices=!m_draw_vertices; + displayMessage(QString("Draw vertices=%1.").arg(m_draw_vertices?"true":"false")); + updateGL(); + } + else if ((e->key()==Qt::Key_Plus) && (modifiers==Qt::KeypadModifier)) + { + m_size_edges+=.5; + displayMessage(QString("Size of edges=%1.").arg(m_size_edges)); + updateGL(); + } + else if ((e->key()==Qt::Key_Minus) && (modifiers==Qt::KeypadModifier)) + { + if (m_size_edges>.5) m_size_edges-=.5; + displayMessage(QString("Size of edges=%1.").arg(m_size_edges)); + updateGL(); + } + else if ((e->key()==Qt::Key_Plus) && (modifiers==(Qt::ShiftModifier|Qt::KeypadModifier))) + { + m_size_points+=.5; + displayMessage(QString("Size of points=%1.").arg(m_size_points)); + updateGL(); + } + else if ((e->key()==Qt::Key_Minus) && (modifiers==(Qt::ShiftModifier|Qt::KeypadModifier))) + { + if (m_size_points>.5) m_size_points-=.5; + displayMessage(QString("Size of points=%1.").arg(m_size_points)); + updateGL(); + } + else if ((e->key()==Qt::Key_PageUp) && (modifiers==Qt::NoButton)) + { + m_ambient_color.setX(m_ambient_color.x()+.1); + if (m_ambient_color.x()>1.) m_ambient_color.setX(1.); + m_ambient_color.setY(m_ambient_color.x()+.1); + if (m_ambient_color.y()>1.) m_ambient_color.setY(1.); + m_ambient_color.setZ(m_ambient_color.x()+.1); + if (m_ambient_color.z()>1.) m_ambient_color.setZ(1.); + displayMessage(QString("Light color=(%1 %2 %3)."). + arg(m_ambient_color.x()).arg(m_ambient_color.y()).arg(m_ambient_color.z())); + updateGL(); + } + else if ((e->key()==Qt::Key_PageDown) && (modifiers==Qt::NoButton)) + { + m_ambient_color.setX(m_ambient_color.x()-.1); + if (m_ambient_color.x()<0.) m_ambient_color.setX(0.); + m_ambient_color.setY(m_ambient_color.y()-.1); + if (m_ambient_color.y()<0.) m_ambient_color.setY(0.); + m_ambient_color.setZ(m_ambient_color.z()-.1); + if (m_ambient_color.z()<0.) m_ambient_color.setZ(0.); + displayMessage(QString("Light color=(%1 %2 %3)."). + arg(m_ambient_color.x()).arg(m_ambient_color.y()).arg(m_ambient_color.z())); + updateGL(); + } + else if ((e->key()==Qt::Key_PageUp) && (modifiers==Qt::ShiftModifier)) + { + m_ambient_color.setX(m_ambient_color.x()+.1); + if (m_ambient_color.x()>1.) m_ambient_color.setX(1.); + displayMessage(QString("Light color=(%1 %2 %3)."). + arg(m_ambient_color.x()).arg(m_ambient_color.y()).arg(m_ambient_color.z())); + updateGL(); + } + else if ((e->key()==Qt::Key_PageUp) && (modifiers==Qt::AltModifier)) + { + m_ambient_color.setY(m_ambient_color.y()+.1); + if (m_ambient_color.y()>1.) m_ambient_color.setY(1.); + displayMessage(QString("Light color=(%1 %2 %3)."). + arg(m_ambient_color.x()).arg(m_ambient_color.y()).arg(m_ambient_color.z())); + updateGL(); + } + else if ((e->key()==Qt::Key_PageUp) && (modifiers==Qt::ControlModifier)) + { + m_ambient_color.setZ(m_ambient_color.z()+.1); + if (m_ambient_color.z()>1.) m_ambient_color.setZ(1.); + displayMessage(QString("Light color=(%1 %2 %3)."). + arg(m_ambient_color.x()).arg(m_ambient_color.y()).arg(m_ambient_color.z())); + updateGL(); + } + else if ((e->key()==Qt::Key_PageDown) && (modifiers==Qt::ShiftModifier)) + { + m_ambient_color.setX(m_ambient_color.x()-.1); + if (m_ambient_color.x()<0.) m_ambient_color.setX(0.); + displayMessage(QString("Light color=(%1 %2 %3)."). + arg(m_ambient_color.x()).arg(m_ambient_color.y()).arg(m_ambient_color.z())); + updateGL(); + } + else if ((e->key()==Qt::Key_PageDown) && (modifiers==Qt::AltModifier)) + { + m_ambient_color.setY(m_ambient_color.y()-.1); + if (m_ambient_color.y()<0.) m_ambient_color.setY(0.); + displayMessage(QString("Light color=(%1 %2 %3)."). + arg(m_ambient_color.x()).arg(m_ambient_color.y()).arg(m_ambient_color.z())); + updateGL(); + } + else if ((e->key()==Qt::Key_PageDown) && (modifiers==Qt::ControlModifier)) + { + m_ambient_color.setZ(m_ambient_color.z()-.1); + if (m_ambient_color.z()<0.) m_ambient_color.setZ(0.); + displayMessage(QString("Light color=(%1 %2 %3)."). + arg(m_ambient_color.x()).arg(m_ambient_color.y()).arg(m_ambient_color.z())); + updateGL(); + } + else + QGLViewer::keyPressEvent(e); + } + + virtual QString helpString() const + { + QString text("

C G A L B a s i c 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; + } + +private: + bool m_draw_vertices; + bool m_draw_edges; + bool m_draw_faces; + bool m_flatShading; + bool m_use_mono_color; + bool m_inverse_normal; + + double m_size_points; + double m_size_edges; + + CGAL::Color m_vertices_mono_color; + CGAL::Color m_edges_mono_color; + CGAL::Color m_faces_mono_color; + QVector4D m_ambient_color; + + bool m_are_buffers_initialized; + CGAL::Bbox_3 bb; + + //Shaders elements + int vertexLocation[NB_VAO_BUFFERS]; + int normalsLocation; + int mvpLocation[2]; + int mvLocation; + int colorLocation; + int colorLocation2; + int lightLocation[5]; + + std::vector pos_points; + std::vector pos_segments; + std::vector pos_faces; + std::vector smooth_normals; + std::vector flat_normals; + std::vector colors; + + QGLBuffer buffers[NB_VBO_BUFFERS]; + QOpenGLVertexArrayObject vao[NB_VAO_BUFFERS]; + int colorsLocation; + + QOpenGLShaderProgram rendering_program; + QOpenGLShaderProgram rendering_program_p_l; + + bool m_face_started; + std::vector points_of_face; + std::vector vertex_normals_for_face; + CGAL::Color color_of_face; +}; + +#endif // CGAL_BASIC_VIEWER_H From f0a44e2483f54bad7c5db40a3cb1701db0ffcd60 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Tue, 14 Nov 2017 19:12:10 +0100 Subject: [PATCH 07/11] update basic viewer to allow to draw mono and color faces --- .../Linear_cell_complex/basic_viewer.h | 635 +++++++++--------- 1 file changed, 333 insertions(+), 302 deletions(-) diff --git a/Linear_cell_complex/examples/Linear_cell_complex/basic_viewer.h b/Linear_cell_complex/examples/Linear_cell_complex/basic_viewer.h index 21f88cfc1bd..41541c15f94 100644 --- a/Linear_cell_complex/examples/Linear_cell_complex/basic_viewer.h +++ b/Linear_cell_complex/examples/Linear_cell_complex/basic_viewer.h @@ -67,7 +67,7 @@ const char vertex_source_mono[] = "}" }; -const char vertex_source_multi[] = +const char vertex_source_color[] = { "#version 120 \n" "attribute highp vec4 vertex;\n" @@ -120,7 +120,7 @@ const char fragment_source_mono[] = "\n" }; -const char fragment_source_multi[] = +const char fragment_source_color[] = { "#version 120 \n" "varying highp vec4 fP; \n" @@ -237,6 +237,7 @@ public: m_flatShading(true), m_use_mono_color(false), m_inverse_normal(false), + m_empty(true), m_size_points(7.), m_size_edges(3.1), m_vertices_mono_color(51, 51, 178), @@ -271,53 +272,63 @@ public: void clear() { - pos_points.clear(); - pos_segments.clear(); - pos_faces.clear(); - smooth_normals.clear(); - flat_normals.clear(); - colors.clear(); + for (unsigned int i=0; i& point_vector) { - pos_points.push_back(p.x()); - pos_points.push_back(p.y()); - pos_points.push_back(p.z()); + point_vector.push_back(p.x()); + point_vector.push_back(p.y()); + point_vector.push_back(p.z()); if (is_empty()) - { bb=p.bbox(); } + { bb=p.bbox(); m_empty=false; } else { bb=bb+p.bbox(); } } - - void add_segment(const Local_point& p1, const Local_point& p2) + + void add_color(const CGAL::Color& acolor, std::vector& color_vector) { - pos_segments.push_back(p1.x()); - pos_segments.push_back(p1.y()); - pos_segments.push_back(p1.z()); - - pos_segments.push_back(p2.x()); - pos_segments.push_back(p2.y()); - pos_segments.push_back(p2.z()); - - if (is_empty()) - { bb=p1.bbox(); } - else - { bb=bb+p1.bbox(); } - - bb=bb+p2.bbox(); + color_vector.push_back((double)color_of_face.red()/(double)255); + color_vector.push_back((double)color_of_face.green()/(double)255); + color_vector.push_back((double)color_of_face.blue()/(double)255); } - /// Start a new face. Its color will be the m_faces_mono_color. - void face_begin() - { face_begin(m_faces_mono_color); } + void add_normal(const Local_vector& n, std::vector& normal_vector) + { + normal_vector.push_back(n.x()); + normal_vector.push_back(n.y()); + normal_vector.push_back(n.z()); + } + + void add_mono_point(const Local_point& p) + { add_point(p, arrays[POS_MONO_POINTS]); } - /// Start a new face, with a given color. - void face_begin(const CGAL::Color& acolor) + void add_colored_point(const Local_point& p, const CGAL::Color& acolor) + { + add_point(p, arrays[POS_COLORED_POINTS]); + add_color(acolor, arrays[COLOR_POINTS]); + } + + void add_mono_segment(const Local_point& p1, const Local_point& p2) + { + add_point(p1, arrays[POS_MONO_SEGMENTS]); + add_point(p2, arrays[POS_MONO_SEGMENTS]); + } + + void add_colored_segment(const Local_point& p1, const Local_point& p2, + const CGAL::Color& acolor) + { + add_point(p1, arrays[POS_COLORED_SEGMENTS]); + add_point(p2, arrays[POS_COLORED_SEGMENTS]); + add_color(acolor, arrays[COLOR_SEGMENTS]); + } + + void face_begin() { if (m_face_started) { @@ -325,10 +336,23 @@ public: return; } - color_of_face=acolor; m_face_started=true; } + void mono_face_begin() + { + m_started_face_is_colored=false; + face_begin(); + } + + /// Start a new face, with a given color. + void colored_face_begin(const CGAL::Color& acolor) + { + color_of_face=acolor; + m_started_face_is_colored=true; + face_begin(); + } + /// Add a point at the end of the current face /// With this method, it is not possible to use the Gourod shading. /// @param p the point to add @@ -339,12 +363,6 @@ public: if (points_of_face.empty() || points_of_face.back()!=p) { points_of_face.push_back(p); - - if (is_empty()) - { bb=p.bbox(); } - else - { bb=bb+p.bbox(); } - return true; } return false; @@ -380,43 +398,42 @@ public: Local_vector normal=compute_normal_of_face(points_of_face); - double r=(double)color_of_face.red()/(double)255; - double g=(double)color_of_face.green()/(double)255; - double b=(double)color_of_face.blue()/(double)255; - if (points_of_face.size()==3) // Triangle: no need to triangulate { for (int i=0; i<3; ++i) { // The point - pos_faces.push_back(points_of_face[i].x()); - pos_faces.push_back(points_of_face[i].y()); - pos_faces.push_back(points_of_face[i].z()); + add_point(points_of_face[i], arrays[m_started_face_is_colored? + POS_COLORED_FACES: + POS_MONO_FACES]); // Its color - colors.push_back(r); colors.push_back(g); colors.push_back(b); + if (m_started_face_is_colored) + { add_color(color_of_face, arrays[COLOR_FACES]); } // Its flat normal - flat_normals.push_back(normal.x()); - flat_normals.push_back(normal.y()); - flat_normals.push_back(normal.z()); + add_normal(normal, arrays[m_started_face_is_colored? + FLAT_NORMAL_COLORED_FACES: + FLAT_NORMAL_MONO_FACES]); // Its smoth normal (if given by the user) if (vertex_normals_for_face.size()==3) { // Here we have 3 vertex normals; we can use Gourod - smooth_normals.push_back(vertex_normals_for_face[i].x()); - smooth_normals.push_back(vertex_normals_for_face[i].y()); - smooth_normals.push_back(vertex_normals_for_face[i].z()); + add_normal(vertex_normals_for_face[i], arrays[m_started_face_is_colored? + SMOOTH_NORMAL_COLORED_FACES: + SMOOTH_NORMAL_MONO_FACES]); } else { // Here user does not provide all vertex normals: we use face normal istead // and thus we will not be able to use Gourod - smooth_normals.push_back(normal.x()); - smooth_normals.push_back(normal.y()); - smooth_normals.push_back(normal.z()); + add_normal(normal, arrays[m_started_face_is_colored? + SMOOTH_NORMAL_COLORED_FACES: + SMOOTH_NORMAL_MONO_FACES]); } } } + // TODO CASE OF 4 POINTS ? PB HOW TO FIND (EASILY) THE TWO POINTS TO LINK ? + // else if (points_of_face.size()==4) else { // More than 3 points: we triangulate try @@ -514,22 +531,23 @@ public: for(int i=0; i<3; ++i) { // The point - pos_faces.push_back(ffit->vertex(i)->point().x()); - pos_faces.push_back(ffit->vertex(i)->point().y()); - pos_faces.push_back(ffit->vertex(i)->point().z()); + add_point(ffit->vertex(i)->point(), arrays[m_started_face_is_colored? + POS_COLORED_FACES: + POS_MONO_FACES]); // Its color - colors.push_back(r);colors.push_back(g);colors.push_back(b); - + if (m_started_face_is_colored) + { add_color(color_of_face, arrays[COLOR_FACES]); } + // Its flat normal - flat_normals.push_back(normal.x()); - flat_normals.push_back(normal.y()); - flat_normals.push_back(normal.z()); + add_normal(normal, arrays[m_started_face_is_colored? + FLAT_NORMAL_COLORED_FACES: + FLAT_NORMAL_MONO_FACES]); // Its smoth normal (if given by the user) - smooth_normals.push_back(ffit->vertex(i)->info().v.x()); - smooth_normals.push_back(ffit->vertex(i)->info().v.y()); - smooth_normals.push_back(ffit->vertex(i)->info().v.z()); + add_normal(ffit->vertex(i)->info().v, arrays[m_started_face_is_colored? + SMOOTH_NORMAL_COLORED_FACES: + SMOOTH_NORMAL_MONO_FACES]); } } } @@ -549,241 +567,211 @@ protected: void compile_shaders() { - rendering_program.removeAllShaders(); - rendering_program_p_l.removeAllShaders(); + rendering_program_mono.removeAllShaders(); + rendering_program_color.removeAllShaders(); + /*rendering_program_p_l_mono.removeAllShaders(); + rendering_program_p_l_color.removeAllShaders(); */ // Create the buffers for (int i=0; icompileSourceCode(vertex_source_mono)) - { - std::cerr<<"Compiling vertex source FAILED"<compileSourceCode(vertex_source_multi)) - { - std::cerr<<"Compiling vertex source FAILED"<compileSourceCode(fragment_source_mono)) - { - std::cerr<<"Compiling fragmentsource FAILED"<compileSourceCode(fragment_source_multi)) - { - std::cerr<<"Compiling fragmentsource FAILED"<compileSourceCode(vertex_source_mono)) + { std::cerr<<"Compiling vertex source FAILED"<compileSourceCode(fragment_source_mono)) + { std::cerr<<"Compiling fragmentsource FAILED"<compileSourceCode(vertex_source_p_l)) + if(!rendering_program_mono.addShader(vertex_shader_mono)) + { std::cerr<<"adding vertex shader FAILED"<compileSourceCode(vertex_source_mono)) + { std::cerr<<"Compiling vertex source FAILED"<compileSourceCode(fragment_source_mono)) + { std::cerr<<"Compiling fragmentsource FAILED"<compileSourceCode(vertex_source_color)) + { std::cerr<<"Compiling vertex source FAILED"<compileSourceCode(fragment_source_color)) + { 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_faces.size()*sizeof(float))); - vertexLocation[vaon] = rendering_program.attributeLocation("vertex"); - rendering_program.bind(); - rendering_program.enableAttributeArray(vertexLocation[vaon]); - rendering_program.setAttributeBuffer(vertexLocation[vaon],GL_FLOAT,0,3); - rendering_program.release(); + buffers[bufn].allocate(arrays[POS_MONO_FACES].data(), + static_cast(arrays[POS_MONO_FACES].size()*sizeof(float))); + vertexLocation[vaon] = rendering_program_mono.attributeLocation("vertex"); + rendering_program_mono.bind(); + rendering_program_mono.enableAttributeArray(vertexLocation[vaon]); + rendering_program_mono.setAttributeBuffer(vertexLocation[vaon],GL_FLOAT,0,3); + rendering_program_mono.release(); buffers[bufn].release(); ++bufn; - //normals of the facets + // 3.1.2) normals of the mono faces assert(bufn(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); - rendering_program.release(); - - buffers[bufn].release(); - ++bufn; - - if (!m_use_mono_color) + if (m_flatShading) { - //colors of the facets - assert(bufn(colors.size()*sizeof(float))); - colorsLocation = rendering_program.attributeLocation("color"); - rendering_program.bind(); - rendering_program.enableAttributeArray(colorsLocation); - rendering_program.setAttributeBuffer(colorsLocation,GL_FLOAT,0,3); - rendering_program.release(); - - buffers[bufn].release(); - ++bufn; + buffers[bufn].allocate(arrays[FLAT_NORMAL_MONO_FACES].data(), + static_cast(arrays[FLAT_NORMAL_MONO_FACES].size()* + sizeof(float))); } + else + { + buffers[bufn].allocate(arrays[SMOOTH_NORMAL_MONO_FACES].data(), + static_cast(arrays[SMOOTH_NORMAL_MONO_FACES].size()* + sizeof(float))); + } + normalsLocation = rendering_program_mono.attributeLocation("normal"); + rendering_program_mono.bind(); + rendering_program_mono.enableAttributeArray(normalsLocation); + rendering_program_mono.setAttributeBuffer(normalsLocation,GL_FLOAT,0,3); + rendering_program_mono.release(); + buffers[bufn].release(); + ++bufn; + vao[vaon].release(); ++vaon; - + + // 3.2) Color faces assert(vaon(pos_faces.size()*sizeof(float))); - vertexLocation[vaon] = rendering_program.attributeLocation("vertex"); - rendering_program.bind(); - rendering_program.enableAttributeArray(vertexLocation[vaon]); - rendering_program.setAttributeBuffer(vertexLocation[vaon],GL_FLOAT,0,3); - rendering_program.release(); - + buffers[bufn].allocate(arrays[POS_COLORED_FACES].data(), + static_cast(arrays[POS_COLORED_FACES].size()*sizeof(float))); + vertexLocation[vaon] = rendering_program_color.attributeLocation("vertex"); + rendering_program_color.bind(); + rendering_program_color.enableAttributeArray(vertexLocation[vaon]); + rendering_program_color.setAttributeBuffer(vertexLocation[vaon],GL_FLOAT,0,3); + rendering_program_color.release(); + buffers[bufn].release(); ++bufn; - - //normals of the facets + + // 3.2.2) normals of the color faces assert(bufn(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); - rendering_program.release(); - + if (m_flatShading) + { + buffers[bufn].allocate(arrays[FLAT_NORMAL_COLORED_FACES].data(), + static_cast(arrays[FLAT_NORMAL_COLORED_FACES].size()* + sizeof(float))); + } + else + { + buffers[bufn].allocate(arrays[SMOOTH_NORMAL_COLORED_FACES].data(), + static_cast(arrays[SMOOTH_NORMAL_COLORED_FACES].size()* + sizeof(float))); + } + normalsLocation = rendering_program_color.attributeLocation("normal"); + rendering_program_color.bind(); + rendering_program_color.enableAttributeArray(normalsLocation); + rendering_program_color.setAttributeBuffer(normalsLocation,GL_FLOAT,0,3); + rendering_program_color.release(); + buffers[bufn].release(); ++bufn; - + + // 3.2.3) colors of the faces if (!m_use_mono_color) { - //colors of the facets assert(bufn(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[bufn].allocate(arrays[COLOR_FACES].data(), + static_cast(arrays[COLOR_FACES].size()*sizeof(float))); + colorsLocation = rendering_program_color.attributeLocation("color"); + rendering_program_color.bind(); + rendering_program_color.enableAttributeArray(colorsLocation); + rendering_program_color.setAttributeBuffer(colorsLocation,GL_FLOAT,0,3); + rendering_program_color.release(); + buffers[bufn].release(); - - rendering_program.release(); ++bufn; } - - vao[vaon].release(); - ++vaon; - - //The segments - assert(vaon(pos_segments.size()*sizeof(float))); - vertexLocation[vaon] = rendering_program_p_l.attributeLocation("vertex"); - rendering_program_p_l.bind(); - rendering_program_p_l.enableAttributeArray(vertexLocation[vaon]); - rendering_program_p_l.setAttributeBuffer(vertexLocation[vaon],GL_FLOAT,0,3); - rendering_program_p_l.release(); - - buffers[bufn].release(); - ++bufn; - - vao[vaon].release(); - ++vaon; - - //The points - assert(vaon(pos_points.size()*sizeof(float))); - vertexLocation[vaon] = rendering_program_p_l.attributeLocation("vertex"); - rendering_program_p_l.bind(); - rendering_program_p_l.enableAttributeArray(vertexLocation[vaon]); - rendering_program_p_l.setAttributeBuffer(vertexLocation[vaon],GL_FLOAT,0,3); - rendering_program_p_l.release(); - - buffers[bufn].release(); - ++bufn; vao[vaon].release(); - ++vaon; - + ++vaon; + m_are_buffers_initialized = true; } @@ -816,33 +804,52 @@ protected: QVector4D position((bb.xmax()-bb.xmin())/2, (bb.ymax()-bb.ymin())/2,bb.zmax(), 0.0 ); 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_mono.bind(); + mvpLocation[0] = rendering_program_mono.uniformLocation("mvp_matrix"); + mvLocation = rendering_program_mono.uniformLocation("mv_matrix"); + lightLocation[0] = rendering_program_mono.uniformLocation("light_pos"); + lightLocation[1] = rendering_program_mono.uniformLocation("light_diff"); + lightLocation[2] = rendering_program_mono.uniformLocation("light_spec"); + lightLocation[3] = rendering_program_mono.uniformLocation("light_amb"); + lightLocation[4] = rendering_program_mono.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], m_ambient_color); - rendering_program.setUniformValue(lightLocation[4], shininess); - rendering_program.setUniformValue(mvpLocation[0], mvpMatrix); - rendering_program.setUniformValue(mvLocation, mvMatrix); + rendering_program_mono.setUniformValue(lightLocation[0], position); + rendering_program_mono.setUniformValue(lightLocation[1], diffuse); + rendering_program_mono.setUniformValue(lightLocation[2], specular); + rendering_program_mono.setUniformValue(lightLocation[3], m_ambient_color); + rendering_program_mono.setUniformValue(lightLocation[4], shininess); + rendering_program_mono.setUniformValue(mvpLocation[0], mvpMatrix); + rendering_program_mono.setUniformValue(mvLocation, mvMatrix); + + colorLocation1 = rendering_program_mono.uniformLocation("color"); + rendering_program_mono.release(); + + rendering_program_color.bind(); + mvpLocation[0] = rendering_program_color.uniformLocation("mvp_matrix"); + mvLocation = rendering_program_color.uniformLocation("mv_matrix"); + lightLocation[0] = rendering_program_color.uniformLocation("light_pos"); + lightLocation[1] = rendering_program_color.uniformLocation("light_diff"); + lightLocation[2] = rendering_program_color.uniformLocation("light_spec"); + lightLocation[3] = rendering_program_color.uniformLocation("light_amb"); + lightLocation[4] = rendering_program_color.uniformLocation("spec_power"); + + rendering_program_color.setUniformValue(lightLocation[0], position); + rendering_program_color.setUniformValue(lightLocation[1], diffuse); + rendering_program_color.setUniformValue(lightLocation[2], specular); + rendering_program_color.setUniformValue(lightLocation[3], m_ambient_color); + rendering_program_color.setUniformValue(lightLocation[4], shininess); + rendering_program_color.setUniformValue(mvpLocation[0], mvpMatrix); + rendering_program_color.setUniformValue(mvLocation, mvMatrix); if (m_use_mono_color) - colorLocation2 = rendering_program.uniformLocation("color"); - - rendering_program.release(); + { colorLocation2 = rendering_program_color.uniformLocation("color"); } + rendering_program_color.release(); - rendering_program_p_l.bind(); + /* 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(); + rendering_program_p_l.release();*/ } virtual void draw() @@ -853,7 +860,7 @@ protected: QColor color; - if(m_draw_vertices) + /* if(m_draw_vertices) { ::glPointSize(m_size_points); vao[3].bind(); @@ -863,7 +870,7 @@ protected: (double)m_vertices_mono_color.blue()/(double)255); rendering_program_p_l.bind(); rendering_program_p_l.setAttributeValue(colorLocation,color); - glDrawArrays(GL_POINTS, 0, static_cast(pos_points.size()/3)); + // glDrawArrays(GL_POINTS, 0, static_cast(pos_points.size()/3)); rendering_program_p_l.release(); vao[3].release(); } @@ -878,34 +885,37 @@ protected: rendering_program_p_l.bind(); rendering_program_p_l.setAttributeValue(colorLocation,color); ::glLineWidth(m_size_edges); - glDrawArrays(GL_LINES, 0, static_cast(pos_segments.size()/3)); + // glDrawArrays(GL_LINES, 0, static_cast(pos_segments.size()/3)); rendering_program_p_l.release(); vao[2].release(); - } + }*/ if (m_draw_faces) { - if(m_flatShading) - { vao[0].bind(); } - else - { vao[1].bind(); } - + vao[0].bind(); attrib_buffers(this); - rendering_program.bind(); + rendering_program_mono.bind(); + color.setRgbF((double)m_faces_mono_color.red()/(double)255, + (double)m_faces_mono_color.green()/(double)255, + (double)m_faces_mono_color.blue()/(double)255); + rendering_program_mono.setUniformValue(colorLocation1,color); + glDrawArrays(GL_TRIANGLES, 0, static_cast(arrays[POS_MONO_FACES].size()/3)); + rendering_program_mono.release(); + vao[0].release(); + + vao[1].bind(); + attrib_buffers(this); + rendering_program_color.bind(); if (m_use_mono_color) { color.setRgbF((double)m_faces_mono_color.red()/(double)255, (double)m_faces_mono_color.green()/(double)255, (double)m_faces_mono_color.blue()/(double)255); - rendering_program.setUniformValue(colorLocation2,color); + rendering_program_color.setUniformValue(colorLocation2,color); } - glDrawArrays(GL_TRIANGLES, 0, static_cast(pos_faces.size()/3)); - rendering_program.release(); - - if(m_flatShading) - { vao[0].release(); } - else - { vao[1].release(); } + glDrawArrays(GL_TRIANGLES, 0, static_cast(arrays[POS_COLORED_FACES].size()/3)); + rendering_program_color.release(); + vao[1].release(); } } @@ -962,11 +972,11 @@ protected: void negate_all_normals() { - for (std::size_t i=0; ikey()==Qt::Key_M) && (modifiers==Qt::NoButton)) { m_use_mono_color=!m_use_mono_color; - initialize_buffers(); - compile_shaders(); displayMessage(QString("Mono color=%1.").arg(m_use_mono_color?"true":"false")); + compile_shaders(); + initialize_buffers(); updateGL(); } else if ((e->key()==Qt::Key_N) && (modifiers==Qt::NoButton)) { m_inverse_normal=!m_inverse_normal; negate_all_normals(); - initialize_buffers(); compile_shaders(); + initialize_buffers(); displayMessage(QString("Inverse normal=%1.").arg(m_inverse_normal?"true":"false")); updateGL(); } @@ -1156,7 +1168,8 @@ private: bool m_flatShading; bool m_use_mono_color; bool m_inverse_normal; - + bool m_empty; + double m_size_points; double m_size_edges; @@ -1173,25 +1186,43 @@ private: int normalsLocation; int mvpLocation[2]; int mvLocation; - int colorLocation; + int colorLocation1; int colorLocation2; int lightLocation[5]; - std::vector pos_points; - std::vector pos_segments; - std::vector pos_faces; - std::vector smooth_normals; - std::vector flat_normals; - std::vector colors; + enum + { POS_MONO_POINTS=0, + POS_COLORED_POINTS, + POS_MONO_SEGMENTS, + POS_COLORED_SEGMENTS, + POS_MONO_FACES, + POS_COLORED_FACES, + BEGIN_NORMAL, + SMOOTH_NORMAL_MONO_FACES=BEGIN_NORMAL, + FLAT_NORMAL_MONO_FACES, + SMOOTH_NORMAL_COLORED_FACES, + FLAT_NORMAL_COLORED_FACES, + END_NORMAL, + COLOR_POINTS=END_NORMAL, + COLOR_SEGMENTS, + COLOR_FACES, + LAST_INDEX + }; + + std::vector arrays[LAST_INDEX]; QGLBuffer buffers[NB_VBO_BUFFERS]; QOpenGLVertexArrayObject vao[NB_VAO_BUFFERS]; int colorsLocation; - QOpenGLShaderProgram rendering_program; - QOpenGLShaderProgram rendering_program_p_l; + QOpenGLShaderProgram rendering_program_mono; + QOpenGLShaderProgram rendering_program_color; + QOpenGLShaderProgram rendering_program_p_l_mono; + QOpenGLShaderProgram rendering_program_p_l_color; + // Local variables, used when we started a new face. bool m_face_started; + bool m_started_face_is_colored; std::vector points_of_face; std::vector vertex_normals_for_face; CGAL::Color color_of_face; From 2f0f97fa47fadef6fbe6b1395cdf0c959783b00a Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Wed, 15 Nov 2017 12:16:13 +0100 Subject: [PATCH 08/11] Update basic viewer to use a generic name. --- ...LCCViewerQt.inc => CMakeBasicViewerQt.inc} | 16 +++++------ .../Linear_cell_complex/CMakeLists.txt | 28 ++++++++++++------- .../linear_cell_complex_3_operations.cpp | 10 +++---- .../linear_cell_complex_3_viewer_qt.h | 9 ++++-- .../Linear_cell_complex/voronoi_2.cpp | 6 ++-- .../Linear_cell_complex/voronoi_3.cpp | 6 ++-- 6 files changed, 43 insertions(+), 32 deletions(-) rename Linear_cell_complex/examples/Linear_cell_complex/{CMakeLCCViewerQt.inc => CMakeBasicViewerQt.inc} (61%) diff --git a/Linear_cell_complex/examples/Linear_cell_complex/CMakeLCCViewerQt.inc b/Linear_cell_complex/examples/Linear_cell_complex/CMakeBasicViewerQt.inc similarity index 61% rename from Linear_cell_complex/examples/Linear_cell_complex/CMakeLCCViewerQt.inc rename to Linear_cell_complex/examples/Linear_cell_complex/CMakeBasicViewerQt.inc index 467af4ff419..5dd94c1e7f9 100644 --- a/Linear_cell_complex/examples/Linear_cell_complex/CMakeLCCViewerQt.inc +++ b/Linear_cell_complex/examples/Linear_cell_complex/CMakeBasicViewerQt.inc @@ -1,9 +1,9 @@ -# This file must be included in your CMakeLists.txt to use cgal_map_viewer_qt.h. +# This file must be included in your CMakeLists.txt to use the basic viewer # You need to link the libraries in your executable by using -# TARGET_LINK_LIBRARIES( myexec ${MAP_VIEWER_LIBRARIES}) +# TARGET_LINK_LIBRARIES( myexec ${BASIC_VIEWER_LIBRARIES}) if ( NOT CGAL_FOUND OR NOT CGAL_Qt5_FOUND) - message(STATUS "NOTICE: Libraries for lcc_viewer not found " + message(STATUS "NOTICE: Libraries for basic viewer not found " "(CGAL, Qt5, QGLViewer).") endif( NOT CGAL_FOUND OR NOT CGAL_Qt5_FOUND) @@ -20,14 +20,14 @@ add_definitions(-DQT_NO_KEYWORDS) include_directories( ${QGLVIEWER_INCLUDE_DIR} ) add_definitions(${QGLVIEWER_DEFINITIONS}) -set (MAP_VIEWER_LIBRARIES ${QT_LIBRARIES} ${QGLVIEWER_LIBRARIES} +set (BASIC_VIEWER_LIBRARIES ${QT_LIBRARIES} ${QGLVIEWER_LIBRARIES} ${OPENGL_gl_LIBRARY}) # ${OPENGL_glu_LIBRARY} -set(MAP_VIEWER_MODULES Xml OpenGL) +set(BASIC_VIEWER_MODULES Xml OpenGL) -ADD_DEFINITIONS("-DCGAL_LCC_USE_VIEWER -DCGAL_LCC_USE_QT") +ADD_DEFINITIONS("-DCGAL_USE_BASIC_VIEWER") message(STATUS "Libraries for lcc_viewer found. You need to link them " "in your executable by using " - "TARGET_LINK_LIBRARIES( myexec \${MAP_VIEWER_LIBRARIES})") + "TARGET_LINK_LIBRARIES( myexec \${BASIC_VIEWER_LIBRARIES})") -set(LCC_VIEWER true) +set(USE_BASIC_VIEWER true) diff --git a/Linear_cell_complex/examples/Linear_cell_complex/CMakeLists.txt b/Linear_cell_complex/examples/Linear_cell_complex/CMakeLists.txt index 22358aaf17c..620838e007b 100644 --- a/Linear_cell_complex/examples/Linear_cell_complex/CMakeLists.txt +++ b/Linear_cell_complex/examples/Linear_cell_complex/CMakeLists.txt @@ -11,14 +11,16 @@ if(POLICY CMP0043) cmake_policy(SET CMP0043 OLD) endif() +ADD_DEFINITIONS("-std=c++11") + # If you want to visualize a linear cell complex, you can use the following viewer # based on qt. Just uncomment the following two lines, plus the lines qt5_use_modules below -# find_package(CGAL COMPONENTS Qt5) -# include("CMakeLCCViewerQt.inc") +find_package(CGAL COMPONENTS Qt5) +include("CMakeBasicViewerQt.inc") # If you don't want to visualize, use the following line (otherwise comment it) -find_package(CGAL QUIET) +# find_package(CGAL QUIET) # For Gprof. # ADD_DEFINITIONS("-pg") @@ -45,21 +47,27 @@ if ( CGAL_FOUND ) add_executable(voronoi_2 voronoi_2.cpp) target_link_libraries(voronoi_2 ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES} - ${MAP_VIEWER_LIBRARIES}) -# qt5_use_modules(voronoi_2 ${MAP_VIEWER_MODULES}) + ${BASIC_VIEWER_LIBRARIES}) + if (USE_BASIC_VIEWER) + qt5_use_modules(voronoi_2 ${BASIC_VIEWER_MODULES}) + endif(USE_BASIC_VIEWER) add_executable(voronoi_3 voronoi_3.cpp) target_link_libraries(voronoi_3 ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES} - ${MAP_VIEWER_LIBRARIES}) -# qt5_use_modules(voronoi_3 ${MAP_VIEWER_MODULES}) + ${BASIC_VIEWER_LIBRARIES}) + if (USE_BASIC_VIEWER) + qt5_use_modules(voronoi_3 ${BASIC_VIEWER_MODULES}) + endif(USE_BASIC_VIEWER) + create_single_source_cgal_program( "gmap_linear_cell_complex_3.cpp" ) add_executable(linear_cell_complex_3_operations linear_cell_complex_3_operations.cpp) target_link_libraries(linear_cell_complex_3_operations ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES} - ${MAP_VIEWER_LIBRARIES}) -# qt5_use_modules(linear_cell_complex_3_operations ${MAP_VIEWER_MODULES}) - + ${BASIC_VIEWER_LIBRARIES}) + if (USE_BASIC_VIEWER) + qt5_use_modules(linear_cell_complex_3_operations ${BASIC_VIEWER_MODULES}) + endif(USE_BASIC_VIEWER) else() diff --git a/Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_3_operations.cpp b/Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_3_operations.cpp index 64a2002ddba..e5646197f9b 100644 --- a/Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_3_operations.cpp +++ b/Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_3_operations.cpp @@ -3,7 +3,7 @@ #include /* If you want to use a viewer, you can use qglviewer. */ -#ifdef CGAL_LCC_USE_QT +#ifdef CGAL_USE_BASIC_VIEWER #include "linear_cell_complex_3_viewer_qt.h" #endif @@ -54,9 +54,9 @@ void run_test() lcc.template sew<3>(lcc.template opposite<2>(lcc.next(dh1)), lcc.other_orientation(lcc.template opposite<2>(lcc.previous(dh3)))); -#ifdef CGAL_LCC_USE_VIEWER +#ifdef CGAL_USE_BASIC_VIEWER display_lcc(lcc); -#endif // CGAL_LCC_USE_VIEWER +#endif // CGAL_USE_BASIC_VIEWER lcc.insert_cell_1_in_cell_2(lcc.next(dh1), Alpha1::run(lcc, lcc.previous(dh1))); @@ -75,9 +75,9 @@ void run_test() lcc.display_characteristics(std::cout) << ", valid=" << lcc.is_valid() << std::endl; -#ifdef CGAL_LCC_USE_VIEWER +#ifdef CGAL_USE_BASIC_VIEWER display_lcc(lcc); -#endif // CGAL_LCC_USE_VIEWER +#endif // CGAL_USE_BASIC_VIEWER } diff --git a/Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_3_viewer_qt.h b/Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_3_viewer_qt.h index 5851bf790c4..e5435528447 100644 --- a/Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_3_viewer_qt.h +++ b/Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_3_viewer_qt.h @@ -138,7 +138,10 @@ protected: CGAL::Color c=ColorFunctor::run(lcc, dh); - face_begin(c); + if (c.red()<60 || c.green()<60 || c.blue()<60) + mono_face_begin(); + else + colored_face_begin(c); cur=dh; do @@ -159,14 +162,14 @@ protected: if ( d2!=NULL ) { Local_point p2 = geomutils.get_point(lcc, d2); - add_segment(p1, p2); + add_mono_segment(p1, p2); } } void compute_vertex(Dart_const_handle dh, bool& empty) { Local_point p = geomutils.get_point(lcc, dh); - add_point(p); + add_mono_point(p); } void compute_elements() diff --git a/Linear_cell_complex/examples/Linear_cell_complex/voronoi_2.cpp b/Linear_cell_complex/examples/Linear_cell_complex/voronoi_2.cpp index 7045b188ab1..43ac93a3327 100644 --- a/Linear_cell_complex/examples/Linear_cell_complex/voronoi_2.cpp +++ b/Linear_cell_complex/examples/Linear_cell_complex/voronoi_2.cpp @@ -7,7 +7,7 @@ #include /* If you want to use a viewer, you can use qglviewer. */ -#ifdef CGAL_LCC_USE_QT +#ifdef CGAL_USE_BASIC_VIEWER #include "linear_cell_complex_3_viewer_qt.h" #endif @@ -57,9 +57,9 @@ void display_voronoi(LCC_2& alcc, Dart_handle adart) << alcc.is_valid() << std::endl; -#ifdef CGAL_LCC_USE_VIEWER +#ifdef CGAL_USE_BASIC_VIEWER display_lcc(alcc); -#endif // CGAL_LCC_USE_VIEWER +#endif // CGAL_USE_BASIC_VIEWER } template diff --git a/Linear_cell_complex/examples/Linear_cell_complex/voronoi_3.cpp b/Linear_cell_complex/examples/Linear_cell_complex/voronoi_3.cpp index 9506bb8e9fc..28bf93b0f12 100644 --- a/Linear_cell_complex/examples/Linear_cell_complex/voronoi_3.cpp +++ b/Linear_cell_complex/examples/Linear_cell_complex/voronoi_3.cpp @@ -6,7 +6,7 @@ #include /* If you want to use a viewer, you can use one qglviewer. */ -#ifdef CGAL_LCC_USE_QT +#ifdef CGAL_USE_BASIC_VIEWER #include "linear_cell_complex_3_viewer_qt.h" #endif @@ -60,9 +60,9 @@ void display_voronoi(LCC_3& alcc, Dart_handle adart) << alcc.is_valid() << std::endl; -#ifdef CGAL_LCC_USE_VIEWER +#ifdef CGAL_USE_BASIC_VIEWER display_lcc(alcc); -#endif // CGAL_LCC_USE_VIEWER +#endif // CGAL_USE_BASIC_VIEWER } template From 4c893ef009dfec9340b0082d54c41088b816a1a3 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Wed, 15 Nov 2017 14:19:43 +0100 Subject: [PATCH 09/11] Add missing #include --- Linear_cell_complex/examples/Linear_cell_complex/basic_viewer.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Linear_cell_complex/examples/Linear_cell_complex/basic_viewer.h b/Linear_cell_complex/examples/Linear_cell_complex/basic_viewer.h index 41541c15f94..b992f7271b0 100644 --- a/Linear_cell_complex/examples/Linear_cell_complex/basic_viewer.h +++ b/Linear_cell_complex/examples/Linear_cell_complex/basic_viewer.h @@ -39,6 +39,7 @@ #include #include +#include #define NB_VBO_BUFFERS 8 #define NB_VAO_BUFFERS 4 From b21b9e21c9d688b0ef8eb5b32904697ae5207f97 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Thu, 16 Nov 2017 15:20:23 +0100 Subject: [PATCH 10/11] By default, disable the use of viewer in LCC examples. --- .../examples/Linear_cell_complex/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Linear_cell_complex/examples/Linear_cell_complex/CMakeLists.txt b/Linear_cell_complex/examples/Linear_cell_complex/CMakeLists.txt index 620838e007b..6a0dc262fe0 100644 --- a/Linear_cell_complex/examples/Linear_cell_complex/CMakeLists.txt +++ b/Linear_cell_complex/examples/Linear_cell_complex/CMakeLists.txt @@ -16,11 +16,11 @@ ADD_DEFINITIONS("-std=c++11") # If you want to visualize a linear cell complex, you can use the following viewer # based on qt. Just uncomment the following two lines, plus the lines qt5_use_modules below -find_package(CGAL COMPONENTS Qt5) -include("CMakeBasicViewerQt.inc") +# find_package(CGAL COMPONENTS Qt5) +# include("CMakeBasicViewerQt.inc") # If you don't want to visualize, use the following line (otherwise comment it) -# find_package(CGAL QUIET) +find_package(CGAL QUIET) # For Gprof. # ADD_DEFINITIONS("-pg") From d5372e1a7d8c5a6f61ccfc4e05e7eeb0a53daf15 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Tue, 21 Nov 2017 10:02:23 +0100 Subject: [PATCH 11/11] Remove option '-std=c++11', committed by error. --- Linear_cell_complex/examples/Linear_cell_complex/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/Linear_cell_complex/examples/Linear_cell_complex/CMakeLists.txt b/Linear_cell_complex/examples/Linear_cell_complex/CMakeLists.txt index 6a0dc262fe0..8d61b1780db 100644 --- a/Linear_cell_complex/examples/Linear_cell_complex/CMakeLists.txt +++ b/Linear_cell_complex/examples/Linear_cell_complex/CMakeLists.txt @@ -11,8 +11,6 @@ if(POLICY CMP0043) cmake_policy(SET CMP0043 OLD) endif() -ADD_DEFINITIONS("-std=c++11") - # If you want to visualize a linear cell complex, you can use the following viewer # based on qt. Just uncomment the following two lines, plus the lines qt5_use_modules below