From af5d902d96f2ee2e93a73fa0ffed5e69e55cc695 Mon Sep 17 00:00:00 2001 From: Menelaos Karavelas Date: Wed, 2 Aug 2006 10:09:37 +0000 Subject: [PATCH] added one more operator() in info converter; modified code to use this new converter --- Segment_Delaunay_graph_2/changes.txt | 2 ++ .../Segment_Delaunay_graph_2/sdg-info-set.cpp | 21 +++++++++----- .../sdg-red-blue-info.cpp | 17 +++++++---- .../include/CGAL/Segment_Delaunay_graph_2.h | 29 ++++++++++++------- .../Segment_Delaunay_graph_2_impl.h | 6 ++-- .../Segment_Delaunay_graph_hierarchy_2_impl.h | 10 +++++-- ...elaunay_graph_storage_traits_with_info_2.h | 5 ++++ .../Segment_Delaunay_graph_2/Multi_info.h | 14 ++++++--- .../Segment_Delaunay_graph_2/Red_blue_info.h | 5 ++++ .../include/Multi_info.h | 6 ++++ 10 files changed, 82 insertions(+), 33 deletions(-) diff --git a/Segment_Delaunay_graph_2/changes.txt b/Segment_Delaunay_graph_2/changes.txt index c41a7dfcb15..c8a3949910e 100644 --- a/Segment_Delaunay_graph_2/changes.txt +++ b/Segment_Delaunay_graph_2/changes.txt @@ -1,5 +1,7 @@ 2 August 2006: Menelaos Karavelas - fixed problem created by deletion of files +- added one more operator() in info converter; modified code to use + this new converter 1 August 2006: Menelaos Karavelas - changed some file names to match the names of the classes they contain diff --git a/Segment_Delaunay_graph_2/examples/Segment_Delaunay_graph_2/sdg-info-set.cpp b/Segment_Delaunay_graph_2/examples/Segment_Delaunay_graph_2/sdg-info-set.cpp index 1e8d837bd27..6fb7b77c569 100644 --- a/Segment_Delaunay_graph_2/examples/Segment_Delaunay_graph_2/sdg-info-set.cpp +++ b/Segment_Delaunay_graph_2/examples/Segment_Delaunay_graph_2/sdg-info-set.cpp @@ -88,18 +88,25 @@ operator<<(std::ostream& os, const Info_set& info) return os; } - -// functor that defines how to convert info when a segment site -// is split into two sub-segments +// functor that defines how to convert color info when: +// 1. constructing the storage site of an endpoint of a segment +// 2. a segment site is split into two sub-segments template struct Info_set_convert_info { - typedef Info_item_t Info_item; - typedef Info_set result_type; + typedef Info_item_t Info_item; + typedef const Info_set& result_type; inline - Info_set operator()(const Info_set& info0, - const Info_set& info1, bool) const + result_type operator()(const Info_set& info0, bool) const + { + // just return the info of the supporting segment + return info0; + } + + inline + result_type operator()(const Info_set& info0, + const Info_set& info1, bool) const { // just return the info of the supporting segment return info0; diff --git a/Segment_Delaunay_graph_2/examples/Segment_Delaunay_graph_2/sdg-red-blue-info.cpp b/Segment_Delaunay_graph_2/examples/Segment_Delaunay_graph_2/sdg-red-blue-info.cpp index f5d5930fb7a..208f6e63364 100644 --- a/Segment_Delaunay_graph_2/examples/Segment_Delaunay_graph_2/sdg-red-blue-info.cpp +++ b/Segment_Delaunay_graph_2/examples/Segment_Delaunay_graph_2/sdg-red-blue-info.cpp @@ -31,15 +31,22 @@ operator<<(std::ostream& os, const Red_blue& rb) return os; } -// functor that defines how to convert color info when a segment site -// is split into two sub-segments +// functor that defines how to convert color info when: +// 1. constructing the storage site of an endpoint of a segment +// 2. a segment site is split into two sub-segments struct Red_blue_convert_info { - typedef Red_blue Info; - typedef Info result_type; + typedef Red_blue Info; + typedef const Info& result_type; inline - Info operator()(const Info& info0, const Info& info1, bool) const { + const Info& operator()(const Info& info0, bool) const { + // just return the info of the supporting segment + return info0; + } + + inline + const Info& operator()(const Info& info0, const Info& info1, bool) const { // just return the info of the supporting segment return info0; } diff --git a/Segment_Delaunay_graph_2/include/CGAL/Segment_Delaunay_graph_2.h b/Segment_Delaunay_graph_2/include/CGAL/Segment_Delaunay_graph_2.h index 95b5bbcbf07..1839c7c9368 100644 --- a/Segment_Delaunay_graph_2/include/CGAL/Segment_Delaunay_graph_2.h +++ b/Segment_Delaunay_graph_2/include/CGAL/Segment_Delaunay_graph_2.h @@ -613,22 +613,31 @@ public: protected: template - inline void copy_info1(SSite& ss_trg, const SSite& ss_src, int, - typename SSite::Has_info_tag const* = 0) const + inline void convert_info1(SSite& ss_trg, const SSite& ss_src, + bool is_src, int, + typename SSite::Has_info_tag const* = 0) const { - // std::cerr << "copying info..." << std::flush; - ss_trg.set_info(ss_src.info()); + // std::cerr << "converting info..." << std::flush; + typename Storage_traits::Convert_info convert = st_.convert_info_object(); + + ss_trg.set_info( convert(ss_src.info(), is_src) ); // std::cerr << " done!" << std::endl; } template - inline void copy_info1(SSite& ss_trg, const SSite& ss_src, char) const + inline void convert_info1(SSite& ss_trg, + const SSite& ss_src, bool, char) const { } - void copy_info(Storage_site_2& ss_trg, - const Storage_site_2& ss_src) const { - copy_info1(ss_trg, ss_src, 0); + void convert_info(Storage_site_2& ss_trg, + const Storage_site_2& ss_src, bool is_src) const { + CGAL_precondition( ss_src.is_segment() && ss_trg.is_point() ); + CGAL_precondition( ss_src.is_input() && ss_trg.is_input() ); + CGAL_assertion( (is_src && same_points(ss_src.source_site(), ss_trg)) || + (!is_src && same_points(ss_src.target_site(), ss_trg)) + ); + convert_info1(ss_trg, ss_src, is_src, 0); } template @@ -639,9 +648,8 @@ protected: Storage_site_2 ss_v = v->storage_site(); typename Storage_traits::Merge_info merge = st_.merge_info_object(); - typename Storage_traits::Info merged_info = merge(ss_v.info(), ss.info()); - ss_v.set_info(merged_info); + ss_v.set_info( merge(ss_v.info(), ss.info()) ); v->set_site(ss_v); // std::cerr << " done!" << std::endl; } @@ -654,7 +662,6 @@ protected: // merges the info of the storage site of the vertex handle with the // info of the given site; the vertex_handle contains the storage // site with the new info - // Precondition: the two sites must be indentical inline void merge_info(Vertex_handle v, const Storage_site_2& ss) { CGAL_precondition( (v->storage_site().is_segment() && ss.is_segment() && diff --git a/Segment_Delaunay_graph_2/include/CGAL/Segment_Delaunay_graph_2/Segment_Delaunay_graph_2_impl.h b/Segment_Delaunay_graph_2/include/CGAL/Segment_Delaunay_graph_2/Segment_Delaunay_graph_2_impl.h index 010ea7def36..e94d7858e99 100644 --- a/Segment_Delaunay_graph_2/include/CGAL/Segment_Delaunay_graph_2/Segment_Delaunay_graph_2_impl.h +++ b/Segment_Delaunay_graph_2/include/CGAL/Segment_Delaunay_graph_2/Segment_Delaunay_graph_2_impl.h @@ -662,14 +662,14 @@ insert_segment(const Storage_site_2& ss, const Site_2& t, Vertex_handle vnear) if ( is_degenerate_segment(t) ) { Storage_site_2 ss_src = ss.source_site(); - copy_info(ss_src, ss); + convert_info(ss_src, ss, true); return insert_point(ss_src, t.source(), vnear); } Storage_site_2 ss_src = ss.source_site(); - copy_info(ss_src, ss); + convert_info(ss_src, ss, true); Storage_site_2 ss_trg = ss.target_site(); - copy_info(ss_trg, ss); + convert_info(ss_trg, ss, false); Vertex_handle v0 = insert_point( ss_src, t.source(), vnear ); CGAL_assertion( is_valid() ); diff --git a/Segment_Delaunay_graph_2/include/CGAL/Segment_Delaunay_graph_2/Segment_Delaunay_graph_hierarchy_2_impl.h b/Segment_Delaunay_graph_2/include/CGAL/Segment_Delaunay_graph_2/Segment_Delaunay_graph_hierarchy_2_impl.h index a9cad698c58..bccdc38dabd 100644 --- a/Segment_Delaunay_graph_2/include/CGAL/Segment_Delaunay_graph_2/Segment_Delaunay_graph_hierarchy_2_impl.h +++ b/Segment_Delaunay_graph_2/include/CGAL/Segment_Delaunay_graph_2/Segment_Delaunay_graph_hierarchy_2_impl.h @@ -325,7 +325,7 @@ insert_segment(const Point_2& p0, const Point_2& p1, if ( is_degenerate_segment(t) ) { Storage_site_2 ss_src = ss.source_site(); - copy_info(ss_src, ss); + convert_info(ss_src, ss, true); return insert_point(p0, ss_src, level); } @@ -333,12 +333,16 @@ insert_segment(const Point_2& p0, const Point_2& p1, Vertex_handle vertices1[sdg_hierarchy_2__maxlevel]; Storage_site_2 ss_src = ss.source_site(); - copy_info(ss_src, ss); + convert_info(ss_src, ss, true); +#if 1 + insert_point(p0, ss_src, level, vertices0); +#else std::pair res = insert_point(p0, ss_src, level, vertices0); if ( res.first ) { level = res.second; } +#endif Storage_site_2 ss_trg = ss.target_site(); - copy_info(ss_trg, ss); + convert_info(ss_trg, ss, false); insert_point(p1, ss_trg, level, vertices1); CGAL_assertion( vertices0[0] != Vertex_handle() ); diff --git a/Segment_Delaunay_graph_2/include/CGAL/Segment_Delaunay_graph_storage_traits_with_info_2.h b/Segment_Delaunay_graph_2/include/CGAL/Segment_Delaunay_graph_storage_traits_with_info_2.h index de5c89d1dff..f8d150eb900 100644 --- a/Segment_Delaunay_graph_2/include/CGAL/Segment_Delaunay_graph_storage_traits_with_info_2.h +++ b/Segment_Delaunay_graph_2/include/CGAL/Segment_Delaunay_graph_storage_traits_with_info_2.h @@ -36,6 +36,11 @@ struct Dummy_convert_info typedef Info_ Info; typedef Info result_type; + inline + Info operator()(const Info&, bool) const { + return Info(); + } + inline Info operator()(const Info&, const Info&, bool) const { return Info(); diff --git a/Segment_Delaunay_graph_2/new_stuff/Segment_Delaunay_graph_2/Multi_info.h b/Segment_Delaunay_graph_2/new_stuff/Segment_Delaunay_graph_2/Multi_info.h index 593e0ec1cf2..a2a27bbbea6 100644 --- a/Segment_Delaunay_graph_2/new_stuff/Segment_Delaunay_graph_2/Multi_info.h +++ b/Segment_Delaunay_graph_2/new_stuff/Segment_Delaunay_graph_2/Multi_info.h @@ -67,8 +67,14 @@ operator<<(std::ostream& os, const Multi_info& info) template struct Multi_info_convert_info { - typedef Info_t Info; - typedef Info result_type; + typedef Info_t Info; + typedef Multi_info result_type; + + inline + Multi_info operator()(const Multi_info& minfo0, bool) const + { + return minfo0; + } inline Multi_info operator()(const Multi_info& minfo0, @@ -81,8 +87,8 @@ struct Multi_info_convert_info template struct Multi_info_merge_info { - typedef Info_t Info; - typedef Info result_type; + typedef Info_t Info; + typedef Multi_info result_type; inline Multi_info operator()(const Multi_info& minfo0, diff --git a/Segment_Delaunay_graph_2/new_stuff/Segment_Delaunay_graph_2/Red_blue_info.h b/Segment_Delaunay_graph_2/new_stuff/Segment_Delaunay_graph_2/Red_blue_info.h index ae81de844ca..42ecf2e96f7 100644 --- a/Segment_Delaunay_graph_2/new_stuff/Segment_Delaunay_graph_2/Red_blue_info.h +++ b/Segment_Delaunay_graph_2/new_stuff/Segment_Delaunay_graph_2/Red_blue_info.h @@ -31,6 +31,11 @@ struct Red_blue_convert_info typedef Red_blue Info; typedef Info result_type; + inline + Info operator()(const Info& info0, bool) const { + return info0; + } + inline Info operator()(const Info& info0, const Info& info1, bool) const { return info0; diff --git a/Segment_Delaunay_graph_2/test/Segment_Delaunay_graph_2/include/Multi_info.h b/Segment_Delaunay_graph_2/test/Segment_Delaunay_graph_2/include/Multi_info.h index e23e108efa9..a2a27bbbea6 100644 --- a/Segment_Delaunay_graph_2/test/Segment_Delaunay_graph_2/include/Multi_info.h +++ b/Segment_Delaunay_graph_2/test/Segment_Delaunay_graph_2/include/Multi_info.h @@ -70,6 +70,12 @@ struct Multi_info_convert_info typedef Info_t Info; typedef Multi_info result_type; + inline + Multi_info operator()(const Multi_info& minfo0, bool) const + { + return minfo0; + } + inline Multi_info operator()(const Multi_info& minfo0, const Multi_info& minfo1, bool) const