Guest User

Pulling combination matrices

a guest
Aug 20th, 2013
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.97 KB | None | 0 0
  1. **
  2.  * This restores the matrix transformation at a combination by taking leaf matrix tranformations,    Innverting
  3.  * and storing the changes at the combinations.
  4.  */
  5. static void
  6. comb_mat_restore(struct db_i *dbip, struct rt_comb_internal *UNUSED(comb), union tree *comb_leaf, genptr_t user_ptr1, genptr_t (user_ptr2), genptr_t UNUSED(user_ptr3), genptr_t UNUSED(user_ptr4))
  7. {
  8.     struct directory *dp;
  9.     struct bu_vls *msg = (struct bu_vls *)user_ptr1;
  10.     mat_t inv_mat;
  11.     matp_t mat = (matp_t)user_ptr2;
  12.  
  13.     RT_CK_DBI(dbip);
  14.     RT_CK_TREE(comb_leaf);
  15.  
  16.     if ((dp = db_lookup(dbip, comb_leaf->tr_l.tl_name, LOOKUP_NOISY)) == RT_DIR_NULL)
  17.     return;
  18.  
  19.     /* invert the matrix transformation of the leaf and store new matrix  at comb */
  20.     bn_mat_inverse(inv_mat, &mat);
  21.    
  22.     /* multiply inverse and store at combination */
  23.     bn_mat_mul2(inv_mat,comb_leaf->tr_l.tl_mat);
  24.  
  25.     MAT_COPY(&mat,comb_leaf->tr_l.tl_mat);
  26.  
  27.     comb_restore(dp, dbip, mat);
  28. }
  29.  
  30.  
  31. /**
  32.  *@brief
  33.  *comb_restore(): This routine enters a comb restoring the matrix transformation at the combination
  34.  *                calls and calls do_comb_restore() which updates current matrix transformation and moves up tree.
  35.  */
  36. void
  37. comb_restore(struct dbi *dbip,
  38.              struct directory *dp,  
  39.              (matp_t mp)
  40. {
  41.     struct rt_db_internal intern;
  42.     struct rt_comb_internal *comb;
  43.    
  44.     if (dp->d_flags & RT_DIR_SOLID)
  45.         return;
  46.     if (rt_db_get_internal(&intern, dp, dbip, (fastf_t *)NULL, &rt_uniresource) < 0) {
  47.     bu_vls_printf(msg, "Database read error, aborting\n");
  48.     return;
  49.     }
  50.     comb = (struct rt_comb_internal *)intern.idb_ptr;
  51.    
  52.     if (comb->tree) {
  53.     db_tree_funcleaf(dbip, comb, comb->tree, comb_mat_restore,
  54.              (genptr_t)mp, (genptr_t)NULL, (genptr_t)NULL);
  55.     if (rt_db_put_internal(dp, dbip, &intern, &rt_uniresource) < 0) {
  56.         bu_vls_printf(msg, "Cannot write modified combination (%s) to database\n", dp->d_namep);
  57.         return;
  58.     }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment