BRL-CAD
#include "common.h"
#include <stddef.h>
#include <string.h>
#include <math.h>
#include "bio.h"
#include "bu/cv.h"
#include "vmath.h"
#include "db.h"
#include "nmg.h"
#include "rtgeom.h"
#include "raytrace.h"
#include "nurb.h"
#include "../../librt_private.h"
Include dependency graph for tgc.c:

Go to the source code of this file.

Data Structures

struct  tgc_specific
 
struct  ellipse
 
struct  tgc_pts
 

Macros

#define VLARGE   1000000.0
 
#define MAX_RATIO   10.0 /* maximum allowed height-to-width ration for triangles */
 
#define RAT   M_SQRT1_2
 
#define OUT   0
 
#define IN   1
 
#define TGC_NORM_BODY   (1) /* compute normal */
 
#define TGC_NORM_TOP   (2) /* copy tgc_N */
 
#define TGC_NORM_BOT   (3) /* copy reverse tgc_N */
 
#define RT_TGC_SEG_MISS(SEG)   (SEG).seg_stp=RT_SOLTAB_NULL
 
#define VEXCHANGE(a, b, tmp)   { VMOVE(tmp, a); VMOVE(a, b); VMOVE(b, tmp); }
 
#define ALPHA(x, y, c, d)   ((x)*(x)*(c) + (y)*(y)*(d))
 
#define GET_TGC_TYPE(type, a, b, c, d)
 

Functions

int rt_rec_prep (struct soltab *stp, struct rt_db_internal *ip, struct rt_i *rtip)
 
void rt_pt_sort (register fastf_t *t, int npts)
 
int rt_tgc_bbox (struct rt_db_internal *ip, point_t *min, point_t *max, const struct bn_tol *tol)
 
int rt_tgc_prep (struct soltab *stp, struct rt_db_internal *ip, struct rt_i *rtip)
 
void rt_tgc_print (register const struct soltab *stp)
 
int rt_tgc_shot (struct soltab *stp, register struct xray *rp, struct application *ap, struct seg *seghead)
 
void rt_tgc_vshot (struct soltab **stp, register struct xray **rp, struct seg *segp, int n, struct application *ap)
 
void rt_pt_sort (fastf_t t[], int npts)
 
void rt_tgc_norm (register struct hit *hitp, struct soltab *stp, register struct xray *rp)
 
void rt_tgc_uv (struct application *ap, struct soltab *stp, register struct hit *hitp, register struct uvcoord *uvp)
 
void rt_tgc_free (struct soltab *stp)
 
int rt_tgc_import4 (struct rt_db_internal *ip, const struct bu_external *ep, register const fastf_t *mat, const struct db_i *dbip)
 
int rt_tgc_export4 (struct bu_external *ep, const struct rt_db_internal *ip, double local2mm, const struct db_i *dbip)
 
int rt_tgc_import5 (struct rt_db_internal *ip, const struct bu_external *ep, register const fastf_t *mat, const struct db_i *dbip)
 
int rt_tgc_export5 (struct bu_external *ep, const struct rt_db_internal *ip, double local2mm, const struct db_i *dbip)
 
int rt_tgc_describe (struct bu_vls *str, const struct rt_db_internal *ip, int verbose, double mm2local)
 
void rt_tgc_ifree (struct rt_db_internal *ip)
 
int rt_tgc_adaptive_plot (struct rt_db_internal *ip, const struct rt_view_info *info)
 
int rt_tgc_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)
 
void rt_tgc_curve (register struct curvature *cvp, register struct hit *hitp, struct soltab *stp)
 
int rt_tgc_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_tgc_tnurb (struct nmgregion **r, struct model *m, struct rt_db_internal *ip, const struct bn_tol *tol)
 
int rt_tgc_params (struct pc_pc_set *ps, const struct rt_db_internal *ip)
 
void rt_tgc_volume (fastf_t *vol, const struct rt_db_internal *ip)
 
void rt_tgc_surf_area (fastf_t *area, const struct rt_db_internal *ip)
 
void rt_tgc_centroid (point_t *cent, const struct rt_db_internal *ip)
 

Variables

const struct bu_structparse rt_tgc_parse []
 

Detailed Description

Intersect a ray with a Truncated General Cone.

Method - TGC: solve quartic equation of cone and line

Definition in file tgc.c.

Macro Definition Documentation

#define VLARGE   1000000.0

Definition at line 79 of file tgc.c.

Referenced by rt_tgc_prep().

#define MAX_RATIO   10.0 /* maximum allowed height-to-width ration for triangles */

Definition at line 80 of file tgc.c.

Referenced by rt_tgc_tess().

#define RAT   M_SQRT1_2

Definition at line 81 of file tgc.c.

#define OUT   0

Definition at line 83 of file tgc.c.

Referenced by rt_tgc_vshot().

#define IN   1

Definition at line 84 of file tgc.c.

Referenced by rt_tgc_vshot().

#define TGC_NORM_BODY   (1) /* compute normal */

Definition at line 87 of file tgc.c.

Referenced by rt_tgc_curve(), rt_tgc_norm(), rt_tgc_shot(), rt_tgc_uv(), and rt_tgc_vshot().

#define TGC_NORM_TOP   (2) /* copy tgc_N */

Definition at line 88 of file tgc.c.

Referenced by rt_tgc_norm(), rt_tgc_shot(), rt_tgc_uv(), and rt_tgc_vshot().

#define TGC_NORM_BOT   (3) /* copy reverse tgc_N */

Definition at line 89 of file tgc.c.

Referenced by rt_tgc_norm(), rt_tgc_shot(), rt_tgc_uv(), and rt_tgc_vshot().

#define RT_TGC_SEG_MISS (   SEG)    (SEG).seg_stp=RT_SOLTAB_NULL

Definition at line 91 of file tgc.c.

Referenced by rt_tgc_vshot().

#define VEXCHANGE (   a,
  b,
  tmp 
)    { VMOVE(tmp, a); VMOVE(a, b); VMOVE(b, tmp); }

Definition at line 92 of file tgc.c.

Referenced by rt_tgc_prep().

#define ALPHA (   x,
  y,
  c,
 
)    ((x)*(x)*(c) + (y)*(y)*(d))

Definition at line 93 of file tgc.c.

Referenced by rt_tgc_shot(), and rt_tgc_vshot().

#define GET_TGC_TYPE (   type,
  a,
  b,
  c,
 
)
Value:
{ \
if (EQUAL((a), (b)) && EQUAL((c), (d))) { \
if (EQUAL((a), (c))) { \
(type) = RCC; \
} else { \
(type) = TRC; \
} \
} else { \
if (EQUAL((a), (c)) && EQUAL((b), (d))) { \
(type) = REC; \
} else { \
(type) = TEC; \
} \
} \
}
if(share_geom)
Definition: nmg_mod.c:3829

Definition at line 96 of file tgc.c.

Referenced by rt_tgc_centroid(), rt_tgc_surf_area(), and rt_tgc_volume().

Function Documentation

void rt_pt_sort ( register fastf_t t,
int  npts 
)

Referenced by rt_tgc_vshot().

int rt_tgc_bbox ( struct rt_db_internal ip,
point_t *  min,
point_t *  max,
const struct bn_tol tol 
)

Compute the bounding RPP for a truncated general cone

Definition at line 155 of file tgc.c.

References rt_db_internal::idb_ptr, and VSETALL.

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

Given the parameters (in vector form) of a truncated general cone, compute the constant terms and a transformation matrix needed for solving the intersection of a ray with the cone.

Also compute the return transformation for normals in the transformed space to the original space. This NOT the inverse of the transformation matrix (if you really want to know why, talk to Ed Davisson).

Definition at line 205 of file tgc.c.

References bn_mat_mul(), BU_GET, bu_log(), DEBUG_SOLIDS, rt_functab::ft_bbox, rt_db_internal::idb_ptr, NEAR_ZERO, RT_DOT_TOL, RT_G_DEBUG, RT_LEN_TOL, rt_rec_prep(), rt_i::rti_tol, SMALL, soltab::st_aradius, soltab::st_bradius, soltab::st_center, soltab::st_max, soltab::st_meth, soltab::st_min, soltab::st_specific, tgc_specific::tgc_A, tgc_specific::tgc_AAdCC, tgc_specific::tgc_AD_CB, tgc_specific::tgc_B, tgc_specific::tgc_BBdDD, tgc_specific::tgc_C, tgc_specific::tgc_CdAm1, tgc_specific::tgc_D, tgc_specific::tgc_DdBm1, tgc_specific::tgc_invRtShSc, tgc_specific::tgc_ScShR, tgc_specific::tgc_sH, tgc_specific::tgc_V, VEXCHANGE, VLARGE, VSET, X, Y, Z, and ZERO.

Here is the call graph for this function:

void rt_tgc_print ( register const struct soltab stp)
int rt_tgc_shot ( struct soltab stp,
register struct xray rp,
struct application ap,
struct seg seghead 
)

Intersect a ray with a truncated general cone, where all constant terms have been computed by rt_tgc_prep().

NOTE: All lines in this function are represented parametrically by a point, P(Px, Py, Pz) and a unit direction vector, D = iDx + jDy + kDz. Any point on a line can be expressed by one variable 't', where

X = Dx*t + Px, Y = Dy*t + Py, Z = Dz*t + Pz.

First, convert the line to the coordinate system of a "stan- dard" cone. This is a cone whose base lies in the X-Y plane, and whose H (now H') vector is lined up with the Z axis.

Then find the equation of that line and the standard cone as an equation in 't'. Solve the equation using a general polynomial root finder. Use those values of 't' to compute the points of intersection in the original coordinate system.

Definition at line 565 of file tgc.c.

References application::a_ray, application::a_resource, ALPHA, bn_pr_roots(), BU_LIST_INSERT, bu_log(), C, bn_poly::cf, directory::d_namep, bn_poly::dgr, seg::l, NEAR_ZERO, Q, R, xray::r_dir, xray::r_pt, bn_complex::re, RT_DOT_TOL, RT_GET_SEG, RT_PCOEF_TOL, rt_poly_roots(), soltab::st_dp, soltab::st_specific, tgc_specific::tgc_AAdCC, tgc_specific::tgc_AD_CB, tgc_specific::tgc_BBdDD, tgc_specific::tgc_CdAm1, tgc_specific::tgc_DdBm1, tgc_specific::tgc_N, TGC_NORM_BODY, TGC_NORM_BOT, TGC_NORM_TOP, tgc_specific::tgc_ScShR, tgc_specific::tgc_V, OSL::Strings::u, V3ARGS, VPRINT, X, Y, Z, and ZERO.

Here is the call graph for this function:

void rt_tgc_vshot ( struct soltab **  stp,
register struct xray **  rp,
struct seg segp,
int  n,
struct application ap 
)
void rt_tgc_norm ( register struct hit hitp,
struct soltab stp,
register struct xray rp 
)

Compute the normal to the cone, given a point on the STANDARD CONE centered at the origin of the X-Y plane.

The gradient of the cone at that point is the normal vector in the standard space. This vector will need to be transformed back to the coordinate system of the original cone in order to be useful. Then the transformed vector must be 'unitized.'

NOTE: The transformation required is NOT the inverse of the of the rotation to the standard cone, due to the shear involved in the mapping. The inverse maps points back to points, but it is the transpose which maps normals back to normals. If you really want to know why, talk to Ed Davisson or Peter Stiller.

The equation for the standard cone without scaling is: (rotated the sheared)

f(X, Y, Z) = X**2 * Q**2 + Y**2 * R**2 - R**2 * Q**2 = 0

where: R = a + ((c - a)/|H'|)*Z Q = b + ((d - b)/|H'|)*Z

When the equation is scaled so the A, B, and the sheared H are unit length, as is done here, the equation can be coerced back into this same form with R and Q now being:

R = 1 + (c/a - 1)*Z Q = 1 + (d/b - 1)*Z

The gradient of f(x, y, z) = 0 is:

df/dx = 2 * x * Q**2 df/dy = 2 * y * R**2 df/dz = x**2 * 2 * Q * dQ/dz + y**2 * 2 * R * dR/dz

  • R**2 * 2 * Q * dQ/dz - Q**2 * 2 * R * dR/dz = 2 [(x**2 - R**2) * Q * dQ/dz + (y**2 - Q**2) * R * dR/dz]

where: dR/dz = (c/a - 1) dQ/dz = (d/b - 1)

[in the unscaled case these would be: (c - a)/|H'| and (d - b)/|H'|]

Since the gradient (normal) needs to be rescaled to unit length after mapping back to absolute coordinates, we divide the 2 out of the above expressions.

Definition at line 1462 of file tgc.c.

References bu_log(), hit::hit_dist, hit::hit_normal, hit::hit_point, hit::hit_surfno, hit::hit_vpriv, Q, R, xray::r_dir, xray::r_pt, soltab::st_specific, tgc_specific::tgc_CdAm1, tgc_specific::tgc_DdBm1, tgc_specific::tgc_invRtShSc, tgc_specific::tgc_N, TGC_NORM_BODY, TGC_NORM_BOT, TGC_NORM_TOP, X, Y, and Z.

Here is the call graph for this function:

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

Definition at line 1504 of file tgc.c.

References hit::hit_point, hit::hit_surfno, if(), RT_CK_APPLICATION, soltab::st_specific, tgc_specific::tgc_A, tgc_specific::tgc_B, tgc_specific::tgc_C, tgc_specific::tgc_D, TGC_NORM_BODY, TGC_NORM_BOT, TGC_NORM_TOP, tgc_specific::tgc_ScShR, tgc_specific::tgc_V, uvcoord::uv_du, uvcoord::uv_dv, uvcoord::uv_u, uvcoord::uv_v, X, Y, and Z.

Here is the call graph for this function:

void rt_tgc_free ( struct soltab stp)

Definition at line 1560 of file tgc.c.

References BU_PUT, and soltab::st_specific.

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

Import a TGC from the database format to the internal format. Apply modeling transformations as well.

Definition at line 1574 of file tgc.c.

References bn_mat_identity, BU_ALLOC, BU_CK_EXTERNAL, bu_log(), db_i::dbi_version, bu_external::ext_buf, flip_fastf_float(), ID_TGC, 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_TGC_INTERNAL_MAGIC.

Here is the call graph for this function:

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

Definition at line 1616 of file tgc.c.

References bu_calloc(), BU_CK_EXTERNAL, bu_external::ext_buf, bu_external::ext_nbytes, ID_REC, ID_TGC, rt_db_internal::idb_ptr, RT_CK_DB_INTERNAL, and RT_CK_DBI.

Here is the call graph for this function:

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

Import a TGC from the database format to the internal format. Apply modeling transformations as well.

Definition at line 1653 of file tgc.c.

References bn_mat_identity, BU_ALLOC, BU_ASSERT_LONG, BU_CK_EXTERNAL, bu_cv_ntohd(), bu_external::ext_buf, bu_external::ext_nbytes, ID_TGC, rt_db_internal::idb_major_type, rt_db_internal::idb_meth, rt_db_internal::idb_ptr, OBJ, RT_CK_DB_INTERNAL, RT_CK_DBI, RT_TGC_INTERNAL_MAGIC, and SIZEOF_NETWORK_DOUBLE.

Here is the call graph for this function:

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

Definition at line 1691 of file tgc.c.

References BU_CK_EXTERNAL, bu_cv_htond(), bu_malloc(), bu_external::ext_buf, bu_external::ext_nbytes, ID_REC, ID_TGC, rt_db_internal::idb_ptr, RT_CK_DB_INTERNAL, RT_CK_DBI, and SIZEOF_NETWORK_DOUBLE.

Here is the call graph for this function:

int rt_tgc_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 1730 of file tgc.c.

References bu_vls_strcat(), rt_db_internal::idb_ptr, rt_find_fallback_angle(), rt_pr_fallback_angle(), X, Y, and Z.

Here is the call graph for this function:

void rt_tgc_ifree ( struct rt_db_internal ip)

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

Definition at line 1813 of file tgc.c.

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

Here is the call graph for this function:

int rt_tgc_adaptive_plot ( struct rt_db_internal ip,
const struct rt_view_info info 
)

Definition at line 1921 of file tgc.c.

References ellipse::axis_a, ellipse::axis_b, BN_VLIST_LINE_DRAW, BN_VLIST_LINE_MOVE, BU_CK_LIST_HEAD, bu_free(), bu_malloc(), ellipse::center, bn_tol::dist, ellipse_point_at_radian(), rt_db_internal::idb_ptr, plot_ellipse(), RT_ADD_VLIST, RT_CK_DB_INTERNAL, rt_view_info::tol, and rt_view_info::vhead.

Here is the call graph for this function:

int rt_tgc_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 at line 2013 of file tgc.c.

References BN_VLIST_LINE_DRAW, BN_VLIST_LINE_MOVE, BU_CK_LIST_HEAD, rt_db_internal::idb_ptr, RT_ADD_VLIST, RT_CK_DB_INTERNAL, rt_ell_16pts(), and top().

Here is the call graph for this function:

void rt_tgc_curve ( register struct curvature cvp,
register struct hit hitp,
struct soltab stp 
)

Return the curvature of the TGC.

Definition at line 2055 of file tgc.c.

References bn_eigen2x2(), bn_mat_mul(), bn_vec_ortho(), curvature::crv_c1, curvature::crv_c2, curvature::crv_pdir, hit::hit_normal, hit::hit_surfno, hit::hit_vpriv, if(), M, Q, R, soltab::st_specific, tgc_specific::tgc_CdAm1, tgc_specific::tgc_DdBm1, tgc_specific::tgc_invRtShSc, TGC_NORM_BODY, tgc_specific::tgc_ScShR, OSL::Strings::u, OSL::Strings::v, X, Y, and Z.

Here is the call graph for this function:

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

"Tessellate an TGC into a trimmed-NURB-NMG data structure. Computing NURB surfaces and trimming curves to interpolate the parameters of the TGC

The process is to create the nmg topology of the TGC fill it in with a unit cylinder geometry (i.e. unitcircle at the top (0, 0, 1) unit cylinder of radius 1, and unitcircle at the bottom), and then scale it with a perspective matrix derived from the parameters of the tgc. The result is three trimmed nurb surfaces which interpolate the parameters of the original TGC.

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

Definition at line 2820 of file tgc.c.

References bn_mat_mul(), BU_LIST_FIRST, BU_LIST_LAST, BU_LIST_NEXT, rt_db_internal::idb_ptr, lu, NMG_CK_LOOPUSE(), nmg_cmface(), nmg_je(), nmg_mrsv(), nmg_region_a(), nmg_vertexuse_a_cnurb(), RT_CK_DB_INTERNAL, s, and VSET.

Here is the call graph for this function:

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

Definition at line 3237 of file tgc.c.

References RT_CK_DB_INTERNAL.

void rt_tgc_volume ( fastf_t vol,
const struct rt_db_internal ip 
)

Definition at line 3246 of file tgc.c.

References bu_log(), GET_TGC_TYPE, rt_db_internal::idb_ptr, and M_PI.

Here is the call graph for this function:

void rt_tgc_surf_area ( fastf_t area,
const struct rt_db_internal ip 
)

Definition at line 3281 of file tgc.c.

References bu_log(), ELL_CIRCUMFERENCE, GET_TGC_TYPE, rt_db_internal::idb_ptr, and M_PI.

Here is the call graph for this function:

void rt_tgc_centroid ( point_t *  cent,
const struct rt_db_internal ip 
)

Definition at line 3324 of file tgc.c.

References bu_log(), GET_TGC_TYPE, and rt_db_internal::idb_ptr.

Here is the call graph for this function:

Variable Documentation

const struct bu_structparse rt_tgc_parse[]
Initial value:
= {
{ "%f", 3, "V", bu_offsetofarray(struct rt_tgc_internal, v, fastf_t, X), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
{ "%f", 3, "H", bu_offsetofarray(struct rt_tgc_internal, h, fastf_t, X), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
{ "%f", 3, "A", bu_offsetofarray(struct rt_tgc_internal, a, fastf_t, X), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
{ "%f", 3, "B", bu_offsetofarray(struct rt_tgc_internal, b, fastf_t, X), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
{ "%f", 3, "C", bu_offsetofarray(struct rt_tgc_internal, c, fastf_t, X), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
{ "%f", 3, "D", bu_offsetofarray(struct rt_tgc_internal, d, fastf_t, X), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
{ {'\0', '\0', '\0', '\0'}, 0, (char *)NULL, 0, BU_STRUCTPARSE_FUNC_NULL, NULL, NULL }
}
Definition: color.c:49
#define bu_offsetofarray(_t, _a, _d, _i)
Definition: parse.h:65
#define BU_STRUCTPARSE_FUNC_NULL
Definition: parse.h:153
double fastf_t
Definition: defines.h:300

Definition at line 114 of file tgc.c.