mkbundle.c

Go to the documentation of this file.
00001 /*                      M K B U N D L E . C
00002  * BRL-CAD
00003  *
00004  * Copyright (c) 2004-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 
00022 /** @addtogroup librt */
00023 /*@{*/
00024 /** @file mkbundle.c
00025  *
00026  *  Author -
00027  *      Michael John Muuss
00028  *
00029  *  Source -
00030  *      The U. S. Army Research Laboratory
00031  *      Aberdeen Proving Ground, Maryland  21005-5068  USA
00032  *
00033  */
00034 /*@}*/
00035 
00036 #ifndef lint
00037 static const char RCSmkbundle[] = "@(#)$Header: /cvsroot/brlcad/brlcad/src/librt/mkbundle.c,v 14.10 2006/09/16 02:04:25 lbutler Exp $ (BRL)";
00038 #endif
00039 
00040 #include "common.h"
00041 
00042 
00043 
00044 #include <stdio.h>
00045 #include <math.h>
00046 #include "machine.h"
00047 #include "vmath.h"
00048 #include "bu.h"
00049 #include "bn.h"
00050 #include "raytrace.h"
00051 #include "./debug.h"
00052 
00053 /*
00054  *                      R T _ R A Y B U N D L E _ M A K E R
00055  *
00056  *  Make a bundle of rays around a main ray, with a circular exterior,
00057  *  and spiral filling of the interior.
00058  *  The outer periphery is sampled with rays_per_ring additional rays,
00059  *  preferably at least 3.
00060  *
00061  *  rp[] must be of size (rays_per_ring*nring)+1.
00062  *  Entry 0 is the main ray, and must be provided by the caller.
00063  *  The remaining entries will be filled in with extra rays.
00064  *  The radius of the bundle is given in mm.
00065  *
00066  *  rp[0].r_dir must have unit length.
00067  *
00068  *  XXX Should we require a and b as inputs, for efficiency?
00069  */
00070 void
00071 rt_raybundle_maker(struct xray *rp, double radius, const fastf_t *avec, const fastf_t *bvec, int rays_per_ring, int nring)
00072 {
00073         register struct xray    *rayp = rp+1;
00074         int     ring;
00075         double  fraction = 1.0;
00076         double  theta;
00077         double  delta;
00078         double  radial_scale;
00079         int     count = 0;
00080 
00081         rp[0].index = count++;
00082         rp[0].magic =RT_RAY_MAGIC;
00083 
00084         for( ring=0; ring < nring; ring++ )  {
00085                 register int i;
00086 
00087                 theta = 0;
00088                 delta = bn_twopi / rays_per_ring;
00089                 fraction = ((double)(ring+1)) / nring;
00090                 theta = delta * fraction;       /* spiral skew */
00091                 radial_scale = radius * fraction;
00092                 for( i=0; i < rays_per_ring; i++ )  {
00093                         register double ct, st;
00094                         /* pt = V + cos(theta) * A + sin(theta) * B */
00095                         ct = cos(theta) * radial_scale;
00096                         st = sin(theta) * radial_scale;
00097                         VJOIN2( rayp->r_pt, rp[0].r_pt, ct, avec, st, bvec );
00098                         VMOVE( rayp->r_dir, rp[0].r_dir );
00099                         rayp->index = count++;
00100                         rayp->magic = RT_RAY_MAGIC;
00101                         theta += delta;
00102                         rayp++;
00103                 }
00104         }
00105 }
00106 
00107 /*
00108  *  Test driver.
00109  */
00110 
00111 #if 0
00112 main()
00113 {
00114         FILE    *fp = fopen("bundle.pl", "w");
00115         int     rays_per_ring=5;
00116         int     nring=3;
00117         fastf_t bundle_radius=1000.0;
00118         int     i;
00119         vect_t avec, bvec;
00120         struct xray *rp;
00121         vect_t dir;
00122 
00123 
00124         VSET( dir, 0, 0, -1 );
00125         /* create orthogonal rays for basis of bundle */
00126         bn_vec_ortho( avec, dir );
00127         VCROSS( bvec, dir, avec );
00128         VUNITIZE( bvec );
00129 
00130         rp = (struct xray *)bu_calloc( sizeof( struct xray ),
00131                                        (rays_per_ring * nring) + 1,
00132                                        "ray bundle" );
00133         VSET( rp[0].r_pt, 0, 0, 2000);
00134         VMOVE( rp[0].r_dir, dir );
00135         rt_raybundle_maker( rp, bundle_radius, avec, bvec, rays_per_ring, nring );
00136 
00137 
00138         for( i=0; i <= rays_per_ring * nring; i++ )  {
00139                 point_t tip;
00140                 VJOIN1( tip, rp[i].r_pt, 3500, rp[i].r_dir );
00141                 pdv_3line( fp, rp[i].r_pt, tip );
00142         }
00143         fclose(fp);
00144 }
00145 #endif
00146 
00147 /*
00148  * Local Variables:
00149  * mode: C
00150  * tab-width: 8
00151  * c-basic-offset: 4
00152  * indent-tabs-mode: t
00153  * End:
00154  * ex: shiftwidth=4 tabstop=8
00155  */

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