sweep_curves_base_2.h

来自「CGAL is a collaborative effort of severa」· C头文件 代码 · 共 1,701 行 · 第 1/5 页

H
1,701 行
字号
    typedef typename std::list<Curve_node>::iterator                                                list_Curve_node_iterator;    Sweep_curves_base_2() :     traits(new Traits), use_delete_traits(true), intersection_exist_(false) {}    Sweep_curves_base_2(Traits *traits_) :     traits(traits_), use_delete_traits(false), intersection_exist_(false) {}    ~Sweep_curves_base_2()  {    if (use_delete_traits)      delete traits;  }protected:    void reset() { intersection_exist_ = false; }  // change it back to the original one.  bool  handle_one_event (Event_queue & event_queue,                           Status_line & status,                           const Point & event_point,                           Intersection_point_node & point_node)  {    bool event_terminated = true;    bool point_node_first_on_status = false, point_node_last_on_status = false;        // a container to hold the point_node curve nodes ordered as they    // should on status.    typedef std::set<Curve_node,Less_yx>         Local_status_line;     typedef typename Local_status_line::iterator Local_status_line_iterator;     Less_yx            pred(traits);    Local_status_line local_status(pred);   // reserve the size of the                                            // point_node enamating curves.            Status_line_iterator hint = status.end();    Curve_node_iterator cv_iter = point_node.curves_begin();    if (cv_iter != point_node.curves_begin())      --cv_iter;    for ( ; hint == status.end() && cv_iter != point_node.curves_end();           ++cv_iter)      hint = std::find(status.begin(), status.end(), *cv_iter);        if (hint == status.begin())      point_node_first_on_status = true;        if (hint != status.end()){      ++hint;  // getting the first curve node on status above the               // highest *cv_iter of curve_node.      if (hint == status.end())        point_node_last_on_status = true;    }        //bool hint_in_point_node = false;    while (hint != status.end()){      for (cv_iter = point_node.curves_begin() ;            cv_iter != point_node.curves_end(); ++cv_iter)        if (*hint == *cv_iter) {	  break;	}          if (cv_iter != point_node.curves_end())        ++hint;      else        break;    }        Local_status_line_iterator local_status_hint = local_status.end();    for (cv_iter = point_node.curves_begin();          cv_iter != point_node.curves_end(); ++cv_iter)    {            // trying to use general find in order to force it to use      // operator == of Curve node. We only care here if *cv_iter is      // on the status, we don't care where it should be put on status      // according less_curve_xy predicate.  Since we work with handles only      // address comparing will be done.      Status_line_iterator curr_cv_node = std::find(status.begin(),                                                     status.end(),                                                     *cv_iter);            // the event point is not the right point of the curve -       // insert curve to status if it's not already there.        if (curr_cv_node != status.end()){        // remove cv_iter from status and reinsert it with the new point.        status.erase(curr_cv_node);      }            CGAL_expensive_postcondition_code(is_valid(status));            // reinserting curve only if it's still on status.      if (!traits->point_equal(event_point,                                 cv_iter->get_rightmost_point().point()))        cv_iter->push_event_point(point_node.get_point());            if (local_status_hint != local_status.end()){          ++local_status_hint;      }            if (Compare_lexicographically_xy(                   event_point,                    traits->curve_target(cv_iter->get_curve()) ) ==           CGAL::SMALLER){        local_status_hint = local_status.insert(local_status_hint, *cv_iter);                //if (local_status_hint == local_status.end()) cout << "ERROR        //- returned value of insert to local status is        //local_status.end()"<<endl;      }    }        if (local_status.empty()) {      if (status.empty())        return event_terminated;            if (!(point_node_first_on_status || point_node_last_on_status)           && hint != status.begin())          // if the neighbor of the curves enamting from point node is        // not the last one or the first one on status        if (check_status_neighbors_intersections(event_queue,                                                  status,                                                  --hint,                                                  event_point))           event_terminated = false;                    return event_terminated;    }        Status_line_iterator new_cv_node_begin = status.insert(                                               hint,                                                *(local_status.begin()) );        hint = new_cv_node_begin;    Local_status_line_iterator local_status_iter = local_status.begin();    for (++local_status_iter;          local_status_iter != local_status.end(); ++local_status_iter){             if (hint != status.end()){         ++hint;       }       hint = status.insert(hint, *local_status_iter);    }    Status_line_iterator new_cv_node_end = new_cv_node_begin;    std::advance(new_cv_node_end, local_status.size());    Status_line_iterator new_cv_node_it;    for (new_cv_node_it = new_cv_node_begin;          new_cv_node_it != new_cv_node_end; ++new_cv_node_it){      if (check_status_neighbors_intersections(event_queue, status,                                                new_cv_node_it, event_point))        // Edge case of tangency in the event point,         // if it is this event will be taked cared again.        event_terminated = false;                  // only if it's the first one, we will also check the preseding      // curve node adjancy.      if (new_cv_node_it ==  new_cv_node_begin){        if (new_cv_node_it != status.begin()){          --new_cv_node_it;                    if (check_status_neighbors_intersections(event_queue,                                                    status,                                                    new_cv_node_it,                                                    event_point))            // Edge case of tangency in the event point, if it is -             // this event will be taked cared again.            event_terminated = false;          ++new_cv_node_it;        }      }    }        return event_terminated;  }   // Handling overlapping curves.  // On each overlapping group, we remove// iteratively each curve and check for new events after the removing.// when finish, we reinsert to the status all the overlapping removed// curves.  void  handle_overlapping_curves(Event_queue& event_queue,                                  Status_line& status,                                    const Point &event_point,                                  Intersection_point_node& point_node)  {    // bool event_overlap_terminated = true;        for (Curve_node_iterator cv_iter = point_node.curves_begin();          cv_iter != point_node.curves_end(); ++cv_iter) {      Status_line_iterator curr_cv_node = std::find(status.begin(),                                                     status.end(),                                                     *cv_iter);      if (curr_cv_node != status.end()){        if (curr_cv_node != status.begin()){          std::list<Curve_node>  overlapping_curves;                    Status_line_iterator lower =  --curr_cv_node;          ++curr_cv_node;          for ( ;curr_cv_node != status.begin() &&                   traits->curves_overlap(lower->get_curve(),                                          curr_cv_node->get_curve()); --lower){                        Point p1, p2;            traits->nearest_intersection_to_right (curr_cv_node->get_curve(),                                                   lower->get_curve(),                                                   event_point, p1, p2);                        if (is_left(event_point, p1) || is_right(event_point, p2))               // means that the overlapping does not intersects the               // status line.              break;                        overlapping_curves.push_back(*curr_cv_node);            status.erase(curr_cv_node);                        curr_cv_node = lower;            Curve_node  cv_node = *curr_cv_node;                        // now taking care of the events created by the overlapping curve                        Point xp;            if (check_status_neighbors_intersections(event_queue,                                                      status,                                                      curr_cv_node,                                                      event_point))              // Edge case of tangency in the event point,               // if it is this event will be taked cared again.              // event_overlap_terminated = false;                        if (curr_cv_node != status.begin()){              --curr_cv_node;              if (check_status_neighbors_intersections(event_queue,                                                        status,                                                        curr_cv_node,                                                        event_point))                // Edge case of tangency in the event point,                 // if it is - this event will be taked cared again.                // event_overlap_terminated = false;              ++curr_cv_node;            }                        if (curr_cv_node != status.end() &&                 Compare_lexicographically_xy (                         event_point,                          traits->curve_target(curr_cv_node->get_curve()) ) ==                CGAL::EQUAL){                            Status_line_iterator prev_cv_node;              bool first = true;              // hold the (lower) neighbor element of the current.              if (curr_cv_node != status.begin()){                prev_cv_node = --curr_cv_node;                ++curr_cv_node;                first = false;              }              status.erase(curr_cv_node);                            CGAL_expensive_postcondition_code(is_valid(status));                            if (!first){                if (check_status_neighbors_intersections(event_queue,                                                          status,                                                          prev_cv_node,                                                          event_point))                  // Edge case of tangency in the event point, if it                  // is this event will be taked cared again.                  // event_overlap_terminated = false;                    ;              }            }           }          // reinsert to the status line all the overlapping removed curves.          for (list_Curve_node_iterator ovlp_iter=overlapping_curves.begin();                ovlp_iter != overlapping_curves.end(); ++ovlp_iter)                        status.insert(Status_line_value_type(*ovlp_iter));        }      }            curr_cv_node = std::find(status.begin(), status.end(), *cv_iter);      if (curr_cv_node != status.end()){        std::list<Curve_node>  overlapping_curves;                Status_line_iterator upper =  ++curr_cv_node;        --curr_cv_node;                        for ( ;upper != status.end() && curr_cv_node != status.end() &&                 traits->curves_overlap(curr_cv_node->get_curve(),                                       upper->get_curve()); ++upper){                    Point p1, p2;          traits->nearest_intersection_to_right (curr_cv_node->get_curve(),                                                 upper->get_curve(),                                                 event_point , p1, p2);                    // means that the overlapping does not intersects the status line.          if (is_left(event_point, p1) || is_right(event_point, p2))             break;                    overlapping_curves.push_back(*curr_cv_node);          status.erase(curr_cv_node);                    curr_cv_node = upper;          Curve_node  cv_node = *curr_cv_node;                    // now taking care of the events created by the overlapping curve.          Point xp;          if (check_status_neighbors_intersections(event_queue, status,                                                    curr_cv_node,                                                    event_point))            // Edge case of tangency in the event point,             // if it is this event will be taked cared again.            // event_overlap_terminated = false;                    if (curr_cv_node != status.begin()){            --curr_cv_node;            if (check_status_neighbors_intersections(event_queue,                                                      status,                                                      curr_cv_node,                                                      event_point))              // Edge case of tangency in the event point,               // if it is - this event will be taked cared again.              // event_overlap_terminated = false;                        ++curr_cv_node;          }                    if (curr_cv_node != status.end() &&               Compare_lexicographically_xy (                       event_point,                        traits->curve_target(curr_cv_node->get_curve()) ) == 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?