GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-3f124c5c78
open2.c
Go to the documentation of this file.
1 #include <grass/gis.h>
2 #include <grass/raster3d.h>
3 
4 /*----------------------------------------------------------------------------*/
5 
6 /*!
7  * \brief
8  *
9  * Opens new g3d-file with <em>name</em> in the current mapset. Tiles
10  * are stored in memory with <em>typeIntern</em> which must be one of
11  * FCELL_TYPE, DCELL_TYPE, or RASTER3D_TILE_SAME_AS_FILE. <em>cache</em>
12  * specifies the cache-mode used and must be either RASTER3D_NO_CACHE,
13  * RASTER3D_USE_CACHE_DEFAULT, RASTER3D_USE_CACHE_X, RASTER3D_USE_CACHE_Y,
14  * RASTER3D_USE_CACHE_Z, RASTER3D_USE_CACHE_XY, RASTER3D_USE_CACHE_XZ,
15  * RASTER3D_USE_CACHE_YZ, RASTER3D_USE_CACHE_XYZ, the result of
16  * <tt>Rast3d_cache_size_encode ()</tt> (cf.{g3d:G3d.cacheSizeEncode}), or any
17  * positive integer which specifies the number of tiles buffered in the cache.
18  * <em>region</em> specifies the 3d region. The map is created using the
19  * <em>type</em> which must be of FCELL_TYPE or DCELL_TYPE. The methods for
20  * compression can be specified LZW or RLE. The digits of the floating point
21  * mantissa can be specified. In case of FCELL_TYPE 0-23 and 0-52 in case of
22  * DCELL_TYPE. The number cells in X, Y and Z direction defines the size of each
23  * tile. Returns a pointer to the cell structure ... if successful, NULL ...
24  * otherwise.
25  *
26  * \param name The name of the map
27  * \param typeIntern The internal storage type for in memory cached tiles
28  * \param cache The type of the caching
29  * \param region The region of the map
30  * \param type The type of the map (FCELL_TYPE, or DCELL_TYPE)
31  * \param doLzw Use the LZW compression algorithm
32  * \param doRle Use the Run-Length-Encoding algroithm for compression
33  * \param precision The precision used for the mantissa (0 - 52) or
34  * RASTER3D_MAX_PRECISION \param tileX The number of cells in X direction of a
35  * tile \param tileY The number of cells in Y direction of a tile \param tileZ
36  * The number of cells in Z direction of a tile \return void *
37  */
38 
39 void *Rast3d_open_new_param(const char *name, int typeIntern, int cache,
40  RASTER3D_Region *region, int type, int compression,
41  int precision, int tileX, int tileY, int tileZ)
42 {
43  void *map;
44  int oldCompress, oldPrecision, oldTileX, oldTileY, oldTileZ;
45  int oldType;
46 
48 
49  Rast3d_get_compression_mode(&oldCompress, &oldPrecision);
51 
52  Rast3d_get_tile_dimension(&oldTileX, &oldTileY, &oldTileZ);
53  Rast3d_set_tile_dimension(tileX, tileY, tileZ);
54 
55  oldType = Rast3d_get_file_type();
57 
58  map = Rast3d_open_cell_new(name, typeIntern, cache, region);
59 
60  Rast3d_set_compression_mode(oldCompress, oldPrecision);
61  Rast3d_set_tile_dimension(oldTileX, oldTileY, oldTileZ);
62  Rast3d_set_file_type(oldType);
63 
64  return map;
65 }
66 
67 /*----------------------------------------------------------------------------*/
68 
69 /*!
70  * \brief
71  *
72  * Opens new g3d-file with <em>name</em> in the current mapset. This method
73  * tries to compute optimal tile size based on the number of rows, cols and
74  * depths and the maximum allowed tile size in KB. Tiles are stored in memory
75  * using RASTER3D_TILE_SAME_AS_FILE method. <em>cache</em> specifies the
76  * cache-mode used and must be either RASTER3D_NO_CACHE,
77  * RASTER3D_USE_CACHE_DEFAULT, RASTER3D_USE_CACHE_X, RASTER3D_USE_CACHE_Y,
78  * RASTER3D_USE_CACHE_Z, RASTER3D_USE_CACHE_XY, RASTER3D_USE_CACHE_XZ,
79  * RASTER3D_USE_CACHE_YZ, RASTER3D_USE_CACHE_XYZ, the result of
80  * <tt>Rast3d_cache_size_encode ()</tt> (cf.{g3d:G3d.cacheSizeEncode}), or any
81  * positive integer which specifies the number of tiles buffered in the cache.
82  * <em>region</em> specifies the 3d region. The map is created using the
83  * <em>type</em> which must be of FCELL_TYPE or DCELL_TYPE. Returns a pointer to
84  * the cell structure ... if successful, NULL ... otherwise.
85  *
86  * \param name The name of the map
87  * \param cache The type of the caching
88  * \param region The region of the map
89  * \param type The type of the map (FCELL_TYPE, or DCELL_TYPE)
90  * \param maxSize The maximum size of a tile in kilo bytes
91  * \return void *
92  */
93 
94 void *Rast3d_open_new_opt_tile_size(const char *name, int cache,
95  RASTER3D_Region *region, int type,
96  int maxSize)
97 {
98  void *map;
99  int oldTileX, oldTileY, oldTileZ, oldType;
100  int tileX, tileY, tileZ;
101 
103 
104  Rast3d_get_tile_dimension(&oldTileX, &oldTileY, &oldTileZ);
105 
106  Rast3d_compute_optimal_tile_dimension(region, type, &tileX, &tileY, &tileZ,
107  maxSize);
108 
109  G_debug(1, "New tile dimension X %i Y %i Z %i\n", tileX, tileY, tileZ);
110 
111  Rast3d_set_tile_dimension(tileX, tileY, tileZ);
112 
113  oldType = Rast3d_get_file_type();
114  Rast3d_set_file_type(type);
115 
117 
118  Rast3d_set_tile_dimension(oldTileX, oldTileY, oldTileZ);
119  Rast3d_set_file_type(oldType);
120 
121  return map;
122 }
int G_debug(int, const char *,...) __attribute__((format(printf
void Rast3d_compute_optimal_tile_dimension(RASTER3D_Region *, int, int *, int *, int *, int)
Compute the optimal tile size.
Definition: tilemath.c:317
void Rast3d_get_tile_dimension(int *, int *, int *)
get Tile Dimension
Definition: defaults.c:262
void Rast3d_set_tile_dimension(int, int, int)
set Tile Dimension
Definition: defaults.c:236
void Rast3d_set_file_type(int)
set G3d file type
Definition: defaults.c:204
int Rast3d_get_file_type(void)
get G3d file type
Definition: defaults.c:220
void Rast3d_get_compression_mode(int *, int *)
Gets compression mode.
Definition: defaults.c:127
void Rast3d_init_defaults(void)
Initializes the default values described in RASTER3D Defaults. Applications have to use this function...
Definition: defaults.c:294
void * Rast3d_open_cell_new(const char *, int, int, RASTER3D_Region *)
Opens new g3d-file with name in the current mapset. Tiles are stored in memory with type which must b...
void Rast3d_set_compression_mode(int, int)
set compression mode
Definition: defaults.c:94
unsigned short compression
Definition: gsd_img_tif.c:42
const char * name
Definition: named_colr.c:6
void * Rast3d_open_new_param(const char *name, int typeIntern, int cache, RASTER3D_Region *region, int type, int compression, int precision, int tileX, int tileY, int tileZ)
Opens new g3d-file with name in the current mapset. Tiles are stored in memory with typeIntern which ...
Definition: open2.c:39
void * Rast3d_open_new_opt_tile_size(const char *name, int cache, RASTER3D_Region *region, int type, int maxSize)
Opens new g3d-file with name in the current mapset. This method tries to compute optimal tile size ba...
Definition: open2.c:94
#define RASTER3D_TILE_SAME_AS_FILE
Definition: raster3d.h:11