1 /* 2 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) 3 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved. 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Software"), 7 * to deal in the Software without restriction, including without limitation 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 * and/or sell copies of the Software, and to permit persons to whom the 10 * Software is furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice including the dates of first publication and 13 * either this permission notice or a reference to 14 * http://oss.sgi.com/projects/FreeB/ 15 * shall be included in all copies or substantial portions of the Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 22 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 * SOFTWARE. 24 * 25 * Except as contained in this notice, the name of Silicon Graphics, Inc. 26 * shall not be used in advertising or otherwise to promote the sale, use or 27 * other dealings in this Software without prior written authorization from 28 * Silicon Graphics, Inc. 29 */ 30 31 /* 32 * subdivider.h 33 * 34 */ 35 36 #ifndef __glusubdivider_h_ 37 #define __glusubdivider_h_ 38 39 #include "mysetjmp.h" 40 #include "bin.h" 41 #include "flist.h" 42 #include "slicer.h" 43 #include "arctess.h" 44 //#include "trimvertex.h" 45 #include "trimvertpool.h" 46 47 class Arc; 48 class Pool; 49 class Renderhints; 50 class Quilt; 51 class Patchlist; 52 class Curvelist; 53 struct JumpBuffer; 54 55 class Subdivider { 56 public: 57 Subdivider( Renderhints&, Backend& ); 58 ~Subdivider( void ); 59 void clear( void ); 60 61 void beginTrims( void ) {} 62 void beginLoop( void ); 63 void addArc( REAL *, Quilt *, long ); 64 void addArc( int, TrimVertex *, long ); 65 void endLoop( void ) {} 66 void endTrims( void ) {} 67 68 void beginQuilts( void ); 69 void addQuilt( Quilt * ); 70 void endQuilts( void ) {} 71 72 void drawCurves( void ); 73 void drawSurfaces( long ); 74 75 int ccwTurn_sl( Arc_ptr, Arc_ptr ); 76 int ccwTurn_sr( Arc_ptr , Arc_ptr ); 77 int ccwTurn_tl( Arc_ptr , Arc_ptr ); 78 int ccwTurn_tr( Arc_ptr , Arc_ptr ); 79 80 void setJumpbuffer( JumpBuffer * ); 81 82 void set_domain_distance_u_rate(REAL u_rate) 83 { 84 domain_distance_u_rate = u_rate; 85 } 86 void set_domain_distance_v_rate(REAL v_rate) 87 { 88 domain_distance_v_rate = v_rate; 89 } 90 void set_is_domain_distance_sampling(int flag) 91 { 92 is_domain_distance_sampling = flag; 93 } 94 95 private: 96 void classify_headonleft_s( Bin &, Bin &, Bin &, REAL ); 97 void classify_tailonleft_s( Bin &, Bin &, Bin &, REAL ); 98 void classify_headonright_s( Bin &, Bin &, Bin &, REAL ); 99 void classify_tailonright_s( Bin &, Bin &, Bin &, REAL ); 100 void classify_headonleft_t( Bin &, Bin &, Bin &, REAL ); 101 void classify_tailonleft_t( Bin &, Bin &, Bin &, REAL ); 102 void classify_headonright_t( Bin &, Bin &, Bin &, REAL ); 103 void classify_tailonright_t( Bin &, Bin &, Bin &, REAL ); 104 105 enum dir { down, same, up, none }; 106 void tessellate( Arc_ptr, REAL ); 107 void monotonize( Arc_ptr , Bin & ); 108 int isMonotone( Arc_ptr ); 109 int decompose( Bin &, REAL ); 110 111 112 Slicer slicer; 113 ArcTessellator arctessellator; 114 Pool arcpool; 115 Pool bezierarcpool; 116 Pool pwlarcpool; 117 TrimVertexPool trimvertexpool; 118 119 JumpBuffer* jumpbuffer; 120 Renderhints& renderhints; 121 Backend& backend; 122 123 Bin initialbin; 124 Arc_ptr pjarc; 125 int s_index; 126 int t_index; 127 Quilt * qlist; 128 Flist spbrkpts; 129 Flist tpbrkpts; 130 Flist smbrkpts; 131 Flist tmbrkpts; 132 REAL stepsizes[4]; 133 int showDegenerate; 134 int isArcTypeBezier; 135 136 void samplingSplit( Curvelist&, int ); 137 138 void subdivideInS( Bin& ); 139 void splitInS( Bin&, int, int ); 140 void splitInT( Bin&, int, int ); 141 void samplingSplit( Bin&, Patchlist&, int, int ); 142 void nonSamplingSplit( Bin&, Patchlist&, int, int ); 143 void tessellation( Bin&, Patchlist& ); 144 void monosplitInS( Bin&, int, int ); 145 void monosplitInT( Bin&, int, int ); 146 147 void outline( Bin & ); 148 void freejarcs( Bin & ); 149 void render( Bin & ); 150 void split( Bin &, Bin &, Bin &, int, REAL ); 151 void tessellate( Bin &, REAL, REAL, REAL, REAL ); 152 153 inline void setDegenerate( void ) { showDegenerate = 1; } 154 inline void setNonDegenerate( void ) { showDegenerate = 0; } 155 inline int showingDegenerate( void ) { return showDegenerate; } 156 inline void setArcTypeBezier( void ) { isArcTypeBezier = 1; } 157 inline void setArcTypePwl( void ) { isArcTypeBezier = 0; } 158 inline int isBezierArcType( void ) { return isArcTypeBezier; } 159 160 void makeBorderTrim( const REAL *, const REAL * ); 161 void split( Bin &, int, const REAL *, int, int ); 162 void partition( Bin &, Bin &, Bin &, Bin &, Bin &, int, REAL ); 163 void findIrregularS( Bin & ); 164 void findIrregularT( Bin & ); 165 166 167 inline int bbox( TrimVertex *, TrimVertex *, TrimVertex *, int ); 168 static int bbox( REAL, REAL, REAL, REAL, REAL, REAL ); 169 static int ccw( TrimVertex *, TrimVertex *, TrimVertex * ); 170 void join_s( Bin &, Bin &, Arc_ptr, Arc_ptr ); 171 void join_t( Bin &, Bin &, Arc_ptr , Arc_ptr ); 172 int arc_split( Arc_ptr , int, REAL, int ); 173 void check_s( Arc_ptr , Arc_ptr ); 174 void check_t( Arc_ptr , Arc_ptr ); 175 inline void link( Arc_ptr , Arc_ptr , Arc_ptr , Arc_ptr ); 176 inline void simple_link( Arc_ptr , Arc_ptr ); 177 178 Bin* makePatchBoundary( const REAL *from, const REAL *to ); 179 180 /*in domain distance method, the tessellation is controled by two numbers: 181 *GLU_U_STEP: number of u-segments per unit u length of domain 182 *GLU_V_STEP: number of v-segments per unit v length of domain 183 *These two numbers are normally stored in mapdesc->maxs(t)rate. 184 *I (ZL) put these two numbers here so that I can optimize the untrimmed 185 *case in the case of domain distance sampling. 186 *These two numbers are set by set_domain_distance_u_rate() and ..._v_..(). 187 */ 188 REAL domain_distance_u_rate; 189 REAL domain_distance_v_rate; 190 int is_domain_distance_sampling; 191 }; 192 193 inline void 194 Subdivider::beginLoop( void ) 195 { 196 pjarc = 0; 197 } 198 199 200 #endif /* __glusubdivider_h_ */ 201