Merge pull request #3058 from maxGimeno/Property_map-Point_kernel_converter_map-GF

Property_map: Kernel_converter_map
This commit is contained in:
Laurent Rineau 2018-06-06 14:41:46 +02:00
commit 7f45dbebe6
8 changed files with 170 additions and 2 deletions

View File

@ -32,6 +32,7 @@
// provided you give a NT converter from A to B.
// There's a Homogeneous counterpart.
#include <CGAL/Cartesian_converter_fwd.h>
#include <CGAL/basic.h>
#include <CGAL/NT_converter.h>
#include <CGAL/Enum_converter.h>
@ -91,7 +92,7 @@ struct Converting_visitor : boost::static_visitor<> {
template < class K1, class K2,
// class Converter = NT_converter<typename K1::FT, typename K2::FT> >
class Converter = typename internal::Default_converter<K1, K2>::Type >
class Converter>
class Cartesian_converter : public Enum_converter
{
typedef Enum_converter Base;

View File

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

View File

@ -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<K1, K2>::Type >
class Cartesian_converter;
} // CGAL
#endif
#endif /* CGAL_CARTESIAN_CONVERTER_FWD_H */

View File

@ -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 <class T> struct Kernel_traits;
} // CGAL
#endif
#endif // CGAL_KERNEL_TRAITS_FWD_H

View File

@ -26,6 +26,7 @@
#ifndef CGAL_KERNEL_TRAITS_H
#define CGAL_KERNEL_TRAITS_H
#include <CGAL/Kernel_traits_fwd.h>
#include <boost/mpl/has_xxx.hpp>
#include <boost/mpl/if.hpp>

View File

@ -36,6 +36,9 @@
#include <utility> // defines std::pair
#include <CGAL/Cartesian_converter_fwd.h>
#include <CGAL/Kernel_traits_fwd.h>
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>(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<class GeomObject, class Vpm>
struct Cartesian_converter_property_map
{
typedef typename boost::property_traits<Vpm>::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<GeomObject>::type K2;
typedef typename Kernel_traits<typename boost::property_traits<Vpm>::value_type>::type K1;
Cartesian_converter_property_map(Vpm vpm):vpm(vpm){}
friend value_type get(const Cartesian_converter_property_map<GeomObject, Vpm>& pm, const key_type& k)
{
return
CGAL::Cartesian_converter<K1, K2>()(get(pm.vpm, k));
}
friend void put(Cartesian_converter_property_map<GeomObject, Vpm>& pm, const key_type& k, const value_type& v)
{
put(pm.vpm, k, CGAL::Cartesian_converter<K2, K1>()(v));
}
};
/// \ingroup PkgProperty_map
/// returns `Cartesian_converter_property_map<GeomObject, Vpm>(vpm)`
template<class GeomObject, class Vpm>
Cartesian_converter_property_map<GeomObject, Vpm>
make_cartesian_converter_property_map(Vpm vpm)
{
return Cartesian_converter_property_map<GeomObject, Vpm>(vpm);
}
} // namespace CGAL

View File

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

View File

@ -0,0 +1,37 @@
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/Quotient.h>
#include <CGAL/MP_Float.h>
#include <CGAL/Cartesian_converter.h>
#include <CGAL/property_map.h>
typedef CGAL::Simple_cartesian<double> K1;
typedef CGAL::Simple_cartesian<CGAL::Quotient<CGAL::MP_Float> > K2;
typedef K1::Point_3 Point_3;
template <typename Mesh>
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<Mesh, CGAL::vertex_point_t >::type VPMap;
VPMap vmap = get(CGAL::vertex_point, m);
CGAL::Cartesian_converter_property_map<K2::Point_3, VPMap> kcmap =CGAL::make_cartesian_converter_property_map<K2::Point_3>(vmap);
CGAL_assertion(get(kcmap, *vertices(m).begin()) == CGAL::Point_3<K2>(2,0,0));
put(kcmap, *vertices(m).begin(), CGAL::Point_3<K2>(0,2,3));
CGAL_assertion(get(kcmap, *vertices(m).begin()) == CGAL::Point_3<K2>(0,2,3));
}
int main()
{
typedef CGAL::Surface_mesh<Point_3> SM;
test<SM>();
return 0;
}