From 72e0a3e677ce16ea44966f97de1059f508cd921c Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Wed, 21 Jan 2015 12:59:07 +0100 Subject: [PATCH 01/32] Fix warnings about signed/unsigned The code involved is about TBB. --- Mesh_3/include/CGAL/Mesh_3/Worksharing_data_structures.h | 2 +- Triangulation_3/include/CGAL/Delaunay_triangulation_3.h | 2 +- Triangulation_3/include/CGAL/Regular_triangulation_3.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Mesh_3/include/CGAL/Mesh_3/Worksharing_data_structures.h b/Mesh_3/include/CGAL/Mesh_3/Worksharing_data_structures.h index a92a4031e9f..7114a5032a1 100644 --- a/Mesh_3/include/CGAL/Mesh_3/Worksharing_data_structures.h +++ b/Mesh_3/include/CGAL/Mesh_3/Worksharing_data_structures.h @@ -690,7 +690,7 @@ protected: } - const int NUM_WORK_ITEMS_PER_BATCH; + const size_t NUM_WORK_ITEMS_PER_BATCH; int m_num_cells_per_axis; int m_num_cells; diff --git a/Triangulation_3/include/CGAL/Delaunay_triangulation_3.h b/Triangulation_3/include/CGAL/Delaunay_triangulation_3.h index 427bb375010..e9afaef555d 100644 --- a/Triangulation_3/include/CGAL/Delaunay_triangulation_3.h +++ b/Triangulation_3/include/CGAL/Delaunay_triangulation_3.h @@ -340,7 +340,7 @@ public: } #endif // CGAL_CONCURRENT_TRIANGULATION_3_ADD_TEMPORARY_POINTS_ON_FAR_SPHERE - int i = 0; + size_t i = 0; // Insert "num_points_seq" points sequentially // (or more if dim < 3 after that) size_t num_points_seq = (std::min)(num_points, (size_t)100); diff --git a/Triangulation_3/include/CGAL/Regular_triangulation_3.h b/Triangulation_3/include/CGAL/Regular_triangulation_3.h index cd47e98642b..948bb757fcd 100644 --- a/Triangulation_3/include/CGAL/Regular_triangulation_3.h +++ b/Triangulation_3/include/CGAL/Regular_triangulation_3.h @@ -274,7 +274,7 @@ namespace CGAL { } #endif // CGAL_CONCURRENT_TRIANGULATION_3_ADD_TEMPORARY_POINTS_ON_FAR_SPHERE - int i = 0; + size_t i = 0; // Insert "num_points_seq" points sequentially // (or more if dim < 3 after that) size_t num_points_seq = (std::min)(num_points, (size_t)500); From b551c0fa5545a7b92ef8174615a4e09fc2469c62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Fri, 23 Jan 2015 09:47:36 +0100 Subject: [PATCH 02/32] move Polyhedron builder from STL files from demo plugin to header --- .../Polyhedron/Polyhedron_demo_stl_plugin.cpp | 119 +-------------- .../CGAL/IO/Polyhedron_builder_from_STL.h | 142 ++++++++++++++++++ 2 files changed, 144 insertions(+), 117 deletions(-) create mode 100644 Polyhedron_IO/include/CGAL/IO/Polyhedron_builder_from_STL.h diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_stl_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_stl_plugin.cpp index 05c1eb5ef3e..56ac315d295 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_stl_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_stl_plugin.cpp @@ -3,128 +3,13 @@ #include "Kernel_type.h" #include "Polyhedron_type.h" -#include -#include #include "Polyhedron_demo_io_plugin_interface.h" #include -#include +#include #include -typedef Kernel::Point_3 Point_3; -typedef std::vector Points_3; -typedef boost::tuple Facet; -typedef std::vector Surface; - - - -template -class Build_from_stl : public CGAL::Modifier_base { - std::istream& is; - int counter; - Points_3 meshPoints; - Surface mesh; - -public: - - std::string name, color; - - - Build_from_stl(std::istream& is_) - : is(is_), counter(0) - {} - - void operator()( HDS& hds) { - if(!read(is, meshPoints, mesh)) return; - - CGAL::Polyhedron_incremental_builder_3 B(hds); - B.begin_surface( meshPoints.size(), mesh.size()); - typedef typename Points_3::size_type size_type; - - for(size_type i=0; i < meshPoints.size(); i++){ - B.add_vertex( meshPoints[i]); - } - for(size_type i=0; i < mesh.size(); i++){ - B.begin_facet(); - B.add_vertex_to_facet( mesh[i].template get<0>()); - B.add_vertex_to_facet( mesh[i].template get<1>()); - B.add_vertex_to_facet( mesh[i].template get<2>()); - B.end_facet(); - } - if(B.error()) - { - std::cerr << "An error occured while creating a Polyhedron" << std::endl; - B.rollback(); - } - - B.end_surface(); - } - -bool -read(std::istream& input, Points_3& points, Surface& surface, int /*offset*/ = 0) -{ - std::string s, solid("solid"), facet("facet"), outer("outer"), loop("loop"), vertex("vertex"), endloop("endloop"), endsolid("endsolid"); - - std::map vertex_index; - int index = 0; - int ijk[3]; - Point_3 p; - - input >> s; - if(s == solid){ - std::getline(input, s); - } else { - std::cerr << "We expect keyword 'solid'" << std::endl; - return false; - } - - while(input >> s){ - if(s == endsolid){ - //std::cerr << "found endsolid" << std::endl; - } else if(s == facet){ - //std::cerr << "found facet" << std::endl; - std::getline(input, s); // ignore the normal - input >> s; - if(s != outer){ - std::cerr << "Expect 'outer' and got " << s << std::endl; - return false; - } - input >> s; - if(s != loop){ - std::cerr << "Expect 'loop' and got " << s << std::endl; - return false; - } - int count = 0; - do { - input >> s; - if(s == vertex){ - // std::cerr << "found vertex" << std::endl; - if(count < 3){ - input >> p; - if(vertex_index.find(p) == vertex_index.end()){ - ijk[count] = index; - vertex_index[p] = index++; - points.push_back(p); - } else { - ijk[count] = vertex_index[p]; - } - ++count; - } else { - std::cerr << "We can only read triangulated surfaces" << std::endl; - return false; - } - } - }while(s != endloop); - - surface.push_back(boost::make_tuple(ijk[0], ijk[1], ijk[2])); - } - } - return true; -} - -}; - class Polyhedron_demo_stl_plugin : public QObject, public Polyhedron_demo_io_plugin_interface @@ -166,7 +51,7 @@ Polyhedron_demo_stl_plugin::load(QFileInfo fileinfo) { //Scene_polyhedron_item* item = new Scene_polyhedron_item(P); //item->setName(fileinfo.baseName()); - Build_from_stl builder(in); + CGAL::Polyhedron_builder_from_STL builder(in); // item->polyhedron()-> P.delegate(builder); diff --git a/Polyhedron_IO/include/CGAL/IO/Polyhedron_builder_from_STL.h b/Polyhedron_IO/include/CGAL/IO/Polyhedron_builder_from_STL.h new file mode 100644 index 00000000000..92b39880502 --- /dev/null +++ b/Polyhedron_IO/include/CGAL/IO/Polyhedron_builder_from_STL.h @@ -0,0 +1,142 @@ +// Copyright (c) 2015 GeometryFactory +// +// 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) : Andreas Fabri + +#ifndef CGAL_IO_POLYHEDRON_STL_BUILDER_H +#define CGAL_IO_POLYHEDRON_STL_BUILDER_H + +#include +#include +#include + +#include + +namespace CGAL{ + +template +class Polyhedron_builder_from_STL : public CGAL::Modifier_base { + typedef typename HDS::Vertex::Point Point_3; + typedef std::vector Points_3; + typedef cpp11::tuple Facet; + typedef std::vector Surface; + + std::istream& is; + int counter; + Points_3 meshPoints; + Surface mesh; + + bool + read(std::istream& input, Points_3& points, Surface& surface, int /*offset*/ = 0) + { + std::string s, solid("solid"), facet("facet"), outer("outer"), loop("loop"), vertex("vertex"), endloop("endloop"), endsolid("endsolid"); + + std::map vertex_index; + int index = 0; + int ijk[3]; + Point_3 p; + + input >> s; + if(s == solid){ + std::getline(input, s); + } else { + std::cerr << "We expect keyword 'solid'" << std::endl; + return false; + } + + while(input >> s){ + if(s == endsolid){ + //std::cerr << "found endsolid" << std::endl; + } else if(s == facet){ + //std::cerr << "found facet" << std::endl; + std::getline(input, s); // ignore the normal + input >> s; + if(s != outer){ + std::cerr << "Expect 'outer' and got " << s << std::endl; + return false; + } + input >> s; + if(s != loop){ + std::cerr << "Expect 'loop' and got " << s << std::endl; + return false; + } + int count = 0; + do { + input >> s; + if(s == vertex){ + // std::cerr << "found vertex" << std::endl; + if(count < 3){ + input >> p; + if(vertex_index.find(p) == vertex_index.end()){ + ijk[count] = index; + vertex_index[p] = index++; + points.push_back(p); + } else { + ijk[count] = vertex_index[p]; + } + ++count; + } else { + std::cerr << "We can only read triangulated surfaces" << std::endl; + return false; + } + } + }while(s != endloop); + + surface.push_back(cpp11::make_tuple(ijk[0], ijk[1], ijk[2])); + } + } + return true; + } + + +public: + + std::string name, color; + + Polyhedron_builder_from_STL(std::istream& is_) + : is(is_), counter(0) + {} + + void operator()( HDS& hds) { + if(!read(is, meshPoints, mesh)) return; + + CGAL::Polyhedron_incremental_builder_3 B(hds); + B.begin_surface( meshPoints.size(), mesh.size()); + typedef typename Points_3::size_type size_type; + + for(size_type i=0; i < meshPoints.size(); i++){ + B.add_vertex( meshPoints[i]); + } + for(size_type i=0; i < mesh.size(); i++){ + B.begin_facet(); + B.add_vertex_to_facet( mesh[i].template get<0>()); + B.add_vertex_to_facet( mesh[i].template get<1>()); + B.add_vertex_to_facet( mesh[i].template get<2>()); + B.end_facet(); + } + if(B.error()) + { + std::cerr << "An error occured while creating a Polyhedron" << std::endl; + B.rollback(); + } + + B.end_surface(); + } +}; + +} //end of CGAL namespace + +#endif // CGAL_IO_POLYHEDRON_STL_BUILDER_H From 5c956f1ccdb2b9ca423a253cea7edf2c1cd5b9b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Fri, 23 Jan 2015 11:47:23 +0100 Subject: [PATCH 03/32] replace tuple by array --- .../include/CGAL/IO/Polyhedron_builder_from_STL.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Polyhedron_IO/include/CGAL/IO/Polyhedron_builder_from_STL.h b/Polyhedron_IO/include/CGAL/IO/Polyhedron_builder_from_STL.h index 92b39880502..97136b0be65 100644 --- a/Polyhedron_IO/include/CGAL/IO/Polyhedron_builder_from_STL.h +++ b/Polyhedron_IO/include/CGAL/IO/Polyhedron_builder_from_STL.h @@ -21,7 +21,7 @@ #include #include -#include +#include #include @@ -31,7 +31,7 @@ template class Polyhedron_builder_from_STL : public CGAL::Modifier_base { typedef typename HDS::Vertex::Point Point_3; typedef std::vector Points_3; - typedef cpp11::tuple Facet; + typedef cpp11::array Facet; typedef std::vector Surface; std::istream& is; @@ -95,7 +95,7 @@ class Polyhedron_builder_from_STL : public CGAL::Modifier_base { } }while(s != endloop); - surface.push_back(cpp11::make_tuple(ijk[0], ijk[1], ijk[2])); + surface.push_back( make_array(ijk[0], ijk[1], ijk[2]) ); } } return true; @@ -122,9 +122,9 @@ public: } for(size_type i=0; i < mesh.size(); i++){ B.begin_facet(); - B.add_vertex_to_facet( mesh[i].template get<0>()); - B.add_vertex_to_facet( mesh[i].template get<1>()); - B.add_vertex_to_facet( mesh[i].template get<2>()); + B.add_vertex_to_facet( mesh[i][0]); + B.add_vertex_to_facet( mesh[i][1]); + B.add_vertex_to_facet( mesh[i][2]); B.end_facet(); } if(B.error()) From 1ee29eb3e101200ab9d99f4279ca93dd32addeb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Fri, 23 Jan 2015 12:17:31 +0100 Subject: [PATCH 04/32] int[] -> array --- Polyhedron_IO/include/CGAL/IO/Polyhedron_builder_from_STL.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Polyhedron_IO/include/CGAL/IO/Polyhedron_builder_from_STL.h b/Polyhedron_IO/include/CGAL/IO/Polyhedron_builder_from_STL.h index 97136b0be65..6ed11a04404 100644 --- a/Polyhedron_IO/include/CGAL/IO/Polyhedron_builder_from_STL.h +++ b/Polyhedron_IO/include/CGAL/IO/Polyhedron_builder_from_STL.h @@ -46,7 +46,7 @@ class Polyhedron_builder_from_STL : public CGAL::Modifier_base { std::map vertex_index; int index = 0; - int ijk[3]; + cpp11::array ijk; Point_3 p; input >> s; @@ -95,7 +95,7 @@ class Polyhedron_builder_from_STL : public CGAL::Modifier_base { } }while(s != endloop); - surface.push_back( make_array(ijk[0], ijk[1], ijk[2]) ); + surface.push_back(ijk); } } return true; From fcd2e56742f9d992d97a586d9c530c22d8b3cb9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Fri, 23 Jan 2015 14:09:40 +0100 Subject: [PATCH 05/32] cleanup --- .../include/CGAL/IO/Polyhedron_builder_from_STL.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Polyhedron_IO/include/CGAL/IO/Polyhedron_builder_from_STL.h b/Polyhedron_IO/include/CGAL/IO/Polyhedron_builder_from_STL.h index 6ed11a04404..aa557ff63e5 100644 --- a/Polyhedron_IO/include/CGAL/IO/Polyhedron_builder_from_STL.h +++ b/Polyhedron_IO/include/CGAL/IO/Polyhedron_builder_from_STL.h @@ -80,12 +80,14 @@ class Polyhedron_builder_from_STL : public CGAL::Modifier_base { // std::cerr << "found vertex" << std::endl; if(count < 3){ input >> p; - if(vertex_index.find(p) == vertex_index.end()){ + typename std::map::iterator iti= + vertex_index.insert(std::make_pair(p,-1)).first; + if(iti->second==-1){ ijk[count] = index; - vertex_index[p] = index++; + iti->second = index++; points.push_back(p); } else { - ijk[count] = vertex_index[p]; + ijk[count] = iti->second; } ++count; } else { @@ -104,8 +106,6 @@ class Polyhedron_builder_from_STL : public CGAL::Modifier_base { public: - std::string name, color; - Polyhedron_builder_from_STL(std::istream& is_) : is(is_), counter(0) {} From 00a57be25a4741471da32e316186772013333512 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Fri, 23 Jan 2015 14:31:11 +0100 Subject: [PATCH 06/32] remove the STL reading part outside of the builder --- .../Polyhedron/Polyhedron_demo_stl_plugin.cpp | 13 +-- .../CGAL/IO/Polyhedron_builder_from_STL.h | 79 ++----------- Polyhedron_IO/include/CGAL/IO/STL_reader.h | 110 ++++++++++++++++++ 3 files changed, 119 insertions(+), 83 deletions(-) create mode 100644 Polyhedron_IO/include/CGAL/IO/STL_reader.h diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_stl_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_stl_plugin.cpp index 56ac315d295..47bb30f5f81 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_stl_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_stl_plugin.cpp @@ -66,18 +66,7 @@ Polyhedron_demo_stl_plugin::load(QFileInfo fileinfo) { } Scene_polyhedron_item* item = new Scene_polyhedron_item(P); - if(builder.name.size() == 0){ - item->setName(fileinfo.baseName()); - } else { - item->setName(builder.name.c_str()); - } - QColor color(builder.color.c_str()); - if(color.isValid()) - { - item->setColor(color); - item->changed(); - } - + item->setName(fileinfo.baseName()); return item; } diff --git a/Polyhedron_IO/include/CGAL/IO/Polyhedron_builder_from_STL.h b/Polyhedron_IO/include/CGAL/IO/Polyhedron_builder_from_STL.h index aa557ff63e5..c58ac0ae97e 100644 --- a/Polyhedron_IO/include/CGAL/IO/Polyhedron_builder_from_STL.h +++ b/Polyhedron_IO/include/CGAL/IO/Polyhedron_builder_from_STL.h @@ -21,7 +21,7 @@ #include #include -#include +#include #include @@ -30,96 +30,33 @@ namespace CGAL{ template class Polyhedron_builder_from_STL : public CGAL::Modifier_base { typedef typename HDS::Vertex::Point Point_3; - typedef std::vector Points_3; + typedef std::vector > Points_3; typedef cpp11::array Facet; typedef std::vector Surface; std::istream& is; - int counter; Points_3 meshPoints; Surface mesh; - bool - read(std::istream& input, Points_3& points, Surface& surface, int /*offset*/ = 0) - { - std::string s, solid("solid"), facet("facet"), outer("outer"), loop("loop"), vertex("vertex"), endloop("endloop"), endsolid("endsolid"); - - std::map vertex_index; - int index = 0; - cpp11::array ijk; - Point_3 p; - - input >> s; - if(s == solid){ - std::getline(input, s); - } else { - std::cerr << "We expect keyword 'solid'" << std::endl; - return false; - } - - while(input >> s){ - if(s == endsolid){ - //std::cerr << "found endsolid" << std::endl; - } else if(s == facet){ - //std::cerr << "found facet" << std::endl; - std::getline(input, s); // ignore the normal - input >> s; - if(s != outer){ - std::cerr << "Expect 'outer' and got " << s << std::endl; - return false; - } - input >> s; - if(s != loop){ - std::cerr << "Expect 'loop' and got " << s << std::endl; - return false; - } - int count = 0; - do { - input >> s; - if(s == vertex){ - // std::cerr << "found vertex" << std::endl; - if(count < 3){ - input >> p; - typename std::map::iterator iti= - vertex_index.insert(std::make_pair(p,-1)).first; - if(iti->second==-1){ - ijk[count] = index; - iti->second = index++; - points.push_back(p); - } else { - ijk[count] = iti->second; - } - ++count; - } else { - std::cerr << "We can only read triangulated surfaces" << std::endl; - return false; - } - } - }while(s != endloop); - - surface.push_back(ijk); - } - } - return true; - } - - public: Polyhedron_builder_from_STL(std::istream& is_) - : is(is_), counter(0) + : is(is_) {} void operator()( HDS& hds) { - if(!read(is, meshPoints, mesh)) return; + if(!read_STL(is, meshPoints, mesh)) return; CGAL::Polyhedron_incremental_builder_3 B(hds); B.begin_surface( meshPoints.size(), mesh.size()); typedef typename Points_3::size_type size_type; for(size_type i=0; i < meshPoints.size(); i++){ - B.add_vertex( meshPoints[i]); + B.add_vertex( + Point_3(meshPoints[i][0], meshPoints[i][1], meshPoints[i][2]) + ); } + for(size_type i=0; i < mesh.size(); i++){ B.begin_facet(); B.add_vertex_to_facet( mesh[i][0]); diff --git a/Polyhedron_IO/include/CGAL/IO/STL_reader.h b/Polyhedron_IO/include/CGAL/IO/STL_reader.h new file mode 100644 index 00000000000..ba7bf3895f2 --- /dev/null +++ b/Polyhedron_IO/include/CGAL/IO/STL_reader.h @@ -0,0 +1,110 @@ +// Copyright (c) 2015 GeometryFactory +// +// 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) : Andreas Fabri + +#ifndef CGAL_IO_STL_READER_H +#define CGAL_IO_STL_READER_H + +#include + +#include +#include +#include + +namespace CGAL{ + + bool + read_STL( std::istream& input, + std::vector< cpp11::array >& points, + std::vector< cpp11::array >& facets, + bool verbose = false) + { + std::string s, + solid("solid"), + facet("facet"), + outer("outer"), + loop("loop"), + vertex("vertex"), + endloop("endloop"), + endsolid("endsolid"); + + std::map, int> vertex_index; + int index = 0; + cpp11::array ijk; + cpp11::array p; + + input >> s; + if(s == solid){ + std::getline(input, s); + } else { + if (verbose) + std::cerr << "We expect keyword 'solid'" << std::endl; + return false; + } + + while(input >> s){ + if(s == endsolid){ + //std::cerr << "found endsolid" << std::endl; + } else if(s == facet){ + //std::cerr << "found facet" << std::endl; + std::getline(input, s); // ignore the normal + input >> s; + if(s != outer){ + if (verbose) + std::cerr << "Expect 'outer' and got " << s << std::endl; + return false; + } + input >> s; + if(s != loop){ + if (verbose) + std::cerr << "Expect 'loop' and got " << s << std::endl; + return false; + } + int count = 0; + do { + input >> s; + if(s == vertex){ + // std::cerr << "found vertex" << std::endl; + if(count < 3){ + input >> p[0] >> p[1] >> p[2]; + typename std::map, int>::iterator iti= + vertex_index.insert(std::make_pair(p,-1)).first; + if(iti->second==-1){ + ijk[count] = index; + iti->second = index++; + points.push_back(p); + } else { + ijk[count] = iti->second; + } + ++count; + } else { + if (verbose) + std::cerr << "We can only read triangulated surfaces" << std::endl; + return false; + } + } + }while(s != endloop); + + facets.push_back(ijk); + } + } + return true; + } + +} // namespace CGAL + +#endif // CGAL_IO_STL_READER_H From 4fbf80df460882dea103d8e200c8881a3c09f8f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Fri, 23 Jan 2015 15:03:13 +0100 Subject: [PATCH 07/32] move Polygon_soup_to_polyhedron_3 to its own header --- .../CGAL/Polygon_soup_to_polyhedron_3.h | 77 +++++++++++++++++++ .../include/CGAL/orient_polygon_soup.h | 48 ------------ .../Polyhedron/Scene_polygon_soup_item.cpp | 1 + .../Scene_polyhedron_selection_item.h | 2 +- 4 files changed, 79 insertions(+), 49 deletions(-) create mode 100644 Operations_on_polyhedra/include/CGAL/Polygon_soup_to_polyhedron_3.h diff --git a/Operations_on_polyhedra/include/CGAL/Polygon_soup_to_polyhedron_3.h b/Operations_on_polyhedra/include/CGAL/Polygon_soup_to_polyhedron_3.h new file mode 100644 index 00000000000..6be1bd916ab --- /dev/null +++ b/Operations_on_polyhedra/include/CGAL/Polygon_soup_to_polyhedron_3.h @@ -0,0 +1,77 @@ +// Copyright (c) 2009-2013 GeometryFactory (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 +// General Public License as published by the Free Software Foundation, +// either version 3 of the License, or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// +// +// Author(s) : Laurent Rineau and Sebastien Loriot + +#include +#include +#include + +#ifndef CGAL_POLYGON_SOUP_TO_POLYHEDRON_3_H +#define CGAL_POLYGON_SOUP_TO_POLYHEDRON_3_H + +namespace CGAL{ + +/** + * Modifier to build a polyhedron from a soup of polygons. + */ +template +class Polygon_soup_to_polyhedron_3: public CGAL::Modifier_base +{ + typedef std::vector Polygon_3; + + const std::vector& points; + const std::vector >& polygons; +public: + /** + * The constructor for modifier object. + * @param points points of the soup of polygons. + * @param polygons each element in the vector describes a polygon using the index of the points in the vector. + */ + Polygon_soup_to_polyhedron_3(const std::vector& points, + const std::vector >& polygons) + : points(points), polygons(polygons) + { } + + void operator()(HDS& out_hds) + { + Polyhedron_incremental_builder_3 builder(out_hds); + + builder.begin_surface(points.size(), polygons.size()); + + for(std::size_t i = 0, end = points.size(); i < end; ++i) + { builder.add_vertex(points[i]); } + + for(std::size_t i = 0, end = polygons.size(); i < end; ++i) + { + const Polygon_3& polygon = polygons[i]; + const std::size_t size = polygon.size(); + + builder.begin_facet(); + for(std::size_t j = 0; j < size; ++j) { + builder.add_vertex_to_facet(polygon[j]); + } + builder.end_facet(); + } + builder.end_surface(); + } +}; + +} //end of namespace CGAL + +#endif //CGAL_POLYGON_SOUP_TO_POLYHEDRON_3_H diff --git a/Operations_on_polyhedra/include/CGAL/orient_polygon_soup.h b/Operations_on_polyhedra/include/CGAL/orient_polygon_soup.h index 7cc5e9b6600..3cfb1e8bea6 100644 --- a/Operations_on_polyhedra/include/CGAL/orient_polygon_soup.h +++ b/Operations_on_polyhedra/include/CGAL/orient_polygon_soup.h @@ -21,9 +21,6 @@ #ifndef CGAL_ORIENT_POLYGON_SOUP #define CGAL_ORIENT_POLYGON_SOUP -#include -#include -#include #include #include @@ -233,51 +230,6 @@ bool orient_polygon_soup(const std::vector& points, return orienter.orient(); } -/** - * Modifier to build a polyhedron from a soup of polygons. - */ -template -class Polygon_soup_to_polyhedron_3: public CGAL::Modifier_base -{ - typedef std::vector Polygon_3; - - const std::vector& points; - const std::vector >& polygons; -public: - /** - * The constructor for modifier object. - * @param points points of the soup of polygons. - * @param polygons each element in the vector describes a polygon using the index of the points in the vector. - */ - Polygon_soup_to_polyhedron_3(const std::vector& points, - const std::vector >& polygons) - : points(points), polygons(polygons) - { } - - void operator()(HDS& out_hds) - { - Polyhedron_incremental_builder_3 builder(out_hds); - - builder.begin_surface(points.size(), polygons.size()); - - for(std::size_t i = 0, end = points.size(); i < end; ++i) - { builder.add_vertex(points[i]); } - - for(std::size_t i = 0, end = polygons.size(); i < end; ++i) - { - const Polygon_3& polygon = polygons[i]; - const std::size_t size = polygon.size(); - - builder.begin_facet(); - for(std::size_t j = 0; j < size; ++j) { - builder.add_vertex_to_facet(polygon[j]); - } - builder.end_facet(); - } - builder.end_surface(); - } -}; - }// namespace CGAL #endif // CGAL_ORIENT_POLYGON_SOUP diff --git a/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.cpp b/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.cpp index 5a4a6557d41..2eb626af670 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.cpp @@ -19,6 +19,7 @@ #include #include +#include #include typedef Kernel::Point_3 Point_3; diff --git a/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.h b/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.h index 22d1a96fb29..799a5952e9d 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.h @@ -8,7 +8,7 @@ #include "Scene_polyhedron_item_decorator.h" #include "Polyhedron_type.h" #include -#include +#include #include #include From 135568bb0dace82c703e128fd5850fee0a37e27a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Fri, 23 Jan 2015 15:30:04 +0100 Subject: [PATCH 08/32] abstract the point and polygon type --- .../CGAL/Polygon_soup_to_polyhedron_3.h | 44 ++++++++++++------- .../Polyhedron/Scene_polygon_soup_item.cpp | 4 +- .../Scene_polyhedron_selection_item.h | 3 +- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/Operations_on_polyhedra/include/CGAL/Polygon_soup_to_polyhedron_3.h b/Operations_on_polyhedra/include/CGAL/Polygon_soup_to_polyhedron_3.h index 6be1bd916ab..61cab2d7fdc 100644 --- a/Operations_on_polyhedra/include/CGAL/Polygon_soup_to_polyhedron_3.h +++ b/Operations_on_polyhedra/include/CGAL/Polygon_soup_to_polyhedron_3.h @@ -14,37 +14,37 @@ // // $URL$ // $Id$ -// +// // // Author(s) : Laurent Rineau and Sebastien Loriot +#ifndef CGAL_POLYGON_SOUP_TO_POLYHEDRON_3_H +#define CGAL_POLYGON_SOUP_TO_POLYHEDRON_3_H + #include #include #include -#ifndef CGAL_POLYGON_SOUP_TO_POLYHEDRON_3_H -#define CGAL_POLYGON_SOUP_TO_POLYHEDRON_3_H - namespace CGAL{ /** * Modifier to build a polyhedron from a soup of polygons. */ -template +template class Polygon_soup_to_polyhedron_3: public CGAL::Modifier_base { - typedef std::vector Polygon_3; - - const std::vector& points; - const std::vector >& polygons; + const std::vector& points; + const std::vector& polygons; + typedef typename HDS::Vertex::Point Point_3; public: - /** + /** * The constructor for modifier object. * @param points points of the soup of polygons. * @param polygons each element in the vector describes a polygon using the index of the points in the vector. */ - Polygon_soup_to_polyhedron_3(const std::vector& points, - const std::vector >& polygons) + Polygon_soup_to_polyhedron_3( + const std::vector& points, + const std::vector& polygons) : points(points), polygons(polygons) { } @@ -55,23 +55,35 @@ public: builder.begin_surface(points.size(), polygons.size()); for(std::size_t i = 0, end = points.size(); i < end; ++i) - { builder.add_vertex(points[i]); } + builder.add_vertex( Point_3(points[i][0], points[i][1], points[i][2]) ); for(std::size_t i = 0, end = polygons.size(); i < end; ++i) { - const Polygon_3& polygon = polygons[i]; + const Polygon& polygon = polygons[i]; const std::size_t size = polygon.size(); builder.begin_facet(); - for(std::size_t j = 0; j < size; ++j) { + for(std::size_t j = 0; j < size; ++j) builder.add_vertex_to_facet(polygon[j]); - } builder.end_facet(); } builder.end_surface(); } }; +/** + * Append a soup of polygons in a Polyhedron + */ +template +void polygon_soup_to_polyhedron_3(Polyhedron& P, + const std::vector& points, + const std::vector& polygons) +{ + Polygon_soup_to_polyhedron_3< typename Polyhedron::HalfedgeDS, + Point, Polygon > modifier(points, polygons); + P.delegate(modifier); +} + } //end of namespace CGAL #endif //CGAL_POLYGON_SOUP_TO_POLYHEDRON_3_H diff --git a/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.cpp b/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.cpp index 2eb626af670..98362c8e5d4 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.cpp @@ -315,9 +315,7 @@ bool Scene_polygon_soup_item::exportAsPolyhedron(Polyhedron* out_polyhedron) { orient(); - CGAL::Polygon_soup_to_polyhedron_3 builder( - soup->points, soup->polygons); - out_polyhedron->delegate(builder); + CGAL::polygon_soup_to_polyhedron_3(*out_polyhedron, soup->points, soup->polygons); if(out_polyhedron->size_of_vertices() > 0) { // Also check whether the consistent orientation is fine diff --git a/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.h b/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.h index 799a5952e9d..2550257eb94 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.h @@ -639,8 +639,7 @@ public: polygons[counter].push_back(hb->vertex()->id() -1); } while(++hb != hend); } - CGAL::Polygon_soup_to_polyhedron_3 builder(points, polygons); - out->delegate(builder); + CGAL::polygon_soup_to_polyhedron_3(*out, points, polygons); return out->size_of_vertices() > 0; } From 58b99a51f2f75725cd74d2d1ed78ffcfe68cc055 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Fri, 23 Jan 2015 15:54:49 +0100 Subject: [PATCH 09/32] hide the modifier in internal namespace and advertise the function --- ...up_to_polyhedron_3.h => polygon_soup_to_polyhedron_3.h} | 7 +++++-- Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.cpp | 2 +- .../demo/Polyhedron/Scene_polyhedron_selection_item.h | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) rename Operations_on_polyhedra/include/CGAL/{Polygon_soup_to_polyhedron_3.h => polygon_soup_to_polyhedron_3.h} (92%) diff --git a/Operations_on_polyhedra/include/CGAL/Polygon_soup_to_polyhedron_3.h b/Operations_on_polyhedra/include/CGAL/polygon_soup_to_polyhedron_3.h similarity index 92% rename from Operations_on_polyhedra/include/CGAL/Polygon_soup_to_polyhedron_3.h rename to Operations_on_polyhedra/include/CGAL/polygon_soup_to_polyhedron_3.h index 61cab2d7fdc..5ec4f7c1c0f 100644 --- a/Operations_on_polyhedra/include/CGAL/Polygon_soup_to_polyhedron_3.h +++ b/Operations_on_polyhedra/include/CGAL/polygon_soup_to_polyhedron_3.h @@ -27,6 +27,7 @@ namespace CGAL{ +namespace internal{ /** * Modifier to build a polyhedron from a soup of polygons. */ @@ -71,6 +72,8 @@ public: } }; +} //namespace internal + /** * Append a soup of polygons in a Polyhedron */ @@ -79,8 +82,8 @@ void polygon_soup_to_polyhedron_3(Polyhedron& P, const std::vector& points, const std::vector& polygons) { - Polygon_soup_to_polyhedron_3< typename Polyhedron::HalfedgeDS, - Point, Polygon > modifier(points, polygons); + internal::Polygon_soup_to_polyhedron_3< typename Polyhedron::HalfedgeDS, + Point, Polygon > modifier(points, polygons); P.delegate(modifier); } diff --git a/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.cpp b/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.cpp index 98362c8e5d4..8325aeee8b0 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.cpp @@ -19,7 +19,7 @@ #include #include -#include +#include #include typedef Kernel::Point_3 Point_3; diff --git a/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.h b/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.h index 2550257eb94..e04a4f8b4c5 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.h @@ -8,7 +8,7 @@ #include "Scene_polyhedron_item_decorator.h" #include "Polyhedron_type.h" #include -#include +#include #include #include From 4708e63fa609c51b0199136545a21e41f97d5e93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Fri, 23 Jan 2015 15:56:02 +0100 Subject: [PATCH 10/32] abstract the polygon type --- .../include/CGAL/orient_polygon_soup.h | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Operations_on_polyhedra/include/CGAL/orient_polygon_soup.h b/Operations_on_polyhedra/include/CGAL/orient_polygon_soup.h index 3cfb1e8bea6..7127d09636a 100644 --- a/Operations_on_polyhedra/include/CGAL/orient_polygon_soup.h +++ b/Operations_on_polyhedra/include/CGAL/orient_polygon_soup.h @@ -33,16 +33,15 @@ namespace CGAL { namespace internal { -template +template class Polygon_soup_orienter { - typedef std::vector Polygon_3; typedef std::vector Points; typedef std::map, std::set > Edges_map; typedef boost::array Edge; typedef std::vector Polygons; typedef std::set Edges; - typedef Polygons::size_type size_type; + typedef typename Polygons::size_type size_type; const Points& points; Polygons& polygons; @@ -220,13 +219,12 @@ public: * @return true if a consistent orientation has been found * * \TODO code: there is no check for duplicate points, yet it can be implemented as separate filter function - * \TODO code: support fixed size arrays for polygons, or creating a concept which provides .size and .operator[] */ -template +template bool orient_polygon_soup(const std::vector& points, - std::vector< std::vector >& polygons) + std::vector< Polygon_3 >& polygons) { - internal::Polygon_soup_orienter orienter(points, polygons); + internal::Polygon_soup_orienter orienter(points, polygons); return orienter.orient(); } From 4242990bf515779804dce8026cc36decb2e59c95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Fri, 23 Jan 2015 16:22:21 +0100 Subject: [PATCH 11/32] change Index type and use CGAL::array --- .../include/CGAL/orient_polygon_soup.h | 49 +++++++++---------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/Operations_on_polyhedra/include/CGAL/orient_polygon_soup.h b/Operations_on_polyhedra/include/CGAL/orient_polygon_soup.h index 7127d09636a..71918bed9e4 100644 --- a/Operations_on_polyhedra/include/CGAL/orient_polygon_soup.h +++ b/Operations_on_polyhedra/include/CGAL/orient_polygon_soup.h @@ -27,7 +27,7 @@ #include #include -#include +#include namespace CGAL { @@ -36,9 +36,10 @@ namespace internal { template class Polygon_soup_orienter { + typedef typename std::iterator_traits::value_type Index; typedef std::vector Points; - typedef std::map, std::set > Edges_map; - typedef boost::array Edge; + typedef std::map, std::set > Edges_map; + typedef cpp11::array Edge; typedef std::vector Polygons; typedef std::set Edges; typedef typename Polygons::size_type size_type; @@ -57,6 +58,11 @@ public: } private: + Edge canonical_edge(Index i, Index j) + { + return i 2) ) { - Edge edge; - edge[0] = i0; - edge[1] = i1; - if(i0 > i1) std::swap(edge[0], edge[1]); - non_manifold_edges.insert(edge); + non_manifold_edges.insert(CGAL::make_array(i0,i1)); } } } @@ -126,22 +128,17 @@ public: for(size_type ih = 0 ; ih < size ; ++ih) { size_type ihp1 = ih+1; if(ihp1>=size) ihp1 = 0; - const std::size_t& i1 = polygons[to_be_oriented_index][ih]; - const std::size_t& i2 = polygons[to_be_oriented_index][ihp1]; + const Index& i1 = polygons[to_be_oriented_index][ih]; + const Index& i2 = polygons[to_be_oriented_index][ihp1]; - Edge edge; - edge[0] = i1; - edge[1] = i2; - if(i1 > i2) std::swap(edge[0], edge[1]); - - if(non_manifold_edges.count(edge) > 0) { + if(non_manifold_edges.count(canonical_edge(i1,i2)) > 0) { continue; } // edge (i1,i2) - Edges_map::iterator it_same_orient = edges.find(make_pair(i1, i2)); + typename Edges_map::iterator it_same_orient = edges.find(make_pair(i1, i2)); // edges (i2,i1) - Edges_map::iterator it_other_orient = edges.find(make_pair(i2, i1)); + typename Edges_map::iterator it_other_orient = edges.find(make_pair(i2, i1)); CGAL_assertion(it_same_orient != edges.end()); if(it_same_orient->second.size() > 1) { @@ -164,8 +161,8 @@ public: // reverse the orientation const size_type size = polygons[index].size(); for(size_type j = 0; j < size; ++j) { - const std::size_t& i0 = polygons[index][j]; - const std::size_t& i1 = polygons[index][ j+1 < size ? j+1: 0]; + const Index& i0 = polygons[index][j]; + const Index& i1 = polygons[index][ j+1 < size ? j+1: 0]; CGAL_assertion_code(const bool r = ) edges[std::make_pair(i0, i1)].erase(index) CGAL_assertion_code(!= 0); @@ -173,8 +170,8 @@ public: } inverse_orientation(index); for(size_type j = 0; j < size; ++j) { - const std::size_t& i0 = polygons[index][j]; - const std::size_t& i1 = polygons[index][ j+1 < size ? j+1: 0]; + const Index& i0 = polygons[index][j]; + const Index& i1 = polygons[index][ j+1 < size ? j+1: 0]; edges[std::make_pair(i0, i1)].insert(index); } // "inverse the orientation of polygon #%1\n").arg(index); From 3fce4e0e5a2bac618e88410b7fd95d5bdb22adcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Fri, 23 Jan 2015 16:30:57 +0100 Subject: [PATCH 12/32] bugfix: we might miss edges for example if we have exactly 3 triangles oriented such that the edge (i0,i1) is in the 3 triangles and i1>i0 then the edge will never be reported --- .../include/CGAL/orient_polygon_soup.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Operations_on_polyhedra/include/CGAL/orient_polygon_soup.h b/Operations_on_polyhedra/include/CGAL/orient_polygon_soup.h index 71918bed9e4..d1c0876d6bb 100644 --- a/Operations_on_polyhedra/include/CGAL/orient_polygon_soup.h +++ b/Operations_on_polyhedra/include/CGAL/orient_polygon_soup.h @@ -84,11 +84,11 @@ private: for(size_type j = 0; j < size; ++j) { const Index& i0 = polygons[i][j]; const Index& i1 = polygons[i][ j+1 < size ? j+1: 0]; - if( (i0 < i1) && - (edges[std::make_pair(i0, i1)].size() + - edges[std::make_pair(i1, i0)].size() > 2) ) + + if( edges[std::make_pair(i0, i1)].size() + + edges[std::make_pair(i1, i0)].size() > 2 ) { - non_manifold_edges.insert(CGAL::make_array(i0,i1)); + non_manifold_edges.insert(canonical_edge(i0,i1)); } } } From ccbcb8b23fe1cab45eba4d09ab6008a55b0ab046 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 26 Jan 2015 08:59:47 +0100 Subject: [PATCH 13/32] remove typename --- Polyhedron_IO/include/CGAL/IO/STL_reader.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Polyhedron_IO/include/CGAL/IO/STL_reader.h b/Polyhedron_IO/include/CGAL/IO/STL_reader.h index ba7bf3895f2..e0e64575ad6 100644 --- a/Polyhedron_IO/include/CGAL/IO/STL_reader.h +++ b/Polyhedron_IO/include/CGAL/IO/STL_reader.h @@ -81,7 +81,7 @@ namespace CGAL{ // std::cerr << "found vertex" << std::endl; if(count < 3){ input >> p[0] >> p[1] >> p[2]; - typename std::map, int>::iterator iti= + std::map, int>::iterator iti= vertex_index.insert(std::make_pair(p,-1)).first; if(iti->second==-1){ ijk[count] = index; From ba36fe0ac11ec2cbf7f99fe2fae4e5d242bf60da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 26 Jan 2015 09:34:25 +0100 Subject: [PATCH 14/32] reordering --- .../include/CGAL/orient_polygon_soup.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Operations_on_polyhedra/include/CGAL/orient_polygon_soup.h b/Operations_on_polyhedra/include/CGAL/orient_polygon_soup.h index d1c0876d6bb..363ae34ffc7 100644 --- a/Operations_on_polyhedra/include/CGAL/orient_polygon_soup.h +++ b/Operations_on_polyhedra/include/CGAL/orient_polygon_soup.h @@ -50,13 +50,6 @@ class Polygon_soup_orienter Edges_map edges; Edges non_manifold_edges; -public: - Polygon_soup_orienter(const Points& points, Polygons& polygons) - : points(points), polygons(polygons) - { - fill_edges(); - } - private: Edge canonical_edge(Index i, Index j) { @@ -99,6 +92,13 @@ private: } public: + + Polygon_soup_orienter(const Points& points, Polygons& polygons) + : points(points), polygons(polygons) + { + fill_edges(); + } + bool orient() { std::vector oriented; From e08c28727c589d6216ee0b43905c79fb8207d6e6 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 19 Jan 2015 17:54:26 +0100 Subject: [PATCH 15/32] Add #defines to trick moc (cherry picked from commit 5db9675db849f97222e5751b24d3a68130de7dca) Conflicts: Installation/include/CGAL/config.h --- Installation/include/CGAL/config.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Installation/include/CGAL/config.h b/Installation/include/CGAL/config.h index 2f44dc8c77b..3355e334af4 100644 --- a/Installation/include/CGAL/config.h +++ b/Installation/include/CGAL/config.h @@ -49,6 +49,36 @@ // When Qt moc runs on CGAL files, do not process // # define BOOST_TT_HAS_OPERATOR_HPP_INCLUDED +# define BOOST_TT_HAS_BIT_AND_ASSIGN_HPP_INCLUDED +# define BOOST_TT_HAS_BIT_OR_HPP_INCLUDED +# define BOOST_TT_HAS_BIT_OR_ASSIGN_HPP_INCLUDED +# define BOOST_TT_HAS_BIT_XOR_HPP_INCLUDED +# define BOOST_TT_HAS_BIT_XOR_ASSIGN_HPP_INCLUDED +# define BOOST_TT_HAS_DIVIDES_HPP_INCLUDED +# define BOOST_TT_HAS_DIVIDES_ASSIGN_HPP_INCLUDED +# define BOOST_TT_HAS_EQUAL_TO_HPP_INCLUDED +# define BOOST_TT_HAS_GREATER_HPP_INCLUDED +# define BOOST_TT_HAS_GREATER_EQUAL_HPP_INCLUDED +# define BOOST_TT_HAS_LEFT_SHIFT_HPP_INCLUDED +# define BOOST_TT_HAS_LEFT_SHIFT_ASSIGN_HPP_INCLUDED +# define BOOST_TT_HAS_LESS_HPP_INCLUDED +# define BOOST_TT_HAS_LESS_EQUAL_HPP_INCLUDED +# define BOOST_TT_HAS_LOGICAL_AND_HPP_INCLUDED +# define BOOST_TT_HAS_LOGICAL_OR_HPP_INCLUDED +# define BOOST_TT_HAS_MINUS_HPP_INCLUDED +# define BOOST_TT_HAS_MINUS_ASSIGN_HPP_INCLUDED +# define BOOST_TT_HAS_MODULUS_HPP_INCLUDED +# define BOOST_TT_HAS_MODULUS_ASSIGN_HPP_INCLUDED +# define BOOST_TT_HAS_MULTIPLIES_HPP_INCLUDED +# define BOOST_TT_HAS_MULTIPLIES_ASSIGN_HPP_INCLUDED +# define BOOST_TT_HAS_NOT_EQUAL_TO_HPP_INCLUDED +# define BOOST_TT_HAS_PLUS_HPP_INCLUDED +# define BOOST_TT_HAS_PLUS_ASSIGN_HPP_INCLUDED +# define BOOST_TT_HAS_RIGHT_SHIFT_HPP_INCLUDED +# define BOOST_TT_HAS_RIGHT_SHIFT_ASSIGN_HPP_INCLUDED +// do not include either +// it includes +# define BOOST_RANDOM_HPP #endif // The following header file defines among other things BOOST_PREVENT_MACRO_SUBSTITUTION From 20ffc3da30cb729faae3b496aa9ac92b6203ee5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Tue, 27 Jan 2015 10:07:32 +0100 Subject: [PATCH 16/32] remove assertion that should be a warning --- Operations_on_polyhedra/include/CGAL/orient_polyhedron_3.h | 1 - 1 file changed, 1 deletion(-) diff --git a/Operations_on_polyhedra/include/CGAL/orient_polyhedron_3.h b/Operations_on_polyhedra/include/CGAL/orient_polyhedron_3.h index be5c7786074..cab80dabc3e 100644 --- a/Operations_on_polyhedra/include/CGAL/orient_polyhedron_3.h +++ b/Operations_on_polyhedra/include/CGAL/orient_polyhedron_3.h @@ -61,7 +61,6 @@ struct Axis_compare { */ template bool is_oriented(const Polyhedron& polyhedron) { - CGAL_precondition(polyhedron.is_closed()); const unsigned int axis = 0; typename Polyhedron::Vertex_const_iterator v_min From d6a8fcaf4f92a02fc19214622f52282e8ad8af9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Tue, 27 Jan 2015 10:39:41 +0100 Subject: [PATCH 17/32] the orientation plugin is only applicable on polygon soup items --- .../demo/Polyhedron/Polyhedron_demo_orient_soup_plugin.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_orient_soup_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_orient_soup_plugin.cpp index e86de67108a..82a9fb7ff5a 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_orient_soup_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_orient_soup_plugin.cpp @@ -25,8 +25,7 @@ public: bool applicable() const { Q_FOREACH(Scene_interface::Item_id index, scene->selectionIndices()) { - if(qobject_cast(scene->item(index))|| - qobject_cast(scene->item(index))) + if(qobject_cast(scene->item(index))) return true; } return false; From 613915c07f17acf93df054324c6b050156d468ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Tue, 27 Jan 2015 11:37:07 +0100 Subject: [PATCH 18/32] add the possibility to load a polygon soup from vector of points and indices I needed to move the Polygon_soup class inside the header as the function added is a template function and the definition must be available in the header --- Polyhedron/demo/Polyhedron/CMakeLists.txt | 2 +- .../Polyhedron/Scene_polygon_soup_item.cpp | 84 +------------ .../demo/Polyhedron/Scene_polygon_soup_item.h | 111 +++++++++++++++++- 3 files changed, 112 insertions(+), 85 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/CMakeLists.txt b/Polyhedron/demo/Polyhedron/CMakeLists.txt index db46e8b88a2..87007ae046e 100644 --- a/Polyhedron/demo/Polyhedron/CMakeLists.txt +++ b/Polyhedron/demo/Polyhedron/CMakeLists.txt @@ -325,7 +325,7 @@ if(CGAL_Qt4_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND) target_link_libraries(gocad_plugin scene_polyhedron_item) polyhedron_demo_plugin(stl_plugin Polyhedron_demo_stl_plugin) - target_link_libraries(stl_plugin scene_polyhedron_item) + target_link_libraries(stl_plugin scene_polyhedron_item scene_polygon_soup_item) polyhedron_demo_plugin(xyz_plugin Polyhedron_demo_xyz_plugin) target_link_libraries(xyz_plugin scene_points_with_normal_item) diff --git a/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.cpp b/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.cpp index 8325aeee8b0..49a9451b5ca 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.cpp @@ -1,7 +1,6 @@ #include "Scene_polygon_soup_item.h" #include "Scene_polyhedron_item.h" #include -#include "Polyhedron_type.h" #include #include @@ -10,8 +9,6 @@ #include #include #include -#include -#include #include #include @@ -22,86 +19,9 @@ #include #include -typedef Kernel::Point_3 Point_3; - -struct Polygon_soup -{ - typedef std::vector Points; - typedef std::vector Polygon_3; - typedef std::map, std::set > Edges_map; - typedef boost::array Edge; - typedef std::vector Polygons; - typedef std::set Edges; - typedef Polygons::size_type size_type; - Points points; - Polygons polygons; - Edges_map edges; - Edges non_manifold_edges; - bool display_non_manifold_edges; - - Polygon_soup(): - display_non_manifold_edges(false){} - - Polygon_soup* clone() const { - Polygon_soup* result = new Polygon_soup(); - result->points = points; - result->polygons = polygons; - result->edges = edges; - result->non_manifold_edges = non_manifold_edges; - result->display_non_manifold_edges = display_non_manifold_edges; - return result; - } - - void clear() { - points.clear(); - polygons.clear(); - edges.clear(); - non_manifold_edges.clear(); - } - - void fill_edges() { - // Fill edges - edges.clear(); - for(size_type i = 0; i < polygons.size(); ++i) - { - const size_type size = polygons[i].size(); - for(size_type j = 0; j < size; ++j) { - const std::size_t& i0 = polygons[i][j]; - const std::size_t& i1 = polygons[i][ j+1 < size ? j+1: 0]; - edges[std::make_pair(i0, i1)].insert(i); -// qDebug() << tr("edges[std::make_pair(%1, %2)].insert(%3). Size=%4") -// .arg(i0).arg(i1).arg(i).arg(edges[std::make_pair(i0, i1)].size()); - } - } - - // Fill non-manifold edges - non_manifold_edges.clear(); - for(size_type i = 0; i < polygons.size(); ++i) - { - const size_type size = polygons[i].size(); - for(size_type j = 0; j < size; ++j) { - const std::size_t& i0 = polygons[i][j]; - const std::size_t& i1 = polygons[i][ j+1 < size ? j+1: 0]; - if( (i0 < i1) && - (edges[std::make_pair(i0, i1)].size() + - edges[std::make_pair(i1, i0)].size() > 2) ) - { - Edge edge; - edge[0] = i0; - edge[1] = i1; - if(i0 > i1) std::swap(edge[0], edge[1]); - non_manifold_edges.insert(edge); - } - } - } - } - - void inverse_orientation(const std::size_t index) { - std::reverse(polygons[index].begin(), polygons[index].end()); - } -}; - struct Polyhedron_to_polygon_soup_writer { + typedef Kernel::Point_3 Point_3; + Polygon_soup* soup; Polygon_soup::Polygon_3 polygon; diff --git a/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.h b/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.h index c376bc72996..4d84c5c369c 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.h @@ -3,16 +3,99 @@ #include "Scene_polygon_soup_item_config.h" #include "Scene_item_with_display_list.h" +#include "Polyhedron_type.h" + +#include + #include -#include "Polyhedron_type_fwd.h" -struct Polygon_soup; +struct Polygon_soup +{ + typedef Kernel::Point_3 Point_3; + typedef std::vector Points; + typedef std::vector Polygon_3; + typedef std::map, std::set > Edges_map; + typedef boost::array Edge; + typedef std::vector Polygons; + typedef std::set Edges; + typedef Polygons::size_type size_type; + Points points; + Polygons polygons; + Edges_map edges; + Edges non_manifold_edges; + bool display_non_manifold_edges; + + Polygon_soup(): + display_non_manifold_edges(false){} + + Polygon_soup* clone() const { + Polygon_soup* result = new Polygon_soup(); + result->points = points; + result->polygons = polygons; + result->edges = edges; + result->non_manifold_edges = non_manifold_edges; + result->display_non_manifold_edges = display_non_manifold_edges; + return result; + } + + void clear() { + points.clear(); + polygons.clear(); + edges.clear(); + non_manifold_edges.clear(); + } + + void fill_edges() { + // Fill edges + edges.clear(); + for(size_type i = 0; i < polygons.size(); ++i) + { + const size_type size = polygons[i].size(); + for(size_type j = 0; j < size; ++j) { + const std::size_t& i0 = polygons[i][j]; + const std::size_t& i1 = polygons[i][ j+1 < size ? j+1: 0]; + edges[std::make_pair(i0, i1)].insert(i); +// qDebug() << tr("edges[std::make_pair(%1, %2)].insert(%3). Size=%4") +// .arg(i0).arg(i1).arg(i).arg(edges[std::make_pair(i0, i1)].size()); + } + } + + // Fill non-manifold edges + non_manifold_edges.clear(); + for(size_type i = 0; i < polygons.size(); ++i) + { + const size_type size = polygons[i].size(); + for(size_type j = 0; j < size; ++j) { + const std::size_t& i0 = polygons[i][j]; + const std::size_t& i1 = polygons[i][ j+1 < size ? j+1: 0]; + if( (i0 < i1) && + (edges[std::make_pair(i0, i1)].size() + + edges[std::make_pair(i1, i0)].size() > 2) ) + { + Edge edge; + edge[0] = i0; + edge[1] = i1; + if(i0 > i1) std::swap(edge[0], edge[1]); + non_manifold_edges.insert(edge); + } + } + } + } + + void inverse_orientation(const std::size_t index) { + std::reverse(polygons[index].begin(), polygons[index].end()); + } +}; + + class Scene_polyhedron_item; class SCENE_POLYGON_SOUP_ITEM_EXPORT Scene_polygon_soup_item : public Scene_item_with_display_list { + typedef Kernel::Point_3 Point_3; + Q_OBJECT public: Scene_polygon_soup_item(); @@ -21,6 +104,30 @@ public: Scene_polygon_soup_item* clone() const; bool load(std::istream& in); void load(Scene_polyhedron_item*); + + template + inline void load(const std::vector& points, const std::vector& polygons) + { + if(!soup) + soup = new Polygon_soup; + soup->clear(); + + /// add points + soup->points.reserve(points.size()); + BOOST_FOREACH(const Point& p, points) + soup->points.push_back( Point_3(p[0], p[1], p[2]) ); + + /// add polygons + std::size_t nb_polygons=polygons.size(); + soup->polygons.resize(nb_polygons); + for(std::size_t i=0; ipolygons[i].assign(polygons[i].begin(), polygons[i].end()); + + /// fill non-manifold edges container + soup->fill_edges(); + oriented = false; + } + bool save(std::ostream& out) const; QString toolTip() const; From 4cf96051c5f86f50b03b07be4d96a908b4af7ea0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Tue, 27 Jan 2015 11:38:59 +0100 Subject: [PATCH 19/32] stl plugin can now also load polygon soups --- .../Polyhedron/Polyhedron_demo_stl_plugin.cpp | 46 +++++++++++-------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_stl_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_stl_plugin.cpp index 47bb30f5f81..7a2498f89da 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_stl_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_stl_plugin.cpp @@ -7,6 +7,7 @@ #include #include +#include #include @@ -45,29 +46,34 @@ Polyhedron_demo_stl_plugin::load(QFileInfo fileinfo) { std::cerr << "Error! Cannot open file " << (const char*)fileinfo.filePath().toUtf8() << std::endl; return NULL; } + + std::vector > points; + std::vector > triangles; + if (!CGAL::read_STL(in, points, triangles)) + { + std::cerr << "Error: invalid STL file" << std::endl; + return NULL; + } + + try{ + // Try building a polyhedron + Polyhedron P; + CGAL::polygon_soup_to_polyhedron_3(P, points, triangles); - // Try to read STL file in a polyhedron - Polyhedron P; - //Scene_polyhedron_item* item = new Scene_polyhedron_item(P); - //item->setName(fileinfo.baseName()); - - CGAL::Polyhedron_builder_from_STL builder(in); - // item->polyhedron()-> + if(! P.is_valid() || P.empty()){ + std::cerr << "Error: Invalid polyhedron" << std::endl; + } + else{ + Scene_polyhedron_item* item = new Scene_polyhedron_item(P); + item->setName(fileinfo.baseName()); + return item; + } + } + catch(...){} - P.delegate(builder); - - if(! P.is_valid()){ - std::cerr << "Error: Invalid polyhedron" << std::endl; - return 0; - } - - if(P.empty()){ - return 0; - } - - Scene_polyhedron_item* item = new Scene_polyhedron_item(P); + Scene_polygon_soup_item* item = new Scene_polygon_soup_item(); item->setName(fileinfo.baseName()); - + item->load(points, triangles); return item; } From 7ab1037f6bdb355ebf6c409f9a3a94c0a51ba62c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Tue, 27 Jan 2015 14:13:17 +0100 Subject: [PATCH 20/32] handle case when the x coordinate of the normal vector at the minimal vertex is 0 --- .../include/CGAL/orient_polyhedron_3.h | 41 ++++++++++++------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/Operations_on_polyhedra/include/CGAL/orient_polyhedron_3.h b/Operations_on_polyhedra/include/CGAL/orient_polyhedron_3.h index cab80dabc3e..541c06a2cd7 100644 --- a/Operations_on_polyhedra/include/CGAL/orient_polyhedron_3.h +++ b/Operations_on_polyhedra/include/CGAL/orient_polyhedron_3.h @@ -25,17 +25,22 @@ #include #include -namespace CGAL { -namespace internal { +namespace CGAL{ -template -struct Axis_compare { - template - bool operator()(const Vertex& v0, const Vertex& v1) const - { return v0.point()[axis] < v1.point()[axis]; } -}; +namespace internal{ + template + struct Compare_vertex_points_xyz_3{ + Less_xyz less; -} // namespace internal + typedef bool result_type; + template + bool operator()(const Vertex& v1, const Vertex& v2) const + { + return less(v1.point(), v2.point()); + } + + }; +} // end of namespace internal /** * Tests whether a closed polyhedron has a positive orientation. @@ -60,17 +65,23 @@ struct Axis_compare { * @endcode */ template -bool is_oriented(const Polyhedron& polyhedron) { - const unsigned int axis = 0; +bool is_oriented(const Polyhedron& polyhedron) +{ + typedef typename Polyhedron::Traits K; + internal::Compare_vertex_points_xyz_3< typename K::Less_xyz_3 > less_xyz; typename Polyhedron::Vertex_const_iterator v_min - = std::min_element(polyhedron.vertices_begin(), polyhedron.vertices_end(), internal::Axis_compare()); + = std::min_element(polyhedron.vertices_begin(), polyhedron.vertices_end(), less_xyz); - typedef typename Polyhedron::Traits K; const typename K::Vector_3& normal_v_min = compute_vertex_normal(*v_min); - CGAL_warning(normal_v_min[axis] != 0); - return normal_v_min[axis] < 0; + return normal_v_min[0] < 0 || ( + normal_v_min[0] == 0 && ( + normal_v_min[1] < 0 || + ( normal_v_min[1]==0 && normal_v_min[2] < 0 ) + ) + ); } + } // namespace CGAL #endif // CGAL_ORIENT_POLYHEDRON_3 From 4ccb186e08f9b8161a443576bc27cc7cc0e01306 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Tue, 27 Jan 2015 14:35:08 +0100 Subject: [PATCH 21/32] handle non triangulated polyhedron --- .../Polyhedron_subset_extraction.h | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Operations_on_polyhedra/include/CGAL/internal/corefinement/Polyhedron_subset_extraction.h b/Operations_on_polyhedra/include/CGAL/internal/corefinement/Polyhedron_subset_extraction.h index cc6291cc9bd..7d4922730de 100644 --- a/Operations_on_polyhedra/include/CGAL/internal/corefinement/Polyhedron_subset_extraction.h +++ b/Operations_on_polyhedra/include/CGAL/internal/corefinement/Polyhedron_subset_extraction.h @@ -132,8 +132,6 @@ void extract_connected_components( typedef ::CGAL::Union_find UF; typedef typename UF::handle UF_handle; typedef typename UF::iterator UF_iterator; - - CGAL_precondition(P.is_pure_triangle()); //init union-find: each facet is in its own set for (Facet_iterator it=P.facets_begin();it!=P.facets_end();++it){ @@ -144,13 +142,18 @@ void extract_connected_components( Facet_handle facet=it; UF_handle current=map_f2h.find(it)->second; - Halfedge_handle neighbors[3]; - neighbors[0]=facet->halfedge()->opposite(); - neighbors[1]=facet->halfedge()->next()->opposite(); - neighbors[2]=facet->halfedge()->next()->next()->opposite(); - - for (int i=0;i!=3;++i){ - if ( neighbors[i]->is_border_edge() ) continue; + std::vector neighbors; + Halfedge_handle hedge=facet->halfedge(); + do + { + neighbors.push_back( hedge->opposite() ); + hedge=hedge->next(); + } + while(hedge!=facet->halfedge()); + + std::size_t nb_edges=neighbors.size(); + for (std::size_t i=0;iis_border() ) continue; UF_handle neigh=map_f2h.find(neighbors[i]->facet())->second; if ( adjacent(neighbors[i]) && !uf.same_set(current,neigh) ){ uf.unify_sets(current,neigh); From 626ec7a144b6ee64069a9813955424db2fdb4706 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Mon, 26 Jan 2015 11:22:09 +0100 Subject: [PATCH 22/32] Disable the normal estimation plugin with Boost-1.57 and C++11 (cherry picked from commit bd435457178c23a2363eb9e05df1f8f63175660d) --- .../Polyhedron_demo_normal_estimation_plugin.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_normal_estimation_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_normal_estimation_plugin.cpp index 45c921a22cf..48ccec330e8 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_normal_estimation_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_normal_estimation_plugin.cpp @@ -19,6 +19,12 @@ #include "ui_Polyhedron_demo_normal_estimation_plugin.h" +#if BOOST_VERSION == 105700 +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) +# define CGAL_DISABLE_NORMAL_ESTIMATION_PLUGIN 1 +#endif +#endif + class Polyhedron_demo_normal_estimation_plugin : public QObject, public Polyhedron_demo_plugin_helper @@ -45,7 +51,11 @@ public: } bool applicable() const { +#if CGAL_DISABLE_NORMAL_ESTIMATION_PLUGIN + return false; +#else return qobject_cast(scene->item(scene->mainSelectionIndex())); +#endif } public slots: @@ -93,6 +103,7 @@ void Polyhedron_demo_normal_estimation_plugin::on_actionNormalInversion_triggere void Polyhedron_demo_normal_estimation_plugin::on_actionNormalEstimation_triggered() { +#if !CGAL_DISABLE_NORMAL_ESTIMATION_PLUGIN const Scene_interface::Item_id index = scene->mainSelectionIndex(); Scene_points_with_normal_item* item = @@ -200,6 +211,7 @@ void Polyhedron_demo_normal_estimation_plugin::on_actionNormalEstimation_trigger .arg(nb_unoriented_normals)); } } +#endif // !CGAL_DISABLE_NORMAL_ESTIMATION_PLUGIN } Q_EXPORT_PLUGIN2(Polyhedron_demo_normal_estimation_plugin, Polyhedron_demo_normal_estimation_plugin) From 7c09fdb4904a596f39855b8ec3da25613a142758 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Thu, 29 Jan 2015 09:03:38 +0100 Subject: [PATCH 23/32] add missing include --- Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.h b/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.h index 4d84c5c369c..f426b544b9a 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.h @@ -6,6 +6,7 @@ #include "Polyhedron_type.h" #include +#include #include From b4bd141980808862079ec0ff80c65c1d27836786 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Thu, 29 Jan 2015 10:27:17 +0100 Subject: [PATCH 24/32] move OFF reading function to a header file --- .../Polyhedron/Scene_polygon_soup_item.cpp | 44 ++---------- Polyhedron_IO/include/CGAL/IO/OFF_reader.h | 71 +++++++++++++++++++ 2 files changed, 75 insertions(+), 40 deletions(-) create mode 100644 Polyhedron_IO/include/CGAL/IO/OFF_reader.h diff --git a/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.cpp b/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.cpp index 49a9451b5ca..63f8b5eae69 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.cpp @@ -11,7 +11,7 @@ #include #include -#include +#include #include #include @@ -85,45 +85,9 @@ Scene_polygon_soup_item::clone() const { bool Scene_polygon_soup_item::load(std::istream& in) { -#if CGAL_VERSION_NR >= 1030700091 - typedef std::size_t indices_t; -#else - typedef boost::int32_t indices_t; -#endif - if(!soup) - soup = new Polygon_soup; - CGAL::File_scanner_OFF scanner(in); - soup->clear(); - soup->points.resize(scanner.size_of_vertices()); - soup->polygons.resize(scanner.size_of_facets()); - for (indices_t i = 0; i < scanner.size_of_vertices(); ++i) { - double x, y, z, w; - scanner.scan_vertex( x, y, z, w); - soup->points[i] = Point_3(x, y, z, w); - scanner.skip_to_next_vertex( i); - } - if(!in) - return false; - - for (indices_t i = 0; i < scanner.size_of_facets(); ++i) { - indices_t no; - - scanner.scan_facet( no, i); - soup->polygons[i].resize(no); - for(indices_t j = 0; j < no; ++j) { - indices_t id; - scanner.scan_facet_vertex_index(id, i); - if(id < scanner.size_of_vertices()) - { - soup->polygons[i][j] = id; - } - else - return false; - } - } - soup->fill_edges(); - oriented = false; - return (bool) in; + if (!soup) soup=new Polygon_soup(); + else soup->clear(); + return CGAL::read_OFF(in, soup->points, soup->polygons); } void Scene_polygon_soup_item::init_polygon_soup(std::size_t nb_pts, std::size_t nb_polygons){ diff --git a/Polyhedron_IO/include/CGAL/IO/OFF_reader.h b/Polyhedron_IO/include/CGAL/IO/OFF_reader.h new file mode 100644 index 00000000000..ce3c71a7f21 --- /dev/null +++ b/Polyhedron_IO/include/CGAL/IO/OFF_reader.h @@ -0,0 +1,71 @@ +// Copyright (c) 2015 GeometryFactory +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// +// Author(s) : Laurent Rineau and Sebastien Loriot + +#ifndef CGAL_IO_OFF_READER_H +#define CGAL_IO_OFF_READER_H + +#include + +#include +#include + +namespace CGAL{ + + template + bool + read_OFF( std::istream& in, + std::vector< Point_3 >& points, + std::vector< Polygon_3 >& polygons, + bool /* verbose */ = false) + { + CGAL::File_scanner_OFF scanner(in); + + points.resize(scanner.size_of_vertices()); + polygons.resize(scanner.size_of_facets()); + for (std::size_t i = 0; i < scanner.size_of_vertices(); ++i) { + double x, y, z, w; + scanner.scan_vertex( x, y, z, w); + CGAL_assertion(w!=0); + points[i] = Point_3(x/w, y/w, z/w); + scanner.skip_to_next_vertex( i); + } + if(!in) + return false; + + for (std::size_t i = 0; i < scanner.size_of_facets(); ++i) { + std::size_t no; + + scanner.scan_facet( no, i); + polygons[i].resize(no); + for(std::size_t j = 0; j < no; ++j) { + std::size_t id; + scanner.scan_facet_vertex_index(id, i); + if(id < scanner.size_of_vertices()) + { + polygons[i][j] = id; + } + else + return false; + } + } + return (bool) in; + } + +} // namespace CGAL + +#endif // CGAL_IO_OFF_READER_H From 24fcc4a2fe64be3c2d7718f52cf65a7ae3d56db0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Thu, 29 Jan 2015 12:27:43 +0100 Subject: [PATCH 25/32] update orient_polygon_soup to always produce a polyhedron with self-intersection at singular vertices/edges --- .../include/CGAL/orient_polygon_soup.h | 438 ++++++++++++------ .../data_polygon_soup/bad_cube.off | 23 + .../incompatible_orientation.off | 27 ++ .../isolated_singular_vertex_one_cc.off | 30 ++ .../data_polygon_soup/isolated_vertices.off | 9 + .../data_polygon_soup/nm_vertex_and_edge.off | 24 + .../data_polygon_soup/one_duplicated_edge.off | 12 + .../one_duplicated_edge_sharing_vertex.off | 18 + .../data_polygon_soup/partial_overlap.off | 30 ++ .../test_orient_polygon_soup.cpp | 54 +++ .../Polyhedron_demo_orient_soup_plugin.cpp | 41 +- .../Polyhedron/Scene_polygon_soup_item.cpp | 7 +- 12 files changed, 557 insertions(+), 156 deletions(-) create mode 100644 Operations_on_polyhedra/test/Operations_on_polyhedra/data_polygon_soup/bad_cube.off create mode 100644 Operations_on_polyhedra/test/Operations_on_polyhedra/data_polygon_soup/incompatible_orientation.off create mode 100644 Operations_on_polyhedra/test/Operations_on_polyhedra/data_polygon_soup/isolated_singular_vertex_one_cc.off create mode 100644 Operations_on_polyhedra/test/Operations_on_polyhedra/data_polygon_soup/isolated_vertices.off create mode 100644 Operations_on_polyhedra/test/Operations_on_polyhedra/data_polygon_soup/nm_vertex_and_edge.off create mode 100644 Operations_on_polyhedra/test/Operations_on_polyhedra/data_polygon_soup/one_duplicated_edge.off create mode 100644 Operations_on_polyhedra/test/Operations_on_polyhedra/data_polygon_soup/one_duplicated_edge_sharing_vertex.off create mode 100644 Operations_on_polyhedra/test/Operations_on_polyhedra/data_polygon_soup/partial_overlap.off create mode 100644 Operations_on_polyhedra/test/Operations_on_polyhedra/test_orient_polygon_soup.cpp diff --git a/Operations_on_polyhedra/include/CGAL/orient_polygon_soup.h b/Operations_on_polyhedra/include/CGAL/orient_polygon_soup.h index 363ae34ffc7..196e07fceaf 100644 --- a/Operations_on_polyhedra/include/CGAL/orient_polygon_soup.h +++ b/Operations_on_polyhedra/include/CGAL/orient_polygon_soup.h @@ -14,21 +14,22 @@ // // $URL$ // $Id$ -// // -// Author(s) : Laurent Rineau and Ilker O. Yaz +// +// Author(s) : Laurent Rineau and Sebastien Loriot #ifndef CGAL_ORIENT_POLYGON_SOUP #define CGAL_ORIENT_POLYGON_SOUP +#include + #include +#include #include #include #include -#include - namespace CGAL { namespace internal { @@ -36,193 +37,368 @@ namespace internal { template class Polygon_soup_orienter { - typedef typename std::iterator_traits::value_type Index; - typedef std::vector Points; - typedef std::map, std::set > Edges_map; - typedef cpp11::array Edge; - typedef std::vector Polygons; - typedef std::set Edges; - typedef typename Polygons::size_type size_type; +/// Index types + typedef typename std::iterator_traits< + typename Polygon_3::iterator >::value_type V_ID; + typedef typename std::vector::size_type P_ID; +// typedef int CC_ID; + typedef std::pair V_ID_pair; +/// Container types + typedef std::vector Points; + typedef std::vector Polygons; + typedef std::map > Edge_map; + typedef typename Edge_map::iterator Edge_map_iterator; + typedef std::set Marked_edges; - const Points& points; - Polygons& polygons; +/// Data members + Points& points; //< the set of input points + Polygons& polygons; //< the set of input polygons + Edge_map edges; //< the set of edges of the input polygons + Marked_edges marked_edges; //< the set of singular edges or edges incident + //< to non-compatible orientation polygons - Edges_map edges; - Edges non_manifold_edges; + /// for each polygon referenced by its position in `polygons`, indicates + /// the connected component it belongs too after orientation. +// std::vector< CC_ID > polygon_cc_id; + /// for each vertex, indicates the list of polygon containing it + std::vector< std::vector > incident_polygons_per_vertex; -private: - Edge canonical_edge(Index i, Index j) +/// Utility functions + V_ID_pair canonical_edge(V_ID i, V_ID j) { - return i 2 ) - { - non_manifold_edges.insert(canonical_edge(i0,i1)); - } - } - } + cpp11::array + get_neighbor_vertices(V_ID v_id, P_ID polygon_index) + { + std::size_t nbv = polygons[polygon_index].size(), pvid=0; + for (; pvid!=nbv; ++pvid) + if (v_id==polygons[polygon_index][pvid]) break; + CGAL_assertion( pvid!=nbv ); + V_ID prev = polygons[polygon_index][ (pvid+nbv-1)%nbv ]; + V_ID next = polygons[polygon_index][ (pvid+1)%nbv ]; + return make_array(prev,v_id,next); + } + + std::pair + next_cw_vertex_around_source(V_ID src, V_ID tgt) + { + typedef std::pair VID_and_PID; + if ( is_edge_marked(src,tgt) ) return VID_and_PID(src,300612); + Edge_map_iterator em_it=edges.find(V_ID_pair(tgt, src)); + if ( em_it==edges.end() ) return VID_and_PID(src,300612);// the vertex is on the border + CGAL_assertion(em_it->second.size()==1); + P_ID p_id = *(em_it->second.begin()); + return VID_and_PID(get_neighbor_vertices(src, p_id)[2], p_id); + } + + std::pair + next_ccw_vertex_around_target(V_ID src, V_ID tgt) + { + typedef std::pair VID_and_PID; + if ( is_edge_marked(src,tgt) ) return VID_and_PID(tgt,300612); + Edge_map_iterator em_it=edges.find(V_ID_pair(tgt, src)); + if ( em_it==edges.end() ) return VID_and_PID(tgt,300612);// the vertex is on the border + CGAL_assertion(em_it->second.size()==1); + P_ID p_id = *(em_it->second.begin()); + return VID_and_PID(get_neighbor_vertices(tgt, p_id)[0], p_id); } void inverse_orientation(const std::size_t index) { std::reverse(polygons[index].begin(), polygons[index].end()); } -public: - - Polygon_soup_orienter(const Points& points, Polygons& polygons) - : points(points), polygons(polygons) + void replace_vertex_index_in_polygon( + std::size_t polygon_id, + V_ID old_index, + V_ID new_index) { - fill_edges(); + BOOST_FOREACH(V_ID& i, polygons[polygon_id]) + if( i==old_index ) + i=new_index; } - bool orient() +/// Functions filling containers + void fill_edge_map() { + // Fill edges + edges.clear(); + for(P_ID i = 0; i < polygons.size(); ++i) + { + const P_ID size = polygons[i].size(); + for(P_ID j = 0; j < size; ++j) { + V_ID i0 = polygons[i][j]; + V_ID i1 = polygons[i][ (j+1)%size]; + edges[V_ID_pair(i0, i1)].insert(i); + } + } + + // Fill non-manifold edges + marked_edges.clear(); + for(P_ID i = 0; i < polygons.size(); ++i) + { + const P_ID size = polygons[i].size(); + for(P_ID j = 0; j < size; ++j) { + V_ID i0 = polygons[i][j]; + V_ID i1 = polygons[i][ (j+1)%size ]; + + std::size_t nb_edges = 0; + Edge_map_iterator em_it = edges.find( V_ID_pair(i0, i1) ); + if ( em_it!=edges.end() ) nb_edges += em_it->second.size(); + em_it = edges.find( V_ID_pair(i1, i0) ); + if ( em_it!=edges.end() ) nb_edges += em_it->second.size(); + + if( nb_edges > 2 ) set_edge_marked(i0,i1); + } + } + } + + void fill_incident_polygons_per_vertex() + { + incident_polygons_per_vertex.resize(points.size()); + + P_ID nb_polygons=polygons.size(); + for(P_ID ip=0; ip oriented; std::stack stack; - using std::make_pair; +// polygon_cc_id.resize(polygons.size(), -1); - // no polygon is oriented + // We first consider all polygons as non-oriented oriented.resize(polygons.size()); - size_type polygon_index = 0; - bool success = true; + P_ID polygon_index = 0; - while (polygon_index != polygons.size()) +// CC_ID current_cc_index=-1; + while (polygon_index != polygons.size()) { + // We look for the first polygon not already oriented while ( polygon_index != polygons.size() && oriented[polygon_index] ) { ++polygon_index; } if(polygon_index == polygons.size()) break; +// ++ current_cc_index; // visit a new connected component + + // we visit the connected component by crossing edges manifold edges oriented[polygon_index] = true; stack.push(polygon_index); while(! stack.empty() ) { - const size_type to_be_oriented_index = stack.top(); + const P_ID to_be_oriented_index = stack.top(); stack.pop(); - const size_type size = polygons[to_be_oriented_index].size(); - for(size_type ih = 0 ; ih < size ; ++ih) { - size_type ihp1 = ih+1; - if(ihp1>=size) ihp1 = 0; - const Index& i1 = polygons[to_be_oriented_index][ih]; - const Index& i2 = polygons[to_be_oriented_index][ihp1]; - if(non_manifold_edges.count(canonical_edge(i1,i2)) > 0) { - continue; - } +// CGAL_assertion(polygon_cc_id[to_be_oriented_index]==-1); +// polygon_cc_id[to_be_oriented_index]=current_cc_index; + + const P_ID size = polygons[to_be_oriented_index].size(); + for(P_ID ih = 0 ; ih < size ; ++ih) { + P_ID ihp1 = (ih+1)%size; + const V_ID i1 = polygons[to_be_oriented_index][ih]; + const V_ID i2 = polygons[to_be_oriented_index][ihp1]; + + if( is_edge_marked(i1,i2) ) continue; // edge (i1,i2) - typename Edges_map::iterator it_same_orient = edges.find(make_pair(i1, i2)); + Edge_map_iterator it_same_orient = edges.find(V_ID_pair(i1, i2)); // edges (i2,i1) - typename Edges_map::iterator it_other_orient = edges.find(make_pair(i2, i1)); + Edge_map_iterator it_other_orient = edges.find(V_ID_pair(i2, i1)); CGAL_assertion(it_same_orient != edges.end()); - if(it_same_orient->second.size() > 1) { - if((it_other_orient != edges.end() && it_other_orient->second.size() > 0) || - it_same_orient->second.size() > 2) { - // three polygons at the edge - success = false; // non-orientable - } - { - // one neighbor polyhedron, opposite orientation - size_type index = *(it_same_orient->second.begin()); - if(index == to_be_oriented_index) - index = *(++it_same_orient->second.begin()); - if(oriented[index]) { - // "neighbor polygon #%1 is already oriented, but in opposite orientation").arg(index); - success = false; // non-orientable - continue; // next edge - } + CGAL_assertion(it_other_orient == edges.end() || + it_other_orient->second.size()==1); - // reverse the orientation - const size_type size = polygons[index].size(); - for(size_type j = 0; j < size; ++j) { - const Index& i0 = polygons[index][j]; - const Index& i1 = polygons[index][ j+1 < size ? j+1: 0]; - CGAL_assertion_code(const bool r = ) - edges[std::make_pair(i0, i1)].erase(index) - CGAL_assertion_code(!= 0); - CGAL_assertion(r); - } - inverse_orientation(index); - for(size_type j = 0; j < size; ++j) { - const Index& i0 = polygons[index][j]; - const Index& i1 = polygons[index][ j+1 < size ? j+1: 0]; - edges[std::make_pair(i0, i1)].insert(index); - } - // "inverse the orientation of polygon #%1\n").arg(index); + if (it_same_orient->second.size() > 1) + { + CGAL_assertion(it_other_orient == edges.end()); + // one neighbor but with the same orientation + P_ID index = *(it_same_orient->second.begin()); + if(index == to_be_oriented_index) + index = *(++it_same_orient->second.begin()); + if(oriented[index]) + { + // polygon already oriented but its orientation is not compatible ---> mark the edge and continue + set_edge_marked(i1,i2); + continue; // next edge + } + + // reverse the orientation + const P_ID size = polygons[index].size(); + for(P_ID j = 0; j < size; ++j) { + V_ID i0 = polygons[index][j]; + V_ID i1 = polygons[index][(j+1)%size]; + Edge_map_iterator em_it = edges.find(V_ID_pair(i0, i1)); + CGAL_assertion_code(const bool r = ) + em_it->second.erase(index) + CGAL_assertion_code(!= 0); + CGAL_assertion(r); + if ( em_it->second.empty() ) edges.erase(em_it); + } + inverse_orientation(index); + for(P_ID j = 0; j < size; ++j) { + V_ID i0 = polygons[index][j]; + V_ID i1 = polygons[index][(j+1)%size]; + edges[V_ID_pair(i0, i1)].insert(index); + } + // "inverse the orientation of polygon #index + oriented[index] = true; + stack.push(index); + } + else{ + if( it_other_orient != edges.end() ){ + CGAL_assertion(it_same_orient->second.size() == 1); + CGAL_assertion(it_other_orient->second.size() == 1); + // one polygon, same orientation + const P_ID index = *(it_other_orient->second.begin()); + if(oriented[index]) continue; //nothing todo already processed and correctly oriented oriented[index] = true; + // "keep the orientation of polygon #index stack.push(index); } } - else if(it_other_orient != edges.end() && it_other_orient->second.size() == 1) { - // one polygon, same orientation - const size_type index = *(it_other_orient->second.begin()); - if(oriented[index]) - continue; - oriented[index] = true; - // "keep the orientation of polygon #%1\n").arg(index); - stack.push(index); - } - else { - if(it_same_orient->second.size() != 1 || - (it_other_orient != edges.end() && it_other_orient->second.size() > 0)) - { - success = false; // non-orientable - } - } - } // end for on all edges of one + } // end for on all edges of one } // end while loop on the polygons of the connected component - } // end while loop on all non-oriented polygons remaining + } // end while loop on all non-oriented polygons remaining + } - return success; + /// A vertex is said to be singular if its link is neither a cycle nor a chain, + /// but several cycles and chains. + /// For each such vertex v, we consider each set of polygons incident to v + /// and sharing a non-marked edge incident to v. A copy of v is assigned to + /// each but one set of incident polygons. + void duplicate_singular_vertices() + { + fill_incident_polygons_per_vertex(); + std::vector< std::pair > > vertices_to_duplicate; + + V_ID nbv = static_cast( points.size() ); + for (V_ID v_id = 0; v_id < nbv; ++v_id) + { + const std::vector< P_ID >& incident_polygons = incident_polygons_per_vertex[v_id]; + + if ( incident_polygons.empty() ) continue; //isolated vertex + std::set visited_polygons; + + bool first_pass = true; + BOOST_FOREACH(P_ID p_id, incident_polygons) + { + if ( !visited_polygons.insert(p_id).second ) continue; // already visited + + if (!first_pass) + { + vertices_to_duplicate.push_back(std::pair >()); + vertices_to_duplicate.back().first=v_id; + } + + const cpp11::array& neighbors = get_neighbor_vertices(v_id,p_id); + + V_ID next = neighbors[2]; + + if( !first_pass) + vertices_to_duplicate.back().second.push_back(p_id); + + do{ + P_ID other_p_id; + cpp11::tie(next, other_p_id) = next_cw_vertex_around_source(v_id, next); + if (next==v_id) break; + visited_polygons.insert(other_p_id); + if( !first_pass) + vertices_to_duplicate.back().second.push_back(other_p_id); + } + while(next!=neighbors[0]); + + if (next==v_id){ + /// turn the otherway round + next = neighbors[0]; + do{ + P_ID other_p_id; + cpp11::tie(next, other_p_id) = next_ccw_vertex_around_target(next, v_id); + if (next==v_id) break; + visited_polygons.insert(other_p_id); + if( !first_pass) + vertices_to_duplicate.back().second.push_back(other_p_id); + } + while(true); + } + first_pass=false; + } + } + + /// now duplicate the vertices + typedef std::pair > V_ID_and_Polygon_ids; + BOOST_FOREACH(const V_ID_and_Polygon_ids& vid_and_pids, vertices_to_duplicate) + { + V_ID new_index = static_cast(points.size()); + points.push_back( points[vid_and_pids.first] ); + BOOST_FOREACH(P_ID polygon_id, vid_and_pids.second) + replace_vertex_index_in_polygon(polygon_id, vid_and_pids.first, new_index); + } } }; } // namespace internal -/** - * Tries to consistently orient a soup of polygons in 3D space. - * If a consistent orientation has been found, `true` is returned. - * In any case `polygons` is updated. +/** + * Tries to consistently orient a soup of polygons in 3D space. + * If it is not possible to produce a combinatorial manifold surface, some points will be + * duplicated. These points are either an endpoint of edges incident to more than + * two polygons, or an endpoint of an edge between two polygons with incompatible orientations + * (during the re-orientation process), or a point shared by at least two polygons that do not + * share an edge this point is incident to. * @tparam Point_3 the point type + * @tparam Polygon_3 the Polygon type, being a container of indices * - * @param points points of the soup of polygons. - * @param[in, out] polygons each element in the vector describes a polygon using the index of the points in the vector. + * @param[in,out] points points of the soup of polygons. Some points might be pushed back to resolve + * non-manifold or non-orientability issues. + * @param[in, out] polygons each element in the vector describes a polygon using the index of the points in `points`. * - * @return true if a consistent orientation has been found + * @return return false if some points where duplicated, thus producing a self-intersecting polyhedron * - * \TODO code: there is no check for duplicate points, yet it can be implemented as separate filter function - */ + */ template -bool orient_polygon_soup(const std::vector& points, +bool orient_polygon_soup(std::vector& points, std::vector< Polygon_3 >& polygons) { + std::size_t inital_nb_pts = points.size(); internal::Polygon_soup_orienter orienter(points, polygons); - return orienter.orient(); + orienter.orient(); + orienter.duplicate_singular_vertices(); + + return inital_nb_pts==points.size(); } }// namespace CGAL diff --git a/Operations_on_polyhedra/test/Operations_on_polyhedra/data_polygon_soup/bad_cube.off b/Operations_on_polyhedra/test/Operations_on_polyhedra/data_polygon_soup/bad_cube.off new file mode 100644 index 00000000000..95d9b19531b --- /dev/null +++ b/Operations_on_polyhedra/test/Operations_on_polyhedra/data_polygon_soup/bad_cube.off @@ -0,0 +1,23 @@ +OFF +8 13 0 +-1 -1 -1 +-1 1 -1 +1 1 -1 +1 -1 -1 +-1 -1 1 +-1 1 1 +1 1 1 +1 -1 1 +3 0 1 3 +3 3 1 2 +3 0 4 1 +3 1 4 5 +3 3 2 7 +3 7 2 6 +3 4 0 3 +3 7 4 3 +3 6 4 7 +3 6 5 4 +3 1 5 6 +3 2 1 6 +3 0 1 2 diff --git a/Operations_on_polyhedra/test/Operations_on_polyhedra/data_polygon_soup/incompatible_orientation.off b/Operations_on_polyhedra/test/Operations_on_polyhedra/data_polygon_soup/incompatible_orientation.off new file mode 100644 index 00000000000..16733a214e1 --- /dev/null +++ b/Operations_on_polyhedra/test/Operations_on_polyhedra/data_polygon_soup/incompatible_orientation.off @@ -0,0 +1,27 @@ +OFF +14 9 0 + +0 0 0 +1 0 0 +1 1 0 +0 1 0 +2 1 0 +0 2 0 +1 2 0 +2 2 0 +0 0 0.5 +0.8 0 0.5 +1 1 1 +2 1 1 +2 2 1 +1 2 1 + +4 0 1 2 3 +4 2 4 7 6 +4 3 2 6 5 +4 2 4 11 10 +4 6 7 12 13 +4 10 11 12 13 +4 0 1 9 8 +3 13 10 8 +3 8 9 13 diff --git a/Operations_on_polyhedra/test/Operations_on_polyhedra/data_polygon_soup/isolated_singular_vertex_one_cc.off b/Operations_on_polyhedra/test/Operations_on_polyhedra/data_polygon_soup/isolated_singular_vertex_one_cc.off new file mode 100644 index 00000000000..ab29e5ba53e --- /dev/null +++ b/Operations_on_polyhedra/test/Operations_on_polyhedra/data_polygon_soup/isolated_singular_vertex_one_cc.off @@ -0,0 +1,30 @@ +OFF +9 12 0 + +0 0 0 +1 0 0 +0 1 0 +1 1 0 +0.5 0.5 0 +0 0 1 +1 0 1 +1 1 1 +0 1 1 + +3 1 3 4 +3 0 1 4 +3 4 3 2 +3 0 4 2 + +3 5 6 4 +3 6 7 4 +3 4 7 8 +3 5 4 8 + +4 0 1 6 5 +4 0 2 8 5 + +4 3 2 8 7 +4 1 3 7 6 + + diff --git a/Operations_on_polyhedra/test/Operations_on_polyhedra/data_polygon_soup/isolated_vertices.off b/Operations_on_polyhedra/test/Operations_on_polyhedra/data_polygon_soup/isolated_vertices.off new file mode 100644 index 00000000000..f9b2ca98807 --- /dev/null +++ b/Operations_on_polyhedra/test/Operations_on_polyhedra/data_polygon_soup/isolated_vertices.off @@ -0,0 +1,9 @@ +OFF +5 2 0 +0 0 0 +0 1 0 +1 0 0 +0 0 1 +0 1 1 +3 0 1 2 +3 0 3 4 diff --git a/Operations_on_polyhedra/test/Operations_on_polyhedra/data_polygon_soup/nm_vertex_and_edge.off b/Operations_on_polyhedra/test/Operations_on_polyhedra/data_polygon_soup/nm_vertex_and_edge.off new file mode 100644 index 00000000000..8edd5c86886 --- /dev/null +++ b/Operations_on_polyhedra/test/Operations_on_polyhedra/data_polygon_soup/nm_vertex_and_edge.off @@ -0,0 +1,24 @@ +OFF +9 13 0 +0 1 0 +1 0 0 +1 2 0 +0.5 1 1 +0 1 2 +1 0 2 +1 2 2 +1.5 1 0 +1.5 1 0.5 +3 0 1 2 +3 0 1 3 +3 1 2 3 +3 0 2 3 +3 3 5 4 +3 3 5 6 +3 3 6 4 +3 4 6 5 +3 1 2 5 +3 1 2 7 +3 1 2 8 +3 2 5 8 +3 1 8 5 diff --git a/Operations_on_polyhedra/test/Operations_on_polyhedra/data_polygon_soup/one_duplicated_edge.off b/Operations_on_polyhedra/test/Operations_on_polyhedra/data_polygon_soup/one_duplicated_edge.off new file mode 100644 index 00000000000..4e392ac96e6 --- /dev/null +++ b/Operations_on_polyhedra/test/Operations_on_polyhedra/data_polygon_soup/one_duplicated_edge.off @@ -0,0 +1,12 @@ +OFF +6 4 0 +0 0 0 +0 1 0 +1 0.5 0 +0 0.5 1 +0 0.5 -1 +-1 0.5 0 +3 0 1 2 +3 0 1 3 +3 0 1 4 +3 0 1 5 diff --git a/Operations_on_polyhedra/test/Operations_on_polyhedra/data_polygon_soup/one_duplicated_edge_sharing_vertex.off b/Operations_on_polyhedra/test/Operations_on_polyhedra/data_polygon_soup/one_duplicated_edge_sharing_vertex.off new file mode 100644 index 00000000000..cc9930a335f --- /dev/null +++ b/Operations_on_polyhedra/test/Operations_on_polyhedra/data_polygon_soup/one_duplicated_edge_sharing_vertex.off @@ -0,0 +1,18 @@ +OFF +10 6 0 +0 0 0 +0 1 0 +1 0.5 0 +0 0.5 1 +0 0.5 -1 +-1 0.5 0 +-1 -1 0 +1 -1 0 +-1 -1 1 +1 -1 1 +3 0 1 2 +3 0 1 3 +3 0 1 4 +3 0 1 5 +3 0 6 7 +3 0 8 9 \ No newline at end of file diff --git a/Operations_on_polyhedra/test/Operations_on_polyhedra/data_polygon_soup/partial_overlap.off b/Operations_on_polyhedra/test/Operations_on_polyhedra/data_polygon_soup/partial_overlap.off new file mode 100644 index 00000000000..6b21dc7c94e --- /dev/null +++ b/Operations_on_polyhedra/test/Operations_on_polyhedra/data_polygon_soup/partial_overlap.off @@ -0,0 +1,30 @@ +OFF +16 8 0 + +0 0 0 +1 0 0 +2 0 0 +0 1 0 +1 1 0 +2 1 0 +0 2 0 +1 2 0 +2 2 0 + +1 1 -1 +2 1 -1 +3 1 -1 +3 1 0 +1 1 1 +2 1 1 +3 1 1 + +4 0 1 4 3 +4 1 2 5 4 +4 4 5 8 7 +4 3 4 7 6 + +4 9 10 5 4 +4 10 11 12 5 +4 5 12 15 14 +4 4 5 14 13 diff --git a/Operations_on_polyhedra/test/Operations_on_polyhedra/test_orient_polygon_soup.cpp b/Operations_on_polyhedra/test/Operations_on_polyhedra/test_orient_polygon_soup.cpp new file mode 100644 index 00000000000..c5ce5e0f31b --- /dev/null +++ b/Operations_on_polyhedra/test/Operations_on_polyhedra/test_orient_polygon_soup.cpp @@ -0,0 +1,54 @@ +#include +#include + +#include +#include +#include + +#include +#include +#include + +typedef CGAL::Simple_cartesian K; +typedef CGAL::Polyhedron_3 Polyhedron; + +void test(std::string fname, std::size_t expected_duplicated_vertices) +{ + std::vector points; + std::vector< std::vector > polygons; + std::ifstream input(fname.c_str()); + if (!input) + { + std::cerr << "Cannot open file " << fname << "\n"; + exit(EXIT_FAILURE); + } + + if (!CGAL::read_OFF(input, points, polygons)) + { + std::cerr << "Error parsing the OFF file " << fname << "\n"; + exit(EXIT_FAILURE); + } + + std::size_t initial_nb_points = points.size(); + CGAL::orient_polygon_soup(points, polygons); + + assert(expected_duplicated_vertices == points.size()-initial_nb_points); + + Polyhedron P; + CGAL::polygon_soup_to_polyhedron_3(P, points, polygons); + assert(P.is_valid()); + std::cout << fname << " OK\n"; +} + + +int main() +{ + test("data_polygon_soup/bad_cube.off", 4); + test("data_polygon_soup/isolated_singular_vertex_one_cc.off", 1); + test("data_polygon_soup/isolated_vertices.off", 1); + test("data_polygon_soup/nm_vertex_and_edge.off", 6); + test("data_polygon_soup/one_duplicated_edge.off", 6); + test("data_polygon_soup/one_duplicated_edge_sharing_vertex.off", 8); + test("data_polygon_soup/partial_overlap.off", 4); + test("data_polygon_soup/incompatible_orientation.off", 2); +} \ No newline at end of file diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_orient_soup_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_orient_soup_plugin.cpp index 82a9fb7ff5a..7ce9e84c45a 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_orient_soup_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_orient_soup_plugin.cpp @@ -88,28 +88,27 @@ void Polyhedron_demo_orient_soup_plugin::orient() // qDebug() << tr("I have the item %1\n").arg(item->name()); QApplication::setOverrideCursor(Qt::WaitCursor); if(!item->orient()) { - messages->warning(tr("The polygon soup \"%1\" is not orientable.") - .arg(item->name())); - // QMessageBox::information(mw, tr("Not orientable"), - // tr("The polygon soup \"%1\" is not orientable.") - // .arg(item->name())); - scene->itemChanged(item); - } else { - - Scene_polyhedron_item* poly_item = new Scene_polyhedron_item(); - if(item->exportAsPolyhedron(poly_item->polyhedron())) { - poly_item->setName(item->name()); - poly_item->setColor(item->color()); - poly_item->setRenderingMode(item->renderingMode()); - poly_item->setVisible(item->visible()); - poly_item->changed(); - poly_item->setProperty("source filename", item->property("source filename")); - scene->replaceItem(index, poly_item); - delete item; - } else { - scene->itemChanged(item); - } + QMessageBox::information(mw, tr("Not orientable without self-intersections"), + tr("The polygon soup \"%1\" is not directly orientable." + " Some vertices have been duplicated and some self-intersections" + " have been created.") + .arg(item->name())); } + + Scene_polyhedron_item* poly_item = new Scene_polyhedron_item(); + if(item->exportAsPolyhedron(poly_item->polyhedron())) { + poly_item->setName(item->name()); + poly_item->setColor(item->color()); + poly_item->setRenderingMode(item->renderingMode()); + poly_item->setVisible(item->visible()); + poly_item->changed(); + poly_item->setProperty("source filename", item->property("source filename")); + scene->replaceItem(index, poly_item); + delete item; + } else { + scene->itemChanged(item); + } + QApplication::restoreOverrideCursor(); } else{ diff --git a/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.cpp b/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.cpp index 63f8b5eae69..7ff448012c6 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_polygon_soup_item.cpp @@ -155,11 +155,10 @@ void Scene_polygon_soup_item::inside_out() bool Scene_polygon_soup_item::orient() { - if(isEmpty() || this->oriented) + if(isEmpty() || oriented) return true; // nothing to do - - oriented = CGAL::orient_polygon_soup(soup->points, soup->polygons); - return oriented; + oriented=true; + return CGAL::orient_polygon_soup(soup->points, soup->polygons); } From f048bd9c50431cefcc1e0822c74d9504acee0165 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Thu, 29 Jan 2015 14:40:45 +0100 Subject: [PATCH 26/32] fix figure with ref; add () to a function --- .../doc/Triangulation_3/CGAL/Triangulation_3.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Triangulation_3/doc/Triangulation_3/CGAL/Triangulation_3.h b/Triangulation_3/doc/Triangulation_3/CGAL/Triangulation_3.h index 0dc036ec797..ae373fb619b 100644 --- a/Triangulation_3/doc/Triangulation_3/CGAL/Triangulation_3.h +++ b/Triangulation_3/doc/Triangulation_3/CGAL/Triangulation_3.h @@ -544,7 +544,7 @@ Cell_handle & c) const; /// @} /*! \name -There is a method `has_vertex` in the cell class. The analogous methods for facets are defined here. +There is a method `has_vertex()` in the cell class. The analogous methods for facets are defined here. */ /// @{ /*! @@ -784,7 +784,7 @@ Locate_type & lt, int & li) const; Two kinds of flips exist for a three-dimensional triangulation. They are reciprocal. To be flipped, an edge must be incident to three tetrahedra. During the flip, these three tetrahedra disappear and two -tetrahedra appear. Figure \ref Triangulation3figflips (left) shows the +tetrahedra appear. \cgalFigureRef{Triangulation3figflips} (left) shows the edge that is flipped as bold dashed, and one of its three incident facets is shaded. On the right, the facet shared by the two new tetrahedra is shaded. Flips are possible only under the following @@ -792,9 +792,9 @@ conditions: - the edge or facet to be flipped is not on the boundary of the convex hull of the triangulation - the five points involved are in convex position. -\anchor Triangulation3figflips -\image html flips.png "Flips" -\image latex flips.png "Flips" +\cgalFigureBegin{Triangulation3figflips, flips.png} +Flips +\cgalFigureEnd The following methods guarantee the validity of the resulting 3D triangulation. Flips for a 2d triangulation are not implemented yet. @@ -1224,7 +1224,7 @@ Try to lock and copy the `Cell_handle`s of all cells incident to `v` into `cells`. Returns `true` in case of success. Otherwise, `cells` is emptied and the function returns false. In any case, the locked cells are not unlocked by -`try_lock_and_get_incident_cells`, leaving this choice to the user. +`try_lock_and_get_incident_cells()`, leaving this choice to the user. \pre `t.dimension() == 3`, `v != Vertex_handle()`, `t.is_vertex(v)`. */ From 062ce726be6e04aa6981324bd14679aeb420a12e Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Thu, 29 Jan 2015 14:49:12 +0100 Subject: [PATCH 27/32] it is operator -- and not - --- .../doc/Triangulation_3/CGAL/Triangulation_3.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Triangulation_3/doc/Triangulation_3/CGAL/Triangulation_3.h b/Triangulation_3/doc/Triangulation_3/CGAL/Triangulation_3.h index ae373fb619b..7440b2900c6 100644 --- a/Triangulation_3/doc/Triangulation_3/CGAL/Triangulation_3.h +++ b/Triangulation_3/doc/Triangulation_3/CGAL/Triangulation_3.h @@ -1027,7 +1027,7 @@ The following iterators allow the user to visit cells, facets, edges and vertice /// @{ /*! -Starts at an arbitrary finite vertex. Then `++` and `-` will +Starts at an arbitrary finite vertex. Then `++` and `--` will iterate over finite vertices. Returns `finite_vertices_end()` when `t.number_of_vertices() == 0`. */ @@ -1039,7 +1039,7 @@ Past-the-end iterator Finite_vertices_iterator finite_vertices_end() const; /*! -Starts at an arbitrary finite edge. Then `++` and `-` will +Starts at an arbitrary finite edge. Then `++` and `--` will iterate over finite edges. Returns `finite_edges_end()` when `t.dimension() < 1`. */ @@ -1051,7 +1051,7 @@ Past-the-end iterator Finite_edges_iterator finite_edges_end() const; /*! -Starts at an arbitrary finite facet. Then `++` and `-` will +Starts at an arbitrary finite facet. Then `++` and `--` will iterate over finite facets. Returns `finite_facets_end()` when `t.dimension() < 2`. */ @@ -1063,7 +1063,7 @@ Past-the-end iterator Finite_facets_iterator finite_facets_end() const; /*! -Starts at an arbitrary finite cell. Then `++` and `-` will +Starts at an arbitrary finite cell. Then `++` and `--` will iterate over finite cells. Returns `finite_cells_end()` when `t.dimension() < 3`. */ From 835dadcfdd91ee23a799a97c235ccb780ba0ee2b Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Fri, 30 Jan 2015 11:18:02 +0100 Subject: [PATCH 28/32] updated crontab (automated commit) --- Maintenance/infrastructure/cgal.geometryfactory.com/crontab | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Maintenance/infrastructure/cgal.geometryfactory.com/crontab b/Maintenance/infrastructure/cgal.geometryfactory.com/crontab index 258d97f9b44..346c3050c63 100644 --- a/Maintenance/infrastructure/cgal.geometryfactory.com/crontab +++ b/Maintenance/infrastructure/cgal.geometryfactory.com/crontab @@ -22,11 +22,11 @@ LC_CTYPE=en_US.UTF-8 0 21 * * Sun cd $HOME/CGAL/create_internal_release && $HOME/bin/create_release $HOME/CGAL/branches/master.git --public --do-it #0 21 * * Mon,Tue,Wed,Thu,Fri,Sun cd $HOME/CGAL/create_internal_release && $HOME/bin/create_release $HOME/CGAL/branches/master.git --public --do-it # "integration" -0 21 * * Mon,Wed,Thu,Fri cd $HOME/CGAL/create_internal_release && $HOME/bin/create_release $HOME/CGAL/branches/integration.git $HOME/CGAL/branches/empty-dir --do-it +0 21 * * Mon,Tue,Wed,Thu,Fri cd $HOME/CGAL/create_internal_release && $HOME/bin/create_release $HOME/CGAL/branches/integration.git $HOME/CGAL/branches/empty-dir --do-it # "integration-4.5" -0 21 * * Tue cd $HOME/CGAL/create_internal_release-4.5-branch && $HOME/bin/create_release $HOME/CGAL/branches/integration-4.5.git $HOME/CGAL/branches/empty-dir --do-it --public +0 21 * * Sat cd $HOME/CGAL/create_internal_release-4.5-branch && $HOME/bin/create_release $HOME/CGAL/branches/integration-4.5.git $HOME/CGAL/branches/empty-dir --do-it --public # from branch 4.5 -0 21 * * Sat cd $HOME/CGAL/create_internal_release-4.5-branch && $HOME/bin/create_release $HOME/CGAL/branches/CGAL-4.5-branch.git --public --do-it +#0 21 * * Sat cd $HOME/CGAL/create_internal_release-4.5-branch && $HOME/bin/create_release $HOME/CGAL/branches/CGAL-4.5-branch.git --public --do-it # from branch 4.4 #0 21 * * Sun cd $HOME/CGAL/create_internal_release-4.4-branch && $HOME/bin/create_release $HOME/CGAL/branches/CGAL-4.4-branch.git --public --do-it From c9efa943d2e9ee6510d2a2f12f70dbca85857524 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 2 Feb 2015 17:05:53 +0100 Subject: [PATCH 29/32] move file to Polygon_mesh_processing --- .../CGAL/intersection_of_Polyhedra_3_refinement_visitor.h | 2 +- .../include/CGAL/Polygon_mesh_processing/Connected_components.h | 0 .../Polyhedron_demo_join_and_split_polyhedra_plugin.cpp | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename Operations_on_polyhedra/include/CGAL/internal/corefinement/Polyhedron_subset_extraction.h => Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/Connected_components.h (100%) diff --git a/Operations_on_polyhedra/include/CGAL/intersection_of_Polyhedra_3_refinement_visitor.h b/Operations_on_polyhedra/include/CGAL/intersection_of_Polyhedra_3_refinement_visitor.h index 9332d6d6dcc..7d049f6a7b8 100644 --- a/Operations_on_polyhedra/include/CGAL/intersection_of_Polyhedra_3_refinement_visitor.h +++ b/Operations_on_polyhedra/include/CGAL/intersection_of_Polyhedra_3_refinement_visitor.h @@ -22,7 +22,7 @@ #define CGAL_INTERSECTION_OF_POLYHEDRA_3_REFINEMENT_VISITOR_H #include -#include +#include #include #include #include diff --git a/Operations_on_polyhedra/include/CGAL/internal/corefinement/Polyhedron_subset_extraction.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/Connected_components.h similarity index 100% rename from Operations_on_polyhedra/include/CGAL/internal/corefinement/Polyhedron_subset_extraction.h rename to Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/Connected_components.h diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_join_and_split_polyhedra_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_join_and_split_polyhedra_plugin.cpp index 68fb6316288..d168a3276bf 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_join_and_split_polyhedra_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_join_and_split_polyhedra_plugin.cpp @@ -11,7 +11,7 @@ #include "Polyhedron_demo_plugin_interface.h" #include -#include +#include #include #include From 35cbfea432fec7210a6ab8767cf4048646ad019f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 2 Feb 2015 17:09:32 +0100 Subject: [PATCH 30/32] =?UTF-8?q?copy=20code=20added=20in=20branch=20Polyh?= =?UTF-8?q?edra=5Fcorefinement-enhancements-sloriot=20=20=20|=20=20=20|com?= =?UTF-8?q?mit=20fea785072d7a0a257752eba75704133a19ab8aa1=20=20=20|Author:?= =?UTF-8?q?=20S=C3=A9bastien=20Loriot=20=20=20?= =?UTF-8?q?=20|Date:=20=20=20Wed=20Mar=2026=2010:48:25=202014=20+0100=20?= =?UTF-8?q?=20=20|=20=20=20|=20=20=20=20add=20an=20alternative=20way=20to?= =?UTF-8?q?=20compute=20the=20patches=20bounded=20by=20marked=20edges=20?= =?UTF-8?q?=20=20|?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Connected_components.h | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/Connected_components.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/Connected_components.h index 7d4922730de..e6bc7c841d9 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/Connected_components.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/Connected_components.h @@ -251,6 +251,78 @@ void extract_connected_components(const Polyhedron& P,Output_iterator out) extract_connected_components(P,Dummy_true(),out); } +template +std::size_t +init_facet_indices( + const Polyhedron& P, + Polyhedron_facet_index_map facet_index_map) +{ + //init facet indices + std::size_t index=0; + for (typename Polyhedron::Facet_const_iterator fit=P.facets_begin(), + fit_end=P.facets_end(); + fit!=fit_end; ++fit) + { + put(facet_index_map, fit, index++); + } + return index; +} + +// alternative method by propagation +template +std::size_t +mark_connected_components_v2( + const Polyhedron& P, + const Adjacency_criterium& adjacent, + Polyhedron_facet_index_map facet_index_map, + std::vector& patch_ids, + std::vector& patch_sizes) +{ + typedef typename Polyhedron::Halfedge_const_handle Halfedge_handle; + + std::size_t max_id=(std::numeric_limits::max)(); + patch_ids.clear(); + patch_ids.resize(P.size_of_facets(), max_id); + + //traversal of the facets to discover connected components + std::size_t patch_id=0; + for (typename Polyhedron::Facet_const_iterator fit=P.facets_begin(), + fit_end=P.facets_end(); + fit!=fit_end; ++fit) + { + std::size_t index=get(facet_index_map, fit); + if ( patch_ids[index]==max_id ) + { + patch_sizes.push_back(0); + patch_ids[index]=patch_id;// set patch id + ++(patch_sizes.back()); + std::vector queue; + if ( adjacent(fit->halfedge()) ) + queue.push_back( fit->halfedge()->opposite() ); + if ( adjacent(fit->halfedge()->next()) ) + queue.push_back( fit->halfedge()->next()->opposite() ); + if ( adjacent(fit->halfedge()->next()->next()) ) + queue.push_back( fit->halfedge()->next()->next()->opposite() ); + while (!queue.empty()) + { + Halfedge_handle h=queue.back(); + queue.pop_back(); + index=get(facet_index_map, h->facet()); + if ( patch_ids[index]!=max_id ) continue; + patch_ids[index]=patch_id; + ++(patch_sizes.back()); + if ( adjacent(h->next()) ) + queue.push_back( h->next()->opposite() ); + if ( adjacent(h->next()->next()) ) + queue.push_back( h->next()->next()->opposite() ); + } + ++patch_id; + } + } + + return patch_id; +} + } } //namespace CGAL::internal #endif //CGAL_INTERNAL_POLYHEDRON_SUBSET_EXTRACTION_H From a686d2ae2da172e92ae51f501d7b19db33bf1bd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 2 Feb 2015 19:38:38 +0100 Subject: [PATCH 31/32] change namespace --- .../CGAL/intersection_of_Polyhedra_3_refinement_visitor.h | 6 +++--- .../CGAL/Polygon_mesh_processing/Connected_components.h | 3 ++- .../Polyhedron_demo_join_and_split_polyhedra_plugin.cpp | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Operations_on_polyhedra/include/CGAL/intersection_of_Polyhedra_3_refinement_visitor.h b/Operations_on_polyhedra/include/CGAL/intersection_of_Polyhedra_3_refinement_visitor.h index 7d049f6a7b8..edb111e4741 100644 --- a/Operations_on_polyhedra/include/CGAL/intersection_of_Polyhedra_3_refinement_visitor.h +++ b/Operations_on_polyhedra/include/CGAL/intersection_of_Polyhedra_3_refinement_visitor.h @@ -1894,8 +1894,8 @@ public: typedef typename Polyhedron::Facet_const_handle Facet_const_handle; typedef ::CGAL::Union_find UF; typedef typename UF::handle UF_handle; - typedef std::map,internal::Compare_handle_ptr > Result; - typedef std::map > Facet_to_handle_map; + typedef std::map,internal::corefinement::Compare_handle_ptr > Result; + typedef std::map > Facet_to_handle_map; UF uf; Facet_to_handle_map map_f2h; @@ -1910,7 +1910,7 @@ public: output_debug << *current_poly; #endif - extract_connected_components(*(static_cast (current_poly) ),criterium,uf,map_f2h,result); + internal::corefinement::extract_connected_components(*(static_cast (current_poly) ),criterium,uf,map_f2h,result); //add each connected component in the map with 2 volumes per component. diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/Connected_components.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/Connected_components.h index e6bc7c841d9..c680dfe22dd 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/Connected_components.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/Connected_components.h @@ -29,6 +29,7 @@ namespace CGAL { namespace internal{ + namespace corefinement{ template struct Compare_handle_ptr{ @@ -323,6 +324,6 @@ mark_connected_components_v2( return patch_id; } -} } //namespace CGAL::internal +} } } //namespace CGAL::internal::corefinement #endif //CGAL_INTERNAL_POLYHEDRON_SUBSET_EXTRACTION_H diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_join_and_split_polyhedra_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_join_and_split_polyhedra_plugin.cpp index d168a3276bf..316e97ef7f4 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_join_and_split_polyhedra_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_join_and_split_polyhedra_plugin.cpp @@ -104,7 +104,7 @@ void Polyhedron_demo_join_and_split_polyhedra_plugin::on_actionSplitPolyhedra_tr if(item) { std::list new_polyhedra; - CGAL::internal::extract_connected_components( + CGAL::internal::corefinement::extract_connected_components( *item->polyhedron(), boost::make_function_output_iterator(Polyhedron_appender(new_polyhedra)) ); From a3a48134f1c7bf704a2d52e087648a2d1d05db04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Tue, 3 Feb 2015 09:02:00 +0100 Subject: [PATCH 32/32] add package overview --- Polygon_mesh_processing/package_info/Hole_filling/copyright | 1 + Polygon_mesh_processing/package_info/Hole_filling/license.txt | 1 + Polygon_mesh_processing/package_info/Hole_filling/maintainer | 1 + 3 files changed, 3 insertions(+) create mode 100644 Polygon_mesh_processing/package_info/Hole_filling/copyright create mode 100644 Polygon_mesh_processing/package_info/Hole_filling/license.txt create mode 100644 Polygon_mesh_processing/package_info/Hole_filling/maintainer diff --git a/Polygon_mesh_processing/package_info/Hole_filling/copyright b/Polygon_mesh_processing/package_info/Hole_filling/copyright new file mode 100644 index 00000000000..d76cdbe60d6 --- /dev/null +++ b/Polygon_mesh_processing/package_info/Hole_filling/copyright @@ -0,0 +1 @@ +GeometryFactory (France) \ No newline at end of file diff --git a/Polygon_mesh_processing/package_info/Hole_filling/license.txt b/Polygon_mesh_processing/package_info/Hole_filling/license.txt new file mode 100644 index 00000000000..0d3d7e59728 --- /dev/null +++ b/Polygon_mesh_processing/package_info/Hole_filling/license.txt @@ -0,0 +1 @@ +GPL (v3 or later) diff --git a/Polygon_mesh_processing/package_info/Hole_filling/maintainer b/Polygon_mesh_processing/package_info/Hole_filling/maintainer new file mode 100644 index 00000000000..4f45ddcd216 --- /dev/null +++ b/Polygon_mesh_processing/package_info/Hole_filling/maintainer @@ -0,0 +1 @@ +Andreas Fabri