db.h

Go to the documentation of this file.
00001 /*                            D B . H
00002  * BRL-CAD
00003  *
00004  * Copyright (c) 1985-2006 United States Government as represented by
00005  * the U.S. Army Research Laboratory.
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public License
00009  * as published by the Free Software Foundation; either version 2.1 of
00010  * the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Library General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this file; see the file named COPYING for more
00019  * information.
00020  */
00021 /** @addtogroup db4 */
00022 /*@{*/
00023 /** @file db.h
00024  *@brief
00025  *              GED Database Format v4
00026  *
00027  * All records are rounded up to have a fixed length;  each such
00028  * database record is also known as a "granule", and is the smallest
00029  * unit of database storage.
00030  *
00031  * Every granule can be identified by the first byte, which can
00032  * be accessed by the u_id name.  Note that the u_id field is not
00033  * valid when writing the actual data for splines.
00034  *
00035  * Each granule is read into a "union record", and is then processed
00036  * based on the value of u_id.  Each granule will have one of these formats:
00037  *      A Free record
00038  *      An ID record
00039  *      A SOLID record
00040  *      A COMBINATION record, followed by multiple
00041  *              MEMBER records
00042  *      An ARS `A' (header) record, followed by multiple
00043  *              ARS `B' (data) records
00044  *      A Polygon header record, followed by multiple
00045  *              Polygon data records
00046  *      A B-spline solid header record, followed by multiple
00047  *              B-spline surface records, followed by
00048  *                      d_kv_size[0] floats,
00049  *                      d_kv_size[1] floats,
00050  *                      padded to d_nknots granules, followed by
00051  *                      ctl_size[0]*ctl_size[1]*geom_type floats,
00052  *                      padded to d_nctls granules.
00053  *
00054  * The records are stored as binary records corresponding to PDP-11 and
00055  * VAX C structs, so padding must be supplied explicitly for alignment.
00056  *
00057  * For the time being, the representation of the floating point numbers
00058  * in the database is machine-specific, requiring conversion to ASCII
00059  * (via g2asc) and back to binary (via asc2g) when exchanging between
00060  * machines of dissimilar types.  In time, an external representation
00061  * for floats might be implemented.
00062  *
00063  *  @author
00064  *      Michael John Muuss
00065  *
00066  *  @par Source
00067  *      SECAD/VLD Computing Consortium, Bldg 394
00068  *@n    The U. S. Army Ballistic Research Laboratory
00069  *@n    Aberdeen Proving Ground, Maryland  21005
00070  *
00071  *  $Header: /cvsroot/brlcad/brlcad/include/db.h,v 14.7 2006/09/18 05:24:07 lbutler Exp $
00072  */
00073 
00074 #ifndef DB_H
00075 #define DB_H seen
00076 
00077 #define NAMESIZE                16
00078 
00079 /*
00080  *  Define the database format for storing binary floating point values.
00081  *  The ultimate intention is to store everything in 8 bytes, using
00082  *  IEEE double precision in network order.
00083  */
00084 #if defined(CRAY)
00085 typedef double dbfloat_t;
00086 #else
00087 typedef float dbfloat_t;
00088 #endif
00089 
00090 #define NAMEMOVE(from,to)       (void)strncpy(to, from, NAMESIZE)
00091 
00092 #define DB_MINREC       128
00093 
00094 #if !defined(RECORD_DEFINED) || !defined(__STDC__)
00095 #define RECORD_DEFINED
00096 union record  {
00097 
00098         char    u_id;           /* To differentiate record types */
00099 #define ID_IDENT        'I'
00100 #define ID_SOLID        'S'
00101 #define ID_COMB         'C'
00102 #define ID_MEMB         'M'
00103 #define ID_ARS_A        'A'
00104 #define ID_ARS_B        'B'
00105 #define ID_FREE         'F'     /* Free record -- ignore */
00106 #define ID_P_HEAD       'P'     /* Polygon header */
00107 #define ID_P_DATA       'Q'     /* Polygon data record */
00108 #define ID_BSOLID       'b'     /* B-spline solid.  multiple surfs */
00109 #define ID_BSURF        'D'     /* d_spline surface header */
00110 #define ID_MATERIAL     'm'     /* Material description record */
00111 #define DBID_STRSOL     's'     /* String solid description */
00112 #define DBID_ARBN       'n'     /* Convex polyhedron with N faces */
00113 #define DBID_PIPE       'w'     /* pipe (wire) solid */
00114 #define DBID_PARTICLE   'p'     /* a particle (lozenge) */
00115 #define DBID_NMG        'N'     /* NMG solid */
00116 #define DBID_SKETCH     'd'     /* 2D sketch */
00117 #define DBID_EXTR       'e'     /* solid of extrusion */
00118 #define DBID_CLINE      'c'     /* FASTGEN4 CLINE solid */
00119 #define DBID_BOT        't'     /* Bag o' triangles */
00120 
00121         char    u_size[DB_MINREC];      /* Minimum record size */
00122 
00123         struct ident  {
00124                 char    i_id;           /* ID_IDENT */
00125                 char    i_units;        /* units */
00126 /* Values of 0..5 are fixed for file compat with Release 2.3 through 4.5 */
00127 #define ID_NO_UNIT      0               /* unspecified */
00128 #define ID_MM_UNIT      1               /* milimeters (preferred) */
00129 #define ID_CM_UNIT      2               /* centimeters */
00130 #define ID_M_UNIT       3               /* meters */
00131 #define ID_IN_UNIT      4               /* inches */
00132 #define ID_FT_UNIT      5               /* feet */
00133 /* These new values 6..9 added in Release 5.0 */
00134 #define ID_UM_UNIT      6               /* micrometers */
00135 #define ID_KM_UNIT      7               /* kilometers */
00136 #define ID_YD_UNIT      8               /* yards */
00137 #define ID_MI_UNIT      9               /* miles */
00138                 char    i_version[6];   /* Version code of Database format */
00139 #define ID_VERSION      "v4"            /* Current Version */
00140                 char    i_title[72];    /* Title or description */
00141                 /* For the future */
00142                 char    i_byteorder;    /* Byte ordering */
00143 #define ID_BY_UNKNOWN   0               /* unknown */
00144 #define ID_BY_VAX       1               /* VAX (Little Endian) */
00145 #define ED_BY_IBM       2               /* IBM (Big Endian) */
00146                 char    i_floattype;    /* Floating point type */
00147 #define ID_FT_UNKNOWN   0               /* unknown */
00148 #define ID_FT_VAX       1               /* VAX */
00149 #define ID_FT_IBM       2               /* IBM */
00150 #define ID_FT_IEEE      3               /* IEEE */
00151 #define ID_FT_CRAY      4               /* Cray */
00152         } i;
00153 
00154         struct solidrec  {
00155                 char    s_id;           /* ID_SOLID */
00156                 char    s_type;         /* GED primitive type */
00157 /* also TOR     16         toroid */
00158 #define GENTGC  18      /* supergeneralized TGC; internal form */
00159 #define GENELL  19      /* ready for drawing ELL:  V,A,B,C */
00160 #define GENARB8 20      /* generalized ARB8:  V, and 7 other vectors */
00161 #define ARS     21      /* HACK arbitrary triangular-surfaced polyhedron */
00162 #define ARSCONT 22      /* HACK extension record type for ARS solid */
00163 #define HALFSPACE 24    /* half-space */
00164 #define SPLINE   25     /* HACK and trouble */
00165 #define RPC     26      /* Right Parabolic Cylinder */
00166 #define RHC     27      /* Right Parabolic Cylinder */
00167 #define EPA     28      /* Elliptical Paraboloid */
00168 #define EHY     29      /* Elliptical Hyperboloid */
00169 #define ETO     30      /* Elliptical Torus */
00170 #define GRP     31      /* Grip pseudo solid */
00171 #define SUPERELL 32     /* Superquadtratic Ellipsoid */
00172                 char    s_name[NAMESIZE];       /* unique name */
00173                 short   s_cgtype;               /* COMGEOM solid type */
00174 #define RPP     1       /* axis-aligned rectangular parallelopiped */
00175 #define BOX     2       /* arbitrary rectangular parallelopiped */
00176 #define RAW     3       /* right-angle wedge */
00177 #define ARB4    4       /* tetrahedron */
00178 #define ARB5    5       /* pyramid */
00179 #define ARB6    6       /* extruded triangle */
00180 #define ARB7    7       /* weird 7-vertex shape */
00181 #define ARB8    8       /* hexahedron */
00182 #define ELL     9       /* ellipsoid */
00183 #define ELL1    10      /* another ellipsoid definition */
00184 #define SPH     11      /* sphere */
00185 #define RCC     12      /* right circular cylinder */
00186 #define REC     13      /* right elliptic sylinder */
00187 #define TRC     14      /* truncated regular cone */
00188 #define TEC     15      /* truncated elliptic cone */
00189 #define TOR     16      /* toroid */
00190 #define TGC     17      /* truncated general cone */
00191 #define ELLG    23      /* comgeom version of GENELL ellipsoid */
00192                 dbfloat_t       s_values[24];           /* parameters */
00193 #define s_tgc_V s_values[0]
00194 #define s_tgc_H s_values[3]
00195 #define s_tgc_A s_values[6]
00196 #define s_tgc_B s_values[9]
00197 #define s_tgc_C s_values[12]
00198 #define s_tgc_D s_values[15]
00199 
00200 #define s_tor_V s_values[0]
00201 #define s_tor_H s_values[3]
00202 #define s_tor_A s_values[6]
00203 #define s_tor_B s_values[9]
00204 #define s_tor_C s_values[12]
00205 #define s_tor_D s_values[15]
00206 #define s_tor_E s_values[18]
00207 #define s_tor_F s_values[21]
00208 
00209 #define s_ell_V s_values[0]
00210 #define s_ell_A s_values[3]
00211 #define s_ell_B s_values[6]
00212 #define s_ell_C s_values[9]
00213 
00214 #define s_superell_V s_values[0]
00215 #define s_superell_A s_values[3]
00216 #define s_superell_B s_values[6]
00217 #define s_superell_C s_values[9]
00218 #define s_superell_n s_values[12]
00219 #define s_superell_e s_values[13]
00220 
00221 #define s_half_N s_values[0]
00222 #define s_half_d s_values[3]
00223 
00224 #define s_grip_C s_values[0]
00225 #define s_grip_N s_values[3]
00226 #define s_grip_m s_values[6]
00227         }  s;
00228 
00229         struct combination  {
00230                 char    c_id;                   /* ID_COMB */
00231                 char    c_flags;                /* `R' if region, else ` ' */
00232 #define DBV4_NON_REGION                 ' '
00233 #define DBV4_NON_REGION_NULL            '\0'
00234 #define DBV4_REGION                     'R'
00235 #define DBV4_REGION_FASTGEN_PLATE       'P'
00236 #define DBV4_REGION_FASTGEN_VOLUME      'V'
00237                 char    c_name[NAMESIZE];       /* unique name */
00238                 short   c_regionid;             /* region ID code */
00239                 short   c_aircode;              /* air space code */
00240                 short   c_pad1;         /* was c_length, DEPRECATED: # of members */
00241                 short   c_pad2;         /* was c_num, DEPRECATED */
00242                 short   c_material;             /* (GIFT) material code */
00243                 short   c_los;                  /* equivalent LOS estimate */
00244                 char    c_override;             /* non-0 ==> c_rgb is color */
00245                 unsigned char c_rgb[3];         /* 0..255 color override */
00246                 char    c_matname[32];          /* Reference: Material name */
00247                 char    c_matparm[60];          /* String Material parms */
00248                 char    c_inherit;              /* Inheritance property */
00249 #define DB_INH_LOWER    0                       /* Lower nodes override */
00250 #define DB_INH_HIGHER   1                       /* Higher nodes override */
00251         }  c;
00252         struct member  {
00253                 char    m_id;                   /* ID_MEMB */
00254                 char    m_relation;             /* boolean operation */
00255 #define INTERSECT       '+'
00256 #define SUBTRACT        '-'
00257 #define UNION           'u'
00258                 char    m_brname[NAMESIZE];     /* DEPRECATED: name of this branch */
00259                 char    m_instname[NAMESIZE];   /* name of referred-to obj. */
00260                 short   m_pad1;
00261                 dbfloat_t m_mat[16];            /* homogeneous trans matrix */
00262                 short   m_pad2; /* was m_num, DEPRECATED: COMGEOM solid # ref */
00263         }  M;
00264 
00265         struct material_rec {           /* whole record is DEPRECATED */
00266                 char    md_id;          /* = ID_MATERIAL color override */
00267                 char    md_flags;       /* UNUSED */
00268                 short   md_low;         /* lower end of region IDs affected */
00269                 short   md_hi;          /* upper end of region IDs affected */
00270                 unsigned char md_r;
00271                 unsigned char md_g;     /* color of these regions:  0..255 */
00272                 unsigned char md_b;
00273                 char    md_material[100]; /* UNUSED now */
00274         } md;
00275 
00276         struct B_solid {
00277                 char    B_id;           /* = ID_BSOLID */
00278                 char    B_pad;
00279                 char    B_name[NAMESIZE];
00280                 short   B_nsurf;        /* #  of surfaces in this solid */
00281                 dbfloat_t B_resolution; /* resolution of flatness */
00282         } B;
00283         struct b_surf {
00284                 char    d_id;           /* = ID_BSURF */
00285                 short   d_order[2];     /* order of u and v directions */
00286                 short   d_kv_size[2];   /* knot vector size  (u and v) */
00287                 short   d_ctl_size[2];  /* control mesh size ( u and v) */
00288                 short   d_geom_type;    /* geom type 3 or 4 */
00289                 short   d_nknots;       /* # granules of knots */
00290                 short   d_nctls;        /* # granules of ctls */
00291         } d;
00292         /*
00293          * The b_surf record is followed by
00294          * d_nknots granules of knot vectors (first u, then v),
00295          * and then by d_nctls granules of control mesh information.
00296          * Note that neither of these have an ID field!
00297          */
00298 
00299         struct polyhead  {
00300                 char    p_id;           /* = POLY_HEAD */
00301                 char    p_pad1;
00302                 char    p_name[NAMESIZE];
00303         } p;
00304         struct polydata  {
00305                 char    q_id;           /* = POLY_DATA */
00306                 char    q_count;        /* # of vertices <= 5 */
00307                 dbfloat_t q_verts[5][3]; /* Actual vertices for this polygon */
00308                 dbfloat_t q_norms[5][3]; /* Normals at each vertex */
00309         } q;
00310 
00311         struct ars_rec  {
00312                 char    a_id;                   /* ID_ARS_A */
00313                 char    a_type;                 /* primitive type */
00314                 char    a_name[NAMESIZE];       /* unique name */
00315                 short   a_m;                    /* # of curves */
00316                 short   a_n;                    /* # of points per curve */
00317                 short   a_curlen;               /* # of granules per curve */
00318                 short   a_totlen;               /* # of granules for ARS */
00319                 /* Remainder are unused, and exist for ?compatability */
00320                 short   a_pad;
00321                 dbfloat_t a_xmax;               /* max x coordinate */
00322                 dbfloat_t a_xmin;               /* min x coordinate */
00323                 dbfloat_t a_ymax;               /* max y coordinate */
00324                 dbfloat_t a_ymin;               /* min y coordinate */
00325                 dbfloat_t a_zmax;               /* max z coordinate */
00326                 dbfloat_t a_zmin;               /* min z coordinate */
00327         }  a;
00328         struct ars_ext  {
00329                 char    b_id;                   /* ID_ARS_B */
00330                 char    b_type;                 /* primitive type */
00331                 short   b_n;                    /* current curve # */
00332                 short   b_ngranule;             /* curr. granule for curve */
00333                 short   b_pad;
00334                 dbfloat_t       b_values[8*3];          /* vectors */
00335         }  b;
00336         /*
00337          *  All records below here are in machine-independent format.
00338          */
00339         struct strsol  {
00340                 char    ss_id;                  /* ID_STRSOL */
00341                 char    ss_pad;
00342                 char    ss_name[NAMESIZE];      /* solid name */
00343 #define DB_SS_NGRAN     8                       /* All STRSOL's have this many granules */
00344 #define DB_SS_LEN       (DB_SS_NGRAN*DB_MINREC-2*NAMESIZE-2)
00345                 char    ss_keyword[NAMESIZE];   /* solid keyword */
00346                 char    ss_args[4];             /* DB_SS_LEN bytes of str args */
00347         }  ss;
00348         struct arbn_rec  {
00349                 char    n_id;                   /* DBID_ARBN */
00350                 char    n_pad;
00351                 char    n_name[NAMESIZE];
00352                 unsigned char   n_neqn[4];      /* # equations which follow */
00353                 unsigned char   n_grans[4];     /* # eqn granules to follow */
00354                 /* Note that eqn granules are in "network" byte order */
00355         }  n;
00356         /* new pipe solid */
00357         struct pipewire_rec  {
00358                 char    pwr_id;                 /* DBID_PIPE */
00359                 char    pwr_pad;
00360                 char    pwr_name[NAMESIZE];
00361                 unsigned char   pwr_pt_count[4]; /* number of points in this pipe solid */
00362                 unsigned char   pwr_count[4];   /* # additional granules */
00363                 struct exported_pipept  {
00364                         unsigned char   epp_coord[8*3];
00365                         unsigned char   epp_bendradius[8];
00366                         unsigned char   epp_id[8];
00367                         unsigned char   epp_od[8];
00368                 } pwr_data[1];                  /* mach indep segments */
00369         }  pwr;
00370         struct particle_rec  {
00371                 char    p_id;                   /* DBID_PARTICLE */
00372                 char    p_pad;
00373                 char    p_name[NAMESIZE];
00374                 unsigned char   p_v[8*3];       /* vertex (mach indep fmt) */
00375                 unsigned char   p_h[8*3];       /* height vector */
00376                 unsigned char   p_vrad[8];      /* radius at vertex */
00377                 unsigned char   p_hrad[8];      /* radius at end of height */
00378         }  part;
00379         /* Version 0 is Release 4.0 to 4.2, Version 1 is Release 4.4 */
00380         struct nmg_rec  {
00381                 char    N_id;                   /* DBID_NMG */
00382                 char    N_version;              /* Version indicator */
00383                 char    N_name[NAMESIZE];
00384                 char    N_pad2[2];              /* neatness */
00385                 unsigned char   N_count[4];     /* # additional granules */
00386                 unsigned char   N_structs[26*4];/* # of structs needed */
00387         } nmg;
00388 
00389         /* Solid of extrusion */
00390         struct extr_rec {
00391                 char    ex_id;                  /* DBID_EXTR */
00392                 char    ex_pad;
00393                 char    ex_name[NAMESIZE];
00394                 unsigned char   ex_V[8*3];      /* Vertex */
00395                 unsigned char   ex_h[8*3];      /* extrusion vector */
00396                 unsigned char   ex_uvec[8*3];   /* vector in U parameter direction */
00397                 unsigned char   ex_vvec[8*3];   /* vector in V parameter direction */
00398                 unsigned char   ex_key[4];      /* keypoint index */
00399                 unsigned char   ex_count[4];    /* number of additional granules
00400                                                  * (for now, this will always be 1 ) */
00401         } extr;
00402 
00403         /* sketch */
00404         struct sketch_rec       {
00405                 char    skt_id;                 /* DBID_SKETCH */
00406                 char    skt_pad;
00407                 char    skt_name[NAMESIZE];
00408                 unsigned char   skt_V[8*3];     /* vertex */
00409                 unsigned char   skt_uvec[8*3];  /* vector in U parameter direction */
00410                 unsigned char   skt_vvec[8*3];  /* vector in V parameter direction */
00411                 unsigned char   skt_vert_count[4];      /* number of vertices in sketch */
00412                 unsigned char   skt_seg_count[4];       /* number of segments in sketch */
00413                 unsigned char   skt_count[4];           /* number of additional granules */
00414         } skt;
00415 
00416         /* FASTGEN4 CLINE element */
00417         struct cline_rec {
00418                 char    cli_id;                 /* DBID_CLINE */
00419                 char    cli_pad;
00420                 char    cli_name[NAMESIZE];
00421                 unsigned char   cli_V[8*3];     /* vertex */
00422                 unsigned char   cli_h[8*3];     /* height vector */
00423                 unsigned char   cli_radius[8];  /* radius */
00424                 unsigned char   cli_thick[8];   /* plate thickness (0 means volume mode) */
00425         } cli;
00426 
00427         /* Bag o' triangles
00428          *  The vertices are stored in an array
00429          *  The faces are arrays of three ints each indexing into the array of vertices
00430          */
00431         struct bot_rec {
00432                 char            bot_id;
00433                 char            bot_pad;
00434                 char            bot_name[NAMESIZE];
00435                 unsigned char   bot_nrec[4];            /* number of additional records required */
00436                 unsigned char   bot_orientation;        /* unoriented, ccw, or cw */
00437                 unsigned char   bot_mode;               /* surface or volume */
00438                 unsigned char   bot_err_mode;
00439                 unsigned char   bot_num_verts[4];       /* number of vertices */
00440                 unsigned char   bot_num_triangles[4];   /* number of triangles */
00441                 unsigned char   bot_data[1];            /* the start of the data:
00442                                                          * num_verts*3*8 for the vertex floats
00443                                                          * num_triangles*3*4 for the triangle ints
00444                                                          * if mode is RT_BOT_PLATE, then additional data is:
00445                                                          * num_triangles*8 for the face thicknesses
00446                                                          * followed by a null terminated hex digit string "face_mode" (bit vector) */
00447         } bot;
00448 
00449 };
00450 #endif /* !RECORD_DEFINED || !__STDC__ */
00451 #define DB_RECORD_NULL  ((union record *)0)
00452 
00453 /*
00454  *  Macros for providing function prototypes, regardless of whether
00455  *  the compiler understands them or not.
00456  *  It is vital that the argument list given for "args" be enclosed
00457  *  in parens.
00458  */
00459 #if __STDC__
00460 #       define  DB_ARGS(args)                   args
00461 #else
00462 #       define  DB_ARGS(args)                   ()
00463 #endif
00464 
00465 /* convert dbfloat->fastf_t */
00466 void rt_fastf_float DB_ARGS( (fastf_t *ff, const dbfloat_t *fp, int n) );
00467 
00468 /* convert dbfloat mat->fastf_t */
00469 void rt_mat_dbmat DB_ARGS( (fastf_t *ff, const dbfloat_t *dbp) );
00470 void rt_dbmat_mat DB_ARGS( (dbfloat_t *dbp, const fastf_t *ff) );
00471 
00472 #endif  /* DB_H */
00473 /*@}*/
00474 /*
00475  * Local Variables:
00476  * mode: C
00477  * tab-width: 8
00478  * c-basic-offset: 4
00479  * indent-tabs-mode: t
00480  * End:
00481  * ex: shiftwidth=4 tabstop=8
00482  */
00483 

Generated on Mon Sep 18 01:24:40 2006 for BRL-CAD by  doxygen 1.4.6