dust3d/thirdparty/cgal/CGAL-5.1/include/CGAL/Straight_skeleton_builder_2.h

932 lines
29 KiB
C
Raw Normal View History

// Copyright (c) 2006-2008 Fernando Luis Cacciola Carballal. All rights reserved.
//
// This file is part of CGAL (www.cgal.org).
//
2020-10-13 12:44:25 +00:00
// $URL: https://github.com/CGAL/cgal/blob/v5.1/Straight_skeleton_2/include/CGAL/Straight_skeleton_builder_2.h $
// $Id: Straight_skeleton_builder_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 <fernando_cacciola@ciudad.com.ar>
//
#ifndef CGAL_STRAIGHT_SKELETON_BUILDER_2_H
#define CGAL_STRAIGHT_SKELETON_BUILDER_2_H 1
#include <CGAL/license/Straight_skeleton_2.h>
#include <CGAL/disable_warnings.h>
#include <list>
#include <queue>
#include <exception>
#include <string>
#include <map>
#include <boost/tuple/tuple.hpp>
#include <boost/intrusive_ptr.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/scoped_ptr.hpp>
#include <CGAL/algorithm.h>
#include <CGAL/Straight_skeleton_2/Straight_skeleton_aux.h>
#include <CGAL/Straight_skeleton_2/Straight_skeleton_builder_events_2.h>
#include <CGAL/Straight_skeleton_2.h>
#include <CGAL/Straight_skeleton_builder_traits_2.h>
#include <CGAL/HalfedgeDS_const_decorator.h>
#include <CGAL/enum.h>
namespace CGAL {
template<class SSkel_>
struct Dummy_straight_skeleton_builder_2_visitor
{
typedef SSkel_ SSkel ;
typedef typename SSkel::Halfedge_const_handle Halfedge_const_handle ;
typedef typename SSkel::Vertex_const_handle Vertex_const_handle ;
void on_contour_edge_entered ( Halfedge_const_handle const& ) const {}
2020-10-13 12:44:25 +00:00
void on_initialization_started( std::size_t /* size_of_vertices */ ) const {}
2020-10-13 12:44:25 +00:00
void on_initial_events_collected( Vertex_const_handle const& , bool /* is_reflex */, bool /*is_degenerate*/ ) const {}
2020-10-13 12:44:25 +00:00
void on_edge_event_created( Vertex_const_handle const& /* lnode */
2020-10-13 12:44:25 +00:00
, Vertex_const_handle const& /* rnode */
) const {}
void on_split_event_created( Vertex_const_handle const& ) const {}
void on_pseudo_split_event_created( Vertex_const_handle const& /* lnode */
, Vertex_const_handle const& /* rnode */
) const {}
2020-10-13 12:44:25 +00:00
void on_initialization_finished() const {}
2020-10-13 12:44:25 +00:00
void on_propagation_started() const {}
2020-10-13 12:44:25 +00:00
void on_anihiliation_event_processed ( Vertex_const_handle const& /* node0 */
, Vertex_const_handle const& /* node1 */
) const {}
void on_edge_event_processed( Vertex_const_handle const& /* lseed */
, Vertex_const_handle const& /* rseed */
, Vertex_const_handle const& /* node */
2020-10-13 12:44:25 +00:00
) const {}
void on_split_event_processed( Vertex_const_handle const& /* seed */
, Vertex_const_handle const& /* node0 */
, Vertex_const_handle const& /* node1 */
) const {}
void on_pseudo_split_event_processed( Vertex_const_handle const& /* lseed */
, Vertex_const_handle const& /* rseed */
, Vertex_const_handle const& /* node0 */
, Vertex_const_handle const& /* node1 */
) const {}
void on_vertex_processed( Vertex_const_handle const& ) const {}
2020-10-13 12:44:25 +00:00
void on_propagation_finished() const {}
2020-10-13 12:44:25 +00:00
void on_cleanup_started() const {}
2020-10-13 12:44:25 +00:00
void on_cleanup_finished() const {}
2020-10-13 12:44:25 +00:00
void on_algorithm_finished ( bool /* finished_ok */ ) const {}
2020-10-13 12:44:25 +00:00
void on_error( char const* ) const {}
} ;
template<class Traits_, class SSkel_, class Visitor_ = Dummy_straight_skeleton_builder_2_visitor<SSkel_> >
class Straight_skeleton_builder_2
{
public:
typedef Traits_ Traits ;
typedef SSkel_ SSkel ;
typedef Visitor_ Visitor ;
typedef boost::shared_ptr<SSkel> SSkelPtr ;
2020-10-13 12:44:25 +00:00
private :
typedef typename Traits::Kernel K ;
2020-10-13 12:44:25 +00:00
typedef typename Traits::FT FT ;
typedef typename Traits::Point_2 Point_2 ;
typedef typename Traits::Vector_2 Vector_2 ;
typedef typename Traits::Direction_2 Direction_2 ;
typedef typename Traits::Segment_2 Segment_2 ;
typedef typename Traits::Trisegment_2 Trisegment_2 ;
typedef typename Traits::Trisegment_2_ptr Trisegment_2_ptr ;
2020-10-13 12:44:25 +00:00
typedef typename SSkel::Vertex Vertex ;
typedef typename SSkel::Halfedge Halfedge ;
typedef typename SSkel::Face Face ;
typedef typename SSkel::Vertex_const_handle Vertex_const_handle ;
typedef typename SSkel::Halfedge_const_handle Halfedge_const_handle ;
typedef typename SSkel::Face_const_handle Face_const_handle ;
typedef typename SSkel::Vertex_const_iterator Vertex_const_iterator ;
typedef typename SSkel::Halfedge_const_iterator Halfedge_const_iterator ;
typedef typename SSkel::Face_const_iterator Face_const_iterator ;
typedef typename SSkel::Vertex_handle Vertex_handle ;
typedef typename SSkel::Halfedge_handle Halfedge_handle ;
typedef typename SSkel::Face_handle Face_handle ;
typedef typename SSkel::Vertex_iterator Vertex_iterator ;
typedef typename SSkel::Halfedge_iterator Halfedge_iterator ;
typedef typename SSkel::Face_iterator Face_iterator ;
typedef typename Vertex::Halfedge_around_vertex_circulator Halfedge_around_vertex_circulator ;
2020-10-13 12:44:25 +00:00
typedef typename SSkel::size_type size_type ;
typedef CGAL_SS_i::Triedge<Halfedge_handle> Triedge ;
2020-10-13 12:44:25 +00:00
typedef CGAL_SS_i::Event_2 <SSkel,Traits> Event ;
typedef CGAL_SS_i::Edge_event_2 <SSkel,Traits> EdgeEvent ;
typedef CGAL_SS_i::Split_event_2 <SSkel,Traits> SplitEvent ;
typedef CGAL_SS_i::Pseudo_split_event_2<SSkel,Traits> PseudoSplitEvent ;
typedef boost::intrusive_ptr<Event> EventPtr ;
typedef std::pair<Vertex_handle,Vertex_handle> Vertex_handle_pair ;
2020-10-13 12:44:25 +00:00
typedef std::vector<EventPtr> EventPtr_Vector ;
typedef std::vector<Halfedge_handle> Halfedge_handle_vector ;
typedef std::vector<Vertex_handle> Vertex_handle_vector ;
typedef std::vector<Vertex_handle_pair> Vertex_handle_pair_vector ;
2020-10-13 12:44:25 +00:00
typedef typename Halfedge_handle_vector ::iterator Halfedge_handle_vector_iterator ;
typedef typename Vertex_handle_vector ::iterator Vertex_handle_vector_iterator ;
typedef typename Vertex_handle_pair_vector::iterator Vertex_handle_pair_vector_iterator ;
2020-10-13 12:44:25 +00:00
typedef typename EventPtr_Vector::const_iterator event_const_iterator ;
typedef Straight_skeleton_builder_2<Traits,SSkel,Visitor> Self ;
2020-10-13 12:44:25 +00:00
typedef typename Halfedge::Base_base HBase_base ;
typedef typename Halfedge::Base HBase ;
typedef typename Vertex::Base VBase ;
typedef typename Face::Base FBase ;
2020-10-13 12:44:25 +00:00
enum Site { AT_SOURCE = -1 , INSIDE = 0, AT_TARGET = +1 } ;
2020-10-13 12:44:25 +00:00
struct Multinode : public Ref_counted_base
{
Multinode ( Halfedge_handle b, Halfedge_handle e )
:
begin(b)
,end (e)
,v (b->vertex())
,size (0)
{}
2020-10-13 12:44:25 +00:00
Halfedge_handle begin ;
Halfedge_handle end ;
Vertex_handle v ;
std::size_t size ;
Halfedge_handle_vector bisectors_to_relink ;
Halfedge_handle_vector bisectors_to_remove ;
Vertex_handle_vector nodes_to_remove ;
2020-10-13 12:44:25 +00:00
} ;
typedef boost::intrusive_ptr<Multinode> MultinodePtr ;
2020-10-13 12:44:25 +00:00
struct MultinodeComparer
{
bool operator() ( MultinodePtr const& x, MultinodePtr const& y ) { return x->size > y->size ; }
} ;
2020-10-13 12:44:25 +00:00
typedef std::vector<MultinodePtr> MultinodeVector ;
struct Halfedge_ID_compare : CGAL::cpp98::binary_function<bool,Halfedge_handle,Halfedge_handle>
{
bool operator() ( Halfedge_handle const& aA, Halfedge_handle const& aB ) const
{
return aA->id() < aB->id() ;
}
} ;
2020-10-13 12:44:25 +00:00
public:
Straight_skeleton_builder_2 ( boost::optional<FT> aMaxTime = boost::none, Traits const& = Traits(), Visitor const& aVisitor = Visitor() ) ;
2020-10-13 12:44:25 +00:00
SSkelPtr construct_skeleton( bool aNull_if_failed = true ) ;
private :
2020-10-13 12:44:25 +00:00
class Event_compare : public CGAL::cpp98::binary_function<bool,EventPtr,EventPtr>
{
public:
Event_compare ( Self const* aBuilder ) : mBuilder(aBuilder) {}
bool operator() ( EventPtr const& aA, EventPtr const& aB ) const
{
return mBuilder->CompareEvents(aA,aB) == LARGER ;
}
private:
Self const* mBuilder ;
} ;
typedef std::priority_queue<EventPtr,std::vector<EventPtr>,Event_compare> PQ ;
struct Vertex_data : public Ref_counted_base
{
Vertex_data ( Vertex_handle aVertex, Event_compare const& aComparer )
:
mVertex(aVertex)
, mIsReflex(false)
, mIsDegenerate(false)
, mIsProcessed(false)
, mIsExcluded(false)
, mPrevInLAV(-1)
, mNextInLAV(-1)
, mNextSplitEventInMainPQ(false)
, mSplitEvents(aComparer)
{}
Vertex_handle mVertex ;
bool mIsReflex ;
bool mIsDegenerate ;
bool mIsProcessed ;
bool mIsExcluded ;
int mPrevInLAV ;
int mNextInLAV ;
bool mNextSplitEventInMainPQ;
PQ mSplitEvents ;
Triedge mTriedge ; // Here, E0,E1 corresponds to the vertex (unlike *event* triedges)
Trisegment_2_ptr mTrisegment ; // Skeleton nodes cache the full trisegment tree that defines the originating event
} ;
2020-10-13 12:44:25 +00:00
typedef boost::intrusive_ptr<Vertex_data> Vertex_data_ptr ;
2020-10-13 12:44:25 +00:00
private :
Halfedge_handle validate( Halfedge_handle aH ) const ;
Vertex_handle validate( Vertex_handle aH ) const ;
void InitVertexData( Vertex_handle aV )
{
mVertexData.push_back( Vertex_data_ptr( new Vertex_data(aV,mEventCompare) ) ) ;
2020-10-13 12:44:25 +00:00
}
Vertex_data const& GetVertexData( Vertex_const_handle aV ) const
{
CGAL_precondition( handle_assigned(aV) ) ;
return *mVertexData[aV->id()];
}
Vertex_data& GetVertexData( Vertex_const_handle aV )
{
CGAL_precondition( handle_assigned(aV) ) ;
return *mVertexData[aV->id()];
}
Vertex_handle GetVertex ( int aIdx )
{
CGAL_precondition(aIdx>=0);
return mVertexData[aIdx]->mVertex ;
}
// Null if aV is a contour or infinite node
Trisegment_2_ptr const& GetTrisegment ( Vertex_handle aV ) const
{
return GetVertexData(aV).mTrisegment ;
}
2020-10-13 12:44:25 +00:00
void SetTrisegment ( Vertex_handle aV, Trisegment_2_ptr const& aTrisegment )
{
GetVertexData(aV).mTrisegment = aTrisegment ;
}
2020-10-13 12:44:25 +00:00
// Null if aV is a contour node
Triedge const& GetVertexTriedge ( Vertex_handle aV ) const
{
return GetVertexData(aV).mTriedge ;
}
2020-10-13 12:44:25 +00:00
void SetVertexTriedge ( Vertex_handle aV, Triedge const& aTriedge )
{
GetVertexData(aV).mTriedge = aTriedge ;
}
2020-10-13 12:44:25 +00:00
Segment_2 CreateSegment ( Halfedge_const_handle aH ) const
{
Point_2 s = aH->opposite()->vertex()->point() ;
Point_2 t = aH->vertex()->point() ;
return K().construct_segment_2_object()(s,t);
}
2020-10-13 12:44:25 +00:00
Vector_2 CreateVector ( Halfedge_const_handle aH ) const
{
Point_2 s = aH->opposite()->vertex()->point() ;
Point_2 t = aH->vertex()->point() ;
return K().construct_vector_2_object()(s,t);
}
2020-10-13 12:44:25 +00:00
Direction_2 CreateDirection ( Halfedge_const_handle aH ) const
{
return K().construct_direction_2_object()( CreateVector(aH) );
}
Trisegment_2_ptr CreateTrisegment ( Triedge const& aTriedge ) const
{
CGAL_precondition(aTriedge.is_valid() && aTriedge.is_skeleton());
2020-10-13 12:44:25 +00:00
Trisegment_2_ptr r = Construct_ss_trisegment_2(mTraits)(CreateSegment(aTriedge.e0())
,CreateSegment(aTriedge.e1())
,CreateSegment(aTriedge.e2())
);
2020-10-13 12:44:25 +00:00
CGAL_STSKEL_BUILDER_TRACE(5,"Trisegment for " << aTriedge << ":" << r ) ;
2020-10-13 12:44:25 +00:00
CGAL_postcondition_msg((r!= Trisegment_2_ptr()), "Unable to determine edges collinearity");
2020-10-13 12:44:25 +00:00
return r ;
}
2020-10-13 12:44:25 +00:00
Trisegment_2_ptr CreateTrisegment ( Triedge const& aTriedge, Vertex_handle aLSeed ) const
{
Trisegment_2_ptr r = CreateTrisegment( aTriedge ) ;
r->set_child_l( GetTrisegment(aLSeed) ) ;
return r ;
}
2020-10-13 12:44:25 +00:00
Trisegment_2_ptr CreateTrisegment ( Triedge const& aTriedge, Vertex_handle aLSeed, Vertex_handle aRSeed ) const
{
Trisegment_2_ptr r = CreateTrisegment( aTriedge ) ;
r->set_child_l( GetTrisegment(aLSeed) ) ;
r->set_child_r( GetTrisegment(aRSeed) ) ;
return r ;
}
2020-10-13 12:44:25 +00:00
Vertex_handle GetPrevInLAV ( Vertex_handle aV )
{
return GetVertex ( GetVertexData(aV).mPrevInLAV ) ;
}
Vertex_handle GetNextInLAV ( Vertex_handle aV )
{
return GetVertex ( GetVertexData(aV).mNextInLAV ) ;
}
void SetPrevInLAV ( Vertex_handle aV, Vertex_handle aPrev )
{
GetVertexData(aV).mPrevInLAV = aPrev->id();
}
void SetNextInLAV ( Vertex_handle aV, Vertex_handle aPrev )
{
GetVertexData(aV).mNextInLAV = aPrev->id();
}
Halfedge_handle GetEdgeEndingAt ( Vertex_handle aV )
{
return GetVertexTriedge(aV).e0();
}
2020-10-13 12:44:25 +00:00
Halfedge_handle GetEdgeStartingAt ( Vertex_handle aV )
{
return GetEdgeEndingAt( GetNextInLAV(aV) ) ;
}
2020-10-13 12:44:25 +00:00
void Exclude ( Vertex_handle aV )
{
GetVertexData(aV).mIsExcluded = true ;
}
bool IsExcluded ( Vertex_const_handle aV ) const
{
return GetVertexData(aV).mIsExcluded ;
}
void SetIsReflex ( Vertex_handle aV )
{
GetVertexData(aV).mIsReflex = true ;
}
bool IsReflex ( Vertex_handle aV )
{
return GetVertexData(aV).mIsReflex ;
}
void SetIsDegenerate ( Vertex_handle aV )
{
GetVertexData(aV).mIsDegenerate = true ;
}
bool IsDegenerate ( Vertex_handle aV )
{
return GetVertexData(aV).mIsDegenerate ;
}
2020-10-13 12:44:25 +00:00
void SetIsProcessed ( Vertex_handle aV )
{
GetVertexData(aV).mIsProcessed = true ;
mVisitor.on_vertex_processed(aV);
}
bool IsConvex ( Vertex_handle aV )
{
Vertex_data const& lData = GetVertexData(aV) ;
return !lData.mIsReflex && !lData.mIsDegenerate ;
}
2020-10-13 12:44:25 +00:00
bool IsProcessed ( Vertex_handle aV )
{
return GetVertexData(aV).mIsProcessed ;
}
void AddSplitEvent ( Vertex_handle aV, EventPtr aEvent )
{
CGAL_STSKEL_BUILDER_TRACE(2, "V" << aV->id() << " PQ: " << *aEvent);
GetVertexData(aV).mSplitEvents.push(aEvent);
}
2020-10-13 12:44:25 +00:00
EventPtr PopNextSplitEvent ( Vertex_handle aV )
{
EventPtr rEvent ;
Vertex_data& lData = GetVertexData(aV) ;
if ( !lData.mNextSplitEventInMainPQ )
{
PQ& lPQ = lData.mSplitEvents ;
if ( !lPQ.empty() )
{
2020-10-13 12:44:25 +00:00
rEvent = lPQ.top();
lPQ.pop();
lData.mNextSplitEventInMainPQ = true ;
}
}
return rEvent ;
}
void AllowNextSplitEvent ( Vertex_handle aV )
{
GetVertexData(aV).mNextSplitEventInMainPQ = false ;
2020-10-13 12:44:25 +00:00
}
void InsertEventInPQ( EventPtr aEvent ) ;
EventPtr PopEventFromPQ() ;
bool ExistEvent ( Trisegment_2_ptr const& aS )
{
return Do_ss_event_exist_2(mTraits)(aS,mMaxTime);
2020-10-13 12:44:25 +00:00
}
bool IsOppositeEdgeFacingTheSplitSeed( Vertex_handle aSeed, Halfedge_handle aOpposite ) const
{
if ( aSeed->is_skeleton() )
return Is_edge_facing_ss_node_2(mTraits)( GetTrisegment(aSeed), CreateSegment(aOpposite) ) ;
else return Is_edge_facing_ss_node_2(mTraits)( aSeed->point() , CreateSegment(aOpposite) ) ;
}
2020-10-13 12:44:25 +00:00
Oriented_side EventPointOrientedSide( Event const& aEvent
, Halfedge_const_handle aE0
, Halfedge_const_handle aE1
, Vertex_handle aV01
, bool aE0isPrimary
) const
{
return Oriented_side_of_event_point_wrt_bisector_2(mTraits)( aEvent.trisegment()
, CreateSegment(aE0)
, CreateSegment(aE1)
, GetTrisegment(aV01) // Can be null
, aE0isPrimary
) ;
}
Comparison_result CompareEvents ( Trisegment_2_ptr const& aA, Trisegment_2_ptr const& aB ) const
{
return Compare_ss_event_times_2(mTraits)(aA,aB) ;
}
Comparison_result CompareEvents ( EventPtr const& aA, EventPtr const& aB ) const
{
return aA->triedge() != aB->triedge() ? CompareEvents( aA->trisegment(), aB->trisegment() ) : EQUAL ;
}
2020-10-13 12:44:25 +00:00
bool AreEventsSimultaneous( Trisegment_2_ptr const& x, Trisegment_2_ptr const& y ) const
{
return Are_ss_events_simultaneous_2(mTraits)(x,y) ;
}
2020-10-13 12:44:25 +00:00
bool AreEventsSimultaneous( EventPtr const& x, EventPtr const& y ) const
{
return AreEventsSimultaneous(x->trisegment(),y->trisegment());
}
2020-10-13 12:44:25 +00:00
bool AreContourNodesCoincident( Vertex_handle aX, Vertex_handle aY ) const
{
CGAL_precondition( aX->is_contour() );
CGAL_precondition( aY->is_contour() );
2020-10-13 12:44:25 +00:00
return CGAL::compare_xy(aX->point(),aY->point()) == EQUAL ;
}
bool AreSkeletonNodesCoincident( Vertex_handle aX, Vertex_handle aY ) const
{
CGAL_precondition( aX->is_skeleton() );
CGAL_precondition( aY->is_skeleton() );
CGAL_precondition( !aX->has_infinite_time() );
CGAL_precondition( !aY->has_infinite_time() );
2020-10-13 12:44:25 +00:00
return AreEventsSimultaneous( GetTrisegment(aX), GetTrisegment(aY) ) ;
}
2020-10-13 12:44:25 +00:00
Comparison_result CompareEvents( Trisegment_2_ptr const& aTrisegment, Vertex_handle aSeedNode ) const
{
return aSeedNode->is_skeleton() ? aSeedNode->has_infinite_time() ? SMALLER
: CompareEvents( aTrisegment, GetTrisegment(aSeedNode) )
: LARGER ;
}
2020-10-13 12:44:25 +00:00
void SetBisectorSlope ( Halfedge_handle aBisector, Sign aSlope )
{
aBisector->HBase_base::set_slope(aSlope);
}
2020-10-13 12:44:25 +00:00
void SetBisectorSlope ( Vertex_handle aA, Vertex_handle aB )
{
Halfedge_handle lOBisector = aA->primary_bisector();
Halfedge_handle lIBisector = lOBisector->opposite();
CGAL_precondition( !aA->is_contour() || !aB->is_contour() ) ;
2020-10-13 12:44:25 +00:00
if ( aA->is_contour() )
{
SetBisectorSlope(lOBisector,POSITIVE);
SetBisectorSlope(lIBisector,NEGATIVE);
}
else if ( aB->is_contour())
{
SetBisectorSlope(lOBisector,NEGATIVE);
SetBisectorSlope(lIBisector,POSITIVE);
}
else
{
if ( aA->has_infinite_time() )
{
CGAL_precondition( !aB->has_infinite_time());
2020-10-13 12:44:25 +00:00
SetBisectorSlope(lOBisector,NEGATIVE);
SetBisectorSlope(lIBisector,POSITIVE);
}
else if ( aB->has_infinite_time())
{
CGAL_precondition( !aA->has_infinite_time());
2020-10-13 12:44:25 +00:00
SetBisectorSlope(lOBisector,NEGATIVE);
SetBisectorSlope(lIBisector,POSITIVE);
}
else
{
CGAL_precondition( !aA->has_infinite_time());
CGAL_precondition( !aB->has_infinite_time());
2020-10-13 12:44:25 +00:00
Sign lSlope = CompareEvents(GetTrisegment(aB),GetTrisegment(aA));
SetBisectorSlope(lOBisector,lSlope);
SetBisectorSlope(lIBisector,opposite(lSlope));
}
}
}
boost::tuple<FT,Point_2> ConstructEventTimeAndPoint( Trisegment_2_ptr const& aS ) const
{
boost::optional< boost::tuple<FT,Point_2> > r = Construct_ss_event_time_and_point_2(mTraits)(aS);
CGAL_postcondition_msg(!!r, "Unable to compute skeleton node coordinates");
2020-10-13 12:44:25 +00:00
return *r ;
}
void SetEventTimeAndPoint( Event& aE )
{
FT lTime ;
Point_2 lP ;
boost::tie(lTime,lP) = ConstructEventTimeAndPoint(aE.trisegment());
2020-10-13 12:44:25 +00:00
aE.SetTimeAndPoint(lTime,lP);
}
2020-10-13 12:44:25 +00:00
void EraseBisector( Halfedge_handle aB )
{
CGAL_STSKEL_BUILDER_TRACE(1,"Dangling B" << aB->id() << " and B" << aB->opposite()->id() << " removed.");
2020-10-13 12:44:25 +00:00
mSSkel->SSkel::Base::edges_erase(aB);
}
#ifdef CGAL_STSKEL_TRACE_ON
std::string wavefront2str( Vertex_handle v )
{
2020-10-13 12:44:25 +00:00
std::ostringstream ss ;
ss << "N" << GetPrevInLAV(v)->id() << "->N" << v->id() << "->N" << GetNextInLAV(v)->id()
<< " E" << GetVertexTriedge(v).e0()->id() << "->E" << GetVertexTriedge(v).e1()->id() ;
2020-10-13 12:44:25 +00:00
return ss.str() ;
2020-10-13 12:44:25 +00:00
}
#endif
2020-10-13 12:44:25 +00:00
void Link( Halfedge_handle aH, Face_handle aF )
{
aH->HBase_base::set_face(aF);
}
2020-10-13 12:44:25 +00:00
void Link( Halfedge_handle aH, Vertex_handle aV )
{
aH->HBase_base::set_vertex(aV);
}
2020-10-13 12:44:25 +00:00
void Link( Vertex_handle aV, Halfedge_handle aH )
{
aV->VBase::set_halfedge(aH);
}
2020-10-13 12:44:25 +00:00
void CrossLinkFwd( Halfedge_handle aPrev, Halfedge_handle aNext )
{
aPrev->HBase_base::set_next(aNext);
aNext->HBase_base::set_prev(aPrev);
}
2020-10-13 12:44:25 +00:00
void CrossLink( Halfedge_handle aH, Vertex_handle aV )
{
Link(aH,aV);
Link(aV,aH);
}
2020-10-13 12:44:25 +00:00
Triedge GetCommonTriedge( Vertex_handle aA, Vertex_handle aB ) ;
bool AreBisectorsCoincident ( Halfedge_const_handle aA, Halfedge_const_handle aB ) const ;
2020-10-13 12:44:25 +00:00
EventPtr IsPseudoSplitEvent( EventPtr const& aEvent, Vertex_handle_pair aOpp, Site const& aSite ) ;
2020-10-13 12:44:25 +00:00
void CollectSplitEvent( Vertex_handle aNode, Triedge const& aTriedge ) ;
void CollectSplitEvents( Vertex_handle aNode, Triedge const& aPrevEventTriedge ) ;
EventPtr FindEdgeEvent( Vertex_handle aLNode, Vertex_handle aRNode, Triedge const& aPrevEventTriedge ) ;
void HandleSimultaneousEdgeEvent( Vertex_handle aA, Vertex_handle aB ) ;
void CollectNewEvents( Vertex_handle aNode, Triedge const& aPrevEventTriedge ) ;
void UpdatePQ( Vertex_handle aV, Triedge const& aPrevEventTriedge ) ;
void CreateInitialEvents();
void CreateContourBisectors();
void InitPhase();
void SetupNewNode( Vertex_handle aNode );
Vertex_handle_pair LookupOnSLAV ( Halfedge_handle aOBorder, EventPtr const& aEvent, Site& rSite ) ;
Vertex_handle ConstructEdgeEventNode ( EdgeEvent& aEvent ) ;
Vertex_handle_pair ConstructSplitEventNodes ( SplitEvent& aEvent, Vertex_handle aOppR ) ;
Vertex_handle_pair ConstructPseudoSplitEventNodes ( PseudoSplitEvent& aEvent ) ;
bool IsValidEdgeEvent ( EdgeEvent const& aEvent ) ;
bool IsValidSplitEvent ( SplitEvent const& aEvent ) ;
bool IsValidPseudoSplitEvent ( PseudoSplitEvent const& aEvent ) ;
2020-10-13 12:44:25 +00:00
void HandleEdgeEvent ( EventPtr aEvent ) ;
void HandleSplitEvent ( EventPtr aEvent, Vertex_handle_pair aOpp ) ;
void HandlePseudoSplitEvent ( EventPtr aEvent ) ;
void HandleSplitOrPseudoSplitEvent ( EventPtr aEvent ) ;
2020-10-13 12:44:25 +00:00
void InsertNextSplitEventInPQ( Vertex_handle v ) ;
void InsertNextSplitEventsInPQ() ;
2020-10-13 12:44:25 +00:00
bool IsProcessed( EventPtr aEvent ) ;
void Propagate();
2020-10-13 12:44:25 +00:00
void EraseNode ( Vertex_handle aNode ) ;
void MergeSplitNodes ( Vertex_handle_pair aSplitNodes ) ;
2020-10-13 12:44:25 +00:00
void RelinkBisectorsAroundMultinode( Vertex_handle const& v0, Halfedge_handle_vector& aLinks ) ;
2020-10-13 12:44:25 +00:00
void PreprocessMultinode( Multinode& aMN ) ;
2020-10-13 12:44:25 +00:00
void ProcessMultinode( Multinode& aMN, Halfedge_handle_vector& rHalfedgesToRemove , Vertex_handle_vector& rNodesToRemove ) ;
MultinodePtr CreateMultinode( Halfedge_handle begin, Halfedge_handle end ) ;
2020-10-13 12:44:25 +00:00
void MergeCoincidentNodes() ;
2020-10-13 12:44:25 +00:00
bool FinishUp();
bool Run();
private:
//Input
Traits mTraits ;
Visitor const& mVisitor ;
std::vector<Vertex_data_ptr> mVertexData ;
2020-10-13 12:44:25 +00:00
Vertex_handle_vector mReflexVertices ;
Halfedge_handle_vector mDanglingBisectors ;
Halfedge_handle_vector mContourHalfedges ;
std::list<Vertex_handle> mGLAV ;
Vertex_handle_pair_vector mSplitNodes ;
Event_compare mEventCompare ;
int mVertexID ;
int mEdgeID ;
int mFaceID ;
int mEventID ;
int mStepID ;
boost::optional<FT> mMaxTime ;
2020-10-13 12:44:25 +00:00
PQ mPQ ;
//Output
SSkelPtr mSSkel ;
2020-10-13 12:44:25 +00:00
private :
template<class InputPointIterator, class Converter>
void enter_valid_contour ( InputPointIterator aBegin, InputPointIterator aEnd, Converter const& cvt )
{
CGAL_STSKEL_BUILDER_TRACE(0,"Inserting Connected Component of the Boundary....");
Halfedge_handle lFirstCCWBorder ;
Halfedge_handle lPrevCCWBorder ;
Halfedge_handle lNextCWBorder ;
Vertex_handle lFirstVertex ;
Vertex_handle lPrevVertex ;
InputPointIterator lCurr = aBegin ;
// InputPointIterator lPrev = aBegin ;
2020-10-13 12:44:25 +00:00
int c = 0 ;
2020-10-13 12:44:25 +00:00
while ( lCurr != aEnd )
{
Halfedge_handle lCCWBorder = mSSkel->SSkel::Base::edges_push_back ( Halfedge(mEdgeID),Halfedge(mEdgeID+1) );
Halfedge_handle lCWBorder = lCCWBorder->opposite();
mEdgeID += 2 ;
mContourHalfedges.push_back(lCCWBorder);
Vertex_handle lVertex = mSSkel->SSkel::Base::vertices_push_back( Vertex(mVertexID++,cvt(*lCurr)) ) ;
CGAL_STSKEL_BUILDER_TRACE(1,"Vertex: V" << lVertex->id() << " at " << lVertex->point() );
InitVertexData(lVertex);
Face_handle lFace = mSSkel->SSkel::Base::faces_push_back( Face(mFaceID++) ) ;
++ c ;
lCCWBorder->HBase_base::set_face(lFace);
lFace ->FBase ::set_halfedge(lCCWBorder);
lVertex ->VBase ::set_halfedge(lCCWBorder);
lCCWBorder->HBase_base::set_vertex(lVertex);
if ( lCurr == aBegin )
{
lFirstVertex = lVertex ;
lFirstCCWBorder = lCCWBorder ;
}
else
{
SetPrevInLAV(lVertex ,lPrevVertex);
SetNextInLAV(lPrevVertex,lVertex );
SetVertexTriedge(lPrevVertex, Triedge(lPrevCCWBorder,lCCWBorder) ) ;
2020-10-13 12:44:25 +00:00
lCWBorder->HBase_base::set_vertex(lPrevVertex);
lCCWBorder ->HBase_base::set_prev(lPrevCCWBorder);
lPrevCCWBorder->HBase_base::set_next(lCCWBorder);
lNextCWBorder->HBase_base::set_prev(lCWBorder);
lCWBorder ->HBase_base::set_next(lNextCWBorder);
CGAL_STSKEL_BUILDER_TRACE(1,"CCW Border: E" << lCCWBorder->id() << ' ' << lPrevVertex->point() << " -> " << lVertex ->point());
CGAL_STSKEL_BUILDER_TRACE(1,"CW Border: E" << lCWBorder ->id() << ' ' << lVertex ->point() << " -> " << lPrevVertex->point() );
2020-10-13 12:44:25 +00:00
mVisitor.on_contour_edge_entered(lCCWBorder);
}
// lPrev = lCurr ;
2020-10-13 12:44:25 +00:00
++ lCurr ;
lPrevVertex = lVertex ;
lPrevCCWBorder = lCCWBorder ;
lNextCWBorder = lCWBorder ;
}
SetPrevInLAV(lFirstVertex,lPrevVertex );
SetNextInLAV(lPrevVertex ,lFirstVertex);
SetVertexTriedge( lPrevVertex, Triedge(lPrevCCWBorder,lFirstCCWBorder) ) ;
lFirstCCWBorder->opposite()->HBase_base::set_vertex(lPrevVertex);
lFirstCCWBorder->HBase_base::set_prev(lPrevCCWBorder);
lPrevCCWBorder ->HBase_base::set_next(lFirstCCWBorder);
lPrevCCWBorder ->opposite()->HBase_base::set_prev(lFirstCCWBorder->opposite());
lFirstCCWBorder->opposite()->HBase_base::set_next(lPrevCCWBorder ->opposite());
2020-10-13 12:44:25 +00:00
CGAL_precondition_msg(c >=3, "The contour must have at least 3 _distinct_ vertices" ) ;
2020-10-13 12:44:25 +00:00
CGAL_STSKEL_BUILDER_TRACE(1
, "CCW Border: E" << lFirstCCWBorder->id()
<< ' ' << lPrevVertex ->point() << " -> " << lFirstVertex->point() << '\n'
<< "CW Border: E" << lFirstCCWBorder->opposite()->id()
<< ' ' << lFirstVertex->point() << " -> " << lPrevVertex ->point()
);
2020-10-13 12:44:25 +00:00
mVisitor.on_contour_edge_entered(lFirstCCWBorder);
}
2020-10-13 12:44:25 +00:00
public:
2020-10-13 12:44:25 +00:00
// This compares INPUT vertices so there is no need to filter it.
struct AreVerticesEqual
{
template<class P>
bool operator() ( P const&x, P const& y ) const
{
return CGAL::compare_xy(x,y) == EQUAL ;
}
2020-10-13 12:44:25 +00:00
} ;
template<class InputPointIterator, class Converter>
Straight_skeleton_builder_2& enter_contour ( InputPointIterator aBegin
, InputPointIterator aEnd
2020-10-13 12:44:25 +00:00
, Converter const& cvt
, bool aCheckValidity = true
)
{
if ( aCheckValidity )
{
typedef typename std::iterator_traits<InputPointIterator>::value_type Input_point;
2020-10-13 12:44:25 +00:00
typedef std::vector<Input_point> Input_point_vector ;
2020-10-13 12:44:25 +00:00
// Remove coincident consecutive vertices
Input_point_vector lList;
std::unique_copy(aBegin,aEnd,std::back_inserter(lList),AreVerticesEqual());
2020-10-13 12:44:25 +00:00
while ( lList.size() > 0 && CGAL::compare_xy(lList.front(),lList.back()) == EQUAL )
lList.pop_back();
2020-10-13 12:44:25 +00:00
if ( lList.size() >= 3 )
{
enter_valid_contour(lList.begin(),lList.end(),cvt);
}
else
{
CGAL_STSKEL_BUILDER_TRACE(0,"Degenerate contour (less than 3 non-degenerate vertices).");
}
}
else
{
enter_valid_contour(aBegin,aEnd,cvt);
2020-10-13 12:44:25 +00:00
}
return *this ;
}
2020-10-13 12:44:25 +00:00
template<class InputPointIterator>
Straight_skeleton_builder_2& enter_contour ( InputPointIterator aBegin
, InputPointIterator aEnd
2020-10-13 12:44:25 +00:00
, bool aCheckValidity = true
)
{
return enter_contour(aBegin, aEnd, Cartesian_converter<K,K>(), aCheckValidity);
2020-10-13 12:44:25 +00:00
}
} ;
} // end namespace CGAL
#include <CGAL/Straight_skeleton_2/Straight_skeleton_builder_2_impl.h>
#include <CGAL/enable_warnings.h>
#endif // CGAL_STRAIGHT_SKELETON_BUILDER_2_H //
// EOF //