in shape_det/region_growing_on_point_set_3.cpp [116:224]
int main(int argc, char *argv[]) {
std::cout << std::endl << "region_growing_on_point_set_3 example started" << std::endl
<< "Note: if 0 points are loaded, please specify the path to the file data/point_set_3.xyz by hand!"
<< std::endl;
// Load xyz data either from a local folder or a user-provided file.
std::ifstream in(argc > 1 ? argv[1] : "../data/point_set_3.xyz");
CGAL::set_ascii_mode(in);
if (!in) {
std::cout << "Error: cannot read the file point_set_3.xyz!" << std::endl;
std::cout << "You can either create a symlink to the data folder or provide this file by hand."
<< std::endl << std::endl;
return EXIT_FAILURE;
}
const bool with_normal_map = true;
Input_range input_range(with_normal_map);
in >> input_range;
in.close();
std::cout << "* loaded " << input_range.size()
<< " points with normals" << std::endl;
// Default parameter values for the data file point_set_3.xyz.
const std::size_t k = 12;
const FT max_distance_to_plane = FT(2);
const FT max_accepted_angle = FT(20);
const std::size_t min_region_size = 50;
// Create instances of the classes Neighbor_query and Region_type.
Neighbor_query neighbor_query(
input_range,
k,
input_range.point_map());
Region_type region_type(
input_range,
max_distance_to_plane, max_accepted_angle, min_region_size,
input_range.point_map(), input_range.normal_map());
// Create an instance of the region growing class.
Region_growing region_growing(
input_range, neighbor_query, region_type);
// Run the algorithm.
Output_range output_range;
std::size_t number_of_regions = 0;
const std::string fname = (argc > 3 ? argv[3] : "output.txt");
Insert_point_colored_by_region_index inserter(
input_range, input_range.point_map(),
output_range, number_of_regions, fname);
CGAL::Timer timer;
timer.start();
region_growing.detect(
boost::make_function_output_iterator(inserter));
timer.stop();
// Print the number of found regions.
std::cout << "* " << number_of_regions
<< " regions have been found in " << timer.time()
<< " seconds" << std::endl;
// Save the result to a file in the user-provided path if any.
if (argc > 2) {
const std::string fullpath = argv[2];
std::ofstream out(fullpath);
out << output_range;
std::cout << "* found regions are saved in " << fullpath << std::endl;
out.close();
}
// Get all unassigned items.
Indices unassigned_items;
region_growing.unassigned_items(std::back_inserter(unassigned_items));
// Print the number of unassigned items.
std::cout << "* " << unassigned_items.size()
<< " points do not belong to any region" << std::endl;
// Store all unassigned points.
Points_3 unassigned_points;
unassigned_points.reserve(unassigned_items.size());
// output file
ofstream myfile;
myfile.open(fname, ios::app);
myfile << std::endl;
for (const auto index : unassigned_items) {
const auto& key = *(input_range.begin() + index);
const Point_3& point = get(input_range.point_map(), key);
unassigned_points.push_back(point);
myfile << index << " ";
}
myfile.close();
std::cout << "* " << unassigned_points.size()
<< " unassigned points are stored" << std::endl;
std::cout << "region_growing_on_point_set_3 example finished"
<< std::endl << std::endl;
return EXIT_SUCCESS;
}