g_tgc.c File Reference

#include "common.h"
#include <stddef.h>
#include <stdio.h>
#include <strings.h>
#include <math.h>
#include "machine.h"
#include "vmath.h"
#include "db.h"
#include "nmg.h"
#include "raytrace.h"
#include "rtgeom.h"
#include "./debug.h"
#include "nurb.h"
#include "noalias.h"

Include dependency graph for g_tgc.c:

Go to the source code of this file.

Data Structures

struct  tgc_specific
struct  tgc_pts

Defines

#define VLARGE   1000000.0
#define ALPHA(x, y, c, d)   ( (x)*(x)*(c) + (y)*(y)*(d) )
#define VEXCHANGE(a, b, tmp)   { VMOVE(tmp,a); VMOVE(a,b); VMOVE(b,tmp); }
#define TGC_MM(v)   VMINMAX( stp->st_min, stp->st_max, v );
#define TGC_NORM_BODY   (1)
#define TGC_NORM_TOP   (2)
#define TGC_NORM_BOT   (3)
#define RT_TGC_SEG_MISS(SEG)   (SEG).seg_stp=RT_SOLTAB_NULL
#define OUT   0
#define IN   1
#define MAX_RATIO   10.0
#define RAT   .707107

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_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 (register 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_class (void)
int rt_tgc_import (struct rt_db_internal *ip, const struct bu_external *ep, register const fastf_t *mat, const struct db_i *dbip)
int rt_tgc_export (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_plot (struct bu_list *vhead, struct rt_db_internal *ip, const struct rt_tess_tol *ttol, const struct bn_tol *tol)
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)

Variables

const struct bu_structparse rt_tgc_parse []
fastf_t nmg_tgc_unitcircle [36]
fastf_t nmg_uv_unitcircle [27]


Detailed Description

Intersect a ray with a Truncated General Cone.

Method - TGC: solve quartic equation of cone and line

Authors - Edwin O. Davisson (Analysis) Jeff Hanes (Programming) Gary Moss (Improvement) Mike Muuss (Optimization) Peter F. Stiller (Curvature) Phillip Dykstra (Curvature) Bill Homer (Vectorization) Paul Stay (Convert to tnurbs)

Source - SECAD/VLD Computing Consortium, Bldg 394 The U. S. Army Ballistic Research Laboratory Aberdeen Proving Ground, Maryland 21005

Definition in file g_tgc.c.


Define Documentation

#define VLARGE   1000000.0
 

Definition at line 100 of file g_tgc.c.

Referenced by rt_tgc_prep().

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

Definition at line 101 of file g_tgc.c.

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

Referenced by rt_tgc_prep().

#define TGC_MM  )     VMINMAX( stp->st_min, stp->st_max, v );
 

Referenced by rt_tgc_prep().

#define TGC_NORM_BODY   (1)
 

Definition at line 496 of file g_tgc.c.

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

#define TGC_NORM_TOP   (2)
 

Definition at line 497 of file g_tgc.c.

Referenced by rt_tgc_norm(), and rt_tgc_uv().

#define TGC_NORM_BOT   (3)
 

Definition at line 498 of file g_tgc.c.

Referenced by rt_tgc_norm(), and rt_tgc_uv().

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

Definition at line 895 of file g_tgc.c.

#define OUT   0
 

#define IN   1
 

#define MAX_RATIO   10.0
 

Definition at line 1909 of file g_tgc.c.

Referenced by rt_tgc_tess().

#define RAT   .707107
 

Definition at line 2812 of file g_tgc.c.


Function Documentation

void rt_pt_sort register fastf_t t,
int  npts
 

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

R T _ T G C _ P R E P

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 126 of file g_tgc.c.

References rt_tgc_internal::a, rt_tgc_internal::b, bn_mat_mul(), BU_GETSTRUCT, bu_log(), rt_tgc_internal::c, rt_tgc_internal::d, rt_tgc_internal::h, rt_db_internal::idb_ptr, LOCAL, MAGSQ, MAT4X3VEC, NEAR_ZERO, RT_DOT_TOL, RT_LEN_TOL, rt_rec_prep(), rt_reldiff(), RT_TGC_CK_MAGIC, SMALL, soltab::st_aradius, soltab::st_bradius, soltab::st_center, soltab::st_max, 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_MM, tgc_specific::tgc_ScShR, tgc_specific::tgc_sH, tgc_specific::tgc_V, rt_tgc_internal::v, VADD2, VADD3, VCROSS, VDOT, VEXCHANGE, VLARGE, VMOVE, VREVERSE, VSET, VSUB2, X, Y, and Z.

Here is the call graph for this function:

void rt_tgc_print register const struct soltab stp  ) 
 

R T _ T G C _ P R I N T

Definition at line 468 of file g_tgc.c.

References bn_mat_print(), bu_log(), 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_N, tgc_specific::tgc_ScShR, tgc_specific::tgc_sH, tgc_specific::tgc_V, and VPRINT.

Here is the call graph for this function:

int rt_tgc_shot struct soltab stp,
register struct xray rp,
struct application ap,
struct seg seghead
 

R T _ T G C _ S H O T

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 525 of file g_tgc.c.

References bu_log(), LOCAL, MAGNITUDE, MAT4X3VEC, NEAR_ZERO, R, RT_PCOEF_TOL, SMALL_FASTF, soltab::st_specific, tgc_specific::tgc_ScShR, tgc_specific::tgc_V, V3ARGS, VDOT, VJOIN1, VSCALE, VSUB2, and Z.

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
 

R T _ T G C _ V S H O T

The Homer vectorized version.

Definition at line 903 of file g_tgc.c.

References bu_malloc(), LOCAL, MAGNITUDE, MAT4X3VEC, NEAR_ZERO, R, RT_PCOEF_TOL, tgc_specific::tgc_AD_CB, tgc_specific::tgc_CdAm1, tgc_specific::tgc_DdBm1, tgc_specific::tgc_ScShR, tgc_specific::tgc_V, VDOT, VMOVE, VSCALE, VSUB2, X, and Y.

Here is the call graph for this function:

void rt_tgc_norm register struct hit hitp,
struct soltab stp,
register struct xray rp
 

R T _ T G C _ N O R M

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 1416 of file g_tgc.c.

References bu_log(), FAST, LOCAL, MAT4X3VEC, R, 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, VJOIN1, VMOVE, VREVERSE, VUNITIZE, X, and Y.

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
 

R T _ T G C _ U V

Definition at line 1459 of file g_tgc.c.

References bn_twopi, FAST, LOCAL, MAT4X3VEC, 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, VSUB2, X, and Y.

void rt_tgc_free struct soltab stp  ) 
 

R T _ T G C _ F R E E

Definition at line 1516 of file g_tgc.c.

References bu_free(), and soltab::st_specific.

Here is the call graph for this function:

int rt_tgc_class void   ) 
 

Definition at line 1525 of file g_tgc.c.

int rt_tgc_import struct rt_db_internal ip,
const struct bu_external ep,
register const fastf_t mat,
const struct db_i dbip
 

R T _ T G C _ I M P O R T

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

Definition at line 1538 of file g_tgc.c.

References rt_tgc_internal::a, rt_tgc_internal::b, BU_CK_EXTERNAL, bu_log(), bu_malloc(), rt_tgc_internal::c, rt_tgc_internal::d, DB5_MAJORTYPE_BRLCAD, bu_external::ext_buf, rt_tgc_internal::h, ID_SOLID, ID_TGC, rt_db_internal::idb_major_type, rt_db_internal::idb_meth, rt_db_internal::idb_ptr, LOCAL, rt_tgc_internal::magic, MAT4X3PNT, MAT4X3VEC, RT_CK_DB_INTERNAL, rt_fastf_float(), RT_TGC_INTERNAL_MAGIC, record::s, record::solidrec::s_values, record::u_id, and rt_tgc_internal::v.

Here is the call graph for this function:

int rt_tgc_export struct bu_external ep,
const struct rt_db_internal ip,
double  local2mm,
const struct db_i dbip
 

R T _ T G C _ E X P O R T

Definition at line 1578 of file g_tgc.c.

References rt_tgc_internal::a, rt_tgc_internal::b, bu_calloc(), BU_CK_EXTERNAL, rt_tgc_internal::c, rt_tgc_internal::d, bu_external::ext_buf, bu_external::ext_nbytes, GENTGC, rt_tgc_internal::h, ID_REC, ID_SOLID, ID_TGC, rt_db_internal::idb_ptr, RT_CK_DB_INTERNAL, RT_TGC_CK_MAGIC, record::s, record::solidrec::s_id, record::solidrec::s_type, record::solidrec::s_values, rt_tgc_internal::v, and VSCALE.

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
 

R T _ T G C _ I M P O R T 5

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

Definition at line 1614 of file g_tgc.c.

References rt_tgc_internal::a, rt_tgc_internal::b, BU_ASSERT_LONG, BU_CK_EXTERNAL, bu_malloc(), rt_tgc_internal::c, rt_tgc_internal::d, DB5_MAJORTYPE_BRLCAD, bu_external::ext_buf, bu_external::ext_nbytes, rt_tgc_internal::h, ID_TGC, rt_db_internal::idb_major_type, rt_db_internal::idb_meth, rt_db_internal::idb_ptr, rt_tgc_internal::magic, MAT4X3PNT, MAT4X3VEC, ntohd(), RT_CK_DB_INTERNAL, RT_TGC_INTERNAL_MAGIC, SIZEOF_NETWORK_DOUBLE, and rt_tgc_internal::v.

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
 

R T _ T G C _ E X P O R T 5

Definition at line 1650 of file g_tgc.c.

References rt_tgc_internal::a, rt_tgc_internal::b, BU_CK_EXTERNAL, bu_malloc(), rt_tgc_internal::c, rt_tgc_internal::d, bu_external::ext_buf, bu_external::ext_nbytes, rt_tgc_internal::h, htond(), ID_REC, ID_TGC, rt_db_internal::idb_ptr, RT_CK_DB_INTERNAL, RT_TGC_CK_MAGIC, SIZEOF_NETWORK_DOUBLE, rt_tgc_internal::v, and VSCALE.

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
 

R T _ T G C _ D E S C R I B E

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 1686 of file g_tgc.c.

References bu_vls_strcat(), rt_db_internal::idb_ptr, INTCLAMP, MAGNITUDE, rt_find_fallback_angle(), rt_pr_fallback_angle(), RT_TGC_CK_MAGIC, VCROSS, VDIVIDE_TOL, VSCALE, VUNITIZE, X, and Y.

Here is the call graph for this function:

void rt_tgc_ifree struct rt_db_internal ip  ) 
 

R T _ T G C _ I F R E E

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

Definition at line 1768 of file g_tgc.c.

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

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
 

R T _ T G C _ P L O T

Definition at line 1779 of file g_tgc.c.

References rt_tgc_internal::a, rt_tgc_internal::b, BN_VLIST_LINE_DRAW, BN_VLIST_LINE_MOVE, rt_tgc_internal::c, rt_tgc_internal::d, ELEMENTS_PER_VECT, rt_tgc_internal::h, rt_db_internal::idb_ptr, LOCAL, RT_ADD_VLIST, RT_CK_DB_INTERNAL, rt_ell_16pts(), RT_TGC_CK_MAGIC, top(), rt_tgc_internal::v, and VADD2.

Here is the call graph for this function:

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

R T _ T G C _ C U R V E

Return the curvature of the TGC.

Definition at line 1821 of file g_tgc.c.

References bn_eigen2x2(), bn_mat_mul(), bn_vec_ortho(), M, MAGNITUDE, MAT4X3VEC, MAT_IDN, R, soltab::st_specific, tgc_specific::tgc_CdAm1, tgc_specific::tgc_DdBm1, tgc_specific::tgc_invRtShSc, TGC_NORM_BODY, tgc_specific::tgc_ScShR, VCOMB2, VCROSS, VDOT, VUNITIZE, X, and Y.

Here is the call graph for this function:

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
 

Definition at line 1913 of file g_tgc.c.

References A, rt_tgc_internal::a, rt_tess_tol::abs, rt_tgc_internal::b, bn_halfpi, bn_pi, bu_log(), bu_malloc(), rt_tgc_internal::c, rt_tgc_internal::d, bn_tol::dist, rt_tgc_internal::h, rt_db_internal::idb_ptr, int, MAGNITUDE, MAX_FASTF, MAX_RATIO, rt_tess_tol::norm, rt_tess_tol::rel, RT_CK_DB_INTERNAL, RT_TGC_CK_MAGIC, VCROSS, VDOT, VJOIN2, VMOVE, and VSCALE.

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
 

R T _ T G C _ T N U R B

"Tessellate an TGC into a trimmed-NURB-NMG data structure. Computing NRUB 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 unitcirlce at the bottom), and then scale it with a perspective matrix derived from the parameters of the tgc. The result is three trimmed nub surfaces which interpolate the parameters of the original TGC.

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

Definition at line 2653 of file g_tgc.c.

References rt_tgc_internal::a, rt_tgc_internal::b, bn_mat_mul(), BU_LIST_FIRST, BU_LIST_LAST, BU_LIST_NEXT, rt_tgc_internal::c, rt_tgc_internal::d, loopuse::down_hd, edgeuse::eumate_p, rt_tgc_internal::h, rt_db_internal::idb_ptr, edgeuse::l, LOCAL, faceuse::lu_hd, MAGNITUDE, MAT_IDN, NMG_CK_EDGEUSE, NMG_CK_LOOPUSE, nmg_cmface(), nmg_je(), nmg_mrsv(), nmg_region_a(), nmg_vertexuse_a_cnurb(), NULL, RT_CK_DB_INTERNAL, RT_TGC_CK_MAGIC, rt_tgc_internal::v, VCROSS, VMOVE, VSET, edgeuse::vu_p, and VUNITIZE.

Here is the call graph for this function:


Variable Documentation

const struct bu_structparse rt_tgc_parse[]
 

Initial value:

 {
    { "%f", 3, "V", bu_offsetof(struct rt_tgc_internal, v[X]), BU_STRUCTPARSE_FUNC_NULL },
    { "%f", 3, "H", bu_offsetof(struct rt_tgc_internal, h[X]), BU_STRUCTPARSE_FUNC_NULL },
    { "%f", 3, "A", bu_offsetof(struct rt_tgc_internal, a[X]), BU_STRUCTPARSE_FUNC_NULL },
    { "%f", 3, "B", bu_offsetof(struct rt_tgc_internal, b[X]), BU_STRUCTPARSE_FUNC_NULL },
    { "%f", 3, "C", bu_offsetof(struct rt_tgc_internal, c[X]), BU_STRUCTPARSE_FUNC_NULL },
    { "%f", 3, "D", bu_offsetof(struct rt_tgc_internal, d[X]), BU_STRUCTPARSE_FUNC_NULL },
    { {'\0','\0','\0','\0'}, 0, (char *)NULL, 0, BU_STRUCTPARSE_FUNC_NULL }
}

Definition at line 103 of file g_tgc.c.

fastf_t nmg_tgc_unitcircle[36]
 

Initial value:

 {
        1.0, 0.0, 0.0, 1.0,
        RAT, -RAT, 0.0, RAT,
        0.0, -1.0, 0.0, 1.0,
        -RAT, -RAT, 0.0, RAT,
        -1.0, 0.0, 0.0, 1.0,
        -RAT, RAT, 0.0, RAT,
        0.0, 1.0, 0.0, 1.0,
        RAT, RAT, 0.0, RAT,
        1.0, 0.0, 0.0, 1.0
}

Definition at line 2814 of file g_tgc.c.

fastf_t nmg_uv_unitcircle[27]
 

Initial value:

 {
        1.0,   .5,  1.0,
        RAT,  RAT,  RAT,
        .5,   1.0,  1.0,
        0.0,  RAT,  RAT,
        0.0,   .5,  1.0,
        0.0,  0.0,  RAT,
        .5,   0.0,  1.0,
        RAT,  0.0,  RAT,
        1.0,   .5,  1.0
}

Definition at line 2826 of file g_tgc.c.


Generated on Mon Sep 18 01:25:06 2006 for BRL-CAD by  doxygen 1.4.6