From bd4a4cddbf5962af28755ce00d7234c46a6e872d Mon Sep 17 00:00:00 2001 From: Dror Atariah Date: Sun, 10 Nov 2013 11:37:25 +0100 Subject: [PATCH 1/4] Reverted to iterat on seg's in Compute_squared_distance_2 --- .../demo/Arrangement_on_surface_2/Utils.h | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/Utils.h b/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/Utils.h index 0ad567084a0..0c2889ecd74 100644 --- a/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/Utils.h +++ b/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/Utils.h @@ -339,28 +339,27 @@ public: typedef typename Traits::Curve_2 Curve_2; typedef typename Curve_2::const_iterator Curve_const_iterator; typedef typename Traits::X_monotone_curve_2 X_monotone_curve_2; + typedef typename Curve_2::Segment_const_iterator Seg_const_it; double operator() ( const Point_2& p, const X_monotone_curve_2& c ) const { - Curve_const_iterator ps = c.begin(); - Curve_const_iterator pt = ps; pt++; + Seg_const_it seg_it_s = c.begin_segments(); + bool first = true; FT min_dist = 0; - while ( pt != c.end() ) - { - const Point_2& source = *ps; - const Point_2& target = *pt; - Segment_2 seg( source, target ); - FT dist = this->squared_distance( p, seg ); - - if ( first || dist < min_dist ) + while (seg_it_s != c.end_segments()) { - first = false; - min_dist = dist; + Segment_2 seg = *seg_it_s; + FT dist = this->squared_distance( p, seg ); + + if ( first || dist < min_dist ) + { + first = false; + min_dist = dist; + } + seg_it_s++; } - ps++; pt++; - } return CGAL::to_double( min_dist ); } From 219eeb036b2c90dacf3c25b089278fa141df4f83 Mon Sep 17 00:00:00 2001 From: Dror Atariah Date: Sun, 10 Nov 2013 13:10:01 +0100 Subject: [PATCH 2/4] Segments iteration instead of points iterations in paintFace --- .../ArrangementGraphicsItem.h | 73 +++++++++++++++---- 1 file changed, 57 insertions(+), 16 deletions(-) diff --git a/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/ArrangementGraphicsItem.h b/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/ArrangementGraphicsItem.h index 0a94286c40c..ad11ff92ebc 100644 --- a/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/ArrangementGraphicsItem.h +++ b/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/ArrangementGraphicsItem.h @@ -313,9 +313,30 @@ protected: { if (!f->is_unbounded()) // f is not the unbounded face { + typedef typename CGAL::Arr_polyline_traits_2 Arr_poly_traits; + typedef typename Arr_poly_traits::Compare_endpoints_xy_2 Comp_end_pts_2; + typedef typename Arr_poly_traits::Construct_min_vertex_2 Poly_const_min_v; + typedef typename Arr_poly_traits::Construct_max_vertex_2 Poly_const_max_v; + + // Obtain a polyline traits class and construct the needed functors + Arr_poly_traits poly_tr; + Comp_end_pts_2 comp_end_pts = poly_tr.compare_endpoints_xy_2_object(); + Poly_const_min_v poly_const_min_v=poly_tr.construct_min_vertex_2_object(); + Poly_const_max_v poly_const_max_v=poly_tr.construct_max_vertex_2_object(); + + // Construct needed functors from the segment traits + typedef typename Arr_poly_traits::Segment_traits_2 Segment_traits; + typedef typename Segment_traits::Construct_min_vertex_2 Seg_const_min_v; + typedef typename Segment_traits::Construct_max_vertex_2 Seg_const_max_v; + Seg_const_min_v construct_min_v = poly_tr.segment_traits_2()-> + construct_min_vertex_2_object(); + Seg_const_max_v construct_max_v = poly_tr.segment_traits_2()-> + construct_max_vertex_2_object(); + + // Iterator of the segments of an x-monotone polyline + typename X_monotone_curve_2::Segment_const_iterator seg_it; + QVector< QPointF > pts; // holds the points of the polygon - typename X_monotone_curve_2::const_iterator pt_itr; - typename X_monotone_curve_2::const_reverse_iterator pt_rev_itr; X_monotone_curve_2 cv; /* running with around the outer of the face and generate from it @@ -324,29 +345,49 @@ protected: Ccb_halfedge_circulator cc = f->outer_ccb(); do { cv = cc->curve(); - bool curve_has_same_direction = - ( *(cc->curve().begin()) == cc->source()->point() ); - if ( curve_has_same_direction ) - { - for( pt_itr = cv.begin() , ++pt_itr ; pt_itr != cv.end(); ++pt_itr) + + // Determine the direction of cv (left-to-right or right-to-left) + Comparison_result dir = comp_end_pts(cv); + + for (seg_it = cv.begin_segments(); + seg_it != cv.end_segments() ; ++seg_it) { - double x = CGAL::to_double((*pt_itr).x()); - double y = CGAL::to_double((*pt_itr).y()); + if (dir == SMALLER) + { + // cv is directed from left-to-right + // Adding the left-min vertex of the current segment + double x = CGAL::to_double((construct_min_v(*seg_it)).x()); + double y = CGAL::to_double((construct_min_v(*seg_it)).y()); + QPointF coord_source(x , y); + pts.push_back(coord_source ); + } + else + { + // cv is directed from right-to-left + // Adding the right-max vertex of the current segment + double x = CGAL::to_double((construct_max_v(*seg_it)).x()); + double y = CGAL::to_double((construct_max_v(*seg_it)).y()); + QPointF coord_source(x , y); + pts.push_back(coord_source ); + } + } + + if (dir == SMALLER) + { + // Add the right-most point of cv + double x = CGAL::to_double((poly_const_max_v(cv)).x()); + double y = CGAL::to_double((poly_const_max_v(cv)).y()); QPointF coord_source(x , y); pts.push_back(coord_source ); } - } else - { - for (pt_rev_itr = cv.rbegin() , ++pt_rev_itr; pt_rev_itr != cv.rend(); - ++pt_rev_itr) { - double x = CGAL::to_double((*pt_rev_itr).x()); - double y = CGAL::to_double((*pt_rev_itr).y()); + // Add the left-most point of cv + double x = CGAL::to_double((poly_const_min_v(cv)).x()); + double y = CGAL::to_double((poly_const_min_v(cv)).y()); QPointF coord_source(x , y); pts.push_back(coord_source ); } - } //created from the outer boundary of the face } while (++cc != f->outer_ccb()); From b254bdf2f099e2b989cc47035a0bf8e6d7024e2b Mon Sep 17 00:00:00 2001 From: Dror Atariah Date: Sun, 10 Nov 2013 13:28:01 +0100 Subject: [PATCH 3/4] construction functor instead of direct construction in mousePressEvent --- .../Arrangement_on_surface_2/GraphicsViewCurveInput.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/GraphicsViewCurveInput.h b/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/GraphicsViewCurveInput.h index 6fd62258b8a..f023a635f67 100644 --- a/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/GraphicsViewCurveInput.h +++ b/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/GraphicsViewCurveInput.h @@ -175,6 +175,7 @@ class GraphicsViewCurveInput< CGAL::Arr_polyline_traits_2< SegmentTraits > >: { public: typedef CGAL::Arr_polyline_traits_2< SegmentTraits > Traits; + typedef typename Traits::Construct_curve_2 Construct_polyline; typedef typename Traits::Curve_2 Curve_2; typedef typename SegmentTraits::Kernel Kernel; typedef typename Kernel::Point_2 Point_2; @@ -199,6 +200,10 @@ protected: void mousePressEvent( QGraphicsSceneMouseEvent* event ) { + // Obtain a functor for the construction of polylines + Traits poly_tr; + Construct_polyline construct_poly = poly_tr.construct_curve_2_object(); + Point_2 clickedPoint = this->snapPoint( event ); if ( this->points.empty( ) ) { // first @@ -234,7 +239,8 @@ protected: delete this->polylineGuide[ i ]; } this->polylineGuide.clear( ); - Curve_2 res( this->points.begin( ), this->points.end( ) ); + Curve_2 res = + construct_poly( this->points.begin( ), this->points.end( ) ); this->points.clear( ); emit generate( CGAL::make_object( res ) ); From 00def304a2007aedbb62c56ad17d6d973f2a43cb Mon Sep 17 00:00:00 2001 From: Dror Atariah Date: Sun, 10 Nov 2013 13:28:32 +0100 Subject: [PATCH 4/4] Removed white spaces at the end of some lines --- .../GraphicsViewCurveInput.h | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/GraphicsViewCurveInput.h b/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/GraphicsViewCurveInput.h index f023a635f67..915d64d17a9 100644 --- a/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/GraphicsViewCurveInput.h +++ b/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/GraphicsViewCurveInput.h @@ -429,10 +429,10 @@ protected: } this->polylineGuide.clear( ); - double x1 = CGAL::to_double( this->points[ 0 ].x( ) ); - double y1 = CGAL::to_double( this->points[ 0 ].y( ) ); - double x2 = CGAL::to_double( this->points[ 1 ].x( ) ); - double y2 = CGAL::to_double( this->points[ 1 ].y( ) ); + double x1 = CGAL::to_double( this->points[ 0 ].x( ) ); + double y1 = CGAL::to_double( this->points[ 0 ].y( ) ); + double x2 = CGAL::to_double( this->points[ 1 ].x( ) ); + double y2 = CGAL::to_double( this->points[ 1 ].y( ) ); Curve_2 res = Curve_2( Rat_segment_2( Rat_point_2( x1, y1 ), Rat_point_2( x2, y2 ) ) ); // std::cout << "res is " << ( (res.is_valid( ))? "" : "not ") @@ -451,10 +451,10 @@ protected: this->circleItem = NULL; // std::cout << "TODO: Add the circle" << std::endl; - double x1 = CGAL::to_double( this->points[ 0 ].x( ) ); - double y1 = CGAL::to_double( this->points[ 0 ].y( ) ); - double x2 = CGAL::to_double( this->points[ 1 ].x( ) ); - double y2 = CGAL::to_double( this->points[ 1 ].y( ) ); + double x1 = CGAL::to_double( this->points[ 0 ].x( ) ); + double y1 = CGAL::to_double( this->points[ 0 ].y( ) ); + double x2 = CGAL::to_double( this->points[ 1 ].x( ) ); + double y2 = CGAL::to_double( this->points[ 1 ].y( ) ); double sq_rad = CGAL::square(x2 - x1) + CGAL::square(y2 - y1); Curve_2 res = Curve_2( Rat_circle_2( Rat_point_2( x1, y1 ), sq_rad ) ); @@ -553,7 +553,7 @@ protected: this->points.clear( ); this->pointsGraphicsItem.clear( ); - } + } catch (...) { std::cout << "Points don't specify a valid conic. Try again!" @@ -583,7 +583,7 @@ protected: ConicType conicType; }; -// class GraphicsViewCurveInput< CGAL::Arr_conic_traits_2< +// class GraphicsViewCurveInput< CGAL::Arr_conic_traits_2< // RatKernel, AlgKernel, NtTraits > > /** @@ -903,7 +903,7 @@ public: Point_2 res = this->toArrPoint( pt ); return res; } - + protected: Traits traits; Converter< Kernel > convert;