00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
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
00066
00067
00068
00069
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
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
00385
00386
00387
00388
00389
00390
00391