27 static int get_bool(
const char *);
28 static void pr_winerr(
int,
const char *);
29 static void edge_sort(
float sides[4]);
30 static int read_old_format(
struct G_3dview *, FILE *);
32 static const int vers_major = 4;
33 static const int vers_minor = 1;
35 static int Suppress_warn = 0;
50 Suppress_warn = b ? 0 : 1;
82 strcpy(v->
bg_col,
"black");
176 G_warning(
_(
"Unable to open %s for writing"), fname);
180 fprintf(fp,
"# %01d.%02d\n", vers_major, vers_minor);
181 fprintf(fp,
"PGM_ID: %s\n", View->
pgm_id);
184 fprintf(fp,
"north: %f\n", Win->
north);
185 fprintf(fp,
"south: %f\n", Win->
south);
186 fprintf(fp,
"east: %f\n", Win->
east);
187 fprintf(fp,
"west: %f\n", Win->
west);
188 fprintf(fp,
"rows: %d\n", Win->
rows);
189 fprintf(fp,
"cols: %d\n", Win->
cols);
192 fprintf(fp,
"north: %f\n", View->
vwin.
north);
193 fprintf(fp,
"south: %f\n", View->
vwin.
south);
194 fprintf(fp,
"east: %f\n", View->
vwin.
east);
195 fprintf(fp,
"west: %f\n", View->
vwin.
west);
196 fprintf(fp,
"rows: %d\n", View->
vwin.
rows);
197 fprintf(fp,
"cols: %d\n", View->
vwin.
cols);
200 fprintf(fp,
"TO_EASTING: %f\n", View->
from_to[1][0]);
201 fprintf(fp,
"TO_NORTHING: %f\n", View->
from_to[1][1]);
202 fprintf(fp,
"TO_HEIGHT: %f\n", View->
from_to[1][2]);
203 fprintf(fp,
"FROM_EASTING: %f\n", View->
from_to[0][0]);
204 fprintf(fp,
"FROM_NORTHING: %f\n", View->
from_to[0][1]);
205 fprintf(fp,
"FROM_HEIGHT: %f\n", View->
from_to[0][2]);
206 fprintf(fp,
"Z_EXAG: %f\n", View->
exag);
207 fprintf(fp,
"TWIST: %f\n", View->
twist);
208 fprintf(fp,
"FIELD_VIEW: %f\n", View->
fov);
209 fprintf(fp,
"MESH_FREQ: %d\n", View->
mesh_freq);
210 fprintf(fp,
"POLY_RES: %d\n", View->
poly_freq);
211 fprintf(fp,
"DOAVG: %d\n", View->
doavg);
213 fprintf(fp,
"DOZERO: %d\n", View->
dozero);
215 fprintf(fp,
"COLORGRID: %d\n", View->
colorgrid);
216 fprintf(fp,
"SHADING: %d\n", View->
shading);
217 fprintf(fp,
"FRINGE: %d\n", View->
fringe);
218 fprintf(fp,
"BG_COL: %s\n", View->
bg_col);
219 fprintf(fp,
"GRID_COL: %s\n", View->
grid_col);
220 fprintf(fp,
"OTHER_COL: %s\n", View->
other_col);
221 fprintf(fp,
"SURFACEONLY: %d\n", View->
surfonly);
222 fprintf(fp,
"LIGHTS_ON: %d\n", View->
lightson);
223 fprintf(fp,
"LIGHTPOS: %f %f %f %f\n", View->
lightpos[0],
227 fprintf(fp,
"LIGHTAMBIENT: %f\n", View->
ambient);
228 fprintf(fp,
"SHINE: %f\n", View->
shine);
255 char buffer[80], keystring[24], boo[8], nbuf[128], ebuf[128];
256 int lap, v_maj, v_min, wind_keys = 0, reqkeys = 0;
260 if (mapset !=
NULL) {
262 G_warning(
_(
"Unable to open %s for reading"), fname);
269 if (
NULL != fgets(buffer, 80, fp)) {
270 if (buffer[0] !=
'#') {
272 if (0 <= read_old_format(View, fp))
278 sscanf(buffer,
"#%d.%d\n", &v_maj, &v_min);
279 if (v_maj == vers_major && v_min == vers_minor)
284 while (
NULL != fgets(buffer, 75, fp)) {
285 if (buffer[0] !=
'#') {
287 sscanf(buffer,
"%[^:]:", keystring);
289 if (!strcmp(keystring,
"PGM_ID")) {
290 sscanf(buffer,
"%*s%s", (View->
pgm_id));
293 if (!strcmp(keystring,
"north")) {
294 sscanf(buffer,
"%*s%lf", &(View->
vwin.
north));
298 if (!strcmp(keystring,
"south")) {
299 sscanf(buffer,
"%*s%lf", &(View->
vwin.
south));
303 if (!strcmp(keystring,
"east")) {
304 sscanf(buffer,
"%*s%lf", &(View->
vwin.
east));
308 if (!strcmp(keystring,
"west")) {
309 sscanf(buffer,
"%*s%lf", &(View->
vwin.
west));
313 if (!strcmp(keystring,
"rows")) {
314 sscanf(buffer,
"%*s%d", &(View->
vwin.
rows));
318 if (!strcmp(keystring,
"cols")) {
319 sscanf(buffer,
"%*s%d", &(View->
vwin.
cols));
323 if (!strcmp(keystring,
"TO_EASTING")) {
324 sscanf(buffer,
"%*s%f", &(View->
from_to[1][0]));
328 if (!strcmp(keystring,
"TO_NORTHING")) {
329 sscanf(buffer,
"%*s%f", &(View->
from_to[1][1]));
333 if (!strcmp(keystring,
"TO_HEIGHT")) {
334 sscanf(buffer,
"%*s%f", &(View->
from_to[1][2]));
338 if (!strcmp(keystring,
"FROM_EASTING")) {
339 sscanf(buffer,
"%*s%f", &(View->
from_to[0][0]));
343 if (!strcmp(keystring,
"FROM_NORTHING")) {
344 sscanf(buffer,
"%*s%f", &(View->
from_to[0][1]));
348 if (!strcmp(keystring,
"FROM_HEIGHT")) {
349 sscanf(buffer,
"%*s%f", &(View->
from_to[0][2]));
353 if (!strcmp(keystring,
"Z_EXAG")) {
354 sscanf(buffer,
"%*s%f", &(View->
exag));
358 if (!strcmp(keystring,
"MESH_FREQ")) {
359 sscanf(buffer,
"%*s%d", &(View->
mesh_freq));
362 if (!strcmp(keystring,
"POLY_RES")) {
363 sscanf(buffer,
"%*s%d", &(View->
poly_freq));
366 if (!strcmp(keystring,
"DOAVG")) {
367 sscanf(buffer,
"%*s%d", &(View->
doavg));
370 if (!strcmp(keystring,
"FIELD_VIEW")) {
371 sscanf(buffer,
"%*s%f", &(View->
fov));
375 if (!strcmp(keystring,
"TWIST")) {
376 sscanf(buffer,
"%*s%f", &(View->
twist));
379 if (!strcmp(keystring,
"DISPLAY_TYPE")) {
383 if (!strcmp(keystring,
"DOZERO")) {
384 sscanf(buffer,
"%*s%s", boo);
385 View->
dozero = get_bool(boo);
388 if (!strcmp(keystring,
"COLORGRID")) {
389 sscanf(buffer,
"%*s%s", boo);
393 if (!strcmp(keystring,
"FRINGE")) {
394 sscanf(buffer,
"%*s%s", boo);
395 View->
fringe = get_bool(boo);
398 if (!strcmp(keystring,
"SHADING")) {
399 sscanf(buffer,
"%*s%s", boo);
403 if (!strcmp(keystring,
"BG_COL")) {
404 sscanf(buffer,
"%*s%s", View->
bg_col);
407 if (!strcmp(keystring,
"GRID_COL")) {
408 sscanf(buffer,
"%*s%s", View->
grid_col);
411 if (!strcmp(keystring,
"OTHER_COL")) {
412 sscanf(buffer,
"%*s%s", View->
other_col);
415 if (!strcmp(keystring,
"SURFACEONLY")) {
416 sscanf(buffer,
"%*s%s", boo);
420 if (!strcmp(keystring,
"LIGHTS_ON")) {
421 sscanf(buffer,
"%*s%s", boo);
425 if (!strcmp(keystring,
"LIGHTPOS")) {
426 sscanf(buffer,
"%*s%f%f%f%f", &(View->
lightpos[0]),
431 if (!strcmp(keystring,
"LIGHTCOL")) {
432 sscanf(buffer,
"%*s%f%f%f", &(View->
lightcol[0]),
436 if (!strcmp(keystring,
"LIGHTAMBIENT")) {
437 sscanf(buffer,
"%*s%f", &(View->
ambient));
440 if (!strcmp(keystring,
"SHINE")) {
441 sscanf(buffer,
"%*s%f", &(View->
shine));
453 if (wind_keys == 6) {
462 if (!Suppress_warn) {
463 if (95 > (lap = compare_wind(&(View->
vwin), &curwin))) {
465 fprintf(stderr,
_(
"GRASS window when view was saved:\n"));
467 fprintf(stderr,
"north: %s\n", nbuf);
469 fprintf(stderr,
"south: %s\n", nbuf);
471 fprintf(stderr,
"east: %s\n", ebuf);
473 fprintf(stderr,
"west: %s\n", ebuf);
474 pr_winerr(lap, fname);
479 G_warning(
_(
"Unable to open %s for reading"), fname);
492 static int compare_wind(
const struct Cell_head *savedwin,
495 float e_ings[4], n_ings[4], area_lap, area_saved;
509 e_ings[0] = savedwin->
west;
510 e_ings[1] = savedwin->
east;
511 e_ings[2] = curwin->
west;
512 e_ings[3] = curwin->
east;
515 n_ings[0] = savedwin->
south;
516 n_ings[1] = savedwin->
north;
517 n_ings[2] = curwin->
south;
518 n_ings[3] = curwin->
north;
521 area_lap = (e_ings[2] - e_ings[1]) * (n_ings[2] - n_ings[1]);
522 area_saved = (savedwin->
east - savedwin->
west) *
525 return ((
int)(area_lap * 100.0 / area_saved));
529 static int get_bool(
const char *str)
531 if (str[0] ==
'y' || str[0] ==
'Y')
533 if (str[0] ==
'n' || str[0] ==
'N')
536 return (atoi(str) ? 1 : 0);
540 static void pr_winerr(
int vis,
541 const char *viewname)
545 G_warning(
_(
" Window saved in \"%s\" is completely outside of current GRASS window."),
549 G_warning(
_(
" Only %d%% of window saved in \"%s\" overlaps with current GRASS window."),
558 static void edge_sort(
float sides[4])
563 for (i = 0; i < 4; ++i) {
564 for (j = i + 1; j < 4; ++j) {
565 if (sides[j] < sides[i]) {
575 static int read_old_format(
struct G_3dview *v, FILE * fp)
582 strcpy((v->
pgm_id),
"d.3d");
583 if (1 == sscanf(fgets(buffer, 80, fp),
"%f", &(v->
from_to[1][0])))
585 if (1 == sscanf(fgets(buffer, 80, fp),
"%f", &(v->
from_to[1][1])))
587 if (1 == sscanf(fgets(buffer, 80, fp),
"%f", &(v->
from_to[1][2])))
589 if (1 == sscanf(fgets(buffer, 80, fp),
"%f", &(v->
from_to[0][0])))
591 if (1 == sscanf(fgets(buffer, 80, fp),
"%f", &(v->
from_to[0][1])))
593 if (1 == sscanf(fgets(buffer, 80, fp),
"%f", &(v->
from_to[0][2])))
595 if (1 == sscanf(fgets(buffer, 80, fp),
"%f", &(v->
exag)))
597 sscanf(fgets(buffer, 80, fp),
"%d", &(v->
mesh_freq));
598 if (1 == sscanf(fgets(buffer, 80, fp),
"%f", &(v->
fov)))
600 if (1 == sscanf(fgets(buffer, 80, fp),
"%lf", &td)) {
606 sscanf(fgets(buffer, 80, fp),
"%s", boo);
608 sscanf(fgets(buffer, 80, fp),
"%s", boo);
609 v->
dozero = get_bool(boo);
610 sscanf(fgets(buffer, 80, fp),
"%s", v->
grid_col);
614 sscanf(fgets(buffer, 80, fp),
"%s", v->
other_col);
615 sscanf(fgets(buffer, 80, fp),
"%s", v->
bg_col);
616 sscanf(fgets(buffer, 80, fp),
"%s", boo);
617 v->
doavg = get_bool(boo);
const char * G_find_file2(const char *, const char *, const char *)
Searches for a file from the mapset search list or in a specified mapset. (look but don't touch) ...
2D/3D raster map header (used also for region)
double west
Extent coordinates (west)
int G_projection(void)
Query cartographic projection.
int G_get_3dview_defaults(struct G_3dview *v, struct Cell_head *w)
Sets default for v based on w.
int format
Max number of bytes per raster data value minus 1 (raster header only)
int G_put_3dview(const char *fname, const char *mapset, const struct G_3dview *View, const struct Cell_head *Win)
Saves info to a 3d.view file.
void G_format_northing(double, char *, int)
Northing to ASCII.
void G_format_easting(double, char *, int)
Easting to ASCII.
int compressed
Compression mode (raster header only)
double north
Extent coordinates (north)
FILE * G_fopen_new(const char *, const char *)
Open a new database file.
double south
Extent coordinates (south)
void G_3dview_warning(int b)
Turns 3D View warnings on and off.
int zone
Projection zone (UTM)
FILE * G_fopen_old(const char *, const char *, const char *)
Open a database file for reading.
void G_get_set_window(struct Cell_head *)
Get the current working window (region)
int G_get_3dview(const char *fname, const char *mapset, struct G_3dview *View)
Gets a 3D View.
int cols
Number of columns for 2D data.
double ns_res
Resolution - north to south cell size for 2D data.
void G_warning(const char *,...) __attribute__((format(printf
double east
Extent coordinates (east)
double ew_res
Resolution - east to west cell size for 2D data.
int rows
Number of rows for 2D data.