1 #include <grass/raster3d.h>
2 #include "raster3d_intern.h"
3 
4 /*---------------------------------------------------------------------------*/
5 
6 
7 /*!
8  * \brief
9  *
10  *  Returns the size of the region of <em>map</em> in cells.
11  *
12  *  \param map
13  *  \param rows
14  *  \param cols
15  *  \param depths
16  *  \return void
17  */
18 
Rast3d_get_coords_map(RASTER3D_Map * map,int * rows,int * cols,int * depths)19 void Rast3d_get_coords_map(RASTER3D_Map * map, int *rows, int *cols, int *depths)
20 {
21     *rows = map->region.rows;
22     *cols = map->region.cols;
23     *depths = map->region.depths;
24 }
25 
26 /*---------------------------------------------------------------------------*/
27 
Rast3d_get_coords_map_window(RASTER3D_Map * map,int * rows,int * cols,int * depths)28 void Rast3d_get_coords_map_window(RASTER3D_Map * map, int *rows, int *cols, int *depths)
29 {
30     *rows = map->window.rows;
31     *cols = map->window.cols;
32     *depths = map->window.depths;
33 }
34 
35 /*---------------------------------------------------------------------------*/
36 
37 
38 /*!
39  * \brief
40  *
41  * Returns the dimensions of the tile-cube used to tile the region of <em>map</em>.
42  * These numbers include partial tiles.
43  *
44  *  \param map
45  *  \param nx
46  *  \param ny
47  *  \param nz
48  *  \return void
49  */
50 
Rast3d_get_nof_tiles_map(RASTER3D_Map * map,int * nx,int * ny,int * nz)51 void Rast3d_get_nof_tiles_map(RASTER3D_Map * map, int *nx, int *ny, int *nz)
52 {
53     *nx = map->nx;
54     *ny = map->ny;
55     *nz = map->nz;
56 }
57 
58 /*---------------------------------------------------------------------------*/
59 
60 
61 /*!
62  * \brief
63  *
64  * Returns the size of the region.
65  *
66  *  \param map
67  *  \param north
68  *  \param south
69  *  \param east
70  *  \param west
71  *  \param top
72  *  \param bottom
73  *  \return void
74  */
75 
76 void
Rast3d_get_region_map(RASTER3D_Map * map,double * north,double * south,double * east,double * west,double * top,double * bottom)77 Rast3d_get_region_map(RASTER3D_Map * map, double *north, double *south, double *east,
78 		 double *west, double *top, double *bottom)
79 {
80     *north = map->region.north;
81     *south = map->region.south;
82     *east = map->region.east;
83     *west = map->region.west;
84     *top = map->region.top;
85     *bottom = map->region.bottom;
86 }
87 
88 /*---------------------------------------------------------------------------*/
89 
90 void
Rast3d_get_window_map(RASTER3D_Map * map,double * north,double * south,double * east,double * west,double * top,double * bottom)91 Rast3d_get_window_map(RASTER3D_Map * map, double *north, double *south, double *east,
92 		 double *west, double *top, double *bottom)
93 {
94     *north = map->window.north;
95     *south = map->window.south;
96     *east = map->window.east;
97     *west = map->window.west;
98     *top = map->window.top;
99     *bottom = map->window.bottom;
100 }
101 
102 /*---------------------------------------------------------------------------*/
103 
104 
105 /*!
106  * \brief
107  *
108  * Returns in <em>region</em> the region of <em>map</em>.
109  *
110  *  \param map
111  *  \param region
112  *  \return void
113  */
114 
Rast3d_get_region_struct_map(RASTER3D_Map * map,RASTER3D_Region * region)115 void Rast3d_get_region_struct_map(RASTER3D_Map * map, RASTER3D_Region * region)
116 {
117     Rast3d_region_copy(region, &(map->region));
118 }
119 
120 /*---------------------------------------------------------------------------*/
121 
Rast3d_getWindowStructMap(RASTER3D_Map * map,RASTER3D_Region * window)122 void Rast3d_getWindowStructMap(RASTER3D_Map * map, RASTER3D_Region * window)
123 {
124     Rast3d_region_copy(window, &(map->window));
125 }
126 
127 /*---------------------------------------------------------------------------*/
128 
129 
130 /*!
131  * \brief
132  *
133  * Returns the tile dimensions used for <em>map</em>.
134  *
135  *  \param map
136  *  \param x
137  *  \param y
138  *  \param z
139  *  \return void
140  */
141 
Rast3d_get_tile_dimensions_map(RASTER3D_Map * map,int * x,int * y,int * z)142 void Rast3d_get_tile_dimensions_map(RASTER3D_Map * map, int *x, int *y, int *z)
143 {
144     *x = map->tileX;
145     *y = map->tileY;
146     *z = map->tileZ;
147 }
148 
149 /*---------------------------------------------------------------------------*/
150 
151 
152 /*!
153  * \brief
154  *
155  * Returns the type in which tiles of <em>map</em> are stored in memory.
156  *
157  *  \param map
158  *  \return int
159  */
160 
Rast3d_tile_type_map(RASTER3D_Map * map)161 int Rast3d_tile_type_map(RASTER3D_Map * map)
162 {
163     return map->typeIntern;
164 }
165 
166 /*---------------------------------------------------------------------------*/
167 
168 /*!
169  * \brief
170  *
171  *  Set the data unit defintiong
172  *
173  *  \param map
174  *  \param unit
175  *  \return void
176  */
177 
Rast3d_set_unit(RASTER3D_Map * map,const char * unit)178 void Rast3d_set_unit(RASTER3D_Map * map, const char *unit)
179 {
180     map->unit = G_store(unit);
181 }
182 
183 /*---------------------------------------------------------------------------*/
184 
185 /*!
186  * \brief
187  *
188  *  set Vertical unit from integer value defined in gis.h (U_METERS, ...)
189  *
190  *  \param map
191  *  \param unit
192  *  \return void
193  */
194 
Rast3d_set_vertical_unit2(RASTER3D_Map * map,int vertical_unit)195 void Rast3d_set_vertical_unit2(RASTER3D_Map * map, int vertical_unit)
196 {
197     map->vertical_unit = vertical_unit;
198 }
199 
200 /*---------------------------------------------------------------------------*/
201 
202 /*!
203  * \brief
204  *
205  *  set Vertical unit from string
206  *
207  *  \param map
208  *  \param unit
209  *  \return void
210  */
211 
Rast3d_set_vertical_unit(RASTER3D_Map * map,const char * vertical_unit)212 void Rast3d_set_vertical_unit(RASTER3D_Map * map, const char *vertical_unit)
213 {
214     map->vertical_unit = G_units(vertical_unit);
215 }
216 
217 /*---------------------------------------------------------------------------*/
218 
219 /*!
220  * \brief
221  *
222  * Return the data unit definition of <em>map</em>.
223  *
224  *  \param map
225  *  \return int
226  */
227 
Rast3d_get_unit(RASTER3D_Map * map)228 const char* Rast3d_get_unit(RASTER3D_Map * map)
229 {
230     return map->unit;
231 }
232 
233 /*---------------------------------------------------------------------------*/
234 
235 /*!
236  * \brief
237  *
238  * Returns the vertical unit of <em>map</em> as integer. Units are defined in gis.h.
239  *
240  * Vertical units may have temporal type
241  *
242  *  \param map
243  *  \return int
244  */
245 
Rast3d_get_vertical_unit2(RASTER3D_Map * map)246 int Rast3d_get_vertical_unit2(RASTER3D_Map * map)
247 {
248     return map->vertical_unit;
249 }
250 
251 /*---------------------------------------------------------------------------*/
252 
253 /*!
254  * \brief
255  *
256  * Return the name of the unit of <em>map</em>. Units are defined in gis.h.
257  *
258  * Vertical units may have temporal type
259  *
260  *  \param map
261  *  \return int
262  */
263 
Rast3d_get_vertical_unit(RASTER3D_Map * map)264 const char* Rast3d_get_vertical_unit(RASTER3D_Map * map)
265 {
266     return G_get_units_name(map->vertical_unit, 1, 0);
267 }
268 
269 /*---------------------------------------------------------------------------*/
270 
271 
272 /*!
273  * \brief
274  *
275  * Returns the type with which tiles of <em>map</em> are stored on file.
276  *
277  *  \param map
278  *  \return int
279  */
280 
Rast3d_file_type_map(RASTER3D_Map * map)281 int Rast3d_file_type_map(RASTER3D_Map * map)
282 {
283     return map->type;
284 }
285 
286 /*---------------------------------------------------------------------------*/
287 
288 
289 /*!
290  * \brief
291  *
292  * Returns the precision used to store <em>map</em>.
293  *
294  *  \param map
295  *  \return int
296  */
297 
Rast3d_tile_precision_map(RASTER3D_Map * map)298 int Rast3d_tile_precision_map(RASTER3D_Map * map)
299 {
300     return map->precision;
301 }
302 
303 /*---------------------------------------------------------------------------*/
304 
305 
306 /*!
307  * \brief
308  *
309  * Returns 1 if <em>map</em> uses cache, returns 0 otherwise.
310  *
311  *  \param map
312  *  \return int
313  */
314 
Rast3d_tile_use_cache_map(RASTER3D_Map * map)315 int Rast3d_tile_use_cache_map(RASTER3D_Map * map)
316 {
317     return map->useCache;
318 }
319 
320 
321 
322 /*!
323  * \brief
324  *
325  * Prints the header information of <em>map</em>.
326  *
327  *  \param map
328  *  \return void
329  */
330 
Rast3d_print_header(RASTER3D_Map * map)331 void Rast3d_print_header(RASTER3D_Map * map)
332 {
333     double rangeMin, rangeMax;
334 
335     printf("File %s open for %sing:\n", map->fileName,
336 	   (map->operation == RASTER3D_WRITE_DATA ? "writing" :
337 	    (map->operation == RASTER3D_READ_DATA ? "reading" : "unknown")));
338     printf("Version %i\n", map->version);
339     printf("  Fd = %d, Unit %s, Vertical Unit %s, Type: %s, ", map->data_fd,
340 	   map->unit, G_get_units_name(map->vertical_unit, 1, 0),
341 	   (map->type == FCELL_TYPE ? "float" :
342 	    (map->type == DCELL_TYPE ? "double" : "unknown")));
343     printf("Type intern: %s\n",
344 	   (map->typeIntern == FCELL_TYPE ? "float" :
345 	    (map->typeIntern == DCELL_TYPE ? "double" : "unknown")));
346     if (map->compression == RASTER3D_NO_COMPRESSION)
347 	printf("  Compression: none\n");
348     else {
349 	printf("  Compression:%s (%s%s) Precision: %s", (map->compression ? "on" : "off"),
350 	       (map->useLzw ? " lzw," : ""), (map->useRle ? " rle," : ""),
351 	       (map->precision == -1 ? "all bits used\n" : "using"));
352 	if (map->precision != -1)
353 	    printf(" %d bits\n", map->precision);
354     }
355 
356     if (!map->useCache)
357 	printf("  Cache: none\n");
358     else {
359 	printf("  Cache: used%s\n",
360 	       (map->operation == RASTER3D_WRITE_DATA ? ", File Cache used" : ""));
361     }
362 
363     Rast3d_range_min_max(map, &rangeMin, &rangeMax);
364 
365     printf("  Region: (%f %f) (%f %f) (%f %f)\n",
366 	   map->region.south, map->region.north, map->region.west,
367 	   map->region.east, map->region.bottom, map->region.top);
368     printf("            (cols %5d rows %5d depths %5d)\n", map->region.cols, map->region.rows,
369 	   map->region.depths);
370     printf("  Num tiles (X    %5d Y    %5d Z      %5d)\n", map->nx, map->ny, map->nz);
371     printf("  Tile size (X    %5d Y    %5d Z      %5d)\n", map->tileX, map->tileY, map->tileZ);
372     printf("  Range (");
373     if (Rast3d_is_null_value_num(&rangeMin, DCELL_TYPE))
374 	printf("NULL, ");
375     else
376 	printf("%f, ", (double)rangeMin);
377     if (Rast3d_is_null_value_num(&rangeMax, DCELL_TYPE))
378 	printf("NULL)\n");
379     else
380 	printf("%f)\n", (double)rangeMax);
381     fflush(stdout);
382 }
383