]> www.wagner.pp.ru Git - oss/fgis.git/blob - include/dgt.h
First checked in version
[oss/fgis.git] / include / dgt.h
1 #ifndef DGT_H
2 #define DGT_H
3 # include <stdio.h>
4 #ifndef EPPL_H
5 # include "eppl.h"
6 #endif
7 #ifndef EPP_ERR_H
8 # include "epp_err.h"
9 #endif
10 #define MAX_LINE_LEN 500
11 typedef struct POINT { short int x,y; } POINT;
12 typedef struct DGT_ITEM { long int ID;
13                           short int x1,y1,x2,y2;
14                           short int npoints;
15                           POINT s[MAX_LINE_LEN];
16                         } DGT_ITEM;    
17 struct ITEM_AS_POINT {long int ID;
18                       POINT p;
19                      };
20 typedef struct DGT { double XLeft,YBottom,XRight,YTop;
21                      int mode;
22                      int item_no;  
23                      unsigned char projection;
24                      DGT_ITEM* buffer;
25                      int limit; 
26                      void* F;
27                      int eof;
28                      int modified;
29                      int (*next_item)(struct DGT* buffer); 
30                      void (*rewind) (struct DGT *d); 
31                      void (*dispose) (void *f);  
32                      int (*cmp_item)(DGT_ITEM* i1,DGT_ITEM* i2);  
33                     } DGT;
34 #define KEEP_OLD_VALUE -32768
35                       
36 DGT* open_dgt(char *filename);
37 /*opens existing file, given by name*/
38 DGT* fopen_dgt(FILE *f);
39 /* open existing file given by file variable */
40 DGT* creat_dgt(char *filename,double x_left,double y_bottom,
41                double x_right,double y_top, unsigned char proj);
42 /* creates file with given limits with given name */               
43 DGT* fcreat_dgt(FILE *f ,double x_left,double y_bottom,
44                double x_right,double y_top,unsigned char proj);
45 /* creates dgt file with given limits in given stream */
46 DGT* mcreat_dgt(double x_left,double y_bottom,
47                double x_right,double y_top, unsigned char proj);
48 /* creates empty dgt in memory with given limits*/               
49 DGT* creat_dgt_as(char *filename,DGT* pattern);
50 DGT* fcreat_dgt_as(FILE *f,DGT *pattern);
51 DGT* mcreat_dgt_as(DGT *pattern);
52 /* creates file, with limits as in given file */
53
54 int load_dgt(DGT* dgt);
55 /* loads file opened for reading into memory */
56 void save_dgt(DGT* dgt,FILE *f);
57 /* saves loaded file*/
58 void close_dgt(DGT* dgt);
59 /* Destroys DGT object */
60 void reset_dgt(DGT* dgt);
61 /* rewinds dgt file for first item, reopens for reading,if nessecary */
62 DGT_ITEM* dgt_get(DGT* dgt);
63 /* allocates current item in memory and returns pointer to it*/
64 void dgt_put(DGT *dgt, DGT_ITEM* item);
65 /* inserts item in writable file*/
66 void dgt_replace(DGT *dgt, int index, DGT_ITEM *item);
67 /* replaces item number index with given item (memory files only*/
68 DGT_ITEM* dgt_item_ptr(DGT *dgt, int index);
69 /* returns pointer to specified item without copiing it*/
70 #define dgt_next(dgt) ((dgt)->next_item(dgt))
71 /* flushes current item buffer */
72 void dgt_seek(DGT *dgt,int index);
73 /* makes item with given number current (for memory files only)*/
74 void chk_mask(DGT_ITEM* item);
75 /*set correct values of bounding rectangle*/
76 void dgt_sort(DGT *dgt,int (*compare_func)(DGT_ITEM *i1,DGT_ITEM *i2));
77
78 void for_each_line(DGT *dgt,void (*item_proc)(DGT *dgt),DGT *outstream);
79 void for_each_point(DGT *dgt,void (*item_proc)(DGT *dgt),DGT *outstream);
80 /* Applies given item_proc to each item of given type in file. If outstream 
81    not NULL,
82    copies all items (inclding those, which are not a subject of item_proc
83    to outstream */
84 void for_each_item(DGT *dgt,void (*item_proc)(DGT *dgt));
85 /* Applies given item_proc to each item in file. If items to be copied
86    to other stream, item_proc has to do it itself */
87 /* coordinate recalculation */
88
89
90 int dgt_x(DGT* dgt,double x);
91 int dgt_y(DGT* dgt,double y);
92
93 double real_x(DGT* dgt,int x);
94 double real_y(DGT* dgt,int y);
95 double real_dx(DGT* dgt,int dx);
96 double real_dy(DGT* dgt,int dy);
97 double dgt_dist(DGT* dgt,int x1,int y1,int x2,int y2);
98 double dgt_pdist(DGT* dgt,POINT p1,POINT p2);
99 long int sq_dist(DGT* dgt,int x1,int y1,int x2,int y2);
100 long int sq_pdist(DGT* dgt,POINT p1,POINT p2);
101 long int sq_const(DGT* dgt,double dist);
102 /* item modification */
103 #define dgt_touch(x) ((x)->modified=1);
104 void item_set_id(DGT_ITEM *item,long int newID);
105 #define dgt_set_id(x,ID) ((x)->modified=1,item_set_id((x)->buffer,ID))
106 void dgt_set_point(DGT *dgt,int x,int y);
107 int dgt_add_node(DGT *dgt,int x,int y);
108 int dgt_ins_node(DGT *dgt,int index,int x,int y);
109 int item_mv_node(DGT_ITEM *item,int index,int x,int y);
110 #define dgt_mv_node(d,index,x,y) ((d)->modified=1,item_mv_node((d)->buffer,index,x,y))
111 int dgt_rm_node(DGT *dgt,int index);
112 int dgt_split(DGT *dgt,int index);
113 int dgt_cut_segment(DGT *dgt,int index);
114 /* item utilities */
115 DGT_ITEM* alloc_item(DGT_ITEM* item);
116 /* allocates new copy of item */
117 /* Macros for access current item */
118 #define dgt_item(x) (((DGT *)(x))->buffer)
119 /* returns pointer to current item */
120 #define dgt_line_len(x)  (((DGT *)(x))->buffer->npoints)
121 /* returns lile length (number of points) in current item*/
122
123 /* following macros provide a read/write access to current item */
124 #define dgt_id(x) (((DGT *)(x))->buffer->ID)
125 /*  ID of current item */
126 #define dgt_node(x,i) (((DGT *)(x))->buffer->s[i])
127
128 /* node #i (0 - (line_len-1)) */
129 #define dgt_nx(d,i) (((DGT *)(d))->buffer->s[i].x)
130 #define dgt_ny(d,i) (((DGT *)(d))->buffer->s[i].y)
131 #define dgt_xl(x) (((DGT *)(x))->buffer->x1)                             
132 /* left limit of bounding rectangle */
133 #define dgt_xr(x) (((DGT *)(x))->buffer->x2)   
134 /* right limit of bounding rectangle */
135 #define dgt_yb(x) (((DGT *)(x))->buffer->y1)
136 /* bottom limit of bounding rectangle */   
137 #define dgt_yt(x) (((DGT *)(x))->buffer->y1)   
138 /* top limit of bounding rectangle */
139 #define dgt_pointx(x) (((DGT *)(x))->buffer->x1)   
140 /* X of label point (if current object is label point)*/
141 #define dgt_pointy(x) (((DGT *)(x))->buffer->y1)                     
142 /* Y of label point (if current object is label point)*/
143 #define dgt_is_line(x)  (((DGT *)(x))->buffer->npoints)
144 /* non-zero if current item is line */
145 #define dgt_is_point(x)  (!(((DGT *)(x))->buffer->npoints))
146 /* non-zero if current item is point */
147 #define dgt_point(x) (((((struct ITEM_AS_POINT *)(((DGT *)(x))->buffer)))->p))
148 #define dgt_eof(x) (((DGT *)(x))->eof)
149 /*macros for access item, given by pointer*/
150 #define item_id(x) ((x)->ID)
151 #define item_node(x,i) ((x)->s[i])
152 #define item_xn(d,i) ((d)->s[i].x)
153 #define item_yn(d,i) ((d)->s[i].y)
154 #define item_xl(x) ((x)->x1)
155 #define item_xr(x) ((x)->x2)
156 #define item_yb(x) ((x)->y1)
157 #define item_yt(x) ((x)->y2)
158 #define point_x(x) ((x)->x1)
159 #define point_y(x) ((x)->y1)
160 #define item_len(x) ((x)->npoints)
161 #define item_point(x) (((struct ITEM_AS_POINT *)(x))->p)
162
163 #endif
164