BRL-CAD
metaball.c File Reference
#include "common.h"
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "bnetwork.h"
#include "bu/cv.h"
#include "vmath.h"
#include "db.h"
#include "nmg.h"
#include "rtgeom.h"
#include "raytrace.h"
#include "nurb.h"
#include "wdb.h"
#include "metaball.h"
Include dependency graph for metaball.c:

Go to the source code of this file.

Macros

#define SQ(a)   ((a)*(a))
 
#define PLOT_THE_BIG_BOUNDING_SPHERE   0
 
#define SHOOTALGO   3
 

Functions

int rt_metaball_lookup_type_id (const char *name)
 
const char * rt_metaball_lookup_type_name (const int id)
 
fastf_t rt_metaball_get_bounding_sphere (point_t *center, fastf_t threshold, struct rt_metaball_internal *mb)
 
int rt_metaball_bbox (struct rt_db_internal *ip, point_t *min, point_t *max, const struct bn_tol *tol)
 
int rt_metaball_prep (struct soltab *stp, struct rt_db_internal *ip, struct rt_i *rtip)
 
void rt_metaball_print (register const struct soltab *stp)
 
void rt_metaballpt_print (const struct wdb_metaballpt *metaball, double mm2local)
 
fastf_t rt_metaball_point_value_metaball (const point_t *p, const struct bu_list *points)
 
fastf_t rt_metaball_point_value_iso (const point_t *p, const struct bu_list *points)
 
fastf_t rt_metaball_point_value_blob (const point_t *p, const struct bu_list *points)
 
fastf_t rt_metaball_point_value (const point_t *p, const struct rt_metaball_internal *mb)
 
int rt_metaball_point_inside (const point_t *p, const struct rt_metaball_internal *mb)
 
int rt_metaball_find_intersection (point_t *intersect, const struct rt_metaball_internal *mb, const point_t *a, const point_t *b, fastf_t step, const fastf_t finalstep)
 
int rt_metaball_shot (struct soltab *stp, register struct xray *rp, struct application *ap, struct seg *seghead)
 
void rt_metaball_norm_internal (vect_t *n, point_t *p, struct rt_metaball_internal *mb)
 
void rt_metaball_norm (register struct hit *hitp, struct soltab *stp, register struct xray *rp)
 
void rt_metaball_curve (struct curvature *cvp, struct hit *hitp, struct soltab *stp)
 
void rt_metaball_uv (struct application *ap, struct soltab *stp, struct hit *hitp, struct uvcoord *uvp)
 
void rt_metaball_free (register struct soltab *stp)
 
int rt_metaball_class (const struct soltab *stp, const fastf_t *min, const fastf_t *max, const struct bn_tol *tol)
 
void rt_metaball_plot_sph (struct bu_list *vhead, point_t *center, fastf_t radius)
 
int rt_metaball_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_metaball_import5 (struct rt_db_internal *ip, const struct bu_external *ep, register const fastf_t *mat, const struct db_i *dbip)
 
int rt_metaball_export5 (struct bu_external *ep, const struct rt_db_internal *ip, double local2mm, const struct db_i *dbip)
 
int rt_metaball_describe (struct bu_vls *str, const struct rt_db_internal *ip, int verbose, double mm2local)
 
void rt_metaball_ifree (struct rt_db_internal *ip)
 
int rt_metaball_add_point (struct rt_metaball_internal *mb, const point_t *loc, const fastf_t fldstr, const fastf_t goo)
 
int rt_metaball_params (struct pc_pc_set *ps, const struct rt_db_internal *ip)
 
int rt_metaball_get (struct bu_vls *logstr, const struct rt_db_internal *intern, const char *attr)
 
int rt_metaball_adjust (struct bu_vls *logstr, struct rt_db_internal *intern, int argc, const char **argv)
 

Variables

const char * metaballnames []
 

Detailed Description

Intersect a ray with a metaball implicit surface.

Algorithm:

The heart of it is the set of point evaluation functions. These are different for each "type" of blobby object (metaballs, blinn blobs, and iso-potential contours). All are simple summation formulas at the moment.

Plot merely draws sphere type objects around the control points, with size related to each points 'strength' and the primitives threshold.

Ray-tracing is incredibly hackish. The ray is walked in a fairly coarse matter until the point evaluation crosses the threshold value, then a basic binary search is done to refine the approximated hit point.

THIS PRIMITIVE IS INCOMPLETE AND SHOULD BE CONSIDERED EXPERIMENTAL.

Definition in file metaball.c.

Macro Definition Documentation

#define SQ (   a)    ((a)*(a))

Definition at line 67 of file metaball.c.

Referenced by rt_metaball_norm_internal().

#define PLOT_THE_BIG_BOUNDING_SPHERE   0

Definition at line 69 of file metaball.c.

#define SHOOTALGO   3

Function Documentation

fastf_t rt_metaball_get_bounding_sphere ( point_t *  center,
fastf_t  threshold,
struct rt_metaball_internal *  mb 
)

Definition at line 100 of file metaball.c.

References BU_LIST_FOR, VSETALL, X, and ZERO.

Referenced by rt_metaball_bbox(), rt_metaball_plot(), rt_metaball_prep(), and rt_metaball_tess().

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

Calculate a bounding RPP around a metaball

Definition at line 165 of file metaball.c.

References rt_db_internal::idb_ptr, rt_metaball_get_bounding_sphere(), VSET, VSETALL, X, Y, and Z.

Referenced by rt_metaball_prep(), and rt_metaball_tess().

Here is the call graph for this function:

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

prep and build bounding volumes... unfortunately, generating the bounding sphere is too 'loose' (I think) and O(n^2).

Definition at line 187 of file metaball.c.

References BU_ALLOC, BU_LIST_FOR, BU_LIST_INIT, BU_LIST_INSERT, rt_db_internal::idb_ptr, RT_CK_RTI, rt_metaball_bbox(), rt_metaball_get_bounding_sphere(), RT_METABALL_INTERNAL_MAGIC, rt_i::rti_tol, soltab::st_aradius, soltab::st_bradius, soltab::st_center, soltab::st_max, soltab::st_min, and soltab::st_specific.

Here is the call graph for this function:

void rt_metaball_print ( register const struct soltab stp)

Definition at line 237 of file metaball.c.

References BU_LIST_FOR, bu_log(), rt_metaball_lookup_type_name(), soltab::st_specific, and V3ARGS.

Here is the call graph for this function:

fastf_t rt_metaball_point_value_metaball ( const point_t *  p,
const struct bu_list points 
)

Definition at line 268 of file metaball.c.

References bu_bomb(), and bu_log().

Referenced by rt_metaball_point_value().

Here is the call graph for this function:

fastf_t rt_metaball_point_value_iso ( const point_t *  p,
const struct bu_list points 
)

Definition at line 280 of file metaball.c.

References BU_LIST_FOR, and OSL::Strings::v.

Referenced by rt_metaball_point_value().

fastf_t rt_metaball_point_value_blob ( const point_t *  p,
const struct bu_list points 
)

Definition at line 295 of file metaball.c.

References BU_LIST_FOR, and OSL::Strings::v.

Referenced by rt_metaball_point_value().

int rt_metaball_find_intersection ( point_t *  intersect,
const struct rt_metaball_internal *  mb,
const point_t *  a,
const point_t *  b,
fastf_t  step,
const fastf_t  finalstep 
)

Definition at line 345 of file metaball.c.

References rt_metaball_find_intersection(), and rt_metaball_point_inside().

Referenced by rt_metaball_find_intersection(), and rt_metaball_shot().

Here is the call graph for this function:

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

Definition at line 365 of file metaball.c.

References application::a_onehit, application::a_resource, BU_LIST_INSERT, delta, seg::l, out, xray::r_dir, xray::r_max, xray::r_min, xray::r_pt, RT_GET_SEG, rt_metaball_find_intersection(), rt_metaball_point_value(), and soltab::st_specific.

Here is the call graph for this function:

void rt_metaball_norm_internal ( vect_t *  n,
point_t *  p,
struct rt_metaball_internal *  mb 
)
inline

Definition at line 503 of file metaball.c.

References BU_LIST_FOR, bu_log(), SQ, OSL::Strings::v, and VSETALL.

Referenced by rt_metaball_norm().

Here is the call graph for this function:

void rt_metaball_norm ( register struct hit hitp,
struct soltab stp,
register struct xray rp 
)

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

Definition at line 537 of file metaball.c.

References hit::hit_normal, hit::hit_point, RT_CK_RAY, rt_metaball_norm_internal(), and soltab::st_specific.

Here is the call graph for this function:

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

Return the curvature of the metaball.

Definition at line 549 of file metaball.c.

References bu_log(), if(), RT_CK_HIT, and soltab::st_specific.

Here is the call graph for this function:

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

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

u = azimuth v = elevation

Definition at line 569 of file metaball.c.

References application::a_diverge, application::a_rbeam, bn_atan2(), hit::hit_dist, hit::hit_point, if(), RT_CK_APPLICATION, RT_CK_HIT, RT_CK_SOLTAB, soltab::st_aradius, soltab::st_center, soltab::st_specific, 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_metaball_free ( register struct soltab stp)

Definition at line 606 of file metaball.c.

References bu_free(), and soltab::st_specific.

Here is the call graph for this function:

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

Definition at line 615 of file metaball.c.

References BN_CK_TOL, and RT_CK_SOLTAB.

void rt_metaball_plot_sph ( struct bu_list vhead,
point_t *  center,
fastf_t  radius 
)

Definition at line 627 of file metaball.c.

References BN_VLIST_LINE_DRAW, BN_VLIST_LINE_MOVE, BU_CK_LIST_HEAD, RT_ADD_VLIST, rt_ell_16pts(), top(), and VSET.

Referenced by rt_metaball_plot().

Here is the call graph for this function:

int rt_metaball_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 652 of file metaball.c.

References BU_CK_LIST_HEAD, BU_LIST_FOR, rt_db_internal::idb_ptr, RT_CK_DB_INTERNAL, rt_metaball_get_bounding_sphere(), and rt_metaball_plot_sph().

Here is the call graph for this function:

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

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

Definition at line 680 of file metaball.c.

References bn_mat_identity, BU_ALLOC, BU_CK_EXTERNAL, bu_cv_ntohd(), bu_free(), BU_GET, BU_LIST_INIT, BU_LIST_INSERT, bu_malloc(), bu_external::ext_buf, ID_METABALL, 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_METABALL_INTERNAL_MAGIC, SIZEOF_NETWORK_DOUBLE, SIZEOF_NETWORK_LONG, and WDB_METABALLPT_MAGIC.

Here is the call graph for this function:

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

storage is something like long numpoints long method fastf_t threshold fastf_t X1 (start point) fastf_t Y1 fastf_t Z1 fastf_t fldstr1 fastf_t sweat1 (end point) fastf_t X2 (start point) ...

Definition at line 738 of file metaball.c.

References bu_bomb(), BU_CK_EXTERNAL, bu_cv_htond(), bu_free(), BU_LIST_FOR, bu_malloc(), bu_external::ext_buf, bu_external::ext_nbytes, ID_METABALL, rt_db_internal::idb_ptr, RT_CK_DB_INTERNAL, RT_CK_DBI, SIZEOF_NETWORK_DOUBLE, and SIZEOF_NETWORK_LONG.

Here is the call graph for this function:

int rt_metaball_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 786 of file metaball.c.

References bu_bomb(), BU_LIST_FOR, bu_vls_strcat(), rt_db_internal::idb_ptr, RT_CK_DB_INTERNAL, rt_metaball_lookup_type_name(), and V3ARGS.

Here is the call graph for this function:

void rt_metaball_ifree ( struct rt_db_internal ip)

Free the storage associated with the rt_db_internal version of this solid. This only effects the in-memory copy.

Definition at line 830 of file metaball.c.

References bu_free(), BU_LIST_DEQUEUE, BU_LIST_WHILE, BU_PUT, rt_db_internal::idb_ptr, and RT_CK_DB_INTERNAL.

Here is the call graph for this function:

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

Definition at line 870 of file metaball.c.

References RT_CK_DB_INTERNAL.

int rt_metaball_get ( struct bu_vls logstr,
const struct rt_db_internal intern,
const char *  attr 
)

db get/g2asc

Definition at line 881 of file metaball.c.

References BU_LIST_FOR, bu_vls_printf(), rt_db_internal::idb_ptr, and V3ARGS.

Here is the call graph for this function:

int rt_metaball_adjust ( struct bu_vls logstr,
struct rt_db_internal intern,
int  argc,
const char **  argv 
)

used for db put/asc2g

Definition at line 908 of file metaball.c.

References BRLCAD_ERROR, BRLCAD_OK, BU_LIST_INIT, bu_vls_printf(), rt_db_internal::idb_ptr, RT_CK_DB_INTERNAL, rt_metaball_add_point(), V3ARGS, and OSL::Strings::xyz.

Here is the call graph for this function:

Variable Documentation

const char* metaballnames[]
Initial value:
=
{
"Metaball",
"Isopotential",
"Blob",
NULL
}

Definition at line 71 of file metaball.c.

Referenced by rt_metaball_lookup_type_id(), and rt_metaball_lookup_type_name().