mirror of https://github.com/CGAL/cgal
342 lines
9.1 KiB
C++
342 lines
9.1 KiB
C++
// Copyright (c) 1999 Utrecht University (The Netherlands),
|
|
// ETH Zurich (Switzerland), Freie Universitaet Berlin (Germany),
|
|
// INRIA Sophia-Antipolis (France), Martin-Luther-University Halle-Wittenberg
|
|
// (Germany), Max-Planck-Institute Saarbruecken (Germany), RISC Linz (Austria),
|
|
// and Tel-Aviv University (Israel). All rights reserved.
|
|
//
|
|
// This file is part of CGAL (www.cgal.org); you can redistribute it and/or
|
|
// modify it under the terms of the GNU Lesser General Public License as
|
|
// published by the Free Software Foundation; version 2.1 of the License.
|
|
// See the file LICENSE.LGPL distributed with CGAL.
|
|
//
|
|
// Licensees holding a valid commercial license may use this file in
|
|
// accordance with the commercial license agreement provided with the software.
|
|
//
|
|
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
|
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|
//
|
|
// $URL$
|
|
// $Id$
|
|
//
|
|
//
|
|
// Author(s) : Stefan Schirra
|
|
|
|
|
|
#ifndef CGAL_POSTSCRIPT_FILE_STREAM_H
|
|
#define CGAL_POSTSCRIPT_FILE_STREAM_H
|
|
|
|
#include <CGAL/LEDA_basic.h>
|
|
#include <CGAL/IO/Color.h>
|
|
|
|
#ifdef LEDA_PS_FILE_H
|
|
# if CGAL_LEDA_VERSION < 500
|
|
# error Internal CGAL error: <LEDA/ps_file.h> should not have been included yet
|
|
# else
|
|
# error Internal CGAL error: <LEDA/graphics/ps_file.h> should not have been included yet
|
|
# endif
|
|
#endif
|
|
|
|
#if (CGAL_LEDA_VERSION < 500)
|
|
# include <LEDA/list.h>
|
|
# include <LEDA/string.h>
|
|
# include <LEDA/stream.h>
|
|
# include <LEDA/point.h>
|
|
# include <LEDA/segment.h>
|
|
# include <LEDA/line.h>
|
|
# include <LEDA/circle.h>
|
|
# include <LEDA/polygon.h>
|
|
# include <LEDA/color.h>
|
|
# include <LEDA/window.h>
|
|
#else
|
|
# include <LEDA/core/list.h>
|
|
# include <LEDA/core/string.h>
|
|
# include <LEDA/system/stream.h>
|
|
# include <LEDA/geo/point.h>
|
|
# include <LEDA/geo/segment.h>
|
|
# include <LEDA/geo/line.h>
|
|
# include <LEDA/geo/circle.h>
|
|
# include <LEDA/geo/polygon.h>
|
|
# include <LEDA/graphics/color.h>
|
|
# include <LEDA/graphics/window.h>
|
|
#endif
|
|
|
|
|
|
|
|
#if (CGAL_LEDA_VERSION >= 400)
|
|
#if (CGAL_LEDA_VERSION < 500)
|
|
#include <LEDA/rectangle.h>
|
|
#include <LEDA/rat_window.h>
|
|
#include <LEDA/geo_graph.h>
|
|
#else
|
|
#include <LEDA/geo/rectangle.h>
|
|
#include <LEDA/graphics/rat_window.h>
|
|
#include <LEDA/graphics/geo_graph.h>
|
|
#endif
|
|
#endif // 400
|
|
|
|
#define private protected
|
|
#if CGAL_LEDA_VERSION < 500
|
|
# include <LEDA/ps_file.h>
|
|
#else
|
|
# include <LEDA/graphics/ps_file.h>
|
|
#endif
|
|
#undef private
|
|
|
|
#include <CGAL/IO/cgal_logo.h>
|
|
|
|
CGAL_BEGIN_NAMESPACE
|
|
|
|
typedef CGAL_LEDA_SCOPE::ps_file leda_ps_file;
|
|
|
|
class Postscript_file_stream : public leda_ps_file
|
|
{
|
|
public:
|
|
Postscript_file_stream(double w,double h, leda_string name="CGAL_unnamed.ps")
|
|
: leda_ps_file(w/40.0, h/40.0, name)
|
|
{}
|
|
|
|
Postscript_file_stream(leda_string name="CGAL_unnamed.ps")
|
|
: leda_ps_file( name )
|
|
{ set_draw_bb(false); }
|
|
|
|
void display() {}
|
|
void display(int, int) {}
|
|
int read_mouse(double& , double& ) {return 1;}
|
|
leda_color set_fg_color(leda_color c) { return set_color(c); }
|
|
void set_font(const leda_string& ls) { set_text_font(ls); }
|
|
void change_rgb(const Color&);
|
|
bool is_in_colormode();
|
|
};
|
|
|
|
|
|
inline
|
|
void
|
|
Postscript_file_stream::change_rgb(const Color& c)
|
|
{
|
|
file << double(c.r())/255.0 << " "
|
|
<< double(c.g())/255.0 << " "
|
|
<< double(c.b())/255.0 << " srgb\n";
|
|
}
|
|
|
|
|
|
inline
|
|
bool
|
|
Postscript_file_stream::is_in_colormode()
|
|
{ return (outputmode== CGAL_LEDA_SCOPE::colored_mode); }
|
|
|
|
|
|
inline
|
|
Postscript_file_stream&
|
|
operator<<(Postscript_file_stream& w, const Color& c)
|
|
{
|
|
assert( w.is_in_colormode() );
|
|
w.change_rgb(c);
|
|
return w;
|
|
}
|
|
|
|
|
|
inline
|
|
void
|
|
cgalize(Postscript_file_stream& w)
|
|
{
|
|
w.set_line_width( 1);
|
|
}
|
|
|
|
|
|
inline
|
|
Postscript_file_stream*
|
|
create_demo_postscript_file_stream( float w = 512.0, float h = 512.0,
|
|
const char* str = "CGAL_unnamed.ps",
|
|
double x_extension = 1.0)
|
|
{
|
|
Postscript_file_stream* Wptr = new Postscript_file_stream( w, h, str);
|
|
cgalize( *Wptr);
|
|
double y_extension = x_extension * h / w;
|
|
Wptr->init(-x_extension, x_extension, -y_extension);
|
|
return Wptr;
|
|
}
|
|
|
|
|
|
inline
|
|
Postscript_file_stream*
|
|
create_and_display_demo_postscript_file_stream(float w = 512.0,
|
|
float h = 512.0, const char* str = "CGAL_unnamed.ps",
|
|
double x_extension = 1.0)
|
|
{
|
|
Postscript_file_stream* Wptr = new Postscript_file_stream( w, h, str);
|
|
cgalize( *Wptr);
|
|
double y_extension = x_extension * h / w;
|
|
Wptr->init(-x_extension, x_extension, -y_extension);
|
|
return Wptr;
|
|
}
|
|
|
|
CGAL_END_NAMESPACE
|
|
|
|
#endif // CGAL_POSTSCRIPT_FILE_STREAM_H
|
|
|
|
CGAL_BEGIN_NAMESPACE
|
|
|
|
// Each of the following operators is individually
|
|
// protected against multiple inclusion.
|
|
|
|
#ifdef CGAL_POINT_2_H
|
|
#ifndef CGAL_POSTSCRIPT_FILE_STREAM_POINT_2
|
|
#define CGAL_POSTSCRIPT_FILE_STREAM_POINT_2
|
|
template< class R >
|
|
Postscript_file_stream&
|
|
operator<<(Postscript_file_stream& w, const Point_2<R>& p)
|
|
{
|
|
double x = CGAL::to_double(p.x());
|
|
double y = CGAL::to_double(p.y());
|
|
w.draw_point(x,y);
|
|
|
|
return w;
|
|
}
|
|
|
|
#endif // CGAL_POSTSCRIPT_FILE_STREAM_POINT_2
|
|
#endif // CGAL_POINT_2_H
|
|
|
|
|
|
#ifdef CGAL_SEGMENT_2_H
|
|
#ifndef CGAL_POSTSCRIPT_FILE_STREAM_SEGMENT_2
|
|
#define CGAL_POSTSCRIPT_FILE_STREAM_SEGMENT_2
|
|
template< class R >
|
|
Postscript_file_stream&
|
|
operator<<(Postscript_file_stream& w, const Segment_2<R>& s)
|
|
{
|
|
w.draw_segment(CGAL::to_double(s.source().x()),
|
|
CGAL::to_double(s.source().y()),
|
|
CGAL::to_double(s.target().x()),
|
|
CGAL::to_double(s.target().y()));
|
|
return w;
|
|
}
|
|
|
|
#endif // CGAL_POSTSCRIPT_FILE_STREAM_SEGMENT_2
|
|
#endif // CGAL_SEGMENT_2_H
|
|
|
|
|
|
#ifdef CGAL_LINE_2_H
|
|
#ifndef CGAL_POSTSCRIPT_FILE_STREAM_LINE_2
|
|
#define CGAL_POSTSCRIPT_FILE_STREAM_LINE_2
|
|
|
|
template< class R >
|
|
Postscript_file_stream&
|
|
operator<<(Postscript_file_stream& w, const Line_2<R>& l)
|
|
{
|
|
Point_2<R> p1 = l.point(),
|
|
p2 = p1 + l.direction().vector();
|
|
w.draw_line(CGAL::to_double(p1.x()), CGAL::to_double(p1.y()),
|
|
CGAL::to_double(p2.x()), CGAL::to_double(p2.y()));
|
|
return w;
|
|
}
|
|
|
|
#endif // CGAL_POSTSCRIPT_FILE_STREAM_LINE_2
|
|
#endif //CGAL_LINE_2_H
|
|
|
|
#ifdef CGAL_RAY_2_H
|
|
#ifndef CGAL_POSTSCRIPT_FILE_STREAM_RAY_2
|
|
#define CGAL_POSTSCRIPT_FILE_STREAM_RAY_2
|
|
template< class R >
|
|
Postscript_file_stream&
|
|
operator<<(Postscript_file_stream& w, const Ray_2<R>& r)
|
|
{
|
|
Point_2<R> p = r.point(0);
|
|
Point_2<R> q = r.point(1);
|
|
w.draw_ray(CGAL::to_double(p.x()),
|
|
CGAL::to_double(p.y()),
|
|
CGAL::to_double(q.x()),
|
|
CGAL::to_double(q.y()));
|
|
return w;
|
|
}
|
|
|
|
#endif // CGAL_POSTSCRIPT_FILE_STREAM_RAY_2
|
|
#endif //CGAL_RAY_2_H
|
|
|
|
#ifdef CGAL_TRIANGLE_2_H
|
|
#ifndef CGAL_POSTSCRIPT_FILE_STREAM_TRIANGLE_2
|
|
#define CGAL_POSTSCRIPT_FILE_STREAM_TRIANGLE_2
|
|
template< class R >
|
|
Postscript_file_stream&
|
|
operator<<(Postscript_file_stream& w, const Triangle_2<R>& t)
|
|
{
|
|
double x0 = CGAL::to_double(t.vertex(0).x()),
|
|
y0 = CGAL::to_double(t.vertex(0).y()),
|
|
x1 = CGAL::to_double(t.vertex(1).x()),
|
|
y1 = CGAL::to_double(t.vertex(1).y()),
|
|
x2 = CGAL::to_double(t.vertex(2).x()),
|
|
y2 = CGAL::to_double(t.vertex(2).y());
|
|
w.draw_segment(x0, y0, x1, y1);
|
|
w.draw_segment(x1, y1, x2, y2);
|
|
w.draw_segment(x2, y2, x0, y0);
|
|
return w;
|
|
}
|
|
|
|
#endif // CGAL_POSTSCRIPT_FILE_STREAM_TRIANGLE_2
|
|
#endif // CGAL_TRIANGLE_2_H
|
|
|
|
#ifdef CGAL_CIRCLE_2_H
|
|
#ifndef CGAL_POSTSCRIPT_FILE_STREAM_CIRCLE_2
|
|
#define CGAL_POSTSCRIPT_FILE_STREAM_CIRCLE_2
|
|
template< class R >
|
|
Postscript_file_stream&
|
|
operator<<(Postscript_file_stream& w, const Circle_2<R>& c)
|
|
{
|
|
double cx = CGAL::to_double(c.center().x()),
|
|
cy = CGAL::to_double(c.center().y()),
|
|
r = CGAL::to_double(c.squared_radius());
|
|
w.draw_circle(cx, cy , sqrt(r));
|
|
return w;
|
|
}
|
|
|
|
#endif // CGAL_POSTSCRIPT_FILE_STREAM_CIRCLE_2
|
|
#endif // CGAL_CIRCLE_2_H
|
|
|
|
#ifdef CGAL_ISO_RECTANGLE_2_H
|
|
#ifndef CGAL_POSTSCRIPT_FILE_STREAM_ISO_RECTANGLE_2
|
|
#define CGAL_POSTSCRIPT_FILE_STREAM_ISO_RECTANGLE_2
|
|
template< class R >
|
|
Postscript_file_stream&
|
|
operator<<(Postscript_file_stream& w, const Iso_rectangle_2<R>& r)
|
|
{
|
|
double xmin = CGAL::to_double((r.min()).x()),
|
|
ymin = CGAL::to_double((r.min()).y()),
|
|
xmax = CGAL::to_double((r.max()).x()),
|
|
ymax = CGAL::to_double((r.max()).y());
|
|
w.draw_segment(xmin, ymin, xmax, ymin);
|
|
w.draw_segment(xmax, ymin, xmax, ymax);
|
|
w.draw_segment(xmax, ymax, xmin, ymax);
|
|
w.draw_segment(xmin, ymax, xmin, ymin);
|
|
return w;
|
|
}
|
|
|
|
#endif // CGAL_POSTSCRIPT_FILE_STREAM_ISO_RECTANGLE_2
|
|
#endif // CGAL_ISO_RECTANGLE_2_H
|
|
|
|
#ifdef CGAL_BBOX_2_H
|
|
#ifndef CGAL_POSTSCRIPT_FILE_STREAM_BBOX_2
|
|
#define CGAL_POSTSCRIPT_FILE_STREAM_BBOX_2
|
|
inline
|
|
Postscript_file_stream&
|
|
operator<<(Postscript_file_stream& w, const Bbox_2& b)
|
|
{
|
|
#if (__LEDA__ >= 400)
|
|
leda_line_style style = w.set_line_style(leda_dotted);
|
|
#else
|
|
line_style style = w.set_line_style(leda_dotted);
|
|
#endif // 400
|
|
double xmin = b.xmin(),
|
|
ymin = b.ymin(),
|
|
xmax = b.xmax(),
|
|
ymax = b.ymax();
|
|
w.draw_segment(xmin, ymin, xmax, ymin);
|
|
w.draw_segment(xmax, ymin, xmax, ymax);
|
|
w.draw_segment(xmax, ymax, xmin, ymax);
|
|
w.draw_segment(xmin, ymax, xmin, ymin);
|
|
w.set_line_style(style);
|
|
return w;
|
|
}
|
|
#endif // CGAL_POSTSCRIPT_FILE_STREAM_BBOX_2
|
|
#endif // CGAL_BBOX_2_H
|
|
|
|
CGAL_END_NAMESPACE
|