Debian Codegraph @

debian/external_deps/fetk/sg/src/glu/nurbs.h

raw
1 /* $Id: nurbs.h,v 1.2 2000/11/02 00:28:54 mholst Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 2.0
6 * Copyright (C) 1995-1996 Brian Paul
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the Free
20 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 /*
24 * NURBS implementation written by Bogdan Sikorski ([email protected])
25 * See README2 for more info.
26 */
27
28
29 #include <stdlib.h>
30 #include "gluP.h"
31
32 #define EPSILON 1e-06 /* epsilon for double precision compares */
33
34 typedef enum
35 {
36 GLU_NURBS_CURVE, GLU_NURBS_SURFACE, GLU_NURBS_TRIM, GLU_NURBS_NO_TRIM,
37 GLU_NURBS_TRIM_DONE, GLU_NURBS_NONE
38 } GLU_nurbs_enum;
39
40 typedef enum
41 {
42 GLU_TRIM_NURBS, GLU_TRIM_PWL
43 } GLU_trim_enum;
44
45 typedef struct
46 {
47 GLint sknot_count;
48 GLfloat *sknot;
49 GLint tknot_count;
50 GLfloat *tknot;
51 GLint s_stride;
52 GLint t_stride;
53 GLfloat *ctrlarray;
54 GLint sorder;
55 GLint torder;
56 GLint dim;
57 GLenum type;
58 } surface_attribs;
59
60 typedef struct
61 {
62 surface_attribs geom;
63 surface_attribs color;
64 surface_attribs texture;
65 surface_attribs normal;
66 } nurbs_surface;
67
68 typedef struct
69 {
70 GLint knot_count;
71 GLfloat *knot;
72 GLint stride;
73 GLfloat *ctrlarray;
74 GLint order;
75 GLint dim;
76 GLenum type;
77 } curve_attribs;
78
79 typedef struct
80 {
81 GLint pt_count;
82 GLfloat *ctrlarray;
83 GLint stride;
84 GLint dim;
85 GLenum type;
86 } pwl_curve_attribs;
87
88 typedef struct
89 {
90 curve_attribs geom;
91 curve_attribs color;
92 curve_attribs texture;
93 curve_attribs normal;
94 } nurbs_curve;
95
96 typedef struct trim_list_str
97 {
98 GLU_trim_enum trim_type;
99 union
100 {
101 pwl_curve_attribs pwl_curve;
102 curve_attribs nurbs_curve;
103 } curve;
104 struct trim_list_str *next;
105 } trim_list;
106
107 typedef struct seg_trim_str
108 {
109 GLfloat *points;
110 GLint pt_cnt,seg_array_len;
111 struct seg_trim_str *next;
112 } trim_segments;
113
114 typedef struct nurbs_trim_str
115 {
116 trim_list *trim_loop;
117 trim_segments *segments;
118 struct nurbs_trim_str *next;
119 } nurbs_trim;
120
121 typedef struct
122 {
123 GLfloat model[16],proj[16],viewport[4];
124 } culling_and_sampling_str;
125
126 struct GLUnurbsObj {
127 GLboolean culling;
128 GLenum error;
129 void (*error_callback)( GLenum err );
130 GLenum display_mode;
131 GLU_nurbs_enum nurbs_type;
132 GLboolean auto_load_matrix;
133 culling_and_sampling_str
134 sampling_matrices;
135 GLfloat sampling_tolerance;
136 nurbs_surface surface;
137 nurbs_curve curve;
138 nurbs_trim *trim;
139 };
140
141 typedef struct
142 {
143 GLfloat *knot;
144 GLint nknots;
145 GLfloat *unified_knot;
146 GLint unified_nknots;
147 GLint order;
148 GLint t_min,t_max;
149 GLint delta_nknots;
150 GLboolean open_at_begin,open_at_end;
151 GLfloat *new_knot;
152 GLfloat *alpha;
153 } knot_str_type;
154
155 typedef struct
156 {
157 GLfloat *geom_ctrl;
158 GLint geom_s_stride,geom_t_stride;
159 GLfloat **geom_offsets;
160 GLint geom_s_pt_cnt,geom_t_pt_cnt;
161 GLfloat *color_ctrl;
162 GLint color_s_stride,color_t_stride;
163 GLfloat **color_offsets;
164 GLint color_s_pt_cnt,color_t_pt_cnt;
165 GLfloat *normal_ctrl;
166 GLint normal_s_stride,normal_t_stride;
167 GLfloat **normal_offsets;
168 GLint normal_s_pt_cnt,normal_t_pt_cnt;
169 GLfloat *texture_ctrl;
170 GLint texture_s_stride,texture_t_stride;
171 GLfloat **texture_offsets;
172 GLint texture_s_pt_cnt,texture_t_pt_cnt;
173 GLint s_bezier_cnt,t_bezier_cnt;
174 } new_ctrl_type;
175
176 void call_user_error( GLUnurbsObj *nobj, GLenum error );
177
178 GLenum test_knot(GLint nknots, GLfloat *knot, GLint order);
179
180 GLenum explode_knot(knot_str_type *the_knot);
181
182 GLenum calc_alphas(knot_str_type *the_knot);
183
184 GLenum calc_new_ctrl_pts(GLfloat *ctrl,GLint stride,knot_str_type *the_knot,
185 GLint dim,GLfloat **new_ctrl,GLint *ncontrol);
186
187 GLenum glu_do_sampling_2D(GLUnurbsObj *nobj, GLfloat *new_ctrl,GLint n_ctrl,
188 GLint order,GLint dim,GLint **factors);
189
190 GLenum glu_do_sampling_3D(GLUnurbsObj *nobj, new_ctrl_type *new_ctrl,
191 int **sfactors, GLint **tfactors);
192
193 GLboolean fine_culling_test_2D(GLUnurbsObj *nobj, GLfloat *ctrl, GLint n_ctrl,
194 GLint stride, GLint dim);
195
196 GLboolean fine_culling_test_3D(GLUnurbsObj *nobj, GLfloat *ctrl,
197 GLint s_n_ctrl, GLint t_n_ctrl, GLint s_stride, GLint t_stride, GLint dim);
198
199 void do_nurbs_curve( GLUnurbsObj *nobj);
200
201 void do_nurbs_surface( GLUnurbsObj *nobj);
202
203 GLenum patch_trimming(GLUnurbsObj *nobj,new_ctrl_type *new_ctrl,
204 GLint *sfactors, GLint *tfactors);
205
206 void collect_unified_knot(knot_str_type *dest, knot_str_type *src,
207 GLfloat maximal_min_knot, GLfloat minimal_max_knot);
208
209 GLenum select_knot_working_range(GLUnurbsObj *nobj,knot_str_type *geom_knot,
210 knot_str_type *color_knot, knot_str_type *normal_knot,
211 knot_str_type *texture_knot);
212
213 void free_unified_knots(knot_str_type *geom_knot, knot_str_type *color_knot,
214 knot_str_type *normal_knot, knot_str_type *texture_knot);
215