Skip to content

Commit

Permalink
Split TOR, TGC and ELL mat applications into separate methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
starseeker committed Jan 29, 2025
1 parent dab4cc1 commit d5b2d02
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 30 deletions.
36 changes: 30 additions & 6 deletions src/librt/primitives/ell/ell.c
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,30 @@ rt_ell_export4(struct bu_external *ep, const struct rt_db_internal *ip, double l
return 0;
}

int
rt_ell_mat(struct rt_db_internal *rop, const mat_t mat, const struct rt_db_internal *ip)
{
if (!rop || !ip || !mat)
return BRLCAD_OK;

struct rt_ell_internal *tip = (struct rt_ell_internal *)ip->idb_ptr;
RT_ELL_CK_MAGIC(tip);
struct rt_ell_internal *top = (struct rt_ell_internal *)rop->idb_ptr;
RT_ELL_CK_MAGIC(top);

vect_t v, a, b, c;
VMOVE(v, tip->v);
VMOVE(a, tip->a);
VMOVE(b, tip->b);
VMOVE(c, tip->c);

MAT4X3PNT(top->v, mat, v);
MAT4X3VEC(top->a, mat, a);
MAT4X3VEC(top->b, mat, b);
MAT4X3VEC(top->c, mat, c);

return BRLCAD_OK;
}

/**
* Import an ellipsoid/sphere from the database format to the internal
Expand Down Expand Up @@ -1372,14 +1396,14 @@ rt_ell_import5(struct rt_db_internal *ip, const struct bu_external *ep, register
/* Convert from database (network) to internal (host) format */
bu_cv_ntohd((unsigned char *)vec, ep->ext_buf, ELEMENTS_PER_VECT*4);

VMOVE(eip->v, &vec[0*ELEMENTS_PER_VECT]);
VMOVE(eip->a, &vec[1*ELEMENTS_PER_VECT]);
VMOVE(eip->b, &vec[2*ELEMENTS_PER_VECT]);
VMOVE(eip->c, &vec[3*ELEMENTS_PER_VECT]);

/* Apply modeling transformations */
if (mat == NULL) mat = bn_mat_identity;
MAT4X3PNT(eip->v, mat, &vec[0*ELEMENTS_PER_VECT]);
MAT4X3VEC(eip->a, mat, &vec[1*ELEMENTS_PER_VECT]);
MAT4X3VEC(eip->b, mat, &vec[2*ELEMENTS_PER_VECT]);
MAT4X3VEC(eip->c, mat, &vec[3*ELEMENTS_PER_VECT]);

return 0; /* OK */
return rt_ell_mat(ip, mat, ip);
}


Expand Down
6 changes: 3 additions & 3 deletions src/librt/primitives/table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ const struct rt_functab OBJ[] = {
NULL, /* serialize */
RTFUNCTAB_FUNC_LABELS_CAST(rt_tor_labels), /* label */
RTFUNCTAB_FUNC_KEYPOINT_CAST(rt_tor_keypoint), /* keypoint */
NULL, /* mat */
RTFUNCTAB_FUNC_MAT_CAST(rt_tor_mat),
NULL /* perturb */
},

Expand Down Expand Up @@ -312,7 +312,7 @@ const struct rt_functab OBJ[] = {
NULL, /* serialize */
RTFUNCTAB_FUNC_LABELS_CAST(rt_tgc_labels), /* label */
RTFUNCTAB_FUNC_KEYPOINT_CAST(rt_tgc_keypoint), /* keypoint */
NULL, /* mat */
RTFUNCTAB_FUNC_MAT_CAST(rt_tgc_mat),
RTFUNCTAB_FUNC_PERTURB_CAST(rt_tgc_perturb) /* perturb */
},

Expand Down Expand Up @@ -362,7 +362,7 @@ const struct rt_functab OBJ[] = {
NULL, /* serialize */
RTFUNCTAB_FUNC_LABELS_CAST(rt_ell_labels), /* label */
RTFUNCTAB_FUNC_KEYPOINT_CAST(rt_ell_keypoint), /* keypoint */
NULL, /* mat */
RTFUNCTAB_FUNC_MAT_CAST(rt_ell_mat),
NULL /* perturb */
},

Expand Down
43 changes: 37 additions & 6 deletions src/librt/primitives/tgc/tgc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1674,6 +1674,35 @@ rt_tgc_export4(struct bu_external *ep, const struct rt_db_internal *ip, double l
return 0;
}

int
rt_tgc_mat(struct rt_db_internal *rop, const mat_t mat, const struct rt_db_internal *ip)
{
if (!rop || !ip || !mat)
return BRLCAD_OK;

struct rt_tgc_internal *tip = (struct rt_tgc_internal *)ip->idb_ptr;
RT_TGC_CK_MAGIC(tip);
struct rt_tgc_internal *top = (struct rt_tgc_internal *)rop->idb_ptr;
RT_TGC_CK_MAGIC(top);

vect_t v, h, a, b, c, d;
VMOVE(v, tip->v);
VMOVE(h, tip->h);
VMOVE(a, tip->a);
VMOVE(b, tip->b);
VMOVE(c, tip->c);
VMOVE(d, tip->d);

MAT4X3PNT(top->v, mat, v);
MAT4X3VEC(top->h, mat, h);
MAT4X3VEC(top->a, mat, a);
MAT4X3VEC(top->b, mat, b);
MAT4X3VEC(top->c, mat, c);
MAT4X3VEC(top->d, mat, d);

return BRLCAD_OK;
}


/**
* Import a TGC from the database format to the internal format.
Expand Down Expand Up @@ -1704,14 +1733,16 @@ rt_tgc_import5(struct rt_db_internal *ip, const struct bu_external *ep, register
/* Convert from database (network) to internal (host) format */
bu_cv_ntohd((unsigned char *)vec, ep->ext_buf, ELEMENTS_PER_VECT*6);

VMOVE(tip->v, &vec[0*ELEMENTS_PER_VECT]);
VMOVE(tip->h, &vec[1*ELEMENTS_PER_VECT]);
VMOVE(tip->a, &vec[2*ELEMENTS_PER_VECT]);
VMOVE(tip->b, &vec[3*ELEMENTS_PER_VECT]);
VMOVE(tip->c, &vec[4*ELEMENTS_PER_VECT]);
VMOVE(tip->d, &vec[5*ELEMENTS_PER_VECT]);

/* Apply modeling transformations */
if (mat == NULL) mat = bn_mat_identity;
MAT4X3PNT(tip->v, mat, &vec[0*ELEMENTS_PER_VECT]);
MAT4X3VEC(tip->h, mat, &vec[1*ELEMENTS_PER_VECT]);
MAT4X3VEC(tip->a, mat, &vec[2*ELEMENTS_PER_VECT]);
MAT4X3VEC(tip->b, mat, &vec[3*ELEMENTS_PER_VECT]);
MAT4X3VEC(tip->c, mat, &vec[4*ELEMENTS_PER_VECT]);
MAT4X3VEC(tip->d, mat, &vec[5*ELEMENTS_PER_VECT]);
rt_tgc_mat(ip, mat, ip);

return 0; /* OK */
}
Expand Down
60 changes: 45 additions & 15 deletions src/librt/primitives/tor/tor.c
Original file line number Diff line number Diff line change
Expand Up @@ -1630,6 +1630,44 @@ rt_tor_export4(struct bu_external *ep, const struct rt_db_internal *ip, double l
return 0;
}

int
rt_tor_mat(struct rt_db_internal *rop, const mat_t mat, const struct rt_db_internal *ip)
{
if (!rop || !ip || !mat)
return BRLCAD_OK;

struct rt_tor_internal *tip = (struct rt_tor_internal *)ip->idb_ptr;
RT_TOR_CK_MAGIC(tip);
struct rt_tor_internal *top = (struct rt_tor_internal *)rop->idb_ptr;
RT_TOR_CK_MAGIC(top);

double r_a, r_h;
vect_t v, h;
VMOVE(v, tip->v);
VMOVE(h, tip->h);
r_a = tip->r_a;
r_h = tip->r_h;

/* Apply modeling transformations */
MAT4X3PNT(top->v, mat, v);
MAT4X3VEC(top->h, mat, h);
VUNITIZE(top->h); /* just to be sure */

top->r_a = r_a / mat[15];
top->r_h = r_h / mat[15];

/* Prepare the extra information */
top->r_b = top->r_a;

/* Calculate two mutually perpendicular vectors, perpendicular to N */
bn_vec_ortho(top->a, top->h); /* a has unit length */
VCROSS(top->b, top->h, top->a); /* |A| = |H| = 1, so |B|=1 */

VSCALE(top->a, top->a, top->r_a);
VSCALE(top->b, top->b, top->r_b);

return BRLCAD_OK;
}

/**
* Taken from the database record:
Expand Down Expand Up @@ -1678,23 +1716,15 @@ rt_tor_import5(struct rt_db_internal *ip, const struct bu_external *ep, register

bu_cv_ntohd((unsigned char *)&rec, ep->ext_buf, 2*3+2);

/* Apply modeling transformations */
MAT4X3PNT(tip->v, mat, rec.v);
MAT4X3VEC(tip->h, mat, rec.h);
VUNITIZE(tip->h); /* just to be sure */
/* Set up initial data */
VMOVE(tip->v, rec.v);
VMOVE(tip->h, rec.h);
tip->r_a = rec.ra;
tip->r_h = rec.rh;

tip->r_a = rec.ra / mat[15];
tip->r_h = rec.rh / mat[15];

/* Prepare the extra information */
tip->r_b = tip->r_a;

/* Calculate two mutually perpendicular vectors, perpendicular to N */
bn_vec_ortho(tip->a, tip->h); /* a has unit length */
VCROSS(tip->b, tip->h, tip->a); /* |A| = |H| = 1, so |B|=1 */
/* Apply modeling transformations */
rt_tor_mat(ip, mat, ip);

VSCALE(tip->a, tip->a, tip->r_a);
VSCALE(tip->b, tip->b, tip->r_b);
return 0;
}

Expand Down

0 comments on commit d5b2d02

Please sign in to comment.