BRL-CAD
density.h
Go to the documentation of this file.
1 /* D E N S I T Y . H
2  * BRL-CAD
3  *
4  * Copyright (c) 2008-2024 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 libanalyze
21  *
22  * Density related routines
23  *
24  */
25 /** @{ */
26 /** @file analyze/density.h */
27 
28 #ifndef ANALYZE_DENSITY_H
29 #define ANALYZE_DENSITY_H
30 
31 #include "common.h"
32 #include "vmath.h"
33 #include "analyze/defines.h"
34 
35 __BEGIN_DECLS
36 
37 /*
38  * Density specific structures
39  */
40 
41 #define DENSITY_MAGIC 0xaf0127
42 
43 /* the entries in the density table */
44 struct density_entry {
45  uint32_t magic;
47  char *name;
48 };
49 
50 /**
51  * Loading information from a .density file and querying it.
52  */
53 #if defined(__cplusplus)
54 extern "C" {
55 #endif
56 struct analyze_densities_impl;
58  struct analyze_densities_impl *i;
59 };
60 #if defined(__cplusplus)
61 }
62 #endif
63 
64 ANALYZE_EXPORT extern int analyze_densities_create(struct analyze_densities **a);
65 ANALYZE_EXPORT extern void analyze_densities_destroy(struct analyze_densities *a);
66 ANALYZE_EXPORT extern int analyze_densities_init(struct analyze_densities *a);
67 ANALYZE_EXPORT extern void analyze_densities_clear(struct analyze_densities *a);
68 
69 /* Update an entry if one matching id already exists, else create a new entry.
70  * Unlike the loading and writing functions, this command uses g/mm^3 */
71 ANALYZE_EXPORT extern int analyze_densities_set(struct analyze_densities *a, long int id, fastf_t density, const char *name, struct bu_vls *msgs);
72 
73 /* Accepts a buffer, typically read from a .density file. Expects units of g/cm^3.
74  * (TODO - Ugh - need to come up with a way to define the units in the file so we aren't
75  * tied to that forever...)
76  *
77  * Returns the number of valid density entries loaded. The optional ecnt variable, if
78  * supplied, will count the number of lines where the parser failed to recognize either
79  * a commented line or a valid density. Calling codes may then decide if they want to
80  * accept the partial result or fail hard based on the ecnt. */
81 ANALYZE_EXPORT extern int analyze_densities_load(struct analyze_densities *a, const char *buff, struct bu_vls *msgs, int *ecnt);
82 
83 /* Creates a .density buffer from a, writing units of g/cm^3. Returns length of buff
84  * (TODO - Ugh - need to come up with a way to define the units so we aren't
85  * tied to g/cm^3 that forever...) */
86 ANALYZE_EXPORT extern long int analyze_densities_write(char **buff, struct analyze_densities *a);
87 
88 /* This mapping will be unique - each id may have at most one entry in the database. Caller
89  * is responsible for freeing the resulting string. */
90 ANALYZE_EXPORT extern char *analyze_densities_name(struct analyze_densities *a, long int id);
91 
92 /* Because this mapping is not guaranteed to be unique, this function has to be
93  * a bit more sophisticated in what it does.
94  *
95  * If ids is NULL or max_ids == 0, it will return the count of the ids
96  * associated with name in the database.
97  *
98  * If an ids array is available, it returns two pieces of data - the id array
99  * of length max_ids (defined by the caller) will hold up to max_ids material
100  * IDs that have the specified name. In this mode, the return code will either
101  * be the number of IDs written to ids (if positive) or the number of
102  * additional ids found that would not fit in the ids array (if negative).
103  */
104 ANALYZE_EXPORT extern long int analyze_densities_id(long int *ids, long int max_ids, struct analyze_densities *a, const char *name);
105 
106 /* Note: to use a name for density lookup, supply one of the outputs of
107  * analyze_densities_id to this function.
108  *
109  * Density is returned in g/mm^3 */
110 ANALYZE_EXPORT extern fastf_t analyze_densities_density(struct analyze_densities *a, long int id);
111 
112 /* Provide a means to iterate over all defined densities. To get the lowest valid id,
113  * supply -1 to curr_id. Given a valid id, supply it to curr_id to get the next highest
114  * id. When there isn't a valid next id, -1 is returned. To count the number of density
115  * definitions active, do the following:
116  *
117  * long int curr_id = -1;
118  * long int dcnt = 0;
119  * while ((curr_id = analyze_densities_next(a, curr_id)) != -1) dcnt++;
120  *
121  */
122 ANALYZE_EXPORT extern long int analyze_densities_next(struct analyze_densities *a, long int curr_id);
123 
124 __END_DECLS
125 
126 #endif /* ANALYZE_DENSITY_H */
127 
128 /** @} */
129 
130 /*
131  * Local Variables:
132  * tab-width: 8
133  * mode: C
134  * indent-tabs-mode: t
135  * c-file-style: "stroustrup"
136  * End:
137  * ex: shiftwidth=4 tabstop=8
138  */
Header file for the BRL-CAD common definitions.
void analyze_densities_destroy(struct analyze_densities *a)
long int analyze_densities_next(struct analyze_densities *a, long int curr_id)
long int analyze_densities_write(char **buff, struct analyze_densities *a)
int analyze_densities_load(struct analyze_densities *a, const char *buff, struct bu_vls *msgs, int *ecnt)
int analyze_densities_create(struct analyze_densities **a)
int analyze_densities_set(struct analyze_densities *a, long int id, fastf_t density, const char *name, struct bu_vls *msgs)
void analyze_densities_clear(struct analyze_densities *a)
int analyze_densities_init(struct analyze_densities *a)
char * analyze_densities_name(struct analyze_densities *a, long int id)
long int analyze_densities_id(long int *ids, long int max_ids, struct analyze_densities *a, const char *name)
fastf_t analyze_densities_density(struct analyze_densities *a, long int id)
double fastf_t
fastest 64-bit (or larger) floating point type
Definition: vmath.h:334
struct analyze_densities_impl * i
Definition: density.h:58
Definition: vls.h:53
Definition: density.h:44
uint32_t magic
Definition: density.h:45
char * name
Definition: density.h:47
double grams_per_cu_mm
Definition: density.h:46
fundamental vector, matrix, quaternion math macros