test_main.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <math.h>
  5. #include <grass/raster3d.h>
  6. #include <grass/gis.h>
  7. #include <grass/raster.h>
  8. #include <grass/vector.h>
  9. #include <grass/glocale.h>
  10. #include "r3flow_structs.h"
  11. #include "flowline.h"
  12. #include "interpolate.h"
  13. static void test_interpolation(RASTER3D_Region * region,
  14. RASTER3D_Map ** input_maps, double north,
  15. double east, double top)
  16. {
  17. double interpolated[3];
  18. if (interpolate_velocity(region, input_maps, north, east, top,
  19. &interpolated[0], &interpolated[1],
  20. &interpolated[2]) < 0) {
  21. fprintf(stdout, "return=-1\n");
  22. }
  23. else
  24. fprintf(stdout, "return=0\nvalues=%.10f,%.10f,%.10f\n",
  25. interpolated[0], interpolated[1], interpolated[2]);
  26. }
  27. int main(int argc, char *argv[])
  28. {
  29. int i;
  30. struct GModule *module;
  31. struct Option *test_opt, *coordinates_opt, *input_opt;
  32. RASTER3D_Region region;
  33. RASTER3D_Map *input_3drasters[3];
  34. double coordinates[3];
  35. G_gisinit(argv[0]);
  36. module = G_define_module();
  37. G_add_keyword(_("raster3d"));
  38. G_add_keyword(_("voxel"));
  39. G_add_keyword(_("flowline"));
  40. module->description = _("Testing flow lines.");
  41. test_opt = G_define_option();
  42. test_opt->key = "test";
  43. test_opt->required = YES;
  44. test_opt->type = TYPE_STRING;
  45. test_opt->options = "interpolation,gradient";
  46. test_opt->description = "Select what is tested";
  47. coordinates_opt = G_define_option();
  48. coordinates_opt->key = "coordinates";
  49. coordinates_opt->required = NO;
  50. coordinates_opt->type = TYPE_DOUBLE;
  51. coordinates_opt->multiple = YES;
  52. coordinates_opt->description = "x,y,z coordinates";
  53. input_opt = G_define_standard_option(G_OPT_R3_INPUTS);
  54. input_opt->required = NO;
  55. if (G_parser(argc, argv))
  56. exit(EXIT_FAILURE);
  57. Rast3d_init_defaults();
  58. Rast3d_get_window(&region);
  59. if (strcmp(test_opt->answer, "interpolation") == 0) {
  60. if (input_opt->answers) {
  61. for (i = 0; i < 3; i++) {
  62. input_3drasters[i] =
  63. Rast3d_open_cell_old(input_opt->answers[i],
  64. G_find_raster3d(input_opt->
  65. answers[i], ""),
  66. &region, RASTER3D_TILE_SAME_AS_FILE,
  67. RASTER3D_USE_CACHE_DEFAULT);
  68. if (input_3drasters[i] == NULL)
  69. Rast3d_fatal_error(_("Unable to open 3D raster map <%s>"),
  70. input_opt->answers[i]);
  71. }
  72. }
  73. else
  74. G_fatal_error("No input map for interpolation test");
  75. if (coordinates_opt->answers) {
  76. for (i = 0; i < 3; i++) {
  77. if (coordinates_opt->answers[i]) {
  78. coordinates[i] = atof(coordinates_opt->answers[i]);
  79. }
  80. else
  81. G_fatal_error("Provide 3 coordinates");
  82. }
  83. }
  84. else
  85. G_fatal_error("No coordinates for interpolation test");
  86. test_interpolation(&region, input_3drasters, coordinates[1],
  87. coordinates[0], coordinates[2]);
  88. }
  89. return EXIT_SUCCESS;
  90. }