From d92d0cef84db3092f43defb93eb04292cec71d49 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 10 Jun 2014 15:26:06 +0200 Subject: [PATCH] Use CGAL points even for OpenMesh --- .../boost/graph/graph_traits_HalfedgeDS.h | 1 + .../graph/properties_PolyMesh_ArrayKernelT.h | 28 +++++++------ ...ation_from_sdf_values_OpenMesh_example.cpp | 12 +++--- .../include/CGAL/mesh_segmentation.h | 10 ++--- .../edge_collapse_OpenMesh.cpp | 41 ++----------------- 5 files changed, 32 insertions(+), 60 deletions(-) diff --git a/BGL/include/CGAL/boost/graph/graph_traits_HalfedgeDS.h b/BGL/include/CGAL/boost/graph/graph_traits_HalfedgeDS.h index 03e5d4b11e4..b2129b53cac 100644 --- a/BGL/include/CGAL/boost/graph/graph_traits_HalfedgeDS.h +++ b/BGL/include/CGAL/boost/graph/graph_traits_HalfedgeDS.h @@ -187,6 +187,7 @@ public: typedef vertices_size_type faces_size_type; static vertex_descriptor null_vertex() { return vertex_descriptor(); } + static halfedge_descriptor null_halfedge() { return halfedge_descriptor(); } static face_descriptor null_face() { return face_descriptor(); } }; diff --git a/BGL/include/CGAL/boost/graph/properties_PolyMesh_ArrayKernelT.h b/BGL/include/CGAL/boost/graph/properties_PolyMesh_ArrayKernelT.h index bdf3b1be413..8e6fa4b3258 100644 --- a/BGL/include/CGAL/boost/graph/properties_PolyMesh_ArrayKernelT.h +++ b/BGL/include/CGAL/boost/graph/properties_PolyMesh_ArrayKernelT.h @@ -99,17 +99,17 @@ public: }; -template + template class OM_point_pmap //: public boost::put_get_helper > { public: typedef boost::read_write_property_map_tag category; -#if !defined(CGAL_BGL_TESTSUITE) +#if defined(CGAL_USE_OM_POINTS) typedef typename OpenMesh::PolyMesh_ArrayKernelT::Point value_type; typedef typename const OpenMesh::PolyMesh_ArrayKernelT::Point& reference; #else - typedef typename CGAL::Exact_predicates_inexact_constructions_kernel::Point_3 value_type; - typedef typename CGAL::Exact_predicates_inexact_constructions_kernel::Point_3 reference; + typedef P value_type; + typedef P reference; #endif typedef typename boost::graph_traits< OpenMesh::PolyMesh_ArrayKernelT >::vertex_descriptor key_type; @@ -125,9 +125,9 @@ public: : sm_(pm.sm_) {} - inline friend reference get(const OM_point_pmap& pm, key_type v) + inline friend reference get(const OM_point_pmap& pm, key_type v) { -#if !defined(CGAL_BGL_TESTSUITE) +#if defined(CGAL_USE_OM_POINTS) return pm.sm->.point(v); #else typename OpenMesh::PolyMesh_ArrayKernelT::Point const& omp = pm.sm_->point(v); @@ -135,12 +135,12 @@ public: #endif } - inline friend void put(const OM_point_pmap& pm, key_type v, const value_type& p) + inline friend void put(const OM_point_pmap& pm, key_type v, const value_type& p) { -#if !defined(CGAL_BGL_TESTSUITE) - const_cast&>(*pm.sm_)->set_point(v,p); +#if defined(CGAL_USE_OM_POINTS) + const_cast&>(*pm.sm_).set_point(v,p); #else - const_cast&>(*pm.sm_)->set_point + const_cast&>(*pm.sm_).set_point (v, typename OpenMesh::PolyMesh_ArrayKernelT::Point(p[0], p[1], p[2])); #endif } @@ -218,7 +218,8 @@ struct property_map, boost::halfedge_index_t template struct property_map, boost::vertex_point_t > { - typedef CGAL::OM_point_pmap type; + typedef CGAL::Exact_predicates_inexact_constructions_kernel::Point_3 P; + typedef CGAL::OM_point_pmap type; typedef type const_type; }; @@ -297,10 +298,11 @@ get(const boost::halfedge_index_t&, const OpenMesh::PolyMesh_ArrayKernelT&) } template -CGAL::OM_point_pmap +CGAL::OM_point_pmap get(boost::vertex_point_t, const OpenMesh::PolyMesh_ArrayKernelT& g) { - return CGAL::OM_point_pmap(g); + typedef typename CGAL::Exact_predicates_inexact_constructions_kernel::Point_3 P; + return CGAL::OM_point_pmap(g); } diff --git a/Surface_mesh_segmentation/examples/Surface_mesh_segmentation/segmentation_from_sdf_values_OpenMesh_example.cpp b/Surface_mesh_segmentation/examples/Surface_mesh_segmentation/segmentation_from_sdf_values_OpenMesh_example.cpp index 9477513d18a..2834a008a20 100644 --- a/Surface_mesh_segmentation/examples/Surface_mesh_segmentation/segmentation_from_sdf_values_OpenMesh_example.cpp +++ b/Surface_mesh_segmentation/examples/Surface_mesh_segmentation/segmentation_from_sdf_values_OpenMesh_example.cpp @@ -33,8 +33,11 @@ int main( int argc, char** argv ) Facet_double_map internal_sdf_map; boost::associative_property_map sdf_property_map(internal_sdf_map); - // compute SDF values using default parameters for number of rays, and cone angle - CGAL::sdf_values(mesh, sdf_property_map, 2.0 / 3.0 * CGAL_PI, 25,true, Kernel()); + + // compute SDF values + // We can't use default parameters for number of rays, and cone angle + // and the postprocessing + CGAL::sdf_values(mesh, sdf_property_map); // create a property-map for segment-ids typedef std::map Facet_int_map; @@ -43,7 +46,7 @@ int main( int argc, char** argv ) // segment the mesh using default parameters for number of levels, and smoothing lambda // Any other scalar values can be used instead of using SDF values computed using the CGAL function - std::size_t number_of_segments = CGAL::segmentation_from_sdf_values(mesh, sdf_property_map, segment_property_map, 5, 0.26, false, Kernel()); + std::size_t number_of_segments = CGAL::segmentation_from_sdf_values(mesh, sdf_property_map, segment_property_map); std::cout << "Number of segments: " << number_of_segments << std::endl; // print segment-ids @@ -60,6 +63,5 @@ int main( int argc, char** argv ) // Note that we can use the same SDF values (sdf_property_map) over and over again for segmentation. // This feature is relevant for segmenting the mesh several times with different parameters. - //CGAL::segmentation_from_sdf_values( - // mesh, sdf_property_map, segment_property_map, number_of_clusters, smoothing_lambda); + CGAL::segmentation_from_sdf_values(mesh, sdf_property_map, segment_property_map, number_of_clusters, smoothing_lambda); } diff --git a/Surface_mesh_segmentation/include/CGAL/mesh_segmentation.h b/Surface_mesh_segmentation/include/CGAL/mesh_segmentation.h index 0d4800e0d78..6a86ca52944 100644 --- a/Surface_mesh_segmentation/include/CGAL/mesh_segmentation.h +++ b/Surface_mesh_segmentation/include/CGAL/mesh_segmentation.h @@ -31,7 +31,7 @@ namespace CGAL template ::value_type>::Kernel #endif , class PointPropertyMap #ifndef CGAL_CFG_NO_CPP0X_DEFAULT_TEMPLATE_ARGUMENTS_FOR_FUNCTION_TEMPLATES @@ -82,7 +82,7 @@ sdf_values( const Polyhedron& polyhedron, */ template ::value_type>::Kernel #endif , class PointPropertyMap #ifndef CGAL_CFG_NO_CPP0X_DEFAULT_TEMPLATE_ARGUMENTS_FOR_FUNCTION_TEMPLATES @@ -177,7 +177,7 @@ sdf_values_postprocessing(const Polyhedron& polyhedron, template ::value_type>::Kernel #endif , class PointPropertyMap #ifndef CGAL_CFG_NO_CPP0X_DEFAULT_TEMPLATE_ARGUMENTS_FOR_FUNCTION_TEMPLATES @@ -204,7 +204,7 @@ segmentation_from_sdf_values( const Polyhedron& polyhedron, template < bool Fast_sdf_calculation_mode, class Polyhedron, class SegmentPropertyMap, class GeomTraits #ifndef CGAL_CFG_NO_CPP0X_DEFAULT_TEMPLATE_ARGUMENTS_FOR_FUNCTION_TEMPLATES - = typename Polyhedron::Traits + = typename Kernel_traits::value_type>::Kernel #endif , class PointPropertyMap #ifndef CGAL_CFG_NO_CPP0X_DEFAULT_TEMPLATE_ARGUMENTS_FOR_FUNCTION_TEMPLATES @@ -273,7 +273,7 @@ segmentation_via_sdf_values(const Polyhedron& polyhedron, */ template < class Polyhedron, class SegmentPropertyMap, class GeomTraits #ifndef CGAL_CFG_NO_CPP0X_DEFAULT_TEMPLATE_ARGUMENTS_FOR_FUNCTION_TEMPLATES -= typename Polyhedron::Traits += typename Kernel_traits::value_type>::Kernel #endif , class PointPropertyMap #ifndef CGAL_CFG_NO_CPP0X_DEFAULT_TEMPLATE_ARGUMENTS_FOR_FUNCTION_TEMPLATES diff --git a/Surface_mesh_simplification/examples/Surface_mesh_simplification/edge_collapse_OpenMesh.cpp b/Surface_mesh_simplification/examples/Surface_mesh_simplification/edge_collapse_OpenMesh.cpp index 35bc822b4d6..baee5d1022c 100644 --- a/Surface_mesh_simplification/examples/Surface_mesh_simplification/edge_collapse_OpenMesh.cpp +++ b/Surface_mesh_simplification/examples/Surface_mesh_simplification/edge_collapse_OpenMesh.cpp @@ -1,7 +1,7 @@ #include #include -#include +#include #include #include @@ -15,6 +15,8 @@ #include #include +typedef CGAL::Exact_predicates_inexact_constructions_kernel K; + typedef OpenMesh::PolyMesh_ArrayKernelT Surface_mesh; typedef boost::graph_traits::edge_descriptor edge_descriptor; @@ -51,41 +53,6 @@ private: }; -class OM_vertex_CGAL_point_pmap -{ -public: - typedef boost::read_write_property_map_tag category; - - typedef CGAL::Simple_cartesian::Point_3 value_type; - typedef CGAL::Simple_cartesian::Point_3 reference; - - typedef boost::graph_traits::vertex_descriptor key_type; - - OM_vertex_CGAL_point_pmap(const Surface_mesh& sm) - : sm_(sm) - {} - - OM_vertex_CGAL_point_pmap(const OM_vertex_CGAL_point_pmap& pm) - : sm_(pm.sm_) - {} - - inline friend reference get(const OM_vertex_CGAL_point_pmap& pm, key_type v) - { - Surface_mesh::Point const& omp = pm.sm_.point(v); - return value_type(omp[0], omp[1], omp[2]); - } - - inline friend void put(const OM_vertex_CGAL_point_pmap& pm, key_type v, const value_type& p) - { - const_cast(pm.sm_).set_point - (v, Surface_mesh::Point(p[0], p[1], p[2])); - } - - private: - const Surface_mesh& sm_; -}; - - namespace SMS = CGAL::Surface_mesh_simplification ; @@ -113,7 +80,7 @@ int main( int argc, char** argv ) (surface_mesh ,stop ,CGAL::halfedge_index_map (get(CGAL::halfedge_index ,surface_mesh)) - .vertex_point_map(OM_vertex_CGAL_point_pmap(surface_mesh)) + .vertex_point_map(get(boost::vertex_point, surface_mesh)) .edge_is_constrained_map(constraints_map) );