| Bsoft 2.0.5 Bernard's software package

ps_marker.cpp
Go to the documentation of this file.
1
9 #include "ps_marker.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
34 int ps_marker_errors(Bstring& filename, Bmarker* set1, Bmarker* set2,
35 Transform t, Vector3<int> size, float err_scale)
36 {
37 if ( !set1 || !set2 ) {
38 cerr << "Error: The two sets must have the same number of points!" << endl;
39 return -1;
40 }
41
42 int num = 0;
43 double xdev = 0, ydev = 0;
44 Bmarker *m1, *m2;
45 Vector3<float> min = set1->loc;
46 Vector3<float> max = set1->loc;
47
48 //determine the deviation of every point in set2 from its predicted
49 //coordinates using the tranfsform parameters
50 for ( m1=set1, m2=set2; m1; m1=m1->next, m2=m2->next ) {
51 min = min.min(m1->loc);
52 max = max.max(m1->loc);
53 m2->err[0] = t.scale[0]*(m1->loc[0] *cos(t.angle) +
54 m1->loc[1]*sin(t.angle)) + t.trans[0] - m2->loc[0];
55 m2->err[1] = t.scale[1]*(-1* m1->loc[0] *sin(t.angle) +
56 m1->loc[1]*cos(t.angle)) + t.trans[1] - m2->loc[1];
57 xdev += m2->err[0]*m2->err[0];
58 ydev += m2->err[1]*m2->err[1];
59 num++;
60 }
61 xdev = sqrt(xdev/num);
62 ydev = sqrt(ydev/num);
63
64 int w = size[0];
65 int h = size[1];
66 float scale = 650.0/h;
67
68 Bstring title("Matched deviations");
69
70 if ( verbose & VERB_DEBUG )
71 cout << "DEBUG ps_marker_errors: Creating " << filename << " xdev " << xdev << " ydev " << ydev << endl;
72
73 ofstream* fps = ps_open_and_init(filename, title, 1, 600, 800);
74
75 *fps << "/Helvetica-Bold findfont 18 scalefont setfont" << endl;
76 *fps << "40 770 moveto (" << filename << ": Matching deviations) show" << endl;
77 *fps << "/Helvetica-Bold findfont 10 scalefont setfont" << endl;
78 *fps << "40 60 moveto (Shift: " << t.trans[0] << " " << t.trans[1] << ") show" << endl;
79 *fps << "40 45 moveto (Scale: " << t.scale[0] << " " << t.scale[1] << ") show" << endl;
80 *fps << "40 30 moveto (Angle: " << t.angle*180.0/M_PI << ") show" << endl;
81 *fps << "40 15 moveto (Deviation: " << xdev << " " << ydev << " (scaled by " << err_scale << ")) show" << endl;
82 *fps << "/x_Origin 100 def \n/y_Origin 100 def \n/Height " << h << " def \n/Width " << w << " def" << endl;
83 *fps << "/Scale " << scale << " def" << endl;
84 *fps << "/err_scale " << err_scale << " def" << endl;
85 *fps << "/Frame { newpath 0 0 moveto 0 Height lineto Width Height lineto Width 0 lineto closepath } def" << endl;
86
87 *fps << "/Data [" << endl;
88 for ( m2=set2; m2; m2=m2->next )
89 *fps << m2->loc[0] << " " << m2->loc[1] << " " << m2->err[0] << " " << m2->err[1] << endl;
90 *fps << "] def\n" << endl;
91
92 *fps << "300 80 moveto (x axis) show" << endl;
93 *fps << "80 300 moveto gsave 90 rotate (y axis) show grestore" << endl;
94 *fps << "100 80 moveto 0 (xxxxx) cvs show\n 80 100 moveto 0 (xxxxx) cvs show" << endl;
95 *fps << w*scale+80 << " 80 moveto Width (xxxxx) cvs show" << endl;
96 *fps << "60 " << h*scale+100 << " moveto Height (xxxxx) cvs show" << endl;
97 *fps << "x_Origin y_Origin translate\nScale Scale scale" << endl;
98 *fps << "gsave \n\t5 setlinewidth \n\tFrame stroke \n\t1 setlinewidth" << endl;
99 *fps << "\t0 4 Data length 1 sub { \n\t\t/Index exch def" << endl;
100 *fps << "\t\tData Index get Data Index 1 add get err_scale 2 div 0 360 arc fill" << endl;
101 *fps << "\t\tData Index get Data Index 1 add get moveto" << endl;
102 *fps << "\t\tData Index 2 add get err_scale mul Data Index 3 add get err_scale mul rlineto stroke" << endl;
103 *fps << "\t} for \ngrestore" << endl;
104
105 *fps << "showpage" << endl;
106
107 ps_close(fps);
108
109 return 0;
110 }
111
124 int ps_marker_match(Bmarker* set1, Bmarker* set2, Bstring& filename)
125 {
126 if ( !set1 || !set2 ) {
127 cerr << "Error: The two sets must have the same number of points!" << endl;
128 return -1;
129 }
130
131 int num = 0;
132 Bmarker *m1, *m2;
133 Vector3<float> min = set1->loc;
134 Vector3<float> max = set1->loc;
135
136 //determine the deviation of every point in set2 from its predicted
137 //coordinates using the tranfsform parameters
138 for ( m1=set1, m2=set2; m1; m1=m1->next, m2=m2->next ) {
139 min = min.min(m1->loc);
140 max = max.max(m1->loc);
141 num++;
142 }
143
144 int w = (int) (max[0] - min[0]);
145 int h = (int) (max[1] - min[1]);
146
147 float scale = 540.0/w;
148
149 Bstring title("Matched Features");
150 ofstream* fps = ps_open_and_init(filename, title, 1, 600, 800);
151
152 *fps << "/Helvetica-Bold findfont 18 scalefont setfont" << endl;
153 *fps << "40 770 moveto \n(Matched Features) show" << endl;
154 *fps << "/x_Origin 50 def \n/y_Origin 50 def \n/Height " << h << " def \n/Width " << w << " def" << endl;
155 *fps << "/Frame { newpath 0 0 moveto 0 Height lineto Width Height lineto Width 0 lineto closepath } def" << endl;
156 *fps << "/Dot { newpath 0 0 moveto 0 0 5 0 360 arc fill closepath} def" << endl;
157 *fps << "/Ring { newpath 0 0 moveto 0 0 5 0 360 arc stroke closepath} def" << endl;
158 *fps << "/Scale " << scale << " def" << endl;
159
160 *fps << "/Data [" << endl;
161 for ( m1=set1, m2=set2; m1; m1=m1->next, m2=m2->next )
162 *fps << m1->loc[0] << " " << m1->loc[1] << " " << m2->loc[0] << " " << m2->loc[1] << endl;
163 *fps << "] def\n" << endl;
164
165 *fps << "300 20 moveto (x axis) show" << endl;
166 *fps << "30 350 moveto gsave 90 rotate (y axis) show grestore" << endl;
167 *fps << "50 20 moveto 0 (xxxx) cvs show\n 30 50 moveto 0 (xxxx) cvs show" << endl;
168 *fps << w*scale << " 20 moveto " << w << " (xxxx) cvs show" << endl;
169 *fps << "10 " << h*scale << " moveto " << h << " (xxxx) cvs show" << endl;
170 *fps << "x_Origin y_Origin translate\nScale Scale scale" << endl;
171 *fps << "gsave \n\t5 setlinewidth \n\tFrame stroke \n\t1 setlinewidth" << endl;
172 *fps << "\t0 4 Data length 1 sub { \n\t\t/Index exch def" << endl;
173 *fps << "\t\tData Index get Data Index 1 add get moveto" << endl;
174 *fps << "\t\tData Index 2 add get Data Index 3 add get lineto stroke" << endl;
175 *fps << "\t\tgsave \n\t\t\tData Index get Data Index 1 add get translate \n\t\t\tDot stroke" << endl;
176 *fps << "\t\tgrestore" << endl;
177 *fps << "\t\tgsave \n\t\t\tData Index 2 add get Data Index 3 add get translate \n\t\t\tRing stroke" << endl;
178 *fps << "\t\tgrestore \n\t} for \ngrestore" << endl;
179
180 *fps << "showpage" << endl;
181
182 ps_close(fps);
183
184 return 0;
185 }
186
utilities.h
Header file for general utilities.
VERB_DEBUG
#define VERB_DEBUG
Definition: utilities.h:112
Transform::angle
double angle
Definition: Transform.h:29
Bmarker
Definition: marker.h:21
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
ps_marker_match
int ps_marker_match(Bmarker *set1, Bmarker *set2, Bstring &filename)
Output a postscript file that draws a line between matching features in a pair of coordinate sets.
Definition: ps_marker.cpp:124
Vector3::max
Type max()
Definition: Vector3.h:175
Transform
Definition: Transform.h:24
M_PI
#define M_PI
Definition: utilities.h:59
linked_list.h
Header file for generalized linked list functions.
ps_marker_errors
int ps_marker_errors(Bstring &filename, Bmarker *set1, Bmarker *set2, Transform t, Vector3< int > size, float err_scale)
Output a postscript file that graphs the deviations of points in a Bmarker from their predicted locat...
Definition: ps_marker.cpp:34
ps_marker.h
Header file for postscript tools dealing with Bmarkers.
Transform::scale
Vector3< double > scale
Definition: Transform.h:31
verbose
int verbose
Transform::trans
Vector3< double > trans
Definition: Transform.h:30
Bmarker::next
Bmarker * next
Definition: marker.h:22
Bstring
Definition: Bstring.h:29
ps_plot.h
Header file for postscript output functions.
Vector3< int >
Bmarker::err
Vector3< float > err
Definition: marker.h:26
Vector3::min
Type min()
Definition: Vector3.h:169
Bmarker::loc
Vector3< float > loc
Definition: marker.h:25
ps_close
int ps_close(ofstream *fps)
Closes a postscript file.
Definition: ps_plot.cpp:104