GRASS GIS 8 Programmer's Manual 8.3.2(2024)-exported
Loading...
Searching...
No Matches
gvl3.c
Go to the documentation of this file.
1/*!
2 \file lib/ogsf/gvl3.c
3
4 \brief OGSF library - loading volumes (lower level functions)
5
6 GRASS OpenGL gsurf OGSF Library
7
8 (C) 1999-2008 by the GRASS Development Team
9
10 This program is free software under the
11 GNU General Public License (>=v2).
12 Read the file COPYING that comes with GRASS
13 for details.
14
15 \author Tomas Paudits (December 2003)
16 \author Doxygenized by Martin Landa <landa.martin gmail.com> (May 2008)
17 */
18
19#include <grass/gis.h>
20#include <grass/raster.h>
21#include <grass/raster3d.h>
22#include <grass/ogsf.h>
23#include <grass/glocale.h>
24
25/*!
26 \brief Load color table
27
28 \param[out] color_data color data buffer
29 \param name 3D raster map name
30
31 \return -1 on failure
32 \return 1 on success
33 */
34int Gvl_load_colors_data(void **color_data, const char *name)
35{
36 const char *mapset;
37 struct Colors *colors;
38
39 if (NULL == (mapset = G_find_raster3d(name, ""))) {
40 G_warning(_("3D raster map <%s> not found"), name);
41 return (-1);
42 }
43
44 if (NULL == (colors = (struct Colors *)G_malloc(sizeof(struct Colors))))
45 return (-1);
46
47 if (0 > Rast3d_read_colors(name, mapset, colors)) {
48 G_free(colors);
49 return (-1);
50 }
51
52 *color_data = colors;
53
54 return (1);
55}
56
57/*!
58 \brief Unload color table
59
60 \param color_data color data buffer
61
62 \return -1 on failure
63 \return 1 on success
64 */
65int Gvl_unload_colors_data(void *color_data)
66{
67 Rast_free_colors(color_data);
68
69 G_free(color_data);
70
71 return (1);
72}
73
74/*!
75 \brief Get color for value
76
77 \param color_data color data value
78 \param value data value
79
80 \return color value
81 */
82int Gvl_get_color_for_value(void *color_data, float *value)
83{
84 int r, g, b;
85
86 Rast_get_f_color((FCELL *)value, &r, &g, &b, color_data);
87 return ((r & 0xff) | ((g & 0xff) << 8) | ((b & 0xff) << 16));
88}
void G_free(void *buf)
Free allocated memory.
Definition alloc.c:150
#define NULL
Definition ccmath.h:32
double b
double r
const char * G_find_raster3d(const char *name, const char *mapset)
Search for a 3D raster map in current search path or in a specified mapset.
Definition find_rast3d.c:28
void G_warning(const char *msg,...)
Print a warning message to stderr.
Definition gis/error.c:203
int Gvl_unload_colors_data(void *color_data)
Unload color table.
Definition gvl3.c:65
int Gvl_load_colors_data(void **color_data, const char *name)
Load color table.
Definition gvl3.c:34
int Gvl_get_color_for_value(void *color_data, float *value)
Get color for value.
Definition gvl3.c:82
float g
Definition named_colr.c:7
const char * name
Definition named_colr.c:6