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 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352
|
// Copyright (c) 2005-2017 GeometryFactory (France). All Rights Reserved.
//
// This file is part of CGAL (www.cgal.org)
//
// $URL: https://github.com/CGAL/cgal/blob/v6.1.1/Subdivision_method_3/include/CGAL/Subdivision_method_3/subdivision_methods_3.h $
// $Id: include/CGAL/Subdivision_method_3/subdivision_methods_3.h 08b27d3db14 $
// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial
//
//
// Author(s): Le-Jeng Shiue <Andy.Shiue@gmail.com>
//
#ifndef CGAL_SUBDIVISION_METHODS_3_H
#define CGAL_SUBDIVISION_METHODS_3_H
#include <CGAL/basic.h>
#include <CGAL/circulator.h>
#include <CGAL/Named_function_parameters.h>
#include <CGAL/boost/graph/named_params_helper.h>
#include <CGAL/Subdivision_method_3/subdivision_hosts_3.h>
#include <CGAL/Subdivision_method_3/subdivision_masks_3.h>
namespace CGAL {
/// The namespace containing the subdivision methods.
namespace Subdivision_method_3 {
/*!
\addtogroup PkgSurfaceSubdivisionMethod3Functions
A subdivision method recursively refines a coarse mesh and
generates an ever closer approximation to a smooth surface.
`Subdivision_method_3` consists of four subdivision methods
and their refinement hosts. Each refinement host is a template
function of a polygon mesh class and a
geometry policy class. It refines the connectivity of the
control mesh and computes the geometry of the refined mesh.
The geometry computation is dedicated to the custom
geometry policy. A geometry policy consists of functions
that compute the new point based on the subdivision stencil.
A stencil defines the footprint (a submesh of the control mesh)
of a new point.
The four supported refinement hosts are the
primal quadrilateral quadrisection (PQQ),
the primal triangle quadrisection (PTQ),
the dual quadrilateral quadrisection (DQQ),
and the \f$ \sqrt{3}\f$ triangulation.
These refinements are respectively used in
Catmull-Clark, Loop, Doo-Sabin and \f$ \sqrt{3}\f$ subdivisions.
\cgalHeading{Refinement Host}
A refinement host is a template function of
a polygon mesh class and a geometry mask class. It refines
the input polygon mesh, and computes new points through
the geometry masks.
`Subdivision_method_3` supports four refinement hosts:
`PQQ`, `PTQ`, `DQQ` and `Sqrt3`.
\image html RefSchemes.svg
\cgalHeading{Example}
This example program subdivides a polygonal mesh with
Catmull-Clark subdivision.
\cgalExample{Subdivision_method_3/CatmullClark_subdivision.cpp}
\sa `CGAL::CatmullClark_mask_3<PolygonMesh>`
\sa `CGAL::DooSabin_mask_3<PolygonMesh`
\sa `CGAL::Loop_mask_3<PolygonMesh`
\sa `CGAL::Sqrt3_mask_3<PolygonMesh>`
\sa `CGAL::Linear_mask_3<PolygonMesh>`
*/
/// @{
// -----------------------------------------------------------------------------
#ifndef DOXYGEN_RUNNING
// Backward compatibility
#ifndef CGAL_NO_DEPRECATED_CODE
template <class PolygonMesh>
CGAL_DEPRECATED_MSG("you are using the deprecated API of CatmullClark_subdivision(), please update your code")
void CatmullClark_subdivision(PolygonMesh& pmesh, int step) {
PQQ(pmesh, CatmullClark_mask_3<PolygonMesh>(&pmesh, get(vertex_point,pmesh)), step);
}
#endif
#endif
/*!
*
* applies Catmull-Clark subdivision several times on the control mesh `pmesh`.
* The geometry of the refined mesh is computed by the geometry policy mask `CatmullClark_mask_3`.
* This function overwrites the control mesh `pmesh` with the subdivided mesh.
*
* @tparam PolygonMesh a model of `MutableFaceGraph`
* @tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters"
*
* @param pmesh a polygon mesh
* @param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below
*
* \cgalNamedParamsBegin
* \cgalParamNBegin{vertex_point_map}
* \cgalParamDescription{a property map associating points to the vertices of `pmesh`}
* \cgalParamType{a class model of `ReadWritePropertyMap` with `boost::graph_traits<PolygonMesh>::%vertex_descriptor`
* as key type and `%Point_3` as value type}
* \cgalParamDefault{`boost::get(CGAL::vertex_point, pmesh)`}
* \cgalParamExtra{If this parameter is omitted, an internal property map for `CGAL::vertex_point_t`
* should be available for the vertices of `pmesh`.}
* \cgalParamNEnd
*
* \cgalParamNBegin{number_of_iterations}
* \cgalParamDescription{the number of subdivision steps}
* \cgalParamType{unsigned int}
* \cgalParamDefault{`1`}
* \cgalParamNEnd
* \cgalParamNBegin{do_not_modify_geometry}
* \cgalParamDescription{if set to `true`, the geometry of the mesh will not be modified}
* \cgalParamType{Boolean}
* \cgalParamDefault{`false`}
* \cgalParamExtra{If `pmesh` is in fact a triangle mesh, this named parameter is also available
* in Loop subdivision and will create better shaped elements.}
* \cgalParamNEnd
* \cgalNamedParamsEnd
*
**/
template <class PolygonMesh, class NamedParameters = parameters::Default_named_parameters>
void CatmullClark_subdivision(PolygonMesh& pmesh, const NamedParameters& np = parameters::default_values()) {
using parameters::choose_parameter;
using parameters::get_parameter;
typedef typename CGAL::GetVertexPointMap<PolygonMesh, NamedParameters>::type Vpm;
Vpm vpm = choose_parameter(get_parameter(np, internal_np::vertex_point),
get_property_map(CGAL::vertex_point, pmesh));
unsigned int step = choose_parameter(get_parameter(np, internal_np::number_of_iterations), 1);
bool do_not_modify_geometry = choose_parameter(get_parameter(np, internal_np::do_not_modify_geometry), false);
if (do_not_modify_geometry) {
Linear_mask_3<PolygonMesh, Vpm> mask(&pmesh, vpm);
for (unsigned int i = 0; i < step; i++)
internal::PQQ_1step(pmesh, vpm, mask);
} else {
CatmullClark_mask_3<PolygonMesh, Vpm> mask(&pmesh, vpm);
for (unsigned int i = 0; i < step; i++)
internal::PQQ_1step(pmesh, vpm, mask);
}
}
// -----------------------------------------------------------------------------
#ifndef DOXYGEN_RUNNING
// backward compatibility
#ifndef CGAL_NO_DEPRECATED_CODE
template <class PolygonMesh>
CGAL_DEPRECATED_MSG("you are using the deprecated API of Loop_subdivision(), please update your code")
void Loop_subdivision(PolygonMesh& pmesh, int step) {
PTQ(pmesh, Loop_mask_3<PolygonMesh>(&pmesh, get(vertex_point,pmesh)) , step);
}
#endif
#endif
/*!
*
* applies Loop subdivision several times on the control mesh `pmesh`.
* The geometry of the refined mesh is computed by the geometry policy mask `Loop_mask_3`.
* This function overwrites the control mesh `pmesh` with the subdivided mesh.
* @tparam PolygonMesh a model of `MutableFaceGraph`
* @tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters"
*
* @param pmesh a polygon mesh
* @param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below
*
* \cgalNamedParamsBegin
* \cgalParamNBegin{vertex_point_map}
* \cgalParamDescription{a property map associating points to the vertices of `pmesh`}
* \cgalParamType{a class model of `ReadWritePropertyMap` with `boost::graph_traits<PolygonMesh>::%vertex_descriptor`
* as key type and `%Point_3` as value type}
* \cgalParamDefault{`boost::get(CGAL::vertex_point, pmesh)`}
* \cgalParamExtra{If this parameter is omitted, an internal property map for `CGAL::vertex_point_t`
* should be available for the vertices of `pmesh`.}
* \cgalParamNEnd
*
* \cgalParamNBegin{number_of_iterations}
* \cgalParamDescription{the number of subdivision steps}
* \cgalParamType{unsigned int}
* \cgalParamDefault{`1`}
* \cgalParamNEnd
* \cgalParamNBegin{do_not_modify_geometry}
* \cgalParamDescription{if set to `true`, the geometry of the mesh will not be modified}
* \cgalParamType{Boolean}
* \cgalParamDefault{`false`}
* \cgalParamExtra{This named parameter is also available in Catmull-Clark subdivision
* for non-triangle meshes.}
* \cgalParamNEnd
* \cgalNamedParamsEnd
*
* \pre `pmesh` must be a triangle mesh.
**/
template <class PolygonMesh, class NamedParameters = parameters::Default_named_parameters>
void Loop_subdivision(PolygonMesh& pmesh, const NamedParameters& np = parameters::default_values()) {
using parameters::choose_parameter;
using parameters::get_parameter;
typedef typename CGAL::GetVertexPointMap<PolygonMesh, NamedParameters>::type Vpm;
Vpm vpm = choose_parameter(get_parameter(np, internal_np::vertex_point),
get_property_map(CGAL::vertex_point, pmesh));
unsigned int step = choose_parameter(get_parameter(np, internal_np::number_of_iterations), 1);
bool do_not_modify_geometry = choose_parameter(get_parameter(np, internal_np::do_not_modify_geometry), false);
if (do_not_modify_geometry) {
Linear_mask_3<PolygonMesh, Vpm> mask(&pmesh, vpm);
for (unsigned int i = 0; i < step; i++)
internal::PTQ_1step(pmesh, vpm, mask);
} else {
Loop_mask_3<PolygonMesh, Vpm> mask(&pmesh, vpm);
for (unsigned int i = 0; i < step; i++)
internal::PTQ_1step(pmesh, vpm, mask);
}
}
// -----------------------------------------------------------------------------
#ifndef DOXYGEN_RUNNING
// backward compatibility
#ifndef CGAL_NO_DEPRECATED_CODE
template <class PolygonMesh>
CGAL_DEPRECATED_MSG("you are using the deprecated API of DooSabin_subdivision(), please update your code")
void DooSabin_subdivision(PolygonMesh& pmesh, int step) {
DQQ(pmesh, DooSabin_mask_3<PolygonMesh>(&pmesh, get(vertex_point, pmesh)), step);
}
#endif
#endif
/*!
*
* applies DooSabin subdivision several times on the control mesh `pmesh`.
* The geometry of the refined mesh is computed by the geometry policy mask `DooSabin_mask_3`.
* This function overwrites the control mesh `pmesh` with the subdivided mesh.
* @tparam PolygonMesh a model of `MutableFaceGraph`
* @tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters"
*
* @param pmesh a polygon mesh
* @param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below
*
* \cgalNamedParamsBegin
* \cgalParamNBegin{vertex_point_map}
* \cgalParamDescription{a property map associating points to the vertices of `pmesh`}
* \cgalParamType{a class model of `ReadWritePropertyMap` with `boost::graph_traits<PolygonMesh>::%vertex_descriptor`
* as key type and `%Point_3` as value type}
* \cgalParamDefault{`boost::get(CGAL::vertex_point, pmesh)`}
* \cgalParamExtra{If this parameter is omitted, an internal property map for `CGAL::vertex_point_t`
* should be available for the vertices of `pmesh`.}
* \cgalParamNEnd
*
* \cgalParamNBegin{number_of_iterations}
* \cgalParamDescription{the number of subdivision steps}
* \cgalParamType{unsigned int}
* \cgalParamDefault{`1`}
* \cgalParamNEnd
* \cgalNamedParamsEnd
**/
template <class PolygonMesh, class NamedParameters = parameters::Default_named_parameters>
void DooSabin_subdivision(PolygonMesh& pmesh, const NamedParameters& np = parameters::default_values()) {
using parameters::choose_parameter;
using parameters::get_parameter;
typedef typename CGAL::GetVertexPointMap<PolygonMesh, NamedParameters>::type Vpm;
Vpm vpm = choose_parameter(get_parameter(np, internal_np::vertex_point),
get_property_map(CGAL::vertex_point, pmesh));
unsigned int step = choose_parameter(get_parameter(np, internal_np::number_of_iterations), 1);
DooSabin_mask_3<PolygonMesh,Vpm> mask(&pmesh, vpm);
for(unsigned int i = 0; i < step; i++)
internal::DQQ_1step(pmesh, vpm, mask);
}
// -----------------------------------------------------------------------------
#ifndef DOXYGEN_RUNNING
// backward compatibility
#ifndef CGAL_NO_DEPRECATED_CODE
template <class PolygonMesh>
CGAL_DEPRECATED_MSG("you are using the deprecated API of Sqrt3_subdivision(), please update your code")
void Sqrt3_subdivision(PolygonMesh& pmesh, int step) {
Sqrt3(pmesh, Sqrt3_mask_3<PolygonMesh>(&pmesh, get(vertex_point,pmesh)), step);
}
#endif
#endif
/*!
*
* applies \f$ \sqrt{3}\f$-subdivision several times on the control mesh `pmesh`.
* The geometry of the refined mesh is computed by the geometry policy mask `Sqrt3_mask_3`.
* This function overwrites the control mesh `pmesh` with the subdivided mesh.
*
* \attention The border subdivision only happens every second subdivision step
* during a <em>single</em> call of this function.
*
* @tparam PolygonMesh a model of `MutableFaceGraph`
* @tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters"
*
* @param pmesh a polygon mesh
* @param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below
*
* \cgalNamedParamsBegin
* \cgalParamNBegin{vertex_point_map}
* \cgalParamDescription{a property map associating points to the vertices of `pmesh`}
* \cgalParamType{a class model of `ReadWritePropertyMap` with `boost::graph_traits<PolygonMesh>::%vertex_descriptor`
* as key type and `%Point_3` as value type}
* \cgalParamDefault{`boost::get(CGAL::vertex_point, pmesh)`}
* \cgalParamExtra{If this parameter is omitted, an internal property map for `CGAL::vertex_point_t`
* should be available for the vertices of `pmesh`.}
* \cgalParamNEnd
*
* \cgalParamNBegin{number_of_iterations}
* \cgalParamDescription{the number of subdivision steps}
* \cgalParamType{unsigned int}
* \cgalParamDefault{`1`}
* \cgalParamNEnd
* \cgalNamedParamsEnd
*
* \pre `pmesh` must be a triangle mesh.
**/
template <class PolygonMesh, class NamedParameters = parameters::Default_named_parameters>
void Sqrt3_subdivision(PolygonMesh& pmesh, const NamedParameters& np = parameters::default_values()) {
using parameters::choose_parameter;
using parameters::get_parameter;
typedef typename CGAL::GetVertexPointMap<PolygonMesh, NamedParameters>::type Vpm;
Vpm vpm = choose_parameter(get_parameter(np, internal_np::vertex_point),
get_property_map(CGAL::vertex_point, pmesh));
unsigned int step = choose_parameter(get_parameter(np, internal_np::number_of_iterations), 1);
Sqrt3_mask_3<PolygonMesh,Vpm> mask(&pmesh, vpm);
for(unsigned int i = 0; i < step; i++)
internal::Sqrt3_1step(pmesh, vpm, mask, (i%2==1));
}
/// @}
} // namespace Subdivision_method_3
} // namespace CGAL
#endif // CGAL_SUBDIVISION_METHODS_3_H
|