BRL-CAD
submodel.c
Go to the documentation of this file.
1 /* S U B M O D E L . C
2  * BRL-CAD
3  *
4  * Copyright (c) 2000-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 /** @addtogroup primitives */
21 /** @{ */
22 /** @file primitives/submodel/submodel.c
23  *
24  * Intersect a ray with an entire subspace full of geometry, possibly
25  * included from another .g file, with a subordinate instance of
26  * LIBRT.
27  *
28  * This solid is particularly useful when instancing millions of
29  * copies of a given complex object, such as a detailed tree.
30  *
31  */
32 /** @} */
33 
34 #include "common.h"
35 
36 #include <stddef.h>
37 #include <math.h>
38 #include <string.h>
39 #include "bio.h"
40 
41 #include "bu/parallel.h"
42 #include "vmath.h"
43 #include "db.h"
44 #include "nmg.h"
45 #include "rtgeom.h"
46 #include "raytrace.h"
47 
48 #define RT_SUBMODEL_O(m) bu_offsetof(struct rt_submodel_internal, m)
49 
51  {"%V", 1, "file", RT_SUBMODEL_O(file), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
52  {"%V", 1, "treetop", RT_SUBMODEL_O(treetop), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
53  {"%d", 1, "meth", RT_SUBMODEL_O(meth), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
54  {"", 0, (char *)0, 0, BU_STRUCTPARSE_FUNC_NULL, NULL, NULL }
55 };
56 
57 
58 /* ray tracing form of solid, including precomputed terms */
60  uint32_t magic;
61  mat_t subm2m; /* To transform normals back out to model coords */
62  mat_t m2subm; /* To transform rays into local coord sys */
63  struct rt_i *rtip; /* sub model */
64 };
65 #define RT_SUBMODEL_SPECIFIC_MAGIC 0x73756253 /* subS */
66 #define RT_CK_SUBMODEL_SPECIFIC(_p) BU_CKMAG(_p, RT_SUBMODEL_SPECIFIC_MAGIC, "submodel_specific")
67 
68 
69 /**
70  * Given a pointer to a GED database record, and a transformation matrix,
71  * determine if this is a valid SUBMODEL, and if so, precompute various
72  * terms of the formula.
73  *
74  * Returns -
75  * 0 SUBMODEL is OK
76  * !0 Error in description
77  *
78  * Implicit return -
79  * A struct submodel_specific is created, and its address is stored in
80  * stp->st_specific for use by submodel_shot().
81  */
82 int
83 rt_submodel_prep(struct soltab *stp, struct rt_db_internal *ip, struct rt_i *rtip)
84 {
85  struct rt_submodel_internal *sip;
86  struct submodel_specific *submodel;
87  struct rt_i *sub_rtip;
88  struct db_i *sub_dbip;
89  struct resource *resp;
90  vect_t radvec;
91  vect_t diam;
92  char *argv[2];
93  struct rt_i **rtipp;
94 
96  sip = (struct rt_submodel_internal *)ip->idb_ptr;
97  RT_SUBMODEL_CK_MAGIC(sip);
98 
100  /*
101  * This code must be prepared to run in parallel
102  * without tripping over itself.
103  */
104  if (bu_vls_strlen(&sip->file) == 0) {
105  /* No .g file name given, tree is in current .g file */
106  sub_dbip = rtip->rti_dbip;
107  } else {
108  /* db_open will cache dbip's via bu_open_mapped_file() */
109  if ((sub_dbip = db_open(bu_vls_addr(&sip->file), DB_OPEN_READONLY)) == DBI_NULL)
110  return -1;
111 
112  /* Save the overhead of stat() calls on subsequent opens */
113  if (sub_dbip->dbi_mf) sub_dbip->dbi_mf->dont_restat = 1;
114 
115  if (!db_is_directory_non_empty(sub_dbip)) {
116  /* This is first open of db, build directory */
117  if (db_dirbuild(sub_dbip) < 0) {
118  db_close(sub_dbip);
120  return -1;
121  }
122  }
123  }
124 
125  /*
126  * Search for a previous exact use of this file and treetop,
127  * so as to obtain storage efficiency from re-using it.
128  * Search dbi_client list for a re-use of an rt_i.
129  * rtip's are registered there by db_clone_dbi().
130  */
131  for (BU_PTBL_FOR(rtipp, (struct rt_i **), &sub_dbip->dbi_clients)) {
132  char *ttp;
133  RT_CK_RTI(*rtipp);
134  ttp = (*rtipp)->rti_treetop;
135  if (ttp && BU_STR_EQUAL(ttp, bu_vls_addr(&sip->treetop))) {
136  /* Re-cycle an already prepped rti */
137  sub_rtip = *rtipp;
138  sub_rtip->rti_uses++;
139 
141 
142  if (RT_G_DEBUG & (DEBUG_DB|DEBUG_SOLIDS)) {
143  bu_log("rt_submodel_prep(%s): Re-used already prepped database %s, rtip=%p\n",
144  stp->st_dp->d_namep,
145  sub_dbip->dbi_filename,
146  (void *)sub_rtip);
147  }
148  goto done;
149  }
150  }
151 
152  sub_rtip = rt_new_rti(sub_dbip); /* does db_clone_dbi() */
153  RT_CK_RTI(sub_rtip);
154 
155  /* Set search term before leaving critical section */
156  sub_rtip->rti_treetop = bu_vls_strdup(&sip->treetop);
157 
159 
160  if (RT_G_DEBUG & (DEBUG_DB|DEBUG_SOLIDS)) {
161  bu_log("rt_submodel_prep(%s): Opened database %s\n",
162  stp->st_dp->d_namep, sub_dbip->dbi_filename);
163  }
164 
165  /*
166  * Initialize per-processor resources for the submodel.
167  * We treewalk here with only one processor (CPU 0).
168  * db_walk_tree() as called from
169  * rt_gettrees() will pluck the 0th resource out of the rtip table.
170  * rt_submodel_shot() will get additional resources as needed.
171  */
172  BU_ALLOC(resp, struct resource);
173  BU_PTBL_SET(&sub_rtip->rti_resources, 0, resp);
174  rt_init_resource(resp, 0, sub_rtip);
175 
176  /* Propagate some important settings downward */
177  sub_rtip->useair = rtip->useair;
178  sub_rtip->rti_dont_instance = rtip->rti_dont_instance;
179  sub_rtip->rti_hasty_prep = rtip->rti_hasty_prep;
180  sub_rtip->rti_tol = rtip->rti_tol; /* struct copy */
181  sub_rtip->rti_ttol = rtip->rti_ttol; /* struct copy */
182 
183  if (sip->meth) {
184  sub_rtip->rti_space_partition = sip->meth;
185  } else {
186  sub_rtip->rti_space_partition = rtip->rti_space_partition;
187  }
188 
189  argv[0] = bu_vls_addr(&sip->treetop);
190  argv[1] = NULL;
191  if (rt_gettrees(sub_rtip, 1, (const char **)argv, 1) < 0) {
192  bu_log("submodel(%s) rt_gettrees(%s) failed\n", stp->st_name, argv[0]);
193  /* Can't call rt_free_rti(sub_rtip) because it may have
194  * already been instanced!
195  */
196  return -2;
197  }
198 
199  if (sub_rtip->nsolids <= 0) {
200  bu_log("rt_submodel_prep(%s): %s No primitives found\n",
201  stp->st_dp->d_namep, bu_vls_addr(&sip->file));
202  /* Can't call rt_free_rti(sub_rtip) because it may have
203  * already been instanced!
204  */
205  return -3;
206  }
207 
208  /* OK, it's going to work. Prep the submodel. */
209  /* Stay on 1 CPU because we're already multi-threaded at this point. */
210  rt_prep_parallel(sub_rtip, 1);
211 
212  /* Ensure bu_ptbl rti_resources is full size. Ptrs will be null */
213  if (BU_PTBL_LEN(&sub_rtip->rti_resources) < sub_rtip->rti_resources.blen) {
214  BU_PTBL_END(&sub_rtip->rti_resources) = sub_rtip->rti_resources.blen;
215  }
216 
217  if (RT_G_DEBUG) rt_pr_cut_info(sub_rtip, stp->st_name);
218 
219  done:
220  BU_GET(submodel, struct submodel_specific);
221  submodel->magic = RT_SUBMODEL_SPECIFIC_MAGIC;
222  stp->st_specific = (void *)submodel;
223 
224  MAT_COPY(submodel->subm2m, sip->root2leaf);
225  bn_mat_inv(submodel->m2subm, sip->root2leaf);
226  submodel->rtip = sub_rtip;
227 
228  /* Propagate submodel bounding box back upwards, rotated&scaled. */
229  bn_rotate_bbox(stp->st_min, stp->st_max,
230  submodel->subm2m,
231  sub_rtip->mdl_min, sub_rtip->mdl_max);
232 
233  VSUB2(diam, stp->st_max, stp->st_min);
234  VADD2SCALE(stp->st_center, stp->st_min, stp->st_max, 0.5);
235  VSCALE(radvec, diam, 0.5);
236  stp->st_aradius = stp->st_bradius = MAGNITUDE(radvec);
237 
238  if (RT_G_DEBUG & (DEBUG_DB|DEBUG_SOLIDS)) {
239  bu_log("rt_submodel_prep(%s): finished loading database %s\n",
240  stp->st_dp->d_namep, sub_dbip->dbi_filename);
241  }
242 
243  return 0; /* OK */
244 }
245 
246 
247 void
248 rt_submodel_print(const struct soltab *stp)
249 {
250  const struct submodel_specific *submodel =
251  (struct submodel_specific *)stp->st_specific;
252 
253  RT_CK_SUBMODEL_SPECIFIC(submodel);
254 
255  bn_mat_print("subm2m", submodel->subm2m);
256  bn_mat_print("m2subm", submodel->m2subm);
257 
259  bu_log("submodel->rtip=%p\n", (void *)submodel->rtip);
260 
261  /* Loop through submodel's solid table printing them too. */
262  RT_VISIT_ALL_SOLTABS_START(stp, submodel->rtip) {
263  rt_pr_soltab(stp);
266 }
267 
268 
269 int
271 {
272  if (ap) RT_CK_APPLICATION(ap);
273 
274  return 0;
275 }
276 
277 
280  struct seg *up_seghead;
281  struct soltab *up_stp;
282  fastf_t delta; /* distance offset */
283 };
284 
285 
286 int
287 rt_submodel_a_hit(struct application *ap, struct partition *PartHeadp, struct seg *UNUSED(segHeadp))
288 {
289  struct partition *pp;
290  struct application *up_ap;
291  struct soltab *up_stp;
292  struct region *up_reg;
293  struct submodel_gobetween *gp;
294  struct submodel_specific *submodel;
295  int count = 0;
296 
297  RT_AP_CHECK(ap);
298  RT_CK_PT_HD(PartHeadp);
299  gp = (struct submodel_gobetween *)ap->a_uptr;
300  up_ap = gp->up_ap;
301  RT_AP_CHECK(up_ap); /* original ap, in containing */
302  RT_CK_RTI(up_ap->a_rt_i);
303  up_stp = gp->up_stp;
304  RT_CK_SOLTAB(up_stp);
305  submodel = (struct submodel_specific *)up_stp->st_specific;
306  RT_CK_SUBMODEL_SPECIFIC(submodel);
307 
308  /* Take the first containing region */
309  up_reg = (struct region *)BU_PTBL_GET(&(up_stp->st_regions), 0);
310  RT_CK_REGION(up_reg);
311 
312  /* Need to tackle this honestly --
313  * build a totally new segment list from the partition list,
314  * with normals, uv, and curvature already computed,
315  * and converted back into up_model coordinate system,
316  * so the lazy-evaluation routines don't have to do anything.
317  * This is probably almost as cheap as the coordinate
318  * re-mapping in the special hook routines.
319  * Then the submodel can be stacked arbitrarily deep.
320  */
321  for (BU_LIST_FOR(pp, partition, (struct bu_list *)PartHeadp)) {
322  struct seg *up_segp;
323  struct seg *inseg;
324  struct seg *outseg;
325 
326  RT_CK_PT(pp);
327  inseg = pp->pt_inseg;
328  outseg = pp->pt_outseg;
329  RT_CK_SEG(inseg);
330  RT_CK_SEG(outseg);
331 
332  /*
333  * Construct a completely new segment
334  * build seg_in, seg_out, and seg_stp.
335  * Take seg_in and seg_out literally, to track surfno, etc.,
336  * then update specific values.
337  */
338  RT_GET_SEG(up_segp, up_ap->a_resource);
339  up_segp->seg_in = inseg->seg_in; /* struct copy */
340  up_segp->seg_out = outseg->seg_out; /* struct copy */
341  up_segp->seg_stp = up_stp;
342 
343  /* Adjust for scale difference */
344  MAT4XSCALOR(up_segp->seg_in.hit_dist, submodel->subm2m, inseg->seg_in.hit_dist);
345  up_segp->seg_in.hit_dist -= gp->delta;
346  MAT4XSCALOR(up_segp->seg_out.hit_dist, submodel->subm2m, outseg->seg_out.hit_dist);
347  up_segp->seg_out.hit_dist -= gp->delta;
348 
349  BU_ASSERT_DOUBLE(up_segp->seg_in.hit_dist, <=, up_segp->seg_out.hit_dist);
350 
351  /* Link to ray in upper model, not submodel */
352  up_segp->seg_in.hit_rayp = &up_ap->a_ray;
353  up_segp->seg_out.hit_rayp = &up_ap->a_ray;
354 
355  /* Pre-calculate what would have been "lazy evaluation" */
356  VJOIN1(up_segp->seg_in.hit_point, up_ap->a_ray.r_pt,
357  up_segp->seg_in.hit_dist, up_ap->a_ray.r_dir);
358  VJOIN1(up_segp->seg_out.hit_point, up_ap->a_ray.r_pt,
359  up_segp->seg_out.hit_dist, up_ap->a_ray.r_dir);
360 
361  /* RT_HIT_NORMAL */
362  inseg->seg_stp->st_meth->ft_norm(&inseg->seg_in, inseg->seg_stp, inseg->seg_in.hit_rayp);
363  outseg->seg_stp->st_meth->ft_norm(&outseg->seg_out, outseg->seg_stp, outseg->seg_out.hit_rayp);
364 
365  /* XXX error checking */
366  {
367  fastf_t cosine = fabs(VDOT(ap->a_ray.r_dir, inseg->seg_in.hit_normal));
368  if (cosine > 1.00001) {
369  bu_log("rt_submodel_a_hit() cos=1+%g, %s surfno=%d\n",
370  cosine-1,
371  inseg->seg_stp->st_dp->d_namep,
372  inseg->seg_in.hit_surfno);
373  VPRINT("inseg->seg_in.hit_normal", inseg->seg_in.hit_normal);
374  }
375  }
376  MAT3X3VEC(up_segp->seg_in.hit_normal, submodel->subm2m,
377  inseg->seg_in.hit_normal);
378 /* XXX error checking */
379  {
380  fastf_t cosine = fabs(VDOT(up_ap->a_ray.r_dir, up_segp->seg_in.hit_normal));
381  if (cosine > 1.00001) {
382  bu_log("rt_submodel_a_hit() cos=1+%g, %s surfno=%d\n",
383  cosine-1,
384  inseg->seg_stp->st_dp->d_namep,
385  inseg->seg_in.hit_surfno);
386  VPRINT("up_segp->seg_in.hit_normal", up_segp->seg_in.hit_normal);
387  }
388  }
389  MAT3X3VEC(up_segp->seg_out.hit_normal, submodel->subm2m,
390  outseg->seg_out.hit_normal);
391 
392  /* RT_HIT_UV */
393  {
394  struct uvcoord uv = {0.0, 0.0, 0.0, 0.0};
395  RT_HIT_UVCOORD(ap, inseg->seg_stp, &inseg->seg_in, &uv);
396  up_segp->seg_in.hit_vpriv[X] = uv.uv_u;
397  up_segp->seg_in.hit_vpriv[Y] = uv.uv_v;
398  if (uv.uv_du >= uv.uv_dv)
399  up_segp->seg_in.hit_vpriv[Z] = uv.uv_du;
400  else
401  up_segp->seg_in.hit_vpriv[Z] = uv.uv_dv;
402 
403  RT_HIT_UVCOORD(ap, outseg->seg_stp, &outseg->seg_out, &uv);
404  up_segp->seg_out.hit_vpriv[X] = uv.uv_u;
405  up_segp->seg_out.hit_vpriv[Y] = uv.uv_v;
406  if (uv.uv_du >= uv.uv_dv)
407  up_segp->seg_out.hit_vpriv[Z] = uv.uv_du;
408  else
409  up_segp->seg_out.hit_vpriv[Z] = uv.uv_dv;
410  }
411 
412  /* RT_HIT_CURVATURE */
413  /* no place to stash curvature data! */
414 
415  /*
416  * Here, the surfno reported upwards is the solid's
417  * index (bit) number in the submodel.
418  * This can be used as subscript to rti_Solids[]
419  * to retrieve the identity of the solid that was hit.
420  */
421  up_segp->seg_in.hit_surfno = inseg->seg_stp->st_bit;
422  up_segp->seg_out.hit_surfno = outseg->seg_stp->st_bit;
423 
424  /* Put this segment on caller's shot routine seglist */
425  BU_LIST_INSERT(&(gp->up_seghead->l), &(up_segp->l));
426  count++;
427  }
428  return count;
429 }
430 
431 
432 /**
433  * Intersect a ray with a submodel.
434  * If an intersection occurs, a struct seg will be acquired
435  * and filled in.
436  *
437  * Returns -
438  * 0 MISS
439  * >0 HIT
440  */
441 int
442 rt_submodel_shot(struct soltab *stp, struct xray *rp, struct application *ap, struct seg *seghead)
443 {
444  struct submodel_specific *submodel =
445  (struct submodel_specific *)stp->st_specific;
446  struct application sub_ap;
447  struct submodel_gobetween gb;
448  vect_t vdiff;
449  int code;
450  struct bu_ptbl *restbl;
451  struct resource *resp;
452  int cpu;
453 
454  RT_CK_SOLTAB(stp);
455  RT_CK_RTI(ap->a_rt_i);
456  RT_CK_SUBMODEL_SPECIFIC(submodel);
457 
458  gb.up_ap = ap;
459  gb.up_seghead = seghead;
460  gb.up_stp = stp;
461 
462  sub_ap = *ap; /* struct copy */
463  sub_ap.a_rt_i = submodel->rtip;
464  sub_ap.a_hit = rt_submodel_a_hit;
465  sub_ap.a_miss = rt_submodel_a_miss;
466  sub_ap.a_uptr = (void *)&gb;
467  sub_ap.a_purpose = "rt_submodel_shot";
468 
469  /* Ensure even # of accurate hits, for building good partitions */
470  if (sub_ap.a_onehit < 0) {
471  if (sub_ap.a_onehit&1) sub_ap.a_onehit--;
472  } else {
473  if (sub_ap.a_onehit&1) sub_ap.a_onehit++;
474  }
475 
476  /*
477  * Obtain the resource structure for this CPU.
478  * No need to semaphore because there is one pointer per cpu already.
479  */
480  restbl = &submodel->rtip->rti_resources; /* a ptbl */
481  cpu = ap->a_resource->re_cpu;
482  BU_ASSERT_LONG(cpu, <, BU_PTBL_END(restbl));
483  if ((resp = (struct resource *)BU_PTBL_GET(restbl, cpu)) == NULL) {
484  /* First ray for this cpu for this submodel, alloc up */
485  BU_ALLOC(resp, struct resource);
486  BU_PTBL_SET(restbl, cpu, resp);
487  rt_init_resource(resp, cpu, submodel->rtip);
488  }
489  RT_CK_RESOURCE(resp);
490  sub_ap.a_resource = resp;
491 
492  /* shootray already computed a_ray.r_min & r_max for us */
493  /* Construct the ray in submodel coords. */
494  /* Do this in a repeatable way */
495  /* Distances differ only by a scale factor of m[15] */
496  MAT4X3PNT(sub_ap.a_ray.r_pt, submodel->m2subm, ap->a_ray.r_pt);
497  MAT3X3VEC(sub_ap.a_ray.r_dir, submodel->m2subm, ap->a_ray.r_dir);
498 
499  /* NOTE: ap->a_ray.r_pt is not the same as rp->r_pt! */
500  /* This changes the distances */
501  VSUB2(vdiff, rp->r_pt, ap->a_ray.r_pt);
502  gb.delta = VDOT(vdiff, ap->a_ray.r_dir);
503 
504  code = rt_shootray(&sub_ap);
505 
506  if (code <= 0) return 0; /* MISS */
507 
508  /* All the real (sneaky) work is done in the hit routine */
509  /* a_hit routine will have added the segs to seghead */
510 
511  return 1; /* HIT */
512 }
513 
514 
515 /**
516  * Given ONE ray distance, return the normal and entry/exit point.
517  */
518 void
519 rt_submodel_norm(struct hit *hitp, struct soltab *stp, struct xray *rp)
520 {
521  RT_CK_HIT(hitp);
522 
523  /* hitp->hit_point is already valid */
524  /* hitp->hit_normal is already valid */
525 /* XXX error checking */
526  {
527  fastf_t cosine = fabs(VDOT(rp->r_dir, hitp->hit_normal));
528  if (cosine > 1.00001) {
529  bu_log("rt_submodel_norm() cos=1+%g, %s surfno=%d\n",
530  cosine-1,
531  stp->st_dp->d_namep,
532  hitp->hit_surfno);
533  }
534  }
535 }
536 
537 
538 /**
539  * Return the curvature of the submodel.
540  */
541 void
542 rt_submodel_curve(struct curvature *cvp, struct hit *hitp, struct soltab *stp)
543 {
544  if (!cvp || !hitp)
545  return;
546  RT_CK_HIT(hitp);
547  if (stp) RT_CK_SOLTAB(stp);
548 
549  cvp->crv_c1 = cvp->crv_c2 = 0;
550 
551  /* any tangent direction */
552  bn_vec_ortho(cvp->crv_pdir, hitp->hit_normal);
553 
554  /* XXX This will never be called */
555  bu_log("rt_submodel_curve() not implemented, need extra fields in 'struct hit'\n");
556 }
557 
558 
559 /**
560  * For a hit on the surface of an submodel, return the (u, v) coordinates
561  * of the hit point, 0 <= u, v <= 1.
562  * u = azimuth
563  * v = elevation
564  */
565 void
566 rt_submodel_uv(struct application *ap, struct soltab *stp, struct hit *hitp, struct uvcoord *uvp)
567 {
568  if (ap) RT_CK_APPLICATION(ap);
569  if (stp) RT_CK_SOLTAB(stp);
570  if (!hitp || !uvp)
571  return;
572  RT_CK_HIT(hitp);
573 
574  uvp->uv_u = hitp->hit_vpriv[X];
575  uvp->uv_v = hitp->hit_vpriv[Y];
576  uvp->uv_du = uvp->uv_dv = hitp->hit_vpriv[Z];
577 }
578 
579 
580 void
582 {
583  struct submodel_specific *submodel =
584  (struct submodel_specific *)stp->st_specific;
585  struct resource **rpp;
586  struct rt_i *rtip;
587 
588  RT_CK_SUBMODEL_SPECIFIC(submodel);
589  rtip = submodel->rtip;
590  RT_CK_RTI(rtip);
591 
592  /* Specifically free resource structures here */
594  for (BU_PTBL_FOR(rpp, (struct resource **), &rtip->rti_resources)) {
595  if (*rpp == NULL) continue;
596  if (*rpp == &rt_uniresource) continue;
597  RT_CK_RESOURCE(*rpp);
598  /* Cleans but does not free the resource struct */
599  rt_clean_resource(rtip, *rpp);
600  bu_free(*rpp, "struct resource (submodel)");
601  /* Forget remembered ptr */
602  *rpp = NULL;
603  }
604  /* Keep the ptbl allocated. */
605 
606  rt_free_rti(submodel->rtip);
607 
608  BU_PUT(submodel, struct submodel_specific);
609 }
610 
611 
612 int
613 rt_submodel_class(const struct soltab *stp, const fastf_t *min, const fastf_t *max, const struct bn_tol *tol)
614 {
615  if (stp) RT_CK_SOLTAB(stp);
616  if (tol) BN_CK_TOL(tol);
617  if (!min) return 0;
618  if (!max) return 0;
619 
620  return 0;
621 }
622 
623 
624 struct goodies {
625  struct db_i *dbip;
626  struct bu_list *vheadp;
627 };
628 
629 
630 /**
631  * This routine must be prepared to run in parallel.
632  * This routine should be generally exported for other uses.
633  */
634 HIDDEN union tree *
635 rt_submodel_wireframe_leaf(struct db_tree_state *tsp, const struct db_full_path *pathp, struct rt_db_internal *ip, void *UNUSED(client_data))
636 {
637  union tree *curtree;
638  struct goodies *gp;
639  int ret;
640 
641  RT_CK_TESS_TOL(tsp->ts_ttol);
642  BN_CK_TOL(tsp->ts_tol);
643  RT_CK_DB_INTERNAL(ip);
644  RT_CK_RESOURCE(tsp->ts_resp);
645 
646  gp = (struct goodies *)tsp->ts_m; /* hack */
647  if (gp)
648  RT_CK_DBI(gp->dbip);
649 
651  char *sofar = db_path_to_string(pathp);
652 
653  bu_log("rt_submodel_wireframe_leaf(%s) path=%s\n",
654  ip->idb_meth->ft_name, sofar);
655  bu_free((void *)sofar, "path string");
656  }
657 
658  ret = -1;
659  if (ip->idb_meth->ft_plot) {
660  ret = ip->idb_meth->ft_plot(gp->vheadp, ip, tsp->ts_ttol, tsp->ts_tol, NULL);
661  }
662  if (ret < 0) {
663  bu_log("rt_submodel_wireframe_leaf(%s): %s plot failure\n",
664  ip->idb_meth->ft_name,
665  DB_FULL_PATH_CUR_DIR(pathp)->d_namep);
666  return TREE_NULL; /* ERROR */
667  }
668 
669  /* Indicate success by returning something other than TREE_NULL */
670  RT_GET_TREE(curtree, tsp->ts_resp);
671  curtree->tr_op = OP_NOP;
672 
673  return curtree;
674 }
675 
676 
677 /**
678  * Not unlike mged/dodraw.c drawtrees()
679  *
680  * Note: The submodel will be drawn entirely in one color
681  * (for mged, typically this is red),
682  * because we can't return a vlblock, only one vlist,
683  * which by definition, is all one color.
684  */
685 int
686 rt_submodel_plot(struct bu_list *vhead, struct rt_db_internal *ip, const struct rt_tess_tol *ttol, const struct bn_tol *tol, const struct rt_view_info *UNUSED(info))
687 {
688  struct rt_submodel_internal *sip;
689  struct db_tree_state state;
690  int ret;
691  char *argv[2];
692  struct goodies good;
693 
694  BU_CK_LIST_HEAD(vhead);
695  RT_CK_DB_INTERNAL(ip);
696  sip = (struct rt_submodel_internal *)ip->idb_ptr;
697  RT_SUBMODEL_CK_MAGIC(sip);
698 
699  /* BU_LIST_INIT(vhead); */
700 
701  state = rt_initial_tree_state; /* struct copy */
702  state.ts_ttol = ttol;
703  state.ts_tol = tol;
704  MAT_COPY(state.ts_mat, sip->root2leaf);
705 
706  state.ts_m = (struct model **)&good; /* hack -- passthrough to rt_submodel_wireframe_leaf() */
707  good.vheadp = vhead;
708 
709  if (bu_vls_strlen(&sip->file) != 0) {
710  /* db_open will cache dbip's via bu_open_mapped_file() */
711  if ((good.dbip = db_open(bu_vls_addr(&sip->file), DB_OPEN_READONLY)) == DBI_NULL) {
712  bu_log("Cannot open geometry database file (%s) to store plot\n", bu_vls_addr(&sip->file));
713  return -1;
714  }
715  if (!db_is_directory_non_empty(good.dbip)) {
716  /* This is first open of this database, build directory */
717  if (db_dirbuild(good.dbip) < 0) {
718  bu_log("rt_submodel_plot() db_dirbuild() failure\n");
719  db_close(good.dbip);
720  return -1;
721  }
722  }
723  } else {
724  /* stash a pointer to the current database instance
725  * (should the dbi be cloned?)
726  */
727  RT_CK_DBI(sip->dbip);
728  good.dbip = (struct db_i *)sip->dbip; /* un-const-cast */
729  }
730 
731  argv[0] = bu_vls_addr(&sip->treetop);
732  argv[1] = NULL;
733  ret = db_walk_tree(good.dbip, 1, (const char **)argv,
734  1,
735  &state,
736  0, /* take all regions */
737  NULL, /* rt_submodel_wireframe_region_end */
739  (void *)NULL);
740 
741  if (ret < 0) bu_log("rt_submodel_plot() db_walk_tree(%s) failure\n", bu_vls_addr(&sip->treetop));
742  if (bu_vls_strlen(&sip->file) != 0)
743  db_close(good.dbip);
744  return ret;
745 }
746 
747 
748 /**
749  * Returns -
750  * -1 failure
751  * 0 OK. *r points to nmgregion that holds this tessellation.
752  */
753 int
754 rt_submodel_tess(struct nmgregion **r, struct model *m, struct rt_db_internal *ip, const struct rt_tess_tol *UNUSED(ttol), const struct bn_tol *UNUSED(tol))
755 {
756  struct rt_submodel_internal *sip;
757 
758  if (r) NMG_CK_REGION(*r);
759  if (m) NMG_CK_MODEL(m);
760  RT_CK_DB_INTERNAL(ip);
761 
762  sip = (struct rt_submodel_internal *)ip->idb_ptr;
763  RT_SUBMODEL_CK_MAGIC(sip);
764 
765  return -1;
766 }
767 
768 
769 /**
770  * Import an SUBMODEL from the database format to the internal format.
771  * Apply modeling transformations as well.
772  */
773 int
774 rt_submodel_import4(struct rt_db_internal *ip, const struct bu_external *ep, const fastf_t *mat, const struct db_i *dbip)
775 {
776  struct rt_submodel_internal *sip;
777  union record *rp;
778  struct bu_vls str = BU_VLS_INIT_ZERO;
779 
780  BU_CK_EXTERNAL(ep);
781  RT_CK_DBI(dbip);
782 
783  rp = (union record *)ep->ext_buf;
784  /* Check record type */
785  if (rp->u_id != DBID_STRSOL) {
786  bu_log("rt_submodel_import4: defective strsol record\n");
787  return -1;
788  }
789 
790  RT_CK_DB_INTERNAL(ip);
791  ip->idb_major_type = DB5_MAJORTYPE_BRLCAD;
792  ip->idb_type = ID_SUBMODEL;
793  ip->idb_meth = &OBJ[ID_SUBMODEL];
794  BU_ALLOC(ip->idb_ptr, struct rt_submodel_internal);
795 
796  sip = (struct rt_submodel_internal *)ip->idb_ptr;
797  sip->magic = RT_SUBMODEL_INTERNAL_MAGIC;
798  sip->dbip = dbip;
799 
800  if (mat == NULL) mat = bn_mat_identity;
801  MAT_COPY(sip->root2leaf, mat);
802 
803  bu_vls_strcpy(&str, rp->ss.ss_args);
804 
805  if (bu_struct_parse(&str, rt_submodel_parse, (char *)sip, NULL) < 0) {
806  bu_vls_free(&str);
807  fail:
808  bu_free((char *)sip, "rt_submodel_import4: sip");
809  ip->idb_type = ID_NULL;
810  ip->idb_ptr = (void *)NULL;
811  return -2;
812  }
813  bu_vls_free(&str);
814 
815  /* Check for reasonable values */
816  if (bu_vls_strlen(&sip->treetop) == 0) {
817  bu_log("rt_submodel_import4() treetop= must be specified\n");
818  goto fail;
819  }
820 
821  return 0; /* OK */
822 }
823 
824 
825 /**
826  * The name is added by the caller, in the usual place.
827  */
828 int
829 rt_submodel_export4(struct bu_external *ep, const struct rt_db_internal *ip, double UNUSED(local2mm), const struct db_i *dbip)
830 {
831  struct rt_submodel_internal *sip;
832  union record *rec;
833  struct bu_vls str = BU_VLS_INIT_ZERO;
834 
835  if (dbip) RT_CK_DBI(dbip);
836 
837  RT_CK_DB_INTERNAL(ip);
838  if (ip->idb_type != ID_SUBMODEL) return -1;
839  sip = (struct rt_submodel_internal *)ip->idb_ptr;
840  RT_SUBMODEL_CK_MAGIC(sip);
841 
842  BU_CK_EXTERNAL(ep);
843  ep->ext_nbytes = sizeof(union record)*DB_SS_NGRAN;
844  ep->ext_buf = (uint8_t *)bu_calloc(1, ep->ext_nbytes, "submodel external");
845  rec = (union record *)ep->ext_buf;
846 
847  bu_vls_struct_print(&str, rt_submodel_parse, (char *)sip);
848 
849  rec->ss.ss_id = DBID_STRSOL;
850  bu_strlcpy(rec->ss.ss_keyword, "submodel", sizeof(rec->ss.ss_keyword));
851  bu_strlcpy(rec->ss.ss_args, bu_vls_addr(&str), DB_SS_LEN);
852  bu_vls_free(&str);
853 
854  return 0;
855 }
856 
857 
858 /**
859  * Import an SUBMODEL from the database format to the internal format.
860  * Apply modeling transformations as well.
861  */
862 int
863 rt_submodel_import5(struct rt_db_internal *ip, const struct bu_external *ep, const fastf_t *mat, const struct db_i *dbip)
864 {
865  struct rt_submodel_internal *sip;
866  struct bu_vls str = BU_VLS_INIT_ZERO;
867 
868  if (dbip) RT_CK_DBI(dbip);
869 
870  BU_CK_EXTERNAL(ep);
871  RT_CK_DBI(dbip);
872 
873  RT_CK_DB_INTERNAL(ip);
874  ip->idb_major_type = DB5_MAJORTYPE_BRLCAD;
875  ip->idb_type = ID_SUBMODEL;
876  ip->idb_meth = &OBJ[ID_SUBMODEL];
877  BU_ALLOC(ip->idb_ptr, struct rt_submodel_internal);
878 
879  sip = (struct rt_submodel_internal *)ip->idb_ptr;
880  sip->magic = RT_SUBMODEL_INTERNAL_MAGIC;
881  BU_VLS_INIT(&sip->file);
882  BU_VLS_INIT(&sip->treetop);
883  sip->meth = 0;
884  if (mat == NULL) mat = bn_mat_identity;
885  MAT_COPY(sip->root2leaf, mat);
886  sip->dbip = dbip;
887 
888  bu_vls_strncpy(&str, (const char *)ep->ext_buf, ep->ext_nbytes);
889 
890  if (bu_struct_parse(&str, rt_submodel_parse, (char *)sip, NULL) < 0) {
891  bu_vls_free(&str);
892  fail:
893  bu_free((char *)sip, "rt_submodel_import4: sip");
894  ip->idb_type = ID_NULL;
895  ip->idb_ptr = (void *)NULL;
896  return -2;
897  }
898  bu_vls_free(&str);
899 
900  /* Check for reasonable values */
901  if (bu_vls_strlen(&sip->treetop) == 0) {
902  bu_log("rt_submodel_import4() treetop= must be specified\n");
903  goto fail;
904  }
905 
906  return 0; /* OK */
907 }
908 
909 
910 /**
911  * The name is added by the caller, in the usual place.
912  */
913 int
914 rt_submodel_export5(struct bu_external *ep, const struct rt_db_internal *ip, double UNUSED(local2mm), const struct db_i *dbip)
915 {
916  struct rt_submodel_internal *sip;
917  struct bu_vls str = BU_VLS_INIT_ZERO;
918 
919  if (dbip) RT_CK_DBI(dbip);
920 
921  RT_CK_DB_INTERNAL(ip);
922  if (ip->idb_type != ID_SUBMODEL) return -1;
923  sip = (struct rt_submodel_internal *)ip->idb_ptr;
924  RT_SUBMODEL_CK_MAGIC(sip);
925 
926  BU_CK_EXTERNAL(ep);
927  bu_vls_struct_print(&str, rt_submodel_parse, (char *)sip);
928  ep->ext_nbytes = bu_vls_strlen(&str);
929  ep->ext_buf = (uint8_t *)bu_calloc(1, ep->ext_nbytes, "submodel external");
930 
931  bu_strlcpy((char *)ep->ext_buf, bu_vls_addr(&str), ep->ext_nbytes);
932  bu_vls_free(&str);
933 
934  return 0;
935 }
936 
937 
938 /**
939  * Make human-readable formatted presentation of this solid.
940  * First line describes type of solid.
941  * Additional lines are indented one tab, and give parameter values.
942  */
943 int
944 rt_submodel_describe(struct bu_vls *str, const struct rt_db_internal *ip, int verbose, double UNUSED(mm2local))
945 {
946  struct rt_submodel_internal *sip = (struct rt_submodel_internal *)ip->idb_ptr;
947 
948  RT_SUBMODEL_CK_MAGIC(sip);
949  bu_vls_strcat(str, "instanced submodel (SUBMODEL)\n");
950 
951  if (!verbose)
952  return 0;
953 
954  bu_vls_printf(str, "\tfile='%s', treetop='%s', meth=%d\n",
955  bu_vls_addr(&sip->file),
956  bu_vls_addr(&sip->treetop),
957  sip->meth);
958 
959  return 0;
960 }
961 
962 
963 /**
964  * Free the storage associated with the rt_db_internal version of this solid.
965  */
966 void
968 {
969  struct rt_submodel_internal *sip;
970 
971  RT_CK_DB_INTERNAL(ip);
972 
973  sip = (struct rt_submodel_internal *)ip->idb_ptr;
974  RT_SUBMODEL_CK_MAGIC(sip);
975  sip->magic = 0; /* sanity */
976  bu_vls_free(&sip->file);
977  bu_vls_free(&sip->treetop);
978  sip->dbip = DBI_NULL;
979  bu_free((void *)sip, "submodel ifree");
980  ip->idb_ptr = ((void *)0); /* sanity */
981 }
982 
983 
984 int
985 rt_submodel_params(struct pc_pc_set *UNUSED(ps), const struct rt_db_internal *ip)
986 {
987  if (ip) RT_CK_DB_INTERNAL(ip);
988 
989  return 0; /* OK */
990 }
991 
992 
993 /*
994  * Local Variables:
995  * mode: C
996  * tab-width: 8
997  * indent-tabs-mode: t
998  * c-file-style: "stroustrup"
999  * End:
1000  * ex: shiftwidth=4 tabstop=8
1001  */
const struct bu_structparse rt_submodel_parse[]
Definition: submodel.c:50
void rt_pr_soltab(const struct soltab *stp)
char * d_namep
pointer to name string
Definition: raytrace.h:859
struct xray a_ray
Actual ray to be shot.
Definition: raytrace.h:1583
#define BU_LIST_FOR(p, structure, hp)
Definition: list.h:365
Definition: raytrace.h:800
struct model ** ts_m
ptr to ptr to NMG "model"
Definition: raytrace.h:1072
void bu_log(const char *,...) _BU_ATTR_PRINTF12
Definition: log.c:176
#define BU_LIST_INSERT(old, new)
Definition: list.h:183
void rt_submodel_uv(struct application *ap, struct soltab *stp, struct hit *hitp, struct uvcoord *uvp)
Definition: submodel.c:566
int rt_submodel_export5(struct bu_external *ep, const struct rt_db_internal *ip, double local2mm, const struct db_i *dbip)
Definition: submodel.c:914
const struct db_tree_state rt_initial_tree_state
Definition: globals.c:90
struct bu_list * vheadp
Definition: submodel.c:626
struct hit seg_in
IN information.
Definition: raytrace.h:370
int(* ft_plot)(struct bu_list *, struct rt_db_internal *, const struct rt_tess_tol *, const struct bn_tol *, const struct rt_view_info *)
Definition: raytrace.h:2096
Definition: list.h:118
const struct directory * st_dp
Directory entry of solid.
Definition: raytrace.h:436
point_t mdl_min
min corner of model bounding RPP
Definition: raytrace.h:1769
struct rt_i * rtip
Definition: submodel.c:63
HIDDEN union tree * rt_submodel_wireframe_leaf(struct db_tree_state *tsp, const struct db_full_path *pathp, struct rt_db_internal *ip, void *client_data)
Definition: submodel.c:635
#define RT_CK_APPLICATION(_p)
Definition: raytrace.h:1675
#define RT_CK_RTI(_p)
Definition: raytrace.h:1833
#define OP_NOP
Leaf with no effect.
Definition: raytrace.h:1132
vect_t crv_pdir
Principle direction.
Definition: raytrace.h:307
const mat_t bn_mat_identity
Matrix and vector functionality.
Definition: mat.c:46
fastf_t uv_u
Range 0..1.
Definition: raytrace.h:341
#define BU_PTBL_FOR(ip, cast, ptbl)
Definition: ptbl.h:125
void rt_free_rti(struct rt_i *rtip)
Definition: prep.c:156
struct soltab * seg_stp
pointer back to soltab
Definition: raytrace.h:372
#define ID_SUBMODEL
Instanced submodel.
Definition: raytrace.h:486
void bn_rotate_bbox(point_t omin, point_t omax, const mat_t mat, const point_t imin, const point_t imax)
Transform a bounding box (RPP) by the given 4x4 matrix. There are 8 corners to the bounding RPP...
int useair
1="air" regions are retained while prepping
Definition: raytrace.h:1756
void bu_vls_strcat(struct bu_vls *vp, const char *s)
Definition: vls.c:368
#define BU_PTBL_SET(ptbl, i, val)
Definition: ptbl.h:109
Definition: raytrace.h:215
#define RT_CK_SEG(_p)
Definition: raytrace.h:377
size_t rti_uses
for rt_submodel
Definition: raytrace.h:1817
void bu_semaphore_acquire(unsigned int i)
Definition: semaphore.c:180
Definition: pc.h:108
Definition: raytrace.h:368
#define BU_ASSERT_LONG(_lhs, _relation, _rhs)
Definition: defines.h:240
Definition: raytrace.h:248
fastf_t st_aradius
Radius of APPROXIMATING sphere.
Definition: raytrace.h:433
#define ID_NULL
Unused.
Definition: raytrace.h:458
void bu_vls_strncpy(struct bu_vls *vp, const char *s, size_t n)
Definition: vls.c:339
Header file for the BRL-CAD common definitions.
#define BU_CK_PTBL(_p)
Definition: ptbl.h:74
#define DB_FULL_PATH_CUR_DIR(_pp)
Definition: db_fullpath.h:51
struct seg * pt_outseg
OUT seg pointer.
Definition: raytrace.h:578
struct soltab * up_stp
Definition: submodel.c:281
void rt_submodel_curve(struct curvature *cvp, struct hit *hitp, struct soltab *stp)
Definition: submodel.c:542
struct resource * a_resource
dynamic memory resources
Definition: raytrace.h:1591
void bu_log_indent_delta(int delta)
Definition: log.c:54
int rt_submodel_describe(struct bu_vls *str, const struct rt_db_internal *ip, int verbose, double mm2local)
Definition: submodel.c:944
#define RT_CK_REGION(_p)
Definition: raytrace.h:559
int rti_space_partition
space partitioning method
Definition: raytrace.h:1763
#define HIDDEN
Definition: common.h:86
struct bu_mapped_file * dbi_mf
PRIVATE: Only in read-only mode.
Definition: raytrace.h:822
struct bu_list l
Definition: raytrace.h:369
Definition: ptbl.h:62
uint32_t magic
Definition: submodel.c:60
void rt_init_resource(struct resource *resp, int cpu_num, struct rt_i *rtip)
Definition: prep.c:585
long st_bit
solids bit vector index (const)
Definition: raytrace.h:439
if(share_geom)
Definition: nmg_mod.c:3829
#define RT_AP_CHECK(_ap)
Definition: raytrace.h:1685
int idb_major_type
Definition: raytrace.h:192
void bu_vls_free(struct bu_vls *vp)
Definition: vls.c:248
Definition: color.c:49
struct rt_i * a_rt_i
this librt instance
Definition: raytrace.h:1588
struct resource rt_uniresource
default. Defined in librt/globals.c
Definition: globals.c:41
#define RT_SUBMODEL_INTERNAL_MAGIC
Definition: magic.h:109
#define RT_G_DEBUG
Definition: raytrace.h:1718
vect_t hit_vpriv
PRIVATE vector for xxx_*()
Definition: raytrace.h:253
void bn_mat_print(const char *title, const mat_t m)
Definition: mat.c:81
#define RT_CK_DB_INTERNAL(_p)
Definition: raytrace.h:207
int rt_submodel_export4(struct bu_external *ep, const struct rt_db_internal *ip, double local2mm, const struct db_i *dbip)
Definition: submodel.c:829
#define BU_ALLOC(_ptr, _type)
Definition: malloc.h:223
void * bu_calloc(size_t nelem, size_t elsize, const char *str)
Definition: malloc.c:321
fastf_t st_bradius
Radius of BOUNDING sphere.
Definition: raytrace.h:434
fastf_t crv_c2
curvature in other direction
Definition: raytrace.h:309
#define RT_CK_HIT(_p)
Definition: raytrace.h:259
#define BU_PTBL_GET(ptbl, i)
Definition: ptbl.h:108
int rt_submodel_import5(struct rt_db_internal *ip, const struct bu_external *ep, const fastf_t *mat, const struct db_i *dbip)
Definition: submodel.c:863
void(* ft_norm)(struct hit *hitp, struct soltab *stp, struct xray *rp)
Definition: raytrace.h:2061
const struct rt_functab * idb_meth
for ft_ifree(), etc.
Definition: raytrace.h:194
fastf_t uv_dv
delta in v
Definition: raytrace.h:344
#define bu_strlcpy(dst, src, size)
Definition: str.h:60
int rt_submodel_plot(struct bu_list *vhead, struct rt_db_internal *ip, const struct rt_tess_tol *ttol, const struct bn_tol *tol, const struct rt_view_info *info)
Definition: submodel.c:686
void bn_mat_inv(mat_t output, const mat_t input)
#define TREE_NULL
Definition: raytrace.h:1181
#define RT_CK_TESS_TOL(_p)
Definition: raytrace.h:184
mat_t ts_mat
transform matrix
Definition: raytrace.h:1050
uint8_t * ext_buf
Definition: parse.h:216
#define BU_GET(_ptr, _type)
Definition: malloc.h:201
struct seg * pt_inseg
IN seg ptr (gives stp)
Definition: raytrace.h:576
point_t hit_point
DEPRECATED: Intersection point, use VJOIN1 hit_dist.
Definition: raytrace.h:251
point_t st_max
max X, Y, Z of bounding RPP
Definition: raytrace.h:438
struct bu_ptbl dbi_clients
PRIVATE: List of rtip's using this db_i.
Definition: raytrace.h:823
struct hit seg_out
OUT information.
Definition: raytrace.h:371
struct xray * hit_rayp
pointer to defining ray
Definition: raytrace.h:256
size_t bu_vls_strlen(const struct bu_vls *vp)
Definition: vls.c:189
#define RT_CK_SUBMODEL_SPECIFIC(_p)
Definition: submodel.c:66
void db_close(struct db_i *dbip)
char ft_name[17]
Definition: raytrace.h:2043
int rt_submodel_shot(struct soltab *stp, struct xray *rp, struct application *ap, struct seg *seghead)
Definition: submodel.c:442
#define UNUSED(parameter)
Definition: common.h:239
char * bu_vls_strdup(const struct bu_vls *vp)
Definition: vls.c:274
#define BU_PUT(_ptr, _type)
Definition: malloc.h:215
Support for uniform tolerances.
Definition: tol.h:71
#define BN_CK_TOL(_p)
Definition: tol.h:82
char * db_path_to_string(const struct db_full_path *pp)
Definition: db_fullpath.c:191
char * bu_vls_addr(const struct bu_vls *vp)
Definition: vls.c:111
void bu_vls_struct_print(struct bu_vls *vls, const struct bu_structparse *sdp, const char *base)
int rt_submodel_prep(struct soltab *stp, struct rt_db_internal *ip, struct rt_i *rtip)
Definition: submodel.c:83
struct resource * ts_resp
Per-CPU data.
Definition: raytrace.h:1074
struct bu_ptbl st_regions
ptrs to regions using this solid (const)
Definition: raytrace.h:440
#define BU_STRUCTPARSE_FUNC_NULL
Definition: parse.h:153
void bu_semaphore_release(unsigned int i)
Definition: semaphore.c:218
void rt_submodel_free(struct soltab *stp)
Definition: submodel.c:581
vect_t r_dir
Direction of ray (UNIT Length)
Definition: raytrace.h:219
#define BU_PTBL_LEN(ptbl)
Definition: ptbl.h:107
size_t blen
Definition: ptbl.h:65
struct bn_tol rti_tol
Math tolerances for this model.
Definition: raytrace.h:1765
int rti_hasty_prep
1=hasty prep, slower ray-trace
Definition: raytrace.h:1759
#define RT_SUBMODEL_SPECIFIC_MAGIC
Definition: submodel.c:65
struct rt_i * rt_new_rti(struct db_i *dbip)
Definition: prep.c:58
#define RT_CK_DBI(_p)
Definition: raytrace.h:829
#define RT_GET_SEG(p, res)
Definition: raytrace.h:379
void * idb_ptr
Definition: raytrace.h:195
HIDDEN int code(fastf_t x, fastf_t y)
Definition: clip.c:43
#define RT_VISIT_ALL_SOLTABS_END
Definition: raytrace.h:1850
point_t r_pt
Point at which ray starts.
Definition: raytrace.h:218
point_t st_min
min X, Y, Z of bounding RPP
Definition: raytrace.h:437
void rt_pr_cut_info(const struct rt_i *rtip, const char *str)
Definition: cut.c:2060
#define DEBUG_DB
5 Database debugging
Definition: raytrace.h:88
const struct rt_functab OBJ[]
Definition: table.c:159
#define RT_CK_RESOURCE(_p)
Definition: raytrace.h:1490
void rt_submodel_print(const struct soltab *stp)
Definition: submodel.c:248
#define BU_PTBL_END(ptbl)
Definition: ptbl.h:106
const struct rt_tess_tol * ts_ttol
Tessellation tolerance.
Definition: raytrace.h:1070
#define RT_VISIT_ALL_SOLTABS_START(_s, _rti)
Definition: raytrace.h:1845
struct db_i * dbip
Definition: submodel.c:625
#define DBI_NULL
Definition: raytrace.h:827
struct application * up_ap
Definition: submodel.c:279
void rt_submodel_norm(struct hit *hitp, struct soltab *stp, struct xray *rp)
Definition: submodel.c:519
void bn_vec_ortho(vect_t out, const vect_t in)
struct db_i * rti_dbip
prt to Database instance struct
Definition: raytrace.h:1774
size_t nsolids
total # of solids participating
Definition: raytrace.h:1783
point_t mdl_max
max corner of model bounding RPP
Definition: raytrace.h:1770
#define RT_CK_PT(_p)
Definition: raytrace.h:589
int db_is_directory_non_empty(const struct db_i *dbip)
Definition: db_lookup.c:39
void rt_clean_resource(struct rt_i *rtip, struct resource *resp)
Definition: prep.c:810
#define RT_GET_TREE(_tp, _res)
Definition: raytrace.h:1210
int bu_struct_parse(const struct bu_vls *in_vls, const struct bu_structparse *desc, const char *base, void *data)
Definition: parse.c:878
#define RT_CK_PT_HD(_p)
Definition: raytrace.h:591
#define RT_CK_SOLTAB(_p)
Definition: raytrace.h:453
int rt_submodel_import4(struct rt_db_internal *ip, const struct bu_external *ep, const fastf_t *mat, const struct db_i *dbip)
Definition: submodel.c:774
void bu_vls_printf(struct bu_vls *vls, const char *fmt,...) _BU_ATTR_PRINTF23
Definition: vls.c:694
#define DB_OPEN_READONLY
Definition: raytrace.h:3550
void * st_specific
-> ID-specific (private) struct
Definition: raytrace.h:435
fastf_t uv_du
delta in u
Definition: raytrace.h:343
int rt_submodel_a_miss(struct application *ap)
Definition: submodel.c:270
struct db_i * db_open(const char *name, const char *mode)
Definition: db_open.c:59
int rti_dont_instance
1=Don't compress instances of solids into 1 while prepping
Definition: raytrace.h:1758
#define BU_ASSERT_DOUBLE(_lhs, _relation, _rhs)
Definition: defines.h:279
fastf_t crv_c1
curvature in principle dir
Definition: raytrace.h:308
struct rt_tess_tol rti_ttol
Tessellation tolerance defaults.
Definition: raytrace.h:1766
Definition: color.c:51
void rt_prep_parallel(struct rt_i *rtip, int ncpu)
int rt_shootray(struct application *ap)
void * a_uptr
application-specific pointer
Definition: raytrace.h:1618
void bu_vls_strcpy(struct bu_vls *vp, const char *s)
Definition: vls.c:310
int hit_surfno
solid-specific surface indicator
Definition: raytrace.h:255
int re_cpu
processor number, for ID
Definition: raytrace.h:1442
#define RT_SEM_MODEL
Definition: raytrace.h:1733
int rt_gettrees(struct rt_i *rtip, int argc, const char **argv, int ncpus)
Definition: tree.c:888
int rt_submodel_a_hit(struct application *ap, struct partition *PartHeadp, struct seg *segHeadp)
Definition: submodel.c:287
void rt_submodel_ifree(struct rt_db_internal *ip)
Definition: submodel.c:967
void bu_free(void *ptr, const char *str)
Definition: malloc.c:328
vect_t hit_normal
DEPRECATED: Surface Normal at hit_point, use RT_HIT_NORMAL.
Definition: raytrace.h:252
#define BU_CK_LIST_HEAD(_p)
Definition: list.h:142
#define BU_CK_EXTERNAL(_p)
Definition: parse.h:224
int db_dirbuild(struct db_i *dbip)
Definition: db5_scan.c:301
#define RT_SUBMODEL_O(m)
Definition: submodel.c:48
int rt_submodel_params(struct pc_pc_set *ps, const struct rt_db_internal *ip)
Definition: submodel.c:985
struct bu_ptbl rti_resources
list of 'struct resource's encountered
Definition: raytrace.h:1811
const struct rt_functab * st_meth
pointer to per-solid methods
Definition: raytrace.h:428
#define BU_VLS_INIT_ZERO
Definition: vls.h:84
int db_walk_tree(struct db_i *dbip, int argc, const char **argv, int ncpu, const struct db_tree_state *init_state, int(*reg_start_func)(struct db_tree_state *, const struct db_full_path *, const struct rt_comb_internal *, void *client_data), union tree *(*reg_end_func)(struct db_tree_state *, const struct db_full_path *, union tree *, void *client_data), union tree *(*leaf_func)(struct db_tree_state *, const struct db_full_path *, struct rt_db_internal *, void *client_data), void *client_data)
size_t ext_nbytes
Definition: parse.h:210
#define DEBUG_TREEWALK
22 Database tree traversal
Definition: raytrace.h:107
int rt_submodel_tess(struct nmgregion **r, struct model *m, struct rt_db_internal *ip, const struct rt_tess_tol *ttol, const struct bn_tol *tol)
Definition: submodel.c:754
fastf_t hit_dist
dist from r_pt to hit_point
Definition: raytrace.h:250
HIDDEN void verbose(struct human_data_t *dude)
Definition: human.c:2008
struct seg * up_seghead
Definition: submodel.c:280
Definition: vls.h:56
int rt_submodel_class(const struct soltab *stp, const fastf_t *min, const fastf_t *max, const struct bn_tol *tol)
Definition: submodel.c:613
const struct bn_tol * ts_tol
Math tolerance.
Definition: raytrace.h:1071
char * dbi_filename
file name
Definition: raytrace.h:805
double fastf_t
Definition: defines.h:300
#define VPRINT(a, b)
Definition: raytrace.h:1881
#define RT_HIT_UVCOORD(ap, _stp, _hitp, uvp)
Definition: raytrace.h:346
#define DEBUG_SOLIDS
6 Print prep'ed solids
Definition: raytrace.h:89
Definition: color.c:50
fastf_t uv_v
Range 0..1.
Definition: raytrace.h:342
char * rti_treetop
bu_strduped, for rt_submodel rti's only
Definition: raytrace.h:1816
point_t st_center
Centroid of solid.
Definition: raytrace.h:432
#define BU_VLS_INIT(_vp)
Definition: vls.h:74
#define BU_STR_EQUAL(s1, s2)
Definition: str.h:126