BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Segment_Delaunay_graph_2/Constructions_C2.h
Go to the documentation of this file.
00001 // Copyright (c) 2003,2004,2005,2006  INRIA Sophia-Antipolis (France) and
00002 // Notre Dame University (U.S.A.).  All rights reserved.
00003 //
00004 // This file is part of CGAL (www.cgal.org); you may redistribute it under
00005 // the terms of the Q Public License version 1.0.
00006 // See the file LICENSE.QPL distributed with CGAL.
00007 //
00008 // Licensees holding a valid commercial license may use this file in
00009 // accordance with the commercial license agreement provided with the software.
00010 //
00011 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 //
00014 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Segment_Delaunay_graph_2/include/CGAL/Segment_Delaunay_graph_2/Constructions_C2.h $
00015 // $Id: Constructions_C2.h 44317 2008-07-22 12:29:01Z spion $
00016 // 
00017 //
00018 // Author(s)     : Menelaos Karavelas <mkaravel@cse.nd.edu>
00019 
00020 
00021 #ifndef CGAL_SEGMENT_DELAUNAY_GRAPH_2_CONSTRUCTIONS_C2_H
00022 #define CGAL_SEGMENT_DELAUNAY_GRAPH_2_CONSTRUCTIONS_C2_H
00023 
00024 #include <CGAL/Segment_Delaunay_graph_2/basic.h>
00025 #include <CGAL/enum.h>
00026 
00027 #include <CGAL/Segment_Delaunay_graph_2/Voronoi_vertex_C2.h>
00028 
00029 #include <CGAL/Parabola_2.h>
00030 #include <CGAL/Parabola_segment_2.h>
00031 
00032 
00033 CGAL_BEGIN_NAMESPACE
00034 
00035 CGAL_SEGMENT_DELAUNAY_GRAPH_2_BEGIN_NAMESPACE
00036 
00037 
00038 //***********************************************************************
00039 //***********************************************************************
00040 //                            CONSTRUCTIONS
00041 //***********************************************************************
00042 //***********************************************************************
00043 
00044 
00045 //-----------------------------------------------------------------------
00046 //                  Segment Delaunay graph site
00047 //-----------------------------------------------------------------------
00048 template<class Site,class ITag> class Construct_sdg_site_2;
00049 
00050 template<class Site>
00051 class Construct_sdg_site_2<Site,Tag_true>
00052 {
00053 public:
00054   typedef Site                             Site_2;
00055   typedef typename Site_2::Point_2         Point_2;
00056   typedef Site_2                           result_type;
00057 
00058 public:
00059   result_type operator()(const Point_2& p) const {
00060     return Site_2(p);
00061   }
00062 
00063   result_type operator()(const Point_2& p0, const Point_2& p1) const {
00064     return Site_2(p0, p1);
00065   }
00066 
00067   result_type operator()(const Point_2& p0, const Point_2& p1,
00068                          const Point_2& q0, const Point_2& q1) const {
00069     return Site_2(p0, p1, q0, q1);
00070   }
00071 
00072   result_type operator()(const Point_2& p0, const Point_2& p1,
00073                          const Point_2& q0, const Point_2& q1,
00074                          bool b) const {
00075     return Site_2(p0, p1, q0, q1, b);
00076   }
00077 
00078   result_type operator()(const Point_2& p0, const Point_2& p1,
00079                          const Point_2& q0, const Point_2& q1,
00080                          const Point_2& r0, const Point_2& r1) const {
00081     return Site_2(p0, p1, q0, q1, r0, r1);
00082   }
00083 };
00084 
00085 
00086 template<class Site>
00087 class Construct_sdg_site_2<Site,Tag_false>
00088 {
00089 public:
00090   typedef Site                             Site_2;
00091   typedef typename Site_2::Point_2         Point_2;
00092   typedef Site_2                           result_type;
00093 
00094 public:
00095   result_type operator()(const Point_2& p) const {
00096     return Site_2(p);
00097   }
00098 
00099   result_type operator()(const Point_2& p0, const Point_2& p1) const {
00100     return Site_2(p0, p1);
00101   }
00102 };
00103 
00104 
00105 
00106 
00107 //-----------------------------------------------------------------------
00108 //                  Segment Delaunay graph Voronoi vertex
00109 //-----------------------------------------------------------------------
00110 
00111 template<class K, class M>
00112 class Construct_svd_vertex_2
00113 {
00114 public:
00115   typedef typename K::Site_2                Site_2;
00116   typedef Voronoi_vertex_C2<K,M>            Voronoi_vertex_2;
00117   typedef typename K::Point_2               Point_2;
00118   typedef Point_2                           result_type;
00119 
00120 public:
00121   Point_2 operator()(const Site_2& s1, const Site_2& s2,
00122                      const Site_2& s3) const
00123   {
00124     Voronoi_vertex_2 v(s1, s2, s3);
00125     return v.point();
00126   }
00127 };
00128 
00129 
00130 //-----------------------------------------------------------------------
00131 //                  Segment Delaunay graph Voronoi circle
00132 //-----------------------------------------------------------------------
00133 
00134 
00135 template<class Gt, class M>
00136 class Construct_sdg_circle_2
00137 {
00138 public:
00139   typedef typename Gt::Site_2                 Site_2;
00140   typedef Voronoi_vertex_C2<Gt,M>             Voronoi_vertex_2;
00141   typedef typename Gt::Circle_2               Circle_2;
00142   typedef Circle_2                            result_type;
00143 
00144 public:
00145   Circle_2 operator() (const Site_2& s1, const Site_2& s2,
00146                        const Site_2& s3) const
00147   {
00148     Voronoi_vertex_2 v(s1, s2, s3);
00149     return v.circle();
00150   }
00151 };
00152 
00153 
00154 
00155 //-----------------------------------------------------------------------
00156 //                    Segment Delaunay graph Voronoi bisector
00157 //-----------------------------------------------------------------------
00158 
00159 
00160 template<class Gt, class M>
00161 class Construct_sdg_bisector_2
00162 {
00163 public:
00164   typedef typename Gt::Site_2        Site_2;
00165   typedef typename Gt::Point_2       Point_2;
00166   typedef typename Gt::Line_2        Line_2;
00167   typedef Line_2                     result_type;
00168 
00169 private:
00170   static
00171   Point_2 midpoint(const Point_2& p, const Point_2& q, Integral_domain_without_division_tag) {
00172     typedef typename Gt::FT  FT;
00173     FT half(0.5);
00174     return Point_2((p.x() + q.x()) * half,(p.y() + q.y()) * half);
00175   }
00176 
00177   static
00178   Point_2 midpoint(const Point_2& p, const Point_2& q, Field_tag) {
00179     return CGAL::midpoint(p, q);
00180   }
00181 
00182   static Point_2 midpoint(const Point_2& p, const Point_2& q) {
00183     typedef typename Gt::FT  FT;
00184     typedef Algebraic_structure_traits<FT> AST;
00185     return midpoint(p, q, typename AST::Algebraic_category());
00186   }
00187 
00188 public:
00189   Line_2 operator()(const Site_2& p, const Site_2& q) const
00190   {
00191     CGAL_assertion( !(p.is_segment() && q.is_segment()) );
00192 
00193     if ( p.is_point() && q.is_point() ) {
00194       Point_2 mid = midpoint(p.point(), q.point());
00195       Line_2 l(p.point(), q.point());
00196       return l.perpendicular(mid);
00197     }
00198     if ( p.is_segment() && q.is_point() ) {
00199       // in this case q has to be one of the two endpoints of the
00200       // segment p...
00201       Line_2 l = p.segment().supporting_line();
00202       return l.perpendicular(q.point());
00203     }
00204     // in this case p has to be one of the two endpoints of the
00205     // segment q...
00206     Line_2 l = q.segment().supporting_line();
00207     return l.perpendicular(p.point());
00208   }
00209 };
00210 
00211 //-----------------------------------------------------------------------
00212 //                 Segment Delaunay graph Voronoi bisecting ray
00213 //-----------------------------------------------------------------------
00214 
00215 template<class Gt, class M>
00216 class Construct_sdg_bisector_ray_2
00217 {
00218 public:
00219   typedef typename Gt::Site_2                   Site_2;
00220   typedef typename Gt::Point_2                  Point_2;
00221   typedef typename Gt::Line_2                   Line_2;
00222   typedef typename Gt::Ray_2                    Ray_2;
00223   typedef typename Gt::Construct_svd_vertex_2   Construct_svd_vertex_2;
00224   typedef typename Gt::Equal_2                  Equal_2;
00225   typedef Ray_2                                 result_type;
00226 
00227   Ray_2 operator()(const Site_2& p, const Site_2& q,
00228                    const Site_2& r) const
00229   {
00230     CGAL_assertion( !(p.is_segment() && q.is_segment()) );
00231 
00232     Equal_2 are_same_points;
00233 
00234     Point_2 v = Construct_svd_vertex_2()(p, q, r);
00235     Point_2 p1, p2;
00236     if ( p.is_point() && q.is_point() ) {
00237       p1 = q.point();
00238       p2 = p.point();
00239     } else if ( p.is_point() && q.is_segment() ) {
00240       CGAL_assertion( are_same_points(p, q.source_site()) ||
00241                       are_same_points(p, q.target_site()) );
00242       p1 = are_same_points(p, q.source_site()) ? q.target() : q.source();
00243       p2 = p.point();
00244     } else {
00245       // p is a segment and q a point
00246       p1 = q.point();
00247       p2 = are_same_points(q, p.source_site()) ? p.target() : p.source();
00248     }
00249     Line_2 l(p1, p2);
00250     Line_2 lperp = l.perpendicular( v );
00251     return Ray_2(v, lperp.direction());
00252   }
00253 };
00254 
00255 
00256 //-----------------------------------------------------------------------
00257 //              Segment Delaunay graph Voronoi bisecting segment
00258 //-----------------------------------------------------------------------
00259 
00260 
00261 template<class Gt, class M>
00262 class Construct_sdg_bisector_segment_2
00263 {
00264 public:
00265   typedef typename Gt::Site_2                  Site_2;
00266   typedef typename Gt::Point_2                 Point_2;
00267   typedef typename Gt::Line_2                  Line_2;
00268   typedef typename Gt::Ray_2                   Ray_2;
00269   typedef typename Gt::Segment_2               Segment_2;
00270   typedef CGAL::Parabola_segment_2<Gt>         Parabola_segment_2;
00271 
00272   typedef typename Gt::Construct_svd_vertex_2  Construct_svd_vertex_2;
00273   typedef typename Gt::Equal_2                 Equal_2;
00274 
00275   typedef CGAL::Object                         Object_2;
00276   typedef Object_2                             result_type;
00277 
00278   result_type operator()(const Site_2& p, const Site_2& q,
00279                          const Site_2& r, const Site_2& s) const
00280   {
00281     Construct_svd_vertex_2 circumcenter;
00282     Point_2 vpqr = circumcenter(p, q, r);
00283     Point_2 vqps = circumcenter(q, p, s);
00284 
00285     Equal_2 same_points;
00286 
00287     if ( (p.is_point() && q.is_point()) ||
00288          (p.is_segment() && q.is_segment()) ) {
00289       Segment_2 vorseg(vpqr, vqps);
00290       return CGAL::make_object(vorseg);
00291     }
00292     if ( p.is_point() ) {
00293       // check is p is an endpoint of q
00294       if (  same_points( p, q.source_site() ) ||
00295             same_points( p, q.target_site() )  ) {
00296         Segment_2 vorseg(vpqr, vqps);
00297         return CGAL::make_object(vorseg);
00298       }
00299       Line_2 l = q.segment().supporting_line();
00300       Parabola_segment_2 vorseg(p.point(), l, vpqr, vqps);
00301       return CGAL::make_object(vorseg);
00302     }
00303     // check is q is an endpoint of p
00304     if ( same_points(q, p.source_site()) ||
00305          same_points(q, p.target_site()) ) {
00306       Segment_2 vorseg(vpqr, vqps);
00307       return CGAL::make_object(vorseg);
00308     }
00309     Line_2 l = p.segment().supporting_line();
00310     Parabola_segment_2 vorseg(q.point(), l, vpqr, vqps);
00311     return CGAL::make_object(vorseg);
00312   }
00313 };
00314 
00315 //-----------------------------------------------------------------------
00316 
00317 
00318 CGAL_SEGMENT_DELAUNAY_GRAPH_2_END_NAMESPACE
00319 
00320 CGAL_END_NAMESPACE
00321 
00322 
00323 #endif // CGAL_SEGMENT_DELAUNAY_GRAPH_2_CONSTRUCTIONS_C2_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines