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) {
856 sprintf(catstr,
"(%d) %s", buf[dcol],
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 min = max = gs->att[desc].constant;
1154 gs->att[desc].range_nz = 0.0;
1157 gs->att[desc].max_nz = 0xFFFFFF;
1158 gs->att[desc].min_nz = 0x010101;
1159 gs->att[desc].range_nz = 0xFFFFFF;
1171 size = gs->rows * gs->cols;
1180 size = gs->rows * gs->cols;
1187 size = gs->rows * gs->cols;
1196 size = gs->rows * gs->cols;
1203 size = gs->rows * gs->cols;
1212 size = gs->rows * gs->cols;
1219 size = gs->rows * gs->cols;
1228 size = gs->rows * gs->cols;
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;
1238 if (ATT_TOPO == desc) {
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;
1248 G_debug(3,
"Gs_update_attrange(): min=%f max=%f", gs->zmin, gs->zmax);
char * G_mapset(void)
current mapset name
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...
void GS_set_fov(int fov)
Set field of view.
int Gs_build_256lookup(const char *filename, int *buff)
Build color table (256)
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
int G_get_d_raster_row(int fd, DCELL *buf, int row)
Get raster row (DCELL type)
void G_free(void *buf)
Free allocated memory.
void GS_set_global_exag(float exag)
Set global z-exag value.
int Gs_save_3dview(const char *vname, geoview *gv, geodisplay *gd, struct Cell_head *w, geosurf *defsurf)
Save 3dview.
CELL * G_allocate_c_raster_buf(void)
Allocates memory for a raster map of type CELL.
int G_close_cell(int fd)
close a raster map
int GS_setall_drawmode(int mode)
Set all draw-modes.
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
int G_begin_distance_calculations(void)
Begin distance calculations.
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.
int G_free_colors(struct Colors *colors)
free color structure memory
int G_open_cell_old(const char *name, const char *mapset)
Open an existing integer raster map (cell)
void GS_set_focus(float *realto)
Set focus.
RASTER_MAP_TYPE G_get_raster_map_type(int fd)
Determine raster type from descriptor.
int G_get_f_raster_row(int fd, FCELL *buf, int row)
Get raster row (FCELL type)
int G_get_3dview_defaults(struct G_3dview *v, struct Cell_head *w)
Sets default for v based on w.
int Gs_loadmap_as_bitmap(struct Cell_head *wind, const char *map_name, struct BM *buff)
Load raster map as integer map.
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.
typbuff * gsds_get_typbuff(int id, IFLAG change_flag)
Get data buffer.
int G_read_colors(const char *name, const char *mapset, struct Colors *colors)
read map layer color table
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.
int Gs_update_attrange(geosurf *gs, int desc)
Update no_zero ranges for attribute (actually no_null now)
int G_read_range(const char *name, const char *mapset, struct Range *range)
read raster range
int GS_setall_drawres(int xres, int yres, int xwire, int ywire)
Set all draw resolutions.
int G_read_cats(const char *name, const char *mapset, struct Categories *pcats)
read raster category file
char * G_allocate_null_buf(void)
Allocates memory for a null buffer.
int G_raster_map_is_fp(const char *name, const char *mapset)
Check if raster map is floating-point.
int GS_get_zrange(float *min, float *max, int doexag)
Get z-extent for all loaded surfaces.
int G_zero(void *buf, int i)
Zero out a buffer, buf, of length i.
int G_percent(long n, long d, int s)
Print percent complete messages.
int G_free_cats(struct Categories *pcats)
free category structure memory
void Gs_pack_colors_float(const char *filename, float *fbuf, int *ibuf, int rows, int cols)
Pack color table (floating-point map)
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.
#define INIT_MINMAX(p, nm, size, min, max, found)
Used in the function Gs_update_attrange()
int G_get_range_min_max(const struct Range *range, CELL *min, CELL *max)
get range min and max
void GS_v3mult(float *v1, float k)
Multiple vectors.
char * G_find_cell2(const char *name, const char *mapset)
find a raster map (look but don't touch)
int Gs_get_cat_label(const char *filename, int drow, int dcol, char *catstr)
Get categories/labels.
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().
int G_get_c_raster_row(int fd, CELL *buf, int row)
Get raster row (CELL type)
void G_message(const char *msg,...)
Print a message to stderr.
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'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.
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.
void Gs_pack_colors(const char *filename, int *buff, int rows, int cols)
Pack color table.
int gsds_get_changed(int id)
ADD.
int G_get_null_value_row(int fd, char *flags, int row)
Read or simmulate null value row.
int Gs_load_3dview(const char *vname, geoview *gv, geodisplay *gd, struct Cell_head *w, geosurf *defsurf)
Load 3dview.
double Gs_distance(double *from, double *to)
Calculates distance in METERS between two points in current projection (2D)
int G_get_3dview(const char *fname, const char *mapset, struct G_3dview *View)
Gets a 3D View.
void gsd_model2real(Point3 point)
Convert model to real coordinates.
void GS_alldraw_wire(void)
Draw all wires.
int Gs_numtype(const char *filename, int *negflag)
Get map data type.
#define SET_MINMAX(p, nm, size, min, max)
Used in the function Gs_update_attrange()
char * G_get_d_raster_cat(DCELL *rast, struct Categories *pcats)
given a DCELL value val Returns pointer to a string describing category.
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
void GS_set_twist(int t)
Set viewpoint twist value.
char * G_get_c_raster_cat(CELL *rast, struct Categories *pcats)
given a CELL value val Returns pointer to a string describing category.
void GS_v3eq(float *v1, float *v2)
Copy vector values.
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) retu...
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
int G_debug(int level, const char *msg,...)
Print debugging message.
int gs_get_att_src(geosurf *gs, int desc)
Get attribute source.
double G_distance(double e1, double n1, double e2, double n2)
Returns distance in meters.
int G_get_color_range(CELL *min, CELL *max, const struct Colors *colors)
int BM_set(struct BM *map, int x, int y, int val)
Sets bitmap value to 'val' at location 'x' 'y'.
char * G_fully_qualified_name(const char *name, const char *mapset)
fully qualified file name
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
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.
void GS_moveto_real(float *pt)
Move position to (real)
DCELL * G_allocate_d_raster_buf(void)
Allocates memory for a raster map of type DCELL.