BRL-CAD
Loading...
Searching...
No Matches

Primitive manipulation functions from former functab callback table. More...

Collaboration diagram for Object API:

Files

file  func.h
 

Data Structures

struct  rt_crofton_params
 

Functions

int rt_obj_prep (struct soltab *stp, struct rt_db_internal *ip, struct rt_i *rtip)
 
int rt_obj_shot (struct soltab *stp, struct xray *rp, struct application *ap, struct seg *seghead)
 
int rt_obj_piece_shot (struct rt_piecestate *psp, struct rt_piecelist *plp, double dist_corr, struct xray *rp, struct application *ap, struct seg *seghead)
 
int rt_obj_piece_hitsegs (struct rt_piecestate *psp, struct seg *seghead, struct application *ap)
 
int rt_obj_print (const struct soltab *stp)
 
int rt_obj_norm (struct hit *hitp, struct soltab *stp, struct xray *rp)
 
int rt_obj_uv (struct application *ap, struct soltab *stp, struct hit *hitp, struct uvcoord *uvp)
 
int rt_obj_curve (struct curvature *cvp, struct hit *hitp, struct soltab *stp)
 
DEPRECATED int rt_obj_class (void)
 
int rt_obj_free (struct soltab *stp)
 
int rt_obj_plot (struct bu_list *vhead, struct rt_db_internal *ip, const struct bg_tess_tol *ttol, const struct bn_tol *tol)
 
int rt_obj_vshot (struct soltab *stp[], struct xray *rp[], struct seg *segp, int n, struct application *ap)
 
int rt_obj_tess (struct nmgregion **r, struct model *m, struct rt_db_internal *ip, const struct bg_tess_tol *ttol, const struct bn_tol *tol)
 
int rt_obj_tnurb (struct nmgregion **r, struct model *m, struct rt_db_internal *ip, const struct bn_tol *tol)
 
int rt_obj_import (struct rt_db_internal *ip, const struct bu_external *ep, const mat_t mat, const struct db_i *dbip)
 
int rt_obj_export (struct bu_external *ep, const struct rt_db_internal *ip, double local2mm, const struct db_i *dbip)
 
int rt_obj_ifree (struct rt_db_internal *ip)
 
int rt_obj_get (struct bu_vls *logstr, const struct rt_db_internal *ip, const char *attr)
 
int rt_obj_adjust (struct bu_vls *logstr, struct rt_db_internal *ip, int argc, const char **argv)
 
int rt_obj_describe (struct bu_vls *logstr, const struct rt_db_internal *ip, int verbose, double mm2local)
 
void rt_obj_make_labels (struct bu_vls *labels, const char *sep)
 
int rt_obj_make (const char *label, const point_t origin, double scale, struct rt_db_internal *ip)
 
int rt_obj_xform (struct rt_db_internal *op, const mat_t mat, struct rt_db_internal *ip, int release, struct db_i *dbip)
 
int rt_obj_params (struct pc_pc_set *ps, const struct rt_db_internal *ip)
 
int rt_obj_mirror (struct rt_db_internal *ip, const plane_t *plane)
 
int rt_obj_prep_serialize (struct soltab *stp, const struct rt_db_internal *ip, struct bu_external *external, size_t *version)
 
int rt_crofton_shoot (double *out_surf_area, double *out_volume, struct rt_i *rtip, const struct rt_crofton_params *params, const fastf_t *bbox_min, const fastf_t *bbox_max)
 
void rt_crofton_sample (fastf_t *area, fastf_t *vol, const struct rt_db_internal *ip, const struct rt_crofton_params *params)
 

Detailed Description

Primitive manipulation functions from former functab callback table.

As this is a relatively new set of interfaces, consider these functions preliminary (i.e. DEPRECATED) and subject to change until this message goes away.

Function Documentation

◆ rt_obj_prep()

int rt_obj_prep ( struct soltab stp,
struct rt_db_internal ip,
struct rt_i rtip 
)
extern

prep an object for ray tracing

◆ rt_obj_shot()

int rt_obj_shot ( struct soltab stp,
struct xray rp,
struct application ap,
struct seg seghead 
)
extern

shoot a ray at an object that has been prepped for ray tracing

◆ rt_obj_piece_shot()

int rt_obj_piece_shot ( struct rt_piecestate psp,
struct rt_piecelist plp,
double  dist_corr,
struct xray rp,
struct application ap,
struct seg seghead 
)
extern

TBD.

◆ rt_obj_piece_hitsegs()

int rt_obj_piece_hitsegs ( struct rt_piecestate psp,
struct seg seghead,
struct application ap 
)
extern

TBD.

◆ rt_obj_print()

int rt_obj_print ( const struct soltab stp)
extern

print an objects parameters in debug/diagnostic form

◆ rt_obj_norm()

int rt_obj_norm ( struct hit hitp,
struct soltab stp,
struct xray rp 
)
extern

calculate a normal on an object that has been hit via rt_shot()

◆ rt_obj_uv()

int rt_obj_uv ( struct application ap,
struct soltab stp,
struct hit hitp,
struct uvcoord uvp 
)
extern

calculate object uv parameterization for a given hit point

◆ rt_obj_curve()

int rt_obj_curve ( struct curvature cvp,
struct hit hitp,
struct soltab stp 
)
extern

calculate object curvature for a given hit point

◆ rt_obj_class()

DEPRECATED int rt_obj_class ( void  )
extern

DEPRECATED: Unimplemented.

◆ rt_obj_free()

int rt_obj_free ( struct soltab stp)
extern

release the memory used by a solid

◆ rt_obj_plot()

int rt_obj_plot ( struct bu_list vhead,
struct rt_db_internal ip,
const struct bg_tess_tol ttol,
const struct bn_tol tol 
)
extern

obtain a vlist wireframe representation of an object for plotting purposes

◆ rt_obj_vshot()

int rt_obj_vshot ( struct soltab stp[],
struct xray rp[],
struct seg segp,
int  n,
struct application ap 
)
extern

shoot an array of rays at a set of homogeneous objects.

◆ rt_obj_tess()

int rt_obj_tess ( struct nmgregion **  r,
struct model m,
struct rt_db_internal ip,
const struct bg_tess_tol ttol,
const struct bn_tol tol 
)
extern

tessellate an object (into NMG form)

◆ rt_obj_tnurb()

int rt_obj_tnurb ( struct nmgregion **  r,
struct model m,
struct rt_db_internal ip,
const struct bn_tol tol 
)
extern

tessellate an object (into NURBS NMG form)

◆ rt_obj_import()

int rt_obj_import ( struct rt_db_internal ip,
const struct bu_external ep,
const mat_t  mat,
const struct db_i dbip 
)
extern

v4/v5 object import from disk

◆ rt_obj_export()

int rt_obj_export ( struct bu_external ep,
const struct rt_db_internal ip,
double  local2mm,
const struct db_i dbip 
)
extern

v4/v5 object export to disk

◆ rt_obj_ifree()

int rt_obj_ifree ( struct rt_db_internal ip)
extern

free the internal representation of an object

◆ rt_obj_get()

int rt_obj_get ( struct bu_vls logstr,
const struct rt_db_internal ip,
const char attr 
)
extern

db object 'get' support, obtain a tcl list representation

◆ rt_obj_adjust()

int rt_obj_adjust ( struct bu_vls logstr,
struct rt_db_internal ip,
int  argc,
const char **  argv 
)
extern

db object 'adjust' support, modify a tcl list representation

◆ rt_obj_describe()

int rt_obj_describe ( struct bu_vls logstr,
const struct rt_db_internal ip,
int  verbose,
double  mm2local 
)
extern

describe an object in text form (used by the 'l' command)

◆ rt_obj_make_labels()

void rt_obj_make_labels ( struct bu_vls labels,
const char sep 
)
extern

Return to labels (separated by sep, defaulting to space if NULL) the set of type labels accepted by rt_obj_make(); sorted alphabetically. Caller's responsibility to free bu_vls.

◆ rt_obj_make()

int rt_obj_make ( const char label,
const point_t  origin,
double  scale,
struct rt_db_internal ip 
)
extern

create a 'default' object of the type named by label, scaled by scale and positioned at origin.

label is the user's type word ("sph", "rcc", "arb6", "tor", ...) and doubles as the variant selector for primitives with geometry aliases. Returns BRLCAD_OK on success, BRLCAD_ERROR otherwise.

◆ rt_obj_xform()

int rt_obj_xform ( struct rt_db_internal op,
const mat_t  mat,
struct rt_db_internal ip,
int  release,
struct db_i dbip 
)
extern

apply a matrix transformation to an object (translation, rotation, scale)

◆ rt_obj_params()

int rt_obj_params ( struct pc_pc_set ps,
const struct rt_db_internal ip 
)
extern

obtain parameters for an object in libpc form

◆ rt_obj_mirror()

int rt_obj_mirror ( struct rt_db_internal ip,
const plane_t plane 
)
extern

mirror an object about a plane

◆ rt_obj_prep_serialize()

int rt_obj_prep_serialize ( struct soltab stp,
const struct rt_db_internal ip,
struct bu_external external,
size_t version 
)
extern

if stp is prepped, serialize; otherwise, deserialize from external

◆ rt_crofton_shoot()

int rt_crofton_shoot ( double out_surf_area,
double out_volume,
struct rt_i rtip,
const struct rt_crofton_params params,
const fastf_t bbox_min,
const fastf_t bbox_max 
)
extern

Run the Cauchy-Crofton ray-sampling estimator on an already-prepared raytrace instance. The caller owns rtip and must call rt_free_rti after this function returns.

Parameters
out_surf_areaReceives the estimated surface area (mm^2).
out_volumeReceives the estimated volume (mm^3).
rtipPrepared raytrace instance (rt_prep_parallel must have been called first).
paramsStopping criteria. NULL or all-zero -> 2 000-ray default.
bbox_minOptional focused sampling bbox minimum. Pass NULL to derive the sampling sphere from prepared soltab extents.
bbox_maxOptional focused sampling bbox maximum. Pass NULL to derive the sampling sphere from prepared soltab extents.
Returns
The total number of ray-surface crossings accumulated during sampling (>= 0) on success; -1 on bad arguments. A return value of 0 means no geometry was intersected by the sampler.

Near-tolerance sliver geometry: CSG vs BoT divergence

The Cauchy-Crofton formula is mathematically exact for any well-defined solid, but its numerical result depends critically on how the underlying raytracer reports intersections. Two representations of what is intended to be the same geometry can yield radically different – and both internally consistent – surface-area estimates when the geometry contains a sub-tolerance sliver.

Anatomy of the sliver

Consider a window-frame region modelled as a base box minus a slightly smaller cutout box (the r.wind6 pattern in havoc.g). If the subtractor's face protrudes less than BN_TOL_DIST (0.0005 mm) past the base face, a thin sliver of near-zero thickness is present in the raw CSG description. The sliver has two large faces (the Z-faces of the cutout interior, each ~41 600 mm² for a 160 × 260 mm cutout) and a negligible edge band.

CSG raytracer behavior (boolweave filtering)

The BRL-CAD CSG Boolean evaluator (boolweave) discards any solid segment whose thickness is below BN_TOL_DIST. For a ray fired perpendicular to the sliver faces the two-segment chord through the sliver is 0.000340 mm thick – shorter than BN_TOL_DIST – so boolweave merges the entry and exit events and reports a MISS through that region.

For oblique rays, however, the apparent thickness grows with the secant of the angle from normal: chord = d / cos(θ). Once θ exceeds approximately 47° (for a 0.000340 mm gap and a 0.0005 mm tolerance) the sliver segment survives boolweave filtering and contributes two crossing events. Since the Crofton bounding sphere uniformly samples all directions, roughly 68% of solid angles subtend the sliver at angles steep enough to be counted. The result is that the CSG SA estimate converges to a value that is ~74% higher than the ideal clean-frame SA – not because sampling is insufficient, but because the CSG raytracer is correctly reflecting its own view of the geometry: the sliver is visible from the majority of directions but hidden from near-perpendicular directions. Denser sampling does not reduce this bias; experiments with up to 2 000 000 rays confirm that the CSG estimate is stable at ~89 900 mm² (vs an ideal of 51 520 mm²) within the first 500 000 rays and does not drift further regardless of sample count.

BoT raytracer behavior (per-triangle hits)

A triangle mesh (BoT) has no boolweave layer. Every ray that intersects a triangle face produces a hit event regardless of how thin the resulting segment is. A BoT tessellated from the raw CSG without any sliver correction therefore exposes both large sliver faces to the full Crofton hemisphere, converging to ~130 400 mm² – approximately the ideal frame SA plus both full sliver faces (51 520 + 2 × 41 600 ≈ 134 720 mm²).

Perturbed BoT (correct result)

The facetize command's variant-planning / perturb pass enlarges the subtractor just enough to eliminate the sub-tolerance sliver before Manifold performs its Boolean evaluation. The resulting BoT has no phantom interior faces and its Crofton SA converges to ~51 750 mm² – within 0.5% of the analytic ideal – typically in fewer than 64 000 rays (<0.1 s).

Summary table (measured, 200 × 300 × 8 mm frame,

gap = 0.000340 mm < BN_TOL_DIST = 0.0005 mm)

Representation Converged SA (mm²) vs ideal Stable by
CSG (raw, unperturbed) ~89 900 +74.5% ~500k rays
BoT (perturbed) ~51 750 +0.5% ~64k rays
BoT (no perturb) ~130 400 +153% ~32k rays

Design implication

The Crofton estimator is accurate and well-converged in all three cases; the divergence is caused by the geometry, not by sampling noise. When comparing a CSG Crofton SA against a BoT Crofton SA as a facetize quality check, geometry with sub-tolerance slivers will always produce a mismatch no matter how many rays are fired. For such geometry the volume estimate (which is insensitive to sliver SA: sliver volume is ~14 mm³ out of 147 200 mm³, or 0.01%) is a far more reliable cross-check metric.

◆ rt_crofton_sample()

void rt_crofton_sample ( fastf_t area,
fastf_t vol,
const struct rt_db_internal ip,
const struct rt_crofton_params params 
)
extern

Cauchy-Crofton surface-area and/or volume estimator for a primitive.

Creates a temporary in-memory raytrace of ip and fires random chord rays until the stopping criteria in params are satisfied (or all criteria are zero / params is NULL, in which case the 2 000-ray default is used). Stores the estimated surface area in *area (if non-NULL) and the estimated volume in *vol (if non-NULL).

This is the primary high-level entry point. Primitives that require controlled accuracy (e.g. TGC TEC case, triaxial ELL, EHY r1≠r2, HYP, superell, ETO/TOR spindle) should call this function directly with appropriate params. Callers that already have a prepared rt_i should call rt_crofton_shoot() instead.