g_torus.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 "noalias.h"

Include dependency graph for g_torus.c:

Go to the source code of this file.

Data Structures

struct  tor_specific

Defines

#define SEG_MISS(SEG)   (SEG).seg_stp=(struct soltab *) 0;
#define TOR_PT(www, lll)   ((((www)%nw)*nlen)+((lll)%nlen))
#define TOR_PTA(ww, ll)   (&pts[TOR_PT(ww,ll)*3])
#define TOR_NORM_A(ww, ll)   (&norms[TOR_PT(ww,ll)*3])

Functions

int rt_tor_prep (struct soltab *stp, struct rt_db_internal *ip, struct rt_i *rtip)
void rt_tor_print (register const struct soltab *stp)
int rt_tor_shot (struct soltab *stp, register struct xray *rp, struct application *ap, struct seg *seghead)
void rt_tor_vshot (struct soltab **stp, struct xray **rp, struct seg *segp, int n, struct application *ap)
void rt_tor_norm (register struct hit *hitp, struct soltab *stp, register struct xray *rp)
void rt_tor_curve (register struct curvature *cvp, register struct hit *hitp, struct soltab *stp)
void rt_tor_uv (struct application *ap, struct soltab *stp, register struct hit *hitp, register struct uvcoord *uvp)
void rt_tor_free (struct soltab *stp)
int rt_tor_class (void)
int rt_num_circular_segments (double maxerr, double radius)
int rt_tor_plot (struct bu_list *vhead, struct rt_db_internal *ip, const struct rt_tess_tol *ttol, const struct bn_tol *tol)
int rt_tor_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_tor_import (struct rt_db_internal *ip, const struct bu_external *ep, register const fastf_t *mat, const struct db_i *dbip)
int rt_tor_export5 (struct bu_external *ep, const struct rt_db_internal *ip, double local2mm, const struct db_i *dbip)
int rt_tor_export (struct bu_external *ep, const struct rt_db_internal *ip, double local2mm, const struct db_i *dbip)
int rt_tor_import5 (struct rt_db_internal *ip, const struct bu_external *ep, register const fastf_t *mat, const struct db_i *dbip)
int rt_tor_describe (struct bu_vls *str, const struct rt_db_internal *ip, int verbose, double mm2local)
void rt_tor_ifree (struct rt_db_internal *ip)

Variables

const struct bu_structparse rt_tor_parse []


Detailed Description

Intersect a ray with a Torus

Authors - Edwin O. Davisson (Analysis) Jeff Hanes (Programming) Michael John Muuss (RT adaptation) Gary S. Moss (Improvement)

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

Definition in file g_torus.c.


Define Documentation

#define SEG_MISS SEG   )     (SEG).seg_stp=(struct soltab *) 0;
 

Definition at line 546 of file g_torus.c.

#define TOR_PT www,
lll   )     ((((www)%nw)*nlen)+((lll)%nlen))
 

#define TOR_PTA ww,
ll   )     (&pts[TOR_PT(ww,ll)*3])
 

Referenced by rt_tor_plot(), and rt_tor_tess().

#define TOR_NORM_A ww,
ll   )     (&norms[TOR_PT(ww,ll)*3])
 

Referenced by rt_tor_tess().


Function Documentation

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

R T _ T O R _ P R E P

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

Returns - 0 TOR is OK !0 Error in description

Implicit return - A struct tor_specific is created, and it's address is stored in stp->st_specific for use by rt_tor_shot().

Definition at line 196 of file g_torus.c.

References rt_tor_internal::a, rt_tor_internal::b, bn_mat_inv(), BU_GETSTRUCT, bu_log(), bn_tol::dist, FAST, rt_tor_internal::h, rt_db_internal::idb_ptr, LOCAL, MAGNITUDE, MAT_COPY, MAT_IDN, NEAR_ZERO, R, rt_tor_internal::r_a, rt_tor_internal::r_b, rt_tor_internal::r_h, rt_fdiff(), RT_TOR_CK_MAGIC, rt_i::rti_tol, soltab::st_aradius, soltab::st_bradius, soltab::st_center, soltab::st_max, soltab::st_min, soltab::st_specific, tor_specific::tor_alpha, tor_specific::tor_invR, tor_specific::tor_N, tor_specific::tor_r1, tor_specific::tor_r2, tor_specific::tor_SoR, tor_specific::tor_V, rt_tor_internal::v, VCROSS, VDOT, VMOVE, VSCALE, VSET, X, Y, and Z.

Here is the call graph for this function:

void rt_tor_print register const struct soltab stp  ) 
 

R T _ T O R _ P R I N T

Definition at line 310 of file g_torus.c.

References bn_mat_print(), bu_log(), tor_specific::tor_alpha, tor_specific::tor_invR, tor_specific::tor_N, tor_specific::tor_r1, tor_specific::tor_r2, tor_specific::tor_SoR, tor_specific::tor_V, and VPRINT.

Here is the call graph for this function:

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

R T _ T O R _ S H O T

Intersect a ray with an torus, where all constant terms have been precomputed by rt_tor_prep(). If an intersection occurs, one or two struct seg(s) will be acquired and filled in.

NOTE: All lines in this function are represented parametrically by a point, P( x0, y0, z0 ) and a direction normal, D = ax + by + cz. Any point on a line can be expressed by one variable 't', where

X = a*t + x0, eg, X = Dx*t + Px Y = b*t + y0, Z = c*t + z0.

First, convert the line to the coordinate system of a "stan- dard" torus. This is a torus which lies in the X-Y plane, circles the origin, and whose primary radius is one. The secondary radius is alpha = ( R2/R1 ) of the original torus where ( 0 < alpha <= 1 ).

Then find the equation of that line and the standard torus, which turns out to be a quartic 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.

Returns - 0 MISS >0 HIT

Definition at line 357 of file g_torus.c.

References A, application::a_rt_i, bn_pr_roots(), bu_log(), directory::d_namep, bn_tol::dist, LOCAL, MAT4X3VEC, NEAR_ZERO, rt_poly_roots(), rt_i::rti_tol, soltab::st_dp, soltab::st_specific, tor_specific::tor_alpha, tor_specific::tor_SoR, tor_specific::tor_V, val, VDOT, VPRINT, VSCALE, VSUB2, VUNITIZE, X, Y, and Z.

Here is the call graph for this function:

void rt_tor_vshot struct soltab **  stp,
struct xray **  rp,
struct seg segp,
int  n,
struct application ap
 

Definition at line 553 of file g_torus.c.

References A, bu_malloc(), LOCAL, MAT4X3VEC, xray::r_dir, tor_specific::tor_alpha, tor_specific::tor_SoR, tor_specific::tor_V, val, VDOT, VMOVE, VSCALE, VSUB2, VUNITIZE, X, Y, and Z.

Here is the call graph for this function:

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

R T _ T O R _ N O R M

Compute the normal to the torus, given a point on the UNIT TORUS centered at the origin on the X-Y plane. The gradient of the torus at that point is in fact the normal vector, which will have to be given unit length. To make this useful for the original torus, it will have to be rotated back to the orientation of the original torus.

Given that the equation for the unit torus is:

[ X**2 + Y**2 + Z**2 + (1 - alpha**2) ]**2 - 4*( X**2 + Y**2 ) = 0

let w = X**2 + Y**2 + Z**2 + (1 - alpha**2), then the equation becomes:

w**2 - 4*( X**2 + Y**2 ) = 0

For f(x,y,z) = 0, the gradient of f() is ( df/dx, df/dy, df/dz ).

df/dx = 2 * w * 2 * x - 8 * x = (4 * w - 8) * x df/dy = 2 * w * 2 * y - 8 * y = (4 * w - 8) * y df/dz = 2 * w * 2 * z = 4 * w * z

Since we rescale the gradient (normal) to unity, we divide the above equations by four here.

Definition at line 844 of file g_torus.c.

References FAST, LOCAL, MAT3X3VEC, soltab::st_specific, tor_specific::tor_alpha, tor_specific::tor_invR, VJOIN1, VSET, VUNITIZE, X, Y, and Z.

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

R T _ T O R _ C U R V E

Return the curvature of the torus.

Definition at line 871 of file g_torus.c.

References NEAR_ZERO, soltab::st_specific, tor_specific::tor_N, tor_specific::tor_V, VSUB2, X, Y, and Z.

void rt_tor_uv struct application ap,
struct soltab stp,
register struct hit hitp,
register struct uvcoord uvp
 

R T _ T O R _ U V

Definition at line 916 of file g_torus.c.

References bn_inv2pi, LOCAL, MAT4X3VEC, tor_specific::tor_SoR, tor_specific::tor_V, VDOT, VSET, VSUB2, VUNITIZE, X, Y, and Z.

void rt_tor_free struct soltab stp  ) 
 

R T _ T O R _ F R E E

Definition at line 944 of file g_torus.c.

References bu_free(), and soltab::st_specific.

Here is the call graph for this function:

int rt_tor_class void   ) 
 

Definition at line 953 of file g_torus.c.

int rt_tor_plot struct bu_list vhead,
struct rt_db_internal ip,
const struct rt_tess_tol ttol,
const struct bn_tol tol
 

R T _ T O R _ P L O T

The TORUS has the following input fields: ti.v V from origin to center ti.h Radius Vector, Normal to plane of torus ti.a,ti.b perpindicular, to CENTER of torus (for top, bottom)

Definition at line 1024 of file g_torus.c.

References rt_tor_internal::a, rt_tess_tol::abs, rt_tor_internal::b, bn_pi, bn_twopi, bu_malloc(), rt_tor_internal::h, rt_db_internal::idb_ptr, rt_tess_tol::norm, rt_tor_internal::r_a, rt_tor_internal::r_h, rt_tess_tol::rel, RT_CK_DB_INTERNAL, rt_num_circular_segments(), RT_TOR_CK_MAGIC, TOR_PTA, rt_tor_internal::v, VADD3, VCOMB2, and VSCALE.

Here is the call graph for this function:

int rt_tor_tess struct nmgregion **  r,
struct model m,
struct rt_db_internal ip,
const struct rt_tess_tol ttol,
const struct bn_tol tol
 

R T _ T O R _ T E S S

Definition at line 1139 of file g_torus.c.

References rt_tor_internal::a, rt_tess_tol::abs, rt_tor_internal::b, bn_pi, bn_twopi, bu_malloc(), rt_tor_internal::h, rt_db_internal::idb_ptr, rt_tess_tol::norm, rt_tor_internal::r_a, rt_tor_internal::r_h, rt_tess_tol::rel, RT_CK_DB_INTERNAL, rt_num_circular_segments(), RT_TOR_CK_MAGIC, TOR_NORM_A, TOR_PTA, rt_tor_internal::v, VADD3, VCOMB2, VMOVE, VSCALE, and VUNITIZE.

Here is the call graph for this function:

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

R T _ T O R _ I M P O R T

Import a torus from the database format to the internal format. Apply modeling transformations at the same time.

Definition at line 1319 of file g_torus.c.

References rt_tor_internal::a, rt_tor_internal::b, BU_CK_EXTERNAL, bu_log(), bu_malloc(), DB5_MAJORTYPE_BRLCAD, bu_external::ext_buf, rt_tor_internal::h, ID_SOLID, ID_TOR, rt_db_internal::idb_major_type, rt_db_internal::idb_meth, rt_db_internal::idb_ptr, LOCAL, rt_tor_internal::magic, MAGNITUDE, MAT4X3PNT, MAT4X3VEC, rt_tor_internal::r_a, rt_tor_internal::r_b, rt_tor_internal::r_h, RT_CK_DB_INTERNAL, rt_fastf_float(), RT_TOR_INTERNAL_MAGIC, record::s, record::solidrec::s_values, SMALL, record::u_id, rt_tor_internal::v, VCROSS, VDOT, VREVERSE, and VSCALE.

Here is the call graph for this function:

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

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

Definition at line 1378 of file g_torus.c.

References BU_CK_EXTERNAL, bu_malloc(), bu_external::ext_buf, bu_external::ext_nbytes, rt_tor_internal::h, htond(), ID_TOR, rt_db_internal::idb_ptr, rt_tor_internal::r_a, rt_tor_internal::r_h, RT_CK_DB_INTERNAL, RT_TOR_CK_MAGIC, SIZEOF_NETWORK_DOUBLE, rt_tor_internal::v, VMOVE, and VSCALE.

Here is the call graph for this function:

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

R T _ T O R _ E X P O R T

The name will be added by the caller.

Definition at line 1409 of file g_torus.c.

References bn_vec_ortho(), bu_calloc(), BU_CK_EXTERNAL, bu_log(), bu_external::ext_buf, bu_external::ext_nbytes, rt_tor_internal::h, ID_SOLID, ID_TOR, rt_db_internal::idb_ptr, MAGNITUDE, rt_tor_internal::r_a, rt_tor_internal::r_h, RT_CK_DB_INTERNAL, RT_TOR_CK_MAGIC, record::s, record::solidrec::s_id, record::solidrec::s_type, record::solidrec::s_values, SQRT_SMALL_FASTF, TOR, rt_tor_internal::v, VCROSS, VMOVE, VSCALE, and VUNITIZE.

Here is the call graph for this function:

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

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

Taken from the database record: v vertex (point) of center of torus. h unit vector in the normal direction of the torus major radius of ring from 'v' to center of ring minor radius of the ring

Calculate: 2nd radius of ring (==1st radius) ring unit vector 1 ring unit vector 2

Definition at line 1503 of file g_torus.c.

References rt_tor_internal::a, rt_tor_internal::b, bn_mat_is_non_unif(), bn_vec_ortho(), BU_ASSERT_LONG, BU_CK_EXTERNAL, bu_log(), bu_malloc(), DB5_MAJORTYPE_BRLCAD, bu_external::ext_buf, bu_external::ext_nbytes, rt_tor_internal::h, ID_TOR, rt_db_internal::idb_major_type, rt_db_internal::idb_meth, rt_db_internal::idb_ptr, LOCAL, rt_tor_internal::magic, MAT4X3PNT, MAT4X3VEC, ntohd(), rt_tor_internal::r_a, rt_tor_internal::r_b, rt_tor_internal::r_h, RT_CK_DB_INTERNAL, RT_TOR_INTERNAL_MAGIC, SIZEOF_NETWORK_DOUBLE, rt_tor_internal::v, VCROSS, VSCALE, and VUNITIZE.

Here is the call graph for this function:

int rt_tor_describe struct bu_vls str,
const struct rt_db_internal ip,
int  verbose,
double  mm2local
 

R T _ T O R _ 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 1561 of file g_torus.c.

References bu_vls_printf(), bu_vls_strcat(), rt_db_internal::idb_ptr, INTCLAMP, RT_TOR_CK_MAGIC, X, Y, and Z.

Here is the call graph for this function:

void rt_tor_ifree struct rt_db_internal ip  ) 
 

R T _ T O R _ I F R E E

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

Definition at line 1615 of file g_torus.c.

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

Here is the call graph for this function:


Variable Documentation

const struct bu_structparse rt_tor_parse[]
 

Initial value:

 {
    { "%f", 3, "V",   bu_offsetof(struct rt_tor_internal, v[X]), BU_STRUCTPARSE_FUNC_NULL },
    { "%f", 3, "H",   bu_offsetof(struct rt_tor_internal, h[X]), BU_STRUCTPARSE_FUNC_NULL },
    { "%f", 1, "r_a", bu_offsetof(struct rt_tor_internal, r_a),  BU_STRUCTPARSE_FUNC_NULL },
    { "%f", 1, "r_h", bu_offsetof(struct rt_tor_internal, r_h),  BU_STRUCTPARSE_FUNC_NULL },
    { {'\0','\0','\0','\0'}, 0, (char *)NULL, 0, BU_STRUCTPARSE_FUNC_NULL }
    }

Definition at line 75 of file g_torus.c.


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