ogsf.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. /*!
  2. \file include/ogsf.h
  3. \brief OGSF header file (structures)
  4. This program is free software under the GNU General
  5. Public License (>=v2). Read the file COPYING that
  6. comes with GRASS for details.
  7. \author Original author Bill Brown, USACERL (January 1993)
  8. \author Thematic mapping enabled by Martin Landa <landa.martin gmail.com) (06/2011)
  9. (C) 2011 by the GRASS Development Team
  10. */
  11. #ifndef GRASS_OGSF_H
  12. #define GRASS_OGSF_H
  13. #include <grass/config.h>
  14. #include <grass/bitmap.h>
  15. #if defined(OPENGL_X11) || defined(OPENGL_WINDOWS)
  16. #include <GL/gl.h>
  17. #endif
  18. #ifdef OPENGL_AQUA
  19. #include <OpenGL/gl.h>
  20. #endif
  21. #include <grass/gis.h>
  22. #define GS_UNIT_SIZE 1000.
  23. #define BETWEEN(x, a, b) (((x) > (a) && (x) < (b)) || ((x) > (b) && (x) < (a)))
  24. #define GS_NEAR_EQUAL(x, y, ratio) ((x) == (y) || ((x) == 0.0? \
  25. GS_BETWEEN((x), (y)+(y)*(ratio), (y)-(y)*(ratio)):\
  26. GS_BETWEEN((y), (x)+(x)*(ratio), (x)-(x)*(ratio))))
  27. /* current maximums */
  28. #define MAX_SURFS 12
  29. #define MAX_VECTS 50
  30. #define MAX_SITES 50
  31. #define MAX_VOLS 12 /* should match MAX_VOL_FILES below ? */
  32. #define MAX_DSP 12
  33. #define MAX_ATTS 7
  34. #define MAX_LIGHTS 3
  35. #define MAX_CPLANES 6
  36. #define MAX_ISOSURFS 12
  37. #define MAX_SLICES 12
  38. /* for gvl_file.c */
  39. #define MAX_VOL_SLICES 4
  40. #define MAX_VOL_FILES 100
  41. /* surface display modes */
  42. #define DM_GOURAUD 0x00000100
  43. #define DM_FLAT 0x00000200 /* defined for symmetry */
  44. #define DM_FRINGE 0x00000010
  45. #define DM_WIRE 0x00000001
  46. #define DM_COL_WIRE 0x00000002
  47. #define DM_POLY 0x00000004
  48. #define DM_WIRE_POLY 0x00000008
  49. #define DM_GRID_WIRE 0x00000400
  50. #define DM_GRID_SURF 0x00000800
  51. #define WC_COLOR_ATT 0xFF000000
  52. #define IFLAG unsigned int
  53. /* surface attribute ***descriptors*** */
  54. #define ATT_NORM 0 /* library use only */
  55. #define ATT_TOPO 1
  56. #define ATT_COLOR 2
  57. #define ATT_MASK 3
  58. #define ATT_TRANSP 4
  59. #define ATT_SHINE 5
  60. #define ATT_EMIT 6
  61. #define LEGAL_ATT(a) (a >= 0 && a < MAX_ATTS)
  62. /* surface attribute **sources** */
  63. #define NOTSET_ATT 0
  64. #define MAP_ATT 1
  65. #define CONST_ATT 2
  66. #define FUNC_ATT 3
  67. #define LEGAL_SRC(s) (s==NOTSET_ATT||s==MAP_ATT||s==CONST_ATT||s==FUNC_ATT)
  68. /* site markers */
  69. #define ST_X 1
  70. #define ST_BOX 2
  71. #define ST_SPHERE 3
  72. #define ST_CUBE 4
  73. #define ST_DIAMOND 5
  74. #define ST_DEC_TREE 6
  75. #define ST_CON_TREE 7
  76. #define ST_ASTER 8
  77. #define ST_GYRO 9
  78. #define ST_HISTOGRAM 10
  79. /* Buffer modes */
  80. #define GSD_FRONT 1
  81. #define GSD_BACK 2
  82. #define GSD_BOTH 3
  83. /* fence colormodes */
  84. #define FC_OFF 0
  85. #define FC_ABOVE 1
  86. #define FC_BELOW 2
  87. #define FC_BLEND 3
  88. #define FC_GREY 4
  89. /* legend types */
  90. #define LT_DISCRETE 0x00000100
  91. #define LT_CONTINUOUS 0x00000200
  92. #define LT_LIST 0x00000010
  93. /* list automatically discrete */
  94. #define LT_RANGE_LOWSET 0x00000001
  95. #define LT_RANGE_HISET 0x00000002
  96. #define LT_RANGE_LOW_HI 0x00000003
  97. #define LT_INVERTED 0x00000008
  98. #define LT_SHOW_VALS 0x00001000
  99. #define LT_SHOW_LABELS 0x00002000
  100. /* types of volume files */
  101. #define VOL_FTYPE_RASTER3D 0
  102. /* types of volume values */
  103. #define VOL_DTYPE_FLOAT 0
  104. #define VOL_DTYPE_DOUBLE 1
  105. /*#define TRACE_FUNCS */
  106. /*#define DEBUG */
  107. #define X 0
  108. #define Y 1
  109. #define Z 2
  110. #define W 3
  111. #define FROM 0
  112. #define TO 1
  113. /* colormodes */
  114. #define CM_COLOR 0
  115. #define CM_EMISSION 1
  116. #define CM_AMBIENT 2
  117. #define CM_DIFFUSE 3
  118. #define CM_SPECULAR 4
  119. #define CM_AD 5
  120. #define CM_NULL 6
  121. #define CM_WIRE CM_COLOR
  122. #define NULL_COLOR 0xFFFFFF
  123. /* attribute sizes - NOT YET USED */
  124. #define GS_CHAR8 char
  125. #define GS_SHORT16 short
  126. #define GS_INT32 int
  127. /* attribute ***types*** */
  128. #define ATTY_NULL 32 /* internal use only */
  129. #define ATTY_MASK 16 /* can't use this one for numbytes */
  130. #define ATTY_FLOAT 8 /* can't use this one for numbytes */
  131. #define ATTY_INT 4
  132. #define ATTY_SHORT 2
  133. #define ATTY_CHAR 1
  134. #define ATTY_ANY 63 /* internal use only */
  135. #define LEGAL_TYPE(t) \
  136. (t==ATTY_MASK || t==ATTY_FLOAT || t==ATTY_INT || t==ATTY_SHORT || t==ATTY_CHAR)
  137. #define MAXDIMS 4
  138. #define FUDGE(gs) ((gs->zmax_nz - gs->zmin_nz)/500.)
  139. #define DOT3( a, b ) ( (a)[X]*(b)[X] + (a)[Y]*(b)[Y] + (a)[Z]*(b)[Z] )
  140. /* changed flags for datasets */
  141. #define CF_NOT_CHANGED 0x000000
  142. #define CF_COLOR_PACKED 0x000001
  143. #define CF_USR_CHANGED 0x000010
  144. #define CF_CHARSCALED 0x000100
  145. #define MAX_TF 6
  146. #define MASK_TL 0x10000000
  147. #define MASK_TR 0x01000000
  148. #define MASK_BR 0x00100000
  149. #define MASK_BL 0x00010000
  150. #define MASK_NPTS 0x00000007
  151. #define OGSF_POINT 1
  152. #define OGSF_LINE 2
  153. #define OGSF_POLYGON 3
  154. #define RED_MASK 0x000000FF
  155. #define GRN_MASK 0x0000FF00
  156. #define BLU_MASK 0x00FF0000
  157. typedef float Point4[4];
  158. typedef float Point3[3];
  159. typedef float Point2[2];
  160. typedef struct
  161. {
  162. float *fb;
  163. int *ib;
  164. short *sb;
  165. unsigned char *cb;
  166. struct BM *bm;
  167. struct BM *nm; /* null mask: set = null */
  168. float (*tfunc) (float, int);
  169. float k;
  170. } typbuff;
  171. typedef struct
  172. { /* use hash table? */
  173. int n_elem; /* if n_elem == 256, index == NULL */
  174. char *index;
  175. int *value;
  176. } table256;
  177. typedef struct
  178. { /* applied thusly: offset, mult, if(use_lookup) lookup */
  179. float offset;
  180. float mult;
  181. int use_lookup;
  182. table256 lookup;
  183. } transform;
  184. /* move this to dataset file? */
  185. typedef struct
  186. {
  187. int data_id;
  188. int dims[MAXDIMS];
  189. int ndims;
  190. size_t numbytes;
  191. char *unique_name;
  192. typbuff databuff;
  193. IFLAG changed;
  194. int need_reload;
  195. } dataset;
  196. /* maybe add transformation matrix? */
  197. typedef struct
  198. {
  199. IFLAG att_src; /* NOTSET_ATT, MAP_ATT, CONST_ATT, FUNC_ATT */
  200. IFLAG att_type; /* ATTY_INT, ATTY_SHORT, ATTY_CHAR, or ATTY_FLOAT */
  201. int hdata; /* handle to dataset */
  202. int (*user_func) ();
  203. float constant;
  204. int *lookup; /* TODO: use transform instead */
  205. float min_nz, max_nz, range_nz;
  206. float default_null;
  207. } gsurf_att;
  208. typedef struct g_surf
  209. {
  210. int gsurf_id;
  211. int cols, rows;
  212. gsurf_att att[MAX_ATTS]; /* mask, topo, color, etc. */
  213. IFLAG draw_mode; /*DM_GOURAUD | DM_FRINGE | DM_POLY, DM_WIRE, DM_WIRE_POLY */
  214. long wire_color; /* 0xBBGGRR or WC_COLOR_ATT */
  215. double ox, oy; /* real world origin (i.e., SW corner) */
  216. double xres, yres;
  217. float z_exag;
  218. float x_trans, y_trans, z_trans;
  219. float xmin, xmax, ymin, ymax, zmin, zmax, zminmasked;
  220. float xrange, yrange, zrange;
  221. float zmin_nz, zmax_nz, zrange_nz;
  222. int x_mod, y_mod, x_modw, y_modw; /*cells per viewcell, per wire viewcell */
  223. int nz_topo, nz_color; /* no zero flags */
  224. int mask_needupdate, norm_needupdate;
  225. unsigned long *norms;
  226. struct BM *curmask;
  227. struct g_surf *next;
  228. void *clientdata;
  229. } geosurf;
  230. /* maybe put attribute info here instead of in geovect - allow a single
  231. vector file to have multiple attributes ? Cached lines should
  232. usually be stored as 2d, since they may be draped on multiple
  233. surfaces & Z will vary depending upon surface. */
  234. /* Struct for vector feature displaying attributes */
  235. typedef struct g_vect_style
  236. {
  237. int color; /* Line color */
  238. int symbol; /* Point symbol/line type */
  239. float size; /* Symbol size. Unset for lines. */
  240. int width; /* Line width. Also used for lines forming symbols i.e. X */
  241. /*TODO:fill; Area fill pattern */
  242. /*TODO:falpha; Area fill transparency */
  243. /*TODO:lalpha; Line/boundary/point transparency */
  244. /*TODO:struct *orientation; Symbol orientation */
  245. struct g_vect_style *next; /* Point to next gvstyle struct if single point has multiple styles.
  246. In such case feature with next style should be shifted. */
  247. } gvstyle;
  248. /* Struct for vector map (thematic mapping) */
  249. typedef struct g_vect_style_thematic
  250. {
  251. int active;
  252. int layer;
  253. char *color_column;
  254. char *symbol_column;
  255. char *size_column;
  256. char *width_column;
  257. } gvstyle_thematic;
  258. /* Line instance */
  259. typedef struct g_line
  260. {
  261. int type;
  262. float norm[3];
  263. int dims, npts;
  264. Point3 *p3;
  265. Point2 *p2;
  266. struct line_cats *cats; /* Store information about all layers/cats for thematic display */
  267. gvstyle *style; /* Line instance look&feel */
  268. signed char highlighted; /* >0 Feature is highlighted */
  269. struct g_line *next;
  270. } geoline;
  271. /* Vector map (lines) */
  272. typedef struct g_vect
  273. {
  274. int gvect_id;
  275. int use_mem, n_lines;
  276. int drape_surf_id[MAX_SURFS]; /* if you want 'em flat, define the surface */
  277. int use_z;
  278. int n_surfs;
  279. char *filename;
  280. float x_trans, y_trans, z_trans;
  281. /* also maybe center & rotate? */
  282. geoline *lines;
  283. geoline *fastlines;
  284. int (*bgn_read) (), (*end_read) (), (*nxt_line) ();
  285. struct g_vect *next;
  286. void *clientdata;
  287. gvstyle_thematic *tstyle; /* thematic mapping */
  288. gvstyle *style; /* Vector default look&feel */
  289. gvstyle *hstyle; /* IMHO highlight should be per layer basis. */
  290. } geovect;
  291. /* Point instance */
  292. typedef struct g_point
  293. {
  294. int dims;
  295. Point3 p3;
  296. struct line_cats *cats; /* Store information about all layers/cats for thematic display */
  297. gvstyle *style;
  298. signed char highlighted; /* >0 Feature is highlighted */
  299. struct g_point *next;
  300. } geopoint;
  301. /* Vector map (points) */
  302. typedef struct g_site
  303. {
  304. int gsite_id;
  305. int drape_surf_id[MAX_SURFS]; /* ditto */
  306. int n_surfs, n_sites;
  307. int use_z, use_mem;
  308. int has_z; /* set when file loaded */
  309. char *filename;
  310. transform attr_trans;
  311. float x_trans, y_trans, z_trans;
  312. geopoint *points;
  313. int (*bgn_read) (), (*end_read) (), (*nxt_site) ();
  314. struct g_site *next;
  315. void *clientdata;
  316. gvstyle_thematic *tstyle; /* thematic mapping */
  317. gvstyle *style; /* points default look&feel */
  318. gvstyle *hstyle; /* IMHO highlight should be per layer basis */
  319. } geosite;
  320. typedef struct
  321. {
  322. int data_id; /* id */
  323. IFLAG file_type; /* file type */
  324. unsigned int count; /* number of referencies to this file */
  325. char *file_name; /* file name */
  326. IFLAG data_type;
  327. void *map; /* pointer to volume file descriptor */
  328. double min, max; /* minimum, maximum value in file */
  329. IFLAG status; /* current status */
  330. IFLAG mode; /* current read mode */
  331. void *buff; /* data buffer */
  332. } geovol_file;
  333. typedef struct
  334. {
  335. IFLAG att_src;
  336. int hfile;
  337. int (*user_func) ();
  338. float constant;
  339. void *att_data;
  340. int changed;
  341. } geovol_isosurf_att;
  342. typedef struct
  343. {
  344. int inout_mode;
  345. geovol_isosurf_att att[MAX_ATTS];
  346. int data_desc;
  347. unsigned char *data;
  348. } geovol_isosurf;
  349. typedef struct
  350. {
  351. int dir;
  352. float x1, x2, y1, y2, z1, z2;
  353. unsigned char *data;
  354. int changed;
  355. int mode, transp;
  356. } geovol_slice;
  357. typedef struct g_vol
  358. {
  359. int gvol_id;
  360. struct g_vol *next;
  361. int hfile;
  362. int cols, rows, depths;
  363. double ox, oy, oz;
  364. double xres, yres, zres;
  365. double xmin, xmax, ymin, ymax, zmin, zmax;
  366. double xrange, yrange, zrange;
  367. float x_trans, y_trans, z_trans;
  368. int draw_wire;
  369. int n_isosurfs;
  370. geovol_isosurf *isosurf[MAX_ISOSURFS];
  371. int isosurf_x_mod, isosurf_y_mod, isosurf_z_mod;
  372. IFLAG isosurf_draw_mode;
  373. int n_slices;
  374. geovol_slice *slice[MAX_SLICES];
  375. int slice_x_mod, slice_y_mod, slice_z_mod;
  376. IFLAG slice_draw_mode;
  377. void *clientdata;
  378. } geovol;
  379. struct lightdefs
  380. {
  381. float position[4]; /* X, Y, Z, (1=local/0=inf) */
  382. float color[3]; /* R, G, B */
  383. float ambient[3]; /* R, G, B */
  384. float emission[3]; /* R, G, B */
  385. float shine; /* 0. to 128. */
  386. };
  387. struct georot
  388. {
  389. int do_rot; /* do rotation */
  390. double rot_angle; /* rotation angle */
  391. double rot_axes[3]; /* rotation axis */
  392. GLdouble rotMatrix[16]; /* rotation matrix */
  393. };
  394. typedef struct
  395. {
  396. int coord_sys; /* latlon, equal area, etc */
  397. int view_proj; /* perspective, ortho */
  398. int infocus; /* fixed center of view - true or false */
  399. float from_to[2][4];
  400. struct georot rotate;
  401. int twist, fov, incl, look; /* 10ths of degrees */
  402. float real_to[4], vert_exag; /* a global Z exag */
  403. float scale;
  404. struct lightdefs lights[MAX_LIGHTS];
  405. } geoview;
  406. typedef struct
  407. { /* need to add elements here for off_screen drawing */
  408. float nearclip, farclip, aspect;
  409. short left, right, bottom, top; /* Screen coordinates */
  410. int bgcol;
  411. } geodisplay;
  412. extern void (*Cxl_func) ();
  413. extern void (*Swap_func) ();
  414. /* Key frames */
  415. /* these have to be 1 << KF_id_index */
  416. #define KF_FROMX_MASK 0x00000001
  417. #define KF_FROMY_MASK 0x00000002
  418. #define KF_FROMZ_MASK 0x00000004
  419. #define KF_FROM_MASK 0x00000007
  420. #define KF_DIRX_MASK 0x00000008
  421. #define KF_DIRY_MASK 0x00000010
  422. #define KF_DIRZ_MASK 0x00000020
  423. #define KF_DIR_MASK 0x00000038
  424. #define KF_FOV_MASK 0x00000040
  425. #define KF_TWIST_MASK 0x00000080
  426. #define KF_ALL_MASK 0x000000FF
  427. #define KF_NUMFIELDS 8
  428. #define KF_LINEAR 111
  429. #define KF_SPLINE 222
  430. #define KF_LEGAL_MODE(m) (m == KF_LINEAR || m == KF_SPLINE)
  431. #define KF_FROMX 0
  432. #define KF_FROMY 1
  433. #define KF_FROMZ 2
  434. #define KF_DIRX 3
  435. #define KF_DIRY 4
  436. #define KF_DIRZ 5
  437. #define KF_FOV 6
  438. #define KF_TWIST 7
  439. #define FM_VECT 0x00000001
  440. #define FM_SITE 0x00000002
  441. #define FM_PATH 0x00000004
  442. #define FM_VOL 0x00000008
  443. #define FM_LABEL 0x00000010
  444. typedef struct view_node
  445. {
  446. float fields[KF_NUMFIELDS];
  447. } Viewnode;
  448. typedef struct key_node
  449. {
  450. float pos, fields[KF_NUMFIELDS];
  451. int look_ahead;
  452. unsigned long fieldmask;
  453. struct key_node *next, *prior;
  454. } Keylist;
  455. /* Bring all the function prototypes */
  456. #include <grass/defs/ogsf.h>
  457. #endif /* GRASS_OGSF_H */