GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
gis/raster.c
Go to the documentation of this file.
1 #include <stdlib.h>
2 #include <grass/gis.h>
3 
4 
33 void *G_incr_void_ptr(const void *ptr, const size_t size)
34 {
35  /* assuming that the size of unsigned char is 1 */
36  return (void *)((const unsigned char *)ptr + size);
37 }
38 
39 
54 int G_raster_cmp(const void *v1, const void *v2, RASTER_MAP_TYPE data_type)
55 {
56  if (G_is_null_value(v1, data_type)) {
57  if (G_is_null_value(v2, data_type))
58  return 0;
59  else
60  return -1;
61  }
62  else if (G_is_null_value(v2, data_type))
63  return 1;
64 
65  switch (data_type) {
66  case CELL_TYPE:
67  if (*((const CELL *)v1) > *((const CELL *)v2))
68  return 1;
69  else if (*((const CELL *)v1) == *((const CELL *)v2))
70  return 0;
71  else
72  return -1;
73  case FCELL_TYPE:
74  if (*((const FCELL *)v1) > *((const FCELL *)v2))
75  return 1;
76  else if (*((const FCELL *)v1) == *((const FCELL *)v2))
77  return 0;
78  else
79  return -1;
80  case DCELL_TYPE:
81  if (*((const DCELL *)v1) > *((const DCELL *)v2))
82  return 1;
83  else if (*((const DCELL *)v1) == *((const DCELL *)v2))
84  return 0;
85  else
86  return -1;
87  }
88 
89  return 0;
90 }
91 
92 
105 int G_raster_cpy(void *v1, const void *v2, int n, RASTER_MAP_TYPE data_type)
106 {
107  G_copy((char *)v1, (char *)v2, n * G_raster_size(data_type));
108  return 0;
109 }
110 
111 
125 int G_set_raster_value_c(void *rast, CELL cval, RASTER_MAP_TYPE data_type)
126 {
127  CELL c;
128 
129  c = cval;
130  if (G_is_c_null_value(&c)) {
131  G_set_null_value(rast, 1, data_type);
132  return 0;
133  }
134  switch (data_type) {
135  case CELL_TYPE:
136  *((CELL *) rast) = cval;
137  break;
138  case FCELL_TYPE:
139  *((FCELL *) rast) = (FCELL) cval;
140  break;
141  case DCELL_TYPE:
142  *((DCELL *) rast) = (DCELL) cval;
143  break;
144  }
145 
146  return 0;
147 }
148 
149 
163 int G_set_raster_value_f(void *rast, FCELL fval, RASTER_MAP_TYPE data_type)
164 {
165  FCELL f;
166 
167  f = fval;
168  if (G_is_f_null_value(&f)) {
169  G_set_null_value(rast, 1, data_type);
170  return 0;
171  }
172  switch (data_type) {
173  case CELL_TYPE:
174  *((CELL *) rast) = (CELL) fval;
175  break;
176  case FCELL_TYPE:
177  *((FCELL *) rast) = fval;
178  break;
179  case DCELL_TYPE:
180  *((DCELL *) rast) = (DCELL) fval;
181  break;
182  }
183 
184  return 0;
185 }
186 
187 
201 int G_set_raster_value_d(void *rast, DCELL dval, RASTER_MAP_TYPE data_type)
202 {
203  DCELL d;
204 
205  d = dval;
206  if (G_is_d_null_value(&d)) {
207  G_set_null_value(rast, 1, data_type);
208  return -1;
209  }
210  switch (data_type) {
211  case CELL_TYPE:
212  *((CELL *) rast) = (CELL) dval;
213  break;
214  case FCELL_TYPE:
215  *((FCELL *) rast) = (FCELL) dval;
216  break;
217  case DCELL_TYPE:
218  *((DCELL *) rast) = dval;
219  break;
220  }
221 
222  return 0;
223 }
224 
225 
243 CELL G_get_raster_value_c(const void *rast, RASTER_MAP_TYPE data_type)
244 {
245  CELL c;
246 
247  if (G_is_null_value(rast, data_type)) {
248  G_set_c_null_value(&c, 1);
249  return c;
250  }
251  switch (data_type) {
252  case CELL_TYPE:
253  return *((const CELL *)rast);
254  case FCELL_TYPE:
255  return (CELL) * ((const FCELL *)rast);
256  case DCELL_TYPE:
257  return (CELL) * ((const DCELL *)rast);
258  }
259 
260  return 0;
261 }
262 
263 
278 FCELL G_get_raster_value_f(const void *rast, RASTER_MAP_TYPE data_type)
279 {
280  FCELL f;
281 
282  if (G_is_null_value(rast, data_type)) {
283  G_set_f_null_value(&f, 1);
284  return f;
285  }
286  switch (data_type) {
287  case CELL_TYPE:
288  return (FCELL) * ((const CELL *)rast);
289  case FCELL_TYPE:
290  return *((const FCELL *)rast);
291  case DCELL_TYPE:
292  return (FCELL) * ((const DCELL *)rast);
293  }
294 
295  return 0;
296 }
297 
298 
313 DCELL G_get_raster_value_d(const void *rast, RASTER_MAP_TYPE data_type)
314 {
315  DCELL d;
316 
317  if (G_is_null_value(rast, data_type)) {
318  G_set_d_null_value(&d, 1);
319  return d;
320  }
321  switch (data_type) {
322  case CELL_TYPE:
323  return (DCELL) * ((const CELL *)rast);
324  case FCELL_TYPE:
325  return (DCELL) * ((const FCELL *)rast);
326  case DCELL_TYPE:
327  return *((const DCELL *)rast);
328  }
329 
330  return 0;
331 }
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...
Definition: null_val.c:244
void G_set_d_null_value(DCELL *dcellVals, int numVals)
Definition: null_val.c:176
int G_raster_cpy(void *v1, const void *v2, int n, RASTER_MAP_TYPE data_type)
Copies raster values q into p.
Definition: gis/raster.c:105
int G_copy(void *a, const void *b, int n)
Copies n bytes starting at address b into address a.
Definition: gis/copy.c:30
CELL G_get_raster_value_c(const void *rast, RASTER_MAP_TYPE data_type)
Retrieves the value of type data_type from pointer p.
Definition: gis/raster.c:243
void * G_incr_void_ptr(const void *ptr, const size_t size)
Advance void pointer.
Definition: gis/raster.c:33
tuple size
value.Bind(wx.EVT_TEXT, self.OnVolumeIsosurfMap)
Definition: tools.py:2334
FCELL G_get_raster_value_f(const void *rast, RASTER_MAP_TYPE data_type)
Retrieves the value of type data_type from pointer p.
Definition: gis/raster.c:278
int G_set_raster_value_c(void *rast, CELL cval, RASTER_MAP_TYPE data_type)
Places a CELL raster value.
Definition: gis/raster.c:125
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().
Definition: null_val.c:306
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&#39;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.
Definition: null_val.c:281
size_t G_raster_size(RASTER_MAP_TYPE data_type)
Returns size of a raster CELL in bytes.
Definition: alloc_cell.c:38
int G_set_raster_value_d(void *rast, DCELL dval, RASTER_MAP_TYPE data_type)
Places a DCELL raster value.
Definition: gis/raster.c:201
void G_set_f_null_value(FCELL *fcellVals, int numVals)
Definition: null_val.c:158
void G_set_null_value(void *buf, int numVals, RASTER_MAP_TYPE data_type)
Definition: null_val.c:112
int G_raster_cmp(const void *v1, const void *v2, RASTER_MAP_TYPE data_type)
Compares raster values p and q.
Definition: gis/raster.c:54
void G_set_c_null_value(CELL *cellVals, int numVals)
Definition: null_val.c:142
DCELL G_get_raster_value_d(const void *rast, RASTER_MAP_TYPE data_type)
Retrieves the value of type data_type from pointer p,.
Definition: gis/raster.c:313
int n
Definition: dataquad.c:291
int G_is_null_value(const void *rast, RASTER_MAP_TYPE data_type)
If the data_type is CELL_TYPE, calls G_is_c_null_value ((CELL *) rast); If the data_type is FCELL_TYP...
Definition: null_val.c:207
int G_set_raster_value_f(void *rast, FCELL fval, RASTER_MAP_TYPE data_type)
Places a FCELL raster value.
Definition: gis/raster.c:163