FreeWRL/FreeX3D  3.0.0
patchlist.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 
35 /*
36  * patchlist.c++
37  *
38  */
39 
40 #include <stdio.h>
41 #include "glimports.h"
42 #include "myassert.h"
43 #include "mystdio.h"
44 #include "quilt.h"
45 #include "patchlist.h"
46 #include "patch.h"
47 #include "nurbsconsts.h"
48 
49 Patchlist::Patchlist( Quilt *quilts, REAL *pta, REAL *ptb )
50 {
51  patch = 0;
52  for( Quilt *q = quilts; q; q = q->next )
53  patch = new Patch( q, pta, ptb, patch );
54  pspec[0].range[0] = pta[0];
55  pspec[0].range[1] = ptb[0];
56  pspec[0].range[2] = ptb[0] - pta[0];
57 
58  pspec[1].range[0] = pta[1];
59  pspec[1].range[1] = ptb[1];
60  pspec[1].range[2] = ptb[1] - pta[1];
61 }
62 
63 Patchlist::Patchlist( Patchlist &upper, int param, REAL value)
64 {
65  Patchlist &lower = *this;
66  patch = 0;
67  for( Patch *p = upper.patch; p; p = p->next )
68  patch = new Patch( *p, param, value, patch );
69 
70  if( param == 0 ) {
71  lower.pspec[0].range[0] = upper.pspec[0].range[0];
72  lower.pspec[0].range[1] = value;
73  lower.pspec[0].range[2] = value - upper.pspec[0].range[0];
74  upper.pspec[0].range[0] = value;
75  upper.pspec[0].range[2] = upper.pspec[0].range[1] - value;
76  lower.pspec[1] = upper.pspec[1];
77  } else {
78  lower.pspec[0] = upper.pspec[0];
79  lower.pspec[1].range[0] = upper.pspec[1].range[0];
80  lower.pspec[1].range[1] = value;
81  lower.pspec[1].range[2] = value - upper.pspec[1].range[0];
82  upper.pspec[1].range[0] = value;
83  upper.pspec[1].range[2] = upper.pspec[1].range[1] - value;
84  }
85 }
86 
87 Patchlist::~Patchlist()
88 {
89  while( patch ) {
90  Patch *p = patch;
91  patch = patch->next;
92  delete p;
93  }
94 }
95 
96 int
97 Patchlist::cullCheck( void )
98 {
99  for( Patch *p = patch; p; p = p->next )
100  if( p->cullCheck() == CULL_TRIVIAL_REJECT )
101  return CULL_TRIVIAL_REJECT;
102  return CULL_ACCEPT;
103 }
104 
105 void
106 Patchlist::getRanges(REAL ranges[4])
107 {
108  ranges[0] = pspec[0].range[0];
109  ranges[1] = pspec[0].range[1];
110  ranges[2] = pspec[1].range[0];
111  ranges[3] = pspec[1].range[1];
112 }
113 
114 void
115 Patchlist::getstepsize( void )
116 {
117  pspec[0].stepsize = pspec[0].range[2];
118  pspec[0].sidestep[0] = pspec[0].range[2];
119  pspec[0].sidestep[1] = pspec[0].range[2];
120 
121  pspec[1].stepsize = pspec[1].range[2];
122  pspec[1].sidestep[0] = pspec[1].range[2];
123  pspec[1].sidestep[1] = pspec[1].range[2];
124 
125  for( Patch *p = patch; p; p = p->next ) {
126  p->getstepsize();
127  p->clamp();
128  pspec[0].stepsize = ((p->pspec[0].stepsize < pspec[0].stepsize) ? p->pspec[0].stepsize : pspec[0].stepsize);
129  pspec[0].sidestep[0] = ((p->pspec[0].sidestep[0] < pspec[0].sidestep[0]) ? p->pspec[0].sidestep[0] : pspec[0].sidestep[0]);
130  pspec[0].sidestep[1] = ((p->pspec[0].sidestep[1] < pspec[0].sidestep[1]) ? p->pspec[0].sidestep[1] : pspec[0].sidestep[1]);
131  pspec[1].stepsize = ((p->pspec[1].stepsize < pspec[1].stepsize) ? p->pspec[1].stepsize : pspec[1].stepsize);
132  pspec[1].sidestep[0] = ((p->pspec[1].sidestep[0] < pspec[1].sidestep[0]) ? p->pspec[1].sidestep[0] : pspec[1].sidestep[0]);
133  pspec[1].sidestep[1] = ((p->pspec[1].sidestep[1] < pspec[1].sidestep[1]) ? p->pspec[1].sidestep[1] : pspec[1].sidestep[1]);
134  }
135 }
136 
137 void
138 Patchlist::bbox( void )
139 {
140  for( Patch *p = patch; p; p = p->next )
141  p->bbox();
142 }
143 
144 int
145 Patchlist::needsNonSamplingSubdivision( void )
146 {
147  notInBbox = 0;
148  for( Patch *p = patch; p; p = p->next )
149  notInBbox |= p->needsNonSamplingSubdivision();
150  return notInBbox;
151 }
152 
153 int
154 Patchlist::needsSamplingSubdivision( void )
155 {
156  pspec[0].needsSubdivision = 0;
157  pspec[1].needsSubdivision = 0;
158 
159  for( Patch *p = patch; p; p = p->next ) {
160  pspec[0].needsSubdivision |= p->pspec[0].needsSubdivision;
161  pspec[1].needsSubdivision |= p->pspec[0].needsSubdivision;
162  }
163  return (pspec[0].needsSubdivision || pspec[1].needsSubdivision) ? 1 : 0;
164 }
165 
166 int
167 Patchlist::needsSubdivision( int param )
168 {
169  return pspec[param].needsSubdivision;
170 }
Definition: quilt.h:64
Definition: patch.h:62