BRL-CAD
nurb_refine.c
Go to the documentation of this file.
1 /* N U R B _ R E F I N E . C
2  * BRL-CAD
3  *
4  * Copyright (c) 1986-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 primitives/bspline/nurb_refine.c
23  *
24  * Refines a surface by inserting knots with respect to the row or
25  * columns of the control points resulting in the same surface with new
26  * control points.
27  *
28  */
29 /** @} */
30 
31 #include "common.h"
32 
33 #include "bio.h"
34 
35 #include "vmath.h"
36 #include "nmg.h"
37 #include "raytrace.h"
38 #include "nurb.h"
39 
40 
41 /**
42  * Returns a refined surface. The original surface is unmodified.
43  */
44 struct face_g_snurb *
45 rt_nurb_s_refine(const struct face_g_snurb *srf, int dir, struct knot_vector *kv, struct resource *res)
46  /* Old surface to be refined */
47  /* Direction to refine */
48  /* Row = 0, Col = 1 */
49  /* New knot vector */
50 
51 {
52  register struct face_g_snurb * nurb_srf;
53  struct oslo_mat *oslo; /* oslo refinement matrix */
54  int i;
55 
56  NMG_CK_SNURB(srf);
57 
58  if (dir == RT_NURB_SPLIT_ROW) {
59  /* Row (u) direction */
60  GET_SNURB(nurb_srf);
61  nurb_srf->order[0] = srf->order[0];
62  nurb_srf->order[1] = srf->order[1];
63 
64  rt_nurb_kvcopy(&nurb_srf->u, kv, res);
65  rt_nurb_kvcopy(&nurb_srf->v, &srf->v, res);
66 
67  nurb_srf->s_size[0] = srf->s_size[0];
68  nurb_srf->s_size[1] = kv->k_size - srf->order[0];
69  nurb_srf->pt_type = srf->pt_type;
70  nurb_srf->ctl_points = (fastf_t *)
71  bu_malloc(sizeof (fastf_t) *
72  nurb_srf->s_size[0] *
73  nurb_srf->s_size[1] *
74  RT_NURB_EXTRACT_COORDS(nurb_srf->pt_type),
75  "rt_nurb_s_refine: row mesh control points");
76 
77  oslo = (struct oslo_mat *)
78  rt_nurb_calc_oslo (srf -> order[RT_NURB_SPLIT_ROW], &srf->u, kv, res);
79 
80  for (i = 0; i < nurb_srf->s_size[0]; i++) {
81  fastf_t * old_mesh_ptr;
82  fastf_t * new_mesh_ptr;
83 
84  old_mesh_ptr = &srf->ctl_points[
85  i * srf->s_size[1] *
86  RT_NURB_EXTRACT_COORDS(srf->pt_type)];
87  new_mesh_ptr = &nurb_srf->ctl_points[
88  i * nurb_srf->s_size[1] *
89  RT_NURB_EXTRACT_COORDS(nurb_srf->pt_type)];
90  rt_nurb_map_oslo(oslo, old_mesh_ptr, new_mesh_ptr,
91  RT_NURB_EXTRACT_COORDS(srf->pt_type),
92  RT_NURB_EXTRACT_COORDS(nurb_srf->pt_type),
93  0, kv->k_size - nurb_srf->order[0],
94  nurb_srf->pt_type);
95  }
96 
97  rt_nurb_free_oslo(oslo, res);
98 
99  } else {
100  /* Col (v) direction */
101  GET_SNURB(nurb_srf);
102  nurb_srf->order[0] = srf->order[0];
103  nurb_srf->order[1] = srf->order[1];
104 
105  rt_nurb_kvcopy(&nurb_srf->u, &srf->u, res);
106  rt_nurb_kvcopy(&nurb_srf->v, kv, res);
107 
108  nurb_srf->s_size[0] = kv->k_size - srf->order[1];
109  nurb_srf->s_size[1] = srf->s_size[1];
110 
111  nurb_srf->pt_type = srf->pt_type;
112  nurb_srf->ctl_points = (fastf_t *)
113  bu_malloc(sizeof (fastf_t) *
114  nurb_srf->s_size[0] *
115  nurb_srf->s_size[1] *
116  RT_NURB_EXTRACT_COORDS(nurb_srf->pt_type),
117  "rt_nurb_s_refine: row mesh control points");
118 
119  oslo = (struct oslo_mat *)
120  rt_nurb_calc_oslo (srf->order[RT_NURB_SPLIT_COL], &srf->v, kv, res);
121 
122  for (i = 0; i < nurb_srf->s_size[1]; i++) {
123  fastf_t * old_mesh_ptr;
124  fastf_t * new_mesh_ptr;
125 
126  old_mesh_ptr = &srf->ctl_points[
127  i * RT_NURB_EXTRACT_COORDS(srf->pt_type)];
128  new_mesh_ptr = &nurb_srf->ctl_points[
129  i * RT_NURB_EXTRACT_COORDS(nurb_srf->pt_type)];
130  rt_nurb_map_oslo(oslo, old_mesh_ptr, new_mesh_ptr,
131  srf->s_size[1] *
132  RT_NURB_EXTRACT_COORDS(srf->pt_type),
133  nurb_srf->s_size[1] *
134  RT_NURB_EXTRACT_COORDS(nurb_srf->pt_type),
135  0, kv->k_size - nurb_srf->order[1],
136  nurb_srf->pt_type);
137  }
138  rt_nurb_free_oslo(oslo, res);
139  }
140  return nurb_srf;
141 }
142 
143 
144 struct edge_g_cnurb *
145 rt_nurb_c_refine(const struct edge_g_cnurb *crv, struct knot_vector *kv)
146 {
147  struct oslo_mat * oslo;
148  struct edge_g_cnurb * new_crv;
149  int i, coords;
150 
151  NMG_CK_CNURB(crv);
152 
153  coords = RT_NURB_EXTRACT_COORDS(crv->pt_type);
154 
155  new_crv = (struct edge_g_cnurb *) rt_nurb_new_cnurb(
156  crv->order, kv->k_size, kv->k_size - crv->order,
157  crv->pt_type);
158 
159  oslo = (struct oslo_mat *) rt_nurb_calc_oslo(
160  crv->order, &crv->k, kv, (struct resource *)NULL);
161 
162  rt_nurb_map_oslo(oslo, crv->ctl_points,
163  new_crv->ctl_points,
164  coords, coords, 0,
165  kv->k_size - new_crv->order,
166  new_crv->pt_type);
167 
168  new_crv->k.k_size = kv->k_size;
169 
170  for (i = 0; i < kv->k_size; i++)
171  new_crv->k.knots[i] = kv->knots[i];
172 
173  rt_nurb_free_oslo(oslo, (struct resource *)NULL);
174 
175  return new_crv;
176 }
177 
178 
179 /*
180  * Local Variables:
181  * mode: C
182  * tab-width: 8
183  * indent-tabs-mode: t
184  * c-file-style: "stroustrup"
185  * End:
186  * ex: shiftwidth=4 tabstop=8
187  */
struct edge_g_cnurb * rt_nurb_new_cnurb(int order, int n_knots, int n_pts, int pt_type)
Definition: nurb_util.c:77
void rt_nurb_map_oslo(struct oslo_mat *oslo, fastf_t *old_pts, fastf_t *new_pts, int o_stride, int n_stride, int lower, int upper, int pt_type)
Definition: oslo_map.c:45
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
Header file for the BRL-CAD common definitions.
void * bu_malloc(size_t siz, const char *str)
Definition: malloc.c:314
void rt_nurb_free_oslo(struct oslo_mat *om, struct resource *res)
Definition: oslo_calc.c:214
void rt_nurb_kvcopy(struct knot_vector *new_kv, register const struct knot_vector *old_kv, struct resource *res)
Definition: nurb_knot.c:227
double fastf_t
Definition: defines.h:300
struct edge_g_cnurb * rt_nurb_c_refine(const struct edge_g_cnurb *crv, struct knot_vector *kv)
Definition: nurb_refine.c:145
struct oslo_mat * rt_nurb_calc_oslo(register int order, register const struct knot_vector *tau_kv, register struct knot_vector *t_kv, struct resource *res)
Definition: oslo_calc.c:51