/usr/include/CGAL/Apollonius_graph_2.h is in libcgal-dev 4.7-4.
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 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 | // Copyright (c) 2003,2004 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) : Menelaos Karavelas <mkaravel@iacm.forth.gr>
#ifndef CGAL_APOLLONIUS_GRAPH_2_H
#define CGAL_APOLLONIUS_GRAPH_2_H
#define CGAL_APOLLONIUS_GRAPH_PSEUDO_CIRCLE_DESIGN 1
#include <iostream>
#include <vector>
#include <map>
#include <boost/tuple/tuple.hpp>
#include <CGAL/Apollonius_graph_2/basic.h>
#include <CGAL/Triangulation_2.h>
#include <CGAL/Triangulation_data_structure_2.h>
#include <CGAL/Triangulation_face_base_2.h>
#include <CGAL/Apollonius_graph_vertex_base_2.h>
#include <CGAL/in_place_edge_list.h>
#include <CGAL/Segment_Delaunay_graph_2/edge_list.h>
#include <CGAL/Apollonius_graph_2/Traits_wrapper_2.h>
#include <CGAL/Apollonius_graph_2/Constructions_C2.h>
#include <CGAL/iterator.h>
#include <CGAL/Iterator_project.h>
#include <CGAL/Nested_iterator.h>
#include <CGAL/Concatenate_iterator.h>
namespace CGAL {
namespace internal {
template<typename Edge, typename LTag> struct AG2_which_list;
// use the in-place edge list
template<typename E>
struct AG2_which_list<E,Tag_true>
{
typedef E Edge;
typedef In_place_edge_list<Edge> List;
};
// do not use the in-place edge list
template<typename E>
struct AG2_which_list<E,Tag_false>
{
typedef E Edge;
// change the following to Tag_false in order to use
// CGAL's Unique_hash_map
typedef Tag_true Use_stl_map_tag;
typedef Edge_list<Edge,Use_stl_map_tag> List;
};
template < class Node >
struct Project_site_2 {
typedef Node argument_type;
typedef typename Node::Site_2 Site;
typedef Site result_type;
Site& operator()( Node& x) const { return x.site(); }
const Site& operator()( const Node& x) const { return x.site(); }
};
} // namespace internal
template<class Gt,class Agds,class LTag>
class Apollonius_graph_hierarchy_2;
template < class Gt,
class Agds = Triangulation_data_structure_2 <
Apollonius_graph_vertex_base_2<Gt,true>,
Triangulation_face_base_2<Gt> >,
class LTag = Tag_false>
class Apollonius_graph_2
: private Triangulation_2
<CGAL_APOLLONIUS_GRAPH_2_NS::Apollonius_graph_traits_wrapper_2<Gt>,Agds>
{
friend class Apollonius_graph_hierarchy_2<Gt,Agds,LTag>;
private:
// types and access methods needed for visualization
//--------------------------------------------------
// types
typedef CGAL_APOLLONIUS_GRAPH_2_NS::Construct_Apollonius_bisector_2<Gt>
Construct_Apollonius_bisector_2;
typedef CGAL_APOLLONIUS_GRAPH_2_NS::Construct_Apollonius_bisector_ray_2<Gt>
Construct_Apollonius_bisector_ray_2;
typedef
CGAL_APOLLONIUS_GRAPH_2_NS::Construct_Apollonius_bisector_segment_2<Gt>
Construct_Apollonius_bisector_segment_2;
typedef CGAL_APOLLONIUS_GRAPH_2_NS::Construct_Apollonius_primal_ray_2<Gt>
Construct_Apollonius_primal_ray_2;
typedef CGAL_APOLLONIUS_GRAPH_2_NS::Construct_Apollonius_primal_segment_2<Gt>
Construct_Apollonius_primal_segment_2;
// access
Construct_Apollonius_bisector_2
construct_Apollonius_bisector_2_object() const {
return Construct_Apollonius_bisector_2();
}
Construct_Apollonius_bisector_ray_2
construct_Apollonius_bisector_ray_2_object() const {
return Construct_Apollonius_bisector_ray_2();
}
Construct_Apollonius_bisector_segment_2
construct_Apollonius_bisector_segment_2_object() const {
return Construct_Apollonius_bisector_segment_2();
}
Construct_Apollonius_primal_ray_2
construct_Apollonius_primal_ray_2_object() const {
return Construct_Apollonius_primal_ray_2();
}
Construct_Apollonius_primal_segment_2
construct_Apollonius_primal_segment_2_object() const {
return Construct_Apollonius_primal_segment_2();
}
protected:
// some local types
typedef
CGAL_APOLLONIUS_GRAPH_2_NS::Apollonius_graph_traits_wrapper_2<Gt>
Modified_traits;
typedef Triangulation_2<Modified_traits,Agds> DG;
typedef DG Delaunay_graph;
public:
// TYPES
//------
typedef Agds Data_structure;
typedef Agds Triangulation_data_structure;
typedef Gt Geom_traits;
typedef typename Gt::Point_2 Point_2;
typedef typename Gt::Site_2 Site_2;
typedef typename Agds::Edge Edge;
typedef typename Agds::Vertex_handle Vertex_handle;
typedef typename Agds::Face_handle Face_handle;
typedef typename Agds::Vertex Vertex;
typedef typename Agds::Face Face;
typedef typename Agds::Vertex_circulator Vertex_circulator;
typedef typename Agds::Edge_circulator Edge_circulator;
typedef typename Agds::Face_circulator Face_circulator;
typedef typename Agds::Face_iterator All_faces_iterator;
typedef typename Agds::Vertex_iterator All_vertices_iterator;
typedef typename Agds::Edge_iterator All_edges_iterator;
typedef typename DG::Finite_faces_iterator Finite_faces_iterator;
typedef typename DG::Finite_vertices_iterator Finite_vertices_iterator;
typedef typename DG::Finite_edges_iterator Finite_edges_iterator;
typedef typename Agds::size_type size_type;
// Auxiliary iterators for convenience
// do not use default template argument to please VC++
typedef internal::Project_site_2<Vertex> Proj_site;
typedef Iterator_project<Finite_vertices_iterator,
Proj_site>
/* */ Visible_sites_iterator;
typedef
Apollonius_graph_vertex_base_nested_iterator_traits<
Finite_vertices_iterator> Hidden_sites_nested_iterator_traits;
typedef Nested_iterator<Finite_vertices_iterator,
Hidden_sites_nested_iterator_traits>
/* */ Hidden_sites_iterator;
typedef Concatenate_iterator<Visible_sites_iterator,
Hidden_sites_iterator> Sites_iterator;
typedef Site_2 value_type; // to have a back_inserter
typedef const value_type& const_reference;
typedef value_type& reference;
public:
struct Vertex_iterator {};
struct Face_iterator {};
struct Edge_iterator {};
protected:
// some more local types
// typedef typename Agds::Vertex Vertex;
// point lists
typedef std::vector<Site_2> Site_list;
typedef typename Site_list::iterator Site_list_iterator;
typedef std::map<Face_handle,bool> Face_map;
typedef std::map<Face_handle, Face_handle> Face_face_map;
typedef std::map<Vertex_handle,bool> Vertex_map;
typedef std::set<Edge> Edge_list;
typedef std::list<Vertex_handle> Vertex_list;
typedef typename Vertex_list::iterator Vertex_list_iterator;
typedef Vertex_handle Vh_triple[3];
// the edge list
typedef typename internal::AG2_which_list<Edge,LTag>::List List;
typedef enum { NO_CONFLICT = -1, INTERIOR, LEFT_VERTEX,
RIGHT_VERTEX, BOTH_VERTICES, ENTIRE_EDGE }
Conflict_type;
static Conflict_type opposite(const Conflict_type& ct) {
if ( ct == RIGHT_VERTEX ) { return LEFT_VERTEX; }
if ( ct == LEFT_VERTEX ) { return RIGHT_VERTEX; }
return ct;
}
protected:
// Less_than comparator for site weights;
// used to sort sites by decreasing weight when a sequence of sites
// is inserted
class Site_less_than_comparator
{
private:
const Gt& gt;
public:
Site_less_than_comparator(const Gt& gt) : gt(gt) {}
bool operator ()(const Site_2& p,
const Site_2& q) {
Comparison_result result = gt.compare_weight_2_object()(p, q);
return (result == LARGER);
}
};
public:
// CREATION
//---------
Apollonius_graph_2(const Gt& gt=Gt()) :
DG( Modified_traits(gt) ) {}
template< class Input_iterator >
Apollonius_graph_2(Input_iterator first, Input_iterator beyond,
const Gt& gt=Gt())
: DG( Modified_traits(gt) )
{
insert(first, beyond);
}
Apollonius_graph_2(const Apollonius_graph_2 &ag)
: DG(ag)
{
CGAL_postcondition( is_valid() );
}
Apollonius_graph_2&
operator=(const Apollonius_graph_2& ag)
{
if ( this != &ag ) {
DG::operator=(ag);
}
return (*this);
}
public:
// ACCESS METHODS
// --------------
const Geom_traits& geom_traits() const {
return DG::geom_traits();
}
const Data_structure& data_structure() const { return this->_tds; }
const Triangulation_data_structure& tds() const { return this->_tds; }
int dimension() const {
return this->_tds.dimension();
}
size_type number_of_faces() const {
return this->_tds.number_of_faces();
}
size_type number_of_vertices() const {
return DG::number_of_vertices();
}
size_type number_of_visible_sites() const {
return number_of_vertices();
}
size_type number_of_hidden_sites() const {
// if ( !Vertex::StoreHidden ) { return 0; }
size_type n_hidden(0);
for (Finite_vertices_iterator vit = finite_vertices_begin();
vit != finite_vertices_end(); ++vit) {
n_hidden += vit->number_of_hidden_sites();
}
return n_hidden;
}
Vertex_handle infinite_vertex() const {
return DG::infinite_vertex();
}
Face_handle infinite_face() const {
return DG::infinite_face();
}
Vertex_handle finite_vertex() const {
return DG::finite_vertex();
}
protected:
using Delaunay_graph::cw;
using Delaunay_graph::ccw;
public:
// TRAVERSAL OF THE APOLLONIUS GRAPH
//----------------------------------
Finite_faces_iterator finite_faces_begin() const {
return DG::finite_faces_begin();
}
Finite_faces_iterator finite_faces_end() const {
return DG::finite_faces_end();
}
Finite_vertices_iterator finite_vertices_begin() const {
return DG::finite_vertices_begin();
}
Finite_vertices_iterator finite_vertices_end() const {
return DG::finite_vertices_end();
}
Finite_edges_iterator finite_edges_begin() const {
return DG::finite_edges_begin();
}
Finite_edges_iterator finite_edges_end() const {
return DG::finite_edges_end();
}
Sites_iterator sites_begin() const {
return Sites_iterator(visible_sites_end(),
hidden_sites_begin(),
visible_sites_begin());
}
Sites_iterator sites_end() const {
return Sites_iterator(visible_sites_end(),
hidden_sites_begin(),
hidden_sites_end(),0);
}
Visible_sites_iterator visible_sites_begin() const {
return Visible_sites_iterator(finite_vertices_begin());
}
Visible_sites_iterator visible_sites_end() const {
return Visible_sites_iterator(finite_vertices_end());
}
Hidden_sites_iterator hidden_sites_begin() const {
return Hidden_sites_iterator(finite_vertices_end(),
finite_vertices_begin());
}
Hidden_sites_iterator hidden_sites_end() const {
return Hidden_sites_iterator(finite_vertices_end(),
finite_vertices_end());
}
All_faces_iterator all_faces_begin() const {
return DG::all_faces_begin();
}
All_faces_iterator all_faces_end() const {
return DG::all_faces_end();
}
All_vertices_iterator all_vertices_begin() const {
return DG::all_vertices_begin();
}
All_vertices_iterator all_vertices_end() const {
return DG::all_vertices_end();
}
All_edges_iterator all_edges_begin() const {
return DG::all_edges_begin();
}
All_edges_iterator all_edges_end() const {
return DG::all_edges_end();
}
public:
// CIRCULATORS
//------------
Face_circulator
incident_faces(Vertex_handle v,
Face_handle f = Face_handle()) const {
return DG::incident_faces(v, f);
}
Vertex_circulator
incident_vertices(Vertex_handle v,
Face_handle f = Face_handle()) const {
return DG::incident_vertices(v, f);
}
Edge_circulator
incident_edges(Vertex_handle v,
Face_handle f = Face_handle()) const {
return DG::incident_edges(v, f);
}
public:
// PREDICATES
//-----------
bool is_infinite(const Vertex_handle& v) const {
return DG::is_infinite(v);
}
bool is_infinite(const Face_handle& f) const {
return DG::is_infinite(f);
}
bool is_infinite(const Face_handle& f, int i) const {
return DG::is_infinite(f, i);
}
bool is_infinite(const Edge& e) const {
return is_infinite(e.first, e.second);
}
bool is_infinite(const Edge_circulator& ec) const {
return DG::is_infinite(ec);
}
public:
// INSERTION
//----------
template< class Input_iterator >
size_type insert(Input_iterator first, Input_iterator beyond) {
// copy to a local container
Site_list wp_list;
for (Input_iterator it = first; it != beyond; ++it) {
wp_list.push_back(*it);
}
// sort by decreasing weight
Site_less_than_comparator less_than(geom_traits());
std::sort(wp_list.begin(), wp_list.end(), less_than);
// now insert
Site_list_iterator lit;
for (lit = wp_list.begin(); lit != wp_list.end(); ++lit) {
insert(*lit);
}
// store how many sites where in the range
size_type num = wp_list.size();
// clear the local container
wp_list.clear();
// return the number of sites in range
return num;
}
Vertex_handle insert(const Site_2& p) {
return insert(p, Vertex_handle());
}
Vertex_handle insert(const Site_2& p, Vertex_handle vnear);
public:
// REMOVAL
//--------
void remove(Vertex_handle v);
public:
// NEAREST NEIGHBOR LOCATION
//--------------------------
Vertex_handle nearest_neighbor(const Point_2& p) const;
Vertex_handle nearest_neighbor(const Point_2& p,
Vertex_handle vnear) const;
public:
// ACCESS TO THE DUAL
//-------------------
typename Gt::Object_2 dual(const Face_handle& f) const;
Site_2 dual(const Finite_faces_iterator& it) const
{
typename Gt::Object_2 o = dual(Face_handle(it));
Site_2 s;
if ( assign(s, o) ) {
return s;
} else {
CGAL_assertion_code( bool the_assign_statement_must_always_work(false); )
CGAL_assertion( the_assign_statement_must_always_work );
}
return s;
}
private:
typename Gt::Object_2 dual(const Edge e) const;
typename Gt::Object_2 dual(const Edge_circulator& ec) const {
return dual(*ec);
}
typename Gt::Object_2 dual(const Finite_edges_iterator& ei) const {
return dual(*ei);
}
public:
// I/O
//----
void file_input(std::istream&);
void file_output(std::ostream&) const;
template< class Stream >
Stream& draw_primal(Stream &str) const
{
if ( number_of_vertices() < 2 ) {
// do nothing
} else if ( number_of_vertices() == 2 ) {
Vertex_handle v1(finite_vertices_begin());
Vertex_handle v2(++finite_vertices_begin());
Site_2 p1 = v1->site();
Site_2 p2 = v2->site();
typename Geom_traits::Segment_2 seg =
construct_Apollonius_primal_segment_2_object()(p1,p2);
typename Geom_traits::Ray_2 ray1 =
construct_Apollonius_primal_ray_2_object()(p1,p2,p2);
typename Geom_traits::Ray_2 ray2 =
construct_Apollonius_primal_ray_2_object()(p2,p1,p1);
str << seg;
str << ray1;
str << ray2;
} else {
All_edges_iterator eit = all_edges_begin();
for (; eit != all_edges_end(); ++eit) {
draw_primal_edge< Stream >(eit, str);
}
}
return str;
}
template < class Stream >
Stream& draw_dual(Stream &str) const
{
Finite_edges_iterator eit = finite_edges_begin();
for (; eit != finite_edges_end(); ++eit) {
typename Gt::Object_2 o = dual(eit);
typename Geom_traits::Line_2 l;
typename Geom_traits::Segment_2 s;
typename Geom_traits::Ray_2 r;
CGAL::Hyperbola_2<Gt> h;
CGAL::Hyperbola_segment_2<Gt> hs;
CGAL::Hyperbola_ray_2<Gt> hr;
if (assign(hs, o)) hs.draw(str);
else if (assign(s, o)) str << s;
else if (assign(hr, o)) hr.draw(str);
else if (assign(r, o)) str << r;
else if (assign(h, o)) h.draw(str);
else if (assign(l, o)) str << l;
}
return str;
}
protected:
template< class Stream >
Stream& draw_primal_vertex(const Finite_vertices_iterator& it,
Stream &str) const
{
return str << it->site().point();
}
template< class Stream >
Stream& draw_dual_vertex(const Finite_faces_iterator& it,
Stream &str) const
{
return str << dual(it);
}
public:
template< class Stream >
Stream& draw_primal_edge(const Finite_edges_iterator& eit,
Stream &str) const
{
return draw_primal_edge(*eit, str);
}
template< class Stream >
Stream& draw_primal_edge(const All_edges_iterator& eit,
Stream &str) const
{
return draw_primal_edge(*eit, str);
}
template < class Stream >
Stream& draw_dual_edge(const Finite_edges_iterator& eit,
Stream &str) const
{
return draw_dual_edge(*eit, str);
}
template< class Stream >
Stream& draw_primal_edge(const Edge& e, Stream &str) const
{
typedef typename Geom_traits::Segment_2 Segment_2;
typedef typename Geom_traits::Ray_2 Ray_2;
typedef std::pair<Segment_2,Segment_2> Segment_pair_2;
typename Geom_traits::Object_2 o = primal(e);
Segment_2 s;
Ray_2 r;
Segment_pair_2 s_pair;
CGAL::Hyperbola_segment_2<Gt> hs;
CGAL::Parabola_segment_2<Gt> ps;
if (assign(hs, o)) hs.draw(str);
if (assign(s, o)) str << s;
if (assign(ps, o)) ps.draw(str);
if (assign(r, o)) str << r;
if (assign(s_pair, o)) str << s_pair.first << s_pair.second;
return str;
}
template < class Stream >
Stream& draw_dual_edge(const Edge& e, Stream &str) const
{
if ( is_infinite(e) ) { return str; }
typename Gt::Object_2 o = dual(e);
typename Geom_traits::Line_2 l;
typename Geom_traits::Segment_2 s;
typename Geom_traits::Ray_2 r;
CGAL::Hyperbola_2<Gt> h;
CGAL::Hyperbola_segment_2<Gt> hs;
CGAL::Hyperbola_ray_2<Gt> hr;
if (assign(hs, o)) hs.draw(str);
if (assign(s, o)) str << s;
if (assign(hr, o)) hr.draw(str);
if (assign(r, o)) str << r;
if (assign(h, o)) h.draw(str);
if (assign(l, o)) str << l;
return str;
}
protected:
template< class Stream >
Stream& draw_primal_face(All_faces_iterator fit, Stream &str) const
{
for (int i = 0; i < 3; i++) {
draw_primal_edge< Stream >(Edge(Face_handle(fit), i), str);
}
return str;
}
template< class Stream >
Stream& draw_dual_face(const All_vertices_iterator& vit,
Stream &str) const
{
Edge_circulator ec_start = incident_edges(Vertex_handle(vit));
Edge_circulator ec = ec_start;
do {
draw_dual_edge< Stream >(*ec, str);
++ec;
} while ( ec_start != ec );
return str;
}
protected:
template < class Stream >
Stream& draw_dual_sites(Stream &str) const
{
All_faces_iterator fit = all_faces_begin();
for (; fit != all_faces_end(); ++fit) {
Face_handle f(fit);
if ( is_infinite(f) ) {
if ( is_infinite(f->vertex(0)) ) {
str << circumcircle( f->vertex(1)->site(),
f->vertex(2)->site() );
} else if ( is_infinite(f->vertex(1)) ){
str << circumcircle( f->vertex(2)->site(),
f->vertex(0)->site() );
} else {
str << circumcircle( f->vertex(0)->site(),
f->vertex(1)->site() );
}
} else {
Site_2 wp = circumcircle(f);
typename Gt::Rep::Circle_2 c(wp.point(),
CGAL::square(wp.weight()));
str << c;
}
}
return str;
}
public:
// VALIDITY CHECK
//---------------
bool is_valid(bool verbose = false, int level = 1) const;
public:
// MISCELLANEOUS
//--------------
void clear() {
DG::clear();
}
void swap(Apollonius_graph_2& ag) {
DG::swap(ag);
}
public:
// MK: THE FOLLOWING ARE NOT IN THE SPEC
//======================================
// Primal
typename Gt::Object_2 primal(const Edge e) const;
typename Gt::Object_2 primal(const Edge_circulator& ec) const {
return primal(*ec);
}
typename Gt::Object_2 primal(const Finite_edges_iterator& ei) const {
return primal(*ei);
}
protected:
// wrappers for the geometric predicates
// checks is q is contained inside p
bool is_hidden(const Site_2 &p, const Site_2 &q) const;
// returns:
// ON_POSITIVE_SIDE if q is closer to p1
// ON_NEGATIVE_SIDE if q is closer to p2
// ON_ORIENTED_BOUNDARY if q is on the bisector of p1 and p2
Oriented_side side_of_bisector(const Site_2 &p1,
const Site_2 &p2,
const Point_2 &q) const;
Sign incircle(const Site_2 &p1, const Site_2 &p2,
const Site_2 &p3, const Site_2 &q) const;
Sign incircle(const Site_2 &p1, const Site_2 &p2,
const Site_2 &q) const;
Sign incircle(const Face_handle& f, const Site_2& q) const;
Sign incircle(const Vertex_handle& v0, const Vertex_handle& v1,
const Vertex_handle& v) const;
Sign incircle(const Vertex_handle& v0, const Vertex_handle& v1,
const Vertex_handle& v2, const Vertex_handle& v) const;
bool finite_edge_interior(const Site_2& p1,
const Site_2& p2,
const Site_2& p3,
const Site_2& p4,
const Site_2& q,
bool endpoints_in_conflict) const;
bool finite_edge_interior(const Face_handle& f, int i,
const Site_2& q,
bool endpoints_in_conflict) const;
bool finite_edge_interior(const Vertex_handle& v1,
const Vertex_handle& v2,
const Vertex_handle& v3,
const Vertex_handle& v4,
const Vertex_handle& v,
bool endpoints_in_conflict) const;
bool finite_edge_interior_degenerated(const Site_2& p1,
const Site_2& p2,
const Site_2& p3,
const Site_2& q,
bool endpoints_in_conflict) const;
bool finite_edge_interior_degenerated(const Site_2& p1,
const Site_2& p2,
const Site_2& q,
bool endpoints_in_conflict) const;
bool finite_edge_interior_degenerated(const Face_handle& f, int i,
const Site_2& p,
bool endpoints_in_conflict) const;
bool finite_edge_interior_degenerated(const Vertex_handle& v1,
const Vertex_handle& v2,
const Vertex_handle& v3,
const Vertex_handle& v4,
const Vertex_handle& v,
bool endpoints_in_conflict) const;
bool infinite_edge_interior(const Site_2& p2,
const Site_2& p3,
const Site_2& p4,
const Site_2& q,
bool endpoints_in_conflict) const;
bool infinite_edge_interior(const Face_handle& f, int i,
const Site_2& p,
bool endpoints_in_conflict) const;
bool infinite_edge_interior(const Vertex_handle& v1,
const Vertex_handle& v2,
const Vertex_handle& v3,
const Vertex_handle& v4,
const Vertex_handle& v,
bool endpoints_in_conflict) const;
Conflict_type
infinite_edge_conflict_type(const Site_2& p2,
const Site_2& p3,
const Site_2& p4,
const Site_2& q) const;
Conflict_type
finite_edge_conflict_type_degenerated(const Site_2& p1,
const Site_2& p2,
const Site_2& q) const;
bool edge_interior(const Face_handle& f, int i,
const Site_2& p, bool b) const;
bool edge_interior(const Edge& e,
const Site_2& p, bool b) const {
return edge_interior(e.first, e.second, p, b);
}
bool edge_interior(const Vertex_handle& v1,
const Vertex_handle& v2,
const Vertex_handle& v3,
const Vertex_handle& v4,
const Vertex_handle& v,
bool endpoints_in_conflict) const;
bool is_degenerate_edge(const Site_2& p1,
const Site_2& p2,
const Site_2& p3,
const Site_2& p4) const {
return geom_traits().is_degenerate_edge_2_object()
(p1, p2, p3, p4);
}
bool is_degenerate_edge(const Vertex_handle& v1,
const Vertex_handle& v2,
const Vertex_handle& v3,
const Vertex_handle& v4) const {
CGAL_precondition( !is_infinite(v1) && !is_infinite(v2) &&
!is_infinite(v3) && !is_infinite(v4) );
return is_degenerate_edge(v1->site(), v2->site(),
v3->site(), v4->site());
}
bool is_degenerate_edge(const Face_handle& f, int i) const {
Vertex_handle v1 = f->vertex( ccw(i) );
Vertex_handle v2 = f->vertex( cw(i) );
Vertex_handle v3 = f->vertex( i );
Vertex_handle v4 = tds().mirror_vertex(f, i);
return is_degenerate_edge(v1, v2, v3, v4);
}
bool is_degenerate_edge(const Edge& e) const {
return is_degenerate_edge(e.first, e.second);
}
protected:
// wrappers for constructions
Point_2 circumcenter(const Face_handle& f) const;
Point_2 circumcenter(const Site_2& p0,
const Site_2& p1,
const Site_2& p2) const;
Site_2 circumcircle(const Face_handle& f) const;
Site_2 circumcircle(const Site_2& p0,
const Site_2& p1,
const Site_2& p2) const;
typename Gt::Line_2 circumcircle(const Site_2& p0,
const Site_2& p1) const;
protected:
// wrappers for combinatorial operations on the data structure
// getting the degree of a vertex
typename Data_structure::size_type degree(const Vertex_handle& v) {
return this->_tds.degree(v);
}
// getting the symmetric edge
Edge sym_edge(const Edge e) const {
return sym_edge(e.first, e.second);
}
Edge sym_edge(const Face_handle& f, int i) const {
Face_handle f_sym = f->neighbor(i);
return Edge( f_sym, f_sym->index( tds().mirror_vertex(f, i) ) );
}
Edge flip(Face_handle& f, int i);
Edge flip(Edge e);
Vertex_handle insert_in_face(Face_handle& f, const Site_2& p);
bool is_degree_2(const Vertex_handle& v) const;
Vertex_handle insert_degree_2(Edge e);
Vertex_handle insert_degree_2(Edge e, const Site_2& p);
void remove_degree_2(Vertex_handle v);
void remove_degree_3(Vertex_handle v);
void remove_degree_3(Vertex_handle v, Face_handle f);
// this was defined because the hierarchy needs it
Vertex_handle create_vertex() {
return this->_tds.create_vertex();
}
protected:
// insertion of the first three sites
Vertex_handle insert_first(const Site_2& p);
Vertex_handle insert_second(const Site_2& p);
Vertex_handle insert_third(const Site_2& p);
// methods for insertion
void initialize_conflict_region(const Face_handle& f, List& l) const;
bool check_edge_for_hidden_sites(const Face_handle& f, int i,
const Site_2& p, Vertex_map& vm) const;
void expand_conflict_region(const Face_handle& f,
const Site_2& p,
List& l, Face_map& fm, Vertex_map& vm,
std::vector<Vh_triple*>* fe);
Vertex_handle add_bogus_vertex(Edge e, List& l);
Vertex_list add_bogus_vertices(List& l);
void remove_bogus_vertices(Vertex_list& vl);
void move_hidden_sites(Vertex_handle& vold, Vertex_handle& vnew);
// MK: this is not currently used
std::vector<Face*> get_faces_for_recycling(Face_map& fm,
unsigned int n_wanted);
void remove_hidden_vertices(Vertex_map& vm);
Vertex_handle retriangulate_conflict_region(const Site_2& p,
List& l,
Face_map& fm,
Vertex_map& vm);
protected:
// methods for removal
void remove_first(Vertex_handle v);
void remove_second(Vertex_handle v);
void remove_third(Vertex_handle v);
void remove_degree_d_vertex(Vertex_handle v);
void minimize_degree(Vertex_handle v);
void find_conflict_region_remove(const Vertex_handle& v,
const Vertex_handle& vnearest,
List& l, Face_map& fm,
Vertex_map& vm,
std::vector<Vh_triple*>* fe);
protected:
// methods for I/O
template<class T>
bool assign(T& t2, const typename Gt::Object_2& o2) const
{
return geom_traits().assign_2_object()(t2, o2);
}
protected:
template<class OutputItFaces>
OutputItFaces find_conflicts(const Face_handle& f,
const Site_2& p,
List& l,
Face_map& fm,
Vertex_map& vm,
OutputItFaces fit) const
{
// setting fm[f] to true means that the face has been reached and
// that the face is available for recycling. If we do not want the
// face to be available for recycling we must set this flag to
// false.
if ( fm.find(f) != fm.end() ) { return fit; }
fm[f] = true;
CGAL_assertion( incircle(f, p) == NEGATIVE );
*fit++ = f;
// CGAL_assertion( fm.find(f) != fm.end() );
for (int i = 0; i < 3; i++) {
bool hidden_found = check_edge_for_hidden_sites(f, i, p, vm);
Face_handle n = f->neighbor(i);
if ( !hidden_found ) {
Sign s = incircle(n, p);
if ( s != NEGATIVE ) { continue; }
bool interior_in_conflict = edge_interior(f, i, p, true);
if ( !interior_in_conflict ) { continue; }
}
if ( fm.find(n) != fm.end() ) {
Edge e = sym_edge(f, i);
if ( l.is_in_list(e) ||
l.is_in_list(sym_edge(e)) ) {
l.remove(e);
l.remove(sym_edge(e));
}
continue;
}
Edge e = sym_edge(f, i);
CGAL_assertion( l.is_in_list(e) );
int j = tds().mirror_index(f, i);
Edge e_before = sym_edge(n, ccw(j));
Edge e_after = sym_edge(n, cw(j));
if ( !l.is_in_list(e_before) ) {
l.insert_before(e, e_before);
}
if ( !l.is_in_list(e_after) ) {
l.insert_after(e, e_after);
}
l.remove(e);
fit = find_conflicts(n, p, l, fm, vm, fit);
} // for-loop
return fit;
} // find_conflicts
bool equal(const Edge& e1, const Edge& e2) const {
return e1.first == e2.first && e1.second == e2.second;
}
protected:
template<class OutputItFaces, class OutputItBoundaryEdges,
class OutputItHiddenVertices>
boost::tuples::tuple<OutputItFaces, OutputItBoundaryEdges,
OutputItHiddenVertices>
get_all(const Site_2& p,
OutputItFaces fit,
OutputItBoundaryEdges eit,
OutputItHiddenVertices vit,
Vertex_handle start,
bool find_nearest) const
{
CGAL_precondition( dimension() == 2 );
// first find the nearest neighbor
Vertex_handle vnearest = start;
if ( find_nearest ) {
vnearest = nearest_neighbor(p.point(), start);
CGAL_assertion( vnearest != Vertex_handle() );
}
// check if it is hidden
if ( is_hidden(vnearest->site(), p) ) {
return boost::tuples::make_tuple(fit, eit, vit);
}
// find the first conflict
// first look for conflict with vertex
Face_circulator fc_start = incident_faces(vnearest);
Face_circulator fc = fc_start;
Face_handle start_f;
Sign s;
do {
Face_handle f(fc);
s = incircle(f, p);
if ( s == NEGATIVE ) {
start_f = f;
break;
}
++fc;
} while ( fc != fc_start );
// we are not in conflict with an Apollonius vertex, so we have to
// be in conflict with the interior of an Apollonius edge
if ( s != NEGATIVE ) {
Edge_circulator ec_start = incident_edges(vnearest);
Edge_circulator ec = ec_start;
bool interior_in_conflict(false);
Edge e;
do {
e = *ec;
interior_in_conflict = edge_interior(e, p, false);
if ( interior_in_conflict ) { break; }
++ec;
} while ( ec != ec_start );
CGAL_assertion( interior_in_conflict );
*eit++ = e;
*eit++ = sym_edge(e);
return boost::tuples::make_tuple(fit, eit, vit);
}
// we are in conflict with an Apollonius vertex; start from that and
// find the entire conflict region and then repair the diagram
List l;
Face_map fm;
Vertex_map vm;
// *fit++ = start_f;
initialize_conflict_region(start_f, l);
fit = find_conflicts(start_f, p, l, fm, vm, fit);
// output the edges on the boundary of the conflict region
if ( l.size() > 0 ) {
const Edge& e_front = l.front();
// here I should be able to write: const Edge& e = l.front();
// instead of what I have; but the compiler complains for the
// assignment: e = l.next(e);
Edge e = l.front();
do {
*eit++ = e;
e = l.next(e);
} while ( !equal(e, e_front) );
}
// output the hidden vertices
for (typename Vertex_map::iterator it = vm.begin(); it != vm.end(); ++it) {
*vit++ = it->first;
}
// clear containers
fm.clear();
vm.clear();
l.clear();
return boost::tuples::make_tuple(fit, eit, vit);
}
public:
template<class OutputItFaces, class OutputItBoundaryEdges,
class OutputItHiddenVertices>
boost::tuples::tuple<OutputItFaces, OutputItBoundaryEdges,
OutputItHiddenVertices>
get_conflicts_and_boundary_and_hidden_vertices(const Site_2& p,
OutputItFaces fit,
OutputItBoundaryEdges eit,
OutputItHiddenVertices vit,
Vertex_handle start =
Vertex_handle()) const
{
return get_all(p, fit, eit, vit, start, true);
}
template<class OutputItFaces, class OutputItBoundaryEdges>
std::pair<OutputItFaces, OutputItBoundaryEdges>
get_conflicts_and_boundary(const Site_2& p,
OutputItFaces fit,
OutputItBoundaryEdges eit,
Vertex_handle start =
Vertex_handle()) const {
boost::tuples::tuple<OutputItFaces,OutputItBoundaryEdges,Emptyset_iterator>
tup =
get_conflicts_and_boundary_and_hidden_vertices(p,
fit,
eit,
Emptyset_iterator(),
start);
return std::make_pair( boost::tuples::get<0>(tup),
boost::tuples::get<1>(tup) );
}
template<class OutputItBoundaryEdges, class OutputItHiddenVertices>
std::pair<OutputItBoundaryEdges, OutputItHiddenVertices>
get_boundary_of_conflicts_and_hidden_vertices(const Site_2& p,
OutputItBoundaryEdges eit,
OutputItHiddenVertices vit,
Vertex_handle start =
Vertex_handle()) const {
boost::tuples::tuple<Emptyset_iterator,OutputItBoundaryEdges,
OutputItHiddenVertices>
tup =
get_conflicts_and_boundary_and_hidden_vertices(p,
Emptyset_iterator(),
eit,
vit,
start);
return std::make_pair( boost::tuples::get<1>(tup),
boost::tuples::get<2>(tup) );
}
template<class OutputItFaces, class OutputItHiddenVertices>
std::pair<OutputItFaces, OutputItHiddenVertices>
get_conflicts_and_hidden_vertices(const Site_2& p,
OutputItFaces fit,
OutputItHiddenVertices vit,
Vertex_handle start =
Vertex_handle()) const {
boost::tuples::tuple<OutputItFaces,Emptyset_iterator,
OutputItHiddenVertices>
tup =
get_conflicts_and_boundary_and_hidden_vertices(p,
fit,
Emptyset_iterator(),
vit,
start);
return std::make_pair( boost::tuples::get<0>(tup),
boost::tuples::get<2>(tup) );
}
template<class OutputItFaces>
OutputItFaces get_conflicts(const Site_2& p,
OutputItFaces fit,
Vertex_handle start = Vertex_handle()) const {
boost::tuples::tuple<OutputItFaces,Emptyset_iterator,Emptyset_iterator>
tup =
get_conflicts_and_boundary_and_hidden_vertices(p,
fit,
Emptyset_iterator(),
Emptyset_iterator(),
start);
return boost::tuples::get<0>(tup);
}
template<class OutputItBoundaryEdges>
OutputItBoundaryEdges
get_boundary_of_conflicts(const Site_2& p,
OutputItBoundaryEdges eit,
Vertex_handle start = Vertex_handle()) const {
boost::tuples::tuple<Emptyset_iterator,OutputItBoundaryEdges,
Emptyset_iterator>
tup =
get_conflicts_and_boundary_and_hidden_vertices(p,
Emptyset_iterator(),
eit,
Emptyset_iterator(),
start);
return boost::tuples::get<1>(tup);
}
template<class OutputItHiddenVertices>
OutputItHiddenVertices
get_hidden_vertices(const Site_2& p,
OutputItHiddenVertices vit,
Vertex_handle start = Vertex_handle()) const {
boost::tuples::tuple<Emptyset_iterator,Emptyset_iterator,
OutputItHiddenVertices>
tup =
get_conflicts_and_boundary_and_hidden_vertices(p,
Emptyset_iterator(),
Emptyset_iterator(),
vit,
start);
return boost::tuples::get<2>(tup);
}
}; // Apollonius_graph_2
template<class Gt, class Agds, class LTag>
std::ostream& operator<<(std::ostream& os,
const Apollonius_graph_2<Gt,Agds,LTag>& ag)
{
ag.file_output(os);
return os;
}
template<class Gt, class Agds, class LTag>
std::istream& operator>>(std::istream& is,
Apollonius_graph_2<Gt,Agds,LTag>& ag)
{
ag.file_input(is);
return is;
}
} //namespace CGAL
#include <CGAL/Apollonius_graph_2/Apollonius_graph_2_impl.h>
#endif // CGAL_APOLLONIUS_GRAPH_2_H
|