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:
10 ** http://oss.sgi.com/projects/FreeB
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.
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.
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.
38 * $Date: 2001/03/17 00:25:41 $ $Revision: 1.1 $
39 * $Header: /home/krh/git/sync/mesa-cvs-repo/Mesa/src/glu/sgi/libnurbs/internals/mapdescv.cc,v 1.1 2001/03/17 00:25:41 brianp Exp $
42 #include "glimports.h"
47 #include "nurbsconsts.h"
50 /*--------------------------------------------------------------------------
51 * calcPartialVelocity - calculate maximum magnitude of a given partial
53 *--------------------------------------------------------------------------
56 Mapdesc::calcPartialVelocity (
63 REAL tmp
[MAXORDER
][MAXCOORDS
];
66 assert( ncols
<= MAXORDER
);
69 // copy inhomogeneous control points into temporary array
70 for( j
=0; j
!= ncols
; j
++ )
71 for( k
=0; k
!= inhcoords
; k
++ )
72 tmp
[j
][k
] = p
[j
*stride
+ k
];
74 for( t
=0; t
!= partial
; t
++ )
75 for( j
=0; j
!= ncols
-t
-1; j
++ )
76 for( k
=0; k
!= inhcoords
; k
++ )
77 tmp
[j
][k
] = tmp
[j
+1][k
] - tmp
[j
][k
];
79 // compute magnitude and store in mag array
80 for( j
=0; j
!= ncols
-partial
; j
++ ) {
82 for( k
=0; k
!= inhcoords
; k
++ )
83 mag
[j
] += tmp
[j
][k
] * tmp
[j
][k
];
86 // compute scale factor
88 REAL invt
= 1.0 / range
;
89 for( t
= ncols
-1; t
!= ncols
-1-partial
; t
-- )
92 // compute max magnitude of all entries in array
94 for( j
=0; j
!= ncols
-partial
; j
++ )
95 if( mag
[j
] > max
) max
= mag
[j
];
96 max
= fac
* ::sqrtf( (float) max
);
101 /*--------------------------------------------------------------------------
102 * calcPartialVelocity - calculate maximum magnitude of a given partial
104 *--------------------------------------------------------------------------
107 Mapdesc::calcPartialVelocity (
120 REAL tmp
[MAXORDER
][MAXORDER
][MAXCOORDS
];
121 REAL mag
[MAXORDER
][MAXORDER
];
123 assert( nrows
<= MAXORDER
);
124 assert( ncols
<= MAXORDER
);
126 REAL
*tp
= &tmp
[0][0][0];
127 REAL
*mp
= &mag
[0][0];
128 const int istride
= sizeof( tmp
[0]) / sizeof( tmp
[0][0][0] );
129 const int jstride
= sizeof( tmp
[0][0]) / sizeof( tmp
[0][0][0] );
130 const int kstride
= sizeof( tmp
[0][0][0]) / sizeof( tmp
[0][0][0] );
131 const int mistride
= sizeof( mag
[0]) / sizeof( mag
[0][0] );
132 const int mjstride
= sizeof( mag
[0][0]) / sizeof( mag
[0][0] );
133 const int idist
= nrows
* istride
;
134 const int jdist
= ncols
* jstride
;
135 const int kdist
= inhcoords
* kstride
;
136 const int id
= idist
- spartial
* istride
;
137 const int jd
= jdist
- tpartial
* jstride
;
140 // copy control points
143 REAL
*til
= tp
+ idist
;
144 for( ; ti
!= til
; ) {
147 REAL
*tjl
= ti
+ jdist
;
148 for( ; tj
!= tjl
; ) {
149 for( int k
=0; k
!= inhcoords
; k
++ ) {
161 // compute (s)-partial derivative control points
162 REAL
*til
= tp
+ idist
- istride
;
163 const REAL
*till
= til
- ( spartial
* istride
);
164 for( ; til
!= till
; til
-= istride
)
165 for( REAL
*ti
= tp
; ti
!= til
; ti
+= istride
)
166 for( REAL
*tj
= ti
, *tjl
= tj
+ jdist
; tj
!= tjl
; tj
+= jstride
)
167 for( int k
=0; k
!= inhcoords
; k
++ )
168 tj
[k
] = tj
[k
+istride
] - tj
[k
];
172 // compute (s,t)-partial derivative control points
173 REAL
*tjl
= tp
+ jdist
- jstride
;
174 const REAL
*tjll
= tjl
- ( tpartial
* jstride
);
175 for( ; tjl
!= tjll
; tjl
-= jstride
)
176 for( REAL
*tj
= tp
; tj
!= tjl
; tj
+= jstride
)
177 for( REAL
*ti
= tj
, *til
= ti
+ id
; ti
!= til
; ti
+= istride
)
178 for( int k
=0; k
!= inhcoords
; k
++ )
179 ti
[k
] = ti
[k
+jstride
] - ti
[k
];
185 // compute magnitude and store in mag array
186 memset( (void *) mp
, 0, sizeof( mag
) );
187 for( REAL
*ti
= tp
, *mi
= mp
, *til
= tp
+ id
; ti
!= til
; ti
+= istride
, mi
+= mistride
)
188 for( REAL
*tj
= ti
, *mj
= mi
, *tjl
= ti
+ jd
; tj
!= tjl
; tj
+= jstride
, mj
+= mjstride
) {
189 for( int k
=0; k
!= inhcoords
; k
++ )
190 *mj
+= tj
[k
] * tj
[k
];
191 if( *mj
> max
) max
= *mj
;
198 // compute scale factor
201 REAL invs
= 1.0 / srange
;
202 REAL invt
= 1.0 / trange
;
203 for( int s
= nrows
-1, slast
= s
-spartial
; s
!= slast
; s
-- )
205 for( int t
= ncols
-1, tlast
= t
-tpartial
; t
!= tlast
; t
-- )
210 // compute max magnitude of first and last column
213 for( i
=0; i
!= nrows
-spartial
; i
++ ) {
215 if( mag
[i
][j
] > dist
[0] ) dist
[0] = mag
[i
][j
];
217 j
= ncols
-tpartial
-1;
218 if( mag
[i
][j
] > dist
[1] ) dist
[1] = mag
[i
][j
];
220 dist
[0] = fac
* ::sqrtf( dist
[0] );
221 dist
[1] = fac
* ::sqrtf( dist
[1] );
222 } else if( side
== 1 ) {
223 // compute max magnitude of first and last row
226 for( j
=0; j
!= ncols
-tpartial
; j
++ ) {
228 if( mag
[i
][j
] > dist
[0] ) dist
[0] = mag
[i
][j
];
230 i
= nrows
-spartial
-1;
231 if( mag
[i
][j
] > dist
[1] ) dist
[1] = mag
[i
][j
];
233 dist
[0] = fac
* ::sqrtf( dist
[0] );
234 dist
[1] = fac
* ::sqrtf( dist
[1] );
237 max
= fac
* ::sqrtf( (float) max
);