diff --git a/src/librt/primitives/datum/datum.c b/src/librt/primitives/datum/datum.c index 2edf9d5588..2f836ee197 100644 --- a/src/librt/primitives/datum/datum.c +++ b/src/librt/primitives/datum/datum.c @@ -368,6 +368,36 @@ rt_datum_export5(struct bu_external *ep, const struct rt_db_internal *ip, double return 0; } +int +rt_datum_mat(struct rt_db_internal *rop, const mat_t mat, const struct rt_db_internal *ip) +{ + if (!rop || !mat) + return BRLCAD_OK; + + // For the moment, we only support applying a mat to a datum in place - the + // input and output must be the same. + if (ip && rop != ip) { + bu_log("rt_datum_mat: alignment of data between multiple datums is unsupported - input datum must be the same as the output datum.\n"); + return BRLCAD_ERROR; + } + + struct rt_datum_internal *datum_ip = (struct rt_datum_internal *)rop->idb_ptr; + RT_DATUM_CK_MAGIC(datum_ip); + + vect_t v; + while (datum_ip) { + VMOVE(v, datum_ip->pnt); + MAT4X3PNT(datum_ip->pnt, mat, v); + if (MAGNITUDE(datum_ip->dir) > 0.0) { + VMOVE(v, datum_ip->dir); + MAT4X3PNT(datum_ip->dir , mat, v); + } + datum_ip = datum_ip->next; + } + + return BRLCAD_OK; +} + /** * Import datums from the database format to the internal format. @@ -412,9 +442,9 @@ rt_datum_import5(struct rt_db_internal *ip, const struct bu_external *ep, const first = datum_ip; if (vals >= ELEMENTS_PER_POINT) - MAT4X3PNT(datum_ip->pnt, mat, vec); + VMOVE(datum_ip->pnt, vec); if (vals >= ELEMENTS_PER_POINT + ELEMENTS_PER_VECT) - MAT4X3VEC(datum_ip->dir, mat, vec+3); + VMOVE(datum_ip->dir, vec+3); if (vals == MAX_VALS) datum_ip->w = vec[6]; @@ -430,7 +460,8 @@ rt_datum_import5(struct rt_db_internal *ip, const struct bu_external *ep, const ip->idb_type = ID_DATUM; ip->idb_major_type = DB5_MAJORTYPE_BRLCAD; - return 0; /* OK */ + /* Apply transform */ + return rt_datum_mat(ip, mat, ip); } diff --git a/src/librt/primitives/table.cpp b/src/librt/primitives/table.cpp index 8002662eb9..fba1a1b16e 100644 --- a/src/librt/primitives/table.cpp +++ b/src/librt/primitives/table.cpp @@ -2418,7 +2418,7 @@ const struct rt_functab OBJ[] = { NULL, /* serialize */ NULL, /* label */ RTFUNCTAB_FUNC_KEYPOINT_CAST(rt_datum_keypoint), /* keypoint */ - NULL, /* mat */ + RTFUNCTAB_FUNC_MAT_CAST(rt_datum_mat), NULL /* perturb */ },