added kernel with template; demos work with both kernels now (see precompiler parameter)

This commit is contained in:
Iordan Iordanov 2018-02-26 11:08:01 +01:00
parent 3440d43796
commit 6aff91506e
7 changed files with 1615 additions and 78 deletions

View File

@ -2,12 +2,20 @@
// CGAL headers
#include <CGAL/Exact_circular_kernel_2.h>
#include <CGAL/Hyperbolic_Delaunay_triangulation_CK_traits_2.h>
#define USE_CORE_EXPR_KERNEL
#ifndef USE_CORE_EXPR_KERNEL
#include <CGAL/Exact_circular_kernel_2.h>
#include <CGAL/Hyperbolic_Delaunay_triangulation_CK_traits_2.h>
#include <CGAL/Qt/HyperbolicPainterOstreamCK.h>
#else
#include <CGAL/Cartesian.h>
#include <CGAL/CORE_Expr.h>
#include <CGAL/Hyperbolic_Delaunay_triangulation_traits_2.h>
#include <CGAL/Qt/HyperbolicPainterOstream.h>
#endif
#include <CGAL/Hyperbolic_Delaunay_triangulation_2.h>
#include <CGAL/Qt/HyperbolicPainterOstream.h>
#include <CGAL/point_generators_2.h>
// Qt headers
@ -37,9 +45,15 @@
#include "ui_Hyperbolic_triangulation_2_demo.h"
//typedef CGAL::Exact_predicates_exact_constructions_kernel R;
typedef CGAL::Exact_circular_kernel_2 R;
typedef CGAL::Hyperbolic_Delaunay_triangulation_CK_traits_2<R> K;
#ifndef USE_CORE_EXPR_KERNEL
typedef CGAL::Exact_circular_kernel_2 R;
typedef CGAL::Hyperbolic_Delaunay_triangulation_CK_traits_2<R> K;
#else
typedef CORE::Expr NT;
typedef CGAL::Cartesian<NT> R;
typedef CGAL::Hyperbolic_Delaunay_triangulation_traits_2<R> K;
#endif
typedef K::Point_2 Point_2;
typedef K::Iso_rectangle_2 Iso_rectangle_2;

View File

@ -1,13 +1,21 @@
#include <fstream>
// CGAL headers
#include <CGAL/Exact_circular_kernel_2.h>
#include <CGAL/Hyperbolic_Delaunay_triangulation_CK_traits_2.h>
#define USE_CORE_EXPR_KERNEL
#ifndef USE_CORE_EXPR_KERNEL
#include <CGAL/Exact_circular_kernel_2.h>
#include <CGAL/Hyperbolic_Delaunay_triangulation_CK_traits_2.h>
#include <CGAL/Qt/HyperbolicPainterOstreamCK.h>
#else
#include <CGAL/Cartesian.h>
#include <CGAL/CORE_Expr.h>
#include <CGAL/Hyperbolic_Delaunay_triangulation_traits_2.h>
#include <CGAL/Qt/HyperbolicPainterOstream.h>
#endif
#include <CGAL/Triangulation_vertex_base_with_info_2.h>
#include <CGAL/Hyperbolic_Delaunay_triangulation_2.h>
#include <CGAL/Qt/HyperbolicPainterOstream.h>
#include <CGAL/point_generators_2.h>
// Qt headers
@ -54,8 +62,15 @@
#include "ui_Hyperbolic_triangulation_2_demo.h"
typedef CGAL::Exact_circular_kernel_2 R;
typedef CGAL::Hyperbolic_Delaunay_triangulation_CK_traits_2<R> K;
#ifndef USE_CORE_EXPR_KERNEL
typedef CGAL::Exact_circular_kernel_2 R;
typedef CGAL::Hyperbolic_Delaunay_triangulation_CK_traits_2<R> K;
#else
typedef CORE::Expr NT;
typedef CGAL::Cartesian<NT> R;
typedef CGAL::Hyperbolic_Delaunay_triangulation_traits_2<R> K;
#endif
typedef K::Point_2 Point_2;
typedef Point_2 Point;
@ -105,7 +120,7 @@ void apply_unique_words(std::vector<Point>& points, Point input = Point(0, 0), d
pair<double, double> res;
for(size_t i = 0; i < unique_words.size(); i++) {
pair<double, double> res;
res = unique_words[i].apply(to_double(input.x()), to_double(input.y()));
res = unique_words[i].apply(CGAL::to_double(input.x()), CGAL::to_double(input.y()));
double dist = res.first*res.first + res.second*res.second;
if(dist < d) {
@ -148,7 +163,7 @@ void apply_unique_words_G(std::vector<Point>& points, Point input = Point(0, 0),
for(size_t i = 0; i < indices.size(); i++) {
pair<double, double> res;
if(indices[i] < unique_words.size() /*&& unique_words[indices[i]].length() < 13.*/) {
res = unique_words[indices[i]].apply(to_double(input.x()), to_double(input.y()));
res = unique_words[indices[i]].apply(CGAL::to_double(input.x()), CGAL::to_double(input.y()));
points.push_back(Point(res.first, res.second));
}
}

View File

@ -0,0 +1,166 @@
// Copyright (c) 2017 INRIA Nancy - Grand Est (France).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you may redistribute it under
// the terms of the Q Public License version 1.0.
// See the file LICENSE.QPL distributed with CGAL.
//
// 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) : Iordan Iordanov
//
//
#ifndef CGAL_EXACT_COMPLEX_H
#define CGAL_EXACT_COMPLEX_H
#include <iostream>
#include <CGAL/assertions.h>
#include <CGAL/number_utils.h>
// Complex number in the form a + bi, where a and b are of type NT.
// NT must be an exact number type, model of:
// + FieldWithRootOf
// + RealEmbeddable
// + FromDoubleConstructible
//
namespace CGAL {
template <class NumberType>
class Exact_complex {
typedef Exact_complex<NumberType> Self;
private:
NumberType _a, _b;
public:
typedef NumberType NT;
Exact_complex() :
_a(0), _b(0) {}
Exact_complex(NT a, NT b) :
_a(a), _b(b) {}
NT real() const {
return _a;
}
void set_real(NT val) {
_a = val;
}
NT imag() const {
return _b;
}
void set_imag(NT val) {
_b = val;
}
Self conj() const {
return Self(_a, -_b);
}
NT square_modulus() const {
return (_a*_a + _b*_b);
}
NT modulus() const {
return CGAL::sqrt(this->square_modulus());
}
Self reciprocal() {
NT denom = _a*_a + _b*_b;
if (denom == NT(0)) {
return Self(0,0);
} else {
return Self(_a/denom, -_b/denom);
}
}
Self invert_in_unit_circle() {
return this->reciprocal().conj();
}
template <class Circle_2>
Self invert_in_circle(Circle_2 c) {
NT r2 = c.squared_radius();
NT xc = c.center().x();
NT yc = c.center().y();
NT denom = (_a - xc)*(_a - xc) + (_b - yc)*(_b - yc);
return Self(xc + r2*(_a-xc)/denom, yc + r2*(_b-yc)/denom);
}
Self operator+(const Self& other) const {
return Self(this->_a + other._a, this->_b + other._b);
}
Self operator-(const Self& other) const {
return Self(this->_a - other._a, this->_b - other._b);
}
Self operator*(const Self& other) const {
NT rp = _a*other._a - _b*other._b;
NT ip = _b*other._a + _a*other._b;
return Self(rp, ip);
}
Self operator/(const Self& other) const {
NT denom = other._a*other._a + other._b*other._b;
CGAL_assertion(denom != 0);
NT rp = _a*other._a + _b*other._b;
NT ip = _b*other._a - _a*other._b;
return Self(rp/denom, ip/denom);
}
};
template <class NT>
std::ostream& operator<<(std::ostream& s, const Exact_complex<NT>& c) {
s << c.real() << (c.imag() >= 0 ? " + " : " - ") << abs(c.imag()) << "i";
return s;
}
// just to give an ordering
template<class NT>
bool operator==( const Exact_complex<NT>& lh,
const Exact_complex<NT>& rh)
{
return (lh.real() == rh.real() && lh.imag() == rh.imag());
}
template<class NT>
bool operator!=( const Exact_complex<NT>& lh,
const Exact_complex<NT>& rh)
{
return !operator==(lh, rh);
}
// just to give an ordering
template<class NT>
bool operator<( const Exact_complex<NT>& lh,
const Exact_complex<NT>& rh)
{
return lh.square_modulus() < rh.square_modulus();
}
} // namespace CGAL
#endif // CGAL_EXACT_COMPLEX_H

View File

@ -64,7 +64,7 @@ public:
typedef Gt Geom_traits;
typedef typename Geom_traits::FT FT;
typedef typename Geom_traits::Point_2 Point;
typedef typename Geom_traits::Circular_arc_point_2 Circular_arc_point;
//typedef typename Geom_traits::Circular_arc_point_2 Circular_arc_point;
typedef typename Geom_traits::Hyperbolic_segment_2 Hyperbolic_segment;
Hyperbolic_Delaunay_triangulation_2(const Gt& gt = Gt())
@ -477,7 +477,8 @@ public:
Finite_edges_iterator finite_edges_begin() const { return hyperbolic_edges_begin(); }
Finite_edges_iterator finite_edges_end() const { return hyperbolic_edges_end(); }
Circular_arc_point
//Circular_arc_point
Point
dual(Face_handle f) const
{
CGAL_triangulation_precondition (!this->is_non_hyperbolic(f));

View File

@ -1,10 +1,9 @@
// Copyright (c) 2011-2016 INRIA Sophia Antipolis, INRIA Nancy (France).
// Copyright (c) 2011 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.
// This file is part of CGAL (www.cgal.org); you may redistribute it under
// the terms of the Q Public License version 1.0.
// See the file LICENSE.QPL distributed with CGAL.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
@ -12,77 +11,111 @@
// 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:
// $URL: svn+ssh://mbogdanov@scm.gforge.inria.fr/svn/cgal/trunk/Triangulation_2/include/CGAL/Triangulation_hyperbolic_traits_2.h $
// $Id: Triangulation_hyperbolic_traits_2.h 57323 2010-07-05 10:07:39Z sloriot $
//
//
// Author(s) : Monique Teillaud <Monique.Teillaud@inria.fr>
// Mikhail Bogdanov
// Author(s) : Mikhail Bogdanov
#ifndef CGAL_HYPERBOLIC_PAINTER_OSTREAM_H
#define CGAL_HYPERBOLIC_PAINTER_OSTREAM_H
#include <CGAL/Qt/PainterOstream.h>
#include <CGAL/Hyperbolic_Delaunay_triangulation_traits_2.h>
namespace CGAL{
namespace Qt {
template <typename K>
class PainterOstream<Hyperbolic_Delaunay_triangulation_CK_traits_2<K> >
: public PainterOstream<K>
{
public:
typedef PainterOstream<K> Base;
typedef Hyperbolic_Delaunay_triangulation_CK_traits_2<K> Gt;
typedef PainterOstream<Gt> Self;
typedef typename Gt::Hyperbolic_segment_2 Hyperbolic_segment_2;
class PainterOstream< Hyperbolic_Delaunay_triangulation_traits_2<K> > : public PainterOstream<K> {
typedef typename Gt::Point_2 Point_2;
typedef Line_arc_2<K> Line_arc_2;
typedef Circular_arc_2<K> Circular_arc_2;
typedef Circular_arc_point_2<K> Circular_arc_point_2;
PainterOstream(QPainter* p, QRectF rect = QRectF())
: Base(p, rect), qp(p), convert(rect)
{}
using Base::operator <<;
PainterOstream& operator << (Hyperbolic_segment_2 s)
{
if (const Line_arc_2* seg = boost::get<Line_arc_2>(&s)) {
operator << (*seg);
typedef PainterOstream<K> Base;
typedef PainterOstream< Hyperbolic_Delaunay_triangulation_traits_2<K> > Self;
typedef Hyperbolic_Delaunay_triangulation_traits_2<K> Gt;
typedef typename Gt::Hyperbolic_segment_2 Hyperbolic_segment_2;
typedef typename Gt::Circular_arc_2 Circular_arc_2;
typedef typename Gt::Euclidean_segment_2 Euclidean_segment_2;
typedef typename Gt::Point_2 Point_2;
private:
PainterOstream& operator<<(const Circular_arc_2& arc) {
const typename K::Circle_2 & circ = arc.circle();
const typename K::Point_2 & center = circ.center();
const typename K::Point_2 & source = arc.source();
const typename K::Point_2 & target = arc.target();
double ds = CGAL::to_double(sqrt(source.x()*source.x() + source.y()*source.y()));
double dt = CGAL::to_double(sqrt(target.x()*target.x() + target.y()*target.y()));
double asource = std::atan2( -to_double(source.y() - center.y()),
to_double(source.x() - center.x()));
double atarget = std::atan2( -to_double(target.y() - center.y()),
to_double(target.x() - center.x()));
std::swap(asource, atarget);
double aspan = atarget - asource;
if(aspan < 0.)
aspan += 2 * CGAL_PI;
const double coeff = 180*16/CGAL_PI;
qp->drawArc(convert(circ.bbox()),
(int)(asource * coeff),
(int)(aspan * coeff));
return *this;
}
PainterOstream& operator<<(const Euclidean_segment_2& seg) {
const typename K::Point_2 & source = seg.source();
const typename K::Point_2 & target = seg.target();
double ds = CGAL::to_double(sqrt(source.x()*source.x() + source.y()*source.y()));
double dt = CGAL::to_double(sqrt(target.x()*target.x() + target.y()*target.y()));
QPointF src(to_double(source.x()), to_double(source.y()));
QPointF tgt(to_double(target.x()), to_double(target.y()));
qp->drawLine(src, tgt);
return *this;
}
public:
PainterOstream(QPainter* p, QRectF rect = QRectF())
: Base(p, rect), qp(p), convert(rect) {}
using Base::operator <<;
PainterOstream& operator << (Hyperbolic_segment_2 s) {
if (const Euclidean_segment_2* seg = boost::get<Euclidean_segment_2>(&s)) {
operator << (*seg);
return *this;
}
Circular_arc_2* arc = boost::get<Circular_arc_2>(&s);
if (arc->squared_radius() > 100) {
Euclidean_segment_2 seg(arc->source(), arc->target());
operator << (seg);
return *this;
}
operator << (*arc);
return *this;
}
Circular_arc_2* arc = boost::get<Circular_arc_2>(&s);
if (arc->squared_radius() > 10 )
// due to rounding, the arc drawn does not look like it
// passes through the endpoints
// so we replace the arc by a line segment
{
Point_2 source(to_double(arc->source().x()),to_double(arc->source().y()));
Point_2 target(to_double(arc->target().x()),to_double(arc->target().y()));
const Line_arc_2 seg(source,target);
operator << (seg);
return *this;
}
operator << (*arc);
return *this;
}
private:
// ToDo: These objects must be deleted
// Copies of these objects are in the base class.
// We need access to the copies in the base class.
QPainter* qp;
Converter<K> convert;
};
// ToDo: These objects must be deleted
// Copies of these objects are in the base class.
// We need access to the copies in the base class.
QPainter* qp;
Converter<K> convert;
};
} //namespace Qt

View File

@ -0,0 +1,92 @@
// Copyright (c) 2011-2016 INRIA Sophia Antipolis, INRIA Nancy (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@inria.fr>
// Mikhail Bogdanov
#ifndef CGAL_HYPERBOLIC_PAINTER_OSTREAM_H
#define CGAL_HYPERBOLIC_PAINTER_OSTREAM_H
#include <CGAL/Qt/PainterOstream.h>
namespace CGAL{
namespace Qt {
template <typename K>
class PainterOstream<Hyperbolic_Delaunay_triangulation_CK_traits_2<K> >
: public PainterOstream<K>
{
public:
typedef PainterOstream<K> Base;
typedef Hyperbolic_Delaunay_triangulation_CK_traits_2<K> Gt;
typedef PainterOstream<Gt> Self;
typedef typename Gt::Hyperbolic_segment_2 Hyperbolic_segment_2;
typedef typename Gt::Point_2 Point_2;
typedef Line_arc_2<K> Line_arc_2;
typedef Circular_arc_2<K> Circular_arc_2;
typedef Circular_arc_point_2<K> Circular_arc_point_2;
PainterOstream(QPainter* p, QRectF rect = QRectF())
: Base(p, rect), qp(p), convert(rect)
{}
using Base::operator <<;
PainterOstream& operator << (Hyperbolic_segment_2 s)
{
if (const Line_arc_2* seg = boost::get<Line_arc_2>(&s)) {
operator << (*seg);
return *this;
}
Circular_arc_2* arc = boost::get<Circular_arc_2>(&s);
if (arc->squared_radius() > 10 )
// due to rounding, the arc drawn does not look like it
// passes through the endpoints
// so we replace the arc by a line segment
{
Point_2 source(to_double(arc->source().x()),to_double(arc->source().y()));
Point_2 target(to_double(arc->target().x()),to_double(arc->target().y()));
const Line_arc_2 seg(source,target);
operator << (seg);
return *this;
}
operator << (*arc);
return *this;
}
private:
// ToDo: These objects must be deleted
// Copies of these objects are in the base class.
// We need access to the copies in the base class.
QPainter* qp;
Converter<K> convert;
};
} //namespace Qt
} //namespace CGAL
#endif // CGAL_HYPERBOLIC_PAINTER_OSTREAM_H