BRL-CAD
nurb_example.c
Go to the documentation of this file.
1 /* N U R B _ E X A M P L E . C
2  * BRL-CAD
3  *
4  * Copyright (c) 2004-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 /** @addtogroup nurb */
21 /** @{ */
22 /** @file librt/nurb_example.c
23  *
24  */
25 /** @} */
26 
27 #include "common.h"
28 
29 #include <stdlib.h>
30 #include <stdio.h>
31 #include <math.h>
32 #include "vmath.h"
33 #include "raytrace.h"
34 #include "nurb.h"
35 #include "plot3.h"
36 
37 
38 extern double drand48(void);
39 
40 fastf_t grid[10][10][3];
41 fastf_t ngrid[10][10][3];
42 
43 
44 /* Interpolate the data using b-splines */
45 void
47 {
48  struct face_g_snurb srf;
49  struct face_g_snurb *srf2, *srf3;
50  struct knot_vector new_kv;
51 
52  rt_nurb_sinterp(&srf, 4, (const fastf_t *)grid, 10, 10);
53 
54  /* lets take a look at it. Refine to 100 points in both directions. */
55  rt_nurb_kvknot(&new_kv, srf.order[0], 0.0, 1.0, 100, (struct resource *)NULL);
56  srf2 = (struct face_g_snurb *) rt_nurb_s_refine(&srf, 0, &new_kv, (struct resource *)NULL);
57  srf3 = (struct face_g_snurb *) rt_nurb_s_refine(srf2, 1, &new_kv, (struct resource *)NULL);
58 
59  /* Draw refined mesh in yellow */
60  pl_color(stdout, 200, 200, 50);
61  rt_nurb_plot_snurb(stdout, srf3);
62 }
63 
64 
65 int
66 main(int argc, char *argv[])
67 {
68 
69  fastf_t hscale;
70  fastf_t v;
71  int i, j;
72 
73  if (argc > 1)
74  fprintf(stderr,"Usage: %s\n", argv[0]);
75 
76  hscale = 2.5;
77 
78  /* generate a 10 x 10 grid of random height data */
79 
80  pl_color(stdout, 155, 55, 55);
81 
82  for (i = 0; i < 10; i++) {
83  for (j = 0; j < 10; j++) {
84  v = hscale * drand48() + 10.0;
85  grid[i][j][0] = i;
86  grid[i][j][1] = j;
87  grid[i][j][2] = v;
88 
89  pd_3move(stdout,
90  grid[i][j][0], grid[i][j][1], grid[i][j][2] - .14);
91  pd_3cont(stdout,
92  grid[i][j][0], grid[i][j][1], grid[i][j][2] + .14);
93 
94  pd_3move(stdout,
95  grid[i][j][0] - .14, grid[i][j][1], grid[i][j][2]);
96  pd_3cont(stdout,
97  grid[i][j][0] + .14, grid[i][j][1], grid[i][j][2]);
98 
99  pd_3move(stdout,
100  grid[i][j][0], grid[i][j][1]-.14, grid[i][j][2]);
101  pd_3cont(stdout,
102  grid[i][j][0], grid[i][j][1]+.14, grid[i][j][2]);
103  }
104  }
105 
106 
108 
109  return 0;
110 }
111 
112 
113 /*
114  * Local Variables:
115  * mode: C
116  * tab-width: 8
117  * indent-tabs-mode: t
118  * c-file-style: "stroustrup"
119  * End:
120  * ex: shiftwidth=4 tabstop=8
121  */
struct face_g_snurb * rt_nurb_s_refine(const struct face_g_snurb *srf, int dir, struct knot_vector *kv, struct resource *res)
Definition: nurb_refine.c:45
fastf_t ngrid[10][10][3]
Definition: nurb_example.c:41
Header file for the BRL-CAD common definitions.
void pd_3move(register FILE *plotfp, double x, double y, double z)
Definition: plot3.c:624
void rt_nurb_sinterp(struct face_g_snurb *srf, int order, const fastf_t *data, int ymax, int xmax)
Definition: nurb_interp.c:151
void pd_3cont(register FILE *plotfp, double x, double y, double z)
Definition: plot3.c:636
void rt_nurb_plot_snurb(FILE *fp, const struct face_g_snurb *srf)
Definition: nurb_plot.c:41
double drand48(void)
void pl_color(register FILE *plotfp, int r, int g, int b)
Definition: plot3.c:325
int main(int argc, char *argv[])
Definition: nurb_example.c:66
void interpolate_data()
Definition: nurb_example.c:46
fastf_t grid[10][10][3]
Definition: nurb_example.c:40
double fastf_t
Definition: defines.h:300
void rt_nurb_kvknot(register struct knot_vector *new_knots, int order, fastf_t lower, fastf_t upper, int num, struct resource *res)
Definition: nurb_knot.c:47