GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
g3dwindow.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <grass/gis.h>
3 #include <grass/G3d.h>
4 #include "G3d_intern.h"
5 
6 /*---------------------------------------------------------------------------*/
7 
8 G3D_Region g3d_window;
9 
10 /*---------------------------------------------------------------------------*/
11 
12 
24 void G3d_setWindowMap(G3D_Map * map, G3D_Region * window)
25 {
26  G3d_regionCopy(&(map->window), window);
27  G3d_adjustRegion(&(map->window));
28 }
29 
30 /*---------------------------------------------------------------------------*/
31 
32 
43 void G3d_setWindow(G3D_Region * window)
44 {
45  G3d_regionCopy(&g3d_window, window);
47 }
48 
49 /*---------------------------------------------------------------------------*/
50 
51 
61 void G3d_getWindow(G3D_Region * window)
62 {
63  G3d_regionCopy(window, &g3d_window);
64 }
65 
66 /*---------------------------------------------------------------------------*/
67 
68 G3D_Region *G3d_windowPtr()
69 {
70  return &g3d_window;
71 }
72 
73 /*---------------------------------------------------------------------------*/
74 
75 
92 void G3d_getValue(G3D_Map * map, int x, int y, int z, void *value, int type)
93 {
94  double north, east, top;
95 
96  /*AV*/
97  /* BEGIN OF ORIGINAL CODE */
98  /*
99  int row, col, depth;
100  */
101  /* END OF ORIGINAL CODE */
102  /*AV*/
103  /* BEGIN OF MY CODE */
104  double row, col, depth;
105 
106  /* END OF MY CODE */
107 
108  /* convert (x, y, z) into (north, east, top) */
109 
110  /*AV*/
111  /* BEGIN OF ORIGINAL CODE */
112  /*
113  north = ((double) map->window.rows - y - 0.5) / (double) map->window.rows *
114  (map->window.north - map->window.south) + map->window.south;
115  */
116  /* END OF ORIGINAL CODE */
117  /*AV*/
118  /* BEGIN OF MY CODE */
119  north = ((double)y + 0.5) / (double)map->window.rows *
120  (map->window.north - map->window.south) + map->window.south;
121  /* END OF MY CODE */
122 
123  east = ((double)x + 0.5) / (double)map->window.cols *
124  (map->window.east - map->window.west) + map->window.west;
125  top = ((double)z + 0.5) / (double)map->window.depths *
126  (map->window.top - map->window.bottom) + map->window.bottom;
127 
128  /* convert (north, east, top) into (row, col, depth) */
129 
130  /*AV*/
131  /* BEGIN OF ORIGINAL CODE */
132  /*
133  row = map->region.rows -
134  (north - map->region.south) / (map->region.north - map->region.south) *
135  map->region.rows;
136  */
137  /* END OF ORIGINAL CODE */
138  /*AV*/
139  /* BEGIN OF MY CODE */
140  row =
141  (north - map->region.south) / (map->region.north -
142  map->region.south) * map->region.rows;
143  /* END OF MY CODE */
144 
145  col = (east - map->region.west) / (map->region.east - map->region.west) *
146  map->region.cols;
147  depth =
148  (top - map->region.bottom) / (map->region.top -
149  map->region.bottom) *
150  map->region.depths;
151 
152  /* if (row, col, depth) outside window return NULL value */
153  if ((row < 0) || (row >= map->region.rows) ||
154  (col < 0) || (col >= map->region.cols) ||
155  (depth < 0) || (depth >= map->region.depths)) {
156  G3d_setNullValue(value, 1, type);
157  return;
158  }
159 
160  /* get value */
161  map->resampleFun(map, (int)row, (int)col, (int)depth, value, type);
162 
163 }
164 
165 /*---------------------------------------------------------------------------*/
166 
167 
181 float G3d_getFloat(G3D_Map * map, int x, int y, int z)
182 {
183  float value;
184 
185  G3d_getValue(map, x, y, z, &value, FCELL_TYPE);
186  return value;
187 }
188 
189 /*---------------------------------------------------------------------------*/
190 
191 
205 double G3d_getDouble(G3D_Map * map, int x, int y, int z)
206 {
207  double value;
208 
209  G3d_getValue(map, x, y, z, &value, DCELL_TYPE);
210  return value;
211 }
G3D_Region * G3d_windowPtr()
Definition: g3dwindow.c:68
void G3d_setNullValue(void *c, int nofElts, int type)
Fills the vector pointed to by c with nofElts NULL-values of type.
Definition: g3dnull.c:32
double G3d_getDouble(G3D_Map *map, int x, int y, int z)
Is equivalent to G3d_getValue (map, x, y, z, &amp;value, DCELL_TYPE); return value.
Definition: g3dwindow.c:205
void G3d_getValue(G3D_Map *map, int x, int y, int z, void *value, int type)
Returns in *value the cell-value of the cell with window-coordinate (x, y, z). The value returned is ...
Definition: g3dwindow.c:92
int y
Definition: plot.c:34
void G3d_getWindow(G3D_Region *window)
Stores the current default window in window.
Definition: g3dwindow.c:61
void G3d_setWindow(G3D_Region *window)
Sets the default window used for every map opened later in the program. Can be used multiple times in...
Definition: g3dwindow.c:43
tuple window
Definition: tools.py:543
char * value
Definition: env.c:30
G3D_Region g3d_window
Definition: g3dwindow.c:8
void G3d_setWindowMap(G3D_Map *map, G3D_Region *window)
Sets the window for map to window. Can be used multiple times for the same map.
Definition: g3dwindow.c:24
void G3d_adjustRegion(G3D_Region *region)
Computes an adjusts the resolutions in the region structure from the region boundaries and number of ...
Definition: g3dregion.c:149
void G3d_regionCopy(G3D_Region *regionDest, G3D_Region *regionSrc)
Copies the values of regionSrc into regionDst. (The unfortunate order of parameters was chosen in ord...
Definition: g3dregion.c:213
float G3d_getFloat(G3D_Map *map, int x, int y, int z)
Is equivalent to G3d_getValue (map, x, y, z, &amp;value, FCELL_TYPE); return value.
Definition: g3dwindow.c:181