Algorithmic Solutions > LEDA > LEDA Guide > Geometry > Input and Output


Input and Output

Stream Input and Output

Geometric objects can be written to streams and read from streams. The operators are designed such that output written by << can be read by >>.

Example

The 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 Output

Graphical 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 window.h the input operator >> is only defined for floating point objects. To use it for rational objects you must include rat_window.h.

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:

Data Types for 2D Geometry

Window

Mouse Input

Colors


Geometry

Advanced Data types for 2-D geometry

Data Types for 3-D Geometry

Geometry Algorithms

GeoWin




Please send any suggestions, comments or questions to leda@algorithmic-solutions.com
© Copyright 2001-2003, Algorithmic Solutions Software GmbH