00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef __BN_H__
00034 #define __BN_H__
00035
00036 #include "common.h"
00037
00038 __BEGIN_DECLS
00039
00040
00041 #include "bu.h"
00042 #include "vmath.h"
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
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 struct bn_tol {
00105 uint32_t magic;
00106 double dist;
00107 double dist_sq;
00108 double perp;
00109 double para;
00110 };
00111
00112
00113
00114
00115 #define BN_CK_TOL(_p) BU_CKMAG(_p, BN_TOL_MAGIC, "bn_tol")
00116
00117
00118
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
00130
00131
00132 #define BN_TOL_INIT_ZERO { BN_TOL_MAGIC, 0.0, 0.0, 0.0, 1.0 }
00133
00134
00135
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
00141
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
00148
00149
00150 #define BN_VECT_ARE_PERP(_dot, _tol) \
00151 (((_dot) < 0) ? ((-(_dot))<=(_tol)->perp) : ((_dot) <= (_tol)->perp))
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185 BN_EXPORT extern void anim_v_permute(mat_t m);
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195 BN_EXPORT extern void anim_v_unpermute(mat_t m);
00196
00197
00198
00199
00200 BN_EXPORT extern void anim_tran(mat_t m);
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210 BN_EXPORT extern int anim_mat2zyx(const mat_t viewrot,
00211 vect_t angle);
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222 BN_EXPORT extern int anim_mat2ypr(mat_t viewrot,
00223 vect_t angle);
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233 BN_EXPORT extern int anim_mat2quat(quat_t quat,
00234 const mat_t viewrot);
00235
00236
00237
00238
00239
00240
00241 BN_EXPORT extern void anim_ypr2mat(mat_t m,
00242 const vect_t a);
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256 BN_EXPORT extern void anim_ypr2vmat(mat_t m,
00257 const vect_t a);
00258
00259
00260
00261
00262
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
00271
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
00280
00281
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
00290
00291
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
00300
00301
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
00310
00311
00312
00313 BN_EXPORT extern void anim_zyx2mat(mat_t m,
00314 const vect_t a);
00315
00316
00317
00318
00319
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
00328
00329
00330
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
00339
00340
00341
00342
00343 BN_EXPORT extern void anim_quat2mat(mat_t m,
00344 const quat_t qq);
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354 BN_EXPORT extern void anim_dir2mat(mat_t m,
00355 const vect_t d,
00356 const vect_t d2);
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366 BN_EXPORT extern void anim_dirn2mat(mat_t m,
00367 const vect_t dx,
00368 const vect_t dn);
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378 BN_EXPORT extern int anim_steer_mat(mat_t mat,
00379 vect_t point,
00380 int end);
00381
00382
00383
00384
00385
00386
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
00394
00395 BN_EXPORT extern void anim_rotatez(fastf_t a,
00396 vect_t d);
00397
00398
00399
00400
00401 BN_EXPORT extern void anim_mat_print(FILE *fp,
00402 const mat_t m,
00403 int s_colon);
00404
00405
00406
00407
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
00417
00418
00419 BN_EXPORT extern void anim_view_rev(mat_t m);
00420
00421
00422
00423
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
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
00449
00450
00451
00452
00453
00454
00455
00456 typedef struct bn_complex {
00457 double re;
00458 double im;
00459 } bn_complex_t;
00460
00461
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
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
00489
00490
00491
00492
00493
00494
00495 BN_EXPORT extern void bn_cx_div(bn_complex_t *ap,
00496 const bn_complex_t *bp);
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508 BN_EXPORT extern void bn_cx_sqrt(bn_complex_t *op,
00509 const bn_complex_t *ip);
00510
00511
00512
00513
00514
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
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
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
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
00687
00688
00689
00690
00691
00692
00693
00694
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
00712
00713
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
00766
00767
00768
00769
00770
00771
00772 BN_EXPORT extern void bn_noise_init();
00773 BN_EXPORT extern double bn_noise_perlin(point_t pt);
00774
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
00798
00799
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
01004
01005
01006
01007
01008 #define BN_MAX_POLY_DEGREE 4
01009
01010
01011
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
01067
01068
01069
01070
01071
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
01083
01084
01085
01086
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
01122
01123
01124
01125
01126
01127
01128
01129
01130
01131
01132
01133
01134
01135
01136
01137
01138
01139
01140
01141
01142
01143
01144
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
01152 #define BN_RANDOM(_i) bn_rand_table[ _i = (_i+1) % BN_RAND_TABSIZE ]
01153
01154
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
01159 BN_EXPORT extern int bn_randhalftabsize;
01160 BN_EXPORT extern float bn_rand_halftab[BN_RANDHALFTABSIZE];
01161
01162
01163
01164
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
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
01182
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
01198
01199
01200
01201
01202
01203
01204
01205
01206
01207
01208
01209
01210
01211
01212
01213
01214
01215
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
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
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
01477
01478
01479
01480
01481
01482
01483
01484
01485
01486
01487
01488
01489
01490
01491
01492
01493
01494
01495
01496
01497
01498
01499
01500
01501
01502
01503
01504
01505
01506
01507
01508
01509
01510
01511
01512
01513
01514
01515
01516 struct bn_table {
01517 uint32_t magic;
01518 size_t nx;
01519 fastf_t x[1];
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
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;
01546 fastf_t y[1];
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
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
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
01674 #define BN_VLIST_CHUNK 35
01675
01676
01677
01678
01679
01680
01681
01682
01683
01684
01685
01686
01687
01688
01689
01690
01691
01692
01693
01694
01695
01696
01697
01698
01699
01700
01701 struct bn_vlist {
01702 struct bu_list l;
01703 size_t nused;
01704 int cmd[BN_VLIST_CHUNK];
01705 point_t pt[BN_VLIST_CHUNK];
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
01711
01712 #define BN_VLIST_LINE_MOVE 0
01713 #define BN_VLIST_LINE_DRAW 1
01714 #define BN_VLIST_POLY_START 2
01715 #define BN_VLIST_POLY_MOVE 3
01716 #define BN_VLIST_POLY_DRAW 4
01717 #define BN_VLIST_POLY_END 5
01718 #define BN_VLIST_POLY_VERTNORM 6
01719 #define BN_VLIST_TRI_START 7
01720 #define BN_VLIST_TRI_MOVE 8
01721 #define BN_VLIST_TRI_DRAW 9
01722 #define BN_VLIST_TRI_END 10
01723 #define BN_VLIST_TRI_VERTNORM 11
01724 #define BN_VLIST_POINT_DRAW 12
01725 #define BN_VLIST_CMD_MAX 12
01726
01727
01728
01729
01730
01731
01732
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
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
01765
01766
01767
01768
01769 struct bn_vlblock {
01770 uint32_t magic;
01771 size_t nused;
01772 size_t max;
01773 long *rgb;
01774 struct bu_list *head;
01775 struct bu_list *free_vlist_hd;
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
01796
01797
01798
01799
01800
01801
01802
01803 struct vert_root {
01804 uint32_t magic;
01805 int tree_type;
01806 union vert_tree *the_tree;
01807 fastf_t *the_array;
01808 size_t curr_vert;
01809 size_t max_vert;
01810 };
01811
01812 #define TREE_TYPE_VERTS 1
01813 #define TREE_TYPE_VERTS_AND_NORMS 2
01814
01815 #define VERT_BLOCK 512
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
01839 BN_EXPORT extern void tp_setup();
01840
01841
01842
01843
01844 BN_EXPORT extern const char *bn_version(void);
01845
01846 __END_DECLS
01847
01848
01849
01850
01851
01852
01853
01854
01855
01856
01857
01858
01859 #define MAXPTS 4
01860 #define pl_A pl_points[0]
01861
01862 struct plane_specific {
01863 size_t pl_npts;
01864 point_t pl_points[MAXPTS];
01865 vect_t pl_Xbasis;
01866 vect_t pl_Ybasis;
01867 vect_t pl_N;
01868 fastf_t pl_NdotA;
01869 fastf_t pl_2d_x[MAXPTS];
01870 fastf_t pl_2d_y[MAXPTS];
01871 fastf_t pl_2d_com[MAXPTS];
01872 struct plane_specific *pl_forw;
01873 char pl_code[MAXPTS+1];
01874 };
01875
01876
01877
01878
01879 struct tri_specific {
01880 point_t tri_A;
01881 vect_t tri_BA;
01882 vect_t tri_CA;
01883 vect_t tri_wn;
01884 vect_t tri_N;
01885 fastf_t *tri_normals;
01886 int tri_surfno;
01887 struct tri_specific *tri_forw;
01888 };
01889
01890 typedef struct tri_specific tri_specific_double;
01891
01892
01893
01894
01895 struct tri_float_specific {
01896 float tri_A[3];
01897 float tri_BA[3];
01898 float tri_CA[3];
01899 float tri_wn[3];
01900 float tri_N[3];
01901 signed char *tri_normals;
01902 int tri_surfno;
01903 struct tri_float_specific *tri_forw;
01904 };
01905
01906 typedef struct tri_float_specific tri_specific_float;
01907
01908 #endif
01909
01910
01911
01912
01913
01914
01915
01916
01917
01918
01919