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

  1. #include <LEDA/subdivision.h>
  2. #include <LEDA/plane.h>
  3. #include <LEDA/window.h>
  4.  
  5.  
  6. declare(subdivision,int)
  7.  
  8. declare(edge_array,real)
  9.  
  10.  
  11. void   show_face(subdivision(int)& G, face f, window& W)
  12. { list(node) L = G.adj_nodes(f);
  13.   list(point) P;
  14.   node v;
  15.   forall(v,L) P.append(G[v]);
  16.   W.draw_filled_polygon(P);
  17. }
  18.  
  19.  
  20. main()
  21. {
  22.  
  23.   window W;
  24.  
  25.   W.init(0,1000,0);
  26.  
  27.   W.set_node_width(3);
  28.   W.set_line_width(2);
  29.  
  30.   panel P("Arrangement of line segments");
  31.  
  32.   P.text_item("This program computes the subdivision defined by the "); 
  33.   P.text_item("arrangement of a list of straight line segments. Use ");
  34.   P.text_item("the left button to insert a sequence of segments and ");
  35.   P.text_item("terminate the input by clicking the right button. Now");
  36.   P.text_item("you can input query points with the left button. For ");
  37.   P.text_item("each point p the face of the arrangment containing p ");
  38.   P.text_item("is computed and displayed. Terminate the program by  "); 
  39.   P.text_item("pressing the right mouse key.                        ");
  40.   P.text_item("                                                     ");
  41.  
  42.   P.button("continue");
  43.  
  44.   P.open();
  45.  
  46.  
  47.  
  48.   list(segment) seglist1,seglist2;
  49.   segment s;
  50.  
  51.   while ( W >> s ) 
  52.   { W << s;
  53.     seglist1.append(s);
  54.    }
  55.  
  56.   GRAPH(point,int) G;
  57.  
  58.  
  59.   cout << "Computing subdivision.\n";
  60.  
  61.  
  62.   SWEEP_SEGMENTS(seglist1,seglist2,G);
  63.  
  64.   W.clear(); 
  65.  
  66.   // Draw Subdivision
  67.  
  68.   edge e;
  69.   forall_edges(e,G)
  70.   W.draw_segment(G[source(e)], G[target(e)]);
  71.  
  72.  
  73.  
  74.   cout << "Constructing search structure\n";
  75.  
  76.  
  77.   // insert reverse edges
  78.  
  79.   list(edge) L = G.all_edges();
  80.   forall(e,L) G.new_edge(target(e),source(e),G[e]);
  81.  
  82.  
  83.   // sort edges counter-clockwise
  84.  
  85.   edge_array(real) angle(G);
  86.  
  87.   forall_edges(e,G)
  88.   { segment s(G[source(e)],G[target(e)]);
  89.     angle[e] = s.angle();
  90.    }
  91.  
  92.   G.sort_edges(angle);
  93.  
  94.  
  95.   // Create Subdivision
  96.  
  97.   subdivision(int) S(G);
  98.  
  99.  
  100.  
  101.   W.message("Give query points!");
  102.  
  103.  
  104.  
  105.  
  106.   // Locate points
  107.  
  108.   W.set_mode(xor_mode);
  109.  
  110.   point p;
  111.   face  f=nil;
  112.  
  113.   while (W >> p)
  114.   { if (f) show_face(S,f,W);
  115.     f = S.locate_point(p);
  116.     show_face(S,f,W);
  117.    }
  118.  
  119. }
  120.