BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/boost/graph/graph_traits_Polyhedron_3.h
Go to the documentation of this file.
00001 // Copyright (c) 2007  GeometryFactory (France).  All rights reserved.
00002 //
00003 // This file is part of CGAL (www.cgal.org); you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public License as
00005 // published by the Free Software Foundation; version 2.1 of the License.
00006 // See the file LICENSE.LGPL 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/BGL/include/CGAL/boost/graph/graph_traits_Polyhedron_3.h $
00015 // $Id: graph_traits_Polyhedron_3.h 42705 2008-04-01 16:15:55Z fcacciola $
00016 // 
00017 //
00018 // Author(s)     : Andreas Fabri, Fernando Cacciola
00019 
00020 #ifndef CGAL_BOOST_GRAPH_GRAPH_TRAITS_POLYHEDRON_3_H
00021 #define CGAL_BOOST_GRAPH_GRAPH_TRAITS_POLYHEDRON_3_H
00022 
00023 #include <CGAL/boost/graph/graph_traits_HalfedgeDS.h>
00024 
00025 #include <CGAL/Polyhedron_3.h>
00026 
00027 #ifndef CGAL_CFG_NO_TMPL_IN_TMPL_PARAM
00028 #  define CGAL_HDS_PARAM_ template < class Traits, class Items, class Alloc> class HDS
00029 #else
00030 #  define CGAL_HDS_PARAM_ class HDS
00031 #endif
00032 
00033 
00034 //
00035 // NOTE: The BGL algorithms are NOT const-correct: i.e., they take a "G const&" 
00036 // but instantiate "graph_traits<G>" instead of "graph_traits<G const>"
00037 // This is known Boost bug which will eventually be fixed, but in the meantime we need
00038 // to coerce both const and non-const specializations.
00039 // That is, HDS_graph_traits<G const> is really the same as HDS_graph_traits<G>
00040 // so graph_traits<G> is also the same as graph_traits<G const>.
00041 // Therefore, while, for instance, "graph_traits<G const>::vertex_descriptor"
00042 // is conceptually const-correct, it actually corresponds to the non-const handle,
00043 // hence the const_cast<> used below in the functions implementation.
00044 //
00045 
00046 namespace boost
00047 { 
00048 
00049 template<class Gt, class I, CGAL_HDS_PARAM_, class A>
00050 struct graph_traits< CGAL::Polyhedron_3<Gt,I,HDS,A> >
00051    : CGAL::HDS_graph_traits< CGAL::Polyhedron_3<Gt,I,HDS,A> >
00052 {};
00053 
00054 
00055 template<class Gt, class I, CGAL_HDS_PARAM_, class A>
00056 struct graph_traits< CGAL::Polyhedron_3<Gt,I,HDS,A> const >
00057    : CGAL::HDS_graph_traits< CGAL::Polyhedron_3<Gt,I,HDS,A> > // See NOTE above!
00058 {};
00059 
00060  
00061 template<class Gt, class I, CGAL_HDS_PARAM_, class A>
00062 typename graph_traits< CGAL::Polyhedron_3<Gt,I,HDS,A> const>::vertices_size_type
00063 num_vertices(const CGAL::Polyhedron_3<Gt,I,HDS,A>& p)
00064 {
00065   return p.size_of_vertices();
00066 }
00067 
00068 template<class Gt, class I, CGAL_HDS_PARAM_, class A>
00069 typename graph_traits< CGAL::Polyhedron_3<Gt,I,HDS,A> const>::edges_size_type 
00070 num_edges(const CGAL::Polyhedron_3<Gt,I,HDS,A>& p)
00071 {
00072   return p.size_of_halfedges() ;
00073 }
00074 
00075 template<class Gt, class I, CGAL_HDS_PARAM_, class A>
00076 typename graph_traits< CGAL::Polyhedron_3<Gt,I,HDS,A> const>::degree_size_type
00077 degree(typename graph_traits< CGAL::Polyhedron_3<Gt,I,HDS,A> const>::vertex_descriptor v, const CGAL::Polyhedron_3<Gt,I,HDS,A>&)
00078 {
00079   return v->vertex_degree() * 2 ;
00080 }
00081 
00082 template<class Gt, class I, CGAL_HDS_PARAM_, class A>
00083 typename graph_traits< CGAL::Polyhedron_3<Gt,I,HDS,A> const>::degree_size_type
00084 out_degree(typename graph_traits< CGAL::Polyhedron_3<Gt,I,HDS,A> const>::vertex_descriptor v, const CGAL::Polyhedron_3<Gt,I,HDS,A>&)
00085 {
00086   return v->vertex_degree();
00087 }
00088 
00089 template<class Gt, class I, CGAL_HDS_PARAM_, class A>
00090 typename graph_traits< CGAL::Polyhedron_3<Gt,I,HDS,A> const>::degree_size_type
00091 in_degree(typename graph_traits< CGAL::Polyhedron_3<Gt,I,HDS,A> const>::vertex_descriptor v,  const CGAL::Polyhedron_3<Gt,I,HDS,A>&)
00092 {
00093   return v->vertex_degree();
00094 }
00095 
00096 
00097 template<class Gt, class I, CGAL_HDS_PARAM_, class A>
00098 typename graph_traits< CGAL::Polyhedron_3<Gt,I,HDS,A> const>::vertex_descriptor
00099 source(typename graph_traits< CGAL::Polyhedron_3<Gt,I,HDS,A> const>::edge_descriptor e, const CGAL::Polyhedron_3<Gt,I,HDS,A> & )
00100 {
00101   return e->opposite()->vertex();
00102 }
00103 
00104 template<class Gt, class I, CGAL_HDS_PARAM_, class A>
00105 typename graph_traits< CGAL::Polyhedron_3<Gt,I,HDS,A> const>::vertex_descriptor
00106 target(typename graph_traits< CGAL::Polyhedron_3<Gt,I,HDS,A> const>::edge_descriptor e, const CGAL::Polyhedron_3<Gt,I,HDS,A> & )
00107 {
00108   return e->vertex();
00109 }
00110 
00111 template<class Gt, class I, CGAL_HDS_PARAM_, class A>
00112 inline std::pair<typename graph_traits< CGAL::Polyhedron_3<Gt,I,HDS,A> const>::vertex_iterator
00113                 ,typename graph_traits< CGAL::Polyhedron_3<Gt,I,HDS,A> const>::vertex_iterator 
00114                 >  
00115 vertices( const CGAL::Polyhedron_3<Gt,I,HDS,A>& p)
00116 {
00117   typedef typename graph_traits< CGAL::Polyhedron_3<Gt,I,HDS,A> const>::vertex_iterator Iter;
00118   CGAL::Polyhedron_3<Gt,I,HDS,A>& ncp = const_cast<CGAL::Polyhedron_3<Gt,I,HDS,A>&>(p);
00119   return std::make_pair( Iter(ncp.vertices_begin()), Iter(ncp.vertices_end()) );
00120 }
00121 
00122 template<class Gt, class I, CGAL_HDS_PARAM_, class A>
00123 inline std::pair<typename graph_traits< CGAL::Polyhedron_3<Gt,I,HDS,A> const>::edge_iterator
00124                 ,typename graph_traits< CGAL::Polyhedron_3<Gt,I,HDS,A> const>::edge_iterator 
00125                 >  
00126 edges( const CGAL::Polyhedron_3<Gt,I,HDS,A>& p)
00127 {
00128   typedef typename graph_traits< CGAL::Polyhedron_3<Gt,I,HDS,A> const>::edge_iterator Iter;
00129   CGAL::Polyhedron_3<Gt,I,HDS,A>& ncp = const_cast<CGAL::Polyhedron_3<Gt,I,HDS,A>&>(p);
00130   return std::make_pair( Iter(ncp.halfedges_begin()), Iter(ncp.halfedges_end()) );
00131 }
00132 
00133 template<class Gt, class I, CGAL_HDS_PARAM_, class A>
00134 inline std::pair<typename graph_traits< CGAL::Polyhedron_3<Gt,I,HDS,A> const>::in_edge_iterator
00135                 ,typename graph_traits< CGAL::Polyhedron_3<Gt,I,HDS,A> const>::in_edge_iterator
00136                 >  
00137 in_edges( typename graph_traits< CGAL::Polyhedron_3<Gt,I,HDS,A> const>::vertex_descriptor u, const CGAL::Polyhedron_3<Gt,I,HDS,A>& g)
00138 {
00139   typename CGAL::Polyhedron_3<Gt,I,HDS,A>::Halfedge_around_vertex_circulator ec = u->vertex_begin();
00140   typename graph_traits< CGAL::Polyhedron_3<Gt,I,HDS,A> const>::edges_size_type in_deg = in_degree(u,g);
00141   typedef typename graph_traits< CGAL::Polyhedron_3<Gt,I,HDS,A> const>::in_edge_iterator Iter;
00142   return std::make_pair( Iter(ec), Iter(ec,in_deg) );
00143 }
00144 
00145 template<class Gt, class I, CGAL_HDS_PARAM_, class A>
00146 inline std::pair<typename graph_traits< CGAL::Polyhedron_3<Gt,I,HDS,A> const>::out_edge_iterator
00147                 ,typename graph_traits< CGAL::Polyhedron_3<Gt,I,HDS,A> const>::out_edge_iterator 
00148                 >  
00149 out_edges( typename graph_traits< CGAL::Polyhedron_3<Gt,I,HDS,A> const>::vertex_descriptor u, const CGAL::Polyhedron_3<Gt,I,HDS,A>& g)
00150 {
00151   typename CGAL::Polyhedron_3<Gt,I,HDS,A>::Halfedge_around_vertex_circulator ec = u->vertex_begin();
00152   typename graph_traits< CGAL::Polyhedron_3<Gt,I,HDS,A> const>::edges_size_type out_deg = out_degree(u,g);
00153   typedef typename graph_traits< CGAL::Polyhedron_3<Gt,I,HDS,A> const>::out_edge_iterator Iter;
00154   return std::make_pair( Iter(ec), Iter(ec,out_deg) );
00155 }
00156         
00157 } // namespace boost
00158 
00159 #undef CGAL_HDS_PARAM_
00160 
00161 #endif // CGAL_BOOST_GRAPH_GRAPH_TRAITS_POLYHEDRON_3_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines