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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
|
// 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/regularize_contours.h $
// $Id: include/CGAL/Shape_regularization/regularize_contours.h b26b07a1242 $
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial
//
//
// Author(s) : Dmitry Anisimov
//
#ifndef CGAL_SHAPE_REGULARIZATION_REGULARIZE_CONTOURS_H
#define CGAL_SHAPE_REGULARIZATION_REGULARIZE_CONTOURS_H
/// \cond SKIP_IN_MANUAL
#include <CGAL/license/Shape_regularization.h>
/// \endcond
/**
* \ingroup PkgShapeRegularizationRef
* \file CGAL/Shape_regularization/regularize_contours.h
* This header includes all classes for regularizing contours.
* It also includes the corresponding free functions.
*/
// Boost includes.
/// \cond SKIP_IN_MANUAL
#include <CGAL/boost/graph/named_params_helper.h>
#include <CGAL/Named_function_parameters.h>
/// \endcond
// Internal includes.
/// \cond SKIP_IN_MANUAL
#include <CGAL/Shape_regularization/internal/utils.h>
#include <CGAL/Shape_regularization/internal/Contour_regularization_2.h>
/// \endcond
#include <CGAL/Shape_regularization/Contours/Longest_direction_2.h>
#include <CGAL/Shape_regularization/Contours/Multiple_directions_2.h>
#include <CGAL/Shape_regularization/Contours/User_defined_directions_2.h>
namespace CGAL {
namespace Shape_regularization {
namespace Contours {
/*!
\ingroup PkgShapeRegularizationRefContours
\brief regularizes closed contours.
Given a set of ordered 2D points connected by segments, which form a closed contour,
this function enables to reinforce three types of regularities among consecutive edges of this contour:
- *Parallelism*: contour edges, which are detected as near parallel, are made exactly parallel.
- *Orthogonality*: contour edges, which are detected as near orthogonal, are made exactly orthogonal.
- *Collinearity*: parallel contour edges, which are detected as near collinear, are made exactly collinear.
The principal directions of the contour are provided via the concept `ContourDirections`.
\tparam InputRange
a model of `ConstRange` whose iterator type is `RandomAccessIterator`
\tparam ContDirections
a model of `ContourDirections`
\tparam OutIterator
a model of `OutputIterator` that accepts points of type `GeomTraits::Point_2`
\tparam NamedParameters
a sequence of \ref bgl_namedparameters "Named Parameters"
\param input_range
a const range of ordered points, which form a contour
\param directions
estimated contour directions towards which the contour edges are oriented
\param contour
an output iterator with points of the regularized contour
\param np
an optional sequence of \ref bgl_namedparameters "Named Parameters"
among the ones listed below; this parameter can be omitted,
the default values are then used
\cgalNamedParamsBegin
\cgalParamNBegin{maximum_offset}
\cgalParamDescription{maximum allowed orthogonal distance between two parallel
and consecutive contour edges such that they are considered to be collinear}
\cgalParamType{`GeomTraits::FT`}
\cgalParamDefault{0.5 unit length}
\cgalParamNEnd
\cgalParamNBegin{point_map}
\cgalParamDescription{a property map that maps an item from `input_range`
to `GeomTraits::Point_2`}
\cgalParamType{a model of `ReadablePropertyMap` whose key type is the value type of the input
range and value type is `GeomTraits::Point_2`}
\cgalParamDefault{`CGAL::Identity_property_map`}
\cgalParamNEnd
\cgalParamNBegin{geom_traits}
\cgalParamDescription{an instance of geometric traits class}
\cgalParamType{a model of `Kernel`}
\cgalParamDefault{a CGAL `Kernel` deduced from the point type,
using `CGAL::Kernel_traits`}
\cgalParamNEnd
\cgalNamedParamsEnd
\return an output iterator to the element in the destination range,
one past the last contour vertex stored
\pre input_range.size() >= 3
*/
template<
typename InputRange,
typename ContDirections,
typename OutIterator,
typename NamedParameters = parameters::Default_named_parameters>
OutIterator regularize_closed_contour(
const InputRange& input_range,
const ContDirections& directions,
OutIterator contour,
const NamedParameters& np = parameters::default_values()) {
using PointMap = typename CGAL::GetPointMap<InputRange, NamedParameters>::type;
using Point_2 = typename PointMap::value_type;
using GeomTraits = typename CGAL::Kernel_traits<Point_2>::Kernel;
const PointMap point_map = parameters::choose_parameter(
parameters::get_parameter(np, internal_np::point_map), PointMap());
const GeomTraits traits = parameters::choose_parameter(
parameters::get_parameter(np, internal_np::geom_traits), GeomTraits());
CGAL_precondition(input_range.size() >= 3);
using Contour_regularizer =
internal::Contour_regularization_2<
internal::CLOSED, ContDirections, GeomTraits>;
Contour_regularizer regularizer(
directions, input_range, point_map, np, traits);
return regularizer.regularize(contour);
}
/*!
\ingroup PkgShapeRegularizationRefContours
\brief regularizes closed contours.
This function regularizes a closed contour with respect to the longest
edge of this contour.
*/
template<
typename InputRange,
typename OutIterator>
OutIterator regularize_closed_contour(
const InputRange& input_range,
OutIterator contour) {
CGAL_precondition(input_range.size() >= 3);
using Iterator_type = typename InputRange::const_iterator;
using Point_2 = typename std::iterator_traits<Iterator_type>::value_type;
using GeomTraits = typename Kernel_traits<Point_2>::Kernel;
using Contour_directions = Longest_direction_2<GeomTraits, InputRange>;
GeomTraits traits;
Contour_directions directions(input_range, true);
return regularize_closed_contour(
input_range, directions, contour, CGAL::parameters::geom_traits(traits));
}
/*!
\ingroup PkgShapeRegularizationRefContours
\brief regularizes open contours.
Given a set of ordered 2D points connected by segments, which form an open contour,
this function enables to reinforce three types of regularities among consecutive edges of this contour:
- *Parallelism*: contour edges, which are detected as near parallel, are made exactly parallel.
- *Orthogonality*: contour edges, which are detected as near orthogonal, are made exactly orthogonal.
- *Collinearity*: parallel contour edges, which are detected as near collinear, are made exactly collinear.
The principal directions of the contour are provided via the concept `ContourDirections`.
\tparam InputRange
a model of `ConstRange` whose iterator type is `RandomAccessIterator`
\tparam ContDirections
a model of `ContourDirections`
\tparam OutIterator
a model of `OutputIterator` that accepts points of type `GeomTraits::Point_2`
\tparam NamedParameters
a sequence of \ref bgl_namedparameters "Named Parameters"
\param input_range
a const range of ordered points, which form a contour
\param directions
estimated contour directions towards which the contour edges are oriented
\param contour
an output iterator with points of the regularized contour
\param np
an optional sequence of \ref bgl_namedparameters "Named Parameters"
among the ones listed below; this parameter can be omitted,
the default values are then used
\cgalNamedParamsBegin
\cgalParamNBegin{maximum_offset}
\cgalParamDescription{maximum allowed orthogonal distance between two parallel
and consecutive contour edges such that they are considered to be collinear}
\cgalParamType{`GeomTraits::FT`}
\cgalParamDefault{0.5 unit length}
\cgalParamNEnd
\cgalParamNBegin{point_map}
\cgalParamDescription{a property map that maps an item from `input_range`
to `GeomTraits::Point_2`}
\cgalParamType{a model of `ReadablePropertyMap` whose key type is the value type of the input
range and value type is `GeomTraits::Point_2`}
\cgalParamDefault{`CGAL::Identity_property_map`}
\cgalParamNEnd
\cgalParamNBegin{geom_traits}
\cgalParamDescription{an instance of geometric traits class}
\cgalParamType{a model of `Kernel`}
\cgalParamDefault{a CGAL `Kernel` deduced from the point type,
using `CGAL::Kernel_traits`}
\cgalParamNEnd
\cgalNamedParamsEnd
\return an output iterator to the element in the destination range,
one past the last contour vertex stored
\pre input_range.size() >= 2
*/
template<
typename InputRange,
typename ContDirections,
typename OutIterator,
typename NamedParameters = parameters::Default_named_parameters>
OutIterator regularize_open_contour(
const InputRange& input_range,
const ContDirections& directions,
OutIterator contour,
const NamedParameters& np = parameters::default_values()) {
using PointMap = typename CGAL::GetPointMap<InputRange, NamedParameters>::type;
using Point_2 = typename PointMap::value_type;
using GeomTraits = typename CGAL::Kernel_traits<Point_2>::Kernel;
const PointMap point_map = parameters::choose_parameter(
parameters::get_parameter(np, internal_np::point_map), PointMap());
const GeomTraits traits = parameters::choose_parameter(
parameters::get_parameter(np, internal_np::geom_traits), GeomTraits());
CGAL_precondition(input_range.size() >= 2);
using Contour_regularizer =
internal::Contour_regularization_2<
internal::OPEN, ContDirections, GeomTraits>;
Contour_regularizer regularizer(
directions, input_range, point_map, np, traits);
return regularizer.regularize(contour);
}
/*!
\ingroup PkgShapeRegularizationRefContours
\brief regularizes open contours.
This function regularizes an open contour with respect to the longest
edge of this contour.
*/
template<
typename InputRange,
typename OutIterator>
OutIterator regularize_open_contour(
const InputRange& input_range,
OutIterator contour) {
CGAL_precondition(input_range.size() >= 3);
using Iterator_type = typename InputRange::const_iterator;
using Point_2 = typename std::iterator_traits<Iterator_type>::value_type;
using GeomTraits = typename Kernel_traits<Point_2>::Kernel;
using Contour_directions = Longest_direction_2<GeomTraits, InputRange>;
GeomTraits traits;
Contour_directions directions(input_range, false);
return regularize_open_contour(
input_range, directions, contour, CGAL::parameters::geom_traits(traits));
}
} // namespace Contours
} // namespace Shape_regularization
} // namespace CGAL
#endif // CGAL_SHAPE_REGULARIZATION_REGULARIZE_CONTOURS_H
|