nurb_example.c

Go to the documentation of this file.
00001 /*                  N U R B _ E X A M P 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 nurb */
00023 
00024 /*@{*/
00025 /** @file nurb_example.c
00026  *
00027  *  Author -
00028  *      Paul R. Stay
00029  *
00030  *  Source -
00031  *      The U. S. Army Research Laboratory
00032  *      Aberdeen Proving Ground, Maryland  21005-5068  USA
00033  *
00034  */
00035 /*@}*/
00036 
00037 #ifndef lint
00038 static const char RCSid[] = "@(#)$Header: /cvsroot/brlcad/brlcad/src/librt/nurb_example.c,v 14.11 2006/09/16 02:04:25 lbutler Exp $ (ARL)";
00039 #endif
00040 
00041 #include "common.h"
00042 
00043 #include <stdlib.h>
00044 #include <stdio.h>
00045 #include <math.h>
00046 #include "machine.h"
00047 #include "vmath.h"
00048 #include "raytrace.h"
00049 #include "nurb.h"
00050 #include "plot3.h"
00051 
00052 
00053 fastf_t grid[10][10][3];
00054 fastf_t ngrid[10][10][3];
00055 
00056 
00057 /* Interpoate the data using b-splines */
00058 void
00059 interpolate_data()
00060 {
00061         struct face_g_snurb srf;
00062         struct face_g_snurb *srf2, *srf3;
00063         struct knot_vector new_kv;
00064 
00065         rt_nurb_sinterp( &srf, 4, (const fastf_t *)grid, 10, 10 );
00066 
00067 #if 0
00068         /* Draw control mesh in blue */
00069         pl_color( stdout, 145, 145, 255 );
00070         rt_nurb_plot_snurb( stdout, &srf );
00071 #endif
00072 
00073 #if 0
00074         rt_nurb_reverse_srf( &srf );
00075         rt_nurb_kvnorm( &srf.u );
00076         rt_nurb_kvnorm( &srf.v );
00077 #endif
00078 
00079         /* lets take a look at it.  Refine to 100 points in both directions. */
00080         rt_nurb_kvknot( &new_kv, srf.order[0], 0.0, 1.0, 100, (struct resource *)NULL);
00081         srf2 = (struct face_g_snurb *) rt_nurb_s_refine( &srf, 0, &new_kv, (struct resource *)NULL);
00082         srf3 = (struct face_g_snurb *) rt_nurb_s_refine( srf2, 1, &new_kv, (struct resource *)NULL);
00083 
00084         /* Draw refined mesh in yellow */
00085         pl_color( stdout, 200, 200, 50 );
00086         rt_nurb_plot_snurb( stdout, srf3 );
00087 }
00088 
00089 int main(int argc, char *argv[])
00090 {
00091 
00092         fastf_t hscale;
00093         fastf_t v;
00094         int i, j;
00095 
00096         hscale = 2.5;
00097 
00098         /* generate a 10 x 10 grid of random height data */
00099 
00100         pl_color(stdout,155, 55, 55);
00101 
00102         for( i = 0; i < 10; i++)
00103                 for( j = 0; j < 10; j++)
00104                 {
00105                         v = hscale * drand48() + 10.0;
00106                         grid[i][j][0] = i;
00107                         grid[i][j][1] = j;
00108                         grid[i][j][2] = v;
00109 
00110                         pd_3move( stdout,
00111                             grid[i][j][0],  grid[i][j][1], grid[i][j][2] - .14);
00112                         pd_3cont( stdout,
00113                             grid[i][j][0], grid[i][j][1], grid[i][j][2] + .14);
00114 
00115                         pd_3move( stdout,
00116                             grid[i][j][0] - .14, grid[i][j][1], grid[i][j][2]);
00117                         pd_3cont( stdout,
00118                             grid[i][j][0] + .14, grid[i][j][1], grid[i][j][2] );
00119 
00120                         pd_3move( stdout,
00121                             grid[i][j][0], grid[i][j][1]-.14, grid[i][j][2]);
00122                         pd_3cont( stdout,
00123                             grid[i][j][0], grid[i][j][1]+.14, grid[i][j][2]);
00124                 }
00125 
00126         interpolate_data();
00127 }
00128 
00129 /*
00130  * Local Variables:
00131  * mode: C
00132  * tab-width: 8
00133  * c-basic-offset: 4
00134  * indent-tabs-mode: t
00135  * End:
00136  * ex: shiftwidth=4 tabstop=8
00137  */

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