/** * R E C _ P R I N T */ void rt_rec_print(const struct soltab *stp) { const struct rec_specific *rec = (struct rec_specific *)stp->st_specific; VPRINT("V", rec->rec_V); VPRINT("Hunit", rec->rec_Hunit); bn_mat_print("S o R", rec->rec_SoR); bn_mat_print("invR o S", rec->rec_invRoS); }
/* * M A I N */ int main(int argc, char **argv) { FILE *fp=NULL; if ( !get_args( argc, argv ) ) { (void)fputs(usage, stderr); bu_exit (1, NULL); } if ( verbose ) { bn_mat_print("rmat", rmat); } if ( bu_optind < argc ) { while ( bu_optind < argc ) { if ( fp != NULL && fp != stdin ) fclose( fp ); if ( strcmp(argv[bu_optind], "-") == 0 ) fp = stdin; else if ( (fp = fopen(argv[bu_optind], "r")) == NULL ) { fprintf( stderr, "plrot: can't open \"%s\"\n", argv[bu_optind] ); continue; } dofile( fp ); bu_optind++; } } else { dofile( stdin ); } return 0; }
/* * T R E E T H E R M _ P R I N T */ HIDDEN void tthrm_print(register struct region *UNUSED(rp), genptr_t dp) { struct tthrm_specific *tthrm_sp = (struct tthrm_specific *)dp; bu_log("%s\n", tthrm_sp->tt_name); bn_mat_print("m_to_sh", tthrm_sp->tthrm_m_to_sh); }
/** * B N _ M A T _ I N V * * The matrix pointed at by "input" is inverted and stored in the area * pointed at by "output". * * Calls bu_bomb if matrix is singular. */ void bn_mat_inv(register mat_t output, const mat_t input) { if (bn_mat_inverse(output, input) == 0) { bu_log("bn_mat_inv: error!"); bn_mat_print("singular matrix", input); bu_bomb("bn_mat_inv: singular matrix\n"); /* NOTREACHED */ } }
int main(int argc, char **argv) { FILE *fp=NULL; static char opts[] = "\ -x# -y# -z# Rotation about axis in degrees\n\ -X# -Y# -Z# Translation along axis\n\ -s# Scale factor\n\ -a# -e# Azimuth/Elevation from front view\n\ (usually first, in this order, implies -M)\n\ -g MGED front view to display coordinates (usually last)\n\ -M Autoscale space command like RT model RPP\n\ -m# Takes a 4X4 matrix as an argument\n\ -v Verbose\n\ -S# Space: takes a quoted string of six floats\n"; if (!get_args(argc, argv)) { fputs("Usage: plot3rot [options] [file1 ... fileN] > file.plot3\n", stderr); (void)fputs(opts, stderr); bu_exit (1, NULL); } if (verbose) { bn_mat_print("rmat", rmat); } if (bu_optind < argc) { while (bu_optind < argc) { if (fp != NULL && fp != stdin) fclose(fp); if (BU_STR_EQUAL(argv[bu_optind], "-")) fp = stdin; else if ((fp = fopen(argv[bu_optind], "r")) == NULL) { bu_log("plot3rot: can't open \"%s\"\n", argv[bu_optind]); continue; } dofile(fp); bu_optind++; } } else { dofile(stdin); } return 0; }
int mat_build(fastf_t *mat1, fastf_t *mat2, fastf_t *regismat) { vect_t adelta, bdelta; /* deltas for mod1 and mod2 */ vect_t delta; /* difference bet. mod1 and mod2 deltas */ fastf_t scale; /* At this point it is important to check that the rotation part * of the matices is within a certain tolerance: ie. that the * two images were raytraced from the same angle. No overlays will * be possible if they are not at the same rotation. */ /* Now record the deltas: the translation part of the matrix. */ VSET(adelta, mat1[MDX], mat1[MDY], mat1[MDZ]); VSET(bdelta, mat2[MDX], mat2[MDY], mat2[MDZ]); /* Take the difference between the deltas. Also scale the size * of the model (scale). These will be used to register two * pixel files later on. */ VSUB2(delta, adelta, bdelta); scale = mat1[15]/mat2[15]; VPRINT("delta", delta); fprintf(stderr, "scale: %.6f\n", scale); /* If the first log corresponds to a UNIX-Plot file, following * applies. Since UNIX-Plot files are in model coordinates, the * mod2view2 ("model2pix") is also the registration matrix. In * this case, pl-fb needs to learn that the UNIX-Plot file's space * runs from -1 -> 1 in x and y. This can be done by adding an * alternate space command in that program. Therefore the below * applies. * What if the first log corresponds to a hi-res pixel file to be * registered with a lo-res pixel file? Then the above calculated * deltas are used. This will be implemented later. */ MAT_COPY( regismat, mat2); bn_mat_print("regismat", regismat); return(1); /* OK */ }
int bn_mat_ck(const char *title, const mat_t m) { vect_t A, B, C; fastf_t fx, fy, fz; if (!m) { return 0; /* implies identity matrix */ } /* Validate that matrix preserves perpendicularity of axis by * checking that A.B == 0, B.C == 0, A.C == 0 XXX these vectors * should just be grabbed out of the matrix */ VMOVE(A, &m[0]); VMOVE(B, &m[4]); VMOVE(C, &m[8]); fx = VDOT(A, B); fy = VDOT(B, C); fz = VDOT(A, C); /* NOTE: this tolerance cannot be any more tight than 0.00001 due * to default calculation tolerancing used by models. Matrices * exported to disk outside of tolerance will fail import if * set too restrictive. */ if (!NEAR_ZERO(fx, 0.00001) || !NEAR_ZERO(fy, 0.00001) || !NEAR_ZERO(fz, 0.00001) || NEAR_ZERO(m[15], VDIVIDE_TOL)) { if (bu_debug & BU_DEBUG_MATH) { bu_log("bn_mat_ck(%s): bad matrix, does not preserve axis perpendicularity.\n X.Y=%g, Y.Z=%g, X.Z=%g, s=%g\n", title, fx, fy, fz, m[15]); bn_mat_print("bn_mat_ck() bad matrix", m); } if (bu_debug & (BU_DEBUG_MATH | BU_DEBUG_COREDUMP)) { bu_debug |= BU_DEBUG_COREDUMP; bu_bomb("bn_mat_ck() bad matrix\n"); } return -1; /* FAIL */ } return 0; /* OK */ }
void Do_subfigs() { int i, j; int entity_type; struct wmember head1; struct wmember *wmem; if (RT_G_DEBUG & DEBUG_MEM_FULL) bu_mem_barriercheck(); BU_LIST_INIT(&head1.l); for (i = 0; i < totentities; i++) { int subfigdef_de; int subfigdef_index; int no_of_members; int *members; char *name = NULL; struct wmember head2; double mat_scale[3]; int non_unit; if (dir[i]->type != 408) continue; if (RT_G_DEBUG & DEBUG_MEM_FULL) bu_mem_barriercheck(); if (dir[i]->param <= pstart) { bu_log("Illegal parameter pointer for entity D%07d (%s)\n" , dir[i]->direct, dir[i]->name); continue; } Readrec(dir[i]->param); Readint(&entity_type, ""); if (entity_type != 408) { bu_log("Expected Singular Subfigure Instance Entity, found %s\n", iges_type(entity_type)); continue; } Readint(&subfigdef_de, ""); subfigdef_index = (subfigdef_de - 1)/2; if (subfigdef_index >= totentities) { bu_log("Singular Subfigure Instance Entity gives Subfigure Definition"); bu_log("\tEntity DE of %d, largest DE in file is %d\n", subfigdef_de, (totentities * 2) - 1); continue; } if (dir[subfigdef_index]->type != 308) { bu_log("Expected Subfigure Definition Entity, found %s\n", iges_type(dir[subfigdef_index]->type)); continue; } if (dir[subfigdef_index]->param <= pstart) { bu_log("Illegal parameter pointer for entity D%07d (%s)\n" , dir[subfigdef_index]->direct, dir[subfigdef_index]->name); continue; } Readrec(dir[subfigdef_index]->param); Readint(&entity_type, ""); if (entity_type != 308) { bu_log("Expected Subfigure Definition Entity, found %s\n", iges_type(entity_type)); continue; } Readint(&j, ""); /* ignore depth */ Readstrg(""); /* ignore subfigure name */ wmem = mk_addmember(dir[subfigdef_index]->name, &head1.l, NULL, WMOP_UNION); non_unit = 0; for (j = 0; j < 3; j++) { double mag_sq; mat_scale[j] = 1.0; mag_sq = MAGSQ(&(*dir[i]->rot)[j*4]); /* FIXME: arbitrary undefined tolerance */ if (!NEAR_EQUAL(mag_sq, 1.0, 100.0*SQRT_SMALL_FASTF)) { mat_scale[j] = 1.0/sqrt(mag_sq); non_unit = 1; } } if (non_unit) { bu_log("Illegal transformation matrix in %s for member %s\n", curr_file->obj_name, wmem->wm_name); bu_log(" row vector magnitudes are %g, %g, and %g\n", 1.0/mat_scale[0], 1.0/mat_scale[1], 1.0/mat_scale[2]); bn_mat_print("", *dir[i]->rot); for (j = 0; j < 11; j++) { if ((j+1)%4 == 0) continue; (*dir[i]->rot)[j] *= mat_scale[0]; } bn_mat_print("After scaling:", *dir[i]->rot); } memcpy(wmem->wm_mat, *dir[i]->rot, sizeof(mat_t)); Readint(&no_of_members, ""); /* get number of members */ members = (int *)bu_calloc(no_of_members, sizeof(int), "Do_subfigs: members"); for (j = 0; j < no_of_members; j++) Readint(&members[j], ""); BU_LIST_INIT(&head2.l); for (j = 0; j < no_of_members; j++) { int idx; idx = (members[j] - 1)/2; if (idx >= totentities) { bu_log("Subfigure Definition Entity gives Member Entity"); bu_log("\tDE of %d, largest DE in file is %d\n", members[j], (totentities * 2) - 1); continue; } if (dir[idx]->param <= pstart) { bu_log("Illegal parameter pointer for entity D%07d (%s)\n" , dir[idx]->direct, dir[idx]->name); continue; } if (dir[idx]->type == 416) { struct file_list *list_ptr; char *file_name; int found = 0; /* external reference */ Readrec(dir[idx]->param); Readint(&entity_type, ""); if (entity_type != 416) { bu_log("Expected External reference Entity, found %s\n", iges_type(entity_type)); continue; } if (dir[idx]->form != 1) { bu_log("External Reference Entity of form #%d found\n", dir[idx]->form); bu_log("\tOnly form #1 is currently handled\n"); continue; } Readname(&file_name, ""); /* Check if this external reference is already on the list */ for (BU_LIST_FOR(list_ptr, file_list, &iges_list.l)) { if (BU_STR_EQUAL(file_name, list_ptr->file_name)) { found = 1; name = list_ptr->obj_name; break; } } if (!found) { /* Need to add this one to the list */ BU_ALLOC(list_ptr, struct file_list); list_ptr->file_name = file_name; if (no_of_members == 1) bu_strlcpy(list_ptr->obj_name, dir[subfigdef_index]->name, NAMESIZE+1); else { bu_strlcpy(list_ptr->obj_name, "subfig", NAMESIZE+1); (void) Make_unique_brl_name(list_ptr->obj_name); } BU_LIST_APPEND(&curr_file->l, &list_ptr->l); name = list_ptr->obj_name; } else bu_free((char *)file_name, "Do_subfigs: file_name"); } else name = dir[idx]->name; if (no_of_members > 1) { wmem = mk_addmember(name, &head2.l, NULL, WMOP_UNION); memcpy(wmem->wm_mat, dir[idx]->rot, sizeof(mat_t)); } } if (no_of_members > 1) (void)mk_lcomb(fdout, dir[subfigdef_index]->name, &head2, 0, (char *)NULL, (char *)NULL, (unsigned char *)NULL, 0); }
int hit(register struct application *ap, struct partition *PartHeadp, struct seg *segp) { register struct partition *pp; register struct soltab *stp; struct curvature cur; fastf_t out; point_t inpt, outpt; vect_t inormal, onormal; if ( (pp=PartHeadp->pt_forw) == PartHeadp ) return(0); /* Nothing hit?? */ if ( overlap_claimant_handling == 1 ) rt_rebuild_overlaps( PartHeadp, ap, 1 ); else if ( overlap_claimant_handling == 2 ) rt_rebuild_overlaps( PartHeadp, ap, 0 ); /* First, plot ray start to inhit */ if ( R_DEBUG&RDEBUG_RAYPLOT ) { if ( pp->pt_inhit->hit_dist > 0.0001 ) { VJOIN1( inpt, ap->a_ray.r_pt, pp->pt_inhit->hit_dist, ap->a_ray.r_dir ); pl_color( plotfp, 0, 0, 255 ); pdv_3line( plotfp, ap->a_ray.r_pt, inpt ); } } for (; pp != PartHeadp; pp = pp->pt_forw ) { matp_t inv_mat; Tcl_HashEntry *entry; bu_log("\n--- Hit region %s (in %s, out %s) reg_bit = %d\n", pp->pt_regionp->reg_name, pp->pt_inseg->seg_stp->st_name, pp->pt_outseg->seg_stp->st_name, pp->pt_regionp->reg_bit); entry = Tcl_FindHashEntry( (Tcl_HashTable *)ap->a_rt_i->Orca_hash_tbl, (const char *)(size_t)pp->pt_regionp->reg_bit ); if ( !entry ) { inv_mat = (matp_t)NULL; } else { inv_mat = (matp_t)Tcl_GetHashValue( entry ); bn_mat_print( "inv_mat", inv_mat ); } if ( pp->pt_overlap_reg ) { struct region *pp_reg; int j=-1; bu_log( " Claiming regions:\n" ); while ( (pp_reg=pp->pt_overlap_reg[++j]) ) bu_log( " %s\n", pp_reg->reg_name ); } /* inhit info */ stp = pp->pt_inseg->seg_stp; VJOIN1( inpt, ap->a_ray.r_pt, pp->pt_inhit->hit_dist, ap->a_ray.r_dir ); RT_HIT_NORMAL( inormal, pp->pt_inhit, stp, &(ap->a_ray), pp->pt_inflip ); RT_CURVATURE( &cur, pp->pt_inhit, pp->pt_inflip, stp ); rt_pr_hit( " In", pp->pt_inhit ); VPRINT( " Ipoint", inpt ); VPRINT( " Inormal", inormal ); bu_log( " PDir (%g, %g, %g) c1=%g, c2=%g\n", V3ARGS(cur.crv_pdir), cur.crv_c1, cur.crv_c2); if ( inv_mat ) { point_t in_trans; MAT4X3PNT( in_trans, inv_mat, inpt ); bu_log( "\ttransformed ORCA inhit = (%g %g %g)\n", V3ARGS( in_trans ) ); } /* outhit info */ stp = pp->pt_outseg->seg_stp; VJOIN1( outpt, ap->a_ray.r_pt, pp->pt_outhit->hit_dist, ap->a_ray.r_dir ); RT_HIT_NORMAL( onormal, pp->pt_outhit, stp, &(ap->a_ray), pp->pt_outflip ); RT_CURVATURE( &cur, pp->pt_outhit, pp->pt_outflip, stp ); rt_pr_hit( " Out", pp->pt_outhit ); VPRINT( " Opoint", outpt ); VPRINT( " Onormal", onormal ); bu_log( " PDir (%g, %g, %g) c1=%g, c2=%g\n", V3ARGS(cur.crv_pdir), cur.crv_c1, cur.crv_c2); if ( inv_mat ) { point_t out_trans; vect_t dir_trans; MAT4X3PNT( out_trans, inv_mat, outpt ); MAT4X3VEC( dir_trans, inv_mat, ap->a_ray.r_dir ); VUNITIZE( dir_trans ); bu_log( "\ttranformed ORCA outhit = (%g %g %g)\n", V3ARGS( out_trans ) ); bu_log( "\ttransformed ORCA ray direction = (%g %g %g)\n", V3ARGS( dir_trans ) ); } /* Plot inhit to outhit */ if ( R_DEBUG&RDEBUG_RAYPLOT ) { if ( (out = pp->pt_outhit->hit_dist) >= INFINITY ) out = 10000; /* to imply the direction */ VJOIN1( outpt, ap->a_ray.r_pt, out, ap->a_ray.r_dir ); pl_color( plotfp, 0, 255, 255 ); pdv_3line( plotfp, inpt, outpt ); } { struct region *regp = pp->pt_regionp; int i; if ( ap->attrs ) { bu_log( "\tattribute values:\n" ); i = 0; while ( ap->attrs[i] && regp->attr_values[i] ) { bu_log( "\t\t%s:\n", ap->attrs[i] ); bu_log( "\t\t\tstring rep = %s\n", BU_MRO_GETSTRING(regp->attr_values[i])); bu_log( "\t\t\tlong rep = %d\n", BU_MRO_GETLONG(regp->attr_values[i])); bu_log( "\t\t\tdouble rep = %f\n", BU_MRO_GETDOUBLE(regp->attr_values[i])); i++; } } } } return(1); }
/* F I R E _ S E T U P * * This routine is called (at prep time) * once for each region which uses this shader. * Any shader-specific initialization should be done here. */ HIDDEN int fire_setup(register struct region *rp, struct bu_vls *matparm, char **dpp, struct mfuncs *mfp, struct rt_i *rtip) /* pointer to reg_udata in *rp */ /* New since 4.4 release */ { register struct fire_specific *fire_sp; /* check the arguments */ RT_CHECK_RTI(rtip); BU_CK_VLS( matparm ); RT_CK_REGION(rp); if (rdebug&RDEBUG_SHADE) bu_log("fire_setup(%s)\n", rp->reg_name); /* Get memory for the shader parameters and shader-specific data */ BU_GETSTRUCT( fire_sp, fire_specific ); *dpp = (char *)fire_sp; /* initialize the default values for the shader */ memcpy(fire_sp, &fire_defaults, sizeof(struct fire_specific)); /* parse the user's arguments for this use of the shader. */ if (bu_struct_parse( matparm, fire_parse_tab, (char *)fire_sp ) < 0 ) return(-1); if (fire_sp->noise_size != -1.0) { VSETALL(fire_sp->noise_vscale, fire_sp->noise_size); } /* * The shader needs to operate in a coordinate system which stays * fixed on the region when the region is moved (as in animation). * We need to get a matrix to perform the appropriate transform(s). */ db_shader_mat(fire_sp->fire_m_to_sh, rtip, rp, fire_sp->fire_min, fire_sp->fire_max, &rt_uniresource); /* Build matrix to map shader space to noise space. * XXX If only we could get the frametime at this point * we could factor the flicker of flames into this matrix * rather than having to recompute it on a pixel-by-pixel basis. */ MAT_IDN(fire_sp->fire_sh_to_noise); MAT_DELTAS_VEC(fire_sp->fire_sh_to_noise, fire_sp->noise_delta); MAT_SCALE_VEC(fire_sp->fire_sh_to_noise, fire_sp->noise_vscale); /* get matrix for performing spline of fire colors */ rt_dspline_matrix(fire_sp->fire_colorspline_mat, "Catmull", 0.5, 0.0); if (rdebug&RDEBUG_SHADE || fire_sp->fire_debug ) { bu_struct_print( " FIRE Parameters:", fire_print_tab, (char *)fire_sp ); bn_mat_print( "m_to_sh", fire_sp->fire_m_to_sh ); bn_mat_print( "sh_to_noise", fire_sp->fire_sh_to_noise ); bn_mat_print( "colorspline", fire_sp->fire_colorspline_mat ); } return(1); }
-x# -y# -z# Rotation about axis in degrees\n\ -X# -Y# -Z# Translation along axis\n\ -s# Scale factor\n\ -a# -e# Azimuth/Elevation from front view\n\ (usually first, in this order, implies -M)\n\ -g MGED front view to display coordinates (usually last)\n\ -M Autoscale space command like RT model RPP\n\ -m# Takes a 4X4 matrix as an argument\n\ -v Verbose\n\ -S# Space: takes a quoted string of six floats\n"; /* * M O D E L _ R P P * * Process a space command. * Behavior depends on setting of several flags. * * Implicit Returns - * In all cases, sets space_min and space_max. */ int model_rpp(const fastf_t *min, const fastf_t *max) { if ( space_set ) { fprintf(stderr, "plrot: additional SPACE command ignored\n"); fprintf(stderr, "got: space (%g, %g, %g) (%g, %g, %g)\n", V3ARGS(min), V3ARGS(max) ); fprintf(stderr, "still using: space (%g, %g, %g) (%g, %g, %g)\n", V3ARGS(space_min), V3ARGS(space_max) ); return 0; } if ( rpp ) { point_t rot_center; /* center of rotation */ mat_t xlate; mat_t resize; mat_t t1, t2; VADD2SCALE( rot_center, min, max, 0.5 ); /* Create the matrix which encodes this */ MAT_IDN( xlate ); MAT_DELTAS_VEC_NEG( xlate, rot_center); MAT_IDN( resize ); resize[15] = 1/scale; bn_mat_mul( t1, resize, xlate ); bn_mat_mul( t2, rmat, t1 ); MAT_COPY( rmat, t2 ); if ( verbose ) { bn_mat_print("rmat", rmat); } if ( Mflag ) { /* Don't rebound, just expand size of space * around center point. * Has advantage of the output space() not being * affected by changes in rotation, * which may be significant for animation scripts. */ vect_t diag; double v; VSUB2( diag, max, min ); v = MAGNITUDE(diag)*0.5 + 0.5; VSET( space_min, -v, -v, -v ); VSET( space_max, v, v, v ); } else { /* re-bound the space() rpp with a tighter one * after rotating & scaling it. */ bn_rotate_bbox( space_min, space_max, rmat, min, max ); } space_set = 1; } else { VMOVE( space_min, min ); VMOVE( space_max, max ); space_set = 1; } if ( forced_space ) { /* Put forced space back */ VMOVE( space_min, forced_space_min ); VMOVE( space_max, forced_space_max ); space_set = 1; } if ( verbose ) { fprintf(stderr, "got: space (%g, %g, %g) (%g, %g, %g)\n", V3ARGS(min), V3ARGS(max) ); fprintf(stderr, "put: space (%g, %g, %g) (%g, %g, %g)\n", V3ARGS(space_min), V3ARGS(space_max) ); } return( 1 ); }
/* * This routine is called (at prep time) * once for each region which uses this shader. * Any shader-specific initialization should be done here. */ HIDDEN int gauss_setup(register struct region *rp, struct bu_vls *matparm, void **dpp, const struct mfuncs *UNUSED(mfp), struct rt_i *rtip) /* pointer to reg_udata in *rp */ /* New since 4.4 release */ { register struct gauss_specific *gauss_sp; struct tree_bark tb; /* check the arguments */ RT_CHECK_RTI(rtip); BU_CK_VLS(matparm); RT_CK_REGION(rp); if (rdebug&RDEBUG_SHADE) bu_log("gauss_setup(%s)\n", rp->reg_name); if (! rtip->useair) bu_bomb("gauss shader used and useair not set\n"); /* Get memory for the shader parameters and shader-specific data */ BU_GET(gauss_sp, struct gauss_specific); *dpp = gauss_sp; /* initialize the default values for the shader */ memcpy(gauss_sp, &gauss_defaults, sizeof(struct gauss_specific)); /* parse the user's arguments for this use of the shader. */ if (bu_struct_parse(matparm, gauss_parse_tab, (char *)gauss_sp, NULL) < 0) return -1; /* We have to pick up the parameters for the gaussian puff now. * They won't be available later. So what we do is sneak a peak * inside the region, make sure the first item in it is an ellipsoid * solid, and if it is go steal a peek at its balls ... er ... make * that definition/parameters. */ BU_LIST_INIT(&gauss_sp->dbil); tb.l = &gauss_sp->dbil; tb.dbip = rtip->rti_dbip; tb.name = rp->reg_name; tb.gs = gauss_sp; tree_solids (rp->reg_treetop, &tb, OP_UNION, &rt_uniresource); /* XXX If this puppy isn't axis-aligned, we should come up with a * matrix to rotate it into alignment. We're going to have to do * computation in the space defined by this ellipsoid. */ if (rdebug&RDEBUG_SHADE) { bu_struct_print(" Parameters:", gauss_print_tab, (char *)gauss_sp); bn_mat_print("m_to_sh", gauss_sp->gauss_m_to_sh); } return 1; }
/* * * M A I N * * Main exists to coordinate the actions of the parts of this program. * It also processes its own arguments (argc and argv). */ int main(int argc, char **argv) { mat_t mod2view1; /* first log matrix its view */ mat_t mod2view2; /* second log matrix to its view*/ mat_t regismat; /* registration matrix */ mat_t view2model; /* matrix for converting from view to model space */ int ret; /* function return code */ MAT_IDN(mod2view1); /* makes an identity matrix */ MAT_IDN(mod2view2); MAT_IDN(regismat); /* Check to see that the correct format is given, else print * usage message. */ if (argc != 3) { fputs(usage, stderr); return 1; } /* Now process the arguments from main: i.e. open the log files * for reading and send to read_rt_file(). * Send read_rt_file() a pointer to local model matrix * and to the appropriate log file. * ( Note &view2model[0] can be used, but is not elegant.) */ fp = fopen(argv[1], "r"); if ( fp == NULL ) { perror(argv[1]); return 1; } ret = read_rt_file(fp, argv[1], mod2view1); if (ret < 0) { return 2; } fclose(fp); /* clean up */ fp = fopen(argv[2], "r"); if ( fp == NULL ) { perror(argv[2]); return 2; } ret = read_rt_file(fp, argv[2], mod2view2); if (ret < 0) { return 2; } fclose(fp); if (verbose) { bn_mat_inv(view2model, mod2view1); bn_mat_print("mod2view1-plot.log", mod2view1); bn_mat_print("mod2view2-pix.log", mod2view2); fprintf(stderr, "mod2view1[0, 1, 2, 3, 15]: %.6f, %.6f, %.6f, %.6f, %.6f\n", mod2view1[0], mod2view1[1], mod2view1[2], mod2view1[3], mod2view1[15]); } /* Now build the registration matrix for the two files. */ ret = mat_build(mod2view1, mod2view2, regismat); if (ret == FALSE) { fprintf(stderr, "regis: can't build registration matrix!\n"); return 3; } print_info(regismat); return 0; }
/* * Process a space command. * Behavior depends on setting of several flags. * * Implicit Returns - * In all cases, sets space_min and space_max. */ int model_rpp(const fastf_t *min, const fastf_t *max) { if (space_set) { bu_log("plot3rot: additional SPACE command ignored\n"); bu_log("got: space (%g, %g, %g) (%g, %g, %g)\n", V3ARGS(min), V3ARGS(max)); bu_log("still using: space (%g, %g, %g) (%g, %g, %g)\n", V3ARGS(space_min), V3ARGS(space_max)); return 0; } if (rpp) { point_t rot_center; /* center of rotation */ mat_t xlate; mat_t resize; mat_t t1, t2; VADD2SCALE(rot_center, min, max, 0.5); /* Create the matrix which encodes this */ MAT_IDN(xlate); MAT_DELTAS_VEC_NEG(xlate, rot_center); MAT_IDN(resize); resize[15] = 1/scale; bn_mat_mul(t1, resize, xlate); bn_mat_mul(t2, rmat, t1); MAT_COPY(rmat, t2); if (verbose) { bn_mat_print("rmat", rmat); } if (Mflag) { /* Don't rebound, just expand size of space * around center point. * Has advantage of the output space() not being * affected by changes in rotation, * which may be significant for animation scripts. */ vect_t diag; double v; VSUB2(diag, max, min); v = MAGNITUDE(diag)*0.5 + 0.5; VSET(space_min, -v, -v, -v); VSET(space_max, v, v, v); } else { /* re-bound the space() rpp with a tighter one * after rotating & scaling it. */ bn_rotate_bbox(space_min, space_max, rmat, min, max); } space_set = 1; } else { VMOVE(space_min, min); VMOVE(space_max, max); space_set = 1; } if (forced_space) { /* Put forced space back */ VMOVE(space_min, forced_space_min); VMOVE(space_max, forced_space_max); space_set = 1; } if (verbose) { bu_log("got: space (%g, %g, %g) (%g, %g, %g)\n", V3ARGS(min), V3ARGS(max)); bu_log("put: space (%g, %g, %g) (%g, %g, %g)\n", V3ARGS(space_min), V3ARGS(space_max)); } return 1; }
/** * R E A D _ M A T */ void read_mat (struct rt_i *rtip) { double scan[16] = MAT_INIT_ZERO; char *buf; int status = 0x0; mat_t m; mat_t q; while ((buf = rt_read_cmd(stdin)) != (char *) 0) { if (bu_strncmp(buf, "eye_pt", 6) == 0) { if (sscanf(buf + 6, "%lf%lf%lf", &scan[X], &scan[Y], &scan[Z]) != 3) { bu_exit(1, "nirt: read_mat(): Failed to read eye_pt\n"); } target(X) = scan[X]; target(Y) = scan[Y]; target(Z) = scan[Z]; status |= RMAT_SAW_EYE; } else if (bu_strncmp(buf, "orientation", 11) == 0) { if (sscanf(buf + 11, "%lf%lf%lf%lf", &scan[X], &scan[Y], &scan[Z], &scan[W]) != 4) { bu_exit(1, "nirt: read_mat(): Failed to read orientation\n"); } MAT_COPY(q, scan); quat_quat2mat(m, q); if (nirt_debug & DEBUG_MAT) bn_mat_print("view matrix", m); azimuth() = atan2(-m[0], m[1]) / DEG2RAD; elevation() = atan2(m[10], m[6]) / DEG2RAD; status |= RMAT_SAW_ORI; } else if (bu_strncmp(buf, "viewrot", 7) == 0) { if (sscanf(buf + 7, "%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf", &scan[0], &scan[1], &scan[2], &scan[3], &scan[4], &scan[5], &scan[6], &scan[7], &scan[8], &scan[9], &scan[10], &scan[11], &scan[12], &scan[13], &scan[14], &scan[15]) != 16) { bu_exit(1, "nirt: read_mat(): Failed to read viewrot\n"); } MAT_COPY(m, scan); if (nirt_debug & DEBUG_MAT) bn_mat_print("view matrix", m); azimuth() = atan2(-m[0], m[1]) / DEG2RAD; elevation() = atan2(m[10], m[6]) / DEG2RAD; status |= RMAT_SAW_VR; } } if ((status & RMAT_SAW_EYE) == 0) { bu_exit(1, "nirt: read_mat(): Was given no eye_pt\n"); } if ((status & (RMAT_SAW_ORI | RMAT_SAW_VR)) == 0) { bu_exit(1, "nirt: read_mat(): Was given no orientation or viewrot\n"); } direct(X) = -m[8]; direct(Y) = -m[9]; direct(Z) = -m[10]; dir2ae(); targ2grid(); shoot("", 0, rtip); }