BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Straight_skeleton_vertex_base_2.h
Go to the documentation of this file.
00001 // Copyright (c) 2005-2008 Fernando Luis Cacciola Carballal. All rights reserved.
00002 //
00003 // This file is part of CGAL (www.cgal.org); you may redistribute it under
00004 // the terms of the Q Public License version 1.0.
00005 // See the file LICENSE.QPL distributed with CGAL.
00006 //
00007 // Licensees holding a valid commercial license may use this file in
00008 // accordance with the commercial license agreement provided with the software.
00009 //
00010 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00011 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00012 //
00013 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Straight_skeleton_2/include/CGAL/Straight_skeleton_vertex_base_2.h $
00014 // $Id: Straight_skeleton_vertex_base_2.h 44130 2008-07-12 21:58:52Z spion $
00015 //
00016 // Author(s)     : Fernando Cacciola <fernando_cacciola@ciudad.com.ar>
00017 //
00018 #ifndef CGAL_STRAIGHT_SKELETON_VERTEX_BASE_2_H
00019 #define CGAL_STRAIGHT_SKELETON_VERTEX_BASE_2_H 1
00020 
00021 #include <CGAL/Straight_skeleton_halfedge_base_2.h>
00022 #include <CGAL/circulator.h>
00023 
00024 #include <boost/iterator/iterator_facade.hpp>
00025 
00026 CGAL_BEGIN_NAMESPACE
00027 
00028 template < class Refs, class P, class N >
00029 class Straight_skeleton_vertex_base_base_2
00030 {
00031   enum Flags { IsSplitBit = 0x01, HasInfiniteTimeBit = 0x02 } ;
00032   
00033 protected :
00034 
00035   class Halfedge_circulator_around_vertex_access_policy
00036   {
00037   public:
00038     template<class Impl>
00039     static typename Impl::reference access ( Impl* aImpl )
00040     {
00041       return aImpl->mHandle;
00042     }
00043   } ;
00044 
00045   class Halfedge_circulator_across_incident_faces_access_policy
00046   {
00047   public:
00048     template<class Impl>
00049     static typename Impl::reference access ( Impl* aImpl )
00050     {
00051       return aImpl->mHandle->face()->halfedge();
00052     }
00053   } ;
00054   
00055   template<class HalfedgeHandle, class AccessPolicy >
00056   class Halfedge_circulator_base
00057     : public boost::iterator_facade< Halfedge_circulator_base< HalfedgeHandle, AccessPolicy >
00058                                    ,HalfedgeHandle
00059                                    ,Bidirectional_circulator_tag
00060                                    ,HalfedgeHandle
00061                                   >
00062   {
00063     public:
00064 
00065       typedef HalfedgeHandle               value_type ;
00066       typedef HalfedgeHandle               reference ;
00067       typedef std::size_t                  size_type ;
00068       typedef Bidirectional_circulator_tag iterator_category ;
00069 
00070       Halfedge_circulator_base () : mHandle() {}
00071 
00072       explicit Halfedge_circulator_base ( value_type aHandle ) : mHandle(aHandle) {}
00073 
00074       template < class OtherHalfedgeHandle, class OtherAccessPolicy >
00075       Halfedge_circulator_base
00076         ( Halfedge_circulator_base<OtherHalfedgeHandle,OtherAccessPolicy> const& aOther )
00077         : mHandle(aOther.mHandle) {}
00078 
00079       bool operator==( Nullptr_t p ) const 
00080       {
00081         CGAL_assertion( p == NULL ); 
00082         HalfedgeHandle null ;
00083         return mHandle == null ;
00084       }
00085       
00086       bool operator!=( Nullptr_t p ) const { return !(*this == p); }
00087       
00088     private :
00089 
00090       typedef Halfedge_circulator_base<HalfedgeHandle,AccessPolicy> Self ;
00091       
00092       friend class boost::iterator_core_access ;
00093 
00094       template < class OtherHalfedgeHandle, class OtherAccessPolicy >
00095       bool equal( Halfedge_circulator_base<OtherHalfedgeHandle,OtherAccessPolicy> const& aOther ) const
00096       {
00097         return mHandle == aOther.mHandle;
00098       }
00099 
00100       void increment() { mHandle = mHandle->opposite()->prev(); }
00101 
00102       void decrement() { mHandle = mHandle->next()->opposite() ; }
00103 
00104       reference dereference() const { return AccessPolicy::access(const_cast<Self*>(this)) ; }
00105 
00106     private :
00107     
00108       friend class Halfedge_circulator_around_vertex_access_policy ;
00109       friend class Halfedge_circulator_across_incident_faces_access_policy ;
00110 
00111       value_type mHandle ;
00112   } ;
00113   
00114 public:
00115 
00116   typedef Straight_skeleton_vertex_base_base_2<Refs, P, N>  Base ;
00117   
00118   typedef P Point_2;
00119   typedef N FT ;
00120 
00121   typedef Refs HalfedgeDS;
00122   
00123   typedef Tag_true Supports_vertex_halfedge;
00124   typedef Tag_true Supports_vertex_point;
00125   
00126   typedef typename Refs::Vertex_handle         Vertex_handle;
00127   typedef typename Refs::Vertex_const_handle   Vertex_const_handle;
00128   typedef typename Refs::Halfedge_handle       Halfedge_handle;
00129   typedef typename Refs::Halfedge_const_handle Halfedge_const_handle;
00130   typedef typename Refs::Face_handle           Face_handle;
00131   typedef typename Refs::Face_const_handle     Face_const_handle;
00132   typedef typename Refs::Halfedge              Halfedge;
00133   typedef typename Refs::Face                  Face;
00134   
00135   typedef Halfedge_circulator_base< Halfedge_const_handle
00136                                    ,Halfedge_circulator_around_vertex_access_policy
00137                                   >
00138             Halfedge_around_vertex_const_circulator ;
00139 
00140   typedef Halfedge_circulator_base< Halfedge_handle
00141                                    ,Halfedge_circulator_around_vertex_access_policy
00142                                   >
00143             Halfedge_around_vertex_circulator ;
00144 
00145   typedef Halfedge_circulator_base< Halfedge_const_handle
00146                                    ,Halfedge_circulator_across_incident_faces_access_policy
00147                                   >
00148             Defining_contour_halfedges_const_circulator ;
00149 
00150   typedef Halfedge_circulator_base< Halfedge_handle
00151                                    ,Halfedge_circulator_across_incident_faces_access_policy
00152                                   >
00153             Defining_contour_halfedges_circulator ;
00154 
00155   typedef CGAL_SS_i::Triedge<Halfedge_handle> Triedge ;
00156   
00157 public:
00158 
00159   Straight_skeleton_vertex_base_base_2() : mID(-1), mTime(0.0), mFlags(0) {}
00160   
00161   // Infinite vertex
00162   Straight_skeleton_vertex_base_base_2 ( int aID )
00163     :
00164       mID   (aID)
00165     , mP    (ORIGIN) 
00166     , mTime (std::numeric_limits<double>::max())
00167     , mFlags(HasInfiniteTimeBit)
00168   {
00169   }
00170   
00171   // Contour vertex
00172   Straight_skeleton_vertex_base_base_2 ( int aID, Point_2 const& aP )
00173     :
00174       mID   (aID)
00175     , mP    (aP)
00176     , mTime (0.0)
00177     , mFlags(0)
00178   {
00179   }
00180 
00181   // Skeleton vertex, corresponding to a split or edge event.
00182   Straight_skeleton_vertex_base_base_2 ( int aID, Point_2 const& aP, FT aTime, bool aIsSplit, bool aHasInfiniteTime )
00183     :
00184       mID   ( aID )
00185     , mP    ( aP )
00186     , mTime ( aTime )
00187     , mFlags( ( aIsSplit ? IsSplitBit : 0 ) | ( aHasInfiniteTime ? HasInfiniteTimeBit : 0 ) )
00188  {
00189  }
00190 
00191 public:
00192 
00193   int id() const { return mID ; }
00194 
00195   FT time() const { return mTime ; }
00196   
00197   bool has_infinite_time() const { return ( mFlags & HasInfiniteTimeBit ) == HasInfiniteTimeBit ; }
00198   
00199   bool has_null_point() const { return has_infinite_time(); }
00200   
00201   bool is_split() const { return ( mFlags & IsSplitBit ) == IsSplitBit ; }
00202 
00203   Halfedge_const_handle primary_bisector() const { return halfedge()->next(); }
00204 
00205   Halfedge_handle primary_bisector() { return halfedge()->next(); }
00206 
00207   Halfedge_around_vertex_const_circulator halfedge_around_vertex_begin() const
00208   {
00209     return Halfedge_around_vertex_const_circulator(halfedge());
00210   }
00211 
00212   Halfedge_around_vertex_circulator halfedge_around_vertex_begin()
00213   {
00214     return Halfedge_around_vertex_circulator(halfedge());
00215   }
00216   
00217   Defining_contour_halfedges_const_circulator defining_contour_halfedges_begin() const
00218   {
00219     return Defining_contour_halfedges_const_circulator(halfedge());
00220   }
00221 
00222   Defining_contour_halfedges_circulator defining_contour_halfedges_begin()
00223   {
00224     return Defining_contour_halfedges_circulator(halfedge());
00225   }
00226 
00227 
00228   std::size_t degree() const { return CGAL::circulator_size(halfedge_around_vertex_begin()); }
00229   
00230   bool is_skeleton() const { return  halfedge()->is_bisector() ; }
00231   bool is_contour () const { return !halfedge()->is_bisector() ; }
00232   
00233   const Point_2& point() const { return mP; }
00234   
00235   Halfedge_handle       halfedge()       { return mHE; }
00236   Halfedge_const_handle halfedge() const { return mHE; }
00237   
00238   void set_halfedge( Halfedge_handle aHE)  { mHE = aHE; }
00239     
00240   Triedge const& event_triedge() const { return mEventTriedge ; }
00241   
00242   void set_event_triedge( Triedge const& aTriedge ) { mEventTriedge = aTriedge ; }
00243   
00244   
00245 public :
00246   
00247   void reset_id__internal__    ( int aID ) { mID = aID ; }
00248   void reset_point__internal__ ( Point_2 const& aP ) { mP = aP ; }
00249   
00250 private:
00251   
00252   int             mID ;
00253   Halfedge_handle mHE;
00254   Triedge         mEventTriedge ;
00255   Point_2         mP;
00256   FT              mTime ;
00257   unsigned char   mFlags ;
00258 };
00259 
00260 template < class Refs, class P, class N >
00261 class Straight_skeleton_vertex_base_2 : public Straight_skeleton_vertex_base_base_2<Refs,P,N>
00262 {
00263 public:
00264 
00265   typedef P Point_2;
00266   typedef N FT ;
00267 
00268   typedef typename Refs::Vertex_handle         Vertex_handle;
00269   typedef typename Refs::Vertex_const_handle   Vertex_const_handle;
00270   typedef typename Refs::Halfedge_handle       Halfedge_handle;
00271   typedef typename Refs::Halfedge_const_handle Halfedge_const_handle;
00272   typedef typename Refs::Face_handle           Face_handle;
00273   typedef typename Refs::Face_const_handle     Face_const_handle;
00274   typedef typename Refs::Halfedge              Halfedge;
00275   typedef typename Refs::Face                  Face;
00276   
00277   typedef Straight_skeleton_vertex_base_base_2<Refs,P,N> Base ;
00278   
00279   typedef typename Base::Triedge Triedge ;
00280   
00281   Straight_skeleton_vertex_base_2() {}
00282   
00283   Straight_skeleton_vertex_base_2 ( int aID ) : Base(aID) {}
00284   
00285   Straight_skeleton_vertex_base_2 ( int aID, Point_2 const& aP ) : Base(aID,aP) {}
00286 
00287   Straight_skeleton_vertex_base_2 ( int aID, Point_2 const& aP, FT aTime, bool aIsSplit, bool aHasInfiniteTime ) : Base(aID,aP,aTime,aIsSplit,aHasInfiniteTime) {}
00288   
00289 private:
00290     
00291   void set_halfedge     ( Halfedge_handle aHE )     { Base::set_halfedge(aHE) ; }
00292   void set_event_triedge( Triedge const& aTriedge ) { Base::set_event_triedge( aTriedge); }
00293   void reset_id         ( int aID )                 { Base::reset_id(aID) ; }
00294   
00295 } ;
00296 
00297 CGAL_END_NAMESPACE
00298 
00299 #endif // CGAL_STRAIGHT_SKELETON_VERTEX_BASE_2_H //
00300 // EOF //
00301 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines