Revision: 47158 http://brlcad.svn.sourceforge.net/brlcad/?rev=47158&view=rev Author: abhi2011 Date: 2011-10-06 18:26:30 +0000 (Thu, 06 Oct 2011) Log Message: ----------- Added initial code to shoot rays during manifold generation
Modified Paths: -------------- brlcad/trunk/src/libged/simulate/simrt.c brlcad/trunk/src/libged/simulate/simrt.h brlcad/trunk/src/libged/simulate/simulate.c Modified: brlcad/trunk/src/libged/simulate/simrt.c =================================================================== --- brlcad/trunk/src/libged/simulate/simrt.c 2011-10-06 16:56:52 UTC (rev 47157) +++ brlcad/trunk/src/libged/simulate/simrt.c 2011-10-06 18:26:30 UTC (rev 47158) @@ -58,6 +58,145 @@ int +if_hit(struct application *ap, struct partition *part_headp, struct seg *UNUSED(segs)) +{ + /* iterating over partitions, this will keep track of the current + * partition we're working on. + */ + struct partition *pp; + + /* will serve as a pointer for the entry and exit hitpoints */ + struct hit *hitp; + + /* will serve as a pointer to the solid primitive we hit */ + struct soltab *stp; + + /* will contain surface curvature information at the entry */ + struct curvature cur; + + /* will contain our hit point coordinate */ + point_t pt; + + /* will contain normal vector where ray enters geometry */ + vect_t inormal; + + /* will contain normal vector where ray exits geometry */ + vect_t onormal; + + /* iterate over each partition until we get back to the head. + * each partition corresponds to a specific homogeneous region of + * material. + */ + + /* iterate over each partition until we get back to the head. + * each partition corresponds to a specific homogeneous region of + * material. + */ + for (pp=part_headp->pt_forw; pp != part_headp; pp = pp->pt_forw) { + + /* print the name of the region we hit as well as the name of + * the primitives encountered on entry and exit. + */ + bu_log("\n--- Hit region %s (in %s, out %s)\n", + pp->pt_regionp->reg_name, + pp->pt_inseg->seg_stp->st_name, + pp->pt_outseg->seg_stp->st_name ); + + /* entry hit point, so we type less */ + hitp = pp->pt_inhit; + + /* construct the actual (entry) hit-point from the ray and the + * distance to the intersection point (i.e., the 't' value). + */ + VJOIN1(pt, ap->a_ray.r_pt, hitp->hit_dist, ap->a_ray.r_dir); + + /* primitive we encountered on entry */ + stp = pp->pt_inseg->seg_stp; + + /* compute the normal vector at the entry point, flipping the + * normal if necessary. + */ + RT_HIT_NORMAL(inormal, hitp, stp, &(ap->a_ray), pp->pt_inflip); + + /* print the entry hit point info */ + rt_pr_hit(" In", hitp); + VPRINT( " Ipoint", pt); + VPRINT( " Inormal", inormal); + + 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); + } + + /* This next macro fills in the curvature information which + * consists on a principle direction vector, and the inverse + * radii of curvature along that direction and perpendicular + * to it. Positive curvature bends toward the outward + * pointing normal. + */ + RT_CURVATURE(&cur, hitp, pp->pt_inflip, stp); + + /* print the entry curvature information */ + VPRINT("PDir", cur.crv_pdir); + bu_log(" c1=%g\n", cur.crv_c1); + bu_log(" c2=%g\n", cur.crv_c2); + + /* exit point, so we type less */ + hitp = pp->pt_outhit; + + /* construct the actual (exit) hit-point from the ray and the + * distance to the intersection point (i.e., the 't' value). + */ + VJOIN1(pt, ap->a_ray.r_pt, hitp->hit_dist, ap->a_ray.r_dir); + + /* primitive we exited from */ + stp = pp->pt_outseg->seg_stp; + + /* compute the normal vector at the exit point, flipping the + * normal if necessary. + */ + RT_HIT_NORMAL(onormal, hitp, stp, &(ap->a_ray), pp->pt_outflip); + + /* print the exit hit point info */ + rt_pr_hit(" Out", hitp); + VPRINT( " Opoint", pt); + VPRINT( " Onormal", onormal); + } + + return HIT; +} + + +int +if_miss(struct application *UNUSED(ap)) +{ + bu_log("MISS"); + return MISS; +} + + +/** + * I F _ O V E R L A P + * + * Default handler for overlaps in rt_boolfinal(). + * Returns - + * 0 to eliminate partition with overlap entirely + * !0 to retain partition in output list + * + */ +int +if_overlap(struct application *ap, struct partition *pp, struct region *reg1, struct region *reg2, struct partition *InputHdp) +{ + bu_log("OVERLAP"); + return rt_defoverlap (ap, pp, reg1, reg2, InputHdp); +} + + +int generate_manifolds(struct ged *gedp, struct simulation_params *sim_params) { struct sim_manifold *current_manifold; @@ -66,9 +205,75 @@ char *prefix_overlap = "overlap_"; struct bu_vls overlap_name = BU_VLS_INIT_ZERO; + /* Raytrace related stuff */ + struct rt_i *rtip; + struct application ap; + struct resource res_tab; + attr_table a_tab; + /* Add all sim objects to raytrace instance */ + /* Make a new rt_i instance from the existing db_i sructure */ + if ((rtip=rt_new_rti(gedp->ged_wdbp->dbip)) == RTI_NULL) { + bu_log("generate_manifolds: rt_new_rti failed while getting new rt instance\n"); + return GED_ERROR; + } + rtip->useair = 1; + /* Add all the sim objects to the rt_i + */ + for (rb = sim_params->head_node; rb != NULL; rb = rb->next) { + if (rt_gettree(rtip, rb->rb_namep) < 0) + bu_log("generate_manifolds: Failed to load geometry for [%s]\n", rb->rb_namep); + else + bu_log("generate_manifolds: Added [%s] to raytracer\n", rb->rb_namep); + } + + /* This next call causes some values to be pre-computed, sets up space + * partitioning, computes bounding volumes, etc. + */ + rt_prep_parallel(rtip, 1); + + bu_log("Simulation objects bounding box (%f, %f, %f):(%f,%f,%f)", + V3ARGS(rtip->mdl_min), V3ARGS(rtip->mdl_max)); + + /* Initialize the table of resource structures */ + rt_init_resource(&res_tab, 0, rtip); + + /* initialization of the application structure */ + RT_APPLICATION_INIT(&ap); + ap.a_hit = if_hit; /* branch to if_hit routine */ + ap.a_miss = if_miss; /* branch to if_miss routine */ + ap.a_overlap = if_overlap;/* branch to if_overlap routine */ + ap.a_logoverlap = rt_silent_logoverlap; + ap.a_onehit = 0; /* continue through shotline after hit */ + ap.a_resource = &res_tab; + ap.a_purpose = "Manifold ray"; + ap.a_rt_i = rtip; /* rt_i pointer */ + ap.a_zero1 = 0; /* sanity check, sayth raytrace.h */ + ap.a_zero2 = 0; /* sanity check, sayth raytrace.h */ + ap.a_uptr = (genptr_t)a_tab.attrib; + + /* Set the ray start point and direction rt_shootray() uses these + * two to determine what ray to fire. In this case we simply + * shoot down the z axis toward the origin from 10 meters away. + * + * It's worth nothing that librt assumes units of millimeters. + * All geometry is stored as millimeters regardless of the units + * set during editing. There are libbu routines for performing + * unit conversions if desired. + */ + VSET(ap.a_ray.r_pt, 1.0, 1.0, 0.0); + VSET(ap.a_ray.r_dir, -1.0, 0.0, 0.0); + + /* Simple debug printing */ + VPRINT("Pnt", ap.a_ray.r_pt); + VPRINT("Dir", ap.a_ray.r_dir); + + /* Shoot the ray. */ + (void)rt_shootray(&ap); + + /* Check all rigid bodies for overlaps using their manifold lists */ for (rb = sim_params->head_node; rb != NULL; rb = rb->next) { Modified: brlcad/trunk/src/libged/simulate/simrt.h =================================================================== --- brlcad/trunk/src/libged/simulate/simrt.h 2011-10-06 16:56:52 UTC (rev 47157) +++ brlcad/trunk/src/libged/simulate/simrt.h 2011-10-06 18:26:30 UTC (rev 47158) @@ -51,6 +51,11 @@ */ #define GRID_GRANULARITY 0.04 +typedef struct attributes { + int attrib_use; + int attrib_cnt; + char **attrib; +} attr_table; /** * Shoots rays within the AABB overlap regions only to allow more rays to be shot Modified: brlcad/trunk/src/libged/simulate/simulate.c =================================================================== --- brlcad/trunk/src/libged/simulate/simulate.c 2011-10-06 16:56:52 UTC (rev 47157) +++ brlcad/trunk/src/libged/simulate/simulate.c 2011-10-06 18:26:30 UTC (rev 47158) @@ -449,7 +449,11 @@ } /* Generate manifolds using rt */ - generate_manifolds(gedp, &sim_params); + rv = generate_manifolds(gedp, &sim_params); + if (rv != GED_OK) { + bu_vls_printf(gedp->ged_result_str, "%s: ERROR while calculating manifolds\n", argv[0]); + return GED_ERROR; + } free_manifold_lists(&sim_params); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity and more. Splunk takes this data and makes sense of it. Business sense. IT sense. Common sense. http://p.sf.net/sfu/splunk-d2dcopy1 _______________________________________________ BRL-CAD Source Commits mailing list brlcad-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/brlcad-commits