|
BWAPI
|
00001 // Copyright (c) 2006-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/compute_outer_frame_margin.h $ 00014 // $Id: compute_outer_frame_margin.h 50430 2009-07-07 14:31:18Z fcacciola $ 00015 // 00016 // Author(s) : Fernando Cacciola <fernando_cacciola@ciudad.com.ar> 00017 // 00018 #ifndef CGAL_COMPUTE_OUTER_FRAME_MARGIN_H 00019 #define CGAL_COMPUTE_OUTER_FRAME_MARGIN_H 00020 00021 #include <vector> 00022 #include <algorithm> 00023 00024 #include <boost/shared_ptr.hpp> 00025 #include <boost/optional/optional.hpp> 00026 00027 #include <CGAL/algorithm.h> 00028 #include <CGAL/Polygon_offset_builder_traits_2.h> 00029 00030 CGAL_BEGIN_NAMESPACE 00031 00032 template<class ForwardPointIterator, class Traits> 00033 boost::optional< typename Traits::FT > compute_outer_frame_margin ( ForwardPointIterator aBegin 00034 , ForwardPointIterator aEnd 00035 , typename Traits::FT aOffset 00036 , Traits const& aTraits 00037 ) 00038 { 00039 typedef typename Traits::Kernel Kernel ; 00040 typedef typename Traits::FT FT ; 00041 typedef typename Traits::Point_2 Point_2 ; 00042 typedef typename Traits::Segment_2 Segment_2 ; 00043 typedef typename Traits::Trisegment_2_ptr Trisegment_2_ptr ; 00044 00045 Kernel kernel ; 00046 00047 typename Kernel::Equal_2 equal = kernel.equal_2_object(); 00048 typename Kernel::Collinear_2 collinear = kernel.collinear_2_object(); 00049 typename Kernel::Compute_squared_distance_2 squared_distance = kernel.compute_squared_distance_2_object(); 00050 typename Kernel::Construct_segment_2 construct_segment = kernel.construct_segment_2_object(); 00051 00052 typedef boost::optional<Point_2> OptionalPoint_2 ; 00053 00054 FT lMaxSDist(0.0) ; 00055 00056 ForwardPointIterator lLast = CGAL::predecessor(aEnd) ; 00057 00058 bool lOverflow = false ; 00059 00060 for ( ForwardPointIterator lCurr = aBegin ; lCurr != aEnd ; ++ lCurr ) 00061 { 00062 ForwardPointIterator lPrev = ( lCurr == aBegin ? lLast : CGAL::predecessor(lCurr) ) ; 00063 ForwardPointIterator lNext = ( lCurr == lLast ? aBegin : CGAL::successor (lCurr) ) ; 00064 00065 if ( !equal(*lPrev,*lCurr) && !equal(*lCurr,*lNext) && !collinear(*lPrev,*lCurr,*lNext) ) 00066 { 00067 Segment_2 lLEdge = construct_segment(*lPrev,*lCurr); 00068 Segment_2 lREdge = construct_segment(*lCurr,*lNext); 00069 00070 OptionalPoint_2 lP = Construct_offset_point_2(aTraits)(aOffset,lLEdge,lREdge, Trisegment_2_ptr() ); 00071 00072 if ( !lP ) 00073 { 00074 lOverflow = true ; 00075 break ; 00076 } 00077 00078 FT lSDist = CGAL::squared_distance(*lCurr,*lP); 00079 00080 if ( ! CGAL_NTS is_valid ( lSDist ) 00081 || ! CGAL_NTS is_finite( lSDist ) 00082 ) 00083 { 00084 lOverflow = true ; 00085 break ; 00086 } 00087 00088 if ( lSDist > lMaxSDist ) 00089 lMaxSDist = lSDist ; 00090 } 00091 } 00092 00093 if ( ! lOverflow ) 00094 { 00095 FT lDist = CGAL_SS_i::inexact_sqrt(lMaxSDist) ; 00096 00097 return boost::optional<FT>( lDist + ( aOffset * FT(1.05) ) ) ; // Add a %5 gap 00098 } 00099 else 00100 return boost::optional<FT>(); 00101 00102 } 00103 00104 template<class ForwardPointIterator, class FT> 00105 boost::optional<FT> compute_outer_frame_margin ( ForwardPointIterator aBegin, ForwardPointIterator aEnd, FT aOffset ) 00106 { 00107 typedef typename std::iterator_traits<ForwardPointIterator>::value_type Point_2 ; 00108 00109 typedef typename Kernel_traits<Point_2>::Kernel K; 00110 00111 Polygon_offset_builder_traits_2<K> traits ; 00112 00113 return compute_outer_frame_margin(aBegin,aEnd,aOffset,traits); 00114 } 00115 00116 CGAL_END_NAMESPACE 00117 00118 #endif // CGAL_COMPUTE_OUTER_FRAME_MARGIN_H // 00119 // EOF // 00120 00121
1.7.6.1