BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/create_straight_skeleton_2.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 
00014 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Straight_skeleton_2/include/CGAL/create_straight_skeleton_2.h $
00015 // $Id: create_straight_skeleton_2.h 50476 2009-07-08 16:04:50Z fcacciola $
00016 //
00017 // Author(s)     : Fernando Cacciola <fernando_cacciola@ciudad.com.ar>
00018 //
00019 #ifndef CGAL_CREATE_STRAIGHT_SKELETON_2_H
00020 #define CGAL_CREATE_STRAIGHT_SKELETON_2_H
00021 
00022 #include <CGAL/Straight_skeleton_builder_2.h>
00023 #include <CGAL/compute_outer_frame_margin.h>
00024 #include <CGAL/Polygon_2.h>
00025 
00026 CGAL_BEGIN_NAMESPACE
00027 
00028 namespace CGAL_SS_i
00029 {
00030 
00031 template<class Poly>
00032 inline typename Poly::const_iterator vertices_begin ( Poly const& aPoly ) { return aPoly.begin() ; }
00033 
00034 template<class Poly>
00035 inline typename Poly::const_iterator vertices_end ( Poly const& aPoly ) { return aPoly.end() ; }
00036 
00037 
00038 template<class K, class C>
00039 inline typename Polygon_2<K,C>::Vertex_const_iterator vertices_begin ( Polygon_2<K,C> const& aPoly ) 
00040 { return aPoly.vertices_begin() ; }
00041 
00042 template<class K, class C>
00043 inline typename Polygon_2<K,C>::Vertex_const_iterator vertices_end( Polygon_2<K,C> const& aPoly ) 
00044 { return aPoly.vertices_end() ; }
00045 
00046 template<class Poly>
00047 inline typename Poly::const_iterator vertices_begin ( boost::shared_ptr<Poly> const& aPoly ) { return aPoly->begin() ; }
00048 
00049 template<class Poly>
00050 inline typename Poly::const_iterator vertices_end ( boost::shared_ptr<Poly> const& aPoly ) { return aPoly->end() ; }
00051 
00052 }
00053 
00054 template<class PointIterator, class HoleIterator, class K>
00055 boost::shared_ptr< Straight_skeleton_2<K> >
00056 create_interior_straight_skeleton_2 ( PointIterator aOuterContour_VerticesBegin
00057                                     , PointIterator aOuterContour_VerticesEnd
00058                                     , HoleIterator  aHolesBegin
00059                                     , HoleIterator  aHolesEnd
00060                                     , K const&      
00061                                     )
00062 {
00063   typedef Straight_skeleton_2<K> Ss ;
00064   typedef boost::shared_ptr<Ss>  SsPtr ;
00065 
00066   typedef Straight_skeleton_builder_traits_2<K> SsBuilderTraits;
00067   
00068   typedef Straight_skeleton_builder_2<SsBuilderTraits,Ss> SsBuilder;
00069   
00070   typedef typename std::iterator_traits<PointIterator>::value_type InputPoint ;
00071   typedef typename Kernel_traits<InputPoint>::Kernel InputKernel ;
00072   
00073   Cartesian_converter<InputKernel, K> Point_converter ;
00074   
00075   SsBuilder ssb ;
00076   
00077   ssb.enter_contour( aOuterContour_VerticesBegin, aOuterContour_VerticesEnd, Point_converter ) ;
00078   
00079   for ( HoleIterator hi = aHolesBegin ; hi != aHolesEnd ; ++ hi )
00080     ssb.enter_contour( CGAL_SS_i::vertices_begin(*hi), CGAL_SS_i::vertices_end(*hi), Point_converter ) ;
00081   
00082   return ssb.construct_skeleton();
00083 }
00084 
00085 template<class PointIterator, class HoleIterator>
00086 boost::shared_ptr< Straight_skeleton_2< Exact_predicates_inexact_constructions_kernel > >
00087 inline 
00088 create_interior_straight_skeleton_2 ( PointIterator aOuterContour_VerticesBegin
00089                                     , PointIterator aOuterContour_VerticesEnd
00090                                     , HoleIterator  aHolesBegin
00091                                     , HoleIterator  aHolesEnd
00092                                     )
00093 {
00094   return create_interior_straight_skeleton_2(aOuterContour_VerticesBegin
00095                                             ,aOuterContour_VerticesEnd
00096                                             ,aHolesBegin
00097                                             ,aHolesEnd
00098                                             ,Exact_predicates_inexact_constructions_kernel()
00099                                             );
00100 }
00101 
00102 template<class PointIterator, class K>
00103 boost::shared_ptr< Straight_skeleton_2<K> >
00104 inline
00105 create_interior_straight_skeleton_2 ( PointIterator aOuterContour_VerticesBegin
00106                                     , PointIterator aOuterContour_VerticesEnd 
00107                                     , K const&      k
00108                                     )
00109 {
00110   std::vector< Polygon_2<K> > no_holes ;
00111   return create_interior_straight_skeleton_2(aOuterContour_VerticesBegin
00112                                             ,aOuterContour_VerticesEnd
00113                                             ,no_holes.begin()
00114                                             ,no_holes.end()
00115                                             ,k 
00116                                             );
00117 }
00118 
00119 template<class PointIterator>
00120 boost::shared_ptr< Straight_skeleton_2<Exact_predicates_inexact_constructions_kernel> >
00121 inline
00122 create_interior_straight_skeleton_2 ( PointIterator aOuterContour_VerticesBegin
00123                                     , PointIterator aOuterContour_VerticesEnd 
00124                                     )
00125 {
00126   return create_interior_straight_skeleton_2(aOuterContour_VerticesBegin
00127                                             ,aOuterContour_VerticesEnd
00128                                             ,Exact_predicates_inexact_constructions_kernel() 
00129                                             );
00130 }
00131 
00132 template<class Polygon, class K>
00133 boost::shared_ptr< Straight_skeleton_2<K> >
00134 inline
00135 create_interior_straight_skeleton_2 ( Polygon const& aOutContour, K const& k )
00136 {
00137   return create_interior_straight_skeleton_2(CGAL_SS_i::vertices_begin(aOutContour)
00138                                             ,CGAL_SS_i::vertices_end(aOutContour)
00139                                             ,k 
00140                                             );
00141 }
00142 
00143 template<class Polygon>
00144 boost::shared_ptr< Straight_skeleton_2< Exact_predicates_inexact_constructions_kernel > >
00145 inline
00146 create_interior_straight_skeleton_2 ( Polygon const& aOutContour )
00147 {
00148   return create_interior_straight_skeleton_2(aOutContour, Exact_predicates_inexact_constructions_kernel() );
00149 }
00150 
00151 template<class FT, class PointIterator, class K>
00152 boost::shared_ptr< Straight_skeleton_2<K> >
00153 create_exterior_straight_skeleton_2 ( FT const&      aMaxOffset
00154                                     , PointIterator  aVerticesBegin
00155                                     , PointIterator  aVerticesEnd
00156                                     , K const&       k
00157                                     )
00158 {
00159   typedef typename std::iterator_traits<PointIterator>::value_type Point_2 ;
00160     
00161   typedef Straight_skeleton_2<K> Ss ;
00162   typedef boost::shared_ptr<Ss>  SsPtr ;
00163   
00164   SsPtr rSkeleton ;
00165   
00166   boost::optional<FT> margin = compute_outer_frame_margin( aVerticesBegin
00167                                                          , aVerticesEnd
00168                                                          , aMaxOffset 
00169                                                          );
00170 
00171   if ( margin )
00172   {
00173     
00174     Bbox_2 bbox = bbox_2(aVerticesBegin, aVerticesEnd);
00175 
00176     FT fxmin = bbox.xmin() - *margin ;
00177     FT fxmax = bbox.xmax() + *margin ;
00178     FT fymin = bbox.ymin() - *margin ;
00179     FT fymax = bbox.ymax() + *margin ;
00180 
00181     Point_2 frame[4] ;
00182     
00183     frame[0] = Point_2(fxmin,fymin) ;
00184     frame[1] = Point_2(fxmax,fymin) ;
00185     frame[2] = Point_2(fxmax,fymax) ;
00186     frame[3] = Point_2(fxmin,fymax) ;
00187 
00188     typedef std::vector<Point_2> Hole ;
00189     
00190     Hole lPoly(aVerticesBegin, aVerticesEnd);
00191     std::reverse(lPoly.begin(), lPoly.end());
00192     
00193     std::vector<Hole> holes ;
00194     holes.push_back(lPoly) ;
00195         
00196     rSkeleton = create_interior_straight_skeleton_2(frame, frame+4, holes.begin(), holes.end(), k ) ;  
00197   }
00198   
00199   return rSkeleton ;
00200 }
00201 
00202 template<class FT, class PointIterator>
00203 boost::shared_ptr< Straight_skeleton_2<Exact_predicates_inexact_constructions_kernel> >
00204 inline
00205 create_exterior_straight_skeleton_2 ( FT const&      aMaxOffset
00206                                     , PointIterator  aVerticesBegin
00207                                     , PointIterator  aVerticesEnd
00208                                     )
00209 {
00210   return create_exterior_straight_skeleton_2(aMaxOffset
00211                                             ,aVerticesBegin
00212                                             ,aVerticesEnd
00213                                             ,Exact_predicates_inexact_constructions_kernel()
00214                                             );
00215 }
00216 
00217 
00218 template<class FT, class Polygon, class K>
00219 boost::shared_ptr< Straight_skeleton_2<K> >
00220 inline
00221 create_exterior_straight_skeleton_2 ( FT const& aMaxOffset, Polygon const& aPoly, K const& k )
00222 {
00223   return create_exterior_straight_skeleton_2(aMaxOffset
00224                                             ,CGAL_SS_i::vertices_begin(aPoly)
00225                                             ,CGAL_SS_i::vertices_end  (aPoly)
00226                                             ,k
00227                                             );
00228 }
00229 
00230 template<class FT, class Polygon>
00231 boost::shared_ptr< Straight_skeleton_2<Exact_predicates_inexact_constructions_kernel> >
00232 inline
00233 create_exterior_straight_skeleton_2 ( FT const& aMaxOffset, Polygon const& aPoly )
00234 {
00235   return create_exterior_straight_skeleton_2(aMaxOffset
00236                                             ,aPoly
00237                                             ,Exact_predicates_inexact_constructions_kernel()
00238                                             );
00239 }
00240 
00241 CGAL_END_NAMESPACE
00242 
00243 
00244 #endif // CGAL_STRAIGHT_SKELETON_BUILDER_2_H //
00245 // EOF //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines