#include "include/utils.h"
#include "include/Saver.h"
#include <CGAL/Eigen_diagonalize_traits.h>
#include <CGAL/linear_least_squares_fitting_2.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel;
using FT = typename Kernel::FT;
using Point_2 = typename Kernel::Point_2;
using Segment_2 = typename Kernel::Segment_2;
using Line_2 = typename Kernel::Line_2;
using Points_2 = std::vector<Point_2>;
using Indices = std::vector<std::size_t>;
using Segments = std::vector<Segment_2>;
using Neighbor_query =
using Angle_regularization =
using Offset_regularization =
int main(int argc, char *argv[]) {
std::string path = "data/real_data_2.xyzi";
if (argc > 1) path = argv[1];
Saver<Kernel> saver;
std::vector<Points_2> groups;
initialize_groups(path, groups);
Line_2 line; Point_2 centroid;
std::vector<Line_2> lines;
lines.reserve(groups.size());
for (const auto& group : groups) {
CGAL::linear_least_squares_fitting_2(
group.begin(), group.end(), line, centroid, CGAL::Dimension_tag<0>(),
Kernel(), CGAL::Eigen_diagonalize_traits<FT, 2>());
lines.push_back(line);
}
std::vector<Segment_2> segments;
segments.reserve(lines.size());
Point_2 source, target;
for (std::size_t i = 0; i < lines.size(); ++i) {
boundary_points_on_line_2(
groups[i], lines[i], source, target);
segments.push_back(Segment_2(source, target));
}
if (argc > 2) {
const std::string full_path = std::string(argv[2]) + "regularize_real_data_2_before";
saver.export_eps_segments(segments, full_path, FT(3) / FT(2));
}
const FT max_angle_2 = FT(80);
Neighbor_query neighbor_query(segments);
Angle_regularization angle_regularization(
segments, CGAL::parameters::maximum_angle(max_angle_2));
segments, neighbor_query, angle_regularization);
std::cout << "* number of modified segments (angles) = " <<
angle_regularization.number_of_modified_segments() << std::endl;
const FT max_offset_2 = FT(2);
std::vector<Indices> pgroups;
angle_regularization.parallel_groups(
std::back_inserter(pgroups));
Offset_regularization offset_regularization(
segments, CGAL::parameters::maximum_offset(max_offset_2));
neighbor_query.clear();
for (const auto& pgroup : pgroups) {
neighbor_query.add_group(pgroup);
offset_regularization.add_group(pgroup);
}
segments, neighbor_query, offset_regularization);
std::cout << "* number of modified segments (offsets) = " <<
offset_regularization.number_of_modified_segments() << std::endl;
if (argc > 2) {
const std::string full_path = std::string(argv[2]) + "regularize_real_data_2_after";
saver.export_eps_segments(segments, full_path, FT(3) / FT(2));
}
}
An angle-based regularization type for 2D segments that reinforces parallelism and orthogonality rela...
Definition Angle_regularization_2.h:55
A neighbor query based on a Delaunay triangulation, which enables to find the nearest neighbors in a ...
Definition Delaunay_neighbor_query_2.h:61
An offset-based regularization type for 2D segments that reinforces collinearity relationships.
Definition Offset_regularization_2.h:60
void regularize_segments(InputRange &input_range, NeighQuery &neighbor_query, RegType ®ularization_type, QPSolver &quadratic_program, const NamedParameters &np=parameters::default_values())
regularizes a set of 2D segments.
Definition regularize_segments.h:136
This header includes all classes for regularizing segments.