imagerylib.dox 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. /*! \page imagerylib GRASS Imagery Library
  2. <!-- doxygenized from "GRASS 5 Programmer's Manual"
  3. by M. Neteler 2/2004
  4. -->
  5. \section imageryintro Introduction to Imagery Library
  6. The <I>Imagery Library</I> was created for version 3.0 of GRASS to
  7. support integrated image processing directly in GRASS. It contains
  8. routines that provide access to the <I>group</I> database structure
  9. which was also introduced in GRASS 3.0 for the same purpose. It is
  10. assumed that the reader has read Database_Structure for a general
  11. description of GRASS databases, \ref Image_Data_Groups for a description of
  12. imagery groups, and \ref Raster_Maps for details about map layers in
  13. GRASS. The routines in the \ref Imagery_Library are presented in functional
  14. groupings, rather than in alphabetical order. The order of
  15. presentation will, it is hoped, provide a better understanding of how
  16. the library is to be used, as well as show the interrelationships
  17. among the various routines. Note that a good way to understand how to
  18. use these routines is to look at the source code for GRASS modules
  19. which use them. Most routines in this library require that the header
  20. file <grass/imagery.h> be included in any code using these
  21. routines. Therefore, programmers should always include this file when
  22. writing code using routines from this library:
  23. \verbatim
  24. #include <grass/imagery.h>
  25. \endverbatim
  26. <P>
  27. <B>Note.</B> All routines and global variables in this library,
  28. documented or undocumented, start with the prefix <B>I_.</B> To avoid
  29. name conflicts, programmers should not create variables or routines in
  30. their own modules which use this prefix.
  31. \subsection Group_Processing Group Processing
  32. The group is the key database structure which permits integration of
  33. image processing in GRASS. As GRASS during import splits up multiband
  34. image into separate rasters, groups allow to keep them together to
  35. ease workflows. Groups do not store data themselves, only references
  36. to group members and auxilary data.
  37. \subsection Finding_Groups_in_the_Database Finding Groups in the Database
  38. <P>
  39. Sometimes it is necessary to determine if a given group already
  40. exists. The following routine provides this service:
  41. <P>
  42. int I_find_group() does group exist in current mapset?
  43. int I_find_group2() does group exist in the specified mapset?
  44. Returns 1 if the specified <B>group</B> exists in the mapset;
  45. 0 otherwise.
  46. \subsection REF_File REF File
  47. <P>
  48. These routines provide access to the information contained in the REF
  49. file for groups and subgroups, as well as routines to update this
  50. information. They use the <I>Ref</I> structure, which is defined in
  51. the <grass/imagery.h> header file; see \ref Imagery_Library_Data_Structures.
  52. <P>
  53. The contents of the REF file are read or updated by the following
  54. routines:
  55. <P>
  56. int I_get_group_ref() read group REF file from current mapset
  57. int I_get_group_ref2() read group REF file from the specified mapset
  58. Reads the contents of the REF file for the specified <B>group</B> into
  59. the <B>ref</B> structure.
  60. <P>
  61. Returns 1 if successful; 0 otherwise (but no error messages are printed).
  62. <P>
  63. int I_put_group_ref() write group REF file
  64. Writes the contents of the <B>ref</B> structure to the REF file for
  65. the specified <B>group.</B>
  66. <P>
  67. Returns 1 if successful; 0 otherwise (and prints a diagnostic error).
  68. <P>
  69. <B>Note.</B> This routine will create the <B>group</B>, if it does not
  70. already exist.
  71. <P>
  72. int I_get_subgroup_ref() read subgroup REF file in current mapset
  73. int I_get_subgroup_ref2() read subgroup REF file in the specified mapset
  74. Reads the contents of the REF file for the specified <B>subgroup</B>
  75. of the specified <B>group</B> into the <B>ref</B> structure.
  76. <P>
  77. Returns 1 if successful; 0 otherwise (but no error messages are printed).
  78. <P>
  79. int I_put_subgroup_ref() write subgroup REF file
  80. Writes the contents of the <B>ref</B> structure into the REF file for
  81. the specified <B>subgroup</B> of the specified <B>group.</B>
  82. <P>
  83. Returns 1 if successful; 0 otherwise (and prints a diagnostic error).
  84. <P>
  85. <B>Note.</B> This routine will create the <B>subgroup</B>, if it does
  86. not already exist.
  87. <P>
  88. These next routines manipulate the <I>Ref</I> structure:
  89. <P>
  90. int I_init_group_ref() initialize Ref structure
  91. This routine initializes the <B>ref</B> structure for other library
  92. calls which require a <I>Ref</I> structure. This routine must be
  93. called before any use of the structure can be made.
  94. <P>
  95. <B>Note.</B> The routines I_get_group_ref() and I_get_subgroup_ref() call
  96. this routine automatically.
  97. <P>
  98. int I_add_file_to_group_ref() add file name to Ref structure
  99. This routine adds the file <B>name</B> and <B>mapset</B> to the list
  100. contained in the <B>ref</B> structure, if it is not already in the
  101. list. The <B>ref</B> structure must have been properly
  102. initialized. This routine is used by programs, such as
  103. <I>i.maxlik</I>, to add to the group new raster files created from
  104. files already in the group.
  105. <P>
  106. Returns the index into the <I>file</I> array within the <B>ref</B>
  107. structure for the file after insertion; see \ref
  108. Imagery_Library_Data_Structures.
  109. <P>
  110. int I_transfer_group_ref_file() copy Ref lists
  111. This routine is used to copy file names from one <I>Ref</I> structure
  112. to another. The name and mapset for file <B>n</B> from the <B>src</B>
  113. structure are copied into the <B>dst</B> structure (which must be
  114. properly initialized).
  115. <P>
  116. For example, the following code copies one <I>Ref</I> structure to another:
  117. \verbatim
  118. struct Ref src,dst;
  119. int n;
  120. /* some code to get information into src */
  121. ...
  122. I_init_group_ref(&dst);
  123. for (n = 0; n < src.nfiles; n++)
  124. I_transfer_group_ref_file (&src, n, &dst);
  125. \endverbatim
  126. <P>
  127. This routine is used by <I>g.gui.gcp</I> to create the REF file for a
  128. subgroup.
  129. <P>
  130. int I_free_group_ref() free Ref structure
  131. This routine frees memory allocated to the <B>ref</B> structure.
  132. \subsection TARGET_File TARGET File
  133. <P>
  134. The following two routines read and write the TARGET file.
  135. <P>
  136. int I_get_target() read target information
  137. Reads the target <B>location</B> and <B>mapset</B> from the TARGET
  138. file for the specified group. Returns 1 if successful; 0 otherwise
  139. (and prints a diagnostic error). This routine is used by
  140. <I>g.gui.gcp</I> and <I>i.rectify</I> and probably should not be used
  141. by other programs.
  142. <P>
  143. <B>Note.</B> This routine does <B>not</B> validate the target information.
  144. <P>
  145. int I_put_target() write target information
  146. Writes the target <B>location</B> and <B>mapset</B> to the TARGET file
  147. for the specified <B>group.</B> Returns 1 if successful; 0 otherwise
  148. (but no error messages are printed).
  149. <P>
  150. This routine is used by <I>i.target</I> and probably should not be
  151. used by other programs.
  152. <P>
  153. <B>Note.</B> This routine does <B>not</B> validate the target
  154. information.
  155. \subsection POINTS_File POINTS File
  156. <P>
  157. The following routines read and write the POINTS file, which contains
  158. the image registration control points. This file is created and
  159. updated by the module <I>g.gui.gcp</I>,and read by <I>i.rectify.</I>
  160. <P>
  161. These routines use the <I>Control_Points</I> structure, which is
  162. defined in the <grass/imagery.h> <I>header file</I>; see \ref
  163. Imagery_Library_Data_Structures.
  164. <P>
  165. <B>Note.</B> The interface to the <I>Control_Points</I> structure
  166. provided by the routines below is incomplete. A routine to initialize
  167. the structure is needed.
  168. <P>
  169. int I_get_control_points() read group control points
  170. Reads the control points from the POINTS file for the <B>group</B>
  171. into the <B>cp</B> structure. Returns 1 if successful; 0 otherwise
  172. (and prints a diagnostic error).
  173. <P>
  174. <B>Note.</B> An error message is printed if the POINTS file is
  175. invalid, or does not exist.
  176. <P>
  177. int I_new_control_point() add new control point
  178. Once the control points have been read into the <B>cp</B> structure,
  179. this routine adds new points to it. The new control point is given by
  180. <B>e1</B> (column) and <B>n1</B> (row) on the image, and the <B>e2</B>
  181. (east) and <B>n2</B> (north) for the target database. The value of
  182. <B>status</B> should be 1 if the point is a valid point; 0
  183. otherwise.Use of this routine implies that the point is probably good,
  184. so status should be set to 1.
  185. <P>
  186. int I_put_control_points() write group control points
  187. Writes the control points from the <B>cp</B> structure to the POINTS
  188. file for the specified group.
  189. <P>
  190. <B>Note.</B> Points in <B>cp</B> with a negative <I>status</I> are not
  191. written to the POINTS file.
  192. \subsection Loading_the_Imagery_Library Loading the Imagery Library
  193. <P>
  194. The library is loaded by specifying $(IMAGERYLIB) in the
  195. Makefile. The following example is a complete Makefile which
  196. compiles code that uses this library:
  197. <P>
  198. <B>Makefile for $(IMAGERYLIB)</B>
  199. \verbatim
  200. #UPDATE THIS EXAMPLE!!
  201. OBJ = main.o sub1.o sub2.o
  202. PGM: $(OBJ) $(IMAGERYLIB) $(GISLIB)
  203. $(CC) $(LDFLAGS) -o $@ $(OBJ) $(IMAGERYLIB) $(GISLIB)
  204. $(IMAGERYLIB): # in case the library changes
  205. $(GISLIB): # in case the library changes
  206. \endverbatim
  207. <B>Note.</B> This library must be loaded with $(GISLIB) since it uses
  208. routines from that library. See \ref GIS_Library or details on that
  209. library. See \ref Compiling_and_Installing_GRASS_Modules for a complete
  210. discussion of Makefiles.
  211. \section Imagery_Library_Data_Structures Imagery Library Data Structures
  212. Some of the data structures in the <grass/imagery.h> header file are
  213. described below.
  214. \subsection struct_Ref struct Ref
  215. <P>
  216. The <I>Ref</I> structure is used to hold the information from the REF
  217. file for groups and subgroups. The structure is:
  218. \verbatim
  219. struct Ref
  220. {
  221. int nfiles; /* number of REF files */
  222. struct Ref_Files
  223. {
  224. char name[INAME_LEN]; /* REF file name */
  225. char mapset[INAME_LEN]; /* REF file mapset */
  226. } *file;
  227. struct Ref_Color
  228. {
  229. unsigned char *table; /* color table for min-max values */
  230. unsigned char *index; /* data translation index */
  231. unsigned char *buf; /* data buffer for reading color file */
  232. int fd; /* for image i/o */
  233. CELL min, max; /* min,max CELL values */
  234. int n; /* index into Ref_Files */
  235. } red, grn, blu;
  236. };
  237. \endverbatim
  238. The <I>Ref</I> structure has <I>nfiles</I> (the number of raster
  239. files), <I>file</I> (the name and mapset of each file), and
  240. <I>red,grn,blu</I> (color information for the group or subgroup) Note:
  241. The red,grn,blu elements are expected to change as the imagery code
  242. develops. Do not reference them. Pretend they do not exist.
  243. <P>
  244. There is no function interface to the <I>nfiles</I> and <I>file</I>
  245. elements in the structure. This means that the programmer must
  246. reference the elements of the structure directly (The nfiles and file
  247. elements are not expected to change in the future). The name and
  248. <I>mapset for the i th file are file[i].name, and file[i].mapset.</I>
  249. <P>
  250. For example, to print out the names of the raster files in the structure:
  251. \verbatim
  252. int i;
  253. struct Ref ref;
  254. ...
  255. /* some code to get the REF file for a group into <B>ref</B> */
  256. ...
  257. for (i = 0; i<ref.nfiles; i++)
  258. fprintf(stdout, "%s in %s\n", ref.file[i].name, ref.file[i].mapset);
  259. \endverbatim
  260. \subsection struct_Control_Points struct Control_Points
  261. The <I>Control_Points</I> structure is used to hold the control points
  262. from the group POINTS file. The structure is:
  263. \verbatim
  264. struct
  265. Control_Points
  266. {
  267. int count; /* number of control points */
  268. double *e1; /* image east (column) */
  269. double *n1; /* image north (row) */
  270. double *e2; /* target east */
  271. double *n2; /* target north */
  272. int *status; /* status of control point */
  273. };
  274. \endverbatim
  275. The number of control points is <I>count.</I>
  276. <P>
  277. Control point <I>i</I> is <I>e1</I> [i], <I>n1</I> [i], <I>e2</I> [i],
  278. <I>n2</I> [i], and its status is <I>status</I> [i].
  279. */