home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / diverses / leda / prog / graphics / interval.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-15  |  1.5 KB  |  80 lines

  1. #include <LEDA/interval_set.h>
  2. #include <LEDA/window.h>
  3.  
  4.  
  5. declare(interval_set,segment)
  6.  
  7.  
  8. main()
  9.   interval_set(segment)  I;
  10.  
  11.   window W;
  12.  
  13.   W.init(-1000,1000,-1000);
  14.   W.set_line_width(1);
  15.  
  16.   panel P("interval_set");
  17.  
  18.   P.text_item("Use the left mouse button to insert a set of segments, ");
  19.   P.text_item("terminate the input by clicking the right button. Now, ");
  20.   P.text_item("you can define query slabs by giving two vertical lines");
  21.   P.text_item("with the left mouse button. For each slab, the program ");
  22.   P.text_item("computes and shows all segments intersecting it. Leave ");
  23.   P.text_item("the program by clicking the right mouse button.        ");
  24.  
  25.   P.button("continue");
  26.  
  27.   P.open();
  28.  
  29.  
  30.   segment s;
  31.  
  32.   while (W >> s)
  33.   { W << s;
  34.     if (s.xcoord1() <= s.xcoord2())
  35.       I.insert(s.xcoord1(),s.xcoord2(),s);
  36.     else
  37.       I.insert(s.xcoord2(),s.xcoord1(),s);
  38.    }
  39.  
  40.   W.set_mode(xor_mode);
  41.  
  42.   list(is_item) L;
  43.   is_item it;
  44.   real    x0 = W.xmin();
  45.   real    x1 = W.xmin();
  46.  
  47.   point   p;
  48.  
  49.   while (W >> p)
  50.   { 
  51.     W.draw_vline(x0);
  52.     W.draw_vline(x1);
  53.  
  54.     W.set_line_width(4);
  55.     forall(it,L) W << I.inf(it);
  56.     W.set_line_width(1);
  57.     forall(it,L) W << I.inf(it);
  58.  
  59.     x0 = p.xcoord();
  60.     W.draw_vline(x0);
  61.  
  62.     W >> p;
  63.     x1 = p.xcoord();
  64.     W.draw_vline(x1);
  65.  
  66.     L = I.intersection(x0,x1);
  67.  
  68.     forall(it,L) W << I.inf(it);
  69.     W.set_line_width(4);
  70.     forall(it,L) W << I.inf(it);
  71.     W.set_line_width(1);
  72.  
  73.     forall(it,L) cout << I.inf(it) << "\n";
  74.     newline;
  75.  
  76.   }
  77.  
  78. }
  79.