| Bsoft 2.0.5 Bernard's software package

ps_views.cpp
Go to the documentation of this file.
1
9 #include "ps_views.h"
10 #include "ps_plot.h"
11 #include "linked_list.h"
12 #include "utilities.h"
13
14 // Declaration of global variables
15 extern int verbose; // Level of output to the screen
16
17 // Internal function prototypes
18
34 int ps_views(Bstring& filename, Bstring& symmetry_string, View* view, int flags)
35 {
36 if ( verbose & VERB_LABEL )
37 cout << "Writing postscript file: " << filename << endl << endl;
38
39 ofstream* fps = ps_open_and_init(filename, symmetry_string, 1, 600, 800);
40
41 *fps << "/Helvetica-Bold findfont 20 scalefont setfont" << endl;
42 *fps << "40 740 moveto (" << filename << ") show" << endl;
43
44 ps_views(fps, symmetry_string, view, flags);
45
46 ps_close(fps);
47
48 return 0;
49 }
50
51 int ps_views(ofstream* fps, Bstring& symmetry_string, View* view, int flags)
52 {
53 if ( verbose & VERB_DEBUG )
54 cout << "DEBUG ps_views: symmetry=" << symmetry_string << " flags=" << flags << endl;
55
56 int i, m, left(50), bottom(150), width(500), height(500), order(1);
57 View* v;
58
59 int h(100);
60 int ix, iy, nx(2*h+1), ny(2*h+1), sx(h), sy(h);
61 double isx(1.0L/sx), isy(1.0L/sy);
62 float snr(0.1);
63 float* count = NULL;
64
65 long n = count_list((char *) view);
66 double textscale(0.06), textoffset(0.02);
67 if ( n > 50 ) textscale = 3.0/n;
68 if ( textscale < 5 ) textscale = 5;
69 textoffset = textscale/3;
70
71 if ( flags == 2 ) {
72 count = new float[nx*ny];
73 for ( i=0; i<nx*ny; i++ ) count[i] = 0;
74 for ( v = view, n=m=0; v; v = v->next ) {
75 ix = (int) (v->x()*sx + sx);
76 iy = (int) (v->y()*sy + sy);
77 i = iy*nx+ix;
78 count[i]++;
79 if ( m < count[i] ) m = (int) count[i];
80 n++;
81 }
82 snr = 1/sqrt((double)m);
83 if ( snr < 0.1 ) snr = 0.1;
84 }
85
86 *fps << "%%%%Page: Views 1" << endl;
87 *fps << "/Helvetica-Bold findfont 14 scalefont setfont" << endl;
88 *fps << "40 720 moveto (Symmetry: " << symmetry_string << ") show" << endl;
89 *fps << "40 700 moveto (Number of views: " << n << ") show" << endl;
90 *fps << "/Left " << left << " def\n/Bottom " << bottom << " def\n/Height " << height << " def\n/Width " << width << " def" << endl;
91 *fps << "/Scale 200 def" << endl;
92
93 *fps << "/View [" << endl;
94 if ( flags == 2 ) {
95 *fps << "%x y count weight" << endl;
96 for ( i=iy=0; iy<ny; iy++ )
97 for ( ix=0; ix<nx; ix++, i++ )
98 if ( count[i] ) *fps << ix*isx - 1 << " " << iy*isy - 1 << " " << count[i] << " " << 1/(1+1/(snr*sqrt(count[i]))) << endl;
99 delete[] count;
100 } else {
101 *fps << "%x y z a" << endl;
102 for ( v = view; v; v = v->next )
103 *fps << v->x() << " " << v->y() << " " << v->z() << " " << v->angle() << endl;
104 }
105 *fps << "] def" << endl;
106
107 *fps << "/Geom { newpath " << endl;
108 *fps << " 1 0 moveto 0 0 1 0 360 arc stroke" << endl;
109 if ( symmetry_string[0] == 'T' ) {
110 *fps << " 0 0 moveto 1 0 lineto" << endl;
111 *fps << " -0.577 0.577 moveto 0.577 -0.577 lineto stroke" << endl;
112 *fps << " -0.577 -0.577 moveto 0.577 0.577 lineto stroke" << endl;
113 *fps << " 0 1 moveto 0 0.39 0.61 90 162 arc stroke" << endl;
114 *fps << " -0.577 0.577 moveto -0.39 0 0.61 108 180 arc stroke" << endl;
115 *fps << " 1 0 moveto 0.39 0 0.61 0 72 arc stroke" << endl;
116 *fps << " 0.577 0.577 moveto 0 0.39 0.61 18 90 arc stroke" << endl;
117 *fps << " 0 -1 moveto 0 -0.39 0.61 -90 -18 arc stroke" << endl;
118 *fps << " 0.577 -0.577 moveto 0.39 0 0.61 -72 0 arc stroke" << endl;
119 *fps << " -1 0 moveto -0.39 0 0.61 180 252 arc stroke" << endl;
120 *fps << " -0.577 -0.577 moveto 0 -0.39 0.61 198 270 arc stroke" << endl;
121 } else if ( symmetry_string[0] == 'O' ) {
122 *fps << " -1 0 moveto 1 0 lineto" << endl;
123 *fps << " 0 -1 moveto 0 1 lineto" << endl;
124 *fps << " 0 0 moveto 0.707 0.707 lineto stroke" << endl;
125 *fps << " 0 0 moveto 0.707 -0.707 lineto stroke" << endl;
126 *fps << " -0.577 0.577 moveto -0.707 0.707 lineto stroke" << endl;
127 *fps << " -0.577 -0.577 moveto -0.707 -0.707 lineto stroke" << endl;
128 *fps << " 0.577 -0.577 moveto -0.637 0 1.344 -25.4 25.4 arc stroke" << endl;
129 *fps << " 0.577 0.577 moveto 0 -0.637 1.344 64.6 115.4 arc stroke" << endl;
130 *fps << " -0.577 0.577 moveto 0.637 0 1.344 154.6 205.4 arc stroke" << endl;
131 *fps << " -0.577 -0.577 moveto 0 0.637 1.344 -115.4 -64.6 arc stroke" << endl;
132 } else if ( symmetry_string[0] == 'I' ) {
133 if ( symmetry_string.contains("I90") ) {
134 *fps << "-0.526 0 moveto 0.526 0 lineto" << endl;
135 *fps << "0 -0.357 lineto -0.526 0 lineto 0 0.357 lineto 0.526 0 lineto" << endl;
136 *fps << "0 0.357 moveto 0 -0.357 lineto" << endl;
137 *fps << "-0.851 -0.526 moveto" << endl;
138 *fps << "-0.526 0 lineto" << endl;
139 *fps << "0 -0.851 lineto" << endl;
140 *fps << "-0.851 -0.526 lineto" << endl;
141 *fps << "-0.851 0.526 lineto" << endl;
142 *fps << "0 0.851 lineto" << endl;
143 *fps << "-0.526 0 lineto" << endl;
144 *fps << "-0.851 0.526 lineto" << endl;
145 *fps << "0.851 -0.526 moveto" << endl;
146 *fps << "0.526 0 lineto" << endl;
147 *fps << "0 -0.851 lineto" << endl;
148 *fps << "0.851 -0.526 lineto" << endl;
149 *fps << "0.851 0.526 lineto" << endl;
150 *fps << "0 0.851 lineto" << endl;
151 *fps << "0.526 0 lineto" << endl;
152 *fps << "0.851 0.526 lineto" << endl;
153 } else {
154 *fps << "0 0 moveto 0.357 0 lineto" << endl;
155 *fps << "0 0.526 lineto 0 -0.526 lineto 0.357 0 lineto" << endl;
156 *fps << "-0.526 -0.851 moveto" << endl;
157 *fps << "0 -0.526 lineto" << endl;
158 *fps << "-0.851 0 lineto" << endl;
159 *fps << "-0.526 -0.851 lineto" << endl;
160 *fps << "0.526 -0.851 lineto" << endl;
161 *fps << "0.851 0 lineto" << endl;
162 *fps << "0 -0.526 lineto" << endl;
163 *fps << "0.526 -0.851 lineto" << endl;
164 *fps << "-0.526 0.851 moveto" << endl;
165 *fps << "0 0.526 lineto" << endl;
166 *fps << "-0.851 0 lineto" << endl;
167 *fps << "-0.526 0.851 lineto" << endl;
168 *fps << "0.526 0.851 lineto" << endl;
169 *fps << "0.851 0 lineto" << endl;
170 *fps << "0 0.526 lineto" << endl;
171 *fps << "0.526 0.851 lineto" << endl;
172 }
173 } else {
174 sscanf(&symmetry_string[1], "%d", &order);
175 *fps << " 0 0 moveto 1 0 lineto" << endl;
176 for ( i=0; i<order; i++ )
177 *fps << " 0 0 moveto " << cos((i+0.5)*M_PI*2.0/order) << " "
178 << sin((i+0.5)*M_PI*2.0/order) << " lineto stroke" << endl;
179 }
180 *fps << " closepath } def" << endl;
181
182 *fps << "gsave" << endl;
183 *fps << " Width 2 div Left add Height 2 div Bottom add translate" << endl;
184 *fps << " Scale Scale scale" << endl;
185 *fps << " 0.005 setlinewidth Geom stroke" << endl;
186 *fps << " /Helvetica findfont " << textscale << " scalefont setfont" << endl;
187 if ( flags == 2 ) {
188 *fps << " 0 0.1 1 {" << endl;
189 *fps << " /f exch def" << endl;
190 *fps << " 0 4 View length 4 sub {" << endl;
191 *fps << " /Index exch def" << endl;
192 *fps << " /x View Index get def" << endl;
193 *fps << " /y View Index 1 add get def" << endl;
194 *fps << " /v View Index 3 add get def" << endl;
195 *fps << " v f ge {" << endl;
196 *fps << " 1 v sub setgray" << endl;
197 *fps << " x y 0.01 0 360 arc fill" << endl;
198 *fps << " } if" << endl;
199 *fps << " } for stroke" << endl;
200 *fps << " } for" << endl;
201 } else {
202 *fps << " /n 0 def" << endl;
203 *fps << " 0 4 View length 4 sub {" << endl;
204 *fps << " /Index exch def" << endl;
205 *fps << " /x View Index get def" << endl;
206 *fps << " /y View Index 1 add get def" << endl;
207 *fps << " /z View Index 2 add get def" << endl;
208 *fps << " z 0 lt { x y 0.02 0 360 arc stroke }" << endl;
209 *fps << " { x y 0.01 0 360 arc fill } ifelse" << endl;
210 if ( flags == 1 ) {
211 *fps << " /n n 1 add def" << endl;
212 *fps << " x y moveto " << textoffset << " " << textoffset <<
213 " rmoveto n cvi (xxxx) cvs show stroke" << endl;
214 }
215 *fps << " } for stroke" << endl;
216 }
217 *fps << "grestore" << endl;
218 *fps << "showpage" << endl;
219
220 return 0;
221 }
222
236 int ps_views(Bstring& filename, View* view)
237 {
238 int i(1), left(50), bottom(200), width(500), height(250);
239 float x, y;
240 Euler euler;
241
242 View* v;
243 if ( !view ) return -1;
244
245 Bstring title("Views");
246 ofstream* fps = ps_open_and_init(filename, title, 1, 600, 800);
247
248 *fps << "%%Page: " << i << " " << i << endl;
249 *fps << "/Helvetica findfont 12 scalefont setfont" << endl;
250 *fps << "50 755 moveto (Views: " << filename << ") show" << endl;
251 *fps << "/Data [" << endl << "%x y" << endl;
252 for ( v = view; v; v = v->next ) {
253 euler = Euler(*v);
254 x = euler.phi()*fabs(sin(euler.theta())) + M_PI;
255 y = euler.theta();
256 *fps << x << " " << y << endl;
257 }
258 *fps << "] def" << endl;
259
260 ps_phi_theta_plot(fps, left, bottom, width, height, 2);
261
262 *fps << "showpage" << endl;
263
264 ps_close(fps);
265
266 return 0;
267 }
268
279 int ps_sets_of_views(Bstring& filename, Bstring& title, int nv, View* views, int ns, double* fom)
280 {
281 int i, j, k, left(50), bottom(200), width(500), height(250);
282 float x, y, vx, vy;
283 double fmax;
284 View* v;
285 Euler euler;
286
287 ofstream* fps = ps_open_and_init(filename, title, ns, 600, 800);
288
289 for ( i=1, k=0; i<=ns; i++ ) {
290 *fps << "%%Page: " << i << " " << i << endl;
291 *fps << "/Helvetica findfont 12 scalefont setfont" << endl;
292 *fps << "50 755 moveto (" << title << ": " << i << ") show" << endl;
293 *fps << "/Data [" << endl << "%x y fom" << endl;
294 for ( j=0, v=views, fmax=0; j<nv && v; j++, k++, v = v->next ) {
295 euler = Euler(*v);
296 x = euler.phi()*fabs(sin(euler.theta())) + M_PI;
297 y = euler.theta();
298 *fps << x << " " << y << " " << fom[k] << endl;
299 // if ( j == i-1 ) {
300 if ( fmax < fom[k] ) {
301 fmax = fom[k];
302 vx = x;
303 vy = y;
304 }
305 }
306 *fps << "] def" << endl;
307 *fps << "/Best [" << vx << " " << vy << "] def" << endl;
308 ps_phi_theta_plot(fps, left, bottom, width, height, 3);
309 *fps << "showpage" << endl;
310 }
311
312 ps_close(fps);
313
314 return 0;
315 }
316
334 int ps_phi_theta_plot(ofstream* fps, int left, int bottom, int width, int height, int ncol)
335 {
336 double x, y, scale(width*1.0/TWOPI);
337 double phi, theta;
338
339 *fps << "/Scale " << scale << " def" << endl;
340 *fps << "/Height " << height << " def" << endl << "/Width " << width << " def" << endl;
341 *fps << "/Frame { newpath 0 0 moveto Width 0 lineto Width Height lineto 0 Height lineto closepath } def" << endl;
342
343 *fps << left+width/2-10 << " " << bottom-30 << " moveto (Phi) show" << endl;
344 *fps << left-30 << " " << bottom+height/2-20 << " moveto gsave 90 rotate (Theta) show grestore" << endl;
345
346 *fps << "gsave" << endl;
347 *fps << " " << left << " " << bottom << " translate" << endl;
348 *fps << " Frame stroke" << endl;
349 // *fps << " Frame clip" << endl;
350 *fps << " Scale Scale scale" << endl;
351 *fps << " " << 1/scale << " setlinewidth" << endl;
352 *fps << " 0.5 setgray" << endl;
353 *fps << " 0 " << M_PI_2 << " moveto " << TWOPI << " " << M_PI_2 << " lineto" << endl;
354 for ( phi = -M_PI; phi < M_PI+0.01; phi += M_PI/3.0 ) {
355 *fps << " " << M_PI << " 0 moveto" << endl;
356 for ( theta = 0; theta < M_PI+0.01; theta += M_PI/90.0 ) {
357 x = phi * fabs(sin(theta)) + M_PI;
358 y = theta;
359 *fps << " " << x << " " << y << " lineto" << endl;
360 }
361 }
362 *fps << " stroke" << endl;
363 *fps << " /Helvetica findfont 64 scalefont setfont" << endl;
364 *fps << " 0 setgray" << endl;
365 *fps << " 0 " << ncol << " Data length " << ncol << " sub { " << endl;
366 *fps << " /Index exch def" << endl;
367 *fps << " /x Data Index get def" << endl;
368 *fps << " /y Data Index 1 add get def" << endl;
369 *fps << " /f Data Index 2 add get def" << endl;
370 *fps << " 1 f sub setgray" << endl;
371 *fps << " x y 0.03 0 360 arc fill" << endl;
372 *fps << " } for" << endl;
373 *fps << " 0 setgray" << endl;
374 *fps << " //userdict /Best known {" << endl;
375 *fps << " /x Best 0 get def" << endl;
376 *fps << " /y Best 1 get def" << endl;
377 *fps << " x y 0.05 0 360 arc stroke" << endl;
378 *fps << " } if" << endl;
379 *fps << "grestore" << endl;
380
381 ps_scale(fps, left, bottom, left+width, bottom, -180, 180, 60, 10, M_PI_2, 0, 12, 0);
382
383 ps_scale(fps, left, bottom, left, bottom+height, 0, 180, 30, 10, 0, 0, 12, 0);
384
385 return 0;
386 }
387
M_PI_2
#define M_PI_2
Definition: utilities.h:62
Euler
Definition: Euler.h:28
View::next
View * next
Definition: View.h:28
utilities.h
Header file for general utilities.
VERB_DEBUG
#define VERB_DEBUG
Definition: utilities.h:112
View::z
double z()
Definition: View.h:94
count_list
long count_list(char *list)
Counts the number of items in a linked list.
Definition: linked_list.cpp:235
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
View::y
double y()
Definition: View.h:93
ps_sets_of_views
int ps_sets_of_views(Bstring &filename, Bstring &title, int nv, View *views, int ns, double *fom)
Postscript plot of the distribution of sets of views.
Definition: ps_views.cpp:279
ps_phi_theta_plot
int ps_phi_theta_plot(ofstream *fps, int left, int bottom, int width, int height, int ncol)
Generates postscript plot of projected phi and theta.
Definition: ps_views.cpp:334
verbose
int verbose
Bstring::contains
bool contains(const Bstring &s)
Definition: Bstring.cpp:584
M_PI
#define M_PI
Definition: utilities.h:59
linked_list.h
Header file for generalized linked list functions.
Euler::phi
double phi()
Definition: Euler.h:58
Euler::theta
double theta()
Definition: Euler.h:57
Bstring
Definition: Bstring.h:29
ps_plot.h
Header file for postscript output functions.
ps_views
int ps_views(Bstring &filename, Bstring &symmetry_string, View *view, int flags)
Generates postscript plot of views on the unit sphere.
Definition: ps_views.cpp:34
View::angle
double angle()
Definition: View.h:95
View
Definition: View.h:26
ps_close
int ps_close(ofstream *fps)
Closes a postscript file.
Definition: ps_plot.cpp:104
ps_scale
int ps_scale(ofstream *fps, double x1, double y1, double x2, double y2, double min, double max, double increment, double tick_length, double tick_angle, int digits, int fontsize, int inverse)
Generates a scale for a postscript graph.
Definition: ps_plot.cpp:487
ps_views.h
Header file for postscript tools dealing with views.
View::x
double x()
Definition: View.h:92
VERB_LABEL
#define VERB_LABEL
Definition: utilities.h:106
TWOPI
#define TWOPI
Definition: utilities.h:68