iclass_bands.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*!
  2. \file lib/imagery/iclass_bands.c
  3. \brief Imagery library - functions for wx.iclass
  4. Computation based on training areas for supervised classification.
  5. Based on i.class module (GRASS 6).
  6. Reading bands cell category values.
  7. Copyright (C) 1999-2007, 2011 by the GRASS Development Team
  8. This program is free software under the GNU General Public License
  9. (>=v2). Read the file COPYING that comes with GRASS for details.
  10. \author David Satnik, Central Washington University (original author)
  11. \author Markus Neteler <neteler itc.it> (i.class module)
  12. \author Bernhard Reiter <bernhard intevation.de> (i.class module)
  13. \author Brad Douglas <rez touchofmadness.com>(i.class module)
  14. \author Glynn Clements <glynn gclements.plus.com> (i.class module)
  15. \author Hamish Bowman <hamish_b yahoo.com> (i.class module)
  16. \author Jan-Oliver Wagner <jan intevation.de> (i.class module)
  17. \author Anna Kratochvilova <kratochanna gmail.com> (rewriting for wx.iclass)
  18. \author Vaclav Petras <wenzeslaus gmail.com> (rewriting for wx.iclass)
  19. */
  20. #include <grass/imagery.h>
  21. #include <grass/raster.h>
  22. #include "iclass_local_proto.h"
  23. /*!
  24. \brief Open and allocate space for the group band files.
  25. \param refer pointer to band files structure
  26. \param[out] band_buffer buffer to read one row of each band
  27. \param[out] band_fd band files descriptors
  28. */
  29. void open_band_files(struct Ref *refer, CELL *** band_buffer, int **band_fd)
  30. {
  31. int n, nbands;
  32. char *name, *mapset;
  33. G_debug(3, "open_band_files()");
  34. /* allocate row buffers and open raster maps */
  35. nbands = refer->nfiles;
  36. *band_buffer = (CELL **) G_malloc(nbands * sizeof(CELL *));
  37. *band_fd = (int *)G_malloc(nbands * sizeof(int));
  38. for (n = 0; n < nbands; n++) {
  39. (*band_buffer)[n] = Rast_allocate_c_buf();
  40. name = refer->file[n].name;
  41. mapset = refer->file[n].mapset;
  42. (*band_fd)[n] = Rast_open_old(name, mapset);
  43. }
  44. }
  45. /*!
  46. \brief Close and free space for the group band files.
  47. \param refer pointer to band files structure
  48. \param band_buffer buffer to read one row of each band
  49. \param band_fd band files descriptors
  50. */
  51. void close_band_files(struct Ref *refer, CELL ** band_buffer, int *band_fd)
  52. {
  53. int n, nbands;
  54. G_debug(3, "close_band_files()");
  55. nbands = refer->nfiles;
  56. for (n = 0; n < nbands; n++) {
  57. G_free(band_buffer[n]);
  58. Rast_close(band_fd[n]);
  59. }
  60. G_free(band_buffer);
  61. G_free(band_fd);
  62. }
  63. /*!
  64. \brief Read one row of each band.
  65. \param band_buffer buffer to read one row of each band
  66. \param band_fd band files descriptors
  67. \param nbands number of band files
  68. \param row data row
  69. */
  70. void read_band_row(CELL ** band_buffer, int *band_fd, int nbands, int row)
  71. {
  72. int i;
  73. G_debug(5, "read_band_row(): row = %d", row);
  74. for (i = 0; i < nbands; i++)
  75. Rast_get_c_row_nomask(band_fd[i], band_buffer[i], row);
  76. }