GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
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  */
34 int 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  */
65 int 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  */
82 int 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 }
#define G_malloc(n)
Definition: defs/gis.h:112
int Gvl_unload_colors_data(void *color_data)
Unload color table.
Definition: gvl3.c:65
int Rast3d_read_colors(const char *, const char *, struct Colors *)
Reads color file for map name in mapset into the Colors structure.
void G_free(void *)
Free allocated memory.
Definition: gis/alloc.c:149
const char * G_find_raster3d(const char *, const char *)
Search for a 3D raster map in current search path or in a specified mapset.
Definition: find_rast3d.c:28
#define NULL
Definition: ccmath.h:32
double b
Definition: r_raster.c:39
int Gvl_get_color_for_value(void *color_data, float *value)
Get color for value.
Definition: gvl3.c:82
int Gvl_load_colors_data(void **color_data, const char *name)
Load color table.
Definition: gvl3.c:34
float g
Definition: named_colr.c:8
void Rast_free_colors(struct Colors *)
Free color structure memory.
Definition: color_free.c:30
float FCELL
Definition: gis.h:604
Definition: gis.h:665
int Rast_get_f_color(const FCELL *, int *, int *, int *, struct Colors *)
Gets color from raster map (FCELL)
Definition: color_get.c:89
void G_warning(const char *,...) __attribute__((format(printf
#define _(str)
Definition: glocale.h:10
const char * name
Definition: named_colr.c:7
double r
Definition: r_raster.c:39