GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
raster3d/misc.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <sys/types.h>
5 #include <unistd.h>
6 
7 #include <grass/raster.h>
8 
9 #include "raster3d_intern.h"
10 
11 /*---------------------------------------------------------------------------*/
12 
13 int Rast3d_g3d_type2cell_type(int g3dType)
14 {
15  if (g3dType == FCELL_TYPE)
16  return FCELL_TYPE;
17  return DCELL_TYPE;
18 }
19 
20 /*---------------------------------------------------------------------------*/
21 
22 void
23 Rast3d_copy_float2Double(const float *src, int offsSrc, double *dst, int offsDst,
24  int nElts)
25 {
26  int i;
27 
28  src += offsSrc;
29  dst += offsDst;
30 
31  for (i = 0; i < nElts; i++)
32  dst[i] = (double)src[i];
33 }
34 
35 /*---------------------------------------------------------------------------*/
36 
37 void
38 Rast3d_copy_double2Float(const double *src, int offsSrc, float *dst, int offsDst,
39  int nElts)
40 {
41  int i;
42 
43  src += offsSrc;
44  dst += offsDst;
45 
46  for (i = 0; i < nElts; i++)
47  dst[i] = (float)src[i];
48 }
49 
50 /*---------------------------------------------------------------------------*/
51 
52 void
53 Rast3d_copy_values(const void *src, int offsSrc, int typeSrc, void *dst,
54  int offsDst, int typeDst, int nElts)
55 {
56  int eltLength;
57 
58  if ((typeSrc == FCELL_TYPE) && (typeDst == DCELL_TYPE)) {
59  Rast3d_copy_float2Double(src, offsSrc, dst, offsDst, nElts);
60  return;
61  }
62 
63  if ((typeSrc == DCELL_TYPE) && (typeDst == FCELL_TYPE)) {
64  Rast3d_copy_double2Float(src, offsSrc, dst, offsDst, nElts);
65  return;
66  }
67 
68  eltLength = Rast3d_length(typeSrc);
69 
70  src = G_incr_void_ptr(src, eltLength * offsSrc);
71  dst = G_incr_void_ptr(dst, eltLength * offsDst);
72 
73  memcpy(dst, src, nElts * eltLength);
74 }
75 
76 /*---------------------------------------------------------------------------*/
77 
78 int Rast3d_length(int t)
79 {
81  Rast3d_fatal_error("Rast3d_length: invalid type");
82 
83  if (t == FCELL_TYPE)
84  return sizeof(FCELL);
85  if (t == DCELL_TYPE)
86  return sizeof(DCELL);
87  return 0;
88 }
89 
91 {
93  Rast3d_fatal_error("Rast3d_extern_length: invalid type");
94 
95  if (t == FCELL_TYPE)
97  if (t == DCELL_TYPE)
99  return 0;
100 }
void Rast3d_copy_float2Double(const float *src, int offsSrc, double *dst, int offsDst, int nElts)
Definition: raster3d/misc.c:23
int Rast3d_g3d_type2cell_type(int g3dType)
Definition: raster3d/misc.c:13
void Rast3d_copy_values(const void *src, int offsSrc, int typeSrc, void *dst, int offsDst, int typeDst, int nElts)
Definition: raster3d/misc.c:53
int Rast3d_extern_length(int t)
Definition: raster3d/misc.c:90
double DCELL
Definition: gis.h:603
#define RASTER3D_XDR_DOUBLE_LENGTH
char * dst
Definition: lz4.h:599
#define G_incr_void_ptr(ptr, size)
Definition: defs/gis.h:100
#define RASTER3D_IS_CORRECT_TYPE(t)
void Rast3d_fatal_error(const char *,...) __attribute__((format(printf
void Rast3d_copy_double2Float(const double *src, int offsSrc, float *dst, int offsDst, int nElts)
Definition: raster3d/misc.c:38
double t
Definition: r_raster.c:39
#define DCELL_TYPE
Definition: raster.h:13
float FCELL
Definition: gis.h:604
#define FCELL_TYPE
Definition: raster.h:12
int Rast3d_length(int t)
Definition: raster3d/misc.c:78
#define RASTER3D_XDR_FLOAT_LENGTH