@@ -29,26 +29,26 @@ int main(int argc, char **argv) {
29
29
printf ("Welcome to Rasterizer 3000.\n" );
30
30
printf ("===========================\n\n" );
31
31
32
- Extents extents = { 0.0 , 5.0 , 5.0 , 0.0 , 1.0 } ;
32
+ Config config ;
33
33
34
34
int rows , //9175,
35
35
cols , //6814,
36
36
i ,
37
37
j ;
38
38
39
- calcImageSize (& extents , & rows , & cols );
39
+ calcImageSize (& config , & rows , & cols );
40
40
41
41
Index index ;
42
42
index .nodes = malloc (rows * cols * sizeof (PointNode * ));
43
- index .extents = & extents ;
43
+ index .config = & config ;
44
44
index .rows = rows ;
45
45
index .cols = cols ;
46
46
47
47
Image image ;
48
48
image .pixels = malloc (rows * cols * sizeof (float ));
49
49
image .rows = rows ;
50
50
image .cols = cols ;
51
- image .extents = & extents ;
51
+ image .config = & config ;
52
52
53
53
// Initialize arrays
54
54
for (j = 0 ; j < rows ; j ++ ) {
@@ -72,6 +72,41 @@ int main(int argc, char **argv) {
72
72
return 0 ;
73
73
}
74
74
75
+ int readConfig (char * filename , Config * config ) {
76
+ printf ("Reading config from file: %s\n\n" , filename );
77
+ FILE * file = fopen (filename , "r" );
78
+ float rx ,ry ,rz ;
79
+ int n = 0 ;
80
+
81
+ if ( fscanf (file , "lu_long=%d" , & (config -> lu_long )) != 1 ) {
82
+ printf ("Could not read lu_long from config." );
83
+ return 1 ;
84
+ }
85
+ if ( fscanf (file , "lu_lat=%d" , & (config -> lu_lat )) != 1 ) {
86
+ printf ("Could not read lu_lat from config." );
87
+ return 1 ;
88
+ }
89
+ if ( fscanf (file , "rl_long=%d" , & (config -> rl_long )) != 1 ) {
90
+ printf ("Could not read rl_long from config." );
91
+ return 1 ;
92
+ }
93
+ if ( fscanf (file , "rl_lat=%d" , & (config -> rl_lat )) != 1 ) {
94
+ printf ("Could not read rl_lat from config." );
95
+ return 1 ;
96
+ }
97
+ if ( fscanf (file , "gsd=%d" , & (config -> gsd )) != 1 ) {
98
+ printf ("Could not read gsd from config." );
99
+ return 1 ;
100
+ }
101
+
102
+ fclose (file );
103
+
104
+ printf ("\nDone reading config.\n" , n );
105
+ printf (END_SECT );
106
+
107
+ return 0 ;
108
+ }
109
+
75
110
// float valueUsingKNN(Index *index, int *row, int *col) {
76
111
// int k = 5; // k-max
77
112
// int k_used = 0;
@@ -99,7 +134,7 @@ Point3D* useNearest(Index *index, Point3D *pixel_rep) {
99
134
d = 1 ,
100
135
row , col ;
101
136
102
- point2Index (index -> extents , pixel_rep , & row , & col );
137
+ point2Index (index -> config , pixel_rep , & row , & col );
103
138
104
139
int minj = MAX (0 , row - d ),
105
140
maxj = MIN (row + d , index -> rows - 1 ),
@@ -153,20 +188,20 @@ void rasterize(Index *index, Image *image) {
153
188
printf (END_SECT );
154
189
}
155
190
156
- void calcImageSize (Extents * extents , int * rows , int * cols ) {
157
- assert (extents -> lu_long < extents -> rl_long && "Longitudes switched." );
158
- assert (extents -> lu_lat > extents -> rl_lat && "Latitudes switched." );
191
+ void calcImageSize (Config * config , int * rows , int * cols ) {
192
+ assert (config -> lu_long < config -> rl_long && "Longitudes switched." );
193
+ assert (config -> lu_lat > config -> rl_lat && "Latitudes switched." );
159
194
160
195
printf ("Calculating image size ...\n" );
161
- printf (" Image extents: left upper corner %6.2f %6.2f\n" , extents -> lu_long , extents -> lu_lat );
162
- printf (" right lower corner %6.2f %6.2f\n" , extents -> rl_long , extents -> rl_lat );
163
- printf (" GSD: %6.2f metres.\n\n" , extents -> gsd );
196
+ printf (" Image extents: left upper corner %6.2f %6.2f\n" , config -> lu_long , config -> lu_lat );
197
+ printf (" right lower corner %6.2f %6.2f\n" , config -> rl_long , config -> rl_lat );
198
+ printf (" GSD: %6.2f metres.\n\n" , config -> gsd );
164
199
165
- double hor = extents -> rl_long - extents -> lu_long ;
166
- double ver = extents -> lu_lat - extents -> rl_lat ;
200
+ double hor = config -> rl_long - config -> lu_long ;
201
+ double ver = config -> lu_lat - config -> rl_lat ;
167
202
168
- * rows = floor (hor / extents -> gsd );
169
- * cols = floor (ver / extents -> gsd );
203
+ * rows = floor (hor / config -> gsd );
204
+ * cols = floor (ver / config -> gsd );
170
205
171
206
printf (" Horizontal extent: %6.2f metres => %d cols.\n" , hor , * cols );
172
207
printf (" Vertical extent: %6.2f metres => %d rows.\n" , ver , * rows );
@@ -251,7 +286,7 @@ void readPointsFromFile(char *filename, Index *index) {
251
286
252
287
void addPointToIndex (Index * index , Point3D * point ) {
253
288
int col ,row ;
254
- point2Index (index -> extents , point , & row , & col );
289
+ point2Index (index -> config , point , & row , & col );
255
290
assert (row < (index -> rows ) && col < (index -> cols ) && "col,row < cols,rows" );
256
291
PointNode * * binstart = (index -> nodes )+ (row * index -> cols )+ col ;
257
292
addToBin (binstart , point );
@@ -276,19 +311,19 @@ void addToBin(PointNode **current, Point3D* point) {
276
311
}
277
312
}
278
313
279
- void point2Index (Extents * extents , Point3D * p , int * row , int * col ) {
280
- * row = floor ((p -> x - extents -> lu_long ) / extents -> gsd );
281
- * col = floor ((p -> y - extents -> rl_lat ) / extents -> gsd );
314
+ void point2Index (Config * config , Point3D * p , int * row , int * col ) {
315
+ * row = floor ((p -> x - config -> lu_long ) / config -> gsd );
316
+ * col = floor ((p -> y - config -> rl_lat ) / config -> gsd );
282
317
assert (* row >= 0 && * col >= 0 && "Row number positive." );
283
318
// printf(" Point x=%4.2f y=%4.2f z=%4.2f -> row=%d col=%d.\n", p->x, p->y, p->z, *row, *col);
284
319
}
285
320
286
321
void pixel2Point (Image * image , int * row , int * col , Point3D * point ) {
287
322
float col_rel = (float )* col / image -> cols ;
288
323
float row_rel = (float )* row / image -> rows ;
289
- Extents * extents = image -> extents ;
290
- point -> x = extents -> lu_long + (extents -> rl_long - extents -> lu_long )* col_rel ;
291
- point -> y = extents -> lu_lat + (extents -> rl_lat - extents -> lu_lat )* row_rel ;
324
+ Config * config = image -> config ;
325
+ point -> x = config -> lu_long + (config -> rl_long - config -> lu_long )* col_rel ;
326
+ point -> y = config -> lu_lat + (config -> rl_lat - config -> lu_lat )* row_rel ;
292
327
point -> z = EMPTY_VAL ;
293
328
printf ("pixel2Point: col=%d row=%d -> x=%f y=%f\n" , * col , * row , point -> x , point -> y );
294
329
}
0 commit comments