g_xxx.c

Go to the documentation of this file.
00001 /*                         G _ X X X . C
00002  * BRL-CAD
00003  *
00004  * Copyright (c) 1990-2006 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  * as published by the Free Software Foundation; either version 2 of
00010  * the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Library General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this file; see the file named COPYING for more
00019  * information.
00020  */
00021 /** @addtogroup g_  */
00022 
00023 /*@{*/
00024 /** @file g_xxx.c
00025  *      Intersect a ray with a.
00026  *
00027  * Adding a new solid type:
00028  *      Design disk record
00029  *
00030  *      define rt_xxx_internal --- parameters for solid
00031  *      define xxx_specific --- raytracing form, possibly w/precomuted terms
00032  *      define rt_xxx_parse --- struct bu_structparse for "db get", "db adjust", ...
00033  *
00034  *      code import/export/describe/print/ifree/plot/prep/shot/curve/uv/tess
00035  *
00036  *      edit db.h add solidrec s_type define
00037  *      edit rtgeom.h to add rt_xxx_internal
00038  *      edit table.c:
00039  *              RT_DECLARE_INTERFACE()
00040  *              struct rt_functab entry
00041  *              rt_id_solid()
00042  *      edit raytrace.h to make ID_XXX, increment ID_MAXIMUM
00043  *      edit db_scan.c to add the new solid to db_scan()
00044  *      edit Makefile.am to add g_xxx.c to compile
00045  *
00046  *      Then:
00047  *      go to src/libwdb and create mk_xxx() routine
00048  *      go to src/conv and edit g2asc.c and asc2g.c to support the new solid
00049  *      go to src/librt and edit tcl.c to add the new solid to
00050  *              rt_solid_type_lookup[]
00051  *              also add the interface table and to rt_id_solid() in table.c
00052  *      go to src/mged and create the edit support
00053  *
00054  *  Authors -
00055  *
00056  *  Source -
00057  *      SECAD/VLD Computing Consortium, Bldg 394
00058  *      The U. S. Army Ballistic Research Laboratory
00059  *      Aberdeen Proving Ground, Maryland  21005-5066
00060  *
00061  */
00062 /*@}*/
00063 
00064 #ifndef lint
00065 static const char RCSxxx[] = "@(#)$Header: /cvsroot/brlcad/brlcad/src/librt/g_xxx.c,v 14.14 2006/09/16 02:04:25 lbutler Exp $ (BRL)";
00066 #endif
00067 
00068 #include "common.h"
00069 
00070 /* system headers */
00071 #include <stdio.h>
00072 #include <math.h>
00073 
00074 /* interface headers */
00075 #include "machine.h"
00076 #include "vmath.h"
00077 #include "db.h"
00078 #include "nmg.h"
00079 #include "raytrace.h"
00080 #include "rtgeom.h"
00081 
00082 /* local headers */
00083 #include "./debug.h"
00084 
00085 
00086 #if 0
00087 /* parameters for solid, internal representation
00088  * This goes in rtgeom.h
00089  */
00090 /* parameters for solid, internal representation */
00091 struct rt_xxx_internal {
00092         long    magic;
00093         vect_t  v;
00094 };
00095 #  define RT_XXX_INTERNAL_MAGIC 0xxx
00096 #  define RT_XXX_CK_MAGIC(_p)   BU_CKMAG(_p,RT_XXX_INTERNAL_MAGIC,"rt_xxx_internal")
00097 #endif
00098 
00099 /* ray tracing form of solid, including precomputed terms */
00100 struct xxx_specific {
00101         vect_t  xxx_V;
00102 };
00103 
00104 
00105 /**
00106  *                      R T _ X X X _ P R E P
00107  *
00108  *  Given a pointer to a GED database record, and a transformation matrix,
00109  *  determine if this is a valid XXX, and if so, precompute various
00110  *  terms of the formula.
00111  *
00112  *  Returns -
00113  *      0       XXX is OK
00114  *      !0      Error in description
00115  *
00116  *  Implicit return -
00117  *      A struct xxx_specific is created, and it's address is stored in
00118  *      stp->st_specific for use by xxx_shot().
00119  */
00120 int
00121 rt_xxx_prep( struct soltab *stp, struct rt_db_internal *ip, struct rt_i *rtip )
00122 {
00123         struct rt_xxx_internal          *xxx_ip;
00124         register struct xxx_specific    *xxx;
00125         const struct bn_tol             *tol = &rtip->rti_tol;
00126 
00127         RT_CK_DB_INTERNAL(ip);
00128         xxx_ip = (struct rt_xxx_internal *)ip->idb_ptr;
00129         RT_XXX_CK_MAGIC(xxx_ip);
00130 }
00131 
00132 /**
00133  *                      R T _ X X X _ P R I N T
00134  */
00135 void
00136 rt_xxx_print( const struct soltab *stp )
00137 {
00138         register const struct xxx_specific *xxx =
00139                 (struct xxx_specific *)stp->st_specific;
00140 }
00141 
00142 /**
00143  *                      R T _ X X X _ S H O T
00144  *
00145  *  Intersect a ray with a xxx.
00146  *  If an intersection occurs, a struct seg will be acquired
00147  *  and filled in.
00148  *
00149  *  Returns -
00150  *      0       MISS
00151  *      >0      HIT
00152  */
00153 int
00154 rt_xxx_shot( struct soltab *stp, struct xray *rp, struct application *ap, struct seg *seghead )
00155 {
00156         register struct xxx_specific *xxx =
00157                 (struct xxx_specific *)stp->st_specific;
00158         register struct seg *segp;
00159         const struct bn_tol     *tol = &ap->a_rt_i->rti_tol;
00160 
00161         return(0);                      /* MISS */
00162 }
00163 
00164 #define RT_XXX_SEG_MISS(SEG)    (SEG).seg_stp=RT_SOLTAB_NULL
00165 
00166 /**
00167  *                      R T _ X X X _ V S H O T
00168  *
00169  *  Vectorized version.
00170  */
00171 void
00172 rt_xxx_vshot(struct soltab *stp[],      /* An array of solid pointers */
00173              struct xray *rp[],         /* An array of ray pointers */
00174              struct seg segp[],         /* array of segs (results returned) */
00175              int n,                     /* Number of ray/object pairs */
00176              struct application *ap)
00177 {
00178         rt_vstub( stp, rp, segp, n, ap );
00179 }
00180 
00181 /**
00182  *                      R T _ X X X _ N O R M
00183  *
00184  *  Given ONE ray distance, return the normal and entry/exit point.
00185  */
00186 void
00187 rt_xxx_norm( struct hit *hitp, struct soltab *stp, struct xray *rp )
00188 {
00189         register struct xxx_specific *xxx =
00190                 (struct xxx_specific *)stp->st_specific;
00191 
00192         VJOIN1( hitp->hit_point, rp->r_pt, hitp->hit_dist, rp->r_dir );
00193 }
00194 
00195 /**
00196  *                      R T _ X X X _ C U R V E
00197  *
00198  *  Return the curvature of the xxx.
00199  */
00200 void
00201 rt_xxx_curve( struct curvature *cvp, struct hit *hitp, struct soltab *stp )
00202 {
00203         register struct xxx_specific *xxx =
00204                 (struct xxx_specific *)stp->st_specific;
00205 
00206         cvp->crv_c1 = cvp->crv_c2 = 0;
00207 
00208         /* any tangent direction */
00209         bn_vec_ortho( cvp->crv_pdir, hitp->hit_normal );
00210 }
00211 
00212 /**
00213  *                      R T _ X X X _ U V
00214  *
00215  *  For a hit on the surface of an xxx, return the (u,v) coordinates
00216  *  of the hit point, 0 <= u,v <= 1.
00217  *  u = azimuth
00218  *  v = elevation
00219  */
00220 void
00221 rt_xxx_uv( struct application *ap, struct soltab *stp, struct hit *hitp, struct uvcoord *uvp )
00222 {
00223         register struct xxx_specific *xxx =
00224                 (struct xxx_specific *)stp->st_specific;
00225 }
00226 
00227 /**
00228  *              R T _ X X X _ F R E E
00229  */
00230 void
00231 rt_xxx_free( struct soltab *stp )
00232 {
00233         register struct xxx_specific *xxx =
00234                 (struct xxx_specific *)stp->st_specific;
00235 
00236         bu_free( (char *)xxx, "xxx_specific" );
00237 }
00238 
00239 /**
00240  *                      R T _ X X X _ C L A S S
00241  */
00242 int
00243 rt_xxx_class( const struct soltab *stp, const vect_t min, const vect_t max, const struct bn_tol *tol )
00244 {
00245         return RT_CLASSIFY_UNIMPLEMENTED;
00246 }
00247 
00248 /**
00249  *                      R T _ X X X _ P L O T
00250  */
00251 int
00252 rt_xxx_plot( struct bu_list *vhead, struct rt_db_internal *ip, const struct rt_tess_tol *ttol, const struct bn_tol *tol )
00253 {
00254         LOCAL struct rt_xxx_internal    *xxx_ip;
00255 
00256         RT_CK_DB_INTERNAL(ip);
00257         xxx_ip = (struct rt_xxx_internal *)ip->idb_ptr;
00258         RT_XXX_CK_MAGIC(xxx_ip);
00259 
00260         return(-1);
00261 }
00262 
00263 /**
00264  *                      R T _ X X X _ T E S S
00265  *
00266  *  Returns -
00267  *      -1      failure
00268  *       0      OK.  *r points to nmgregion that holds this tessellation.
00269  */
00270 int
00271 rt_xxx_tess( struct nmgregion **r, struct model *m, struct rt_db_internal *ip, const struct rt_tess_tol *ttol, const struct bn_tol *tol )
00272 {
00273         LOCAL struct rt_xxx_internal    *xxx_ip;
00274 
00275         RT_CK_DB_INTERNAL(ip);
00276         xxx_ip = (struct rt_xxx_internal *)ip->idb_ptr;
00277         RT_XXX_CK_MAGIC(xxx_ip);
00278 
00279         return(-1);
00280 }
00281 
00282 /**
00283  *                      R T _ X X X _ I M P O R T
00284  *
00285  *  Import an XXX from the database format to the internal format.
00286  *  Apply modeling transformations as well.
00287  */
00288 int
00289 rt_xxx_import( struct rt_db_internal *ip, const struct bu_external *ep, const mat_t mat, const struct db_i *dbip )
00290 {
00291         LOCAL struct rt_xxx_internal    *xxx_ip;
00292         union record                    *rp;
00293 
00294         BU_CK_EXTERNAL( ep );
00295         rp = (union record *)ep->ext_buf;
00296         /* Check record type */
00297         if( rp->u_id != ID_SOLID )  {
00298                 bu_log("rt_xxx_import: defective record\n");
00299                 return(-1);
00300         }
00301 
00302         RT_CK_DB_INTERNAL( ip );
00303         ip->idb_major_type = DB5_MAJORTYPE_BRLCAD;
00304         ip->idb_type = ID_XXX;
00305         ip->idb_meth = &rt_functab[ID_XXX];
00306         ip->idb_ptr = bu_malloc( sizeof(struct rt_xxx_internal), "rt_xxx_internal");
00307         xxx_ip = (struct rt_xxx_internal *)ip->idb_ptr;
00308         xxx_ip->magic = RT_XXX_INTERNAL_MAGIC;
00309 
00310         MAT4X3PNT( xxx_ip->xxx_V, mat, &rp->s.s_values[0] );
00311 
00312         return(0);                      /* OK */
00313 }
00314 
00315 /**
00316  *                      R T _ X X X _ E X P O R T
00317  *
00318  *  The name is added by the caller, in the usual place.
00319  */
00320 int
00321 rt_xxx_export( struct bu_external *ep, const struct rt_db_internal *ip, double local2mm, const struct db_i *dbip )
00322 {
00323         struct rt_xxx_internal  *xxx_ip;
00324         union record            *rec;
00325 
00326         RT_CK_DB_INTERNAL(ip);
00327         if( ip->idb_type != ID_XXX )  return(-1);
00328         xxx_ip = (struct rt_xxx_internal *)ip->idb_ptr;
00329         RT_XXX_CK_MAGIC(xxx_ip);
00330 
00331         BU_CK_EXTERNAL(ep);
00332         ep->ext_nbytes = sizeof(union record);
00333         ep->ext_buf = (genptr_t)bu_calloc( 1, ep->ext_nbytes, "xxx external");
00334         rec = (union record *)ep->ext_buf;
00335 
00336         rec->s.s_id = ID_SOLID;
00337         rec->s.s_type = XXX;    /* GED primitive type from db.h */
00338 
00339         /* Since libwdb users may want to operate in units other
00340          * than mm, we offer the opportunity to scale the solid
00341          * (to get it into mm) on the way out.
00342          */
00343 
00344 
00345         /* convert from local editing units to mm and export
00346          * to database record format
00347          *
00348          * Warning: type conversion: double to float
00349          */
00350         VSCALE( &rec->s.s_values[0], xxx_ip->xxx_V, local2mm );
00351         rec->s.s_values[3] = xxx_ip->xxx_radius * local2mm;
00352 
00353         return(0);
00354 }
00355 
00356 
00357 
00358 /**
00359  *                      R T _ X X X _ I M P O R T 5
00360  *
00361  *  Import an XXX from the database format to the internal format.
00362  *  Note that the data read will be in network order.  This means
00363  *  Big-Endian integers and IEEE doubles for floating point.
00364  *
00365  *  Apply modeling transformations as well.
00366  *
00367  */
00368 int
00369 rt_xxx_import5( struct rt_db_internal  *ip, const struct bu_external *ep, const mat_t mat, const struct db_i *dbip )
00370 {
00371         LOCAL struct rt_xxx_internal    *xxx_ip;
00372         fastf_t                         vv[ELEMENTS_PER_VECT*1];
00373 
00374         RT_CK_DB_INTERNAL(ip)
00375         BU_CK_EXTERNAL( ep );
00376 
00377         BU_ASSERT_LONG( ep->ext_nbytes, ==, SIZEOF_NETWORK_DOUBLE * 3*4 );
00378 
00379         /* set up the internal structure */
00380         ip->idb_major_type = DB5_MAJORTYPE_BRLCAD;
00381         ip->idb_type = ID_XXX;
00382         ip->idb_meth = &rt_functab[ID_XXX];
00383         ip->idb_ptr = bu_malloc( sizeof(struct rt_xxx_internal), "rt_xxx_internal");
00384         xxx_ip = (struct rt_xxx_internal *)ip->idb_ptr;
00385         xxx_ip->magic = RT_XXX_INTERNAL_MAGIC;
00386 
00387         /* Convert the data in ep->ext_buf into internal format.
00388          * Note the conversion from network data
00389          * (Big Endian ints, IEEE double floating point) to host local data
00390          * representations.
00391          */
00392         ntohd( (unsigned char *)&vv, (char *)ep->ext_buf, ELEMENTS_PER_VECT*1 );
00393 
00394         /* Apply the modeling transformation */
00395         MAT4X3PNT( xxx_ip->v, mat, vv );
00396 
00397         return(0);                      /* OK */
00398 }
00399 
00400 /**
00401  *                      R T _ X X X _ E X P O R T 5
00402  *
00403  *  Export an XXX from internal form to external format.
00404  *  Note that this means converting all integers to Big-Endian format
00405  *  and floating point data to IEEE double.
00406  *
00407  *  Apply the transformation to mm units as well.
00408  */
00409 int
00410 rt_xxx_export5( struct bu_external *ep, const struct rt_db_internal *ip, double local2mm, const struct db_i *dbip )
00411 {
00412         struct rt_xxx_internal  *xxx_ip;
00413         fastf_t                 vec[ELEMENTS_PER_VECT];
00414 
00415         RT_CK_DB_INTERNAL(ip);
00416         if( ip->idb_type != ID_XXX )  return(-1);
00417         xxx_ip = (struct rt_xxx_internal *)ip->idb_ptr;
00418         RT_XXX_CK_MAGIC(xxx_ip);
00419 
00420         BU_CK_EXTERNAL(ep);
00421         ep->ext_nbytes = SIZEOF_NETWORK_DOUBLE * ELEMENTS_PER_VECT;
00422         ep->ext_buf = (genptr_t)bu_calloc( 1, ep->ext_nbytes, "xxx external");
00423 
00424 
00425         /* Since libwdb users may want to operate in units other
00426          * than mm, we offer the opportunity to scale the solid
00427          * (to get it into mm) on the way out.
00428          */
00429         VSCALE( vec, xxx_ip->v, local2mm );
00430 
00431         /* Convert from internal (host) to database (network) format */
00432         htond( ep->ext_buf, (unsigned char *)vec, ELEMENTS_PER_VECT*1 );
00433 
00434         return 0;
00435 }
00436 
00437 /**
00438  *                      R T _ X X X _ D E S C R I B E
00439  *
00440  *  Make human-readable formatted presentation of this solid.
00441  *  First line describes type of solid.
00442  *  Additional lines are indented one tab, and give parameter values.
00443  */
00444 int
00445 rt_xxx_describe( struct bu_vls *str, const struct rt_db_internal *ip, int verbose, double mm2local )
00446 {
00447         register struct rt_xxx_internal *xxx_ip =
00448                 (struct rt_xxx_internal *)ip->idb_ptr;
00449         char    buf[256];
00450 
00451         RT_XXX_CK_MAGIC(xxx_ip);
00452         bu_vls_strcat( str, "truncated general xxx (XXX)\n");
00453 
00454         sprintf(buf, "\tV (%g, %g, %g)\n",
00455                 INTCLAMP(xxx_ip->v[X] * mm2local),
00456                 INTCLAMP(xxx_ip->v[Y] * mm2local),
00457                 INTCLAMP(xxx_ip->v[Z] * mm2local) );
00458         bu_vls_strcat( str, buf );
00459 
00460         return(0);
00461 }
00462 
00463 /**
00464  *                      R T _ X X X _ I F R E E
00465  *
00466  *  Free the storage associated with the rt_db_internal version of this solid.
00467  */
00468 void
00469 rt_xxx_ifree( struct rt_db_internal *ip )
00470 {
00471         register struct rt_xxx_internal *xxx_ip;
00472 
00473         RT_CK_DB_INTERNAL(ip);
00474         xxx_ip = (struct rt_xxx_internal *)ip->idb_ptr;
00475         RT_XXX_CK_MAGIC(xxx_ip);
00476         xxx_ip->magic = 0;                      /* sanity */
00477 
00478         bu_free( (char *)xxx_ip, "xxx ifree" );
00479         ip->idb_ptr = GENPTR_NULL;      /* sanity */
00480 }
00481 
00482 /**
00483  *                      R T _ X X X _ X F O R M
00484  *
00485  *  Create transformed version of internal form.  Free *ip if requested.
00486  *  Implement this if it's faster than doing an export/import cycle.
00487  */
00488 int
00489 rt_xxx_xform( struct rt_db_internal *op, const mat_t mat, struct rt_db_internal *ip, int free )
00490 {
00491 }
00492 
00493 /*
00494  * Local Variables:
00495  * mode: C
00496  * tab-width: 8
00497  * c-basic-offset: 4
00498  * indent-tabs-mode: t
00499  * End:
00500  * ex: shiftwidth=4 tabstop=8
00501  */

Generated on Mon Sep 18 01:24:52 2006 for BRL-CAD by  doxygen 1.4.6