open2.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #include <grass/gis.h>
  2. #include <grass/raster3d.h>
  3. /*----------------------------------------------------------------------------*/
  4. /*!
  5. * \brief
  6. *
  7. * Opens new g3d-file with <em>name</em> in the current mapset. Tiles
  8. * are stored in memory with <em>typeIntern</em> which must be one of FCELL_TYPE,
  9. * DCELL_TYPE, or RASTER3D_TILE_SAME_AS_FILE. <em>cache</em> specifies the
  10. * cache-mode used and must be either RASTER3D_NO_CACHE, RASTER3D_USE_CACHE_DEFAULT,
  11. * RASTER3D_USE_CACHE_X, RASTER3D_USE_CACHE_Y, RASTER3D_USE_CACHE_Z,
  12. * RASTER3D_USE_CACHE_XY, RASTER3D_USE_CACHE_XZ, RASTER3D_USE_CACHE_YZ,
  13. * RASTER3D_USE_CACHE_XYZ, the result of <tt>Rast3d_cache_size_encode ()</tt>
  14. * (cf.{g3d:G3d.cacheSizeEncode}), or any positive integer which
  15. * specifies the number of tiles buffered in the cache. <em>region</em> specifies
  16. * the 3d region.
  17. * The map is created using the <em>type</em> which must be of FCELL_TYPE or DCELL_TYPE.
  18. * The methods for compression can be specified LZW or RLE. The digits of the floating point mantissa
  19. * can be specified. In case of FCELL_TYPE 0-23 and 0-52 in case of DCELL_TYPE.
  20. * The number cells in X, Y and Z direction defines the size of each tile.
  21. * Returns a pointer to the cell structure ... if successful,
  22. * NULL ... otherwise.
  23. *
  24. * \param name The name of the map
  25. * \param typeIntern The internal storage type for in memory chached tiles
  26. * \param cache The type of the caching
  27. * \param region The region of the map
  28. * \param type The type of the map (FCELL_TYPE, or DCELL_TYPE)
  29. * \param doLzw Use the LZW compression algorithm
  30. * \param doRle Use the Run-Length-Encoding algroithm for compression
  31. * \param precision The precision used for the mantissa (0 - 52) or RASTER3D_MAX_PRECISION
  32. * \param tileX The number of cells in X direction of a tile
  33. * \param tileY The number of cells in Y direction of a tile
  34. * \param tileZ The number of cells in Z direction of a tile
  35. * \return void *
  36. */
  37. void *Rast3d_open_new_param(const char *name, int typeIntern, int cache,
  38. RASTER3D_Region * region, int type, int compression,
  39. int precision, int tileX, int tileY, int tileZ)
  40. {
  41. void *map;
  42. int oldCompress, oldPrecision, oldTileX, oldTileY,
  43. oldTileZ;
  44. int oldType;
  45. Rast3d_init_defaults();
  46. Rast3d_get_compression_mode(&oldCompress, &oldPrecision);
  47. Rast3d_set_compression_mode(compression, precision);
  48. Rast3d_get_tile_dimension(&oldTileX, &oldTileY, &oldTileZ);
  49. Rast3d_set_tile_dimension(tileX, tileY, tileZ);
  50. oldType = Rast3d_get_file_type();
  51. Rast3d_set_file_type(type);
  52. map = Rast3d_open_cell_new(name, typeIntern, cache, region);
  53. Rast3d_set_compression_mode(oldCompress, oldPrecision);
  54. Rast3d_set_tile_dimension(oldTileX, oldTileY, oldTileZ);
  55. Rast3d_set_file_type(oldType);
  56. return map;
  57. }
  58. /*----------------------------------------------------------------------------*/
  59. /*!
  60. * \brief
  61. *
  62. * Opens new g3d-file with <em>name</em> in the current mapset. This method tries to compute
  63. * optimal tile size based on the number of rows, cols and depths and the maximum allowed tile size in KB.
  64. * Tiles are stored in memory using RASTER3D_TILE_SAME_AS_FILE method. <em>cache</em> specifies the
  65. * cache-mode used and must be either RASTER3D_NO_CACHE, RASTER3D_USE_CACHE_DEFAULT,
  66. * RASTER3D_USE_CACHE_X, RASTER3D_USE_CACHE_Y, RASTER3D_USE_CACHE_Z,
  67. * RASTER3D_USE_CACHE_XY, RASTER3D_USE_CACHE_XZ, RASTER3D_USE_CACHE_YZ,
  68. * RASTER3D_USE_CACHE_XYZ, the result of <tt>Rast3d_cache_size_encode ()</tt>
  69. * (cf.{g3d:G3d.cacheSizeEncode}), or any positive integer which
  70. * specifies the number of tiles buffered in the cache. <em>region</em> specifies
  71. * the 3d region.
  72. * The map is created using the <em>type</em> which must be of FCELL_TYPE or DCELL_TYPE.
  73. * Returns a pointer to the cell structure ... if successful,
  74. * NULL ... otherwise.
  75. *
  76. * \param name The name of the map
  77. * \param cache The type of the caching
  78. * \param region The region of the map
  79. * \param type The type of the map (FCELL_TYPE, or DCELL_TYPE)
  80. * \param maxSize The maximum size of a tile in kilo bytes
  81. * \return void *
  82. */
  83. void *Rast3d_open_new_opt_tile_size(const char *name, int cache, RASTER3D_Region * region, int type, int maxSize)
  84. {
  85. void *map;
  86. int oldTileX, oldTileY, oldTileZ, oldType;
  87. int tileX, tileY, tileZ;
  88. Rast3d_init_defaults();
  89. Rast3d_get_tile_dimension(&oldTileX, &oldTileY, &oldTileZ);
  90. Rast3d_compute_optimal_tile_dimension(region, type, &tileX, &tileY, &tileZ, maxSize);
  91. G_debug(1, "New tile dimension X %i Y %i Z %i\n", tileX, tileY, tileZ);
  92. Rast3d_set_tile_dimension(tileX, tileY, tileZ);
  93. oldType = Rast3d_get_file_type();
  94. Rast3d_set_file_type(type);
  95. map = Rast3d_open_cell_new(name, RASTER3D_TILE_SAME_AS_FILE, cache, region);
  96. Rast3d_set_tile_dimension(oldTileX, oldTileY, oldTileZ);
  97. Rast3d_set_file_type(oldType);
  98. return map;
  99. }