BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Segment_Delaunay_graph_simple_storage_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_storage_site_2.h $
00015 // $Id: Segment_Delaunay_graph_simple_storage_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_STORAGE_SITE_H
00023 #define CGAL_SEGMENT_DELAUNAY_GRAPH_SIMPLE_STORAGE_SITE_H
00024 
00025 #include <iostream>
00026 #include <CGAL/assertions.h>
00027 
00028 #include <CGAL/Segment_Delaunay_graph_2/basic.h>
00029 
00030 CGAL_BEGIN_NAMESPACE
00031 
00036 CGAL_SEGMENT_DELAUNAY_GRAPH_2_BEGIN_NAMESPACE
00037 
00038 template<class STraits> class Construct_storage_site_2;
00039 
00040 CGAL_SEGMENT_DELAUNAY_GRAPH_2_END_NAMESPACE
00041 
00042 
00043 template <class STraits>
00044 class Segment_Delaunay_graph_simple_storage_site_2 
00045 {
00046   friend class
00047   CGAL_SEGMENT_DELAUNAY_GRAPH_2_NS::Construct_storage_site_2<STraits>;
00048 
00049 public:
00050   typedef STraits                                 Storage_traits;
00051   typedef typename Storage_traits::Geom_traits    Geom_traits;
00052   typedef typename Geom_traits::Site_2            Site_2;
00053   typedef typename Storage_traits::Point_handle   Point_handle;
00054 
00055 protected:
00056   typedef Point_handle                   Handle;
00057 
00058   typedef
00059   Segment_Delaunay_graph_simple_storage_site_2<Storage_traits>
00060   Self;
00061 
00062 protected:
00063   // constructs point site using input point
00064   static Self construct_storage_site_2(const Handle& hp) {
00065     Self t;
00066     t.initialize_site(hp);
00067     return t;
00068   }
00069 
00070   // constructs segment site using input segment
00071   static Self construct_storage_site_2(const Handle& hp1,
00072                                        const Handle& hp2) {
00073     Self t;
00074     t.initialize_site(hp1, hp2);
00075     return t;
00076   }
00077 
00078 public:
00079   // DEFAULT CONSTRUCTOR
00080   //--------------------
00081   Segment_Delaunay_graph_simple_storage_site_2() : type_(0) {}
00082 
00083   // COPY CONSTRUCTOR
00084   //-----------------
00085   Segment_Delaunay_graph_simple_storage_site_2(const Self& other) {
00086     copy_from(other);
00087   }
00088 
00089   // ASSIGNMENT OPERATOR
00090   //--------------------
00091   Self& operator=(const Self& other) {
00092     copy_from(other);
00093     return *this;
00094   }
00095 
00096 public:
00097   // PREDICATES
00098   //-----------
00099   bool is_defined() const { return type_ != 0; }
00100   bool is_point() const { return type_ == 1; }
00101   bool is_segment() const { return type_ == 2; }
00102   bool is_input() const { return true; }
00103   bool is_input(unsigned int) const { return true; }
00104 
00105   // ACCESS METHODS
00106   //---------------
00107   const Handle& point() const {
00108     CGAL_precondition( is_point() && is_input() );
00109     return h_[0];
00110   }
00111 
00112   const Handle& source_of_supporting_site() const {
00113     CGAL_precondition( is_segment() );
00114     return h_[0];
00115   }
00116 
00117   const Handle& target_of_supporting_site() const {
00118     CGAL_precondition( is_segment() );
00119     return h_[1];
00120   }
00121 
00122   // the following methods should never be called; they have been
00123   // defined in order for this class to be a model of the
00124   // SegmentDelaunayGraphStorageSite_2 concept.
00125   const Handle& source_of_supporting_site(unsigned int) const {
00126     CGAL_precondition( is_point() && !is_input() );
00127     return h_[0];
00128   }
00129 
00130   const Handle& target_of_supporting_site(unsigned int) const {
00131     CGAL_precondition( is_point() && !is_input() );
00132     return h_[0];
00133   }
00134 
00135   const Handle& source_of_crossing_site(unsigned int i) const {
00136     CGAL_precondition( is_segment() && !is_input(i) );
00137     return h_[0];
00138   }
00139 
00140   const Handle& target_of_crossing_site(unsigned int i) const {
00141     CGAL_precondition( is_segment() && !is_input(i) );
00142     return h_[0];
00143   }
00144 
00145   Site_2 site() const {
00146     if ( is_point() ) {
00147       return Site_2::construct_site_2(*h_[0]);
00148     } else {
00149       return Site_2::construct_site_2(*h_[0],*h_[1]);
00150     }
00151   }
00152 
00153   Self source_site() const
00154   {
00155     CGAL_precondition( is_segment() );
00156     return construct_storage_site_2(h_[0]);
00157   }
00158 
00159   Self target_site() const
00160   {
00161     CGAL_precondition( is_segment() );
00162     return construct_storage_site_2(h_[1]);
00163   }
00164 
00165   Self supporting_site() const {
00166     CGAL_precondition( is_segment() );
00167     return construct_storage_site_2(h_[0], h_[1]);
00168   }
00169 
00170   Self supporting_site(unsigned int i) const {
00171     CGAL_precondition( is_point() && !is_input() && i < 2 );
00172     return construct_storage_site_2(h_[0], h_[0]);
00173   }
00174 
00175   Self crossing_site(unsigned int i) const {
00176     CGAL_precondition( is_segment() && !is_input() );
00177     CGAL_precondition( i < 2 && !is_input(i) );
00178     return construct_storage_site_2(h_[0], h_[0]);
00179   }
00180 
00181 protected:
00182   // INITIALIZATION
00183   //---------------
00184   void initialize_site(const Handle& hp)
00185   {
00186     type_ = 1;
00187     h_[0] = hp;
00188   }
00189 
00190   void initialize_site(const Handle& hp1, const Handle& hp2)
00191   {
00192     type_ = 2;
00193     h_[0] = hp1;
00194     h_[1] = hp2;
00195   }
00196 
00197   void copy_from(const Self& other) {
00198     type_ = other.type_;
00199 
00200     if ( !other.is_defined() ) { return; }
00201 
00202     h_[0] = other.h_[0];
00203 
00204     if ( other.is_segment() ) {
00205       h_[1] = other.h_[1];
00206     }
00207   }
00208 
00209 protected:
00210   Handle h_[2];
00211   char type_;
00212 };
00213 
00214 //-------------------------------------------------------------------------
00215 
00216 CGAL_END_NAMESPACE
00217 
00218 #endif // CGAL_SEGMENT_DELAUNAY_GRAPH_SIMPLE_STORAGE_SITE_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines