g3dlib.dox 54 KB

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