/* * Returns the views eyemodel * * Usage: * get_eyemodel * */ int ged_get_eyemodel(struct ged *gedp, int argc, const char *argv[]) { quat_t quat; vect_t eye_model; GED_CHECK_DATABASE_OPEN(gedp, GED_ERROR); GED_CHECK_DRAWABLE(gedp, GED_ERROR); GED_CHECK_VIEW(gedp, GED_ERROR); GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR); /* initialize result */ bu_vls_trunc(gedp->ged_result_str, 0); if (argc != 1) { bu_vls_printf(gedp->ged_result_str, "Usage: %s", argv[0]); return GED_ERROR; } _ged_rt_set_eye_model(gedp, eye_model); quat_mat2quat(quat, gedp->ged_gvp->gv_rotation); bu_vls_printf(gedp->ged_result_str, "viewsize %.15e;\n", gedp->ged_gvp->gv_size); bu_vls_printf(gedp->ged_result_str, "orientation %.15e %.15e %.15e %.15e;\n", V4ARGS(quat)); bu_vls_printf(gedp->ged_result_str, "eye_pt %.15e %.15e %.15e;\n", eye_model[X], eye_model[Y], eye_model[Z]); return GED_OK; }
/** * Routine to format the parameters of an ARBN primitive for "db get" * * Legal requested parameters include: * "N" - number of equations * "P" - list of all the planes * "P#" - the specified plane number (0 based) * no arguments returns everything */ int rt_arbn_get(struct bu_vls *logstr, const struct rt_db_internal *intern, const char *attr) { struct rt_arbn_internal *arbn=(struct rt_arbn_internal *)intern->idb_ptr; size_t i; long val; RT_ARBN_CK_MAGIC(arbn); if (attr == (char *)NULL) { bu_vls_strcpy(logstr, "arbn"); bu_vls_printf(logstr, " N %zu", arbn->neqn); for (i = 0; i < arbn->neqn; i++) { bu_vls_printf(logstr, " P%zu {%.25g %.25g %.25g %.25g}", i, V4ARGS(arbn->eqn[i])); } } else if (BU_STR_EQUAL(attr, "N")) { bu_vls_printf(logstr, "%zu", arbn->neqn); } else if (BU_STR_EQUAL(attr, "P")) { for (i = 0; i < arbn->neqn; i++) { bu_vls_printf(logstr, " P%zu {%.25g %.25g %.25g %.25g}", i, V4ARGS(arbn->eqn[i])); } } else if (attr[0] == 'P') { if (isdigit((int)attr[1]) == 0) { bu_vls_printf(logstr, "ERROR: Illegal plane number\n"); return BRLCAD_ERROR; } val = atol(&attr[1]); if (val < 0 || (size_t)val >= arbn->neqn) { bu_vls_printf(logstr, "ERROR: Illegal plane number [%ld]\n", val); return BRLCAD_ERROR; } i = (size_t)val; bu_vls_printf(logstr, "%.25g %.25g %.25g %.25g", V4ARGS(arbn->eqn[i])); } else { bu_vls_printf(logstr, "ERROR: Unknown attribute, choices are N, P, or P#\n"); return BRLCAD_ERROR; } return BRLCAD_OK; }
static void Write_euclid_face(const struct loopuse *lu, const int facet_type, const int regionid, const int face_number) { struct faceuse *fu; struct edgeuse *eu; plane_t plane; int vertex_count = 0; NMG_CK_LOOPUSE(lu); if (verbose) bu_log("Write_euclid_face: lu=%p, facet_type=%d, regionid=%d, face_number=%d\n", (void *)lu, facet_type, regionid, face_number); if (BU_LIST_FIRST_MAGIC(&lu->down_hd) != NMG_EDGEUSE_MAGIC) return; if (*lu->up.magic_p != NMG_FACEUSE_MAGIC) return; for (BU_LIST_FOR(eu, edgeuse, &lu->down_hd)) vertex_count++; fprintf(fp_out, "%10d%3d 0. 1%5d", regionid, facet_type, vertex_count); vertex_count = 0; for (BU_LIST_FOR(eu, edgeuse, &lu->down_hd)) { struct vertex *v; int i; NMG_CK_EDGEUSE(eu); v = eu->vu_p->v_p; NMG_CK_VERTEX(v); /* fprintf(fp_out, "%10d%8f%8f%8f", ++vertex_count, V3ARGS(v->vg_p->coord)); */ vertex_count++; fprintf(fp_out, "%10d", vertex_count); for (i=X; i<=Z; i++) fastf_print(fp_out, 8, v->vg_p->coord[i]); } fu = lu->up.fu_p; NMG_CK_FACEUSE(fu); NMG_GET_FU_PLANE(plane, fu); fprintf(fp_out, "%10d%15.5f%15.5f%15.5f%15.5f", face_number, V4ARGS(plane)); }
int ged_quat(struct ged *gedp, int argc, const char *argv[]) { quat_t quat; double scan[4]; static const char *usage = "a b c d"; GED_CHECK_DATABASE_OPEN(gedp, GED_ERROR); GED_CHECK_VIEW(gedp, GED_ERROR); GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR); /* initialize result */ bu_vls_trunc(gedp->ged_result_str, 0); /* return Viewrot as a quaternion */ if (argc == 1) { quat_mat2quat(quat, gedp->ged_gvp->gv_rotation); bu_vls_printf(gedp->ged_result_str, "%.12g %.12g %.12g %.12g", V4ARGS(quat)); return GED_OK; } if (argc != 5) { bu_vls_printf(gedp->ged_result_str, "Usage: view %s %s", argv[0], usage); return GED_ERROR; } /* Set the view orientation given a quaternion */ if (sscanf(argv[1], "%lf", &scan[0]) != 1 || sscanf(argv[2], "%lf", &scan[1]) != 1 || sscanf(argv[3], "%lf", &scan[2]) != 1 || sscanf(argv[4], "%lf", &scan[3]) != 1) { bu_vls_printf(gedp->ged_result_str, "view %s: bad value detected - %s %s %s %s", argv[0], argv[1], argv[2], argv[3], argv[4]); return GED_ERROR; } HMOVE(quat, scan); quat_quat2mat(gedp->ged_gvp->gv_rotation, quat); ged_view_update(gedp->ged_gvp); return GED_OK; }
/* * The output occurs here. * * framenumber, viewsize, eye x y z, orientation x y z w */ int cm_end(const int UNUSED(argc), const char **UNUSED(argv)) { quat_t orient; /* If no matrix or az/el specified yet, use params from cmd line */ if (Viewrotscale[15] <= 0.0) bu_exit(EXIT_FAILURE, "cm_end: matrix not specified\n"); quat_mat2quat(orient, Viewrotscale); /* Output information about this frame */ printf("%d %.15e %.15e %.15e %.15e %.15e %.15e %.15e %.15e\n", curframe, viewsize, V3ARGS(eye_model), V4ARGS(orient)); return 0; }
static void log_Run(void) { time_t clock_time; mat_t model2hv; /* model to h, v matrix */ mat_t hv2model; /* h, v tp model matrix */ quat_t orient; /* orientation */ point_t hv_eye; /* eye position in h, v coords */ point_t m_eye; /* eye position in model coords */ fastf_t hv_viewsize; /* size of view in h, v coords */ fastf_t m_viewsize; /* size of view in model coords. */ /* Current date and time get printed in header comment */ (void) time(&clock_time); (void) printf("# Log information produced by cell-fb %s\n", ctime(&clock_time)); (void) printf("az_el: %f %f\n", az, el); (void) printf("view_extrema: %f %f %f %f\n", SCRX2H(0), SCRX2H(fb_width), SCRY2V(0), SCRY2V(fb_height)); (void) printf("fb_size: %d %d\n", fb_width, fb_height); /* Produce the orientation, the model eye_pos, and the model * view size for input into rtregis. * First use the azimuth and elevation to produce the model2hv * matrix and use that to find the orientation. */ MAT_IDN(model2hv); MAT_IDN(hv2model); /* Print out the "view" just to keep rtregis from belly-aching */ printf("View: %g azimuth, %g elevation\n", az, el); /** mat_ae(model2hv, az, el); **/ /* Formula from rt/do.c */ bn_mat_angles(model2hv, 270.0+el, 0.0, 270.0-az); model2hv[15] = 25.4; /* input is in inches */ bn_mat_inv(hv2model, model2hv); quat_mat2quat(orient, model2hv); printf("Orientation: %.6f, %.6f, %.6f, %.6f\n", V4ARGS(orient)); /* Now find the eye position in h, v space. Note that the eye * is located at the center of the image; in this case, the center * of the screen space, i.e., the framebuffer.) * Also find the hv_viewsize at this time. */ hv_viewsize = SCRX2H((double)fb_width) - SCRX2H(0.0); hv_eye[0] = SCRX2H((double)fb_width/2); hv_eye[1] = SCRY2V((double)fb_height/2); hv_eye[2] = hv_viewsize/2; /* Debugging */ printf("hv_viewsize= %g\n", hv_viewsize); printf("hv_eye= %.6f, %.6f, %.6f\n", V3ARGS(hv_eye)); /* Now find the model eye_position and report on that */ MAT4X3PNT(m_eye, hv2model, hv_eye); printf("Eye_pos: %.6f, %.6f, %.6f\n", V3ARGS(m_eye)); /* * Find the view size in model coordinates and print that as well. * Important: Don't use %g format, it may round to nearest integer! */ m_viewsize = hv_viewsize/hv2model[15]; printf("Size: %.6f\n", m_viewsize); }
struct face_g_snurb * rt_nurb_project_srf(const struct face_g_snurb *srf, fastf_t *plane1, fastf_t *plane2, struct resource *res) { register struct face_g_snurb *psrf; register fastf_t *mp1, *mp2; int n_pt_type; int rational; int i; if (RTG.NMG_debug & DEBUG_RT_ISECT) bu_log("rt_nurb_project_srf: projecting surface, planes = (%g %g %g %g) (%g %g %g %g)\n", V4ARGS(plane1), V4ARGS(plane2)); rational = RT_NURB_IS_PT_RATIONAL(srf->pt_type); n_pt_type = RT_NURB_MAKE_PT_TYPE(2, RT_NURB_PT_PROJ, 0); psrf = (struct face_g_snurb *) rt_nurb_new_snurb(srf->order[0], srf->order[1], srf->u.k_size, srf->v.k_size, srf->s_size[0], srf->s_size[1], n_pt_type, res); psrf->dir = RT_NURB_SPLIT_COL; for (i = 0; i < srf->u.k_size; i++) { psrf->u.knots[i] = srf->u.knots[i]; } for (i = 0; i < srf->v.k_size; i++) { psrf->v.knots[i] = srf->v.knots[i]; } mp1 = srf->ctl_points; mp2 = psrf->ctl_points; for (i = 0; i < srf->s_size[0] * srf->s_size[1]; i++) { if (rational) { mp2[0] = (mp1[0] / mp1[3] * plane1[0] + mp1[1] / mp1[3] * plane1[1] + mp1[2] / mp1[3] * plane1[2] - plane1[3]) * mp1[3]; mp2[1] = (mp1[0] / mp1[3] * plane2[0] + mp1[1] / mp1[3] * plane2[1] + mp1[2] / mp1[3] * plane2[2] - plane2[3]) * mp1[3]; } else { mp2[0] = mp1[0] * plane1[0] + mp1[1] * plane1[1] + mp1[2] * plane1[2] - plane1[3]; mp2[1] = mp1[0] * plane2[0] + mp1[1] * plane2[1] + mp1[2] * plane2[2] - plane2[3]; } if (RTG.NMG_debug & DEBUG_RT_ISECT) { if (rational) bu_log("\tmesh pt (%g %g %g %g), becomes (%g %g)\n", V4ARGS(mp1), mp2[0], mp2[1]); else bu_log("\tmesh pt (%g %g %g), becomes (%g %g)\n", V3ARGS(mp1), mp2[0], mp2[1]); } mp1 += RT_NURB_EXTRACT_COORDS(srf->pt_type); mp2 += RT_NURB_EXTRACT_COORDS(psrf->pt_type); } return (struct face_g_snurb *) psrf; }
int ged_rtwizard(struct ged *gedp, int argc, const char *argv[]) { char **vp; int i; char pstring[32]; int args; quat_t quat; vect_t eye_model; struct bu_vls perspective_vls = BU_VLS_INIT_ZERO; struct bu_vls size_vls = BU_VLS_INIT_ZERO; struct bu_vls orient_vls = BU_VLS_INIT_ZERO; struct bu_vls eye_vls = BU_VLS_INIT_ZERO; const char *bin; char rt[256] = {0}; char rtscript[256] = {0}; GED_CHECK_DATABASE_OPEN(gedp, GED_ERROR); GED_CHECK_DRAWABLE(gedp, GED_ERROR); GED_CHECK_VIEW(gedp, GED_ERROR); GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR); /* initialize result */ bu_vls_trunc(gedp->ged_result_str, 0); if (gedp->ged_gvp->gv_perspective > 0) /* btclsh rtwizard --no_gui -perspective p -i db.g --viewsize size --orientation "A B C D} --eye_pt "X Y Z" */ args = argc + 1 + 1 + 1 + 2 + 2 + 2 + 2 + 2; else /* btclsh rtwizard --no_gui -i db.g --viewsize size --orientation "A B C D} --eye_pt "X Y Z" */ args = argc + 1 + 1 + 1 + 2 + 2 + 2 + 2; gedp->ged_gdp->gd_rt_cmd = (char **)bu_calloc(args, sizeof(char *), "alloc gd_rt_cmd"); bin = bu_brlcad_root("bin", 1); if (bin) { snprintf(rt, 256, "%s/btclsh", bin); snprintf(rtscript, 256, "%s/rtwizard", bin); } else { snprintf(rt, 256, "btclsh"); snprintf(rtscript, 256, "rtwizard"); } _ged_rt_set_eye_model(gedp, eye_model); quat_mat2quat(quat, gedp->ged_gvp->gv_rotation); bu_vls_printf(&size_vls, "%.15e", gedp->ged_gvp->gv_size); bu_vls_printf(&orient_vls, "%.15e %.15e %.15e %.15e", V4ARGS(quat)); bu_vls_printf(&eye_vls, "%.15e %.15e %.15e", V3ARGS(eye_model)); vp = &gedp->ged_gdp->gd_rt_cmd[0]; *vp++ = rt; *vp++ = rtscript; *vp++ = "--no-gui"; *vp++ = "--viewsize"; *vp++ = bu_vls_addr(&size_vls); *vp++ = "--orientation"; *vp++ = bu_vls_addr(&orient_vls); *vp++ = "--eye_pt"; *vp++ = bu_vls_addr(&eye_vls); if (gedp->ged_gvp->gv_perspective > 0) { *vp++ = "--perspective"; (void)sprintf(pstring, "%g", gedp->ged_gvp->gv_perspective); *vp++ = pstring; } *vp++ = "-i"; *vp++ = gedp->ged_wdbp->dbip->dbi_filename; /* Append all args */ for (i = 1; i < argc; i++) *vp++ = (char *)argv[i]; *vp = 0; /* * Accumulate the command string. */ vp = &gedp->ged_gdp->gd_rt_cmd[0]; while (*vp) bu_vls_printf(gedp->ged_result_str, "%s ", *vp++); bu_vls_printf(gedp->ged_result_str, "\n"); gedp->ged_gdp->gd_rt_cmd_len = vp - gedp->ged_gdp->gd_rt_cmd; (void)_ged_run_rtwizard(gedp); bu_free(gedp->ged_gdp->gd_rt_cmd, "free gd_rt_cmd"); gedp->ged_gdp->gd_rt_cmd = NULL; bu_vls_free(&perspective_vls); bu_vls_free(&size_vls); bu_vls_free(&orient_vls); bu_vls_free(&eye_vls); return GED_OK; }
void bn_encode_quat(struct bu_vls *vp, const mat_t q) { bu_vls_printf(vp, "%g %g %g %g", V4ARGS(q)); }
void bn_encode_hvect(struct bu_vls *vp, const mat_t v) { bu_vls_printf(vp, "%g %g %g %g", V4ARGS(v)); }
int main(void) { point_t *pts = (point_t *)NULL; int ident, face_type, npts, face_no; plane_t pl; int tmp_i; float tmp_a; float a, b, c, d; int old_id=(-1); int face_count=0; #if defined(_WIN32) && !defined(__CYGWIN__) setmode(fileno(stdin), O_BINARY); setmode(fileno(stdout), O_BINARY); #endif while ( scanf( "%d %d %f %d %d", &ident, &face_type, &tmp_a, &tmp_i, &npts ) != EOF ) { int i; if ( npts > 0 ) pts = (point_t *)bu_calloc( npts, sizeof( point_t ), "pts" ); for ( i=0; i<npts; i++ ) { int j; if ( scanf( "%d %f %f %f", &j, &a, &b, &c ) == EOF ) bu_exit(1, "Unexpected EOF\n"); if ( j != i+1 ) { bu_exit(1, "Points out of order\n"); } VSET( pts[i], a, b, c ); } if ( scanf( "%d %f %f %f %f", &face_no, &a, &b, &c, &d ) == EOF ) bu_exit(1, "Unexpected EOF\n" ); VSET( pl, a, b, c ); pl[3] = d; if ( ident != old_id ) { if ( npts > 2 ) { face_count = 1; printf( "%5d%5d%5d 0 %8d %5.2f \n" , face_count, npts, face_type, ident, 0.0 ); } old_id = ident; } else { if ( npts > 2 ) { face_count++; printf( "%5d%5d%5d 0 \n" , face_count, npts, face_type ); } } if ( npts > 2 ) { printf( "%11.6f%11.6f%11.6f%13.6f\n", V4ARGS( pl ) ); for ( i=0; i<npts; i++ ) printf( "%8f %8f %8f \n", V3ARGS( pts[i] ) ); } if ( npts > 0 ) bu_free( (char *)pts, "pts" ); } return 0; }