Add a function in PMP to apply a CGAL::Aff_transformation_3 to a mesh.

This commit is contained in:
Maxime Gimeno 2018-04-25 14:52:46 +02:00
parent a362d94106
commit 72c31ebfac
6 changed files with 170 additions and 0 deletions

View File

@ -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 <CGAL/config.h>
#include <CGAL/license.h>
#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

View File

@ -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

View File

@ -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

View File

@ -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 <CGAL/license/Polygon_mesh_processing/transform.h>
#include <CGAL/Polygon_mesh_processing/internal/named_function_params.h>
#include <CGAL/Polygon_mesh_processing/internal/named_params_helper.h>
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<class Transformation, class Mesh,class NamedParameters>
void transform(const Transformation& transformation,
Mesh& mesh,
const NamedParameters& np)
{
typedef typename GetVertexPointMap<Mesh, NamedParameters>::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<Mesh>::vertex_descriptor vd, vertices(mesh))
{
put(vpm, vd, transformation.transform(get(vpm, vd)));
}
}
}
}
#endif // CGAL_TRANSFORM_H

View File

@ -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)

View File

@ -0,0 +1,34 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polygon_mesh_processing/transform.h>
#include <iostream>
#include <fstream>
#include <CGAL/Surface_mesh.h>
#include <CGAL/Aff_transformation_3.h>
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<Point> 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<K> 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<m.vertices().size(); ++i)
{
double z = m.point(Mesh::Vertex_index(i)).z();
ok &= z == i+1;
}
CGAL_assertion(ok);
return 0;
}