BRL-CAD
submodel.c File Reference
#include "common.h"
#include <stddef.h>
#include <math.h>
#include <string.h>
#include "bio.h"
#include "bu/parallel.h"
#include "vmath.h"
#include "db.h"
#include "nmg.h"
#include "rtgeom.h"
#include "raytrace.h"
Include dependency graph for submodel.c:

Go to the source code of this file.

Data Structures

struct  submodel_specific
 
struct  submodel_gobetween
 
struct  goodies
 

Macros

#define RT_SUBMODEL_O(m)   bu_offsetof(struct rt_submodel_internal, m)
 
#define RT_SUBMODEL_SPECIFIC_MAGIC   0x73756253 /* subS */
 
#define RT_CK_SUBMODEL_SPECIFIC(_p)   BU_CKMAG(_p, RT_SUBMODEL_SPECIFIC_MAGIC, "submodel_specific")
 

Functions

int rt_submodel_prep (struct soltab *stp, struct rt_db_internal *ip, struct rt_i *rtip)
 
void rt_submodel_print (const struct soltab *stp)
 
int rt_submodel_a_miss (struct application *ap)
 
int rt_submodel_a_hit (struct application *ap, struct partition *PartHeadp, struct seg *segHeadp)
 
int rt_submodel_shot (struct soltab *stp, struct xray *rp, struct application *ap, struct seg *seghead)
 
void rt_submodel_norm (struct hit *hitp, struct soltab *stp, struct xray *rp)
 
void rt_submodel_curve (struct curvature *cvp, struct hit *hitp, struct soltab *stp)
 
void rt_submodel_uv (struct application *ap, struct soltab *stp, struct hit *hitp, struct uvcoord *uvp)
 
void rt_submodel_free (struct soltab *stp)
 
int rt_submodel_class (const struct soltab *stp, const fastf_t *min, const fastf_t *max, const struct bn_tol *tol)
 
HIDDEN union treert_submodel_wireframe_leaf (struct db_tree_state *tsp, const struct db_full_path *pathp, struct rt_db_internal *ip, void *client_data)
 
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)
 
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)
 
int rt_submodel_import4 (struct rt_db_internal *ip, const struct bu_external *ep, const fastf_t *mat, const struct db_i *dbip)
 
int rt_submodel_export4 (struct bu_external *ep, const struct rt_db_internal *ip, double local2mm, const struct db_i *dbip)
 
int rt_submodel_import5 (struct rt_db_internal *ip, const struct bu_external *ep, const fastf_t *mat, const struct db_i *dbip)
 
int rt_submodel_export5 (struct bu_external *ep, const struct rt_db_internal *ip, double local2mm, const struct db_i *dbip)
 
int rt_submodel_describe (struct bu_vls *str, const struct rt_db_internal *ip, int verbose, double mm2local)
 
void rt_submodel_ifree (struct rt_db_internal *ip)
 
int rt_submodel_params (struct pc_pc_set *ps, const struct rt_db_internal *ip)
 

Variables

const struct bu_structparse rt_submodel_parse []
 

Detailed Description

Intersect a ray with an entire subspace full of geometry, possibly included from another .g file, with a subordinate instance of LIBRT.

This solid is particularly useful when instancing millions of copies of a given complex object, such as a detailed tree.

Definition in file submodel.c.

Macro Definition Documentation

#define RT_SUBMODEL_O (   m)    bu_offsetof(struct rt_submodel_internal, m)

Definition at line 48 of file submodel.c.

#define RT_SUBMODEL_SPECIFIC_MAGIC   0x73756253 /* subS */

Definition at line 65 of file submodel.c.

Referenced by rt_submodel_prep().

#define RT_CK_SUBMODEL_SPECIFIC (   _p)    BU_CKMAG(_p, RT_SUBMODEL_SPECIFIC_MAGIC, "submodel_specific")

Function Documentation

int rt_submodel_prep ( struct soltab stp,
struct rt_db_internal ip,
struct rt_i rtip 
)

Given a pointer to a GED database record, and a transformation matrix, determine if this is a valid SUBMODEL, and if so, precompute various terms of the formula.

Returns - 0 SUBMODEL is OK !0 Error in description

Implicit return - A struct submodel_specific is created, and its address is stored in stp->st_specific for use by submodel_shot().

Definition at line 83 of file submodel.c.

References bu_ptbl::blen, bn_mat_inv(), bn_rotate_bbox(), BU_ALLOC, BU_GET, bu_log(), BU_PTBL_END, BU_PTBL_FOR, BU_PTBL_LEN, BU_PTBL_SET, bu_semaphore_acquire(), bu_semaphore_release(), BU_STR_EQUAL, bu_vls_addr(), bu_vls_strdup(), bu_vls_strlen(), directory::d_namep, db_close(), db_dirbuild(), db_is_directory_non_empty(), db_open(), DB_OPEN_READONLY, db_i::dbi_clients, db_i::dbi_filename, db_i::dbi_mf, DBI_NULL, DEBUG_DB, DEBUG_SOLIDS, bu_mapped_file::dont_restat, rt_db_internal::idb_ptr, submodel_specific::m2subm, submodel_specific::magic, rt_i::mdl_max, rt_i::mdl_min, rt_i::nsolids, RT_CK_DB_INTERNAL, RT_CK_RTI, RT_G_DEBUG, rt_gettrees(), rt_init_resource(), rt_new_rti(), rt_pr_cut_info(), rt_prep_parallel(), RT_SEM_MODEL, RT_SUBMODEL_SPECIFIC_MAGIC, rt_i::rti_dbip, rt_i::rti_dont_instance, rt_i::rti_hasty_prep, rt_i::rti_resources, rt_i::rti_space_partition, rt_i::rti_tol, rt_i::rti_treetop, rt_i::rti_ttol, rt_i::rti_uses, submodel_specific::rtip, soltab::st_aradius, soltab::st_bradius, soltab::st_center, soltab::st_dp, soltab::st_max, soltab::st_min, soltab::st_specific, submodel_specific::subm2m, and rt_i::useair.

Here is the call graph for this function:

void rt_submodel_print ( const struct soltab stp)

Definition at line 248 of file submodel.c.

References bn_mat_print(), bu_log(), bu_log_indent_delta(), submodel_specific::m2subm, RT_CK_SUBMODEL_SPECIFIC, rt_pr_soltab(), RT_VISIT_ALL_SOLTABS_END, RT_VISIT_ALL_SOLTABS_START, submodel_specific::rtip, soltab::st_specific, and submodel_specific::subm2m.

Here is the call graph for this function:

int rt_submodel_a_miss ( struct application ap)

Definition at line 270 of file submodel.c.

References RT_CK_APPLICATION.

Referenced by rt_submodel_shot().

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

Intersect a ray with a submodel. If an intersection occurs, a struct seg will be acquired and filled in.

Returns - 0 MISS >0 HIT

Definition at line 442 of file submodel.c.

References application::a_ray, application::a_resource, application::a_rt_i, BU_ALLOC, BU_ASSERT_LONG, BU_PTBL_END, BU_PTBL_GET, BU_PTBL_SET, code(), submodel_specific::m2subm, xray::r_dir, xray::r_pt, resource::re_cpu, RT_CK_RESOURCE, RT_CK_RTI, RT_CK_SOLTAB, RT_CK_SUBMODEL_SPECIFIC, rt_init_resource(), rt_shootray(), rt_submodel_a_hit(), rt_submodel_a_miss(), rt_i::rti_resources, submodel_specific::rtip, and soltab::st_specific.

Here is the call graph for this function:

void rt_submodel_norm ( struct hit hitp,
struct soltab stp,
struct xray rp 
)

Given ONE ray distance, return the normal and entry/exit point.

Definition at line 519 of file submodel.c.

References bu_log(), directory::d_namep, hit::hit_normal, hit::hit_surfno, xray::r_dir, RT_CK_HIT, and soltab::st_dp.

Here is the call graph for this function:

void rt_submodel_curve ( struct curvature cvp,
struct hit hitp,
struct soltab stp 
)

Return the curvature of the submodel.

Definition at line 542 of file submodel.c.

References bn_vec_ortho(), bu_log(), curvature::crv_c1, curvature::crv_c2, curvature::crv_pdir, hit::hit_normal, RT_CK_HIT, and RT_CK_SOLTAB.

Here is the call graph for this function:

void rt_submodel_uv ( struct application ap,
struct soltab stp,
struct hit hitp,
struct uvcoord uvp 
)

For a hit on the surface of an submodel, return the (u, v) coordinates of the hit point, 0 <= u, v <= 1. u = azimuth v = elevation

Definition at line 566 of file submodel.c.

References hit::hit_vpriv, RT_CK_APPLICATION, RT_CK_HIT, RT_CK_SOLTAB, uvcoord::uv_du, uvcoord::uv_dv, uvcoord::uv_u, uvcoord::uv_v, X, Y, and Z.

void rt_submodel_free ( struct soltab stp)

Definition at line 581 of file submodel.c.

References BU_CK_PTBL, bu_free(), BU_PTBL_FOR, BU_PUT, RT_CK_RESOURCE, RT_CK_RTI, RT_CK_SUBMODEL_SPECIFIC, rt_clean_resource(), rt_free_rti(), rt_uniresource, rt_i::rti_resources, submodel_specific::rtip, and soltab::st_specific.

Here is the call graph for this function:

int rt_submodel_class ( const struct soltab stp,
const fastf_t min,
const fastf_t max,
const struct bn_tol tol 
)

Definition at line 613 of file submodel.c.

References BN_CK_TOL, and RT_CK_SOLTAB.

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 
)

This routine must be prepared to run in parallel. This routine should be generally exported for other uses.

Definition at line 635 of file submodel.c.

References BN_CK_TOL, bu_free(), bu_log(), DB_FULL_PATH_CUR_DIR, db_path_to_string(), goodies::dbip, DEBUG_TREEWALK, rt_functab::ft_name, rt_functab::ft_plot, rt_db_internal::idb_meth, if(), OP_NOP, RT_CK_DB_INTERNAL, RT_CK_DBI, RT_CK_RESOURCE, RT_CK_TESS_TOL, RT_G_DEBUG, RT_GET_TREE, TREE_NULL, db_tree_state::ts_m, db_tree_state::ts_resp, db_tree_state::ts_tol, db_tree_state::ts_ttol, and goodies::vheadp.

Referenced by rt_submodel_plot().

Here is the call graph for this function:

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 
)

Not unlike mged/dodraw.c drawtrees()

Note: The submodel will be drawn entirely in one color (for mged, typically this is red), because we can't return a vlblock, only one vlist, which by definition, is all one color.

Definition at line 686 of file submodel.c.

References BU_CK_LIST_HEAD, bu_log(), bu_vls_addr(), bu_vls_strlen(), db_close(), db_dirbuild(), db_is_directory_non_empty(), db_open(), DB_OPEN_READONLY, db_walk_tree(), DBI_NULL, goodies::dbip, rt_db_internal::idb_ptr, RT_CK_DB_INTERNAL, RT_CK_DBI, rt_initial_tree_state, rt_submodel_wireframe_leaf(), db_tree_state::ts_m, db_tree_state::ts_mat, db_tree_state::ts_tol, db_tree_state::ts_ttol, and goodies::vheadp.

Here is the call graph for this function:

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 
)

Returns - -1 failure 0 OK. *r points to nmgregion that holds this tessellation.

Definition at line 754 of file submodel.c.

References rt_db_internal::idb_ptr, and RT_CK_DB_INTERNAL.

int rt_submodel_import4 ( struct rt_db_internal ip,
const struct bu_external ep,
const fastf_t mat,
const struct db_i dbip 
)

Import an SUBMODEL from the database format to the internal format. Apply modeling transformations as well.

Definition at line 774 of file submodel.c.

References bn_mat_identity, BU_ALLOC, BU_CK_EXTERNAL, bu_free(), bu_log(), bu_struct_parse(), bu_vls_free(), BU_VLS_INIT_ZERO, bu_vls_strcpy(), bu_vls_strlen(), bu_external::ext_buf, ID_NULL, ID_SUBMODEL, rt_db_internal::idb_major_type, rt_db_internal::idb_meth, rt_db_internal::idb_ptr, if(), OBJ, RT_CK_DB_INTERNAL, RT_CK_DBI, and RT_SUBMODEL_INTERNAL_MAGIC.

Here is the call graph for this function:

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

The name is added by the caller, in the usual place.

Definition at line 829 of file submodel.c.

References bu_calloc(), BU_CK_EXTERNAL, bu_strlcpy, bu_vls_addr(), bu_vls_free(), BU_VLS_INIT_ZERO, bu_vls_struct_print(), bu_external::ext_buf, bu_external::ext_nbytes, ID_SUBMODEL, rt_db_internal::idb_ptr, RT_CK_DB_INTERNAL, and RT_CK_DBI.

Here is the call graph for this function:

int rt_submodel_import5 ( struct rt_db_internal ip,
const struct bu_external ep,
const fastf_t mat,
const struct db_i dbip 
)

Import an SUBMODEL from the database format to the internal format. Apply modeling transformations as well.

Definition at line 863 of file submodel.c.

References bn_mat_identity, BU_ALLOC, BU_CK_EXTERNAL, bu_free(), bu_log(), bu_struct_parse(), bu_vls_free(), BU_VLS_INIT, BU_VLS_INIT_ZERO, bu_vls_strlen(), bu_vls_strncpy(), bu_external::ext_buf, bu_external::ext_nbytes, ID_NULL, ID_SUBMODEL, rt_db_internal::idb_major_type, rt_db_internal::idb_meth, rt_db_internal::idb_ptr, OBJ, RT_CK_DB_INTERNAL, RT_CK_DBI, and RT_SUBMODEL_INTERNAL_MAGIC.

Here is the call graph for this function:

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

The name is added by the caller, in the usual place.

Definition at line 914 of file submodel.c.

References bu_calloc(), BU_CK_EXTERNAL, bu_strlcpy, bu_vls_addr(), bu_vls_free(), BU_VLS_INIT_ZERO, bu_vls_strlen(), bu_vls_struct_print(), bu_external::ext_buf, bu_external::ext_nbytes, ID_SUBMODEL, rt_db_internal::idb_ptr, RT_CK_DB_INTERNAL, and RT_CK_DBI.

Here is the call graph for this function:

int rt_submodel_describe ( struct bu_vls str,
const struct rt_db_internal ip,
int  verbose,
double  mm2local 
)

Make human-readable formatted presentation of this solid. First line describes type of solid. Additional lines are indented one tab, and give parameter values.

Definition at line 944 of file submodel.c.

References bu_vls_addr(), bu_vls_printf(), bu_vls_strcat(), and rt_db_internal::idb_ptr.

Here is the call graph for this function:

void rt_submodel_ifree ( struct rt_db_internal ip)

Free the storage associated with the rt_db_internal version of this solid.

Definition at line 967 of file submodel.c.

References bu_free(), bu_vls_free(), DBI_NULL, rt_db_internal::idb_ptr, and RT_CK_DB_INTERNAL.

Here is the call graph for this function:

int rt_submodel_params ( struct pc_pc_set ps,
const struct rt_db_internal ip 
)

Definition at line 985 of file submodel.c.

References RT_CK_DB_INTERNAL.

Variable Documentation

const struct bu_structparse rt_submodel_parse[]
Initial value:
= {
{"%V", 1, "file", RT_SUBMODEL_O(file), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
{"%V", 1, "treetop", RT_SUBMODEL_O(treetop), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
{"%d", 1, "meth", RT_SUBMODEL_O(meth), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
{"", 0, (char *)0, 0, BU_STRUCTPARSE_FUNC_NULL, NULL, NULL }
}
#define BU_STRUCTPARSE_FUNC_NULL
Definition: parse.h:153
#define RT_SUBMODEL_O(m)
Definition: submodel.c:48

Definition at line 50 of file submodel.c.