bn.h

Go to the documentation of this file.
00001 /*                            B N . H
00002  * BRL-CAD
00003  *
00004  * Copyright (c) 2004-2012 United States Government as represented by
00005  * the U.S. Army Research Laboratory.
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public License
00009  * version 2.1 as published by the Free Software Foundation.
00010  *
00011  * This library is distributed in the hope that it will be useful, but
00012  * WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this file; see the file named COPYING for more
00018  * information.
00019  */
00020 /** @addtogroup libbn */
00021 /** @{ */
00022 /** @file bn.h
00023  *
00024  * Header file for the BRL-CAD Numerical Computation Library, LIBBN.
00025  *
00026  * The library provides a broad assortment of numerical algorithms and
00027  * computational routines, including random number generation, vector
00028  * math, matrix math, quaternion math, complex math, synthetic
00029  * division, root finding, etc.
00030  *
00031  */
00032 
00033 #ifndef __BN_H__
00034 #define __BN_H__
00035 
00036 #include "common.h"
00037 
00038 __BEGIN_DECLS
00039 
00040 /* interface headers */
00041 #include "bu.h"         /* required for BU_CKMAG */
00042 #include "vmath.h"      /* required for mat_t, vect_t */
00043 
00044 #ifndef BN_EXPORT
00045 #  if defined(BN_DLL_EXPORTS) && defined(BN_DLL_IMPORTS)
00046 #    error "Only BN_DLL_EXPORTS or BN_DLL_IMPORTS can be defined, not both."
00047 #  elif defined(BN_DLL_EXPORTS)
00048 #    define BN_EXPORT __declspec(dllexport)
00049 #  elif defined(BN_DLL_IMPORTS)
00050 #    define BN_EXPORT __declspec(dllimport)
00051 #  else
00052 #    define BN_EXPORT
00053 #  endif
00054 #endif
00055 
00056 #define BN_AZIMUTH   0
00057 #define BN_ELEVATION 1
00058 #define BN_TWIST     2
00059 
00060 
00061 /** @} */
00062 /*----------------------------------------------------------------------*/
00063 /** @addtogroup tol */
00064 /** @{ */
00065 /**
00066  * B N _ T O L
00067  *
00068  * @brief Support for uniform tolerances
00069  *
00070  * A handy way of passing around the tolerance information needed to
00071  * perform approximate floating-point calculations on geometry.
00072  *
00073  * dist & dist_sq establish the distance tolerance.
00074  *
00075  * If two points are closer together than dist, then they are to be
00076  * considered the same point.
00077  *
00078  * For example:
00079  @code
00080  point_t a, b;
00081  vect_t diff;
00082  VSUB2(diff, a, b);
00083  if (MAGNITUDE(diff) < tol->dist)       a & b are the same.
00084  or, more efficiently:
00085  if (MAQSQ(diff) < tol->dist_sq)
00086  @endcode
00087  * perp & para establish the angular tolerance.
00088  *
00089  * If two rays emanate from the same point, and their dot product is
00090  * nearly one, then the two rays are the same, while if their dot
00091  * product is nearly zero, then they are perpendicular.
00092  *
00093  * For example:
00094  @code
00095  vect_t a, b;
00096  if (fabs(VDOT(a, b)) >= tol->para)     a & b are parallel
00097  if (fabs(VDOT(a, b)) <= tol->perp)     a & b are perpendicular
00098  @endcode
00099  *
00100  *@note
00101  * tol->dist_sq = tol->dist * tol->dist;
00102  *@n tol->para = 1 - tol->perp;
00103  */
00104 struct bn_tol {
00105     uint32_t magic;
00106     double dist;                /**< @brief >= 0 */
00107     double dist_sq;             /**< @brief dist * dist */
00108     double perp;                /**< @brief nearly 0 */
00109     double para;                /**< @brief nearly 1 */
00110 };
00111 
00112 /**
00113  * asserts the validity of a bn_tol struct.
00114  */
00115 #define BN_CK_TOL(_p)   BU_CKMAG(_p, BN_TOL_MAGIC, "bn_tol")
00116 
00117 /**
00118  * initializes a bn_tol struct to zero without allocating any memory.
00119  */
00120 #define BN_TOL_INIT(_p) { \
00121         (_p)->magic = BN_TOL_MAGIC; \
00122         (_p)->dist = 0.0; \
00123         (_p)->dist_sq = 0.0; \
00124         (_p)->perp = 0.0; \
00125         (_p)->para = 1.0; \
00126     }
00127 
00128 /**
00129  * macro suitable for declaration statement zero-initialization of a
00130  * bn_tol struct.
00131  */
00132 #define BN_TOL_INIT_ZERO { BN_TOL_MAGIC, 0.0, 0.0, 0.0, 1.0 }
00133 
00134 /**
00135  * returns truthfully whether a bn_tol struct has been initialized.
00136  */
00137 #define BN_TOL_IS_INITIALIZED(_p) (((struct bn_tol *)(_p) != (struct bn_tol *)0) && LIKELY((_p)->magic == BN_TOL_MAGIC))
00138 
00139 /**
00140  * returns truthfully whether a given dot-product of two unspecified
00141  * vectors are within a specified parallel tolerance.
00142  */
00143 #define BN_VECT_ARE_PARALLEL(_dot, _tol)                                \
00144     (((_dot) <= -SMALL_FASTF) ? (NEAR_EQUAL((_dot), -1.0, (_tol)->perp)) : (NEAR_EQUAL((_dot), 1.0, (_tol)->perp)))
00145 
00146 /**
00147  * returns truthfully whether a given dot-product of two unspecified
00148  * vectors are within a specified perpendicularity tolerance.
00149  */
00150 #define BN_VECT_ARE_PERP(_dot, _tol)                                    \
00151     (((_dot) < 0) ? ((-(_dot))<=(_tol)->perp) : ((_dot) <= (_tol)->perp))
00152 
00153 
00154 
00155 /** @} */
00156 /*----------------------------------------------------------------------*/
00157 /* anim.c */
00158 /** @addtogroup anim */
00159 /** @{ */
00160 
00161 /**
00162  * Routines useful in animation programs.
00163  *
00164  * Orientation conventions: The default object orientation is facing
00165  * the positive x-axis, with the positive y-axis to the object's left
00166  * and the positive z-axis above the object.
00167  *
00168  * The default view orientation for rt and mged is facing the negative
00169  * z-axis, with the negative x-axis leading to the left and the
00170  * positive y-axis going upwards.
00171  */
00172 
00173 /* FIXME: These should all have bn_ prefixes */
00174 
00175 /**
00176  * @brief Pre-multiply a rotation matrix by a matrix which maps the
00177  * z-axis to the negative x-axis, the y-axis to the z-axis and the
00178  * x-axis to the negative y-axis.
00179  *
00180  * This has the effect of twisting an object in the default view
00181  * orientation into the default object orientation before applying the
00182  * matrix.  Given a matrix designed to operate on an object, yield a
00183  * matrix which operates on the view.
00184  */
00185 BN_EXPORT extern void anim_v_permute(mat_t m);
00186 
00187 /**
00188  * @brief Undo the mapping done by anim_v_permute().
00189  *
00190  * This has the effect of twisting an object in the default object
00191  * orientation into the default view orientation before applying the
00192  * matrix.  Given a matrix designed to operate on the view, yield a
00193  * matrix which operates on an object.
00194  */
00195 BN_EXPORT extern void anim_v_unpermute(mat_t m);
00196 
00197 /**
00198  * @brief Transpose matrix in place
00199  */
00200 BN_EXPORT extern void anim_tran(mat_t m);
00201 
00202 /**
00203  * @brief
00204  * Convert the rotational part of a 4x4 transformation matrix to zyx
00205  * form, that is to say, rotations carried out in the order z, y, and
00206  * then x. The angles are stored in radians as a vector in the order
00207  * x, y, z. A return value of ERROR1 means that arbitrary assumptions
00208  * were necessary. ERROR2 means that the conversion failed.
00209  */
00210 BN_EXPORT extern int anim_mat2zyx(const mat_t viewrot,
00211                                   vect_t angle);
00212 
00213 /**
00214  * @brief
00215  * Convert the rotational part of a 4x4 transformation matrix to
00216  * yaw-pitch-roll form, that is to say, +roll degrees about the
00217  * x-axis, -pitch degrees about the y-axis, and +yaw degrees about the
00218  * z-axis. The angles are stored in radians as a vector in the order
00219  * y, p, r.  A return of ERROR1 means that arbitrary assumptions were
00220  * necessary.  ERROR2 means that the conversion failed.
00221  */
00222 BN_EXPORT extern int anim_mat2ypr(mat_t viewrot,
00223                                   vect_t angle);
00224 
00225 /**
00226  * @brief
00227  * This interprets the rotational part of a 4x4 transformation matrix
00228  * in terms of unit quaternions. The result is stored as a vector in
00229  * the order x, y, z, w.  The algorithm is from Ken Shoemake,
00230  * Animating Rotation with Quaternion Curves, 1985 SIGGraph Conference
00231  * Proceeding, p.245.
00232  */
00233 BN_EXPORT extern int anim_mat2quat(quat_t quat,
00234                                    const mat_t viewrot);
00235 
00236 /**
00237  * @brief Create a premultiplication rotation matrix to turn the front
00238  * of an object (its x-axis) to the given yaw, pitch, and roll, which
00239  * is stored in radians in the vector a.
00240  */
00241 BN_EXPORT extern void anim_ypr2mat(mat_t m,
00242                                    const vect_t a);
00243 
00244 /**
00245  * @brief Create a post-multiplication rotation matrix, which could be
00246  * used to move the virtual camera to the given yaw, pitch, and roll,
00247  * which are stored in radians in the given vector a. The following
00248  * are equivalent sets of commands:
00249  *
00250  * ypr2vmat(matrix, a);
00251  * -- or --
00252  * ypr2mat(matrix, a);
00253  * v_permute(matrix);
00254  * transpose(matrix;
00255  */
00256 BN_EXPORT extern void anim_ypr2vmat(mat_t m,
00257                                     const vect_t a);
00258 
00259 /**
00260  * @brief
00261  * Make matrix to rotate an object to the given yaw, pitch, and
00262  * roll. (Specified in radians.)
00263  */
00264 BN_EXPORT extern void anim_y_p_r2mat(mat_t m,
00265                                      double y,
00266                                      double p,
00267                                      double r);
00268 
00269 /**
00270  * @brief Make matrix to rotate an object to the given yaw, pitch, and
00271  * roll. (Specified in degrees.)
00272  */
00273 BN_EXPORT extern void anim_dy_p_r2mat(mat_t m,
00274                                       double y,
00275                                       double p,
00276                                       double r);
00277 
00278 /**
00279  * @brief Make a view rotation matrix, given desired yaw, pitch and
00280  * roll. (Note that the matrix is a permutation of the object rotation
00281  * matrix).
00282  */
00283 BN_EXPORT extern void anim_dy_p_r2vmat(mat_t m,
00284                                        double yaw,
00285                                        double pch,
00286                                        double rll);
00287 
00288 /**
00289  * @brief Make a rotation matrix corresponding to a rotation of "x"
00290  * radians about the x-axis, "y" radians about the y-axis, and then
00291  * "z" radians about the z-axis.
00292  */
00293 BN_EXPORT extern void anim_x_y_z2mat(mat_t m,
00294                                      double x,
00295                                      double y,
00296                                      double z);
00297 
00298 /**
00299  * @brief Make a rotation matrix corresponding to a rotation of "x"
00300  * degrees about the x-axis, "y" degrees about the y-axis, and then
00301  * "z" degrees about the z-axis.
00302  */
00303 BN_EXPORT extern void anim_dx_y_z2mat(mat_t m,
00304                                       double x,
00305                                       double y,
00306                                       double z);
00307 
00308 /**
00309  * @brief Make a rotation matrix corresponding to a rotation of "z"
00310  * radians about the z-axis, "y" radians about the y-axis, and then
00311  * "x" radians about the x-axis.
00312  */
00313 BN_EXPORT extern void anim_zyx2mat(mat_t m,
00314                                    const vect_t a);
00315 
00316 /**
00317  * @brief Make a rotation matrix corresponding to a rotation of "z"
00318  * radians about the z-axis, "y" radians about the y-axis, and then
00319  * "x" radians about the x-axis.
00320  */
00321 BN_EXPORT extern void anim_z_y_x2mat(mat_t m,
00322                                      double x,
00323                                      double y,
00324                                      double z);
00325 
00326 /**
00327  * @brief
00328  * Make a rotation matrix corresponding to a rotation of "z" degrees
00329  * about the z-axis, "y" degrees about the y-axis, and then "x"
00330  * degrees about the x-axis.
00331  */
00332 BN_EXPORT extern void anim_dz_y_x2mat(mat_t m,
00333                                       double x,
00334                                       double y,
00335                                       double z);
00336 
00337 /**
00338  * @brief
00339  * Make 4x4 matrix from the given quaternion Note: these quaternions
00340  * are the conjugates of the quaternions used in the librt/qmath.c
00341  * quat_quat2mat()
00342  */
00343 BN_EXPORT extern void anim_quat2mat(mat_t m,
00344                                     const quat_t qq);
00345 
00346 /**
00347  * @brief
00348  * make a matrix which turns a vehicle from the x-axis to point in the
00349  * desired direction, staying "right-side up" (ie the y-axis never has
00350  * a z-component). A second direction vector is consulted when the
00351  * given direction is vertical. This is intended to represent the the
00352  * direction from a previous frame.
00353  */
00354 BN_EXPORT extern void anim_dir2mat(mat_t m,
00355                                    const vect_t d,
00356                                    const vect_t d2);
00357 
00358 /**
00359  * @brief make a matrix which turns a vehicle from the x-axis to point
00360  * in the desired direction, staying "right-side up". In cases where
00361  * the direction is vertical, the second vector is consulted. The
00362  * second vector defines a normal to the the vertical plane into which
00363  * the vehicle's x and z axes should be put. A good choice to put here
00364  * is the direction of the vehicle's y-axis in the previous frame.
00365  */
00366 BN_EXPORT extern void anim_dirn2mat(mat_t m,
00367                                     const vect_t dx,
00368                                     const vect_t dn);
00369 
00370 /**
00371  * @brief given the next frame's position, remember the value of the
00372  * previous frame's position and calculate a matrix which points the
00373  * x-axis in the direction defined by those two positions. Return new
00374  * matrix, and the remembered value of the current position, as
00375  * arguments; return 1 as the normal value, and 0 when there is not
00376  * yet information to remember.
00377  */
00378 BN_EXPORT extern int anim_steer_mat(mat_t mat,
00379                                     vect_t point,
00380                                     int end);
00381 
00382 /**
00383  * @brief Add pre- and post- translation to a rotation matrix.  The
00384  * resulting matrix has the effect of performing the first
00385  * translation, followed by the rotation, followed by the second
00386  * translation.
00387  */
00388 BN_EXPORT extern void anim_add_trans(mat_t m,
00389                                      const vect_t post,
00390                                      const vect_t pre);
00391 
00392 /**
00393  * @brief Rotate the vector "d" through "a" radians about the z-axis.
00394  */
00395 BN_EXPORT extern void anim_rotatez(fastf_t a,
00396                                    vect_t d);
00397 
00398 /**
00399  * @brief print out 4X4 matrix, with optional colon
00400  */
00401 BN_EXPORT extern void anim_mat_print(FILE *fp,
00402                                      const mat_t m,
00403                                      int s_colon);
00404 
00405 /** 
00406  * @brief print out 4X4 matrix.  formstr must be less than twenty
00407  * chars
00408  */
00409 BN_EXPORT extern void anim_mat_printf(FILE *fp,
00410                                       const mat_t m,
00411                                       const char *formstr,
00412                                       const char *linestr,
00413                                       const char *endstr);
00414 
00415 /**
00416  * @brief Reverse the direction of a view matrix, keeping it
00417  * right-side up
00418  */
00419 BN_EXPORT extern void anim_view_rev(mat_t m);
00420 
00421 
00422 /*----------------------------------------------------------------------*/
00423 /* bn_tcl.c */
00424 BN_EXPORT extern int bn_decode_mat(mat_t m,
00425                                    const char *str);
00426 BN_EXPORT extern int bn_decode_quat(quat_t q,
00427                                     const char *str);
00428 BN_EXPORT extern int bn_decode_vect(vect_t v,
00429                                     const char *str);
00430 BN_EXPORT extern int bn_decode_hvect(hvect_t v,
00431                                      const char *str);
00432 BN_EXPORT extern void bn_encode_mat(struct bu_vls *vp,
00433                                     const mat_t m);
00434 BN_EXPORT extern void bn_encode_quat(struct bu_vls *vp,
00435                                      const quat_t q);
00436 BN_EXPORT extern void bn_encode_vect(struct bu_vls *vp,
00437                                      const vect_t v);
00438 BN_EXPORT extern void bn_encode_hvect(struct bu_vls *vp,
00439                                       const hvect_t v);
00440 
00441 /* The presence of Tcl_Interp as an arg prevents giving arg list */
00442 BN_EXPORT extern void bn_tcl_setup();
00443 BN_EXPORT extern int Bn_Init();
00444 BN_EXPORT extern void bn_tcl_mat_print();
00445 
00446 /** @} */
00447 /*----------------------------------------------------------------------*/
00448 /* complex.c */
00449 /** @addtogroup complex */
00450 /** @{ */
00451 /*
00452  * Complex numbers
00453  */
00454 
00455 /** "complex number" data type: */
00456 typedef struct bn_complex {
00457     double re;          /**< @brief real part */
00458     double im;          /**< @brief imaginary part */
00459 }  bn_complex_t;
00460 
00461 /* functions that are efficiently done as macros: */
00462 
00463 #define bn_cx_copy(ap, bp) {*(ap) = *(bp);}
00464 #define bn_cx_neg(cp) { (cp)->re = -((cp)->re);(cp)->im = -((cp)->im);}
00465 #define bn_cx_real(cp)          (cp)->re
00466 #define bn_cx_imag(cp)          (cp)->im
00467 
00468 #define bn_cx_add(ap, bp) { (ap)->re += (bp)->re; (ap)->im += (bp)->im;}
00469 #define bn_cx_ampl(cp)          hypot((cp)->re, (cp)->im)
00470 #define bn_cx_amplsq(cp)                ((cp)->re * (cp)->re + (cp)->im * (cp)->im)
00471 #define bn_cx_conj(cp) { (cp)->im = -(cp)->im; }
00472 #define bn_cx_cons(cp, r, i) { (cp)->re = r; (cp)->im = i; }
00473 #define bn_cx_phas(cp)          atan2((cp)->im, (cp)->re)
00474 #define bn_cx_scal(cp, s) { (cp)->re *= (s); (cp)->im *= (s); }
00475 #define bn_cx_sub(ap, bp) { (ap)->re -= (bp)->re; (ap)->im -= (bp)->im;}
00476 
00477 #define bn_cx_mul(ap, bp)               \
00478     { register fastf_t a__re, b__re; \
00479         (ap)->re = ((a__re=(ap)->re)*(b__re=(bp)->re)) - (ap)->im*(bp)->im; \
00480         (ap)->im = a__re*(bp)->im + (ap)->im*b__re; }
00481 
00482 /* Output variable "ap" is different from input variables "bp" or "cp" */
00483 #define bn_cx_mul2(ap, bp, cp) { \
00484         (ap)->re = (cp)->re * (bp)->re - (cp)->im * (bp)->im; \
00485         (ap)->im = (cp)->re * (bp)->im + (cp)->im * (bp)->re; }
00486 
00487 /**
00488  * B N _ C X _ D I V
00489  *@brief
00490  * Divide one complex by another
00491  *
00492  * bn_cx_div(&a, &b).  divides a by b.  Zero divisor fails.  a and b
00493  * may coincide.  Result stored in a.
00494  */
00495 BN_EXPORT extern void bn_cx_div(bn_complex_t *ap,
00496                                 const bn_complex_t *bp);
00497 
00498 /**
00499  * B N _ C X _ S Q R T
00500  *@brief
00501  * Compute square root of complex number
00502  *
00503  * bn_cx_sqrt(&out, &c) replaces out by sqrt(c)
00504  *
00505  * Note: This is a double-valued function; the result of bn_cx_sqrt()
00506  * always has nonnegative imaginary part.
00507  */
00508 BN_EXPORT extern void bn_cx_sqrt(bn_complex_t *op,
00509                                  const bn_complex_t *ip);
00510 
00511 /*----------------------------------------------------------------------*/
00512 /* mat.c */
00513 /*
00514  * 4x4 Matrix math
00515  */
00516 BN_EXPORT extern const mat_t bn_mat_identity;
00517 
00518 BN_EXPORT extern void bn_mat_print(const char *title,
00519                                    const mat_t m);
00520 BN_EXPORT extern void bn_mat_print_guts(const char *title,
00521                                         const mat_t m,
00522                                         char *buf,
00523                                         int buflen);
00524 BN_EXPORT extern void bn_mat_print_vls(const char *title,
00525                                        const mat_t m,
00526                                        struct bu_vls *vls);
00527 BN_EXPORT extern double bn_atan2(double x, double y);
00528 
00529 #define bn_mat_zero(_m) { \
00530         bu_log("%s:%d bn_mat_zero() is deprecated, use MAT_ZERO()\n", \
00531                __FILE__, __LINE__); \
00532         (_m)[0] = (_m)[1] = (_m)[2] = (_m)[3] = \
00533             (_m)[4] = (_m)[5] = (_m)[6] = (_m)[7] = \
00534             (_m)[8] = (_m)[9] = (_m)[10] = (_m)[11] = \
00535             (_m)[12] = (_m)[13] = (_m)[14] = (_m)[15] = 0.0; }
00536 /*
00537   #define bn_mat_zero(_m)       (void)memset((void *)_m, 0, sizeof(mat_t))
00538 */
00539 #define bn_mat_idn(_m) { \
00540         bu_log("%s:%d bn_mat_idn() is deprecated, use MAT_IDN()\n", \
00541                __FILE__, __LINE__); \
00542         (_m)[1] = (_m)[2] = (_m)[3] = (_m)[4] = \
00543             (_m)[6] = (_m)[7] = (_m)[8] = (_m)[9] = \
00544             (_m)[11] = (_m)[12] = (_m)[13] = (_m)[14] = 0.0; \
00545         (_m)[0] = (_m)[5] = (_m)[10] = (_m)[15] = 1.0; }
00546 /*
00547   #define bn_mat_idn(_m)        (void)memcpy((void *)_m, (const void *)bn_mat_identity, sizeof(mat_t))
00548 */
00549 
00550 #define bn_mat_copy(_d, _s) { \
00551         bu_log("%s:%d bn_mat_copy() is deprecated, use MAT_COPY()\n", \
00552                __FILE__, __LINE__); \
00553         (_d)[0] = (_s)[0];\
00554         (_d)[1] = (_s)[1];\
00555         (_d)[2] = (_s)[2];\
00556         (_d)[3] = (_s)[3];\
00557         (_d)[4] = (_s)[4];\
00558         (_d)[5] = (_s)[5];\
00559         (_d)[6] = (_s)[6];\
00560         (_d)[7] = (_s)[7];\
00561         (_d)[8] = (_s)[8];\
00562         (_d)[9] = (_s)[9];\
00563         (_d)[10] = (_s)[10];\
00564         (_d)[11] = (_s)[11];\
00565         (_d)[12] = (_s)[12];\
00566         (_d)[13] = (_s)[13];\
00567         (_d)[14] = (_s)[14];\
00568         (_d)[15] = (_s)[15]; }
00569 /*
00570   #define bn_mat_copy(_d, _s)   (void)memcpy((void *)_d, (const void *)(_s), sizeof(mat_t))
00571 */
00572 
00573 
00574 BN_EXPORT extern void bn_mat_mul(mat_t o,
00575                                  const mat_t a,
00576                                  const mat_t b);
00577 BN_EXPORT extern void bn_mat_mul2(const mat_t i,
00578                                   mat_t o);
00579 BN_EXPORT extern void bn_mat_mul3(mat_t o,
00580                                   const mat_t a,
00581                                   const mat_t b,
00582                                   const mat_t c);
00583 BN_EXPORT extern void bn_mat_mul4(mat_t o,
00584                                   const mat_t a,
00585                                   const mat_t b,
00586                                   const mat_t c,
00587                                   const mat_t d);
00588 BN_EXPORT extern void bn_matXvec(hvect_t ov,
00589                                  const mat_t im,
00590                                  const hvect_t iv);
00591 BN_EXPORT extern void bn_mat_inv(mat_t output,
00592                                  const mat_t input);
00593 BN_EXPORT extern int bn_mat_inverse(mat_t output,
00594                                     const mat_t input);
00595 BN_EXPORT extern void bn_vtoh_move(vect_t h,
00596                                    const vect_t v);
00597 BN_EXPORT extern void bn_htov_move(vect_t v,
00598                                    const vect_t h);
00599 BN_EXPORT extern void bn_mat_trn(mat_t om,
00600                                  const mat_t im);
00601 BN_EXPORT extern void bn_mat_ae(mat_t m,
00602                                 double azimuth,
00603                                 double elev);
00604 BN_EXPORT extern void bn_ae_vec(fastf_t *azp,
00605                                 fastf_t *elp,
00606                                 const vect_t v);
00607 BN_EXPORT extern void bn_aet_vec(fastf_t *az,
00608                                  fastf_t *el,
00609                                  fastf_t *twist,
00610                                  vect_t vec_ae,
00611                                  vect_t vec_twist,
00612                                  fastf_t accuracy);
00613 BN_EXPORT extern void bn_vec_ae(vect_t vec,
00614                                 fastf_t az,
00615                                 fastf_t el);
00616 BN_EXPORT extern void bn_vec_aed(vect_t vec,
00617                                  fastf_t az,
00618                                  fastf_t el,
00619                                  fastf_t dist);
00620 
00621 BN_EXPORT extern void bn_mat_angles(mat_t mat,
00622                                     double alpha,
00623                                     double beta, double ggamma);
00624 BN_EXPORT extern void bn_mat_angles_rad(mat_t mat,
00625                                         double alpha,
00626                                         double beta,
00627                                         double ggamma);
00628 
00629 BN_EXPORT extern void bn_eigen2x2(fastf_t *val1,
00630                                   fastf_t *val2,
00631                                   vect_t vec1,
00632                                   vect_t vec2,
00633                                   fastf_t a,
00634                                   fastf_t b,
00635                                   fastf_t c);
00636 
00637 BN_EXPORT extern void bn_vec_perp(vect_t new_vec,
00638                                   const vect_t old_vec);
00639 BN_EXPORT extern void bn_mat_fromto(mat_t m,
00640                                     const vect_t from,
00641                                     const vect_t to);
00642 BN_EXPORT extern void bn_mat_xrot(mat_t m,
00643                                   double sinx,
00644                                   double cosx);
00645 BN_EXPORT extern void bn_mat_yrot(mat_t m,
00646                                   double siny,
00647                                   double cosy);
00648 BN_EXPORT extern void bn_mat_zrot(mat_t m,
00649                                   double sinz,
00650                                   double cosz);
00651 BN_EXPORT extern void bn_mat_lookat(mat_t rot,
00652                                     const vect_t dir,
00653                                     int yflip);
00654 BN_EXPORT extern void bn_vec_ortho(vect_t out,
00655                                    const vect_t in);
00656 BN_EXPORT extern int bn_mat_scale_about_pt(mat_t mat,
00657                                            const point_t pt,
00658                                            const double scale);
00659 BN_EXPORT extern void bn_mat_xform_about_pt(mat_t mat,
00660                                             const mat_t xform,
00661                                             const point_t pt);
00662 BN_EXPORT extern int bn_mat_is_equal(const mat_t a,
00663                                      const mat_t b,
00664                                      const struct bn_tol *tol);
00665 BN_EXPORT extern int bn_mat_is_identity(const mat_t m);
00666 BN_EXPORT extern void bn_mat_arb_rot(mat_t m,
00667                                      const point_t pt,
00668                                      const vect_t dir,
00669                                      const fastf_t ang);
00670 BN_EXPORT extern matp_t bn_mat_dup(const mat_t in);
00671 BN_EXPORT extern int bn_mat_ck(const char *title,
00672                                const mat_t m);
00673 BN_EXPORT extern fastf_t bn_mat_det3(const mat_t m);
00674 BN_EXPORT extern fastf_t bn_mat_determinant(const mat_t m);
00675 
00676 BN_EXPORT extern int bn_mat_is_non_unif(const mat_t m);
00677 
00678 BN_EXPORT extern void bn_wrt_point_direc(mat_t out,
00679                                          const mat_t change,
00680                                          const mat_t in,
00681                                          const point_t point,
00682                                          const vect_t direc);
00683 
00684 /** @} */
00685 /*----------------------------------------------------------------------*/
00686 /* msr.c */
00687 /** @addtogroup msr */
00688 /** @{ */
00689 /*
00690  * Define data structures and constants for the "MSR" random number
00691  * package.
00692  *
00693  * Also define a set of macros to access the random number tables and
00694  * to limit the area/volume that a set of random numbers inhabit.
00695  */
00696 
00697 struct bn_unif {
00698     uint32_t magic;
00699     long msr_seed;
00700     int msr_double_ptr;
00701     double *msr_doubles;
00702     int msr_long_ptr;
00703     long *msr_longs;
00704 };
00705 
00706 #define BN_CK_UNIF(_p)  BU_CKMAG(_p, BN_UNIF_MAGIC, "bn_unif")
00707 #define BN_CK_GAUSS(_p) BU_CKMAG(_p, BN_GAUSS_MAGIC, "bn_gauss")
00708 
00709 
00710 /**
00711  * NOTE!!! The order of msr_gauss and msr_unif MUST match in the first
00712  * three entries as msr_gauss is passed as a msr_unif in
00713  * msr_gauss_fill.
00714  */
00715 struct bn_gauss {
00716     uint32_t magic;
00717     long msr_gauss_seed;
00718     int msr_gauss_dbl_ptr;
00719     double *msr_gauss_doubles;
00720     int msr_gauss_ptr;
00721     double *msr_gausses;
00722 };
00723 
00724 BN_EXPORT extern struct bn_unif *bn_unif_init(long setseed,
00725                                               int method);
00726 BN_EXPORT extern void bn_unif_free(struct bn_unif *p);
00727 BN_EXPORT extern long bn_unif_long_fill(struct bn_unif *p);
00728 BN_EXPORT extern double bn_unif_double_fill(struct bn_unif *p);
00729 BN_EXPORT extern struct bn_gauss *bn_gauss_init(long setseed,
00730                                                 int method);
00731 BN_EXPORT extern void bn_gauss_free(struct bn_gauss *p);
00732 BN_EXPORT extern double bn_gauss_fill(struct bn_gauss *p);
00733 
00734 #define BN_UNIF_LONG(_p)        \
00735     (((_p)->msr_long_ptr) ? \
00736      (_p)->msr_longs[--(_p)->msr_long_ptr] : \
00737      bn_unif_long_fill(_p))
00738 #define BN_UNIF_DOUBLE(_p)      \
00739     (((_p)->msr_double_ptr) ? \
00740      (_p)->msr_doubles[--(_p)->msr_double_ptr] : \
00741      bn_unif_double_fill(_p))
00742 
00743 #define BN_UNIF_CIRCLE(_p, _x, _y, _r) { \
00744         do { \
00745             (_x) = 2.0*BN_UNIF_DOUBLE((_p)); \
00746             (_y) = 2.0*BN_UNIF_DOUBLE((_p)); \
00747             (_r) = (_x)*(_x)+(_y)*(_y); \
00748         } while ((_r) >= 1.0);  }
00749 
00750 #define BN_UNIF_SPHERE(_p, _x, _y, _z, _r) { \
00751         do { \
00752             (_x) = 2.0*BN_UNIF_DOUBLE(_p); \
00753             (_y) = 2.0*BN_UNIF_DOUBLE(_p); \
00754             (_z) = 2.0*BN_UNIF_DOUBLE(_p); \
00755             (_r) = (_x)*(_x)+(_y)*(_y)+(_z)*(_z);\
00756         } while ((_r) >= 1.0) }
00757 
00758 #define BN_GAUSS_DOUBLE(_p)     \
00759     (((_p)->msr_gauss_ptr) ? \
00760      (_p)->msr_gausses[--(_p)->msr_gauss_ptr] : \
00761      bn_gauss_fill(_p))
00762 
00763 /** @} */
00764 /*----------------------------------------------------------------------*/
00765 /* noise.c */
00766 /* @addtogroup noise */
00767 /** @{ */
00768 /*
00769  * fractal noise support
00770  */
00771 
00772 BN_EXPORT extern void bn_noise_init();
00773 BN_EXPORT extern double bn_noise_perlin(point_t pt);
00774 /* FIXME: Why isn't the result listed first? */
00775 BN_EXPORT extern void bn_noise_vec(point_t point,
00776                                    point_t result);
00777 BN_EXPORT extern double bn_noise_fbm(point_t point,
00778                                      double h_val,
00779                                      double lacunarity,
00780                                      double octaves);
00781 BN_EXPORT extern double bn_noise_turb(point_t point,
00782                                       double h_val,
00783                                       double lacunarity,
00784                                       double octaves);
00785 BN_EXPORT extern double bn_noise_mf(point_t point,
00786                                     double h_val,
00787                                     double lacunarity,
00788                                     double octaves,
00789                                     double offset);
00790 BN_EXPORT extern double bn_noise_ridged(point_t point,
00791                                         double h_val,
00792                                         double lacunarity,
00793                                         double octaves,
00794                                         double offset);
00795 
00796 /*----------------------------------------------------------------------*/
00797 /* plane.c */
00798 /*
00799  * Plane/line/point calculations
00800  */
00801 
00802 
00803 BN_EXPORT extern int bn_distsq_line3_line3(fastf_t dist[3],
00804                                            point_t P,
00805                                            vect_t d,
00806                                            point_t Q,
00807                                            vect_t e,
00808                                            point_t pt1,
00809                                            point_t pt2);
00810 
00811 BN_EXPORT extern int bn_dist_pt3_line3(fastf_t *dist,
00812                                        point_t pca,
00813                                        const point_t a,
00814                                        const point_t p,
00815                                        const vect_t dir,
00816                                        const struct bn_tol *tol);
00817 
00818 BN_EXPORT extern int bn_dist_line3_lseg3(fastf_t *dist,
00819                                          const fastf_t *p,
00820                                          const fastf_t *d,
00821                                          const fastf_t *a,
00822                                          const fastf_t *b,
00823                                          const struct bn_tol *tol);
00824 
00825 BN_EXPORT extern int bn_dist_line3_line3(fastf_t dist[2],
00826                                          const point_t p1,
00827                                          const point_t p2,
00828                                          const vect_t d1,
00829                                          const vect_t d2,
00830                                          const struct bn_tol *tol);
00831 
00832 BN_EXPORT extern int bn_dist_pt3_lseg3(fastf_t *dist,
00833                                        point_t pca,
00834                                        const point_t a,
00835                                        const point_t b,
00836                                        const point_t p,
00837                                        const struct bn_tol *tol);
00838 BN_EXPORT extern int bn_3pts_collinear(point_t a,
00839                                        point_t b,
00840                                        point_t c,
00841                                        const struct bn_tol *tol);
00842 BN_EXPORT extern int bn_pt3_pt3_equal(const point_t a,
00843                                       const point_t b,
00844                                       const struct bn_tol *tol);
00845 BN_EXPORT extern int bn_dist_pt2_lseg2(fastf_t *dist_sq,
00846                                        fastf_t pca[2],
00847                                        const point_t a,
00848                                        const point_t b,
00849                                        const point_t p,
00850                                        const struct bn_tol *tol);
00851 BN_EXPORT extern int bn_isect_lseg3_lseg3(fastf_t *dist,
00852                                               const point_t p, const vect_t pdir,
00853                                               const point_t q, const vect_t qdir,
00854                                               const struct bn_tol *tol);
00855 BN_EXPORT extern int bn_isect_line3_line3(fastf_t *s, fastf_t *t,
00856                                               const point_t p0,
00857                                               const vect_t u,
00858                                               const point_t q0,
00859                                               const vect_t v,
00860                                               const struct bn_tol *tol);
00861 BN_EXPORT extern int bn_2line3_colinear(const point_t p1,
00862                                         const vect_t d1,
00863                                         const point_t p2,
00864                                         const vect_t d2,
00865                                         double range,
00866                                         const struct bn_tol *tol);
00867 BN_EXPORT extern int bn_isect_pt2_lseg2(fastf_t *dist,
00868                                         const point_t a,
00869                                         const point_t b,
00870                                         const point_t p,
00871                                         const struct bn_tol *tol);
00872 BN_EXPORT extern int bn_isect_line2_lseg2(fastf_t *dist,
00873                                           const point_t p,
00874                                           const vect_t d,
00875                                           const point_t a,
00876                                           const vect_t c,
00877                                           const struct bn_tol *tol);
00878 BN_EXPORT extern int bn_isect_lseg2_lseg2(fastf_t *dist,
00879                                           const point_t p,
00880                                           const vect_t pdir,
00881                                           const point_t q,
00882                                           const vect_t qdir,
00883                                           const struct bn_tol *tol);
00884 BN_EXPORT extern int bn_isect_line2_line2(fastf_t *dist,
00885                                           const point_t p,
00886                                           const vect_t d,
00887                                           const point_t a,
00888                                           const vect_t c,
00889                                           const struct bn_tol *tol);
00890 BN_EXPORT extern double bn_dist_pt3_pt3(const point_t a,
00891                                         const point_t b);
00892 BN_EXPORT extern int bn_3pts_distinct(const point_t a,
00893                                       const point_t b,
00894                                       const point_t c,
00895                                       const struct bn_tol *tol);
00896 BN_EXPORT extern int bn_npts_distinct(const int npts,
00897                                       const point_t *pts,
00898                                       const struct bn_tol *tol);
00899 BN_EXPORT extern int bn_mk_plane_3pts(plane_t plane,
00900                                       const point_t a,
00901                                       const point_t b,
00902                                       const point_t c,
00903                                       const struct bn_tol *tol);
00904 BN_EXPORT extern int bn_mkpoint_3planes(point_t pt,
00905                                         const plane_t a,
00906                                         const plane_t b,
00907                                         const plane_t c);
00908 BN_EXPORT extern int bn_isect_line3_plane(fastf_t *dist,
00909                                           const point_t pt,
00910                                           const vect_t dir,
00911                                           const plane_t plane,
00912                                           const struct bn_tol *tol);
00913 BN_EXPORT extern int bn_isect_2planes(point_t pt,
00914                                       vect_t dir,
00915                                       const plane_t a,
00916                                       const plane_t b,
00917                                       const vect_t rpp_min,
00918                                       const struct bn_tol *tol);
00919 BN_EXPORT extern int bn_isect_2lines(fastf_t *t,
00920                                      fastf_t *u,
00921                                      const point_t p,
00922                                      const vect_t d,
00923                                      const point_t a,
00924                                      const vect_t c,
00925                                      const struct bn_tol *tol);
00926 BN_EXPORT extern int bn_isect_line_lseg(fastf_t *t, const point_t p,
00927                                         const vect_t d,
00928                                         const point_t a,
00929                                         const point_t b,
00930                                         const struct bn_tol *tol);
00931 BN_EXPORT extern double bn_dist_line3_pt3(const point_t pt,
00932                                           const vect_t dir,
00933                                           const point_t a);
00934 BN_EXPORT extern double bn_distsq_line3_pt3(const point_t pt,
00935                                             const vect_t dir,
00936                                             const point_t a);
00937 BN_EXPORT extern double bn_dist_line_origin(const point_t pt,
00938                                             const vect_t dir);
00939 BN_EXPORT extern double bn_dist_line2_point2(const point_t pt,
00940                                              const vect_t dir,
00941                                              const point_t a);
00942 BN_EXPORT extern double bn_distsq_line2_point2(const point_t pt,
00943                                                const vect_t dir,
00944                                                const point_t a);
00945 BN_EXPORT extern double bn_area_of_triangle(const point_t a,
00946                                             const point_t b,
00947                                             const point_t c);
00948 BN_EXPORT extern int bn_isect_pt_lseg(fastf_t *dist,
00949                                       const point_t a,
00950                                       const point_t b,
00951                                       const point_t p,
00952                                       const struct bn_tol *tol);
00953 BN_EXPORT extern double bn_dist_pt_lseg(point_t pca,
00954                                         const point_t a,
00955                                         const point_t b,
00956                                         const point_t p,
00957                                         const struct bn_tol *tol);
00958 BN_EXPORT extern void bn_rotate_bbox(point_t omin,
00959                                      point_t omax,
00960                                      const mat_t mat,
00961                                      const point_t imin,
00962                                      const point_t imax);
00963 BN_EXPORT extern void bn_rotate_plane(plane_t oplane,
00964                                       const mat_t mat,
00965                                       const plane_t iplane);
00966 BN_EXPORT extern int bn_coplanar(const plane_t a,
00967                                  const plane_t b,
00968                                  const struct bn_tol *tol);
00969 BN_EXPORT extern double bn_angle_measure(vect_t vec,
00970                                          const vect_t x_dir,
00971                                          const vect_t y_dir);
00972 BN_EXPORT extern double bn_dist_pt3_along_line3(const point_t p,
00973                                                 const vect_t d,
00974                                                 const point_t x);
00975 BN_EXPORT extern double bn_dist_pt2_along_line2(const point_t p,
00976                                                 const vect_t d,
00977                                                 const point_t x);
00978 BN_EXPORT extern int bn_between(double left,
00979                                 double mid,
00980                                 double right,
00981                                 const struct bn_tol *tol);
00982 BN_EXPORT extern int bn_does_ray_isect_tri(const point_t pt,
00983                                            const vect_t dir,
00984                                            const point_t V,
00985                                            const point_t A,
00986                                            const point_t B,
00987                                            point_t inter);
00988 BN_EXPORT extern int bn_hlf_class(const plane_t half_eqn,
00989                                   const vect_t min, const vect_t max,
00990                                   const struct bn_tol *tol);
00991 
00992 #define BN_CLASSIFY_UNIMPLEMENTED 0x0000
00993 #define BN_CLASSIFY_INSIDE        0x0001
00994 #define BN_CLASSIFY_OVERLAPPING   0x0002
00995 #define BN_CLASSIFY_OUTSIDE       0x0003
00996 
00997 BN_EXPORT extern int bn_isect_planes(point_t pt,
00998                                      const plane_t planes[],
00999                                      const size_t pl_count);
01000 
01001 /** @} */
01002 /*----------------------------------------------------------------------*/
01003 /* poly.c */
01004 /** @addtogroup poly */
01005 /** @{ */
01006 
01007 /* This could be larger, or even dynamic... */
01008 #define BN_MAX_POLY_DEGREE 4    /**< Maximum Poly Order */
01009 /**
01010  * Polynomial data type
01011  * bn_poly->cf[n] corresponds to X^n
01012  */
01013 typedef struct bn_poly {
01014     uint32_t magic;
01015     size_t dgr;
01016     double cf[BN_MAX_POLY_DEGREE+1];
01017 }  bn_poly_t;
01018 #define BN_CK_POLY(_p) BU_CKMAG(_p, BN_POLY_MAGIC, "struct bn_poly")
01019 #define BN_POLY_NULL   ((struct bn_poly *)NULL)
01020 
01021 BN_EXPORT extern struct bn_poly *bn_poly_mul(struct bn_poly *product,
01022                                              const struct bn_poly *m1,
01023                                              const struct bn_poly *m2);
01024 BN_EXPORT extern struct bn_poly *bn_poly_scale(struct bn_poly *eqn,
01025                                                double factor);
01026 BN_EXPORT extern struct bn_poly *bn_poly_add(struct bn_poly *sum,
01027                                              const struct bn_poly *poly1,
01028                                              const struct bn_poly *poly2);
01029 BN_EXPORT extern struct bn_poly *bn_poly_sub(struct bn_poly *diff,
01030                                              const struct bn_poly *poly1,
01031                                              const struct bn_poly *poly2);
01032 BN_EXPORT extern void bn_poly_synthetic_division(struct bn_poly *quo,
01033                                                  struct bn_poly *rem,
01034                                                  const struct bn_poly *dvdend,
01035                                                  const struct bn_poly *dvsor);
01036 BN_EXPORT extern int bn_poly_quadratic_roots(struct bn_complex roots[],
01037                                              const struct bn_poly *quadrat);
01038 BN_EXPORT extern int bn_poly_cubic_roots(struct bn_complex roots[],
01039                                          const struct bn_poly *eqn);
01040 BN_EXPORT extern int bn_poly_quartic_roots(struct bn_complex roots[],
01041                                            const struct bn_poly *eqn);
01042 BN_EXPORT extern int bn_poly_findroot(bn_poly_t *eqn, 
01043                                       bn_complex_t *nxZ, 
01044                                       const char *str);
01045 BN_EXPORT extern void bn_poly_eval_w_2derivatives(bn_complex_t *cZ,
01046                                                   bn_poly_t *eqn,
01047                                                   bn_complex_t *b,
01048                                                   bn_complex_t *c,
01049                                                   bn_complex_t *d);
01050 BN_EXPORT extern int bn_poly_checkroots(bn_poly_t *eqn,
01051                                         bn_complex_t *roots,
01052                                         int nroots);
01053 BN_EXPORT extern void bn_poly_deflate(bn_poly_t *oldP,
01054                                       bn_complex_t *root);
01055 BN_EXPORT extern int bn_poly_roots(bn_poly_t *eqn,
01056                                    bn_complex_t roots[],
01057                                    const char *name);
01058 BN_EXPORT extern void bn_pr_poly(const char *title,
01059                                  const struct bn_poly *eqn);
01060 BN_EXPORT extern void bn_pr_roots(const char *title,
01061                                   const struct bn_complex roots[],
01062                                   int n);
01063 
01064 /** @} */
01065 /*----------------------------------------------------------------------*/
01066 /* multipoly.c */
01067 /** @addtogroup multipoly */
01068 /** @{ */
01069 
01070 /**
01071  * Polynomial data type
01072  */
01073 typedef struct bn_multipoly {
01074     uint32_t magic;
01075     int dgrs;
01076     int dgrt;
01077     double **cf;
01078 }  bn_multipoly_t;
01079 
01080 /** @} */
01081 /*----------------------------------------------------------------------*/
01082 /* qmath.c */
01083 /** @addtogroup mat */
01084 /** @{ */
01085 /*
01086  * Quaternion support
01087  */
01088 
01089 BN_EXPORT extern void quat_mat2quat(quat_t quat,
01090                                     const mat_t mat);
01091 BN_EXPORT extern void quat_quat2mat(mat_t mat,
01092                                     const quat_t quat);
01093 BN_EXPORT extern double quat_distance(const quat_t q1,
01094                                       const quat_t q2);
01095 BN_EXPORT extern void quat_double(quat_t qout,
01096                                   const quat_t q1,
01097                                   const quat_t q2);
01098 BN_EXPORT extern void quat_bisect(quat_t qout,
01099                                   const quat_t q1,
01100                                   const quat_t q2);
01101 BN_EXPORT extern void quat_slerp(quat_t qout,
01102                                  const quat_t q1,
01103                                  const quat_t q2,
01104                                  double f);
01105 BN_EXPORT extern void quat_sberp(quat_t qout,
01106                                  const quat_t q1,
01107                                  const quat_t qa,
01108                                  const quat_t qb,
01109                                  const quat_t q2,
01110                                  double f);
01111 BN_EXPORT extern void quat_make_nearest(quat_t q1,
01112                                         const quat_t q2);
01113 BN_EXPORT extern void quat_print(const char *title,
01114                                  const quat_t quat);
01115 BN_EXPORT extern void quat_exp(quat_t out,
01116                                const quat_t in);
01117 BN_EXPORT extern void quat_log(quat_t out,
01118                                const quat_t in);
01119 /** @} */
01120 /*----------------------------------------------------------------------*/
01121 /* rand.c */
01122 /** @addtogroup rnd */
01123 /** @{ */
01124 /**
01125  * A supply of fast pseudo-random numbers from table in bn/rand.c.
01126  * The values are in the open interval (i.e. exclusive) of 0.0 to 1.0
01127  * range with a period of 4096.
01128  *
01129  * @par Usage:
01130  @code
01131  unsigned idx;
01132  float f;
01133 
01134  BN_RANDSEED(idx, integer_seed);
01135 
01136  while (NEED_MORE_RAND_NUMBERS) {
01137  f = BN_RANDOM(idx);
01138  }
01139  @endcode
01140  *
01141  * Note that the values from bn_rand_half() become all 0.0 when the
01142  * benchmark flag is set (bn_rand_halftab is set to all 0's).  The
01143  * numbers from bn_rand_table do not change, because the procedural
01144  * noise would cease to exist.
01145  */
01146 #define BN_RAND_TABSIZE 4096
01147 #define BN_RAND_TABMASK 0xfff
01148 #define BN_RANDSEED(_i, _seed)  _i = ((unsigned)_seed) % BN_RAND_TABSIZE
01149 BN_EXPORT extern const float bn_rand_table[BN_RAND_TABSIZE];
01150 
01151 /** BN_RANDOM always gives numbers between the open interval 0.0 to 1.0 */
01152 #define BN_RANDOM(_i)   bn_rand_table[ _i = (_i+1) % BN_RAND_TABSIZE ]
01153 
01154 /** BN_RANDHALF always gives numbers between the open interval -0.5 and 0.5 */
01155 #define BN_RANDHALF(_i) (bn_rand_table[ _i = (_i+1) % BN_RAND_TABSIZE ]-0.5)
01156 #define BN_RANDHALF_INIT(_p) _p = bn_rand_table
01157 
01158 #define BN_RANDHALFTABSIZE 16535        /**< Powers of two give streaking */
01159 BN_EXPORT extern int bn_randhalftabsize;
01160 BN_EXPORT extern float bn_rand_halftab[BN_RANDHALFTABSIZE];
01161 
01162 /**
01163  * random numbers between the closed interval -0.5 to 0.5 inclusive,
01164  * except when benchmark flag is set, when this becomes a constant 0.0
01165  */
01166 #define bn_rand_half(_p)        \
01167     ((++(_p) >= &bn_rand_halftab[bn_randhalftabsize] || \
01168       (_p) < bn_rand_halftab) ? \
01169      *((_p) = bn_rand_halftab) : *(_p))
01170 
01171 /**
01172  * initialize the seed for the large random number table (halftab)
01173  */
01174 #define bn_rand_init(_p, _seed) \
01175     (_p) = &bn_rand_halftab[ \
01176         (int)(\
01177             (bn_rand_halftab[(_seed)%bn_randhalftabsize] + 0.5) * \
01178             (bn_randhalftabsize-1)) ]
01179 
01180 /**
01181  * random numbers in the closed interval 0.0 to 1.0 range (inclusive)
01182  * except when benchmarking, when this is always 0.5
01183  */
01184 #define bn_rand0to1(_q) (bn_rand_half(_q)+0.5)
01185 
01186 #define BN_SINTABSIZE 2048
01187 BN_EXPORT extern double bn_sin_scale;
01188 #define bn_tab_sin(_a)  (((_a) > 0) ? \
01189                          (bn_sin_table[(int)((0.5+ (_a)*bn_sin_scale))&(BN_SINTABSIZE-1)]) :\
01190                          (-bn_sin_table[(int)((0.5- (_a)*bn_sin_scale))&(BN_SINTABSIZE-1)]))
01191 BN_EXPORT extern const float bn_sin_table[BN_SINTABSIZE];
01192 
01193 BN_EXPORT extern void bn_mathtab_constant();
01194 
01195 /** @} */
01196 /*----------------------------------------------------------------------*/
01197 /* randmt.c */
01198 /** @addtogroup rnd */
01199 /** @{ */
01200 /**
01201  * Mersenne Twister random number generation as defined by MT19937.
01202  *
01203  * Generates one pseudorandom real number (double) which is uniformly
01204  * distributed on [0, 1]-interval, for each call.
01205  *
01206  * @par Usage:
01207  @code
01208  double d;
01209 
01210  bn_randmt_seed(integer_seed);
01211 
01212  while (NEED_MORE_RAND_NUMBERS) {
01213  d = bn_randmt();
01214  }
01215  @endcode
01216  *
01217  */
01218 
01219 BN_EXPORT extern double bn_randmt();
01220 BN_EXPORT extern void bn_randmt_seed(unsigned long seed);
01221 
01222 
01223 /*----------------------------------------------------------------------*/
01224 /* wavelet.c */
01225 
01226 #define CK_POW_2(dimen) { \
01227         register unsigned long j; \
01228         register int ok; \
01229         for (ok=0, j=0; j < sizeof(unsigned long) * 8; j++) { \
01230             if ((unsigned long)(1<<j) == dimen) { ok = 1;  break; } \
01231         } \
01232         if (! ok) { \
01233             bu_log("%s:%d value %ld should be power of 2 (2^%ld)\n", \
01234                    __FILE__, __LINE__, (long)dimen, (long)j); \
01235             bu_bomb("CK_POW_2"); \
01236         } \
01237     }
01238 
01239 BN_EXPORT extern void bn_wlt_haar_1d_double_decompose(double *tbuf,
01240                                                       double *buf,
01241                                                       unsigned long dimen,
01242                                                       unsigned long depth,
01243                                                       unsigned long limit);
01244 BN_EXPORT extern void bn_wlt_haar_1d_double_reconstruct(double *tbuf,
01245                                                         double *buf,
01246                                                         unsigned long dimen,
01247                                                         unsigned long depth,
01248                                                         unsigned long subimage_size,
01249                                                         unsigned long limit);
01250 
01251 BN_EXPORT extern void bn_wlt_haar_1d_float_decompose(float *tbuf,
01252                                                      float *buf,
01253                                                      unsigned long dimen,
01254                                                      unsigned long depth,
01255                                                      unsigned long limit);
01256 BN_EXPORT extern void bn_wlt_haar_1d_float_reconstruct(float *tbuf,
01257                                                        float *buf,
01258                                                        unsigned long dimen,
01259                                                        unsigned long depth,
01260                                                        unsigned long subimage_size,
01261                                                        unsigned long limit);
01262 
01263 BN_EXPORT extern void bn_wlt_haar_1d_char_decompose(char *tbuf,
01264                                                     char *buf,
01265                                                     unsigned long dimen,
01266                                                     unsigned long depth,
01267                                                     unsigned long limit);
01268 BN_EXPORT extern void bn_wlt_haar_1d_char_reconstruct(char *tbuf, char *buf,
01269                                                       unsigned long dimen,
01270                                                       unsigned long depth,
01271                                                       unsigned long subimage_size,
01272                                                       unsigned long limit);
01273 
01274 BN_EXPORT extern void bn_wlt_haar_1d_short_decompose(short *tbuf, short *buf,
01275                                                      unsigned long dimen,
01276                                                      unsigned long depth,
01277                                                      unsigned long limit);
01278 BN_EXPORT extern void bn_wlt_haar_1d_short_reconstruct(short *tbuf, short *buf,
01279                                                        unsigned long dimen,
01280                                                        unsigned long depth,
01281                                                        unsigned long subimage_size,
01282                                                        unsigned long limit);
01283 
01284 BN_EXPORT extern void bn_wlt_haar_1d_int_decompose(int *tbuf, int *buf,
01285                                                    unsigned long dimen,
01286                                                    unsigned long depth,
01287                                                    unsigned long limit);
01288 BN_EXPORT extern void bn_wlt_haar_1d_int_reconstruct(int *tbuf,
01289                                                      int *buf,
01290                                                      unsigned long dimen,
01291                                                      unsigned long depth,
01292                                                      unsigned long subimage_size,
01293                                                      unsigned long limit);
01294 
01295 BN_EXPORT extern void bn_wlt_haar_1d_long_decompose(long *tbuf, long *buf,
01296                                                     unsigned long dimen,
01297                                                     unsigned long depth,
01298                                                     unsigned long limit);
01299 BN_EXPORT extern void bn_wlt_haar_1d_long_reconstruct(long *tbuf, long *buf,
01300                                                       unsigned long dimen,
01301                                                       unsigned long depth,
01302                                                       unsigned long subimage_size,
01303                                                       unsigned long limit);
01304 
01305 
01306 BN_EXPORT extern void bn_wlt_haar_2d_double_decompose(double *tbuf,
01307                                                       double *buf,
01308                                                       unsigned long dimen,
01309                                                       unsigned long depth,
01310                                                       unsigned long limit);
01311 BN_EXPORT extern void bn_wlt_haar_2d_double_reconstruct(double *tbuf,
01312                                                         double *buf,
01313                                                         unsigned long dimen,
01314                                                         unsigned long depth,
01315                                                         unsigned long subimage_size,
01316                                                         unsigned long limit);
01317 
01318 BN_EXPORT extern void bn_wlt_haar_2d_float_decompose(float *tbuf,
01319                                                      float *buf,
01320                                                      unsigned long dimen,
01321                                                      unsigned long depth,
01322                                                      unsigned long limit);
01323 BN_EXPORT extern void bn_wlt_haar_2d_float_reconstruct(float *tbuf,
01324                                                        float *buf,
01325                                                        unsigned long dimen,
01326                                                        unsigned long depth,
01327                                                        unsigned long subimage_size,
01328                                                        unsigned long limit);
01329 
01330 BN_EXPORT extern void bn_wlt_haar_2d_char_decompose(char *tbuf,
01331                                                     char *buf,
01332                                                     unsigned long dimen,
01333                                                     unsigned long depth,
01334                                                     unsigned long limit);
01335 BN_EXPORT extern void bn_wlt_haar_2d_char_reconstruct(char *tbuf,
01336                                                       char *buf,
01337                                                       unsigned long dimen,
01338                                                       unsigned long depth,
01339                                                       unsigned long subimage_size,
01340                                                       unsigned long limit);
01341 
01342 BN_EXPORT extern void bn_wlt_haar_2d_short_decompose(short *tbuf,
01343                                                      short *buf,
01344                                                      unsigned long dimen,
01345                                                      unsigned long depth,
01346                                                      unsigned long limit);
01347 BN_EXPORT extern void bn_wlt_haar_2d_short_reconstruct(short *tbuf,
01348                                                        short *buf,
01349                                                        unsigned long dimen,
01350                                                        unsigned long depth,
01351                                                        unsigned long subimage_size,
01352                                                        unsigned long limit);
01353 
01354 BN_EXPORT extern void bn_wlt_haar_2d_int_decompose(int *tbuf,
01355                                                    int *buf,
01356                                                    unsigned long dimen,
01357                                                    unsigned long depth,
01358                                                    unsigned long limit);
01359 BN_EXPORT extern void bn_wlt_haar_2d_int_reconstruct(int *tbuf,
01360                                                      int *buf,
01361                                                      unsigned long dimen,
01362                                                      unsigned long depth,
01363                                                      unsigned long subimage_size,
01364                                                      unsigned long limit);
01365 
01366 BN_EXPORT extern void bn_wlt_haar_2d_long_decompose(long *tbuf,
01367                                                     long *buf,
01368                                                     unsigned long dimen,
01369                                                     unsigned long depth,
01370                                                     unsigned long limit);
01371 BN_EXPORT extern void bn_wlt_haar_2d_long_reconstruct(long *tbuf,
01372                                                       long *buf,
01373                                                       unsigned long dimen,
01374                                                       unsigned long depth,
01375                                                       unsigned long subimage_size,
01376                                                       unsigned long limit);
01377 
01378 
01379 BN_EXPORT extern void bn_wlt_haar_2d_double_decompose2(double *tbuf,
01380                                                        double *buf,
01381                                                        unsigned long dimen,
01382                                                        unsigned long width,
01383                                                        unsigned long height,
01384                                                        unsigned long limit);
01385 BN_EXPORT extern void bn_wlt_haar_2d_double_reconstruct2(double *tbuf,
01386                                                          double *buf,
01387                                                          unsigned long dimen,
01388                                                          unsigned long width,
01389                                                          unsigned long height,
01390                                                          unsigned long subimage_size,
01391                                                          unsigned long limit);
01392 
01393 BN_EXPORT extern void bn_wlt_haar_2d_float_decompose2(float *tbuf,
01394                                                       float *buf,
01395                                                       unsigned long dimen,
01396                                                       unsigned long width,
01397                                                       unsigned long height,
01398                                                       unsigned long limit);
01399 BN_EXPORT extern void bn_wlt_haar_2d_float_reconstruct2(float *tbuf,
01400                                                         float *buf,
01401                                                         unsigned long dimen,
01402                                                         unsigned long width,
01403                                                         unsigned long height,
01404                                                         unsigned long subimage_size,
01405                                                         unsigned long limit);
01406 
01407 BN_EXPORT extern void bn_wlt_haar_2d_char_decompose2(char *tbuf,
01408                                                      char *buf,
01409                                                      unsigned long dimen,
01410                                                      unsigned long width,
01411                                                      unsigned long height,
01412                                                      unsigned long limit);
01413 BN_EXPORT extern void bn_wlt_haar_2d_char_reconstruct2(char *tbuf,
01414                                                        char *buf,
01415                                                        unsigned long dimen,
01416                                                        unsigned long width,
01417                                                        unsigned long height,
01418                                                        unsigned long subimage_size,
01419                                                        unsigned long limit);
01420 
01421 BN_EXPORT extern void bn_wlt_haar_2d_short_decompose2(short *tbuf,
01422                                                       short *buf,
01423                                                       unsigned long dimen,
01424                                                       unsigned long width,
01425                                                       unsigned long height,
01426                                                       unsigned long limit);
01427 BN_EXPORT extern void bn_wlt_haar_2d_short_reconstruct2(short *tbuf,
01428                                                         short *buf,
01429                                                         unsigned long dimen,
01430                                                         unsigned long width,
01431                                                         unsigned long height,
01432                                                         unsigned long subimage_size,
01433                                                         unsigned long limit);
01434 
01435 BN_EXPORT extern void bn_wlt_haar_2d_int_decompose2(int *tbuf,
01436                                                     int *buf,
01437                                                     unsigned long dimen,
01438                                                     unsigned long width,
01439                                                     unsigned long height,
01440                                                     unsigned long limit);
01441 BN_EXPORT extern void bn_wlt_haar_2d_int_reconstruct2(int *tbuf,
01442                                                       int *buf,
01443                                                       unsigned long dimen,
01444                                                       unsigned long width,
01445                                                       unsigned long height,
01446                                                       unsigned long subimage_size,
01447                                                       unsigned long limit);
01448 
01449 BN_EXPORT extern void bn_wlt_haar_2d_long_decompose2(long *tbuf,
01450                                                      long *buf,
01451                                                      unsigned long dimen,
01452                                                      unsigned long width,
01453                                                      unsigned long height,
01454                                                      unsigned long limit);
01455 BN_EXPORT extern void bn_wlt_haar_2d_long_reconstruct2(long *tbuf,
01456                                                        long *buf,
01457                                                        unsigned long dimen,
01458                                                        unsigned long width,
01459                                                        unsigned long height,
01460                                                        unsigned long subimage_size,
01461                                                        unsigned long limit);
01462 
01463 
01464 /*----------------------------------------------------------------------*/
01465 /* const.c */
01466 BN_EXPORT extern const double bn_pi;
01467 BN_EXPORT extern const double bn_twopi;
01468 BN_EXPORT extern const double bn_halfpi;
01469 BN_EXPORT extern const double bn_invpi;
01470 BN_EXPORT extern const double bn_inv2pi;
01471 BN_EXPORT extern const double bn_inv255;
01472 BN_EXPORT extern const double bn_degtorad;
01473 BN_EXPORT extern const double bn_radtodeg;
01474 
01475 /*----------------------------------------------------------------------*/
01476 /* tabdata.c */
01477 
01478 /**
01479  * T A B D A T A
01480  *
01481  * Data structures to assist with recording many sets of data sampled
01482  * along the same set of independent variables.
01483  *
01484  * The overall notion is that each sample should be as compact as
01485  * possible (an array of measurements), with all the context stored in
01486  * one place.
01487  *
01488  * These structures and support routines apply to any measured "curve"
01489  * or "function" or "table" with one independent variable and one or
01490  * more scalar dependent variable(s).
01491  *
01492  * The context is kept in an 'bn_table' structure, and the data for
01493  * one particular sample are kept in an 'bn_tabdata' structure.
01494  *
01495  * The contents of the sample in val[j] are interpreted in the
01496  * interval (wavel[j]..wavel[j+1]).  This value could be power,
01497  * albedo, absorption, refractive index, or any other
01498  * wavelength-specific parameter.
01499  *
01500  * For example, if the val[] array contains power values, then val[j]
01501  * contains the integral of the power from wavel[j] to wavel[j+1]
01502  *
01503  * As an exmple, assume nwave=2, wavel[0]=500, wavel[1]=600, wavel[2]=700.
01504  * Then val[0] would contain data for the 500 to 600nm interval,
01505  * and val[1] would contain data for the 600 to 700nm interval.
01506  * There would be no storage allocated for val[2] -- don't use it!
01507  * There are several interpretations of this:
01508  *      1)  val[j] stores the total (integral, area) value for the interval, or
01509  *      2)  val[j] stores the average value across the interval.
01510  *
01511  * The intervals need not be uniformly spaced; it is acceptable to
01512  * increase wavelength sampling density around "important"
01513  * frequencies.
01514  *
01515  */
01516 struct bn_table {
01517     uint32_t magic;
01518     size_t nx;
01519     fastf_t x[1];       /**< @brief array of nx+1 wavelengths, dynamically sized */
01520 };
01521 #define BN_CK_TABLE(_p) BU_CKMAG(_p, BN_TABLE_MAGIC, "bn_table")
01522 #define BN_TABLE_NULL   ((struct bn_table *)NULL)
01523 
01524 /** Gets an bn_table, with x[] having size _nx+1 */
01525 #ifndef NO_BOMBING_MACROS
01526 #  define BN_GET_TABLE(_table, _nx) { \
01527         if ((_nx) < 1)  bu_bomb("RT_GET_TABLE() _nx < 1\n"); \
01528         _table = (struct bn_table *)bu_calloc(1, \
01529                                               sizeof(struct bn_table) + sizeof(fastf_t)*(_nx), \
01530                                               "struct bn_table"); \
01531         _table->magic = BN_TABLE_MAGIC; \
01532         _table->nx = (_nx);  }
01533 #else
01534 #  define BN_GET_TABLE(_table, _nx) { \
01535         _table = (struct bn_table *)bu_calloc(1, \
01536                                               sizeof(struct bn_table) + sizeof(fastf_t)*(_nx), \
01537                                               "struct bn_table"); \
01538         _table->magic = BN_TABLE_MAGIC; \
01539         _table->nx = (_nx);  }
01540 #endif
01541 
01542 struct bn_tabdata {
01543     uint32_t magic;
01544     size_t ny;
01545     const struct bn_table *table;       /**< @brief Up pointer to definition of X axis */
01546     fastf_t y[1];                       /**< @brief array of ny samples, dynamically sized */
01547 };
01548 #define BN_CK_TABDATA(_p)       BU_CKMAG(_p, BN_TABDATA_MAGIC, "bn_tabdata")
01549 #define BN_TABDATA_NULL         ((struct bn_tabdata *)NULL)
01550 
01551 #define BN_SIZEOF_TABDATA_Y(_tabdata)   sizeof(fastf_t)*((_tabdata)->ny)
01552 #define BN_SIZEOF_TABDATA(_table)       (sizeof(struct bn_tabdata) + \
01553                                          sizeof(fastf_t)*((_table)->nx-1))
01554 
01555 /** Gets an bn_tabdata, with y[] having size _ny */
01556 #define BN_GET_TABDATA(_data, _table) { \
01557         BN_CK_TABLE(_table);\
01558         _data = (struct bn_tabdata *)bu_calloc(1, \
01559                                                BN_SIZEOF_TABDATA(_table), "struct bn_tabdata"); \
01560         _data->magic = BN_TABDATA_MAGIC; \
01561         _data->ny = (_table)->nx; \
01562         _data->table = (_table); }
01563 
01564 /*
01565  * Routines
01566  */
01567 
01568 BN_EXPORT extern void bn_table_free(struct bn_table *tabp);
01569 BN_EXPORT extern void bn_tabdata_free(struct bn_tabdata *data);
01570 BN_EXPORT extern void bn_ck_table(const struct bn_table *tabp);
01571 BN_EXPORT extern struct bn_table *bn_table_make_uniform(size_t num,
01572                                                         double first,
01573                                                         double last);
01574 BN_EXPORT extern void bn_tabdata_add(struct bn_tabdata *out,
01575                                      const struct bn_tabdata *in1,
01576                                      const struct bn_tabdata *in2);
01577 BN_EXPORT extern void bn_tabdata_mul(struct bn_tabdata *out,
01578                                      const struct bn_tabdata *in1,
01579                                      const struct bn_tabdata *in2);
01580 BN_EXPORT extern void bn_tabdata_mul3(struct bn_tabdata *out,
01581                                       const struct bn_tabdata *in1,
01582                                       const struct bn_tabdata *in2,
01583                                       const struct bn_tabdata *in3);
01584 BN_EXPORT extern void bn_tabdata_incr_mul3_scale(struct bn_tabdata *out,
01585                                                  const struct bn_tabdata *in1,
01586                                                  const struct bn_tabdata *in2,
01587                                                  const struct bn_tabdata *in3,
01588                                                  double scale);
01589 BN_EXPORT extern void bn_tabdata_incr_mul2_scale(struct bn_tabdata *out,
01590                                                  const struct bn_tabdata *in1,
01591                                                  const struct bn_tabdata *in2,
01592                                                  double scale);
01593 BN_EXPORT extern void bn_tabdata_scale(struct bn_tabdata *out,
01594                                        const struct bn_tabdata *in1,
01595                                        double scale);
01596 BN_EXPORT extern void bn_table_scale(struct bn_table *tabp,
01597                                      double scale);
01598 BN_EXPORT extern void bn_tabdata_join1(struct bn_tabdata *out,
01599                                        const struct bn_tabdata *in1,
01600                                        double scale,
01601                                        const struct bn_tabdata *in2);
01602 BN_EXPORT extern void bn_tabdata_join2(struct bn_tabdata *out,
01603                                        const struct bn_tabdata *in1,
01604                                        double scale2,
01605                                        const struct bn_tabdata *in2,
01606                                        double scale3,
01607                                        const struct bn_tabdata *in3);
01608 BN_EXPORT extern void bn_tabdata_blend2(struct bn_tabdata *out,
01609                                         double scale1,
01610                                         const struct bn_tabdata *in1,
01611                                         double scale2,
01612                                         const struct bn_tabdata *in2);
01613 BN_EXPORT extern void bn_tabdata_blend3(struct bn_tabdata *out,
01614                                         double scale1,
01615                                         const struct bn_tabdata *in1,
01616                                         double scale2,
01617                                         const struct bn_tabdata *in2,
01618                                         double scale3,
01619                                         const struct bn_tabdata *in3);
01620 BN_EXPORT extern double bn_tabdata_area1(const struct bn_tabdata *in);
01621 BN_EXPORT extern double bn_tabdata_area2(const struct bn_tabdata *in);
01622 BN_EXPORT extern double bn_tabdata_mul_area1(const struct bn_tabdata *in1,
01623                                              const struct bn_tabdata *in2);
01624 BN_EXPORT extern double bn_tabdata_mul_area2(const struct bn_tabdata *in1,
01625                                              const struct bn_tabdata *in2);
01626 BN_EXPORT extern fastf_t bn_table_lin_interp(const struct bn_tabdata *samp,
01627                                              double wl);
01628 BN_EXPORT extern struct bn_tabdata *bn_tabdata_resample_max(const struct bn_table *newtable,
01629                                                             const struct bn_tabdata *olddata);
01630 BN_EXPORT extern struct bn_tabdata *bn_tabdata_resample_avg(const struct bn_table *newtable,
01631                                                             const struct bn_tabdata *olddata);
01632 BN_EXPORT extern int bn_table_write(const char *filename,
01633                                     const struct bn_table *tabp);
01634 BN_EXPORT extern struct bn_table *bn_table_read(const char *filename);
01635 BN_EXPORT extern void bn_pr_table(const char *title,
01636                                   const struct bn_table *tabp);
01637 BN_EXPORT extern void bn_pr_tabdata(const char *title,
01638                                     const struct bn_tabdata *data);
01639 BN_EXPORT extern int bn_print_table_and_tabdata(const char *filename,
01640                                                 const struct bn_tabdata *data);
01641 BN_EXPORT extern struct bn_tabdata *bn_read_table_and_tabdata(const char *filename);
01642 BN_EXPORT extern struct bn_tabdata *bn_tabdata_binary_read(const char *filename,
01643                                                            size_t num,
01644                                                            const struct bn_table *tabp);
01645 BN_EXPORT extern struct bn_tabdata *bn_tabdata_malloc_array(const struct bn_table *tabp,
01646                                                             size_t num);
01647 BN_EXPORT extern void bn_tabdata_copy(struct bn_tabdata *out,
01648                                       const struct bn_tabdata *in);
01649 BN_EXPORT extern struct bn_tabdata *bn_tabdata_dup(const struct bn_tabdata *in);
01650 BN_EXPORT extern struct bn_tabdata *bn_tabdata_get_constval(double val,
01651                                                             const struct bn_table *tabp);
01652 BN_EXPORT extern void bn_tabdata_constval(struct bn_tabdata *data,
01653                                           double val);
01654 BN_EXPORT extern void bn_tabdata_to_tcl(struct bu_vls *vp,
01655                                         const struct bn_tabdata *data);
01656 BN_EXPORT extern struct bn_tabdata *bn_tabdata_from_array(const double *array);
01657 BN_EXPORT extern void bn_tabdata_freq_shift(struct bn_tabdata *out,
01658                                             const struct bn_tabdata *in,
01659                                             double offset);
01660 BN_EXPORT extern int bn_table_interval_num_samples(const struct bn_table *tabp,
01661                                                    double low,
01662                                                    double hi);
01663 BN_EXPORT extern int bn_table_delete_sample_pts(struct bn_table *tabp,
01664                                                 unsigned int i,
01665                                                 unsigned int j);
01666 BN_EXPORT extern struct bn_table *bn_table_merge2(const struct bn_table *a,
01667                                                   const struct bn_table *b);
01668 BN_EXPORT extern struct bn_tabdata *bn_tabdata_mk_linear_filter(const struct bn_table *spectrum,
01669                                                                 double lower_wavelen,
01670                                                                 double upper_wavelen);
01671 
01672 /*----------------------------------------------------------------------*/
01673 /* vlist.c */
01674 #define BN_VLIST_CHUNK 35               /**< @brief 32-bit mach => just less than 1k */
01675 /**
01676  * B N _ V L I S T
01677  *
01678  * Definitions for handling lists of vectors (really verticies, or
01679  * points) and polygons in 3-space.  Intented for common handling of
01680  * wireframe display information, in the full resolution that is
01681  * calculated in.
01682  *
01683  * On 32-bit machines, BN_VLIST_CHUNK of 35 results in bn_vlist
01684  * structures just less than 1k bytes.
01685  *
01686  * The head of the doubly linked list can be just a "struct bu_list"
01687  * head.
01688  *
01689  * To visit all the elements in the vlist:
01690  *      for (BU_LIST_FOR(vp, bn_vlist, hp)) {
01691  *              register int    i;
01692  *              register int    nused = vp->nused;
01693  *              register int    *cmd = vp->cmd;
01694  *              register point_t *pt = vp->pt;
01695  *              for (i = 0; i < nused; i++, cmd++, pt++) {
01696  *                      access(*cmd, *pt);
01697  *                      access(vp->cmd[i], vp->pt[i]);
01698  *              }
01699  *      }
01700  */
01701 struct bn_vlist  {
01702     struct bu_list l;           /**< @brief magic, forw, back */
01703     size_t nused;               /**< @brief elements 0..nused active */
01704     int cmd[BN_VLIST_CHUNK];    /**< @brief VL_CMD_* */
01705     point_t pt[BN_VLIST_CHUNK]; /**< @brief associated 3-point/vect */
01706 };
01707 #define BN_VLIST_NULL   ((struct bn_vlist *)0)
01708 #define BN_CK_VLIST(_p) BU_CKMAG((_p), BN_VLIST_MAGIC, "bn_vlist")
01709 
01710 /* should these be enum? -Erik */
01711 /* Values for cmd[] */
01712 #define BN_VLIST_LINE_MOVE      0
01713 #define BN_VLIST_LINE_DRAW      1
01714 #define BN_VLIST_POLY_START     2       /**< @brief pt[] has surface normal */
01715 #define BN_VLIST_POLY_MOVE      3       /**< @brief move to first poly vertex */
01716 #define BN_VLIST_POLY_DRAW      4       /**< @brief subsequent poly vertex */
01717 #define BN_VLIST_POLY_END       5       /**< @brief last vert (repeats 1st), draw poly */
01718 #define BN_VLIST_POLY_VERTNORM  6       /**< @brief per-vertex normal, for interpoloation */
01719 #define BN_VLIST_TRI_START      7       /**< @brief pt[] has surface normal */
01720 #define BN_VLIST_TRI_MOVE       8       /**< @brief move to first triangle vertex */
01721 #define BN_VLIST_TRI_DRAW       9       /**< @brief subsequent triangle vertex */
01722 #define BN_VLIST_TRI_END        10      /**< @brief last vert (repeats 1st), draw poly */
01723 #define BN_VLIST_TRI_VERTNORM   11      /**< @brief per-vertex normal, for interpoloation */
01724 #define BN_VLIST_POINT_DRAW     12      /**< @brief  Draw a single point */
01725 #define BN_VLIST_CMD_MAX        12      /**< @brief  Max command number */
01726 
01727 /**
01728  * Applications that are going to use BN_ADD_VLIST and BN_GET_VLIST
01729  * are required to execute this macro once, on their _free_hd:
01730  * BU_LIST_INIT(&_free_hd);
01731  *
01732  * Note that BN_GET_VLIST and BN_FREE_VLIST are non-PARALLEL.
01733  */
01734 #define BN_GET_VLIST(_free_hd, p) {\
01735         (p) = BU_LIST_FIRST(bn_vlist, (_free_hd)); \
01736         if (BU_LIST_IS_HEAD((p), (_free_hd))) { \
01737             (p) = (struct bn_vlist *)bu_malloc(sizeof(struct bn_vlist), "bn_vlist"); \
01738             (p)->l.magic = BN_VLIST_MAGIC; \
01739         } else { \
01740             BU_LIST_DEQUEUE(&((p)->l)); \
01741         } \
01742         (p)->nused = 0; \
01743     }
01744 
01745 /** Place an entire chain of bn_vlist structs on the freelist _free_hd */
01746 #define BN_FREE_VLIST(_free_hd, hd) { \
01747         BU_CK_LIST_HEAD((hd)); \
01748         BU_LIST_APPEND_LIST((_free_hd), (hd)); \
01749     }
01750 
01751 #define BN_ADD_VLIST(_free_hd, _dest_hd, pnt, draw) { \
01752         register struct bn_vlist *_vp; \
01753         BU_CK_LIST_HEAD(_dest_hd); \
01754         _vp = BU_LIST_LAST(bn_vlist, (_dest_hd)); \
01755         if (BU_LIST_IS_HEAD(_vp, (_dest_hd)) || _vp->nused >= BN_VLIST_CHUNK) { \
01756             BN_GET_VLIST(_free_hd, _vp); \
01757             BU_LIST_INSERT((_dest_hd), &(_vp->l)); \
01758         } \
01759         VMOVE(_vp->pt[_vp->nused], (pnt)); \
01760         _vp->cmd[_vp->nused++] = (draw); \
01761     }
01762 
01763 /**
01764  * B N _ V L B L O C K
01765  *
01766  * For plotting, a way of separating plots into separate color vlists:
01767  * blocks of vlists, each with an associated color.
01768  */
01769 struct bn_vlblock {
01770     uint32_t magic;
01771     size_t nused;
01772     size_t max;
01773     long *rgb;          /**< @brief rgb[max] variable size array */
01774     struct bu_list *head;               /**< @brief head[max] variable size array */
01775     struct bu_list *free_vlist_hd;      /**< @brief where to get/put free vlists */
01776 };
01777 #define BN_CK_VLBLOCK(_p)       BU_CKMAG((_p), BN_VLBLOCK_MAGIC, "bn_vlblock")
01778 
01779 BN_EXPORT extern void bn_vlist_3string(struct bu_list *vhead,
01780                                        struct bu_list *free_hd,
01781                                        const char *string,
01782                                        const point_t origin,
01783                                        const mat_t rot,
01784                                        double scale);
01785 BN_EXPORT extern void bn_vlist_2string(struct bu_list *vhead,
01786                                        struct bu_list *free_hd,
01787                                        const char *string,
01788                                        double x,
01789                                        double y,
01790                                        double scale,
01791                                        double theta);
01792 
01793 
01794 /*----------------------------------------------------------------------*/
01795 /* vert_tree.c */
01796 /*
01797  * vertex tree support
01798  */
01799 /**
01800  * packaging structure
01801  * holds all the required info for a single vertex tree
01802  */
01803 struct vert_root {
01804     uint32_t magic;
01805     int tree_type;              /**< @brief vertices or vertices with normals */
01806     union vert_tree *the_tree;  /**< @brief the actual vertex tree */
01807     fastf_t *the_array;         /**< @brief the array of vertices */
01808     size_t curr_vert;           /**< @brief the number of vertices currently in the array */
01809     size_t max_vert;            /**< @brief the current maximum capacity of the array */
01810 };
01811 
01812 #define TREE_TYPE_VERTS 1
01813 #define TREE_TYPE_VERTS_AND_NORMS 2
01814 
01815 #define VERT_BLOCK 512                  /**< @brief number of vertices to malloc per call when building the array */
01816 
01817 #define BN_CK_VERT_TREE(_p) BU_CKMAG(_p, VERT_TREE_MAGIC, "vert_tree")
01818 
01819 BN_EXPORT extern struct vert_root *create_vert_tree();
01820 BN_EXPORT extern struct vert_root *create_vert_tree_w_norms();
01821 BN_EXPORT extern void free_vert_tree(struct vert_root *tree_root);
01822 BN_EXPORT extern int Add_vert(double x,
01823                               double y,
01824                               double z,
01825                               struct vert_root *tree_root,
01826                               fastf_t local_tol_sq);
01827 BN_EXPORT extern int Add_vert_and_norm(double x,
01828                                        double y,
01829                                        double z,
01830                                        double nx,
01831                                        double ny,
01832                                        double nz,
01833                                        struct vert_root *tree_root,
01834                                        fastf_t local_tol_sq);
01835 BN_EXPORT extern void clean_vert_tree(struct vert_root *tree_root);
01836 
01837 /*----------------------------------------------------------------------*/
01838 /* vectfont.c */
01839 BN_EXPORT extern void tp_setup();
01840 
01841 /**
01842  * report version information about LIBBN
01843  */
01844 BN_EXPORT extern const char *bn_version(void);
01845 
01846 __END_DECLS
01847 
01848 /*----------------------------------------------------------------------*/
01849 /*
01850  * plane structures (from src/librt/plane.h)
01851  */
01852 /**
01853  * Plane structures
01854  * holds all the required info for geometric planes.
01855  */
01856 
01857 /* from src/librt/plane.h. */
01858 
01859 #define MAXPTS 4                        /**< @brief All we need are 4 points */
01860 #define pl_A pl_points[0]               /**< @brief Synonym for A point */
01861 
01862 struct plane_specific  {
01863     size_t pl_npts;                     /**< @brief number of points on plane */
01864     point_t pl_points[MAXPTS];          /**< @brief Actual points on plane */
01865     vect_t pl_Xbasis;                   /**< @brief X (B-A) vector (for 2d coords) */
01866     vect_t pl_Ybasis;                   /**< @brief Y (C-A) vector (for 2d coords) */
01867     vect_t pl_N;                        /**< @brief Unit-length Normal (outward) */
01868     fastf_t pl_NdotA;                   /**< @brief Normal dot A */
01869     fastf_t pl_2d_x[MAXPTS];            /**< @brief X 2d-projection of points */
01870     fastf_t pl_2d_y[MAXPTS];            /**< @brief Y 2d-projection of points */
01871     fastf_t pl_2d_com[MAXPTS];          /**< @brief pre-computed common-term */
01872     struct plane_specific *pl_forw;     /**< @brief Forward link */
01873     char pl_code[MAXPTS+1];             /**< @brief Face code string.  Decorative. */
01874 };
01875 
01876 /*
01877  * Describe the tri_specific structure.
01878  */
01879 struct tri_specific  {
01880     point_t tri_A;                      /**< @brief triangle vertex (A) */
01881     vect_t tri_BA;                      /**< @brief B - A (second point) */
01882     vect_t tri_CA;                      /**< @brief C - A (third point) */
01883     vect_t tri_wn;                      /**< @brief facet normal (non-unit) */
01884     vect_t tri_N;                       /**< @brief unit normal vector */
01885     fastf_t *tri_normals;               /**< @brief unit vertex normals A, B, C  (this is malloced storage) */
01886     int tri_surfno;                     /**< @brief solid specific surface number */
01887     struct tri_specific *tri_forw;      /**< @brief Next facet */
01888 };
01889 
01890 typedef struct tri_specific tri_specific_double;
01891 
01892 /*
01893  * A more memory conservative version
01894  */
01895 struct tri_float_specific  {
01896     float tri_A[3];                     /**< @brief triangle vertex (A) */
01897     float tri_BA[3];                    /**< @brief B - A (second point) */
01898     float tri_CA[3];                    /**< @brief C - A (third point) */
01899     float tri_wn[3];                    /**< @brief facet normal (non-unit) */
01900     float tri_N[3];                     /**< @brief unit normal vector */
01901     signed char *tri_normals;           /**< @brief unit vertex normals A, B, C  (this is malloced storage) */
01902     int tri_surfno;                     /**< @brief solid specific surface number */
01903     struct tri_float_specific *tri_forw;/**< @brief Next facet */
01904 };
01905 
01906 typedef struct tri_float_specific tri_specific_float;
01907 
01908 #endif /* __BN_H__ */
01909 
01910 /** @} */
01911 /*
01912  * Local Variables:
01913  * mode: C
01914  * tab-width: 8
01915  * indent-tabs-mode: t
01916  * c-file-style: "stroustrup"
01917  * End:
01918  * ex: shiftwidth=4 tabstop=8
01919  */
Generated on Tue Dec 11 13:14:27 2012 for LIBBN by  doxygen 1.6.3