| 1 | /* $Id: mapdescv.cpp,v 1.1 2000-02-09 08:50:24 jeroen Exp $ */
|
|---|
| 2 | /*
|
|---|
| 3 | ** License Applicability. Except to the extent portions of this file are
|
|---|
| 4 | ** made subject to an alternative license as permitted in the SGI Free
|
|---|
| 5 | ** Software License B, Version 1.0 (the "License"), the contents of this
|
|---|
| 6 | ** file are subject only to the provisions of the License. You may not use
|
|---|
| 7 | ** this file except in compliance with the License. You may obtain a copy
|
|---|
| 8 | ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
|
|---|
| 9 | ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
|
|---|
| 10 | **
|
|---|
| 11 | ** http://oss.sgi.com/projects/FreeB
|
|---|
| 12 | **
|
|---|
| 13 | ** Note that, as provided in the License, the Software is distributed on an
|
|---|
| 14 | ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
|
|---|
| 15 | ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
|
|---|
| 16 | ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
|
|---|
| 17 | ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
|
|---|
| 18 | **
|
|---|
| 19 | ** Original Code. The Original Code is: OpenGL Sample Implementation,
|
|---|
| 20 | ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
|
|---|
| 21 | ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
|
|---|
| 22 | ** Copyright in any portions created by third parties is as indicated
|
|---|
| 23 | ** elsewhere herein. All Rights Reserved.
|
|---|
| 24 | **
|
|---|
| 25 | ** Additional Notice Provisions: The application programming interfaces
|
|---|
| 26 | ** established by SGI in conjunction with the Original Code are The
|
|---|
| 27 | ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
|
|---|
| 28 | ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
|
|---|
| 29 | ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
|
|---|
| 30 | ** Window System(R) (Version 1.3), released October 19, 1998. This software
|
|---|
| 31 | ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
|
|---|
| 32 | ** published by SGI, but has not been independently verified as being
|
|---|
| 33 | ** compliant with the OpenGL(R) version 1.2.1 Specification.
|
|---|
| 34 | */
|
|---|
| 35 |
|
|---|
| 36 | /*
|
|---|
| 37 | * mapdescv.c++
|
|---|
| 38 | *
|
|---|
| 39 | * $Date: 2000-02-09 08:50:24 $ $Revision: 1.1 $
|
|---|
| 40 | * $Header: /home/ktk/tmp/odin/2007/netlabs.cvs/odin32/src/opengl/glu/nurbs/internals/mapdescv.cpp,v 1.1 2000-02-09 08:50:24 jeroen Exp $
|
|---|
| 41 | */
|
|---|
| 42 |
|
|---|
| 43 | #include "glimports.h"
|
|---|
| 44 | #include "mystdio.h"
|
|---|
| 45 | #include "myassert.h"
|
|---|
| 46 | #include "mystring.h"
|
|---|
| 47 | #include "mymath.h"
|
|---|
| 48 | #include "nurbsconsts.h"
|
|---|
| 49 | #include "mapdesc.h"
|
|---|
| 50 |
|
|---|
| 51 | /*--------------------------------------------------------------------------
|
|---|
| 52 | * calcPartialVelocity - calculate maximum magnitude of a given partial
|
|---|
| 53 | * derivative
|
|---|
| 54 | *--------------------------------------------------------------------------
|
|---|
| 55 | */
|
|---|
| 56 | REAL
|
|---|
| 57 | Mapdesc::calcPartialVelocity (
|
|---|
| 58 | REAL *p,
|
|---|
| 59 | int stride,
|
|---|
| 60 | int ncols,
|
|---|
| 61 | int partial,
|
|---|
| 62 | REAL range )
|
|---|
| 63 | {
|
|---|
| 64 | REAL tmp[MAXORDER][MAXCOORDS];
|
|---|
| 65 | REAL mag[MAXORDER];
|
|---|
| 66 |
|
|---|
| 67 | assert( ncols <= MAXORDER );
|
|---|
| 68 |
|
|---|
| 69 | int j, k, t;
|
|---|
| 70 | // copy inhomogeneous control points into temporary array
|
|---|
| 71 | for( j=0; j != ncols; j++ )
|
|---|
| 72 | for( k=0; k != inhcoords; k++ )
|
|---|
| 73 | tmp[j][k] = p[j*stride + k];
|
|---|
| 74 |
|
|---|
| 75 | for( t=0; t != partial; t++ )
|
|---|
| 76 | for( j=0; j != ncols-t-1; j++ )
|
|---|
| 77 | for( k=0; k != inhcoords; k++ )
|
|---|
| 78 | tmp[j][k] = tmp[j+1][k] - tmp[j][k];
|
|---|
| 79 |
|
|---|
| 80 | // compute magnitude and store in mag array
|
|---|
| 81 | for( j=0; j != ncols-partial; j++ ) {
|
|---|
| 82 | mag[j] = 0.0;
|
|---|
| 83 | for( k=0; k != inhcoords; k++ )
|
|---|
| 84 | mag[j] += tmp[j][k] * tmp[j][k];
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | // compute scale factor
|
|---|
| 88 | REAL fac = 1;
|
|---|
| 89 | REAL invt = 1.0 / range;
|
|---|
| 90 | for( t = ncols-1; t != ncols-1-partial; t-- )
|
|---|
| 91 | fac *= t * invt;
|
|---|
| 92 |
|
|---|
| 93 | // compute max magnitude of all entries in array
|
|---|
| 94 | REAL max = 0.0;
|
|---|
| 95 | for( j=0; j != ncols-partial; j++ )
|
|---|
| 96 | if( mag[j] > max ) max = mag[j];
|
|---|
| 97 | max = fac * ::sqrtf( (float) max );
|
|---|
| 98 |
|
|---|
| 99 | return max;
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|
| 102 | /*--------------------------------------------------------------------------
|
|---|
| 103 | * calcPartialVelocity - calculate maximum magnitude of a given partial
|
|---|
| 104 | * derivative
|
|---|
| 105 | *--------------------------------------------------------------------------
|
|---|
| 106 | */
|
|---|
| 107 | REAL
|
|---|
| 108 | Mapdesc::calcPartialVelocity (
|
|---|
| 109 | REAL *dist,
|
|---|
| 110 | REAL *p,
|
|---|
| 111 | int rstride,
|
|---|
| 112 | int cstride,
|
|---|
| 113 | int nrows,
|
|---|
| 114 | int ncols,
|
|---|
| 115 | int spartial,
|
|---|
| 116 | int tpartial,
|
|---|
| 117 | REAL srange,
|
|---|
| 118 | REAL trange,
|
|---|
| 119 | int side )
|
|---|
| 120 | {
|
|---|
| 121 | REAL tmp[MAXORDER][MAXORDER][MAXCOORDS];
|
|---|
| 122 | REAL mag[MAXORDER][MAXORDER];
|
|---|
| 123 |
|
|---|
| 124 | assert( nrows <= MAXORDER );
|
|---|
| 125 | assert( ncols <= MAXORDER );
|
|---|
| 126 |
|
|---|
| 127 | REAL *tp = &tmp[0][0][0];
|
|---|
| 128 | REAL *mp = &mag[0][0];
|
|---|
| 129 | const int istride = sizeof( tmp[0]) / sizeof( tmp[0][0][0] );
|
|---|
| 130 | const int jstride = sizeof( tmp[0][0]) / sizeof( tmp[0][0][0] );
|
|---|
| 131 | const int kstride = sizeof( tmp[0][0][0]) / sizeof( tmp[0][0][0] );
|
|---|
| 132 | const int mistride = sizeof( mag[0]) / sizeof( mag[0][0] );
|
|---|
| 133 | const int mjstride = sizeof( mag[0][0]) / sizeof( mag[0][0] );
|
|---|
| 134 | const int idist = nrows * istride;
|
|---|
| 135 | const int jdist = ncols * jstride;
|
|---|
| 136 | const int kdist = inhcoords * kstride;
|
|---|
| 137 | const int id = idist - spartial * istride;
|
|---|
| 138 | const int jd = jdist - tpartial * jstride;
|
|---|
| 139 |
|
|---|
| 140 | {
|
|---|
| 141 | // copy control points
|
|---|
| 142 | REAL *ti = tp;
|
|---|
| 143 | REAL *qi = p;
|
|---|
| 144 | REAL *til = tp + idist;
|
|---|
| 145 | for( ; ti != til; ) {
|
|---|
| 146 | REAL *tj = ti;
|
|---|
| 147 | REAL *qj = qi;
|
|---|
| 148 | REAL *tjl = ti + jdist;
|
|---|
| 149 | for( ; tj != tjl; ) {
|
|---|
| 150 | for( int k=0; k != inhcoords; k++ ) {
|
|---|
| 151 | tj[k] = qj[k];
|
|---|
| 152 | }
|
|---|
| 153 | tj += jstride;
|
|---|
| 154 | qj += cstride;
|
|---|
| 155 | }
|
|---|
| 156 | ti += istride;
|
|---|
| 157 | qi += rstride;
|
|---|
| 158 | }
|
|---|
| 159 | }
|
|---|
| 160 |
|
|---|
| 161 | {
|
|---|
| 162 | // compute (s)-partial derivative control points
|
|---|
| 163 | REAL *til = tp + idist - istride;
|
|---|
| 164 | const REAL *till = til - ( spartial * istride );
|
|---|
| 165 | for( ; til != till; til -= istride )
|
|---|
| 166 | for( REAL *ti = tp; ti != til; ti += istride )
|
|---|
| 167 | for( REAL *tj = ti, *tjl = tj + jdist; tj != tjl; tj += jstride )
|
|---|
| 168 | for( int k=0; k != inhcoords; k++ )
|
|---|
| 169 | tj[k] = tj[k+istride] - tj[k];
|
|---|
| 170 | }
|
|---|
| 171 |
|
|---|
| 172 | {
|
|---|
| 173 | // compute (s,t)-partial derivative control points
|
|---|
| 174 | REAL *tjl = tp + jdist - jstride;
|
|---|
| 175 | const REAL *tjll = tjl - ( tpartial * jstride );
|
|---|
| 176 | for( ; tjl != tjll; tjl -= jstride )
|
|---|
| 177 | for( REAL *tj = tp; tj != tjl; tj += jstride )
|
|---|
| 178 | for( REAL *ti = tj, *til = ti + id; ti != til; ti += istride )
|
|---|
| 179 | for( int k=0; k != inhcoords; k++ )
|
|---|
| 180 | ti[k] = ti[k+jstride] - ti[k];
|
|---|
| 181 |
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|
| 184 | REAL max = 0.0;
|
|---|
| 185 | {
|
|---|
| 186 | // compute magnitude and store in mag array
|
|---|
| 187 | memset( (void *) mp, 0, sizeof( mag ) );
|
|---|
| 188 | for( REAL *ti = tp, *mi = mp, *til = tp + id; ti != til; ti += istride, mi += mistride )
|
|---|
| 189 | for( REAL *tj = ti, *mj = mi, *tjl = ti + jd; tj != tjl; tj += jstride, mj += mjstride ) {
|
|---|
| 190 | for( int k=0; k != inhcoords; k++ )
|
|---|
| 191 | *mj += tj[k] * tj[k];
|
|---|
| 192 | if( *mj > max ) max = *mj;
|
|---|
| 193 | }
|
|---|
| 194 |
|
|---|
| 195 | }
|
|---|
| 196 |
|
|---|
| 197 | int i, j;
|
|---|
| 198 |
|
|---|
| 199 | // compute scale factor
|
|---|
| 200 | REAL fac = 1.0;
|
|---|
| 201 | {
|
|---|
| 202 | REAL invs = 1.0 / srange;
|
|---|
| 203 | REAL invt = 1.0 / trange;
|
|---|
| 204 | for( int s = nrows-1, slast = s-spartial; s != slast; s-- )
|
|---|
| 205 | fac *= s * invs;
|
|---|
| 206 | for( int t = ncols-1, tlast = t-tpartial; t != tlast; t-- )
|
|---|
| 207 | fac *= t * invt;
|
|---|
| 208 | }
|
|---|
| 209 |
|
|---|
| 210 | if( side == 0 ) {
|
|---|
| 211 | // compute max magnitude of first and last column
|
|---|
| 212 | dist[0] = 0.0;
|
|---|
| 213 | dist[1] = 0.0;
|
|---|
| 214 | for( i=0; i != nrows-spartial; i++ ) {
|
|---|
| 215 | j = 0;
|
|---|
| 216 | if( mag[i][j] > dist[0] ) dist[0] = mag[i][j];
|
|---|
| 217 |
|
|---|
| 218 | j = ncols-tpartial-1;
|
|---|
| 219 | if( mag[i][j] > dist[1] ) dist[1] = mag[i][j];
|
|---|
| 220 | }
|
|---|
| 221 | dist[0] = fac * ::sqrtf( dist[0] );
|
|---|
| 222 | dist[1] = fac * ::sqrtf( dist[1] );
|
|---|
| 223 | } else if( side == 1 ) {
|
|---|
| 224 | // compute max magnitude of first and last row
|
|---|
| 225 | dist[0] = 0.0;
|
|---|
| 226 | dist[1] = 0.0;
|
|---|
| 227 | for( j=0; j != ncols-tpartial; j++ ) {
|
|---|
| 228 | i = 0;
|
|---|
| 229 | if( mag[i][j] > dist[0] ) dist[0] = mag[i][j];
|
|---|
| 230 |
|
|---|
| 231 | i = nrows-spartial-1;
|
|---|
| 232 | if( mag[i][j] > dist[1] ) dist[1] = mag[i][j];
|
|---|
| 233 | }
|
|---|
| 234 | dist[0] = fac * ::sqrtf( dist[0] );
|
|---|
| 235 | dist[1] = fac * ::sqrtf( dist[1] );
|
|---|
| 236 | }
|
|---|
| 237 |
|
|---|
| 238 | max = fac * ::sqrtf( (float) max );
|
|---|
| 239 |
|
|---|
| 240 | return max;
|
|---|
| 241 | }
|
|---|
| 242 |
|
|---|