From 72c31ebfac3d27d40bcded010ddc25c6ced381f0 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Wed, 25 Apr 2018 14:52:46 +0200 Subject: [PATCH] Add a function in PMP to apply a CGAL::Aff_transformation_3 to a mesh. --- .../Polygon_mesh_processing/transform.h | 67 +++++++++++++++++++ .../include/CGAL/license/gpl_package_list.txt | 1 + .../PackageDescription.txt | 1 + .../CGAL/Polygon_mesh_processing/transform.h | 66 ++++++++++++++++++ .../Polygon_mesh_processing/CMakeLists.txt | 1 + .../test_pmp_transform.cpp | 34 ++++++++++ 6 files changed, 170 insertions(+) create mode 100644 Installation/include/CGAL/license/Polygon_mesh_processing/transform.h create mode 100644 Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/transform.h create mode 100644 Polygon_mesh_processing/test/Polygon_mesh_processing/test_pmp_transform.cpp diff --git a/Installation/include/CGAL/license/Polygon_mesh_processing/transform.h b/Installation/include/CGAL/license/Polygon_mesh_processing/transform.h new file mode 100644 index 00000000000..f4e3b24c6f6 --- /dev/null +++ b/Installation/include/CGAL/license/Polygon_mesh_processing/transform.h @@ -0,0 +1,67 @@ +// Copyright (c) 2016 GeometryFactory SARL (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0+ +// +// Author(s) : Andreas Fabri +// +// Warning: this file is generated, see include/CGAL/licence/README.md + + +#ifndef CGAL_LICENSE_POLYGON_MESH_PROCESSING_TRANSFORM_H +#define CGAL_LICENSE_POLYGON_MESH_PROCESSING_TRANSFORM_H + +#include +#include + + + + +#ifdef CGAL_POLYGON_MESH_PROCESSING_TRANSFORM_COMMERCIAL_LICENSE + +# if CGAL_POLYGON_MESH_PROCESSING_TRANSFORM_COMMERCIAL_LICENSE < CGAL_RELEASE_DATE + +# if defined(CGAL_LICENSE_WARNING) + + CGAL_pragma_warning("Your commercial license for CGAL does not cover " + "this release of the Polygon Mesh Processing - Transform package.") +# endif + +# ifdef CGAL_LICENSE_ERROR +# error "Your commercial license for CGAL does not cover this release \ +of the Polygon Mesh Processing - Transform package. \ +You get this error, as you defined CGAL_LICENSE_ERROR." +# endif // CGAL_LICENSE_ERROR + +# endif // CGAL_POLYGON_MESH_PROCESSING_TRANSFORM_COMMERCIAL_LICENSE < CGAL_RELEASE_DATE + +#else // no CGAL_POLYGON_MESH_PROCESSING_TRANSFORM_COMMERCIAL_LICENSE + +# if defined(CGAL_LICENSE_WARNING) + CGAL_pragma_warning("\nThe macro CGAL_POLYGON_MESH_PROCESSING_TRANSFORM_COMMERCIAL_LICENSE is not defined." + "\nYou use the CGAL Polygon Mesh Processing - Transform package under " + "the terms of the GPLv3+.") +# endif // CGAL_LICENSE_WARNING + +# ifdef CGAL_LICENSE_ERROR +# error "The macro CGAL_POLYGON_MESH_PROCESSING_TRANSFORM_COMMERCIAL_LICENSE is not defined.\ + You use the CGAL Polygon Mesh Processing - Transform package under the terms of \ +the GPLv3+. You get this error, as you defined CGAL_LICENSE_ERROR." +# endif // CGAL_LICENSE_ERROR + +#endif // no CGAL_POLYGON_MESH_PROCESSING_TRANSFORM_COMMERCIAL_LICENSE + +#endif // CGAL_LICENSE_CHECK_POLYGON_MESH_PROCESSING_TRANSFORM_H diff --git a/Installation/include/CGAL/license/gpl_package_list.txt b/Installation/include/CGAL/license/gpl_package_list.txt index 46f5b172373..737e2463536 100644 --- a/Installation/include/CGAL/license/gpl_package_list.txt +++ b/Installation/include/CGAL/license/gpl_package_list.txt @@ -53,6 +53,7 @@ Polygon_mesh_processing/predicate Polygon Mesh Processing - Predicate Polygon_mesh_processing/repair Polygon Mesh Processing - Repair Polygon_mesh_processing/miscellaneous Polygon Mesh Processing - Miscellaneous Polygon_mesh_processing/detect_features Polygon Mesh Processing - Feature Detection +Polygon_mesh_processing/transform Polygon Mesh Processing - Transform Polyhedron 3D Polyhedral Surface Polyline_simplification_2 2D Polyline Simplification Polytope_distance_d Optimal Distances diff --git a/Polygon_mesh_processing/doc/Polygon_mesh_processing/PackageDescription.txt b/Polygon_mesh_processing/doc/Polygon_mesh_processing/PackageDescription.txt index d1e269af0ed..80e65018910 100644 --- a/Polygon_mesh_processing/doc/Polygon_mesh_processing/PackageDescription.txt +++ b/Polygon_mesh_processing/doc/Polygon_mesh_processing/PackageDescription.txt @@ -176,6 +176,7 @@ and provides a list of the parameters that are used in this package. - `CGAL::Polygon_mesh_processing::edge_bbox()` - `CGAL::Polygon_mesh_processing::face_bbox()` - `CGAL::Polygon_mesh_processing::border_halfedges()` +- `CGAL::Polygon_mesh_processing::transform()` \todo add `clip_triangle_mesh()` using the code of `Polyhedron_place_clipping.h` and `PMP::corefine()` \todo fix and restore remove_degenerate_faces in the user and the reference manual diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/transform.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/transform.h new file mode 100644 index 00000000000..04f56e8983a --- /dev/null +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/transform.h @@ -0,0 +1,66 @@ +// Copyright (c) 2018 GeometryFactory (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// You can redistribute it and/or modify it under the terms of the GNU +// General Public License as published by the Free Software Foundation, +// either version 3 of the License, or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0+ +// +// +// Author(s) : Maxime Gimeno +#ifndef CGAL_TRANSFORM_H +#define CGAL_TRANSFORM_H +#include + +#include +#include + +namespace CGAL{ +namespace Polygon_mesh_processing{ +/** + * \ingroup PkgPolygonMeshProcessing + * applies a `Transformation` to every vertex of a `Mesh`. + * + * @tparam Transformation inherits from `CGAL::Aff_transformation_3` + * @tparam Mesh a model of `VertexListGraph` + * @tparam NamedParameters a sequence of \ref pmp_namedparameters "Named Parameters" + * + * @param transformation the `Aff_transformation_3` to apply to `mesh`. + * @param mesh the `Mesh` to transform. + * @param np optional sequence of \ref pmp_namedparameters for `mesh`, among the ones listed below + * + * * \cgalNamedParamsBegin + * \cgalParamBegin{vertex_point_map} the property map with the points associated to the vertices of `mesh`. + * If this parameter is omitted, an internal property map for + * `CGAL::vertex_point_t` should be available in `Mesh`\cgalParamEnd + * \cgalNamedParamsEnd + * + */ +template +void transform(const Transformation& transformation, + Mesh& mesh, + const NamedParameters& np) +{ + typedef typename GetVertexPointMap::type VPMap; + VPMap vpm = choose_param(get_param(np, internal_np::vertex_point), + get_property_map(vertex_point, mesh)); + + BOOST_FOREACH(typename boost::graph_traits::vertex_descriptor vd, vertices(mesh)) + { + put(vpm, vd, transformation.transform(get(vpm, vd))); + } +} +} +} + +#endif // CGAL_TRANSFORM_H diff --git a/Polygon_mesh_processing/test/Polygon_mesh_processing/CMakeLists.txt b/Polygon_mesh_processing/test/Polygon_mesh_processing/CMakeLists.txt index bad4e3eceb6..f7af9794708 100644 --- a/Polygon_mesh_processing/test/Polygon_mesh_processing/CMakeLists.txt +++ b/Polygon_mesh_processing/test/Polygon_mesh_processing/CMakeLists.txt @@ -99,6 +99,7 @@ endif() create_single_source_cgal_program("triangulate_hole_polyline_test.cpp") create_single_source_cgal_program("surface_intersection_sm_poly.cpp" ) create_single_source_cgal_program("test_orient_cc.cpp") + create_single_source_cgal_program("test_pmp_transform.cpp") if( TBB_FOUND ) CGAL_target_use_TBB(test_pmp_distance) diff --git a/Polygon_mesh_processing/test/Polygon_mesh_processing/test_pmp_transform.cpp b/Polygon_mesh_processing/test/Polygon_mesh_processing/test_pmp_transform.cpp new file mode 100644 index 00000000000..86de6d0c6fe --- /dev/null +++ b/Polygon_mesh_processing/test/Polygon_mesh_processing/test_pmp_transform.cpp @@ -0,0 +1,34 @@ +#include +#include +#include +#include + +#include +#include + + + +namespace PMP = CGAL::Polygon_mesh_processing; +namespace params = PMP::parameters; +typedef CGAL::Exact_predicates_inexact_constructions_kernel K; +typedef K::Point_3 Point; +typedef CGAL::Surface_mesh Mesh; + + + +int main() +{ + // test open clipping with Surface_mesh + Mesh m; + CGAL::make_tetrahedron(Point(0,0,0), Point(0,0,1), Point(0,1,2), Point(1,0,3), m); + CGAL::Aff_transformation_3 trans(0,0,0,1,0,1,0,0,0,0,1,1); + PMP::transform(trans, m, params::all_default()); + bool ok = true; + for(std::size_t i = 0; i