GRASS Programmer's Manual
6.4.2(2012)
|
00001 00002 #include <stdio.h> 00003 #include <stdlib.h> 00004 #include <sys/types.h> 00005 #include <unistd.h> 00006 #include "G3d_intern.h" 00007 00008 /*---------------------------------------------------------------------------*/ 00009 00010 /*---------------------------------------------------------------------------*/ 00011 00012 /* EXPORTED FUNCTIONS */ 00013 00014 /*---------------------------------------------------------------------------*/ 00015 00016 /*---------------------------------------------------------------------------*/ 00017 00018 00071 void *G3d_getTilePtr(G3D_Map * map, int tileIndex) 00072 { 00073 void *ptr; 00074 00075 if ((tileIndex >= map->nTiles) || (tileIndex < 0)) { 00076 G3d_error("G3d_getTilePtr: tileIndex out of range"); 00077 return NULL; 00078 } 00079 00080 if (map->useCache) { 00081 ptr = G3d_cache_elt_ptr(map->cache, tileIndex); 00082 if (ptr == NULL) { 00083 G3d_error("G3d_getTilePtr: error in G3d_cache_elt_ptr"); 00084 return NULL; 00085 } 00086 return ptr; 00087 } 00088 00089 if (map->currentIndex == tileIndex) 00090 return map->data; 00091 00092 map->currentIndex = tileIndex; 00093 if (!G3d_readTile(map, map->currentIndex, map->data, map->typeIntern)) { 00094 G3d_error("G3d_getTilePtr: error in G3d_readTile"); 00095 return NULL; 00096 } 00097 00098 return map->data; 00099 } 00100 00101 /*---------------------------------------------------------------------------*/ 00102 00103 00115 int G3d_tileLoad(G3D_Map * map, int tileIndex) 00116 { 00117 if (G3d_getTilePtr(map, tileIndex) == NULL) { 00118 G3d_error("G3d_tileLoad: error in G3d_getTilePtr"); 00119 return 0; 00120 } 00121 00122 return 1; 00123 } 00124 00125 /*---------------------------------------------------------------------------*/ 00126 00127 int G3d__removeTile(G3D_Map * map, int tileIndex) 00128 { 00129 if (!map->useCache) 00130 return 1; 00131 00132 if (!G3d_cache_remove_elt(map->cache, tileIndex)) { 00133 G3d_error("G3d_removeTile: error in G3d_cache_remove_elt"); 00134 return 0; 00135 } 00136 00137 return 1; 00138 } 00139 00140 /*---------------------------------------------------------------------------*/ 00141 00142 00156 double G3d_getDoubleRegion(); 00157 00158 00172 float G3d_getFloatRegion(G3D_Map * map, int x, int y, int z) 00173 { 00174 int tileIndex, offs; 00175 float *tile; 00176 00177 if (map->typeIntern == DCELL_TYPE) 00178 return (float)G3d_getDoubleRegion(map, x, y, z); 00179 00180 G3d_coord2tileIndex(map, x, y, z, &tileIndex, &offs); 00181 tile = (float *)G3d_getTilePtr(map, tileIndex); 00182 00183 if (tile == NULL) 00184 G3d_fatalError("G3d_getFloatRegion: error in G3d_getTilePtr"); 00185 00186 return tile[offs]; 00187 } 00188 00189 /*---------------------------------------------------------------------------*/ 00190 00191 00205 double G3d_getDoubleRegion(G3D_Map * map, int x, int y, int z) 00206 { 00207 int tileIndex, offs; 00208 double *tile; 00209 00210 if (map->typeIntern == FCELL_TYPE) 00211 return (double)G3d_getFloatRegion(map, x, y, z); 00212 00213 G3d_coord2tileIndex(map, x, y, z, &tileIndex, &offs); 00214 tile = (double *)G3d_getTilePtr(map, tileIndex); 00215 00216 if (tile == NULL) 00217 G3d_fatalError("G3d_getDoubleRegion: error in G3d_getTilePtr"); 00218 00219 return tile[offs]; 00220 } 00221 00222 /*---------------------------------------------------------------------------*/ 00223 00224 00243 void 00244 G3d_getValueRegion(G3D_Map * map, int x, int y, int z, void *value, int type) 00245 { 00246 if (type == FCELL_TYPE) { 00247 *((float *)value) = G3d_getFloatRegion(map, x, y, z); 00248 return; 00249 } 00250 00251 *((double *)value) = G3d_getDoubleRegion(map, x, y, z); 00252 }