home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / IRIT / IRITS.ZIP / PROGRAM.H < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-05  |  12.3 KB  |  285 lines

  1. /*****************************************************************************
  2. *   "Irit" - the 3d polygonal solid modeller.                     *
  3. *                                         *
  4. * Written by:  Gershon Elber                Ver 0.2, Mar. 1990   *
  5. ******************************************************************************
  6. * Main definition Header file  for Irit - the 3d polygonal solid modeller.   *
  7. *****************************************************************************/
  8.  
  9. #ifndef    IRIT_H
  10. #define    IRIT_H
  11.  
  12. /* Note program version should also be updated in irit.c module, in few      */
  13. /* places, as some system can not chain strings in the pre-processor level.  */
  14. #define  VERSION    "Version 2.1"             /* Program version. */
  15.  
  16. #ifdef NO_VOID_PTR
  17. #define VoidPtr        char *
  18. #else
  19. #define VoidPtr        void *
  20. #endif /* NO_VOID_PTR */
  21.  
  22. #ifdef __MSDOS__
  23. #include <mem.h>                        /* Used for memcpy rtns. */
  24. #else
  25. #include "xgeneral.h"
  26. #endif /* __MSDOS__ */
  27.  
  28. #include <setjmp.h>    /* Used for the long jumps - to main iteration loop. */
  29.  
  30. #ifndef    NULL
  31. #define    NULL    0
  32. #endif /* NULL */
  33.  
  34. #ifndef    TRUE
  35. #define    TRUE    1
  36. #define    FALSE    0
  37. #endif /* TRUE */
  38.  
  39. #define BSPACE    8
  40. #define TAB    9
  41. #define LF    10
  42. #define CR    13
  43. #define    ESC     27
  44.  
  45. #ifdef __MSDOS__
  46. typedef    float        RealType;        /* On IBMPC to reserve memory... */
  47. #else
  48. #define DOUBLE
  49. typedef    double        RealType;
  50. #endif /* __MSDOS__ */
  51.  
  52. typedef    unsigned char    ByteType;
  53.  
  54. typedef    RealType    PointType[3];    /* For X, Y, Z coordinates of point. */
  55. typedef RealType    VectorType[3];
  56. typedef RealType    PlaneType[4];            /* Plane equation coeff. */
  57. typedef RealType    MatrixType[4][4];       /* Homogeneous transform. */
  58.  
  59. #define EPSILON        1e-5
  60. #define INFINITY    1e6
  61.  
  62. #define NO_TYPE        0               /* Basic structure types. */
  63. #define VERTEX_TYPE    1
  64. #define POLYGON_TYPE    2
  65. #define OBJECT_TYPE    3
  66. #define OTHER_TYPE    10  /* Anything which is not one of the basic types. */
  67.  
  68. #define LINE_LEN_LONG    256           /* Lines read from stdin/files... */
  69. #define LINE_LEN    81           /* Lines read from stdin/files... */
  70. #define LINE_LEN_SHORT    31           /* Lines read from stdin/files... */
  71. #define OBJ_NAME_LEN    11                /* Names of objects. */
  72. #define FILE_NAME_LEN    13           /* Name (8) + Type (3) + Dot (1). */
  73.  
  74. #define MAX_OBJ_LIST    20       /* Maximum size of geometric object list. */
  75.  
  76. #define DEFAULT_LOAD_COLOR 1  /* Default colors for object loaded using LOAD */
  77. #define DEFAULT_BOOL_COLOR 2  /* command, for boolean result objects, for    */
  78. #define DEFAULT_ICRV_COLOR 14 /* boolean intersection curves and for basic   */
  79. #define DEFAULT_PRIM_COLOR 4  /* primitives colors, respectively.         */
  80.  
  81. #define UNDEF_OBJ    0       /* Objects (ObjectStruct - OBJECT_TYPE) types*/
  82. #define GEOMETRIC_OBJ    1    /* Dont change the order of these objects as */
  83. #define NUMERIC_OBJ    2    /* the over loading table (see OverLoad.c)   */
  84. #define VECTOR_OBJ    3    /* is hardwired to it. If you add objects    */
  85. #define MATRIX_OBJ    4    /* update that module properly.             */
  86. #define STRING_OBJ    5
  87. #define OBJ_LIST_OBJ    6
  88.  
  89. #define NUM_OF_OBJECT_TYPES    6
  90.  
  91. #define DELAY_CONST_DEFAULT    500            /* Used in cursor delay. */
  92.  
  93. #define DEFAULT_RESOLUTION    20    /* Used in Primitiv/Boolean modules. */
  94. #define DEFAULT_INTERNAL    FALSE          /* View of Internal edges? */
  95. #define DEFAULT_INTERCRV    FALSE          /* Return intersection curves? */
  96.  
  97. /*****************************************************************************
  98. * Global data structures:                             *
  99. * Objects in the system might be (real) scalars, (R3) vectors, matrices      *
  100. * (4 by 4 - transformation matrix), strings of chars, lists of objects, or   *
  101. * geometric objects. All but the last are simple and all their data is saved *
  102. * in the object space itself. The last (geometric) object points on a         *
  103. * polygonal list of the form:                             *
  104. *                                         *
  105. * Polygon -> Polygon -> Polygon -> Polygon -> .... -> NULL             *
  106. *    |        |       |          |                         *
  107. *    V          V          V          V                         *
  108. *  VList      VList      VList      VList    (VList = Vertex List)         *
  109. *                                         *
  110. * Each VList is a CIRCULAR vertex list. Each VList element (VertexStruct)    *
  111. * implicitly defines an edge from this vertex, to the next. As each edge     *
  112. * is used by exactly two polygons, a pointer to the other polygon using this *
  113. * edge exists in the VertexStruct. Each polygon has also its Plane         *
  114. * definition for fast processing, with its normal pointing INTO the object.  *
  115. *   Few other tags & flags are included in the data structures for different *
  116. * modules.                                     *
  117. *   Note, vertices are not shared by few VLists/Polygons although it may     *
  118. * decrease memory usage (suprisingly, not much). The main reason to that is  *
  119. * the basic assumption of this solid modeller, which is simplicity...         *
  120. *****************************************************************************/
  121.  
  122. /*****************************************************************************
  123. * Vertex Type - holds single 3D point, including some attributes on it as    *
  124. * Tags & Count. The 3D coordinates are saved in Pt. Pointer to next in chain *
  125. * is Pnext, and the pointer to the adjacent polygon (to the edge defined by  *
  126. * this Vertex and Vertex->Pnext) is PAdj.                     *
  127. *****************************************************************************/
  128. typedef struct VertexStruct {
  129.     ByteType Count, Tags;                /* Same attributes. */
  130.     PointType Pt;                  /* Holds X, Y, Z coordinates. */
  131.     struct PolygonStruct *PAdj;                /* To adjacent polygon. */
  132.     struct VertexStruct *Pnext;                   /* To next in chain. */
  133. } VertexStruct;
  134.  
  135. /* Internal edge, or edge generated by the polygon decomposition stage when */
  136. /* only convex polygons are allowed. This edge was not in the input        */
  137. /* non-convex polygon, and therefore one may not want to see/display it.    */
  138. /* Note bits 4-7 (high nibble of Tags) are reserved for the different        */
  139. /* modules to perform their local tasks and so should not be used here.        */
  140. #define INTERNAL_TAG    0x01           /* Edge Tag - This edge is internal. */
  141.  
  142. #define    IS_INTERNAL_EDGE(Vrtx)    ((Vrtx)->Tags & INTERNAL_TAG)
  143. #define    SET_INTERNAL_EDGE(Vrtx)    ((Vrtx)->Tags |= INTERNAL_TAG)
  144. #define    RST_INTERNAL_EDGE(Vrtx)    ((Vrtx)->Tags &= ~INTERNAL_TAG)
  145.  
  146. /*****************************************************************************
  147. * Polygon Type - holds single polygon - Its Plane definition, and a pointer  *
  148. * to its vertices contour list V. As for VertexStruct, different attributes  *
  149. * can be saved in Count & Tags. PAux can be used locally by different         *
  150. * modules, for local usage only, and nothing sould be assumed on entry.         *
  151. *****************************************************************************/
  152. typedef struct PolygonStruct {
  153.     ByteType Count, Tags;                /* Same attributes. */
  154.     PlaneType Plane;            /* Holds Plane as Ax + By + Cz + D. */
  155.     VoidPtr PAux;     /* May be used locally (temporary!) by any module. */
  156.     struct VertexStruct *V;              /* To vertices circular list. */
  157.     struct PolygonStruct *Pnext;               /* To next in chain. */
  158. } PolygonStruct;
  159.  
  160. /* Note bits 4-7 (high nibble of Tags) are reserved for the different        */
  161. /* modules to perform their local tasks and so should not be used here.        */
  162. #define CONVEX_TAG    0x01      /* Convex Tag - Set if polygon is convex. */
  163.  
  164. #define    IS_CONVEX_POLY(Poly)    ((Poly)->Tags & CONVEX_TAG)
  165. #define    SET_CONVEX_POLY(Poly)    ((Poly)->Tags |= CONVEX_TAG)
  166. #define    RST_CONVEX_POLY(Poly)    ((Poly)->Tags &= ~CONVEX_TAG)
  167.  
  168. /*****************************************************************************
  169. * Object Type - main system structure, which holds all the objects defined   *
  170. * in the system like Numeric, Geometric etc.                     *
  171. *   Note that as the number of objects will be usually extermely low (100 is *
  172. * high estimate!) we can waste some memory here...                 *
  173. *****************************************************************************/
  174. typedef struct ObjectStruct {
  175.     char Name[OBJ_NAME_LEN];                 /* Name of object. */
  176.     ByteType ObjType;           /* Object Type: Numeric, Geometric, etc. */
  177.     ByteType Count;          /* Count Number of references to this object. */
  178.     union {
  179.     struct PolygonStruct *Pl;               /* To polygons list. */
  180.     RealType R;                      /* Numeric real data. */
  181.     VectorType Vec;                   /* Numeric real vector data. */
  182.     MatrixType Mat;           /* Numeric 4 by 4 transformation matrix. */
  183.     struct ObjectStruct *PObjList[MAX_OBJ_LIST];    /* List of objects. */
  184.     char Str[LINE_LEN];         /* General string for text object. */
  185.     ByteType Attr[LINE_LEN];   /* Used to hold attributes of objects... */
  186.     } U;
  187.     struct ObjectStruct *Pnext;                   /* To next in chain. */
  188. } ObjectStruct;
  189.  
  190. #define IS_UNDEF_OBJ(Obj)    ((Obj)->ObjType == UNDEF_OBJ)
  191. #define IS_GEOM_OBJ(Obj)    ((Obj)->ObjType == GEOMETRIC_OBJ)
  192. #define IS_NUM_OBJ(Obj)        ((Obj)->ObjType == NUMERIC_OBJ)
  193. #define IS_VEC_OBJ(Obj)        ((Obj)->ObjType == VECTOR_OBJ)
  194. #define IS_MAT_OBJ(Obj)        ((Obj)->ObjType == MATRIX_OBJ)
  195. #define IS_STR_OBJ(Obj)        ((Obj)->ObjType == STRING_OBJ)
  196. #define IS_OLST_OBJ(Obj)    ((Obj)->ObjType == OBJ_LIST_OBJ)
  197.  
  198. /* Note the following is should be used only if the object is geometric! */
  199. #define GET_OBJECT_COLOR(Obj)   ((int) ((Obj)->U.Attr[4]))
  200. #define SET_OBJECT_COLOR(Obj, Value)   (((Obj)->U.Attr[4]) = Value)
  201. #define    IS_POLYLINE_GEOM_OBJ(Obj)    ((int) (Obj)->U.Attr[5])
  202. #define    SET_POLYLINE_GEOM_OBJ(Obj)    ((Obj)->U.Attr[5] = TRUE)
  203. #define    RST_POLYLINE_GEOM_OBJ(Obj)    ((Obj)->U.Attr[5] = FALSE)
  204. #define COPY_GEOM_ATTRIB(Dest, Src)    memcpy(&(Dest)->U.Attr[4], \
  205.                            &(Src)->U.Attr[4], 2);
  206. /* Follows by general purpose helpfull macros: */
  207.  
  208. #define MIN(x, y)        ((x) > (y) ? (y) : (x))
  209. #define MAX(x, y)        ((x) > (y) ? (x) : (y))
  210. #define BOUND(x, Min, Max)    (MAX(MIN(x, Max), Min))
  211.  
  212. #define ABS(x)            ((x) > 0 ? (x) : (-(x)))
  213. #define SQR(x)            ((x) * (x))
  214. #define SIGN(x)            ((x) > 0 ? 1 : ((x) < 0 ? -1 : 0))
  215.  
  216. #define SWAP(x, y, type)    { type temp = (x); (x) = (y); (y) = temp; }
  217.  
  218. #define APX_EQ(x, y)        (ABS(x - y) < EPSILON)
  219. #define PT_EQ(Pt1, Pt2)        (APX_EQ(Pt1[0], Pt2[0]) && \
  220.                  APX_EQ(Pt1[1], Pt2[1]) && \
  221.                  APX_EQ(Pt1[2], Pt2[2]))
  222.  
  223. #define PT_CLEAR(Pt)        Pt[0] = Pt[1] = Pt[2] = 0.0
  224.  
  225. #define PT_SCALE(Pt, Scalar)    Pt[0] *= Scalar; \
  226.                 Pt[1] *= Scalar; \
  227.                 Pt[2] *= Scalar
  228.  
  229. #define PT_COPY(PtDest, PtSrc)    memcpy(PtDest, PtSrc, 3 * sizeof(RealType))
  230. #define PLANE_COPY(PlDest, PlSrc) memcpy(PlDest, PlSrc, 4 * sizeof(RealType))
  231. #define MAT_COPY(Dest, Src)    memcpy(Dest, Src, 16 * sizeof(RealType))
  232. #define GEN_COPY(Dest, Src, Size) memcpy(Dest, Src, Size)
  233.  
  234. #define PT_LENGTH(Pt)        sqrt(SQR(Pt[0]) + SQR(Pt[1]) + SQR(Pt[2]))
  235.  
  236. #define PT_NORMALIZE(Pt)    { RealType Size = PT_LENGTH(Pt); \
  237.                   Pt[0] /= Size; \
  238.                   Pt[1] /= Size; \
  239.                   Pt[2] /= Size; \
  240.                 }
  241.  
  242. #define PT_ADD(Res, Pt1, Pt2)    Res[0] = Pt1[0] + Pt2[0]; \
  243.                 Res[1] = Pt1[1] + Pt2[1]; \
  244.                 Res[2] = Pt1[2] + Pt2[2]
  245.  
  246. #define PT_SUB(Res, Pt1, Pt2)    Res[0] = Pt1[0] - Pt2[0]; \
  247.                 Res[1] = Pt1[1] - Pt2[1]; \
  248.                 Res[2] = Pt1[2] - Pt2[2]
  249.  
  250. #define DOT_PROD(Pt1, Pt2)    (Pt1[0] * Pt2[0] + \
  251.                  Pt1[1] * Pt2[1] + \
  252.                  Pt1[2] * Pt2[2])
  253.  
  254. #define DEG2RAD(Deg)        ((Deg) * M_PI / 180.0)
  255. #define RAD2DEG(Rad)        ((Rad) * 180.0 / M_PI)
  256.  
  257.  
  258. extern struct ObjectStruct *GlblObjList;       /* All objects on system. */
  259.  
  260. extern jmp_buf LongJumpBuffer;                  /* Used in error recovery. */
  261.  
  262. extern FILE *LogFile;           /* If do log everything, it goes to here. */
  263.  
  264. extern char CurrentWorkingDir[],       /* Save start CWD to recover on exit. */
  265.         *PrgmHeader, *CopyRight, *AuthorName,
  266.         *HelpFileName,
  267.         *StartFileName,        /* Name of startup file to executed. */
  268.         *LogFileName,                /* Name of log file. */
  269.         *EditPrgm;        /* Name of editor to execute (edit command). */
  270.  
  271. extern int MouseExists, GraphDriver, /* Graph driver kind & mouse existance. */
  272.        DelayConstant,            /* Delay used in cursor display. */
  273.        GlblFatalError,      /* True if disaster in system - must quit! */
  274.        PrintLogFile,         /* If TRUE everything goes to log file. */
  275.        LoadColor,          /* Default colors for object loaded using LOAD */
  276.        BoolColor,          /* command, for boolean result objects or      */
  277.        ICrvColor,          /* boolean intersection curves and for basic   */
  278.        PrimColor;          /* primitives colors, respectively.         */
  279.  
  280. void MyExit(int ExitCode);
  281. void FatalError(char * ErrorMsg);
  282. void DefaultFPEHandler(int Sig, int Type, int *RegList);
  283.  
  284. #endif    /* IRIT_H */
  285.