home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / demos / gpc / bifmacro.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-09  |  8.9 KB  |  299 lines

  1. /* $XConsortium: bifmacro.h,v 5.2 91/07/10 08:27:25 rws Exp $ */
  2.  
  3. /*
  4.  */
  5. /*--------------------------------------------------------------------*\
  6. |
  7. |  Copyright (C) 1989,1990, 1991, National Computer Graphics Association
  8. |
  9. |  Permission is granted to any individual or institution to use, copy, or
  10. |  redistribute this software so long as it is not sold for profit, provided
  11. |  this copyright notice is retained.
  12. |
  13. |                         Developed for the
  14. |                National Computer Graphics Association
  15. |                         2722 Merrilee Drive
  16. |                         Fairfax, VA  22031
  17. |                           (703) 698-9600
  18. |
  19. |                                by
  20. |                 SimGraphics Engineering Corporation
  21. |                    1137 Huntington Drive  Unit A
  22. |                      South Pasadena, CA  91030
  23. |                           (213) 255-0900
  24. |---------------------------------------------------------------------
  25. |
  26. | Author        :    jmz / SimGraphics Engineering Corportation
  27. |
  28. | File          :    bifmacro.h
  29. | Date          :    3/17/89
  30. | Project       :    PLB
  31. |
  32. | Description    :    Useful macros, from vector copying to
  33. |            yacc-token-to-BIF-constants mappings
  34. |
  35. | Status         :     Version 1.0
  36. |            Not completely organized.  
  37. |            Some macros could use extra
  38. |            ()'s to make them "bullet-proof"
  39. |
  40. | Revisions     :    
  41. |    4/4/89        Added macro Transpose44
  42. |    2/90        Error Macros upgraded to meet ANSI cpp spec.
  43. |
  44. \*--------------------------------------------------------------------*/
  45.  
  46. /* ---------------------------------------------------------------------*\
  47. | Local MACROS                                        
  48. \*--------------------------------------------------------------------- */
  49.  
  50. /* Fill the top of an entity */
  51. #define HEADER(ent,type,hf,next_ent) \
  52. {\
  53.     ent->entity_type = type;\
  54.     ent->handler     = hf;\
  55.     ent->next        = next_ent;\
  56.     ent->exception     = 0;\
  57. }
  58.  
  59. /* Generalized Traverser Call */
  60. #define    Traverse(traverser_state,entity) \
  61.     (*traverser_state->handler)(traverser_state,entity)
  62.  
  63. /* Free all Non Retained Entities */
  64. #define    Free_NRE(traverser_state, entity) \
  65. {\
  66.     if (traverser_state->open_structure == NULL )\
  67.         free(entity);\
  68. } /* End macro Free_NRE */
  69.  
  70. /* Return the traverser mode */
  71. #define    Build_mode(traverser_state) \
  72.      (traverser_state->open_structure == NULL ? 1 : 0 )
  73.  
  74. #define Cpvec3f(a,b) \
  75. { \
  76.     b[0] = a[0] ; \
  77.     b[1] = a[1] ; \
  78.     b[2] = a[2] ; \
  79. } /* End macro Cpvec3f */
  80.  
  81. #define DOTVEC3F(a,b) \
  82. ( \
  83.     b[0] * a[0] + \
  84.     b[1] * a[1] + \
  85.     b[2] * a[2]  \
  86. ) /* End macro DOTVEC3F */
  87.  
  88. #define Cpmatrix44(mata, matb) \
  89. {\
  90.     matb[0][0]=mata[0][0]; matb[0][1]=mata[0][1]; \
  91.     matb[0][2]=mata[0][2]; matb[0][3]=mata[0][3]; \
  92.     matb[1][0]=mata[1][0]; matb[1][1]=mata[1][1]; \
  93.     matb[1][2]=mata[1][2]; matb[1][3]=mata[1][3]; \
  94.     matb[2][0]=mata[2][0]; matb[2][1]=mata[2][1]; \
  95.     matb[2][2]=mata[2][2]; matb[2][3]=mata[2][3]; \
  96.     matb[3][0]=mata[3][0]; matb[3][1]=mata[3][1]; \
  97.     matb[3][2]=mata[3][2]; matb[3][3]=mata[3][3]; \
  98. } /* End macro Cpmatrix44 */
  99.  
  100. #define MAX_VAL(a,b) (( (a) > (b) ) ? (a) : (b)  )
  101. #define MIN_VAL(a,b) (( (a) < (b) ) ? (a) : (b)  )
  102.  
  103. #ifdef EXTERNAL_NOTE
  104.     The error reporting macros have been modified to conform with
  105.     the ANSI C macro argument replacement specifications.
  106. #endif /* EXTERNAL_NOTE */
  107. #define ERROR_MATRIX_ID(mat_id,entity) \
  108. {\
  109.     if ( !(-1 < mat_id && mat_id < MATRIX_TABLE_SIZE ) ) \
  110.     { \
  111.         char buffy[255];\
  112.         char *find_keyword_token();\
  113.         \
  114.         sprintf(buffy, "%s: matrix_id %d out of range.",\
  115.             find_keyword_token(entity), mat_id);\
  116.         yyerror(buffy);\
  117.         \
  118.         sprintf(buffy, "Valid range is 0 <= matrix_id < %d.",\
  119.                 MATRIX_TABLE_SIZE); \
  120.         yyerror(buffy);\
  121.         exit(-1); \
  122.     }\
  123. } /* End macro Error_matrix_id */
  124.  
  125.  
  126. #define ERROR(what) \
  127. {\
  128.     yyerror(what);\
  129.     exit(-1);\
  130. } /* End macro ERROR */
  131.  
  132. #define ENT_ERROR(ent) \
  133. {\
  134.     if ( ent == NULL ) \
  135.             ERROR("OUT_OF_MEMORY");\
  136. }
  137.  
  138. #define BEGEND(what) \
  139. {\
  140.     switch ( begin_or_end )\
  141.     {\
  142.     case BIF_P_BEGIN:\
  143.         printf("Beginning %s \n", what);\
  144.         break;\
  145.     case BIF_P_END:\
  146.         printf("End %s \n", what);\
  147.         break;\
  148.     }\
  149. } /* End macro BEGEND */
  150.  
  151. #define PRINT_MATRIX44f(mat) \
  152. {\
  153.     printf("Row1: %f %f %f %f\n",mat[0][0],mat[0][1],mat[0][2],mat[0][3]);\
  154.     printf("Row2: %f %f %f %f\n",mat[1][0],mat[1][1],mat[1][2],mat[1][3]);\
  155.     printf("Row3: %f %f %f %f\n",mat[2][0],mat[2][1],mat[2][2],mat[2][3]);\
  156.     printf("Row4: %f %f %f %f\n",mat[3][0],mat[3][1],mat[3][2],mat[3][3]);\
  157. } /* End macro PRINT_MATRIX44 */
  158.  
  159. #define PRINT_MATRIX44(mat) \
  160. {\
  161.     printf("Row1: %lf %lf %lf %lf\n",mat[0][0],mat[0][1],mat[0][2],mat[0][3]);\
  162.     printf("Row2: %lf %lf %lf %lf\n",mat[1][0],mat[1][1],mat[1][2],mat[1][3]);\
  163.     printf("Row3: %lf %lf %lf %lf\n",mat[2][0],mat[2][1],mat[2][2],mat[2][3]);\
  164.     printf("Row4: %lf %lf %lf %lf\n",mat[3][0],mat[3][1],mat[3][2],mat[3][3]);\
  165. } /* End macro PRINT_MATRIX44 */
  166.  
  167. #define REMAP_CMODEL(cmodel) \
  168.     ( ((cmodel) == RGB ) ?  BIF_RGB : \
  169.     ( ((cmodel) == CIE ) ?  BIF_CIE : \
  170.     ( ((cmodel) == HSV ) ?  BIF_HSV : \
  171.                 BIF_HLS ) ) )
  172.  
  173. #define REMAP_CONCAT(concat) \
  174.     ( ( (concat) == PRECONCAT  ) ? BIF_PRECONCAT  : \
  175.     ( ( (concat) == POSTCONCAT ) ? BIF_POSTCONCAT : \
  176.             BIF_REPLACE ) )
  177.  
  178. #define REMAP_PROJ(proj_type) \
  179.     ( ( (proj_type) == PARALLEL  ) ? BIF_PARALLEL  : \
  180.         BIF_PERSPECTIVE )
  181.  
  182. #define REMAP_CLIP(clip) \
  183.     ( ( ( (clip) == XY_CLIP ) || ( (clip) == FRONT_CLIP )  || \
  184.         ( (clip) == BACK_CLIP ) ) ? BIF_CLIP  : BIF_NO_CLIP )
  185.  
  186. #define REMAP_INTSTYLE(style) \
  187.     ( ((style) == HOLLOW ) ? BIF_HOLLOW : \
  188.     ( ((style) == SOLID  ) ? BIF_SOLID  : \
  189.     ( ((style) == PATTERN) ? BIF_PATTERN: \
  190.                  BIF_EMPTY ) ) )
  191.  
  192. #define REMAP_EDGEFLAG(flag) \
  193.     ( ( (flag) == ENABLE  ) ? BIF_ON  : BIF_OFF )
  194.  
  195. #define REMAP_TEXTFONT(flag) \
  196.     ( ( (flag) == -1  ) ? 1  : 1 )
  197.  
  198. #define REMAP_TEXTPREC(prec) \
  199.     ( ( (prec) == STRING  ) ? BIF_STRING  : \
  200.     ( ( (prec) == CHAR    ) ? BIF_CHAR    : \
  201.                   BIF_STROKE  ) )
  202.  
  203. #define REMAP_LIGHTTYPE(type) \
  204.     ( ( (type) == AMBIENT_LIGHT     ) ? BIF_AMBIENT     : \
  205.     ( ( (type) == DIRECTIONAL_LIGHT ) ? BIF_DIRECTIONAL : \
  206.     ( ( (type) == POSITIONAL_LIGHT  ) ? BIF_POSITIONAL  : \
  207.                         BIF_SPOT ) ) )
  208.  
  209. #define REMAP_DCMODE(flag) \
  210.     ( ( (flag) == ENABLE  ) ? BIF_ON  : BIF_OFF )
  211.  
  212. #define REMAP_HLHS(flag) \
  213.     ( ( (flag) == HLHS_ENABLE  ) ? BIF_HLHS_ENABLE  : \
  214.                        BIF_HLHS_DISABLE )
  215.  
  216. #define REMAP_GETMAT(get) \
  217.     ( ( (get) == VIEW_MAPPING     ) ? BIF_VIEW_MAPPING     :\
  218.     ( ( (get) == VIEW_ORIENTATION ) ? BIF_VIEW_ORIENTATION :\
  219.     ( ( (get) == GLOBAL_MODELLING ) ? BIF_GLOBAL_MODELLING :\
  220.     ( ( (get) == LOCAL_MODELLING  ) ? BIF_LOCAL_MODELLING  :\
  221.                 BIF_COMPOSITE_MODELLING ) ) ) )
  222.  
  223. #define REMAP_CSFID(colType) \
  224.     ( ( (colType) == LINE_COLOR     ) ? FIG_PCOPL    :\
  225.     ( ( (colType) == INTERIOR_COLOR ) ? FIG_PCOINT    :\
  226.     ( ( (colType) == EDGE_COLOR     ) ? FIG_PCOEDG    :\
  227.     ( ( (colType) == TEXT_COLOR     ) ? FIG_PCOTXT    :\
  228.     ( ( (colType) == MARKER_COLOR   ) ? FIG_PCOPM    :\
  229.                         FIG_PCOBK ) ) ) ) )
  230.  
  231. #define REMAP_CSFIDINDEX(colType) \
  232.     ( ( (colType) == LINE_COLOR_INDEX     ) ? FIG_PCOPL    :\
  233.     ( ( (colType) == INTERIOR_COLOR_INDEX ) ? FIG_PCOINT    :\
  234.     ( ( (colType) == EDGE_COLOR_INDEX     ) ? FIG_PCOEDG    :\
  235.     ( ( (colType) == TEXT_COLOR_INDEX     ) ? FIG_PCOTXT    :\
  236.     ( ( (colType) == MARKER_COLOR_INDEX   ) ? FIG_PCOPM    :\
  237.                           FIG_PCOBK ) ) ) ) )
  238.  
  239. #define REMAP_INVOKE(flag) \
  240.     ( ( (flag) == CALL  ) ? BIF_CALL  : BIF_EXECUTE )
  241.  
  242.  
  243. #define REMAP_PIXFUNC(func) \
  244.     ( ( (func) == ADD        ) ?  BIF_PF_ADD           :\
  245.     ( ( (func) == AND        ) ?  BIF_PF_AND           :\
  246.     ( ( (func) == CLEAR        ) ?  BIF_PF_CLEAR         :\
  247.     ( ( (func) == INVERT        ) ?  BIF_PF_INVERT        :\
  248.     ( ( (func) == NAND        ) ?  BIF_PF_NAND          :\
  249.     ( ( (func) == NOOP        ) ?  BIF_PF_NOOP          :\
  250.     ( ( (func) == NOR        ) ?  BIF_PF_NOR           :\
  251.     ( ( (func) == OR         ) ?  BIF_PF_OR            :\
  252.     ( ( (func) == REPLACE        ) ?  BIF_PF_REPLACE       :\
  253.     ( ( (func) == SET        ) ?  BIF_PF_SET           :\
  254.     ( ( (func) == SUBTRACT_DEST    ) ?  BIF_PF_SUBTRACT_DEST :\
  255.     ( ( (func) == SUBTRACT_SOURCE    ) ?  BIF_PF_SUBTRACT_SOURCE :\
  256.                     XOR ) ) ) ) ) ) ) ) ) ) ) )
  257.  
  258. #define Cp16f(a,b) \
  259. { \
  260.     b[ 0] = a[ 0] ; \
  261.     b[ 1] = a[ 1] ; \
  262.     b[ 2] = a[ 2] ; \
  263.     b[ 3] = a[ 3] ; \
  264.     b[ 4] = a[ 4] ; \
  265.     b[ 5] = a[ 5] ; \
  266.     b[ 6] = a[ 6] ; \
  267.     b[ 7] = a[ 7] ; \
  268.     b[ 8] = a[ 8] ; \
  269.     b[ 9] = a[ 9] ; \
  270.     b[10] = a[10] ; \
  271.     b[11] = a[11] ; \
  272.     b[12] = a[12] ; \
  273.     b[13] = a[13] ; \
  274.     b[14] = a[14] ; \
  275.     b[15] = a[15] ; \
  276. } /* End macro Cp16f */
  277.  
  278.  
  279. #define Transpose44(mata, matb) \
  280. {\
  281. /* Diagonal Terms  ( Copy ) */ \
  282.     matb[0][0]=mata[0][0]; matb[1][1]=mata[1][1]; \
  283.     matb[2][2]=mata[2][2]; matb[3][3]=mata[3][3]; \
  284. /* Off-Diagonal Terms  ( Swap ) */ \
  285.     matb[0][1]=mata[1][0]; matb[1][0]=mata[0][1];\
  286.     matb[0][2]=mata[2][0]; matb[2][0]=mata[0][2]; \
  287.     matb[0][3]=mata[3][0]; matb[3][0]=mata[0][3]; \
  288.     \
  289.     matb[1][2]=mata[2][1]; matb[2][1]=mata[1][2]; \
  290.     matb[1][3]=mata[3][1]; matb[3][1]=mata[1][3]; \
  291.     \
  292.     matb[2][3]=mata[3][2]; matb[3][2]=mata[2][3]; \
  293. } /* End macro Transpose44 */
  294.  
  295. /* Pass a vector as pointers to its components */
  296. #define Fpass3f(v) &v[0], &v[1], &v[2] 
  297. #define Fpass4f(v) &v[0], &v[1], &v[2], &v[3]
  298. #define Fpass6f(v) &v[0], &v[1], &v[2], &v[3], &v[4], &v[5]
  299.