Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Material Object Representation #7

Merged
merged 21 commits into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
4a47fc4
added material objects and db I/O functions
treydinges Sep 29, 2021
25b05cd
Merge branch 'main' of github.com:BRL-CAD/brlcad into materials
treydinges Oct 2, 2021
fb5bfe4
added basic material object implementation
treydinges Oct 3, 2021
389b2da
working material object implementation - incomplete property fields
treydinges Oct 4, 2021
1e405db
Merge branch 'main' of github.com:treydinges/brlcad into materials
treydinges Oct 4, 2021
bcea23c
Name for the material is now picked up from the in command 'name'field
treydinges Oct 12, 2021
cf8b083
Add AVS' for materials (WIP).
cdconn00 Oct 14, 2021
448ad14
Merge branch 'materials' of https://github.com/treydinges/brlcad into…
cdconn00 Oct 14, 2021
5432f24
attempting to parse material avs stores
treydinges Oct 15, 2021
39d30a7
Create gltf_read.cpp
volivarez60 Oct 19, 2021
1e50b5c
Material object with AVS store import and export
treydinges Oct 19, 2021
574ee71
Completed AVS store implementation with in command
treydinges Oct 19, 2021
04e8548
mk_material implementation
treydinges Oct 19, 2021
cf4c0b8
Revert "Create gltf_read.cpp"
treydinges Oct 20, 2021
8c4fac5
Merge branch 'BRL-CAD:main' into main
treydinges Oct 20, 2021
60ac20c
typein command updated for material objects
treydinges Oct 26, 2021
561377c
Memory leaks??
treydinges Oct 26, 2021
823a70b
Material object representation ready for main
treydinges Oct 26, 2021
8e422a8
Merge pull request #1 from treydinges/materials
treydinges Oct 28, 2021
3e220cc
fixes for material branch code style/implementation
treydinges Nov 11, 2021
9527359
Merge pull request #2 from treydinges/materials-hotfix
treydinges Nov 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
227 changes: 222 additions & 5 deletions src/libged/typein/typein.c
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,21 @@ static const char *p_script[] = {
"Enter the script type: "
};

/**
* TODO:
* add support
*/
static const char *p_material[] = {
"Enter the material name: ",
"Enter the parent material name: ",
"Enter the material source: ",
"Enter key value pairs for the following properties as follows:\n \
\tPhysical properties (end or skip with .)\n\
\tMechanical properties (end or skip with .)\n\
\tOptical properties (end or skip with .)\n\
\tThermal properties (end or skip with .)\nExample: key val key val . key val . . key val .\n"
};

/**
* helper function that infers a boolean value from a given string
* returning 0 or 1 for false and true respectively.
Expand Down Expand Up @@ -1504,6 +1519,192 @@ sph_in(struct ged *gedp, const char **cmd_argvs, struct rt_db_internal *intern,
return GED_OK;
}

static int
material_in(struct ged *gedp, int argc, const char **cmd_argvs, struct rt_db_internal *intern)
{
struct rt_material_internal *material_ip;

intern->idb_major_type = DB5_MAJORTYPE_BRLCAD;
intern->idb_minor_type = DB5_MINORTYPE_BRLCAD_MATERIAL;
intern->idb_meth = &OBJ[ID_MATERIAL];
BU_ALLOC(intern->idb_ptr, struct rt_material_internal);

material_ip = (struct rt_material_internal *)intern->idb_ptr;
material_ip->magic = RT_MATERIAL_MAGIC;

// name, parent, and source
bu_vls_init(&material_ip->name);
bu_vls_strcpy(&material_ip->name, cmd_argvs[3]);

bu_vls_init(&material_ip->parent);
bu_vls_strcpy(&material_ip->parent, cmd_argvs[4]);

bu_vls_init(&material_ip->source);
bu_vls_strcpy(&material_ip->source, cmd_argvs[5]);

// Intialize AVS stores
bu_avs_init_empty(&material_ip->physicalProperties);
bu_avs_init_empty(&material_ip->mechanicalProperties);
bu_avs_init_empty(&material_ip->opticalProperties);
bu_avs_init_empty(&material_ip->thermalProperties);

if (argc % 2 != 0) {
bu_vls_printf(gedp->ged_result_str, "ERROR, key value pairs entered incorrectly!\n");
return GED_ERROR;
}

int arg_idx = 6;
int arg_ptr = 7;
while (1) {
if (argc < arg_ptr) {
bu_vls_printf(gedp->ged_result_str, "ERROR, not enough arguments!\n");
return GED_ERROR;
}

if (BU_STR_EQUAL(".", cmd_argvs[arg_idx]) && arg_ptr % 2 == 0) {
bu_vls_printf(gedp->ged_result_str, "ERROR, key value pairs entered incorrectly!\n");
return GED_ERROR;
}

if (BU_STR_EQUAL(".", cmd_argvs[arg_idx])) {
// increment counters to get key values in next loop
arg_idx += 1;
arg_ptr += 1;
break;
}

// have to check the next arg after we know it is not '.'
if (argc < arg_ptr + 1) {
bu_vls_printf(gedp->ged_result_str, "ERROR, not enough arguments!\n");
return GED_ERROR;
}

if (BU_STR_EQUAL(".", cmd_argvs[arg_idx + 1]) && (arg_ptr + 1) % 2 != 0) {
bu_vls_printf(gedp->ged_result_str, "ERROR, key value pairs entered incorrectly!\n");
return GED_ERROR;
}

// if we make it here we have a valid key value set for argv[arg_idx] and argv[arg_idx + 1]
(void)bu_avs_add(&material_ip->physicalProperties, cmd_argvs[arg_idx], cmd_argvs[arg_idx + 1]);

// increment the counters by two so we can get the next pair
arg_idx += 2;
arg_ptr += 2;
}

while (1) {
if (argc < arg_ptr) {
bu_vls_printf(gedp->ged_result_str, "ERROR, not enough arguments!\n");
return GED_ERROR;
}

if (BU_STR_EQUAL(".", cmd_argvs[arg_idx]) && arg_ptr % 2 != 0) {
bu_vls_printf(gedp->ged_result_str, "ERROR, key value pairs entered incorrectly!\n");
return GED_ERROR;
}

if (BU_STR_EQUAL(".", cmd_argvs[arg_idx])) {
// increment counters to get key values in next loop
arg_idx += 1;
arg_ptr += 1;
break;
}

// have to check the next arg after we know it is not '.'
if (argc < arg_ptr + 1) {
bu_vls_printf(gedp->ged_result_str, "ERROR, not enough arguments!\n");
return GED_ERROR;
}

if (BU_STR_EQUAL(".", cmd_argvs[arg_idx + 1]) && (arg_ptr + 1) % 2 == 0) {
bu_vls_printf(gedp->ged_result_str, "ERROR, key value pairs entered incorrectly!\n");
return GED_ERROR;
}

// if we make it here we have a valid key value set for argv[arg_idx] and argv[arg_idx + 1]
(void)bu_avs_add(&material_ip->mechanicalProperties, cmd_argvs[arg_idx], cmd_argvs[arg_idx + 1]);

// increment the counters by two so we can get the next pair
arg_idx += 2;
arg_ptr += 2;
}

while (1) {
if (argc < arg_ptr) {
bu_vls_printf(gedp->ged_result_str, "ERROR, not enough arguments!\n");
return GED_ERROR;
}

if (BU_STR_EQUAL(".", cmd_argvs[arg_idx]) && arg_ptr % 2 == 0) {
bu_vls_printf(gedp->ged_result_str, "ERROR, key value pairs entered incorrectly!\n");
return GED_ERROR;
}

if (BU_STR_EQUAL(".", cmd_argvs[arg_idx])) {
// increment counters to get key values in next loop
arg_idx += 1;
arg_ptr += 1;
break;
}

// have to check the next arg after we know it is not '.'
if (argc < arg_ptr + 1) {
bu_vls_printf(gedp->ged_result_str, "ERROR, not enough arguments!\n");
return GED_ERROR;
}

if (BU_STR_EQUAL(".", cmd_argvs[arg_idx + 1]) && (arg_ptr + 1) % 2 != 0) {
bu_vls_printf(gedp->ged_result_str, "ERROR, key value pairs entered incorrectly!\n");
return GED_ERROR;
}

// if we make it here we have a valid key value set for argv[arg_idx] and argv[arg_idx + 1]
(void)bu_avs_add(&material_ip->opticalProperties, cmd_argvs[arg_idx], cmd_argvs[arg_idx + 1]);

// increment the counters by two so we can get the next pair
arg_idx += 2;
arg_ptr += 2;
}

while (1) {
if (argc < arg_ptr) {
bu_vls_printf(gedp->ged_result_str, "ERROR, not enough arguments!\n");
return GED_ERROR;
}

if (BU_STR_EQUAL(".", cmd_argvs[arg_idx]) && arg_ptr % 2 != 0) {
bu_vls_printf(gedp->ged_result_str, "ERROR, key value pairs entered incorrectly!\n");
return GED_ERROR;
}

if (BU_STR_EQUAL(".", cmd_argvs[arg_idx])) {
arg_idx += 1;
arg_ptr += 1;
break;
}

// have to check the next arg after we know it is not '.'
if (argc < arg_ptr + 1) {
bu_vls_printf(gedp->ged_result_str, "ERROR, not enough arguments!\n");
return GED_ERROR;
}

if (BU_STR_EQUAL(".", cmd_argvs[arg_idx + 1]) && (arg_ptr + 1) % 2 == 0) {
bu_vls_printf(gedp->ged_result_str, "ERROR, key value pairs entered incorrectly!\n");
return GED_ERROR;
}

// if we make it here we have a valid key value set for argv[arg_idx] and argv[arg_idx + 1]
(void)bu_avs_add(&material_ip->thermalProperties, cmd_argvs[arg_idx], cmd_argvs[arg_idx + 1]);

// increment the counters by two so we can get the next pair
arg_idx += 2;
arg_ptr += 2;
}

return GED_OK;
}


/*
* reads ell parameters from keyboard
Expand Down Expand Up @@ -3149,6 +3350,7 @@ ged_in_core(struct ged *gedp, int argc, const char *argv[])
int nvals;
int (*fn_in)(struct ged *, const char **, struct rt_db_internal *) = NULL;
int (*fn_in_2)(struct ged *, const char **, struct rt_db_internal *, const char *) = NULL;
int (*fn_in_3)(struct ged *, int, const char **, struct rt_db_internal *) = NULL;

GED_CHECK_DATABASE_OPEN(gedp, GED_ERROR);
GED_CHECK_READ_ONLY(gedp, GED_ERROR);
Expand All @@ -3157,9 +3359,9 @@ ged_in_core(struct ged *gedp, int argc, const char *argv[])
/* initialize result */
bu_vls_trunc(gedp->ged_result_str, 0);

/* Get the name of the solid to be created */
/* Get the name of the object to be created */
if (argc < 2) {
bu_vls_printf(gedp->ged_result_str, "Enter name of solid: ");
bu_vls_printf(gedp->ged_result_str, "Enter name of object: ");
return GED_MORE;
}
if (db_lookup(gedp->dbip, argv[1], LOOKUP_QUIET) != RT_DIR_NULL) {
Expand All @@ -3170,12 +3372,12 @@ ged_in_core(struct ged *gedp, int argc, const char *argv[])
bu_vls_printf(gedp->ged_result_str, "%s: ERROR, v4 names are limited to %d characters\n", argv[0], NAMESIZE);
return GED_ERROR;
}
/* Save the solid name */
/* Save the object name */
name = (char *)argv[1];

/* Get the solid type to be created and make it */
/* Get the object type to be created and make it */
if (argc < 3) {
bu_vls_printf(gedp->ged_result_str, "Enter solid type: ");
bu_vls_printf(gedp->ged_result_str, "Enter object type: ");
return GED_MORE;
}

Expand Down Expand Up @@ -3414,6 +3616,10 @@ ged_in_core(struct ged *gedp, int argc, const char *argv[])
nvals = 1;
menu = p_script;
fn_in = script_in;
} else if (BU_STR_EQUAL(argv[2], "material")) {
nvals = 7;
menu = p_material;
fn_in_3 = material_in;
} else if (BU_STR_EQUAL(argv[2], "pnts")) {
switch (pnts_in(gedp, argc, argv, &internal, p_pnts)) {
case GED_ERROR:
Expand Down Expand Up @@ -3476,6 +3682,17 @@ ged_in_core(struct ged *gedp, int argc, const char *argv[])
}
return GED_ERROR;
}
} else if (fn_in_3) {
if (fn_in_3(gedp, argc, argv, &internal) != 0) {
bu_vls_printf(gedp->ged_result_str, "%s: ERROR %s not made!\n", argv[0], argv[2]);
if (internal.idb_ptr) {
/* a few input functions do not use the internal pointer
* only free it, if it has been used
*/
rt_db_free_internal(&internal);
}
return GED_ERROR;
}
} else {
bu_vls_printf(gedp->ged_result_str, "%s: ERROR %s not made!\n", argv[0], argv[2]);
return GED_ERROR;
Expand Down
1 change: 1 addition & 0 deletions src/librt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ set(LIBRT_SOURCES
comb/comb_brep.cpp
comb/comb_mirror.c
comb/db_comb.c
material/material.c
constraint.c
cut.c
cut_hlbvh.c
Expand Down
Loading