From 5e57a538e77aeb190796cc07a0fdfd27f40e13da Mon Sep 17 00:00:00 2001 From: Eli Packer Date: Sun, 10 Aug 2003 15:11:00 +0000 Subject: [PATCH] *** --- .../demo/Snap_rounding_2/data/density | 2 +- .../demo/Snap_rounding_2/demo.C | 14 ----- .../basic/Snap_rounding_ref/snap_ref.tex | 7 +-- .../include/CGAL/Snap_rounding_2.h | 22 +++++++- .../include/CGAL/Snap_rounding_kd_2.h | 45 ++++++++++------ .../include/CGAL/Snap_rounding_traits_2.h | 52 ++++++++++++------- 6 files changed, 88 insertions(+), 54 deletions(-) diff --git a/Packages/Snap_rounding_2/demo/Snap_rounding_2/data/density b/Packages/Snap_rounding_2/demo/Snap_rounding_2/data/density index fc1a12978fd..0cc1be52bf6 100644 --- a/Packages/Snap_rounding_2/demo/Snap_rounding_2/data/density +++ b/Packages/Snap_rounding_2/demo/Snap_rounding_2/data/density @@ -1,4 +1,4 @@ -200 +100 1/1 0/1 0/1 100/1 0/1 0/1 0/1 100/1 2/1 diff --git a/Packages/Snap_rounding_2/demo/Snap_rounding_2/demo.C b/Packages/Snap_rounding_2/demo/Snap_rounding_2/demo.C index ab498cbd0b6..eb20d512c62 100644 --- a/Packages/Snap_rounding_2/demo/Snap_rounding_2/demo.C +++ b/Packages/Snap_rounding_2/demo/Snap_rounding_2/demo.C @@ -1,17 +1,5 @@ #include -#ifndef CGAL_USE_LEDA -int main() -{ - - std::cout << "Sorry, this demo needs LEDA for visualisation."; - std::cout << std::endl; - - return 0; -} - -#else - #include #include #include @@ -459,5 +447,3 @@ int main(int argc,char *argv[]) return(0); } - -#endif diff --git a/Packages/Snap_rounding_2/doc_tex/basic/Snap_rounding_ref/snap_ref.tex b/Packages/Snap_rounding_2/doc_tex/basic/Snap_rounding_ref/snap_ref.tex index 8809723c0ee..5733e7e56e1 100644 --- a/Packages/Snap_rounding_2/doc_tex/basic/Snap_rounding_ref/snap_ref.tex +++ b/Packages/Snap_rounding_2/doc_tex/basic/Snap_rounding_ref/snap_ref.tex @@ -77,9 +77,7 @@ grid just as defined by the Snap Rounding algorithm. Note that the number type o the representation remains {\ccc Traits::FT}. Otherwise, the plane is tiled with unit pixels with size {\ccc pixel\_size} and each vertice of the output is represented by the coordinates of the cenetr of the hot pixel that contains it. -The seventh parameter is desribed below. - -\ccPrecond{\ccc{pixel_size} must have a positive value and \ccc{number_of_kd_trees} must be a positive integer.} +The seventh parameter is desribed next. \begin{ccAdvanced} @@ -123,6 +121,9 @@ The seventh parameter is desribed below. \end{ccAdvanced} +\ccPrecond{\ccc{pixel_size} must have a positive value and \ccc{number_of_kd_trees} must be a positive integer.} + + \end{ccRefFunction} %\end{ccRefClass} diff --git a/Packages/Snap_rounding_2/include/CGAL/Snap_rounding_2.h b/Packages/Snap_rounding_2/include/CGAL/Snap_rounding_2.h index 9ac00e6e394..3b15236ba9e 100644 --- a/Packages/Snap_rounding_2/include/CGAL/Snap_rounding_2.h +++ b/Packages/Snap_rounding_2/include/CGAL/Snap_rounding_2.h @@ -135,6 +135,10 @@ struct hot_pixel_dir_cmp bool operator ()(const Hot_Pixel *h1,const Hot_Pixel *h2); }; +#ifdef KD_DEBUG +int number_of_false_hp; +#endif + template class Snap_rounding_2 { @@ -191,8 +195,6 @@ private: NT pixel_size, bool int_output, Multiple_kd_tree *> *mul_kd_tree); - - // void list_copy(std::list& target,std::list& source); }; // ctor @@ -557,6 +559,12 @@ void Snap_rounding_2:: (*iter)->set_direction(seg_dir); hot_pixels_intersected_set.insert(*iter); } + +#ifdef KD_DEBUG + else + ++number_of_false_hp; +#endif + } number_of_intersections = hot_pixels_intersected_set.size(); @@ -685,6 +693,10 @@ void snap_rounding_2( bool int_output = true, unsigned int number_of_kd_trees = 1) { +#ifdef KD_DEBUG + number_of_false_hp = 0; +#endif + std::list > seg_list; Multiple_kd_tree *> *mul_kd_tree; @@ -702,6 +714,12 @@ void snap_rounding_2( seg_list,&mul_kd_tree); s.iterate(output_container,pixel_size,int_output,do_isr,seg_list, mul_kd_tree); + +#ifdef KD_DEBUG + std::cout << "Overall number of false hot pixels in all the queries : " + << number_of_false_hp << std::endl; +#endif + } CGAL_END_NAMESPACE diff --git a/Packages/Snap_rounding_2/include/CGAL/Snap_rounding_kd_2.h b/Packages/Snap_rounding_2/include/CGAL/Snap_rounding_kd_2.h index 4259efb4d5c..43f002495dd 100644 --- a/Packages/Snap_rounding_2/include/CGAL/Snap_rounding_kd_2.h +++ b/Packages/Snap_rounding_2/include/CGAL/Snap_rounding_kd_2.h @@ -71,10 +71,9 @@ typedef std::pair > kd_triple; typedef std::list > > kd_triple_list; - private: Rep_ _gt; - const double pi,half_pi,epsilon; + const double pi,half_pi; int number_of_trees; kd_triple_list kd_trees_list; std::list > input_points_list; @@ -84,11 +83,11 @@ private: { static const double rad_to_deg = 57.297; int tranc_angle = int(angle.to_double() * rad_to_deg); + NT cosine_val = angle_to_sines_appr[90 - tranc_angle], sine_val = angle_to_sines_appr[tranc_angle]; Transformation_2 rotate(ROTATION, sine_val, cosine_val); - p = rotate(p); } @@ -104,9 +103,7 @@ private: ++iter) { Point_2 p(iter->first); rotate(p,angle); - my_point rotated_point(p,iter->first,iter->second); - l.push_back(rotated_point); } @@ -118,15 +115,20 @@ private: assert(tree->is_valid()); NT buffer_angle(angle - half_pi / (2 * number_of_trees)); + if(buffer_angle < 0) + buffer_angle = 0; Line_2 li(tan(buffer_angle.to_double()),-1,0); Direction_2 d(li); + // rotate_by 180 degrees + Transformation_2 t(ROTATION,0,-1); + d = d.transform(t); std::pair kp(d,angle); kd_triple kt(tree,kp); return(kt); } - inline NT squere(NT x) {return(x * x);} + inline NT square(NT x) {return(x * x);} inline NT min(NT x,NT y) {return((x < y) ? x : y);} inline NT max(NT x,NT y) {return((x < y) ? y : x);} inline NT min(NT x1,NT x2,NT x3,NT x4,NT x5,NT x6) @@ -180,13 +182,13 @@ private: } void check_kd(int *kd_counter,int number_of_trees, - std::list &seg_list,std::list& directions) + const std::list &seg_list,std::list& directions) { for(int i = 0;i < number_of_trees;++i) kd_counter[i] = 0; int kd_num; - for(typename std::list::iterator iter = + for(typename std::list::const_iterator iter = seg_list.begin();iter != seg_list.end();++iter) { kd_num = get_kd_num(*iter,number_of_trees,directions); kd_counter[kd_num]++; @@ -290,10 +292,10 @@ private: public: - Multiple_kd_tree(std::list > + Multiple_kd_tree(const std::list > &inp_points_list,int inp_number_of_trees, - std::list &seg_list) : - pi(3.1415),half_pi(1.57075),epsilon(0.001), + const std::list &seg_list) : + pi(3.1415),half_pi(1.57075), number_of_trees(inp_number_of_trees),input_points_list(inp_points_list) { kd_triple kd; @@ -316,10 +318,20 @@ public: NT buffer_angle; Line_2 li; Direction_2 d; - for(NT angle = 0;angle < half_pi;angle += half_pi / number_of_trees) { + + int i = 0; + for(NT angle = 0; + i < number_of_trees; + angle += half_pi / number_of_trees,++i) { buffer_angle = angle - half_pi / (2 * number_of_trees); + if(buffer_angle < 0) + buffer_angle = 0; li = Line_2(tan(buffer_angle.to_double()),-1,0); d = Direction_2(li); + // rotate_by 180 degrees + Transformation_2 t(ROTATION,0,-1); + d = d.transform(t); + directions.push_back(d); } @@ -330,7 +342,9 @@ public: int number_of_actual_kd_trees = 0; #endif - for(NT angle = 0;angle < half_pi;angle += half_pi / number_of_trees) { + for(NT angle = 0,i = 0; + i < number_of_trees; + angle += half_pi / number_of_trees,++i) { if(kd_counter[ind] >= (double)number_of_segments / (double)number_of_trees / 2.0) { kd = create_kd_tree(angle); @@ -390,7 +404,7 @@ public: void get_intersecting_points(list &result_list, Segment_2 s, - NT unit_squere) + NT unit_square) { // determine right kd-tree to work on, depending on the segment's slope Direction_2 d = get_direction(s); @@ -414,7 +428,7 @@ public: std::list points_list; _gt.minkowski_sum_with_pixel_2_object() - (points_list,s,unit_squere); + (points_list,s,unit_square); typename std::list::iterator points_iter; @@ -459,7 +473,6 @@ public: result_list.push_back(my_point_iter->object); } }; - CGAL_END_NAMESPACE #endif // CGAL_SR_KD_2_H diff --git a/Packages/Snap_rounding_2/include/CGAL/Snap_rounding_traits_2.h b/Packages/Snap_rounding_2/include/CGAL/Snap_rounding_traits_2.h index 470c7b19839..878d7f8925b 100644 --- a/Packages/Snap_rounding_2/include/CGAL/Snap_rounding_traits_2.h +++ b/Packages/Snap_rounding_2/include/CGAL/Snap_rounding_traits_2.h @@ -26,7 +26,6 @@ #include #include -#include #include CGAL_BEGIN_NAMESPACE @@ -87,31 +86,48 @@ class Minkowski_sum_with_pixel_2 { public: void operator()(std::list& points_list, Segment_2 s, - NT unit_squere) + NT unit_square) { Comparison_result cx = _gt->compare_x_2_object()(s.source(),s.target()); + Comparison_result cy = _gt->compare_y_2_object()(s.source(),s.target()); NT x1 = s.source().x(),y1 = s.source().y(),x2 = s.target().x(),y2 = s.target().y(); Point_2 ms1,ms2,ms3,ms4,ms5,ms6;// minkowski sum points if(cx == SMALLER) { - // we use unit_squere instead of unit_squere / 2 in order to - // find tangency points which are not supported by kd-tree - ms1 = Point_2(x1 - 0.6 * unit_squere,y1 - 0.6 * unit_squere); - ms2 = Point_2(x1 - 0.6 * unit_squere,y1 + 0.6 * unit_squere); - ms3 = Point_2(x1 + 0.6 * unit_squere,y1 - 0.6 * unit_squere); - ms4 = Point_2(x2 + 0.6 * unit_squere,y2 - 0.6 * unit_squere); - ms5 = Point_2(x2 + 0.6 * unit_squere,y2 + 0.6 * unit_squere); - ms6 = Point_2(x2 - 0.6 * unit_squere,y2 + 0.6 * unit_squere); + if(cy == SMALLER) { + // we use unit_square instead of unit_square / 2 in order to + // find tangency points which are not supported by kd-tree + ms1 = Point_2(x1 - unit_square,y1 - unit_square); + ms2 = Point_2(x1 - unit_square,y1 + unit_square); + ms3 = Point_2(x1 + unit_square,y1 - unit_square); + ms4 = Point_2(x2 + unit_square,y2 - unit_square); + ms5 = Point_2(x2 + unit_square,y2 + unit_square); + ms6 = Point_2(x2 - unit_square,y2 + unit_square); + } else { + ms1 = Point_2(x1 - unit_square,y1 - unit_square); + ms2 = Point_2(x1 - unit_square,y1 + unit_square); + ms3 = Point_2(x1 + unit_square,y1 + unit_square); + ms4 = Point_2(x2 + unit_square,y2 - unit_square); + ms5 = Point_2(x2 + unit_square,y2 + unit_square); + ms6 = Point_2(x2 - unit_square,y2 - unit_square); + } } else { - // we use unit_squere instead of unit_squere / 2 in order to - // find tangency points which are not supported by kd-tree - ms1 = Point_2(x1 + 0.6 * unit_squere,y1 - 0.6 * unit_squere); - ms2 = Point_2(x1 - 0.6 * unit_squere,y1 - 0.6 * unit_squere); - ms3 = Point_2(x1 + 0.6 * unit_squere,y1 + 0.6 * unit_squere); - ms4 = Point_2(x2 + 0.6 * unit_squere,y2 + 0.6 * unit_squere); - ms5 = Point_2(x2 - 0.6 * unit_squere,y2 + 0.6 * unit_squere); - ms6 = Point_2(x2 - 0.6 * unit_squere,y2 - 0.6 * unit_squere); + if(cy == SMALLER) { + ms1 = Point_2(x1 + unit_square,y1 - unit_square); + ms2 = Point_2(x1 + unit_square,y1 + unit_square); + ms3 = Point_2(x1 - unit_square,y1 - unit_square); + ms4 = Point_2(x2 + unit_square,y2 + unit_square); + ms5 = Point_2(x2 - unit_square,y2 + unit_square); + ms6 = Point_2(x2 - unit_square,y2 - unit_square); + } else { + ms1 = Point_2(x1 + unit_square,y1 - unit_square); + ms2 = Point_2(x1 + unit_square,y1 + unit_square); + ms3 = Point_2(x1 - unit_square,y1 + unit_square); + ms4 = Point_2(x2 + unit_square,y2 - unit_square); + ms5 = Point_2(x2 - unit_square,y2 - unit_square); + ms6 = Point_2(x2 - unit_square,y2 + unit_square); + } } points_list.push_back(ms1);