param.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #include <string.h>
  2. #include <grass/gis.h>
  3. #include <grass/glocale.h>
  4. #include "G3d_intern.h"
  5. /*----------------------------------------------------------------------------*/
  6. typedef struct
  7. {
  8. struct Option *type;
  9. struct Option *precision;
  10. struct Option *compression;
  11. struct Option *dimension;
  12. struct Option *cache;
  13. } G3d_paramType;
  14. /*----------------------------------------------------------------------------*/
  15. static G3d_paramType *param;
  16. /*!
  17. * \brief
  18. *
  19. * Initializes a parameter
  20. * structure for the subset of command line arguments which lets the user
  21. * overwrite the default properties of the new file. Applications are
  22. * encouraged to use this function in order to provide a uniform style. The
  23. * command line arguments provided are the <em>type</em> of the cell values, the
  24. * <em>precision</em>, the properties of the <em>compression</em>, and the dimension
  25. * of the tiles (<em>tiledimension</em>). Every of these values defaults to the
  26. * value described in G3D Defaults.
  27. * This function has to be used in conjunction with
  28. * G3d_getStandard3dInputParams() (cf.{g3d:G3d.getStandard3dInputParams}).
  29. *
  30. * \return void
  31. */
  32. void G3d_setStandard3dInputParams()
  33. {
  34. param = G3d_malloc(sizeof(G3d_paramType));
  35. param->type = G_define_standard_option(G_OPT_R3_TYPE);
  36. param->precision = G_define_standard_option(G_OPT_R3_PRECISION);
  37. param->compression = G_define_standard_option(G_OPT_R3_COMPRESSION);
  38. param->dimension = G_define_standard_option(G_OPT_R3_TILE_DIMENSION);
  39. }
  40. /*----------------------------------------------------------------------------*/
  41. int G3d_getStandard3dParams(int *useTypeDefault, int *type,
  42. int *useLzwDefault, int *doLzw,
  43. int *useRleDefault, int *doRle,
  44. int *usePrecisionDefault, int *precision,
  45. int *useDimensionDefault, int *tileX, int *tileY,
  46. int *tileZ)
  47. {
  48. int doCompress;
  49. *useTypeDefault = *useLzwDefault = *useRleDefault = 0;
  50. *usePrecisionDefault = *useDimensionDefault = 0;
  51. G3d_initDefaults();
  52. if (strcmp(param->type->answer, "double") == 0)
  53. *type = DCELL_TYPE;
  54. else if (strcmp(param->type->answer, "float") == 0)
  55. *type = FCELL_TYPE;
  56. else {
  57. *type = G3d_getFileType();
  58. *useTypeDefault = 1;
  59. }
  60. G3d_getCompressionMode(&doCompress, doLzw, doRle, precision);
  61. if (strcmp(param->precision->answer, "default") != 0) {
  62. if (strcmp(param->precision->answer, "max") == 0)
  63. *precision = -1;
  64. else if ((sscanf(param->precision->answer, "%d", precision) != 1) ||
  65. (*precision < 0)) {
  66. G3d_error(_("G3d_getStandard3dParams: precision value invalid"));
  67. return 0;
  68. }
  69. }
  70. else
  71. *usePrecisionDefault = 1;
  72. if (strcmp(param->compression->answer, "default") != 0) {
  73. if (strcmp(param->compression->answer, "rle") == 0) {
  74. *doRle = G3D_USE_RLE;
  75. *doLzw = G3D_NO_LZW;
  76. }
  77. else if (strcmp(param->compression->answer, "lzw") == 0) {
  78. *doRle = G3D_NO_RLE;
  79. *doLzw = G3D_USE_LZW;
  80. }
  81. else if (strcmp(param->compression->answer, "rle+lzw") == 0) {
  82. *doRle = G3D_USE_RLE;
  83. *doLzw = G3D_USE_LZW;
  84. }
  85. else {
  86. *doRle = G3D_NO_RLE;
  87. *doLzw = G3D_NO_LZW;
  88. }
  89. }
  90. else
  91. *useLzwDefault = *useRleDefault = 1;
  92. G3d_getTileDimension(tileX, tileY, tileZ);
  93. if (strcmp(param->dimension->answer, "default") != 0) {
  94. if (sscanf(param->dimension->answer, "%dx%dx%d",
  95. tileX, tileY, tileZ) != 3) {
  96. G3d_error(_("G3d_getStandard3dParams: tile dimension value invalid"));
  97. return 0;
  98. }
  99. }
  100. else
  101. *useDimensionDefault = 1;
  102. G3d_free(param);
  103. return 1;
  104. }
  105. /*----------------------------------------------------------------------------*/
  106. static struct Option *windowParam = NULL;
  107. void G3d_setWindowParams(void)
  108. {
  109. windowParam = G_define_option();
  110. windowParam->key = "region3";
  111. windowParam->type = TYPE_STRING;
  112. windowParam->required = NO;
  113. windowParam->multiple = NO;
  114. windowParam->answer = NULL;
  115. windowParam->description = _("Window replacing the default");
  116. }
  117. /*----------------------------------------------------------------------------*/
  118. char *G3d_getWindowParams(void)
  119. {
  120. if (windowParam == NULL)
  121. return NULL;
  122. if (windowParam->answer == NULL)
  123. return NULL;
  124. if (strcmp(windowParam->answer, G3D_WINDOW_ELEMENT) == 0)
  125. return G_store(G3D_WINDOW_ELEMENT);
  126. return G_store(windowParam->answer);
  127. }