Merge branch 'gallium-0.1' into gallium-0.2
[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 */
35 /*
36 */
37
38 #ifndef _GRIDWRAP_H
39 #define _GRIDWRAP_H
40
41 #include <stdio.h>
42 #include "definitions.h"
43
44 #include "primitiveStream.h"
45 #include "zlassert.h"
46
47 class gridWrap{
48 Int n_ulines;
49 Int n_vlines;
50 Real u_min, u_max;
51 Real v_min, v_max;
52
53 /*cache the coordinate values for efficiency.
54 *these are redundant information when
55 *the grid is uniform.
56 */
57 Real* u_values; /*size is n_ulines*/
58 Real* v_values; /*size is n_vlines*/
59
60 Int is_uniform;
61
62 public:
63 //uniform grid constructor
64 gridWrap(Int nUlines, Int nVlines,
65 Real uMin, Real uMax,
66 Real vMin, Real vMax
67 );
68
69 //nonuniform grid constructor.
70 gridWrap(Int nUlines, Real *uvals,
71 Int nVlines, Real *vvlas
72 );
73 ~gridWrap();
74
75 void print();
76 Int get_n_ulines() {return n_ulines;}
77 Int get_n_vlines() {return n_vlines;}
78 Real get_u_min() {return u_min;}
79 Real get_u_max() {return u_max;}
80 Real get_v_min() {return v_min;}
81 Real get_v_max() {return v_max;}
82
83 Real get_u_value(Int i)
84 {
85 assert(i<n_ulines);
86 /*if(i>=n_ulines){printf("ERROR, n_ulines=%i,i=%i\n",n_ulines,i);exit(0);}*/
87 return u_values[i];}
88 Real get_v_value(Int j) {return v_values[j];}
89
90 Real* get_u_values() {return u_values;}
91 Real* get_v_values() {return v_values;}
92
93 void outputFanWithPoint(Int v, Int uleft, Int uright,
94 Real vert[2], primStream* pStream);
95
96 void draw();
97
98 Int isUniform() {return is_uniform;}
99 };
100
101 class gridBoundaryChain{
102 gridWrap* grid;
103 Int firstVlineIndex;
104 Int nVlines;
105 Int* ulineIndices; /*each v line has a boundary*/
106 Int* innerIndices; /*the segment of the vertical gridline from */
107 /*(innerIndices[i], i) to (innerIndices[i+1], i-1) */
108 /*is inside the polygon: i=1,...,nVlines-1*/
109
110 Real2* vertices; /*one grid point at each grid V-line, cached for efficiency*/
111
112 public:
113 gridBoundaryChain(gridWrap* gr, Int first_vline_index, Int n_vlines, Int* uline_indices, Int* inner_indices);
114
115 ~gridBoundaryChain()
116 {
117 free(innerIndices);
118 free(ulineIndices);
119 free(vertices);
120 }
121
122 /*i indexes the vlines in this chain.
123 */
124 Int getVlineIndex(Int i) {return firstVlineIndex-i;}
125 Int getUlineIndex(Int i) {return ulineIndices[i];}
126 Real get_u_value(Int i) {return vertices[i][0];}
127 Real get_v_value(Int i) {return vertices[i][1];}
128 Int get_nVlines() {return nVlines;}
129 Int getInnerIndex(Int i) {return innerIndices[i];}
130 Real getInner_u_value(Int i) {return grid->get_u_value(innerIndices[i]);}
131
132 Real* get_vertex(Int i) {return vertices[i];}
133 gridWrap* getGrid() {return grid;}
134 void leftEndFan(Int i, primStream* pStream);
135 void rightEndFan(Int i, primStream* pStream);
136
137 Int lookfor(Real v, Int i1, Int i2); //find i in [i1,i2] so that vertices[i][1]>= v > vertices[i+1][1]
138 void draw();
139 void drawInner();
140 };
141
142 #endif