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