BRL-CAD
superell.c File Reference
#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 "../../librt_private.h"
Include dependency graph for superell.c:

Go to the source code of this file.

Data Structures

struct  superell_specific
 
struct  superell_state
 
struct  superell_vert_strip
 

Macros

#define SUPERELL_NULL   ((struct superell_specific *)0)
 
#define SUPERELLOUT(n)   ov+(n-1)*3
 

Functions

int rt_superell_bbox (struct rt_db_internal *ip, point_t *min, point_t *max, const struct bn_tol *tol)
 
int rt_superell_prep (struct soltab *stp, struct rt_db_internal *ip, struct rt_i *rtip)
 
void rt_superell_print (const struct soltab *stp)
 
int rt_superell_shot (struct soltab *stp, struct xray *rp, struct application *ap, struct seg *seghead)
 
void rt_superell_norm (struct hit *hitp, struct soltab *stp, struct xray *rp)
 
void rt_superell_curve (struct curvature *cvp, struct hit *hitp, struct soltab *stp)
 
void rt_superell_uv (struct application *ap, struct soltab *stp, struct hit *hitp, struct uvcoord *uvp)
 
void rt_superell_free (struct soltab *stp)
 
void rt_superell_16pts (fastf_t *ov, fastf_t *V, fastf_t *A, fastf_t *B)
 
int rt_superell_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_superell_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_superell_import4 (struct rt_db_internal *ip, const struct bu_external *ep, const fastf_t *mat, const struct db_i *dbip)
 
int rt_superell_export4 (struct bu_external *ep, const struct rt_db_internal *ip, double local2mm, const struct db_i *dbip)
 
int rt_superell_import5 (struct rt_db_internal *ip, const struct bu_external *ep, const fastf_t *mat, const struct db_i *dbip)
 
int rt_superell_export5 (struct bu_external *ep, const struct rt_db_internal *ip, double local2mm, const struct db_i *dbip)
 
int rt_superell_describe (struct bu_vls *str, const struct rt_db_internal *ip, int verbose, double mm2local)
 
void rt_superell_ifree (struct rt_db_internal *ip)
 
int rt_superell_params (struct pc_pc_set *ps, const struct rt_db_internal *ip)
 
void rt_superell_volume (fastf_t *volume, const struct rt_db_internal *ip)
 
void rt_superell_surf_area (fastf_t *area, const struct rt_db_internal *ip)
 

Variables

const struct bu_structparse rt_superell_parse []
 

Detailed Description

Intersect a ray with a Superquadratic Ellipsoid.

NOTICE: this primitive is incomplete and should be considered experimental. This primitive will exhibit several instabilities in the existing root solver method.

Definition in file superell.c.

Macro Definition Documentation

#define SUPERELL_NULL   ((struct superell_specific *)0)

Definition at line 171 of file superell.c.

#define SUPERELLOUT (   n)    ov+(n-1)*3

Also used by the TGC code

Definition at line 633 of file superell.c.

Referenced by rt_superell_16pts().

Function Documentation

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

Calculate a bounding RPP for a superell

Definition at line 177 of file superell.c.

References rt_db_internal::idb_ptr, OSL::Strings::P, R, VSET, X, Y, and Z.

Referenced by rt_superell_prep().

int rt_superell_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 superellipsoid, and if so, precompute various terms of the formula.

Returns - 0 SUPERELL is OK !0 Error in description

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

Definition at line 254 of file superell.c.

References bn_mat_mul(), bn_mat_trn(), BU_GET, bu_log(), bn_tol::dist, rt_db_internal::idb_ptr, NEAR_ZERO, R, rt_superell_bbox(), rt_i::rti_tol, soltab::st_aradius, soltab::st_bradius, soltab::st_center, soltab::st_max, soltab::st_min, soltab::st_specific, superell_specific::superell_Au, superell_specific::superell_Bu, superell_specific::superell_Cu, superell_specific::superell_e, superell_specific::superell_invmsAu, superell_specific::superell_invmsBu, superell_specific::superell_invmsCu, superell_specific::superell_invR, superell_specific::superell_invRSSR, superell_specific::superell_invsq, superell_specific::superell_n, superell_specific::superell_SoR, superell_specific::superell_V, and VSET.

Here is the call graph for this function:

void rt_superell_print ( const struct soltab stp)

Definition at line 372 of file superell.c.

References soltab::st_specific, superell_specific::superell_V, and VPRINT.

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

Intersect a ray with an superellipsoid, where all constant terms have been precomputed by rt_superell_prep(). If an intersection occurs, a struct seg will be acquired and filled in.

Returns - 0 MISS >0 HIT

Definition at line 396 of file superell.c.

References application::a_resource, bn_pr_roots(), BU_LIST_INSERT, bu_log(), directory::d_namep, seg::l, NEAR_ZERO, xray::r_dir, xray::r_pt, RT_GET_SEG, rt_poly_roots(), soltab::st_dp, soltab::st_specific, superell_specific::superell_e, superell_specific::superell_invmsAu, superell_specific::superell_invmsBu, superell_specific::superell_invmsCu, superell_specific::superell_SoR, superell_specific::superell_V, OSL::Strings::u, VPRINT, X, Y, and Z.

Here is the call graph for this function:

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

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

Definition at line 566 of file superell.c.

References hit::hit_dist, hit::hit_normal, hit::hit_point, xray::r_dir, xray::r_pt, soltab::st_specific, superell_specific::superell_invRSSR, and superell_specific::superell_V.

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

Return the curvature of the superellipsoid.

Definition at line 588 of file superell.c.

References bu_log(), RT_CK_HIT, and RT_CK_SOLTAB.

Here is the call graph for this function:

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

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

Definition at line 607 of file superell.c.

References bu_log(), RT_CK_APPLICATION, RT_CK_HIT, and RT_CK_SOLTAB.

Here is the call graph for this function:

void rt_superell_free ( struct soltab stp)

Definition at line 621 of file superell.c.

References BU_PUT, and soltab::st_specific.

void rt_superell_16pts ( fastf_t ov,
fastf_t V,
fastf_t A,
fastf_t B 
)

Definition at line 635 of file superell.c.

References M_SQRT1_2, and SUPERELLOUT.

Referenced by rt_superell_plot().

int rt_superell_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 674 of file superell.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_superell_16pts(), and top().

Here is the call graph for this function:

int rt_superell_tess ( struct nmgregion **  r,
struct model *  m,
struct rt_db_internal ip,
const struct rt_tess_tol ttol,
const struct bn_tol tol 
)

Tesssuperellate an superellipsoid.

The strategy is based upon the approach of Jon Leech 3/24/89, from program "sphere", which generates a polygon mesh approximating a sphere by recursive subdivision. First approximation is an octahedron; each level of refinement increases the number of polygons by a factor of 4. Level 3 (128 polygons) is a good tradeoff if gouraud shading is used to render the database.

At the start, points ABC lie on surface of the unit sphere. Pick DEF as the midpoints of the three edges of ABC. Normalize the new points to lie on surface of the unit sphere.

   1
   B
  /\

3 / \ 4 D /____\ E /\ /\ / \ / \ /____\/____\ A F C 0 5 2

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

Definition at line 758 of file superell.c.

References bu_log(), and RT_CK_DB_INTERNAL.

Here is the call graph for this function:

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

Import an superellipsoid/sphere from the database format to the internal structure. Apply modeling transformations as wsuperell.

Definition at line 774 of file superell.c.

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

Here is the call graph for this function:

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

Definition at line 822 of file superell.c.

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

Here is the call graph for this function:

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

Import an superellipsoid/sphere from the database format to the internal structure. Apply modeling transformations as wsuperell.

Definition at line 862 of file superell.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_SUPERELL, 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_SUPERELL_INTERNAL_MAGIC, and SIZEOF_NETWORK_DOUBLE.

Here is the call graph for this function:

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

The external format is: V point A vector B vector C vector

Definition at line 908 of file superell.c.

References BU_CK_EXTERNAL, bu_cv_htond(), bu_malloc(), bu_external::ext_buf, bu_external::ext_nbytes, ID_SUPERELL, 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_superell_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 948 of file superell.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_superell_ifree ( struct rt_db_internal ip)

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

Definition at line 1017 of file superell.c.

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

Here is the call graph for this function:

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

Definition at line 1040 of file superell.c.

References RT_CK_DB_INTERNAL.

void rt_superell_volume ( fastf_t volume,
const struct rt_db_internal ip 
)

Computes the volume of a superellipsoid

Volume equation from http://lrv.fri.uni-lj.si/~franc/SRSbook/geometry.pdf which also includes a derivation on page 32.

Definition at line 1055 of file superell.c.

References rt_db_internal::idb_ptr, and RT_CK_DB_INTERNAL.

void rt_superell_surf_area ( fastf_t area,
const struct rt_db_internal ip 
)

Definition at line 1209 of file superell.c.

References BN_TOL_DIST, rt_db_internal::idb_ptr, and RT_CK_DB_INTERNAL.

Variable Documentation

const struct bu_structparse rt_superell_parse[]
Initial value:
= {
{ "%f", 3, "V", bu_offsetofarray(struct rt_superell_internal, v, fastf_t, X), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
{ "%f", 3, "A", bu_offsetofarray(struct rt_superell_internal, a, fastf_t, X), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
{ "%f", 3, "B", bu_offsetofarray(struct rt_superell_internal, b, fastf_t, X), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
{ "%f", 3, "C", bu_offsetofarray(struct rt_superell_internal, c, fastf_t, X), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
{ "%g", 1, "n", bu_offsetof(struct rt_superell_internal, n), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
{ "%g", 1, "e", bu_offsetof(struct rt_superell_internal, e), 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
#define bu_offsetof(_t, _m)
Definition: parse.h:64
double fastf_t
Definition: defines.h:300

Definition at line 50 of file superell.c.