#include <CGAL/Point_set_3.h>
#include <CGAL/Point_set_3/IO.h>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Shape_detection/Region_growing/Region_growing.h>
#include <boost/iterator/function_output_iterator.hpp>
#include "include/utils.h"
using FT = Kernel::FT;
using Point_map = Point_set_2::Point_map;
using Normal_map = Point_set_2::Vector_map;
using Neighbor_query = CGAL::Shape_detection::Point_set::K_neighbor_query_for_point_set<Point_set_2>;
using Region_type = CGAL::Shape_detection::Point_set::Least_squares_circle_fit_region_for_point_set<Point_set_2>;
using Sorting = CGAL::Shape_detection::Point_set::Least_squares_circle_fit_sorting_for_point_set<Point_set_2, Neighbor_query>;
int main(int argc, char** argv) {
const bool is_default_input = argc > 1 ? false : true;
std::ifstream in(is_default_input ? CGAL::data_file_path("points_3/circles.ply") : argv[1]);
if (!in) {
std::cerr << "ERROR: cannot read the input file!" << std::endl;
return EXIT_FAILURE;
}
in >> point_set_3;
in.close();
std::cout << "* number of input points: " << point_set_3.size() << std::endl;
assert(!is_default_input || point_set_3.size() == 1101);
Point_set_2 point_set_2;
point_set_2.add_normal_map();
for (const auto& idx : point_set_3) {
point_set_2.insert(
}
const std::size_t k = 16;
const FT max_distance = FT(1) / FT(100);
const FT max_angle = FT(10);
const std::size_t min_region_size = 20;
Neighbor_query neighbor_query = CGAL::Shape_detection::Point_set::make_k_neighbor_query(
point_set_2, CGAL::parameters::k_neighbors(k));
Region_type region_type = CGAL::Shape_detection::Point_set::make_least_squares_circle_fit_region(
point_set_2,
maximum_distance(max_distance).
maximum_angle(max_angle).
minimum_region_size(min_region_size));
Sorting sorting = CGAL::Shape_detection::Point_set::make_least_squares_circle_fit_sorting(
point_set_2, neighbor_query, CGAL::parameters::k_neighbors(k));
sorting.sort();
Region_growing region_growing(
point_set_2, sorting.ordered(), neighbor_query, region_type);
Point_set_2::Property_map<unsigned char>
red = point_set_2.add_property_map<unsigned char>("red" , 0).first,
green = point_set_2.add_property_map<unsigned char>("green", 0).first,
blue = point_set_2.add_property_map<unsigned char>("blue" , 0).first;
CGAL::Random random;
std::size_t num_circles = 0;
region_growing.detect(
boost::make_function_output_iterator(
[&](const std::pair< Region_type::Primitive, typename Region_growing::Region >& region) {
const unsigned char r = static_cast<unsigned char>(random.get_int(64, 192));
const unsigned char g = static_cast<unsigned char>(random.get_int(64, 192));
const unsigned char b = static_cast<unsigned char>(random.get_int(64, 192));
for (auto item : region.second) {
red[item] = r;
green[item] = g;
blue[item] = b;
}
++num_circles;
}
)
);
std::cout << "* number of found circles: " << num_circles << std::endl;
assert(!is_default_input || num_circles == 10);
std::ofstream out("circles_point_set_2.ply");
out << point_set_2;
return EXIT_SUCCESS;
}
A convenience header that includes all classes related to the region growing algorithm on a point set...
Main class/entry point for running the region growing algorithm.
Definition: Region_growing.h:72
Vector & normal(const Index &index)
bool has_normal_map() const
Point & point(const Index &index)
Mode set_ascii_mode(std::ios &s)