GRASS GIS 8 Programmer's Manual  8.4.0dev(2024)-112dd97adf
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 Rast3d_copy_float2Double(const float *src, int offsSrc, double *dst,
23  int offsDst, int nElts)
24 {
25  int i;
26 
27  src += offsSrc;
28  dst += offsDst;
29 
30  for (i = 0; i < nElts; i++)
31  dst[i] = (double)src[i];
32 }
33 
34 /*---------------------------------------------------------------------------*/
35 
36 void Rast3d_copy_double2Float(const double *src, int offsSrc, float *dst,
37  int offsDst, int nElts)
38 {
39  int i;
40 
41  src += offsSrc;
42  dst += offsDst;
43 
44  for (i = 0; i < nElts; i++)
45  dst[i] = (float)src[i];
46 }
47 
48 /*---------------------------------------------------------------------------*/
49 
50 void Rast3d_copy_values(const void *src, int offsSrc, int typeSrc, void *dst,
51  int offsDst, int typeDst, int nElts)
52 {
53  int eltLength;
54 
55  if ((typeSrc == FCELL_TYPE) && (typeDst == DCELL_TYPE)) {
56  Rast3d_copy_float2Double(src, offsSrc, dst, offsDst, nElts);
57  return;
58  }
59 
60  if ((typeSrc == DCELL_TYPE) && (typeDst == FCELL_TYPE)) {
61  Rast3d_copy_double2Float(src, offsSrc, dst, offsDst, nElts);
62  return;
63  }
64 
65  eltLength = Rast3d_length(typeSrc);
66 
67  src = G_incr_void_ptr(src, eltLength * offsSrc);
68  dst = G_incr_void_ptr(dst, eltLength * offsDst);
69 
70  memcpy(dst, src, nElts * eltLength);
71 }
72 
73 /*---------------------------------------------------------------------------*/
74 
75 int Rast3d_length(int t)
76 {
78  Rast3d_fatal_error("Rast3d_length: invalid type");
79 
80  if (t == FCELL_TYPE)
81  return sizeof(FCELL);
82  if (t == DCELL_TYPE)
83  return sizeof(DCELL);
84  return 0;
85 }
86 
88 {
90  Rast3d_fatal_error("Rast3d_extern_length: invalid type");
91 
92  if (t == FCELL_TYPE)
94  if (t == DCELL_TYPE)
96  return 0;
97 }
#define G_incr_void_ptr(ptr, size)
Definition: defs/gis.h:81
void Rast3d_fatal_error(const char *,...) __attribute__((format(printf
float FCELL
Definition: gis.h:627
double DCELL
Definition: gis.h:626
double t
Definition: r_raster.c:39
int Rast3d_length(int t)
Definition: raster3d/misc.c:75
void Rast3d_copy_float2Double(const float *src, int offsSrc, double *dst, int offsDst, int nElts)
Definition: raster3d/misc.c:22
void Rast3d_copy_double2Float(const double *src, int offsSrc, float *dst, int offsDst, int nElts)
Definition: raster3d/misc.c:36
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:50
int Rast3d_extern_length(int t)
Definition: raster3d/misc.c:87
#define RASTER3D_XDR_DOUBLE_LENGTH
#define RASTER3D_IS_CORRECT_TYPE(t)
#define RASTER3D_XDR_FLOAT_LENGTH
#define FCELL_TYPE
Definition: raster.h:12
#define DCELL_TYPE
Definition: raster.h:13