23#include <grass/raster.h>
24#include <grass/glocale.h>
25#include <grass/bitmap.h>
27#include <grass/ogsf.h>
35#define INIT_MINMAX(p, nm, size, min, max, found) \
39 if (!BM_GET_BYOFFSET(nm, size)) { \
50#define SET_MINMAX(p, nm, size, min, max) \
53 if (!BM_GET_BYOFFSET(nm, size)) { \
57 else if (*p > max) { \
66#define NO_DATA_COL 0xffffff
88 return G_distance(from[0], from[1], to[0], to[1]);
110 float *buff,
struct BM *nullmap,
int *has_null)
114 int offset, row, col;
116 G_debug(3,
"Gs_loadmap_as_float(): name=%s", map_name);
120 G_warning(_(
"Raster map <%s> not found"), map_name);
125 cellfile = Rast_open_old(map_name, map_set);
127 G_message(_(
"Loading raster map <%s>..."),
130 for (row = 0; row < wind->rows; row++) {
131 offset = row * wind->cols;
132 Rast_get_f_row(cellfile, &(buff[offset]), row);
136 for (col = 0; col < wind->cols; col++) {
137 if (Rast_is_f_null_value(buff + offset + col)) {
139 BM_set(nullmap, col, row, 1);
146 G_debug(4,
" has_null=%d", *has_null);
148 Rast_close(cellfile);
174 struct BM *nullmap,
int *has_null)
178 int offset, row, col;
180 G_debug(3,
"Gs_loadmap_as_int");
184 G_warning(_(
"Raster map <%s> not found"), map_name);
189 cellfile = Rast_open_old(map_name, map_set);
191 G_message(_(
"Loading raster map <%s>..."),
194 for (row = 0; row < wind->rows; row++) {
195 offset = row * wind->cols;
196 Rast_get_c_row(cellfile, &(buff[offset]), row);
200 for (col = 0; col < wind->cols; col++) {
201 if (Rast_is_f_null_value(buff + offset + col)) {
203 BM_set(nullmap, col, row, 1);
211 Rast_close(cellfile);
230 int shortbits, charbits, bitplace;
231 static int max_short, max_char;
232 static int first = 1;
235 max_short = max_char = 1;
236 shortbits = 8 *
sizeof(short);
238 for (bitplace = 1; bitplace < shortbits; ++bitplace) {
246 charbits = 8 *
sizeof(
unsigned char);
248 for (bitplace = 0; bitplace < charbits; ++bitplace) {
259 G_warning(_(
"Raster map <%s> not found"), filename);
263 if (Rast_map_is_fp(filename, mapset)) {
264 G_debug(3,
"Gs_numtype(): fp map detected");
269 if (-1 == Rast_read_range(filename, mapset, &range)) {
273 Rast_get_range_min_max(&range, &
min, &
max);
274 *negflag = (
min < 0);
276 if (max < max_char && min > 0) {
280 if (max < max_short && min > -max_short) {
308 short *buff,
struct BM *nullmap,
int *has_null)
313 int offset, row, col, val, max_short, overflow, shortsize, bitplace;
316 G_debug(3,
"Gs_loadmap_as_short");
319 shortsize = 8 *
sizeof(short);
323 for (max_short = bitplace = 1; bitplace < shortsize; ++bitplace) {
331 G_warning(_(
"Raster map <%s> not found"), map_name);
336 cellfile = Rast_open_old(map_name, map_set);
338 tmp_buf = (
int *)G_malloc(wind->cols *
sizeof(
int));
343 G_message(_(
"Loading raster map <%s>..."),
346 for (row = 0; row < wind->rows; row++) {
347 offset = row * wind->cols;
348 Rast_get_c_row(cellfile, tmp_buf, row);
352 ts = &(buff[offset]);
355 for (col = 0; col < wind->cols; col++) {
356 if (Rast_is_c_null_value(&tmp_buf[col])) {
358 BM_set(nullmap, col, row, 1);
362 if (abs(val) > max_short) {
366 *ts = (short)(max_short * val / abs(val));
379 Rast_close(cellfile);
383 return (overflow ? -2 : 1);
413 unsigned char *buff,
struct BM *nullmap,
int *has_null)
418 int offset, row, col, val, max_char, overflow, charsize, bitplace;
421 G_debug(3,
"Gs_loadmap_as_char");
424 charsize = 8 *
sizeof(
unsigned char);
429 for (bitplace = 0; bitplace < charsize; ++bitplace) {
437 G_warning(_(
"Raster map <%s> not found"), map_name);
442 cellfile = Rast_open_old(map_name, map_set);
444 tmp_buf = (
int *)G_malloc(wind->cols *
sizeof(
int));
449 G_message(_(
"Loading raster map <%s>..."),
452 for (row = 0; row < wind->rows; row++) {
453 offset = row * wind->cols;
454 Rast_get_c_row(cellfile, tmp_buf, row);
455 tc = (
unsigned char *)&(buff[offset]);
460 for (col = 0; col < wind->cols; col++) {
461 if (Rast_is_c_null_value(&tmp_buf[col])) {
463 BM_set(nullmap, col, row, 1);
467 if (val > max_char) {
469 *tc = (
unsigned char)max_char;
476 *tc = (
unsigned char)val;
486 Rast_close(cellfile);
490 return (overflow ? -2 : 1);
520 G_debug(3,
"Gs_loadmap_as_bitmap");
524 G_warning(_(
"Raster map <%s> not found"), map_name);
528 cellfile = Rast_open_old(map_name, map_set);
530 tmp_buf = (
int *)G_malloc(wind->cols *
sizeof(
int));
535 G_message(_(
"Loading raster map <%s>..."),
538 for (row = 0; row < wind->rows; row++) {
539 Rast_get_c_row(cellfile, tmp_buf, row);
541 for (col = 0; col < wind->cols; col++) {
542 if (Rast_is_c_null_value(&tmp_buf[col])) {
544 BM_set(buff, col, row, 1);
547 BM_set(buff, col, row, 0);
552 Rast_close(cellfile);
574 struct Colors colrules;
577 unsigned char r[256],
g[256],
b[256], set[256];
579 G_debug(3,
"building color table");
583 G_warning(_(
"Raster map <%s> not found"), filename);
587 Rast_read_colors(filename, mapset, &colrules);
588 Rast_get_c_color_range(&
min, &
max, &colrules);
590 if (min < 0 || max > 255) {
592 _(
"Color table range doesn't match data (mincol=%d, maxcol=%d"),
599 G_zero(cats, 256 *
sizeof(CELL));
601 for (i =
min; i <=
max; i++) {
605 Rast_lookup_c_colors(cats,
r,
g,
b, set, 256, &colrules);
607 for (i = 0; i < 256; i++) {
611 (
r[i] & 0xff) | ((
g[i] & 0xff) << 8) | ((
b[i] & 0xff) << 16);
635 struct Colors colrules;
636 unsigned char *
r, *
g, *
b, *set;
641 G_warning(_(
"Raster map <%s> not found"), filename);
645 r = (
unsigned char *)G_malloc(cols);
646 g = (
unsigned char *)G_malloc(cols);
647 b = (
unsigned char *)G_malloc(cols);
648 set = (
unsigned char *)G_malloc(cols);
650 Rast_read_colors(filename, mapset, &colrules);
654 G_message(_(
"Translating colors from raster map <%s>..."),
657 for (i = 0; i < rows; i++) {
658 Rast_lookup_c_colors(cur,
r,
g,
b, set, cols, &colrules);
661 for (j = 0; j < cols; j++) {
663 cur[j] = (
r[j] & 0xff) | ((
g[j] & 0xff) << 8) |
664 ((
b[j] & 0xff) << 16);
675 Rast_free_colors(&colrules);
704 struct Colors colrules;
705 unsigned char *
r, *
g, *
b, *set;
711 G_warning(_(
"Raster map <%s> not found"), filename);
715 r = (
unsigned char *)G_malloc(cols);
716 g = (
unsigned char *)G_malloc(cols);
717 b = (
unsigned char *)G_malloc(cols);
718 set = (
unsigned char *)G_malloc(cols);
720 Rast_read_colors(filename, mapset, &colrules);
725 G_message(_(
"Translating colors from raster map <%s>..."),
728 for (i = 0; i < rows; i++) {
729 Rast_lookup_f_colors(fcur,
r,
g,
b, set, cols, &colrules);
732 for (j = 0; j < cols; j++) {
734 icur[j] = (
r[j] & 0xff) | ((
g[j] & 0xff) << 8) |
735 ((
b[j] & 0xff) << 16);
742 icur = &(icur[cols]);
743 fcur = &(fcur[cols]);
747 Rast_free_colors(&colrules);
772 struct Categories cats;
776 RASTER_MAP_TYPE map_type;
780 G_warning(_(
"Raster map <%s> not found"), filename);
784 if (-1 != Rast_read_cats(filename, mapset, &cats)) {
785 fd = Rast_open_old(filename, mapset);
786 map_type = Rast_get_map_type(fd);
788 if (map_type == CELL_TYPE) {
789 buf = Rast_allocate_c_buf();
791 Rast_get_c_row(fd, buf, drow);
792 if (Rast_is_c_null_value(&buf[dcol])) {
793 sprintf(catstr,
"(NULL) %s", Rast_get_c_cat(&buf[dcol], &cats));
796 sprintf(catstr,
"(%d) %s", buf[dcol],
797 Rast_get_c_cat(&buf[dcol], &cats));
805 dbuf = Rast_allocate_d_buf();
807 Rast_get_d_row(fd, dbuf, drow);
808 if (Rast_is_d_null_value(&dbuf[dcol])) {
809 sprintf(catstr,
"(NULL) %s",
810 Rast_get_d_cat(&dbuf[dcol], &cats));
813 sprintf(catstr,
"(%g) %s", dbuf[dcol],
814 Rast_get_d_cat(&dbuf[dcol], &cats));
821 strcpy(catstr,
"no category label");
826 Rast_free_cats(&cats);
847 struct Cell_head *w, geosurf *defsurf)
858 if (mapset !=
NULL) {
860 if (defsurf->draw_mode & DM_WIRE_POLY) {
863 else if (defsurf->draw_mode & DM_WIRE ||
864 defsurf->draw_mode & DM_COL_WIRE) {
867 else if (defsurf->draw_mode & DM_POLY) {
871 v.mesh_freq = defsurf->x_modw;
872 v.poly_freq = defsurf->x_mod;
873 v.dozero = !(defsurf->nz_topo);
874 v.colorgrid = (defsurf->draw_mode & DM_COL_WIRE) ? 1 : 0;
875 v.shading = (defsurf->draw_mode & DM_GOURAUD) ? 1 : 0;
879 GS_v3eq(v.from_to[TO], gv->real_to);
880 v.from_to[TO][Z] -= zmin;
882 v.from_to[TO][Z] *= gv->vert_exag;
885 GS_v3eq(v.from_to[TO], gv->from_to[TO]);
890 GS_v3eq(v.from_to[FROM], gv->from_to[FROM]);
893 v.exag = gv->vert_exag;
894 v.fov = gv->fov / 10.;
900 if (gv->lights[0].position[W] == 1) {
902 v.lightpos[
X] = gv->lights[0].position[
X];
903 v.lightpos[
Y] = gv->lights[0].position[
Y];
904 v.lightpos[Z] = gv->lights[0].position[Z];
909 v.lightpos[
X] = gv->lights[0].position[
X];
910 v.lightpos[
Y] = gv->lights[0].position[
Y];
911 v.lightpos[Z] = gv->lights[0].position[Z];
915 v.lightcol[0] = gv->lights[0].color[0];
916 v.lightcol[1] = gv->lights[0].color[1];
917 v.lightcol[2] = gv->lights[0].color[2];
919 v.ambient = (gv->lights[0].ambient[0] + gv->lights[0].ambient[1] +
920 gv->lights[0].ambient[2]) /
922 v.shine = gv->lights[0].shine;
925 strcpy((v.pgm_id),
"Nvision-ALPHA!");
946 struct Cell_head *w,
const geosurf *defsurf)
954 if (mapset !=
NULL) {
959 if (strcmp((v.pgm_id),
"Nvision-ALPHA!")) {
960 G_warning(_(
"View not saved by this program,"
961 "there may be some inconsistancies"));
965 v.mesh_freq = (int)(v.mesh_freq * v.vwin.ns_res / w->ns_res);
966 v.poly_freq = (int)(v.poly_freq * v.vwin.ns_res / w->ns_res);
972 pt[0] = (v.from_to[TO][
X] - w->west) - w->ew_res / 2.;
973 pt[1] = (v.from_to[TO][
Y] - w->south) - w->ns_res / 2.;
974 pt[2] = v.from_to[TO][Z];
978 pt[0] = (float)v.from_to[FROM][
X];
979 pt[1] = (float)v.from_to[FROM][
Y];
980 pt[2] = (float)v.from_to[FROM][Z];
989 while (v.display_type >= 10) {
991 v.display_type -= 10;
996 dmode |= DM_COL_WIRE;
1000 dmode |= DM_GOURAUD;
1003 switch (v.display_type) {
1013 dmode |= DM_WIRE_POLY;
1029 (
int)(v.fov > 0 ? v.fov * 10. + 0.5 : v.fov * 10. - 0.5));
1037 GS_set_twist((
int)(v.twist > 0 ? v.twist + 0.5 : v.twist - 0.5));
1045 gv->lights[0].position[
X] = v.lightpos[
X];
1046 gv->lights[0].position[
Y] = v.lightpos[
Y];
1047 gv->lights[0].position[Z] = v.lightpos[Z];
1050 gv->lights[0].color[0] = v.lightcol[0];
1051 gv->lights[0].color[1] = v.lightcol[1];
1052 gv->lights[0].color[2] = v.lightcol[2];
1055 gv->lights[0].shine = v.shine;
1058 gv->lights[0].ambient[0] = gv->lights[0].ambient[1] =
1059 gv->lights[0].ambient[2] = v.ambient * 3.;
1087 gs->att[desc].max_nz = gs->att[desc].min_nz = gs->att[desc].range_nz = 0.0;
1090 gs->att[desc].max_nz = gs->att[desc].min_nz = gs->att[desc].constant;
1091 min =
max = gs->att[desc].constant;
1092 gs->att[desc].range_nz = 0.0;
1095 gs->att[desc].max_nz = 0xFFFFFF;
1096 gs->att[desc].min_nz = 0x010101;
1097 gs->att[desc].range_nz = 0xFFFFFF;
1109 size = (size_t)gs->rows * gs->cols;
1118 size = (size_t)gs->rows * gs->cols;
1125 size = (size_t)gs->rows * gs->cols;
1134 size = (size_t)gs->rows * gs->cols;
1141 size = (size_t)gs->rows * gs->cols;
1150 size = (size_t)gs->rows * gs->cols;
1157 size = (size_t)gs->rows * gs->cols;
1166 size = (size_t)gs->rows * gs->cols;
1171 gs->att[desc].max_nz =
max;
1172 gs->att[desc].min_nz =
min;
1173 gs->att[desc].range_nz = gs->att[desc].max_nz - gs->att[desc].min_nz;
1176 if (ATT_TOPO == desc) {
1179 gs->zrange = gs->zmax - gs->zmin;
1180 gs->zminmasked = gs->zmin;
1181 gs->zmax_nz = gs->zmax;
1182 gs->zmin_nz = gs->zmin;
1183 gs->zrange_nz = gs->zmax_nz - gs->zmin_nz;
1186 G_debug(3,
"Gs_update_attrange(): min=%f max=%f", gs->zmin, gs->zmax);
void G_free(void *buf)
Free allocated memory.
int BM_set(struct BM *map, int x, int y, int val)
Sets bitmap value to 'val' at location 'x' 'y'.
int G_debug(int level, const char *msg,...)
Print debugging message.
const 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't touch)
const char * G_find_raster2(const char *name, const char *mapset)
Find a raster map (look but don't touch)
int G_begin_distance_calculations(void)
Begin distance calculations.
double G_distance(double e1, double n1, double e2, double n2)
Returns distance in meters.
void G_message(const char *msg,...)
Print a message to stderr.
void G_warning(const char *msg,...)
Print a warning message to stderr.
int GS_setall_drawres(int xres, int yres, int xwire, int ywire)
Set all draw resolutions.
void GS_set_global_exag(float exag)
Set global z-exag value.
void GS_set_focus(float *realto)
Set focus.
void GS_alldraw_wire(void)
Draw all wires.
int GS_get_zrange(float *min, float *max, int doexag)
Get z-extent for all loaded surfaces.
int GS_setall_drawmode(int mode)
Set all draw-modes.
void GS_moveto_real(float *pt)
Move position to (real)
void GS_set_fov(int fov)
Set field of view.
void GS_set_twist(int t)
Set viewpoint twist value.
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.
int Gs_loadmap_as_bitmap(struct Cell_head *wind, const char *map_name, struct BM *buff)
Load raster map as integer map.
int Gs_save_3dview(const char *vname, geoview *gv, geodisplay *gd UNUSED, struct Cell_head *w, geosurf *defsurf)
Save 3dview.
int Gs_numtype(const char *filename, int *negflag)
Get map data type.
void Gs_pack_colors(const char *filename, int *buff, int rows, int cols)
Pack color table.
void Gs_pack_colors_float(const char *filename, float *fbuf, int *ibuf, int rows, int cols)
Pack color table (floating-point map)
#define INIT_MINMAX(p, nm, size, min, max, found)
Used in the function Gs_update_attrange()
int Gs_load_3dview(const char *vname, geoview *gv, geodisplay *gd UNUSED, struct Cell_head *w, const geosurf *defsurf)
Load 3dview.
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.
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.
int Gs_get_cat_label(const char *filename, int drow, int dcol, char *catstr)
Get categories/labels.
#define SET_MINMAX(p, nm, size, min, max)
Used in the function Gs_update_attrange()
double Gs_distance(double *from, double *to)
Calculates distance in METERS between two points in current projection (2D)
int Gs_build_256lookup(const char *filename, int *buff)
Build color table (256)
int Gs_update_attrange(geosurf *gs, int desc)
Update no_zero ranges for attribute (actually no_null now)
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.
int gs_get_att_src(geosurf *gs, int desc)
Get attribute source.
void GS_v3mult(float *v1, float k)
Multiple vectors.
void GS_v3eq(float *v1, float *v2)
Copy vector values.
void gsd_model2real(Point3 point)
Convert model to real coordinates.
typbuff * gsds_get_typbuff(int id, IFLAG change_flag)
Get data buffer.
int gsds_get_changed(int id)
ADD.
const char * G_mapset(void)
Get current mapset name.
char * G_fully_qualified_name(const char *name, const char *mapset)
Get fully qualified element name.
void G_percent(long n, long d, int s)
Print percent complete messages.
int G_get_3dview(const char *fname, const char *mapset, struct G_3dview *View)
Gets a 3D View.
int G_get_3dview_defaults(struct G_3dview *v, struct Cell_head *w)
Sets default for v based on w.
int G_put_3dview(const char *fname, const struct G_3dview *View, const struct Cell_head *Win)
Saves info to a 3d.view file in the current mapset.
void G_zero(void *buf, int i)
Zero out a buffer, buf, of length i.