gsget.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #ifndef _GSGET_H
  2. #define _GSGET_H
  3. #include <grass/ogsf.h>
  4. #define GET_MAPATT1(buff, offset, att) att=(buff->ib? (float)buff->ib[offset]: \
  5. buff->sb? (float)buff->sb[offset]: \
  6. buff->cb? (float)buff->cb[offset]: \
  7. buff->fb? (float)buff->fb[offset]: \
  8. 0.0)
  9. #define GET_MAPATT2(buff, offset, att) att=(buff->ib? (float)buff->ib[offset]: \
  10. buff->sb? (float)buff->sb[offset]: \
  11. buff->cb? (float)buff->cb[offset]: \
  12. buff->fb? (float)buff->fb[offset]: \
  13. buff->k); \
  14. if(buff->tfunc) \
  15. att = (buff->tfunc)(att, offset);
  16. /* cast to float, otherwise doesn't seem to handle neg. values */
  17. #define SCALE_ATT(att, val, low, high) ((val) <= att->max_nz && \
  18. (val) >= att->min_nz && att->range_nz? \
  19. (((val) - att->min_nz)/att->range_nz) * \
  20. ((high) - (low)) + (low): 0)
  21. #define GET_MAPATT(buff, offset, att) (get_mapatt(buff, offset, &(att)))
  22. #define BM_GET_BYOFFSET(bm, off) (bm? BM_get(bm, (off%bm->cols), (off/bm->cols)): 0)
  23. #define XYMAXPOS 0x3ff /* 1023 */
  24. #define ZMAXPOS 0x3ff /* 1023 */
  25. #define NXMASK 0xffe00000 /* top 11 bits */
  26. #define NYMASK 0x1ffc00 /* middle 11 bits of packed int */
  27. #define NZMASK 0x3ff /* lowest 10 bits */
  28. #define NZUP 0x000003ff
  29. /* Fetch Normal vector from packed int */
  30. /*
  31. #define FNORM(i,nv) \
  32. nv[X] = ((int)(((i) & NXMASK) >> 21) - XYMAXPOS)/(float)XYMAXPOS; \
  33. nv[Y] = ((int)(((i) & NYMASK) >> 10) - XYMAXPOS)/(float)XYMAXPOS; \
  34. nv[Z] = (int)((i) & NZMASK) * GS_global_exag()/(float)ZMAXPOS
  35. */
  36. #define FNORM(i,nv) \
  37. nv[X] = ((int)(((i) & NXMASK) >> 21) - XYMAXPOS)/(float)XYMAXPOS; \
  38. nv[Y] = ((int)(((i) & NYMASK) >> 10) - XYMAXPOS)/(float)XYMAXPOS; \
  39. nv[Z] = (int)((i) & NZMASK) /(float)ZMAXPOS
  40. /* Pack Normal vector into int */
  41. #define PNORM(i,nv) \
  42. i = ((unsigned int)((nv[X]*XYMAXPOS)+XYMAXPOS) << 21) | \
  43. ((unsigned int)((nv[Y]*XYMAXPOS)+XYMAXPOS) << 10) | \
  44. (unsigned int)(nv[Z]*ZMAXPOS)
  45. #endif /* _GSGET_H */