From cc2c3e69d06e8cf2bb3f45246a003e783a63e4aa Mon Sep 17 00:00:00 2001 From: Panagiotis Cheilaris Date: Tue, 18 Mar 2014 11:59:20 +0100 Subject: [PATCH] support line optimization in first intersection Addition of is_line_optimization boolean member variable in object of class Polychainline_2. Suppose this variable of an obect is set to true. If this object is tried for an intersection with another Polychainline object pcl, using the function first_intersection_point_with, then instead the function line_first_intersection_point_with is used. Signed-off-by: Panagiotis Cheilaris --- .../include/CGAL/Polychain_2.h | 87 +++++++++++++++++-- 1 file changed, 80 insertions(+), 7 deletions(-) diff --git a/Segment_Delaunay_graph_Linf_2/include/CGAL/Polychain_2.h b/Segment_Delaunay_graph_Linf_2/include/CGAL/Polychain_2.h index 45616f59842..5a5d68e347a 100644 --- a/Segment_Delaunay_graph_Linf_2/include/CGAL/Polychain_2.h +++ b/Segment_Delaunay_graph_Linf_2/include/CGAL/Polychain_2.h @@ -329,29 +329,44 @@ private: typedef Traits_P Traits; typedef typename Traits_P::Direction_2 IncomingDirection; typedef typename Traits_P::Direction_2 OutgoingDirection; + typedef typename Traits_P::Line_2 Line_2; + typedef typename Traits_P::Ray_2 Ray_2; + typedef typename Traits_P::Segment_2 Segment_2; + typedef typename Traits_P::Point_2 Point_2; typedef Polychainray_2 Base; typedef Polychainline_2 Self; IncomingDirection incoming; + bool is_line_optimization; public: // constructors - Polychainline_2() : Base(), incoming() {} + Polychainline_2() : Base(), incoming(), + is_line_optimization(false) + {} Polychainline_2(const Self& pcl) - : Base((Base) pcl), incoming(pcl.incoming) {} + : Base((Base) pcl), incoming(pcl.incoming), + is_line_optimization(pcl.is_line_optimization) + {} template Polychainline_2(IncomingDirection dinc, InputIterator first, InputIterator last, OutgoingDirection dout, Traits p_traits = Traits()) - : Base(first, last, dout, p_traits), incoming(dinc) + : Base(first, last, dout, p_traits), incoming(dinc), + is_line_optimization(false) { } + void set_line_optimization() { + CGAL_assertion(this->size() == 1); + CGAL_assertion(this->incoming == - this->outgoing); + is_line_optimization = true; + } // get_incoming @@ -409,9 +424,67 @@ public: reverse.end(), this->get_incoming()); + if (is_line_optimization) { + pclreverse.set_line_optimization(); + } + return pclreverse; } + // line_first_intersection_point_with + typename Traits_P::Point_2 + line_first_intersection_point_with( + const Polychainline_2& pcl) + { + CGAL_assertion(is_line_optimization); + Line_2 line((*this)[0], this->get_outgoing()); + + typedef typename + Polychainline_2:: + Vertex_const_iterator + VI; + + typedef typename std::vector:: + const_iterator SI; + + CGAL::Object result; + + VI sourcepcl = pcl.vertices_begin(); + Ray_2 rayincpcl (*sourcepcl, pcl.get_incoming()); + result = CGAL::intersection(line, rayincpcl); + if (const Point_2 *ipoint = CGAL::object_cast(&result)) { + return *ipoint; + } + + if (pcl.size() > 1) { + VI targetpcl = sourcepcl+1; + for( ; + targetpcl != pcl.vertices_end(); + ++sourcepcl, ++targetpcl) + { + Segment_2 testseg(*sourcepcl, *targetpcl); + result = CGAL::intersection(line, testseg); + if (const Point_2 *ipoint = CGAL::object_cast(&result)) { + return *ipoint; + } + } + } + Ray_2 rayoutpcl(*sourcepcl, pcl.get_outgoing()); + result = CGAL::intersection(line, rayoutpcl); + if (const Point_2 *ipoint = CGAL::object_cast(&result)) { + return *ipoint; + } + + CGAL_SDG_DEBUG(std::cout + << "debug error: no intersection found for " + << "this=" << *this << " pcl=" << pcl << std::endl;); + + CGAL_assertion(false); + + return Point_2(); + + } // end of line_first_intersection_point_with + // first_intersection_point_with typename Traits_P::Point_2 first_intersection_point_with( @@ -420,10 +493,6 @@ public: // for every piece of object, // try intersecting with every piece of pcl - typedef typename Traits_P::Point_2 Point_2; - typedef typename Traits_P::Ray_2 Ray_2; - typedef typename Traits_P::Segment_2 Segment_2; - CGAL_SDG_DEBUG(std::cout << "debug first_intersection entering this=" << *this << " pcl=" << pcl << std::endl;); @@ -439,6 +508,10 @@ public: CGAL_assertion( this->size() > 0 ); CGAL_assertion( pcl.size() > 0 ); + if (this->is_line_optimization) { + return line_first_intersection_point_with(pcl); + } + #if 0 CGAL_SDG_DEBUG(std::cout << "debug first_intersection " << "creating empty vectors" << std::endl;);