CGAL 6.2 - 2D Alpha Wrapping
Loading...
Searching...
No Matches
Alpha_wrap_2/triangle_soup_wrap_2.cpp
#define CGAL_AW2_DEBUG_PP
#include "output_helper.h"
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/alpha_wrap_2.h>
#include <CGAL/Multipolygon_with_holes_2.h>
#include <CGAL/Polygon_mesh_processing/bbox.h>
#include <CGAL/Real_timer.h>
#include <CGAL/IO/polygon_soup_io.h>
#include <CGAL/IO/WKT.h>
#include <array>
#include <iostream>
#include <string>
#include <vector>
using Point_2 = K::Point_2;
using Point_3 = K::Point_3;
int main(int argc, char** argv)
{
std::cout.precision(17);
std::cerr.precision(17);
// Read the input
const std::string filename = (argc > 1) ? argv[1] : CGAL::data_file_path("meshes/blobby-shuffled.off");
std::cout << "Reading " << filename << "..." << std::endl;
std::vector<Point_3> points;
std::vector<std::array<std::size_t, 3> > faces;
if(!CGAL::IO::read_polygon_soup(filename, points, faces) || faces.empty())
{
std::cerr << "Invalid input:" << filename << std::endl;
return EXIT_FAILURE;
}
std::cout << "Input: " << points.size() << " points, " << faces.size() << " faces" << std::endl;
// Project onto the XY plane
std::vector<Point_2> points_2(points.size());
for(std::size_t i = 0; i < points.size(); ++i)
points_2[i] = Point_2(points[i].x(), points[i].y());
std::vector<Point_3> points_3(points_2.size());
for(std::size_t i = 0; i < points_2.size(); ++i)
points_3[i] = Point_3(points_2[i].x(), points_2[i].y(), 0.);
CGAL::IO::write_polygon_soup("projected.off", points_3, faces, CGAL::parameters::stream_precision(17));
// Compute the alpha and offset values
const double relative_alpha = (argc > 2) ? std::stod(argv[2]) : 20.;
const double relative_offset = (argc > 3) ? std::stod(argv[3]) : 600.;
for(const Point_2& p : points_2)
bbox += p.bbox();
const double diag_length = std::sqrt(CGAL::square(bbox.xmax() - bbox.xmin()) +
CGAL::square(bbox.ymax() - bbox.ymin()));
const double alpha = diag_length / relative_alpha;
const double offset = diag_length / relative_offset;
// Construct the wrap
CGAL::Real_timer t;
t.start();
Multipolygon wrap;
CGAL::alpha_wrap_2(points_2, faces, alpha, offset, wrap);
t.stop();
std::cout << "Result: " << wrap.polygons_with_holes().size() << " polygons" << std::endl;
std::cout << "Took " << t.time() << " s." << std::endl;
// Save the result
const std::string output_name = generate_output_name(filename, relative_alpha, relative_offset);
std::cout << "Writing to " << output_name << std::endl;
std::ofstream out(output_name);
out.precision(std::numeric_limits<double>::max_digits10);
std::cout << "Done." << std::endl;
return EXIT_SUCCESS;
}
double ymax() const
double xmin() const
double ymin() const
double xmax() const
void alpha_wrap_2(const PointRange &points, const FaceRange &faces, const double alpha, const double offset, MultipolygonWithHoles &alpha_wrap, const InputNamedParameters &np)
computes a watertight, 1-manifold, simple multipolygon that strictly contains an input indexed face s...
Definition: alpha_wrap_2.h:153
bool write_polygon_soup(const std::string &fname, const PointRange &points, const PolygonRange &polygons, const NamedParameters &np=parameters::default_values())
bool read_polygon_soup(const std::string &fname, PointRange &points, PolygonRange &polygons, const NamedParameters &np=parameters::default_values())
NT square(const NT &x)
std::ostream & write_multi_polygon_WKT(std::ostream &out, MultiPolygon &polygons)
std::string data_file_path(const std::string &filename)