BRL-CAD
nurb_trim_util.c
Go to the documentation of this file.
1 /* N U R B _ T R I M _ U T I L . C
2  * BRL-CAD
3  *
4  * Copyright (c) 1990-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_trim_util.c
23  *
24  * Trimming curve Utilities.
25  *
26  */
27 /** @} */
28 
29 #include "common.h"
30 
31 #include <math.h>
32 #include "bio.h"
33 
34 #include "vmath.h"
35 #include "raytrace.h"
36 #include "nurb.h"
37 
38 /**
39  * Check to see if the curve control polygon wanders outside the
40  * parametric range given. This is useful if a trimming curve
41  * control polygon is outside but the evaluated curve is not. We will
42  * want to refine the curve so that it lies within the range;
43  * otherwise it breaks the surface evaluation.
44  */
45 int
46 rt_nurb_crv_in_range(struct edge_g_cnurb *crv, fastf_t u_min, fastf_t u_max, fastf_t v_min, fastf_t v_max)
47 {
48  point_t eval;
49  fastf_t *pts;
50  int coords = RT_NURB_EXTRACT_COORDS(crv->pt_type);
51  int rat = RT_NURB_IS_PT_RATIONAL(crv->pt_type);
52  int i;
53 
54  pts = &crv->ctl_points[0];
55 
56  for (i = 0; i < crv->c_size; i++) {
57  if (rat) {
58  eval[0] = pts[0] / pts[2];
59  eval[1] = pts[1] / pts[2];
60  eval[2] = 1;
61  } else {
62  eval[0] = pts[0];
63  eval[1] = pts[1];
64  eval[2] = 1;
65  }
66 
67  if (eval[0] < u_min || eval[0] > u_max)
68  return 0;
69 
70  if (eval[1] < v_min || eval[1] > v_max)
71  return 0;
72 
73  pts += coords;
74  }
75  return 1;
76 }
77 
78 
79 /*
80  * Local Variables:
81  * mode: C
82  * tab-width: 8
83  * indent-tabs-mode: t
84  * c-file-style: "stroustrup"
85  * End:
86  * ex: shiftwidth=4 tabstop=8
87  */
int rt_nurb_crv_in_range(struct edge_g_cnurb *crv, fastf_t u_min, fastf_t u_max, fastf_t v_min, fastf_t v_max)
void eval()
Definition: vm_test.cpp:79
Header file for the BRL-CAD common definitions.
double fastf_t
Definition: defines.h:300