Input and OutputStream Input and OutputGeometric objects can be written to streams and read from streams. The operators are designed such that output written by << can be read by >>. ExampleThe following example generates two points writes them to a file and reads them again. #include <LEDA/geo/point.h> #include <LEDA/system/stream.h> using namespace leda; int main() { point p(2,3), q(3,4); std::cout << p << endl << q << std::endl; file_ostream O("points.txt"); O << p << std::endl << q << std::endl; file_istream I("points.txt"); point r, s; I >> r >> s; std::cout << r << std::endl << s << std::endl; return 0; } Graphical Input and OutputGraphical input and output of geometric objects is very important. The Window class knows how to draw geometric objects and supports the construction of geometric objects by mouse input.The simplest way to draw a geometric object is to use the operator <<, for example, W << r.to_ray(); W << l.to_line();If more control is needed, e.g., concerning the color or whether a circle should be drawn as a disk, special draw functions of the Window class can be used. The operator >> can be used to read a point, segment, line, ray, circle, or polygon with the mouse, for example, W >> p; //p is a point W >> s; //s is a segment The reading operations are blocking and wait for mouse clicks. A point is constructed by a single click on the left mouse button, and a segment, line, ray, and circle is constructed by two clicks on the left mouse button. Remark: In Example#include <LEDA/graphics/window.h> #include <LEDA/geo/rat_point.h> #include <LEDA/geo/point.h> #include <LEDA/geo/rat_segment.h> #include <LEDA/geo/segment.h> using namespace leda; int main() { rat_point rp(60,70); rat_segment rs(point(0,0),point(100,100)); window W(100,100); W.open(); W << rp.to_point(); W << rs.to_segment(); point p; segment s; W >> p; W >> s; W.display(); W.read_mouse(); std::cout << p << std::endl << s << std::endl; return 0; } |
See also: |