From 1a3d89344e58f911b50041cfa80d4555ea59c8bb Mon Sep 17 00:00:00 2001 From: Efi Fogel Date: Mon, 25 Jun 2012 20:45:11 +0000 Subject: [PATCH] 1st revision --- .gitattributes | 2 + .../Arrangement_on_surface_2/IO_base_test.h | 1313 +++++++++++++++++ .../Point_location_test.h | 742 ++++++++++ 3 files changed, 2057 insertions(+) create mode 100644 Arrangement_on_surface_2/test/Arrangement_on_surface_2/IO_base_test.h create mode 100644 Arrangement_on_surface_2/test/Arrangement_on_surface_2/Point_location_test.h diff --git a/.gitattributes b/.gitattributes index 6f5cda99095..c0ba6bb6601 100644 --- a/.gitattributes +++ b/.gitattributes @@ -512,7 +512,9 @@ Arrangement_on_surface_2/include/CGAL/Curved_kernel_via_analysis_2/gfx/Curve_ren Arrangement_on_surface_2/include/CGAL/Curved_kernel_via_analysis_2/gfx/Subdivision_1.h -text Arrangement_on_surface_2/include/CGAL/Curved_kernel_via_analysis_2/gfx/Subdivision_2.h -text Arrangement_on_surface_2/include/CGAL/Curved_kernel_via_analysis_2/test/simple_models.h -text +Arrangement_on_surface_2/test/Arrangement_on_surface_2/IO_base_test.h -text Arrangement_on_surface_2/test/Arrangement_on_surface_2/IO_test.h -text +Arrangement_on_surface_2/test/Arrangement_on_surface_2/Point_location_test.h -text Arrangement_on_surface_2/test/Arrangement_on_surface_2/Traits_adaptor_test.h -text Arrangement_on_surface_2/test/Arrangement_on_surface_2/cgal_test_base -text Arrangement_on_surface_2/test/Arrangement_on_surface_2/cgal_test_with_cmake eol=lf diff --git a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/IO_base_test.h b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/IO_base_test.h new file mode 100644 index 00000000000..f4f131d8c16 --- /dev/null +++ b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/IO_base_test.h @@ -0,0 +1,1313 @@ +#ifndef CGAL_IO_BASE_TEST_H +#define CGAL_IO_BASE_TEST_H + +template +class IO_base_test { +public: + typedef T_Traits Traits; + typedef typename Traits::Point_2 Point_2; + typedef typename Traits::X_monotone_curve_2 X_monotone_curve_2; + typedef typename Traits::Curve_2 Curve_2; + + template + bool read_point(stream& is, Point_2&); + + template + bool read_xcurve(stream& is, X_monotone_curve_2&); + + template + bool read_curve(stream& is, Curve_2&); + +protected: + /*! An instance of the traits */ + Traits m_traits; +}; + +// Generic implementation +template +template +bool IO_base_test:: +read_point(stream& is, typename T_Traits::Point_2& p) +{ + Basic_number_type x, y; + is >> x >> y; + p = typename T_Traits::Point_2(x, y); + return true; +} + +template +template +bool IO_base_test:: +read_xcurve(stream& is, typename T_Traits::X_monotone_curve_2& xcv) +{ + Basic_number_type x1, y1, x2, y2; + is >> x1 >> y1 >> x2 >> y2; + Point_2 p1(x1, y1); + Point_2 p2(x2, y2); + CGAL_assertion(p1 != p2); + xcv = typename T_Traits::X_monotone_curve_2(p1, p2); + return true; +} + +template +template +bool +IO_base_test::read_curve(stream& is, typename T_Traits::Curve_2& cv) +{ + Basic_number_type x1, y1, x2, y2; + is >> x1 >> y1 >> x2 >> y2; + Point_2 p1(x1, y1); + Point_2 p2(x2, y2); + CGAL_assertion(p1 != p2); + cv = typename T_Traits::Curve_2(p1, p2); + return true; +} + +// Specialized implementations + +// Linear +#if TEST_TRAITS == LINEAR_TRAITS + +template <> +template +bool IO_base_test::read_xcurve(stream& is, X_monotone_curve_2& xcv) +{ + is >> xcv; + return true; +} + +template <> +template +bool IO_base_test::read_curve(stream& is, Curve_2& cv) +{ + is >> cv; + return true; +} + +// Polyline +#elif TEST_TRAITS == POLYLINE_TRAITS || \ + TEST_TRAITS == NON_CACHING_POLYLINE_TRAITS + +template <> +template +bool +IO_base_test:: +read_xcurve(stream& is, Traits::X_monotone_curve_2& xcv) +{ + unsigned int num_points; + is >> num_points; + std::vector points; + points.clear(); + for (unsigned int j = 0; j < num_points; j++) { + Basic_number_type x, y; + is >> x >> y; + Point_2 p(x, y); + points.push_back(p); + } + xcv = + CGAL:: + Arr_polyline_traits_2::X_monotone_curve_2(points.begin(), + points.end()); + return true; +} + +template <> +template +bool IO_base_test::read_curve(stream& is, Traits::Curve_2& cv) +{ + unsigned int num_points; + is >> num_points; + std::vector points; + points.clear(); + for (unsigned int j = 0; j < num_points; j++) { + Basic_number_type x, y; + is >> x >> y; + Point_2 p(x, y); + points.push_back(p); + } + cv = CGAL::Arr_polyline_traits_2::Curve_2(points.begin(), + points.end()); + return true; +} + +// Circle segment +#elif TEST_TRAITS == CIRCLE_SEGMENT_TRAITS + +template +bool read_ort_point(stream& is, Point_2& p) +{ + bool is_rat; + typename Point_2::CoordNT ort_x, ort_y; + Number_type alpha,beta,gamma; + is >> is_rat; + if (is_rat) { + is >> alpha; + ort_x=Point_2::CoordNT(alpha); + } + else { + is >> alpha >> beta >> gamma; + ort_x=Point_2::CoordNT(alpha,beta,gamma); + } + is >> is_rat; + if (is_rat) { + is >> alpha; + ort_y=Point_2::CoordNT(alpha); + } + else { + is >> alpha >> beta >> gamma; + ort_y=Point_2::CoordNT(alpha,beta,gamma); + } + p = Point_2(ort_x, ort_y); + return true; +} + +/*! Read an x-monotone circle segment curve */ +template <> +template +bool IO_base_test::read_xcurve(stream& is,X_monotone_curve_2& xcv) +{ + bool ans = true; + char type; + is >> type; + if (type == 'z' || type == 'Z') { + Line_2 l; + Point_2 ps,pt; + is >> l; + ans &= read_ort_point(is, ps); + ans &= read_ort_point(is, pt); + xcv=X_monotone_curve_2(l, ps, pt); + return ans; + } + else if (type == 'y' || type == 'Y') { + Rat_point_2 ps,pt; + is >> ps >> pt; + xcv=X_monotone_curve_2(ps,pt); + return true; + } + else if (type == 'x' || type == 'X') { + Circle_2 c; + Point_2 ps,pt; + is >> c; + ans &= read_ort_point(is, ps); + ans &= read_ort_point(is, pt); + xcv=X_monotone_curve_2(c, ps, pt, c.orientation()); + return ans; + } + // If we reached here, we have an unknown conic type: + std::cerr << "Illegal circle segment type specification: " << type + << std::endl; + return false; +} + +/*! Read a general circle segment curve */ +template <> +template +bool IO_base_test::read_curve(stream& is, Curve_2& cv) +{ + std::cout << "Y1" << std::endl; + bool ans = true; + char type; + is >> type; + if (type == 'a' || type == 'A') { + Rat_point_2 ps,pt; + is >> ps >> pt; + Segment_2 s(ps,pt); + cv = Curve_2(s); + return true; + } + else if (type == 'b' || type == 'B') { + Rat_point_2 ps,pt; + is >> ps >> pt; + cv = Curve_2(ps,pt); + return true; + } + else if (type == 'c' || type == 'C') { + Line_2 l; + Point_2 ps, pt; + is >> l; + ans &= read_ort_point(is, ps); + ans &= read_ort_point(is, pt); + cv = Curve_2(l, ps, pt); + return ans; + } + else if (type == 'd' || type == 'D') { + std::cout << "X1" << std::endl; + Circle_2 c; + is >> c; + std::cout << "X2" << std::endl; + cv = Curve_2(c); + std::cout << "X3" << std::endl; + return true; + } + else if (type == 'e' || type == 'E') { + Rat_point_2 p; + Rat_nt r; + int orient; + is >> p >> r >> orient; + cv = Curve_2(p,r,static_cast(orient)); + return true; + } + else if (type == 'f' || type == 'F') { + Circle_2 c; + Point_2 ps,pt; + is >> c; + ans &= read_ort_point(is, ps); + ans &= read_ort_point(is, pt); + cv = Curve_2(c,ps,pt); + return ans; + } + else if (type == 'g' || type == 'G') { + Rat_point_2 p; + Rat_nt r; + int orient; + Point_2 ps,pt; + is >> p >> r >> orient; + ans &= read_ort_point(is, ps); + ans &= read_ort_point(is, pt); + cv = Curve_2(p,r,static_cast(orient), ps, pt); + return ans; + } + else if (type == 'h' || type == 'H') { + Rat_point_2 ps,pm,pt; + is >> ps >> pm >> pt; + cv = Curve_2(ps, pm, pt); + return true; + } + // If we reached here, we have an unknown conic type: + std::cerr << "Illegal circle segment type specification: " << type + << std::endl; + return false; +} + +// Conic +#elif TEST_TRAITS == CORE_CONIC_TRAITS + +// conic traits and rational traits use same number +// type CORE:Expr so this code can be shared + +/*! Read a point */ + +template <> +template +bool IO_base_test::read_point(stream& is, Point_2& p) +{ + Rational rat_x,rat_y; + is >> rat_x >> rat_y; + Basic_number_type x(rat_x), y(rat_y); + p = Point_2(x, y); + return true; +} + +/*! */ +template +bool read_orientation(stream& is, CGAL::Orientation& orient) +{ + int i_orient; + is >> i_orient; + orient = (i_orient > 0) ? CGAL::COUNTERCLOCKWISE : + (i_orient < 0) ? CGAL::CLOCKWISE : CGAL::COLLINEAR; + return true; +} + +/*! */ +template +bool read_app_point(stream& is, Point_2& p) +{ + double x, y; + is >> x >> y; + p = Point_2(Algebraic(x), Algebraic(y)); + return true; +} + +/*! */ +template +bool read_orientation_and_end_points(stream& is, CGAL::Orientation& orient, + Point_2& source, Point_2& target) +{ + // Read the orientation. + if (!read_orientation(is, orient)) return false; + + // Read the end points of the arc and create it. + if (!read_app_point(is, source)) return false; + if (!read_app_point(is, target)) return false; + return true; +} + +/*! Read a circle or an ellipse */ +template +bool read_ellipse(stream& is, bool& is_circle, Rat_circle& circle, + Rational& r, Rational& s, + Rational& t, Rational& u, Rational& v, Rational& w) +{ + // Read the ellipse (using the format "a b x0 y0"): + // 2 2 + // ( x - x0 ) ( y - y0 ) + // -------- + -------- = 1 + // a b + // + Rational a, b, x0, y0; + is >> a >> b >> x0 >> y0; + + if (a == b) { + is_circle = true; + circle = Rat_circle(Rat_point(x0, y0), a); + } + else { + r = 1/a; + s = 1/b; + t = 0; + u = -2*x0*b; + v = -2*y0*a; + w = x0*x0*b + y0*y0*a - a*b; + } + return true; +} + +/*! */ +template +bool read_partial_ellipse(stream& is, Curve& cv) +{ + bool is_circle; // Is this a circle. + Rat_circle circle; + Rational r, s, t, u, v, w; + if (!read_ellipse(is, is_circle, circle, r, s, t, u, v, w)) return false; + CGAL::Orientation orient; + Point_2 source, target; + if (!read_orientation_and_end_points(is, orient, source, target)) //!!! + return false; + + // Create the conic (or circular) arc. + cv = (is_circle) ? Curve(circle, orient, source, target) : + Curve(r, s, t, u, v, w, orient, source, target); + return true; +} + +/*! */ +template +bool read_full_ellipse(stream& is, Curve& cv) +{ + bool is_circle; // Is this a circle. + Rat_circle circle; + Rational r, s, t, u, v, w; + if (!read_ellipse(is, is_circle, circle, r, s, t, u, v, w)) + return false; + + // Create a full ellipse (or circle). + cv = (is_circle) ? Curve(circle) : Curve(r, s, t, u, v, w); + return true; +} + +/*! Read a hyperbola */ +template +bool read_hyperbola(stream& is, Curve& cv) +{ + // Read the hyperbola (using the format "a b x0 y0"): + // 2 2 + // ( x - x0 ) ( y - y0 ) + // -------- - -------- = 1 + // a b + // + Rational a, b, x0, y0; + is >> a >> b >> x0 >> y0; + + Rational r = b; + Rational s= -a; + Rational t = 0; + Rational u = -2*x0*b; + Rational v = 2*y0*a; + Rational w = x0*x0*b - y0*y0*a - a*b; + + CGAL::Orientation orient; + Point_2 source, target; + if (!read_orientation_and_end_points(is, orient, source, target)) //!!! + return false; + + // Create the conic (or circular) arc. + cv = Curve(r, s, t, u, v, w, orient, source, target); + return true; +} + +/*! Read a hyperbola */ +template +bool read_parabola(stream& is, Curve& cv) +{ + // Read the parabola (using the format "c x0 y0"): + // + // 2 + // (x - x0) = 4c*(y - y0) + // + Rational c, x0, y0; + is >> c >> x0 >> y0; + + Rational r = 1; + Rational s = 0; + Rational t = 0; + Rational u = -2*x0; + Rational v = -4*c; + Rational w = x0*x0 + 4*c*y0; + + CGAL::Orientation orient; + Point_2 source, target; + if (!read_orientation_and_end_points(is, orient, source, target)) + return false; + + // Create the conic (or circular) arc. + cv = Curve(r, s, t, u, v, w, orient, source, target); + return true; +} + +/*! */ +template +bool read_segment(stream& is, Curve& cv) +{ + + // Read a segment, given by its endpoints (x1,y1) and (x2,y2); + Rational x1, y1, x2, y2; + is >> x1 >> y1 >> x2 >> y2; + + Rat_point source(x1, y1); + Rat_point target(x2, y2); + Rat_segment segment(source, target); + + // Create the segment. + cv = Curve(segment); + return true; +} + +/*! */ +template +bool read_general_arc(stream& is, Curve& cv) +{ + // Read a general conic, given by its coefficients . + Rational r, s, t, u, v, w; // The conic coefficients. + is >> r >> s >> t >> u >> v >> w; + // Read the orientation. + int i_orient = 0; + is >> i_orient; + CGAL::Orientation orient = (i_orient > 0) ? CGAL::COUNTERCLOCKWISE : + (i_orient < 0) ? CGAL::CLOCKWISE : CGAL::COLLINEAR; + + // Read the approximated source, along with a general conic + // whose intersection with + // defines the source. + Point_2 app_source; + if (!read_app_point(is, app_source)) return false; + Rational r1, s1, t1, u1, v1, w1; + is >> r1 >> s1 >> t1 >> u1 >> v1 >> w1; + + // Read the approximated target, along with a general conic + // whose intersection with + // defines the target. + Point_2 app_target; + if (!read_app_point(is, app_target)) return false; + + Rational r2, s2, t2, u2, v2, w2; + is >> r2 >> s2 >> t2 >> u2 >> v2 >> w2; + + // Create the conic arc. + cv = Curve(r, s, t, u, v, w, orient, + app_source, r1, s1, t1, u1, v1, w1, + app_target, r2, s2, t2, u2, v2, w2); + return true; +} + +/*! */ +template +bool read_general_curve(stream& is, Curve& cv) +{ + Rational r, s, t, u, v, w; // The conic coefficients. + // Read a general conic, given by its coefficients . + is >> r >> s >> t >> u >> v >> w; + CGAL::Orientation orient; + Point_2 source, target; + if (!read_orientation_and_end_points(is, orient, source, target)) + return false; + + // Create the conic (or circular) arc. + cv = Curve(r, s, t, u, v, w, orient, source, target); + return true; +} + +/*! Read an x-monotone conic curve */ +template <> +template +bool IO_base_test::read_xcurve(stream& is, X_monotone_curve_2& xcv) +{ + Curve_2 tmp_cv; + if (!read_curve(is,tmp_cv)) + return false; + xcv = X_monotone_curve_2(tmp_cv); + return true; +} + +/*! Read a general conic curve */ +template <> +template +bool IO_base_test::read_curve(stream& is, Curve_2& cv) +{ + // Get the arc type: + char type; + is >> type; + if (type == 'f' || type == 'F') + return read_full_ellipse(is, cv); + else if (type == 's' || type == 'S') + return read_segment(is, cv); + else if (type == 'i' || type == 'I') + return read_general_arc(is, cv); + else if (type == 'c' || type == 'C') { + // Read a general conic, given by its coefficients . + Rational r, s, t, u, v, w; + is >> r >> s >> t >> u >> v >> w; + // Create a full conic (should work only for ellipses). + cv = Curve_2(r, s, t, u, v, w); + return true; + } + else if (type == 'e' || type == 'E') + return read_partial_ellipse(is, cv); + else if (type == 'h' || type == 'H') + return read_hyperbola(is, cv); + else if (type == 'p' || type == 'P') + return read_parabola(is, cv); + else if (type == 'a' || type == 'A') + return read_general_curve(is, cv); + + // If we reached here, we have an unknown conic type: + std::cerr << "Illegal conic type specification: " << type << "." + << std::endl; + return false; +} + +// Rational arc +#elif TEST_TRAITS == RATIONAL_ARC_TRAITS +/*! Read a point */ + +template <> +template +bool IO_base_test::read_point(stream& is, Point_2& p) +{ + Traits::Construct_point_2 construct_point_2 = + m_traits.construct_point_2_object(); + + Rational x, y; + is >> x >> y ; + p = construct_point_2(x, y); + return true; +} + +template +bool read_rational_to_real(stream& is, Algebraic_real_1& r) +{ + static Traits::Algebraic_kernel_d_1 algebraic_kernel; + Rational rat; + is >> rat; + r = algebraic_kernel.construct_algebraic_real_1_object()(rat); + return true; +} + +template +bool read_coefficients(stream& is, Rat_vector& coeffs) +{ + unsigned int num_coeffs; + Rational rat; + is >> num_coeffs; + coeffs.clear(); + for (unsigned int j = 0; j < num_coeffs; j++) { + is >> rat; + coeffs.push_back(rat); + } + return true; +} + +/*! Read a xcurve */ +template <> +template +bool IO_base_test::read_xcurve(stream& is, X_monotone_curve_2& xcv) +{ + //curve constructor + const Traits::Construct_x_monotone_curve_2 + ctr_x_monotone_curve = + m_traits.construct_x_monotone_curve_2_object(); + + // Get the arc type: + Rat_vector p_coeffs, q_coeffs; + Algebraic_real_1 src, trg; + int dir = 0; + char type; + is >> type; + if (type == 'a' || type == 'A') { + //Default constructor + xcv = X_monotone_curve_2(); + return true; + } + else if (type == 'b' || type == 'B') { + //Constructor of a whole polynomial curve + if (read_coefficients(is,p_coeffs)) + xcv = ctr_x_monotone_curve(p_coeffs.begin(),p_coeffs.end()); + else + return false; + return true; + } + else if (type == 'c' || type == 'C') { + //Constructor of a polynomial ray + if (!read_coefficients(is,p_coeffs)) + return false; + if (!read_rational_to_real(is,src)) + return false; + is >> dir; + xcv = ctr_x_monotone_curve(p_coeffs.begin(), p_coeffs.end(), + src, (dir == 0 ? false : true)); + return true; + } + else if (type == 'd' || type == 'D') { + //Constructor of a polynomial arc + if (!read_coefficients(is,p_coeffs)) + return false; + if (!read_rational_to_real(is,src)) + return false; + if (!read_rational_to_real(is,trg)) + return false; + xcv = ctr_x_monotone_curve(p_coeffs.begin(),p_coeffs.end(), src, trg); + return true; + } + else if (type == 'e' || type == 'E') { + //Constructor of a whole rational function + if (!read_coefficients(is,p_coeffs)) + return false; + if (!read_coefficients(is,q_coeffs)) + return false; + xcv = ctr_x_monotone_curve(p_coeffs.begin(), p_coeffs.end(), + q_coeffs.begin(),q_coeffs.end()); + return true; + } + else if (type == 'f' || type == 'F') { + //Constructor of a ray of a rational function + if (!read_coefficients(is,p_coeffs)) + return false; + if (!read_coefficients(is,q_coeffs)) + return false; + if (!read_rational_to_real(is,src)) + return false; + is >> dir; + xcv =ctr_x_monotone_curve(p_coeffs.begin(),p_coeffs.end(), + q_coeffs.begin(),q_coeffs.end(), + src, (dir == 0 ? false : true)); + return true; + } + else if (type == 'g' || type == 'G') { + //Constructor of a bounded rational arc + if (!read_coefficients(is, p_coeffs)) + return false; + if (!read_coefficients(is, q_coeffs)) + return false; + if (!read_rational_to_real(is,src)) + return false; + if (!read_rational_to_real(is,trg)) + return false; + + xcv = ctr_x_monotone_curve( p_coeffs.begin(),p_coeffs.end(), + q_coeffs.begin(),q_coeffs.end(), + src, trg); + return true; + } + // If we reached here, we have an unknown rational arc type: + std::cerr << "Illegal rational arc type specification: " << type << "." + << std::endl; + return (false); +} + +/*! Read a curve */ +template <> +template +bool IO_base_test::read_curve(stream& is, Curve_2& cv) +{ + //curve constructor + const Traits::Construct_curve_2 construct_curve_2 = + m_traits.construct_curve_2_object(); + + // Get the arc type: + Rat_vector p_coeffs, q_coeffs; + Algebraic_real_1 src, trg; + int dir = 0; + char type; + is >> type; + if (type == 'a' || type == 'A') { + //Default constructor + cv = Curve_2(); + return true; + } + else if (type == 'b' || type == 'B') { + //Constructor of a whole polynomial curve + if (read_coefficients(is,p_coeffs)) + cv = construct_curve_2(p_coeffs.begin(),p_coeffs.end()); + else + return false; + return true; + } + else if (type == 'c' || type == 'C') { + //Constructor of a polynomial ray + if (!read_coefficients(is,p_coeffs)) + return false; + if (!read_rational_to_real(is,src)) + return false; + is >> dir; + cv = construct_curve_2(p_coeffs.begin(), p_coeffs.end(), src, + (dir == 0 ? false : true)); + return true; + } + else if (type == 'd' || type == 'D') { + //Constructor of a polynomial arc + if (!read_coefficients(is,p_coeffs)) + return false; + if (!read_rational_to_real(is,src)) + return false; + if (!read_rational_to_real(is,trg)) + return false; + cv = construct_curve_2(p_coeffs.begin(),p_coeffs.end(), src, trg); + return true; + } + else if (type == 'e' || type == 'E') { + //Constructor of a whole rational function + if (!read_coefficients(is,p_coeffs)) + return false; + if (!read_coefficients(is,q_coeffs)) + return false; + cv = construct_curve_2(p_coeffs.begin(), p_coeffs.end(), + q_coeffs.begin(), q_coeffs.end()); + return true; + } + else if (type == 'f' || type == 'F') { + //Constructor of a ray of a rational function + if (!read_coefficients(is,p_coeffs)) + return false; + if (!read_coefficients(is,q_coeffs)) + return false; + if (!read_rational_to_real(is,src)) + return false; + is >> dir; + cv =construct_curve_2(p_coeffs.begin(),p_coeffs.end(), + q_coeffs.begin(),q_coeffs.end(), + src, (dir == 0 ? false : true)); + return true; + } + else if (type == 'g' || type == 'G') { + //Constructor of a bounded rational arc + if (!read_coefficients(is, p_coeffs)) + return false; + if (!read_coefficients(is, q_coeffs)) + return false; + if (!read_rational_to_real(is,src)) + return false; + if (!read_rational_to_real(is,trg)) + return false; + cv = construct_curve_2(p_coeffs.begin(),p_coeffs.end(), + q_coeffs.begin(),q_coeffs.end(), + src, trg); + return true; + } + // If we reached here, we have an unknown rational arc type: + std::cerr << "Illegal rational arc type specification: " << type << "." + << std::endl; + return (false); +} + +// Bezier +#elif TEST_TRAITS == BEZIER_TRAITS + +template <> +template +bool IO_base_test::read_point(stream& is, Point_2& p) +{ + Rational rat_x,rat_y; + is >> rat_x >> rat_y; + p = Point_2(rat_x, rat_y); + return true; +} + +/*! Read an x-monotone bezier curve */ + +template <> +template +bool IO_base_test::read_xcurve(stream& is, X_monotone_curve_2& xcv) +{ + std::list x_objs; + std::list::const_iterator xoit; + Curve_2 tmp_cv; + is >> tmp_cv; + Rational B_psx = Rational(tmp_cv.control_point(0).x()); + Rational B_psy = Rational(tmp_cv.control_point(0).y()); + Rational B_ptx = + Rational(tmp_cv.control_point(tmp_cv.number_of_control_points()-1).x()); + Rational B_pty = + Rational(tmp_cv.control_point(tmp_cv.number_of_control_points()-1).y()); + Point_2 B_ps(B_psx, B_psy); + Point_2 B_pt(B_ptx, B_pty); + Traits::Make_x_monotone_2 make_x_monotone = + this->m_traits.make_x_monotone_2_object(); + make_x_monotone (tmp_cv, std::front_inserter (x_objs)); + xoit = x_objs.begin(); + if (CGAL::assign(xcv, *xoit)) + return true; + return false; +} + +/*! Read a general bezier curve */ +template <> +template +bool IO_base_test::read_curve(stream& is, Curve_2& cv) +{ + is >> cv; + return true; +} + +// Algebraic +#elif TEST_TRAITS == ALGEBRAIC_TRAITS + +#include + +template <> +template +bool IO_base_test::read_point(stream& is, Point_2& p) { + Traits traits; + Traits::Construct_point_2 construct_point_2 = + traits.construct_point_2_object(); + char type; + is >> type; + switch(type) { + case 'i': { + int x=0,y=0; + is >> x >> y; + p = construct_point_2(x, y); + break; + } + case 'b': { + Traits::Bound x,y; + is >> x >> y; + p=construct_point_2(x, y); + break; + } + case 'c': { + Traits::Coefficient x, y; + is >> x >> y; + p = construct_point_2(x, y); + break; + } + case 'a': { + Traits::Algebraic_real_1 x, y; + is >> x >> y; + p = construct_point_2(x, y); + break; + } + case 's': { + Traits::Algebraic_real_1 x; + is >> x; + Traits::X_monotone_curve_2 xcv; + CGAL::swallow(is,'('); + CGAL_assertion_code(bool check=) + read_xcurve(is, xcv); + CGAL_assertion(check); + + CGAL::swallow(is,')'); + p = construct_point_2(x, xcv); + break; + } + case 'g': { + Traits::Algebraic_real_1 x; + is >> x; + Traits::Curve_2 c; + CGAL_assertion_code(bool check = ) + read_curve(is,c); + CGAL_assertion(check); + int arcno=0; + is >> arcno; + p = construct_point_2(x, c, arcno); + break; + } + default: { + std::cout << "Expected i, b, c, a, s, or g, but got \"" << type << "\"" + << std::endl; + return false; + } + } + return true; +} + +template <> +template +bool IO_base_test::read_xcurve(stream& is, + Traits::X_monotone_curve_2& xcv) +{ + Traits traits; + Traits::Construct_x_monotone_segment_2 construct_segment_2 = + traits.construct_x_monotone_segment_2_object(); + char type; + is >> type; + switch(type) { + case '1': { + Curve_2 cv; + Point_2 end_left,end_right; + CGAL_assertion_code(bool check=) + read_curve(is,cv); + CGAL_assertion(check); + CGAL::swallow(is,'('); + CGAL_assertion_code(check=) + read_point(is,end_left); + CGAL_assertion(check); + CGAL::swallow(is,')'); + CGAL::swallow(is,'('); + CGAL_assertion_code(check=) + read_point(is,end_right); + CGAL_assertion(check); + CGAL::swallow(is,')'); + std::vector xcvs; + construct_segment_2(cv, end_left, end_right, std::back_inserter(xcvs)); + CGAL_assertion(xcvs.size() == 1); + xcv = xcvs[0]; + break; + } + case '2': { + Curve_2 cv; + Point_2 p; + CGAL_assertion_code(bool check=) + read_curve(is,cv); + CGAL_assertion(check); + CGAL::swallow(is,'('); + CGAL_assertion_code(check=) + read_point(is,p); + CGAL_assertion(check); + CGAL::swallow(is,')'); + std::string site_of_p_string; + Traits::Site_of_point site_of_p; + is >> site_of_p_string; + if (site_of_p_string=="MIN_ENDPOINT") { + site_of_p=Traits::MIN_ENDPOINT; + } else if (site_of_p_string=="MAX_ENDPOINT") { + site_of_p=Traits::MAX_ENDPOINT; + } else { + CGAL_assertion(site_of_p_string=="POINT_IN_INTERIOR"); + site_of_p=Traits::POINT_IN_INTERIOR; + } + std::vector xcvs; + construct_segment_2(cv, p, site_of_p, std::back_inserter(xcvs)); + CGAL_assertion(xcvs.size() == 1); + xcv = xcvs[0]; + break; + } + default: { + std::cout << "Expected 1 or 2, but got \"" << type << "\"" << std::endl; + return false; + } + } + return true; +} + +template <> +template +bool IO_base_test::read_curve(stream& is, Curve_2& cv) { + Traits traits; + Traits::Polynomial_2 p; + Traits::Construct_curve_2 construct_curve_2 = + traits.construct_curve_2_object(); + is >> p; + cv = construct_curve_2(p); + return true; +} + +// Spherical arc +#elif TEST_TRAITS == SPHERICAL_ARC_TRAITS + +/*! Read a point */ + +template <> +template +bool IO_base_test::read_point(stream& is, Point_2& p) +{ + Basic_number_type x, y, z; + is >> x >> y >> z; + p = Point_2(x, y, z); + return true; +} + +/*! Read a xcurve */ +template <> +template +bool IO_base_test::read_xcurve(stream& is, X_monotone_curve_2& xcv) +{ + Point_2 p1,p2; + read_point(is, p1); + read_point(is, p2); + CGAL_assertion(p1 != p2); + xcv = X_monotone_curve_2(p1, p2); + return true; +} + +/*! Read a curve */ +template <> +template +bool IO_base_test::read_curve(stream& is, Curve_2& cv) +{ + Point_2 p1, p2; + read_point(is, p1); + read_point(is, p2); + CGAL_assertion(p1 != p2); + cv = Curve_2(p1, p2); + return true; +} + +// circular line arc +#elif TEST_TRAITS == LINE_ARC_TRAITS || \ + TEST_TRAITS == CIRCULAR_ARC_TRAITS || \ + TEST_TRAITS == CIRCULAR_LINE_ARC_TRAITS + +/*! Read an arc point */ +template +bool read_arc_point(stream& is, typename T_Traits::Point_2& p) +{ + Basic_number_type x, y; + is >> x >> y; + Circular_kernel::Point_2 lp(x, y); + p = typename T_Traits::Point_2(lp); + return true; +} + +bool is_deg_1(char c) +{ + return (c=='z' || c=='Z') || (c=='y' || c=='Y') || (c=='x' || c=='X') || + (c=='w' || c=='W') || (c=='v' || c=='V') || (c=='l' || c=='L'); +} + +bool is_deg_2(char c) +{ + return (c=='b' || c=='B') || (c=='c' || c=='C') || + (c=='d' || c=='D') || (c=='e' || c=='E'); +} + +#if TEST_TRAITS == LINE_ARC_TRAITS || \ + TEST_TRAITS == CIRCULAR_LINE_ARC_TRAITS + +template +Circular_kernel::Line_arc_2 read_line(char type, stream& is) +{ + if (type == 'z' || type == 'Z') { + Circular_kernel::Line_2 l_temp; + Circular_kernel::Circle_2 c_temp1,c_temp2; + bool b1,b2; + is >> l_temp >> c_temp1 >> b1 >> c_temp2 >> b2; + return Circular_kernel::Line_arc_2(l_temp,c_temp1,b1,c_temp2,b2); + } + else if (type == 'y' || type == 'Y') { + Circular_kernel::Line_2 l_temp,l_temp1,l_temp2; + is >> l_temp >> l_temp1 >> l_temp2; + return Circular_kernel::Line_arc_2(l_temp,l_temp1,l_temp2); + } + else if (type == 'x' || type == 'X') { + Circular_kernel::Line_2 l_temp; + Circular_kernel::Circular_arc_point_2 p0,p1; + is >> l_temp >> p0 >> p1; + //std::cout << "got here l_temp p0 p1 " << l_temp << " " << p0 << " " << p1 << std::endl; + return Circular_kernel::Line_arc_2(l_temp, p0, p1); + } + else if (type == 'w' || type == 'W' || type == 'l' || type == 'L') { + Circular_kernel::Point_2 p0,p1; + is >> p0 >> p1; + return Circular_kernel::Line_arc_2(p0,p1); + } + else if (type == 'v' || type == 'V') { + Circular_kernel::Segment_2 seg; + is >> seg; + return Circular_kernel::Line_arc_2(seg); + } + std::cout << "should never happen Line_arc_2 " << type < +Circular_kernel::Circular_arc_2 read_arc(char type,stream& is) +{ + if (type == 'b' || type == 'B') { + Circular_kernel::Circle_2 circle, circle1, circle2; + bool b1, b2; + is >> circle >> circle1 >> b1 >> circle2 >> b2; + + return Circular_kernel::Circular_arc_2(circle, circle1, b1, circle2, b2); + } + else if (type == 'c' || type == 'C') { + Circular_kernel::Circle_2 circle; + Circular_kernel::Circular_arc_point_2 p0, p1; + is >> circle >> p0 >> p1; + return Circular_kernel::Circular_arc_2(circle, p0, p1); + } + else if (type == 'd' || type == 'D') { + Circular_kernel::Circle_2 circle; + Circular_kernel::Line_2 line1, line2; + bool b1,b2; + is >> circle >> line1 >> b1 >> line2 >> b2; + return Circular_kernel::Circular_arc_2(circle, line1, b1, line2, b2); + } + else + CGAL_error_msg("Unrecognized constructor. Should never happen" \ + "Circular_arc_2"); + // else if (type == 'e' || type == 'E') + // { + // Circular_kernel::Circular_arc_2 arc; + // Circular_kernel::Circle_2 circle; + // bool b1, b2; + // is >> arc >> b1 >> circle >> b2; + // return Circular_kernel::Circular_arc_2(arc, b1, circle, b2); + // } + return Circular_kernel::Circular_arc_2(); //should never happen +} +#endif + +#if TEST_TRAITS == LINE_ARC_TRAITS + +/*! Read a line arc point */ +template <> +template +bool IO_base_test::read_point(stream& is, Point_2& p) +{ + return read_arc_point(is, p); +} + +/*! Read an x-monotone line arc curve */ +template <> +template +bool IO_base_test::read_xcurve(stream& is, X_monotone_curve_2& xcv) +{ + // Get the arc type: + char type; + is >> type; + if (is_deg_1(type)) { + xcv = read_line(type,is); + return true; + } + return false; +} + +/*! Read a general line arc curve */ +template <> +template +bool IO_base_test::read_curve(stream& is, Curve_2& cv) +{ + // Get the arc type: + char type; + is >> type; + if (is_deg_1(type)) { + cv = read_line(type,is); + return true; + } + return false; +} + +#endif + +#if TEST_TRAITS == CIRCULAR_ARC_TRAITS + +/*! Read a circular arc point */ +template <> +template +bool IO_base_test::read_point(stream& is, Point_2& p) +{ + return read_arc_point(is, p); +} + +/*! Read an x-monotone circular arc curve */ +template <> +template +bool IO_base_test::read_xcurve(stream& is,X_monotone_curve_2& xcv) +{ + // Get the arc type: + char type; + is >> type; + if (is_deg_2(type)) { + xcv = read_arc(type, is); + return true; + } + return false; +} + +/*! Read a general circular curve */ +template <> +template +bool IO_base_test::read_curve(stream& is, Curve_2& cv) +{ + // Get the arc type: + char type; + is >> type; + if (type == 'a' || type == 'A') { + Circular_kernel::Circle_2 circle; + is >> circle; + cv = Circular_kernel::Circular_arc_2(circle); + return true; + } + else if (is_deg_2(type)) { + cv = read_arc(type, is); + return true; + } + return false; +} + +#endif + +#if TEST_TRAITS == CIRCULAR_LINE_ARC_TRAITS + +/*! Read a circular-line arc point */ +template <> +template +bool IO_base_test::read_point(stream& is, Point_2& p) +{ + return read_arc_point(is, p); +} + +/*! Read an x-monotone circular-line arc curve */ +template <> +template +bool IO_base_test::read_xcurve(stream& is, X_monotone_curve_2& xcv) +{ + // Get the arc type: + char type; + is >> type; + if (is_deg_1(type)) { + xcv = read_line(type,is); + return true; + } + else if (is_deg_2(type)) { + xcv = X_monotone_curve_2(read_arc(type, is)); + return true; + } + return false; +} + +/*! Read a general circular-line curve */ +template <> +template +bool IO_base_test::read_curve(stream& is, Curve_2& cv) +{ + // Get the arc type: + char type; + is >> type; + if (type == 'a' || type == 'A') { + Circular_kernel::Circle_2 circle; + is >> circle; + cv=Curve_2(circle); + return true; + } + else if (is_deg_1(type)) { + cv = Curve_2(read_line(type, is)); + return true; + } + else if (is_deg_2(type)) { + cv = read_arc(type, is); + return true; + } + return false; + +} + +#endif + +#endif + +#endif diff --git a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/Point_location_test.h b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/Point_location_test.h new file mode 100644 index 00000000000..ed143863ab7 --- /dev/null +++ b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/Point_location_test.h @@ -0,0 +1,742 @@ +#ifndef CGAL_POINT_LOCATION_TEST_H +#define CGAL_POINT_LOCATION_TEST_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +//#include + +#include "IO_test.h" + +/*! Point location test */ +template +class Point_location_test : public IO_test { +private: + typedef T_Traits Traits; + typedef IO_test Base; + +public: + typedef typename Base::Point_2 Point_2; + typedef typename Base::X_monotone_curve_2 X_monotone_curve_2; + typedef typename Base::Curve_2 Curve_2; + + typedef typename Base::Points_vector Points_vector; + typedef typename Base::Xcurves_vector Xcurves_vector; + typedef typename Base::Curves_vector Curves_vector; + + typedef CGAL::Arrangement_2 Arrangement_2; + + typedef typename Arrangement_2::Halfedge_handle Halfedge_handle; + typedef typename Arrangement_2::Edge_const_iterator Edge_const_iterator; + typedef typename Arrangement_2::Vertex_const_iterator Vertex_const_iterator; + + typedef typename Points_vector::iterator Point_iterator; + typedef std::vector Objects_vector; + typedef Objects_vector::iterator Object_iterator; + +protected: + typedef typename CGAL::Arr_naive_point_location + Naive_point_location; + typedef typename CGAL::Arr_simple_point_location + Simple_point_location; + typedef typename CGAL::Arr_walk_along_line_point_location + Walk_point_location; + typedef typename CGAL::Arr_landmarks_point_location + Lm_point_location; + typedef typename CGAL::Arr_random_landmarks_generator + Random_lm_generator; + typedef typename CGAL::Arr_landmarks_point_location + Lm_random_point_location; + typedef typename CGAL::Arr_grid_landmarks_generator + Grid_lm_generator; + typedef typename CGAL::Arr_landmarks_point_location + Lm_grid_point_location; + typedef typename CGAL::Arr_halton_landmarks_generator + Halton_lm_generator; + typedef typename CGAL::Arr_landmarks_point_location + Lm_halton_point_location; + typedef typename CGAL::Arr_middle_edges_landmarks_generator + Middle_edges_generator; + typedef typename CGAL::Arr_landmarks_point_location + Lm_middle_edges_point_location; + typedef typename CGAL::Arr_landmarks_specified_points_generator + Specified_points_generator; + typedef typename CGAL::Arr_landmarks_point_location + Lm_specified_points_point_location; + typedef typename CGAL::Arr_trapezoid_ric_point_location + Trapezoid_ric_point_location; + + // typedef CGAL::Arr_triangulation_point_location + // Triangulation_point_location; + + // ===> Add new point location type here <=== + + Naive_point_location* m_naive_pl; // 0 + Simple_point_location* m_simple_pl; // 1 + Walk_point_location* m_walk_pl; // 2 + Lm_point_location* m_lm_pl; // 3 + Lm_random_point_location* m_random_lm_pl; // 4 + Lm_grid_point_location* m_grid_lm_pl; // 5 + Lm_halton_point_location* m_halton_lm_pl; // 6 + Lm_middle_edges_point_location* m_middle_edges_lm_pl; // 7 + Lm_specified_points_point_location* m_specified_points_lm_pl; // 8 + // Triangulation_point_location m_triangulation_pl; // 9 + Trapezoid_ric_point_location* m_trapezoid_ric_pl; // 10 + Trapezoid_ric_point_location* m_trapezoid_ric_no_grnt_pl; // 11 + + Random_lm_generator* m_random_g; + Grid_lm_generator* m_grid_g; + Halton_lm_generator* m_halton_g; + Middle_edges_generator* m_middle_edges_g; + Specified_points_generator* m_specified_points_g; + + // // ===> Change the number of point-location startegies + // // when a new point location is added. <=== + #define MAX_NUM_POINT_LOCATION_STRATEGIES 11 + +public: + /*! Constructor */ + Point_location_test(); + + /*! Destructor */ + virtual ~Point_location_test() + { + clear_arrangement(); + clear(); + deallocate_pl_strategies(); + } + + void set_filenames(const char* points_filename, const char* xcurves_filename, + const char* curves_filename, const char* queries_filename); + + /*! Initialize the data structures */ + virtual bool init(); + + /*! Perform the test */ + virtual bool perform(); + + /*! Clear the data structures */ + virtual void clear(); + + bool allocate_arrangement(); + + bool deallocate_arrangement(); + + bool construct_arrangement(); + + void clear_arrangement(); + + bool allocate_pl_strategies(); + + bool construct_pl_strategies(); + + bool attach_pl_strategies(); + + void deallocate_pl_strategies(); + + template + void query(Point_location& pl, const char* type, + InputIterator begin, InputIterator end, OutputIterator oi) + { + typedef InputIterator Input_iterator; + + CGAL::Timer timer; + timer.reset(); timer.start(); + Input_iterator piter; + for (piter = begin; piter != end; ++piter) { + Point_2 q = (*piter); + CGAL::Object obj = pl.locate(q); + *oi++ = obj; + } + timer.stop(); + std::cout << type << " location took " << timer.time() << std::endl; + } + +private: + /*! The input data file of the query points*/ + std::string m_filename_queries; + + /*! The query points */ + Points_vector m_query_points; + + /*! The arrangement */ + Arrangement_2* m_arr; +}; + +/*! + * Constructor. + * Accepts test data file name. + */ +template +Point_location_test::Point_location_test() : + m_naive_pl(NULL), + m_simple_pl(NULL), + m_walk_pl(NULL), + m_lm_pl(NULL), + m_random_lm_pl(NULL), + m_grid_lm_pl(NULL), + m_halton_lm_pl(NULL), + m_middle_edges_lm_pl(NULL), + m_specified_points_lm_pl(NULL), + // m_triangulation_pl(NULL), + m_trapezoid_ric_pl(NULL), + m_trapezoid_ric_no_grnt_pl(NULL), + m_random_g(NULL), + m_grid_g(NULL), + m_halton_g(NULL), + m_middle_edges_g(NULL), + m_specified_points_g(NULL), + m_arr(NULL) +{} + +/*! Set the file names */ +template +void Point_location_test::set_filenames(const char* points_filename, + const char* xcurves_filename, + const char* curves_filename, + const char* queries_filename) +{ + Base::set_filenames(points_filename, xcurves_filename, curves_filename); + m_filename_queries.assign(queries_filename); +} + +/*! Initialize the data structures */ +template +bool Point_location_test::init() +{ + if (!Base::init()) return false; + + // Read the query points + if (!this->read_points(m_filename_queries.c_str(), m_query_points)) + return false; + + return true; +} + +/*! Clear the data structures */ +template +void Point_location_test::clear() +{ + Base::clear(); + m_query_points.clear(); + m_filename_queries.clear(); +} + +/*! Clear the data structures */ +template +void Point_location_test::deallocate_pl_strategies() +{ + if (m_naive_pl) { + delete m_naive_pl; + m_naive_pl = NULL; + } + if (m_simple_pl) { + delete m_simple_pl; + m_simple_pl = NULL; + } + if (m_walk_pl) { + delete m_walk_pl; + m_walk_pl = NULL; + } + +#if (TEST_TRAITS == SEGMENT_TRAITS) || (TEST_TRAITS == LINEAR_TRAITS) + if (m_lm_pl) { + delete m_lm_pl; + m_lm_pl = NULL; + } + if (m_random_lm_pl) { + delete m_random_lm_pl; + m_random_lm_pl = NULL; + } + if (m_grid_lm_pl) { + delete m_grid_lm_pl; + m_grid_lm_pl = NULL; + } + if (m_halton_lm_pl) { + delete m_halton_lm_pl; + m_halton_lm_pl = NULL; + } + if (m_middle_edges_lm_pl) { + delete m_middle_edges_lm_pl; + m_middle_edges_lm_pl = NULL; + } + if (m_specified_points_lm_pl) { + delete m_specified_points_lm_pl; + m_specified_points_lm_pl = NULL; + } + + // Free Generators + if (m_random_g) { + delete m_random_g; + m_random_g = NULL; + } + if (m_grid_g) { + delete m_grid_g; + m_grid_g = NULL; + } + if (m_halton_g) { + delete m_halton_g; + m_halton_g = NULL; + } + if (m_middle_edges_g) { + delete m_middle_edges_g; + m_middle_edges_g = NULL; + } + if (m_specified_points_g) { + delete m_specified_points_g; + m_specified_points_g = NULL; + } +#endif + + // if (m_triangulation_pl) { + // delete m_triangulation_pl; + // m_triangulation_pl = NULL; + // } + if (m_trapezoid_ric_pl) { + delete m_trapezoid_ric_pl; + m_trapezoid_ric_pl = NULL; + } + if (m_trapezoid_ric_no_grnt_pl) { + delete m_trapezoid_ric_no_grnt_pl; + m_trapezoid_ric_no_grnt_pl = NULL; + } +} + +template +bool Point_location_test::allocate_arrangement() +{ + if (!(m_arr = new Arrangement_2())) return false; + return true; +} + +template +bool Point_location_test::deallocate_arrangement() +{ + if (m_arr) { + delete m_arr; + m_arr = NULL; + } +} + +template +bool Point_location_test::construct_arrangement() +{ + // Insert all into the arrangement + CGAL::insert(*m_arr, this->m_xcurves.begin(), this->m_xcurves.end()); + // insert(*m_arr, m_points.begin(), m_points.end()); + CGAL::insert(*m_arr, this->m_curves.begin(), this->m_curves.end()); + + // Print the size of the arrangement. + std::cout << "V = " << m_arr->number_of_vertices() + << ", E = " << m_arr->number_of_edges() + << ", F = " << m_arr->number_of_faces() << std::endl; + + return true; +} + +template +void Point_location_test::clear_arrangement() +{ + if (m_arr) m_arr->clear(); +} + +template +bool Point_location_test::allocate_pl_strategies() +{ + // Allocate all point location strategies. + if (!(m_naive_pl = new Naive_point_location())) return false; + if (!(m_simple_pl = new Simple_point_location())) return false; + if (!(m_walk_pl = new Walk_point_location())) return false; + +#if (TEST_TRAITS == SEGMENT_TRAITS) || (TEST_TRAITS == LINEAR_TRAITS) + + if (!(m_lm_pl = new Lm_point_location())) return false; + if (!(m_random_lm_pl = new Lm_random_point_location())) return false; + if (!(m_grid_lm_pl = new Lm_grid_point_location())) return false; + if (!(m_halton_lm_pl = new Lm_halton_point_location())) return false; + if (!(m_middle_edges_lm_pl = new Lm_middle_edges_point_location())) + return false; + if (!(m_specified_points_lm_pl = new Lm_specified_points_point_location())) + return false; + + // if (!(m_triangulation_pl = new Triangulation_point_location())) + // return false; + +#endif + + if (!(m_trapezoid_ric_pl = new Trapezoid_ric_point_location())) return false; + if (!(m_trapezoid_ric_no_grnt_pl = new Trapezoid_ric_point_location())) + return false; + + // ===> Add new point location instance here. <=== + return true; +} + +template +bool Point_location_test::construct_pl_strategies() +{ + typedef T_Traits Traits; + + // Initialize all point location strategies. + CGAL::Timer timer; + + m_naive_pl = new Naive_point_location(*m_arr); // 0 + m_simple_pl = new Simple_point_location(*m_arr); // 1 + m_walk_pl = new Walk_point_location(*m_arr); // 2 + +#if (TEST_TRAITS == SEGMENT_TRAITS) || (TEST_TRAITS == LINEAR_TRAITS) + + timer.reset(); timer.start(); + m_lm_pl = new Lm_point_location(*m_arr); // 3 + timer.stop(); + std::cout << "Lm (vert) construction took " << timer.time() << std::endl; + + timer.reset(); timer.start(); + m_random_g = new Random_lm_generator(*m_arr); + m_random_lm_pl = new Lm_random_point_location(*m_arr, m_random_g); // 4 + timer.stop(); + std::cout << "Random lm construction took " << timer.time() << std::endl; + + timer.reset(); timer.start(); + m_grid_g = new Grid_lm_generator(*m_arr); + m_grid_lm_pl = new Lm_grid_point_location(*m_arr, m_grid_g); // 5 + timer.stop(); + std::cout << "Grid lm construction took " << timer.time() << std::endl; + + timer.reset(); timer.start(); + m_halton_g = new Halton_lm_generator(*m_arr); + m_halton_lm_pl = new Lm_halton_point_location(*m_arr, m_halton_g); // 6 + timer.stop(); + std::cout << "Halton lm construction took " << timer.time() << std::endl; + + timer.reset(); timer.start(); + m_middle_edges_g = new Middle_edges_generator(*m_arr); + m_middle_edges_lm_pl = + new Lm_middle_edges_point_location(*m_arr, m_middle_edges_g); // 7 + timer.stop(); + std::cout << "Middle edges lm construction took " << timer.time() + << std::endl; + + timer.reset(); timer.start(); + m_specified_points_g = new Specified_points_generator(*m_arr); + m_specified_points_lm_pl = + new Lm_specified_points_point_location(*m_arr, m_specified_points_g); // 8 + timer.stop(); + std::cout << "Specified_points lm construction took " + << timer.time() << std::endl; + + // timer.reset(); timer.start(); + // m_triangulation_pl = new Triangulation_point_location(*m_arr); // 9 + // timer.stop(); + // std::cout << "Triangulation lm construction took " + // << timer.time() << std::endl; + +#endif + + timer.reset(); timer.start(); + m_trapezoid_ric_pl = new Trapezoid_ric_point_location(*m_arr); // 10 + timer.stop(); + std::cout << "Trapezoid RIC construction took " << timer.time() << std::endl; + + timer.reset(); timer.start(); + m_trapezoid_ric_no_grnt_pl = + new Trapezoid_ric_point_location(*m_arr, false); // 11 + timer.stop(); + std::cout << "Trapezoid RIC without-guarantees construction took " + << timer.time() << std::endl; + + std::cout << std::endl; + + // ===> Add new point location instance here. <=== + return true; +} + +template +bool Point_location_test::attach_pl_strategies() +{ + typedef T_Traits Traits; + + // Initialize all point location strategies. + CGAL::Timer timer; + + m_naive_pl.attach(*m_arr); // 0 + m_simple_pl.attach(*m_arr); // 1 + m_walk_pl.attach(*m_arr); // 2 + +#if (TEST_TRAITS == SEGMENT_TRAITS) || (TEST_TRAITS == LINEAR_TRAITS) + + timer.reset(); timer.start(); + m_lm_pl.attach(*m_arr); // 3 + timer.stop(); + std::cout << "Lm (vert) construction took " << timer.time() << std::endl; + + timer.reset(); timer.start(); + m_random_g = new Random_lm_generator(*m_arr); + m_random_lm_pl.attach(*m_arr, m_random_g); // 4 + timer.stop(); + std::cout << "Random lm construction took " << timer.time() << std::endl; + + timer.reset(); timer.start(); + m_grid_g = new Grid_lm_generator(*m_arr); + m_grid_lm_pl.attach(*m_arr, m_grid_g); // 5 + timer.stop(); + std::cout << "Grid lm construction took " << timer.time() << std::endl; + + timer.reset(); timer.start(); + m_halton_g = new Halton_lm_generator(*m_arr); + m_halton_lm_pl.attach(*m_arr, m_halton_g); // 6 + timer.stop(); + std::cout << "Halton lm construction took " << timer.time() << std::endl; + + timer.reset(); timer.start(); + m_middle_edges_g = new Middle_edges_generator(*m_arr); + m_middle_edges_lm_pl.attach(*m_arr, m_middle_edges_g); // 7 + timer.stop(); + std::cout << "Middle edges lm construction took " << timer.time() + << std::endl; + + timer.reset(); timer.start(); + Specified_points_generator specified_points_g(*m_arr); + m_specified_points_lm_pl.attach(*m_arr, specified_points_g); // 8 + timer.stop(); + std::cout << "Specified_points lm construction took " + << timer.time() << std::endl; + + // timer.reset(); timer.start(); + // m_location triangulation_lm_pl.attach(*m_arr); // 9 + // timer.stop(); + // std::cout << "Triangulation lm construction took " + // << timer.time() << std::endl; + +#endif + + timer.reset(); timer.start(); + m_trapezoid_ric_pl.attach(*m_arr); // 10 + timer.stop(); + std::cout << "Trapezoid RIC construction took " << timer.time() << std::endl; + + timer.reset(); timer.start(); + m_trapezoid_ric_no_grnt_pl.with_guarantees(false); + m_trapezoid_ric_no_grnt_pl.attach(*m_arr); // 11 + + timer.stop(); + std::cout << "Trapezoid RIC without-guarantees construction took " + << timer.time() << std::endl; + + std::cout << std::endl; + + // ===> Add new point location instance here. <=== + return true; +} + +// Perform the test +template +bool Point_location_test::perform() +{ + Objects_vector objs[MAX_NUM_POINT_LOCATION_STRATEGIES]; + typename Arrangement_2::Vertex_const_handle vh_ref, vh_curr; + typename Arrangement_2::Halfedge_const_handle hh_ref, hh_curr; + typename Arrangement_2::Face_const_handle fh_ref, fh_curr; + + // Locate the points in the list using all point location strategies. + + // std::cout << "Time in seconds" << std::endl; + std::cout << std::endl; + + unsigned int pl_index = 0; + + query(*m_naive_pl, "Naive", m_query_points.begin(), m_query_points.end(), + std::back_inserter(objs[pl_index++])); // Naive + + query(*m_simple_pl, "Simple", m_query_points.begin(), m_query_points.end(), + std::back_inserter(objs[pl_index++])); // Simple + + query(*m_walk_pl, "Walk", m_query_points.begin(), m_query_points.end(), + std::back_inserter(objs[pl_index++])); // Walk + +#if (TEST_TRAITS == SEGMENT_TRAITS) || (TEST_TRAITS == LINEAR_TRAITS) + + query(*m_lm_pl, "Landmarks (vertices)", + m_query_points.begin(), m_query_points.end(), + std::back_inserter(objs[pl_index++])); // Landmarks (vertices) + + query(*m_random_lm_pl, "Landmarks random", + m_query_points.begin(), m_query_points.end(), + std::back_inserter(objs[pl_index++])); // Landmarks random + + query(*m_grid_lm_pl, "Landmarks grid", + m_query_points.begin(), m_query_points.end(), + std::back_inserter(objs[pl_index++])); // Landmarks grid + + query(*m_halton_lm_pl, "Landmarks Halton", + m_query_points.begin(), m_query_points.end(), + std::back_inserter(objs[pl_index++])); // Landmarks Halton + + query(*m_middle_edges_lm_pl, "Landmarks middle edges", + m_query_points.begin(), m_query_points.end(), + std::back_inserter(objs[pl_index++])); // Landmarks middle edges + + query(*m_specified_points_lm_pl, "Landmarks specified points", + m_query_points.begin(), m_query_points.end(), + std::back_inserter(objs[pl_index++])); // Landmarks specified points + + // Triangulation + // query(*m_triangulation_pl, "Triangulation", + // m_query_points.begin(), m_query_points.end(), + // std::back_inserter(objs[pl_index++])); // Triangulation + +#endif + + query(*m_trapezoid_ric_pl, "Trapezoidal RIC", + m_query_points.begin(), m_query_points.end(), + std::back_inserter(objs[pl_index++])); // Trapezoidal RIC + + // Trapezoidal RIC without guarantees + query(*m_trapezoid_ric_no_grnt_pl, "Trapezoidal RIC without guarantees", + m_query_points.begin(), m_query_points.end(), + std::back_inserter(objs[pl_index++])); + + std::cout << std::endl; + + // ===> Add a call to operate the new point location. <=== + + // Number of point location strategies used. + unsigned int pls_num = pl_index; + std::cout << "Number of strategies is " << pls_num << std::endl; + + // End Location + + int result = 0; + + //init all obejct iterators + Object_iterator ob_iter[MAX_NUM_POINT_LOCATION_STRATEGIES]; + for (pl_index = 0; pl_index < pls_num; ++pl_index) + ob_iter[pl_index] = objs[pl_index].begin(); + + // get size of objects + unsigned int size = objs[0].size(); + std::cout << "size is " << size << std::endl; + + for (pl_index = 0; pl_index < pls_num; ++pl_index) { + if (size != objs[pl_index].size()) { + std::cout << "Error: size of pl number " << pl_index << " is " + << objs[pl_index].size() << std::endl; + result = -1; + } + } + + // Assign and check results + unsigned int qi; //qi is the query point index + for (qi = 0; qi < size; ++qi) { + // Assign object to a face + if (CGAL::assign(fh_ref, ob_iter[0][qi])) { + for (int pl_index = 1; pl_index < pls_num; ++pl_index) { + if (! CGAL::assign(fh_curr, ob_iter[pl_index][qi])) { + std::cout << "Error in point location number " << pl_index; + if (CGAL::assign(fh_curr, ob_iter[pl_index][qi])) { + std::cout << ", an halfedge returned instead of a face" + << std::endl; + } + else if (CGAL::assign(hh_curr, ob_iter[pl_index][qi])) { + std::cout << ", a vertex returned instead of a face" + << std::endl; + } + else { + std::cout << ", an unknowen object returned instead of a face" + << std::endl; + } + result = -1; + } + else if (fh_curr != fh_ref) { + std::cout << "Error: point location number " + << pl_index << " return a different face" << std::endl; + result = -1; + } + } + //if (fh_ref->is_unbounded()) + // std::cout << "Unbounded face." << std::endl; + //else + // std::cout << "Face." << std::endl; + } + + // Assign object to a halfedge + else if (CGAL::assign (hh_ref, ob_iter[0][qi])) { + std::cout << "Halfedge: " << hh_ref->curve() << std::endl; + for (int pl_index = 1; pl_index < pls_num; ++pl_index) { + if (! CGAL::assign(hh_curr, ob_iter[pl_index][qi])) { + std::cout << "Error in point location number " << pl_index; + if (CGAL::assign(fh_curr, ob_iter[pl_index][qi])) { + std::cout << ", a face returned instead of an halfedge" + << std::endl; + } + else if (CGAL::assign(hh_curr, ob_iter[pl_index][qi])) { + std::cout << ", a vertex returned instead of an halfedge" + << std::endl; + } + else { + std::cout << ", an unknowen object returned instead of an halfedge" + << std::endl; + } + result = -1; + } + else if ((hh_curr != hh_ref) && (hh_curr->twin() != hh_ref)) { + std::cout << "Error: point location number " + << pl_index << " return a different halfedge" << std::endl; + std::cout << "Halfedge (curr): " << hh_curr->curve() << std::endl; + result = -1; + } + } + } + + // Assign object to a vertex + else if (CGAL::assign(vh_ref, ob_iter[0][qi])) { + for (int pl_index = 1; pl_index < pls_num; ++pl_index) { + if (! CGAL::assign(vh_curr, ob_iter[pl_index][qi])) { + std::cout << "Error in point location number " << pl_index; + if (CGAL::assign(fh_curr, ob_iter[pl_index][qi])) { + std::cout << ", a face returned instead of a vertex"<< std::endl; + } + else if (CGAL::assign(hh_curr, ob_iter[pl_index][qi])) { + std::cout << ", an halfedge returned instead of a vertex" + << std::endl; + } + else { + std::cout << ", an unknown object returned instead of a vertex" + << std::endl; + } + result = -1; + } + else if (vh_curr != vh_ref) { + std::cout << "Error: point location number " + << pl_index << " return a different vertex"<< std::endl; + result = -1; + } + } + std::cout << "Vertex: "<< vh_ref->point() << std::endl; + } + + else { + std::cout << "Illegal point-location result." << std::endl; + result = -1; + } + } + return (result); +} + +#endif