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
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 #ifndef lint
00047 static const char RCSsuperell[] = "@(#)$Header: /cvsroot/brlcad/brlcad/src/librt/g_superell.c,v 14.16 2006/09/16 02:04:25 lbutler Exp $ (BRL)";
00048 #endif
00049
00050 #include "common.h"
00051
00052 #include <stddef.h>
00053 #include <stdio.h>
00054 #ifdef HAVE_STRING_H
00055 # include <string.h>
00056 #else
00057 # include <strings.h>
00058 #endif
00059 #include <math.h>
00060
00061 #include "machine.h"
00062 #include "vmath.h"
00063 #include "db.h"
00064 #include "nmg.h"
00065 #include "raytrace.h"
00066 #include "nurb.h"
00067 #include "rtgeom.h"
00068 #include "./debug.h"
00069
00070 const struct bu_structparse rt_superell_parse[] = {
00071 { "%f", 3, "V", bu_offsetof(struct rt_superell_internal, v[X]), BU_STRUCTPARSE_FUNC_NULL },
00072 { "%f", 3, "A", bu_offsetof(struct rt_superell_internal, a[X]), BU_STRUCTPARSE_FUNC_NULL },
00073 { "%f", 3, "B", bu_offsetof(struct rt_superell_internal, b[X]), BU_STRUCTPARSE_FUNC_NULL },
00074 { "%f", 3, "C", bu_offsetof(struct rt_superell_internal, c[X]), BU_STRUCTPARSE_FUNC_NULL },
00075 { "%f", 1, "n", bu_offsetof(struct rt_superell_internal, n), BU_STRUCTPARSE_FUNC_NULL },
00076 { "%f", 1, "e", bu_offsetof(struct rt_superell_internal, e), BU_STRUCTPARSE_FUNC_NULL },
00077 { {'\0','\0','\0','\0'}, 0, (char *)NULL, 0, BU_STRUCTPARSE_FUNC_NULL }
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
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174 struct superell_specific {
00175 vect_t superell_V;
00176 vect_t superell_Au;
00177 vect_t superell_Bu;
00178 vect_t superell_Cu;
00179 double superell_n;
00180 double superell_e;
00181 double superell_invmsAu;
00182 double superell_invmsBu;
00183 double superell_invmsCu;
00184 vect_t superell_invsq;
00185 mat_t superell_SoR;
00186 mat_t superell_invRSSR;
00187 mat_t superell_invR;
00188 };
00189 #define SUPERELL_NULL ((struct superell_specific *)0)
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206 int
00207 rt_superell_prep(struct soltab *stp, struct rt_db_internal *ip, struct rt_i *rtip)
00208 {
00209
00210 register struct superell_specific *superell;
00211 struct rt_superell_internal *eip;
00212 LOCAL fastf_t magsq_a, magsq_b, magsq_c;
00213 LOCAL mat_t R, TEMP;
00214 LOCAL vect_t Au, Bu, Cu;
00215 LOCAL vect_t w1, w2, P;
00216 LOCAL fastf_t f;
00217
00218 eip = (struct rt_superell_internal *)ip->idb_ptr;
00219 RT_SUPERELL_CK_MAGIC(eip);
00220
00221
00222 magsq_a = MAGSQ( eip->a );
00223 magsq_b = MAGSQ( eip->b );
00224 magsq_c = MAGSQ( eip->c );
00225
00226 if( magsq_a < rtip->rti_tol.dist || magsq_b < rtip->rti_tol.dist || magsq_c < rtip->rti_tol.dist ) {
00227 bu_log("superell(%s): near-zero length A(%g), B(%g), or C(%g) vector\n",
00228 stp->st_name, magsq_a, magsq_b, magsq_c );
00229 return(1);
00230 }
00231 if (eip->n < rtip->rti_tol.dist || eip->e < rtip->rti_tol.dist) {
00232 bu_log("superell(%s): near-zero length <n,e> curvature (%g, %g) causes problems\n",
00233 stp->st_name, eip->n, eip->e);
00234
00235 }
00236 if (eip->n > 10000.0 || eip->e > 10000.0) {
00237 bu_log("superell(%s): very large <n,e> curvature (%g, %g) causes problems\n",
00238 stp->st_name, eip->n, eip->e);
00239
00240 }
00241
00242
00243 f = 1.0/sqrt(magsq_a);
00244 VSCALE( Au, eip->a, f );
00245 f = 1.0/sqrt(magsq_b);
00246 VSCALE( Bu, eip->b, f );
00247 f = 1.0/sqrt(magsq_c);
00248 VSCALE( Cu, eip->c, f );
00249
00250
00251 f = VDOT( Au, Bu );
00252 if( ! NEAR_ZERO(f, rtip->rti_tol.dist) ) {
00253 bu_log("superell(%s): A not perpendicular to B, f=%f\n",stp->st_name, f);
00254 return(1);
00255 }
00256 f = VDOT( Bu, Cu );
00257 if( ! NEAR_ZERO(f, rtip->rti_tol.dist) ) {
00258 bu_log("superell(%s): B not perpendicular to C, f=%f\n",stp->st_name, f);
00259 return(1);
00260 }
00261 f = VDOT( Au, Cu );
00262 if( ! NEAR_ZERO(f, rtip->rti_tol.dist) ) {
00263 bu_log("superell(%s): A not perpendicular to C, f=%f\n",stp->st_name, f);
00264 return(1);
00265 }
00266
00267
00268
00269 BU_GETSTRUCT( superell, superell_specific );
00270 stp->st_specific = (genptr_t)superell;
00271
00272 superell->superell_n = eip->n;
00273 superell->superell_e = eip->e;
00274
00275 VMOVE( superell->superell_V, eip->v );
00276
00277 VSET( superell->superell_invsq, 1.0/magsq_a, 1.0/magsq_b, 1.0/magsq_c );
00278 VMOVE( superell->superell_Au, Au );
00279 VMOVE( superell->superell_Bu, Bu );
00280 VMOVE( superell->superell_Cu, Cu );
00281
00282
00283 superell->superell_invmsAu = 1.0 / magsq_a;
00284 superell->superell_invmsBu = 1.0 / magsq_b;
00285 superell->superell_invmsCu = 1.0 / magsq_c;
00286
00287
00288 MAT_IDN(R);
00289 VMOVE( &R[0], Au );
00290 VMOVE( &R[4], Bu );
00291 VMOVE( &R[8], Cu );
00292 bn_mat_trn( superell->superell_invR, R );
00293
00294
00295 MAT_IDN(superell->superell_invRSSR);
00296 MAT_IDN(TEMP);
00297 TEMP[0] = superell->superell_invsq[0];
00298 TEMP[5] = superell->superell_invsq[1];
00299 TEMP[10] = superell->superell_invsq[2];
00300 bn_mat_mul(TEMP, TEMP, R);
00301 bn_mat_mul(superell->superell_invRSSR, superell->superell_invR, TEMP);
00302
00303
00304 MAT_IDN(superell->superell_SoR);
00305 VSCALE( &superell->superell_SoR[0], eip->a, superell->superell_invsq[0]);
00306 VSCALE( &superell->superell_SoR[4], eip->b, superell->superell_invsq[1]);
00307 VSCALE( &superell->superell_SoR[8], eip->c, superell->superell_invsq[2]);
00308
00309
00310 VMOVE( stp->st_center, eip->v );
00311 f = magsq_a;
00312 if( magsq_b > f )
00313 f = magsq_b;
00314 if( magsq_c > f )
00315 f = magsq_c;
00316 stp->st_aradius = stp->st_bradius = sqrt(f);
00317
00318
00319 VSET( w1, magsq_a, magsq_b, magsq_c );
00320
00321
00322 VSET( P, 1.0, 0, 0 );
00323 MAT3X3VEC( w2, R, P );
00324 VELMUL( w2, w2, w2 );
00325 f = VDOT( w1, w2 );
00326 f = sqrt(f);
00327 stp->st_min[X] = superell->superell_V[X] - f;
00328 stp->st_max[X] = superell->superell_V[X] + f;
00329
00330
00331 VSET( P, 0, 1.0, 0 );
00332 MAT3X3VEC( w2, R, P );
00333 VELMUL( w2, w2, w2 );
00334 f = VDOT( w1, w2 );
00335 f = sqrt(f);
00336 stp->st_min[Y] = superell->superell_V[Y] - f;
00337 stp->st_max[Y] = superell->superell_V[Y] + f;
00338
00339
00340 VSET( P, 0, 0, 1.0 );
00341 MAT3X3VEC( w2, R, P );
00342 VELMUL( w2, w2, w2 );
00343 f = VDOT( w1, w2 );
00344 f = sqrt(f);
00345 stp->st_min[Z] = superell->superell_V[Z] - f;
00346 stp->st_max[Z] = superell->superell_V[Z] + f;
00347
00348 return(0);
00349 }
00350
00351
00352
00353
00354 void
00355 rt_superell_print(register const struct soltab *stp)
00356 {
00357 register struct superell_specific *superell =
00358 (struct superell_specific *)stp->st_specific;
00359
00360 VPRINT("V", superell->superell_V);
00361 }
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379 int
00380 rt_superell_shot(struct soltab *stp, register struct xray *rp, struct application *ap, struct seg *seghead)
00381 {
00382 static int counter=10;
00383
00384 register struct superell_specific *superell = (struct superell_specific *)stp->st_specific;
00385 LOCAL bn_poly_t equation;
00386 LOCAL vect_t translated;
00387 LOCAL vect_t newShotPoint;
00388 LOCAL vect_t newShotDir;
00389 LOCAL vect_t normalizedShotPoint;
00390 LOCAL bn_complex_t complexRoot[4];
00391 LOCAL double realRoot[4];
00392 register int i,j;
00393 register struct seg *segp;
00394
00395
00396
00397 (translated)[X] = (rp->r_pt)[X] - (superell->superell_V)[X];
00398 (translated)[Y] = (rp->r_pt)[Y] - (superell->superell_V)[Y];
00399 (translated)[Z] = (rp->r_pt)[Z] - (superell->superell_V)[Z];
00400
00401
00402
00403
00404 newShotPoint[X] = (superell->superell_SoR[0]*translated[X] + superell->superell_SoR[1]*translated[Y] + superell->superell_SoR[ 2]*translated[Z]) * 1.0/(superell->superell_SoR[15]);
00405 newShotPoint[Y] = (superell->superell_SoR[4]*translated[X] + superell->superell_SoR[5]*translated[Y] + superell->superell_SoR[ 6]*translated[Z]) * 1.0/(superell->superell_SoR[15]);
00406 newShotPoint[Z] = (superell->superell_SoR[8]*translated[X] + superell->superell_SoR[9]*translated[Y] + superell->superell_SoR[10]*translated[Z]) * 1.0/(superell->superell_SoR[15]);
00407
00408
00409 MAT4X3VEC(newShotDir, superell->superell_SoR, rp->r_dir);
00410 VUNITIZE(newShotDir);
00411
00412
00413
00414
00415
00416
00417
00418 VSCALE( normalizedShotPoint, newShotDir,
00419 VDOT( newShotPoint, newShotDir ));
00420 VSUB2( normalizedShotPoint, newShotPoint, normalizedShotPoint );
00421
00422
00423
00424 equation.dgr = 2;
00425
00426
00427 equation.cf[0] = newShotPoint[X] * newShotPoint[X] * superell->superell_invmsAu + newShotPoint[Y] * newShotPoint[Y] * superell->superell_invmsBu + newShotPoint[Z] * newShotPoint[Z] * superell->superell_invmsCu - 1;
00428
00429 equation.cf[1] = 2 * newShotDir[X] * newShotPoint[X] * superell->superell_invmsAu + 2 * newShotDir[Y] * newShotPoint[Y] * superell->superell_invmsBu + 2 * newShotDir[Z] * newShotPoint[Z] * superell->superell_invmsCu;
00430
00431 equation.cf[2] = newShotDir[X] * newShotDir[X] * superell->superell_invmsAu + newShotDir[Y] * newShotDir[Y] * superell->superell_invmsBu + newShotDir[Z] * newShotDir[Z] * superell->superell_invmsCu;
00432
00433 if ( (i = rt_poly_roots( &equation, complexRoot, stp->st_dp->d_namep)) != 2 ) {
00434 if (i > 0) {
00435 bu_log("superell: rt_poly_roots() 2 != %d\n", i);
00436 bn_pr_roots(stp->st_name, complexRoot, i);
00437 } else if (i < 0) {
00438 static int reported=0;
00439 bu_log("The root solver failed to converge on a solution for %s\n", stp->st_dp->d_namep);
00440 if (!reported) {
00441 VPRINT("while shooting from:\t", rp->r_pt);
00442 VPRINT("while shooting at:\t", rp->r_dir);
00443 bu_log("Additional superellipsoid convergence failure details will be suppressed.\n");
00444 reported=1;
00445 }
00446 }
00447 return (0);
00448 }
00449
00450
00451
00452
00453
00454
00455
00456
00457 for ( j=0, i=0; j < 2; j++ ){
00458 if( NEAR_ZERO( complexRoot[j].im, 0.001 ) )
00459 realRoot[i++] = complexRoot[j].re;
00460 }
00461
00462
00463
00464
00465
00466
00467
00468 switch( i ) {
00469 case 0:
00470 return(0);
00471
00472 default:
00473 bu_log("rt_superell_shot: reduced 4 to %d roots\n",i);
00474 bn_pr_roots( stp->st_name, complexRoot, 4 );
00475 return(0);
00476
00477 case 2:
00478 {
00479
00480 FAST fastf_t u;
00481 if( (u=realRoot[0]) < realRoot[1] ) {
00482
00483 realRoot[0] = realRoot[1];
00484 realRoot[1] = u;
00485 }
00486 }
00487 break;
00488 case 4:
00489 {
00490 register short n;
00491 register short lim;
00492
00493
00494 for( lim = i-1; lim > 0; lim-- ) {
00495 for( n = 0; n < lim; n++ ) {
00496 FAST fastf_t u;
00497 if( (u=realRoot[n]) < realRoot[n+1] ) {
00498
00499 realRoot[n] = realRoot[n+1];
00500 realRoot[n+1] = u;
00501 }
00502 }
00503 }
00504 }
00505 break;
00506 }
00507
00508 if (counter > 0) {
00509 bu_log("realroot: in %d out %d\n", realRoot[1], realRoot[0]);
00510 counter--;
00511 }
00512
00513
00514
00515
00516 RT_GET_SEG(segp, ap->a_resource);
00517 segp->seg_stp = stp;
00518 segp->seg_in.hit_dist = realRoot[1];
00519 segp->seg_out.hit_dist = realRoot[0];
00520
00521
00522
00523
00524 BU_LIST_INSERT( &(seghead->l), &(segp->l) );
00525
00526 if( i == 2 ) {
00527 return(2);
00528 }
00529
00530
00531
00532 RT_GET_SEG(segp, ap->a_resource);
00533 segp->seg_stp = stp;
00534 segp->seg_in.hit_dist = realRoot[3]*superell->superell_e;
00535 segp->seg_out.hit_dist = realRoot[2]*superell->superell_e;
00536 segp->seg_in.hit_surfno = segp->seg_out.hit_surfno = 1;
00537 VJOIN1( segp->seg_in.hit_vpriv, newShotPoint, realRoot[3], newShotDir );
00538 VJOIN1( segp->seg_out.hit_vpriv, newShotPoint, realRoot[2], newShotDir );
00539 BU_LIST_INSERT( &(seghead->l), &(segp->l) );
00540 return(4);
00541
00542
00543
00544
00545
00546 if ( (superell->superell_n > 2.0) || (superell->superell_e > 2.0) ) {
00547
00548 }
00549
00550 return 1;
00551 }
00552
00553
00554
00555
00556
00557
00558
00559 void
00560 rt_superell_vshot(struct soltab **stp, struct xray **rp, struct seg *segp, int n, struct application *ap)
00561
00562
00563
00564
00565
00566 {
00567 return;
00568 }
00569
00570
00571
00572
00573
00574
00575
00576 void
00577 rt_superell_norm(register struct hit *hitp, struct soltab *stp, register struct xray *rp)
00578 {
00579 register struct superell_specific *superell =
00580 (struct superell_specific *)stp->st_specific;
00581
00582 LOCAL vect_t xlated;
00583 LOCAL fastf_t scale;
00584
00585 VJOIN1( hitp->hit_point, rp->r_pt, hitp->hit_dist, rp->r_dir );
00586 VSUB2( xlated, hitp->hit_point, superell->superell_V );
00587 MAT4X3VEC( hitp->hit_normal, superell->superell_invRSSR, xlated );
00588 scale = 1.0 / MAGNITUDE( hitp->hit_normal );
00589 VSCALE( hitp->hit_normal, hitp->hit_normal, scale );
00590
00591 return;
00592 }
00593
00594
00595
00596
00597
00598
00599
00600 void
00601 rt_superell_curve(register struct curvature *cvp, register struct hit *hitp, struct soltab *stp)
00602 {
00603 bu_log("called rt_superell_curve!\n");
00604 return;
00605 }
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616 void
00617 rt_superell_uv(struct application *ap, struct soltab *stp, register struct hit *hitp, register struct uvcoord *uvp)
00618 {
00619 bu_log("called rt_superell_uv!\n");
00620 return;
00621 }
00622
00623
00624
00625
00626 void
00627 rt_superell_free(register struct soltab *stp)
00628 {
00629 register struct superell_specific *superell =
00630 (struct superell_specific *)stp->st_specific;
00631
00632 bu_free( (char *)superell, "superell_specific" );
00633 }
00634
00635
00636 int
00637 rt_superell_class(void)
00638 {
00639 return(0);
00640 }
00641
00642
00643
00644
00645
00646
00647
00648 #define SUPERELLOUT(n) ov+(n-1)*3
00649 void
00650 rt_superell_16pts(register fastf_t *ov,
00651 register fastf_t *V,
00652 fastf_t *A,
00653 fastf_t *B)
00654 {
00655 static fastf_t c, d, e, f,g,h;
00656
00657 e = h = .92388;
00658 c = d = .707107;
00659 g = f = .382683;
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669 VADD2( SUPERELLOUT(1), V, A );
00670 VJOIN2( SUPERELLOUT(2), V, e, A, f, B );
00671 VJOIN2( SUPERELLOUT(3), V, c, A, d, B );
00672 VJOIN2( SUPERELLOUT(4), V, g, A, h, B );
00673 VADD2( SUPERELLOUT(5), V, B );
00674 VJOIN2( SUPERELLOUT(6), V, -g, A, h, B );
00675 VJOIN2( SUPERELLOUT(7), V, -c, A, d, B );
00676 VJOIN2( SUPERELLOUT(8), V, -e, A, f, B );
00677 VSUB2( SUPERELLOUT(9), V, A );
00678 VJOIN2( SUPERELLOUT(10), V, -e, A, -f, B );
00679 VJOIN2( SUPERELLOUT(11), V, -c, A, -d, B );
00680 VJOIN2( SUPERELLOUT(12), V, -g, A, -h, B );
00681 VSUB2( SUPERELLOUT(13), V, B );
00682 VJOIN2( SUPERELLOUT(14), V, g, A, -h, B );
00683 VJOIN2( SUPERELLOUT(15), V, c, A, -d, B );
00684 VJOIN2( SUPERELLOUT(16), V, e, A, -f, B );
00685 }
00686
00687
00688
00689
00690 int
00691 rt_superell_plot(struct bu_list *vhead, struct rt_db_internal *ip, const struct rt_tess_tol *ttol, const struct bn_tol *tol)
00692 {
00693 register int i;
00694 struct rt_superell_internal *eip;
00695 fastf_t top[16*3];
00696 fastf_t middle[16*3];
00697 fastf_t bottom[16*3];
00698
00699 RT_CK_DB_INTERNAL(ip);
00700 eip = (struct rt_superell_internal *)ip->idb_ptr;
00701 RT_SUPERELL_CK_MAGIC(eip);
00702
00703 rt_superell_16pts( top, eip->v, eip->a, eip->b );
00704 rt_superell_16pts( bottom, eip->v, eip->b, eip->c );
00705 rt_superell_16pts( middle, eip->v, eip->a, eip->c );
00706
00707 RT_ADD_VLIST( vhead, &top[15*ELEMENTS_PER_VECT], BN_VLIST_LINE_MOVE );
00708 for( i=0; i<16; i++ ) {
00709 RT_ADD_VLIST( vhead, &top[i*ELEMENTS_PER_VECT], BN_VLIST_LINE_DRAW );
00710 }
00711
00712 RT_ADD_VLIST( vhead, &bottom[15*ELEMENTS_PER_VECT], BN_VLIST_LINE_MOVE );
00713 for( i=0; i<16; i++ ) {
00714 RT_ADD_VLIST( vhead, &bottom[i*ELEMENTS_PER_VECT], BN_VLIST_LINE_DRAW );
00715 }
00716
00717 RT_ADD_VLIST( vhead, &middle[15*ELEMENTS_PER_VECT], BN_VLIST_LINE_MOVE );
00718 for( i=0; i<16; i++ ) {
00719 RT_ADD_VLIST( vhead, &middle[i*ELEMENTS_PER_VECT], BN_VLIST_LINE_DRAW );
00720 }
00721 return(0);
00722 }
00723
00724 #if 0
00725 static point_t octa_verts[6] = {
00726 { 1, 0, 0 },
00727 {-1, 0, 0 },
00728 { 0, 1, 0 },
00729 { 0,-1, 0 },
00730 { 0, 0, 1 },
00731 { 0, 0,-1 }
00732 };
00733
00734 #define XPLUS 0
00735 #define XMIN 1
00736 #define YPLUS 2
00737 #define YMIN 3
00738 #define ZPLUS 4
00739 #define ZMIN 5
00740 #endif
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759 struct superell_state {
00760 struct shell *s;
00761 struct rt_superell_internal *eip;
00762 mat_t invRinvS;
00763 mat_t invRoS;
00764 fastf_t theta_tol;
00765 };
00766
00767 struct superell_vert_strip {
00768 int nverts_per_strip;
00769 int nverts;
00770 struct vertex **vp;
00771 vect_t *norms;
00772 int nfaces;
00773 struct faceuse **fu;
00774 };
00775
00776
00777
00778
00779
00780
00781
00782
00783
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809 int
00810 rt_superell_tess(struct nmgregion **r, struct model *m, struct rt_db_internal *ip, const struct rt_tess_tol *ttol, const struct bn_tol *tol)
00811 {
00812 bu_log("rt_superell_tess called!\n");
00813 return -1;
00814 }
00815
00816
00817
00818
00819
00820
00821
00822
00823 int
00824 rt_superell_import(struct rt_db_internal *ip, const struct bu_external *ep, register const fastf_t *mat, const struct db_i *dbip)
00825 {
00826 struct rt_superell_internal *eip;
00827 union record *rp;
00828 LOCAL fastf_t vec[3*4 + 2];
00829
00830 BU_CK_EXTERNAL( ep );
00831 rp = (union record *)ep->ext_buf;
00832
00833 if( rp->u_id != ID_SOLID ) {
00834 bu_log("rt_superell_import: defective record\n");
00835 return(-1);
00836 }
00837
00838 RT_CK_DB_INTERNAL( ip );
00839 ip->idb_major_type = DB5_MAJORTYPE_BRLCAD;
00840 ip->idb_type = ID_SUPERELL;
00841 ip->idb_meth = &rt_functab[ID_SUPERELL];
00842 ip->idb_ptr = bu_malloc( sizeof(struct rt_superell_internal), "rt_superell_internal");
00843 eip = (struct rt_superell_internal *)ip->idb_ptr;
00844 eip->magic = RT_SUPERELL_INTERNAL_MAGIC;
00845
00846
00847 rt_fastf_float( vec, rp->s.s_values, 4 );
00848
00849
00850 MAT4X3PNT( eip->v, mat, &vec[0*3] );
00851 MAT4X3VEC( eip->a, mat, &vec[1*3] );
00852 MAT4X3VEC( eip->b, mat, &vec[2*3] );
00853 MAT4X3VEC( eip->c, mat, &vec[3*3] );
00854 eip->n = rp->s.s_values[12];
00855 eip->e = rp->s.s_values[13];
00856
00857 return(0);
00858 }
00859
00860
00861
00862
00863 int
00864 rt_superell_export(struct bu_external *ep, const struct rt_db_internal *ip, double local2mm, const struct db_i *dbip)
00865 {
00866 struct rt_superell_internal *tip;
00867 union record *rec;
00868
00869 RT_CK_DB_INTERNAL(ip);
00870 if( ip->idb_type != ID_SUPERELL ) return(-1);
00871 tip = (struct rt_superell_internal *)ip->idb_ptr;
00872 RT_SUPERELL_CK_MAGIC(tip);
00873
00874 BU_CK_EXTERNAL(ep);
00875 ep->ext_nbytes = sizeof(union record);
00876 ep->ext_buf = (genptr_t)bu_calloc( 1, ep->ext_nbytes, "superell external");
00877 rec = (union record *)ep->ext_buf;
00878
00879 rec->s.s_id = ID_SOLID;
00880 rec->s.s_type = SUPERELL;
00881
00882
00883 VSCALE( &rec->s.s_values[0], tip->v, local2mm );
00884 VSCALE( &rec->s.s_values[3], tip->a, local2mm );
00885 VSCALE( &rec->s.s_values[6], tip->b, local2mm );
00886 VSCALE( &rec->s.s_values[9], tip->c, local2mm );
00887
00888 printf("SUPERELL: %g %g\n", tip->n, tip->e);
00889
00890 rec->s.s_values[12] = tip->n;
00891 rec->s.s_values[13] = tip->e;
00892
00893 return(0);
00894 }
00895
00896
00897
00898
00899
00900
00901
00902
00903 int
00904 rt_superell_import5(struct rt_db_internal *ip, const struct bu_external *ep, register const fastf_t *mat, const struct db_i *dbip)
00905 {
00906 struct rt_superell_internal *eip;
00907 fastf_t vec[ELEMENTS_PER_VECT*4 + 2];
00908
00909 RT_CK_DB_INTERNAL( ip );
00910 BU_CK_EXTERNAL( ep );
00911
00912 BU_ASSERT_LONG( ep->ext_nbytes, ==, SIZEOF_NETWORK_DOUBLE * (ELEMENTS_PER_VECT*4 + 2));
00913
00914 ip->idb_major_type = DB5_MAJORTYPE_BRLCAD;
00915 ip->idb_type = ID_SUPERELL;
00916 ip->idb_meth = &rt_functab[ID_SUPERELL];
00917 ip->idb_ptr = bu_malloc( sizeof(struct rt_superell_internal), "rt_superell_internal");
00918
00919 eip = (struct rt_superell_internal *)ip->idb_ptr;
00920 eip->magic = RT_SUPERELL_INTERNAL_MAGIC;
00921
00922
00923 ntohd( (unsigned char *)vec, ep->ext_buf, ELEMENTS_PER_VECT*4 + 2);
00924
00925
00926 MAT4X3PNT( eip->v, mat, &vec[0*ELEMENTS_PER_VECT] );
00927 MAT4X3VEC( eip->a, mat, &vec[1*ELEMENTS_PER_VECT] );
00928 MAT4X3VEC( eip->b, mat, &vec[2*ELEMENTS_PER_VECT] );
00929 MAT4X3VEC( eip->c, mat, &vec[3*ELEMENTS_PER_VECT] );
00930 eip->n = vec[4*ELEMENTS_PER_VECT];
00931 eip->e = vec[4*ELEMENTS_PER_VECT + 1];
00932
00933 return 0;
00934 }
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945 int
00946 rt_superell_export5(struct bu_external *ep, const struct rt_db_internal *ip, double local2mm, const struct db_i *dbip)
00947 {
00948 struct rt_superell_internal *eip;
00949 fastf_t vec[ELEMENTS_PER_VECT*4 + 2];
00950
00951 RT_CK_DB_INTERNAL(ip);
00952 if( ip->idb_type != ID_SUPERELL ) return(-1);
00953 eip = (struct rt_superell_internal *)ip->idb_ptr;
00954 RT_SUPERELL_CK_MAGIC(eip);
00955
00956 BU_CK_EXTERNAL(ep);
00957 ep->ext_nbytes = SIZEOF_NETWORK_DOUBLE * (ELEMENTS_PER_VECT*4 + 2);
00958 ep->ext_buf = (genptr_t)bu_malloc( ep->ext_nbytes, "superell external");
00959
00960
00961 VSCALE( &vec[0*ELEMENTS_PER_VECT], eip->v, local2mm );
00962 VSCALE( &vec[1*ELEMENTS_PER_VECT], eip->a, local2mm );
00963 VSCALE( &vec[2*ELEMENTS_PER_VECT], eip->b, local2mm );
00964 VSCALE( &vec[3*ELEMENTS_PER_VECT], eip->c, local2mm );
00965
00966 vec[4*ELEMENTS_PER_VECT] = eip->n;
00967 vec[4*ELEMENTS_PER_VECT + 1] = eip->e;
00968
00969
00970 htond( ep->ext_buf, (unsigned char *)vec, ELEMENTS_PER_VECT*4 + 2 );
00971
00972 return 0;
00973 }
00974
00975
00976
00977
00978
00979
00980
00981
00982 int
00983 rt_superell_describe(struct bu_vls *str, const struct rt_db_internal *ip, int verbose, double mm2local)
00984 {
00985 register struct rt_superell_internal *tip =
00986 (struct rt_superell_internal *)ip->idb_ptr;
00987 fastf_t mag_a, mag_b, mag_c;
00988 char buf[256];
00989 double angles[5];
00990 vect_t unitv;
00991
00992 RT_SUPERELL_CK_MAGIC(tip);
00993 bu_vls_strcat( str, "superellipsoid (SUPERELL)\n");
00994
00995 sprintf(buf, "\tV (%g, %g, %g)\n",
00996 INTCLAMP(tip->v[X] * mm2local),
00997 INTCLAMP(tip->v[Y] * mm2local),
00998 INTCLAMP(tip->v[Z] * mm2local) );
00999 bu_vls_strcat( str, buf );
01000
01001 mag_a = MAGNITUDE(tip->a);
01002 mag_b = MAGNITUDE(tip->b);
01003 mag_c = MAGNITUDE(tip->c);
01004
01005 sprintf(buf, "\tA (%g, %g, %g) mag=%g\n",
01006 INTCLAMP(tip->a[X] * mm2local),
01007 INTCLAMP(tip->a[Y] * mm2local),
01008 INTCLAMP(tip->a[Z] * mm2local),
01009 INTCLAMP(mag_a * mm2local) );
01010 bu_vls_strcat( str, buf );
01011
01012 sprintf(buf, "\tB (%g, %g, %g) mag=%g\n",
01013 INTCLAMP(tip->b[X] * mm2local),
01014 INTCLAMP(tip->b[Y] * mm2local),
01015 INTCLAMP(tip->b[Z] * mm2local),
01016 INTCLAMP(mag_b * mm2local) );
01017 bu_vls_strcat( str, buf );
01018
01019 sprintf(buf, "\tC (%g, %g, %g) mag=%g\n",
01020 INTCLAMP(tip->c[X] * mm2local),
01021 INTCLAMP(tip->c[Y] * mm2local),
01022 INTCLAMP(tip->c[Z] * mm2local),
01023 INTCLAMP(mag_c * mm2local) );
01024 bu_vls_strcat( str, buf );
01025
01026 sprintf(buf, "\t<n,e> (%g, %g)\n", INTCLAMP(tip->n), INTCLAMP(tip->e));
01027 bu_vls_strcat(str, buf);
01028
01029 if( !verbose ) return(0);
01030
01031 VSCALE( unitv, tip->a, 1/mag_a );
01032 rt_find_fallback_angle( angles, unitv );
01033 rt_pr_fallback_angle( str, "\tA", angles );
01034
01035 VSCALE( unitv, tip->b, 1/mag_b );
01036 rt_find_fallback_angle( angles, unitv );
01037 rt_pr_fallback_angle( str, "\tB", angles );
01038
01039 VSCALE( unitv, tip->c, 1/mag_c );
01040 rt_find_fallback_angle( angles, unitv );
01041 rt_pr_fallback_angle( str, "\tC", angles );
01042
01043 return(0);
01044 }
01045
01046
01047
01048
01049
01050
01051 void
01052 rt_superell_ifree(struct rt_db_internal *ip)
01053 {
01054 RT_CK_DB_INTERNAL(ip);
01055 bu_free( ip->idb_ptr, "superell ifree" );
01056 ip->idb_ptr = GENPTR_NULL;
01057 }
01058
01059
01060
01061
01062
01063 static const fastf_t rt_superell_uvw[5*ELEMENTS_PER_VECT] = {
01064 0, 1, 0,
01065 0, 0, 0,
01066 1, 0, 0,
01067 1, 1, 0,
01068 0, 1, 0
01069 };
01070
01071
01072
01073
01074 int
01075 rt_superell_tnurb(struct nmgregion **r, struct model *m, struct rt_db_internal *ip, const struct bn_tol *tol)
01076 {
01077 bu_log("rt_superell_tnurb called!\n");
01078 return 0;
01079 }
01080
01081
01082
01083
01084
01085
01086
01087
01088
01089
01090