| Bsoft 2.0.5 Bernard's software package

ps_tree.cpp
Go to the documentation of this file.
1
9 #include "ps_plot.h"
10 #include "ps_tree.h"
11 #include "utilities.h"
12
13 // Declaration of global variables
14 extern int verbose; // Level of output to the screen
15
28 int ps_draw_tree(Bstring& filename, Bnode* root, float scale)
29 {
30 ofstream* fps = ps_open_and_init(filename, filename, 1, 612, 792);
31
32 if ( verbose & VERB_LABEL )
33 cout << "Writing file: " << filename << endl;
34
35 *fps << "%%%%Page: 1 1" << endl;
36
37 *fps << "/Helvetica findfont 10 scalefont setfont" << endl;
38 *fps << "1 setlinecap\n1 setlinejoin\n2 setlinewidth" << endl;
39
40 ps_draw_node(fps, root, scale, 300, 400);
41
42 *fps << "showpage" << endl;
43
44 ps_close(fps);
45
46 return 0;
47 }
48
63 int ps_draw_node(ofstream* fps, Bnode* node, float scale, float x, float y)
64 {
65 float dx = scale*node->length*cos(node->angle);
66 float dy = scale*node->length*sin(node->angle);
67
68 *fps << x << " " << y << " moveto ";
69 x += dx;
70 y += dy;
71 *fps << x << " " << y << " lineto stroke" << endl;
72
73 if ( node->two ) {
74 ps_draw_node(fps, node->two, scale, x, y);
75 ps_draw_node(fps, node->three, scale, x, y);
76 } else {
77 if ( node->angle < M_PI_2 || node->angle > 3*M_PI_2 )
78 *fps << x + 5 << " " << y << " moveto ";
79 else
80 *fps << x - 5 << " (" << node->label << ") stringwidth pop sub " << y << " moveto ";
81 *fps << "(" << node->label << ") show" << endl;
82 }
83
84 if ( node->length == 0 ) // Third branch of the root node
85 ps_draw_node(fps, node->one, scale, x, y);
86
87 return 0;
88 }
89
90
91
M_PI_2
#define M_PI_2
Definition: utilities.h:62
ps_draw_node
int ps_draw_node(ofstream *fps, Bnode *node, float scale, float x, float y)
Draws a tree node into a postscript file.
Definition: ps_tree.cpp:63
utilities.h
Header file for general utilities.
ps_open_and_init
ofstream * ps_open_and_init(Bstring filename, Bstring title, int npages, int width, int height)
Opens and initializes a postscript file.
Definition: ps_plot.cpp:31
verbose
int verbose
ps_draw_tree
int ps_draw_tree(Bstring &filename, Bnode *root, float scale)
Draws a tree into a postscript file.
Definition: ps_tree.cpp:28
Bnode::two
Bnode * two
Definition: rwtree.h:25
Bnode::label
char label[100]
Definition: rwtree.h:27
Bstring
Definition: Bstring.h:29
ps_plot.h
Header file for postscript output functions.
Bnode::length
float length
Definition: rwtree.h:28
Bnode::angle
float angle
Definition: rwtree.h:29
Bnode::three
Bnode * three
Definition: rwtree.h:25
Bnode
Definition: rwtree.h:24
ps_close
int ps_close(ofstream *fps)
Closes a postscript file.
Definition: ps_plot.cpp:104
Bnode::one
Bnode * one
Definition: rwtree.h:25
VERB_LABEL
#define VERB_LABEL
Definition: utilities.h:106
ps_tree.h
Header file for writing a tree into a postcsript file.