Skip to content

Commit

Permalink
Merge pull request #1 from treydinges/materials
Browse files Browse the repository at this point in the history
Material object representation with multiple AVS sets for different types of material properties. There is a parent field within the object struct but there is currently no inheritance. There is also an update for the typein command.
  • Loading branch information
treydinges authored Oct 28, 2021
2 parents 8c4fac5 + 823a70b commit 8e422a8
Show file tree
Hide file tree
Showing 14 changed files with 739 additions and 7 deletions.
7 changes: 7 additions & 0 deletions include/bu/avs.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@ BU_EXPORT extern void bu_avs_merge(struct bu_attribute_value_set *dest,
BU_EXPORT extern const char *bu_avs_get(const struct bu_attribute_value_set *avp,
const char *attribute);

/**
* gets all attributes in an attribute set in "name = value" form,
* using the provided title.
*/
BU_EXPORT extern const char *bu_avs_get_all(const struct bu_attribute_value_set *avp,
const char *title);

/**
* Remove all occurrences of an attribute from the provided attribute
* set.
Expand Down
1 change: 1 addition & 0 deletions include/bu/magic.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ __BEGIN_DECLS
#define RT_AP_MAGIC 0x4170706c /**< Appl */
#define RT_COMB_MAGIC 0x436f6d49 /**< ComI */
#define RT_CONSTRAINT_MAGIC 0x7063696d /**< pcim */
#define RT_MATERIAL_MAGIC 0x54414d55 /**< TAMU */
#define RT_CTS_MAGIC 0x98989123 /**< ???\# */
#define RT_DB_TRAVERSE_MAGIC 0x64627472 /**< dbtr */
#define RT_DBTS_MAGIC 0x64627473 /**< dbts */
Expand Down
1 change: 1 addition & 0 deletions include/rt/db5.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ struct db5_ondisk_header {
#define DB5_MINORTYPE_BRLCAD_HRT 43
#define DB5_MINORTYPE_BRLCAD_DATUM 44
#define DB5_MINORTYPE_BRLCAD_SCRIPT 45
#define DB5_MINORTYPE_BRLCAD_MATERIAL 46

/* Uniform-array binary */
#define DB5_MINORTYPE_BINU_WID_MASK 0x30
Expand Down
5 changes: 3 additions & 2 deletions include/rt/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
* NOTE: must update the non-geometric object id's below the
* ADD_BELOW_HERE marker
*/
#define ID_MAX_SOLID 46 /**< @brief Maximum defined ID_xxx for solids */
#define ID_MAX_SOLID 47 /**< @brief Maximum defined ID_xxx for solids */

/*
* Non-geometric objects
Expand All @@ -119,6 +119,7 @@
#define ID_BINUNIF 33 /**< @brief Uniform-array binary */
#define ID_UNUSED2 34 /**< @brief UNUSED (placeholder) */
#define ID_CONSTRAINT 39 /**< @brief Constraint object */
#define ID_MATERIAL 46 /**< @brief Material object */

/* - ADD_BELOW_HERE - */
/* superellipsoid should be 31, but is not v5 compatible */
Expand All @@ -132,7 +133,7 @@
#define ID_HRT 43 /**< @brief Heart */
#define ID_DATUM 44 /**< @brief Datum references */
#define ID_SCRIPT 45 /**< @brief Script */
#define ID_MAXIMUM 46 /**< @brief Maximum defined ID_xxx value */
#define ID_MAXIMUM 47 /**< @brief Maximum defined ID_xxx value */

/**
* DEPRECATED: external applications should use other LIBRT API to
Expand Down
17 changes: 17 additions & 0 deletions include/rt/nongeom.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,23 @@ struct rt_constraint_internal {
#define RT_CHECK_CONSTRAINT(_p) BU_CKMAG(_p, RT_CONSTRAINT_MAGIC, "rt_constraint_internal")
#define RT_CK_CONSTRAINT(_p) RT_CHECK_CONSTRAINT(_p)

/**
* In-memory format for database "material" record
*/
struct rt_material_internal {
uint32_t magic;
struct bu_vls name;
struct bu_vls parent;
struct bu_vls source;

struct bu_attribute_value_set physicalProperties;
struct bu_attribute_value_set mechanicalProperties;
struct bu_attribute_value_set opticalProperties;
struct bu_attribute_value_set thermalProperties;
};

#define RT_CHECK_MATERIAL(_p) BU_CKMAG(_p, RT_MATERIAL_MAGIC, "rt_material_internal")
#define RT_CK_MATERIAL(_p) RT_CHECK_MATERIAL(_p)

__END_DECLS

Expand Down
11 changes: 11 additions & 0 deletions include/wdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,17 @@ WDB_EXPORT extern int mk_ars(struct rt_wdb *fp, const char *name, size_t ncurves
WDB_EXPORT extern int mk_constraint(struct rt_wdb *wdbp, const char *name, const char *expr);


WDB_EXPORT extern int mk_material(struct rt_wdb *wdbp,
const char *db_name,
const char *name,
const char *parent,
const char *source,
struct bu_attribute_value_set *physicalProperties,
struct bu_attribute_value_set *mechanicalProperties,
struct bu_attribute_value_set *opticalProperties,
struct bu_attribute_value_set *thermalProperties);


/* FIXME: are the variable-sized types actually necessary? should be
* able to rely on stdint types. the file+nonfile duplication seems
* silly too.
Expand Down
31 changes: 31 additions & 0 deletions src/libbu/avs.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,37 @@ bu_avs_get(const struct bu_attribute_value_set *avsp, const char *name)
return NULL;
}

const char *
bu_avs_get_all(const struct bu_attribute_value_set *avsp, const char *title) {
BU_CK_AVS(avsp);

struct bu_attribute_value_pair *avpp;
size_t i;
struct bu_vls str = BU_VLS_INIT_ZERO;

if (title) {
bu_vls_strcat(&str, title);
bu_vls_strcat(&str, "=\"");
}

avpp = avsp->avp;
for (i = 0; i < avsp->count; i++, avpp++) {
bu_vls_strcat(&str, "\t\t(");
bu_vls_strcat(&str, avpp->name ? avpp->name : "NULL");
bu_vls_strcat(&str, " : ");
bu_vls_strcat(&str, avpp->value ? avpp->value : "NULL");
bu_vls_strcat(&str, ")\n");
}

if (title) {
bu_vls_strcat(&str, "\"");
}

const char * attributes = bu_vls_strgrab(&str);

return attributes;
}


int
bu_avs_remove(struct bu_attribute_value_set *avsp, const char *name)
Expand Down
2 changes: 2 additions & 0 deletions src/libbu/magic.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ bu_identify_magic(register uint32_t magic)
return "librt rt_comb_internal";
case RT_CONSTRAINT_MAGIC:
return "librt rt_constraint_internal";
case RT_MATERIAL_MAGIC:
return "librt rt_material_internal";
case RT_CTS_MAGIC:
return "librt combined_tree_state";
case RT_DB_TRAVERSE_MAGIC:
Expand Down
Loading

0 comments on commit 8e422a8

Please sign in to comment.