| 1 | /* $Id: curve.cpp,v 1.1 2000-02-09 08:50:21 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 | * curve.c++
|
|---|
| 38 | *
|
|---|
| 39 | * $Date: 2000-02-09 08:50:21 $ $Revision: 1.1 $
|
|---|
| 40 | * $Header: /home/ktk/tmp/odin/2007/netlabs.cvs/odin32/src/opengl/glu/nurbs/internals/curve.cpp,v 1.1 2000-02-09 08:50:21 jeroen Exp $
|
|---|
| 41 | */
|
|---|
| 42 |
|
|---|
| 43 | #include "glimports.h"
|
|---|
| 44 | #include "myassert.h"
|
|---|
| 45 | #include "mystdio.h"
|
|---|
| 46 | #include "mymath.h"
|
|---|
| 47 | #include "curve.h"
|
|---|
| 48 | #include "mapdesc.h"
|
|---|
| 49 | #include "types.h"
|
|---|
| 50 | #include "quilt.h"
|
|---|
| 51 | #include "nurbsconsts.h"
|
|---|
| 52 |
|
|---|
| 53 | /*--------------------------------------------------------------------------
|
|---|
| 54 | * Curve::Curve - copy curve from quilt and transform control points
|
|---|
| 55 | *--------------------------------------------------------------------------
|
|---|
| 56 | */
|
|---|
| 57 |
|
|---|
| 58 | Curve::Curve( Quilt_ptr geo, REAL pta, REAL ptb, Curve *c )
|
|---|
| 59 | {
|
|---|
| 60 | mapdesc = geo->mapdesc;
|
|---|
| 61 | next = c;
|
|---|
| 62 | needsSampling = mapdesc->isRangeSampling() ? 1 : 0;
|
|---|
| 63 | cullval = mapdesc->isCulling() ? CULL_ACCEPT : CULL_TRIVIAL_ACCEPT;
|
|---|
| 64 | order = geo->qspec[0].order;
|
|---|
| 65 | stride = MAXCOORDS;
|
|---|
| 66 |
|
|---|
| 67 | REAL *ps = geo->cpts;
|
|---|
| 68 | Quiltspec_ptr qs = geo->qspec;
|
|---|
| 69 | ps += qs->offset;
|
|---|
| 70 | ps += qs->index * qs->order * qs->stride;
|
|---|
| 71 | REAL *pend = ps + qs->order * qs->stride;
|
|---|
| 72 |
|
|---|
| 73 | if( needsSampling )
|
|---|
| 74 | mapdesc->xformSampling( ps, qs->order, qs->stride, spts, stride );
|
|---|
| 75 |
|
|---|
| 76 | if( cullval == CULL_ACCEPT )
|
|---|
| 77 | mapdesc->xformCulling( ps, qs->order, qs->stride, cpts, stride );
|
|---|
| 78 |
|
|---|
| 79 | /* set untrimmed curve range */
|
|---|
| 80 | range[0] = qs->breakpoints[qs->index];
|
|---|
| 81 | range[1] = qs->breakpoints[qs->index+1];
|
|---|
| 82 | range[2] = range[1] - range[0];
|
|---|
| 83 |
|
|---|
| 84 | if( range[0] != pta ) {
|
|---|
| 85 | Curve lower( *this, pta, 0 );
|
|---|
| 86 | lower.next = next;
|
|---|
| 87 | *this = lower;
|
|---|
| 88 | }
|
|---|
| 89 | if( range[1] != ptb ) {
|
|---|
| 90 | Curve lower( *this, ptb, 0 );
|
|---|
| 91 | }
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | /*--------------------------------------------------------------------------
|
|---|
| 95 | * Curve::Curve - subdivide a curve along an isoparametric line
|
|---|
| 96 | *--------------------------------------------------------------------------
|
|---|
| 97 | */
|
|---|
| 98 |
|
|---|
| 99 | Curve::Curve( Curve& upper, REAL value, Curve *c )
|
|---|
| 100 | {
|
|---|
| 101 | Curve &lower = *this;
|
|---|
| 102 |
|
|---|
| 103 | lower.next = c;
|
|---|
| 104 | lower.mapdesc = upper.mapdesc;
|
|---|
| 105 | lower.needsSampling = upper.needsSampling;
|
|---|
| 106 | lower.order = upper.order;
|
|---|
| 107 | lower.stride = upper.stride;
|
|---|
| 108 | lower.cullval = upper.cullval;
|
|---|
| 109 |
|
|---|
| 110 | REAL d = (value - upper.range[0]) / upper.range[2];
|
|---|
| 111 |
|
|---|
| 112 | if( needsSampling )
|
|---|
| 113 | mapdesc->subdivide( upper.spts, lower.spts, d, upper.stride, upper.order );
|
|---|
| 114 |
|
|---|
| 115 | if( cullval == CULL_ACCEPT )
|
|---|
| 116 | mapdesc->subdivide( upper.cpts, lower.cpts, d, upper.stride, upper.order );
|
|---|
| 117 |
|
|---|
| 118 | lower.range[0] = upper.range[0];
|
|---|
| 119 | lower.range[1] = value;
|
|---|
| 120 | lower.range[2] = value - upper.range[0];
|
|---|
| 121 | upper.range[0] = value;
|
|---|
| 122 | upper.range[2] = upper.range[1] - value;
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 | /*--------------------------------------------------------------------------
|
|---|
| 127 | * Curve::clamp - clamp the sampling rate to a given maximum
|
|---|
| 128 | *--------------------------------------------------------------------------
|
|---|
| 129 | */
|
|---|
| 130 |
|
|---|
| 131 | void
|
|---|
| 132 | Curve::clamp( void )
|
|---|
| 133 | {
|
|---|
| 134 | if( stepsize < minstepsize )
|
|---|
| 135 | stepsize = mapdesc->clampfactor * minstepsize;
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | void
|
|---|
| 139 | Curve::setstepsize( REAL max )
|
|---|
| 140 | {
|
|---|
| 141 | stepsize = ( max >= 1.0 ) ? (range[2] / max) : range[2];
|
|---|
| 142 | minstepsize = stepsize;
|
|---|
| 143 | }
|
|---|
| 144 |
|
|---|
| 145 | void
|
|---|
| 146 | Curve::getstepsize( void )
|
|---|
| 147 | {
|
|---|
| 148 | minstepsize= 0;
|
|---|
| 149 |
|
|---|
| 150 | if( mapdesc->isConstantSampling() ) {
|
|---|
| 151 | // fixed number of samples per patch in each direction
|
|---|
| 152 | // maxrate is number of s samples per patch
|
|---|
| 153 | setstepsize( mapdesc->maxrate );
|
|---|
| 154 | } else if( mapdesc->isDomainSampling() ) {
|
|---|
| 155 | // maxrate is number of s samples per unit s length of domain
|
|---|
| 156 | setstepsize( mapdesc->maxrate * range[2] );
|
|---|
| 157 | } else {
|
|---|
| 158 | // upper bound on path length between sample points
|
|---|
| 159 |
|
|---|
| 160 | assert( order <= MAXORDER );
|
|---|
| 161 |
|
|---|
| 162 | /* points have been transformed, therefore they are homogeneous */
|
|---|
| 163 | REAL tmp[MAXORDER][MAXCOORDS];
|
|---|
| 164 | const int tstride = sizeof(tmp[0]) / sizeof(REAL);
|
|---|
| 165 | int val = mapdesc->project( spts, stride, &tmp[0][0], tstride, order );
|
|---|
| 166 |
|
|---|
| 167 | if( val == 0 ) {
|
|---|
| 168 | // control points cross infinity, therefore derivatives are undefined
|
|---|
| 169 | setstepsize( mapdesc->maxrate );
|
|---|
| 170 | } else {
|
|---|
| 171 | REAL t = mapdesc->getProperty( N_PIXEL_TOLERANCE );
|
|---|
| 172 | if( mapdesc->isParametricDistanceSampling() ) {
|
|---|
| 173 | REAL d = mapdesc->calcPartialVelocity( &tmp[0][0], tstride, order, 2, range[2] );
|
|---|
| 174 | stepsize = (d > 0.0) ? ::sqrtf( 8.0 * t / d ) : range[2];
|
|---|
| 175 | minstepsize = ( mapdesc->maxrate > 0.0 ) ? (range[2] / mapdesc->maxrate) : 0.0;
|
|---|
| 176 | } else if( mapdesc->isPathLengthSampling() ) {
|
|---|
| 177 | // t is upper bound on path (arc) length
|
|---|
| 178 | REAL d = mapdesc->calcPartialVelocity( &tmp[0][0], tstride, order, 1, range[2] );
|
|---|
| 179 | stepsize = ( d > 0.0 ) ? (t / d) : range[2];
|
|---|
| 180 | minstepsize = ( mapdesc->maxrate > 0.0 ) ? (range[2] / mapdesc->maxrate) : 0.0;
|
|---|
| 181 | } else {
|
|---|
| 182 | // control points cross infinity, therefore partials are undefined
|
|---|
| 183 | setstepsize( mapdesc->maxrate );
|
|---|
| 184 | }
|
|---|
| 185 | }
|
|---|
| 186 | }
|
|---|
| 187 | }
|
|---|
| 188 |
|
|---|
| 189 | int
|
|---|
| 190 | Curve::needsSamplingSubdivision( void )
|
|---|
| 191 | {
|
|---|
| 192 | return ( stepsize < minstepsize ) ? 1 : 0;
|
|---|
| 193 | }
|
|---|
| 194 |
|
|---|
| 195 | int
|
|---|
| 196 | Curve::cullCheck( void )
|
|---|
| 197 | {
|
|---|
| 198 | if( cullval == CULL_ACCEPT )
|
|---|
| 199 | cullval = mapdesc->cullCheck( cpts, order, stride );
|
|---|
| 200 | return cullval;
|
|---|
| 201 | }
|
|---|
| 202 |
|
|---|