Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygensplitarcs.cc
Go to the documentation of this file.
00001 /* 00002 ** License Applicability. Except to the extent portions of this file are 00003 ** made subject to an alternative license as permitted in the SGI Free 00004 ** Software License B, Version 1.1 (the "License"), the contents of this 00005 ** file are subject only to the provisions of the License. You may not use 00006 ** this file except in compliance with the License. You may obtain a copy 00007 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 00008 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: 00009 ** 00010 ** http://oss.sgi.com/projects/FreeB 00011 ** 00012 ** Note that, as provided in the License, the Software is distributed on an 00013 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS 00014 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND 00015 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A 00016 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. 00017 ** 00018 ** Original Code. The Original Code is: OpenGL Sample Implementation, 00019 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, 00020 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. 00021 ** Copyright in any portions created by third parties is as indicated 00022 ** elsewhere herein. All Rights Reserved. 00023 ** 00024 ** Additional Notice Provisions: The application programming interfaces 00025 ** established by SGI in conjunction with the Original Code are The 00026 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released 00027 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version 00028 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X 00029 ** Window System(R) (Version 1.3), released October 19, 1998. This software 00030 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation 00031 ** published by SGI, but has not been independently verified as being 00032 ** compliant with the OpenGL(R) version 1.2.1 Specification. 00033 */ 00034 00035 /* 00036 * splitarcs.c++ 00037 * 00038 * $Date: 2006-03-12 00:07:02 +0000 (Sun, 12 Mar 2006) $ $Revision: 1.1 $ 00039 * $Header: /cygdrive/c/RCVS/CVS/ReactOS/reactos/lib/glu32/libnurbs/internals/splitarcs.cc,v 1.1 2004/02/02 16:39:12 navaraf Exp $ 00040 */ 00041 00042 #include "glimports.h" 00043 #include "myassert.h" 00044 #include "mysetjmp.h" 00045 #include "mystdio.h" 00046 #include "subdivider.h" 00047 #include "arcsorter.h" 00048 #include "arc.h" 00049 #include "bin.h" 00050 00051 /* local preprocessor definitions */ 00052 #define MAXARCS 10 00053 00054 /*---------------------------------------------------------------------------- 00055 * Subdivider::split - split trim regions in source bin by line (param == value). 00056 *---------------------------------------------------------------------------- 00057 */ 00058 00059 void 00060 Subdivider::split( Bin& bin, Bin& left, Bin& right, int param, REAL value ) 00061 { 00062 Bin intersections, unknown; 00063 00064 partition( bin, left, intersections, right, unknown, param, value ); 00065 00066 int count = intersections.numarcs(); 00067 if( count % 2 ) { 00068 #ifndef NDEBUG 00069 left.show( "left" ); 00070 intersections.show( "intersections" ); 00071 right.show( "right" ); 00072 #endif 00073 ::mylongjmp( jumpbuffer, 29 ); 00074 } 00075 00076 Arc_ptr arclist[MAXARCS], *list; 00077 if( count >= MAXARCS ) { 00078 list = new Arc_ptr[count]; 00079 } else { 00080 list = arclist; 00081 } 00082 00083 Arc_ptr jarc, *last, *lptr; 00084 for( last = list; (jarc=intersections.removearc()) != NULL; last++ ) 00085 *last = jarc; 00086 00087 if( param == 0 ) { /* sort into increasing t order */ 00088 ArcSdirSorter sorter(*this); 00089 sorter.qsort( list, count ); 00090 00091 //::qsort ((void *)list, count, sizeof(Arc_ptr), (cmpfunc)compare_s); 00092 for( lptr=list; lptr<last; lptr+=2 ) 00093 check_s ( lptr[0], lptr[1] ); 00094 for( lptr=list; lptr<last; lptr+=2 ) 00095 join_s ( left, right, lptr[0], lptr[1] ); 00096 for( lptr=list; lptr != last; lptr++ ) { 00097 if( ((*lptr)->head()[0] <= value) && ((*lptr)->tail()[0] <= value) ) 00098 left.addarc( *lptr ); 00099 else 00100 right.addarc( *lptr ); 00101 } 00102 } else { /* sort into decreasing s order */ 00103 ArcTdirSorter sorter(*this); 00104 sorter.qsort( list, count ); 00105 //::qsort ((void *)list, count, sizeof(Arc_ptr), (cmpfunc)compare_t); 00106 for( lptr=list; lptr<last; lptr+=2 ) 00107 check_t ( lptr[0], lptr[1] ); 00108 for( lptr=list; lptr<last; lptr+=2 ) 00109 join_t ( left, right, lptr[0], lptr[1] ); 00110 for( lptr=list; lptr != last; lptr++ ) { 00111 if( ((*lptr)->head()[1] <= value) && ((*lptr)->tail()[1] <= value) ) 00112 left.addarc( *lptr ); 00113 else 00114 right.addarc( *lptr ); 00115 } 00116 } 00117 00118 if( list != arclist ) delete[] list; 00119 unknown.adopt(); 00120 } 00121 00122 00123 void 00124 Subdivider::check_s( Arc_ptr jarc1, Arc_ptr jarc2 ) 00125 { 00126 assert( jarc1->check( ) != 0 ); 00127 assert( jarc2->check( ) != 0 ); 00128 assert( jarc1->next->check( ) != 0 ); 00129 assert( jarc2->next->check( ) != 0 ); 00130 assert( jarc1 != jarc2 ); 00131 00132 /* XXX - if these assertions fail, it is due to user error or 00133 undersampling */ 00134 if( ! ( jarc1->tail()[0] < (jarc1)->head()[0] ) ) { 00135 #ifndef NDEBUG 00136 dprintf( "s difference %f\n", (jarc1)->tail()[0] - (jarc1)->head()[0] ); 00137 #endif 00138 ::mylongjmp( jumpbuffer, 28 ); 00139 } 00140 00141 if( ! ( jarc2->tail()[0] > (jarc2)->head()[0] ) ) { 00142 #ifndef NDEBUG 00143 dprintf( "s difference %f\n", (jarc2)->tail()[0] - (jarc2)->head()[0] ); 00144 #endif 00145 ::mylongjmp( jumpbuffer, 28 ); 00146 } 00147 } 00148 00149 inline void 00150 Subdivider::link( Arc_ptr jarc1, Arc_ptr jarc2, Arc_ptr up, Arc_ptr down ) 00151 { 00152 up->nuid = down->nuid = 0; // XXX 00153 00154 up->next = jarc2; 00155 down->next = jarc1; 00156 up->prev = jarc1->prev; 00157 down->prev = jarc2->prev; 00158 00159 down->next->prev = down; 00160 up->next->prev = up; 00161 down->prev->next = down; 00162 up->prev->next = up; 00163 } 00164 00165 inline void 00166 Subdivider::simple_link( Arc_ptr jarc1, Arc_ptr jarc2 ) 00167 { 00168 Arc_ptr tmp = jarc2->prev; 00169 jarc2->prev = jarc1->prev; 00170 jarc1->prev = tmp; 00171 jarc2->prev->next = jarc2; 00172 jarc1->prev->next = jarc1; 00173 } 00174 00175 00176 /*---------------------------------------------------------------------------- 00177 * join - add a pair of oppositely directed jordan arcs between two arcs 00178 *---------------------------------------------------------------------------- 00179 */ 00180 00181 void 00182 Subdivider::join_s( Bin& left, Bin& right, Arc_ptr jarc1, Arc_ptr jarc2 ) 00183 { 00184 assert( jarc1->check( ) != 0); 00185 assert( jarc2->check( ) != 0); 00186 assert( jarc1 != jarc2 ); 00187 00188 if( ! jarc1->getitail() ) 00189 jarc1 = jarc1->next; 00190 00191 if( ! jarc2->getitail() ) 00192 jarc2 = jarc2->next; 00193 00194 REAL s = jarc1->tail()[0]; 00195 REAL t1 = jarc1->tail()[1]; 00196 REAL t2 = jarc2->tail()[1]; 00197 00198 if( t1 == t2 ) { 00199 simple_link( jarc1, jarc2 ); 00200 } else { 00201 Arc_ptr newright = new(arcpool) Arc( arc_right, 0 ); 00202 Arc_ptr newleft = new(arcpool) Arc( arc_left, 0 ); 00203 assert( t1 < t2 ); 00204 if( isBezierArcType() ) { 00205 arctessellator.bezier( newright, s, s, t1, t2 ); 00206 arctessellator.bezier( newleft, s, s, t2, t1 ); 00207 } else { 00208 arctessellator.pwl_right( newright, s, t1, t2, stepsizes[0] ); 00209 arctessellator.pwl_left( newleft, s, t2, t1, stepsizes[2] ); 00210 } 00211 link( jarc1, jarc2, newright, newleft ); 00212 left.addarc( newright ); 00213 right.addarc( newleft ); 00214 } 00215 00216 assert( jarc1->check( ) != 0 ); 00217 assert( jarc2->check( ) != 0 ); 00218 assert( jarc1->next->check( ) != 0); 00219 assert( jarc2->next->check( ) != 0); 00220 } 00221 00222 void 00223 Subdivider::check_t( Arc_ptr jarc1, Arc_ptr jarc2 ) 00224 { 00225 assert( jarc1->check( ) != 0 ); 00226 assert( jarc2->check( ) != 0 ); 00227 assert( jarc1->next->check( ) != 0 ); 00228 assert( jarc2->next->check( ) != 0 ); 00229 assert( jarc1 != jarc2 ); 00230 00231 /* XXX - if these assertions fail, it is due to user error or 00232 undersampling */ 00233 if( ! ( jarc1->tail()[1] < (jarc1)->head()[1] ) ) { 00234 #ifndef NDEBUG 00235 dprintf( "t difference %f\n", jarc1->tail()[1] - (jarc1)->head()[1] ); 00236 #endif 00237 ::mylongjmp( jumpbuffer, 28 ); 00238 } 00239 00240 if( ! ( jarc2->tail()[1] > (jarc2)->head()[1] ) ) { 00241 #ifndef NDEBUG 00242 dprintf( "t difference %f\n", jarc2->tail()[1] - (jarc2)->head()[1] ); 00243 #endif 00244 ::mylongjmp( jumpbuffer, 28 ); 00245 } 00246 } 00247 00248 /*---------------------------------------------------------------------------- 00249 * join_t - add a pair of oppositely directed jordan arcs between two arcs 00250 *---------------------------------------------------------------------------- 00251 */ 00252 00253 void 00254 Subdivider::join_t( Bin& bottom, Bin& top, Arc_ptr jarc1, Arc_ptr jarc2 ) 00255 { 00256 assert( jarc1->check( ) != 0 ); 00257 assert( jarc2->check( ) != 0 ); 00258 assert( jarc1->next->check( ) != 0 ); 00259 assert( jarc2->next->check( ) != 0 ); 00260 assert( jarc1 != jarc2 ); 00261 00262 if( ! jarc1->getitail() ) 00263 jarc1 = jarc1->next; 00264 00265 if( ! jarc2->getitail() ) 00266 jarc2 = jarc2->next; 00267 00268 REAL s1 = jarc1->tail()[0]; 00269 REAL s2 = jarc2->tail()[0]; 00270 REAL t = jarc1->tail()[1]; 00271 00272 if( s1 == s2 ) { 00273 simple_link( jarc1, jarc2 ); 00274 } else { 00275 Arc_ptr newtop = new(arcpool) Arc( arc_top, 0 ); 00276 Arc_ptr newbot = new(arcpool) Arc( arc_bottom, 0 ); 00277 assert( s1 > s2 ); 00278 if( isBezierArcType() ) { 00279 arctessellator.bezier( newtop, s1, s2, t, t ); 00280 arctessellator.bezier( newbot, s2, s1, t, t ); 00281 } else { 00282 arctessellator.pwl_top( newtop, t, s1, s2, stepsizes[1] ); 00283 arctessellator.pwl_bottom( newbot, t, s2, s1, stepsizes[3] ); 00284 } 00285 link( jarc1, jarc2, newtop, newbot ); 00286 bottom.addarc( newtop ); 00287 top.addarc( newbot ); 00288 } 00289 00290 assert( jarc1->check( ) != 0 ); 00291 assert( jarc2->check( ) != 0 ); 00292 assert( jarc1->next->check( ) != 0 ); 00293 assert( jarc2->next->check( ) != 0 ); 00294 } 00295 Generated on Fri May 25 2012 04:21:55 for ReactOS by
1.7.6.1
|