home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / demos / gpc / new_ents.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-23  |  71.8 KB  |  2,260 lines

  1. /* $XConsortium: new_ents.c,v 5.3 91/08/23 16:45:45 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        :    nde/mjf/jmz / SimGraphics Engineering Corportation
  48. |
  49. | File          :    new_ents.c
  50. | Date          :    3/16/89
  51. | Project       :    PLB
  52. | Description   :    
  53. | Status        :    Version 1.0
  54. |
  55. | Revisions     :
  56. |
  57. |       2/90            MFC Tektronix, Inc.: PEX-SI API implementation.
  58. |
  59. |       5/90            MFC Tektronix, Inc.: PEX-SI API Binding change.
  60. |
  61. |      12/90            MFC Tektronix, Inc.: PEX-SI PEX5R1 Release.
  62. |
  63. \*--------------------------------------------------------------------*/
  64.  
  65. /*--------------------------------------------------------------------*\
  66. |    Table of Contents
  67. |
  68. |    BIF_Simple_triple *new_simple_triple( int, *Real_int_union )
  69. |        :    Allocate and fill a simple_triple structure, and
  70. |    BIF_Simple_double *new_simple_double(
  71. |        :    Allocate and fill a simple_double structure,
  72. |    BIF_Beginstructure *new_beginstructure(int)
  73. |        :    Allocates a new BIF_Beginstructure entity for the
  74. |    BIF_Marker *new_marker(int, *Real_int_union)
  75. |        :    Allocate and fill a marker structure.  All space
  76. |    BIF_Marker3 *new_marker3(int, *Real_int_union)
  77. |        :    Allocate and fill a marker3 structure.  All space is
  78. |    BIF_Line *new_line(int, *Real_int_union)
  79. |        :    Allocate and fill a line structure.  All space
  80. |    BIF_Line3 *new_line3(int, *Group_description)
  81. |        :    Allocate and fill a LINE3 entity w/ optional data
  82. |    BIF_Polygon *new_polygon(int, *Real_int_union)
  83. |        :    Allocate and fill a polygon structure.  All
  84. |    BIF_polygon3 *new_polygon3(int,
  85. |        :    Allocate and fill a POLYGON3 entity w/ optional
  86. |    BIF_Fillareaset *new_fillareaset (int, *Real_int_union)
  87. |        :    Allocate and fill a fillareaset structure.  
  88. |    BIF_fillareaset3 *new_fillareaset3(int, *Group_description)
  89. |        :    Allocate and fill a FILLAREASET3 entity with
  90. |    BIF_Triangle3 *new_triangle3(int, *Group_description)
  91. |        :    Allocate and fill a TRIANGLE3 entity with
  92. |    BIF_Quadmesh3 *new_quadmesh3(int, int, int, *Group_description)
  93. |        :    Allocate and fill a QUADMESH3 entity with
  94. |    BIF_Indexpolygons3 *new_indexpolygons3(int, *Group_description)
  95. |        :    Allocate and fill a INDEX_POLYGONS3 entity with
  96. |    BIF_Text *new_text(float, float, float, *char) 
  97. |        :    Allocates and fills a text structure 
  98. |    BIF_Text3 *new_text3(float, float, float, *char) 
  99. |        :    Allocates and fills a text3 structure 
  100. |    BIF_Anno_text3 *new_annotext3( float, float, float,
  101. |                    float, float, float, *char) 
  102. |        :    Allocates and fills a annotext3 structure 
  103. |    BIF_Lightstate *new_lightstate(int, *Group_description)
  104. |        :    Allocates and fills a LIGHT_STATE entity
  105. |    BIF_All *new_generic(*BIF_All, int, int, (*int)())
  106. |        :    Allocate a new generic BIF entity
  107. |    int scanForGroups( int, Group_description *, int, int *,
  108. |                int *, Real_int_union *,)
  109. |        :    scans a group headers list for the groups
  110. |    int fillVec(int, Real_int_union *, char *, int, *vector[] )
  111. |        :    Assign the malloc'd space to the array and
  112. |    int fillInt(int, Real_int_union *, char *, int, *int[], int )
  113. |        :    Assign the malloc'd space to the array and
  114. |    errorSize(char *, int, int, int)
  115. |        :    report if an actual group size is not correct
  116. |    int scanWithData(*char, int, int, int, int, *Group_description )
  117. |        :    Scan the groups for the standard ODG's
  118. |    int scanWithDataSet(*char, int, int, int, int, *Group_description )
  119. |        :    Scan the groups for the standard ODG Sets
  120. |    int loadWithData(*BIF_Withdata3, *char)
  121. |        :    Load the scan'd (see scanWithData) groups into
  122. |    int loadWithDataSet(*BIF_Withdata3, *char)
  123. |        :    Load the scan'd (see scanWithData) groups into
  124. |    int makeVertexFlag(int, int, int)
  125. |        :    add the contribution values that make up
  126. |    int makeFacetFlag(int, int, int)
  127. |        :    add the contribution values that make up
  128. |    int makeEdgeFlag(int, int, int)
  129. |        :    add the contribution values that make up
  130. |    int makeWithDataFlag(* int)
  131. |        :    Set the fields in the with_data_flag array
  132. |    BIF_Withdata3 *new_withdata3(    *char, int, (*int)(), int, int,
  133. |                    int, int, *Real_int_union,
  134. |                    *int, *int, *int, int,
  135. |                    *Group_description)
  136. |        :    Allocate and fill a Withdata entity with optional data
  137. |    BIF_Pixelmap3 *new_pixelmap3(* BIF_Pixelmap3)
  138. |        :    Allocate a Pixelmap3 entity
  139. |    BIF_Nubc *new_nubc(int, *Group_description)
  140. |        :    Allocate and fill a NON_UNIFORM_BSPLINE_CURVE
  141. |    BIF_Nubs *new_nubs(int, *Group_description)
  142. |        :    Allocate and fill a NON_UNIFORM_BSPLINE_SURFACE
  143. |
  144. \*--------------------------------------------------------------------*/
  145.  
  146. /*--------------------------------------------------------------------*\
  147. |    Include files
  148. \*--------------------------------------------------------------------*/
  149. #include <stdio.h>
  150. #include <X11/Xosdefs.h>
  151. #ifndef X_NOT_STDC_ENV
  152. #include <stdlib.h>
  153. #else
  154. char *malloc();
  155. #endif
  156. #if defined(macII) && !defined(__STDC__)  /* stdlib.h fails to define these */
  157. char *malloc();
  158. #endif /* macII */
  159. #include "bifbuild.h"
  160. #include "biftypes.h"
  161. #include "bifparse.h"
  162. #include "new_ents.h"
  163. #include "doentity.h"
  164. #include "db_tools.h"
  165. #include "bifmacro.h"
  166. #include "ph_map.h"
  167. #include "globals.h"
  168. #include <X11/Xfuncs.h>
  169.  
  170. /*--------------------------------------------------------------------*\
  171. |    Local Macros
  172. \*--------------------------------------------------------------------*/
  173. #define ALLOC(type) (type *)malloc( sizeof( type ) )
  174. #define ALLOCV(type,vfl) (type *)malloc( sizeof( type ) + vfl )
  175.  
  176. #define STDSIZE(ent,nc,nf,ne) \
  177. {\
  178.     ent->numCoords = nc;\
  179.     ent->numFacets = nf;\
  180.     ent->numEdges  = ne;\
  181. }
  182.  
  183. #ifdef EXTERNAL_NOTE
  184.     MAX_VAL has been moved to bifmacro.h
  185.     A slight fix to the macro.
  186. #endif /* EXTERNAL_NOTE */
  187. #define ODGSIZE(flag,number,size) \
  188.     ( ( flag ? MAX_VAL(1,number) : 1 ) * size)
  189.  
  190.  
  191. /*--------------------------------------------------------------------*\
  192. |    Local #define Constants
  193. \*--------------------------------------------------------------------*/
  194. #define NUM_STD_ODGS 7
  195. #define STD_ODGS_V 3
  196. #define STD_ODGS_F 6
  197. #define STD_ODGS_E 7
  198.  
  199. /*--------------------------------------------------------------------*\
  200. |    Local global variables (static)
  201. \*--------------------------------------------------------------------*/
  202. static int scanList[NUM_STD_ODGS] = 
  203. {
  204.     VERTEX_COLORS,     VERTEX_COLOR_INDICES,
  205.     VERTEX_NORMALS,
  206.  
  207.     FACET_COLORS,        FACET_COLOR_INDICES,
  208.     FACET_NORMALS,
  209.  
  210.     EDGE_VISIBILITY
  211. };
  212. static int sizeofList[NUM_STD_ODGS] = 
  213. {
  214.     sizeof(Pcoval),            sizeof(Pcoval),
  215.     sizeof(Pvec3),
  216.     sizeof(Pcoval),            sizeof(Pcoval),
  217.     sizeof(Pvec3),
  218.     sizeof(Pedge_flag)
  219. };
  220.  
  221. #ifdef EXTERNAL_NOTE
  222.     recSizeList is a new field defining the size of the data records
  223.     for each group.  Useful for the fillareaset3 primitive.
  224. #endif
  225. static int recSizeList[NUM_STD_ODGS] = 
  226. {
  227.     3,            1,
  228.     3,
  229.     3,            1,
  230.     3,
  231.     1
  232. };
  233.  
  234. static int sizeList[NUM_STD_ODGS];
  235. static Real_int_union *listList[NUM_STD_ODGS];
  236.  
  237. #define NUM_DATA_FLAGS 4
  238. static int sizeofFacetdata[NUM_DATA_FLAGS] =
  239. {
  240.     0, sizeof(Pcoval), sizeof(Pvec3), sizeof(Pconorm3)
  241. };
  242.  
  243. static int sizeofVertexdata[NUM_DATA_FLAGS] =
  244. {
  245.     sizeof(Ppoint3), sizeof(Pptco3), sizeof(Pptnorm3), sizeof(Pptconorm3)
  246. };
  247.  
  248. #define NUM_GROUPS_COORD     1
  249.     static int coordGroup[NUM_GROUPS_COORD] = { VERTEX_COORDINATES };
  250.     static int coordSize[NUM_GROUPS_COORD]; 
  251.     static Real_int_union *coordList[NUM_GROUPS_COORD];
  252.  
  253.  
  254. /*--------------------------------------------------------------------*\
  255. |    BEGIN PROCEDURE CODE
  256. \*--------------------------------------------------------------------*/
  257.  
  258.  
  259. /*----------------------------------------------------------------------*\
  260. | Procedure     :    BIF_Simple_triple *new_simple_triple( int,
  261. |                        *Real_int_union )
  262. |------------------------------------------------------------------------|
  263. | Description   :    Allocate and fill a simple_triple structure, and
  264. |            the three arrays of floats which are pointed to
  265. |            from within this structure.  All space is
  266. |            allocated at once, allowing a single free to 
  267. |            delete the structure.
  268. |------------------------------------------------------------------------|
  269. | Return        :    The pointer to the new structure.
  270. \*----------------------------------------------------------------------*/
  271. BIF_Simple_triple *new_simple_triple(size,trip_list)
  272. int size;
  273. Real_int_union *trip_list;
  274.  
  275. {
  276.     char *ptr;
  277.     BIF_Simple_triple *ent;
  278.     int total;
  279.     int indx;
  280.     Ppoint3 *points;
  281.  
  282.     /*------------------------------------------------------------*\
  283.     |    Define memory requirement
  284.     \*------------------------------------------------------------*/
  285.     total = sizeof(BIF_Simple_triple) + size * 3 * sizeof(Pfloat);
  286.     ptr = malloc((unsigned)total);
  287.     if ( ptr != NULL )
  288.     {
  289.         /*----------------------------------------------------*\
  290.         |    Initialize the structure
  291.         \*----------------------------------------------------*/
  292.         ent = (BIF_Simple_triple *)ptr;
  293.         ptr += sizeof(BIF_Simple_triple);
  294.         ent->number = size;
  295.         if ( size > 0 )
  296.         {
  297.             /*--------------------------------------------*\
  298.             | Fill the structure with pointer to Ppoint3 
  299.             | The space for the points was allocated with
  300.             | the same malloc as this structure.
  301.             \*--------------------------------------------*/
  302.                 ent->points = (Ppoint3 *)ptr;
  303.  
  304.             /*--------------------------------------------*\
  305.             | Fill array of Ppoint structures.
  306.             \*--------------------------------------------*/
  307.             points = ent->points;
  308.             for ( indx = 0 ; indx < size ; indx++, points++ )
  309.             {
  310.                 points->x = (trip_list++)->Float;
  311.                 points->y = (trip_list++)->Float;
  312.                 points->z = (trip_list++)->Float;
  313.             }
  314.         }
  315.         else
  316.         {
  317.             /*--------------------------------------------*\
  318.             | Empty Ppoint3 array
  319.             \*--------------------------------------------*/
  320.                 ent->points = NULL;
  321.         }
  322.     }
  323.     /*------------------------------------------------------------*\
  324.     |    Return the generated entity 
  325.     \*------------------------------------------------------------*/
  326.     return( ent );
  327.  
  328. } /* End procedure new_simple_triple */
  329.  
  330. /*----------------------------------------------------------------------*\
  331. | Procedure     :    BIF_Simple_double *new_simple_double(
  332.                         int, *Real_int_union)
  333. |------------------------------------------------------------------------|
  334. | Description   :    Allocate and fill a simple_double structure,
  335. |            and the two arrays of floats which are pointed
  336. |            to from within this structure.  All space is
  337. |            allocated at once, allowing a single free to 
  338. |            delete the structure.
  339. |------------------------------------------------------------------------|
  340. | Return        :    The pointer to the new structure.
  341. \*----------------------------------------------------------------------*/
  342. BIF_Simple_double *new_simple_double(size,trip_list)
  343. int size;
  344. Real_int_union *trip_list;
  345.  
  346. {
  347.     char *ptr;
  348.     BIF_Simple_double *ent;
  349.     int total;
  350.     int indx;
  351.     Ppoint *points;
  352.  
  353.     /*------------------------------------------------------------*\
  354.     |    Define memory requirement
  355.     \*------------------------------------------------------------*/
  356.     total = sizeof(BIF_Simple_double) + size * 2 * sizeof(float);
  357.     ptr = malloc((unsigned)total);
  358.     if ( ptr != NULL )
  359.     {
  360.         /*----------------------------------------------------*\
  361.         |    Initialize the structure
  362.         \*----------------------------------------------------*/
  363.         ent = (BIF_Simple_double *)ptr;
  364.         ptr += sizeof(BIF_Simple_double);
  365.         ent->number = size;
  366.         if ( size > 0 )
  367.         {
  368.             /*--------------------------------------------*\
  369.             | The space for the Ppoint array of structures
  370.             | was allocated with the same malloc as this
  371.             | structure.
  372.             \*--------------------------------------------*/
  373.                 ent->points = (Ppoint *)ptr;
  374.  
  375.             /*--------------------------------------------*\
  376.             | Fill array of Ppoint structures.
  377.             \*--------------------------------------------*/
  378.             points = ent->points;
  379.             for ( indx = 0 ; indx < size ; indx++, points++ )
  380.             {
  381.                 points->x = (trip_list++)->Float;
  382.                 points->y = (trip_list++)->Float;
  383.                 /* Skip the "Z" values */
  384.                 trip_list++;
  385.             }
  386.         }
  387.         else
  388.         {
  389.             /*--------------------------------------------*\
  390.             | Empty array of Ppoint structures
  391.             \*--------------------------------------------*/
  392.             ent->points = NULL;
  393.         }
  394.     }
  395.     /*------------------------------------------------------------*\
  396.     |    Return the generated entity 
  397.     \*------------------------------------------------------------*/
  398.     return( ent );
  399.  
  400. } /* End procedure new_simple_double */
  401.  
  402. /*----------------------------------------------------------------------*\
  403. | Procedure     :    BIF_Beginstructure *new_beginstructure(int)
  404. |------------------------------------------------------------------------
  405. | Description   :    Allocates a new BIF_Beginstructure entity for the
  406. |        structures database.
  407. |------------------------------------------------------------------------
  408. | Return        :    The address of the allocated structure
  409. \*----------------------------------------------------------------------*/
  410. BIF_Beginstructure *new_beginstructure( structure_id )
  411. int structure_id;
  412.  
  413. {
  414.  
  415. BIF_Beginstructure  *ent;
  416.  
  417.     ent = ALLOC( BIF_Beginstructure );
  418.     if ( ent != NULL )
  419.     {
  420.         HEADER(ent, BEGIN_STRUCTURE, do_beginstructure, NULL);
  421.  
  422.         ent->structure_id = structure_id;
  423.         ent->top_of_list = NULL;
  424.         ent->expanded = FALSE;
  425.     }
  426.  
  427.     return( ent );
  428.  
  429. } /* End new_beginstructure */
  430.  
  431. /*----------------------------------------------------------------------*\
  432. | Procedure     :    BIF_Marker *new_marker(int, *Real_int_union)
  433. |------------------------------------------------------------------------|
  434. | Description   :    Allocate and fill a marker structure.  All space
  435. |            is allocated at once, allowing a single free to 
  436. |            delete the structure.
  437. |------------------------------------------------------------------------|
  438. | Return        :    The pointer to the new structure.
  439. \*----------------------------------------------------------------------*/
  440. BIF_Marker *new_marker(size,trip_list)
  441. int size;
  442. Real_int_union *trip_list;
  443.  
  444. {
  445.     BIF_Marker *ent;
  446.     ent = (BIF_Marker *)new_simple_double(size,trip_list);
  447.  
  448.     if ( ent != NULL )
  449.     {
  450.         HEADER(ent, MARKER, do_marker, NULL);
  451.     }
  452.  
  453.     return(ent);
  454. } /* End procedure new_marker */
  455.  
  456. /*----------------------------------------------------------------------*\
  457. | Procedure     :    BIF_Marker3 *new_marker3(int, *Real_int_union)
  458. |------------------------------------------------------------------------|
  459. | Description   :    Allocate and fill a marker3 structure.  All space is
  460. |            allocated at once, allowing a single free to 
  461. |            delete the structure.
  462. |------------------------------------------------------------------------|
  463. | Return        :    The pointer to the new structure.
  464. \*----------------------------------------------------------------------*/
  465. BIF_Marker3 *new_marker3(size,trip_list)
  466. int size;
  467. Real_int_union *trip_list;
  468.  
  469. {
  470.     BIF_Marker3 *ent;
  471.     ent = (BIF_Marker3 *)new_simple_triple(size,trip_list);
  472.  
  473.     if ( ent != NULL )
  474.     {
  475.         HEADER(ent, MARKER3, do_marker3, NULL);
  476.     }
  477.     return(ent);
  478. } /* End procedure new_marker3 */
  479.  
  480. /*--------------------------------------------------------------------*\
  481. | Procedure     :    BIF_Line *new_line(int, *Real_int_union)
  482. |---------------------------------------------------------------------
  483. | Description   :    Allocate and fill a line structure.  All space
  484. |            is allocated at once, allowing a single free to 
  485. |            delete the structure.
  486. |---------------------------------------------------------------------
  487. | Return        :    The pointer to the new structure.
  488. \*--------------------------------------------------------------------*/
  489. BIF_Line *new_line(size,trip_list)
  490. int size;
  491. Real_int_union *trip_list;
  492.  
  493. {
  494.     BIF_Line *ent;
  495.     ent = (BIF_Line *)new_simple_double(size,trip_list);
  496.  
  497.     {
  498.         HEADER(ent, LINE, do_line, NULL);
  499.     }
  500.     return(ent);
  501. } /* End procedure new_line */
  502.  
  503. /*--------------------------------------------------------------------*\
  504. | Procedure     :    BIF_Line3 *new_line3(int, *Group_description)
  505. |----------------------------------------------------------------------|
  506. | Description   :    Allocate and fill a LINE3 entity w/ optional data
  507. |----------------------------------------------------------------------|
  508. | Return        :    The pointer to the new structure ( or NULL on error )
  509. \*--------------------------------------------------------------------*/
  510. BIF_Line3 *new_line3(numGroups, groups)
  511. int numGroups;
  512. Group_description *groups;
  513. {
  514.     static char *entName = "LINE3";
  515.     static int vFlagData[3] = { 1, 1, 0 };
  516.     static int fFlagData[3] = { 0, 0, 0 };
  517.     static int eFlagData[1] = { 0 };
  518.  
  519.     int numCoords,numFacets,numEdges;
  520.  
  521.     BIF_Line3 *ent;
  522.  
  523. #ifdef TEST_PRINT
  524.     fflush(stderr);
  525.     printf("in new_line3 %d \n",numGroups);
  526.     fflush(stdout);
  527. #endif /* TEST_PRINT */
  528.     /*------------------------------------------------------------*\
  529.     |    Get the entity specific data groups
  530.     \*------------------------------------------------------------*/
  531.     scanForGroups(numGroups,groups,NUM_GROUPS_COORD,coordGroup,
  532.         coordSize,coordList);
  533.  
  534.     /*------------------------------------------------------------*\
  535.     |    Set the standard sizes
  536.     \*------------------------------------------------------------*/
  537.     numCoords = coordSize[0];
  538.     numFacets = 0;
  539.     numEdges  = 0;
  540.  
  541.     ent = (BIF_Line3 *)new_withdata3(
  542.         entName, LINE3, do_line3,
  543.         sizeof(BIF_Line3), numCoords, numFacets, numEdges,
  544.         coordList[0], vFlagData, fFlagData, eFlagData,
  545.         numGroups, groups);
  546.  
  547.     /* Finish off the entity */
  548.     if ( ent != NULL )
  549.     {
  550.         /* Fill in the data fields */
  551.         ent->vdata.num_vertices = numCoords;
  552.         ent->vdata.vertex_data.points = ent->vertex_data.points;
  553.     }
  554.  
  555.     /*------------------------------------------------------------*\
  556.     |    Return the Entity Address
  557.     \*------------------------------------------------------------*/
  558.     return(ent);
  559.  
  560. } /* End procedure new_line3 */
  561.  
  562. /*--------------------------------------------------------------------*\
  563. | Procedure     :    BIF_Polygon *new_polygon(int, *Real_int_union)
  564. |----------------------------------------------------------------------|
  565. | Description   :    Allocate and fill a polygon structure.  All
  566. |            space is allocated at once, allowing a single
  567. |            free to delete the structure.
  568. |----------------------------------------------------------------------|
  569. | Return        :    The pointer to the new structure.
  570. \*--------------------------------------------------------------------*/
  571. BIF_Polygon *new_polygon(size,trip_list)
  572. int size;
  573. Real_int_union *trip_list;
  574.  
  575. {
  576.     BIF_Polygon *ent;
  577.     ent = (BIF_Polygon *)new_simple_double(size,trip_list);
  578.  
  579.     if ( ent != NULL )
  580.     {
  581.         HEADER(ent,POLYGON,do_polygon,NULL);
  582.     }
  583.     return(ent);
  584. } /* End procedure new_polygon */
  585.  
  586. /*--------------------------------------------------------------------*\
  587. | Procedure     :    BIF_polygon3 *new_polygon3(int,
  588.                         *Group_description)
  589. |----------------------------------------------------------------------|
  590. | Description   :    Allocate and fill a POLYGON3 entity w/ optional
  591. |            data (if any )
  592. |----------------------------------------------------------------------|
  593. | Return        :    The pointer to the new structure ( or NULL on error )
  594. \*--------------------------------------------------------------------*/
  595. BIF_Polygon3 *new_polygon3(numGroups, groups)
  596. int numGroups;
  597. Group_description *groups;
  598.  
  599. {
  600.     static char *entName = "POLYGON3";
  601.     static int vFlagData[3] = { 1, 1, 2 };
  602.     static int fFlagData[3] = { 1, 1, 2 };
  603.     static int eFlagData[1] = { 0 };
  604.  
  605.     int size, numCoords,numFacets,numEdges;
  606.  
  607.     BIF_Polygon3 *ent;
  608.  
  609. #ifdef TEST_PRINT
  610.     fflush(stderr);
  611.     printf("in new_polygon3 %d \n",numGroups);
  612.     fflush(stdout);
  613. #endif /* TEST_PRINT */
  614.     /*------------------------------------------------------------*\
  615.     |    Get the entity specific data groups
  616.     \*------------------------------------------------------------*/
  617.     scanForGroups(numGroups,groups,NUM_GROUPS_COORD,coordGroup,
  618.         coordSize,coordList);
  619.  
  620.     /*------------------------------------------------------------*\
  621.     |    Set the standard sizes
  622.     \*------------------------------------------------------------*/
  623.     numCoords = coordSize[0];
  624.     numFacets = 1;
  625.     numEdges  = numCoords;
  626.  
  627.     ent = (BIF_Polygon3 *)new_withdata3(
  628.         entName, POLYGON3, do_polygon3,
  629.         sizeof(BIF_Polygon3), numCoords, numFacets, numEdges,
  630.         coordList[0], vFlagData, fFlagData, eFlagData,
  631.         numGroups, groups);
  632.  
  633.     /* Finish off the entity */
  634.     if ( ent != NULL )
  635.     {
  636.         /* Fill in the data fields */
  637.     
  638.         /* Fill in the facet data */
  639.         size = sizeofFacetdata[ent->facet_data_flag];
  640.         if (size) {
  641. #ifdef SYSV
  642.           memcpy((char *)&ent->fdata.colr,
  643.              (char *)ent->facet_data.colrs, size);
  644. #else
  645.           bcopy((char *)ent->facet_data.colrs,
  646.             (char *)&ent->fdata.colr, size);
  647. #endif
  648.         }
  649.         /* Fill in the vertex data */
  650.         ent->vdata.points = ent->vertex_data.points;
  651.     }
  652.  
  653.     /*------------------------------------------------------------*\
  654.     |    Return the Entity Address
  655.     \*------------------------------------------------------------*/
  656.     return(ent);
  657.  
  658. } /* End procedure new_polygon3 */
  659.  
  660. /*--------------------------------------------------------------------*\
  661. | Procedure     :    BIF_Fillareaset *new_fillareaset (int,
  662. |                        *Real_int_union)
  663. |---------------------------------------------------------------------
  664. | Description   :    Allocate and fill a fillareaset structure.  
  665. |            All space is allocated at once, allowing a
  666. |            single free to delete the structure.
  667. |---------------------------------------------------------------------
  668. | Return        :    The pointer to the new structure.
  669. \*--------------------------------------------------------------------*/
  670. BIF_Fillareaset *new_fillareaset(numContour, contList)
  671. int numContour;
  672. Real_int_union *contList;
  673.  
  674. {
  675.     int i, j, numCoords;
  676.     int contSize;
  677.     int vfLength;
  678.     Ppoint_list *psets;
  679.     Ppoint *pnts;
  680.     char *ptr;
  681.     BIF_Fillareaset *ent;
  682.  
  683. /* Find the size of the Fillareaset in memory */
  684.     numCoords = contour_counter(numContour,contList,3);
  685.     
  686. /* Malloc the memory */
  687.     vfLength = numContour * sizeof(Ppoint_list)
  688.         + numCoords * sizeof(Ppoint);
  689.     
  690.     ent = ALLOCV(BIF_Fillareaset, vfLength);
  691.  
  692.     if ( ent != NULL )
  693.     {
  694.         /* Fill the structure */
  695.         HEADER(ent,FILL_AREA_SET,do_fillareaset,NULL);
  696.  
  697.         ent->numContours = numContour;
  698.         ptr = ((char *)ent) + sizeof(BIF_Fillareaset);
  699.  
  700.         /* Assign memory to the Ppoint_list structures */
  701.         ent->sets = (Ppoint_list *)ptr;
  702.         psets = ent->sets;
  703.         ptr += numContour * sizeof(Ppoint_list);
  704.  
  705.         /* Assign memory to the Ppoint lists */
  706.         pnts = (Ppoint *)ptr;
  707.  
  708.         for ( i = 0; i < numContour; i++ )
  709.         {
  710.             /* The contour size list */
  711.             contSize = (contList++)->Int;
  712.             psets->num_points = contSize;
  713.             psets->points = pnts;
  714.  
  715.             /* The point arrays */
  716.             for ( j = 0; j < contSize ; j++ )
  717.             {
  718.                 pnts->x = (contList++)->Float;
  719.                 pnts->y = (contList++)->Float;
  720.                 contList++; /* Skip the Z */
  721.                 pnts++;
  722.             }
  723.             psets++;
  724.         }
  725.     }
  726.     else
  727.     /* Malloc Failed */
  728.         ent = NULL;
  729.  
  730.     return(ent);
  731. } /* End procedure new_fillareaset */
  732.  
  733. #ifdef EXTERNAL_NOTE
  734.     The new_fillareaset3 routine has been completely rewritten
  735.     to reflect the differences in the structure of the data groups
  736.     (contours vs. straight lists) vs. all of the other "withData"
  737.     BIF primitives.
  738. #endif /*EXTERNAL_NOTE */
  739.  
  740. void loadWithDataSet();
  741.  
  742. /*--------------------------------------------------------------------*\
  743. | Procedure     :    BIF_fillareaset3 *new_fillareaset3(int,
  744. |                        *Group_description)
  745. |----------------------------------------------------------------------|
  746. | Description   :    Allocate and fill a FILLAREASET3 entity with
  747. |            optional data (if any )
  748. |----------------------------------------------------------------------|
  749. | Return        :    The pointer to the new structure ( or NULL on error )
  750. \*--------------------------------------------------------------------*/
  751. BIF_Fillareaset3 *new_fillareaset3(numGroups, groups)
  752. int numGroups;
  753. Group_description *groups;
  754.  
  755. {
  756.     static char *entName = "FILLAREASET3";
  757.     static int vFlagData[3] = { 1, 1, 2 };
  758.     static int fFlagData[3] = { 1, 1, 2 };
  759.     static int eFlagData[1] = { 1 };
  760.  
  761.     int numCoords,numFacets,numEdges;
  762.     int numContours, entBodySize, vfLength;
  763.     int i, contSize, vsize;
  764.     Real_int_union *contList;
  765.     Pedge_data_list *elist;
  766.     Pfacet_vdata_list3 *vlist;
  767.     Ppoint3 *pnts;
  768.     Pedge_flag *epnts;
  769.     char *ptr, *vptr, *fptr, *eptr;
  770.  
  771.     BIF_Fillareaset3 *ent;
  772.  
  773. #ifdef TEST_PRINT
  774.     fflush(stderr);
  775.     printf("in new_fillareaset3 %d \n",numGroups);
  776.     fflush(stdout);
  777. #endif /* TEST_PRINT */
  778.     /*------------------------------------------------------------*\
  779.     |    Get the vertex coordinate data groups
  780.     \*------------------------------------------------------------*/
  781.     scanForGroups(numGroups,groups,NUM_GROUPS_COORD,coordGroup,
  782.         coordSize,coordList);
  783.  
  784.     /*------------------------------------------------------------*\
  785.     |    Set the standard sizes
  786.     \*------------------------------------------------------------*/
  787.     numContours = coordSize[0];
  788.     numCoords   = contour_counter(coordSize[0],coordList[0],3);
  789.     numFacets   = 1;
  790.     numEdges    = numCoords;
  791.  
  792.     /*------------------------------------------------------------*\
  793.     |    The basic size....
  794.     \*------------------------------------------------------------*/
  795.     entBodySize = sizeof(BIF_Fillareaset3);    /* Body Size */
  796.     vfLength = ( MAX_VAL(1,numCoords) * sizeof(Ppoint3) ) +
  797.         ( MAX_VAL(1,numContours) * sizeof(Pedge_data_list) ) +
  798.         ( MAX_VAL(1,numContours) * sizeof(Pfacet_vdata_list3) );
  799.         
  800.     /*------------------------------------------------------------*\
  801.     |    Find the ODG's and compute the sizes
  802.     \*------------------------------------------------------------*/
  803.     vfLength += scanWithDataSet(entName, numCoords, numFacets,
  804.                     numEdges, numGroups, groups);
  805.  
  806.     /*------------------------------------------------------------*\
  807.     |    Allocate the entity and fill it
  808.     \*------------------------------------------------------------*/
  809.     ent = (BIF_Fillareaset3 *)malloc(entBodySize+vfLength);
  810.     if ( ent != NULL )
  811.     {
  812.         /*----------------------------------------------------*\
  813.         |    Fill entity specific data
  814.         |    Fixed Length Fields
  815.         \*----------------------------------------------------*/
  816.         HEADER(ent,FILL_AREA_SET3, do_fillareaset3,NULL);
  817.         STDSIZE(ent, numCoords, numFacets, numEdges);
  818.         ent->numContours = numContours;
  819.  
  820.         if ((sizeList[1] && vFlagData[1]) ||
  821.             (sizeList[4] && fFlagData[1]))
  822.             ent->colour_model = PINDIRECT;
  823.         else
  824.             ent->colour_model = wk_info.color_model;
  825.  
  826.         /*----------------------------------------------------*\
  827.         |    Vertex and Fact Data Flags
  828.         \*----------------------------------------------------*/
  829.         ent->vertex_data_flag = 
  830.             makeVertexFlag(vFlagData[0],vFlagData[1],vFlagData[2]);
  831.         ent->facet_data_flag =
  832.             makeFacetFlag(fFlagData[0],fFlagData[1],fFlagData[2]);
  833.         ent->edge_data_flag = 
  834.             makeEdgeFlag(eFlagData[0]);
  835.         
  836.         makeWithDataFlag(ent->with_data_flag);
  837.  
  838.         /*----------------------------------------------------*\
  839.         |    Fill the variable length fields
  840.         \*----------------------------------------------------*/
  841.  
  842.         /*----------------------------------------------------*\
  843.         |    Fill the Coords and the facet length array.
  844.         \*----------------------------------------------------*/
  845.         ptr = ((char *)ent) + entBodySize;
  846.  
  847.         /* Adjust to point at the Pedge_data_list structs */
  848.         elist = ent->edata = (Pedge_data_list *)ptr;
  849.         ptr += sizeof(Pedge_data_list) * numContours;
  850.  
  851.         /* Adjust to point to the Pfacet_vdata_list3 structs */
  852.         vlist = ent->vdata = (Pfacet_vdata_list3 *)ptr;
  853.         ptr += sizeof(Pfacet_vdata_list3) * numContours;
  854.  
  855.         pnts = (Ppoint3 *)ptr;
  856.  
  857.         /* Fill in the point data */
  858.         fillVecSet(coordSize[0], coordList[0], ptr, numCoords,
  859.                sizeofVertexdata[ent->vertex_data_flag]);
  860.  
  861.         /* Where the rest of the vertex data will go */
  862.         vptr = ptr + sizeof(Ppoint3);
  863.  
  864.         /* Where to put facet data */
  865.         fptr = (char *)&ent->fdata.colr;
  866.  
  867.         /* Where to put edges */
  868.         eptr = ptr + (MAX_VAL(1,numCoords) *
  869.                   sizeofVertexdata[ent->vertex_data_flag]);
  870.         epnts = (Pedge_flag *)eptr;
  871.  
  872.         /*----------------------------------------------------*\
  873.         |    Fill the Optional Data fields
  874.         \*----------------------------------------------------*/
  875.         loadWithDataSet(ent, vptr, fptr, eptr);
  876.  
  877.         /*---------------------------------------------------*\
  878.         |       Fill in the structure lists
  879.         \*---------------------------------------------------*/
  880.         vsize = sizeofVertexdata[ent->vertex_data_flag];
  881.         contList =coordList[0];
  882.  
  883.         for ( i = 0; i < numContours; i++ )
  884.         {
  885.             contSize = (contList++)->Int;
  886.  
  887.             vlist->num_vertices = contSize;
  888.             vlist->vertex_data.points = pnts;
  889.             pnts = (Ppoint3 *)(((char *)pnts) + vsize * contSize);
  890.             contList += contSize * 3;
  891.             vlist++;
  892.             if (ent->edge_data_flag) {
  893.               elist->num_edges = contSize;
  894.               elist->edgedata.edges = epnts;
  895.               epnts += contSize;
  896.               elist++;
  897.             }
  898.         }
  899.  
  900.     }
  901.  
  902.     /*------------------------------------------------------------*\
  903.     |    Return the Entity Address
  904.     \*------------------------------------------------------------*/
  905.     return(ent);
  906.  
  907. } /* End procedure new_fillareaset3 */
  908.  
  909.  
  910. /*--------------------------------------------------------------------*\
  911. | Procedure     :    BIF_Triangle3 *new_triangle3(int,
  912. |                        *Group_description)
  913. |----------------------------------------------------------------------|
  914. | Description   :    Allocate and fill a TRIANGLE3 entity with
  915. |            optional data (if any )
  916. |----------------------------------------------------------------------|
  917. | Return        :    The pointer to the new structure ( or NULL on error )
  918. \*--------------------------------------------------------------------*/
  919. BIF_Triangle3 *new_triangle3(numGroups, groups)
  920. int numGroups;
  921. Group_description *groups;
  922.  
  923. {
  924.     static char *entName = "TRIANGLE3";
  925.     static int vFlagData[3] = { 1, 1, 2 };
  926.     static int fFlagData[3] = { 1, 1, 2 };
  927.     static int eFlagData[1] = { 0 };
  928.  
  929.     int numCoords,numFacets,numEdges;
  930.  
  931.     BIF_Triangle3 *ent;
  932.  
  933. #ifdef TEST_PRINT
  934.     fflush(stderr);
  935.     printf("in new_triangle3 %d \n",numGroups);
  936.     fflush(stdout);
  937. #endif /* TEST_PRINT */
  938.     /*------------------------------------------------------------*\
  939.     |    Get the entity specific data groups
  940.     \*------------------------------------------------------------*/
  941.     scanForGroups(numGroups,groups,NUM_GROUPS_COORD,coordGroup,
  942.         coordSize,coordList);
  943.  
  944.     /*------------------------------------------------------------*\
  945.     |    Set the standard sizes
  946.     \*------------------------------------------------------------*/
  947.     numCoords = coordSize[0];
  948.     numFacets = numCoords -2;
  949.     numEdges  = numCoords;
  950.  
  951.     ent = (BIF_Triangle3 *)new_withdata3(
  952.         entName, TRIANGLE3, do_triangle3,
  953.         sizeof(BIF_Triangle3), numCoords, numFacets, numEdges,
  954.         coordList[0], vFlagData, fFlagData, eFlagData,
  955.         numGroups, groups);
  956.  
  957.     /* Finish off the entity */
  958.     if ( ent != NULL )
  959.     {
  960.         /* Fill in the data fields */
  961.         ent->fdata.colrs = ent->facet_data.colrs;
  962.         ent->vdata.points = ent->vertex_data.points;
  963.     }
  964.  
  965.     /*------------------------------------------------------------*\
  966.     |    Return the Entity Address
  967.     \*------------------------------------------------------------*/
  968.     return(ent);
  969.  
  970. } /* End procedure new_triangle3 */
  971.  
  972. /*--------------------------------------------------------------------*\
  973. | Procedure     :    BIF_Quadmesh3 *new_quadmesh3(int, int, int,
  974. |                        *Group_description)
  975. |----------------------------------------------------------------------|
  976. | Description   :    Allocate and fill a QUADMESH3 entity with
  977. |            optional data (if any )
  978. |----------------------------------------------------------------------|
  979. | Return        :    The pointer to the new structure ( or NULL on error )
  980. \*--------------------------------------------------------------------*/
  981. BIF_Quadmesh3 *new_quadmesh3(numRows, numColumns, numGroups, groups)
  982. int numRows, numColumns;
  983. int numGroups;
  984. Group_description *groups;
  985.  
  986. {
  987.     static char *entName = "QUAD_MESH3";
  988.     static int vFlagData[3] = { 1, 1, 2 };
  989.     static int fFlagData[3] = { 1, 1, 2 };
  990.     static int eFlagData[1] = { 0 };
  991.  
  992.     int numNeeded, numCoords, numFacets, numEdges;
  993.  
  994.     BIF_Quadmesh3 *ent;
  995.  
  996. #ifdef TEST_PRINT
  997.     fflush(stderr);
  998.     printf("in new_quadmesh3 %d \n",numGroups);
  999.     fflush(stdout);
  1000. #endif /* TEST_PRINT */
  1001.     /*------------------------------------------------------------*\
  1002.     |    Get the entity specific data groups
  1003.     \*------------------------------------------------------------*/
  1004.     scanForGroups(numGroups,groups,NUM_GROUPS_COORD,coordGroup,
  1005.         coordSize,coordList);
  1006.  
  1007.  
  1008.     /*------------------------------------------------------------*\
  1009.     |    Set the standard sizes
  1010.     \*------------------------------------------------------------*/
  1011.     numCoords = coordSize[0];
  1012.     numFacets = ( numRows -1 )* ( numColumns - 1);
  1013.     numEdges  = numCoords;
  1014.  
  1015.     /*------------------------------------------------------------*\
  1016.     |    Check the size of the coords
  1017.     \*------------------------------------------------------------*/
  1018.     numNeeded = (numRows * numColumns);
  1019.     errorSize(entName, numNeeded, numCoords, VERTEX_COORDINATES);
  1020.  
  1021.     /*------------------------------------------------------------*\
  1022.     |    Allocate and fill the standard with data body
  1023.     \*------------------------------------------------------------*/
  1024.     ent = (BIF_Quadmesh3 *)new_withdata3(
  1025.         entName, QUAD_MESH3, do_quadmesh3,
  1026.         sizeof(BIF_Quadmesh3), numCoords, numFacets, numEdges,
  1027.         coordList[0], vFlagData, fFlagData, eFlagData,
  1028.         numGroups, groups);
  1029.     
  1030.     /* Finish off the entity */
  1031.     if ( ent != NULL )
  1032.     {
  1033.         ent->dim.size_x    = numColumns;
  1034.         ent->dim.size_y    = numRows;
  1035.  
  1036.         /* Fill in the data fields */
  1037.         ent->fdata.colrs = ent->facet_data.colrs;
  1038.         ent->vdata.points = ent->vertex_data.points;
  1039.     }
  1040.  
  1041.     /*------------------------------------------------------------*\
  1042.     |    Return the Entity Address
  1043.     \*------------------------------------------------------------*/
  1044.     return(ent);
  1045.  
  1046.  
  1047. } /* End procedure new_quadmesh3 */
  1048.  
  1049. /*--------------------------------------------------------------------*\
  1050. | Procedure     :    BIF_Indexpolygons3 *new_indexpolygons3(int,
  1051. |                        *Group_description)
  1052. |----------------------------------------------------------------------|
  1053. | Description   :    Allocate and fill a INDEX_POLYGONS3 entity with
  1054. |            optional data (if any )
  1055. |----------------------------------------------------------------------|
  1056. | Return        :    The pointer to the new structure ( or NULL on error )
  1057. \*--------------------------------------------------------------------*/
  1058. BIF_Indexpolygons3 *new_indexpolygons3(numGroups, groups)
  1059. int numGroups;
  1060. Group_description *groups;
  1061.  
  1062. {
  1063.     static char *entName = "INDEX_POLYGONS3";
  1064.     static int vFlagData[3] = { 1, 1, 2 };
  1065.     static int fFlagData[3] = { 1, 1, 2 };
  1066.     static int eFlagData[1] = { 1 };
  1067.  
  1068. #define NUM_INDEXPOLY_DGS 2
  1069.     static int scanListL[NUM_INDEXPOLY_DGS] = 
  1070.     {
  1071.         VERTEX_COORDINATES,
  1072.         FACET_CONNECTIVITY
  1073.     };
  1074.     static int sizeListL[NUM_INDEXPOLY_DGS];
  1075.     static Real_int_union *listListL[NUM_INDEXPOLY_DGS];
  1076.  
  1077.     int connListSize;
  1078.     int ip3SizePlus, numCoords, numFacets, numEdges;
  1079.  
  1080.     Pedge_data_list *elst;
  1081.     Pint_list *vlst;
  1082.     Pint *vconns;
  1083.     Pedge_flag *edges;
  1084.     int i, j, facetSize;
  1085.     char *ptr;
  1086.     Real_int_union *connList;
  1087.  
  1088.     BIF_Indexpolygons3 *ent;
  1089.  
  1090. #ifdef TEST_PRINT
  1091.     fflush(stderr);
  1092.     printf("in new_indexpolygons3 %d \n",numGroups);
  1093.     fflush(stdout);
  1094. #endif /* TEST_PRINT */
  1095.  
  1096.     /*------------------------------------------------------------*\
  1097.     |    Get the entity specific data groups
  1098.     \*------------------------------------------------------------*/
  1099.     scanForGroups(numGroups,groups,NUM_INDEXPOLY_DGS,scanListL,
  1100.         sizeListL,listListL);
  1101.  
  1102.  
  1103.     /*------------------------------------------------------------*\
  1104.     |    Set the standard sizes
  1105.     \*------------------------------------------------------------*/
  1106.     numCoords = sizeListL[0];
  1107.     numFacets = sizeListL[1];
  1108.     numEdges = contour_counter(sizeListL[1],listListL[1],1);
  1109.  
  1110.     connListSize = numFacets * sizeof(Pedge_data_list_list) +
  1111.       numFacets * sizeof(Pedge_data_list) + numFacets *
  1112.       sizeof(Pint_list_list) + numFacets * sizeof(Pint_list) +
  1113.       numEdges * sizeof(Pint);
  1114.     ip3SizePlus = sizeof(BIF_Indexpolygons3) + connListSize;
  1115.  
  1116.     /*------------------------------------------------------------*\
  1117.     |    Get the std withdata body loaded
  1118.     \*------------------------------------------------------------*/
  1119.     ent = (BIF_Indexpolygons3 *)new_withdata3(
  1120.         entName, INDEX_POLYGONS3, do_indexpolygons3,
  1121.         ip3SizePlus, numCoords, numFacets, numEdges,
  1122.         listListL[0], vFlagData, fFlagData, eFlagData,
  1123.         numGroups, groups);
  1124.     
  1125.     /*------------------------------------------------------------*\
  1126.     |    Finish off the entity
  1127.     \*------------------------------------------------------------*/
  1128.     if ( ent != NULL )
  1129.     {
  1130.         /*----------------------------------------------------*\
  1131.         |    Convert the facet and fill connectivity list
  1132.         \*----------------------------------------------------*/
  1133.         ptr = ((char *)ent) + sizeof(BIF_Indexpolygons3);
  1134.  
  1135.         ent->fdata.colrs = ent->facet_data.colrs;
  1136.         ent->vdata.num_vertices = numCoords;
  1137.         ent->vdata.vertex_data.points = ent->vertex_data.points;
  1138.  
  1139.         ent->edata = (Pedge_data_list_list *)ptr;
  1140.         ptr += numFacets * sizeof(Pedge_data_list_list);
  1141.         elst = (Pedge_data_list *)ptr;
  1142.         ptr += numFacets * sizeof(Pedge_data_list);
  1143.  
  1144.         ent->vlist = (Pint_list_list *)ptr;
  1145.         ptr += numFacets * sizeof(Pint_list_list);
  1146.         vlst = (Pint_list *)ptr;
  1147.         ptr += numFacets * sizeof(Pint_list);
  1148.  
  1149.         vconns = (Pint *)ptr;
  1150.         edges = ent->edge_data.edges;
  1151.         connList =listListL[1];
  1152.  
  1153.         for ( i = 0; i < numFacets; i++ )
  1154.         {
  1155.           ent->vlist[i].num_lists = 1;
  1156.           ent->vlist[i].lists = vlst++;
  1157.           facetSize = (connList++)->Int;
  1158.           ent->vlist[i].lists[0].num_ints = facetSize;
  1159.           ent->vlist[i].lists[0].ints = vconns;
  1160.           if (ent->edge_data_flag) {
  1161.             ent->edata[i].num_lists = 1;
  1162.             ent->edata[i].edgelist = elst++;
  1163.             ent->edata[i].edgelist[0].num_edges = facetSize;
  1164.             ent->edata[i].edgelist[0].edgedata.edges = edges;
  1165.             edges += facetSize;
  1166.           }
  1167.  
  1168.           for (j = 0; j < facetSize; j++) {
  1169.             *(vconns++) = (connList++)->Int;
  1170.           }
  1171.           }
  1172.     }
  1173.  
  1174.     /*------------------------------------------------------------*\
  1175.     |    Return the Entity Address
  1176.     \*------------------------------------------------------------*/
  1177.     return(ent);
  1178.  
  1179. } /* End procedure new_indexpolygons3 */
  1180.  
  1181. /*----------------------------------------------------------------------*\
  1182. | Procedure     :    BIF_Text *new_text(float, float, float, *char) 
  1183. |------------------------------------------------------------------------
  1184. | Description   :    Allocates and fills a text structure 
  1185. |------------------------------------------------------------------------
  1186. | Return        :    The pointer to the new structure
  1187. \*----------------------------------------------------------------------*/
  1188. BIF_Text *new_text( x, y, qtext_string ) 
  1189. float x, y;
  1190. char *qtext_string;
  1191.  
  1192. {
  1193.     BIF_Text     *ent;
  1194.     char         *ptr;
  1195.     int        total;
  1196.  
  1197.     total = sizeof( BIF_Text ) +
  1198.         ( strlen( qtext_string ) + 1 ) * sizeof( char );
  1199.  
  1200.     ptr = malloc((unsigned)total);
  1201.     ent = (BIF_Text *)ptr;
  1202.     if ( ptr != NULL )
  1203.     {
  1204.     /* Fill in the entity data */
  1205.         HEADER(ent, TEXT, do_text, NULL);
  1206.  
  1207.         ent->text_pt.x = x;
  1208.         ent->text_pt.y = y;
  1209.         ent->text_string = ptr + sizeof(BIF_Text);
  1210.         strcpy( ent->text_string, qtext_string );
  1211.     }
  1212.  
  1213.     return( ent );
  1214. }/* End new_text */
  1215.  
  1216. /*----------------------------------------------------------------------*\
  1217. | Procedure     :    BIF_Text3 *new_text3(float, float, float, *char) 
  1218. |------------------------------------------------------------------------
  1219. | Description   :    Allocates and fills a text3 structure 
  1220. |------------------------------------------------------------------------
  1221. | Return        :    The pointer to the new structure
  1222. \*----------------------------------------------------------------------*/
  1223. BIF_Text3 *new_text3( x, y, z, qtext_string,
  1224.     tbx, tby, tbz, tux, tuy, tuz) 
  1225.  
  1226. float x, y, z;
  1227. char *qtext_string;
  1228. float tbx, tby, tbz, tux, tuy, tuz;
  1229.  
  1230. {
  1231.     BIF_Text3     *ent;
  1232.     char         *ptr;
  1233.     int        total;
  1234.  
  1235.     total = sizeof( BIF_Text3 ) +
  1236.         ( strlen( qtext_string ) + 1 ) * sizeof( char );
  1237.  
  1238.     ptr = malloc((unsigned)total);
  1239.     ent = (BIF_Text3 *)ptr;
  1240.     if ( ptr != NULL )
  1241.     {
  1242.     /* Fill in the entity data */
  1243.         HEADER(ent, TEXT3, do_text3, NULL);
  1244.  
  1245.         ent->text_pt.x = x;
  1246.         ent->text_pt.y = y;
  1247.         ent->text_pt.z = z;
  1248.  
  1249.         ent->dir[0].delta_x = tbx;
  1250.         ent->dir[0].delta_y = tby;
  1251.         ent->dir[0].delta_z = tbz;
  1252.  
  1253.         ent->dir[1].delta_x = tux;
  1254.         ent->dir[1].delta_y = tuy;
  1255.         ent->dir[1].delta_z = tuz;
  1256.  
  1257.         ent->text_string = ptr + sizeof(BIF_Text3);
  1258.         strcpy( ent->text_string, qtext_string );
  1259.     }
  1260.  
  1261.     return( ent );
  1262. }/* End new_text3 */
  1263.  
  1264. /*----------------------------------------------------------------------*\
  1265. | Procedure     :    BIF_Anno_text3 *new_annotext3(
  1266. |                        float, float, float,
  1267. |                        float, float, float,
  1268. |                        *char) 
  1269. |------------------------------------------------------------------------
  1270. | Description   :    Allocates and fills a annotext3 structure 
  1271. |------------------------------------------------------------------------
  1272. | Return        :    The pointer to the new structure
  1273. \*----------------------------------------------------------------------*/
  1274. BIF_Anno_text3 *new_annotext3( x, y, z, ox, oy, oz, qtext_string)
  1275.  
  1276. float  x,  y,  z;
  1277. float ox, oy, oz;
  1278. char *qtext_string;
  1279.  
  1280. {
  1281.     BIF_Anno_text3     *ent;
  1282.     char         *ptr;
  1283.     int        total;
  1284.  
  1285.     total = sizeof( BIF_Anno_text3 ) +
  1286.         ( strlen( qtext_string ) + 1 ) * sizeof( char );
  1287.  
  1288.     ptr = malloc((unsigned)total);
  1289.     ent = (BIF_Anno_text3 *)ptr;
  1290.     if ( ptr != NULL )
  1291.     {
  1292.     /* Fill in the entity data */
  1293.         HEADER(ent,ANNOTATION_TEXT3,do_annotext3,NULL);
  1294.  
  1295.         ent->ref_pt.x  = x;
  1296.         ent->ref_pt.y  = y;
  1297.         ent->ref_pt.z  = z;
  1298.  
  1299.         ent->anno_offset.x = ox;
  1300.         ent->anno_offset.y = oy;
  1301.         ent->anno_offset.z = oz;
  1302.  
  1303.         ent->text_string = ptr + sizeof(BIF_Anno_text3);
  1304.         strcpy( ent->text_string, qtext_string );
  1305.     }
  1306.  
  1307.     return( ent );
  1308. }/* End new_annotext3 */
  1309.  
  1310. /*----------------------------------------------------------------------*\
  1311. | Procedure     :    BIF_Lightstate *new_lightstate(int,
  1312. |                        *Group_description)
  1313. |------------------------------------------------------------------------
  1314. | Description   :    Allocates and fills a LIGHT_STATE entity
  1315. |------------------------------------------------------------------------
  1316. | Return        :    The pointer to the new structure
  1317. \*----------------------------------------------------------------------*/
  1318. BIF_Lightstate *new_lightstate( num_groups, grp_header )
  1319. int num_groups;
  1320. Group_description *grp_header;
  1321.  
  1322. {
  1323.     int i, group;
  1324.     int number_to_on, number_to_off;
  1325.     Real_int_union *onlist, *offlist;
  1326.     int error, numskip;
  1327.     char *ptr;
  1328.     BIF_Lightstate *ent;
  1329.     Pint *listp;
  1330.  
  1331. /* Find the Size of it */
  1332.     number_to_on  = 0;
  1333.     number_to_off = 0;
  1334.     onlist = NULL;
  1335.     offlist = NULL;
  1336.     for ( group = 0 ; group < num_groups ; group++ )
  1337.     {
  1338.         switch (grp_header[group].name)
  1339.         {
  1340.         case ACTIVATE_LIST :
  1341.             number_to_on = grp_header[group].number;
  1342.             onlist = grp_header[group].list;
  1343.             break;
  1344.         case DEACTIVATE_LIST :
  1345.             number_to_off = grp_header[group].number;
  1346.             offlist = grp_header[group].list;
  1347.             break;
  1348.         }
  1349.  
  1350.     }
  1351.  
  1352. /* The two extra integers are for the case of
  1353.   number_to_off or number_to_off = 0 */
  1354.     ptr = malloc(sizeof(BIF_Lightstate) + 
  1355.              2 * sizeof(Pint_list) +
  1356.              (number_to_on + number_to_off) * 
  1357.              sizeof(Pint));
  1358.     if ( ptr != NULL )
  1359.     {
  1360.         ent = (BIF_Lightstate *)ptr;
  1361.         ptr += sizeof(BIF_Lightstate);
  1362.         ent->activation.ints = (Pint *)ptr;
  1363.         /* Fill the entity structures */
  1364.         /* The header */
  1365.         HEADER(ent, LIGHT_STATE, do_lightstate, NULL);
  1366.         /* The lists */    
  1367.         /* The On List */
  1368.         listp = ent->activation.ints;
  1369.         numskip = 0;
  1370.         for ( i = 0; i < number_to_on; i++ )
  1371.         {
  1372.             *listp = onlist[i].Int;
  1373.  
  1374.             /* Check the index */
  1375.             error = indexRange(LIGHT_STATE, (BIF_INT)(*listp),
  1376.                 1, BIF_MAX_LIGHTS);
  1377.             if ( error != 0 )
  1378.                 /* Skip baad lights */
  1379.                 numskip++;
  1380.             else
  1381.                 listp++;
  1382.         }
  1383.         ent->activation.num_ints = number_to_on - numskip;
  1384.         ptr += ent->activation.num_ints * sizeof(Pint);
  1385.         ent->deactivation.ints = (Pint *)ptr;
  1386.  
  1387.         /* The Off List */
  1388.         listp = ent->deactivation.ints;
  1389.         numskip = 0;
  1390.         for ( i = 0; i < number_to_off; i++ )
  1391.         {
  1392.             *listp = offlist[i].Int;
  1393.  
  1394.             /* Check the index */
  1395.             error = indexRange(LIGHT_STATE, (BIF_INT)(*listp),
  1396.                 1, BIF_MAX_LIGHTS);
  1397.             if ( error != 0 )
  1398.                 /* Skip baad lights */
  1399.                 numskip++;
  1400.             else
  1401.                 listp++;
  1402.         }
  1403.         ent->deactivation.num_ints = number_to_off - numskip;
  1404.  
  1405.     }
  1406.  
  1407.     return( ent );
  1408.  
  1409. } /* End new_lightstate */
  1410.  
  1411. /*----------------------------------------------------------------------*\
  1412. | Procedure     :    BIF_All *new_generic(*BIF_All, int, int, (*int)())
  1413. |------------------------------------------------------------------------
  1414. | Description   :    Allocate a new generic BIF entity
  1415. |------------------------------------------------------------------------
  1416. | Return        :    The pointer to the new structure
  1417. \*----------------------------------------------------------------------*/
  1418. BIF_All *new_generic( buffer, size, type, handler )
  1419.  
  1420. BIF_All *buffer;
  1421. int size;
  1422. int type;
  1423. int (*handler)();
  1424.  
  1425. {
  1426.  
  1427.     BIF_All *ent;
  1428.     BIF_Any *enta;
  1429. /* Allocate the memory */
  1430.     ent = (BIF_All *)malloc((unsigned)size);
  1431.     if ( ent != NULL )
  1432.     {
  1433.     /* Copy from the buffer  ( the body data ) */
  1434. #ifdef SYSV
  1435.         memcpy((char *)ent, (char *)buffer, size);
  1436. #else
  1437.         bcopy((char *)buffer, (char *)ent, size);
  1438. #endif
  1439.             
  1440.     /* Fill the entity header */
  1441.         enta = &ent->any;
  1442.         HEADER(enta, type, handler, NULL);
  1443.     }
  1444.  
  1445.     return( ent );
  1446.  
  1447. } /* End new_generic */
  1448.  
  1449. /*--------------------------------------------------------------------*\
  1450. | Procedure     :    int scanForGroups( int, Group_description *,
  1451. |                int, int *, int *, Real_int_union *,)
  1452. |---------------------------------------------------------------------
  1453. | Description   :    scans a group headers list for the groups
  1454. |            whoses name are given in the scanList.
  1455. |            Store their size and starting location in
  1456. |            sizeList and listList respectively.
  1457. |---------------------------------------------------------------------
  1458. | Return        :    Error Code (not Implemented)
  1459. \*--------------------------------------------------------------------*/
  1460.  
  1461. int scanForGroups(numGroups,groups,numScan,scanList,sizeList,listList)
  1462. int numGroups;
  1463. Group_description *groups;
  1464.  
  1465. int numScan;
  1466. int scanList[];
  1467.  
  1468. int sizeList[];
  1469. Real_int_union *listList[];
  1470.  
  1471. {
  1472.     int scan, group, found;
  1473.  
  1474.  
  1475.     /*------------------------------------------------------------*\
  1476.     |    For each of the requested groups scan the groups
  1477.     |    in the groups list.
  1478.     \*------------------------------------------------------------*/
  1479.     for ( scan = 0 ; scan < numScan  ; scan++ )
  1480.     {
  1481.         /* Initialize the scan */
  1482.         found = 0;
  1483.         sizeList[scan] = 0;
  1484.         listList[scan] = (Real_int_union *)NULL;
  1485.  
  1486.         for ( group=0 ; group < numGroups && !found ; group++ )
  1487.         {
  1488.             /* When a match is found save the size etc. */
  1489.             if (groups[group].name == scanList[scan])
  1490.             {
  1491.                 found = 1;
  1492.                 sizeList[scan] = groups[group].number;
  1493.                 listList[scan] = groups[group].list;
  1494.             }
  1495.         }
  1496.     }
  1497. }
  1498.  
  1499. /*--------------------------------------------------------------------*\
  1500. | Procedure     :    int fillVec(int, Real_int_union *,
  1501. |            char *, int, *vector[] )
  1502. |---------------------------------------------------------------------
  1503. | Description   :    Assign the malloc'd space to the array and
  1504. |            fill it.  If the supplied triplet list is too
  1505. |            short, the final entry is duplicated to the end
  1506. |            of the array.
  1507. |---------------------------------------------------------------------
  1508. | Return        :    The number of bytes used by the filled array.
  1509. \*--------------------------------------------------------------------*/
  1510. void fillVec(actSize, tripList, ptr, reqSize, adSize)
  1511. int actSize;
  1512. Real_int_union *tripList;
  1513. char * ptr;
  1514. int reqSize;
  1515. int adSize;
  1516. {
  1517.     int i;
  1518.     Pvec3 *vecs, *dupeMe;
  1519.  
  1520.     /* Establish the base of the array */
  1521.     vecs = (Pvec3 *)ptr;
  1522.  
  1523.     /* Fill It */
  1524.     if ( actSize > 0 )
  1525.     {
  1526.  
  1527.         /* Copy the data */
  1528.         for ( i = 0 ; i < actSize ; i++ )
  1529.         {
  1530.             vecs->delta_x = (tripList++)->Float;
  1531.             vecs->delta_y = (tripList++)->Float;
  1532.             vecs->delta_z = (tripList++)->Float;
  1533.             vecs = (Pvec3 *)(((char *)vecs) + adSize);
  1534.         }
  1535.  
  1536.         /* Dupe the last entry ( if needed ) */
  1537.         dupeMe = (Pvec3 *)(((char *)vecs) - adSize);
  1538.         for ( i = actSize ; i < reqSize ; i++ )
  1539.         {
  1540.             vecs->delta_x = dupeMe->delta_x;
  1541.             vecs->delta_y = dupeMe->delta_y;
  1542.             vecs->delta_z = dupeMe->delta_z;
  1543.             vecs = (Pvec3 *)(((char *)vecs) + adSize);
  1544.         }
  1545.     }
  1546.     else
  1547.     {
  1548.     /* Default Empty List has one zero entry */
  1549.     /* To possible reference from bombing    */
  1550.         vecs->delta_x = 0.0;
  1551.         vecs->delta_y = 0.0;
  1552.         vecs->delta_z = 0.0;
  1553.     }
  1554.  
  1555. } /* End fillVec() */
  1556.  
  1557. /*--------------------------------------------------------------------*\
  1558. | Procedure     :    int fillInt(int, Real_int_union *,
  1559. |            char *, int, *int[], int )
  1560. |---------------------------------------------------------------------
  1561. | Description   :    Assign the malloc'd space to the array and
  1562. |            fill it.  If the supplied integer list is too
  1563. |            short, the final entry is duplicated to the end
  1564. |            of the array.
  1565. |---------------------------------------------------------------------
  1566. | Return        :    The number of bytes used by the filled array.
  1567. \*--------------------------------------------------------------------*/
  1568. void fillInt(actSize, tripList, ptr, reqSize, adSize, colorInd)
  1569. int actSize;
  1570. Real_int_union *tripList;
  1571. char * ptr;
  1572. int reqSize;
  1573. int adSize;
  1574. int colorInd;
  1575.  
  1576. {
  1577.     int i, *vals, *dupeMe;
  1578.  
  1579.     /* Establish the base of the array */
  1580.     vals = (int *)ptr;
  1581.  
  1582.     /* Fill It */
  1583.     if ( actSize > 0 )
  1584.     {
  1585.  
  1586.         /* Copy the data */
  1587.         for ( i = 0 ; i < actSize ; i++ )
  1588.         {    
  1589. #ifdef EXTERNALNOTE
  1590.         /* index is incremented by one so that color '0' does
  1591.            not step on the default BG color. */
  1592. #endif
  1593.         *vals = (tripList++)->Int + colorInd;
  1594.         vals = (int *)(((char *)vals) + adSize);
  1595.         }
  1596.  
  1597.         /* Dupe the last entry ( if needed ) */
  1598.         dupeMe = (int *)(((char *)vals) - adSize);
  1599.         for ( i = actSize ; i < reqSize ; i++ )
  1600.         {
  1601.         *vals = *dupeMe;
  1602.         vals = (int *)(((char *)vals) + adSize);
  1603.         }
  1604.     }
  1605.     else
  1606.     {
  1607.     /* Default Empty List has one zero entry */
  1608.     /* To possible reference from bombing    */
  1609.         *vals = 0;
  1610.     }
  1611.  
  1612. } /* End fillInt() */
  1613.  
  1614. /*--------------------------------------------------------------------*\
  1615. | Procedure     :    errorSize(char *, int, int, int)
  1616. |---------------------------------------------------------------------
  1617. | Description   :    report if an actual group size is not correct
  1618. |---------------------------------------------------------------------
  1619. | Return        :    Error Code:
  1620. |                 0 no error
  1621. |                -1 error, error. sterilize, sterilize.
  1622. \*--------------------------------------------------------------------*/
  1623. int errorSize(entName,correctSize, actualSize, groupNameToken)
  1624. char *entName;
  1625. int correctSize, actualSize, groupNameToken;
  1626.  
  1627. {
  1628.     int retCode;
  1629.     char buffy[256];
  1630.     char *find_keyword_token();
  1631.  
  1632.     if ( actualSize && ( correctSize != actualSize ) )
  1633.     {
  1634.         /* Send an error message */
  1635.         sprintf(buffy,
  1636.             "In %s: %s size error (%d vs. %d).\n",
  1637.             entName,find_keyword_token((BIF_INT)groupNameToken),
  1638.             actualSize, correctSize);
  1639.         yyerror(buffy);
  1640.         retCode = -1;
  1641.     }
  1642.     else
  1643.         retCode = 0;
  1644.     
  1645.     return(retCode);
  1646. } /* End errorSize */
  1647.  
  1648. /*--------------------------------------------------------------------*\
  1649. | Procedure     :    int scanWithData(*char, int, int, int, int,
  1650. |                        *Group_description )
  1651. |---------------------------------------------------------------------
  1652. | Description   :    Scan the groups for the standard ODG's
  1653. |            filling the static arrays sizeList and listList
  1654. |---------------------------------------------------------------------
  1655. | Return        :    The number of bytes needed by the ODG's
  1656. \*--------------------------------------------------------------------*/
  1657.  
  1658. int scanWithData(entName,numCoords,numFacets,numEdges,
  1659.     numGroups,groups)
  1660.                 
  1661. char *entName;
  1662. int numCoords,numFacets,numEdges;
  1663. int numGroups;
  1664. Group_description *groups;
  1665.  
  1666. {
  1667.     int odgLength, i;
  1668.     int numRec;
  1669.  
  1670.     /*------------------------------------------------------------*\
  1671.     |    Find the out how many data groups we have:
  1672.     \*------------------------------------------------------------*/
  1673.     scanForGroups(numGroups,groups,NUM_STD_ODGS,scanList,
  1674.         sizeList,listList);
  1675.  
  1676.     /*------------------------------------------------------------*\
  1677.     |    Accumulate memory req's of the ODG's
  1678.     |    Check sizes of the ODG's
  1679.     |    Minimum Size req. is 1*sizeof(<ODG record>)
  1680.     \*------------------------------------------------------------*/
  1681.     odgLength = 0;
  1682.     for( i=0 ; i < STD_ODGS_V ; i++)
  1683.     {
  1684.         odgLength += ODGSIZE(sizeList[i], numCoords,
  1685.             sizeofList[i]);
  1686.         if ( sizeList[i] )
  1687.             odgLength += ( numCoords * sizeofList[i] );
  1688.         errorSize(entName, numCoords, sizeList[i], scanList[i]);
  1689.     }
  1690.  
  1691.     for( i= STD_ODGS_V ; i <  STD_ODGS_F ; i++)
  1692.     {
  1693.         odgLength += ODGSIZE(sizeList[i], numFacets,
  1694.             sizeofList[i]);
  1695.         errorSize(entName, numFacets, sizeList[i], scanList[i]);
  1696.     }
  1697.  
  1698.     for( i= STD_ODGS_F ; i <  STD_ODGS_E ; i++)
  1699.     {
  1700.         odgLength += ODGSIZE(sizeList[i], numEdges,
  1701.             sizeofList[i]);
  1702.         numRec = contour_counter(sizeList[i],listList[i],
  1703.                     recSizeList[i]);
  1704.         errorSize(entName, numEdges, numRec, scanList[i]);
  1705.     }
  1706.  
  1707.     /*------------------------------------------------------------*\
  1708.     |    Return the size of the ODG's (in bytes)
  1709.     \*------------------------------------------------------------*/
  1710.     return(odgLength);
  1711.  
  1712. } /* End scanWithData */
  1713.  
  1714. /*--------------------------------------------------------------------*\
  1715. | Procedure     :    int scanWithDataSet(*char, int, int, int, int,
  1716. |                        *Group_description )
  1717. |---------------------------------------------------------------------
  1718. | Description   :    Scan the groups for the standard ODG Sets
  1719. |            filling the static arrays sizeList and listList
  1720. |---------------------------------------------------------------------
  1721. | Return        :    The number of bytes needed by the ODG's
  1722. \*--------------------------------------------------------------------*/
  1723. int scanWithDataSet(entName,numCoords,numFacets,numEdges,
  1724.     numGroups,groups)
  1725.                 
  1726. char *entName;
  1727. int numCoords,numFacets,numEdges;
  1728. int numGroups;
  1729. Group_description *groups;
  1730.  
  1731. {
  1732.     int odgLength, i;
  1733.     int numRec;
  1734.  
  1735.     /*------------------------------------------------------------*\
  1736.     |    Find the out how many data groups we have:
  1737.     \*------------------------------------------------------------*/
  1738.     scanForGroups(numGroups,groups,NUM_STD_ODGS,scanList,
  1739.         sizeList,listList);
  1740.  
  1741.     /*------------------------------------------------------------*\
  1742.     |    Accumulate memory req's of the ODG's
  1743.     |    Check sizes of the ODG's
  1744.     |    Minimum Size req. is 1*sizeof(<ODG record>)
  1745.     \*------------------------------------------------------------*/
  1746.     odgLength = 0;
  1747.     for( i=0 ; i < STD_ODGS_V ; i++)
  1748.     {
  1749.         odgLength += ODGSIZE(sizeList[i], numCoords,
  1750.             sizeofList[i]);
  1751.         if ( sizeList[i] )
  1752.             odgLength += ( numCoords * sizeofList[i] );
  1753.         numRec = contour_counter(sizeList[i],listList[i],
  1754.                     recSizeList[i]);
  1755.         errorSize(entName, numCoords, numRec, scanList[i]);
  1756.     }
  1757.  
  1758.     for( i= STD_ODGS_V ; i <  STD_ODGS_F ; i++)
  1759.     {
  1760.         odgLength += ODGSIZE(sizeList[i], numFacets,
  1761.             sizeofList[i]);
  1762.         errorSize(entName, numFacets, sizeList[i], scanList[i]);
  1763.     }
  1764.  
  1765.     for( i= STD_ODGS_F ; i <  STD_ODGS_E ; i++)
  1766.     {
  1767.         odgLength += ODGSIZE(sizeList[i], numEdges,
  1768.             sizeofList[i]);
  1769.         numRec = contour_counter(sizeList[i],listList[i],
  1770.                     recSizeList[i]);
  1771.         errorSize(entName, numEdges, numRec, scanList[i]);
  1772.     }
  1773.  
  1774.     /*------------------------------------------------------------*\
  1775.     |    Return the size of the ODG's (in bytes)
  1776.     \*------------------------------------------------------------*/
  1777.     return(odgLength);
  1778.  
  1779. } /* End scanWithDataSet */
  1780.  
  1781.  
  1782. /*--------------------------------------------------------------------*\
  1783. | Procedure     :    int loadWithData(ent, vptr, fptr, eptr);
  1784. |---------------------------------------------------------------------
  1785. | Description   :    Load the scan'd (see scanWithData) groups into
  1786. |            the STD_DATA_BODY
  1787. |---------------------------------------------------------------------
  1788. | Return        :    The amount of startPtr used in loadWithData
  1789. |            (in bytes).
  1790. \*--------------------------------------------------------------------*/
  1791. void loadWithData(ent, vptr, fptr, eptr)
  1792. BIF_Withdata3 *ent;
  1793. char *vptr, *fptr, *eptr;
  1794.  
  1795. {
  1796.     /*------------------------------------------------------------*\
  1797.     |    Fill the Vertex Colors
  1798.     \*------------------------------------------------------------*/
  1799.         if (sizeList[0]) {
  1800.       fillVec(sizeList[0], listList[0], vptr, ent->numCoords,
  1801.           sizeofVertexdata[ent->vertex_data_flag]);
  1802.       vptr += sizeof(Pcoval);
  1803.     }
  1804.         
  1805.     /*------------------------------------------------------------*\
  1806.     |    Fill the Vertex Color Indices
  1807.     \*------------------------------------------------------------*/
  1808.         if (sizeList[1]) {
  1809.       fillInt(sizeList[1], listList[1], vptr, ent->numCoords,
  1810.           sizeofVertexdata[ent->vertex_data_flag], 1);
  1811.       vptr += sizeof(Pcoval);
  1812.     }
  1813.         
  1814.     /*------------------------------------------------------------*\
  1815.     |    Fill the Vertex Normals
  1816.     \*------------------------------------------------------------*/
  1817.         if (sizeList[2]) {
  1818.       fillVec(sizeList[2], listList[2], vptr, ent->numCoords,
  1819.           sizeofVertexdata[ent->vertex_data_flag]);
  1820.       vptr += sizeof(Pvec3);
  1821.     }
  1822.         
  1823.     /*------------------------------------------------------------*\
  1824.     |    Fill the Facet Colors
  1825.     \*------------------------------------------------------------*/
  1826.         if (sizeList[3]) {
  1827.       fillVec(sizeList[3], listList[3], fptr, ent->numFacets,
  1828.           sizeofFacetdata[ent->facet_data_flag]);
  1829.       fptr += sizeof(Pcoval);
  1830.     }
  1831.         
  1832.     /*------------------------------------------------------------*\
  1833.     |    Fill the Facet Color Indices
  1834.     \*------------------------------------------------------------*/
  1835.         if (sizeList[4]) {
  1836.       fillInt(sizeList[4], listList[4], fptr, ent->numFacets,
  1837.           sizeofFacetdata[ent->facet_data_flag], 1);
  1838.       fptr += sizeof(Pcoval);
  1839.     }
  1840.         
  1841.     /*------------------------------------------------------------*\
  1842.     |    Fill the Facet Normals
  1843.     \*------------------------------------------------------------*/
  1844.         if (sizeList[5]) {
  1845.       fillVec(sizeList[5], listList[5], fptr, ent->numFacets,
  1846.           sizeofFacetdata[ent->facet_data_flag]);
  1847.       fptr += sizeof(Pvec3);
  1848.     }
  1849.         
  1850.     /*------------------------------------------------------------*\
  1851.     |    Fill the Edge Data
  1852.     \*------------------------------------------------------------*/
  1853.         if (sizeList[6]) {
  1854.       fillInt(sizeList[6], listList[6], eptr, ent->numEdges,
  1855.           sizeof(Pedge_flag), 0);
  1856.     }
  1857.         
  1858.     /*------------------------------------------------------------*\
  1859.     |    Return the Entity Address
  1860.     \*------------------------------------------------------------*/
  1861.  
  1862. } /* End procedure loadWithData */
  1863.  
  1864. /*--------------------------------------------------------------------*\
  1865. | Procedure     :    int loadWithDataSet(*BIF_Withdata3, *char, *char, *char)
  1866. |---------------------------------------------------------------------
  1867. | Description   :    Load the scan'd (see scanWithData) groups into
  1868. |             the STD_DATA_BODY for "set type" groups...
  1869. |             specifically for FILLAREASET3
  1870. |---------------------------------------------------------------------
  1871. | Return        :    The amount of startPtr used in loadWithDataSet
  1872. |             (in bytes).
  1873. \*--------------------------------------------------------------------*/
  1874. void loadWithDataSet(ent, vptr, fptr, eptr)
  1875. BIF_Withdata3 *ent;
  1876. char *vptr, *fptr, *eptr;
  1877.  
  1878. {
  1879.     /*------------------------------------------------------------*\
  1880.     |    Fill the Vertex Colors
  1881.     \*------------------------------------------------------------*/
  1882.         if (sizeList[0]) {
  1883.         fillVecSet(sizeList[0], listList[0], vptr, ent->numCoords,
  1884.                sizeofVertexdata[ent->vertex_data_flag]);
  1885.         vptr += sizeof(Pcoval);
  1886.     }
  1887.         
  1888.     /*------------------------------------------------------------*\
  1889.     |    Fill the Vertex Color Indices
  1890.     \*------------------------------------------------------------*/
  1891.     if (sizeList[1]) {
  1892.         fillIntSet(sizeList[1], listList[1], vptr, ent->numCoords,
  1893.                sizeofVertexdata[ent->vertex_data_flag], 1);
  1894.         vptr += sizeof(Pcoval);
  1895.     }
  1896.         
  1897.     /*------------------------------------------------------------*\
  1898.     |    Fill the Vertex Normals
  1899.     \*------------------------------------------------------------*/
  1900.     if (sizeList[2]) {
  1901.         fillVecSet(sizeList[2], listList[2], vptr, ent->numCoords,
  1902.                sizeofVertexdata[ent->vertex_data_flag]);
  1903.         vptr += sizeof(Pvec3);
  1904.     }
  1905.         
  1906.     /*------------------------------------------------------------*\
  1907.     |    Fill the Facet Colors
  1908.     \*------------------------------------------------------------*/
  1909.     if (sizeList[3]) {
  1910.         fillVec(sizeList[3], listList[3], fptr, ent->numFacets,
  1911.             sizeofFacetdata[ent->facet_data_flag]);
  1912.         fptr += sizeof(Pcoval);
  1913.     }
  1914.         
  1915.     /*------------------------------------------------------------*\
  1916.     |    Fill the Facet Color Indices
  1917.     \*------------------------------------------------------------*/
  1918.     if (sizeList[4]) {
  1919.         fillInt(sizeList[4], listList[4], fptr, ent->numFacets,
  1920.             sizeofFacetdata[ent->facet_data_flag], 1);
  1921.         fptr += sizeof(Pcoval);
  1922.     }
  1923.         
  1924.     /*------------------------------------------------------------*\
  1925.     |    Fill the Facet Normals
  1926.     \*------------------------------------------------------------*/
  1927.     if (sizeList[5]) {
  1928.         fillVec(sizeList[5], listList[5], fptr, ent->numFacets,
  1929.             sizeofFacetdata[ent->facet_data_flag]);
  1930.         fptr += sizeof(Pvec3);
  1931.     }
  1932.         
  1933.     /*------------------------------------------------------------*\
  1934.     |    Fill the Edge Data
  1935.     \*------------------------------------------------------------*/
  1936.     if (sizeList[6]) {
  1937.         fillIntSet(sizeList[6], listList[6], eptr, ent->numEdges,
  1938.                sizeof(Pedge_flag), 0);
  1939.     }        
  1940.  
  1941. } /* End procedure loadWithDataSet */
  1942.  
  1943. /*--------------------------------------------------------------------*\
  1944. | Procedure     :    int makeVertexFlag(int, int, int)
  1945. |---------------------------------------------------------------------
  1946. | Description   :    add the contribution values that make up
  1947. |            the vertex data flag.
  1948. |
  1949. |            The assumption is that the flag is composed of
  1950. |            the sum of powers of two, (arithmetic bit
  1951. |            setting).
  1952. |---------------------------------------------------------------------
  1953. | Return        :    the sum of the contributions of the "active"
  1954. |            ODG's
  1955. \*--------------------------------------------------------------------*/
  1956. int makeVertexFlag(colors,indices,normals)
  1957. int colors,indices,normals;
  1958.  
  1959. {
  1960.     return ( (sizeList[0] ? colors  : 0 )    /* Colors  */
  1961.         +(sizeList[1] ? indices : 0 )     /* Indices */
  1962.         +(sizeList[2] ? normals : 0 ) );    /* Normals */
  1963.  
  1964. } /* End makeVertexFlag */
  1965.  
  1966. /*--------------------------------------------------------------------*\
  1967. | Procedure     :    int makeFacetFlag(int, int, int)
  1968. |---------------------------------------------------------------------
  1969. | Description   :    add the contribution values that make up
  1970. |            the facet data flag.
  1971. |
  1972. |            The assumption is that the flag is composed of
  1973. |            the sum of powers of two, (arithmetic bit
  1974. |            setting).
  1975. |---------------------------------------------------------------------
  1976. | Return        :    the sum of the contributions of the "active"
  1977. |            ODG's
  1978. \*--------------------------------------------------------------------*/
  1979. int makeFacetFlag(colors,indices,normals)
  1980. int colors,indices,normals;
  1981.  
  1982. {
  1983.     return ( (sizeList[3] ? colors  : 0 )    /* Colors  */
  1984.         +(sizeList[4] ? indices : 0 )     /* Indices */
  1985.         +(sizeList[5] ? normals : 0 ) );    /* Normals */
  1986.  
  1987. } /* makeFacetFlag */
  1988.  
  1989. /*--------------------------------------------------------------------*\
  1990. | Procedure     :    int makeEdgeFlag(int)
  1991. |---------------------------------------------------------------------
  1992. | Description   :    add the contribution values that make up
  1993. |            the vertex data flag.
  1994. |
  1995. |            The assumption is that the flag is composed of
  1996. |            the sum of powers of two, (arithmetic bit
  1997. |            setting).
  1998. |---------------------------------------------------------------------
  1999. | Return        :    the sum of the contributions of the "active"
  2000. |            ODG's
  2001. \*--------------------------------------------------------------------*/
  2002. int makeEdgeFlag(edges)
  2003. int edges;
  2004.  
  2005. {
  2006.     return ( (sizeList[6] ? edges  : 0 ) );    /* Edges  */
  2007.  
  2008. } /* End makeEdgeFlag */
  2009.  
  2010. /*--------------------------------------------------------------------*\
  2011. | Procedure     :    int makeWithDataFlag(* int)
  2012. |---------------------------------------------------------------------
  2013. | Description   :    Set the fields in the with_data_flag array
  2014. |            given.
  2015. |---------------------------------------------------------------------
  2016. | Return        :    Error Code
  2017. \*--------------------------------------------------------------------*/
  2018. int makeWithDataFlag(flag)
  2019. int *flag;
  2020.  
  2021. {
  2022.     flag[VCOLORT] = ( sizeList[0] > 0 ) ? TRUE : FALSE;
  2023.     flag[VCOLORI] = ( sizeList[1] > 0 ) ? TRUE : FALSE;
  2024.     flag[VNORM]   = ( sizeList[2] > 0 ) ? TRUE : FALSE;
  2025.     flag[FCOLORT] = ( sizeList[3] > 0 ) ? TRUE : FALSE;
  2026.     flag[FCOLORI] = ( sizeList[4] > 0 ) ? TRUE : FALSE;
  2027.     flag[FNORM  ] = ( sizeList[5] > 0 ) ? TRUE : FALSE;
  2028.     flag[EDATA]   = ( sizeList[6] > 0 ) ? TRUE : FALSE;
  2029. } /* End makeWithDataFlag() */
  2030.  
  2031. /*--------------------------------------------------------------------*\
  2032. | Procedure     :    BIF_Withdata3 *new_withdata3( *char, int,
  2033. |                    (*int)(), int, int, int, int,
  2034. |                    *Real_int_union, *int, *int,
  2035. |                    *int, int, *Group_description)
  2036. |----------------------------------------------------------------------|
  2037. | Description   :    Allocate and fill a Withdata entity with optional data
  2038. |        (if any ) this is called from some other (line3, 
  2039. |        polygon3, et. al.) "new" entity routine, which finds
  2040. |        the Coords stuff and supplied the correct info & sizes. 
  2041. |----------------------------------------------------------------------|
  2042. | Return        :    The pointer to the new structure ( or NULL on error )
  2043. \*--------------------------------------------------------------------*/
  2044. BIF_Withdata3 *new_withdata3(entName,entType,entHandler,entBodySize,
  2045.         numCoords,numFacets,numEdges,
  2046.         coordList, vFlagData,fFlagData,eFlagData,
  2047.         numGroups, groups)
  2048.  
  2049. char *entName;
  2050. int entType;
  2051. int (*entHandler)();
  2052. int entBodySize;            /* Including extra arrays */
  2053. int numCoords,numFacets,numEdges;
  2054. Real_int_union coordList[];
  2055. int vFlagData[],fFlagData[],eFlagData[];
  2056. int numGroups;
  2057. Group_description *groups;
  2058.  
  2059. {
  2060.     BIF_Withdata3 *ent;
  2061.     char *ptr, *vptr, *fptr, *eptr;
  2062.     int vfLength;
  2063.  
  2064. #ifdef TEST_PRINT
  2065.     fflush(stderr);
  2066.     printf("in new_withdata3 %d \n",numGroups);
  2067.     fflush(stdout);
  2068. #endif /* TEST_PRINT */
  2069.  
  2070.     /*------------------------------------------------------------*\
  2071.     |    Find the ODG's and compute the sizes
  2072.     \*------------------------------------------------------------*/
  2073.     vfLength =( MAX_VAL(1,numCoords) *  sizeof(Ppoint3) );
  2074.     vfLength += scanWithData(entName,numCoords,numFacets, numEdges,
  2075.             numGroups, groups);
  2076.  
  2077.     /*------------------------------------------------------------*\
  2078.     |    Allocate the entity and fill it
  2079.     \*------------------------------------------------------------*/
  2080.     ent = (BIF_Withdata3 *)malloc((unsigned)(entBodySize+vfLength));
  2081.     if ( ent != NULL )
  2082.     {
  2083.         /*----------------------------------------------------*\
  2084.         |    Fill entity specific data
  2085.         |    Fixed Length Fields
  2086.         \*----------------------------------------------------*/
  2087.         HEADER(ent,entType,entHandler,NULL);
  2088.         STDSIZE(ent,numCoords,numFacets, numEdges);
  2089.  
  2090.         if ((sizeList[1] && vFlagData[1]) ||
  2091.             (sizeList[4] && fFlagData[1]))
  2092.             ent->colour_model = PINDIRECT;
  2093.         else
  2094.             ent->colour_model = wk_info.color_model;
  2095.  
  2096.         /*----------------------------------------------------*\
  2097.         |    Vertex and Fact Data Flags
  2098.         \*----------------------------------------------------*/
  2099.         ent->vertex_data_flag =
  2100.             makeVertexFlag(vFlagData[0],vFlagData[1],vFlagData[2]);
  2101.         ent->facet_data_flag =
  2102.             makeFacetFlag(fFlagData[0],fFlagData[1],fFlagData[2]);
  2103.         ent->edge_data_flag = makeEdgeFlag(eFlagData[0]);
  2104.         
  2105.         makeWithDataFlag(ent->with_data_flag);
  2106.  
  2107.         /*----------------------------------------------------*\
  2108.         |    Fill the variable length fields
  2109.         \*----------------------------------------------------*/
  2110.         ptr = ((char *)ent) + entBodySize;
  2111.  
  2112.         /* Fill the Coords */
  2113.         ent->vertex_data.points = (Ppoint3 *)ptr;
  2114.         fillVec(numCoords, coordList, ptr, numCoords,
  2115.             sizeofVertexdata[ent->vertex_data_flag]);
  2116.  
  2117.         /* Adjust to address for loading vertex data */
  2118.         vptr = ptr + sizeof(Ppoint3);
  2119.  
  2120.         fptr = ptr + (MAX_VAL(1,numCoords) *
  2121.                   sizeofVertexdata[ent->vertex_data_flag]);
  2122.         ent->facet_data.colrs = (Pcoval *)fptr;
  2123.  
  2124.         eptr = fptr + (MAX_VAL(1,numFacets) *
  2125.                    sizeofFacetdata[ent->facet_data_flag]);
  2126.         ent->edge_data.edges = (Pedge_flag *) eptr;
  2127.  
  2128.         /* Fill the With Data fields */
  2129.         loadWithData(ent, vptr, fptr, eptr);
  2130.     }
  2131.  
  2132.     /*------------------------------------------------------------*\
  2133.     |    Return the Entity Address
  2134.     \*------------------------------------------------------------*/
  2135. #ifdef TEST_PRINT
  2136.     printf("new_withdata3 $\n");
  2137.     fflush(stdout);
  2138. #endif /* TEST_PRINT */
  2139.     return(ent);
  2140.  
  2141. } /* End procedure new_WithData3 */
  2142.  
  2143. /*--------------------------------------------------------------------*\
  2144. | Procedure     :    BIF_Pixelmap3 *new_pixelmap3(* BIF_Pixelmap3)
  2145. |---------------------------------------------------------------------
  2146. | Description   :    Allocate a Pixelmap3 entity
  2147. |            The pixelmap will be filled be the parser using
  2148. |            the bif_pixellist function.
  2149. |---------------------------------------------------------------------
  2150. | Return        :    The pointer to the new structure ( or NULL on error )
  2151. \*--------------------------------------------------------------------*/
  2152. BIF_Pixelmap3 *new_pixelmap3( tempEnt )
  2153. BIF_Pixelmap3 *tempEnt;
  2154.  
  2155. {
  2156.     BIF_Pixelmap3 *ent;
  2157.     char *ptr;
  2158.     int numPixels, oneChannelSize, vfLength;
  2159.     int numChannels;
  2160.  
  2161.     /*------------------------------------------------------------*\
  2162.     |    Allocate the entity and fill it
  2163.     \*------------------------------------------------------------*/
  2164.     numPixels = tempEnt->numRows * tempEnt->numColumns;
  2165.     oneChannelSize = sizeof(unsigned char) * numPixels;
  2166.  
  2167. #ifdef TEST_PRINT
  2168. fprintf(stderr,"numPixels: %d \n",numPixels);
  2169. #endif /* TEST_PRINT */
  2170.  
  2171.     if ( wk_info.color_mode == BIF_TRUE_COLOR )
  2172.         numChannels = 3;
  2173.     else
  2174.         numChannels = 1;
  2175.  
  2176.     if ( numChannels == 3 )
  2177.         /* RGB Components */
  2178.         vfLength = 3 * oneChannelSize;
  2179.     else
  2180.         /* Pseudo color */
  2181.         vfLength = 1 * oneChannelSize;
  2182.  
  2183.     ent = ALLOCV(BIF_Pixelmap3,vfLength);
  2184.  
  2185.     if ( ent != NULL )
  2186.     {
  2187.         /*----------------------------------------------------*\
  2188.         |    Fill entity specific data
  2189.         |    Fixed Length Fields
  2190.         \*----------------------------------------------------*/
  2191. #ifdef SYSV
  2192.         memcpy((char *)ent, (char *)tempEnt,
  2193.             sizeof(BIF_Pixelmap3));
  2194. #else
  2195.         bcopy((char *)tempEnt, (char *)ent, sizeof(BIF_Pixelmap3));
  2196. #endif
  2197.         HEADER(ent,PIXEL_MAP3,do_pixelmap3,NULL);
  2198.         ent->numCoords    = 1;
  2199.  
  2200.         /*----------------------------------------------------*\
  2201.         |    Apportion the memory to the RGB arrays
  2202.         \*----------------------------------------------------*/
  2203.         ptr = ((char *)ent) + sizeof(BIF_Pixelmap3);
  2204.  
  2205.         ent->red = (unsigned char *)ptr;
  2206.  
  2207.         if ( numChannels == 3 )
  2208.         {
  2209.             ptr += oneChannelSize;
  2210.             ent->green = (unsigned char *)ptr;
  2211.             ptr += oneChannelSize;
  2212.             ent->blue  = (unsigned char *)ptr;
  2213.         }
  2214.         else
  2215.         {
  2216.             ent->green = (unsigned char *)ptr;
  2217.             ent->blue  = (unsigned char *)ptr;
  2218.         }
  2219.     }
  2220.  
  2221.     /*------------------------------------------------------------*\
  2222.     |    Return the Entity Address
  2223.     \*------------------------------------------------------------*/
  2224.     return(ent);
  2225.  
  2226. } /* End procedure new_Pixelmap3 */
  2227.  
  2228.  
  2229.  
  2230. /*--------------------------------------------------------------------*\
  2231. | Procedure     :    BIF_Nubc *new_nubc(int, *Group_description)
  2232. |----------------------------------------------------------------------|
  2233. | Description   :    Allocate and fill a NON_UNIFORM_BSPLINE_CURVE
  2234. |            entity with optional data
  2235. |            (if any )
  2236. |----------------------------------------------------------------------|
  2237. | Return        :    The pointer to the new structure ( or NULL on error )
  2238. \*--------------------------------------------------------------------*/
  2239. BIF_Nubc *new_nubc(numGroups, groups)
  2240. int numGroups;
  2241. Group_description *groups;
  2242.  
  2243. {
  2244. }
  2245.  
  2246. /*--------------------------------------------------------------------*\
  2247. | Procedure     :    BIF_Nubs *new_nubs(int, *Group_description)
  2248. |----------------------------------------------------------------------|
  2249. | Description   :    Allocate and fill a NON_UNIFORM_BSPLINE_SURFACE
  2250. |            entity with optional data (if any )
  2251. |----------------------------------------------------------------------|
  2252. | Return        :    The pointer to the new structure ( or NULL on error )
  2253. \*--------------------------------------------------------------------*/
  2254. BIF_Nubs *new_nubs(numGroups, groups)
  2255. int numGroups;
  2256. Group_description *groups;
  2257.  
  2258. {
  2259. }
  2260.