Chapter 12
Colors, Window streams, and Postscript Streams

Matthias Bäsken, Andreas Fabri, Lutz Kettner, and Stefan Schirra

12.1   Introduction

The LEDA library comes with its own window toolkit and with a Postscipt file stream. CGAL provides two classes CGAL::Window_stream Postscript_file_stream which are a thin glue layer that allows I/O for the geometric classes of the CGAL Kernel.

12.2   Window output

An object of type CGAL::Window_stream is a two-dimensional window for graphical IO. The input and output operations perform a mapping from object coordinates to window coordinates. Actually, CGAL::Window_stream is identical to the LEDA class leda_window, and LEDA must be installed. The class additionlly provides input and output operators for the classes which are defined in the CGAL kernel. CGAL::Window_stream should be initialized with a coordinate frame (by calling member function init) and must be displayed (by calling member function display) before drawing.

For further information on leda_window, we refer to the LEDA manual.

Input and output operators for CGAL::Window_stream are defined for the geometric classes in the CGAL kernel. The coordinates of the geometric objects are in object space. Data are entered with the left mouse button.

It is important that the window stream header file gets included after the inclusion of the header files of geometric classes that get inserted to or extracted from the window stream. See the following small example program.

#include <CGAL/Cartesian.h>
#include <CGAL/Segment_2.h>
#include <CGAL/IO/Window_stream.h>

typedef CGAL::Point_2< CGAL::Cartesian<double> >     Point;
typedef CGAL::Segment_2< CGAL::Cartesian<double> >   Segment;

int main()
{
    Point p(0,1), q(2,2);
    Segment s(p,q);

    CGAL::Window_stream W(100,100);
    W.init(0,10,10);
    CGAL::cgalize( W);
    W.display();

    W << CGAL::RED << s << CGAL::BLACK << p << q ;
    W >> s >> p;
    return 0;
}

3D objects can be used as well with the Window_stream. The stream output operator << projects them to the xy-plane. The stream input operator >> sets the z coordinate to zero. To get these operators you have to

#include <CGAL/IO/window_stream_xy_3.h>

12.3   Postscript output

An object of type Postscript_file_stream provides graphical output in PostScript format. Postscript_file_stream is derived from the LEDA class ps_file. Therefore, the functionality of ps_file is available on Postscript_file_stream as well. In addition, the class Postscript_file_stream provides output operators for the classes which are defined in the CGAL kernel. The interface of Postscript_file_stream is very similar to the interface of leda_window. To increase similarity, some functions have been added with respect to ps_file. For further information on ps_file, we refer to the LEDA manual.

The output operator to Postscript_file_stream is defined for all geometric classes in the two-dimensional CGAL kernel. There are no input operators of course.

It is important that the postscript file stream header file gets included after the inclusion of the header files of geometric classes that get inserted to the postscript stream file. See the following example program.

#include <CGAL/Cartesian.h>
#include <CGAL/Segment_2.h>
#include <CGAL/IO/Postscript_file_stream.h>

typedef CGAL::Point_2< CGAL::Cartesian<double> >     Point;
typedef CGAL::Segment_2< CGAL::Cartesian<double> >   Segment;

int main()
{
    Point p(0,1), q(2,2);
    Segment s(p,q);

    CGAL::Postscript_file_stream PS(100,100);
    PS.init(0,10,0);
    CGAL::cgalize( PS);
    PS.display();

    PS << CGAL::RED << s << CGAL::BLACK << p << q ;
    return 0;
}