| 1 | /* $Id: trimline.cpp,v 1.1 2000-02-09 08:50:30 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 | * trimline.c++
|
|---|
| 38 | *
|
|---|
| 39 | * $Date: 2000-02-09 08:50:30 $ $Revision: 1.1 $
|
|---|
| 40 | * $Header: /home/ktk/tmp/odin/2007/netlabs.cvs/odin32/src/opengl/glu/nurbs/internals/trimline.cpp,v 1.1 2000-02-09 08:50:30 jeroen Exp $
|
|---|
| 41 | */
|
|---|
| 42 |
|
|---|
| 43 | #include "glimports.h"
|
|---|
| 44 | #include "myassert.h"
|
|---|
| 45 | #include "mystdio.h"
|
|---|
| 46 | #include "trimline.h"
|
|---|
| 47 | #include "backend.h"
|
|---|
| 48 |
|
|---|
| 49 | Trimline::Trimline()
|
|---|
| 50 | {
|
|---|
| 51 | size = 0; pts = 0; numverts = 0;
|
|---|
| 52 | tinterp = &t; binterp = &b;
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | Trimline::~Trimline()
|
|---|
| 56 | {
|
|---|
| 57 | if( pts ) delete[] pts;
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | void
|
|---|
| 61 | Trimline::init( TrimVertex *v )
|
|---|
| 62 | {
|
|---|
| 63 | reset();
|
|---|
| 64 | grow(1);
|
|---|
| 65 | append(v);
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | inline void
|
|---|
| 69 | Trimline::grow( long npts )
|
|---|
| 70 | {
|
|---|
| 71 | if( size < npts ) {
|
|---|
| 72 | size = 2 * npts;
|
|---|
| 73 | if( pts ) delete[] pts;
|
|---|
| 74 | pts = new TrimVertex_p[size];
|
|---|
| 75 | }
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | inline void
|
|---|
| 79 | Trimline::append( TrimVertex *v )
|
|---|
| 80 | {
|
|---|
| 81 | assert( numverts != size );
|
|---|
| 82 | pts[numverts++] = v;
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | void
|
|---|
| 86 | Trimline::init( long npts, Arc_ptr jarc, long last )
|
|---|
| 87 | {
|
|---|
| 88 | jarcl.init( jarc, 0, last );
|
|---|
| 89 | grow( npts + 2 );
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | inline void
|
|---|
| 93 | Trimline::swap()
|
|---|
| 94 | {
|
|---|
| 95 | TrimVertex *tmp=tinterp;
|
|---|
| 96 | tinterp=binterp;
|
|---|
| 97 | binterp=tmp;
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | void
|
|---|
| 101 | Trimline::getNextPt()
|
|---|
| 102 | {
|
|---|
| 103 | *binterp = *jarcl.getnextpt();
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | void
|
|---|
| 107 | Trimline::getPrevPt()
|
|---|
| 108 | {
|
|---|
| 109 | *binterp = *jarcl.getprevpt();
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | /*----------------------------------------------------------------------
|
|---|
| 113 | * getNextPts - make arrays of pointers to trim points on left and right
|
|---|
| 114 | * hulls of trim strip.
|
|---|
| 115 | *----------------------------------------------------------------------
|
|---|
| 116 | */
|
|---|
| 117 | void
|
|---|
| 118 | Trimline::getNextPts( REAL vval, Backend& backend )
|
|---|
| 119 | {
|
|---|
| 120 | reset(); swap(); append( tinterp );
|
|---|
| 121 | assert( tinterp->param[1] >= vval );
|
|---|
| 122 |
|
|---|
| 123 | register TrimVertex *p;
|
|---|
| 124 | for( p=jarcl.getnextpt() ; p->param[1] >= vval; p=jarcl.getnextpt() ) {
|
|---|
| 125 | append( p );
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 | /* compute and copy pointer to final point on left hull */
|
|---|
| 129 | if( interpvert( last(), p, binterp, vval ) ) {
|
|---|
| 130 | binterp->nuid = p->nuid;
|
|---|
| 131 | backend.triangle( p, binterp, last() );
|
|---|
| 132 | append( binterp );
|
|---|
| 133 | }
|
|---|
| 134 | jarcl.reverse();
|
|---|
| 135 | (void) jarcl.getprevpt(); /* reset jarcl to proper position */
|
|---|
| 136 | jarcl.reverse();
|
|---|
| 137 | }
|
|---|
| 138 |
|
|---|
| 139 | void
|
|---|
| 140 | Trimline::getPrevPts( REAL vval, Backend& backend )
|
|---|
| 141 | {
|
|---|
| 142 | reset(); swap(); append( tinterp );
|
|---|
| 143 | assert( tinterp->param[1] >= vval );
|
|---|
| 144 |
|
|---|
| 145 | register TrimVertex *q;
|
|---|
| 146 | for( q=jarcl.getprevpt(); q->param[1] >= vval; q=jarcl.getprevpt() ) {
|
|---|
| 147 | append( q );
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | /* compute and copy pointer to final point on right hull */
|
|---|
| 151 | if( interpvert( q, last(), binterp, vval ) ) {
|
|---|
| 152 | binterp->nuid = q->nuid;
|
|---|
| 153 | backend.triangle( last(), binterp, q );
|
|---|
| 154 | append( binterp );
|
|---|
| 155 | }
|
|---|
| 156 | jarcl.reverse();
|
|---|
| 157 | (void) jarcl.getnextpt(); /* reset jarcl to proper position */
|
|---|
| 158 | jarcl.reverse();
|
|---|
| 159 | }
|
|---|
| 160 |
|
|---|
| 161 | void
|
|---|
| 162 | Trimline::getNextPts( Arc_ptr botarc )
|
|---|
| 163 | {
|
|---|
| 164 | reset(); swap(); append( tinterp );
|
|---|
| 165 |
|
|---|
| 166 | PwlArc *lastpwl = botarc->prev->pwlArc;
|
|---|
| 167 | TrimVertex *lastpt1 = &lastpwl->pts[lastpwl->npts-1];
|
|---|
| 168 | TrimVertex *lastpt2 = botarc->pwlArc->pts;
|
|---|
| 169 |
|
|---|
| 170 | register TrimVertex *p = jarcl.getnextpt();
|
|---|
| 171 | for( append( p ); p != lastpt2; append( p ) ) {
|
|---|
| 172 | assert( p != lastpt1 );
|
|---|
| 173 | p = jarcl.getnextpt();
|
|---|
| 174 | }
|
|---|
| 175 | }
|
|---|
| 176 |
|
|---|
| 177 | void
|
|---|
| 178 | Trimline::getPrevPts( Arc_ptr botarc )
|
|---|
| 179 | {
|
|---|
| 180 | reset(); swap(); append( tinterp );
|
|---|
| 181 |
|
|---|
| 182 | PwlArc *lastpwl = botarc->prev->pwlArc;
|
|---|
| 183 | TrimVertex *lastpt1 = &lastpwl->pts[lastpwl->npts-1];
|
|---|
| 184 | TrimVertex *lastpt2 = botarc->pwlArc->pts;
|
|---|
| 185 |
|
|---|
| 186 | register TrimVertex *q = jarcl.getprevpt();
|
|---|
| 187 | for( append( q ); q != lastpt1; append( q ) ) {
|
|---|
| 188 | assert( q != lastpt2 );
|
|---|
| 189 | q = jarcl.getprevpt();
|
|---|
| 190 | }
|
|---|
| 191 | }
|
|---|
| 192 |
|
|---|
| 193 |
|
|---|
| 194 | long
|
|---|
| 195 | Trimline::interpvert( TrimVertex *a, TrimVertex *b, TrimVertex *c, REAL vval )
|
|---|
| 196 | {
|
|---|
| 197 | REAL denom = a->param[1] - b->param[1];
|
|---|
| 198 |
|
|---|
| 199 | if(denom != 0) {
|
|---|
| 200 | if( vval == a->param[1] ) {
|
|---|
| 201 | c->param[0] = a->param[0];
|
|---|
| 202 | c->param[1] = a->param[1];
|
|---|
| 203 | c->nuid = a->nuid;
|
|---|
| 204 | return 0;
|
|---|
| 205 | } else if( vval == b->param[1] ) {
|
|---|
| 206 | c->param[0] = b->param[0];
|
|---|
| 207 | c->param[1] = b->param[1];
|
|---|
| 208 | c->nuid = b->nuid;
|
|---|
| 209 | return 0;
|
|---|
| 210 | } else {
|
|---|
| 211 | REAL r = (a->param[1] - vval)/denom;
|
|---|
| 212 | c->param[0] = a->param[0] - r * (a->param[0] - b->param[0]);
|
|---|
| 213 | c->param[1] = vval;
|
|---|
| 214 | return 1;
|
|---|
| 215 | }
|
|---|
| 216 | } else {
|
|---|
| 217 | c->param[0] = a->param[0];
|
|---|
| 218 | c->param[1] = a->param[1];
|
|---|
| 219 | c->nuid = a->nuid;
|
|---|
| 220 | return 0;
|
|---|
| 221 | }
|
|---|
| 222 | }
|
|---|
| 223 |
|
|---|