diff --git a/Linear_cell_complex/examples/Linear_cell_complex/CMakeLists.txt b/Linear_cell_complex/examples/Linear_cell_complex/CMakeLists.txt index 95b4ac0b40d..b110a7951d1 100644 --- a/Linear_cell_complex/examples/Linear_cell_complex/CMakeLists.txt +++ b/Linear_cell_complex/examples/Linear_cell_complex/CMakeLists.txt @@ -11,8 +11,8 @@ endif() # 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("CMakeLCCViewerQt.inc") # If you don't want to visualize, use the following line (otherwise comment it) find_package(CGAL QUIET) @@ -43,15 +43,21 @@ 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}) + qt5_use_modules(voronoi_2 ${MAP_VIEWER_MODULES}) 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}) + qt5_use_modules(voronoi_3 ${MAP_VIEWER_MODULES}) 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}) + + else() message(STATUS "This program requires the CGAL library, " diff --git a/Linear_cell_complex/examples/Linear_cell_complex/gmap_linear_cell_complex_3.cpp b/Linear_cell_complex/examples/Linear_cell_complex/gmap_linear_cell_complex_3.cpp index 57acff2951e..5638418b20b 100644 --- a/Linear_cell_complex/examples/Linear_cell_complex/gmap_linear_cell_complex_3.cpp +++ b/Linear_cell_complex/examples/Linear_cell_complex/gmap_linear_cell_complex_3.cpp @@ -1,5 +1,4 @@ #include -#include #include #include diff --git a/Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_3.cpp b/Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_3.cpp index beafc9811b4..44267f460af 100644 --- a/Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_3.cpp +++ b/Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_3.cpp @@ -1,5 +1,4 @@ -#include -#include +#include #include #include diff --git a/Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_3_attributes_management.cpp b/Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_3_attributes_management.cpp index 15ac21a001b..ec22f0bff56 100644 --- a/Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_3_attributes_management.cpp +++ b/Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_3_attributes_management.cpp @@ -1,5 +1,4 @@ -#include -#include +#include #include #include #include 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 new file mode 100644 index 00000000000..64a2002ddba --- /dev/null +++ b/Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_3_operations.cpp @@ -0,0 +1,90 @@ +#include +#include +#include + +/* If you want to use a viewer, you can use qglviewer. */ +#ifdef CGAL_LCC_USE_QT +#include "linear_cell_complex_3_viewer_qt.h" +#endif + +typedef CGAL::Linear_cell_complex_for_combinatorial_map<3> LCC_3_cmap; +typedef CGAL::Linear_cell_complex_for_generalized_map<3> LCC_3_gmap; + +template +struct Alpha1 +{ + static typename LCC::Dart_handle run(LCC&, typename LCC::Dart_handle dh) + { return dh; } +}; +template +struct Alpha1 +{ + static typename LCC::Dart_handle run(LCC& lcc, typename LCC::Dart_handle dh) + { return lcc.template alpha<1>(dh); } +}; + +template +void run_test() +{ + typedef typename LCC::Point Point; + typedef typename LCC::Dart_handle Dart_handle; + + LCC lcc; + + Dart_handle dh1 = lcc. + make_hexahedron(Point(0,0,0),Point(1,0,0), + Point(1,2,0),Point(0,2,0), + Point(0,3,4),Point(0,0,4), + Point(6,0,4),Point(6,3,4)); + Dart_handle dh2 = lcc. + make_hexahedron(Point(0,-5,0),Point(2,-5,0), + Point(2,-2,0),Point(0,-2,0), + Point(1,-1,5),Point(1,-2,5), + Point(5,-2,5),Point(5,-2,5)); + Dart_handle dh3 = lcc. + make_hexahedron(Point(1,0,5),Point(0,0,6), + Point(0,2,5),Point(1,2,6), + Point(1,3,8),Point(0,0,8), + Point(5,0,9),Point(7,3,9)); + + lcc.template sew<3>(dh1,lcc.other_orientation + (lcc.template opposite<2> + (lcc.next(lcc.next(lcc.template opposite<2>(dh2)))))); + 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 + display_lcc(lcc); +#endif // CGAL_LCC_USE_VIEWER + + lcc.insert_cell_1_in_cell_2(lcc.next(dh1), + Alpha1::run(lcc, lcc.previous(dh1))); + dh2=lcc.template opposite<2>(lcc.next(lcc.next + (lcc.template opposite<2>(dh1)))); + lcc.insert_cell_1_in_cell_2(dh2, Alpha1::run + (lcc, lcc.next(lcc.next(dh2)))); + + std::vector path; + path.push_back(lcc.next(dh1)); + path.push_back(lcc.next(lcc.template opposite<2>(lcc.previous(dh1)))); + path.push_back(lcc.previous(dh2)); + path.push_back(lcc.next(lcc.template opposite<2>(dh2))); + lcc.insert_cell_2_in_cell_3(path.begin(),path.end()); + + lcc.display_characteristics(std::cout) << ", valid=" + << lcc.is_valid() << std::endl; + +#ifdef CGAL_LCC_USE_VIEWER + display_lcc(lcc); +#endif // CGAL_LCC_USE_VIEWER +} + + +int main() +{ + run_test(); + run_test(); + + return EXIT_SUCCESS; +} 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 cfd406a7298..a3f4a902fcd 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 @@ -38,33 +38,184 @@ #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; +// Default color functor; user can change it to have its own face color +struct DefaultColorFunctor +{ + template + static CGAL::Color run(const LCC& alcc, + typename LCC::Dart_const_handle dh) + { + if (dh==alcc.null_handle) // use to get the mono color + return CGAL::Color(100, 125, 200); // R G B between 0-255 + + // 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)); + } +}; + +//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; template struct Geom_utils { - Local_point get_point(LCC& lcc, typename LCC::Vertex_attribute_const_handle vh) + Local_point get_point(const LCC& lcc, + typename LCC::Vertex_attribute_const_handle vh) { return converter(lcc.point_of_vertex_attribute(vh)); } - Local_point get_point(LCC& lcc, typename LCC::Dart_const_handle dh) + Local_point get_point(const LCC& lcc, typename LCC::Dart_const_handle dh) { return converter(lcc.point(dh)); } - Local_vector get_facet_normal(LCC& lcc, typename LCC::Dart_const_handle 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(LCC& lcc, typename LCC::Dart_const_handle dh) + Local_vector get_vertex_normal(const LCC& lcc, + typename LCC::Dart_const_handle dh) { Local_vector n = converter(CGAL::compute_normal_of_cell_0(lcc,dh)); n = n/(CGAL::sqrt(n*n)); @@ -77,23 +228,24 @@ protected: template struct Geom_utils { - Local_point get_point(LCC& lcc, typename LCC::Vertex_attribute_const_handle vh) + Local_point get_point(const LCC& lcc, + typename LCC::Vertex_attribute_const_handle vh) { Local_point p(converter(lcc.point_of_vertex_attribute(vh).x()),0, converter(lcc.point_of_vertex_attribute(vh).y())); return p; } - Local_point get_point(LCC& lcc, typename LCC::Dart_const_handle dh) + 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(LCC&, typename LCC::Dart_const_handle) + 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(LCC&, typename LCC::Dart_const_handle) + Local_vector get_vertex_normal(const LCC&, typename LCC::Dart_const_handle) { Local_vector n(0,1,0); return n; @@ -103,7 +255,7 @@ protected: }; template -CGAL::Bbox_3 bbox(LCC& lcc) +CGAL::Bbox_3 bbox(const LCC& lcc) { CGAL::Bbox_3 bb; Geom_utils geomutils; @@ -122,14 +274,14 @@ CGAL::Bbox_3 bbox(LCC& lcc) return bb; } -template +template class SimpleLCCViewerQt : public QGLViewer, public QOpenGLFunctions_2_1 { - typedef typename LCC::Dart_handle Dart_handle; + typedef typename LCC::Dart_const_handle Dart_const_handle; struct Vertex_info { - Dart_handle dh; + Dart_const_handle dh; Local_vector v; }; @@ -147,19 +299,24 @@ class SimpleLCCViewerQt : public QGLViewer, public QOpenGLFunctions_2_1 typedef CGAL::Constrained_triangulation_face_base_2 Fb; typedef CGAL::Triangulation_data_structure_2 TDS; - typedef CGAL::No_intersection_tag Itag; + // typedef CGAL::No_intersection_tag Itag; + typedef CGAL::Exact_predicates_tag Itag; typedef CGAL::Constrained_Delaunay_triangulation_2 CDT; public: // Constructor/Destructor - SimpleLCCViewerQt(LCC& alcc) : + SimpleLCCViewerQt(const LCC& alcc) : QGLViewer(CGAL::Qt::createOpenGLContext()), lcc(alcc), wireframe(false), flatShading(true), edges(true), vertices(true), + mono(false), + size_points(7.), + size_edges(3.1), + ambient(0.6f, 0.5f, 0.5f, 0.5f), are_buffers_initialized(false) { setWindowTitle("3D lcc viewer"); @@ -169,105 +326,69 @@ public: newFormat.setSampleBuffers(true); newFormat.setSamples(16); this->setFormat(newFormat); - } +} ~SimpleLCCViewerQt() { - buffers[0].destroy(); - buffers[1].destroy(); - buffers[2].destroy(); - buffers[3].destroy(); - buffers[4].destroy(); - buffers[5].destroy(); - vao[0].destroy(); - vao[1].destroy(); - vao[2].destroy(); - vao[3].destroy(); + for (int i=0; icompileSourceCode(vertex_source)) + if (mono) { - std::cerr<<"Compiling vertex source FAILED"<compileSourceCode(vertex_source_mono)) + { + std::cerr<<"Compiling vertex source FAILED"<compileSourceCode(vertex_source_multi)) + { + std::cerr<<"Compiling vertex source FAILED"<compileSourceCode(fragment_source)) + if (mono) { - std::cerr<<"Compiling fragmentsource FAILED"<compileSourceCode(fragment_source_mono)) + { + std::cerr<<"Compiling fragmentsource FAILED"<compileSourceCode(fragment_source_multi)) + { + std::cerr<<"Compiling fragmentsource FAILED"<compileSourceCode(vertex_source_p_l)) { @@ -333,215 +433,315 @@ protected: void initialize_buffers() { + int bufn = 0; + int vaon = 0; + //points of the facets - vao[0].bind(); - buffers[0].bind(); - buffers[0].allocate(pos_facets.data(), + assert(vaon(pos_facets.size()*sizeof(float))); - vertexLocation[0] = rendering_program.attributeLocation("vertex"); + vertexLocation[vaon] = rendering_program.attributeLocation("vertex"); rendering_program.bind(); - rendering_program.enableAttributeArray(vertexLocation[0]); - rendering_program.setAttributeBuffer(vertexLocation[0],GL_FLOAT,0,3); + rendering_program.enableAttributeArray(vertexLocation[vaon]); + rendering_program.setAttributeBuffer(vertexLocation[vaon],GL_FLOAT,0,3); rendering_program.release(); - buffers[0].release(); + buffers[bufn].release(); + ++bufn; + //normals of the facets - buffers[1].bind(); - buffers[1].allocate(flat_normals.data(), + 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[1].release(); - vao[0].release(); + buffers[bufn].release(); + ++bufn; - vao[1].bind(); + 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[1] = rendering_program.attributeLocation("vertex"); + vertexLocation[vaon] = rendering_program.attributeLocation("vertex"); rendering_program.bind(); - rendering_program.enableAttributeArray(vertexLocation[1]); - rendering_program.setAttributeBuffer(vertexLocation[1],GL_FLOAT,0,3); + rendering_program.enableAttributeArray(vertexLocation[vaon]); + rendering_program.setAttributeBuffer(vertexLocation[vaon],GL_FLOAT,0,3); rendering_program.release(); - buffers[2].release(); + + buffers[bufn].release(); + ++bufn; //normals of the facets - buffers[3].bind(); - buffers[3].allocate(smooth_normals.data(), + 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[3].release(); - vao[1].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 - vao[2].bind(); - - buffers[4].bind(); - buffers[4].allocate(pos_lines.data(), static_cast(pos_lines.size()*sizeof(float))); - vertexLocation[2] = rendering_program_p_l.attributeLocation("vertex"); + 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[2]); - rendering_program_p_l.setAttributeBuffer(vertexLocation[2],GL_FLOAT,0,3); - buffers[4].release(); + rendering_program_p_l.enableAttributeArray(vertexLocation[vaon]); + rendering_program_p_l.setAttributeBuffer(vertexLocation[vaon],GL_FLOAT,0,3); rendering_program_p_l.release(); - vao[2].release(); - + buffers[bufn].release(); + ++bufn; + + vao[vaon].release(); + ++vaon; + //The points - vao[3].bind(); - buffers[5].bind(); - buffers[5].allocate(pos_points.data(), static_cast(pos_points.size()*sizeof(float))); - vertexLocation[3] = rendering_program_p_l.attributeLocation("vertex"); - rendering_program_p_l.bind(); - rendering_program_p_l.enableAttributeArray(vertexLocation[3]); - rendering_program_p_l.setAttributeBuffer(vertexLocation[3],GL_FLOAT,0,3); - buffers[5].release(); - rendering_program_p_l.release(); - vao[3].release(); + 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_handle dh) + void compute_face(Dart_const_handle dh) { + // We fill only closed faces. + Dart_const_handle cur=dh; + Dart_const_handle min=dh; + do + { + if (!lcc.is_next_exist(cur)) return; // open face=>not filled + if (cur(dh)!=dh) + if (lcc.next(lcc.next(lcc.next(dh)))!=dh) { - P_traits cdt_traits(normal); - CDT cdt(cdt_traits); - - // Iterates on the vector of facet handles - typename CDT::Vertex_handle previous = NULL, first = NULL; - for (typename LCC::template Dart_of_orbit_range<1>::const_iterator - he_circ = lcc.template darts_of_orbit<1>(dh).begin(), - he_circ_end = lcc.template darts_of_orbit<1>(dh).end(); - he_circ!=he_circ_end; ++he_circ) + try { - typename CDT::Vertex_handle vh = cdt.insert(geomutils.get_point(lcc, he_circ)); - if(first == NULL) - { first = vh; } - vh->info().v = geomutils.get_vertex_normal(lcc, he_circ); - if(previous!=NULL && previous != vh) - { cdt.insert_constraint(previous, vh); } - previous = vh; - } - 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) + 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 { - fh->info().is_process = true; - for(int i = 0; i <3; ++i) + 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(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) { - if(!cdt.is_constrained(std::make_pair(fh, i))) + fh->info().is_process = true; + for(int i = 0; i <3; ++i) { - face_queue.push(fh->neighbor(i)); - } - else if (face_internal==NULL) - { - face_internal = fh->neighbor(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) + if ( face_internal!=NULL ) + face_queue.push(face_internal); + + while(! face_queue.empty() ) { - fh->info().is_process = true; - fh->info().is_external = false; - for(int i = 0; i <3; ++i) + typename CDT::Face_handle fh = face_queue.front(); + face_queue.pop(); + if(!fh->info().is_process) { - if(!cdt.is_constrained(std::make_pair(fh, i))) + fh->info().is_process = true; + fh->info().is_external = false; + for(int i = 0; i <3; ++i) { - face_queue.push(fh->neighbor(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) + //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) { - 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()); + 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 + } } 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()); @@ -554,30 +754,31 @@ protected: flat_normals.push_back(normal.y()); flat_normals.push_back(normal.z()); - for (typename LCC::template Dart_of_orbit_range<1>::const_iterator - orbitIter = lcc.template darts_of_orbit<1>(dh).begin(); - orbitIter.cont(); ++orbitIter) + //compute Smooth normals + cur=dh; + do { - //compute Smooth normals - Local_vector normal = geomutils.get_vertex_normal(lcc, orbitIter); + Local_vector normal = geomutils.get_vertex_normal(lcc, cur); normal = normal/(CGAL::sqrt(normal*normal)); - + 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, orbitIter); + + 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); } } - void compute_edge(Dart_handle dh) + void compute_edge(Dart_const_handle dh) { Local_point p = geomutils.get_point(lcc, dh); - Dart_handle d2 = lcc.other_extremity(dh); + Dart_const_handle d2 = lcc.other_extremity(dh); if ( d2!=NULL ) { Local_point p2 = geomutils.get_point(lcc, d2); @@ -591,7 +792,7 @@ protected: } } - void compute_vertex(Dart_handle dh, bool empty) + void compute_vertex(Dart_const_handle dh, bool empty) { Local_point p = geomutils.get_point(lcc, dh); pos_points.push_back(p.x()); @@ -614,7 +815,8 @@ protected: smooth_normals.clear(); pos_lines.clear(); pos_points.clear(); - + colors.clear(); + if ( lcc.is_empty() ) { bb = Local_point(CGAL::ORIGIN).bbox(); @@ -627,7 +829,7 @@ protected: unsigned int markvertices = lcc.get_new_mark(); bool empty = true; - for (typename LCC::Dart_range::iterator it=lcc.darts().begin(), + for (typename LCC::Dart_range::const_iterator it=lcc.darts().begin(), itend=lcc.darts().end(); it!=itend; ++it ) { if ( !lcc.is_marked(it, markfaces) ) @@ -653,7 +855,6 @@ protected: lcc.free_mark(markfaces); lcc.free_mark(markedges); lcc.free_mark(markvertices); - } void attrib_buffers(QGLViewer* viewer) @@ -672,7 +873,6 @@ protected: mvMatrix.data()[i] = (float)mat[i]; } // define material - QVector4D ambient(0.4f, 0.4f, 0.4f, 0.4f); QVector4D diffuse( 0.9f, 0.9f, 0.9f, @@ -703,7 +903,9 @@ protected: rendering_program.setUniformValue(mvpLocation[0], mvpMatrix); rendering_program.setUniformValue(mvLocation, mvMatrix); - colorLocation2 = rendering_program.uniformLocation("color"); + if (mono) + colorLocation2 = rendering_program.uniformLocation("color"); + rendering_program.release(); rendering_program_p_l.bind(); @@ -726,9 +928,15 @@ protected: { vao[0].bind(); attrib_buffers(this); - color.setRgbF(0.1f, 0.7f, 0.1f); rendering_program.bind(); - rendering_program.setUniformValue(colorLocation2,color); + 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(); @@ -737,9 +945,15 @@ protected: { vao[1].bind(); attrib_buffers(this); - color.setRgbF(0.1f, 0.7f, 0.1f); rendering_program.bind(); - rendering_program.setUniformValue(colorLocation2,color); + 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(); @@ -752,13 +966,14 @@ protected: 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(7.f); + ::glPointSize(size_points); vao[3].bind(); attrib_buffers(this); color.setRgbF(.2f,.2f,.6f); @@ -783,10 +998,17 @@ protected: 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_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(2.4f); - ::glPointSize(7.f); + ::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); @@ -798,7 +1020,7 @@ protected: ::glShadeModel(GL_FLAT); ::glDisable(GL_BLEND); - ::glDisable(GL_LINE_SMOOTH); + ::glEnable(GL_LINE_SMOOTH); ::glDisable(GL_POLYGON_SMOOTH_HINT); ::glBlendFunc(GL_ONE, GL_ZERO); ::glHint(GL_LINE_SMOOTH_HINT, GL_FASTEST); @@ -845,6 +1067,89 @@ protected: vertices = !vertices; updateGL(); } + else if ((e->key()==Qt::Key_M) && (modifiers==Qt::NoButton)) + { + mono = !mono; + initialize_buffers(); + compile_shaders(); + updateGL(); + } + else if ((e->key()==Qt::Key_Plus) && (modifiers==Qt::KeypadModifier)) + { + size_edges+=.5; + updateGL(); + } + else if ((e->key()==Qt::Key_Minus) && (modifiers==Qt::KeypadModifier)) + { + if (size_edges>.5) size_edges-=.5; + updateGL(); + } + else if ((e->key()==Qt::Key_Plus) && (modifiers==(Qt::ShiftModifier|Qt::KeypadModifier))) + { + size_points+=.5; + updateGL(); + } + else if ((e->key()==Qt::Key_Minus) && (modifiers==(Qt::ShiftModifier|Qt::KeypadModifier))) + { + if (size_points>.5) size_points-=.5; + 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.); + 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.); + updateGL(); + } + else if ((e->key()==Qt::Key_PageUp) && (modifiers==Qt::ShiftModifier)) + { + ambient.setX(ambient.x()+.1); + if (ambient.x()>1.) ambient.setX(1.); + updateGL(); + } + else if ((e->key()==Qt::Key_PageUp) && (modifiers==Qt::AltModifier)) + { + ambient.setY(ambient.y()+.1); + if (ambient.y()>1.) ambient.setY(1.); + updateGL(); + } + else if ((e->key()==Qt::Key_PageUp) && (modifiers==Qt::ControlModifier)) + { + ambient.setZ(ambient.z()+.1); + if (ambient.z()>1.) ambient.setZ(1.); + updateGL(); + } + else if ((e->key()==Qt::Key_PageDown) && (modifiers==Qt::ShiftModifier)) + { + ambient.setX(ambient.x()-.1); + if (ambient.x()<0.) ambient.setX(0.); + updateGL(); + } + else if ((e->key()==Qt::Key_PageDown) && (modifiers==Qt::AltModifier)) + { + ambient.setY(ambient.y()-.1); + if (ambient.y()<0.) ambient.setY(0.); + updateGL(); + } + else if ((e->key()==Qt::Key_PageDown) && (modifiers==Qt::ControlModifier)) + { + ambient.setZ(ambient.z()-.1); + if (ambient.z()<0.) ambient.setZ(0.); + updateGL(); + } else QGLViewer::keyPressEvent(e); } @@ -883,18 +1188,23 @@ protected: } private: - LCC& lcc; + const LCC& lcc; + bool wireframe; bool flatShading; bool edges; bool vertices; - Geom_utils geomutils; + bool mono; - CGAL::Bbox_3 bb; + double size_points; + double size_edges; + + QVector4D ambient; + bool are_buffers_initialized; //Shaders elements - int vertexLocation[4]; + int vertexLocation[NB_VAO_BUFFERS]; int normalsLocation; int mvpLocation[2]; int mvLocation; @@ -907,23 +1217,28 @@ private: std::vector pos_facets; std::vector smooth_normals; std::vector flat_normals; + std::vector colors; - QGLBuffer buffers[6]; - QOpenGLVertexArrayObject vao[4]; + QGLBuffer buffers[NB_VBO_BUFFERS]; + QOpenGLVertexArrayObject vao[NB_VAO_BUFFERS]; + int colorsLocation; QOpenGLShaderProgram rendering_program; QOpenGLShaderProgram rendering_program_p_l; + + CGAL::Bbox_3 bb; + Geom_utils geomutils; }; -template -void display_lcc(LCC& alcc) +template +void display_lcc(const LCC& alcc) { int argc=1; const char* argv[2]={"lccviewer","\0"}; QApplication app(argc,const_cast(argv)); - SimpleLCCViewerQt mainwindow(alcc,&app); + SimpleLCCViewerQt mainwindow(alcc); mainwindow.show(); app.exec(); diff --git a/Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_3_with_colored_vertices.cpp b/Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_3_with_colored_vertices.cpp index b9d9e65da87..6f5b8b061e3 100644 --- a/Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_3_with_colored_vertices.cpp +++ b/Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_3_with_colored_vertices.cpp @@ -1,5 +1,4 @@ -#include -#include +#include #include #include diff --git a/Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_3_with_mypoint.cpp b/Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_3_with_mypoint.cpp index 0a4a1ce71e4..41503f1408f 100644 --- a/Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_3_with_mypoint.cpp +++ b/Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_3_with_mypoint.cpp @@ -1,5 +1,4 @@ -#include -#include +#include #include #include diff --git a/Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_4.cpp b/Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_4.cpp index a2cbbda6f5a..6a27bb11c4d 100644 --- a/Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_4.cpp +++ b/Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_4.cpp @@ -1,5 +1,4 @@ #include -#include #include #include diff --git a/Linear_cell_complex/examples/Linear_cell_complex/plane_graph_to_lcc_2.cpp b/Linear_cell_complex/examples/Linear_cell_complex/plane_graph_to_lcc_2.cpp index 9f62e59fb9d..c0db6f63a63 100644 --- a/Linear_cell_complex/examples/Linear_cell_complex/plane_graph_to_lcc_2.cpp +++ b/Linear_cell_complex/examples/Linear_cell_complex/plane_graph_to_lcc_2.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include 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 cc09e69d08a..7045b188ab1 100644 --- a/Linear_cell_complex/examples/Linear_cell_complex/voronoi_2.cpp +++ b/Linear_cell_complex/examples/Linear_cell_complex/voronoi_2.cpp @@ -1,6 +1,5 @@ -#include -#include -#include +#include +#include #include #include @@ -12,13 +11,9 @@ #include "linear_cell_complex_3_viewer_qt.h" #endif -/* // If you want to use exact constructions. -#include -typedef CGAL::Linear_cell_complex_for_combinatorial_map<2,2, - CGAL::Linear_cell_complex_traits<2, CGAL::Exact_predicates_exact_constructions_kernel> > LCC_2; -*/ - -typedef CGAL::Linear_cell_complex_for_combinatorial_map<2> LCC_2; +// This example works both with cmap and gmap as combinatorial data structure. +//typedef CGAL::Linear_cell_complex_for_combinatorial_map<2> LCC_2; +typedef CGAL::Linear_cell_complex_for_generalized_map<2> LCC_2; typedef LCC_2::Dart_handle Dart_handle; typedef LCC_2::Point Point; @@ -42,11 +37,11 @@ void display_voronoi(LCC_2& alcc, Dart_handle adart) it=alcc.darts_of_cell<2>(adart).begin(), itend=alcc.darts_of_cell<2>(adart).end(); it!=itend; ++it) { - if ( !alcc.is_marked(alcc.beta(it,2), mark_toremove) ) + if ( !alcc.is_marked(alcc.opposite<2>(it), mark_toremove) ) { - CGAL::mark_cell(alcc, alcc.beta(it,2), mark_toremove); - toremove.push(alcc.beta(it,2)); - } + CGAL::mark_cell(alcc, alcc.opposite<2>(it), mark_toremove); + toremove.push(alcc.opposite<2>(it)); + } } while( !toremove.empty() ) 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 ac033dac0c1..9506bb8e9fc 100644 --- a/Linear_cell_complex/examples/Linear_cell_complex/voronoi_3.cpp +++ b/Linear_cell_complex/examples/Linear_cell_complex/voronoi_3.cpp @@ -1,6 +1,4 @@ -#include -#include -#include +#include #include #include