From 36d50d9477510f363d2cca706e2a272a2fe2871e Mon Sep 17 00:00:00 2001 From: iyaz Date: Tue, 6 Aug 2013 23:23:56 +0300 Subject: [PATCH] add another parameter to API which lets user to get either cluster or segment ids as output --- .../Surface_mesh_segmentation.h | 14 +++++--- .../include/CGAL/mesh_segmentation.h | 33 ++++++++++++------- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/Surface_mesh_segmentation/include/CGAL/internal/Surface_mesh_segmentation/Surface_mesh_segmentation.h b/Surface_mesh_segmentation/include/CGAL/internal/Surface_mesh_segmentation/Surface_mesh_segmentation.h index 9a70c47d739..4c606598589 100644 --- a/Surface_mesh_segmentation/include/CGAL/internal/Surface_mesh_segmentation/Surface_mesh_segmentation.h +++ b/Surface_mesh_segmentation/include/CGAL/internal/Surface_mesh_segmentation/Surface_mesh_segmentation.h @@ -113,7 +113,8 @@ public: template int partition(int number_of_centers, double smoothing_lambda, - SDFPropertyMap sdf_pmap, FacetSegmentMap segment_pmap) { + SDFPropertyMap sdf_pmap, FacetSegmentMap segment_pmap, + bool clusters_to_segments) { smoothing_lambda = (std::max)(0.0, smoothing_lambda); // min zero smoothing_lambda *= CGAL_SMOOTHING_LAMBDA_MULTIPLIER; // scale it into meaningful range for graph-cut @@ -147,10 +148,13 @@ public: ++facet_it, ++label_it) { segment_pmap[facet_it] = *label_it; // fill with cluster-ids } - // assign a segment id for each facet - int number_of_segments = assign_segments(number_of_centers, sdf_pmap, - segment_pmap); - return number_of_segments; + if(clusters_to_segments) { + // assign a segment id for each facet + int number_of_segments = assign_segments(number_of_centers, sdf_pmap, + segment_pmap); + return number_of_segments; + } + return number_of_centers; } /** diff --git a/Surface_mesh_segmentation/include/CGAL/mesh_segmentation.h b/Surface_mesh_segmentation/include/CGAL/mesh_segmentation.h index 9e0e24be319..037677d41fc 100644 --- a/Surface_mesh_segmentation/include/CGAL/mesh_segmentation.h +++ b/Surface_mesh_segmentation/include/CGAL/mesh_segmentation.h @@ -77,8 +77,9 @@ compute_sdf_values(const Polyhedron& polyhedron, * \ingroup PkgSurfaceSegmentation * @brief Function computing the segmentation of a surface mesh given an SDF value per facet. * - * This function fills a property map which associates a segment-id (between [0, number of segments -1]) to each facet. - * A segment is a set of connected facets which are placed under the same cluster. + * This function fills a property map which associates a segment-id (between [0, number of segments -1]) + * or a cluster-id (between [0, @a number_of_levels -1]) to each facet. + * A segment is a set of connected facets which are placed under the same cluster \cgalFigureRef{Cluster_vs_segment}. * * \note Log-normalization is applied on @a sdf_values before segmentation. * \note There is no direct relation between the parameter @a number_of_levels @@ -94,8 +95,9 @@ compute_sdf_values(const Polyhedron& polyhedron, * @param[out] segment_ids the segment id of each facet * @param number_of_levels number of clusters for soft clustering * @param smoothing_lambda factor which indicates the importance of the surface features for the energy minimization. It is recommended to choose a value in the interval [0,1]. See the section \ref Surface_mesh_segmentationGraphCut for more details. + * @param extract_segments if true fill @a segment_ids with segment-ids, otherwise fill with cluster-ids \cgalFigureRef{Cluster_vs_segment} * @param traits traits object - * @return number of segments + * @return number of segments if @a extract_segments true, @a number_of_levels otherwise */ template algorithm( polyhedron, traits); return algorithm.partition(number_of_levels, smoothing_lambda, sdf_values, - segment_ids); + segment_ids, extract_segments); } @@ -122,8 +125,8 @@ segment_from_sdf_values(const Polyhedron& polyhedron, * \ingroup PkgSurfaceSegmentation * @brief Function computing the segmentation of a surface mesh. * - * This function combines `CGAL::sdf_values_computation` and - * `CGAL::surface_mesh_segmentation_from_sdf_values` functions by computing SDF values and segmenting the mesh in one go. + * This function combines `CGAL::compute_sdf_values` and + * `CGAL::segment_from_sdf_values` functions by computing SDF values and segmenting the mesh in one go. * * \note For computing segmentations of the mesh with different parameters (i.e. number of levels, and smoothing lambda), * it is more efficient to first compute the SDF values using `CGAL::compute_sdf_values` and use them for each call to @@ -141,8 +144,9 @@ segment_from_sdf_values(const Polyhedron& polyhedron, * @param number_of_rays number of rays picked from cone for each facet. In general, increasing the number of rays has a little effect on the quality of the result * @param number_of_levels number of clusters for soft clustering * @param smoothing_lambda factor which indicates the importance of the surface features for the energy minimization. It is recommended to choose a value in the interval [0,1]. See the section \ref Surface_mesh_segmentationGraphCut for more details. + * @param extract_segments if true fill @a segment_ids with segment-ids, otherwise fill with cluster-ids \cgalFigureRef{Cluster_vs_segment} * @param traits traits object - * @return number of segments + * @return number of segments if @a extract_segments true, @a number_of_levels otherwise */ template < bool Fast_sdf_calculation_mode, class Polyhedron, class SegmentPropertyMap, class GeomTraits @@ -157,6 +161,7 @@ compute_sdf_values_and_segment(const Polyhedron& polyhedron, int number_of_rays = 25, int number_of_levels = 5, double smoothing_lambda = 0.26, + bool extract_segments = true, GeomTraits traits = GeomTraits()) { typedef std::map< typename Polyhedron::Facet_const_handle, double> @@ -169,7 +174,7 @@ compute_sdf_values_and_segment(const Polyhedron& polyhedron, (polyhedron, sdf_property_map, cone_angle, number_of_rays, traits); return segment_from_sdf_values, SegmentPropertyMap, GeomTraits> (polyhedron, sdf_property_map, segment_ids, number_of_levels, smoothing_lambda, - traits); + extract_segments, traits); } /// @cond SKIP_IN_MANUAL @@ -185,11 +190,12 @@ compute_sdf_values_and_segment(const Polyhedron& polyhedron, int number_of_rays = 25, int number_of_levels = 5, double smoothing_lambda = 0.26, + bool extract_segments = true, GeomTraits traits = GeomTraits()) { return compute_sdf_values_and_segment (polyhedron, segment_ids, cone_angle, number_of_rays, number_of_levels, - smoothing_lambda, traits); + smoothing_lambda, extract_segments, traits); } /// @endcond @@ -225,11 +231,12 @@ segment_from_sdf_values(const Polyhedron& polyhedron, SegmentPropertyMap segment_ids, int number_of_levels = 5, double smoothing_lambda = 0.26, + bool extract_segments = true, typename Polyhedron::Traits traits = typename Polyhedron::Traits()) { return segment_from_sdf_values (polyhedron, sdf_values, segment_ids, number_of_levels, smoothing_lambda, - traits); + extract_segments, traits); } template @@ -240,11 +247,12 @@ compute_sdf_values_and_segment(const Polyhedron& polyhedron, int number_of_rays = 25, int number_of_levels = 5, double smoothing_lambda = 0.26, + bool extract_segments = true, typename Polyhedron::Traits traits = typename Polyhedron::Traits()) { return compute_sdf_values_and_segment< Fast_sdf_calculation_mode, Polyhedron, SegmentPropertyMap, typename Polyhedron::Traits> (polyhedron, segment_ids, cone_angle, number_of_rays, number_of_levels, - smoothing_lambda, traits); + smoothing_lambda, extract_segments, traits); } template @@ -255,11 +263,12 @@ compute_sdf_values_and_segment(const Polyhedron& polyhedron, int number_of_rays = 25, int number_of_levels = 5, double smoothing_lambda = 0.26, + bool extract_segments = true, typename Polyhedron::Traits traits = typename Polyhedron::Traits()) { return compute_sdf_values_and_segment (polyhedron, segment_ids, cone_angle, number_of_rays, number_of_levels, - smoothing_lambda, traits); + smoothing_lambda, extract_segments, traits); }