22 #include <grass/gis.h>
23 #include <grass/glocale.h>
24 #include <grass/bitmap.h>
26 #include <grass/gsurf.h>
27 #include <grass/gstypes.h>
35 #define INIT_MINMAX(p, nm, size, min, max, found) \
40 if (!BM_GET_BYOFFSET(nm, size)) \
52 #define SET_MINMAX(p, nm, size, min, max) \
56 if (!BM_GET_BYOFFSET(nm, size)) \
72 #define NO_DATA_COL 0xffffff
93 return G_distance(from[0], from[1], to[0], to[1]);
115 float *buff,
struct BM *nullmap,
int *has_null)
120 int offset, row, col;
122 G_debug(3,
"Gs_loadmap_as_float(): name=%s", map_name);
126 G_warning(_(
"Raster map <%s> not found"), map_name);
133 G_fatal_error(_(
"Unable to allocate memory for a null buffer"));
137 G_fatal_error(_(
"Unable to open raster map <%s>"), map_name);
140 G_message(_(
"Loading raster map <%s>..."),
143 for (row = 0; row < wind->rows; row++) {
144 offset = row * wind->cols;
150 for (col = 0; col < wind->cols; col++) {
153 BM_set(nullmap, col, row, 1);
160 G_debug(4,
" has_null=%d", *has_null);
190 struct BM *nullmap,
int *has_null)
195 int offset, row, col;
197 G_debug(3,
"Gs_loadmap_as_int");
201 G_warning(_(
"Raster map <%s> not found"), map_name);
208 G_fatal_error(_(
"Unable to allocate memory for a null buffer"));
212 G_fatal_error(_(
"Unable to open raster map <%s>"), map_name);
215 G_message(_(
"Loading raster map <%s>..."),
218 for (row = 0; row < wind->rows; row++) {
219 offset = row * wind->cols;
225 for (col = 0; col < wind->cols; col++) {
226 if (nullflags[col]) {
228 BM_set(nullmap, col, row, 1);
257 int shortbits, charbits, bitplace;
258 static int max_short, max_char;
259 static int first = 1;
262 max_short = max_char = 1;
263 shortbits = 8 *
sizeof(short);
265 for (bitplace = 1; bitplace < shortbits; ++bitplace) {
273 charbits = 8 *
sizeof(
unsigned char);
275 for (bitplace = 0; bitplace < charbits; ++bitplace) {
286 G_warning(_(
"Raster map <%s> not found"), filename);
291 G_debug(3,
"Gs_numtype(): fp map detected");
301 *negflag = (
min < 0);
303 if (max < max_char && min > 0) {
307 if (max < max_short && min > -max_short) {
335 short *buff,
struct BM *nullmap,
int *has_null)
341 int offset, row, col, val, max_short, overflow, shortsize, bitplace;
344 G_debug(3,
"Gs_loadmap_as_short");
347 shortsize = 8 *
sizeof(short);
351 for (max_short = bitplace = 1; bitplace < shortsize; ++bitplace) {
359 G_warning(_(
"Raster map <%s> not found"), map_name);
366 G_fatal_error(_(
"Unable to allocate memory for a null buffer"));
370 G_fatal_error(_(
"Unable to open raster map <%s>"), map_name);
373 tmp_buf = (
int *)G_malloc(wind->cols *
sizeof(
int));
378 G_message(_(
"Loading raster map <%s>..."),
381 for (row = 0; row < wind->rows; row++) {
382 offset = row * wind->cols;
388 ts = &(buff[offset]);
391 for (col = 0; col < wind->cols; col++) {
392 if (nullflags[col]) {
394 BM_set(nullmap, col, row, 1);
398 if (abs(val) > max_short) {
402 *ts = (short)(max_short * val / abs(val));
420 return (overflow ? -2 : 1);
450 unsigned char *buff,
struct BM *nullmap,
int *has_null)
456 int offset, row, col, val, max_char, overflow, charsize, bitplace;
459 G_debug(3,
"Gs_loadmap_as_char");
462 charsize = 8 *
sizeof(
unsigned char);
467 for (bitplace = 0; bitplace < charsize; ++bitplace) {
475 G_warning(_(
"Raster map <%s> not found"), map_name);
482 G_fatal_error(_(
"Unable to allocate memory for a null buffer"));
486 G_fatal_error(_(
"Unable to open raster map <%s>"), map_name);
489 tmp_buf = (
int *)G_malloc(wind->cols *
sizeof(
int));
494 G_message(_(
"Loading raster map <%s>..."),
497 for (row = 0; row < wind->rows; row++) {
498 offset = row * wind->cols;
501 tc = (
unsigned char *)&(buff[offset]);
506 for (col = 0; col < wind->cols; col++) {
507 if (nullflags[col]) {
509 BM_set(nullmap, col, row, 1);
513 if (val > max_char) {
515 *tc = (
unsigned char)max_char;
522 *tc = (
unsigned char)val;
537 return (overflow ? -2 : 1);
568 G_debug(3,
"Gs_loadmap_as_bitmap");
572 G_warning(_(
"Raster map <%s> not found"), map_name);
577 G_fatal_error(_(
"Unable to open raster map <%s>"), map_name);
580 tmp_buf = (
int *)G_malloc(wind->cols *
sizeof(
int));
587 G_fatal_error(_(
"Unable to allocate memory for a null buffer"));
590 G_message(_(
"Loading raster map <%s>..."),
593 for (row = 0; row < wind->rows; row++) {
596 for (col = 0; col < wind->cols; col++) {
597 if (nullflags[col]) {
599 BM_set(buff, col, row, 1);
602 BM_set(buff, col, row, 0);
630 struct Colors colrules;
633 unsigned char r[256],
g[256],
b[256],
set[256];
635 G_debug(3,
"building color table");
639 G_warning(_(
"Raster map <%s> not found"), filename);
646 if (min < 0 || max > 255) {
647 G_warning(_(
"Color table range doesn't match data (mincol=%d, maxcol=%d"),
650 min = min < 0 ? 0 :
min;
651 max = max > 255 ? 255 :
max;
654 G_zero(cats, 256 *
sizeof(CELL));
656 for (i = min; i <=
max; i++) {
662 for (i = 0; i < 256; i++) {
666 (r[i] & 0xff) | ((g[i] & 0xff) << 8) | ((b[i] & 0xff) << 16);
690 struct Colors colrules;
691 unsigned char *
r, *
g, *
b, *
set;
696 G_warning(_(
"Raster map <%s> not found"), filename);
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);
709 G_message(_(
"Translating colors from raster map <%s>..."),
712 for (i = 0; i < rows; i++) {
716 for (j = 0; j <
cols; j++) {
719 (r[j] & 0xff) | ((g[j] & 0xff) << 8) | ((b[j] & 0xff) <<
760 struct Colors colrules;
761 unsigned char *
r, *
g, *
b, *
set;
767 G_warning(_(
"Raster map <%s> not found"), filename);
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);
781 G_message(_(
"Translating colors from raster map <%s>..."),
784 for (i = 0; i < rows; i++) {
788 for (j = 0; j <
cols; j++) {
791 (r[j] & 0xff) | ((g[j] & 0xff) << 8) | ((b[j] & 0xff) <<
799 icur = &(icur[
cols]);
800 fcur = &(fcur[
cols]);
829 struct Categories cats;
833 RASTER_MAP_TYPE map_type;
837 G_warning(_(
"Raster map <%s> not found"), filename);
845 if (map_type == CELL_TYPE) {
849 sprintf(catstr,
"error");
852 sprintf(catstr,
"(NULL) %s",
856 sprintf(catstr,
"(%d) %s", buf[dcol],
868 sprintf(catstr,
"error");
871 sprintf(catstr,
"(NULL) %s",
875 sprintf(catstr,
"(%g) %s", dbuf[dcol],
883 strcpy(catstr,
"no category label");
907 struct Cell_head *
w, geosurf * defsurf)
918 if (mapset !=
NULL) {
920 if (defsurf->draw_mode & DM_WIRE_POLY) {
923 else if (defsurf->draw_mode & DM_WIRE ||
924 defsurf->draw_mode & DM_COL_WIRE) {
927 else if (defsurf->draw_mode & DM_POLY) {
931 v.mesh_freq = defsurf->x_modw;
932 v.poly_freq = defsurf->x_mod;
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;
939 GS_v3eq(v.from_to[TO], gv->real_to);
940 v.from_to[TO][Z] -= zmin;
942 v.from_to[TO][Z] *= gv->vert_exag;
945 GS_v3eq(v.from_to[TO], gv->from_to[TO]);
953 v.exag = gv->vert_exag;
954 v.fov = gv->fov / 10.;
960 if (gv->lights[0].position[W] == 1) {
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];
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];
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];
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;
984 strcpy((v.pgm_id),
"Nvision-ALPHA!");
1005 struct Cell_head *
w, geosurf * defsurf)
1014 if (mapset !=
NULL) {
1019 if (strcmp((v.pgm_id),
"Nvision-ALPHA!")) {
1020 G_warning(_(
"View not saved by this program,"
1021 "there may be some inconsistancies"));
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);
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];
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];
1045 v.mesh_freq, v.mesh_freq);
1047 while (v.display_type >= 10) {
1049 v.display_type -= 10;
1054 dmode |= DM_COL_WIRE;
1058 dmode |= DM_GOURAUD;
1061 switch (v.display_type) {
1071 dmode |= DM_WIRE_POLY;
1087 (v.fov > 0 ? v.fov * 10. + 0.5 : v.fov * 10. - 0.5));
1095 GS_set_twist((
int)(v.twist > 0 ? v.twist + 0.5 : v.twist - 0.5));
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];
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];
1114 gv->lights[0].shine = v.shine;
1117 gv->lights[0].ambient[0] = gv->lights[0].ambient[1] =
1118 gv->lights[0].ambient[2] = v.ambient * 3.;
1148 gs->att[desc].max_nz = gs->att[desc].min_nz = gs->att[desc].range_nz =
1152 gs->att[desc].max_nz = gs->att[desc].min_nz = gs->att[desc].constant;
1153 gs->att[desc].range_nz = 0.0;
1156 gs->att[desc].max_nz = 0xFFFFFF;
1157 gs->att[desc].min_nz = 0x010101;
1158 gs->att[desc].range_nz = 0xFFFFFF;
1170 size = gs->rows * gs->cols;
1179 size = gs->rows * gs->cols;
1186 size = gs->rows * gs->cols;
1195 size = gs->rows * gs->cols;
1202 size = gs->rows * gs->cols;
1211 size = gs->rows * gs->cols;
1218 size = gs->rows * gs->cols;
1227 size = gs->rows * gs->cols;
1232 gs->att[desc].max_nz =
max;
1233 gs->att[desc].min_nz =
min;
1234 gs->att[desc].range_nz = gs->att[desc].max_nz - gs->att[desc].min_nz;
1237 if (ATT_TOPO == desc) {
1240 gs->zrange = gs->zmax - gs->zmin;
1241 gs->zminmasked = gs->zmin;
1242 gs->zmax_nz = gs->zmax;
1243 gs->zmin_nz = gs->zmin;
1244 gs->zrange_nz = gs->zmax_nz - gs->zmin_nz;
1247 G_debug(3,
"Gs_update_attrange(): min=%f max=%f", gs->zmin, gs->zmax);