SHAPE FILE TOOL. More...
#include "shape_file.h"
#include "jbxl_state.h"
Go to the source code of this file.
Functions | |
ShapeIndex * | read_shape_index_file (FILE *fp) |
BSGraph * | read_shape_main_file (ShapeIndex *idx, BSGraph *mp, vector og, vector dd, FILE *fp) |
void | draw_shape_polygon (ShapeIndex *idx, BSGraph *mp, vector og, vector dd, int cc, FILE *fp) |
Definition in file shape_file.c.
void draw_shape_polygon | ( | ShapeIndex * | idx, | |
BSGraph * | mp, | |||
vector | og, | |||
vector | dd, | |||
int | cc, | |||
FILE * | fp | |||
) |
Definition at line 141 of file shape_file.c.
References bline3d(), double_from_little_endian(), int_from_little_endian(), ShapeIndex::maxnum, ShapeIndex::offset, SHAPE_TYPE_POLYGON, UNUSED, vector::x, vector::y, vector::z, and BSGraph::zs.
Referenced by read_shape_main_file().
00142 { 00143 size_t rs; 00144 UNUSED(rs); 00145 00146 int i, j, k, rdint; 00147 int kk = (int)(og.z + 0.5); // color 00148 if (kk<0 || kk>mp->zs-1) kk = 0; 00149 00150 ShapeIndex* sx = idx; 00151 00152 for (i=0; i<idx->maxnum; i++) { 00153 fseek(fp, sx->offset*2+8, SEEK_SET); 00154 rs = fread(&rdint, 4, 1, fp); 00155 int type = int_from_little_endian((void*)&rdint); 00156 if (type!=SHAPE_TYPE_POLYGON) return; 00157 00158 fseek(fp, 32L, SEEK_CUR); 00159 rs = fread(&rdint, 4, 1, fp); 00160 int parts = int_from_little_endian((void*)&rdint); 00161 rs = fread(&rdint, 4, 1, fp); 00162 int points = int_from_little_endian((void*)&rdint); 00163 00164 for (j=0; j<parts; j++) { 00165 fseek(fp, sx->offset*2+52+j*4, SEEK_SET); // offset*2 + 8 + 44 + j*4 00166 rs = fread(&rdint, 4, 1, fp); 00167 int sttidx = int_from_little_endian((void*)&rdint); 00168 int endidx = points - 1; 00169 00170 if (j<parts-1) { 00171 rs = fread(&rdint, 4, 1, fp); 00172 endidx = int_from_little_endian((void*)&rdint) - 1; 00173 } 00174 00175 double xx, yy, ox, oy; 00176 fseek(fp, sx->offset*2+52+parts*4+sttidx*16, SEEK_SET); // offset*2 + 8 + 44 + parts*4 + sttidx*16 00177 00178 for (k=sttidx; k<=endidx; k++) { 00179 rs = fread(&xx, 8, 1, fp); 00180 rs = fread(&yy, 8, 1, fp); 00181 xx = double_from_little_endian((void*)&xx); 00182 yy = double_from_little_endian((void*)&yy); 00183 00184 if (k!=sttidx) { 00185 int oi = (int)((ox-og.x)/dd.x + 0.5); 00186 int oj = (int)((og.y-oy)/dd.y + 0.5); 00187 int ii = (int)((xx-og.x)/dd.x + 0.5); 00188 int jj = (int)((og.y-yy)/dd.y + 0.5); 00189 bline3d(*mp, oi, oj, kk, ii, jj, kk, cc); 00190 } 00191 ox = xx; 00192 oy = yy; 00193 } 00194 } 00195 sx++; 00196 } 00197 }
ShapeIndex* read_shape_index_file | ( | FILE * | fp | ) |
Definition at line 13 of file shape_file.c.
References ShapeIndex::datanum, DEBUG_MODE, int_from_big_endian(), int_from_little_endian(), ShapeIndex::maxnum, ShapeIndex::offset, PRINT_MESG, ShapeIndex::size, ShapeIndex::type, and UNUSED.
00014 { 00015 int magic, type, rdint; 00016 size_t rs; 00017 UNUSED(rs); 00018 00019 // Magic Number 00020 fseek(fp, 0L, SEEK_SET); 00021 rs = fread(&rdint, 4, 1, fp); 00022 magic = int_from_big_endian((void*)&rdint); 00023 if (magic!=9994) { 00024 DEBUG_MODE PRINT_MESG("READ_SHAPE_INDEX_FILE: But Mafic Number = %d\n", magic); 00025 return NULL; 00026 } 00027 00028 // Shape Type 00029 fseek(fp, 32L, SEEK_SET); 00030 rs = fread(&rdint, 4, 1, fp); 00031 type = int_from_little_endian((void*)&rdint); 00032 00033 // 00034 int i, count = 0; 00035 00036 fseek(fp, 100L, SEEK_SET); 00037 rs = fread(&rdint, 4, 1, fp); 00038 rs = fread(&rdint, 4, 1, fp); 00039 while(!feof(fp)) { 00040 count++; 00041 rs = fread(&rdint, 4, 1, fp); // next record 00042 rs = fread(&rdint, 4, 1, fp); // next record 00043 } 00044 00045 ShapeIndex* shpidx = (ShapeIndex*)malloc(count*sizeof(ShapeIndex)); 00046 if (shpidx==NULL) return NULL; 00047 00048 fseek(fp, 100L, SEEK_SET); 00049 for (i=0; i<count; i++) { 00050 shpidx[i].datanum = i; 00051 shpidx[i].type = type; 00052 shpidx[i].maxnum = count; 00053 rs = fread(&rdint, 4, 1, fp); 00054 shpidx[i].offset = int_from_big_endian((void*)&rdint); 00055 rs = fread(&rdint, 4, 1, fp); 00056 shpidx[i].size = int_from_big_endian((void*)&rdint); 00057 } 00058 00059 return shpidx; 00060 }
BSGraph* read_shape_main_file | ( | ShapeIndex * | idx, | |
BSGraph * | mp, | |||
vector | og, | |||
vector | dd, | |||
FILE * | fp | |||
) |
Definition at line 64 of file shape_file.c.
References DEBUG_MODE, double_from_little_endian(), draw_shape_polygon(), BSGraph::gp, int_from_big_endian(), int_from_little_endian(), JBXL_NORMAL, make_BSGraph(), PRINT_MESG, set_vector(), SHAPE_TYPE_POLYGON, BSGraph::state, ShapeIndex::type, UNUSED, vector::x, vector::y, and vector::z.
00065 { 00066 int magic, type, rdint; 00067 unsigned char rdbyte[8]; 00068 double xmin, ymin, zmin, xmax, ymax, zmax; 00069 size_t rs; 00070 UNUSED(rs); 00071 00072 // Magic Number 00073 fseek(fp, 0L, SEEK_SET); 00074 rs = fread(&rdint, 4, 1, fp); 00075 magic = int_from_big_endian((void*)&rdint); 00076 if (magic!=9994) { 00077 DEBUG_MODE PRINT_MESG("READ_SHAPE_MAIN_FILE: But Mafic Number = %d\n", magic); 00078 return NULL; 00079 } 00080 00081 // Shape Type 00082 fseek(fp, 32L, SEEK_SET); 00083 rs = fread(&rdint, 4, 1, fp); 00084 type = int_from_little_endian((void*)&rdint); 00085 00086 if (idx->type!=type) { 00087 DEBUG_MODE PRINT_MESG("READ_SHAPE_MAIN_FILE: Type mismatch with index file %d != %d\n", type, idx->type); 00088 return NULL; 00089 } 00090 00091 if (idx->type!=SHAPE_TYPE_POLYGON) { 00092 DEBUG_MODE PRINT_MESG("READ_SHAPE_MAIN_FILE: Unsupported Shape Type = %d\n", idx->type); 00093 return NULL; 00094 } 00095 00096 // Bounding Box 00097 fseek(fp, 36L, SEEK_SET); 00098 rs = fread(rdbyte, 8, 1, fp); 00099 xmin = double_from_little_endian((void*)rdbyte); 00100 rs = fread(rdbyte, 8, 1, fp); 00101 ymin = double_from_little_endian((void*)rdbyte); 00102 rs = fread(rdbyte, 8, 1, fp); 00103 xmax = double_from_little_endian((void*)rdbyte); 00104 rs = fread(rdbyte, 8, 1, fp); 00105 ymax = double_from_little_endian((void*)rdbyte); 00106 rs = fread(rdbyte, 8, 1, fp); 00107 zmin = double_from_little_endian((void*)rdbyte); 00108 rs = fread(rdbyte, 8, 1, fp); 00109 zmax = double_from_little_endian((void*)rdbyte); 00110 00111 // 00112 if (mp==NULL) { 00113 mp = (BSGraph*)malloc(sizeof(BSGraph)); 00114 memset(mp, 0, sizeof(BSGraph)); 00115 } 00116 if (mp->gp==NULL) { 00117 if (dd.x<=0.0) dd.x = 1.0; 00118 if (dd.y<=0.0) dd.y = 1.0; 00119 if (dd.z<=0.0) dd.z = 1.0; 00120 int xsize = (int)((xmax - xmin)/dd.x) + 1; 00121 int ysize = (int)((ymax - ymin)/dd.y) + 1; 00122 int zsize = (int)((zmax - zmin)/dd.z) + 1; 00123 *mp = make_BSGraph(xsize, ysize, zsize); 00124 og = set_vector(xmin, ymax, zmin); 00125 } 00126 00127 // 00128 switch(idx->type) { 00129 00130 case SHAPE_TYPE_POLYGON : 00131 draw_shape_polygon(idx, mp, og, dd, 255, fp); 00132 break; 00133 } 00134 00135 mp->state = JBXL_NORMAL; 00136 return mp; 00137 }