#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#ifdef USE_POLYHEDRON
#include <CGAL/Polyhedron_3.h>
#else
#include <CGAL/Surface_mesh.h>
#endif
#include <CGAL/Shape_detection/Region_growing/Region_growing.h>
#include <CGAL/IO/polygon_mesh_io.h>
#include "include/utils.h"
using FT = typename Kernel::FT;
#ifdef USE_POLYHEDRON
#else
#endif
int main(int argc, char *argv[]) {
const bool is_default_input = argc > 1 ? false : true;
const std::string filename = is_default_input ? CGAL::data_file_path("meshes/building.off") : argv[1];
std::ifstream in(filename);
Polygon_mesh polygon_mesh;
std::cerr << "ERROR: cannot read the input file!" << std::endl;
return EXIT_FAILURE;
}
const auto& face_range = faces(polygon_mesh);
std::cout << "* number of input faces: " << face_range.size() << std::endl;
assert(!is_default_input || face_range.size() == 32245);
const FT max_distance = FT(1);
const FT max_angle = FT(45);
const std::size_t min_region_size = 5;
Neighbor_query neighbor_query(polygon_mesh);
Region_type region_type(
polygon_mesh,
maximum_distance(max_distance).
maximum_angle(max_angle).
minimum_region_size(min_region_size));
Sorting sorting(
polygon_mesh, neighbor_query);
sorting.sort();
Region_growing region_growing(
face_range, sorting.ordered(), neighbor_query, region_type);
std::vector<typename Region_growing::Primitive_and_region> regions;
region_growing.detect(std::back_inserter(regions));
std::cout << "* number of found planes: " << regions.size() << std::endl;
assert(!is_default_input || regions.size() == 365);
const Region_growing::Region_map& map = region_growing.region_map();
for (std::size_t i = 0; i < regions.size(); i++)
for (auto& item : regions[i].second) {
if (i != get(map, item)) {
std::cout << "Region map incorrect" << std::endl;
}
}
std::vector<typename Region_growing::Item> unassigned;
region_growing.unassigned_items(face_range, std::back_inserter(unassigned));
for (auto& item : unassigned) {
if (std::size_t(-1) != get(map, item)) {
std::cout << "Region map for unassigned incorrect" << std::endl;
}
}
const std::string fullpath = (argc > 2 ? argv[2] : "planes_polygon_mesh.ply");
utils::save_polygon_mesh_regions(polygon_mesh, regions, fullpath);
return EXIT_SUCCESS;
}
A convenience header that includes all classes related to the region growing algorithm on a polygon m...
Region type based on the quality of the least squares plane fit applied to faces of a polygon mesh.
Definition: Least_squares_plane_fit_region.h:57
Sorting of polygon mesh faces with respect to the local plane fit quality.
Definition: Least_squares_plane_fit_sorting.h:53
Edge-adjacent faces connectivity in a polygon mesh.
Definition: One_ring_neighbor_query.h:45
Main class/entry point for running the region growing algorithm.
Definition: Region_growing.h:72
bool read_polygon_mesh(const std::string &fname, Graph &g, const NamedParameters &np=parameters::default_values())
Mode set_ascii_mode(std::ios &s)