diff --git a/Polygon_mesh_processing/benchmark/Polygon_mesh_processing/CMakeLists.txt b/Polygon_mesh_processing/benchmark/Polygon_mesh_processing/CMakeLists.txt index ee478c44946..dd04cdd3318 100644 --- a/Polygon_mesh_processing/benchmark/Polygon_mesh_processing/CMakeLists.txt +++ b/Polygon_mesh_processing/benchmark/Polygon_mesh_processing/CMakeLists.txt @@ -57,6 +57,6 @@ include_directories( BEFORE ../../include ) include( CGAL_CreateSingleSourceCGALProgram ) -create_single_source_cgal_program( "polygon_mesh_slicer_test.cpp" ) +create_single_source_cgal_program( "polygon_mesh_slicer.cpp" ) diff --git a/Polygon_mesh_processing/benchmark/Polygon_mesh_processing/polygon_mesh_slicer.cpp b/Polygon_mesh_processing/benchmark/Polygon_mesh_processing/polygon_mesh_slicer.cpp index 60e37de0a07..88cfd93b77c 100644 --- a/Polygon_mesh_processing/benchmark/Polygon_mesh_processing/polygon_mesh_slicer.cpp +++ b/Polygon_mesh_processing/benchmark/Polygon_mesh_processing/polygon_mesh_slicer.cpp @@ -97,7 +97,7 @@ int main(int argc, char* argv[]) { std::ifstream input(argv[1]); Mesh m; - int N = 10; + int N = 100; if (!input || !(input >> m)){ std::cerr << "Error: can not read file.\n"; return 1; @@ -116,6 +116,7 @@ int main(int argc, char* argv[]) CGAL::Polygon_mesh_slicer_3 slicer(m); + std::ofstream out("out.off"); int polycount = 0; int vertex_count = 0; for(int i=0; i < N; i++){ @@ -125,11 +126,11 @@ int main(int argc, char* argv[]) polycount += polylines.size(); BOOST_FOREACH(Polyline pl, polylines){ vertex_count += pl.size(); - std::cout << pl.size(); + out << pl.size(); BOOST_FOREACH(Point_3 p, pl){ - std::cout << " " << p; + out << " " << p; } - std::cout << std::endl; + out << std::endl; } t.start(); diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/compute_normal.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/compute_normal.h index bbc07cc5402..41894fb97a6 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/compute_normal.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/compute_normal.h @@ -28,10 +28,23 @@ namespace CGAL{ namespace Polygon_mesh_processing{ +#ifndef DOXYGEN_RUNNING +template +typename Kernel_traits::type>::value_type>::Kernel::Vector_3 +compute_facet_normal( + typename boost::graph_traits::face_descriptor f, + const PolygonMesh& pmesh) +{ + typedef typename Kernel_traits::type>::value_type>::Kernel Kernel; + return compute_facet_normal(f, pmesh, Kernel()); +} +#endif + + // %CGAL `Kernel` with `FT` a model of `FieldWithSqrt`. This /** * \ingroup PkgPolygonMeshProcessing * computes the outward unit vector normal to facet `f`. -* @tparam Kernel a %CGAL `Kernel` with `FT` a model of `FieldWithSqrt` +* @tparam Kernel Geometric traits class. It can be omitted and deduced automatically from the point type of `PolygonMesh`. * @tparam PolygonMesh a model of `FaceGraph` * * @param f the facet on which the normal is computed @@ -41,13 +54,14 @@ template typename Kernel::Vector_3 compute_facet_normal( typename boost::graph_traits::face_descriptor f, - const PolygonMesh& pmesh) + const PolygonMesh& pmesh, + const Kernel& ) { typedef typename Kernel::Point_3 Point; typedef typename Kernel::Vector_3 Vector; - typename boost::property_map::const_type - ppmap = get(boost::vertex_point, pmesh); + typename boost::property_map::const_type + ppmap = get(CGAL::vertex_point, pmesh); Vector normal = CGAL::NULL_VECTOR; typedef typename boost::graph_traits::halfedge_descriptor halfedge_descriptor; @@ -67,6 +81,19 @@ compute_facet_normal( return normal / std::sqrt(normal * normal); } + +#ifndef DOXYGEN_RUNNING +template +typename Kernel_traits::type>::value_type>::Kernel::Vector_3 +compute_vertex_normal( + typename boost::graph_traits::vertex_descriptor v, + const PolygonMesh& pmesh) +{ + typedef typename Kernel_traits::type>::value_type>::Kernel Kernel; + return compute_vertex_normal(v, pmesh, Kernel()); +} +#endif + /** * \ingroup PkgPolygonMeshProcessing * computes the unit normal at vertex `v` as the average of the normals of incident facets. @@ -80,7 +107,8 @@ template typename Kernel::Vector_3 compute_vertex_normal( typename boost::graph_traits::vertex_descriptor v, - const PolygonMesh& pmesh) + const PolygonMesh& pmesh, + const Kernel& k) { typedef typename Kernel::Vector_3 Vector; typedef typename boost::graph_traits::halfedge_descriptor halfedge_descriptor; @@ -92,7 +120,7 @@ compute_vertex_normal( { if (!is_border(he, pmesh)) { - Vector n = compute_facet_normal(face(he, pmesh), pmesh); + Vector n = compute_facet_normal(face(he, pmesh), pmesh, k); normal = normal + (n / std::sqrt(n*n)); } he = opposite(next(he, pmesh), pmesh); diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/is_oriented.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/is_oriented.h index 959c93c844b..2efeef2338d 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/is_oriented.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/is_oriented.h @@ -52,7 +52,16 @@ namespace internal{ }; } // end of namespace internal - +#ifndef DOXYGEN_RUNNING +template +bool +is_outward_oriented( + const PolygonMesh& pmesh) +{ + typedef typename Kernel_traits::type>::value_type>::Kernel Kernel; + return is_outward_oriented(pmesh, Kernel()); +} +#endif /** * \ingroup PkgPolygonMeshProcessing * Tests whether a closed surface polygon mesh has a positive orientation. @@ -76,10 +85,9 @@ namespace internal{ * } * @endcode */ -template< class PolygonMesh > -bool is_outward_oriented(const PolygonMesh& pmesh) + template + bool is_outward_oriented(const PolygonMesh& pmesh, const Kernel&k) { - typedef typename CGAL::Kernel_traits::Kernel Kernel; CGAL_warning(CGAL::is_closed(pmesh)); CGAL_precondition(CGAL::is_valid(pmesh)); @@ -94,7 +102,7 @@ bool is_outward_oriented(const PolygonMesh& pmesh) = std::min_element(vbegin, vend, less_xyz); const typename Kernel::Vector_3& - normal_v_min = compute_vertex_normal(*v_min, pmesh); + normal_v_min = compute_vertex_normal(*v_min, pmesh, k); return normal_v_min[0] < 0 || ( normal_v_min[0] == 0 && ( diff --git a/Polygon_mesh_processing/test/Polygon_mesh_processing/orient_polygon_mesh_test.cpp b/Polygon_mesh_processing/test/Polygon_mesh_processing/orient_polygon_mesh_test.cpp index a006709eea2..ac391901efb 100644 --- a/Polygon_mesh_processing/test/Polygon_mesh_processing/orient_polygon_mesh_test.cpp +++ b/Polygon_mesh_processing/test/Polygon_mesh_processing/orient_polygon_mesh_test.cpp @@ -1,6 +1,8 @@ #include #include +#include #include +#include #include #include