nurb_bound.c
Go to the documentation of this file.
1 /* N U R B _ B O U N D . C
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
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  */
21 /** @{ */
22 /** @file primitives/bspline/nurb_bound.c
23  *
24  * Find the bounding box for the a NURB surface.
25  *
26  * Since a B-Spline surface follows the convex hull property the
27  * bounding box can be found by taking the min and max of all points
28  * in the control If the surface mesh contains homogeneous points
29  * (i.e. [XYZW]) then divide out the W first.
30  *
31  */
32 /** @} */
33
34 #include "common.h"
35
36 #include "bio.h"
37
38 #include "vmath.h"
39 #include "raytrace.h"
40 #include "nurb.h"
41
42
43 /**
44  * Calculates the bounding Right Parallel Piped (RPP) of the NURB
45  * surface, and returns the minimum and maximum points of the surface.
46  */
47 int
48 rt_nurb_s_bound(struct face_g_snurb *srf, fastf_t *bmin, fastf_t *bmax)
49 {
50  register fastf_t *p_ptr; /* Mesh pointer */
51  register int coords; /* Elements per vector */
52  int i;
53  int rat;
54
55  VSETALL(bmin, INFINITY);
56  VSETALL(bmax, -INFINITY);
57
58  if (srf == (struct face_g_snurb *)0) {
59  bu_log("nurb_s_bound: NULL surface\n");
60  return -1; /* BAD */
61  }
62
63  p_ptr = srf->ctl_points;
64  coords = RT_NURB_EXTRACT_COORDS(srf->pt_type);
65  rat = RT_NURB_IS_PT_RATIONAL(srf->pt_type);
66
67  for (i = (srf->s_size[RT_NURB_SPLIT_ROW] *
68  srf->s_size[RT_NURB_SPLIT_COL]); i > 0; i--) {
69  if (!rat) {
70  VMINMAX(bmin, bmax, p_ptr);
71  } else if (rat) {
72  point_t tmp_pt;
73  if (ZERO(p_ptr[H])) {
74  HPRINT("mesh point", p_ptr);
75  bu_log("nurb_s_bound: H too small\n");
76  } else {
77  HDIVIDE(tmp_pt, p_ptr);
78  VMINMAX(bmin, bmax, tmp_pt);
79  }
80  }
81  p_ptr += coords;
82  }
83  return 0; /* OK */
84 }
85
86
87 int
88 rt_nurb_c_bound(struct edge_g_cnurb *crv, fastf_t *bmin, fastf_t *bmax)
89 {
90  register fastf_t *p_ptr; /* Mesh pointer */
91  register int coords; /* Elements per vector */
92  int i;
93  int rat;
94
95  VSETALL(bmin, INFINITY);
96  VSETALL(bmax, -INFINITY);
97
98  if (crv == (struct edge_g_cnurb *)0) {
99  bu_log("nurb_c_bound: NULL surface\n");
100  return -1; /* BAD */
101  }
102
103  p_ptr = crv->ctl_points;
104  coords = RT_NURB_EXTRACT_COORDS(crv->pt_type);
105  rat = RT_NURB_IS_PT_RATIONAL(crv->pt_type);
106
107  for (i = crv->c_size; i > 0; i--) {
108  if (!rat) {
109  VMINMAX(bmin, bmax, p_ptr);
110  } else if (rat) {
111  point_t tmp_pt;
112  if (ZERO(p_ptr[H])) {
113  HPRINT("mesh point", p_ptr);
114  bu_log("nurb_c_bound: H too small\n");
115  } else {
116  HDIVIDE(tmp_pt, p_ptr);
117  VMINMAX(bmin, bmax, tmp_pt);
118  }
119  }
120  p_ptr += coords;
121  }
122  return 0; /* OK */
123 }
124
125
126 /**
127  * rt_nurb_s_check(srf)
128  *
129  * Checks the NURB surface control points to make sure no one point is
130  * near INFINITY, which probably means that the surface mesh is bad.
131  */
132
133 int
134 rt_nurb_s_check(register struct face_g_snurb *srf)
135 {
136  register fastf_t *mp; /* Mesh pointer */
137  register int i;
138
139  mp = srf->ctl_points;
140  i = srf->s_size[RT_NURB_SPLIT_ROW] *
141  srf->s_size[RT_NURB_SPLIT_COL] *
142  srf->pt_type;
143  for (; i > 0; i--, mp++) {
144  /* Sanity checking */
145  if (!NEAR_ZERO(*mp, INFINITY)) {
147  return -1; /* BAD */
148  }
149  }
150  return 0; /* OK */
151 }
152
153
154 /**
155  * rt_nurb_c_check(srf)
156  *
157  * Checks the NURB curve control points to make sure no one point is
158  * near INFINITY, which probably means that the surface mesh is bad.
159  */
160
161 int
162 rt_nurb_c_check(register struct edge_g_cnurb *crv)
163 {
164  register fastf_t *mp; /* Mesh pointer */
165  register int i;
166
167  mp = crv->ctl_points;
168  i = crv->c_size *
169  crv->pt_type;
170  for (; i > 0; i--, mp++) {
171  /* Sanity checking */
172  if (!NEAR_ZERO(*mp, INFINITY)) {
174  return -1; /* BAD */
175  }
176  }
177  return 0; /* OK */
178 }
179
180
181 /*
182  * Local Variables:
183  * mode: C
184  * tab-width: 8
185  * indent-tabs-mode: t
186  * c-file-style: "stroustrup"
187  * End:
188  * ex: shiftwidth=4 tabstop=8
189  */
void bu_log(const char *,...) _BU_ATTR_PRINTF12
Definition: log.c:176
int rt_nurb_s_check(register struct face_g_snurb *srf)
Definition: nurb_bound.c:134
#define VSETALL(a, s)
Definition: color.c:54
#define NEAR_ZERO(val, epsilon)
Definition: color.c:55
int rt_nurb_c_check(register struct edge_g_cnurb *crv)
Definition: nurb_bound.c:162
#define HPRINT(a, b)
Definition: raytrace.h:1882
int rt_nurb_c_bound(struct edge_g_cnurb *crv, fastf_t *bmin, fastf_t *bmax)
Definition: nurb_bound.c:88
#define ZERO(val)
Definition: units.c:38
double fastf_t
Definition: defines.h:300
int rt_nurb_s_bound(struct face_g_snurb *srf, fastf_t *bmin, fastf_t *bmax)
Definition: nurb_bound.c:48