BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Straight_skeleton_2/Straight_skeleton_aux.h
Go to the documentation of this file.
00001 // Copyright (c) 2006 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_2/Straight_skeleton_aux.h $
00014 // $Id: Straight_skeleton_aux.h 40295 2007-09-10 14:07:00Z fcacciola $
00015 //
00016 // Author(s)     : Fernando Cacciola <fernando_cacciola@ciudad.com.ar>
00017 //
00018 #ifndef CGAL_STRAIGHT_SKELETON_AUX_H
00019 #define CGAL_STRAIGHT_SKELETON_AUX_H 1
00020 
00021 #include <boost/optional/optional.hpp>
00022 #include <boost/none.hpp>
00023 
00024 #include <CGAL/Straight_skeleton_2/assertions.h>
00025 #include <CGAL/Straight_skeleton_2/debug.h>
00026 #include <CGAL/Straight_skeleton_2/test.h>
00027 
00028 //
00029 // The heap objects used in this implementation are intrusively reference counted. Thus, they inherit from Ref_counted_base.
00030 //
00031 CGAL_BEGIN_NAMESPACE
00032 
00033 namespace CGAL_SS_i
00034 {
00035 
00036 
00037 //
00038 // This record encapsulates the defining contour halfedges for a node (both contour and skeleton)
00039 //
00040 template<class Handle_>
00041 class Triedge 
00042 {
00043 public:
00044 
00045   typedef Handle_ Handle ;
00046   
00047   typedef Triedge<Handle> Self ;
00048   
00049   Triedge() {}
00050   
00051   // Contour nodes (input polygon vertices) have only 2 defining contour edges    
00052   Triedge ( Handle aE0, Handle aE1 )
00053   {
00054     mE[0] = aE0 ;
00055     mE[1] = aE1 ;
00056     // mE[2] gets default constructed, i.e., "null".
00057   }              
00058   
00059   // Skeleton nodes (offset polygon vertices) have 3 defining contour edges    
00060   Triedge ( Handle aE0, Handle aE1 , Handle aE2 )
00061   {
00062     mE[0] = aE0 ;
00063     mE[1] = aE1 ;
00064     mE[2] = aE2 ;
00065   }              
00066   
00067   Handle e( unsigned idx ) const { CGAL_assertion(idx<3); return mE[idx]; }
00068   
00069   Handle e0() const { return e(0); }
00070   Handle e1() const { return e(1); }
00071   Handle e2() const { return e(2); }
00072   
00073   bool is_valid() const 
00074   { 
00075     return    handle_assigned(e0())
00076            && handle_assigned(e1())
00077            && e0() != e1() && e1() != e2() ; 
00078   }
00079   
00080   bool is_contour () const { return !handle_assigned(e2()) ; }
00081   bool is_skeleton() const { return  handle_assigned(e2()) ; }
00082   
00083   // returns 1 if aE is one of the halfedges stored in this triedge, 0 otherwise.
00084   int contains ( Handle aE ) const
00085   {
00086     return aE == e0() || aE == e1() || aE == e2() ? 1 : 0 ;
00087   }
00088   
00089   // Returns the number of common halfedges in the two triedges x and y
00090   static int CountInCommon( Self const& x, Self const& y )
00091   {
00092     return x.contains(y.e0()) + x.contains(y.e1()) + x.contains(y.e2()) ; 
00093   }
00094   
00095   // Returns true if the triedges store the same 3 halfedges (in any order)
00096   friend bool operator == ( Self const& x, Self const& y ) { return CountInCommon(x,y) == 3 ; }
00097   
00098   friend bool operator != ( Self const& x, Self const& y ) { return !(x==y) ; }
00099   
00100   friend Self operator & ( Self const& x, Self const& y )
00101   {
00102     return Self(x.e0(), x.e1(), ( x.e0() == y.e0() || x.e1() == y.e0() ) ? y.e1() : y.e0()  ) ;
00103   }
00104   
00105   static void insert_handle_id( std::ostream& ss, Handle aH )
00106   {  
00107     if ( handle_assigned(aH) )
00108          ss << aH->id() ;
00109     else ss << "#" ;
00110   }
00111   
00112   friend std::ostream& operator<< ( std::ostream& ss, Self const& t )
00113   {
00114     ss << "{E" ;
00115     insert_handle_id(ss,t.e0())  ;
00116     ss << ",E" ;
00117     insert_handle_id(ss,t.e1()) ;
00118     ss << ",E" ;
00119     insert_handle_id(ss,t.e2()) ;
00120     ss << "}" ;
00121     return ss ;
00122   }
00123   
00124 private:
00125   
00126 
00127   Handle mE[3];
00128 } ;
00129 
00130 } // namespace CGAL_SS_i
00131 
00132 enum Trisegment_collinearity
00133 { 
00134     TRISEGMENT_COLLINEARITY_NONE
00135   , TRISEGMENT_COLLINEARITY_01
00136   , TRISEGMENT_COLLINEARITY_12
00137   , TRISEGMENT_COLLINEARITY_02
00138   , TRISEGMENT_COLLINEARITY_ALL
00139 } ;
00140 
00141 static char const* trisegment_collinearity_to_string( Trisegment_collinearity c )
00142 {
00143   switch ( c )
00144   {
00145     case TRISEGMENT_COLLINEARITY_NONE : return "<>" ;  
00146     case TRISEGMENT_COLLINEARITY_01   : return "<0,1>" ; 
00147     case TRISEGMENT_COLLINEARITY_12   : return "<1,2>" ; 
00148     case TRISEGMENT_COLLINEARITY_02   : return "<0,2>" ; 
00149     case TRISEGMENT_COLLINEARITY_ALL  : return "<0,1,2>" ; 
00150   }
00151   
00152   return "!!UNKNOWN COLLINEARITY!!" ;
00153 }
00154 namespace CGALi 
00155 {
00156 
00157 template <>
00158 struct Minmax_traits< Trisegment_collinearity >
00159 {
00160   static const Trisegment_collinearity min = TRISEGMENT_COLLINEARITY_NONE;
00161   static const Trisegment_collinearity max = TRISEGMENT_COLLINEARITY_ALL;
00162 };
00163 
00164 }
00165 
00166 class Ref_counted_base
00167 {
00168 private:
00169   mutable long mCount ;
00170   Ref_counted_base( Ref_counted_base const &);
00171   Ref_counted_base& operator=( Ref_counted_base const &);
00172 protected:
00173   Ref_counted_base(): mCount(0) {}
00174   virtual ~Ref_counted_base() {}
00175 public:
00176     void AddRef() const { ++mCount; }
00177     void Release() const
00178       {
00179         if( --mCount == 0 )
00180           delete this;
00181       }
00182 };
00183 
00184 CGAL_END_NAMESPACE
00185 
00186 namespace boost
00187 {
00188 inline void intrusive_ptr_add_ref( CGAL::Ref_counted_base const* p ) { p->AddRef(); }
00189 inline void intrusive_ptr_release( CGAL::Ref_counted_base const* p ) { p->Release(); }
00190 } // namespace boost
00191 
00192 
00193 
00194 #endif // CGAL_STRAIGHT_SKELETON_AUX_H //
00195 // EOF //
00196 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines