Do in 2D what we did in 3D

This commit is contained in:
Andreas Fabri 2017-03-03 15:32:24 +01:00 committed by Mael Rouxel-Labbé
parent 442e7f00f0
commit d73be575f5
6 changed files with 413 additions and 37 deletions

View File

@ -3200,6 +3200,7 @@ namespace HomogeneousKernelFunctors {
template <typename K>
class Construct_weighted_point_2
{
typedef typename K::RT RT;
typedef typename K::FT FT;
typedef typename K::Point_2 Point_2;
typedef typename K::Weighted_point_2 Weighted_point_2;

View File

@ -78,9 +78,11 @@ public:
: RPoint_2(p)
{}
#if 0
Point_2(const Weighted_point_2& wp)
: Rep(wp.point())
{}
#endif
template < typename T1, typename T2 >
Point_2(const T1 &x, const T2 &y)

View File

@ -76,7 +76,7 @@ public:
Weighted_point_2(const Rep& p)
: Rep(p) {}
Weighted_point_2(const Point_2& p)
explicit Weighted_point_2(const Point_2& p)
: Rep(typename R::Construct_weighted_point_2()(Return_base_tag(), p, 0))
{}

View File

@ -0,0 +1,213 @@
// Copyright (c) 1999-2004,2006-2009,2014-2015 INRIA Sophia-Antipolis (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$
//
//
// Author(s) : Monique Teillaud <Monique.Teillaud@sophia.inria.fr>
// Sylvain Pion <Sylvain.Pion@sophia.inria.fr>
// Andreas Fabri <Andreas.Fabri@sophia.inria.fr>
// Nico Kruithof <Nico.Kruithof@sophia.inria.fr>
// Manuel Caroli <Manuel.Caroli@sophia.inria.fr>
// Aymeric Pellé <Aymeric.Pelle@sophia.inria.fr>
#ifndef CGAL_REGULAR_TRAITS_ADAPTOR_2_H
#define CGAL_REGULAR_TRAITS_ADAPTOR_2_H
#include <CGAL/license/Triangulation_2.h>
#include <CGAL/internal/Triangulation/Has_nested_type_Bare_point.h>
#include <boost/mpl/if.hpp>
#include <boost/mpl/identity.hpp>
namespace CGAL {
template < class RTT, class ConstructPoint, class Functor_>
class Regular_traits_adaptor_2
{
const ConstructPoint& cp;
const Functor_& f;
typedef RTT RTraits;
typedef Functor_ Functor;
typedef typename RTraits::FT FT;
#if 0
typedef typename boost::mpl::eval_if_c<
internal::Has_nested_type_Bare_point<RTraits>::value,
typename internal::Bare_point_type<RTraits>,
boost::mpl::identity<typename RTraits::Point_2>
>::type Point_2;
#else
typedef typename RTT::Point_2 Point_2;
#endif
typedef typename RTraits::Triangle_2 Triangle_2;
typedef typename RTraits::Segment_2 Segment_2;
typedef typename RTraits::Circle_2 Circle_2;
typedef typename RTraits::Weighted_point_2 Weighted_point_2;
template <typename T>
struct Conv_wp_to_p {
typedef T type;
};
template <>
struct Conv_wp_to_p<Weighted_point_2> {
typedef Point_2 type;
};
template <>
struct Conv_wp_to_p<const Weighted_point_2> {
typedef const Point_2 type;
};
template <>
struct Conv_wp_to_p<const Weighted_point_2&> {
typedef const Point_2& type;
};
template <typename> struct result {};
template <typename F, typename A0> struct result<F(A0)> {
typedef typename Conv_wp_to_p<A0>::type A0p;
typedef typename cpp11::result_of<F(A0p)>::type type;
};
template <typename F, typename A0, typename A1> struct result<F(A0,A1)> {
typedef typename Conv_wp_to_p<A0>::type A0p;
typedef typename Conv_wp_to_p<A1>::type A1p;
typedef typename cpp11::result_of<F(A0p, A1p)>::type type;
};
template <typename F, typename A0, typename A1, typename A2> struct result<F(A0,A1,A2)> {
typedef typename Conv_wp_to_p<A0>::type A0p;
typedef typename Conv_wp_to_p<A1>::type A1p;
typedef typename Conv_wp_to_p<A2>::type A2p;
typedef typename cpp11::result_of<F(A0p, A1p, A2p)>::type type;
};
template <typename F, typename A0, typename A1, typename A2, typename A3>
struct result<F(A0,A1,A2,A3)> {
typedef typename Conv_wp_to_p<A0>::type A0p;
typedef typename Conv_wp_to_p<A1>::type A1p;
typedef typename Conv_wp_to_p<A2>::type A2p;
typedef typename Conv_wp_to_p<A3>::type A3p;
typedef typename cpp11::result_of<F(A0p, A1p, A2p, A3p)>::type type;
};
public:
Regular_traits_adaptor_2 (const ConstructPoint& cp, const Functor& f)
: cp(cp), f(f)
{ }
typename cpp11::result_of<Functor(Triangle_2)>::type operator() (const Triangle_2& t) const
{
return f(t);
}
typename cpp11::result_of< Functor(Point_2,Point_2) >::type operator() (const Point_2& p0, const Point_2& p1) const
{
return f(p0, p1);
}
typename cpp11::result_of< Functor(Point_2,Point_2, Point_2) >::type operator() (const Point_2& p0, const Point_2& p1, const Point_2& p2) const
{
return f(p0, p1, p2);
}
typename cpp11::result_of< Functor(Point_2,Point_2, Point_2,Point_2) >::type operator() (const Point_2& p0, const Point_2& p1, const Point_2& p2, const Point_2& p3) const
{
return f(p0, p1, p2, p3);
}
typename cpp11::result_of< Functor(Point_2,Origin) >::type operator() (const Point_2& p0, const Origin& o) const
{
return f(p0, o);
}
typename cpp11::result_of< Functor(Point_2,Origin) >::type operator() (const Origin& o, const Point_2& p0) const
{
return f(o, p0);
}
typename cpp11::result_of< Functor(Segment_2,Point_2) >::type operator() (const Segment_2& pl, const Point_2& p) const
{
return f(pl, p);
}
typename cpp11::result_of< Functor(Point_2,Point_2) >::type operator() (const Weighted_point_2& p0, const Weighted_point_2& p1) const
{
return f(cp(p0), cp(p1));
}
typename cpp11::result_of< Functor(Point_2,Point_2) >::type operator() (const Point_2& p0, const Weighted_point_2& p1) const
{
return f(p0, cp(p1));
}
typename cpp11::result_of< Functor(Point_2,Point_2) >::type operator() (const Weighted_point_2& p0, const Point_2& p1) const
{
return f(cp(p0), p1);
}
typename cpp11::result_of<Functor(Segment_2,Point_2)>::type operator() (const Segment_2& p0, const Weighted_point_2& p1) const
{
return f(p0, cp(p1));
}
typename cpp11::result_of<Functor(Point_2,Point_2,Point_2)>::type operator() (const Weighted_point_2& p0, const Weighted_point_2& p1,
const Weighted_point_2& p2) const
{
return f(cp(p0), cp(p1), cp(p2));
}
typename cpp11::result_of<Functor(Point_2,Point_2,Point_2,Point_2)>::type operator() (const Weighted_point_2& p0, const Weighted_point_2& p1,
const Weighted_point_2& p2, const Weighted_point_2& p3) const
{
return f(cp(p0), cp(p1), cp(p2), cp(p3));
}
typename cpp11::result_of<Functor(Point_2,Point_2,Point_2)>::type operator() (const Weighted_point_2& p0, const Weighted_point_2& p1,
const Point_2& p2) const
{
return f(cp(p0), cp(p1), p2);
}
typename cpp11::result_of<Functor(Point_2,Point_2,Point_2,Point_2)>::type operator() (const Weighted_point_2& p0, const Weighted_point_2& p1,
const Weighted_point_2& p2, const Point_2& p3) const
{
return f(cp(p0), cp(p1), cp(p2), p3);
}
typename cpp11::result_of<Functor(Point_2,Point_2,Point_2)>::type operator() (const Point_2& p0, const Weighted_point_2& p1,
const Weighted_point_2& p2) const
{
return f(p0, cp(p1), cp(p2));
}
typename cpp11::result_of<Functor(Point_2,Point_2,Point_2,FT)>::type operator() (const Weighted_point_2& p0, const Weighted_point_2& p1,
const Weighted_point_2& p2, const Weighted_point_2& p3,
const FT w) const
{
return f(cp(p0), cp(p1), cp(p2), cp(p3), w);
}
};
} // namespace CGAL
#endif /* CGAL_REGULAR_TRAITS_ADAPTOR_2_H */

View File

@ -57,22 +57,140 @@ struct Weighted_point_mapper_2
Weighted_point_mapper_2(const K_& k) : K_(k) {}
};
namespace internal {
template < typename K_ >
struct RegTraits_2
: public K_
{
typedef typename K_::Construct_point_2 Construct_point_2_base;
typedef typename K_::Construct_segment_2 Construct_segment_2_base;
typedef typename K_::Construct_triangle_2 Construct_triangle_2_base;
typedef typename K_::Construct_vector_2 Construct_vector_2_base;
typedef typename K_::Equal_2 Equal_2_base;
typedef typename K_::Compare_x_2 Compare_x_2_base;
typedef typename K_::Compare_y_2 Compare_y_2_base;
typedef typename K_::Orientation_2 Orientation_2_base;
typedef typename K_::Construct_circumcenter_2 Construct_circumcenter_2_base;
typedef typename K_::Less_x_2 Less_x_2_base;
typedef typename K_::Less_y_2 Less_y_2_base;
Construct_point_2_base cp;
RegTraits_2() {}
RegTraits_2(const K_& k)
: K_(k), cp(k.construct_point_2_object())
{}
typedef Regular_traits_adaptor_2<K_,
Construct_point_2_base,
Equal_2_base > Equal_2;
typedef Regular_traits_adaptor_2<K_,
Construct_point_2_base,
Construct_vector_2_base > Construct_vector_2;
typedef Regular_traits_adaptor_2<K_,
Construct_point_2_base,
Compare_x_2_base > Compare_x_2;
typedef Regular_traits_adaptor_2<K_,
Construct_point_2_base,
Compare_y_2_base > Compare_y_2;
typedef Regular_traits_adaptor_2<K_,
Construct_point_2_base,
Orientation_2_base > Orientation_2;
typedef Regular_traits_adaptor_2<K_,
Construct_point_2_base,
Construct_circumcenter_2_base > Construct_circumcenter_2;
typedef Regular_traits_adaptor_2<K_,
Construct_point_2_base,
Construct_triangle_2_base > Construct_triangle_2;
typedef Regular_traits_adaptor_2<K_,
Construct_point_2_base,
Construct_segment_2_base > Construct_segment_2;
typedef Regular_traits_adaptor_2<K_,
Construct_point_2_base,
Less_x_2_base > Less_x_2;
typedef Regular_traits_adaptor_2<K_,
Construct_point_2_base,
Less_y_2_base > Less_y_2;
Construct_vector_2 construct_vector_2_object() const
{
return Construct_vector_2(cp, static_cast<const K_&>(*this).construct_vector_2_object());
}
Construct_triangle_2 construct_triangle_2_object() const
{
return Construct_triangle_2(cp, static_cast<const K_&>(*this).construct_triangle_2_object());
}
Construct_segment_2 construct_segment_2_object() const
{
return Construct_segment_2(cp, static_cast<const K_&>(*this).construct_segment_2_object());
}
Equal_2 equal_2_object() const
{
return Equal_2(cp, static_cast<const K_&>(*this).equal_2_object());
}
Compare_x_2 compare_x_2_object() const
{
return Compare_x_2(cp, static_cast<const K_&>(*this).compare_x_2_object());
}
Compare_y_2 compare_y_2_object() const
{
return Compare_y_2(cp, static_cast<const K_&>(*this).compare_y_2_object());
}
Orientation_2 orientation_2_object() const
{
return Orientation_2(cp, static_cast<const K_&>(*this).orientation_2_object());
}
Construct_circumcenter_2 construct_circumcenter_2_object() const
{
return Construct_circumcenter_2(cp, static_cast<const K_&>(*this).construct_circumcenter_2_object());
}
Less_x_2 less_x_2_object() const
{
return Less_x_2(cp, static_cast<const K_&>(*this).less_x_2_object());
}
Less_y_2 less_y_2_object() const
{
return Less_y_2(cp, static_cast<const K_&>(*this).less_y_2_object());
}
};
} // namespace internal
template < class Gt,
class Tds = Triangulation_data_structure_2 <
Regular_triangulation_vertex_base_2<Gt>,
Regular_triangulation_face_base_2<Gt> > >
class Regular_triangulation_2
: public Triangulation_2<
Weighted_point_mapper_2<Gt>,
Weighted_point_mapper_2<internal::RegTraits_2<Gt> >,
Tds>
{
typedef Regular_triangulation_2<Gt, Tds> Self;
typedef Weighted_point_mapper_2<Gt> RT_traits;
typedef Triangulation_2<RT_traits, Tds> Base;
typedef Regular_triangulation_2<Gt, Tds> Self;
typedef Weighted_point_mapper_2<internal::RegTraits_2<Gt> > RT_traits;
typedef Triangulation_2<RT_traits, Tds> Base;
public:
typedef Self Triangulation;
typedef Tds Triangulation_data_structure;
typedef Gt Geom_traits;
typedef internal::RegTraits_2<Gt> Geom_traits;
typedef typename boost::mpl::eval_if_c<
internal::Has_nested_type_Bare_point<Gt>::value,
typename internal::Bare_point_type<Gt>,
@ -80,7 +198,7 @@ public:
>::type Bare_point;
typedef typename Gt::Weighted_point_2 Weighted_point;
typedef typename Gt::FT Weight;
typedef typename Gt::Construct_weighted_point_2 Construct_weighted_point_2;
typedef typename Base::size_type size_type;
typedef typename Base::Face_handle Face_handle;
typedef typename Base::Vertex_handle Vertex_handle;
@ -120,6 +238,7 @@ public:
using Base::OUTSIDE_CONVEX_HULL;
using Base::orientation;
using Base::locate;
using Base::inexact_locate;
using Base::incident_faces;
using Base::is_infinite;
using Base::degree;
@ -129,6 +248,7 @@ public:
using Base::mirror_index;
using Base::show_vertex;
using Base::test_dim_down;
using Base::oriented_side;
#endif
private:
@ -243,6 +363,46 @@ public:
return _hidden_vertices;
}
// Overloads for Bare_point
Face_handle
inexact_locate(const Bare_point& bp,
Face_handle start = Face_handle()) const
{
return Base::inexact_locate(geom_traits().construct_weighted_point_2_object()(bp), start);
}
Face_handle
locate(const Bare_point& bp,
Locate_type& lt,
int& li,
Face_handle start = Face_handle()) const
{
return Base::locate(geom_traits().construct_weighted_point_2_object()(bp), lt, li, start);
}
Face_handle
locate(const Bare_point& bp)
{
return Base::locate(geom_traits().construct_weighted_point_2_object()(bp));
}
Line_face_circulator line_walk(const Bare_point& p,
const Bare_point& q,
Face_handle f = Face_handle()) const
{
return Base::line_walk(this->geom_traits().construct_weighted_point_2_object()(p),
this->geom_traits().construct_weighted_point_2_object()(q),
f);
}
Oriented_side
oriented_side(Face_handle f, const Bare_point &p) const
{
return Base::oriented_side(f, geom_traits().construct_weighted_point_2_object()(p));
}
// CHECK - QUERY
Oriented_side power_test(const Weighted_point &p,

View File

@ -47,7 +47,7 @@ _test_is_to_the_left( const Triangulation &T,
{
return( T.orientation(f->vertex(f->ccw(li))->point(),
f->vertex(f->cw(li))->point(),
p) == CGAL::LEFT_TURN );
typename Triangulation::Weighted_point(p)) == CGAL::LEFT_TURN );
}
template <class Triangulation>
@ -372,16 +372,16 @@ _test_cls_regular_triangulation_2( const Triangulation & )
T1_3_2.insert(wp9);
T1_3_2.is_valid(verbose);
loc = T1_3_2.locate(p1,lt,li); assert( lt == Cls::VERTEX );
assert( T1_3_2.xy_equal(loc->vertex(li)->point(), p1) );
assert( T1_3_2.xy_equal(loc->vertex(li)->point(), wp1) );
loc = T1_3_2.locate(p2,lt,li); assert( lt == Cls::VERTEX );
assert( T1_3_2.xy_equal(loc->vertex(li)->point(), p2) );
assert( T1_3_2.xy_equal(loc->vertex(li)->point(), wp2) );
loc = T1_3_2.locate(p9,lt,li); assert( lt == Cls::VERTEX );
assert( T1_3_2.xy_equal(loc->vertex(li)->point(), p9) );
assert( T1_3_2.xy_equal(loc->vertex(li)->point(), wp9) );
loc = T1_3_2.locate(p3,lt,li); assert( lt == Cls::EDGE );
assert( (T1_3_2.xy_equal(loc->vertex(loc->ccw(li))->point().point(), p1)
&& T1_3_2.xy_equal(loc->vertex(loc->cw(li))->point().point(), p2))
|| (T1_3_2.xy_equal(loc->vertex(loc->ccw(li))->point().point(), p2)
&& T1_3_2.xy_equal(loc->vertex(loc->cw(li))->point().point(), p1)));
assert( (T1_3_2.xy_equal(loc->vertex(loc->ccw(li))->point(), wp1)
&& T1_3_2.xy_equal(loc->vertex(loc->cw(li))->point(), wp2))
|| (T1_3_2.xy_equal(loc->vertex(loc->ccw(li))->point(), wp2)
&& T1_3_2.xy_equal(loc->vertex(loc->cw(li))->point(), wp1)));
loc = T1_3_2.locate(p8,lt,li); assert( lt == Cls::OUTSIDE_CONVEX_HULL );
loc = T1_3_2.locate(p7,lt,li); assert( lt == Cls::OUTSIDE_AFFINE_HULL );
loc = T1_3_2.locate(p5,lt,li); assert( lt == Cls::OUTSIDE_AFFINE_HULL );
@ -392,32 +392,32 @@ _test_cls_regular_triangulation_2( const Triangulation & )
// Check point location in 2-dimensional triangulations
std::cout << " point locations 2-dim" << std::endl;
loc = T2_3.locate(p0,lt,li); assert( lt == Cls::VERTEX );
assert( T2_3.xy_equal(loc->vertex(li)->point().point(), p0) );
assert( T2_3.xy_equal(loc->vertex(li)->point(), wp0) );
loc = T2_3.locate(p1,lt,li); assert( lt == Cls::VERTEX );
assert( T2_3.xy_equal(loc->vertex(li)->point().point(), p1) );
assert( T2_3.xy_equal(loc->vertex(li)->point(), wp1) );
loc = T2_3.locate(p2,lt,li); assert( lt == Cls::VERTEX );
assert( T2_3.xy_equal(loc->vertex(li)->point().point(), p2) );
assert( T2_3.xy_equal(loc->vertex(li)->point(), wp2) );
loc = T2_3.locate(p4,lt,li); assert( lt == Cls::VERTEX );
assert( T2_3.xy_equal(loc->vertex(li)->point().point(), p4) );
assert( T2_3.xy_equal(loc->vertex(li)->point(), wp4) );
loc = T2_3.locate(p5,lt,li); assert( lt == Cls::VERTEX );
assert( T2_3.xy_equal(loc->vertex(li)->point().point(), p5) );
assert( T2_3.xy_equal(loc->vertex(li)->point(), wp5) );
loc = T2_3.locate(p6,lt,li); assert( lt == Cls::VERTEX );
assert( T2_3.xy_equal(loc->vertex(li)->point().point(), p6) );
assert( T2_3.xy_equal(loc->vertex(li)->point(), wp6) );
loc = T2_3.locate(p7,lt,li); assert( lt == Cls::VERTEX );
assert( T2_3.xy_equal(loc->vertex(li)->point().point(), p7) );
assert( T2_3.xy_equal(loc->vertex(li)->point(), wp7) );
loc = T2_3.locate(p8,lt,li); assert( lt == Cls::VERTEX );
assert( T2_3.xy_equal(loc->vertex(li)->point().point(), p8) );
assert( T2_3.xy_equal(loc->vertex(li)->point(), wp8) );
loc = T2_3.locate(p10,lt,li); assert( lt == Cls::VERTEX );
assert( T2_3.xy_equal(loc->vertex(li)->point().point(), p10) );
assert( T2_3.xy_equal(loc->vertex(li)->point(), wp10) );
loc = T2_3.locate(p3,lt,li); assert( lt == Cls::EDGE );
loc = T2_3.locate(p9,lt,li); assert( lt == Cls::EDGE );
loc = T2_3.locate(p11,lt,li); assert( lt == Cls::EDGE);
assert( (T2_3.xy_equal(loc->vertex(loc->ccw(li))->point().point(), p1)
&& T2_3.xy_equal(loc->vertex(loc->cw(li))->point().point(), p0))
|| (T2_3.xy_equal(loc->vertex(loc->ccw(li))->point().point(), p0)
&& T2_3.xy_equal(loc->vertex(loc->cw(li))->point().point(), p1)));
assert( (T2_3.xy_equal(loc->vertex(loc->ccw(li))->point(), wp1)
&& T2_3.xy_equal(loc->vertex(loc->cw(li))->point(), wp0))
|| (T2_3.xy_equal(loc->vertex(loc->ccw(li))->point(), wp0)
&& T2_3.xy_equal(loc->vertex(loc->cw(li))->point(), wp1)));
loc = T2_3.locate(p12,lt,li); assert( lt == Cls::FACE );
assert( T2_3.oriented_side(loc,p12) == CGAL::ON_POSITIVE_SIDE );
loc = T2_3.locate(p13,lt,li,loc); assert( lt == Cls::OUTSIDE_CONVEX_HULL );
@ -443,7 +443,7 @@ _test_cls_regular_triangulation_2( const Triangulation & )
loc = T2_3_1.locate(p12,lt,li); assert( lt == Cls::FACE );
assert( T2_3_1.oriented_side(loc,p12) == CGAL::ON_POSITIVE_SIDE );
assert( T2_3_1.power_test(loc,p12) == CGAL::ON_NEGATIVE_SIDE);
assert( T2_3_1.power_test(loc,wp12) == CGAL::ON_NEGATIVE_SIDE);
T2_3_1.insert(wp12); //hidden in face
T2_3_1.is_valid(verbose);
@ -537,10 +537,10 @@ _test_cls_regular_triangulation_2( const Triangulation & )
--fc;
// testing with dummy triangulations
Cls T2_8;
T2_8.insert(Bare_point(0,0,1));
T2_8.insert(Bare_point(1,0,1));
T2_8.insert(Bare_point(0,1,1));
T2_8.insert(Bare_point(1,1,1));
T2_8.insert(Weighted_point(Bare_point(0,0,1)));
T2_8.insert(Weighted_point(Bare_point(1,0,1)));
T2_8.insert(Weighted_point(Bare_point(0,1,1)));
T2_8.insert(Weighted_point(Bare_point(1,1,1)));
int n=0;
do {fc2++ ; n = n+1;} while (fc2 != fc);
assert(T2_8.number_of_vertices()>=2);
@ -553,10 +553,10 @@ _test_cls_regular_triangulation_2( const Triangulation & )
assert(n==4);
// the two point are vertices of the triangulation.
Cls TT;
TT.insert(Bare_point(0,0));
TT.insert(Bare_point(1,0));
TT.insert(Bare_point(1,1));
TT.insert(Bare_point(0,1));
TT.insert(Weighted_point(Bare_point(0,0)));
TT.insert(Weighted_point(Bare_point(1,0)));
TT.insert(Weighted_point(Bare_point(1,1)));
TT.insert(Weighted_point(Bare_point(0,1)));
assert(TT.dimension()==2);
assert(TT.is_valid(verbose));
assert(TT.number_of_vertices()==4);