diff --git a/Surface_mesh_segmentation/include/CGAL/internal/Surface_mesh_segmentation/Alpha_expansion_graph_cut.h b/Surface_mesh_segmentation/include/CGAL/internal/Surface_mesh_segmentation/Alpha_expansion_graph_cut.h index 5802251cc3b..4a5ebcb0852 100644 --- a/Surface_mesh_segmentation/include/CGAL/internal/Surface_mesh_segmentation/Alpha_expansion_graph_cut.h +++ b/Surface_mesh_segmentation/include/CGAL/internal/Surface_mesh_segmentation/Alpha_expansion_graph_cut.h @@ -23,7 +23,7 @@ #include -#define CGAL_USE_BOYKOV_KOLMOGOROV_MAXFLOW_SOFTWARE +//#define CGAL_USE_BOYKOV_KOLMOGOROV_MAXFLOW_SOFTWARE #ifdef CGAL_USE_BOYKOV_KOLMOGOROV_MAXFLOW_SOFTWARE #include @@ -109,7 +109,7 @@ private: * @param v2 second vertex * @param w1 weight for edge from v1 to v2 (v1->v2) * @param w2 weight for edge from v2 to v1 (v2->v1) - * @graph to be added + * @param graph to be added * @return pair of added edges, first: v1->v2 and second: v2->v1 */ boost::tuple @@ -141,6 +141,7 @@ public: * @param probability_matrix contains responsibility of the center on the vertex probability[center][vertex] * @param[in, out] labels as input it contains initial labeling of vertices (i.e. a center-id between [0, number of centers -1]), * and as output it returns final labeling of vertices + * @return result of energy function */ double operator()(const std::vector >& edges, const std::vector& edge_weights, @@ -273,7 +274,7 @@ private: * @param v2 second vertex * @param w1 weight for edge from v1 to v2 (v1->v2) * @param w2 weight for edge from v2 to v1 (v2->v1) - * @graph to be added + * @param graph to be added * @return pair of added edges, first: v1->v2 and second: v2->v1 */ boost::tuple @@ -305,6 +306,7 @@ public: * @param probability_matrix contains responsibility of the center on the vertex probability[center][vertex] * @param[in, out] labels as input it contains initial labeling of vertices (i.e. a center-id between [0, number of centers -1]), * and as output it returns final labeling of vertices + * @return result of energy function */ double operator()(const std::vector >& edges, const std::vector& edge_weights, @@ -404,6 +406,7 @@ public: * @param probability_matrix contains responsibility of the center on the vertex probability[center][vertex] * @param[in, out] labels as input it contains initial labeling of vertices (i.e. a center-id between [0, number of centers -1]), * and as output it returns final labeling of vertices + * @return result of energy function */ double operator()(const std::vector >& edges, const std::vector& edge_weights, diff --git a/Surface_mesh_segmentation/include/CGAL/internal/Surface_mesh_segmentation/Disk_samplers.h b/Surface_mesh_segmentation/include/CGAL/internal/Surface_mesh_segmentation/Disk_samplers.h index 12a4e23de14..3cdeb530f79 100644 --- a/Surface_mesh_segmentation/include/CGAL/internal/Surface_mesh_segmentation/Disk_samplers.h +++ b/Surface_mesh_segmentation/include/CGAL/internal/Surface_mesh_segmentation/Disk_samplers.h @@ -42,6 +42,7 @@ namespace internal * @brief Uses Vogel's method to sample points from unit-disk. * * @tparam Tuple should have a constructor which takes 3 double parameters. + * @tparam uniform indicates how sampling occurs (uniform or biased to center) * @see Disk_samplers.h, SDF_calculation */ template @@ -53,10 +54,9 @@ public: * @param number_of_points number of points to be picked * @param cone_angle opening angle of cone (might be necessary for weighting) * @param[out] out_it sampled points from disk, each point is tuple of: - * - first = coordinate-x - * - second = coordinate-y - * - third = weight (proportional to angle between cone-normal) - * @param uniform if false custom power will be used and sampled points will be biased to center + * - coordinate-x + * - coordinate-y + * - weight (proportional to angle between cone-normal) */ template void operator()(int number_of_points, @@ -127,12 +127,11 @@ public: * @param number_of_points number of points to be picked * @param cone_angle opening angle of cone (might be necessary for weighting) * @param[out] out_it sampled points from disk, each point is tuple of: - * - first = coordinate-x - * - second = coordinate-y - * - third = weight (proportional to angle between cone-normal) + * - coordinate-x + * - coordinate-y + * - weight (proportional to angle between cone-normal) * - * Note: - * Returned samples size = \f$ \lfloor \sqrt {number\_of\_points} \rfloor ^ 2 \f$ + * Note: returned samples size = \f$ \lfloor \sqrt {number\_of\_points} \rfloor ^ 2 \f$ */ template void operator()(int number_of_points, @@ -194,12 +193,11 @@ public: * @param number_of_points number of points to be picked * @param cone_angle opening angle of cone (might be necessary for weighting) * @param[out] out_it sampled points from disk, each point is tuple of: - * - first = coordinate-x - * - second = coordinate-y - * - third = weight (proportional to angle between cone-normal) + * - coordinate-x + * - coordinate-y + * - weight (proportional to angle between cone-normal) * - * Note: - * Returned samples size = \f$ \lfloor \sqrt {number\_of\_points} \rfloor ^ 2 \f$ + * Note: returned samples size = \f$ \lfloor \sqrt {number\_of\_points} \rfloor ^ 2 \f$ */ template void operator()(int number_of_points, diff --git a/Surface_mesh_segmentation/include/CGAL/internal/Surface_mesh_segmentation/Filters.h b/Surface_mesh_segmentation/include/CGAL/internal/Surface_mesh_segmentation/Filters.h index 3b9c62f1298..d18d9be0294 100644 --- a/Surface_mesh_segmentation/include/CGAL/internal/Surface_mesh_segmentation/Filters.h +++ b/Surface_mesh_segmentation/include/CGAL/internal/Surface_mesh_segmentation/Filters.h @@ -5,7 +5,7 @@ * @file Filters.h * @brief This file contains 2 filtering methods, which can be used as a template parameter for CGAL::internal::Surface_mesh_segmentation. * - * Also filtering methods can be used by their-own for smoothing associated values to `CGAL Polyhedron`. + * Also filtering methods can be used by their-own for smoothing associated values with `CGAL Polyhedron` facets. */ #include #include diff --git a/Surface_mesh_segmentation/include/CGAL/internal/Surface_mesh_segmentation/K_means_clustering.h b/Surface_mesh_segmentation/include/CGAL/internal/Surface_mesh_segmentation/K_means_clustering.h index f2787e5b7df..7294e6ef4e2 100644 --- a/Surface_mesh_segmentation/include/CGAL/internal/Surface_mesh_segmentation/K_means_clustering.h +++ b/Surface_mesh_segmentation/include/CGAL/internal/Surface_mesh_segmentation/K_means_clustering.h @@ -142,8 +142,7 @@ public: data_centers.reserve(points.size()); for(std::vector::iterator point_it = points.begin(); point_it != points.end(); ++point_it) { - point_it->calculate_new_center( - centers); // just refind closest center (incase order of centers are changed etc) + point_it->calculate_new_center(centers); // find closest center data_centers.push_back(point_it->center_id); } } @@ -274,18 +273,16 @@ private: min_centers = centers; } } - // By saving points (min_points) also, we can get rid of this part - // But since centers are already converged this step will require one iteration - // If it stopped since maximum_iteration is reached then this step will take some time + // Note that current center-ids in points are not valid. + // But they are recalculated when asked (in fill_with_center_ids()) centers = min_centers; - calculate_clustering(); } /** * Sum of squared distances between each point and the closest center to it. */ double within_cluster_sum_of_squares() const { - double sum = 0; + double sum = 0.0; for(std::vector::const_iterator point_it = points.begin(); point_it != points.end(); ++point_it) { sum += std::pow(centers[point_it->center_id].mean - point_it->data, 2); diff --git a/Surface_mesh_segmentation/include/CGAL/internal/Surface_mesh_segmentation/SDF_calculation.h b/Surface_mesh_segmentation/include/CGAL/internal/Surface_mesh_segmentation/SDF_calculation.h index 584da326ca9..9e7bb8e652c 100644 --- a/Surface_mesh_segmentation/include/CGAL/internal/Surface_mesh_segmentation/SDF_calculation.h +++ b/Surface_mesh_segmentation/include/CGAL/internal/Surface_mesh_segmentation/SDF_calculation.h @@ -22,24 +22,26 @@ namespace internal /** * @brief Responsible for calculating Shape Diameter Function over surface of the mesh. - * @see Disk_samplers.h + * + * @tparam Polyhedron a CGAL polyhedron + * @tparam GeomTraits a model of SegmentationGeomTraits + * @tparam DiskSampling chosen sampling method from Disk_samplers.h */ template < class Polyhedron, - class SegmentationGeomTraits, + class GeomTraits, class DiskSampling = Vogel_disk_sampling > > class SDF_calculation { //type definitions private: - typedef SegmentationGeomTraits SGT; - typedef typename SGT::Vector_3 Vector; - typedef typename SGT::Point_3 Point; - typedef typename SGT::Ray_3 Ray; - typedef typename SGT::Plane_3 Plane; - typedef typename SGT::Segment_3 Segment; + typedef typename GeomTraits::Vector_3 Vector; + typedef typename GeomTraits::Point_3 Point; + typedef typename GeomTraits::Ray_3 Ray; + typedef typename GeomTraits::Plane_3 Plane; + typedef typename GeomTraits::Segment_3 Segment; typedef typename Polyhedron::Traits Kernel; typedef typename Polyhedron::Facet Facet; @@ -49,8 +51,9 @@ private: typedef typename Polyhedron::Facet_const_handle Facet_const_handle; - typedef AABB_const_polyhedron_triangle_primitive Primitive; - typedef typename CGAL::AABB_tree > Tree; + typedef AABB_const_polyhedron_triangle_primitive + Primitive; + typedef typename CGAL::AABB_tree > Tree; typedef typename Tree::Object_and_primitive_id Object_and_primitive_id; typedef typename Tree::Primitive_id @@ -69,20 +72,20 @@ private: bool use_minimum_segment; double multiplier_for_segment; - SGT traits; + GeomTraits traits; - typename SGT::Angle_3 angle_functor; - typename SGT::Construct_scaled_vector_3 scale_functor; - typename SGT::Construct_sum_of_vectors_3 sum_functor; - typename SGT::Construct_normal_3 normal_functor; - typename SGT::Construct_unit_normal_3 unit_normal_functor; - typename SGT::Construct_translated_point_3 translated_point_functor; - typename SGT::Construct_centroid_3 centroid_functor; + typename GeomTraits::Angle_3 angle_functor; + typename GeomTraits::Construct_scaled_vector_3 scale_functor; + typename GeomTraits::Construct_sum_of_vectors_3 sum_functor; + typename GeomTraits::Construct_normal_3 normal_functor; + typename GeomTraits::Construct_unit_normal_3 unit_normal_functor; + typename GeomTraits::Construct_translated_point_3 translated_point_functor; + typename GeomTraits::Construct_centroid_3 centroid_functor; public: /** * Assign default values to member variables. */ - SDF_calculation(SGT traits) + SDF_calculation(GeomTraits traits) : traits(traits), use_minimum_segment(false), multiplier_for_segment(1), angle_functor(traits.angle_3_object()), scale_functor(traits.construct_scaled_vector_3_object()), @@ -95,7 +98,6 @@ public: /** * Calculates SDF values for each facet, and stores them in @a sdf_values. Note that sdf values are neither smoothed nor normalized. - * @pre parameter @a mesh should consist of triangles. * @param mesh `CGAL Polyhedron` on which SDF values are computed * @param cone_angle opening angle for cone, expressed in radians * @param number_of_rays number of rays picked from cone for each facet @@ -134,7 +136,6 @@ private: */ double calculate_sdf_value_of_facet(Facet_const_handle& facet, const Tree& tree, const Disk_samples_list& samples) const { - //ofstream output("rays.txt", ios::app); const Point& p1 = facet->halfedge()->vertex()->point(); const Point& p2 = facet->halfedge()->next()->vertex()->point(); const Point& p3 = facet->halfedge()->prev()->vertex()->point(); @@ -171,9 +172,7 @@ private: Vector disk_vector = sum_functor(scale_functor(v1, sample_it->get<0>()), scale_functor(v2, sample_it->get<1>())); Vector ray_direction = sum_functor(normal, disk_vector); - //output << center << std::endl; - //std::cout << center << std::endl; - //output << ray_direction << std::endl; + #ifdef SHOOT_ONLY_RAYS Ray ray(center, ray_direction); boost::tie(is_intersected, intersection_is_acute, @@ -215,6 +214,7 @@ private: continue; } + if(use_minimum_segment) { if(min_distance < *segment_distance) { // update segment_distance (minimum / maximum) 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 2a0cffc7eab..c9c09853c34 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 @@ -30,17 +30,22 @@ namespace internal * It is a connector class which uses: * - SDF_calculation for calculating sdf values * - Expectation_maximization for soft clustering - * - An implementation of alpha-expansion graph cut for hard clustering (Alpha_expansion_graph_cut.h) + * - An implementation of alpha-expansion graph cut for hard clustering * * Other than being a connector, it is also responsable for preprocess and postprocess on intermadiate data, which are: * - log-normalizing probabilities received from soft clustering * - log-normalizing and calculating dihedral-angle based weights for edges * - smoothing and log-normalizing sdf values received from sdf calculation (Filters.h) * - assigning segment-id for each facet after hard clustering + * + * @tparam Polyhedron a CGAL polyhedron + * @tparam GeomTraits a model of SegmentationGeomTraits + * @tparam GraphCut chosen graph-cut implementation from Alpha_expansion_graph_cut.h + * @tparam Filter chosen filtering method from Filters.h */ template < class Polyhedron, - class SegmentationGeomTraits, + class GeomTraits, #ifdef CGAL_USE_BOYKOV_KOLMOGOROV_MAXFLOW_SOFTWARE class GraphCut = Alpha_expansion_graph_cut_boykov_kolmogorov, #else @@ -56,7 +61,7 @@ public: private: //typedef typename Polyhedron::Traits Kernel; - typedef typename SegmentationGeomTraits::Point_3 Point; + typedef typename GeomTraits::Point_3 Point; typedef typename Polyhedron::Facet Facet; @@ -66,20 +71,19 @@ private: typedef typename Polyhedron::Facet_const_iterator Facet_const_iterator; typedef typename Polyhedron::Vertex_const_iterator Vertex_const_iterator; - typedef SDF_calculation - SDF_calculation_class; + typedef SDF_calculation SDF_calculation_class; // member variables private: const Polyhedron& mesh; - SegmentationGeomTraits traits; + GeomTraits traits; // member functions public: /** * @pre @a polyhedron.is_pure_triangle() * @param mesh `CGAL Polyhedron` on which other functions operate. */ - Surface_mesh_segmentation(const Polyhedron& mesh, SegmentationGeomTraits traits) + Surface_mesh_segmentation(const Polyhedron& mesh, GeomTraits traits) : mesh(mesh), traits(traits) { CGAL_precondition(mesh.is_pure_triangle()); }