BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Segment_Delaunay_graph_simple_site_2.h
Go to the documentation of this file.
00001 // Copyright (c) 2003,2004,2005  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_simple_site_2.h $
00015 // $Id: Segment_Delaunay_graph_simple_site_2.h 46222 2008-10-13 09:56:02Z afabri $
00016 // 
00017 //
00018 // Author(s)     : Menelaos Karavelas <mkaravel@cse.nd.edu>
00019 
00020 
00021 
00022 #ifndef CGAL_SEGMENT_DELAUNAY_GRAPH_SIMPLE_SITE_H
00023 #define CGAL_SEGMENT_DELAUNAY_GRAPH_SIMPLE_SITE_H
00024 
00025 #include <iostream>
00026 #include <CGAL/assertions.h>
00027 
00028 #include <CGAL/Segment_Delaunay_graph_2/basic.h>
00029 
00030 #include <CGAL/Segment_Delaunay_graph_2/Constructions_C2.h>
00031 
00032 CGAL_BEGIN_NAMESPACE
00033 
00038 template <class R_>
00039 class Segment_Delaunay_graph_simple_site_2 
00040 {
00041 public:
00042   typedef R_ R;
00043   typedef R  Rep;
00044   typedef typename R::Point_2   Point_2;
00045   typedef typename R::Segment_2 Segment_2;
00046 
00047 protected:
00048   typedef typename R::FT        FT;
00049   typedef typename R::RT        RT;
00050   typedef Segment_Delaunay_graph_simple_site_2<Rep>  Self;
00051 
00052 public:
00053   static Self construct_site_2(const Point_2& p) {
00054     Self t;
00055     t.initialize_site(p);
00056     return t;
00057   }
00058 
00059   static Self construct_site_2(const Point_2& p0, const Point_2& p1) {
00060     Self t;
00061     t.initialize_site(p0, p1);
00062     return t;
00063   }
00064 
00065  private:
00066   static bool no_warning(bool b) {
00067     CGAL_assertion( b );
00068     return b;
00069   }
00070 
00071   static void no_constructor_support() {
00072     bool THIS_CLASS_DOES_NOT_SUPPORT_THIS_CONSTRUCTOR = false;
00073     no_warning( THIS_CLASS_DOES_NOT_SUPPORT_THIS_CONSTRUCTOR );
00074   }
00075 
00076  public:
00077   // these "constructors" are defined in order to conform with the
00078   // specs; they will produce a run-time error if used
00079   static Self construct_site_2(const Point_2& p1, const Point_2& p2,
00080                                const Point_2& q1, const Point_2& q2) {
00081     no_constructor_support();
00082     return Self();
00083   }
00084 
00085   static Self construct_site_2(const Point_2& , const Point_2& ,
00086                                const Point_2& , const Point_2& ,
00087                                bool ) {
00088     no_constructor_support();
00089     return Self();
00090   }
00091 
00092   static Self construct_site_2(const Point_2& , const Point_2& ,
00093                                const Point_2& , const Point_2& ,
00094                                const Point_2& , const Point_2& ) {
00095     no_constructor_support();
00096     return Self();
00097   }
00098 
00099 public:
00100   Segment_Delaunay_graph_simple_site_2() : type_(0) {}
00101 
00102 public:
00103   bool is_defined() const { return type_ != 0; }
00104   bool is_point() const { return type_ == 1; }
00105   bool is_segment() const { return type_ == 2; }
00106   bool is_input() const { return true; }
00107   bool is_input(unsigned int) const { return true; }
00108 
00109   const Point_2& point() const { 
00110     CGAL_precondition ( is_point() );
00111     return p_[0];
00112   }
00113 
00114   const Point_2& source_of_supporting_site() const {
00115     CGAL_precondition( is_segment() );
00116     return p_[0];
00117   }
00118 
00119   const Point_2& target_of_supporting_site() const {
00120     CGAL_precondition( is_segment() );
00121     return p_[1];
00122   }
00123 
00124   // the following four methods do not really make any sense but have
00125   // been added in order for this class to be a model of the
00126   // SegmentDelaunayGraphSite_2 concept.
00127   const Point_2& source_of_supporting_site(unsigned int i) const {
00128     CGAL_precondition( is_point() && !is_input() );
00129     return p_[0];
00130   }
00131 
00132   const Point_2& target_of_supporting_site(unsigned int i) const {
00133     CGAL_precondition( is_point() && !is_input() );
00134     return p_[0];
00135   }
00136 
00137   const Point_2& source_of_crossing_site(unsigned int i) const {
00138     CGAL_precondition( is_segment() && !is_input(i) );
00139     return p_[0];
00140   }
00141 
00142   const Point_2& target_of_crossing_site(unsigned int i) const {
00143     CGAL_precondition( is_segment() && !is_input(i) );
00144     return p_[0];
00145   }
00146 
00147 
00148   Segment_2 segment() const {
00149     CGAL_precondition ( is_segment() ); 
00150     return Segment_2( p_[0], p_[1] );
00151   }
00152 
00153   const Point_2& source() const {
00154     CGAL_precondition ( is_segment() ); 
00155     return p_[0];
00156   }
00157 
00158   const Point_2& target() const {
00159     CGAL_precondition ( is_segment() ); 
00160     return p_[1];
00161   }
00162 
00163   Self source_site() const {
00164     CGAL_precondition( is_segment() );
00165     return Self::construct_site_2(p_[0]);
00166   }
00167 
00168   Self target_site() const {
00169     CGAL_precondition( is_segment() );
00170     return Self::construct_site_2(p_[1]);
00171   }
00172 
00173   const Self& supporting_site() const {
00174     CGAL_precondition( is_segment() );
00175     return *this;
00176   }
00177 
00178   // the following two methods make no sense, but have been added in
00179   // order for this class to be a model of the
00180   // SegmentDelaunayGraphSite_2 concept.
00181   Self supporting_site(unsigned int i) const {
00182     CGAL_precondition( is_point() && i < 2 );
00183     CGAL_precondition( !is_input() );
00184     return Self::construct_site_2(p_[0], p_[0]);
00185   }
00186 
00187   Self crossing_site(unsigned int i) const {
00188     CGAL_precondition( is_segment() && i < 2 );
00189     CGAL_precondition( !is_input(i) );
00190     return *this;
00191   }
00192 
00193 protected:
00194   void initialize_site(const Point_2& p)
00195   {
00196     type_ = 1;
00197     p_[0] = p;
00198   }
00199 
00200   void initialize_site(const Point_2& p1, const Point_2& p2)
00201   {
00202     type_ = 2;
00203     p_[0] = p1;
00204     p_[1] = p2;
00205   }
00206 
00207 protected:
00208   Point_2 p_[2];
00209   char type_;
00210 };
00211 
00212 //-------------------------------------------------------------------------
00213 
00214 template <class R>
00215 std::ostream&
00216 operator<<(std::ostream& os, 
00217            const Segment_Delaunay_graph_simple_site_2<R>& s)
00218 {
00219   if (!s.is_defined())
00220     return os << "u";
00221   if (s.is_point())
00222     return os << "p " << s.point ();
00223   return os << "s " << s.segment ();
00224 }
00225 
00226 template <class R>
00227 std::istream &
00228 operator>>(std::istream &is,
00229            Segment_Delaunay_graph_simple_site_2<R>& t)
00230 {
00231   typedef Segment_Delaunay_graph_simple_site_2<R>   Site_2;
00232   typedef typename Site_2::Point_2                  Point_2;
00233 
00234   char type;
00235   if (is >> type) {
00236     if (type == 'p') {
00237       Point_2 p;
00238       is >> p;
00239       t = Site_2::construct_site_2(p);
00240     } else if (type == 's') {
00241       Point_2 p1, p2;
00242       is >> p1 >> p2;
00243       t = Site_2::construct_site_2(p1, p2);
00244     }
00245   }
00246   return is;
00247 }
00248 
00249 template < class R, class Stream >
00250 Stream&
00251 operator<<(Stream& str, Segment_Delaunay_graph_simple_site_2<R>& t)
00252 {
00253   if ( t.is_defined() ) {
00254     if ( t.is_point() ) {
00255       str << "p " << t.point();
00256     } else {
00257       str << "s " << t.segment().source() << "  "
00258           << t.segment().target();
00259     }
00260   }
00261 
00262   return str;
00263 }
00264 
00265 
00266 CGAL_END_NAMESPACE
00267 
00268 #endif // CGAL_SEGMENT_DELAUNAY_GRAPH_SIMPLE_SITE_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines