Update to SGI FreeB 2.0.
[mesa.git] / src / glu / sgi / libnurbs / nurbtess / gridWrap.h
1 /*
2 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice including the dates of first publication and
13 * either this permission notice or a reference to
14 * http://oss.sgi.com/projects/FreeB/
15 * shall be included in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 *
25 * Except as contained in this notice, the name of Silicon Graphics, Inc.
26 * shall not be used in advertising or otherwise to promote the sale, use or
27 * other dealings in this Software without prior written authorization from
28 * Silicon Graphics, Inc.
29 */
30 /*
31 ** $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 $
32 */
33
34 #ifndef _GRIDWRAP_H
35 #define _GRIDWRAP_H
36
37 #include <stdio.h>
38 #include "definitions.h"
39
40 #include "primitiveStream.h"
41 #include "zlassert.h"
42
43 class gridWrap{
44 Int n_ulines;
45 Int n_vlines;
46 Real u_min, u_max;
47 Real v_min, v_max;
48
49 /*cache the coordinate values for efficiency.
50 *these are redundant information when
51 *the grid is uniform.
52 */
53 Real* u_values; /*size is n_ulines*/
54 Real* v_values; /*size is n_vlines*/
55
56 Int is_uniform;
57
58 public:
59 //uniform grid constructor
60 gridWrap(Int nUlines, Int nVlines,
61 Real uMin, Real uMax,
62 Real vMin, Real vMax
63 );
64
65 //nonuniform grid constructor.
66 gridWrap(Int nUlines, Real *uvals,
67 Int nVlines, Real *vvlas
68 );
69 ~gridWrap();
70
71 void print();
72 Int get_n_ulines() {return n_ulines;}
73 Int get_n_vlines() {return n_vlines;}
74 Real get_u_min() {return u_min;}
75 Real get_u_max() {return u_max;}
76 Real get_v_min() {return v_min;}
77 Real get_v_max() {return v_max;}
78
79 Real get_u_value(Int i)
80 {
81 assert(i<n_ulines);
82 /*if(i>=n_ulines){printf("ERROR, n_ulines=%i,i=%i\n",n_ulines,i);exit(0);}*/
83 return u_values[i];}
84 Real get_v_value(Int j) {return v_values[j];}
85
86 Real* get_u_values() {return u_values;}
87 Real* get_v_values() {return v_values;}
88
89 void outputFanWithPoint(Int v, Int uleft, Int uright,
90 Real vert[2], primStream* pStream);
91
92 void draw();
93
94 Int isUniform() {return is_uniform;}
95 };
96
97 class gridBoundaryChain{
98 gridWrap* grid;
99 Int firstVlineIndex;
100 Int nVlines;
101 Int* ulineIndices; /*each v line has a boundary*/
102 Int* innerIndices; /*the segment of the vertical gridline from */
103 /*(innerIndices[i], i) to (innerIndices[i+1], i-1) */
104 /*is inside the polygon: i=1,...,nVlines-1*/
105
106 Real2* vertices; /*one grid point at each grid V-line, cached for efficiency*/
107
108 public:
109 gridBoundaryChain(gridWrap* gr, Int first_vline_index, Int n_vlines, Int* uline_indices, Int* inner_indices);
110
111 ~gridBoundaryChain()
112 {
113 free(innerIndices);
114 free(ulineIndices);
115 free(vertices);
116 }
117
118 /*i indexes the vlines in this chain.
119 */
120 Int getVlineIndex(Int i) {return firstVlineIndex-i;}
121 Int getUlineIndex(Int i) {return ulineIndices[i];}
122 Real get_u_value(Int i) {return vertices[i][0];}
123 Real get_v_value(Int i) {return vertices[i][1];}
124 Int get_nVlines() {return nVlines;}
125 Int getInnerIndex(Int i) {return innerIndices[i];}
126 Real getInner_u_value(Int i) {return grid->get_u_value(innerIndices[i]);}
127
128 Real* get_vertex(Int i) {return vertices[i];}
129 gridWrap* getGrid() {return grid;}
130 void leftEndFan(Int i, primStream* pStream);
131 void rightEndFan(Int i, primStream* pStream);
132
133 Int lookfor(Real v, Int i1, Int i2); //find i in [i1,i2] so that vertices[i][1]>= v > vertices[i+1][1]
134 void draw();
135 void drawInner();
136 };
137
138 #endif