diff --git a/Point_set_shape_detection_3/examples/Point_set_shape_detection_3/shape_detection_3_basic.cpp b/Point_set_shape_detection_3/examples/Point_set_shape_detection_3/shape_detection_3_basic.cpp index 872da048163..a67cb7d03aa 100644 --- a/Point_set_shape_detection_3/examples/Point_set_shape_detection_3/shape_detection_3_basic.cpp +++ b/Point_set_shape_detection_3/examples/Point_set_shape_detection_3/shape_detection_3_basic.cpp @@ -23,7 +23,7 @@ typedef std::vector Point_list; typedef CGAL::Identity_property_map Point_pmap; typedef CGAL::Normal_of_point_with_normal_pmap Normal_pmap; -// In Shape_detection_traits_3 the used types, i.e. Point and Vector types +// In Shape_detection_traits_3 the basic types, i.e., Point and Vector types // as well as iterator type and property maps, are defined. typedef CGAL::Shape_detection_traits_3 ShapeDetectionTraits; @@ -33,9 +33,9 @@ typedef CGAL::Shape_detection_3 Shape_detection; int main(int argc, char **argv) { Point_list points; - // Loading a point set from file. - // read_xyz_points_and_normals takes an OutputIterator for storing the points - // and a property map to store the normal vector with each point. + // Loading a point set from a file. + // read_xyz_points_and_normals takes an OutputIterator for writing the points + // and a property map for storing the normal vector associated to each point. std::ifstream stream("cube.xyz"); if (!stream || @@ -46,20 +46,20 @@ int main(int argc, char **argv) { return EXIT_FAILURE; } - // Creation of the instance and providing the input data. + // Instantiates shape detection engine and provides input data. Shape_detection sd(points.begin(), points.end(), Point_pmap(), Normal_pmap()); - // Shapes to be searched for are registered + // Shapes to be detected are registered // by using the template Shape_factory sd.add_shape_factory(new CGAL::Shape_factory >); - // The actual shape detection with default parameters. + // Detects registered shapes with default parameters. sd.detect(); - // Print results. - std::cout << sd.number_of_shapes() << " primitives" << std::endl; + // Prints number of detected shapes. + std::cout << sd.number_of_shapes() << " shapes detected." << std::endl; return EXIT_SUCCESS; } diff --git a/Point_set_shape_detection_3/examples/Point_set_shape_detection_3/shape_detection_3_parameters.cpp b/Point_set_shape_detection_3/examples/Point_set_shape_detection_3/shape_detection_3_parameters.cpp index f6089901318..2712f4a50ac 100644 --- a/Point_set_shape_detection_3/examples/Point_set_shape_detection_3/shape_detection_3_parameters.cpp +++ b/Point_set_shape_detection_3/examples/Point_set_shape_detection_3/shape_detection_3_parameters.cpp @@ -23,7 +23,7 @@ typedef std::vector Point_list; typedef CGAL::Identity_property_map Point_pmap; typedef CGAL::Normal_of_point_with_normal_pmap Normal_pmap; -// In Shape_detection_traits_3 the used types, i.e. Point and Vector types +// In Shape_detection_traits_3 the basic types, i.e., Point and Vector types // as well as iterator type and property maps, are defined. typedef CGAL::Shape_detection_traits_3 ShapeDetectionTraits; @@ -33,9 +33,9 @@ typedef CGAL::Shape_detection_3 Shape_detection; int main(int argc, char **argv) { Point_list points; - // Loading a point set from file. - // read_xyz_points_and_normals takes an OutputIterator for storing the points - // and a property map to store the normal vector with each point. + // Loads point set from a file. + // read_xyz_points_and_normals takes an OutputIterator for writing the points + // and a property map for storing the normal vector associated to each point. std::ifstream stream("cube.xyz"); if (!stream || @@ -46,12 +46,13 @@ int main(int argc, char **argv) { return EXIT_FAILURE; } - // Creation of the instance and providing the input data. + // Instantiates shape detection engine and provides input data. Shape_detection sd(points.begin(), points.end(), Point_pmap(), Normal_pmap()); - // Shapes to be searched for are registered + // Shapes to be detected are registered // by using the template Shape_factory + sd.add_shape_factory(new CGAL::Shape_factory >); @@ -67,42 +68,42 @@ int main(int argc, char **argv) { sd.add_shape_factory(new CGAL::Shape_factory >); - // Parameterization of the shape detection using the Parameters structure. - Shape_detection::Parameters op; + // Setting parameters for shape detection. + Shape_detection::Parameters parameters; // 5% probability to miss the largest primitive on each iteration. - op.probability = 0.05f; + parameters.probability = 0.05f; - // Only extract shapes with at least 500 points. - op.min_points = 500; + // Detect shapes with at least 500 points. + parameters.min_points = 500; - // 0.002 maximum euclidean distance between point and shape. - op.epsilon = 0.002f; + // 0.002 maximum Euclidean distance between a point and a shape. + parameters.epsilon = 0.002f; - // 0.01 maximum euclidean distance between points to be clustered. - op.cluster_epsilon = 0.01f; + // 0.01 maximum Euclidean distance between points to be clustered. + parameters.cluster_epsilon = 0.01f; // 0.9 < dot(surface_normal, point_normal); maximum normal deviation. - op.normal_threshold = 0.9f; + parameters.normal_threshold = 0.9f; - // The actual shape detection. - sd.detect(op); + // Detects shapes + sd.detect(parameters); - // Print results. - std::cout << sd.number_of_shapes() << " primitives, " + // Prints number of detected shapes and unassigned points. + std::cout << sd.number_of_shapes() << " detecte shapes, " << sd.number_of_unassigned_points() - << " unassigned points" << std::endl; + << " unassigned points." << std::endl; // Shape_detection_3::shapes_begin() provides // an iterator to the detected shapes. Shape_detection::Shape_iterator it = sd.shapes_begin(); while (it != sd.shapes_end()) { const Shape_detection::Shape *shape = *it; - // Using Shape_base::info() for printing + // Uses Shape_base::info() for printing // the parameters of the detected shape. std::cout << (*it)->info() << std::endl; - // Proceed with next shape. + // Proceeds with next detected shape. it++; } diff --git a/Point_set_shape_detection_3/examples/Point_set_shape_detection_3/shape_detection_3_point_access.cpp b/Point_set_shape_detection_3/examples/Point_set_shape_detection_3/shape_detection_3_point_access.cpp index aaeed32e20a..d4b0ca46144 100644 --- a/Point_set_shape_detection_3/examples/Point_set_shape_detection_3/shape_detection_3_point_access.cpp +++ b/Point_set_shape_detection_3/examples/Point_set_shape_detection_3/shape_detection_3_point_access.cpp @@ -46,8 +46,7 @@ int main(int argc, char **argv) { return EXIT_FAILURE; } - // For time measurement we take the time - // before setting up the shape detection. + // Measure time before setting up the shape detection. CGAL::Timer time; time.start(); @@ -55,18 +54,17 @@ int main(int argc, char **argv) { Shape_detection sd(points.begin(), points.end(), Point_pmap(), Normal_pmap()); - // Shapes to be searched for are registered - // by using the template Shape_factory + // Registers detection of planes sd.add_shape_factory(new CGAL::Shape_factory >); - // The actual shape detection. + // Detects shapes. sd.detect(); - // Take the time afterwards. + // Measures time after detection. time.stop(); - // Print results. + // Prints number of assigned shapes and unsassigned points. std::cout << "time: " << time.time() * 1000 << "ms" << std::endl; std::cout << sd.number_of_shapes() << " primitives, " << sd.number_of_unassigned_points() @@ -76,33 +74,37 @@ int main(int argc, char **argv) { // an iterator to the detected shapes. Shape_detection::Shape_iterator it = sd.shapes_begin(); while (it != sd.shapes_end()) { + const Shape_detection::Shape *shape = *it; // Using Shape_base::info() for printing // the parameters of the detected shape. std::cout << (*it)->info(); - // Determine mean distance of points to detected shape. - FT mean_distance = 0; - // Iterate through indices of points assigned to each shape. + // Sum distances of points to detected shapes. + FT sum_distances = 0.f; + + // Iterate through point indices assigned to each detected shape. std::vector::const_iterator indexIt = (*it)->assigned_points().begin(); while (indexIt != (*it)->assigned_points().end()) { - // Retrieve point + + // Retrieve point const Point &p = *(points.begin() + (*indexIt)); + // Add Euclidean distance between point and shape. - mean_distance += sqrt((*it)->squared_distance(p)); + sum_distances += sqrt((*it)->squared_distance(p)); // Proceed with next point. indexIt++; } - // Divide sum of distance by number of points. - mean_distance /= shape->assigned_points().size(); + // Compute average distance. + const FT average_distance = sum_distances / shape->assigned_points().size(); - std::cout << " mean error: " << mean_distance << std::endl; + std::cout << " average distance: " << average_distance << std::endl; - // Proceed with next shape. + // Proceed with next detected shape. it++; }