1c8237fe27a05a8b41f0e2508aa99ed4f173f2a3
[mesa.git] / src / glu / sgi / libnurbs / nurbtess / gridWrap.h
1 /*
2 ** License Applicability. Except to the extent portions of this file are
3 ** made subject to an alternative license as permitted in the SGI Free
4 ** Software License B, Version 1.1 (the "License"), the contents of this
5 ** file are subject only to the provisions of the License. You may not use
6 ** this file except in compliance with the License. You may obtain a copy
7 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
8 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
9 **
10 ** http://oss.sgi.com/projects/FreeB
11 **
12 ** Note that, as provided in the License, the Software is distributed on an
13 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
14 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
15 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
16 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
17 **
18 ** Original Code. The Original Code is: OpenGL Sample Implementation,
19 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
20 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
21 ** Copyright in any portions created by third parties is as indicated
22 ** elsewhere herein. All Rights Reserved.
23 **
24 ** Additional Notice Provisions: The application programming interfaces
25 ** established by SGI in conjunction with the Original Code are The
26 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
27 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
28 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
29 ** Window System(R) (Version 1.3), released October 19, 1998. This software
30 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
31 ** published by SGI, but has not been independently verified as being
32 ** compliant with the OpenGL(R) version 1.2.1 Specification.
33 **
34 ** $Date: 2001/03/17 00:25:41 $ $Revision: 1.1 $
35 */
36 /*
37 ** $Header: /home/krh/git/sync/mesa-cvs-repo/Mesa/src/glu/sgi/libnurbs/nurbtess/gridWrap.h,v 1.1 2001/03/17 00:25:41 brianp Exp $
38 */
39
40 #ifndef _GRIDWRAP_H
41 #define _GRIDWRAP_H
42
43 #include <stdio.h>
44 #include "definitions.h"
45
46 #include "primitiveStream.h"
47 #include "zlassert.h"
48
49 class gridWrap{
50 Int n_ulines;
51 Int n_vlines;
52 Real u_min, u_max;
53 Real v_min, v_max;
54
55 /*cache the coordinate values for efficiency.
56 *these are redundant information when
57 *the grid is uniform.
58 */
59 Real* u_values; /*size is n_ulines*/
60 Real* v_values; /*size is n_vlines*/
61
62 Int is_uniform;
63
64 public:
65 //uniform grid constructor
66 gridWrap(Int nUlines, Int nVlines,
67 Real uMin, Real uMax,
68 Real vMin, Real vMax
69 );
70
71 //nonuniform grid constructor.
72 gridWrap(Int nUlines, Real *uvals,
73 Int nVlines, Real *vvlas
74 );
75 ~gridWrap();
76
77 void print();
78 Int get_n_ulines() {return n_ulines;}
79 Int get_n_vlines() {return n_vlines;}
80 Real get_u_min() {return u_min;}
81 Real get_u_max() {return u_max;}
82 Real get_v_min() {return v_min;}
83 Real get_v_max() {return v_max;}
84
85 Real get_u_value(Int i)
86 {
87 assert(i<n_ulines);
88 /*if(i>=n_ulines){printf("ERROR, n_ulines=%i,i=%i\n",n_ulines,i);exit(0);}*/
89 return u_values[i];}
90 Real get_v_value(Int j) {return v_values[j];}
91
92 Real* get_u_values() {return u_values;}
93 Real* get_v_values() {return v_values;}
94
95 void outputFanWithPoint(Int v, Int uleft, Int uright,
96 Real vert[2], primStream* pStream);
97
98 void draw();
99
100 Int isUniform() {return is_uniform;}
101 };
102
103 class gridBoundaryChain{
104 gridWrap* grid;
105 Int firstVlineIndex;
106 Int nVlines;
107 Int* ulineIndices; /*each v line has a boundary*/
108 Int* innerIndices; /*the segment of the vertical gridline from */
109 /*(innerIndices[i], i) to (innerIndices[i+1], i-1) */
110 /*is inside the polygon: i=1,...,nVlines-1*/
111
112 Real2* vertices; /*one grid point at each grid V-line, cached for efficiency*/
113
114 public:
115 gridBoundaryChain(gridWrap* gr, Int first_vline_index, Int n_vlines, Int* uline_indices, Int* inner_indices);
116
117 ~gridBoundaryChain()
118 {
119 free(innerIndices);
120 free(ulineIndices);
121 free(vertices);
122 }
123
124 /*i indexes the vlines in this chain.
125 */
126 Int getVlineIndex(Int i) {return firstVlineIndex-i;}
127 Int getUlineIndex(Int i) {return ulineIndices[i];}
128 Real get_u_value(Int i) {return vertices[i][0];}
129 Real get_v_value(Int i) {return vertices[i][1];}
130 Int get_nVlines() {return nVlines;}
131 Int getInnerIndex(Int i) {return innerIndices[i];}
132 Real getInner_u_value(Int i) {return grid->get_u_value(innerIndices[i]);}
133
134 Real* get_vertex(Int i) {return vertices[i];}
135 gridWrap* getGrid() {return grid;}
136 void leftEndFan(Int i, primStream* pStream);
137 void rightEndFan(Int i, primStream* pStream);
138
139 Int lookfor(Real v, Int i1, Int i2); //find i in [i1,i2] so that vertices[i][1]>= v > vertices[i+1][1]
140 void draw();
141 void drawInner();
142 };
143
144 #endif