g3dparam.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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_option();
  36. param->type->key = "type";
  37. param->type->type = TYPE_STRING;
  38. param->type->required = NO;
  39. param->type->multiple = NO;
  40. param->type->answer = "default";
  41. param->type->options = "default,double,float";
  42. param->type->description = _("Data type used in the output file");
  43. param->precision = G_define_option();
  44. param->precision->key = "precision";
  45. param->precision->type = TYPE_STRING;
  46. param->precision->required = NO;
  47. param->precision->multiple = NO;
  48. param->precision->answer = "default";
  49. param->precision->description =
  50. _("Precision used in the output file (default, max, or 0 to 52)");
  51. param->compression = G_define_option();
  52. param->compression->key = "compression";
  53. param->compression->type = TYPE_STRING;
  54. param->compression->required = NO;
  55. param->compression->multiple = NO;
  56. param->compression->answer = "default";
  57. param->compression->options = "default,rle,none";
  58. param->compression->description =
  59. _("The compression method used in the output file");
  60. param->dimension = G_define_option();
  61. param->dimension->key = "tiledimension";
  62. param->dimension->type = TYPE_STRING;
  63. param->dimension->required = NO;
  64. param->dimension->multiple = NO;
  65. param->dimension->key_desc = "XxYxZ";
  66. param->dimension->answer = "default";
  67. param->dimension->description =
  68. _("The dimensions of the tiles used in the output file");
  69. }
  70. /*----------------------------------------------------------------------------*/
  71. int G3d_getStandard3dParams(int *useTypeDefault, int *type,
  72. int *useLzwDefault, int *doLzw,
  73. int *useRleDefault, int *doRle,
  74. int *usePrecisionDefault, int *precision,
  75. int *useDimensionDefault, int *tileX, int *tileY,
  76. int *tileZ)
  77. {
  78. int doCompress;
  79. *useTypeDefault = *useLzwDefault = *useRleDefault = 0;
  80. *usePrecisionDefault = *useDimensionDefault = 0;
  81. G3d_initDefaults();
  82. if (strcmp(param->type->answer, "double") == 0)
  83. *type = DCELL_TYPE;
  84. else if (strcmp(param->type->answer, "float") == 0)
  85. *type = FCELL_TYPE;
  86. else {
  87. *type = G3d_getFileType();
  88. *useTypeDefault = 1;
  89. }
  90. G3d_getCompressionMode(&doCompress, doLzw, doRle, precision);
  91. if (strcmp(param->precision->answer, "default") != 0) {
  92. if (strcmp(param->precision->answer, "max") == 0)
  93. *precision = -1;
  94. else if ((sscanf(param->precision->answer, "%d", precision) != 1) ||
  95. (*precision < 0)) {
  96. G3d_error(_("G3d_getStandard3dParams: precision value invalid"));
  97. return 0;
  98. }
  99. }
  100. else
  101. *usePrecisionDefault = 1;
  102. if (strcmp(param->compression->answer, "default") != 0) {
  103. if (strcmp(param->compression->answer, "rle") == 0) {
  104. *doRle = G3D_USE_RLE;
  105. *doLzw = G3D_NO_LZW;
  106. }
  107. else if (strcmp(param->compression->answer, "lzw") == 0) {
  108. *doRle = G3D_NO_RLE;
  109. *doLzw = G3D_USE_LZW;
  110. }
  111. else if (strcmp(param->compression->answer, "rle+lzw") == 0) {
  112. *doRle = G3D_USE_RLE;
  113. *doLzw = G3D_USE_LZW;
  114. }
  115. else {
  116. *doRle = G3D_NO_RLE;
  117. *doLzw = G3D_NO_LZW;
  118. }
  119. }
  120. else
  121. *useLzwDefault = *useRleDefault = 1;
  122. G3d_getTileDimension(tileX, tileY, tileZ);
  123. if (strcmp(param->dimension->answer, "default") != 0) {
  124. if (sscanf(param->dimension->answer, "%dx%dx%d",
  125. tileX, tileY, tileZ) != 3) {
  126. G3d_error(_("G3d_getStandard3dParams: tile dimension value invalid"));
  127. return 0;
  128. }
  129. }
  130. else
  131. *useDimensionDefault = 1;
  132. G3d_free(param);
  133. return 1;
  134. }
  135. /*----------------------------------------------------------------------------*/
  136. static struct Option *windowParam = NULL;
  137. void G3d_setWindowParams(void)
  138. {
  139. windowParam = G_define_option();
  140. windowParam->key = "region3";
  141. windowParam->type = TYPE_STRING;
  142. windowParam->required = NO;
  143. windowParam->multiple = NO;
  144. windowParam->answer = NULL;
  145. windowParam->description = _("Window replacing the default");
  146. }
  147. /*----------------------------------------------------------------------------*/
  148. char *G3d_getWindowParams(void)
  149. {
  150. if (windowParam == NULL)
  151. return NULL;
  152. if (windowParam->answer == NULL)
  153. return NULL;
  154. if (strcmp(windowParam->answer, G3D_WINDOW_ELEMENT) == 0)
  155. return G_store(G3D_WINDOW_ELEMENT);
  156. return G_store(windowParam->answer);
  157. }