init_caps.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* the caps are being built by reading thru the original grid3 file
  2. ** and drawn to the screen not being stored at this time
  3. */
  4. #include <grass/gis.h>
  5. #include "vizual.h"
  6. #include <grass/raster3d.h>
  7. /*
  8. #define DEBUG1
  9. */
  10. int init_caps(D_Cap, g3reg)
  11. struct Cap *D_Cap;
  12. RASTER3D_Region *g3reg;
  13. /* this subroutine only needs to be called once */
  14. {
  15. int min; /*the smallest dimension */
  16. int dim1, dim2; /* the two largest dimensions */
  17. /* In order to determine how much memory to malloc for a D_buff
  18. ** need to determine the largest 2 dimensions (x,y or z)
  19. ** this is done by finding the minimum and using the other two */
  20. if (g3reg->cols < g3reg->rows) {
  21. dim1 = g3reg->rows;
  22. min = g3reg->cols;
  23. }
  24. else {
  25. dim1 = g3reg->cols;
  26. min = g3reg->rows;
  27. }
  28. if (g3reg->depths < min)
  29. dim2 = min;
  30. else
  31. dim2 = g3reg->depths;
  32. #ifdef DEBUG1
  33. fprintf(stderr, "dim1 = %d dim2 = %d \n", dim1, dim2);
  34. #endif
  35. /* NOTE: code only written for floats at this time */
  36. /* malloc memory for buffer that will hold slice of data */
  37. if ((D_Cap->D_buff =
  38. (float *)G_malloc(dim1 * dim2 * sizeof(float))) == NULL) {
  39. fprintf(stderr, "ERROR: in mallocing memory for D_Cap->D_buff\n");
  40. return (-1);
  41. }
  42. return (1);
  43. }