diff --git a/Linear_cell_complex/examples/Linear_cell_complex/CMakeLists.txt b/Linear_cell_complex/examples/Linear_cell_complex/CMakeLists.txt index 10e9d05cf36..1e217145464 100644 --- a/Linear_cell_complex/examples/Linear_cell_complex/CMakeLists.txt +++ b/Linear_cell_complex/examples/Linear_cell_complex/CMakeLists.txt @@ -38,7 +38,7 @@ if ( CGAL_FOUND ) # If you want to visualize a linear cell complex, there are 2 viewers # based on qt and vtk. Just uncomment the corresponding line include("CMakeLCCViewerQt.inc") - # include("CMakeLCCViewerVtk.inc") + # include("CMakeLCCViewerVtk.inc") add_executable(linear_cell_complex_3_triangulation linear_cell_complex_3_triangulation.cpp) diff --git a/Linear_cell_complex/examples/Linear_cell_complex/data/small_points_2 b/Linear_cell_complex/examples/Linear_cell_complex/data/small_points_2 index d84872e0d73..f86135fb384 100644 --- a/Linear_cell_complex/examples/Linear_cell_complex/data/small_points_2 +++ b/Linear_cell_complex/examples/Linear_cell_complex/data/small_points_2 @@ -1,17 +1,17 @@ --263.345 -200.31 -95.2523 -197.508 --289.959 187.703 --11.2062 207.314 -184.902 -50.4277 --156.886 -343.188 -84.0461 -324.978 --238.131 -54.63 -121.867 8.40461 30.8169 130.272 -163.89 39.2215 -224.123 -81.2446 193.306 138.676 +-376.807 164.902 +-289.959 187.703 +-11.2062 207.314 +163.89 39.2215 +-238.131 -54.63 +184.902 -50.4277 -329.181 -170.894 --201.711 -438.441 +224.123 -81.2446 +-263.345 -200.31 +95.2523 -197.508 +-156.886 -343.188 +84.0461 -324.978 225.524 -385.211 --376.807 184.902 +-201.711 -438.441 diff --git a/Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_3_triangulation.cpp b/Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_3_triangulation.cpp index 8c8896365f7..163581b018e 100644 --- a/Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_3_triangulation.cpp +++ b/Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_3_triangulation.cpp @@ -97,8 +97,6 @@ void constrained_delaunay_triangulation(LCC_3 &lcc, Dart_handle d1) std::cout< #include #include +#include +#include + +typedef CGAL::Cartesian Local_kernel; +typedef typename Local_kernel::Point_3 Local_point; +typedef typename Local_kernel::Vector_3 Local_vector; template struct Geom_utils; @@ -33,72 +39,70 @@ struct Geom_utils; template struct Geom_utils { - typedef typename LCC::Point Point; - typedef typename LCC::Vector Vector; + Local_point get_point(typename LCC::Vertex_attribute_const_handle vh) + { return converter(vh->point()); } - static Point get_point(typename LCC::Vertex_attribute_const_handle vh) - { return vh->point(); } - - static Point get_point(typename LCC::Dart_const_handle dh) - { return LCC::point(dh); } + Local_point get_point(typename LCC::Dart_const_handle dh) + { return converter(LCC::point(dh)); } - static Vector get_facet_normal(LCC& lcc, typename LCC::Dart_const_handle dh) + Local_vector get_facet_normal(LCC& lcc, typename LCC::Dart_const_handle dh) { - typename LCC::Vector n = CGAL::compute_normal_of_cell_2(lcc,dh); + Local_vector n = converter(CGAL::compute_normal_of_cell_2(lcc,dh)); n = n/(CGAL::sqrt(n*n)); return n; } - - static Vector get_vertex_normal(LCC& lcc, typename LCC::Dart_const_handle dh) + + Local_vector get_vertex_normal(LCC& lcc, typename LCC::Dart_const_handle dh) { - Vector n = CGAL::compute_normal_of_cell_0(lcc,dh); + Local_vector n = converter(CGAL::compute_normal_of_cell_0(lcc,dh)); n = n/(CGAL::sqrt(n*n)); return n; } +protected: + CGAL::Cartesian_converter converter; }; - + template struct Geom_utils { - typedef typename LCC::Traits::Point_3 Point; - typedef typename LCC::Traits::Vector_3 Vector; - - static - Point get_point(typename LCC::Vertex_attribute_const_handle vh) + Local_point get_point(typename LCC::Vertex_attribute_const_handle vh) { - Point p(vh->point().x(),0,vh->point().y()); + Local_point p(converter(vh->point().x()),0,converter(vh->point().y())); return p; } - static Point get_point(typename LCC::Dart_const_handle dh) + Local_point get_point(typename LCC::Dart_const_handle dh) { return get_point(LCC::vertex_attribute(dh)); } - static - Vector get_facet_normal(LCC&, typename LCC::Dart_const_handle) + Local_vector get_facet_normal(LCC&, typename LCC::Dart_const_handle) { - Vector n(0,1,0); + Local_vector n(0,1,0); return n; } - static Vector get_vertex_normal(LCC&, typename LCC::Dart_const_handle) + Local_vector get_vertex_normal(LCC&, typename LCC::Dart_const_handle) { - Vector n(0,1,0); - return n; + Local_vector n(0,1,0); + return n; } +protected: + CGAL::Cartesian_converter converter; }; template CGAL::Bbox_3 bbox(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 = Geom_utils::get_point(it).bbox(); + bb = geomutils.get_point(it).bbox(); for( ++it; it!=itend; ++it) { - bb = bb + Geom_utils::get_point(it).bbox(); + bb = bb + geomutils.get_point(it).bbox(); } } @@ -109,8 +113,6 @@ template class SimpleLCCViewerQt : public QGLViewer { typedef typename LCC::Dart_handle Dart_handle; - typedef typename Geom_utils::Point Point; - typedef typename Geom_utils::Vector Vector; public: @@ -134,7 +136,7 @@ protected : // If Flat shading: 1 normal per polygon if (flatShading) { - Vector n = Geom_utils::get_facet_normal(lcc,ADart); + Local_vector n = geomutils.get_facet_normal(lcc,ADart); ::glNormal3d(n.x(),n.y(),n.z()); } @@ -145,38 +147,50 @@ protected : // If Gouraud shading: 1 normal per vertex if (!flatShading) { - Vector n = Geom_utils::get_vertex_normal(lcc,ADart); + Local_vector n = geomutils.get_vertex_normal(lcc,it); ::glNormal3d(n.x(),n.y(),n.z()); } - Point p = Geom_utils::get_point(it); + Local_point p = geomutils.get_point(it); ::glVertex3d(p.x(),p.y(),p.z()); lcc.mark(it, AMark); if ( lcc.dimension>=3 && !it->is_free(3) ) lcc.mark(it->beta(3), AMark); } + // close the polygon + if (!flatShading) + { + Local_vector n = geomutils.get_vertex_normal(lcc,ADart); + ::glNormal3d(n.x(),n.y(),n.z()); + } + + Local_point p = geomutils.get_point(ADart); + ::glVertex3d(p.x(),p.y(),p.z()); + ::glEnd(); } /// Draw all the edge of the facet given by ADart void drawEdges(Dart_handle ADart) { + glDepthRange (0.0, 0.9); glBegin(GL_LINES); - glColor3f(.2,.2,.6); + ::glColor3f(.2,.2,.6); for (typename LCC::template Dart_of_orbit_range<1>::iterator it=lcc.template darts_of_orbit<1>(ADart).begin(); it.cont(); ++it) { - Point p = Geom_utils::get_point(it); - Dart_handle d2 = it->opposite(); + Local_point p = geomutils.get_point(it); + Dart_handle d2 = it->other_extremity(); if ( d2!=NULL ) { - Point p2 = Geom_utils::get_point(d2); + Local_point p2 = geomutils.get_point(d2); glVertex3f( p.x(),p.y(),p.z()); glVertex3f( p2.x(),p2.y(),p2.z()); } } glEnd(); + glDepthRange (0.1, 1.0); } virtual void draw() @@ -199,12 +213,14 @@ protected : { if ( !lcc.is_marked(it, vertextreated) ) { - Point p = Geom_utils::get_point(it); + Local_point p = geomutils.get_point(it); + glDepthRange (0.0, 0.9); glBegin(GL_POINTS); - glColor3f(.6,.2,.8); + ::glColor3f(.6,.2,.8); glVertex3f(p.x(),p.y(),p.z()); glEnd(); + glDepthRange (0.1, 1.0); CGAL::mark_cell(lcc, it, vertextreated); } @@ -237,10 +253,10 @@ protected : setKeyDescription(Qt::Key_V, "Toggles vertices display"); // Light default parameters - ::glLineWidth(1.4f); - ::glPointSize(4.f); - ::glEnable(GL_POLYGON_OFFSET_FILL); - ::glPolygonOffset(1.0f,1.0f); + ::glLineWidth(2.4f); + ::glPointSize(7.f); + // ::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); @@ -372,6 +388,7 @@ private: bool flatShading; bool edges; bool vertices; + Geom_utils geomutils; }; template diff --git a/Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_3_viewer_vtk.h b/Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_3_viewer_vtk.h index 1145c43f7fa..4c34a32887c 100644 --- a/Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_3_viewer_vtk.h +++ b/Linear_cell_complex/examples/Linear_cell_complex/linear_cell_complex_3_viewer_vtk.h @@ -35,6 +35,12 @@ #include #include #include +#include +#include + +typedef CGAL::Cartesian Local_kernel; +typedef typename Local_kernel::Point_3 Local_point; +typedef typename Local_kernel::Vector_3 Local_vector; template struct Geom_utils; @@ -42,61 +48,56 @@ struct Geom_utils; template struct Geom_utils { - typedef typename LCC::Point Point; - typedef typename LCC::Vector Vector; + Local_point get_point(typename LCC::Vertex_attribute_const_handle vh) + { return converter(vh->point()); } - static Point get_point(typename LCC::Vertex_attribute_const_handle vh) - { return vh->point(); } - - static Point get_point(typename LCC::Dart_const_handle dh) - { return LCC::point(dh); } + Local_point get_point(typename LCC::Dart_const_handle dh) + { return converter(LCC::point(dh)); } - static Vector get_facet_normal(LCC& lcc, typename LCC::Dart_const_handle dh) + Local_vector get_facet_normal(LCC& lcc, typename LCC::Dart_const_handle dh) { - typename LCC::Vector n = CGAL::compute_normal_of_cell_2(lcc,dh); + Local_vector n = converter(CGAL::compute_normal_of_cell_2(lcc,dh)); n = n/(CGAL::sqrt(n*n)); return n; } - - static Vector get_vertex_normal(LCC& lcc, typename LCC::Dart_const_handle dh) + + Local_vector get_vertex_normal(LCC& lcc, typename LCC::Dart_const_handle dh) { - Vector n = CGAL::compute_normal_of_cell_0(lcc,dh); + Local_vector n = converter(CGAL::compute_normal_of_cell_0(lcc,dh)); n = n/(CGAL::sqrt(n*n)); return n; } +protected: + CGAL::Cartesian_converter converter; }; - + template struct Geom_utils { - typedef typename LCC::Traits::Point_3 Point; - typedef typename LCC::Traits::Vector_3 Vector; - - static - Point get_point(typename LCC::Vertex_attribute_const_handle vh) + Local_point get_point(typename LCC::Vertex_attribute_const_handle vh) { - Point p(vh->point().x(),vh->point().y(),0); + Local_point p(converter(vh->point().x()),0,converter(vh->point().y())); return p; } - static Point get_point(typename LCC::Dart_const_handle dh) + Local_point get_point(typename LCC::Dart_const_handle dh) { return get_point(LCC::vertex_attribute(dh)); } - static - Vector get_facet_normal(LCC&, typename LCC::Dart_const_handle) + Local_vector get_facet_normal(LCC&, typename LCC::Dart_const_handle) { - Vector n(0,0,1); + Local_vector n(0,1,0); return n; } - static Vector get_vertex_normal(LCC&, typename LCC::Dart_const_handle) + Local_vector get_vertex_normal(LCC&, typename LCC::Dart_const_handle) { - Vector n(0,0,1); - return n; + Local_vector n(0,1,0); + return n; } +protected: + CGAL::Cartesian_converter converter; }; - class SimpleViewVtk : public QMainWindow { public: @@ -140,8 +141,7 @@ template class SimpleLCCViewerVtk : public SimpleViewVtk { typedef typename LCC::Dart_handle Dart_handle; - typedef typename Geom_utils::Point Point; - typedef typename Geom_utils::Vector Vector; + Geom_utils geomutils; public: SimpleLCCViewerVtk(LCC& lcc) : SimpleViewVtk() @@ -179,7 +179,7 @@ public: it2=lcc.template darts_of_orbit<1>(it).begin(); it2.cont(); ++it2) { - Point p = Geom_utils::get_point(it2); + Local_point p = geomutils.get_point(it2); vtkIdType id=points->InsertNextPoint(p.x(),p.y(),p.z()); ++nbpoints; 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 47793114835..e461eb25e70 100644 --- a/Linear_cell_complex/examples/Linear_cell_complex/voronoi_2.cpp +++ b/Linear_cell_complex/examples/Linear_cell_complex/voronoi_2.cpp @@ -43,16 +43,17 @@ typedef CGAL::Delaunay_triangulation_2 Triangulation; // Function used to display the voronoi diagram. void display_voronoi(LCC_2& alcc, Dart_handle adart) { - // We remove all the faces containing one dart of the infinite faces + // We remove the infinite face plus all the faces adjacent to it. + // Indeed, we cannot view these faces since they do not have + // a "correct geometry". std::stack toremove; int mark_toremove=alcc.get_new_mark(); - // We cannot view the infinite face since it does not have - // a correct geometry. For that we have to remove the infinite face. + // adart belongs to the infinite face. toremove.push(adart); CGAL::mark_cell(alcc, adart, mark_toremove); - // Plus all the faces sharing an edge with it. + // Now we get all the faces adjacent to the infinite face. for (LCC_2::Dart_of_cell_range<2>::iterator it=alcc.darts_of_cell<2>(adart).begin(), itend=alcc.darts_of_cell<2>(adart).end(); it!=itend; ++it) @@ -109,23 +110,16 @@ void set_geometry_of_dual(LCC& alcc, TR& tr, std::map& assoc) { - /* std::cout<<"Avant "; - for (typename LCC::template One_dart_per_cell_range<0>:: - iterator it=alcc.template one_dart_per_cell<0>().begin(), - itend=alcc.template one_dart_per_cell<0>().end(); - it!=itend; ++it) - { - std::cout << LCC::point(it) << "; "; - } - std::cout< ::iterator it=assoc.begin(), itend=assoc.end(); it!=itend; ++it) { - LCC::point(it->second)=tr.circumcenter(it->first); - std::cout<second)<<" "; + if ( !tr.is_infinite(it->first) ) + alcc.set_vertex_attribute + (it->second,alcc.create_vertex_attribute(tr.circumcenter(it->first))); + else + alcc.set_vertex_attribute + (it->second,alcc.create_vertex_attribute()); } - std::cout<(dual_lcc, T, face_to_dart); - // 4) Display the dual_lcc characteristics. + // 5) Display the dual_lcc characteristics. std::cout<<"Voronoi subdvision :"<