BRL-CAD
db5_types.c
Go to the documentation of this file.
1 /* D B 5 _ T Y P E S . C
2  * BRL-CAD
3  *
4  * Copyright (c) 2000-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 /** @addtogroup db5 */
21 /** @{ */
22 /** @file librt/db5_types.c
23  *
24  * Map between Major_Types/Minor_Types and ASCII strings
25  *
26  */
27 
28 #include "common.h"
29 
30 #include <string.h>
31 #include <math.h>
32 #include "bio.h"
33 
34 
35 #include "bu/parse.h"
36 #include "bu/cv.h"
37 #include "vmath.h"
38 #include "db5.h"
39 #include "raytrace.h"
40 
41 
42 struct db5_type {
46  char *tag;
47  char *description;
48 };
49 
50 /**
51  * In order to support looking up Major_Types as well as (Major_Type,
52  * Minor_Type) pairs, every Major_Type needs an entry with
53  * heed_minor==0 and it must occur below any of its entries that have
54  * heed_minor==1.
55  */
56 static const struct db5_type type_table[] = {
57  { DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_TOR, 1, "tor", "torus" },
58  { DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_TGC, 1, "tgc", "truncated general cone" },
59  { DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_ELL, 1, "ell", "ellipsoid" },
60  { DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_ARB8, 1, "arb8", "arb8" },
61  { DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_ARS, 1, "ars", "waterline" },
62  { DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_HALF, 1, "half", "halfspace" },
63  { DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_REC, 1, "rec", "right elliptical cylinder" },
64  { DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_BSPLINE, 1, "bspline", "B-spline" },
65  { DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_SPH, 1, "sph", "sphere" },
66  { DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_NMG, 1, "nmg", "nmg" },
67  { DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_EBM, 1, "ebm", "extruded bitmap" },
68  { DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_VOL, 1, "vol", "voxels" },
69  { DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_ARBN, 1, "arbn", "arbn" },
70  { DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_PIPE, 1, "pipe", "pipe" },
71  { DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_PARTICLE, 1, "particle", "particle" },
72  { DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_RPC, 1, "rpc", "right parabolic cylinder" },
73  { DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_RHC, 1, "rhc", "right hyperbolic cylinder" },
74  { DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_EPA, 1, "epa", "elliptical paraboloid" },
75  { DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_EHY, 1, "ehy", "elliptical hyperboloid" },
76  { DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_ETO, 1, "eto", "elliptical torus" },
77  { DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_GRIP, 1, "grip", "grip" },
78  { DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_JOINT, 1, "joint", "joint" },
79  { DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_DSP, 1, "dsp", "displacement map (height field)" },
80  { DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_SKETCH, 1, "sketch", "sketch" },
81  { DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_EXTRUDE, 1, "extrude", "extrusion" },
82  { DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_SUBMODEL, 1, "submodel", "submodel" },
83  { DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_CLINE, 1, "cline", "cline" },
84  { DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_BOT, 1, "bot", "bag of triangles" },
85  { DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_COMBINATION, 1, "combination", "combination" },
86  { DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_BREP, 1, "brep", "Boundary Representation" },
87  { DB5_MAJORTYPE_BRLCAD, DB5_MINORTYPE_BRLCAD_HRT, 1, "hrt", "Heart" },
88  { DB5_MAJORTYPE_BRLCAD, 0, 0, "brlcad", "BRL-CAD geometry" },
89  { DB5_MAJORTYPE_ATTRIBUTE_ONLY, 0, 0, "attribonly", "attribute only" },
90  { DB5_MAJORTYPE_BINARY_UNIF, DB5_MINORTYPE_BINU_FLOAT, 1, "float", "array of floats" },
91  { DB5_MAJORTYPE_BINARY_UNIF, DB5_MINORTYPE_BINU_FLOAT, 1, "f", "array of floats" },
92  { DB5_MAJORTYPE_BINARY_UNIF, DB5_MINORTYPE_BINU_DOUBLE, 1, "double", "array of doubles" },
93  { DB5_MAJORTYPE_BINARY_UNIF, DB5_MINORTYPE_BINU_DOUBLE, 1, "d", "array of doubles" },
94  { DB5_MAJORTYPE_BINARY_UNIF, DB5_MINORTYPE_BINU_8BITINT_U, 1, "u8", "array of unsigned 8-bit ints" },
95  { DB5_MAJORTYPE_BINARY_UNIF, DB5_MINORTYPE_BINU_16BITINT_U, 1, "u16", "array of unsigned 16-bit ints" },
96  { DB5_MAJORTYPE_BINARY_UNIF, DB5_MINORTYPE_BINU_32BITINT_U, 1, "u32", "array of unsigned 32-bit ints" },
97  { DB5_MAJORTYPE_BINARY_UNIF, DB5_MINORTYPE_BINU_32BITINT_U, 1, "uint", "array of unsigned 32-bit ints" },
98  { DB5_MAJORTYPE_BINARY_UNIF, DB5_MINORTYPE_BINU_32BITINT_U, 1, "ui", "array of unsigned 32-bit ints" },
99  { DB5_MAJORTYPE_BINARY_UNIF, DB5_MINORTYPE_BINU_64BITINT_U, 1, "u64", "array of unsigned 64-bit ints" },
100  { DB5_MAJORTYPE_BINARY_UNIF, DB5_MINORTYPE_BINU_8BITINT, 1, "8", "array of 8-bit ints" },
101  { DB5_MAJORTYPE_BINARY_UNIF, DB5_MINORTYPE_BINU_16BITINT, 1, "16", "array of 16-bit ints" },
102  { DB5_MAJORTYPE_BINARY_UNIF, DB5_MINORTYPE_BINU_32BITINT, 1, "32", "array of 32-bit ints" },
103  { DB5_MAJORTYPE_BINARY_UNIF, DB5_MINORTYPE_BINU_32BITINT, 1, "int", "array of 32-bit ints" },
104  { DB5_MAJORTYPE_BINARY_UNIF, DB5_MINORTYPE_BINU_32BITINT, 1, "i", "array of 32-bit ints" },
105  { DB5_MAJORTYPE_BINARY_UNIF, DB5_MINORTYPE_BINU_64BITINT, 1, "64", "array of 64-bit ints" },
106  { DB5_MAJORTYPE_BINARY_UNIF, 0, 0, "binunif", "uniform-array binary" },
107  /* Following entry must be at end of table */
108  { DB5_MAJORTYPE_RESERVED, 0, 0, 0, 0 },
109 };
110 
111 
112 int
113 db5_type_tag_from_major(char **tag, const int major)
114 {
115  register struct db5_type *tp;
116 
117  for (tp = (struct db5_type *) type_table;
118  tp->major_code != DB5_MAJORTYPE_RESERVED;
119  ++tp) {
120  if ((tp->major_code == major) && !(tp->heed_minor)) {
121  *tag = tp->tag;
122  return 0;
123  }
124  }
125  return 1;
126 }
127 
128 
129 int
130 db5_type_descrip_from_major(char **descrip, const int major)
131 {
132  register struct db5_type *tp;
133 
134  for (tp = (struct db5_type *) type_table;
135  tp->major_code != DB5_MAJORTYPE_RESERVED;
136  ++tp) {
137  if ((tp->major_code == major) && !(tp->heed_minor)) {
138  *descrip = tp->description;
139  return 0;
140  }
141  }
142  return 1;
143 }
144 
145 
146 int
147 db5_type_tag_from_codes(char **tag, const int major, const int minor)
148 {
149  register struct db5_type *tp;
150  register int found_minors = 0;
151 
152  for (tp = (struct db5_type *) type_table;
153  tp->major_code != DB5_MAJORTYPE_RESERVED;
154  ++tp) {
155  if (tp->major_code == major) {
156  if (tp->heed_minor)
157  found_minors = 1;
158  if ((tp->minor_code == minor) || !found_minors) {
159  *tag = tp->tag;
160  return 0;
161  }
162  }
163  }
164  return 1;
165 }
166 
167 
168 int
169 db5_type_descrip_from_codes(char **descrip, const int major, const int minor)
170 {
171  register struct db5_type *tp;
172  register int found_minors = 0;
173 
174  for (tp = (struct db5_type *) type_table;
175  tp->major_code != DB5_MAJORTYPE_RESERVED;
176  ++tp) {
177  if (tp->major_code == major) {
178  if (tp->heed_minor)
179  found_minors = 1;
180  if ((tp->minor_code == minor) || !found_minors) {
181  *descrip = tp->description;
182  return 0;
183  }
184  }
185  }
186  return 1;
187 }
188 
189 
190 int
191 db5_type_codes_from_tag(int *major, int *minor, const char *tag)
192 {
193  register struct db5_type *tp;
194 
195  for (tp = (struct db5_type *) type_table;
196  tp->major_code != DB5_MAJORTYPE_RESERVED;
197  ++tp) {
198  if ((*(tp->tag) == *tag) && (BU_STR_EQUAL(tp->tag, tag))) {
199  *major = tp->major_code;
200  *minor = tp->minor_code;
201  return 0;
202  }
203  }
204  return 1;
205 }
206 
207 
208 int
209 db5_type_codes_from_descrip(int *major, int *minor, const char *descrip)
210 {
211  register struct db5_type *tp;
212 
213  for (tp = (struct db5_type *) type_table;
214  tp->major_code != DB5_MAJORTYPE_RESERVED;
215  ++tp) {
216  if ((*(tp->description) == *descrip)
217  && (BU_STR_EQUAL(tp->description, descrip))) {
218  *major = tp->major_code;
219  *minor = tp->minor_code;
220  return 0;
221  }
222  }
223  return 1;
224 }
225 
226 
227 size_t
228 db5_type_sizeof_h_binu(const int minor)
229 {
230  switch (minor) {
231  case DB5_MINORTYPE_BINU_FLOAT:
232  return sizeof(float);
233  case DB5_MINORTYPE_BINU_DOUBLE:
234  return sizeof(double);
235  case DB5_MINORTYPE_BINU_8BITINT:
236  case DB5_MINORTYPE_BINU_8BITINT_U:
237  return (size_t) 1;
238  case DB5_MINORTYPE_BINU_16BITINT:
239  case DB5_MINORTYPE_BINU_16BITINT_U:
240  return (size_t) 2;
241  case DB5_MINORTYPE_BINU_32BITINT:
242  case DB5_MINORTYPE_BINU_32BITINT_U:
243  return (size_t) 4;
244  case DB5_MINORTYPE_BINU_64BITINT:
245  case DB5_MINORTYPE_BINU_64BITINT_U:
246  return (size_t) 8;
247  }
248  return 0;
249 }
250 
251 
252 size_t
253 db5_type_sizeof_n_binu(const int minor)
254 {
255  switch (minor) {
256  case DB5_MINORTYPE_BINU_FLOAT:
257  return (size_t) SIZEOF_NETWORK_FLOAT;
258  case DB5_MINORTYPE_BINU_DOUBLE:
259  return (size_t) SIZEOF_NETWORK_DOUBLE;
260  case DB5_MINORTYPE_BINU_8BITINT:
261  case DB5_MINORTYPE_BINU_8BITINT_U:
262  return (size_t) 1;
263  case DB5_MINORTYPE_BINU_16BITINT:
264  case DB5_MINORTYPE_BINU_16BITINT_U:
265  return (size_t) 2;
266  case DB5_MINORTYPE_BINU_32BITINT:
267  case DB5_MINORTYPE_BINU_32BITINT_U:
268  return (size_t) 4;
269  case DB5_MINORTYPE_BINU_64BITINT:
270  case DB5_MINORTYPE_BINU_64BITINT_U:
271  return (size_t) 8;
272  }
273  return 0;
274 }
275 
276 /** @} */
277 /*
278  * Local Variables:
279  * mode: C
280  * tab-width: 8
281  * indent-tabs-mode: t
282  * c-file-style: "stroustrup"
283  * End:
284  * ex: shiftwidth=4 tabstop=8
285  */
int db5_type_tag_from_major(char **tag, const int major)
Definition: db5_types.c:113
#define SIZEOF_NETWORK_DOUBLE
Definition: cv.h:48
size_t db5_type_sizeof_n_binu(const int minor)
Definition: db5_types.c:253
int db5_type_descrip_from_codes(char **descrip, const int major, const int minor)
Definition: db5_types.c:169
int minor_code
Definition: db5_types.c:44
Header file for the BRL-CAD common definitions.
int heed_minor
Definition: db5_types.c:45
char * description
Definition: db5_types.c:47
char * tag
Definition: db5_types.c:46
int db5_type_codes_from_tag(int *major, int *minor, const char *tag)
Definition: db5_types.c:191
int db5_type_codes_from_descrip(int *major, int *minor, const char *descrip)
Definition: db5_types.c:209
int db5_type_tag_from_codes(char **tag, const int major, const int minor)
Definition: db5_types.c:147
#define SIZEOF_NETWORK_FLOAT
Definition: cv.h:47
size_t db5_type_sizeof_h_binu(const int minor)
Definition: db5_types.c:228
int db5_type_descrip_from_major(char **descrip, const int major)
Definition: db5_types.c:130
int major_code
Definition: db5_types.c:43
#define BU_STR_EQUAL(s1, s2)
Definition: str.h:126