home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / demos / gpc / fillcont.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-02  |  6.9 KB  |  226 lines

  1. /* $XConsortium: fillcont.c,v 5.2 91/04/03 09:40:25 rws Exp $ */
  2. /***********************************************************
  3. Copyright(c) 1989,1990, 1991 by Sun Microsystems, Inc. and the X Consortium at M.I.T.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its
  8. documentation for any purpose and without fee is hereby granted,
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in
  11. supporting documentation, and that the names of Sun Microsystems,
  12. the X Consortium, and MIT not be used in advertising or publicity
  13. pertaining to distribution of the software without specific, written
  14. prior permission.
  15.  
  16. SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  17. INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT
  18. SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
  19. DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  20. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  21. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  22. SOFTWARE.
  23.  
  24. ******************************************************************/
  25.  
  26. /*--------------------------------------------------------------------*\
  27. |
  28. |  Copyright (C) 1989,1990, 1991, National Computer Graphics Association
  29. |
  30. |  Permission is granted to any individual or institution to use, copy, or
  31. |  redistribute this software so long as it is not sold for profit, provided
  32. |  this copyright notice is retained.
  33. |
  34. |                         Developed for the
  35. |                National Computer Graphics Association
  36. |                         2722 Merrilee Drive
  37. |                         Fairfax, VA  22031
  38. |                           (703) 698-9600
  39. |
  40. |                                by
  41. |                 SimGraphics Engineering Corporation
  42. |                    1137 Huntington Drive  Unit A
  43. |                      South Pasadena, CA  91030
  44. |                           (213) 255-0900
  45. |---------------------------------------------------------------------
  46. |
  47. | Author        :    jmz / SimGraphics Engineering Corportation
  48. |
  49. | File          :    fillcont.c
  50. | Date          :    Thu Feb  8 15:13:51 PST 1990
  51. | Project       :    PLB
  52. | Description    :    Contour buffer -to- array  copy routines
  53. | Status    :    Version 1.0
  54. |
  55. | Revisions     :    
  56. |
  57. |      12/90            MFC Tektronix, Inc.: PEX-SI PEX5R1 Release.
  58. |
  59. \*--------------------------------------------------------------------*/
  60.  
  61. /*--------------------------------------------------------------------*\
  62. |    Table of Contents
  63. |
  64. |    int fillVecSet(int, Real_int_union *, char *, int, vector **)
  65. |        :    Assign the malloc'd space to the array and
  66. |    int fillIntSet(int, Real_int_union *, char *, int, int **
  67. |        :    Assign the malloc'd space to the array and
  68. |
  69. \*--------------------------------------------------------------------*/
  70.  
  71. /*--------------------------------------------------------------------*\
  72. |    Include files
  73. \*--------------------------------------------------------------------*/
  74. #include <stdio.h>
  75. #include <X11/Xosdefs.h>
  76. #ifndef X_NOT_STDC_ENV
  77. #include <stdlib.h>
  78. #else
  79. char *malloc();
  80. #endif
  81. #if defined(macII) && !defined(__STDC__)  /* stdlib.h fails to define these */
  82. char *malloc();
  83. #endif /* macII */
  84. #include "bifbuild.h"
  85. #include "biftypes.h"
  86. #include "bifparse.h"
  87. #include "new_ents.h"
  88. #include "doentity.h"
  89. #include "db_tools.h"
  90. #include "bifmacro.h"
  91. #include "ph_map.h"
  92. #include "globals.h"
  93.  
  94. /*--------------------------------------------------------------------*\
  95. | Procedure     :    int fillVecSet(int, Real_int_union *,
  96. |            char *, int, int)
  97. |---------------------------------------------------------------------
  98. | Description   :    Assign the malloc'd space to the array and
  99. |            fill it.  If the supplied contour list is too
  100. |            short, the final entry is duplicated to the end
  101. |            of the array.
  102. |---------------------------------------------------------------------
  103. | Return        :    The number of bytes used by the filled array.
  104. \*--------------------------------------------------------------------*/
  105. void fillVecSet(numConts, contList, ptr, reqSize, adSize)
  106. int        numConts;
  107. Real_int_union    *contList;
  108. char        *ptr;
  109. int        reqSize;
  110. int        adSize;
  111.  
  112. {
  113.     int i, j, actSize, contSize;
  114.     Pvec3 *vecs, *dupeMe;
  115.  
  116.     /* Establish the base of the array */
  117.     vecs = (Pvec3 *)ptr;
  118.  
  119.     /* Fill It */
  120.     actSize = 0;
  121.     if ( numConts  > 0 )
  122.     {
  123.         /* Copy the data */
  124.         for ( i = 0; i < numConts; i++ )
  125.         {
  126.             /* The contour size list */
  127.             contSize = (contList++)->Int;
  128.             actSize += contSize;
  129.  
  130.             /* The vector arrays */
  131.             for ( j = 0; j < contSize ; j++ )
  132.             {
  133.                 vecs->delta_x = (contList++)->Float;
  134.                 vecs->delta_y = (contList++)->Float;
  135.                 vecs->delta_z = (contList++)->Float;
  136.                 vecs = (Pvec3 *)(((char *)vecs) + adSize);
  137.             }
  138.         }
  139.  
  140.         /* Dupe the last entry ( if needed ) */
  141.         dupeMe = (Pvec3 *)(((char *)vecs) - adSize);
  142.         for ( i = actSize ; i < reqSize ; i++ )
  143.         {
  144.             vecs->delta_x = dupeMe->delta_x;
  145.             vecs->delta_y = dupeMe->delta_y;
  146.             vecs->delta_z = dupeMe->delta_z;
  147.             vecs = (Pvec3 *)(((char *)vecs) + adSize);
  148.         }
  149.     }
  150.     else
  151.     {
  152.     /* Default Empty List has one zero entry */
  153.     /* To possible reference from bombing    */
  154.         vecs->delta_x = 0.0;
  155.         vecs->delta_y = 0.0;
  156.         vecs->delta_z = 0.0;
  157.     }
  158.  
  159. } /* End fillVecSet() */
  160.  
  161. /*--------------------------------------------------------------------*\
  162. | Procedure     :    int fillIntSet(int, Real_int_union *,
  163. |            char *, int, int, int)
  164. |---------------------------------------------------------------------
  165. | Description   :    Assign the malloc'd space to the array and
  166. |            fill it.  If the supplied contour list is too
  167. |            short, the final entry is duplicated to the end
  168. |            of the array.
  169. |---------------------------------------------------------------------
  170. | Return        :    The number of bytes used by the filled array.
  171. \*--------------------------------------------------------------------*/
  172. int fillIntSet(numConts, contList, ptr, reqSize, adSize, colorInd)
  173. int        numConts;
  174. Real_int_union    *contList;
  175. char        *ptr;
  176. int        reqSize;
  177. int        adSize;
  178. int        colorInd;
  179.  
  180. {
  181.     int i, j, actSize, contSize;
  182.     int *vals, *dupeMe;
  183.  
  184.     /* Establish the base of the array */
  185.     vals = (int *)ptr;
  186.  
  187.     /* Fill It */
  188.     actSize = 0;
  189.     if ( numConts  > 0 )
  190.     {
  191.         /* Copy the data */
  192.         for ( i = 0 ; i < numConts ; i++ )
  193.         {    
  194.         /* The contour size list */
  195.         contSize = (contList++)->Int;
  196.         actSize += contSize;
  197.  
  198. #ifdef EXTERNALNOTE
  199.         /* index is incremented by one so that color '0' does
  200.            not step on the default BG color. */
  201. #endif
  202.         for ( j = 0; j < contSize ; j++ )
  203.         {
  204.             *vals = (contList++)->Int + colorInd;
  205.             vals = (int *)(((char *)vals) + adSize);
  206.         }
  207.         }
  208.  
  209.         /* Dupe the last entry ( if needed ) */
  210.         dupeMe = (int *)(((char *)vals) - adSize);
  211.         for ( i = actSize ; i < reqSize ; i++ )
  212.         {
  213.         *vals = *dupeMe;
  214.         vals = (int *)(((char *)vals) + adSize);
  215.         }
  216.     }
  217.     else
  218.     {
  219.     /* Default Empty List has one zero entry */
  220.     /* To keep possible reference from bombing    */
  221.         *vals = 0;
  222.     }
  223.  
  224. } /* End fillIntSet() */
  225.  
  226.