diff --git a/Envelope_3/include/CGAL/Env_sphere_traits_3.h b/Envelope_3/include/CGAL/Env_sphere_traits_3.h index 9bca8a20766..bf6b0a69eb8 100644 --- a/Envelope_3/include/CGAL/Env_sphere_traits_3.h +++ b/Envelope_3/include/CGAL/Env_sphere_traits_3.h @@ -46,7 +46,7 @@ class Env_sphere_traits_3 : public ConicTraits_2 { public: typedef ConicTraits_2 Traits_2; - typedef Env_sphere_traits_3 Self; + typedef Env_sphere_traits_3 Self; typedef typename Traits_2::Point_2 Point_2; typedef typename Traits_2::Curve_2 Curve_2; @@ -73,7 +73,7 @@ public: // here we refer to the lower part of the sphere only typedef Surface_3 Xy_monotone_surface_3; protected: - typedef std::pair Intersection_curve; + typedef std::pair Intersection_curve; #ifdef CGAL_ENV_SPHERES_TRAITS_CACHE_POINT_ON // caching the computation of a surface 3d point from a 2d point @@ -137,7 +137,7 @@ public: // insert into the OutputIterator all the (2d) curves of the boundary of // the vertical projection of the surface on the xy-plane - // the OutputIterator value type is Curve_2 + // the OutputIterator value type is X_monotone_curve_2 template OutputIterator operator()(const Xy_monotone_surface_3& s, OutputIterator o) @@ -187,11 +187,11 @@ public: class Construct_projected_intersections_2 { protected: - const Self& parent; + Self& parent; public: - Construct_projected_intersections_2(const Self* p) + Construct_projected_intersections_2(Self* p) : parent(*p) {} @@ -304,7 +304,9 @@ public: // 2(a1-a2)x - m = 0 Curve_2 res(0,0,0, 2*a_diff, 0, -m, COLLINEAR, end1, end2); - *o++ = make_object(Intersection_curve(res, TRANSVERSAL)); + + parent.add_curve_to_output(res, o); + //*o++ = make_object(Intersection_curve(res, TRANSVERSAL)); } else { @@ -381,7 +383,8 @@ public: // equation (1) is: // 2(a1-a2)x + 2(b1-b2)y - m = 0 Curve_2 res(0,0,0, 2*a_diff, 2*b_diff, -m, COLLINEAR, end1, end2); - *o++ = make_object(Intersection_curve(res, TRANSVERSAL)); + parent.add_curve_to_output(res, o); + //*o++ = make_object(Intersection_curve(res, TRANSVERSAL)); } } @@ -520,7 +523,8 @@ public: if (sign_lc != NEGATIVE) { Curve_2 res(R, S, T, U, V, W); - *o++ = make_object(Intersection_curve(res, TRANSVERSAL)); + parent.add_curve_to_output(res, o); + //*o++ = make_object(Intersection_curve(res, TRANSVERSAL)); } return o; } @@ -674,7 +678,8 @@ public: if (lval_sign == POSITIVE) { // the full ellipse is in the positive side - *o++ = make_object(Intersection_curve(inter_cv, TRANSVERSAL)); + parent.add_curve_to_output(inter_cv, o); + //*o++ = make_object(Intersection_curve(inter_cv, TRANSVERSAL)); return o; } else if (lval_sign == NEGATIVE) @@ -697,7 +702,8 @@ public: CGAL_assertion(lval_sign != ZERO); if (lval_sign == POSITIVE) - *o++ = make_object(Intersection_curve(inter_cv, TRANSVERSAL)); + parent.add_curve_to_output(inter_cv, o); + //*o++ = make_object(Intersection_curve(inter_cv, TRANSVERSAL)); else *o++ = make_object(Point_2(source)); @@ -721,7 +727,8 @@ public: Curve_2 res(R, S, T, U, V, W, orient, source, target); CGAL_assertion(res.is_valid()); - *o++ = make_object(Intersection_curve(res, TRANSVERSAL)); + parent.add_curve_to_output(res, o); + //*o++ = make_object(Intersection_curve(res, TRANSVERSAL)); } return o; @@ -730,7 +737,7 @@ public: /*! Get a Construct_projected_intersections_2 functor object. */ Construct_projected_intersections_2 - construct_projected_intersections_2_object() const + construct_projected_intersections_2_object() { return Construct_projected_intersections_2(this); } @@ -1277,6 +1284,30 @@ public: return cv.get_point_at_x(pt); } + template + OutputIterator add_curve_to_output(const Curve_2& c, OutputIterator oi) + { + Object objs[2]; + Object* p_obj = this->make_x_monotone_2_object()(c, objs); + CGAL_assertion((p_obj - objs) <= 2); + for(Object* o = objs; o != p_obj; ++o) + { + X_monotone_curve_2 cv; + if(assign(cv, *o)) + { + *oi++ = make_object(Intersection_curve(cv, TRANSVERSAL)); + } + else + { + Point_2 pt; + CGAL_assertion(assign(pt, *o)); + assign(pt, *o); + *oi++ = make_object(pt); + } + } + return oi; + } + /*! Default constructor. */ Env_sphere_traits_3() : m_is_lower(true) {} diff --git a/Envelope_3/include/CGAL/Env_triangle_traits_3.h b/Envelope_3/include/CGAL/Env_triangle_traits_3.h index 34a76243581..adcd4f9dd34 100644 --- a/Envelope_3/include/CGAL/Env_triangle_traits_3.h +++ b/Envelope_3/include/CGAL/Env_triangle_traits_3.h @@ -52,7 +52,6 @@ class Env_triangle_traits_3 : public Arr_segment_traits_2 public: typedef Arr_segment_traits_2 Traits_2; typedef typename Traits_2::Point_2 Point_2; - typedef typename Traits_2::Curve_2 Curve_2; typedef typename Traits_2::X_monotone_curve_2 X_monotone_curve_2; typedef Kernel_ Kernel; @@ -353,7 +352,7 @@ protected: Less_surface_point_pair> Surface_point_cache; #endif - typedef std::pair Intersection_curve; + typedef std::pair Intersection_curve; public: /***************************************************************************/ @@ -525,7 +524,7 @@ public: /*!\brief * Insert all 2D curves, which form the boundary of the vertical * projection of the surface onto the xy-plane, into the output iterator. - * The iterator value-type is Curve_2. + * The iterator value-type is X_monotone_curve_2. */ class Construct_projected_boundary_2 { @@ -539,7 +538,7 @@ public: // insert into the OutputIterator all the (2d) curves of the boundary of // the vertical projection of the surface on the xy-plane - // the OutputIterator value type is Curve_2 + // the OutputIterator value type is X_monotone_curve_2 template OutputIterator operator()(const Xy_monotone_surface_3& s, OutputIterator o) const @@ -613,7 +612,7 @@ public: * intersection objects between s1 and s2 into the output iterator. * * The iterator value-type is Object. An Object may be: - * 1. A pair, where the intersection + * 1. A pair, where the intersection * type is an enumeration that can take the values * {Transversal, Tangency, Unknown}. * 2. A Point_2 instance (in degenerate cases). @@ -660,7 +659,7 @@ public: k.assign_3_object()(curve, inter_obj); CGAL_assertion(b); - Curve_2 projected_cv = parent->project(curve); + const X_monotone_curve_2& projected_cv = parent->project(curve); if (projected_cv.is_degenerate()) *o++ = make_object(projected_cv.left()); else @@ -1044,7 +1043,7 @@ public: return Is_defined_over(); } - Curve_2 project(const Segment_3& segment_3) const + X_monotone_curve_2 project(const Segment_3& segment_3) const { Kernel k; Construct_vertex_3 vertex_on = k.construct_vertex_3_object(); @@ -1053,7 +1052,7 @@ public: end2 = vertex_on(segment_3, 1); Point_2 projected_end1(end1.x(), end1.y()), projected_end2(end2.x(), end2.y()); - return Curve_2(projected_end1, projected_end2); + return X_monotone_curve_2(projected_end1, projected_end2); } Point_2 project(const Point_3& obj) const diff --git a/Envelope_3/include/CGAL/Envelope_3/Arrangement_2_incremental_insert.h b/Envelope_3/include/CGAL/Envelope_3/Arrangement_2_incremental_insert.h index e887f0ff039..d18c5bbda49 100644 --- a/Envelope_3/include/CGAL/Envelope_3/Arrangement_2_incremental_insert.h +++ b/Envelope_3/include/CGAL/Envelope_3/Arrangement_2_incremental_insert.h @@ -28,14 +28,9 @@ #include #include #include - -#ifdef CGAL_ENVELOPE_USE_IMPROVED_ZONE -#include -#else #include -#endif - #include + #include #include @@ -48,8 +43,8 @@ CGAL_BEGIN_NAMESPACE // Use the given zone visitor. // template -void insert_curve (Arrangement_2& arr, - const typename Traits::Curve_2& c, +void insert_x_monotone_curve (Arrangement_2& arr, + const typename Traits::X_monotone_curve_2& c, const PointLocation& pl, ZoneVisitor& visitor) { @@ -59,66 +54,73 @@ void insert_curve (Arrangement_2& arr, typedef Arrangement_2 Arrangement_2; Arr_accessor arr_access (arr); - -#ifdef CGAL_ENVELOPE_USE_IMPROVED_ZONE - Envelope_arrangement_zone_2 - arr_zone (arr, &visitor); -#else Arrangement_zone_2 arr_zone (arr, &visitor); -#endif + + arr_zone.init (c, pl); + + // Notify the arrangement observers that a global operation is about to + // take place. + arr_access.notify_before_global_change(); + + // Insert the current x-monotone curve into the arrangement. + arr_zone.compute_zone(); + + // Notify the arrangement observers that the global operation has been + // completed. + arr_access.notify_after_global_change(); - // Break the input curve into x-monotone subcurves and isolated points. - typedef Arr_traits_adaptor_2 Traits_wrapper_2; + //// Break the input curve into x-monotone subcurves and isolated points. + //typedef Arr_traits_adaptor_2 Traits_wrapper_2; - Traits_wrapper_2 *traits = - static_cast(arr.get_traits()); + //Traits_wrapper_2 *traits = + // static_cast(arr.get_traits()); - std::list x_objects; - std::list::const_iterator obj_iter; - typename Traits::X_monotone_curve_2 x_curve; - typename Traits::Point_2 iso_p; - Object obj; - bool assign_success; + //std::list x_objects; + //std::list::const_iterator obj_iter; + //typename Traits::X_monotone_curve_2 x_curve; + //typename Traits::Point_2 iso_p; + //Object obj; + //bool assign_success; - traits->make_x_monotone_2_object() (c, - std::back_inserter (x_objects)); + /* traits->make_x_monotone_2_object() (c, + std::back_inserter (x_objects));*/ - // Insert each x-monotone curve into the arrangement. - for (obj_iter = x_objects.begin(); obj_iter != x_objects.end(); ++obj_iter) - { - // Act according to the type of the current object. - if (assign (x_curve, *obj_iter)) - { - // Inserting an x-monotone curve: - // Initialize the zone-computation object with the given curve. - arr_zone.init (x_curve, pl); + //// Insert each x-monotone curve into the arrangement. + //for (obj_iter = x_objects.begin(); obj_iter != x_objects.end(); ++obj_iter) + //{ + // // Act according to the type of the current object. + // if (assign (x_curve, *obj_iter)) + // { + // // Inserting an x-monotone curve: + // // Initialize the zone-computation object with the given curve. + // arr_zone.init (x_curve, pl); - // Notify the arrangement observers that a global operation is about to - // take place. - arr_access.notify_before_global_change(); + // // Notify the arrangement observers that a global operation is about to + // // take place. + // arr_access.notify_before_global_change(); - // Insert the current x-monotone curve into the arrangement. - arr_zone.compute_zone(); + // // Insert the current x-monotone curve into the arrangement. + // arr_zone.compute_zone(); - // Notify the arrangement observers that the global operation has been - // completed. - arr_access.notify_after_global_change(); - } - else - { - assign_success = assign (iso_p, *obj_iter); + // // Notify the arrangement observers that the global operation has been + // // completed. + // arr_access.notify_after_global_change(); + // } + // else + // { + // assign_success = assign (iso_p, *obj_iter); - CGAL_assertion (assign_success); - if (! assign_success) - continue; + // CGAL_assertion (assign_success); + // if (! assign_success) + // continue; - // Inserting a point into the arrangement: - //insert_vertex (arr, iso_p, pl); - // we use the version with the visitor - insert_point(arr, iso_p, pl, visitor); - - } - } + // // Inserting a point into the arrangement: + // //insert_vertex (arr, iso_p, pl); + // // we use the version with the visitor + // insert_point(arr, iso_p, pl, visitor); + // + // } + //} return; } diff --git a/Envelope_3/include/CGAL/Envelope_3/Envelope_divide_and_conquer_3.h b/Envelope_3/include/CGAL/Envelope_3/Envelope_divide_and_conquer_3.h index c8f4c2816b2..dde69de5dc7 100644 --- a/Envelope_3/include/CGAL/Envelope_3/Envelope_divide_and_conquer_3.h +++ b/Envelope_3/include/CGAL/Envelope_3/Envelope_divide_and_conquer_3.h @@ -21,7 +21,7 @@ #define CGAL_ENVELOPE_DIVIDE_AND_CONQUER_3_H #define CGAL_ENVELOPE_SAVE_COMPARISONS -//#define CGAL_ENVELOPE_USE_BFS_FACE_ORDER +#define CGAL_ENVELOPE_USE_BFS_FACE_ORDER #include #include diff --git a/Envelope_3/include/CGAL/Envelope_3/Envelope_element_visitor_3.h b/Envelope_3/include/CGAL/Envelope_3/Envelope_element_visitor_3.h index c382ee00191..7fb227d9e48 100644 --- a/Envelope_3/include/CGAL/Envelope_3/Envelope_element_visitor_3.h +++ b/Envelope_3/include/CGAL/Envelope_3/Envelope_element_visitor_3.h @@ -54,7 +54,7 @@ public: typedef MinimizationDiagram_2 Minimization_diagram_2; 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; + //typedef typename Traits::Curve_2 Curve_2; typedef typename Traits::Has_infinite_category Has_infinite_category; protected: @@ -104,7 +104,7 @@ protected: typedef Unique_hash_map Vertices_to_edges_map; - typedef std::pair Intersection_curve; + typedef std::pair Intersection_curve; typedef std::list Intersections_list; // this is used in the resolve edge process @@ -277,7 +277,7 @@ public: else if (assign(curve, cur_obj)) { zone_visitor.set_current_intersection_type(curve.second); - insert_curve(copied_face_arr, curve.first, pl, zone_visitor); + insert_x_monotone_curve(copied_face_arr, curve.first, pl, zone_visitor); } else CGAL_assertion_msg(false, "wrong projected intersection type"); @@ -286,36 +286,6 @@ public: zone_visitor.finish(); // now determine the envelope data in result over the new faces - - //// first, we try to copy information from incident faces, thru fake edges - //if (fakes_exist) - //{ - // typename std::list::iterator fit; - // for(fit = result_face_parts.begin(); - // fit != result_face_parts.end(); ++fit) - // { - // Face_handle new_f = *fit; - // // we didn't set envelope data yet - // CGAL_assertion(!new_f->is_decision_set()); - // // try to find a fake edge on the outer boundary - // // (if we have fake edges, we don't have holes) - // Ccb_halfedge_circulator hec = new_f->outer_ccb(); - // Ccb_halfedge_circulator hec_begin = hec; - // do { - // Halfedge_handle hh = hec; - // if (hh->get_is_fake() && - // hh->twin()->face()->is_decision_set()) - // { - // Face_handle twin_f = hh->twin()->face(); - // new_f->set_decision(twin_f->get_decision()); - // - // hh->set_decision(twin_f->get_decision()); - // hh->twin()->set_decision(hh->get_decision()); - // } - // ++hec; - // }while (hec != hec_begin); - // } - //} // in order to use resolve_minimal_face with intersection halfedge, we go over // the new edges, and set data over their faces @@ -537,75 +507,57 @@ public: } else if (assign(icurve, cur_obj)) { - const Curve_2& curve = icurve.first; + const X_monotone_curve_2& x_curve = icurve.first; // find the intersection points and overlapping segments with the // original curve and insert them to the list of split points - // first, get x_monotone parts - std::list x_objects; - std::list::const_iterator obj_it; - const X_monotone_curve_2 *x_curve; - const Point_2 *iso_p; + //// first, get x_monotone parts + //std::list x_objects; + //std::list::const_iterator obj_it; + //const X_monotone_curve_2 *x_curve; + //const Point_2 *iso_p; - traits->make_x_monotone_2_object()(curve, - std::back_inserter(x_objects)); - for (obj_it = x_objects.begin(); obj_it != x_objects.end(); ++obj_it) + // intersect the x-monotone curve with the edge's curve + typedef std::pair Intersect_point_2; + std::list intersections_list; + const Intersect_point_2 *ip; + const X_monotone_curve_2 *icv; + + traits->intersect_2_object()(x_curve, original_cv, + std::back_inserter(intersections_list)); + + std::list::iterator inter_it = intersections_list.begin(); + for(; inter_it != intersections_list.end(); ++inter_it) { - x_curve = object_cast (&(*obj_it)); - if (x_curve != NULL) - + ip = object_cast (&(*inter_it)); + if (ip != NULL) { - // intersect the x-monotone curve with the edge's curve - typedef std::pair Intersect_point_2; - std::list intersections_list; - const Intersect_point_2 *ip; - const X_monotone_curve_2 *icv; - - traits->intersect_2_object()(*x_curve, original_cv, - std::back_inserter(intersections_list)); - - std::list::iterator inter_it = intersections_list.begin(); - for(; inter_it != intersections_list.end(); ++inter_it) - { - ip = object_cast (&(*inter_it)); - if (ip != NULL) - { - split_points.push_back(Point_2_with_info(ip->first, false, false)); - } - else - { - icv = object_cast (&(*inter_it)); - CGAL_assertion (icv != NULL); - - // we will add the *icv end points to the split_points, unless - // but we should be carefull with infinite curves. - Arr_traits_adaptor_2 tr_adaptor(*traits); - if(tr_adaptor.infinite_in_y_2_object()(*icv, MIN_END) == FINITE && - tr_adaptor.infinite_in_x_2_object()(*icv, MIN_END) == FINITE) - split_points.push_back(Point_2_with_info( - traits->construct_min_vertex_2_object()(*icv), - true, false)); - if(tr_adaptor.infinite_in_y_2_object()(*icv, MAX_END) == FINITE && - tr_adaptor.infinite_in_x_2_object()(*icv, MAX_END) == FINITE) - split_points.push_back(Point_2_with_info( - traits->construct_max_vertex_2_object()(*icv), - false, true)); - } - } + split_points.push_back(Point_2_with_info(ip->first, false, false)); } else { - iso_p = object_cast (&(*obj_it)); - CGAL_assertion (iso_p != NULL); - // if the point is on the curve, should add it the the split points - // list, otherwise, it is irrelevant and should be ignored - if (is_point_on_curve(*iso_p, original_cv)) - split_points.push_back(Point_2_with_info(*iso_p, false, false)); + icv = object_cast (&(*inter_it)); + CGAL_assertion (icv != NULL); + + // we will add the *icv end points to the split_points, unless + // but we should be carefull with infinite curves. + Arr_traits_adaptor_2 tr_adaptor(*traits); + if(tr_adaptor.infinite_in_y_2_object()(*icv, MIN_END) == FINITE && + tr_adaptor.infinite_in_x_2_object()(*icv, MIN_END) == FINITE) + split_points.push_back(Point_2_with_info( + traits->construct_min_vertex_2_object()(*icv), + true, false)); + if(tr_adaptor.infinite_in_y_2_object()(*icv, MAX_END) == FINITE && + tr_adaptor.infinite_in_x_2_object()(*icv, MAX_END) == FINITE) + split_points.push_back(Point_2_with_info( + traits->construct_max_vertex_2_object()(*icv), + false, true)); } - } + } } + else CGAL_assertion_msg(false, "wrong projected intersection type"); }