JunkBox_Lib  1.10.2
shape_file.h File Reference

SHAPE FILE TOOL Header. More...

#include "gio.h"
#include "graph.h"
Include dependency graph for shape_file.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ShapeIndex
 

Macros

#define SHAPE_TYPE_NULL_SHAPE   0
 
#define SHAPE_TYPE_POINT   1
 
#define SHAPE_TYPE_POLY_LINE   3
 
#define SHAPE_TYPE_POLYGON   5
 
#define SHAPE_TYPE_MULTI_POINT   8
 
#define SHAPE_TYPE_POINTZ   11
 
#define SHAPE_TYPE_MULTI_PATCH   31
 

Functions

ShapeIndexread_shape_index_file (FILE *fp)
 
BSGraphread_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)
 

Detailed Description

Author
Fumi.Iseki (C)

Definition in file shape_file.h.

Macro Definition Documentation

◆ SHAPE_TYPE_MULTI_PATCH

#define SHAPE_TYPE_MULTI_PATCH   31

Definition at line 21 of file shape_file.h.

◆ SHAPE_TYPE_MULTI_POINT

#define SHAPE_TYPE_MULTI_POINT   8

Definition at line 19 of file shape_file.h.

◆ SHAPE_TYPE_NULL_SHAPE

#define SHAPE_TYPE_NULL_SHAPE   0

Definition at line 15 of file shape_file.h.

◆ SHAPE_TYPE_POINT

#define SHAPE_TYPE_POINT   1

Definition at line 16 of file shape_file.h.

◆ SHAPE_TYPE_POINTZ

#define SHAPE_TYPE_POINTZ   11

Definition at line 20 of file shape_file.h.

◆ SHAPE_TYPE_POLY_LINE

#define SHAPE_TYPE_POLY_LINE   3

Definition at line 17 of file shape_file.h.

◆ SHAPE_TYPE_POLYGON

#define SHAPE_TYPE_POLYGON   5

Definition at line 18 of file shape_file.h.

Function Documentation

◆ draw_shape_polygon()

void draw_shape_polygon ( ShapeIndex idx,
BSGraph mp,
vector  og,
vector  dd,
int  cc,
FILE *  fp 
)

Definition at line 138 of file shape_file.c.

139 {
140  size_t rs;
141  UNUSED(rs);
142 
143  int i, j, k, rdint;
144  int kk = (int)(og.z + 0.5); // color
145  if (kk<0 || kk>mp->zs-1) kk = 0;
146 
147  ShapeIndex* sx = idx;
148 
149  for (i=0; i<idx->maxnum; i++) {
150  fseek(fp, sx->offset*2+8, SEEK_SET);
151  rs = fread(&rdint, 4, 1, fp);
152  int type = int_from_little_endian((void*)&rdint);
153  if (type!=SHAPE_TYPE_POLYGON) return;
154 
155  fseek(fp, 32L, SEEK_CUR);
156  rs = fread(&rdint, 4, 1, fp);
157  int parts = int_from_little_endian((void*)&rdint);
158  rs = fread(&rdint, 4, 1, fp);
159  int points = int_from_little_endian((void*)&rdint);
160 
161  for (j=0; j<parts; j++) {
162  fseek(fp, sx->offset*2+52+j*4, SEEK_SET); // offset*2 + 8 + 44 + j*4
163  rs = fread(&rdint, 4, 1, fp);
164  int sttidx = int_from_little_endian((void*)&rdint);
165  int endidx = points - 1;
166 
167  if (j<parts-1) {
168  rs = fread(&rdint, 4, 1, fp);
169  endidx = int_from_little_endian((void*)&rdint) - 1;
170  }
171 
172  double xx, yy, ox, oy;
173  ox = oy = 0.0;
174  fseek(fp, sx->offset*2+52+parts*4+sttidx*16, SEEK_SET); // offset*2 + 8 + 44 + parts*4 + sttidx*16
175 
176  for (k=sttidx; k<=endidx; k++) {
177  rs = fread(&xx, 8, 1, fp);
178  rs = fread(&yy, 8, 1, fp);
179  xx = double_from_little_endian((void*)&xx);
180  yy = double_from_little_endian((void*)&yy);
181 
182  if (k!=sttidx) {
183  int oi = (int)((ox-og.x)/dd.x + 0.5);
184  int oj = (int)((og.y-oy)/dd.y + 0.5);
185  int ii = (int)((xx-og.x)/dd.x + 0.5);
186  int jj = (int)((og.y-yy)/dd.y + 0.5);
187  bline3d(*mp, oi, oj, kk, ii, jj, kk, cc);
188  }
189  ox = xx;
190  oy = yy;
191  }
192  }
193  sx++;
194  }
195 }
#define UNUSED(x)
Definition: common.h:264
void bline3d(BSGraph gd, int x1, int y1, int z1, int x2, int y2, int z2, int cc)
Definition: graph.c:613
#define SHAPE_TYPE_POLYGON
Definition: shape_file.h:18
int zs
zサイズ. 4Byte. 2Dの場合は 1.
Definition: gdata.h:30
int maxnum
Definition: shape_file.h:29
int offset
Definition: shape_file.h:26
double z
z方向成分
Definition: matrix.h:32
double y
y方向成分
Definition: matrix.h:31
double x
x方向成分
Definition: matrix.h:30
int int_from_little_endian(void *ptr)
Definition: tools.c:192
double double_from_little_endian(void *ptr)
エンディアンによるデータ変換
Definition: tools.c:156

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_shape_index_file()

ShapeIndex* read_shape_index_file ( FILE *  fp)

Definition at line 11 of file shape_file.c.

12 {
13  int magic, type, rdint;
14  size_t rs;
15  UNUSED(rs);
16 
17  // Magic Number
18  fseek(fp, 0L, SEEK_SET);
19  rs = fread(&rdint, 4, 1, fp);
20  magic = int_from_big_endian((void*)&rdint);
21  if (magic!=9994) {
22  DEBUG_MODE PRINT_MESG("READ_SHAPE_INDEX_FILE: But Mafic Number = %d\n", magic);
23  return NULL;
24  }
25 
26  // Shape Type
27  fseek(fp, 32L, SEEK_SET);
28  rs = fread(&rdint, 4, 1, fp);
29  type = int_from_little_endian((void*)&rdint);
30 
31  //
32  int i, count = 0;
33 
34  fseek(fp, 100L, SEEK_SET);
35  rs = fread(&rdint, 4, 1, fp);
36  rs = fread(&rdint, 4, 1, fp);
37  while(!feof(fp)) {
38  count++;
39  rs = fread(&rdint, 4, 1, fp); // next record
40  rs = fread(&rdint, 4, 1, fp); // next record
41  }
42 
43  ShapeIndex* shpidx = (ShapeIndex*)malloc(count*sizeof(ShapeIndex));
44  if (shpidx==NULL) return NULL;
45  memset(shpidx, 0, count*sizeof(ShapeIndex));
46 
47  fseek(fp, 100L, SEEK_SET);
48  for (i=0; i<count; i++) {
49  shpidx[i].datanum = i;
50  shpidx[i].type = type;
51  shpidx[i].maxnum = count;
52  rs = fread(&rdint, 4, 1, fp);
53  shpidx[i].offset = int_from_big_endian((void*)&rdint);
54  rs = fread(&rdint, 4, 1, fp);
55  shpidx[i].size = int_from_big_endian((void*)&rdint);
56  }
57 
58  return shpidx;
59 }
int datanum
Definition: shape_file.h:25
int int_from_big_endian(void *ptr)
Definition: tools.c:300
#define PRINT_MESG
環境依存用の出力関数.print_message()
Definition: tools.h:475
#define DEBUG_MODE
Definition: tools.h:502

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.

Here is the call graph for this function:

◆ read_shape_main_file()

BSGraph* read_shape_main_file ( ShapeIndex idx,
BSGraph mp,
vector  og,
vector  dd,
FILE *  fp 
)

Definition at line 62 of file shape_file.c.

63 {
64  int magic, type, rdint;
65  unsigned char rdbyte[8];
66  double xmin, ymin, zmin, xmax, ymax, zmax;
67  size_t rs;
68  UNUSED(rs);
69 
70  // Magic Number
71  fseek(fp, 0L, SEEK_SET);
72  rs = fread(&rdint, 4, 1, fp);
73  magic = int_from_big_endian((void*)&rdint);
74  if (magic!=9994) {
75  DEBUG_MODE PRINT_MESG("READ_SHAPE_MAIN_FILE: But Mafic Number = %d\n", magic);
76  return NULL;
77  }
78 
79  // Shape Type
80  fseek(fp, 32L, SEEK_SET);
81  rs = fread(&rdint, 4, 1, fp);
82  type = int_from_little_endian((void*)&rdint);
83 
84  if (idx->type!=type) {
85  DEBUG_MODE PRINT_MESG("READ_SHAPE_MAIN_FILE: Type mismatch with index file %d != %d\n", type, idx->type);
86  return NULL;
87  }
88 
89  if (idx->type!=SHAPE_TYPE_POLYGON) {
90  DEBUG_MODE PRINT_MESG("READ_SHAPE_MAIN_FILE: Unsupported Shape Type = %d\n", idx->type);
91  return NULL;
92  }
93 
94  // Bounding Box
95  fseek(fp, 36L, SEEK_SET);
96  rs = fread(rdbyte, 8, 1, fp);
97  xmin = double_from_little_endian((void*)rdbyte);
98  rs = fread(rdbyte, 8, 1, fp);
99  ymin = double_from_little_endian((void*)rdbyte);
100  rs = fread(rdbyte, 8, 1, fp);
101  xmax = double_from_little_endian((void*)rdbyte);
102  rs = fread(rdbyte, 8, 1, fp);
103  ymax = double_from_little_endian((void*)rdbyte);
104  rs = fread(rdbyte, 8, 1, fp);
105  zmin = double_from_little_endian((void*)rdbyte);
106  rs = fread(rdbyte, 8, 1, fp);
107  zmax = double_from_little_endian((void*)rdbyte);
108 
109  //
110  if (mp==NULL) {
111  mp = (BSGraph*)malloc(sizeof(BSGraph));
112  memset(mp, 0, sizeof(BSGraph));
113  }
114  if (mp->gp==NULL) {
115  if (dd.x<=0.0) dd.x = 1.0;
116  if (dd.y<=0.0) dd.y = 1.0;
117  if (dd.z<=0.0) dd.z = 1.0;
118  int xsize = (int)((xmax - xmin)/dd.x) + 1;
119  int ysize = (int)((ymax - ymin)/dd.y) + 1;
120  int zsize = (int)((zmax - zmin)/dd.z) + 1;
121  *mp = make_BSGraph(xsize, ysize, zsize);
122  og = set_vector(xmin, ymax, zmin);
123  }
124 
125  //
126  switch(idx->type) {
127 
128  case SHAPE_TYPE_POLYGON :
129  draw_shape_polygon(idx, mp, og, dd, 255, fp);
130  break;
131  }
132 
133  mp->state = JBXL_NORMAL;
134  return mp;
135 }
BSGraph make_BSGraph(int xs, int ys, int zs)
Definition: gdata.c:66
#define JBXL_NORMAL
正常
Definition: jbxl_state.h:32
vector set_vector(double x, double y, double z)
Definition: matrix.c:82
void draw_shape_polygon(ShapeIndex *idx, BSGraph *mp, vector og, vector dd, int cc, FILE *fp)
Definition: shape_file.c:138
Definition: gdata.h:27
int state
状態
Definition: gdata.h:31
uByte * gp
グラフィックデータへのポインタ. xs*ys*zs*1Byte.
Definition: gdata.h:32

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.

Here is the call graph for this function: