home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / gems / gemsii / sparse.c < prev    next >
C/C++ Source or Header  |  1991-09-22  |  4KB  |  85 lines

  1. /*
  2.  *  Author: Jim Arvo
  3.  */
  4.  
  5. #include "GraphicsGems.h"
  6.  
  7. #define P1 (1<< 0)
  8. #define P2 (1<< 1)
  9. #define P3 (1<< 2)
  10. #define P4 (1<< 3)
  11. #define P5 (1<< 4)  
  12. #define P6 (1<< 5)
  13. #define RX (1<< 6)
  14. #define RY (1<< 7)
  15. #define RZ (1<< 8)
  16. #define C1 (1<< 9)
  17. #define C2 (1<<10)
  18. #define C3 (1<<11)
  19. #define C4 (1<<12)
  20. #define C5 (1<<13)
  21. #define C6 (1<<14)
  22. #define C7 (1<<15)
  23.  
  24. /*=========================================================================* 
  25.  *                                                                         *
  26.  * This function classifies a 3x3 matrix according to its zero structure.  * 
  27.  * It returns an unsigned integer in which each bit signifies a zero       *
  28.  * structure that describes the given matrix.  If all bits are zero it     *
  29.  * means the matrix is dense or does not fit any of these 16 forms.        *
  30.  *                                                                         *
  31.  *                                                                         *
  32.  *  Permutations:                                                          *
  33.  *                                                                         *
  34.  *  * 0 0     0 * 0     0 0 *     0 * 0     * 0 0      0 0 *               *
  35.  *  0 * 0     0 0 *     * 0 0     * 0 0     0 0 *      0 * 0               *
  36.  *  0 0 *     * 0 0     0 * 0     0 0 *     0 * 0      * 0 0               *
  37.  *                                                                         *
  38.  *   P1        P2        P3        P4        P5         P6                 *
  39.  *                                                                         *
  40.  *                                                                         *
  41.  *  Simple Rotations:                                                      *
  42.  *                                                                         *
  43.  *  * 0 0     * 0 *     * * 0                                              *
  44.  *  0 * *     0 * 0     * * 0                                              *
  45.  *  0 * *     * 0 *     0 0 *                                              *
  46.  *                                                                         *
  47.  *   RX        RY        RZ                                                *
  48.  *                                                                         *
  49.  *                                                                         *
  50.  *  Permutations of the simple rotations:                                  *
  51.  *                                                                         *
  52.  *  * 0 *     0 0 *     0 * *     0 * 0     * * 0     * 0 *      0 * *     *
  53.  *  0 * 0     * * 0     0 * *     * 0 *     0 0 *     * 0 *      * 0 0     *
  54.  *  * 0 *     * * 0     * 0 0     * 0 *     * * 0     0 * 0      0 * *     *
  55.  *                                                                         *
  56.  *   C1        C2        C3        C4        C5        C6         C7       *
  57.  *                                                                         *
  58.  *=========================================================================*/
  59. unsigned int classify_matrix( M )
  60. Matrix3  M;
  61.     {
  62.     unsigned int form = 0xFFFF;
  63.  
  64.     /* Classify based on the diagonal elements. */
  65.  
  66.     if( M.element[0][0] != 0 ) form &= P1 | P5 | RX | RY | RZ | C1 | C5 | C6;
  67.     if( M.element[1][1] != 0 ) form &= P1 | P6 | RX | RY | RZ | C1 | C2 | C3;
  68.     if( M.element[2][2] != 0 ) form &= P1 | P4 | RX | RY | RZ | C1 | C4 | C7;
  69.  
  70.     /* Classify based on the upper triangular elements. */
  71.  
  72.     if( M.element[0][1] != 0 ) form &= P2 | P4 | RZ | C3 | C4 | C5 | C7;
  73.     if( M.element[0][2] != 0 ) form &= P3 | P6 | RY | C1 | C2 | C3 | C6 | C7;
  74.     if( M.element[1][2] != 0 ) form &= P2 | P5 | RX | C3 | C4 | C5 | C6;
  75.  
  76.     /* Classify based on the lower triangular elements. */
  77.  
  78.     if( M.element[1][0] != 0 ) form &= P3 | P4 | RZ | C2 | C4 | C6 | C7;
  79.     if( M.element[2][0] != 0 ) form &= P2 | P6 | RY | C1 | C2 | C3 | C4 | C5;
  80.     if( M.element[2][1] != 0 ) form &= P3 | P5 | RX | C2 | C5 | C6 | C7;
  81.  
  82.     return( form );
  83.     }
  84.  
  85.