1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
// Copyright (c) 2020 GeometryFactory SARL (France).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org).
//
// $URL: https://github.com/CGAL/cgal/blob/v6.1/Shape_regularization/include/CGAL/Shape_regularization/internal/Segment_wrapper_2.h $
// $Id: include/CGAL/Shape_regularization/internal/Segment_wrapper_2.h b26b07a1242 $
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial
//
//
// Author(s) : Dmitry Anisimov, Gennadii Sytov
//
#ifndef CGAL_SHAPE_REGULARIZATION_INTERNAL_SEGMENT_WRAPPER_2_H
#define CGAL_SHAPE_REGULARIZATION_INTERNAL_SEGMENT_WRAPPER_2_H
#include <CGAL/license/Shape_regularization.h>
// Internal includes.
#include <CGAL/Shape_regularization/internal/utils.h>
namespace CGAL {
namespace Shape_regularization {
namespace internal {
template<typename GeomTraits>
struct Segment_wrapper_2 {
using Traits = GeomTraits;
using FT = typename Traits::FT;
using Point_2 = typename Traits::Point_2;
using Segment_2 = typename Traits::Segment_2;
using Direction_2 = typename Traits::Direction_2;
std::size_t index = std::size_t(-1); // regularize segments and contours
bool is_used = false;
Point_2 barycenter, ref_coords; // regularize segments
FT orientation, length, a, b, c;
Direction_2 direction;
Segment_2 segment; // regularize contours
std::size_t group = std::size_t(-1);
bool is_valid_direction = false;
void set_index(const std::size_t index_) {
index = index_; is_used = true;
}
void set_length(
const Segment_2& segment) {
length = internal::segment_length_2(segment);
}
void set_barycenter(
const Segment_2& segment) {
barycenter = CGAL::midpoint(segment.source(), segment.target());
}
void set_direction(
const Segment_2& segment) {
auto v = segment.to_vector();
direction = internal::direction_2(v);
}
void set_orientation(
const Segment_2& segment) {
set_direction(segment);
orientation = internal::orientation_2(direction);
}
void set_abc(
const Segment_2& segment) {
set_barycenter(segment);
set_orientation(segment);
internal::line_coefficients_2(
barycenter, direction, a, b, c);
}
void set_qp(
const std::size_t index_,
const Segment_2& segment) {
set_index(index_);
set_length(segment);
set_abc(segment);
}
void set_ref_coords(
const Point_2& frame_origin) {
ref_coords = internal::transform_coordinates_2(
barycenter, frame_origin, orientation);
}
};
template<typename GeomTraits>
class Wrap_segment_map {
using Self = Wrap_segment_map<GeomTraits>;
using key_type = Segment_wrapper_2<GeomTraits>;
using value_type = typename GeomTraits::Segment_2;
using reference = const value_type&;
using category = boost::readable_property_map_tag;
reference operator[](const key_type& key) const {
return key.segment;
}
friend reference get(const Self& self, const key_type& key) {
return self[key];
}
};
} // namespace internal
} // namespace Shape_regularization
} // namespace CGAL
#endif // CGAL_SHAPE_REGULARIZATION_INTERNAL_SEGMENT_WRAPPER_2_H
|