diff --git a/Cartesian_kernel/include/CGAL/Cartesian_converter.h b/Cartesian_kernel/include/CGAL/Cartesian_converter.h index d77689adca9..fb25953c85f 100644 --- a/Cartesian_kernel/include/CGAL/Cartesian_converter.h +++ b/Cartesian_kernel/include/CGAL/Cartesian_converter.h @@ -32,6 +32,7 @@ // provided you give a NT converter from A to B. // There's a Homogeneous counterpart. +#include #include #include #include @@ -91,7 +92,7 @@ struct Converting_visitor : boost::static_visitor<> { template < class K1, class K2, // class Converter = NT_converter > - class Converter = typename internal::Default_converter::Type > + class Converter> class Cartesian_converter : public Enum_converter { typedef Enum_converter Base; diff --git a/Installation/CHANGES.md b/Installation/CHANGES.md index aaca52d651b..82f399e9dba 100644 --- a/Installation/CHANGES.md +++ b/Installation/CHANGES.md @@ -18,6 +18,11 @@ Release date: September 2018 ConstructProjectedPoint 3. +### CGAL and Boost Property Maps + +- Addition of a read-write property map to convert on-the-fly geometric + object from Cartesian kernels + ### 2D Triangulations - Added a new type of intersection to deal with insertion of a constraints diff --git a/Installation/include/CGAL/Cartesian_converter_fwd.h b/Installation/include/CGAL/Cartesian_converter_fwd.h new file mode 100644 index 00000000000..2e265bc205c --- /dev/null +++ b/Installation/include/CGAL/Cartesian_converter_fwd.h @@ -0,0 +1,42 @@ +// Copyright (C) 2018 GeometryFactory Sarl +// +// 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+ +// + +#ifndef CGAL_CARTESIAN_CONVERTER_FWD_H +#define CGAL_CARTESIAN_CONVERTER_FWD_H + +/// \file Cartesian_converter_fwd.h +/// Forward declarations of the `Cartesian_converter` class. + +#ifndef DOXYGEN_RUNNING +namespace CGAL { + +namespace internal { +template < typename K1, typename K2 > +struct Default_converter; +}//internal + +template < class K1, class K2, + class Converter = typename internal::Default_converter::Type > +class Cartesian_converter; + +} // CGAL +#endif + +#endif /* CGAL_CARTESIAN_CONVERTER_FWD_H */ + + diff --git a/Installation/include/CGAL/Kernel_traits_fwd.h b/Installation/include/CGAL/Kernel_traits_fwd.h new file mode 100644 index 00000000000..0f7359e7b72 --- /dev/null +++ b/Installation/include/CGAL/Kernel_traits_fwd.h @@ -0,0 +1,33 @@ +// Copyright (C) 2018 GeometryFactory Sarl +// +// 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+ +// + +#ifndef CGAL_KERNEL_TRAITS_FWD_H +#define CGAL_KERNEL_TRAITS_FWD_H + +/// \file Kernel_traits_fwd.h +/// Forward declarations of the `Kernel_traits` class. + +#ifndef DOXYGEN_RUNNING +namespace CGAL { + +template struct Kernel_traits; + +} // CGAL +#endif + +#endif // CGAL_KERNEL_TRAITS_FWD_H diff --git a/Kernel_23/include/CGAL/Kernel_traits.h b/Kernel_23/include/CGAL/Kernel_traits.h index e52020fcb47..dc5d38257c0 100644 --- a/Kernel_23/include/CGAL/Kernel_traits.h +++ b/Kernel_23/include/CGAL/Kernel_traits.h @@ -26,6 +26,7 @@ #ifndef CGAL_KERNEL_TRAITS_H #define CGAL_KERNEL_TRAITS_H +#include #include #include diff --git a/Property_map/include/CGAL/property_map.h b/Property_map/include/CGAL/property_map.h index a4f5c52d3fd..d025f3962e2 100644 --- a/Property_map/include/CGAL/property_map.h +++ b/Property_map/include/CGAL/property_map.h @@ -36,6 +36,9 @@ #include // defines std::pair +#include +#include + namespace CGAL { /// \cond SKIP_DOXYGEN @@ -469,7 +472,7 @@ struct Constant_property_map }; /// \ingroup PkgProperty_map -/// Read-write Property map turning a set (such a `std::set`, +/// Read-write property map turning a set (such a `std::set`, /// `boost::unordered_set`, `std::unordered_set`) into a property map /// associating a Boolean to the value type of the set. The function `get` will /// return `true` if the key is inside the set and `false` otherwise. The `put` @@ -515,6 +518,50 @@ make_boolean_property_map(Set& set_) return Boolean_property_map(set_); } +/// \ingroup PkgProperty_map +/// Read-write property map doing on-the-fly conversions between two default constructible \cgal %Cartesian kernels. +/// Its value type is `GeomObject` and its key type is the same as `Vpm`. +/// `GeomObject` must be a geometric object from a \cgal kernel. +/// `Vpm` is a model `of ReadWritePropertyMap` and its value type must be +/// a geometric object of the same type as `GeomObject` but possibly from +/// another kernel. +/// Conversions between the two geometric objects are done using `Cartesian_converter`. +/// \cgalModels `ReadWritePropertyMap` +template +struct Cartesian_converter_property_map +{ + typedef typename boost::property_traits::key_type key_type; + typedef GeomObject value_type; + typedef value_type reference; + typedef boost::read_write_property_map_tag category; + Vpm vpm; + + typedef typename Kernel_traits::type K2; + typedef typename Kernel_traits::value_type>::type K1; + + Cartesian_converter_property_map(Vpm vpm):vpm(vpm){} + + friend value_type get(const Cartesian_converter_property_map& pm, const key_type& k) + { + return + CGAL::Cartesian_converter()(get(pm.vpm, k)); + } + + friend void put(Cartesian_converter_property_map& pm, const key_type& k, const value_type& v) + { + put(pm.vpm, k, CGAL::Cartesian_converter()(v)); + } +}; + +/// \ingroup PkgProperty_map +/// returns `Cartesian_converter_property_map(vpm)` +template +Cartesian_converter_property_map +make_cartesian_converter_property_map(Vpm vpm) +{ + return Cartesian_converter_property_map(vpm); +} + } // namespace CGAL diff --git a/Property_map/test/Property_map/CMakeLists.txt b/Property_map/test/Property_map/CMakeLists.txt index 768e08015fb..cf2d22c7469 100644 --- a/Property_map/test/Property_map/CMakeLists.txt +++ b/Property_map/test/Property_map/CMakeLists.txt @@ -55,6 +55,8 @@ create_single_source_cgal_program( "dynamic_property_map.cpp" ) create_single_source_cgal_program( "dynamic_properties_test.cpp" ) +create_single_source_cgal_program( "kernel_converter_properties_test.cpp" ) + if(OpenMesh_FOUND) target_link_libraries( dynamic_properties_test PRIVATE ${OPENMESH_LIBRARIES} ) endif() diff --git a/Property_map/test/Property_map/kernel_converter_properties_test.cpp b/Property_map/test/Property_map/kernel_converter_properties_test.cpp new file mode 100644 index 00000000000..586cdd49383 --- /dev/null +++ b/Property_map/test/Property_map/kernel_converter_properties_test.cpp @@ -0,0 +1,37 @@ + +#include +#include +#include +#include +#include +#include + +typedef CGAL::Simple_cartesian K1; +typedef CGAL::Simple_cartesian > K2; +typedef K1::Point_3 Point_3; + +template +void +test() +{ + Mesh m; + CGAL::make_triangle(Point_3(2,0,0),Point_3(1,0,0),Point_3(1,1,0),m); + + typedef typename boost::property_map::type VPMap; + VPMap vmap = get(CGAL::vertex_point, m); + + CGAL::Cartesian_converter_property_map kcmap =CGAL::make_cartesian_converter_property_map(vmap); + CGAL_assertion(get(kcmap, *vertices(m).begin()) == CGAL::Point_3(2,0,0)); + put(kcmap, *vertices(m).begin(), CGAL::Point_3(0,2,3)); + CGAL_assertion(get(kcmap, *vertices(m).begin()) == CGAL::Point_3(0,2,3)); + +} + +int main() +{ + + typedef CGAL::Surface_mesh SM; + test(); + return 0; +} +