silence a bunch of compiler warnings
[mesa.git] / src / glu / sgi / libnurbs / nurbtess / sampleComp.cc
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: 2005/10/28 13:09:23 $ $Revision: 1.2 $
35 */
36 /*
37 ** $Header: /home/krh/git/sync/mesa-cvs-repo/Mesa/src/glu/sgi/libnurbs/nurbtess/sampleComp.cc,v 1.2 2005/10/28 13:09:23 brianp Exp $
38 */
39
40 #include <stdlib.h>
41 #include <stdio.h>
42 #include "glimports.h"
43 #include "sampleComp.h"
44 #include "sampleCompTop.h"
45 #include "sampleCompBot.h"
46 #include "sampleCompRight.h"
47
48
49
50 #define max(a,b) ((a>b)? a:b)
51 #define min(a,b) ((a>b)? b:a)
52
53 void sampleConnectedComp(Real* topVertex, Real* botVertex,
54 vertexArray* leftChain,
55 Int leftStartIndex, Int leftEndIndex,
56 vertexArray* rightChain,
57 Int rightStartIndex, Int rightEndIndex,
58 gridBoundaryChain* leftGridChain,
59 gridBoundaryChain* rightGridChain,
60 Int gridIndex1, Int gridIndex2,
61 Int up_leftCornerWhere,
62 Int up_leftCornerIndex,
63 Int up_rightCornerWhere,
64 Int up_rightCornerIndex,
65 Int down_leftCornerWhere,
66 Int down_leftCornerIndex,
67 Int down_rightCornerWhere,
68 Int down_rightCornerIndex,
69 primStream* pStream,
70 rectBlockArray* rbArray
71 )
72 {
73
74 sampleCompLeft(topVertex, botVertex,
75 leftChain,
76 leftStartIndex, leftEndIndex,
77 rightChain,
78 rightStartIndex, rightEndIndex,
79 leftGridChain,
80 gridIndex1,
81 gridIndex2,
82 up_leftCornerWhere,
83 up_leftCornerIndex,
84 down_leftCornerWhere,
85 down_leftCornerIndex,
86 pStream);
87
88
89 sampleCompRight(topVertex, botVertex,
90 leftChain,
91 leftStartIndex, leftEndIndex,
92 rightChain,
93 rightStartIndex,
94 rightEndIndex,
95 rightGridChain,
96 gridIndex1, gridIndex2,
97 up_rightCornerWhere,
98 up_rightCornerIndex,
99 down_rightCornerWhere,
100 down_rightCornerIndex,
101 pStream);
102
103
104 sampleCompTop(topVertex,
105 leftChain,
106 leftStartIndex,
107 rightChain,
108 rightStartIndex,
109 leftGridChain,
110 rightGridChain,
111 gridIndex1,
112 up_leftCornerWhere,
113 up_leftCornerIndex,
114 up_rightCornerWhere,
115 up_rightCornerIndex,
116 pStream);
117
118 sampleCompBot(botVertex,
119 leftChain,
120 leftEndIndex,
121 rightChain,
122 rightEndIndex,
123 leftGridChain,
124 rightGridChain,
125 gridIndex2,
126 down_leftCornerWhere,
127 down_leftCornerIndex,
128 down_rightCornerWhere,
129 down_rightCornerIndex,
130 pStream);
131
132
133 //the center
134
135 rbArray->insert(new rectBlock(leftGridChain, rightGridChain, gridIndex1, gridIndex2));
136
137
138 }
139
140 /*notice that we need rightChain because the
141 *corners could be on the rightChain.
142 *here comp means component.
143 */
144 void sampleCompLeft(Real* topVertex, Real* botVertex,
145 vertexArray* leftChain,
146 Int leftStartIndex, Int leftEndIndex,
147 vertexArray* rightChain,
148 Int rightStartIndex, Int rightEndIndex,
149 gridBoundaryChain* leftGridChain,
150 Int gridIndex1, Int gridIndex2,
151 Int up_leftCornerWhere,
152 Int up_leftCornerIndex,
153 Int down_leftCornerWhere,
154 Int down_leftCornerIndex,
155 primStream* pStream)
156 {
157 /*find out whether there is a trim vertex which is
158 *inbetween the top and bot grid lines or not.
159 */
160 Int midIndex1;
161 Int midIndex2;
162 Int gridMidIndex1 = 0, gridMidIndex2 = 0;
163 //midIndex1: array[i] <= v, array[i-1] > v
164 //midIndex2: array[i] >= v, array[i+1] < v
165 // v(gridMidIndex1) >= v(midindex1) > v(gridMidIndex1+1)
166 // v(gridMidIndex2-1) >= v(midIndex2) > v(gridMidIndex2) ??
167 midIndex1 = leftChain->findIndexBelowGen(
168 leftGridChain->get_v_value(gridIndex1),
169 leftStartIndex,
170 leftEndIndex);
171
172 midIndex2 = -1; /*initilization*/
173 if(midIndex1<= leftEndIndex && gridIndex1<gridIndex2)
174 if(leftChain->getVertex(midIndex1)[1] >= leftGridChain->get_v_value(gridIndex2))
175 {
176 midIndex2 = leftChain->findIndexAboveGen(
177 leftGridChain->get_v_value(gridIndex2),
178 midIndex1, //midIndex1 <= midIndex2.
179 leftEndIndex);
180 gridMidIndex1 = leftGridChain->lookfor(leftChain->getVertex(midIndex1)[1],
181 gridIndex1, gridIndex2);
182 gridMidIndex2 = 1+leftGridChain->lookfor(leftChain->getVertex(midIndex2)[1],
183 gridMidIndex1, gridIndex2);
184 }
185
186
187 /*to interprete the corner information*/
188 Real* cornerTop;
189 Real* cornerBot;
190 Int cornerLeftStart;
191 Int cornerLeftEnd;
192 Int cornerRightUpEnd;
193 Int cornerRightDownStart;
194 if(up_leftCornerWhere == 0) /*left corner is on left chain*/
195 {
196 cornerTop = leftChain->getVertex(up_leftCornerIndex);
197 cornerLeftStart = up_leftCornerIndex+1;
198 cornerRightUpEnd = -1; /*no right*/
199 }
200 else if(up_leftCornerWhere == 1) /*left corner is on top*/
201 {
202 cornerTop = topVertex;
203 cornerLeftStart = leftStartIndex;
204 cornerRightUpEnd = -1; /*no right*/
205 }
206 else /*left corner is on right chain*/
207 {
208 cornerTop = topVertex;
209 cornerLeftStart = leftStartIndex;
210 cornerRightUpEnd = up_leftCornerIndex;
211 }
212
213 if(down_leftCornerWhere == 0) /*left corner is on left chain*/
214 {
215 cornerBot = leftChain->getVertex(down_leftCornerIndex);
216 cornerLeftEnd = down_leftCornerIndex-1;
217 cornerRightDownStart = rightEndIndex+1; /*no right*/
218 }
219 else if(down_leftCornerWhere == 1) /*left corner is on bot*/
220 {
221 cornerBot = botVertex;
222 cornerLeftEnd = leftEndIndex;
223 cornerRightDownStart = rightEndIndex+1; /*no right*/
224 }
225 else /*left corner is on the right chian*/
226 {
227 cornerBot = botVertex;
228 cornerLeftEnd = leftEndIndex;
229 cornerRightDownStart = down_leftCornerIndex;
230 }
231
232
233
234
235 /*sample*/
236 if(midIndex2 >= 0) /*there is a trim point inbewteen grid lines*/
237 {
238
239 sampleLeftSingleTrimEdgeRegionGen(cornerTop, leftChain->getVertex(midIndex1),
240 leftChain,
241 cornerLeftStart,
242 midIndex1-1,
243 leftGridChain,
244 gridIndex1,
245 gridMidIndex1,
246 rightChain,
247 rightStartIndex,
248 cornerRightUpEnd,
249 0, //no right down section
250 -1,
251 pStream);
252
253 sampleLeftSingleTrimEdgeRegionGen(leftChain->getVertex(midIndex2),
254 cornerBot,
255 leftChain,
256 midIndex2+1,
257 cornerLeftEnd,
258 leftGridChain,
259 gridMidIndex2,
260 gridIndex2,
261 rightChain,
262 0, //no right up section
263 -1,
264 cornerRightDownStart,
265 rightEndIndex,
266 pStream);
267
268
269 sampleLeftStripRecF(leftChain,
270 midIndex1,
271 midIndex2,
272 leftGridChain,
273 gridMidIndex1,
274 gridMidIndex2,
275 pStream);
276 }
277 else
278 {
279 sampleLeftSingleTrimEdgeRegionGen(cornerTop, cornerBot,
280 leftChain,
281 cornerLeftStart,
282 cornerLeftEnd,
283 leftGridChain,
284 gridIndex1,
285 gridIndex2,
286 rightChain,
287 rightStartIndex,
288 cornerRightUpEnd,
289 cornerRightDownStart,
290 rightEndIndex,
291 pStream);
292 }
293 }
294
295 void sampleLeftSingleTrimEdgeRegionGen(Real topVert[2], Real botVert[2],
296 vertexArray* leftChain,
297 Int leftStart,
298 Int leftEnd,
299 gridBoundaryChain* gridChain,
300 Int gridBeginIndex,
301 Int gridEndIndex,
302 vertexArray* rightChain,
303 Int rightUpBegin,
304 Int rightUpEnd,
305 Int rightDownBegin,
306 Int rightDownEnd,
307 primStream* pStream)
308 {
309 Int i,j,k;
310
311 /*creat an array to store all the up and down secments of the right chain,
312 *and the left end grid points
313 *
314 *although vertex array is a dynamic array, but to gain efficiency,
315 *it is better to initiliza the exact array size
316 */
317 vertexArray vArray(gridEndIndex-gridBeginIndex+1 +
318 max(0,rightUpEnd - rightUpBegin+1)+
319 max(0,rightDownEnd - rightDownBegin+1));
320
321 /*append the vertices on the up section of thr right chain*/
322 for(i=rightUpBegin; i<= rightUpEnd; i++)
323 vArray.appendVertex(rightChain->getVertex(i));
324
325 /*append the vertices of the left extremal grid points,
326 *and at the same time, perform triangulation for the stair cases
327 */
328 vArray.appendVertex(gridChain->get_vertex(gridBeginIndex));
329
330 for(k=1, i=gridBeginIndex+1; i<=gridEndIndex; i++, k++)
331 {
332 vArray.appendVertex(gridChain->get_vertex(i));
333
334 /*output the fan of the grid points of the (i)th and (i-1)th grid line.
335 */
336 if(gridChain->getUlineIndex(i) < gridChain->getUlineIndex(i-1))
337 {
338 pStream->begin();
339 pStream->insert(gridChain->get_vertex(i-1));
340 for(j=gridChain->getUlineIndex(i); j<= gridChain->getUlineIndex(i-1); j++)
341 pStream->insert(gridChain->getGrid()->get_u_value(j), gridChain->get_v_value(i));
342 pStream->end(PRIMITIVE_STREAM_FAN);
343 }
344 else if(gridChain->getUlineIndex(i) > gridChain->getUlineIndex(i-1))
345 {
346 pStream->begin();
347 pStream->insert(gridChain->get_vertex(i));
348 for(j=gridChain->getUlineIndex(i); j>= gridChain->getUlineIndex(i-1); j--)
349 pStream->insert(gridChain->getGrid()->get_u_value(j), gridChain->get_v_value(i-1));
350 pStream->end(PRIMITIVE_STREAM_FAN);
351 }
352 /*otherwisem, the two are equal, so there is no fan to outout*/
353 }
354
355 /*then append all the vertices on the down section of the right chain*/
356 for(i=rightDownBegin; i<= rightDownEnd; i++)
357 vArray.appendVertex(rightChain->getVertex(i));
358
359 monoTriangulationRecGen(topVert, botVert,
360 leftChain, leftStart, leftEnd,
361 &vArray, 0, vArray.getNumElements()-1,
362 pStream);
363
364 }
365
366
367
368
369
370
371
372
373