/usr/include/CGAL/Delaunay_d.h is in libcgal-dev 4.2-5ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 | // Copyright (c) 1997-2000 Max-Planck-Institute Saarbruecken (Germany).
// 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) : Michael Seel <seel@mpi-sb.mpg.de>
//---------------------------------------------------------------------
// file generated by notangle from delaunay.lw
// please debug or modify LEDA web file
// mails and bugs: Michael.Seel@mpi-sb.mpg.de
// based on LEDA architecture by S. Naeher, C. Uhrig
// coding: K. Mehlhorn, M. Seel
// debugging and templatization: M. Seel
//---------------------------------------------------------------------
#ifndef CGAL_DELAUNAY_D_H
#define CGAL_DELAUNAY_D_H
/*{\Manpage {Delaunay_d}{R,Lifted_R}{Delaunay Triangulations}{DT}}*/
/*{\Mdefinition
An instance |\Mvar| of type |\Mname| is the nearest and furthest
site Delaunay triangulation of a set |S| of points in some
$d$-dimensional space. We call |S| the underlying point set and $d$ or
|dim| the dimension of the underlying space. We use |dcur| to denote
the affine dimension of |S|. The data type supports incremental
construction of Delaunay triangulations and various kind of query
operations (in particular, nearest and furthest neighbor queries and
range queries with spheres and simplices).
A Delaunay triangulation is a simplicial complex. All simplices in
the Delaunay triangulation have dimension |dcur|. In the nearest site
Delaunay triangulation the circumsphere of any simplex in the
triangulation contains no point of $S$ in its interior. In the
furthest site Delaunay triangulation the circumsphere of any simplex
contains no point of $S$ in its exterior. If the points in $S$ are
co-circular then any triangulation of $S$ is a nearest as well as a
furthest site Delaunay triangulation of $S$. If the points in $S$ are
not co-circular then no simplex can be a simplex of both
triangulations. Accordingly, we view |\Mvar| as either one or two
collection(s) of simplices. If the points in $S$ are co-circular there
is just one collection: the set of simplices of some triangulation.
If the points in $S$ are not co-circular there are two
collections. One collection consists of the simplices of a nearest
site Delaunay triangulation and the other collection consists of the
simplices of a furthest site Delaunay triangulation.
For each simplex of maximal dimension there is a handle of type
|Simplex_handle| and for each vertex of the triangulation there is a
handle of type |Vertex_handle|. Each simplex has |1 + dcur| vertices
indexed from $0$ to |dcur|. For any simplex $s$ and any index $i$,
|DT.vertex_of(s,i)| returns the $i$-th vertex of $s$. There may or may
not be a simplex $t$ opposite to the vertex of $s$ with index $i$.
The function |DT.opposite_simplex(s,i)| returns $t$ if it exists and
returns |Simplex_handle()| otherwise. If $t$ exists then $s$ and $t$
share |dcur| vertices, namely all but the vertex with index $i$ of $s$
and the vertex with index
|DT.index_of_vertex_in_opposite_simplex(s,i)| of $t$. Assume that $t
= |DT.opposite_simplex(s,i)|$ exists and let $j =
|DT.index_of_vertex_in_opposite_simplex(s,i)|$. Then |s =
DT.opposite_simplex(t,j)| and |i =
DT.index_of_vertex_in_opposite_simplex(t,j)|. In general, a vertex
belongs to many simplices.
Any simplex of |\Mvar| belongs either to the nearest or to the
furthest site Delaunay triangulation or both. The test
|DT.simplex_of_nearest(dt_simplex s)| returns true if |s| belongs to
the nearest site triangulation and the test
|DT.simplex_of_furthest(dt_simplex s)| returns true if |s| belongs to
the furthest site triangulation.
}*/
#include <CGAL/Unique_hash_map.h>
#include <CGAL/Convex_hull_d.h>
namespace CGAL {
template <typename R_, typename Lifted_R_ = R_>
class Delaunay_d : public Convex_hull_d<Lifted_R_>
{
typedef Delaunay_d<R_,Lifted_R_> Self;
typedef Convex_hull_d<Lifted_R_> Base;
using Base::origin_simplex_;
public:
using Base::associate_vertex_with_simplex;
using Base::dcur;
using Base::hyperplane_supporting;
using Base::visited_mark;
using Base::is_bounded_simplex;
using Base::is_unbounded_simplex;
using Base::clear_visited_marks;
using Base::is_dimension_jump;
using Base::point_of_simplex;
using Base::point_of_facet;
using Base::vertex_of_facet;
/*{\Mgeneralization Convex_hull_d<Lifted_R>}*/
/*{\Mtypes 7}*/
typedef R_ R;
typedef Lifted_R_ Lifted_R;
typedef typename Base::Simplex_handle Simplex_handle;
/*{\Mtypemember handles to the simplices of the complex.}*/
typedef typename Base::Vertex_handle Vertex_handle;
/*{\Mtypemember handles to vertices of the complex.}*/
typedef typename Base::Simplex_const_handle Simplex_const_handle;
typedef typename Base::Vertex_const_handle Vertex_const_handle;
class Simplex_iterator;
class Simplex_const_iterator;
friend class Simplex_iterator;
friend class Simplex_const_iterator;
typedef typename R::Point_d Point_d;
/*{\Mtypemember the point type}*/
typedef typename R::Sphere_d Sphere_d;
/*{\Mtypemember the sphere type}*/
typedef typename R::FT FT;
typedef typename Lifted_R::Point_d Lifted_point_d;
typedef typename Lifted_R::Vector_d Lifted_vector_d;
typedef typename Lifted_R::Hyperplane_d Lifted_hyperplane_d;
typedef typename Lifted_R::RT RT;
enum Delaunay_voronoi_kind { NEAREST, FURTHEST };
/*{\Menum interface flags}*/
/*{\Mtext To use these types you can typedef them into the global
scope after instantiation of the class. We use |Vertex_handle| instead
of |\Mname::Vertex_handle| from now on. Similarly we use
|Simplex_handle|.}*/
private:
enum type_of_S { unknown, non_cocircular, cocircular };
type_of_S ts;
const R& Delaunay_kernel_;
enum type_of_facet { lower_hull, upper_hull, vertical };
type_of_facet type_of(typename Base::Facet_const_handle f) const
/*{\Xop returns the type of the facet $f$.}*/
{ typename Lifted_R::Orthogonal_vector_d ortho =
lifted_kernel().orthogonal_vector_d_object();
Lifted_vector_d normal = ortho(hyperplane_supporting(f));
typename Lifted_R::Component_accessor_d access =
lifted_kernel().component_accessor_d_object();
int d = CGAL_NTS sign(
access.homogeneous(normal,access.dimension(normal)-1));
if (d > 0) return upper_hull;
if (d < 0) return lower_hull;
return vertical;
}
type_of_facet type_of(typename Base::Facet_handle f) const
{ return type_of(static_cast<typename Base::Facet_const_handle>(f)); }
bool incident_simplex_search(Vertex_handle v, Simplex_handle s) const;
public:
typedef typename Base::Point_const_iterator Point_const_iterator;
/*{\Mtypemember the iterator for points.}*/
typedef typename Base::Vertex_iterator Vertex_iterator;
/*{\Mtypemember the iterator for vertices.}*/
typedef typename Base::Simplex_iterator CH_simplex_iterator;
typedef typename Base::Simplex_const_iterator CH_simplex_const_iterator;
class Simplex_iterator
/*{\Mtypemember the iterator for simplices.}*/
: public CH_simplex_iterator
{
typedef Delaunay_d<R,Lifted_R> Delaunay;
typedef CH_simplex_iterator Base_iterator;
Delaunay* DT;
type_of_facet tf;
Base_iterator base() { return Base_iterator(*this); }
public:
Simplex_iterator(Base_iterator y = Base_iterator()) :
Base_iterator(y) {}
Simplex_iterator(Delaunay* x, Base_iterator y,
Delaunay_voronoi_kind z = NEAREST) : Base_iterator(y), DT(x)
/* if the facet is not nil we set the current marker to
the facet and insert all it's neighbors into the
candidates stack */
{ CGAL_assertion(base() != Base_iterator());
tf = (z == NEAREST ? lower_hull : upper_hull);
bool cocirc = DT->is_S_cocircular();
// Note [Sylvain,2007-03-08] : I added some parentheses to fix a warning,
// I hope I got the logic right.
// Note: I have add a new pair of parentheses. Laurent Rineau, 2010/08/20
while ( base() != DT->simplices_end() &&
!( ( cocirc && DT->is_bounded_simplex(base()) ) ||
( ( !cocirc && DT->is_unbounded_simplex(base()) ) &&
DT->type_of(base()) == tf ) ) ) {
Base_iterator::operator++();
}
}
Simplex_iterator(const Simplex_iterator& it) : Base_iterator(it) {}
Simplex_iterator& operator++()
/* here we get a new candidate from the stack
and insert all its not-visited neighbors */
{
bool cocirc = DT->is_S_cocircular();
do {
Base_iterator::operator++();
// Note [Sylvain,2007-03-08] : I added some parentheses to fix a warning,
// I hope I got the logic right.
// Note: I have add a new pair of parentheses. Laurent Rineau, 2010/08/20
} while ( base() != DT->simplices_end() &&
!( ( cocirc && DT->is_bounded_simplex(base()) ) ||
( ( !cocirc && DT->is_unbounded_simplex(base()) ) &&
DT->type_of(base()) == tf ) ) );
return *this;
}
Simplex_iterator operator++(int)
{ Simplex_iterator tmp = *this; ++(*this); return tmp; }
// change modus:
typedef std::forward_iterator_tag iterator_category;
private:
Simplex_iterator operator--(int);
Simplex_iterator& operator--();
}; // Simplex_iterator
class Simplex_const_iterator : public CH_simplex_const_iterator {
typedef Delaunay_d<R,Lifted_R> Delaunay;
typedef CH_simplex_const_iterator Base_iterator;
const Delaunay* DT;
type_of_facet tf;
Base_iterator base() { return Base_iterator(*this); }
public:
Simplex_const_iterator(Base_iterator y = Base_iterator()) :
Base_iterator(y) {}
Simplex_const_iterator(const Delaunay* x, Base_iterator y,
Delaunay_voronoi_kind z = NEAREST) : Base_iterator(y), DT(x)
/* if the facet is not nil we set the current marker to
the facet and insert all it's neighbors into the
candidates stack */
{ CGAL_assertion(base() != Base_iterator());
tf = (z == NEAREST ? lower_hull : upper_hull);
bool cocirc = const_cast<Delaunay*>(DT)->is_S_cocircular();
while ( (base() != DT->simplices_end()) &&
!( (cocirc && DT->is_bounded_simplex(base())) ||
(!cocirc && DT->is_unbounded_simplex(base()) &&
DT->type_of(base()) == tf ) ) ) {
Base_iterator::operator++();
}
}
Simplex_const_iterator(const Simplex_const_iterator& it) :
Base_iterator(it) {}
Simplex_const_iterator& operator++()
/* here we get a new candidate from the stack
and insert all its not-visited neighbors */
{
bool cocirc = const_cast<Delaunay*>(DT)->is_S_cocircular();
do {
Base_iterator::operator++();
} while ( (base() != DT->simplices_end()) &&
!( (cocirc && DT->is_bounded_simplex(base())) ||
(!cocirc && DT->is_unbounded_simplex(base()) &&
DT->type_of(base()) == tf ) ) );
return *this;
}
Simplex_const_iterator operator++(int)
{ Simplex_iterator tmp = *this; ++(*this); return tmp; }
// change modus:
typedef std::forward_iterator_tag iterator_category;
private:
Simplex_const_iterator operator--(int);
Simplex_const_iterator& operator--();
}; // Simplex_iterator
void project(Regular_complex_d<R>& RC, int which = -1) const;
/*{\Xop projects the upper (|which = 1|) or lower (|which = -1|) hull
into regular complex |RC|. }*/
bool is_S_cocircular();
/*{\Xop returns |true| if the points of |S| are cocircular and returns
|false| otherwise}*/
/*{\Mcreation 3}*/
Delaunay_d(int d, const R& k1 = R(), const Lifted_R& k2 = Lifted_R())
/*{\Mcreate creates an instance |\Mvar| of type |\Mtype|. The
dimension of the underlying space is $d$ and |S| is initialized to the
empty point set. The traits class |R| specifies the models of
all types and the implementations of all geometric primitives used by
the Delaunay class. The traits class |Lifted_R| specifies the models of
all types and the implementations of all geometric primitives used by
the base class of |\Mname|. The second template parameter defaults to
the first: |Delaunay_d<R> = Delaunay_d<R, Lifted_R = R >|.}*/
: Base(d+1,k2), Delaunay_kernel_(k1) { ts = unknown; }
/*{\Mtext Both template arguments have to be models that fit a
subset of requirements of the d-dimensional kernel. We list them at
the end of this manual page.}*/
const R& kernel() const { return Delaunay_kernel_; }
const R& lifted_kernel() const { return Base::kernel(); }
private:
/*{\Mtext The data type |\Mtype| offers neither copy constructor nor
assignment operator.}*/
Delaunay_d(const Self&);
Self& operator=(const Self&);
public:
/*{\Moperations 3 3}*/
/*{\Mtext All operations below that take a point |x| as an argument
have the common precondition that $|x.dimension()| = |\Mvar.dimension()|$.}*/
int dimension() const
/*{\Mop returns the dimension of ambient space}*/
{ return (Base::dimension() - 1); }
int current_dimension() const
/*{\Mop returns the affine dimension of the current point set, i.e.,
$-1$ is $S$ is empty, $0$ if $S$ consists of a single point,
$1$ if all points of $S$ lie on a common line, etcetera.}*/
{ int d = Base::current_dimension();
if (d == -1) return d;
return ( const_cast<Self*>(this)->is_S_cocircular() ? d : d-1 );
}
bool is_simplex_of_nearest(Simplex_handle s) const
/*{\Mop returns true if |s| is a simplex of the nearest site
triangulation.}*/
{ if ( const_cast<Self*>(this)->is_S_cocircular() ) return true;
return ( type_of(s) == lower_hull );
}
bool is_simplex_of_furthest(Simplex_handle s) const
/*{\Mop returns true if |s| is a simplex of the furthest site
triangulation.}*/
{ if ( const_cast<Self*>(this)->is_S_cocircular() ) return true;
return (type_of(s) == upper_hull);
}
bool is_simplex_of_nearest(Simplex_const_handle s) const
{ if ( const_cast<Self*>(this)->is_S_cocircular() ) return true;
return ( type_of(s) == lower_hull );
}
bool is_simplex_of_furthest(Simplex_const_handle s) const
{ if ( const_cast<Self*>(this)->is_S_cocircular() ) return true;
return (type_of(s) == upper_hull);
}
Vertex_handle vertex_of_simplex(Simplex_handle s, int i) const
/*{\Mop returns the vertex associated with the $i$-th node of $s$.
\precond $0 \leq i \leq |dcur|$. }*/
{ if ( const_cast<Self*>(this)->is_S_cocircular() )
return Base::vertex_of_simplex(s,i);
else
return Base::vertex_of_simplex(s,i+1);
}
Vertex_const_handle vertex_of_simplex(Simplex_const_handle s,
int i) const
{ if ( const_cast<Self*>(this)->is_S_cocircular() )
return Base::vertex_of_simplex(s,i);
else
return Base::vertex_of_simplex(s,i+1);
}
Point_d associated_point(Vertex_handle v) const
/*{\Mop returns the point associated with vertex $v$.}*/
{ typename Lifted_R::Project_along_d_axis_d project =
lifted_kernel().project_along_d_axis_d_object();
return project(Base::associated_point(v)); }
Point_d associated_point(Vertex_const_handle v) const
{ typename Lifted_R::Project_along_d_axis_d project =
lifted_kernel().project_along_d_axis_d_object();
return project(Base::associated_point(v)); }
Point_d point_of_simplex(Simplex_handle s,int i) const
/*{\Mop returns the point associated with the $i$-th vertex of $s$.
\precond $0 \leq i \leq |dcur|$. }*/
{ return associated_point(vertex_of_simplex(s,i)); }
Point_d point_of_simplex(Simplex_const_handle s,int i) const
{ return associated_point(vertex_of_simplex(s,i)); }
Simplex_handle opposite_simplex(Simplex_handle s, int i) const
/*{\Mop returns the simplex opposite to the $i$-th vertex of $s$
(|Simplex_handle()| if there is no such simplex).
\precond $0 \leq i \leq |dcur|$. }*/
{
if ( const_cast<Self*>(this)->is_S_cocircular() ) {
Simplex_handle f = Base::opposite_simplex(s,i);
return ( Base::is_unbounded_simplex(f) ?
Simplex_handle() : f );
} else {
Simplex_handle f = Base::opposite_simplex(s,i+1);
return ( type_of(f) == type_of(s) ? f : Simplex_handle() );
}
}
Simplex_const_handle opposite_simplex(Simplex_const_handle s,
int i) const
{
if ( const_cast<Self*>(this)->is_S_cocircular() ) {
Simplex_const_handle f = Base::opposite_simplex(s,i);
return ( Base::is_unbounded_simplex(f) ?
Simplex_const_handle() : f );
} else {
Simplex_const_handle f = Base::opposite_simplex(s,i+1);
return ( type_of(f) == type_of(s) ? f : Simplex_const_handle() );
}
}
int index_of_vertex_in_opposite_simplex(Simplex_handle s,int i) const
/*{\Mop returns the index of the vertex opposite to the $i$-th vertex
of $s$. \precond $0 \leq i \leq |dcur|$.}*/
{
if ( const_cast<Self*>(this)->is_S_cocircular() )
return Base::index_of_vertex_in_opposite_simplex(s,i);
else
return Base::index_of_vertex_in_opposite_simplex(s,i+1) - 1;
}
int index_of_vertex_in_opposite_simplex(Simplex_const_handle s,
int i) const
{
if ( const_cast<Self*>(this)->is_S_cocircular() )
return Base::index_of_vertex_in_opposite_simplex(s,i);
else
return Base::index_of_vertex_in_opposite_simplex(s,i+1) - 1;
}
Simplex_handle simplex(Vertex_handle v) const;
/*{\Mop returns a simplex of the nearest site triangulation incident
to $v$.}*/
int index(Vertex_handle v) const;
/*{\Mop returns the index of $v$ in |\Mvar.simplex(v)|.}*/
bool contains(Simplex_handle s, const Point_d& x) const;
/*{\Mop returns true if |x| is contained in the closure of simplex |s|.}*/
bool empty() const
/*{\Mop decides whether |\Mvar| is empty.}*/
{ return (current_dimension() == -1); }
void clear()
/*{\Mop reinitializes |\Mvar| to the empty Delaunay triangulation.}*/
{ int d = dimension(); Base::clear(d + 1);
ts = unknown;
}
Vertex_handle insert(const Point_d& x)
/*{\Mop inserts point $x$ into |\Mvar| and returns the corresponding
|Vertex_handle|. More precisely, if there is already a vertex |v| in
|\Mvar| positioned at $x$ (i.e., |associated_point(v)| is equal to
|x|) then |associated_point(v)| is changed to |x| (i.e.,
|associated_point(v)| is made identical to |x|) and if there is no
such vertex then a new vertex $v$ with |associated_point(v) = x| is
added to |\Mvar|. In either case, $v$ is returned.}*/
{ ts = unknown;
typename Lifted_R::Lift_to_paraboloid_d lift =
lifted_kernel().lift_to_paraboloid_d_object();
return Base::insert(lift(x));
}
Simplex_handle locate(const Point_d& x) const;
/*{\Mop returns a simplex of the nearest site triangulation
containing |x| in its closure (returns |Simplex_handle()| if |x| lies
outside the convex hull of $S$).}*/
Vertex_handle lookup(const Point_d& x) const
/*{\Mop if |\Mvar| contains a vertex $v$ with |associated_point(v) = x|
the result is $v$ otherwise the result is |Vertex_handle()|. }*/
{
Simplex_handle s = locate(x);
if ( s == Simplex_handle() ) return Vertex_handle();
for (int i = 0; i <= current_dimension(); i++) {
Vertex_handle v = vertex_of_simplex(s,i);
if (v!=this->anti_origin_ && x == associated_point(v) ) return v;
}
return Vertex_handle();
}
Vertex_handle nearest_neighbor(const Point_d& x) const;
/*{\Mop computes a vertex $v$ of |\Mvar| that is closest to $x$,
i.e.,\\ $|dist(x,associated_point(v))| = \min \{
|dist(x, associated_point(u))| \mid u \in S\ \}$.}*/
/*{\Mtext \setopdims{5cm}{1cm}}*/
std::list<Vertex_handle>
range_search(const Sphere_d& C) const;
/*{\Mop returns the list of all vertices contained in the closure of
sphere $C$.}*/
std::list<Vertex_handle>
range_search(const std::vector<Point_d>& A) const;
/*{\Mop returns the list of all vertices contained in the closure of
the simplex whose corners are given by |A|.
\precond |A| must consist of $d+1$ affinely independent points
in base space.}*/
void all_vertices_below(const Lifted_hyperplane_d& h,
Simplex_handle s,
std::list<Vertex_handle>& result,
Unique_hash_map<Vertex_handle,bool>& is_new,
bool is_cocircular) const;
std::list<Simplex_handle>
all_simplices(Delaunay_voronoi_kind k = NEAREST) const;
/*{\Mop returns a list of all simplices of either the nearest or the
furthest site Delaunay triangulation of |S|.}*/
std::list<Vertex_handle>
all_vertices(Delaunay_voronoi_kind k = NEAREST) const;
/*{\Mop returns a list of all vertices of either the nearest or the
furthest site Delaunay triangulation of |S|.}*/
std::list<Point_d> all_points() const;
/*{\Mop returns $S$. }*/
Point_const_iterator points_begin() const
/*{\Mop returns the start iterator for points in |\Mvar|.}*/
{ return Point_const_iterator(Base::points_begin()); }
Point_const_iterator points_end() const
/*{\Mop returns the past the end iterator for points in |\Mvar|.}*/
{ return Point_const_iterator(Base::points_end()); }
Simplex_iterator simplices_begin(Delaunay_voronoi_kind k = NEAREST)
/*{\Mop returns the start iterator for simplices of |\Mvar|.}*/
{ return Simplex_iterator(this,Base::simplices_begin(),k); }
Simplex_iterator simplices_end()
/*{\Mop returns the past the end iterator for simplices of |\Mvar|.}*/
{ return Simplex_iterator(Base::simplices_end()); }
Simplex_const_iterator
simplices_begin(Delaunay_voronoi_kind k = NEAREST) const
{ return Simplex_const_iterator(this,Base::simplices_begin(),k); }
Simplex_const_iterator simplices_end() const
{ return Simplex_const_iterator(Base::simplices_end()); }
/*{\Mimplementation The data type is derived from |Convex_hull_d| via
the lifting map. For a point $x$ in $d$-dimensional space let
|lift(x)| be its lifting to the unit paraboloid of revolution. There
is an intimate relationship between the Delaunay triangulation of a
point set $S$ and the convex hull of |lift(S)|: The nearest site
Delaunay triangulation is the projection of the lower hull and the
furthest site Delaunay triangulation is the upper hull. For
implementation details we refer the reader to the implementation
report available from the CGAL server.
The space requirement is the same as for convex hulls. The time
requirement for an insert is the time to insert the lifted point
into the convex hull of the lifted points.}*/
/*{\Mexample
The abstract data type |Delaunay_d| has a default instantiation by
means of the $d$-dimensional geometric kernel.
\begin{Mverb}
#include <CGAL/Homogeneous_d.h>
#include <CGAL/leda_integer.h>
#include <CGAL/Delaunay_d.h>
typedef leda_integer RT;
typedef CGAL::Homogeneous_d<RT> Kernel;
typedef CGAL::Delaunay_d<Kernel> Delaunay_d;
typedef Delaunay_d::Point_d Point;
typedef Delaunay_d::Simplex_handle Simplex_handle;
typedef Delaunay_d::Vertex_handle Vertex_handle;
int main()
{
Delaunay_d T(2);
Vertex_handle v1 = T.insert(Point_d(2,11));
...
}
\end{Mverb}
}*/
/*{\Mtext\headerline{Traits requirements}
|\Mname| requires the following types from the kernel traits |Lifted_R|:
\begin{Mverb}
RT Point_d Vector_d Ray_d Hyperplane_d
\end{Mverb}
and uses the following function objects from the kernel traits:
\begin{Mverb}
Construct_hyperplane_d
Construct_vector_d
Vector_to_point_d / Point_to_vector_d
Orientation_d
Orthogonal_vector_d
Oriented_side_d / Has_on_positive_side_d
Affinely_independent_d
Contained_in_simplex_d
Contained_in_affine_hull_d
Intersect_d
Lift_to_paraboloid_d / Project_along_d_axis_d
Component_accessor_d
\end{Mverb}
|\Mname| requires the following types from the kernel traits |R|:
\begin{Mverb}
FT Point_d Sphere_d
\end{Mverb}
and uses the following function objects from the kernel traits |R|:
\begin{Mverb}
Construct_sphere_d
Squared_distance_d
Point_of_sphere_d
Affinely_independent_d
Contained_in_simplex_d
\end{Mverb}
}*/
}; // Delaunay_d<R,Lifted_R>
template <typename R, typename Lifted_R>
void Delaunay_d<R,Lifted_R>::project(Regular_complex_d<R>& RC, int which) const
{
RC.clear(dimension());
Delaunay_voronoi_kind k = (which == -1 ? NEAREST : FURTHEST);
Unique_hash_map<Simplex_const_handle, Simplex_handle > project_simps;
Unique_hash_map<Vertex_const_handle, Vertex_handle > project_verts;
int dc = current_dimension();
RC.set_current_dimension(dc);
Simplex_const_iterator f;
for(f = simplices_begin(k); f != simplices_end(); ++f) {
Simplex_handle s = project_simps[f] = RC.new_simplex();
for (int i = 0; i <= dc; i++) {
Vertex_const_handle v = vertex_of_simplex(f,i);
Vertex_handle pv = project_verts[v];
if ( pv == Vertex_handle() ) {
Point_d x = associated_point(v);
pv = project_verts[v] = RC.new_vertex(x);
}
RC.associate_vertex_with_simplex(s,i,pv);
}
}
/* in a second pass we set up neighbor connections */
Simplex_iterator s,t;
for(f = simplices_begin(k); f != simplices_end(); ++f) {
s = project_simps[f];
if ( s != Simplex_handle() ) {
for (int i = 0; i <= dc; i++) {
t = project_simps[opposite_simplex(f,i)];
if ( dc > 0 && t != Simplex_handle() ) {
RC.set_neighbor(s,i,t,
index_of_vertex_in_opposite_simplex(f,i));
}
}
}
}
}
template <typename R, typename Lifted_R>
bool Delaunay_d<R,Lifted_R>::is_S_cocircular()
{
if (ts == unknown) {
int d = Base::current_dimension();
std::vector<Lifted_point_d> A(d + 1);
typename Lifted_R::Project_along_d_axis_d project =
lifted_kernel().project_along_d_axis_d_object();
for (int i = 0; i <= d; i++)
A[i] = project( Base::point_of_simplex(origin_simplex_,i));
typename Lifted_R::Affinely_independent_d affinely_independent =
lifted_kernel().affinely_independent_d_object();
ts = ( affinely_independent(A.begin(),A.end()) ?
cocircular : non_cocircular );
if ( d == -1 && ts != cocircular )
CGAL_error_msg( "affinely independent works incorrectly for empty set");
}
return (ts == cocircular);
}
template <typename R, typename Lifted_R>
bool Delaunay_d<R,Lifted_R>::
incident_simplex_search(Vertex_handle v, Simplex_handle s) const
{
visited_mark(s) = true;
if ( const_cast<Self*>(this)->is_S_cocircular() ==
is_bounded_simplex(s) ) {
// we have found a simplex of the desired kind
int low = ( is_unbounded_simplex(s) ? 1 : 0 );
for ( int i = low; i <= Base::current_dimension(); i++) {
if ( v == Base::vertex_of_simplex(s,i) ) {
const_cast<Self*>(this)->associate_vertex_with_simplex(s,i,v);
return true;
}
}
CGAL_error_msg( "Delaunay_d::incident_simplex_search: unreachable point.");
}
/* s does not have the desired kind; we visit all neighbors except
the one opposite v */
bool incident = false;
register int j;
for (j = 0; j <= dcur; j++)
if ( Base::vertex_of_simplex(s,j) == v ) incident = true;
if ( !incident )
CGAL_error_msg("reached a simplex that is not incident to v");
for (j = 0; j <= Base::current_dimension(); j++) {
Simplex_handle t = Base::opposite_simplex(s,j);
if ( Base::vertex_of_simplex(s,j) != v && !visited_mark(t) &&
incident_simplex_search(v,t) )
return true;
}
return false;
}
template <typename R, typename Lifted_R>
typename Delaunay_d<R,Lifted_R>::Simplex_handle
Delaunay_d<R,Lifted_R>::simplex(Vertex_handle v) const
{
Simplex_handle s = Base::simplex(v);
if ( Base::vertex_of_simplex(s,Base::index(v)) != v )
CGAL_error_msg("Delaunay_d::simplex: s is not incident to v.");
incident_simplex_search(v,s);
clear_visited_marks(s);
return Base::simplex(v);
}
template <typename R, typename Lifted_R>
int Delaunay_d<R,Lifted_R>::index(Vertex_handle v) const
{ simplex(v);
int i = Base::index(v);
return ( const_cast<Self*>(this)->is_S_cocircular() ? i : i-1);
}
template <typename R, typename Lifted_R>
bool Delaunay_d<R,Lifted_R>::
contains(Simplex_handle s, const Point_d& x) const
{ int d = current_dimension();
if (d < 0) return false;
std::vector<Point_d> A;
A.reserve(d + 1);
for (int i = 0; i <= d; i++){
Vertex_handle vh = vertex_of_simplex(s,i);
if (vh!=this->anti_origin_)
A.push_back( associated_point(vh) );
}
typename R::Contained_in_simplex_d contained_in_simplex =
kernel().contained_in_simplex_d_object();
return contained_in_simplex(A.begin(),A.end(),x);
}
template <typename R, typename Lifted_R>
typename Delaunay_d<R,Lifted_R>::Simplex_handle
Delaunay_d<R,Lifted_R>::
locate(const Point_d& x) const
{
int d = current_dimension();
if (d < 0) return Simplex_handle();
if ( d == 0 ) {
if ( x == point_of_simplex(origin_simplex_,0) )
return origin_simplex_;
else
return Simplex_handle();
}
typename Lifted_R::Lift_to_paraboloid_d lift =
lifted_kernel().lift_to_paraboloid_d_object();;
Lifted_point_d lp = lift(x);
if ( is_dimension_jump(lp) ) {
Simplex_iterator s;
for (s = const_cast<Self*>(this)->simplices_begin(NEAREST);
s != const_cast<Self*>(this)->simplices_end(); ++s)
if ( contains(s,x) ) return s;
return Simplex_handle();
}
// lift(p) is not a dimension jump
std::list<Simplex_handle> candidates;
std::size_t dummy1 = 0;
int loc = -1; // intialization is important
Simplex_handle f;
this -> visibility_search(origin_simplex_,lp,candidates,dummy1,loc,f);
this -> clear_visited_marks(origin_simplex_);
//f and simplices in candidates are unbounded simplices only
if ( f != Simplex_handle() ){
return f;
}
typename std::list<Simplex_handle>::iterator it;
for(it = candidates.begin(); it != candidates.end(); ++it)
if ( contains(*it,x) ) return *it;
return Simplex_handle();
}
template <typename R, typename Lifted_R>
typename Delaunay_d<R,Lifted_R>::Vertex_handle
Delaunay_d<R,Lifted_R>::
nearest_neighbor(const Point_d& x) const
{
int d = current_dimension();
if (d < 0) return Vertex_handle();
if (d == 0)
return Base::vertex_of_simplex(origin_simplex_,0);
typename Lifted_R::Lift_to_paraboloid_d lift =
lifted_kernel().lift_to_paraboloid_d_object();;
Lifted_point_d lp = lift(x);
std::list<Simplex_handle> candidates;
if ( is_dimension_jump(lp) )
candidates = all_simplices(NEAREST);
else {
// lift(x) is not a dimension jump
std::size_t dummy1 = 0;
int location = -1;
typename Base::Facet_handle f;
this -> visibility_search(origin_simplex_,lp,candidates,dummy1,location,f);
this -> clear_visited_marks(origin_simplex_);
CGAL_assertion_msg( location != -1,
"Delaunay_d::nearest_neighbor: location cannot be -1");
if (location == 0) {
// x must be one of the corners of f
for (int i = 0; i < Base::current_dimension(); i++) {
if ( point_of_facet(f,i) == lp )
return vertex_of_facet(f,i);
}
CGAL_error_msg("Delaunay_d::nearest_neighbor: \
if loc = 1 then lp must be corner of f");
}
}
/* search through the vertices of the candidate simplices */
if ( candidates.empty() )
CGAL_error_msg("Delaunay_d::nearest_neighbor: candidates is empty");
Vertex_handle nearest_v =
vertex_of_simplex(*candidates.begin(),0);
typename R::Squared_distance_d sqr_dist =
kernel().squared_distance_d_object();
FT min_dist = sqr_dist(x,associated_point(nearest_v));
typename std::list<Simplex_handle>::iterator it;
for(it=candidates.begin(); it!=candidates.end(); ++it) {
for (int i = 0; i <= d ; i++) {
typename R::Squared_distance_d sqr_dist =
kernel().squared_distance_d_object();
FT sidist = sqr_dist(x,point_of_simplex(*it,i));
if ( sidist < min_dist ) {
min_dist = sidist ;
nearest_v = vertex_of_simplex(*it,i);
}
}
}
return nearest_v;
}
template <typename R, typename Lifted_R>
void Delaunay_d<R,Lifted_R>::
all_vertices_below(const Lifted_hyperplane_d& h,
Simplex_handle s,
std::list< Vertex_handle >& result,
Unique_hash_map<Vertex_handle,bool>& is_new,
bool is_cocircular) const
{
visited_mark(s) = true;
bool some_vertex_on_or_below_h = false;
register int i;
int low = (is_cocircular ? 0 : 1);
for (i = low; i <= Base::current_dimension(); i++) {
Vertex_handle v = Base::vertex_of_simplex(s,i);
typename Lifted_R::Oriented_side_d side =
lifted_kernel().oriented_side_d_object();
if ( !(side(h, Base::associated_point(v)) == ON_POSITIVE_SIDE) ) {
some_vertex_on_or_below_h = true;
if ( is_new[v] ) {
result.push_back(v);
is_new[v] = false;
}
}
}
if ( !some_vertex_on_or_below_h ) return;
for (i = low; i <= Base::current_dimension(); i++) {
Simplex_handle t = Base::opposite_simplex(s,i);
if ( !visited_mark(t) &&
(!is_cocircular || is_bounded_simplex(t)) )
all_vertices_below(h,t,result,is_new,is_cocircular);
}
}
template <typename R, typename Lifted_R>
std::list< typename Delaunay_d<R,Lifted_R>::Vertex_handle >
Delaunay_d<R,Lifted_R>::
range_search(const Sphere_d& C) const
{
std::list<Vertex_handle> result;
int dc = current_dimension();
if ( dc < 0 )
return result;
Point_d c = C.center();
Vertex_handle v = nearest_neighbor(c);
if ( dc == 0 ) {
if ( C.has_on_bounded_side(associated_point(v)) )
result.push_back(v); return result;
}
Simplex_handle s = simplex(v);
bool is_cocircular = const_cast<Self*>(this)->is_S_cocircular();
Unique_hash_map<Vertex_handle,bool> is_new(true);
int d = dimension();
std::vector<Lifted_point_d> P(d + 1);
typename Lifted_R::Lift_to_paraboloid_d lift =
lifted_kernel().lift_to_paraboloid_d_object();
typename R::Point_of_sphere_d point_of_sphere =
kernel().point_of_sphere_d_object();
for (int i = 0; i <= d; i++)
P[i] = lift(point_of_sphere(C,i));
typedef typename Lifted_vector_d::Base_vector Base_vector;
Lifted_point_d o = P[0] -
Lifted_vector_d(d+1,Base_vector(),d);
typename Lifted_R::Construct_hyperplane_d hyperplane_trough =
lifted_kernel().construct_hyperplane_d_object();
Lifted_hyperplane_d h =
hyperplane_trough(P.begin(),P.end(),o,ON_NEGATIVE_SIDE);
// below is negative
all_vertices_below(h,s,result,is_new,is_cocircular);
clear_visited_marks(s);
return result;
}
template <typename R, typename Lifted_R>
std::list< typename Delaunay_d<R,Lifted_R>::Vertex_handle >
Delaunay_d<R,Lifted_R>::
range_search(const std::vector<Point_d>& A) const
{
typename R::Affinely_independent_d affinely_independent =
kernel().affinely_independent_d_object();
CGAL_assertion_msg( affinely_independent(A.begin(),A.end()),
"Delaunay_d::range_search: simplex must be affinely independent.");
typename R::Construct_sphere_d sphere_through =
kernel().construct_sphere_d_object();
Sphere_d C = sphere_through(dimension(),A.begin(),A.end());
std::list<Vertex_handle> result;
std::list<Vertex_handle> candidates = range_search(C);
typename R::Contained_in_simplex_d contained_in_simplex =
kernel().contained_in_simplex_d_object();
typename std::list<Vertex_handle>::iterator it;
for(it = candidates.begin(); it != candidates.end(); ++it) {
if ( contained_in_simplex(A.begin(),A.end(),associated_point(*it)) )
result.push_back(*it);
}
return result;
}
template <typename R, typename Lifted_R>
std::list< typename Delaunay_d<R,Lifted_R>::Simplex_handle >
Delaunay_d<R,Lifted_R>::
all_simplices(Delaunay_voronoi_kind k) const
{
std::list<Simplex_handle> result;
if ( dcur < 0 ) return result;
Simplex_iterator s;
for (s = const_cast<Self*>(this)->simplices_begin(k);
s != const_cast<Self*>(this)->simplices_end(); ++s) {
result.push_back(s);
}
return result;
}
template <typename R, typename Lifted_R>
std::list< typename Delaunay_d<R,Lifted_R>::Vertex_handle >
Delaunay_d<R,Lifted_R>::
all_vertices(Delaunay_voronoi_kind k) const
{
Unique_hash_map<Vertex_handle,bool> is_new_vertex(true);
std::list<Vertex_handle> result;
std::list<Simplex_handle> hull_simplices = all_simplices(k);
typename std::list<Simplex_handle>::iterator it;
for (it = hull_simplices.begin(); it != hull_simplices.end(); ++it) {
for (int i = 0; i <= current_dimension(); i++) {
Vertex_handle v = vertex_of_simplex(*it,i);
if ( is_new_vertex[v] ) {
is_new_vertex[v] = false;
result.push_back(v);
}
}
}
return result;
}
template <typename R, typename Lifted_R>
std::list< typename Delaunay_d<R,Lifted_R>::Point_d >
Delaunay_d<R,Lifted_R>::
all_points() const
{
std::list<Point_d> result;
std::list<Vertex_handle> all_nearest_verts = all_vertices(NEAREST);
typename std::list<Vertex_handle>::iterator it;
for(it = all_nearest_verts.begin();
it != all_nearest_verts.end();
++it)
result.push_back(associated_point(*it));
return result;
}
} //namespace CGAL
#endif // CGAL_DELAUNAY_D_H
|