GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Gs3.c
Go to the documentation of this file.
1 
19 #include <stdlib.h>
20 #include <string.h>
21 
22 #include <grass/gis.h>
23 #include <grass/glocale.h>
24 #include <grass/bitmap.h>
25 
26 #include <grass/gsurf.h>
27 #include <grass/gstypes.h>
28 /* for geoview & geodisplay in 3dview stuff */
29 #include "gsget.h"
30 /* for update_attrange - might be able to move this func now */
31 
35 #define INIT_MINMAX(p, nm, size, min, max, found) \
36  found = 0; \
37  p+=(size-1); \
38  while (size--) \
39  { \
40  if (!BM_GET_BYOFFSET(nm, size)) \
41  { \
42  min = max = *p; \
43  found = 1; \
44  break; \
45  } \
46  p--; \
47  }
48 
52 #define SET_MINMAX(p, nm, size, min, max) \
53  p+=(size-1); \
54  while(size--) \
55  { \
56  if (!BM_GET_BYOFFSET(nm, size)) \
57  { \
58  if (*p < min) \
59  { \
60  min = *p; \
61  } \
62  else if (*p > max) \
63  { \
64  max = *p; \
65  } \
66  } \
67  p--; \
68  }
69 
70 typedef int FILEDESC;
71 
72 #define NO_DATA_COL 0xffffff
73 
84 double Gs_distance(double *from, double *to)
85 {
86  static int first = 1;
87 
88  if (first) {
89  first = 0;
91  }
92 
93  return G_distance(from[0], from[1], to[0], to[1]);
94 }
95 
114 int Gs_loadmap_as_float(struct Cell_head *wind, const char *map_name,
115  float *buff, struct BM *nullmap, int *has_null)
116 {
117  FILEDESC cellfile;
118  const char *map_set;
119  char *nullflags;
120  int offset, row, col;
121 
122  G_debug(3, "Gs_loadmap_as_float(): name=%s", map_name);
123 
124  map_set = G_find_cell2(map_name, "");
125  if (!map_set) {
126  G_warning(_("Raster map <%s> not found"), map_name);
127  return 0;
128  }
129  *has_null = 0;
130 
131  nullflags = G_allocate_null_buf(); /* G_fatal_error */
132  if (!nullflags) {
133  G_fatal_error(_("Unable to allocate memory for a null buffer"));
134  }
135 
136  if ((cellfile = G_open_cell_old(map_name, map_set)) == -1) {
137  G_fatal_error(_("Unable to open raster map <%s>"), map_name);
138  }
139 
140  G_message(_("Loading raster map <%s>..."),
141  G_fully_qualified_name(map_name, map_set));
142 
143  for (row = 0; row < wind->rows; row++) {
144  offset = row * wind->cols;
145  G_get_f_raster_row(cellfile, &(buff[offset]), row);
146  G_get_null_value_row(cellfile, nullflags, row);
147 
148  G_percent(row, wind->rows, 2);
149 
150  for (col = 0; col < wind->cols; col++) {
151  if (nullflags[col] || G_is_f_null_value(buff + offset + col)) {
152  *has_null = 1;
153  BM_set(nullmap, col, row, 1);
154  }
155  /* set nm */
156  }
157  }
158  G_percent(1, 1, 1);
159 
160  G_debug(4, " has_null=%d", *has_null);
161 
162  G_close_cell(cellfile);
163 
164  G_free(nullflags);
165 
166  return (1);
167 }
168 
189 int Gs_loadmap_as_int(struct Cell_head *wind, const char *map_name, int *buff,
190  struct BM *nullmap, int *has_null)
191 {
192  FILEDESC cellfile;
193  const char *map_set;
194  char *nullflags;
195  int offset, row, col;
196 
197  G_debug(3, "Gs_loadmap_as_int");
198 
199  map_set = G_find_cell2(map_name, "");
200  if (!map_set) {
201  G_warning(_("Raster map <%s> not found"), map_name);
202  return 0;
203  }
204  *has_null = 0;
205 
206  nullflags = G_allocate_null_buf(); /* G_fatal_error */
207  if (!nullflags) {
208  G_fatal_error(_("Unable to allocate memory for a null buffer"));
209  }
210 
211  if ((cellfile = G_open_cell_old(map_name, map_set)) == -1) {
212  G_fatal_error(_("Unable to open raster map <%s>"), map_name);
213  }
214 
215  G_message(_("Loading raster map <%s>..."),
216  G_fully_qualified_name(map_name, map_set));
217 
218  for (row = 0; row < wind->rows; row++) {
219  offset = row * wind->cols;
220  G_get_c_raster_row(cellfile, &(buff[offset]), row);
221  G_get_null_value_row(cellfile, nullflags, row);
222 
223  G_percent(row, wind->rows, 2);
224 
225  for (col = 0; col < wind->cols; col++) {
226  if (nullflags[col]) {
227  *has_null = 1;
228  BM_set(nullmap, col, row, 1);
229  }
230 
231  /* set nm */
232  }
233  }
234  G_percent(1, 1, 1);
235 
236  G_close_cell(cellfile);
237 
238  G_free(nullflags);
239 
240  return (1);
241 }
242 
252 int Gs_numtype(const char *filename, int *negflag)
253 {
254  CELL max = 0, min = 0;
255  struct Range range;
256  const char *mapset;
257  int shortbits, charbits, bitplace;
258  static int max_short, max_char;
259  static int first = 1;
260 
261  if (first) {
262  max_short = max_char = 1;
263  shortbits = 8 * sizeof(short);
264 
265  for (bitplace = 1; bitplace < shortbits; ++bitplace) {
266  /*1 bit for sign */
267  max_short *= 2;
268  }
269 
270  max_short -= 1;
271 
272  /* NO bits for sign, using unsigned char */
273  charbits = 8 * sizeof(unsigned char);
274 
275  for (bitplace = 0; bitplace < charbits; ++bitplace) {
276  max_char *= 2;
277  }
278 
279  max_char -= 1;
280 
281  first = 0;
282  }
283 
284  mapset = G_find_cell2(filename, "");
285  if (!mapset) {
286  G_warning(_("Raster map <%s> not found"), filename);
287  return -1;
288  }
289 
290  if (G_raster_map_is_fp(filename, mapset)) {
291  G_debug(3, "Gs_numtype(): fp map detected");
292 
293  return (ATTY_FLOAT);
294  }
295 
296  if (-1 == G_read_range(filename, mapset, &range)) {
297  return (-1);
298  }
299 
300  G_get_range_min_max(&range, &min, &max);
301  *negflag = (min < 0);
302 
303  if (max < max_char && min > 0) {
304  return (ATTY_CHAR);
305  }
306 
307  if (max < max_short && min > -max_short) {
308  return (ATTY_SHORT);
309  }
310 
311  return (ATTY_INT);
312 }
313 
334 int Gs_loadmap_as_short(struct Cell_head *wind, const char *map_name,
335  short *buff, struct BM *nullmap, int *has_null)
336 {
337  FILEDESC cellfile;
338  const char *map_set;
339  char *nullflags;
340  int *ti, *tmp_buf;
341  int offset, row, col, val, max_short, overflow, shortsize, bitplace;
342  short *ts;
343 
344  G_debug(3, "Gs_loadmap_as_short");
345 
346  overflow = 0;
347  shortsize = 8 * sizeof(short);
348 
349  /* 1 bit for sign */
350  /* same as 2 << (shortsize-1) */
351  for (max_short = bitplace = 1; bitplace < shortsize; ++bitplace) {
352  max_short *= 2;
353  }
354 
355  max_short -= 1;
356 
357  map_set = G_find_cell2(map_name, "");
358  if (!map_set) {
359  G_warning(_("Raster map <%s> not found"), map_name);
360  return -1;
361  }
362  *has_null = 0;
363 
364  nullflags = G_allocate_null_buf();
365  if (!nullflags) {
366  G_fatal_error(_("Unable to allocate memory for a null buffer"));
367  }
368 
369  if ((cellfile = G_open_cell_old(map_name, map_set)) == -1) {
370  G_fatal_error(_("Unable to open raster map <%s>"), map_name);
371  }
372 
373  tmp_buf = (int *)G_malloc(wind->cols * sizeof(int)); /* G_fatal_error */
374  if (!tmp_buf) {
375  return -1;
376  }
377 
378  G_message(_("Loading raster map <%s>..."),
379  G_fully_qualified_name(map_name, map_set));
380 
381  for (row = 0; row < wind->rows; row++) {
382  offset = row * wind->cols;
383  G_get_c_raster_row(cellfile, tmp_buf, row);
384  G_get_null_value_row(cellfile, nullflags, row);
385 
386  G_percent(row, wind->rows, 2);
387 
388  ts = &(buff[offset]);
389  ti = tmp_buf;
390 
391  for (col = 0; col < wind->cols; col++) {
392  if (nullflags[col]) {
393  *has_null = 1;
394  BM_set(nullmap, col, row, 1);
395  }
396  else {
397  val = *ti;
398  if (abs(val) > max_short) {
399  overflow = 1;
400  /* assign floor/ceiling value?
401  */
402  *ts = (short)(max_short * val / abs(val));
403  }
404  else {
405  *ts = (short)val;
406  }
407  }
408 
409  ti++;
410  ts++;
411  }
412  }
413  G_percent(1, 1, 1);
414 
415  G_close_cell(cellfile);
416 
417  G_free(tmp_buf);
418  G_free(nullflags);
419 
420  return (overflow ? -2 : 1);
421 }
422 
449 int Gs_loadmap_as_char(struct Cell_head *wind, const char *map_name,
450  unsigned char *buff, struct BM *nullmap, int *has_null)
451 {
452  FILEDESC cellfile;
453  const char *map_set;
454  char *nullflags;
455  int *ti, *tmp_buf;
456  int offset, row, col, val, max_char, overflow, charsize, bitplace;
457  unsigned char *tc;
458 
459  G_debug(3, "Gs_loadmap_as_char");
460 
461  overflow = 0;
462  charsize = 8 * sizeof(unsigned char);
463 
464  /* 0 bits for sign! */
465  max_char = 1;
466 
467  for (bitplace = 0; bitplace < charsize; ++bitplace) {
468  max_char *= 2;
469  }
470 
471  max_char -= 1;
472 
473  map_set = G_find_cell2(map_name, "");
474  if (!map_set) {
475  G_warning(_("Raster map <%s> not found"), map_name);
476  return -1;
477  }
478  *has_null = 0;
479 
480  nullflags = G_allocate_null_buf(); /* G_fatal_error */
481  if (!nullflags) {
482  G_fatal_error(_("Unable to allocate memory for a null buffer"));
483  }
484 
485  if ((cellfile = G_open_cell_old(map_name, map_set)) == -1) {
486  G_fatal_error(_("Unable to open raster map <%s>"), map_name);
487  }
488 
489  tmp_buf = (int *)G_malloc(wind->cols * sizeof(int)); /* G_fatal_error */
490  if (!tmp_buf) {
491  return -1;
492  }
493 
494  G_message(_("Loading raster map <%s>..."),
495  G_fully_qualified_name(map_name, map_set));
496 
497  for (row = 0; row < wind->rows; row++) {
498  offset = row * wind->cols;
499  G_get_c_raster_row(cellfile, tmp_buf, row);
500  G_get_null_value_row(cellfile, nullflags, row);
501  tc = (unsigned char *)&(buff[offset]);
502  ti = tmp_buf;
503 
504  G_percent(row, wind->rows, 2);
505 
506  for (col = 0; col < wind->cols; col++) {
507  if (nullflags[col]) {
508  *has_null = 1;
509  BM_set(nullmap, col, row, 1);
510  }
511  else {
512  val = *ti;
513  if (val > max_char) {
514  overflow = 1;
515  *tc = (unsigned char)max_char;
516  }
517  else if (val < 0) {
518  overflow = 1;
519  *tc = 0;
520  }
521  else {
522  *tc = (unsigned char)val;
523  }
524  }
525 
526  ti++;
527  tc++;
528  }
529  }
530  G_percent(1, 1, 1);
531 
532  G_close_cell(cellfile);
533 
534  G_free(tmp_buf);
535  G_free(nullflags);
536 
537  return (overflow ? -2 : 1);
538 }
539 
559 int Gs_loadmap_as_bitmap(struct Cell_head *wind, const char *map_name,
560  struct BM *buff)
561 {
562  FILEDESC cellfile;
563  const char *map_set;
564  char *nullflags;
565  int *tmp_buf;
566  int row, col;
567 
568  G_debug(3, "Gs_loadmap_as_bitmap");
569 
570  map_set = G_find_cell2(map_name, "");
571  if (!map_set) {
572  G_warning(_("Raster map <%s> not found"), map_name);
573  return -1;
574  }
575 
576  if ((cellfile = G_open_cell_old(map_name, map_set)) == -1) {
577  G_fatal_error(_("Unable to open raster map <%s>"), map_name);
578  }
579 
580  tmp_buf = (int *)G_malloc(wind->cols * sizeof(int)); /* G_fatal_error */
581  if (!tmp_buf) {
582  return -1;
583  }
584 
585  nullflags = G_allocate_null_buf();
586  if (!nullflags) {
587  G_fatal_error(_("Unable to allocate memory for a null buffer"));
588  }
589 
590  G_message(_("Loading raster map <%s>..."),
591  G_fully_qualified_name(map_name, map_set));
592 
593  for (row = 0; row < wind->rows; row++) {
594  G_get_null_value_row(cellfile, nullflags, row);
595 
596  for (col = 0; col < wind->cols; col++) {
597  if (nullflags[col]) {
598  /* no data */
599  BM_set(buff, col, row, 1);
600  }
601  else {
602  BM_set(buff, col, row, 0);
603  }
604  }
605  }
606 
607  G_close_cell(cellfile);
608 
609  G_free(tmp_buf);
610  G_free(nullflags);
611 
612  return (1);
613 }
614 
627 int Gs_build_256lookup(const char *filename, int *buff)
628 {
629  const char *mapset;
630  struct Colors colrules;
631  CELL min, max, cats[256];
632  int i;
633  unsigned char r[256], g[256], b[256], set[256];
634 
635  G_debug(3, "building color table");
636 
637  mapset = G_find_cell2(filename, "");
638  if (!mapset) {
639  G_warning(_("Raster map <%s> not found"), filename);
640  return 0;
641  }
642 
643  G_read_colors(filename, mapset, &colrules);
644  G_get_color_range(&min, &max, &colrules);
645 
646  if (min < 0 || max > 255) {
647  G_warning(_("Color table range doesn't match data (mincol=%d, maxcol=%d"),
648  min, max);
649 
650  min = min < 0 ? 0 : min;
651  max = max > 255 ? 255 : max;
652  }
653 
654  G_zero(cats, 256 * sizeof(CELL));
655 
656  for (i = min; i <= max; i++) {
657  cats[i] = i;
658  }
659 
660  G_lookup_colors(cats, r, g, b, set, 256, &colrules);
661 
662  for (i = 0; i < 256; i++) {
663 
664  if (set[i]) {
665  buff[i] =
666  (r[i] & 0xff) | ((g[i] & 0xff) << 8) | ((b[i] & 0xff) << 16);
667  }
668  else {
669  buff[i] = NO_DATA_COL;
670  }
671  }
672 
673  return (1);
674 }
675 
687 void Gs_pack_colors(const char *filename, int *buff, int rows, int cols)
688 {
689  const char *mapset;
690  struct Colors colrules;
691  unsigned char *r, *g, *b, *set;
692  int *cur, i, j;
693 
694  mapset = G_find_cell2(filename, "");
695  if (!mapset) {
696  G_warning(_("Raster map <%s> not found"), filename);
697  return;
698  }
699 
700  r = (unsigned char *)G_malloc(cols);
701  g = (unsigned char *)G_malloc(cols);
702  b = (unsigned char *)G_malloc(cols);
703  set = (unsigned char *)G_malloc(cols);
704 
705  G_read_colors(filename, mapset, &colrules);
706 
707  cur = buff;
708 
709  G_message(_("Translating colors from raster map <%s>..."),
710  G_fully_qualified_name(filename, mapset));
711 
712  for (i = 0; i < rows; i++) {
713  G_lookup_colors(cur, r, g, b, set, cols, &colrules);
714  G_percent(i, rows, 2);
715 
716  for (j = 0; j < cols; j++) {
717  if (set[j]) {
718  cur[j] =
719  (r[j] & 0xff) | ((g[j] & 0xff) << 8) | ((b[j] & 0xff) <<
720  16);
721  }
722  else {
723  cur[j] = NO_DATA_COL;
724  }
725  }
726 
727  cur = &(cur[cols]);
728  }
729  G_percent(1, 1, 1);
730 
731  G_free_colors(&colrules);
732 
733  G_free(r);
734  G_free(g);
735  G_free(b);
736 
737  G_free(set);
738 
739  return;
740 }
741 
756 void Gs_pack_colors_float(const char *filename, float *fbuf, int *ibuf,
757  int rows, int cols)
758 {
759  const char *mapset;
760  struct Colors colrules;
761  unsigned char *r, *g, *b, *set;
762  int i, j, *icur;
763  FCELL *fcur;
764 
765  mapset = G_find_cell2(filename, "");
766  if (!mapset) {
767  G_warning(_("Raster map <%s> not found"), filename);
768  return;
769  }
770 
771  r = (unsigned char *)G_malloc(cols);
772  g = (unsigned char *)G_malloc(cols);
773  b = (unsigned char *)G_malloc(cols);
774  set = (unsigned char *)G_malloc(cols);
775 
776  G_read_colors(filename, mapset, &colrules);
777 
778  fcur = fbuf;
779  icur = ibuf;
780 
781  G_message(_("Translating colors from raster map <%s>..."),
782  G_fully_qualified_name(filename, mapset));
783 
784  for (i = 0; i < rows; i++) {
785  G_lookup_f_raster_colors(fcur, r, g, b, set, cols, &colrules);
786  G_percent(i, rows, 2);
787 
788  for (j = 0; j < cols; j++) {
789  if (set[j]) {
790  icur[j] =
791  (r[j] & 0xff) | ((g[j] & 0xff) << 8) | ((b[j] & 0xff) <<
792  16);
793  }
794  else {
795  icur[j] = NO_DATA_COL;
796  }
797  }
798 
799  icur = &(icur[cols]);
800  fcur = &(fcur[cols]);
801  }
802  G_percent(1, 1, 1);
803 
804  G_free_colors(&colrules);
805 
806  G_free(r);
807  G_free(g);
808  G_free(b);
809  G_free(set);
810 
811  return;
812 }
813 
827 int Gs_get_cat_label(const char *filename, int drow, int dcol, char *catstr)
828 {
829  struct Categories cats;
830  const char *mapset;
831  CELL *buf;
832  DCELL *dbuf;
833  RASTER_MAP_TYPE map_type;
834  int fd;
835 
836  if ((mapset = G_find_cell2(filename, "")) == NULL) {
837  G_warning(_("Raster map <%s> not found"), filename);
838  return 0;
839  }
840 
841  if (-1 != G_read_cats(filename, mapset, &cats)) {
842  fd = G_open_cell_old(filename, mapset);
843  map_type = G_get_raster_map_type(fd);
844 
845  if (map_type == CELL_TYPE) {
846  buf = G_allocate_c_raster_buf();
847 
848  if (G_get_c_raster_row(fd, buf, drow) < 0) {
849  sprintf(catstr, "error");
850  }
851  else if (G_is_c_null_value(&buf[dcol])) {
852  sprintf(catstr, "(NULL) %s",
853  G_get_c_raster_cat(&buf[dcol], &cats));
854  }
855  else {
856  sprintf(catstr, "(%d) %s", buf[dcol],
857  G_get_c_raster_cat(&buf[dcol], &cats));
858  }
859 
860  G_free(buf);
861  }
862 
863  else {
864  /* fp map */
865  dbuf = G_allocate_d_raster_buf();
866 
867  if (G_get_d_raster_row(fd, dbuf, drow) < 0) {
868  sprintf(catstr, "error");
869  }
870  else if (G_is_d_null_value(&dbuf[dcol])) {
871  sprintf(catstr, "(NULL) %s",
872  G_get_d_raster_cat(&dbuf[dcol], &cats));
873  }
874  else {
875  sprintf(catstr, "(%g) %s", dbuf[dcol],
876  G_get_d_raster_cat(&dbuf[dcol], &cats));
877  }
878 
879  G_free(dbuf);
880  }
881  }
882  else {
883  strcpy(catstr, "no category label");
884  }
885 
886  /* TODO: may want to keep these around for multiple queries */
887  G_free_cats(&cats);
888 
889  G_close_cell(fd);
890 
891  return (1);
892 }
893 
906 int Gs_save_3dview(const char *vname, geoview * gv, geodisplay * gd,
907  struct Cell_head *w, geosurf * defsurf)
908 {
909  const char *mapset;
910  struct G_3dview v;
911  float zmax, zmin;
912 
913  GS_get_zrange(&zmin, &zmax, 0);
914 
915  G_get_3dview_defaults(&v, w);
916  mapset = G_mapset();
917 
918  if (mapset != NULL) {
919  if (defsurf) {
920  if (defsurf->draw_mode & DM_WIRE_POLY) {
921  v.display_type = 3;
922  }
923  else if (defsurf->draw_mode & DM_WIRE ||
924  defsurf->draw_mode & DM_COL_WIRE) {
925  v.display_type = 1;
926  }
927  else if (defsurf->draw_mode & DM_POLY) {
928  v.display_type = 2;
929  }
930 
931  v.mesh_freq = defsurf->x_modw; /* mesh resolution */
932  v.poly_freq = defsurf->x_mod; /* poly resolution */
933  v.dozero = !(defsurf->nz_topo);
934  v.colorgrid = (defsurf->draw_mode & DM_COL_WIRE) ? 1 : 0;
935  v.shading = (defsurf->draw_mode & DM_GOURAUD) ? 1 : 0;
936  }
937 
938  if (gv->infocus) {
939  GS_v3eq(v.from_to[TO], gv->real_to);
940  v.from_to[TO][Z] -= zmin;
941  GS_v3mult(v.from_to[TO], gv->scale);
942  v.from_to[TO][Z] *= gv->vert_exag;
943  }
944  else {
945  GS_v3eq(v.from_to[TO], gv->from_to[TO]);
946  }
947 
948  gsd_model2real(v.from_to[TO]);
949 
950  GS_v3eq(v.from_to[FROM], gv->from_to[FROM]);
951  gsd_model2real(v.from_to[FROM]);
952 
953  v.exag = gv->vert_exag;
954  v.fov = gv->fov / 10.;
955  v.twist = gv->twist;
956  v.fringe = 0; /* not implemented here */
957 
958  v.lightson = 1; /* always true, curently */
959 
960  if (gv->lights[0].position[W] == 1) {
961  /* local */
962  v.lightpos[X] = gv->lights[0].position[X];
963  v.lightpos[Y] = gv->lights[0].position[Y];
964  v.lightpos[Z] = gv->lights[0].position[Z];
965  gsd_model2real(v.lightpos);
966  v.lightpos[W] = 1.0; /* local */
967  }
968  else {
969  v.lightpos[X] = gv->lights[0].position[X];
970  v.lightpos[Y] = gv->lights[0].position[Y];
971  v.lightpos[Z] = gv->lights[0].position[Z];
972  v.lightpos[W] = 0.0; /* inf */
973  }
974 
975  v.lightcol[0] = gv->lights[0].color[0];
976  v.lightcol[1] = gv->lights[0].color[1];
977  v.lightcol[2] = gv->lights[0].color[2];
978 
979  v.ambient = (gv->lights[0].ambient[0] + gv->lights[0].ambient[1] +
980  gv->lights[0].ambient[2]) / 3.;
981  v.shine = gv->lights[0].shine;
982 
983  v.surfonly = 0; /* N/A - now uses constant color */
984  strcpy((v.pgm_id), "Nvision-ALPHA!");
985 
986  return (G_put_3dview(vname, mapset, &v, w));
987  }
988  else {
989  return (-1);
990  }
991 }
992 
1004 int Gs_load_3dview(const char *vname, geoview * gv, geodisplay * gd,
1005  struct Cell_head *w, geosurf * defsurf)
1006 {
1007  const char *mapset;
1008  struct G_3dview v;
1009  int ret = -1;
1010  float pt[3];
1011 
1012  mapset = G_find_file2("3d.view", vname, "");
1013 
1014  if (mapset != NULL) {
1015  ret = G_get_3dview(vname, mapset, &v);
1016  }
1017 
1018  if (ret >= 0) {
1019  if (strcmp((v.pgm_id), "Nvision-ALPHA!")) {
1020  G_warning(_("View not saved by this program,"
1021  "there may be some inconsistancies"));
1022  }
1023 
1024  /* set poly and mesh resolutions */
1025  v.mesh_freq = (int)(v.mesh_freq * v.vwin.ns_res / w->ns_res);
1026  v.poly_freq = (int)(v.poly_freq * v.vwin.ns_res / w->ns_res);
1027 
1028  /* Set To and FROM positions */
1029  /* TO */
1030  pt[0] = (v.from_to[TO][X] - w->west) - w->ew_res / 2.;
1031  pt[1] = (v.from_to[TO][Y] - w->south) - w->ns_res / 2.;
1032  pt[2] = v.from_to[TO][Z];
1033  GS_set_focus(pt);
1034 
1035  /* FROM */
1036  pt[0] = (float)v.from_to[FROM][X];
1037  pt[1] = (float)v.from_to[FROM][Y];
1038  pt[2] = (float)v.from_to[FROM][Z];
1039  GS_moveto_real(pt);
1040 
1041  if (defsurf) {
1042  int dmode = 0;
1043 
1044  GS_setall_drawres(v.poly_freq, v.poly_freq,
1045  v.mesh_freq, v.mesh_freq);
1046 
1047  while (v.display_type >= 10) {
1048  /* globe stuff not used */
1049  v.display_type -= 10;
1050  }
1051 
1052  /* set drawing modes */
1053  if (v.colorgrid) {
1054  dmode |= DM_COL_WIRE;
1055  }
1056 
1057  if (v.shading) {
1058  dmode |= DM_GOURAUD;
1059  }
1060 
1061  switch (v.display_type) {
1062  case 1:
1063  dmode |= DM_WIRE;
1064 
1065  break;
1066  case 2:
1067  dmode |= DM_POLY;
1068 
1069  break;
1070  case 3:
1071  dmode |= DM_WIRE_POLY;
1072 
1073  break;
1074  }
1075  GS_setall_drawmode(dmode);
1076 
1077  /* should also set nozeros here */
1078  }
1079 
1080  /* set exaggeration */
1081  if (v.exag)
1082  GS_set_global_exag(v.exag);
1083 
1084  /* Set FOV */
1085  if (v.fov) {
1086  GS_set_fov((int)
1087  (v.fov > 0 ? v.fov * 10. + 0.5 : v.fov * 10. - 0.5));
1088  }
1089  else {
1090  /* TODO: do ortho */
1091  }
1092 
1093  /* Set twist */
1094  if (v.twist)
1095  GS_set_twist((int)(v.twist > 0 ? v.twist + 0.5 : v.twist - 0.5));
1096 
1097 
1098  /* TODO: OK to here - need to unravel/reverse lights stuff*** */
1099 
1100  if (v.lightson) {
1101  /* Lights are on */
1102 
1103  /* Light Position */
1104  gv->lights[0].position[X] = v.lightpos[X];
1105  gv->lights[0].position[Y] = v.lightpos[Y];
1106  gv->lights[0].position[Z] = v.lightpos[Z];
1107 
1108  /* Light Color */
1109  gv->lights[0].color[0] = v.lightcol[0];
1110  gv->lights[0].color[1] = v.lightcol[1];
1111  gv->lights[0].color[2] = v.lightcol[2];
1112 
1113  /* Light Shininess */
1114  gv->lights[0].shine = v.shine;
1115 
1116  /* Light Ambient */
1117  gv->lights[0].ambient[0] = gv->lights[0].ambient[1] =
1118  gv->lights[0].ambient[2] = v.ambient * 3.;
1119 
1120 
1121  } /* Done with lights */
1122 
1123 
1124  GS_alldraw_wire();
1125 
1126  } /* Done with file */
1127  return (1);
1128 
1129 }
1130 
1140 int Gs_update_attrange(geosurf * gs, int desc)
1141 {
1142  long size;
1143  float min, max;
1144  typbuff *tb;
1145  struct BM *nm;
1146  int found;
1147 
1148  gs->att[desc].max_nz = gs->att[desc].min_nz = gs->att[desc].range_nz =
1149  0.0;
1150 
1151  if (CONST_ATT == gs_get_att_src(gs, desc)) {
1152  gs->att[desc].max_nz = gs->att[desc].min_nz = gs->att[desc].constant;
1153  min = max = gs->att[desc].constant;
1154  gs->att[desc].range_nz = 0.0;
1155  }
1156  else if (CF_COLOR_PACKED & gsds_get_changed(gs->att[desc].hdata)) {
1157  gs->att[desc].max_nz = 0xFFFFFF;
1158  gs->att[desc].min_nz = 0x010101;
1159  gs->att[desc].range_nz = 0xFFFFFF;
1160  }
1161  else {
1162  if (NULL == (tb = gsds_get_typbuff(gs->att[desc].hdata, 0))) {
1163  return (-1);
1164  }
1165 
1166  nm = tb->nm;
1167 
1168  if (tb->ib) {
1169  int *p;
1170 
1171  size = gs->rows * gs->cols;
1172  p = tb->ib;
1173  INIT_MINMAX(p, nm, size, min, max, found);
1174 
1175  if (!found) {
1176  /* all nulls! */
1177  return (-1);
1178  }
1179 
1180  size = gs->rows * gs->cols;
1181  p = tb->ib;
1182  SET_MINMAX(p, nm, size, min, max);
1183  }
1184  else if (tb->sb) {
1185  short *p;
1186 
1187  size = gs->rows * gs->cols;
1188  p = tb->sb;
1189  INIT_MINMAX(p, nm, size, min, max, found);
1190 
1191  if (!found) {
1192  /* all nulls! */
1193  return (-1);
1194  }
1195 
1196  size = gs->rows * gs->cols;
1197  p = tb->sb;
1198  SET_MINMAX(p, nm, size, min, max);
1199  }
1200  else if (tb->cb) {
1201  char *p;
1202 
1203  size = gs->rows * gs->cols;
1204  p = (char *)tb->cb;
1205  INIT_MINMAX(p, nm, size, min, max, found);
1206 
1207  if (!found) {
1208  /* all nulls! */
1209  return (-1);
1210  }
1211 
1212  size = gs->rows * gs->cols;
1213  p = (char *)tb->cb;
1214  SET_MINMAX(p, nm, size, min, max);
1215  }
1216  else if (tb->fb) {
1217  float *p;
1218 
1219  size = gs->rows * gs->cols;
1220  p = tb->fb;
1221  INIT_MINMAX(p, nm, size, min, max, found);
1222 
1223  if (!found) {
1224  /* all nulls! */
1225  return (-1);
1226  }
1227 
1228  size = gs->rows * gs->cols;
1229  p = tb->fb;
1230  SET_MINMAX(p, nm, size, min, max);
1231  }
1232 
1233  gs->att[desc].max_nz = max;
1234  gs->att[desc].min_nz = min;
1235  gs->att[desc].range_nz = gs->att[desc].max_nz - gs->att[desc].min_nz;
1236  }
1237 
1238  if (ATT_TOPO == desc) {
1239  gs->zmin = min;
1240  gs->zmax = max;
1241  gs->zrange = gs->zmax - gs->zmin;
1242  gs->zminmasked = gs->zmin;
1243  gs->zmax_nz = gs->zmax;
1244  gs->zmin_nz = gs->zmin;
1245  gs->zrange_nz = gs->zmax_nz - gs->zmin_nz;
1246  }
1247 
1248  G_debug(3, "Gs_update_attrange(): min=%f max=%f", gs->zmin, gs->zmax);
1249 
1250  return (1);
1251 }
char * G_mapset(void)
current mapset name
Definition: mapset.c:31
int G_is_c_null_value(const CELL *cellVal)
Returns 1 if cell is NULL, 0 otherwise. This will test if the value cell is the largest int...
Definition: null_val.c:244
void GS_set_fov(int fov)
Set field of view.
Definition: GS2.c:2841
#define NO_DATA_COL
Definition: Gs3.c:72
int Gs_build_256lookup(const char *filename, int *buff)
Build color table (256)
Definition: Gs3.c:627
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
int G_get_d_raster_row(int fd, DCELL *buf, int row)
Get raster row (DCELL type)
Definition: gis/get_row.c:965
void G_free(void *buf)
Free allocated memory.
Definition: gis/alloc.c:142
float b
Definition: named_colr.c:8
void GS_set_global_exag(float exag)
Set global z-exag value.
Definition: GS2.c:1974
int Gs_save_3dview(const char *vname, geoview *gv, geodisplay *gd, struct Cell_head *w, geosurf *defsurf)
Save 3dview.
Definition: Gs3.c:906
CELL * G_allocate_c_raster_buf(void)
Allocates memory for a raster map of type CELL.
Definition: alloc_cell.c:96
int G_close_cell(int fd)
close a raster map
Definition: closecell.c:71
int GS_setall_drawmode(int mode)
Set all draw-modes.
Definition: GS2.c:2058
int G_lookup_colors(const CELL *cell, unsigned char *red, unsigned char *grn, unsigned char *blu, unsigned char *set, int n, struct Colors *colors)
lookup an array of colors
Definition: color_look.c:38
int G_begin_distance_calculations(void)
Begin distance calculations.
Definition: gis/distance.c:44
FILE * fd
Definition: g3dcolor.c:368
int G_lookup_f_raster_colors(const FCELL *fcell, unsigned char *red, unsigned char *grn, unsigned char *blu, unsigned char *set, int n, struct Colors *colors)
Converts the n floating-point values in the fcell array to their r,g,b color components. Embedded NULL-values are handled properly as well.
Definition: color_look.c:155
#define min(x, y)
Definition: draw2.c:68
int G_free_colors(struct Colors *colors)
free color structure memory
Definition: color_free.c:17
int G_open_cell_old(const char *name, const char *mapset)
Open an existing integer raster map (cell)
Definition: opencell.c:100
float r
Definition: named_colr.c:8
void GS_set_focus(float *realto)
Set focus.
Definition: GS2.c:2518
RASTER_MAP_TYPE G_get_raster_map_type(int fd)
Determine raster type from descriptor.
Definition: opencell.c:1038
#define Y(x)
Definition: display/draw.c:246
int G_get_f_raster_row(int fd, FCELL *buf, int row)
Get raster row (FCELL type)
Definition: gis/get_row.c:945
int G_get_3dview_defaults(struct G_3dview *v, struct Cell_head *w)
Sets default for v based on w.
Definition: view.c:63
#define X(y)
Definition: display/draw.c:248
int Gs_loadmap_as_bitmap(struct Cell_head *wind, const char *map_name, struct BM *buff)
Load raster map as integer map.
Definition: Gs3.c:559
int Gs_loadmap_as_char(struct Cell_head *wind, const char *map_name, unsigned char *buff, struct BM *nullmap, int *has_null)
Load raster map as integer map.
Definition: Gs3.c:449
typbuff * gsds_get_typbuff(int id, IFLAG change_flag)
Get data buffer.
Definition: gsds.c:281
int G_read_colors(const char *name, const char *mapset, struct Colors *colors)
read map layer color table
Definition: color_read.c:62
#define max(x, y)
Definition: draw2.c:69
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.
Definition: view.c:171
int Gs_update_attrange(geosurf *gs, int desc)
Update no_zero ranges for attribute (actually no_null now)
Definition: Gs3.c:1140
int G_read_range(const char *name, const char *mapset, struct Range *range)
read raster range
Definition: range.c:226
int GS_setall_drawres(int xres, int yres, int xwire, int ywire)
Set all draw resolutions.
Definition: GS2.c:2195
int G_read_cats(const char *name, const char *mapset, struct Categories *pcats)
read raster category file
Definition: gis/cats.c:347
tuple size
value.Bind(wx.EVT_TEXT, self.OnVolumeIsosurfMap)
Definition: tools.py:2334
char * G_allocate_null_buf(void)
Allocates memory for a null buffer.
Definition: alloc_cell.c:141
int G_raster_map_is_fp(const char *name, const char *mapset)
Check if raster map is floating-point.
Definition: opencell.c:969
int GS_get_zrange(float *min, float *max, int doexag)
Get z-extent for all loaded surfaces.
Definition: GS2.c:2687
int G_zero(void *buf, int i)
Zero out a buffer, buf, of length i.
Definition: gis/zero.c:29
int G_percent(long n, long d, int s)
Print percent complete messages.
Definition: percent.c:63
char buff[1024]
Definition: g3dcats.c:89
int G_free_cats(struct Categories *pcats)
free category structure memory
Definition: gis/cats.c:1540
void Gs_pack_colors_float(const char *filename, float *fbuf, int *ibuf, int rows, int cols)
Pack color table (floating-point map)
Definition: Gs3.c:756
int Gs_loadmap_as_int(struct Cell_head *wind, const char *map_name, int *buff, struct BM *nullmap, int *has_null)
Load raster map as integer map.
Definition: Gs3.c:189
#define INIT_MINMAX(p, nm, size, min, max, found)
Used in the function Gs_update_attrange()
Definition: Gs3.c:35
int G_get_range_min_max(const struct Range *range, CELL *min, CELL *max)
get range min and max
Definition: range.c:608
void GS_v3mult(float *v1, float k)
Multiple vectors.
Definition: GS_util.c:229
char * G_find_cell2(const char *name, const char *mapset)
find a raster map (look but don&#39;t touch)
Definition: find_cell.c:83
int Gs_get_cat_label(const char *filename, int drow, int dcol, char *catstr)
Get categories/labels.
Definition: Gs3.c:827
int G_is_d_null_value(const DCELL *dcellVal)
Returns 1 if dcell is NULL, 0 otherwise. This will test if the value dcell is a NaN. Same test as in G_is_f_null_value().
Definition: null_val.c:306
int G_get_c_raster_row(int fd, CELL *buf, int row)
Get raster row (CELL type)
Definition: gis/get_row.c:922
void G_message(const char *msg,...)
Print a message to stderr.
Definition: lib/gis/error.c:74
int G_is_f_null_value(const FCELL *fcellVal)
Returns 1 if fcell is NULL, 0 otherwise. This will test if the value fcell is a NaN. It isn&#39;t good enough to test for a particular NaN bit pattern since the machine code may change this bit pattern to a different NaN. The test will be.
Definition: null_val.c:281
int Gs_loadmap_as_float(struct Cell_head *wind, const char *map_name, float *buff, struct BM *nullmap, int *has_null)
Load raster map as floating point map.
Definition: Gs3.c:114
void Gs_pack_colors(const char *filename, int *buff, int rows, int cols)
Pack color table.
Definition: Gs3.c:687
int gsds_get_changed(int id)
ADD.
Definition: gsds.c:614
int G_get_null_value_row(int fd, char *flags, int row)
Read or simmulate null value row.
Definition: gis/get_row.c:1242
float g
Definition: named_colr.c:8
int
Definition: g3dcolor.c:48
int Gs_load_3dview(const char *vname, geoview *gv, geodisplay *gd, struct Cell_head *w, geosurf *defsurf)
Load 3dview.
Definition: Gs3.c:1004
double Gs_distance(double *from, double *to)
Calculates distance in METERS between two points in current projection (2D)
Definition: Gs3.c:84
int G_get_3dview(const char *fname, const char *mapset, struct G_3dview *View)
Gets a 3D View.
Definition: view.c:252
void gsd_model2real(Point3 point)
Convert model to real coordinates.
Definition: gsd_views.c:393
int first
Definition: form/open.c:25
void GS_alldraw_wire(void)
Draw all wires.
Definition: GS2.c:1916
int Gs_numtype(const char *filename, int *negflag)
Get map data type.
Definition: Gs3.c:252
#define SET_MINMAX(p, nm, size, min, max)
Used in the function Gs_update_attrange()
Definition: Gs3.c:52
char * G_get_d_raster_cat(DCELL *rast, struct Categories *pcats)
given a DCELL value val Returns pointer to a string describing category.
Definition: gis/cats.c:634
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
Definition: g3drange.c:62
void GS_set_twist(int t)
Set viewpoint twist value.
Definition: GS2.c:2875
return NULL
Definition: dbfopen.c:1394
char * G_get_c_raster_cat(CELL *rast, struct Categories *pcats)
given a CELL value val Returns pointer to a string describing category.
Definition: gis/cats.c:600
void GS_v3eq(float *v1, float *v2)
Copy vector values.
Definition: GS_util.c:178
char * G_find_file2(const char *element, const char *name, const char *mapset)
searches for a file from the mapset search list or in a specified mapset. (look but don&#39;t touch) retu...
Definition: find_file.c:191
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
tuple cols
int G_debug(int level, const char *msg,...)
Print debugging message.
Definition: gis/debug.c:51
int gs_get_att_src(geosurf *gs, int desc)
Get attribute source.
Definition: gs.c:656
double G_distance(double e1, double n1, double e2, double n2)
Returns distance in meters.
Definition: gis/distance.c:78
int G_get_color_range(CELL *min, CELL *max, const struct Colors *colors)
Definition: color_range.c:44
int BM_set(struct BM *map, int x, int y, int val)
Sets bitmap value to &#39;val&#39; at location &#39;x&#39; &#39;y&#39;.
Definition: bitmap.c:187
char * G_fully_qualified_name(const char *name, const char *mapset)
fully qualified file name
Definition: nme_in_mps.c:118
#define FROM
Definition: y.tab.c:161
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
int FILEDESC
Definition: Gs3.c:70
int Gs_loadmap_as_short(struct Cell_head *wind, const char *map_name, short *buff, struct BM *nullmap, int *has_null)
Load raster map as integer map.
Definition: Gs3.c:334
void GS_moveto_real(float *pt)
Move position to (real)
Definition: GS2.c:2645
string set
DCELL * G_allocate_d_raster_buf(void)
Allocates memory for a raster map of type DCELL.
Definition: alloc_cell.c:126