lib.dox 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759
  1. /*! \page g3dlib GRASS Grid3D raster volume Library
  2. <!-- doxygenized from "GRASS 5 Programmer's Manual"
  3. by M. Neteler 5/2004, 8/2005
  4. -->
  5. \section g3dintro Grid3D raster volume Library
  6. <P>
  7. Authors: Roman Waupotitsch and Michael Shapiro, Helena Mitasova,
  8. Bill Brown, Lubos Mitas, Jaro Hofierka,
  9. Minor modification, code cleanup and test suite by Soeren Gebbert
  10. <b>Overview</b>
  11. The Grid3D raster volume Library is used for the r3.* and vector
  12. volume tools. The G3D library uses a tile cache based approach to store floating point
  13. values in abritrary order in a volume. The coordinate system of a volume is
  14. column and row compatible to the raster library and counts from the bottom to the top
  15. of the cube.
  16. <center>
  17. <img src=g3d_volume_layout.png border=0><BR>
  18. <table border=0 width=700>
  19. <tr><td><center>
  20. <i>The volume coordinate system and tile layout of the G3D library</i>
  21. </center></td></tr>
  22. </table>
  23. </center>
  24. \section Directory_Structure Directory Structure
  25. <P>
  26. The file format consists of a mapset element <EM>grid3</EM> which contains a
  27. directory for every map. The elements for each map are
  28. <P>
  29. \verbatim
  30. 3d region file
  31. color file (color)
  32. categories file (cats)
  33. range file (range)
  34. timestamp file /* not yet implemented */
  35. cell file (cell)
  36. header file (cellhd)
  37. a directory containing display files (dsp)
  38. \endverbatim
  39. <P>
  40. There is also a <EM>colr2</EM> mechanism provided. <EM>colr2</EM> color tables
  41. are stored in <EM>grid3/colr2/MAPSET/MAP</EM>.
  42. <P>
  43. Note: color, categories, and the range can be used in the same way as in <EM>2d</EM>
  44. GRASS with the exception of reading and writng. <EM>3d</EM> read and write
  45. functions have to be used for this purpose.
  46. \section Data_File_Format Data File Format
  47. <UL>
  48. <LI>Cell-values can be either double or float.
  49. </LI>
  50. <LI>Values are written in XDR-format.
  51. </LI>
  52. <LI>NULL-values are stored in an embedded fashion.
  53. </LI>
  54. <LI>The cell-values are organized in <EM>3d</EM>-tiles.
  55. </LI>
  56. <LI>The tile dimensions can be chosen when a new map is opened.
  57. </LI>
  58. <LI>Every tile of a map has the same dimension except those which overlap the
  59. region boundaries.
  60. </LI>
  61. <LI>Compression is used to store tiles.
  62. </LI>
  63. </UL>
  64. <P>
  65. The data file has the following format:
  66. <P>
  67. \verbatim
  68. xdr_int nofBytesLong;
  69. xdr_int nofBytesUsed;
  70. encoded_long indexOffset;
  71. compressed_tile[] tiles;
  72. compressed_encoded_long[] index;
  73. \endverbatim
  74. <P>
  75. \section Transportability_of_data_file Transportability of data file
  76. <P>
  77. All numbers stored in the data file are either XDR-encoded or encoded by some
  78. other method (for variables of type long only).
  79. <P>
  80. \section Tile_Data_NULL_values Tile Data NULL-values
  81. <P>
  82. G3D uses the same functions as <EM>2d</EM> GRASS to set and test NULL-values. The
  83. storage in the file is different though. NULL-values are stored with a special
  84. bit-pattern if maximum precision is chosen. They are stored by adding an
  85. additional bit if the precision is smaller.
  86. <P>
  87. \section Tile_Data_Compression Tile Data Compression
  88. <P>
  89. There are three methods of compression provided. The compression
  90. methods can either be those defined by default, set by environment
  91. variables or explicitly set at run-time.
  92. \verbatim
  93. Precision
  94. RLE
  95. \endverbatim
  96. <P>
  97. Precision indicates how many of the mantissa bits should be stored on
  98. file. This number can be any value between 0 and 23 for floats and
  99. between 0 and 52 for doubles. Choosing a small precision is the most
  100. effective way to achieve good compression.
  101. <P>
  102. RLE takes advantage of possible repetitions of the
  103. exponents and the NULL-bit structure. Using RLE does not significantly
  104. increase the running time. If for some tile the non-RLEed version is
  105. smaller in size, RLE is not used for this tile.
  106. <P>
  107. The default and suggested setting is to use precision and RLE.
  108. <P>
  109. Additional compression is achieved by storing the extra NULL-bit in a
  110. separate bit-array. Using this scheme NULL-values need not actually be
  111. represented in the array of cell values. This array is stored together
  112. with the cell-values of the tile.
  113. \section Tile_Cache Tile Cache
  114. <P>
  115. Tiles can either be read and written directly or use an intermediate
  116. cache instead.
  117. <P>
  118. In non-cache mode the application should only use the functions
  119. <P>
  120. int G3d_readTile()
  121. <P>
  122. and
  123. <P>
  124. int G3d_writeTile()
  125. <P>
  126. to read and write tiles. The application can use one tile provided by the map
  127. structure as buffer. See <TT>G3d_getTilePtr()</TT>.
  128. <P>
  129. In cache mode the application can access cell-values directly by their
  130. coordinates. The corresponding functions are
  131. <P>
  132. int G3d_getValue()
  133. <P>
  134. and
  135. <P>
  136. int G3d_putValue()
  137. <P>
  138. and their corresponding typed versions.
  139. <BR>
  140. <P>
  141. If the map is new then in addition to the memory-cache a file-cache is provided.
  142. This allows the application to write the cell-values in any arbitrary order.
  143. Tiles are written (flushed) to the data-file either at closing time or if
  144. explicitly requested.
  145. <BR>
  146. <P>
  147. If the map is new <TT>G3d_getValue()</TT> can be used even if the tile which
  148. contains the cell has already been flushed to the data file. In this case the
  149. tile is simply read back into the memory-cache from the data file.
  150. <BR>
  151. <P>
  152. Explicitly flushing tiles can have the advantage that less disk space is
  153. occupied since tiles are stored in a uncompressed fashion in the file-cache.
  154. Flushing tiles explicitly can cause problems with accuracy though if precision
  155. is less than the maximum precision and an already flushed value is used for
  156. computations later in the program.
  157. <BR>
  158. <P>
  159. The type of the cell-values of the tiles in memory can be chosen independently
  160. of the type of the tiles in the file. Here, once again one has to consider
  161. possible problems arising from mixing different precisions.
  162. <BR>
  163. <P>
  164. As an example consider the case where the data is stored in the file with double
  165. precision and the tiles are stored in memory in single precision. Then using
  166. <TT>G3d_getValue()</TT> will actually return a double precision number whose precision
  167. is only 23 bits. It is therefore a good idea to use the types in the memory
  168. consistently.
  169. <BR>
  170. <P>
  171. \section Header_File Header File
  172. <P>
  173. The header file has the following format:
  174. <P>
  175. \verbatim
  176. Proj: 1
  177. Zone: 1
  178. North: 2.0000000000000
  179. South: 0.5000000000000
  180. East: 4.0000000000000
  181. West: 3.0000000000000
  182. Top: 6.0000000000000
  183. Bottom: 5.0000000000000
  184. nofRows: 30
  185. nofCols: 20
  186. nofDepths: 14
  187. e-w resol: 0.05
  188. n-s resol: 0.05
  189. t-b resol: 0.071428571
  190. TileDimensionX: 8
  191. TileDimensionY: 8
  192. TileDimensionZ: 8
  193. CellType: double
  194. useCompression: 1
  195. useRle: 1
  196. Precision: -1
  197. nofHeaderBytes: 12
  198. useXdr: 1
  199. hasIndex: 1
  200. Units: none
  201. \endverbatim
  202. <P>
  203. Except for the first 14 fields the entries of the header file should
  204. not be modified. The precision value -1 indicates that maximum
  205. precision is used.
  206. <BR>
  207. <P>
  208. Binary files not in G3D format can be read by the library. The
  209. following actions have to be taken:
  210. <P>
  211. Make a new map directory in the <EM>grid3</EM> element of the mapset (say <EM>mymap</EM>).
  212. Copy the file into <EM>mymap/cell</EM> and generate a header file <EM>mymap/cellhd</EM>.
  213. <P>
  214. In the following example the relevant values of <EM>mymap/cellhd</EM> are shown:
  215. <P>
  216. \verbatim
  217. TileDimensionX: A
  218. TileDimensionY: B
  219. TileDimensionZ: C
  220. useCompression: 0
  221. useRle: 0
  222. Precision: -1
  223. nofHeaderBytes: X
  224. useXdr: 0
  225. hasIndex: 0
  226. \endverbatim
  227. <P>
  228. The values of <EM>A</EM>, <EM>B</EM>, and <EM>C</EM> have to be chosen
  229. according to one of the following patterns:
  230. <P>
  231. \verbatim
  232. A &gt;= 1, B == 1, C == 1, or
  233. A &gt;= nofRows, B &gt;= 1, C == 1, or
  234. A &gt;= nofRows, B &gt;= nofCols, C &gt;= 1.
  235. \endverbatim
  236. <P>
  237. A larger tile size reduces the number of tile-reads. If in the third pattern
  238. <EM>C</EM> is chosen larger than or equal to <EM>nofDepths</EM>, the entire region is
  239. considered one large tile.
  240. <P>
  241. The value <EM>nofHeaderBytes</EM> indicates the offset in the file to the first
  242. data entry.
  243. <P>
  244. For performance reasons it is a good idea to use function
  245. <TT>G3d_retile()</TT> before using the file in other applications.
  246. <P>
  247. \section Region_Structure Region Structure
  248. <P>
  249. \verbatim
  250. typedef struct{
  251. double north, south;
  252. double east, west;
  253. double top, bottom;
  254. int rows, cols, depths;/* data dimensions in cells */
  255. double ns_res, ew_res, tb_res;
  256. int proj; /* Projection (see gis.h) */
  257. int zone; /* Projection zone (see gis.h) */
  258. } G3D\_Region;
  259. \endverbatim
  260. <P>
  261. \section Windows Windows
  262. <P>
  263. Window capability similar to that of <EM>2d</EM> GRASS is provided (compare
  264. Region). Additional features are the window for the third dimension
  265. as well as the possibility to choose a different window for every map. The
  266. window can be specified at the time of opening an old map. It can be modified
  267. at any time later in the program. The resampling method can be the default
  268. nearest neighbor method as well as an application provided method.
  269. <BR>
  270. <P>
  271. The default <EM>3d</EM> window file is <EM>WIND3</EM> located in the mapset.
  272. Application programs should use <TT>G3d_useWindowParams()</TT> to allow the
  273. user to overwrite this default.
  274. <P>
  275. The window file has the following format:
  276. <P>
  277. \verbatim
  278. Proj: 1
  279. Zone: 1
  280. North: 2.0
  281. South: 0.5
  282. East: 4.0
  283. West: 3.0
  284. Top: 5.0
  285. Bottom: 6.0
  286. nofRows: 30
  287. nofCols: 20
  288. nofDepths: 14
  289. e-w resol: 0.05000000000000000
  290. n-s resol: 0.05000000000000000
  291. t-b resol: 0.07142857142857142
  292. \endverbatim
  293. <P>
  294. Note: after reading the window file the fields <EM>e-w</EM>, <EM>n-s</EM>, and <EM>t-b</EM>
  295. are recomputed internally.
  296. <P>
  297. A note about windows and caching. Caching is performed on the level of tiles
  298. read from the file. There is no caching performed on resampled data. This is
  299. different from <EM>2d</EM> GRASS since resampling for a specific value is
  300. performed every time it is being accessed.
  301. <P>
  302. \section Masks Masks
  303. <P>
  304. G3D provides a mask for the <EM>3d</EM> region. The mask structure is
  305. automatically initialized at the time the first file is opened. The same
  306. structure is used for all the files. The default for every file is that the
  307. mask is turned off. If masking should be performed, the application program has
  308. to turn on masking explicitly. If masking is turned on for a file, the
  309. cell-values of a tile are automatically checked against the mask. Values which
  310. are masked out, are set to NULL.
  311. <P>
  312. Note: changing the status of masking after one or more tiles have already
  313. been read does not affect the tiles which are already stored in the cache.
  314. <P>
  315. Any arbitrary 3d raster map can be used as mask file: NULL-values are interpreted as
  316. <TT>"mask-out"</TT>, all other values are interpreted as <TT>"don't mask
  317. out"</TT>. Using <EM>r3.mask</EM> to convert a 3d raster map into a mask file instead of
  318. simply copying (or renaming) the directory will significantly reduce to amount
  319. of disk space and the access time for the mask.
  320. <P>
  321. \section Include_File Include File
  322. <P>
  323. Exported G3D constants and structures can be found in <EM>G3d.h</EM>.
  324. <P>
  325. \section G3D_Defaults G3D Defaults
  326. <P>
  327. There are three methods to set default variables. First, the default can be set
  328. at compile time in <EM>g3ddefault.c</EM>. This value has lowest priority.
  329. <P>
  330. Second, the default can be set via an environment variable. Third, the value
  331. can be set explicitly set at run time. This value has highest priority.
  332. <P>
  333. There are also functions provided to query the value.
  334. <P>
  335. \section Cache_Mode Cache Mode
  336. <P>
  337. \subsection Limiting_the_maximum_cache_size Limiting the maximum cache size
  338. <P>
  339. The limit is specified in bytes. It is a limit on the size of cell-data stored
  340. in the cache and does not include the support structure.
  341. <P>
  342. Default G3D_CACHE_SIZE_MAX_DEFAULT. This is currently set to 16meg and can
  343. be changed at compilation time of the library.
  344. <P>
  345. Environment variable G3D_MAX_CACHE_SIZE.
  346. <P>
  347. void G3d_setCacheLimit(int nBytes)Set cache limit
  348. <P>
  349. int G3d_getCacheLimit(int nBytes)Get cache limit
  350. <P>
  351. \subsection Setting_the_cache_size Setting the cache size
  352. <P>
  353. This value specifies the number of tiles stored in the cache. It is the value
  354. used if at opening time of a map G3D_USE_CACHE_DEFAULT is used for the cache
  355. mode. Any other value used at opening time will supersede the default value. A
  356. default value of 0 indicates that non-cache mode should be used by default.
  357. <P>
  358. Default G3D_CACHE_SIZE_DEFAULT. This is currently set to 1000 and can be
  359. changed at compilation time of the library.
  360. <P>
  361. Environment variable G3D_DEFAULT_CACHE_SIZE.
  362. <P>
  363. void G3d_setCacheSize(int nTiles)
  364. <P>
  365. int G3d_getCacheSize()
  366. <P>
  367. \section Compression Compression
  368. \subsection Toggling_compression_mode Toggling compression mode
  369. <P>
  370. This value specifies whether compression should be used while writing a new
  371. map. It does not have any effect on old maps.
  372. <P>
  373. Default G3D_COMPRESSION_DEFAULT. This is set to G3D_COMPRESSION. This
  374. default should not be changed.
  375. <P>
  376. Environment variables G3D_USE_COMPRESSION and G3D_NO_COMPRESSION.
  377. <P>
  378. See functions G3d_setCompressionMode() (cf.
  379. Section 22.3.2.3 ) and G3d_getCompressionMode() (cf. Section 22.3.2.3 ).
  380. <P>
  381. \subsection Toggling_RLE_compression Toggling RLE compression
  382. <P>
  383. This value specifies whether RLE compression should be used (in addition to
  384. precision).
  385. <P>
  386. Default G3D_USE_RLE_DEFAULT. This is currently set to G3D_USE_RLE and can
  387. be changed at compilation time of the library.
  388. <P>
  389. Environment variables G3D_USE_RLE and G3D_NO_RLE.
  390. <P>
  391. See functions G3d_setCompressionMode() (cf.
  392. Section 22.3.2.3) and G3d_getCompressionMode() (cf. Section 22.3.2.3).
  393. \section Setting_the_precision Setting the precision
  394. <P>
  395. This number specifies how many mantissa bits should be used when writing a cell
  396. value. The minimum value is 0. The maximum value is 23 or G3D_MAX_PRECISION
  397. for type FCELL_TYPE, it is 52 or G3D_MAX_PRECISION for type DCELL_TYPE.
  398. <P>
  399. Default G3D_PRECISION_DEFAULT. This is set to G3D_MAX_PRECISION. This
  400. default should not be changed.
  401. <P>
  402. Environment variables G3D_PRECISION and G3D_MAX_PRECISION.
  403. <P>
  404. void G3d_setCompressionMode(int doCompress, int doLzw, int doRle, int
  405. precision) <EM>doCompress</EM> should be one of G3D_NO_COMPRESSION and
  406. G3D_COMPRESSION, <EM>doRle</EM> should be either G3D_NO_RLE or
  407. G3D_USE_RLE, and <EM>precision</EM> should be either G3D_MAX_PRECISION or
  408. a positive integer.
  409. <P>
  410. void G3d_getCompressionMode(int *doCompress, int *doLzw, int *doRle,
  411. int *precision)
  412. <P>
  413. \section Tiles Tiles
  414. \subsection Setting_the_tile_dimensions Setting the tile dimensions
  415. <P>
  416. The dimensions are specified in number of cell.
  417. <P>
  418. Defaults G3D_TILE_X_DEFAULT, G3D_TILE_Y_DEFAULT, and
  419. G3D_TILE_Z_DEFAULT. These are currently set to 8 and can be changed at
  420. compilation time of the library.
  421. <P>
  422. Environment variables G3D_TILE_DIMENSION_X, G3D_TILE_DIMENSION_Y, and
  423. G3D_TILE_DIMENSION_Z.
  424. <P>
  425. void G3d_setTileDimension(int tileX, int tileY, int tileZ)
  426. <P>
  427. void G3d_getTileDimension(int *tileX, int *tileY, int *tileZ)
  428. <P>
  429. \section Setting_the_tile_cell_value_type Setting the tile cell-value type
  430. <P>
  431. Specifies which type is used to write cell-values on file. This type can be
  432. chosen independently of the type used to store cell-values in memory.
  433. <P>
  434. Default G3D_FILE_TYPE_DEFAULT. This is set to DCELL_TYPE. This default
  435. should not be changed.
  436. <P>
  437. Environment variables G3D_WRITE_FLOAT and G3D_WRITE_DOUBLE.
  438. <P>
  439. void G3d_setFileType(int type)
  440. <P>
  441. int G3d_getFileType(int type)
  442. <P>
  443. \section Setting_the_window Setting the window
  444. <P>
  445. The window is set from a <EM>3d</EM> window file.
  446. <P>
  447. The default <EM>3d</EM> window file is <EM>WIND3</EM> located in the current mapset.
  448. <P>
  449. Possible choices for <EM>3d</EM> window files are <EM>name</EM> which refers to a
  450. window file in the <EM>3d</EM> window database located at <EM>windows3d</EM> of the
  451. current mapset; or file names which are identified by a leading <EM><TT>"/"</TT></EM>
  452. or <EM><TT>"."</TT></EM>; or fully qualified
  453. names, i.e. <EM>file@mapset</EM> which refer to window files in the <EM>3d</EM> window
  454. database of mapset. Note, that names <EM>WIND3</EM> and <EM>WIND3@mapset</EM> do not
  455. specify the default window name in the (current)
  456. mapset but rather a window file in the window database of the (current) mapset.
  457. <P>
  458. Environment variable G3D_DEFAULT_WINDOW3D.
  459. <P>
  460. See functions
  461. <P>
  462. <TT>G3d_useWindowParams()</TT>,
  463. <P>
  464. <TT>G3d_setWindow()</TT>, and
  465. <P>
  466. <TT>G3d_setWindowMap()</TT>.
  467. <P>
  468. \section Setting_the_Units Setting the Units
  469. <P>
  470. Default <TT>"none"</TT>.
  471. <P>
  472. No environment variable.
  473. <P>
  474. void G3d_setUnit (unit)
  475. char *unit;
  476. <P>
  477. \section Error_Handling Error Handling: Setting the error function
  478. <P>
  479. This variable specifies the function which is invoked when an error
  480. (not a fatal error) occurs. For example setting the error function to
  481. <TT>G3d_fatalError</TT> simplifies debugging with dbx and also might show
  482. errors which are missed because the application does not check the
  483. return value.
  484. <P>
  485. Default <TT>G3d_skipError</TT>.
  486. <P>
  487. Environment variables G3D_USE_FATAL_ERROR and G3D_USE_PRINT_ERROR.
  488. <P>
  489. void G3d_setErrorFun(void (*fun)(char *))
  490. <P>
  491. The following 3 functions are possible choices for error functions.
  492. <P>
  493. void G3d_skipError(char (*msg)(char *)) This function ignores the
  494. error.
  495. <P>
  496. void G3d_printError(char (*msg)(char *)) This function prints the
  497. error message <EM>msg</EM> to <EM>stderr</EM> and returns.
  498. <P>
  499. void G3d_fatalError(char (*msg)(char *)) This function prints the
  500. error message <EM>msg</EM> to <EM>stderr</EM>, flushes <EM>stdout</EM>
  501. and <EM>stderr</EM>, and terminates the program with a segementation fault.
  502. <P>
  503. \section G3D_Function_Index G3D Function Index
  504. \subsection Opening_and_Closing_G3D_Files Opening and Closing G3D Files
  505. <P>
  506. void *G3d_openCellOld(char *name, char *mapset, G3D_Region *window,
  507. int type, int cache)Opens existing g3d-file <EM>name</EM> in <EM>mapset</EM>.
  508. <P>
  509. Tiles are stored in memory with <EM>type</EM> which must be any of FCELL_TYPE,
  510. DCELL_TYPE, or G3D_TILE_SAME_AS_FILE. <EM>cache</EM> specifies the
  511. cache-mode used and must be either G3D_NO_CACHE, G3D_USE_CACHE_DEFAULT,
  512. G3D_USE_CACHE_X, G3D_USE_CACHE_Y, G3D_USE_CACHE_Z,
  513. G3D_USE_CACHE_XY, G3D_USE_CACHE_XZ, G3D_USE_CACHE_YZ,
  514. G3D_USE_CACHE_XYZ, the result of <TT>G3d_cacheSizeEncode()</TT> (cf.
  515. Section 22.4.6), or any positive integer which
  516. specifies the number of tiles buffered in the cache. <EM>window</EM> sets the
  517. window-region for the map. It is either a pointer to a window structure or
  518. G3D_DEFAULT_WINDOW, which uses the window stored at initialization time or
  519. set via <TT>G3d_setWindow()</TT> (cf. Section 22.4.16).
  520. To modify the window for the map after it has already been opened use
  521. <TT>G3d_setWindowMap()</TT> (cf. Section 22.4.16).
  522. <P>
  523. Returns a pointer to the cell structure ... if successful, NULL ...
  524. otherwise.
  525. <P>
  526. void *G3d_openCellNew(char *name, int type, int cache, G3D_Region
  527. *region)Opens new g3d-file with <EM>name</EM> in the current mapset. Tiles
  528. are stored in memory with <EM>type</EM> which must be one of FCELL_TYPE,
  529. DCELL_TYPE, or G3D_TILE_SAME_AS_FILE. <EM>cache</EM> specifies the
  530. cache-mode used and must be either G3D_NO_CACHE, G3D_USE_CACHE_DEFAULT,
  531. G3D_USE_CACHE_X, G3D_USE_CACHE_Y, G3D_USE_CACHE_Z,
  532. G3D_USE_CACHE_XY, G3D_USE_CACHE_XZ, G3D_USE_CACHE_YZ,
  533. G3D_USE_CACHE_XYZ, the result of <TT>G3d_cacheSizeEncode()</TT> (cf.
  534. Section 22.4.6), or any positive integer which
  535. specifies the number of tiles buffered in the cache. <EM>region</EM> specifies
  536. the 3d region.
  537. <P>
  538. Returns a pointer to the cell structure ... if successful,
  539. NULL ... otherwise.
  540. <P>
  541. void *G3d_openCellNewParam(char *name, int typeIntern, int cache,
  542. G3D_Region *region, int type, int doLzw, int doRle, int precision, int tileX,
  543. int tileY, int tileZ)Opens new g3d-file with <EM>name</EM> in the current
  544. mapset. Tiles are stored in memory with <EM>typeIntern</EM> which must be one of
  545. FCELL_TYPE, DCELL_TYPE, or G3D_TILE_SAME_AS_FILE. <EM>cache</EM> specifies
  546. the cache-mode used and must be either G3D_NO_CACHE,
  547. G3D_USE_CACHE_DEFAULT, G3D_USE_CACHE_X, G3D_USE_CACHE_Y,
  548. G3D_USE_CACHE_Z, G3D_USE_CACHE_XY, G3D_USE_CACHE_XZ,
  549. G3D_USE_CACHE_YZ, G3D_USE_CACHE_XYZ, the result of
  550. <TT>G3d_cacheSizeEncode()</TT> (cf.
  551. Section 22.4.6), or any positive integer which
  552. specifies the number of tiles buffered in the cache. <EM>region</EM> specifies
  553. the 3d region.
  554. <P>
  555. In addition the properties of the new file have to be specified. It is
  556. assumed by default that compression is used. This function first sets the
  557. global default values to the specified values, and then restores the original
  558. global defaults. This function can be used in conjunction with
  559. <TT>G3d_setStandard3dInputParams()</TT> (cf.
  560. Section 22.4.18) and
  561. <TT>G3d_getStandard3dParams()</TT>.
  562. <P>
  563. Returns a pointer to the cell structure ... if successful, NULL ...
  564. otherwise.
  565. <P>
  566. int G3d_closeCell(void *map)Closes g3d-file. If <EM>map</EM> is new
  567. and cache-mode is used for <EM>map</EM> then every tile which is not flushed
  568. before closing is flushed.
  569. <P>
  570. Returns 1 ... if successful, 0 ... otherwise.
  571. <P>
  572. \subsection Reading_and_Writing_Tiles Reading and Writing Tiles
  573. <P>
  574. These functions read or write data directly to the file (after performing the
  575. appropriate compression) without going through the cache. In order to avoid
  576. unexpected side-effects the use of these functions in cache mode is
  577. discouraged.
  578. <P>
  579. int G3d_readTile(void *map, char *tileIndex, int tile, int type)
  580. Reads tile with index <EM>tileIndex</EM> into the <EM>tile</EM> buffer. The cells
  581. are stored with type <EM>type</EM> which must be one of FCELL_TYPE and
  582. DCELL_TYPE. If the tile with <EM>tileIndex</EM> is not stored on the file
  583. corresponding to <EM>map</EM>, and <EM>tileIndex</EM> is a valid index <EM>tile</EM>
  584. is filled with NULL-values.
  585. <P>
  586. Returns
  587. 1 ... if successful,
  588. 0 ... otherwise.
  589. <P>
  590. int G3d_readTileFloat(void *map, char *tileIndex, int tile)
  591. Is equivalent to G3d_readTile (map, tileIndex, tile, FCELL_TYPE).
  592. <P>
  593. int G3d_readTileDouble(void *map, char *tileIndex, int tile)
  594. Is equivalent to G3d_readTile (map, tileIndex, tile, DCELL_TYPE).
  595. <P>
  596. int G3d_writeTile(void *map, char *tileIndex, int tile, int type)
  597. Writes tile with index <EM>tileIndex</EM> to the file corresponding to <EM>map</EM>. It is assumed that the cells in <EM>tile</EM> are of <EM>type</EM> which
  598. must be one of FCELL_TYPE and DCELL_TYPE. The actual type used to write the
  599. tile depends on the type specified at the time when <EM>map</EM> is initialized.
  600. <P>
  601. A tile can only be written once. Subsequent attempts to write the same tile
  602. are ignored.
  603. <P>
  604. Returns
  605. 1 ... if successful,
  606. 2 ... if write request was ignored,
  607. 0 ... otherwise.
  608. <P>
  609. int G3d_writeTileFloat(void *map, char *tileIndex, int tile)
  610. Is equivalent to <TT>G3d_writeTile (map, tileIndex, tile, FCELL_TYPE).</TT>
  611. <P>
  612. int G3d_writeTileDouble(void *map, char *tileIndex, int tile)
  613. Is equivalent to <TT>G3d_writeTile (map, tileIndex, tile, DCELL_TYPE).</TT>
  614. <P>
  615. \subsection Reading_and_Writing_Cells Reading and Writing Cells
  616. <P>
  617. void G3d_getValue(void *map, int x, int y, int z, char *value, int
  618. type) Returns in <EM>*value</EM> the cell-value of the cell with
  619. window-coordinate <EM>(x, y, z)</EM>. The value returned is of <EM>type</EM>.
  620. <P>
  621. This function invokes a fatal error if an error occurs.
  622. <P>
  623. float G3d_getFloat(void *map, int x, int y, int z)Is equivalent to
  624. <TT>G3d_getValue (map, x, y, z, &amp;value, FCELL_TYPE);</TT> return value.
  625. <P>
  626. double G3d_getDouble(void *map, int x, int y, int z)Is equivalent
  627. to <TT>G3d_getValue (map, x, y, z, &amp;value, DCELL_TYPE);</TT> return value.
  628. <P>
  629. void G3d_getValueRegion(void *map, int x, int y, int z, char*value,
  630. int type) Returns in <EM>*value</EM> the cell-value of the cell with
  631. region-coordinate <EM>(x, y, z)</EM>. The value returned is of <EM>type</EM>.
  632. Here <EM>region</EM> means the coordinate in the cube of data in the file, i.e.
  633. ignoring geographic coordinates.
  634. <P>
  635. This function invokes a fatal error if an error occurs.
  636. <P>
  637. float G3d_getFloatRegion(void *map, int x, int y, int z)Is
  638. equivalent to <TT>G3d_getValueRegion (map, x, y, z, &amp;value, FCELL_TYPE);</TT>
  639. return value.
  640. <P>
  641. double G3d_getDoubleRegion(void *map, int x, int y, int z)Is
  642. equivalent to <TT>G3d_getValueRegion (map, x, y, z, &amp;value,
  643. DCELL_TYPE);</TT> return value.
  644. <P>
  645. int G3d_putValue(void *map, int x, int y, int z, char *value, int
  646. type)After converting <EM>*value</EM> of <EM>type</EM> into the type specified
  647. at the initialization time (i.e. <EM>typeIntern</EM>) this function writes the
  648. value into the tile buffer corresponding to cell-coordinate <EM>(x, y, z)</EM>.
  649. <P>
  650. Returns
  651. <P>
  652. 1 ... if successful,
  653. 0 ... otherwise.
  654. <P>
  655. int G3d_putFloat(void *map, int x, int y, int z, char *value)Is
  656. equivalent to G3d_putValue (map, x, y, z, &amp;value, FCELL_TYPE).
  657. <P>
  658. int G3d_putDouble(void *map, int x, int y, int z, char *value) Is
  659. equivalent to G3d_putValue (map, x, y, z, &amp;value, DCELL_TYPE).
  660. <P>
  661. \subsection Loading_and_Removing_TilesLoading and Removing Tiles
  662. <P>
  663. char *G3d_getTilePtr(void *map, int tileIndex) This function
  664. returns a pointer to a tile which contains the data for the tile with index
  665. <EM>tileIndex</EM>. The type of the data stored in the tile depends on the type
  666. specified at the initialization time of <EM>map</EM>. The functionality is
  667. different depending on whether <EM>map</EM> is old or new and depending on the
  668. cache-mode of <EM>map</EM>.
  669. <BR>
  670. <P>
  671. If <EM>map</EM> is old and the cache is not used the tile with <EM>tileIndex</EM>
  672. is read from file and stored in the buffer provided by the map structure.
  673. The pointer to this buffer is returned. If the buffer already contains the
  674. tile with <EM>tileIndex</EM> reading is skipped. Data which was stored in
  675. earlier calls to <TT>G3d_getTilePtr</TT> is destroyed. If the tile with
  676. <EM>tileIndex</EM> is not stored on the file corresponding to <EM>map</EM>, and
  677. <EM>tileIndex</EM> is a valid index the buffer is filled with NULL-values.
  678. <BR>
  679. <P>
  680. If <EM>map</EM> is old and the cache is used the tile with <EM>tileIndex</EM> is
  681. read from file and stored in one of the cache buffers. The pointer to buffer
  682. is returned. If no free cache buffer is available an unlocked cache-buffer
  683. is freed up and the new tile is stored in its place. If the tile with
  684. <EM>tileIndex</EM> is not stored on the file corresponding to <EM>map</EM>, and
  685. <EM>tileIndex</EM> is a valid index the buffer is filled with NULL-values. If one
  686. of the cache buffers already contains the tile with <EM>tileIndex</EM> reading
  687. is skipped and the pointer to this buffer is returned.
  688. <BR>
  689. <P>
  690. If <EM>map</EM> is new and the cache is not used the functionality is the same
  691. as if <EM>map</EM> is old and the cache is not used. If the tile with
  692. <EM>tileIndex</EM> is already stored on file, it is read into the buffer, if not,
  693. the cells are set to null-values. If the buffer corresponding to the pointer
  694. is used for writing, subsequent calls to <TT>G3d_getTilePtr</TT> may destroy the
  695. values already stored in the buffer. Use <TT>G3d_flushTile</TT> to write the buffer
  696. to the file before reusing it for a different index. The use of this buffer
  697. as write buffer is discouraged.
  698. <BR>
  699. <P>
  700. If <EM>map</EM> is new and the cache is used the functionality is the same as if
  701. <EM>map</EM> is old and the cache is used with the following exception. If
  702. <EM>tileIndex</EM> is a valid index and the tile with this index is not found in
  703. the cache and is not stored on the file corresponding to <EM>map</EM>, then the
  704. file cache is queried next. If the file-cache contains the tile it is loaded
  705. into the cache (memory-cache). Only if the file-cache does not contain the
  706. tile it is filled with NULL-values. Tile contents of buffers are never
  707. destroyed. If a cache buffer needs to be freed up, and the tile stored in the
  708. buffer has not been written to the file corresponding to <EM>map</EM> yet, the
  709. tile is copied into the file-cache.
  710. <BR>
  711. <P>
  712. Care has to be taken if this function is used in non-cache mode since it is
  713. implicitly invoked every time a read or write request is issued. The only
  714. I/O-functions for which it is safe to assume that they do not invoke
  715. <TT>G3d_getTilePtr</TT> are <TT>G3d_readTile()</TT> and
  716. <TT>G3d_writeTile()</TT> and their corresponding type-specific versions.
  717. <P>
  718. Returns
  719. a pointer to a buffer ... if successful,
  720. NULL ... otherwise.
  721. <P>
  722. int G3d_tileLoad(void *map, int tileIndex)
  723. Same functionality as <TT>G3d_getTilePtr()</TT> but does not return the
  724. pointer.
  725. <P>
  726. Returns
  727. 1 ... if successful,
  728. 0 ... otherwise.
  729. <P>
  730. int G3d_removeTile(void *map, inttileIndex) Removes a tile
  731. from memory-cache if tile is in memory-cache. For new maps the
  732. application does not know whether the tile is in the memory-cache or in
  733. the file-cache. Therefore, for new maps this function should be
  734. preceded by <TT>G3d_tileLoad()</TT>.
  735. <P>
  736. <EM>(Question: Is this a useful function?)</EM>
  737. <P>
  738. Returns 1 ... if successful, 0 ... otherwise.
  739. <P>
  740. \subsection Write_Functions_used_in_Cache_Mode Write Functions used in Cache Mode
  741. <P>
  742. int G3d_flushTile(void *map, int tileIndex) Writes the tile with
  743. <EM>tileIndex</EM> to the file corresponding to <EM>map</EM> and removes the tile
  744. from the cache (in non-cache mode the buffer provided by the map-structure is
  745. written).
  746. <P>
  747. If this tile has already been written before the write request is ignored.
  748. If the tile was never referred to before the invokation of G3d_flushTile, a
  749. tile filled with NULL-values is written.
  750. <P>
  751. Returns
  752. 1 ... if successful,
  753. 0 ... otherwise.
  754. <P>
  755. int G3d_flushTileCube(void *map, int xMin, int yMin, int zMin, int
  756. xMax, int yMax, int zMax) Writes the tiles with tile-coordinates
  757. contained in the axis-parallel cube with vertices <EM>(xMin, yMin, zMin)</EM>
  758. and <EM>(xMax, yMax, zMax</EM>). Tiles which are not stored in the cache are
  759. written as NULL-tiles. Write attempts for tiles which have already been
  760. written earlier are ignored.
  761. <P>
  762. Returns
  763. 1 ... if successful,
  764. 0 ... otherwise.
  765. <P>
  766. int G3d_flushTilesInCube(void *map, int xMin, int yMin, int
  767. zMin, int xMax, int yMax, int zMax) Writes those tiles for which
  768. <EM>every</EM> cell has coordinate contained in the axis-parallel cube
  769. defined by the vertices with cell-coordinates <EM>(xMin, yMin, zMin)</EM>
  770. and <EM>(xMax, yMax, zMax)</EM>.
  771. <P>
  772. Tiles which are not stored in the cache are written as NULL-tiles.
  773. Write attempts for tiles which have already been written earlier are
  774. ignored.
  775. <P>
  776. Returns
  777. 1 ... if successful,
  778. 0 ... otherwise.
  779. <P>
  780. \subsection Locking_and_Unlocking_Tiles_and_CyclesLocking and Unlocking Tiles, and Cycles
  781. <P>
  782. int G3d_lockTile(void *map, int tileIndex) Locks tile with <EM>tileIndex</EM> in cache.
  783. If after locking fewer than the minimum number of
  784. unlocked tiles are unlocked, the lock request is ignored.
  785. <P>
  786. Returns
  787. 1 ... if successful,
  788. -1 ... if request is ignored,
  789. 0 ... otherwise.
  790. <P>
  791. int G3d_unlockTile(void *map, int tileIndex)
  792. Unlocks tile with <EM>tileIndex</EM>.
  793. <P>
  794. Returns
  795. 1 ... if successful,
  796. 0 ... otherwise.
  797. <P>
  798. int G3d_unlockAll(void *map)
  799. Unlocks every tile in cache of <EM>map</EM>.
  800. <P>
  801. Returns
  802. 1 ... if successful,
  803. 0 ... otherwise.
  804. <P>
  805. void G3d_autolockOn(void *map)
  806. Turns autolock mode on.
  807. <P>
  808. void G3d_autolockOff(void *map)
  809. Turns autolock mode Off.
  810. <P>
  811. void G3d_minUnlocked(void *map, int minUnlocked) Sets the minimum
  812. number of unlocked tiles to <EM>minUnlocked</EM>. This function should be used
  813. in combination with <TT>G3d_unlockAll()</TT> in order to avoid situations where the
  814. new minimum is larger than the actual number of unlocked tiles.
  815. <P>
  816. <EM>minUnlocked</EM> must be one of G3D_USE_CACHE_X, G3D_USE_CACHE_Y,
  817. G3D_USE_CACHE_Z, G3D_USE_CACHE_XY, G3D_USE_CACHE_XZ,
  818. G3D_USE_CACHE_YZ, G3D_USE_CACHE_XYZ, the result of G3d_cacheSizeEncode()
  819. (cf. Section 22.4.6), or any positive integer
  820. which explicitly specifies the number of tiles.
  821. <P>
  822. int G3d_beginCycle(void *map)
  823. Starts a new cycle.
  824. <P>
  825. Returns
  826. 1 ... if successful,
  827. 0 ... otherwise.
  828. <P>
  829. int G3d_endCycle(void *map)
  830. Ends a cycle.
  831. <P>
  832. Returns
  833. 1 ... if successful,
  834. 0 ... otherwise.
  835. <P>
  836. int G3d_cacheSizeEncode(int cacheCode, int n) Returns a number
  837. which encodes multiplicity <EM>n</EM> of <EM>cacheCode</EM>. This value can be used
  838. to specify the size of the cache.
  839. <P>
  840. If <EM>cacheCode</EM> is the size (in tiles) of the cache the function returns
  841. <EM>cacheCode * n</EM>.
  842. <P>
  843. If <EM>cacheCode</EM> is G3D_USE_CACHE_DEFAULT the function returns
  844. G3D_USE_CACHE_DEFAULT.
  845. <P>
  846. If <EM>cacheCode</EM> is G3D_USE_CACHE_??? the function returns a value
  847. encoding G3D_USE_CACHE_??? and <EM>n</EM>. Here G3D_USE_CACHE_??? is one
  848. of G3D_USE_CACHE_X, G3D_USE_CACHE_Y, G3D_USE_CACHE_Z,
  849. G3D_USE_CACHE_XY, G3D_USE_CACHE_XZ, G3D_USE_CACHE_YZ, or
  850. G3D_USE_CACHE_XYZ, where e.g. G3D_USE_CACHE_X specifies that the cache
  851. should store as many tiles as there exist in one row along the x-axis of the
  852. tile cube, and G3D_USE_CACHE_XY specifies that the cache should store as
  853. many tiles as there exist in one slice of the tile cube with constant Z
  854. coordinate.
  855. <P>
  856. \subsection Reading_Volumes Reading Volumes
  857. <P>
  858. int G3d_getVolume(void *map, double originNorth, double originWest,
  859. double originBottom, double vxNorth, double vxWest, double vxBottom, double
  860. vyNorth, double vyWest, double vyBottom, double vzNorth, double vzWest,
  861. double vzBottom, int nx, int ny, int nz, char *volumeBuf, int type)
  862. Resamples the cube defined by <EM>origin</EM> and the 3 vertices <EM>vx</EM>,
  863. <EM>vy</EM>, and <EM>vz</EM> which are incident to the 3 edges adjacent to
  864. <EM>origin</EM>. The resampled cube is stored in <EM>volumeBuf</EM> which is a cube
  865. with dimensions <EM>(nx, ny, nz)</EM>.
  866. <P>
  867. The method of sampling is nearest neighbor sampling.
  868. <P>
  869. The values stored are of <EM>type</EM>.
  870. <P>
  871. Returns 1 ... if successful, 0 ... otherwise.
  872. <P>
  873. int G3d_getAllignedVolume(void *map, double originNorth, double
  874. originWest, double originBottom, double lengthNorth, double lengthWest,
  875. double lengthBottom, int nx, int ny, int nz, char *volumeBuf, int type)
  876. Resamples the axis-parallel cube defined by <EM>origin</EM> and the lengths of
  877. the 3 edges adjacent to <EM>origin</EM>. The resampled cube is stored in
  878. <EM>volumeBuf</EM> which is a cube with dimensions <EM>(nx, ny, nz)</EM>. The method
  879. of sampling is nearest neighbor sampling. The values stored are of <EM>type</EM>.
  880. <P>
  881. Returns 1 ... if successful, 0 ... otherwise.
  882. <P>
  883. \subsection Allocating_and_Freeing_Memory Allocating and Freeing Memory
  884. <P>
  885. void *G3d_malloc(int nBytes)
  886. Same as <EM>malloc (nBytes)</EM>, except that in case of error
  887. <TT>G3d_error()</TT> is invoked.
  888. <P>
  889. Returns
  890. a pointer ... if successful,
  891. NULL ... otherwise.
  892. <P>
  893. void *G3d_realloc(void *ptr, int nBytes)
  894. Same as <EM>realloc (ptr, nBytes)</EM>, except that in case of error
  895. <TT>G3d_error()</TT> is invoked.
  896. <P>
  897. Returns
  898. a pointer ... if successful,
  899. NULL ... otherwise.
  900. <P>
  901. void G3d_free(void *ptr) Same as <EM>free (ptr)</EM>.
  902. <P>
  903. char *G3d_allocTilesType(void *map, int nofTiles, int type)
  904. Allocates a vector of <EM>nofTiles</EM> tiles with the same dimensions
  905. as the tiles of <EM>map</EM> and large enough to store cell-values of
  906. <EM>type</EM>.
  907. <P>
  908. Returns
  909. a pointer to the vector ... if successful,
  910. NULL ... otherwise.
  911. <P>
  912. char *G3d_allocTiles(void *map, int nofTiles)
  913. Is equivalent to G3d_allocTilesType (map, nofTiles, G3d_fileTypeMap (map)).
  914. <P>
  915. void G3d_freeTiles(char *tiles)
  916. Is equivalent to <TT>G3d_free (tiles);</TT>
  917. <P>
  918. \subsection G3D_Null_Value_Support G3D Null Value Support
  919. <P>
  920. void G3d_isNullValueNum(void *n, int type)
  921. Returns 1 if the value of <EM>*n</EM> is a NULL-value. Returns 0
  922. otherwise.
  923. <P>
  924. void G3d_setNullValue(void *c, int nofElts, int type)
  925. Fills the vector pointed to by <EM>c</EM> with <EM>nofElts</EM> NULL-values
  926. of <EM>type</EM>.
  927. <P>
  928. void G3d_setNullTileType(void *map, int tile, int type)
  929. Assumes that <EM>tile</EM> is a tile with the same dimensions as the
  930. tiles of <EM>map</EM>. Fills <EM>tile</EM> with NULL-values of
  931. <EM>type</EM>.
  932. <P>
  933. void G3d_setNullTile(void *map, int tile)
  934. Is equivalent to G3d_setNullTileType (map, tile, G3d_fileTypeMap (map)).
  935. <P>
  936. \subsection G3D_Map_Header_Information G3D Map Header Information
  937. <P>
  938. void G3d_getCoordsMap(void *map, int *rows, int *cols, int *depths)
  939. Returns the size of the region of <EM>map</EM> in cells.
  940. <P>
  941. void G3d_getRegionMap(void *map, int *north, int *south, int *east,
  942. int *west, int *top, int *bottom)Returns the size of the region.
  943. <P>
  944. void G3d_getRegionStructMap(void *map, G3D_Region *region)
  945. Returns in <EM>region</EM> the region of <EM>map</EM>.
  946. <P>
  947. void G3d_getTileDimensionsMap(void *map, int *x, int *y, int *z)
  948. Returns the tile dimensions used for <EM>map</EM>.
  949. <P>
  950. void G3d_getNofTilesMap(void *map, int *nx, int *ny, int *nz)
  951. Returns the dimensions of the tile-cube used to tile the region of <EM>map</EM>.
  952. These numbers include partial tiles.
  953. <P>
  954. int G3d_tileTypeMap(void *map)
  955. Returns the type in which tiles of <EM>map</EM> are stored in memory.
  956. <P>
  957. int G3d_fileTypeMap(void *map)
  958. Returns the type with which tiles of <EM>map</EM> are stored on file.
  959. <P>
  960. int G3d_tilePrecisionMap(void *map)
  961. Returns the precision used to store <EM>map</EM>.
  962. <P>
  963. int G3d_tileUseCacheMap(void *map)
  964. Returns 1 if <EM>map</EM> uses cache, returns 0 otherwise.
  965. <P>
  966. void G3d_printHeader(void *map)
  967. Prints the header information of <EM>map</EM>.
  968. <P>
  969. \subsection G3D_Tile_Math G3D Tile Math
  970. <P>
  971. void G3d_tileIndex2tile(void *map, int tileIndex, int *xTile, int
  972. *yTile, int *zTile) Converts index <EM>tileIndex</EM> into tile-coordinates
  973. <EM>(xTile, yTile, zTile)</EM>.
  974. <P>
  975. int G3d_tile2tileIndex(void *map, int xTile, int yTile, int
  976. zTile) Returns tile-index corresponding to tile-coordinates <EM>(xTile,
  977. yTile, zTile)</EM>.
  978. <P>
  979. void G3d_coord2tileCoord(void *map, int x, int y, int z, int *xTile,
  980. int *yTile, int *zTile, int *xOffs, int *yOffs, int *zOffs) Converts
  981. cell-coordinates <EM>(x, y, z)</EM> into tile-coordinates <EM>(xTile, yTile,
  982. zTile)</EM> and the coordinate of the cell <EM>(xOffs, yOffs, zOffs)</EM> within
  983. the tile.
  984. <P>
  985. void G3d_tileCoordOrigin(void *map, int xTile, int yTile, int zTile,
  986. int *x, int *y, int *z) Computes the cell-coordinates <EM>(x, y, z)</EM>
  987. which correspond to the origin of the tile with tile-coordinates <EM>(xTile,
  988. yTile, zTile)</EM>.
  989. <P>
  990. void G3d_tileIndexOrigin(void *map, int tileIndex, int *x, int *y,
  991. int *z) Computes the cell-coordinates <EM>(x, y, z)</EM> which correspond to
  992. the origin of the tile with <EM>tileIndex</EM>.
  993. <P>
  994. void G3d_coord2tileIndex(void *map, int x, int y, int z, int
  995. *tileIndex, int *offset) Converts cell-coordinates <EM>(x, y, z)</EM> into
  996. <EM>tileIndex</EM> and the <EM>offset</EM> of the cell within the tile.
  997. <P>
  998. int G3d_coordInRange(void *map, int x, int y, int z) Returns 1 if
  999. cell-coordinate <EM>(x, y, z)</EM> is a coordinate inside the region. Returns 0
  1000. otherwise.
  1001. <P>
  1002. int G3d_tileInRange(void *map, int x, int y, int z) Returns 1 if
  1003. tile-coordinate <EM>(x, y, z)</EM> is a coordinate inside tile cube. Returns 0
  1004. otherwise.
  1005. <P>
  1006. int G3d_tileIndexInRange(void *map, int tileIndex)
  1007. Returns 1 if <EM>tileIndex</EM> is a valid index for <EM>map</EM>.
  1008. Returns 0 otherwise.
  1009. <P>
  1010. int G3d_isValidLocation(void *map, double north, double west, double
  1011. bottom) Returns 1 if region-coordinates <EM>(north, west, bottom)</EM> are
  1012. inside the region of <EM>map</EM>. Returns 0 otherwise.
  1013. <P>
  1014. void G3d_location2coord(void *map, double north, double west, double
  1015. bottom, int *x, *y, *z) Converts region-coordinates <EM>(north, west,
  1016. bottom)</EM> into cell-coordinates <EM>(x, y, z)</EM>.
  1017. <P>
  1018. int G3d_computeClippedTileDimensions(void *map, int tileIndex, int
  1019. *rows, int *cols, int *depths, int *xRedundant, int *yRedundant, int
  1020. *zRedundant) Computes the dimensions of the tile when clipped to fit the
  1021. region of <EM>map</EM>. The clipped dimensions are returned in <EM>rows</EM>,
  1022. <EM>cols</EM>, <EM>depths</EM>. The complement is returned in <EM>xRedundant</EM>,
  1023. <EM>yRedundant</EM>, and <EM>zRedundant</EM>. This function returns the number of
  1024. cells in the clipped tile.
  1025. <P>
  1026. \subsection G3D_Range_Support G3D Range Support
  1027. <P>
  1028. The map structure of G3D provides storage for the range. The range of a map is
  1029. updated every time a cell is written to the file. When an old map is opened the
  1030. range is not automatically loaded. The application has to invoke
  1031. <TT>G3d_range_load()</TT> (cf. Section 22.4.12)
  1032. explicitly. In
  1033. addition to these function the application can also use the standard grass
  1034. functions to manipulate the range.
  1035. <P>
  1036. int G3d_range_load(void *map)
  1037. Loads the range into the range structure of <EM>map</EM>.
  1038. <P>
  1039. Returns
  1040. 1 ... if successful
  1041. 0 ... otherwise.
  1042. <P>
  1043. void G3d_range_min_max(void *map, double *min, double *max)
  1044. Returns in <EM>min</EM> and <EM>max</EM> the minimum and maximum values of
  1045. the range.
  1046. <P>
  1047. int G3d_range_write(void *map)
  1048. Writes the range which is stored in the range structure of <EM>map</EM>.
  1049. (This function is invoked automatically when a new file is closed).
  1050. <P>
  1051. Returns
  1052. 1 ... if successful
  1053. 0 ... otherwise.
  1054. <P>
  1055. \subsection G3D_Color_Support G3D Color Support
  1056. <P>
  1057. Applications can use the standard grass functions to work with colors, except
  1058. for the file manipulations.
  1059. <P>
  1060. int G3d_removeColor(char *name)
  1061. Removes the primary and/or secondary color file. See <EM>G_remove_colr</EM> for
  1062. details.
  1063. <P>
  1064. Returns always 0.
  1065. <P>
  1066. int G3d_readColors(char *name, char *mapset, struct Colors
  1067. *colors) Reads color file for map <EM>name</EM> in <EM>mapset</EM> into the
  1068. <EM>colors</EM> structure. See <EM>G_read_colors</EM>
  1069. (Raster_Color_Table) for details and return values.
  1070. <P>
  1071. int G3d_writeColors(char *name, char *mapset, struct Colors
  1072. *colors)Writes colors stored in <EM>colors</EM> structure into the color
  1073. file for map <EM>name</EM> in <EM>mapset</EM>. See <EM>G_write_colors</EM>
  1074. (Raster_Color_Table) for
  1075. details and return values.
  1076. <P>
  1077. \subsection G3D_Categories_Support G3D Categories Support
  1078. <P>
  1079. Applications can use the standard grass functions to work with categories,
  1080. except for the file manipulations.
  1081. <P>
  1082. int G3d_readCats(char *name, char *mapset, struct Categories *cats)
  1083. Reads the categories file for map <EM>name</EM> in <EM>mapset</EM> and
  1084. stores the categories in the <EM>cats</EM> structure. See <EM>G_read_cats</EM>
  1085. (Raster_Category_File) for details and return values.
  1086. <P>
  1087. int G3d_writeCats(char *name, struct Categories *cats) Writes the
  1088. categories stored in the <EM>cats</EM> structure into the categories file for
  1089. map <EM>name</EM> in the current mapset. See <EM>G_write_cats</EM>
  1090. (Raster_Category_File) for details and return values.
  1091. <P>
  1092. \subsection G3D_History_Support G3D History Support
  1093. <P>
  1094. Applications can use the standard grass functions to work with histories,
  1095. except for the file manipulations.
  1096. <P>
  1097. int G3d_readHistory(char *name, char *mapset, struct History *hist)
  1098. Reads the history file for map <EM>name</EM> in <EM>mapset</EM> and
  1099. stores the history in the <EM>hist</EM> structure. See <EM>G_read_history</EM>
  1100. (Raster_History_File) for details and return values.
  1101. <P>
  1102. int G3d_writeHistory(char *name, struct History *hist)
  1103. Writes the
  1104. history stored in the <EM>hist</EM> structure into the categories file for
  1105. map <EM>name</EM> in the current mapset. See <EM>G_write_history</EM>
  1106. (Raster_History_File) for details and return values.
  1107. <P>
  1108. \subsection G3D_Mask_Support G3D Mask Support
  1109. <P>
  1110. void G3d_maskOn(void *map) Turns on the mask for <EM>map</EM>. Do
  1111. not invoke this function after the first tile has been read since the result
  1112. might be inconsistent cell-values.
  1113. <P>
  1114. void G3d_maskOff(void *map) Turns off the mask for <EM>map</EM>.
  1115. This is the default. Do not invoke this function after the first tile has
  1116. been read since the result might be inconsistent cell-values.
  1117. <P>
  1118. int G3d_maskIsOn(void *map) Returns 1 if the mask for <EM>map</EM>
  1119. is turned on. Returns 0 otherwise.
  1120. <P>
  1121. int G3d_maskIsOff(void *map)
  1122. Returns 1 if the mask for <EM>map</EM> is turned off. Returns 0 otherwise.
  1123. <P>
  1124. The remaining functions in this section are for the explicit query of the mask
  1125. and the masking of individual cells or tiles. These functions are used in the
  1126. library and might have applications in situations where both the masked and
  1127. non-masked value of a cell has to be known.
  1128. <P>
  1129. int G3d_maskReopen(int cache)
  1130. This function should be used to adjust the cache size used for the
  1131. 3d-mask. First the open 3d-mask is closed and then opened again with
  1132. a cache size as specified with <EM>cache</EM>.
  1133. <P>
  1134. Returns
  1135. 1 ... if successful
  1136. 0 ... otherwise.
  1137. <P>
  1138. int G3d_maskFileExists() Returns 1 if the 3d mask file
  1139. exists.
  1140. <P>
  1141. int G3d_maskMapExists()
  1142. Returns 1 if the 3d mask is loaded.
  1143. <P>
  1144. char *G3d_maskFile()
  1145. Returns the name of the 3d mask file.
  1146. <P>
  1147. int G3d_isMasked(int x, int y, int z)
  1148. Returns 1 if the cell with cell-coordinates <EM>(x, y, z)</EM> is masked
  1149. out. Returns 0 otherwise.
  1150. <P>
  1151. void G3d_maskNum(int x, int y, int z, void *value, int type)
  1152. Replaces the value stored in <EM>value</EM> with the NULL-value if
  1153. <EM>G3d_isMasked (x, y, z)</EM> returns 1. Does nothing otherwise.
  1154. <EM>value</EM> is assumed to be of<EM>type</EM>.
  1155. <P>
  1156. void G3d_maskFloat(int x, int y, int z, float *value)
  1157. Same as <EM>G3d_maskNum (x, y, z, value, FCELL_TYPE)</EM>.
  1158. <P>
  1159. void G3d_maskDouble(int x, int y, int z, double *value)
  1160. Same as <EM>G3d_maskNum (x, y, z, value, DCELL_TYPE)</EM>.
  1161. <P>
  1162. void G3d_maskTile(void *map, int tileIndex, char *tile, int type)
  1163. Replaces the values stored in <EM>tile</EM> (with <EM>tileIndex</EM>) for
  1164. which <EM>G3d_isMasked</EM> returns 1 with NULL-values. Does not change
  1165. the remaining values. The values are assumed to be of <EM>type</EM>.
  1166. Whether replacement is performed or not only depends on location of the
  1167. cells of the tile and not on the status of the mask for <EM>map</EM>
  1168. (i.e. turned on or off).
  1169. <P>
  1170. \subsection G3D_Window_Support G3D Window Support
  1171. <P>
  1172. void G3d_setWindowMap(void *map, G3D_Region *window)
  1173. Sets the window for <EM>map</EM> to <EM>window</EM>.
  1174. Can be used multiple times for the same map.
  1175. <P>
  1176. void G3d_setWindow(G3D_Region *window)
  1177. Sets the default window used for every map opened later in the program.
  1178. Can be used multiple times in the same program.
  1179. <P>
  1180. void G3d_getWindow(G3D_Region *window)
  1181. Stores the current default window in <EM>window</EM>.
  1182. <P>
  1183. void *G3d_windowPtr()
  1184. Returns a pointer to the current default window. This pointer should not be
  1185. (ab)used to modify the current window structure directly. It is
  1186. provided to pass a window pointer when opening a map.
  1187. <P>
  1188. int G3d_readWindow(G3D_Region *window, char *windowName) Reads
  1189. <EM>window</EM> from the file specified by <EM>windowName</EM>. The name is
  1190. converted by the rules defined in window defaults. A NULL pointer indicates
  1191. the <EM>WIND3</EM> file in the current mapset.
  1192. <P>
  1193. Returns
  1194. 1 ... if successful
  1195. 0 ... otherwise.
  1196. <P>
  1197. int G3d_writeWindow(G3D_Region *window, char *windowName)
  1198. Writes <EM>window</EM> to the file specified by <EM>windowName</EM>. The name
  1199. is converted by the rules defined in window defaults. A NULL pointer
  1200. indicates the <EM>WIND3</EM> file in the current mapset.
  1201. <P>
  1202. Returns
  1203. 1 ... if successful
  1204. 0 ... otherwise.
  1205. <P>
  1206. void G3d_useWindowParams()
  1207. Allows the window to be set at run-time via the <EM>region3</EM>
  1208. command line argument. This function has to be called before
  1209. <EM>G_parser()</EM>. See also
  1210. window defaults.
  1211. <P>
  1212. void G3d_setResamplingFun(void *map, void (*resampleFun)())
  1213. Sets the resampling function to be used by
  1214. G3d_getValue() (cf. Section 22.4.3). This function is defined
  1215. as follows:
  1216. <P>
  1217. void G3d_customResampleFun(void *map, int row, int col, int depth,
  1218. char *value, int type) <EM>row</EM>, <EM>col</EM>, and <EM>depth</EM> are in
  1219. region coordinates. The result is returned in <EM>value</EM> as <EM>type</EM> which
  1220. is one of FCELL_TYPE or DCELL_TYPE. Possible choices include
  1221. G3d_nearestNeighbor() (cf. Section22.4.16) and
  1222. G3d_getValueRegion() (cf. Section 22.4.3).
  1223. <P>
  1224. void G3d_nearestNeighbor(void *map, int row, int col, int depth, char
  1225. *value, int type) The default resampling function which uses nearest
  1226. neighbor resampling.
  1227. <P>
  1228. void G3d_getResamplingFun(void *map, void (**resampleFun)())
  1229. Returns in <EM>resampleFun</EM> a pointer to the resampling function used by
  1230. <EM>map</EM>.
  1231. <P>
  1232. void G3d_getNearestNeighborFunPtr(void (**nnFunPtr)()) Returns
  1233. in <EM>nnFunPtr</EM> a pointer to G3d_nearestNeighbor() (cf.
  1234. Section&nbsp;<A HREF="#g3d:G3d.nearestNeighbor">22.4.16</A>).
  1235. <P>
  1236. \subsection G3D_Region G3D Region
  1237. <P>
  1238. void G3d_extract2dRegion(G3D_Region *region3d, struct Cell_head
  1239. *region2d) Returns in <EM>region2d</EM> the <EM>2d</EM> portion of <EM>region3d</EM>.
  1240. <P>
  1241. void G3d_incorporate2dRegion(struct Cell_head *region2d, G3D_Region
  1242. *region3d) Replaces the <EM>2d</EM> portion of <EM>region3d</EM> with the
  1243. values stored in <EM>region2d</EM>.
  1244. <P>
  1245. void G3d_adjustRegion(G3D_Region *region)
  1246. Computes an adjusts the resolutions in the region structure from the region
  1247. boundaries and number of cells per dimension.
  1248. <P>
  1249. void G3d_adjustRegionRes(G3D_Region *region)
  1250. Computes an adjusts the number of cells per dimension in the region
  1251. structure from the region boundaries and resolutions.
  1252. <P>
  1253. void G3d_regionCopy(G3D_Region *regionDest, G3D_Region *regionSrc)
  1254. Copies the values of <EM>regionSrc</EM> into <EM>regionDst</EM>.
  1255. (The unfortunate order of parameters was chosen in order to conform to the
  1256. order used in <EM>G_copy()</EM>).
  1257. <P>
  1258. void G3d_getRegionValue(void *map, double north, double east, double
  1259. top, char *value, int type) Returns in <EM>value</EM> the value of the <EM>map</EM>
  1260. which corresponds to region coordinates <EM>(north, east, top)</EM>. The
  1261. value is resampled using the resampling function specified for <EM>map</EM>. The
  1262. <EM>value</EM> is of <EM>type</EM>.
  1263. <P>
  1264. void G3d_readRegionMap(char *name, char *mapset, G3D_Region *region)
  1265. Returns in <EM>region</EM> the region information for 3d cell <EM>name@mapset</EM>.
  1266. <P>
  1267. \subsection Miscellaneous_Functions Miscellaneous Functions
  1268. <P>
  1269. void G3d_g3dType2cellType(int g3dType) Returns the GRASS floating
  1270. point type which is equivalent to the G3D type of <EM>g3dType</EM>.
  1271. <P>
  1272. void G3d_initDefaults() Initializes the default values described
  1273. in G3D Defaults. Applications have to use this function only if they need to
  1274. query the default values before the first file (either old or new) has been
  1275. opened.
  1276. <P>
  1277. void G3d_setStandard3dInputParams()
  1278. Initializes a parameter
  1279. structure for the subset of command line arguments which lets the user
  1280. overwrite the default properties of the new file. Applications are
  1281. encouraged to use this function in order to provide a uniform style. The
  1282. command line arguments provided are the <EM>type</EM> of the cell values, the
  1283. <EM>precision</EM>, the properties of the <EM>compression</EM>, and the dimension
  1284. of the tiles (<EM>tiledimension</EM>). Every of these values defaults to the
  1285. value described in G3D Defaults.
  1286. <P>
  1287. This function has to be used in conjunction with
  1288. G3d_getStandard3dInputParams() (cf.
  1289. Section 22.4.18).
  1290. <P>
  1291. int G3d_getStandard3dInputParams(int *useTypeDefault, *type, *useLzwDefault, *doLzw,
  1292. int *useRleDefault, *doRle, *usePrecisionDefault, *precision,
  1293. int *useDimensionDefault, *tileX, *tileY, *tileZ
  1294. Returns the properties of the new file as chosen by the user via command
  1295. line arguments. If the default is chosen the values of
  1296. <EM>useXxxxDefault</EM> is 1, it is 0 otherwise. In addition, the
  1297. corresponding parameters contain the default value if
  1298. <EM>useXxxxDefault</EM> is 1, or the value specified by the user if
  1299. <EM>useXxxxDefault</EM> is 0.
  1300. <P>
  1301. Function
  1302. G3d_setStandard3dInputParams() (cf. Section 22.4.18)
  1303. has to be used to initialize the internal parameter structure.
  1304. <P>
  1305. Returns
  1306. 1 ... if successful,
  1307. 0 ... otherwise.
  1308. <P>
  1309. int G3d_makeMapsetMapDirectory(char *mapName)
  1310. Creates the 3d mapset element for map <EM>mapName</EM>.
  1311. <P>
  1312. int G3d_filename(char *path, *elementName, *mapName, *mapset)
  1313. Returns in <EM>path</EM> the path for element <EM>elementName</EM> for map
  1314. <EM>mapName</EM> in <EM>mapset</EM>. Note, an error occurs if <EM>mapName</EM>
  1315. is fully qualified.
  1316. <P>
  1317. See TimeStamp_functions for a complete discussion of GRASS datetime
  1318. routines (reading, writing grid3d timestamps).
  1319. <P>
  1320. \section Sample_G3D_Applications Sample G3D Applications
  1321. <P>
  1322. These functions were implemented to test the library. They are not very
  1323. efficient but can be used as starting point for other
  1324. applications. Some of them might actually be useful. They are available from
  1325. GRASS 7 source code in lib/g3d/.
  1326. <P>
  1327. void G3d_retile(void *map, char *nameOut, int tileX, int tileY, int tileZ)
  1328. Makes a copy of <EM>map</EM> with name <EM>nameOut</EM> which has
  1329. tile dimensions <EM>tileX</EM>, <EM>tileY</EM>, <EM>tileZ</EM>.
  1330. <P>
  1331. The source code can be found in <EM>retile.c</EM>.
  1332. <P>
  1333. void G3d_changePrecision(void *map, int precision, char *nameOut)
  1334. Makes a copy of <EM>map</EM> with name <EM>nameOut</EM> which is
  1335. written with <EM>precision</EM>.
  1336. <P>
  1337. The source code can be found in <EM>changeprecision.c</EM>.
  1338. <P>
  1339. void G3d_changeType(void *map, char *nameOut)
  1340. Makes a copy of <EM>map</EM> with name <EM>nameOut</EM> in which the
  1341. cells are of type FCELL_TYPE if they are DCELL_TYPE in <EM>map</EM>,
  1342. and in DCELL_TYPE otherwise.
  1343. <P>
  1344. The source code can be found in <EM>changetype.c</EM>.
  1345. <P>
  1346. void G3d_compareFiles(char *f1, char *mapset1, char *f2, char *mapset2)
  1347. Compares the cell-values of file <EM>f1</EM> in mapset
  1348. <EM>mapset1</EM> and file <EM>f2</EM> in mapset <EM>mapset2</EM>.
  1349. The values are compared up to precision.
  1350. Terminates in error if the files don't match.
  1351. This function uses the more advanced features of the cache.
  1352. <P>
  1353. The source code can be found in <EM>filecompare.c</EM>.
  1354. <P>
  1355. void G3d_getBlock(void *map, int x0, int y0, int z0, int nx, int ny,
  1356. int nz, char *block, int type)
  1357. Copies the cells contained in the block (cube) with vertices
  1358. <EM>(x0, y0, z0)</EM> and <EM>(x0 + nx - 1, y0 + ny - 1, z0 + nz - 1)</EM>
  1359. into <EM>block</EM>. The cell-values in <EM>block</EM> are of <EM>type</EM>.
  1360. <P>
  1361. The source code can be found in <EM>getblock.c</EM>.
  1362. <P>
  1363. void G3d_writeAscii(void *map, char *fname)
  1364. Writes the cell-values of <EM>map</EM> in ascii format to file
  1365. <EM>fname</EM>. The values are organized by horizontal slices.
  1366. <P>
  1367. See \ref Compiling_and_Installing_GRASS_Modules for a complete
  1368. discussion of Makefiles.
  1369. */