db5_types.c

Go to the documentation of this file.
00001 /*                     D B 5 _ T Y P E S . C
00002  * BRL-CAD
00003  *
00004  * Copyright (c) 2000-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 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 
00022 /** @addtogroup db5 */
00023 
00024 /*@{*/
00025 /** @file db5_types.c
00026  *      Map between Major_Types/Minor_Types and ASCII strings
00027  *
00028  *  Author -
00029  *      Paul J. Tanenbaum
00030  *
00031  *  Source -
00032  *      The U. S. Army Research Laboratory
00033  *      Aberdeen Proving Ground, Maryland  21005-5066
00034  *
00035  */
00036 #ifndef lint
00037 static const char RCSell[] = "@(#)$Header: /cvsroot/brlcad/brlcad/src/librt/db5_types.c,v 14.10 2006/09/16 02:04:24 lbutler Exp $ (BRL)";
00038 #endif
00039 
00040 #include "common.h"
00041 
00042 
00043 
00044 #include <stdio.h>
00045 #ifdef HAVE_STRING_H
00046 #include <string.h>
00047 #endif
00048 #include <math.h>
00049 #include "machine.h"
00050 #include "bu.h"
00051 #include "vmath.h"
00052 #include "db5.h"
00053 #include "nmg.h"
00054 #include "raytrace.h"
00055 
00056 struct db5_type {
00057     int         major_code;
00058     int         minor_code;
00059     int         heed_minor;
00060     char        *tag;
00061     char        *description;
00062 };
00063 
00064 /*
00065  *      In order to support looking up Major_Types
00066  *      as well as (Major_Type, Minor_Type) pairs,
00067  *      every Major_Type needs an entry with heed_minor==0
00068  *      and it must occur below any of its entries that
00069  *      have heed_minor==1.
00070  */
00071 const static struct db5_type type_table[] = {
00072     {
00073         DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_TOR, 1, "tor", "torus"
00074     },
00075     {
00076         DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_TGC, 1, "tgc", "truncated general cone"
00077     },
00078     {
00079         DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_ELL, 1, "ell", "ellipsoid"
00080     },
00081     {
00082         DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_ARB8, 1, "arb8", "arb8"
00083     },
00084     {
00085         DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_ARS, 1, "ars", "waterline"
00086     },
00087     {
00088         DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_HALF, 1, "half", "halfspace"
00089     },
00090     {
00091         DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_REC, 1, "rec", "right elliptical cylinder"
00092     },
00093     {
00094         DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_BSPLINE, 1, "bspline", "B-spline"
00095     },
00096     {
00097         DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_SPH, 1, "sph", "sphere"
00098     },
00099     {
00100         DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_NMG, 1, "nmg", "nmg"
00101     },
00102     {
00103         DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_EBM, 1, "ebm", "extruded bitmap"
00104     },
00105     {
00106         DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_VOL, 1, "vol", "voxels"
00107     },
00108     {
00109         DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_ARBN, 1, "arbn", "arbn"
00110     },
00111     {
00112         DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_PIPE, 1, "pipe", "pipe"
00113     },
00114     {
00115         DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_PARTICLE, 1, "particle", "particle"
00116     },
00117     {
00118         DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_RPC, 1, "rpc", "right parabolic cylinder"
00119     },
00120     {
00121         DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_RHC, 1, "rhc", "right hyperbolic cylinder"
00122     },
00123     {
00124         DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_EPA, 1, "epa", "elliptical paraboloid"
00125     },
00126     {
00127         DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_EHY, 1, "ehy", "elliptical hyperboloid"
00128     },
00129     {
00130         DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_ETO, 1, "eto", "elliptical torus"
00131     },
00132     {
00133         DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_GRIP, 1, "grip", "grip"
00134     },
00135     {
00136         DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_JOINT, 1, "joint", "joint"
00137     },
00138     {
00139         DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_DSP, 1, "dsp", "displacement map (height field)"
00140     },
00141     {
00142         DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_SKETCH, 1, "sketch", "sketch"
00143     },
00144     {
00145         DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_EXTRUDE, 1, "extrude", "extrusion"
00146     },
00147     {
00148         DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_SUBMODEL, 1, "submodel", "submodel"
00149     },
00150     {
00151         DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_CLINE, 1, "cline", "cline"
00152     },
00153     {
00154         DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_BOT, 1, "bot", "bag of triangles"
00155     },
00156     {
00157         DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_COMBINATION, 1, "combination", "combination"
00158     },
00159     {
00160         DB5_MAJORTYPE_BRLCAD, 0, 0, "brlcad", "BRL-CAD geometry"
00161     },
00162     {
00163         DB5_MAJORTYPE_ATTRIBUTE_ONLY, 0, 0, "attribonly", "attribute only"
00164     },
00165     {
00166         DB5_MAJORTYPE_BINARY_EXPM, 0, 0, "binexpm", "experimental binary"
00167     },
00168     {
00169         DB5_MAJORTYPE_BINARY_UNIF, DB5_MINORTYPE_BINU_FLOAT, 1, "float", "array of floats"
00170     },
00171     {
00172         DB5_MAJORTYPE_BINARY_UNIF, DB5_MINORTYPE_BINU_FLOAT, 1, "f", "array of floats"
00173     },
00174     {
00175         DB5_MAJORTYPE_BINARY_UNIF, DB5_MINORTYPE_BINU_DOUBLE, 1, "double", "array of doubles"
00176     },
00177     {
00178         DB5_MAJORTYPE_BINARY_UNIF, DB5_MINORTYPE_BINU_DOUBLE, 1, "d", "array of doubles"
00179     },
00180     {
00181         DB5_MAJORTYPE_BINARY_UNIF, DB5_MINORTYPE_BINU_8BITINT_U, 1, "u8", "array of unsigned 8-bit ints"
00182     },
00183     {
00184         DB5_MAJORTYPE_BINARY_UNIF, DB5_MINORTYPE_BINU_16BITINT_U, 1, "u16", "array of unsigned 16-bit ints"
00185     },
00186     {
00187         DB5_MAJORTYPE_BINARY_UNIF, DB5_MINORTYPE_BINU_32BITINT_U, 1, "u32", "array of unsigned 32-bit ints"
00188     },
00189     {
00190         DB5_MAJORTYPE_BINARY_UNIF, DB5_MINORTYPE_BINU_32BITINT_U, 1, "uint", "array of unsigned 32-bit ints"
00191     },
00192     {
00193         DB5_MAJORTYPE_BINARY_UNIF, DB5_MINORTYPE_BINU_32BITINT_U, 1, "ui", "array of unsigned 32-bit ints"
00194     },
00195     {
00196         DB5_MAJORTYPE_BINARY_UNIF, DB5_MINORTYPE_BINU_64BITINT_U, 1, "u64", "array of unsigned 64-bit ints"
00197     },
00198     {
00199         DB5_MAJORTYPE_BINARY_UNIF, DB5_MINORTYPE_BINU_8BITINT, 1, "8", "array of 8-bit ints"
00200     },
00201     {
00202         DB5_MAJORTYPE_BINARY_UNIF, DB5_MINORTYPE_BINU_16BITINT, 1, "16", "array of 16-bit ints"
00203     },
00204     {
00205         DB5_MAJORTYPE_BINARY_UNIF, DB5_MINORTYPE_BINU_32BITINT, 1, "32", "array of 32-bit ints"
00206     },
00207     {
00208         DB5_MAJORTYPE_BINARY_UNIF, DB5_MINORTYPE_BINU_32BITINT, 1, "int", "array of 32-bit ints"
00209     },
00210     {
00211         DB5_MAJORTYPE_BINARY_UNIF, DB5_MINORTYPE_BINU_32BITINT, 1, "i", "array of 32-bit ints"
00212     },
00213     {
00214         DB5_MAJORTYPE_BINARY_UNIF, DB5_MINORTYPE_BINU_64BITINT, 1, "64", "array of 64-bit ints"
00215     },
00216     {
00217         DB5_MAJORTYPE_BINARY_UNIF, 0, 0, "binunif", "uniform-array binary"
00218     },
00219     {
00220         DB5_MAJORTYPE_BINARY_MIME, 0, 0, "binmime", "MIME-typed binary"
00221     },
00222     /*
00223      *  Following entry must be at end of table
00224      */
00225     {
00226         DB5_MAJORTYPE_RESERVED, 0, 0, 0, 0
00227     },
00228 };
00229 
00230 int
00231 db5_type_tag_from_major( char **tag, const int major ) {
00232     register struct db5_type    *tp;
00233 
00234     for (tp = (struct db5_type *) type_table;
00235             tp -> major_code != DB5_MAJORTYPE_RESERVED;
00236             ++tp) {
00237         if ((tp -> major_code == major) && !(tp -> heed_minor)) {
00238             *tag = tp -> tag;
00239             return 0;
00240         }
00241     }
00242     return 1;
00243 }
00244 
00245 int
00246 db5_type_descrip_from_major( char **descrip, const int major ) {
00247     register struct db5_type    *tp;
00248 
00249     for (tp = (struct db5_type *) type_table;
00250             tp -> major_code != DB5_MAJORTYPE_RESERVED;
00251             ++tp) {
00252         if ((tp -> major_code == major) && !(tp -> heed_minor)) {
00253             *descrip = tp -> description;
00254             return 0;
00255         }
00256     }
00257     return 1;
00258 }
00259 
00260 int
00261 db5_type_tag_from_codes( char **tag, const int major, const int minor ) {
00262     register struct db5_type    *tp;
00263     register int                found_minors = 0;
00264 
00265     for (tp = (struct db5_type *) type_table;
00266             tp -> major_code != DB5_MAJORTYPE_RESERVED;
00267             ++tp) {
00268         if (tp -> major_code == major) {
00269             if (tp -> heed_minor)
00270                 found_minors = 1;
00271             if ((tp -> minor_code == minor) || !found_minors) {
00272                 *tag = tp -> tag;
00273                 return 0;
00274             }
00275         }
00276     }
00277     return 1;
00278 }
00279 
00280 int
00281 db5_type_descrip_from_codes( char **descrip, const int major,
00282                             const int minor ) {
00283     register struct db5_type    *tp;
00284     register int                found_minors = 0;
00285 
00286     for (tp = (struct db5_type *) type_table;
00287             tp -> major_code != DB5_MAJORTYPE_RESERVED;
00288             ++tp) {
00289         if (tp -> major_code == major) {
00290             if (tp -> heed_minor)
00291                 found_minors = 1;
00292             if ((tp -> minor_code == minor) || !found_minors) {
00293                 *descrip = tp -> description;
00294                 return 0;
00295             }
00296         }
00297     }
00298     return 1;
00299 }
00300 
00301 int
00302 db5_type_codes_from_tag( int *major, int *minor, const char *tag ) {
00303     register struct db5_type    *tp;
00304 
00305 
00306     for (tp = (struct db5_type *) type_table;
00307             tp -> major_code != DB5_MAJORTYPE_RESERVED;
00308             ++tp) {
00309         if ((*(tp -> tag) == *tag) && (strcmp(tp -> tag, tag) == 0)) {
00310             *major = tp -> major_code;
00311             *minor = tp -> minor_code;
00312             return 0;
00313         }
00314     }
00315     return 1;
00316 }
00317 
00318 int
00319 db5_type_codes_from_descrip( int *major, int *minor, const char *descrip ) {
00320     register struct db5_type    *tp;
00321 
00322 
00323     for (tp = (struct db5_type *) type_table;
00324             tp -> major_code != DB5_MAJORTYPE_RESERVED;
00325             ++tp) {
00326         if ((*(tp -> description) == *descrip)
00327          && (strcmp(tp -> description, descrip) == 0)) {
00328             *major = tp -> major_code;
00329             *minor = tp -> minor_code;
00330             return 0;
00331         }
00332     }
00333     return 1;
00334 }
00335 
00336 size_t
00337 db5_type_sizeof_h_binu( const int minor ) {
00338     switch ( minor ) {
00339         case DB5_MINORTYPE_BINU_FLOAT:
00340             return sizeof(float);
00341         case DB5_MINORTYPE_BINU_DOUBLE:
00342             return sizeof(double);
00343         case DB5_MINORTYPE_BINU_8BITINT:
00344         case DB5_MINORTYPE_BINU_8BITINT_U:
00345             return (size_t) 1;
00346         case DB5_MINORTYPE_BINU_16BITINT:
00347         case DB5_MINORTYPE_BINU_16BITINT_U:
00348             return (size_t) 2;
00349         case DB5_MINORTYPE_BINU_32BITINT:
00350         case DB5_MINORTYPE_BINU_32BITINT_U:
00351             return (size_t) 4;
00352         case DB5_MINORTYPE_BINU_64BITINT:
00353         case DB5_MINORTYPE_BINU_64BITINT_U:
00354             return (size_t) 8;
00355     }
00356     return 0;
00357 }
00358 
00359 size_t
00360 db5_type_sizeof_n_binu( const int minor ) {
00361     switch ( minor ) {
00362         case DB5_MINORTYPE_BINU_FLOAT:
00363             return (size_t) SIZEOF_NETWORK_FLOAT;
00364         case DB5_MINORTYPE_BINU_DOUBLE:
00365             return (size_t) SIZEOF_NETWORK_DOUBLE;
00366         case DB5_MINORTYPE_BINU_8BITINT:
00367         case DB5_MINORTYPE_BINU_8BITINT_U:
00368             return (size_t) 1;
00369         case DB5_MINORTYPE_BINU_16BITINT:
00370         case DB5_MINORTYPE_BINU_16BITINT_U:
00371             return (size_t) 2;
00372         case DB5_MINORTYPE_BINU_32BITINT:
00373         case DB5_MINORTYPE_BINU_32BITINT_U:
00374             return (size_t) 4;
00375         case DB5_MINORTYPE_BINU_64BITINT:
00376         case DB5_MINORTYPE_BINU_64BITINT_U:
00377             return (size_t) 8;
00378     }
00379     return 0;
00380 }
00381 
00382 /*@}*/
00383 /*
00384  * Local Variables:
00385  * mode: C
00386  * tab-width: 8
00387  * c-basic-offset: 4
00388  * indent-tabs-mode: t
00389  * End:
00390  * ex: shiftwidth=4 tabstop=8
00391  */

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