| 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 |
* slicer.c++ - $Revision: 1.1.1.1 $ |
| 39 |
* Derrick Burns - 1991 |
| 40 |
*/ |
| 41 |
|
| 42 |
#include "glimports.h" |
| 43 |
#include "mystdio.h" |
| 44 |
#include "myassert.h" |
| 45 |
#include "bufpool.h" |
| 46 |
#include "slicer.h" |
| 47 |
#include "backend.h" |
| 48 |
#include "arc.h" |
| 49 |
#include "gridtrimvertex.h" |
| 50 |
#include "trimvertex.h" |
| 51 |
#include "varray.h" |
| 52 |
|
| 53 |
Slicer::Slicer( Backend &b ) |
| 54 |
: CoveAndTiler( b ), Mesher( b ), backend( b ) |
| 55 |
{ |
| 56 |
} |
| 57 |
|
| 58 |
Slicer::~Slicer() |
| 59 |
{ |
| 60 |
} |
| 61 |
|
| 62 |
void |
| 63 |
Slicer::setisolines( int x ) |
| 64 |
{ |
| 65 |
isolines = x; |
| 66 |
} |
| 67 |
|
| 68 |
void |
| 69 |
Slicer::setstriptessellation( REAL x, REAL y ) |
| 70 |
{ |
| 71 |
assert(x > 0 && y > 0); |
| 72 |
du = x; |
| 73 |
dv = y; |
| 74 |
setDu( du ); |
| 75 |
} |
| 76 |
|
| 77 |
void |
| 78 |
Slicer::slice( Arc_ptr loop ) |
| 79 |
{ |
| 80 |
loop->markverts(); |
| 81 |
|
| 82 |
Arc_ptr extrema[4]; |
| 83 |
loop->getextrema( extrema ); |
| 84 |
|
| 85 |
unsigned int npts = loop->numpts(); |
| 86 |
TrimRegion::init( npts, extrema[0] ); |
| 87 |
|
| 88 |
Mesher::init( npts ); |
| 89 |
|
| 90 |
long ulines = uarray.init( du, extrema[1], extrema[3] ); |
| 91 |
|
| 92 |
Varray varray; |
| 93 |
long vlines = varray.init( dv, extrema[0], extrema[2] ); |
| 94 |
long botv = 0; |
| 95 |
long topv; |
| 96 |
TrimRegion::init( varray.varray[botv] ); |
| 97 |
getGridExtent( &extrema[0]->pwlArc->pts[0], &extrema[0]->pwlArc->pts[0] ); |
| 98 |
|
| 99 |
for( long quad=0; quad<varray.numquads; quad++ ) { |
| 100 |
backend.surfgrid( uarray.uarray[0], |
| 101 |
uarray.uarray[ulines-1], |
| 102 |
ulines-1, |
| 103 |
varray.vval[quad], |
| 104 |
varray.vval[quad+1], |
| 105 |
varray.voffset[quad+1] - varray.voffset[quad] ); |
| 106 |
|
| 107 |
for( long i=varray.voffset[quad]+1; i <= varray.voffset[quad+1]; i++ ) { |
| 108 |
topv = botv++; |
| 109 |
advance( topv - varray.voffset[quad], |
| 110 |
botv - varray.voffset[quad], |
| 111 |
varray.varray[botv] ); |
| 112 |
if( i == vlines ) |
| 113 |
getPts( extrema[2] ); |
| 114 |
else |
| 115 |
getPts( backend ); |
| 116 |
getGridExtent(); |
| 117 |
if( isolines ) { |
| 118 |
outline(); |
| 119 |
} else { |
| 120 |
if( canTile() ) |
| 121 |
coveAndTile(); |
| 122 |
else |
| 123 |
mesh(); |
| 124 |
} |
| 125 |
} |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
|
| 130 |
void |
| 131 |
Slicer::outline( void ) |
| 132 |
{ |
| 133 |
GridTrimVertex upper, lower; |
| 134 |
Hull::init( ); |
| 135 |
|
| 136 |
backend.bgnoutline(); |
| 137 |
while( (nextupper( &upper )) ) { |
| 138 |
if( upper.isGridVert() ) |
| 139 |
backend.linevert( upper.g ); |
| 140 |
else |
| 141 |
backend.linevert( upper.t ); |
| 142 |
} |
| 143 |
backend.endoutline(); |
| 144 |
|
| 145 |
backend.bgnoutline(); |
| 146 |
while( (nextlower( &lower )) ) { |
| 147 |
if( lower.isGridVert() ) |
| 148 |
backend.linevert( lower.g ); |
| 149 |
else |
| 150 |
backend.linevert( lower.t ); |
| 151 |
} |
| 152 |
backend.endoutline(); |
| 153 |
} |
| 154 |
|
| 155 |
|
| 156 |
void |
| 157 |
Slicer::outline( Arc_ptr jarc ) |
| 158 |
{ |
| 159 |
jarc->markverts(); |
| 160 |
|
| 161 |
if( jarc->pwlArc->npts >= 2 ) { |
| 162 |
backend.bgnoutline(); |
| 163 |
for( int j = jarc->pwlArc->npts-1; j >= 0; j-- ) |
| 164 |
backend.linevert( &(jarc->pwlArc->pts[j]) ); |
| 165 |
backend.endoutline(); |
| 166 |
} |
| 167 |
} |
| 168 |
|