GRASS 8 Programmer's Manual 8.6.0dev(2026)-8843f13794
Loading...
Searching...
No Matches
gs3.c File Reference

OGSF library - loading surfaces (lower level functions) More...

#include <stdlib.h>
#include <string.h>
#include <grass/gis.h>
#include <grass/raster.h>
#include <grass/glocale.h>
#include <grass/bitmap.h>
#include <grass/ogsf.h>
#include "gsget.h"
Include dependency graph for gs3.c:

Go to the source code of this file.

Macros

#define INIT_MINMAX(p, nm, size, min, max, found)
 Used in the function Gs_update_attrange()
 
#define SET_MINMAX(p, nm, size, min, max)
 Used in the function Gs_update_attrange()
 
#define NO_DATA_COL   0xffffff
 

Typedefs

typedef int FILEDESC
 

Functions

double Gs_distance (double *from, double *to)
 Calculates distance in METERS between two points in current projection (2D)
 
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_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_numtype (const char *filename, int *negflag)
 Get map data type.
 
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_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_bitmap (struct Cell_head *wind, const char *map_name, struct BM *buff)
 Load raster map as integer map.
 
int Gs_build_256lookup (const char *filename, int *buff)
 Build color table (256)
 
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)
 
int Gs_get_cat_label (const char *filename, int drow, int dcol, char *catstr)
 Get categories/labels.
 
int Gs_save_3dview (const char *vname, geoview *gv, geodisplay *gd, struct Cell_head *w, geosurf *defsurf)
 Save 3dview.
 
int Gs_load_3dview (const char *vname, geoview *gv, geodisplay *gd, struct Cell_head *w, const geosurf *defsurf)
 Load 3dview.
 
int Gs_update_attrange (geosurf *gs, int desc)
 Update no_zero ranges for attribute (actually no_null now)
 

Detailed Description

OGSF library - loading surfaces (lower level functions)

GRASS OpenGL gsurf OGSF Library

SPDX-FileCopyrightText: 1999-2008 GRASS Development Team SPDX-License-Identifier: GPL-2.0-or-later

Author
Bill Brown USACERL, GMSL/University of Illinois (January 1993)
Doxygenized by Martin Landa <landa.martin gmail.com> (May 2008)

Definition in file gs3.c.

Macro Definition Documentation

◆ INIT_MINMAX

#define INIT_MINMAX (   p,
  nm,
  size,
  min,
  max,
  found 
)
Value:
found = 0; \
p += (size - 1); \
while (size--) { \
if (!BM_GET_BYOFFSET(nm, size)) { \
min = max = *p; \
found = 1; \
break; \
} \
p--; \
}
#define min(x, y)
Definition draw2.c:29
#define max(x, y)
Definition draw2.c:30
#define BM_GET_BYOFFSET(bm, off)
Definition gsget.h:31

Used in the function Gs_update_attrange()

Definition at line 31 of file gs3.c.

◆ NO_DATA_COL

#define NO_DATA_COL   0xffffff

Definition at line 62 of file gs3.c.

◆ SET_MINMAX

#define SET_MINMAX (   p,
  nm,
  size,
  min,
  max 
)
Value:
p += (size - 1); \
while (size--) { \
if (!BM_GET_BYOFFSET(nm, size)) { \
if (*p < min) { \
min = *p; \
} \
else if (*p > max) { \
max = *p; \
} \
} \
p--; \
}

Used in the function Gs_update_attrange()

Definition at line 46 of file gs3.c.

Typedef Documentation

◆ FILEDESC

Definition at line 60 of file gs3.c.

Function Documentation

◆ Gs_build_256lookup()

int Gs_build_256lookup ( const char filename,
int buff 
)

Build color table (256)

Calling function must have already allocated space in buff for range of data (256 for now) - simply calls get_color for each cat in color range

Parameters
filenameraster map name
[out]buffdata buffer
Returns
1 on success
0 on failure

Definition at line 572 of file gs3.c.

References _, b, g, G_debug(), G_find_raster2(), G_warning(), G_zero(), max, min, NO_DATA_COL, r, Rast_get_c_color_range(), Rast_lookup_c_colors(), and Rast_read_colors().

Referenced by GS_load_att_map().

◆ Gs_distance()

double Gs_distance ( double from,
double to 
)

Calculates distance in METERS between two points in current projection (2D)

Uses G_distance().

Parameters
[in]from'from' point (X, Y)
[in]to'to' point (X, Y)
Returns
distance

Definition at line 75 of file gs3.c.

References G_begin_distance_calculations(), and G_distance().

Referenced by GS_geodistance().

◆ Gs_get_cat_label()

int Gs_get_cat_label ( const char filename,
int  drow,
int  dcol,
char catstr 
)

Get categories/labels.

Formats label as in d.what.rast -> (catval) catlabel

Parameters
filenameraster map name
drow
dcol
catstrcategory string
Returns
1 on success
0 on failure

Definition at line 772 of file gs3.c.

References _, CELL_TYPE, G_find_raster2(), G_free(), G_warning(), NULL, Rast_allocate_c_buf(), Rast_allocate_d_buf(), Rast_close(), Rast_free_cats(), Rast_get_c_cat(), Rast_get_c_row(), Rast_get_d_cat(), Rast_get_d_row(), Rast_get_map_type(), Rast_is_c_null_value, Rast_is_d_null_value, Rast_open_old(), Rast_read_cats(), and strcpy.

Referenced by GS_get_cat_at_xy().

◆ Gs_load_3dview()

◆ Gs_loadmap_as_bitmap()

int Gs_loadmap_as_bitmap ( struct Cell_head wind,
const char map_name,
struct BM buff 
)

Load raster map as integer map.

Calling function must have already allocated space in buff for struct BM of wind->rows & wind->cols.

This routine simply loads the map into the bitmap by repetitve calls to get_map_row. Any value other than 0 in the map will set the bitmap. (may want to change later to allow specific value to set)

Changed to use null.

Parameters
windcurrent window
map_nameraster map name
[out]buffdata buffer
Returns
1 on success
-1 on failure

Definition at line 512 of file gs3.c.

References _, BM_set(), Cell_head::cols, G_debug(), G_find_raster2(), G_free(), G_fully_qualified_name(), G_malloc, G_message(), G_warning(), Rast_close(), Rast_get_c_row(), Rast_is_c_null_value, Rast_open_old(), and Cell_head::rows.

Referenced by GS_load_att_map().

◆ Gs_loadmap_as_char()

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.

Calling function must have already allocated space in buff for wind->rows * wind->cols unsigned chars.

This routine simply loads the map into a 2d array by repetitve calls to get_map_row.

Since signs of chars can be tricky, we only load positive chars between 0-255.

Todo:
fn body Gs_loadmap_as_float()
Parameters
windcurrent window
map_nameraster map name
[out]buffdata buffer
[out]nullmapnull map buffer
[out]has_nullindicates if raster map contains null-data
Returns
1 on success
-1 on failure
-2 if read ok, but 1 or more values were too large (small) to fit into an unsigned char. (in which case the max (min) char is used)

Definition at line 411 of file gs3.c.

References _, BM_set(), Cell_head::cols, G_debug(), G_find_raster2(), G_free(), G_fully_qualified_name(), G_malloc, G_message(), G_percent(), G_warning(), Rast_close(), Rast_get_c_row(), Rast_is_c_null_value, Rast_open_old(), and Cell_head::rows.

Referenced by GS_load_att_map().

◆ Gs_loadmap_as_float()

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.

Calling function must have already allocated space in buff for wind->rows * wind->cols floats.

This routine simply loads the map into a 2d array by repetitve calls to get_f_raster_row.

Parameters
windcurrent window
map_nameraster map name
[out]buffdata buffer
[out]nullmapnull map buffer
[out]has_nullindicates if raster map contains null-data
Returns
1 on success
0 on failure

Definition at line 105 of file gs3.c.

References _, BM_set(), Cell_head::cols, G_debug(), G_find_raster2(), G_free(), G_fully_qualified_name(), G_message(), G_percent(), G_warning(), Rast_close(), Rast_get_f_row(), Rast_is_f_null_value, Rast_open_old(), and Cell_head::rows.

Referenced by GS_load_att_map().

◆ Gs_loadmap_as_int()

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.

Calling function must have already allocated space in buff for wind->rows * wind->cols floats.

This routine simply loads the map into a 2d array by repetitve calls to get_f_raster_row.

Todo:
fn body of Gs_loadmap_as_float()
Parameters
windcurrent window
map_nameraster map name
[out]buffdata buffer
[out]nullmapnull map buffer
[out]has_nullindicates if raster map contains null-data
Returns
1 on success
0 on failure

Definition at line 170 of file gs3.c.

References _, BM_set(), Cell_head::cols, G_debug(), G_find_raster2(), G_free(), G_fully_qualified_name(), G_message(), G_percent(), G_warning(), Rast_close(), Rast_get_c_row(), Rast_is_f_null_value, Rast_open_old(), and Cell_head::rows.

Referenced by GS_load_att_map().

◆ Gs_loadmap_as_short()

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.

Calling function must have already allocated space in buff for wind->rows * wind->cols shorts.

This routine simply loads the map into a 2d array by repetitve calls to get_map_row.

Parameters
windcurrent window
map_nameraster map name
[out]buffdata buffer
[out]nullmapnull map buffer
[out]has_nullindicates if raster map contains null-data
Returns
1 on success
-1 on failure,
-2 if read ok, but 1 or more values were too large (small) to fit into a short (in which case the max (min) short is used)

Definition at line 305 of file gs3.c.

References _, BM_set(), Cell_head::cols, G_debug(), G_find_raster2(), G_free(), G_fully_qualified_name(), G_malloc, G_message(), G_percent(), G_warning(), Rast_close(), Rast_get_c_row(), Rast_is_c_null_value, Rast_open_old(), and Cell_head::rows.

Referenced by GS_load_att_map().

◆ Gs_numtype()

int Gs_numtype ( const char filename,
int negflag 
)

Get map data type.

Parameters
filenameraster map name
negflag
Returns
-1 if map is integer and Rast_read_range() fails
data type (ARRY_*)

Definition at line 223 of file gs3.c.

References _, ATTY_CHAR, ATTY_FLOAT, ATTY_INT, ATTY_SHORT, G_debug(), G_find_raster2(), G_warning(), max, min, Rast_get_range_min_max(), Rast_map_is_fp(), and Rast_read_range().

Referenced by GS_load_att_map().

◆ Gs_pack_colors()

void Gs_pack_colors ( const char filename,
int buff,
int  rows,
int  cols 
)

Pack color table.

Passed an array of 32 bit ints that is converted from cell values to packed colors (0xbbggrr)

Parameters
filenameraster map name
buff
rowsnumber of rows
colsnumber of cols

Definition at line 633 of file gs3.c.

References _, b, g, G_find_raster2(), G_free(), G_fully_qualified_name(), G_malloc, G_message(), G_percent(), G_warning(), NO_DATA_COL, r, Rast_free_colors(), Rast_lookup_c_colors(), and Rast_read_colors().

Referenced by GS_load_att_map().

◆ Gs_pack_colors_float()

void Gs_pack_colors_float ( const char filename,
float fbuf,
int ibuf,
int  rows,
int  cols 
)

Pack color table (floating-point map)

Passed a array of floats that will be converted from cell values to packed colors (0xbbggrr) and float to int Floating point data not freed here, use: gsds_free_data_buff(id, ATTY_FLOAT)

Parameters
filenameraster map name
fbuf
ibuf
rowsnumber of rows
colsnumber of cols

Definition at line 701 of file gs3.c.

References _, b, g, G_find_raster2(), G_free(), G_fully_qualified_name(), G_malloc, G_message(), G_percent(), G_warning(), NO_DATA_COL, r, Rast_free_colors(), Rast_lookup_f_colors(), and Rast_read_colors().

Referenced by GS_load_att_map().

◆ Gs_save_3dview()

int Gs_save_3dview ( const char vname,
geoview gv,
geodisplay gd,
struct Cell_head w,
geosurf defsurf 
)

◆ Gs_update_attrange()

int Gs_update_attrange ( geosurf gs,
int  desc 
)

Update no_zero ranges for attribute (actually no_null now)

Parameters
gspointer to geosurf struct
descattribute id (descriptor)
Returns
-1 on error
1 on success

Definition at line 1080 of file gs3.c.

References ATT_TOPO, CF_COLOR_PACKED, CONST_ATT, G_debug(), gs_get_att_src(), gsds_get_changed(), gsds_get_typbuff(), INIT_MINMAX, max, min, NULL, and SET_MINMAX.

Referenced by GS_load_att_map(), gs_set_att_const(), and GS_set_att_const().