-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestpa3.cpp
352 lines (297 loc) · 9.34 KB
/
testpa3.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
/**
* @file main.cpp
* @description basic test cases for TripleTree
* CPSC 221 PA3
*
* You may add your own tests to this file
*
* THIS FILE WILL NOT BE SUBMITTED
*/
#define IMAGE_1 "green-1x1"
#define IMAGE_2 "rgb-3x1"
#define IMAGE_3 "mix-3x3"
#define IMAGE_4 "mix-2x5"
#define IMAGE_5 "pruneto16leaves-8x5"
#define IMAGE_6 "malachi-60x87"
// Added by Jamen:
#define IMAGE_7 "custom4x3" // Note!! WITHOUT the .png extension
#define MAX_IMG_NUM 9
#define IMAGE_8 "meow"
#define IMAGE_9 "beep"
#include <iostream>
#include <string>
#include "tripletree.h"
using namespace std;
/**********************************/
/*** TEST FUNCTION DECLARATIONS ***/
/**********************************/
void TestBuildRender(int image_num);
void TestFlipHorizontal(int image_num);
void TestRotateCCW(int image_num);
void TestPrune(double tol);
// You should probably write tests for your copy constructor / operator=
// and tests which combine flip/rotate/prune
/***********************************/
/*** MAIN FUNCTION PROGRAM ENTRY ***/
/***********************************/
int main(int argc, char* argv[]) {
// provide one command-line argument as a number in the range of [1, 6] to specify the test image used
int image_number = 6; // default image number
// set image_number from first command-line argument
if (argc > 1)
image_number = atoi(argv[1]);
// clamp image_number to allowable range (change these if you add your own images)
if (image_number < 1)
image_number = 1;
if (image_number > MAX_IMG_NUM) // updated by Jamen
image_number = 6;
TestBuildRender(image_number);
TestFlipHorizontal(image_number);
TestRotateCCW(image_number);
TestPrune(0.1);
return 0;
}
/*************************************/
/*** TEST FUNCTION IMPLEMENTATIONS ***/
/*************************************/
void TestBuildRender(int image_num) {
cout << "Entered TestBuildRender" << endl;
// read input PNG
string input_path = "images-original/";
string output_path = "images-output/";
switch (image_num) {
case 1:
input_path = input_path + IMAGE_1 + ".png";
output_path = output_path + IMAGE_1 + "-render.png";
break;
case 2:
input_path = input_path + IMAGE_2 + ".png";
output_path = output_path + IMAGE_2 + "-render.png";
break;
case 3:
input_path = input_path + IMAGE_3 + ".png";
output_path = output_path + IMAGE_3 + "-render.png";
break;
case 4:
input_path = input_path + IMAGE_4 + ".png";
output_path = output_path + IMAGE_4 + "-render.png";
break;
case 5:
input_path = input_path + IMAGE_5 + ".png";
output_path = output_path + IMAGE_5 + "-render.png";
break;
case 6:
input_path = input_path + IMAGE_6 + ".png";
output_path = output_path + IMAGE_6 + "-render.png";
break;
case 7: // Added by Jamen
input_path = input_path + IMAGE_7 + ".png";
output_path = output_path + IMAGE_7 + "-render.png";
break;
case 8: // Added by Jamen
input_path = input_path + IMAGE_8 + ".png";
output_path = output_path + IMAGE_8 + "-render.png";
break;
case 9: // Added by Jamen
input_path = input_path + IMAGE_9 + ".png";
output_path = output_path + IMAGE_9 + "-render.png";
break;
default:
input_path = input_path + IMAGE_6 + ".png";
output_path = output_path + IMAGE_6 + "-render.png";
break;
}
PNG input;
input.readFromFile(input_path);
cout << "Input image: " << input_path << endl; // Added by Jamen
cout << "Constructing TripleTree from image... ";
TripleTree t(input);
cout << "done." << endl;
cout << "Rendering tree to PNG... ";
PNG output = t.Render();
cout << "done." << endl;
// write output PNG
cout << "Writing rendered PNG to file... ";
output.writeToFile(output_path);
cout << "done." << endl;
cout << "Exiting TestBuildRender.\n" << endl;
}
void TestFlipHorizontal(int image_num) {
cout << "Entered TestFlipHorizontal" << endl;
// read input PNG
string input_path = "images-original/";
string output_path = "images-output/";
switch (image_num) {
case 1:
input_path = input_path + IMAGE_1 + ".png";
output_path = output_path + IMAGE_1;
break;
case 2:
input_path = input_path + IMAGE_2 + ".png";
output_path = output_path + IMAGE_2;
break;
case 3:
input_path = input_path + IMAGE_3 + ".png";
output_path = output_path + IMAGE_3;
break;
case 4:
input_path = input_path + IMAGE_4 + ".png";
output_path = output_path + IMAGE_4;
break;
case 5:
input_path = input_path + IMAGE_5 + ".png";
output_path = output_path + IMAGE_5;
break;
case 6:
input_path = input_path + IMAGE_6 + ".png";
output_path = output_path + IMAGE_6;
break;
case 8:
input_path = input_path + IMAGE_8 + ".png";
output_path = output_path + IMAGE_8;
break;
case 9:
input_path = input_path + IMAGE_9 + ".png";
output_path = output_path + IMAGE_9;
break;
default:
input_path = input_path + IMAGE_6 + ".png";
output_path = output_path + IMAGE_6;
break;
}
PNG input;
input.readFromFile(input_path);
cout << "Constructing TripleTree from image... ";
TripleTree t(input);
cout << "done." << endl;
cout << "Calling FlipHorizontal... ";
t.FlipHorizontal();
cout << "done." << endl;
cout << "Rendering tree to PNG... ";
PNG output = t.Render();
cout << "done." << endl;
// write output PNG
cout << "Writing rendered PNG to file... ";
output.writeToFile(output_path + "-fh-render.png");
cout << "done." << endl;
cout << "Calling FlipHorizontal a second time... ";
t.FlipHorizontal();
cout << "done." << endl;
cout << "Rendering tree to PNG... ";
output = t.Render();
cout << "done." << endl;
// write output PNG
cout << "Writing rendered PNG to file... ";
output.writeToFile(output_path + "-fh_x2-render.png");
cout << "done." << endl;
cout << "Exiting TestFlipHorizontal.\n" << endl;
}
void TestRotateCCW(int image_num) {
cout << "Entered TestRotateCCW" << endl;
// read input PNG
string input_path = "images-original/";
string output_path = "images-output/";
switch (image_num) {
case 1:
input_path = input_path + IMAGE_1 + ".png";
output_path = output_path + IMAGE_1;
break;
case 2:
input_path = input_path + IMAGE_2 + ".png";
output_path = output_path + IMAGE_2;
break;
case 3:
input_path = input_path + IMAGE_3 + ".png";
output_path = output_path + IMAGE_3;
break;
case 4:
input_path = input_path + IMAGE_4 + ".png";
output_path = output_path + IMAGE_4;
break;
case 5:
input_path = input_path + IMAGE_5 + ".png";
output_path = output_path + IMAGE_5;
break;
case 6:
input_path = input_path + IMAGE_6 + ".png";
output_path = output_path + IMAGE_6;
break;
case 7:
input_path = input_path + IMAGE_7 + ".png";
output_path = output_path + IMAGE_7;
break;
default:
input_path = input_path + IMAGE_6 + ".png";
output_path = output_path + IMAGE_6;
break;
}
PNG input;
input.readFromFile(input_path);
cout << "Constructing TripleTree from image... ";
TripleTree t(input);
cout << "done." << endl;
cout << "Calling RotateCCW... ";
t.RotateCCW();
cout << "done." << endl;
cout << "Rendering tree to PNG... ";
PNG output = t.Render();
cout << "done." << endl;
// write output PNG
cout << "Writing rendered PNG to file... ";
output.writeToFile(output_path + "-rccw_x1-render.png");
cout << "done." << endl;
cout << "Calling RotateCCW a second time... ";
t.RotateCCW();
cout << "done." << endl;
cout << "Rendering tree to PNG... ";
output = t.Render();
cout << "done." << endl;
// write output PNG
cout << "Writing rendered PNG to file... ";
output.writeToFile(output_path + "-rccw_x2-render.png");
cout << "done." << endl;
cout << "Calling RotateCCW a third time... ";
t.RotateCCW();
cout << "done." << endl;
cout << "Rendering tree to PNG... ";
output = t.Render();
cout << "done." << endl;
// write output PNG
cout << "Writing rendered PNG to file... ";
output.writeToFile(output_path + "-rccw_x3-render.png");
cout << "done." << endl;
cout << "Calling RotateCCW a fourth time... ";
t.RotateCCW();
cout << "done." << endl;
cout << "Rendering tree to PNG... ";
output = t.Render();
cout << "done." << endl;
// write output PNG
cout << "Writing rendered PNG to file... ";
output.writeToFile(output_path + "-rccw_x4-render.png");
cout << "done." << endl;
cout << "Exiting TestRotateCCW.\n" << endl;
}
void TestPrune(double tol) {
cout << "Entered TestPrune, tolerance: " << tol << endl;
// read input PNG
PNG input;
input.readFromFile("images-original/pruneto16leaves-8x5.png");
cout << "Constructing TripleTree from image... ";
TripleTree t(input);
cout << "done." << endl;
cout << "Tree contains " << t.NumLeaves() << " leaves." << endl;
cout << "Calling Prune... ";
t.Prune(tol);
cout << "done." << endl;
cout << "Pruned tree contains " << t.NumLeaves() << " leaves." << endl;
cout << "Rendering tree to PNG... ";
PNG output = t.Render();
cout << "done." << endl;
// write output PNG
string output_path = "images-output/pruneto16leaves-8x5-prune_" + to_string(tol) + "-render.png";
cout << "Writing rendered PNG to file... ";
output.writeToFile(output_path);
cout << "done." << endl;
cout << "Exiting TestPrune.\n" << endl;
}