// Copyright (c) 2006-2008 Fernando Luis Cacciola Carballal. All rights reserved. // // This file is part of CGAL (www.cgal.org). // // $URL: https://github.com/CGAL/cgal/blob/v5.1/Straight_skeleton_2/include/CGAL/create_offset_polygons_2.h $ // $Id: create_offset_polygons_2.h 0779373 2020-03-26T13:31:46+01:00 Sébastien Loriot // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial // // Author(s) : Fernando Cacciola // #ifndef CGAL_CREATE_OFFSET_POLYGONS_2_H #define CGAL_CREATE_OFFSET_POLYGONS_2_H #include #include #include #include #include #include #include namespace CGAL { namespace CGAL_SS_i { template struct Is_same_type { typedef Tag_false type ; } ; template struct Is_same_type { typedef Tag_true type ; } ; template boost::shared_ptr< Straight_skeleton_2 > create_partial_interior_straight_skeleton_2 ( FT const& aMaxTime , PointIterator aOuterContour_VerticesBegin , PointIterator aOuterContour_VerticesEnd , HoleIterator aHolesBegin , HoleIterator aHolesEnd , K const& ) { typedef Straight_skeleton_2 Ss ; typedef Straight_skeleton_builder_traits_2 SsBuilderTraits; typedef Straight_skeleton_builder_2 SsBuilder; typedef typename K::FT KFT ; typedef typename std::iterator_traits::value_type InputPoint ; typedef typename Kernel_traits::Kernel InputKernel ; Cartesian_converter Converter ; boost::optional lMaxTime( Converter(aMaxTime) ) ; SsBuilder ssb( lMaxTime ) ; ssb.enter_contour( aOuterContour_VerticesBegin, aOuterContour_VerticesEnd, Converter ) ; for ( HoleIterator hi = aHolesBegin ; hi != aHolesEnd ; ++ hi ) ssb.enter_contour( CGAL_SS_i::vertices_begin(*hi), CGAL_SS_i::vertices_end(*hi), Converter ) ; return ssb.construct_skeleton(); } template boost::shared_ptr< Straight_skeleton_2 > create_partial_exterior_straight_skeleton_2 ( FT const& aMaxOffset , PointIterator aVerticesBegin , PointIterator aVerticesEnd , K const& k ) { typedef typename std::iterator_traits::value_type Point_2 ; typedef Straight_skeleton_2 Ss ; typedef boost::shared_ptr SsPtr ; SsPtr rSkeleton ; boost::optional margin = compute_outer_frame_margin( aVerticesBegin , aVerticesEnd , aMaxOffset ); if ( margin ) { Bbox_2 bbox = bbox_2(aVerticesBegin, aVerticesEnd); FT fxmin = bbox.xmin() - *margin ; FT fxmax = bbox.xmax() + *margin ; FT fymin = bbox.ymin() - *margin ; FT fymax = bbox.ymax() + *margin ; Point_2 frame[4] ; frame[0] = Point_2(fxmin,fymin) ; frame[1] = Point_2(fxmax,fymin) ; frame[2] = Point_2(fxmax,fymax) ; frame[3] = Point_2(fxmin,fymax) ; typedef std::vector Hole ; Hole lPoly(aVerticesBegin, aVerticesEnd); std::reverse(lPoly.begin(), lPoly.end()); std::vector holes ; holes.push_back(lPoly) ; rSkeleton = create_partial_interior_straight_skeleton_2(aMaxOffset,frame, frame+4, holes.begin(), holes.end(), k ) ; } return rSkeleton ; } // // Kernel != Skeleton::kernel. The skeleton is converted to Straight_skeleton_2 // template std::vector< boost::shared_ptr > create_offset_polygons_2 ( FT const& aOffset, Skeleton const& aSs, K const& , Tag_false ) { typedef boost::shared_ptr OutPolygonPtr ; typedef std::vector OutPolygonPtrVector ; typedef Straight_skeleton_2 OfSkeleton ; typedef Polygon_offset_builder_traits_2 OffsetBuilderTraits; typedef Polygon_offset_builder_2 OffsetBuilder; OutPolygonPtrVector rR ; boost::shared_ptr lConvertedSs = convert_straight_skeleton_2(aSs); OffsetBuilder ob( *lConvertedSs ); ob.construct_offset_contours(aOffset, std::back_inserter(rR) ) ; return rR ; } // // Kernel == Skeleton::kernel, no convertion // template std::vector< boost::shared_ptr > create_offset_polygons_2 ( FT const& aOffset, Skeleton const& aSs, K const& /*k*/, Tag_true ) { typedef boost::shared_ptr OutPolygonPtr ; typedef std::vector OutPolygonPtrVector ; typedef Polygon_offset_builder_traits_2 OffsetBuilderTraits; typedef Polygon_offset_builder_2 OffsetBuilder; OutPolygonPtrVector rR ; OffsetBuilder ob(aSs); ob.construct_offset_contours(aOffset, std::back_inserter(rR) ) ; return rR ; } // Allow failure due to invalid straight skeletons to go through the users template Skeleton const& dereference ( boost::shared_ptr const& ss ) { CGAL_precondition(ss.get() != 0); return *ss; } } template std::vector< boost::shared_ptr > inline create_offset_polygons_2 ( FT const& aOffset, Skeleton const& aSs, K const& k ) { typedef typename Skeleton::Traits SsKernel ; typename CGAL_SS_i::Is_same_type::type same_kernel ; return CGAL_SS_i::create_offset_polygons_2(aOffset,aSs,k,same_kernel); } template std::vector< boost::shared_ptr< Polygon_2 > > inline create_offset_polygons_2 ( FT const& aOffset, Skeleton const& aSs, K const& k ) { typedef Polygon_2 Polygon ; return create_offset_polygons_2(aOffset, aSs, k ) ; } template std::vector< boost::shared_ptr > inline create_offset_polygons_2 ( FT const& aOffset, Skeleton const& aSs ) { return create_offset_polygons_2(aOffset, aSs, typename Polygon::Traits() ) ; } template std::vector< boost::shared_ptr > inline create_interior_skeleton_and_offset_polygons_2 ( FT const& aOffset , Polygon const& aOuterBoundary , HoleIterator aHolesBegin , HoleIterator aHolesEnd , OfK const& ofk , SsK const& ssk ) { return create_offset_polygons_2 (aOffset ,CGAL_SS_i::dereference ( CGAL_SS_i::create_partial_interior_straight_skeleton_2(aOffset ,CGAL_SS_i::vertices_begin(aOuterBoundary) ,CGAL_SS_i::vertices_end (aOuterBoundary) ,aHolesBegin ,aHolesEnd ,ssk ) ) ,ofk ); } template std::vector< boost::shared_ptr > inline create_interior_skeleton_and_offset_polygons_2 ( FT const& aOffset , Polygon const& aOuterBoundary , HoleIterator aHolesBegin , HoleIterator aHolesEnd , OfK const& ofk ) { return create_interior_skeleton_and_offset_polygons_2(aOffset ,aOuterBoundary ,aHolesBegin ,aHolesEnd ,ofk ,Exact_predicates_inexact_constructions_kernel() ); } template std::vector< boost::shared_ptr > inline create_interior_skeleton_and_offset_polygons_2 ( FT const& aOffset, Polygon const& aPoly, OfK const& ofk, SsK const& ssk ) { std::vector no_holes ; return create_interior_skeleton_and_offset_polygons_2(aOffset ,aPoly ,no_holes.begin() ,no_holes.end() ,ofk ,ssk ); } template std::vector< boost::shared_ptr > inline create_interior_skeleton_and_offset_polygons_2 ( FT const& aOffset, Polygon const& aPoly, OfK const& ofk ) { std::vector no_holes ; return create_interior_skeleton_and_offset_polygons_2(aOffset ,aPoly ,no_holes.begin() ,no_holes.end() ,ofk ,Exact_predicates_inexact_constructions_kernel() ); } template std::vector< boost::shared_ptr > inline create_interior_skeleton_and_offset_polygons_2 ( FT const& aOffset, Polygon const& aPoly ) { return create_interior_skeleton_and_offset_polygons_2(aOffset, aPoly, typename Polygon::Traits() ); } template std::vector< boost::shared_ptr > inline create_exterior_skeleton_and_offset_polygons_2 ( FT const& aOffset, Polygon const& aPoly, OfK const& ofk , SsK const& ssk) { return create_offset_polygons_2 (aOffset ,CGAL_SS_i::dereference (CGAL_SS_i::create_partial_exterior_straight_skeleton_2(aOffset ,CGAL_SS_i::vertices_begin(aPoly) ,CGAL_SS_i::vertices_end (aPoly) ,ssk ) ) ,ofk ); } template std::vector< boost::shared_ptr > inline create_exterior_skeleton_and_offset_polygons_2 ( FT const& aOffset, Polygon const& aPoly, OfK const& ofk ) { return create_exterior_skeleton_and_offset_polygons_2(aOffset ,aPoly ,ofk ,Exact_predicates_inexact_constructions_kernel() ); } template std::vector< boost::shared_ptr > inline create_exterior_skeleton_and_offset_polygons_2 ( FT const& aOffset, Polygon const& aOuterBoundary ) { return create_exterior_skeleton_and_offset_polygons_2(aOffset, aOuterBoundary, typename Polygon::Traits() ); } } // end namespace CGAL #include #endif // EOF //