/* * Each word in the command buffer is the name of a treetop. */ void ph_gettrees(struct pkg_conn *UNUSED(pc), char *buf) { size_t n = 0; long max_argc = 0; char **argv = NULL; int argc = 0; struct rt_i *rtip = APP.a_rt_i; RT_CK_RTI(rtip); if (debug) fprintf(stderr, "ph_gettrees: %s\n", buf); /* Copy values from command line options into rtip */ rtip->useair = use_air; if (rt_dist_tol > 0) { rtip->rti_tol.dist = rt_dist_tol; rtip->rti_tol.dist_sq = rt_dist_tol * rt_dist_tol; } if (rt_perp_tol > 0) { rtip->rti_tol.perp = rt_perp_tol; rtip->rti_tol.para = 1 - rt_perp_tol; } for (n = 0; n < strlen(buf); n++) { if (isspace((int)buf[n])) max_argc++; } argv = (char **)bu_calloc(max_argc+1, sizeof(char *), "alloc argv"); if ((argc = bu_argv_from_string(argv, max_argc, buf)) <= 0) { /* No words in input */ (void)free(buf); bu_free(argv, "free argv"); return; } title_obj = bu_strdup(argv[0]); if (rtip->needprep == 0) { /* First clean up after the end of the previous frame */ if (debug)bu_log("Cleaning previous model\n"); view_end(&APP); view_cleanup(rtip); rt_clean(rtip); if (rdebug&RDEBUG_RTMEM_END) bu_prmem("After rt_clean"); } /* Load the desired portion of the model */ if (rt_gettrees(rtip, argc, (const char **)argv, npsw) < 0) fprintf(stderr, "rt_gettrees(%s) FAILED\n", argv[0]); bu_free(argv, "free argv"); /* In case it changed from startup time via an OPT command */ if (npsw > 1) { RTG.rtg_parallel = 1; } else RTG.rtg_parallel = 0; seen_gettrees = 1; (void)free(buf); prepare(); /* Acknowledge that we are ready */ if (pkg_send(MSG_GETTREES_REPLY, title_obj, strlen(title_obj)+1, pcsrv) < 0) fprintf(stderr, "MSG_START error\n"); }
void shoot(char *UNUSED(buffer), com_table *UNUSED(ctp), struct rt_i *rtip) { int i; double bov = 0.0; /* back out value */ extern void init_ovlp(); if (!rtip) return; if (need_prep) { rt_clean(rtip); do_rt_gettrees(rtip, NULL, 0, &need_prep); } if (do_backout) { point_t ray_point; vect_t ray_dir; vect_t center_bsphere; fastf_t dist_to_target; vect_t dvec; fastf_t delta; for (i = 0; i < 3; ++i) { ray_point[i] = target(i); ray_dir[i] = direct(i); } if (bsphere_diameter < 0) set_diameter(rtip); /* * calculate the distance from a plane normal to the ray direction through the center of * the bounding sphere and a plane normal to the ray direction through the aim point. */ VADD2SCALE(center_bsphere, rtip->mdl_max, rtip->mdl_min, 0.5); dist_to_target = DIST_PT_PT(center_bsphere, ray_point); VSUB2(dvec, ray_point, center_bsphere); VUNITIZE(dvec); delta = dist_to_target*VDOT(ray_dir, dvec); /* * this should put us about a bounding sphere radius in front of the bounding sphere */ bov = bsphere_diameter + delta; } for (i = 0; i < 3; ++i) { target(i) = target(i) + (bov * -direct(i)); ap.a_ray.r_pt[i] = target(i); ap.a_ray.r_dir[i] = direct(i); } if (nirt_debug & DEBUG_BACKOUT) { bu_log("Backing out %g units to (%g %g %g), shooting dir is (%g %g %g)\n", bov * base2local, ap.a_ray.r_pt[0] * base2local, ap.a_ray.r_pt[1] * base2local, ap.a_ray.r_pt[2] * base2local, V3ARGS(ap.a_ray.r_dir)); } init_ovlp(); (void) rt_shootray(&ap); /* Restore pre-backout target values */ if (do_backout) { for (i = 0; i < 3; ++i) { target(i) = target(i) - (bov * -direct(i)); } } }