| 1 |
/* |
| 2 |
* |
| 3 |
* Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved. |
| 4 |
* |
| 5 |
* This library is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU Lesser General Public |
| 7 |
* License as published by the Free Software Foundation; either |
| 8 |
* version 2.1 of the License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This library is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* Lesser General Public License for more details. |
| 14 |
* |
| 15 |
* Further, this software is distributed without any warranty that it is |
| 16 |
* free of the rightful claim of any third person regarding infringement |
| 17 |
* or the like. Any license provided herein, whether implied or |
| 18 |
* otherwise, applies only to this software file. Patent licenses, if |
| 19 |
* any, provided herein do not apply to combinations of this program with |
| 20 |
* other software, or any other product whatsoever. |
| 21 |
* |
| 22 |
* You should have received a copy of the GNU Lesser General Public |
| 23 |
* License along with this library; if not, write to the Free Software |
| 24 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 25 |
* |
| 26 |
* Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
| 27 |
* Mountain View, CA 94043, or: |
| 28 |
* |
| 29 |
* http://www.sgi.com |
| 30 |
* |
| 31 |
* For further information regarding this notice, see: |
| 32 |
* |
| 33 |
* http://oss.sgi.com/projects/GenInfo/NoticeExplan/ |
| 34 |
* |
| 35 |
*/ |
| 36 |
|
| 37 |
/* |
| 38 |
* trimline.c++ - $Revision: 1.1.1.1 $ |
| 39 |
* Derrick Burns - 1991 |
| 40 |
*/ |
| 41 |
|
| 42 |
#include "glimports.h" |
| 43 |
#include "myassert.h" |
| 44 |
#include "mystdio.h" |
| 45 |
#include "trimline.h" |
| 46 |
#include "backend.h" |
| 47 |
|
| 48 |
Trimline::Trimline() |
| 49 |
{ |
| 50 |
size = 0; pts = 0; numverts = 0; |
| 51 |
tinterp = &t; binterp = &b; |
| 52 |
} |
| 53 |
|
| 54 |
Trimline::~Trimline() |
| 55 |
{ |
| 56 |
if( pts ) delete[] pts; |
| 57 |
} |
| 58 |
|
| 59 |
void |
| 60 |
Trimline::init( TrimVertex *v ) |
| 61 |
{ |
| 62 |
reset(); |
| 63 |
grow(1); |
| 64 |
append(v); |
| 65 |
} |
| 66 |
|
| 67 |
inline void |
| 68 |
Trimline::grow( long npts ) |
| 69 |
{ |
| 70 |
if( size < npts ) { |
| 71 |
size = 2 * npts; |
| 72 |
if( pts ) delete[] pts; |
| 73 |
pts = new TrimVertex_p[size]; |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
inline void |
| 78 |
Trimline::append( TrimVertex *v ) |
| 79 |
{ |
| 80 |
assert( numverts != size ); |
| 81 |
pts[numverts++] = v; |
| 82 |
} |
| 83 |
|
| 84 |
void |
| 85 |
Trimline::init( long npts, Arc_ptr jarc, long last ) |
| 86 |
{ |
| 87 |
jarcl.init( jarc, 0, last ); |
| 88 |
grow( npts + 2 ); |
| 89 |
} |
| 90 |
|
| 91 |
inline void |
| 92 |
Trimline::swap() |
| 93 |
{ |
| 94 |
TrimVertex *tmp=tinterp; |
| 95 |
tinterp=binterp; |
| 96 |
binterp=tmp; |
| 97 |
} |
| 98 |
|
| 99 |
void |
| 100 |
Trimline::getNextPt() |
| 101 |
{ |
| 102 |
*binterp = *jarcl.getnextpt(); |
| 103 |
} |
| 104 |
|
| 105 |
void |
| 106 |
Trimline::getPrevPt() |
| 107 |
{ |
| 108 |
*binterp = *jarcl.getprevpt(); |
| 109 |
} |
| 110 |
|
| 111 |
/*---------------------------------------------------------------------- |
| 112 |
* getNextPts - make arrays of pointers to trim points on left and right |
| 113 |
* hulls of trim strip. |
| 114 |
*---------------------------------------------------------------------- |
| 115 |
*/ |
| 116 |
void |
| 117 |
Trimline::getNextPts( REAL vval, Backend& backend ) |
| 118 |
{ |
| 119 |
reset(); swap(); append( tinterp ); |
| 120 |
assert( tinterp->param[1] >= vval ); |
| 121 |
|
| 122 |
register TrimVertex *p; |
| 123 |
for( p=jarcl.getnextpt() ; p->param[1] >= vval; p=jarcl.getnextpt() ) { |
| 124 |
append( p ); |
| 125 |
} |
| 126 |
|
| 127 |
/* compute and copy pointer to final point on left hull */ |
| 128 |
if( interpvert( last(), p, binterp, vval ) ) { |
| 129 |
binterp->nuid = p->nuid; |
| 130 |
backend.triangle( p, binterp, last() ); |
| 131 |
append( binterp ); |
| 132 |
} |
| 133 |
jarcl.reverse(); |
| 134 |
(void) jarcl.getprevpt(); /* reset jarcl to proper position */ |
| 135 |
jarcl.reverse(); |
| 136 |
} |
| 137 |
|
| 138 |
void |
| 139 |
Trimline::getPrevPts( REAL vval, Backend& backend ) |
| 140 |
{ |
| 141 |
reset(); swap(); append( tinterp ); |
| 142 |
assert( tinterp->param[1] >= vval ); |
| 143 |
|
| 144 |
register TrimVertex *q; |
| 145 |
for( q=jarcl.getprevpt(); q->param[1] >= vval; q=jarcl.getprevpt() ) { |
| 146 |
append( q ); |
| 147 |
} |
| 148 |
|
| 149 |
/* compute and copy pointer to final point on right hull */ |
| 150 |
if( interpvert( q, last(), binterp, vval ) ) { |
| 151 |
binterp->nuid = q->nuid; |
| 152 |
backend.triangle( last(), binterp, q ); |
| 153 |
append( binterp ); |
| 154 |
} |
| 155 |
jarcl.reverse(); |
| 156 |
(void) jarcl.getnextpt(); /* reset jarcl to proper position */ |
| 157 |
jarcl.reverse(); |
| 158 |
} |
| 159 |
|
| 160 |
void |
| 161 |
Trimline::getNextPts( Arc_ptr botarc ) |
| 162 |
{ |
| 163 |
reset(); swap(); append( tinterp ); |
| 164 |
|
| 165 |
PwlArc *lastpwl = botarc->prev->pwlArc; |
| 166 |
TrimVertex *lastpt1 = &lastpwl->pts[lastpwl->npts-1]; |
| 167 |
TrimVertex *lastpt2 = botarc->pwlArc->pts; |
| 168 |
|
| 169 |
register TrimVertex *p = jarcl.getnextpt(); |
| 170 |
for( append( p ); p != lastpt2; append( p ) ) { |
| 171 |
assert( p != lastpt1 ); |
| 172 |
p = jarcl.getnextpt(); |
| 173 |
} |
| 174 |
} |
| 175 |
|
| 176 |
void |
| 177 |
Trimline::getPrevPts( Arc_ptr botarc ) |
| 178 |
{ |
| 179 |
reset(); swap(); append( tinterp ); |
| 180 |
|
| 181 |
PwlArc *lastpwl = botarc->prev->pwlArc; |
| 182 |
TrimVertex *lastpt1 = &lastpwl->pts[lastpwl->npts-1]; |
| 183 |
TrimVertex *lastpt2 = botarc->pwlArc->pts; |
| 184 |
|
| 185 |
register TrimVertex *q = jarcl.getprevpt(); |
| 186 |
for( append( q ); q != lastpt1; append( q ) ) { |
| 187 |
assert( q != lastpt2 ); |
| 188 |
q = jarcl.getprevpt(); |
| 189 |
} |
| 190 |
} |
| 191 |
|
| 192 |
|
| 193 |
long |
| 194 |
Trimline::interpvert( TrimVertex *a, TrimVertex *b, TrimVertex *c, REAL vval ) |
| 195 |
{ |
| 196 |
REAL denom = a->param[1] - b->param[1]; |
| 197 |
|
| 198 |
if(denom != 0) { |
| 199 |
if( vval == a->param[1] ) { |
| 200 |
c->param[0] = a->param[0]; |
| 201 |
c->param[1] = a->param[1]; |
| 202 |
c->nuid = a->nuid; |
| 203 |
return 0; |
| 204 |
} else if( vval == b->param[1] ) { |
| 205 |
c->param[0] = b->param[0]; |
| 206 |
c->param[1] = b->param[1]; |
| 207 |
c->nuid = b->nuid; |
| 208 |
return 0; |
| 209 |
} else { |
| 210 |
REAL r = (a->param[1] - vval)/denom; |
| 211 |
c->param[0] = a->param[0] - r * (a->param[0] - b->param[0]); |
| 212 |
c->param[1] = vval; |
| 213 |
return 1; |
| 214 |
} |
| 215 |
} else { |
| 216 |
c->param[0] = a->param[0]; |
| 217 |
c->param[1] = a->param[1]; |
| 218 |
c->nuid = a->nuid; |
| 219 |
return 0; |
| 220 |
} |
| 221 |
} |
| 222 |
|