Skip to content

Commit

Permalink
Add DATUM mat application method
Browse files Browse the repository at this point in the history
  • Loading branch information
starseeker committed Jan 31, 2025
1 parent e537e6c commit d32f787
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
37 changes: 34 additions & 3 deletions src/librt/primitives/datum/datum.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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];

Expand All @@ -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);
}


Expand Down
2 changes: 1 addition & 1 deletion src/librt/primitives/table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
},

Expand Down

0 comments on commit d32f787

Please sign in to comment.