Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenmonotonizer.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 * monotonizer.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/monotonizer.cc,v 1.1 2004/02/02 16:39:12 navaraf Exp $ 00040 */ 00041 00042 #include "glimports.h" 00043 #include "mystdio.h" 00044 #include "myassert.h" 00045 #include "arc.h" 00046 #include "arctess.h" 00047 #include "bezierarc.h" 00048 #include "bin.h" 00049 #include "mapdesc.h" 00050 #include "nurbsconsts.h" 00051 #include "subdivider.h" 00052 00053 /*----------------------------------------------------------------------------- 00054 * Subdivider::decompose - break all curves into monotone arcs 00055 *----------------------------------------------------------------------------- 00056 */ 00057 int 00058 Subdivider::decompose( Bin& bin, REAL geo_stepsize ) 00059 { 00060 Arc_ptr jarc; 00061 for( jarc=bin.firstarc(); jarc; jarc=bin.nextarc() ) { 00062 if( ! jarc->isTessellated() ) { 00063 /* points have not been transformed, therefore they may be either 00064 homogeneous or inhomogeneous */ 00065 tessellate( jarc, geo_stepsize ); 00066 if( jarc->isDisconnected() || jarc->next->isDisconnected() ) 00067 return 1; 00068 } 00069 } 00070 00071 for( jarc=bin.firstarc(); jarc; jarc=bin.nextarc() ) { 00072 monotonize( jarc, bin ); 00073 } 00074 00075 #ifndef NDEBUG 00076 for( jarc=bin.firstarc(); jarc; jarc=bin.nextarc() ) { 00077 assert( isMonotone( jarc ) != 0 ); 00078 } 00079 #endif 00080 00081 return 0; 00082 } 00083 00084 void 00085 Subdivider::tessellate( Arc_ptr jarc, REAL geo_stepsize ) 00086 { 00087 BezierArc *b = jarc->bezierArc; 00088 Mapdesc *mapdesc = b->mapdesc; 00089 00090 if( mapdesc->isRational() ) { 00091 REAL max = mapdesc->calcVelocityRational( b->cpts, b->stride, b->order ); 00092 REAL arc_stepsize = (max > 1.0) ? (1.0/max) : 1.0; 00093 if( jarc->bezierArc->order != 2 ) 00094 arctessellator.tessellateNonlinear( jarc, geo_stepsize, arc_stepsize, 1 ); 00095 else { 00096 arctessellator.tessellateLinear( jarc, geo_stepsize, arc_stepsize, 1 ); 00097 } 00098 } else { 00099 REAL max = mapdesc->calcVelocityNonrational( b->cpts, b->stride, b->order ); 00100 REAL arc_stepsize = (max > 1.0) ? (1.0/max) : 1.0; 00101 if( jarc->bezierArc->order != 2 ) 00102 arctessellator.tessellateNonlinear( jarc, geo_stepsize, arc_stepsize, 0 ); 00103 else { 00104 arctessellator.tessellateLinear( jarc, geo_stepsize, arc_stepsize, 0 ); 00105 } 00106 } 00107 } 00108 00109 /*------------------------------------------------------------------------- 00110 * Subdivider::monotonize - break up a jordan arc into s,t-monotone 00111 * components. This code will remove degenerate segments, including 00112 * arcs of only a single point. 00113 *------------------------------------------------------------------------- 00114 */ 00115 void 00116 Subdivider::monotonize( Arc_ptr jarc, Bin& bin ) 00117 { 00118 TrimVertex *firstvert = jarc->pwlArc->pts; 00119 TrimVertex *lastvert = firstvert + (jarc->pwlArc->npts - 1); 00120 long uid = jarc->nuid; 00121 arc_side side = jarc->getside(); 00122 dir sdir = none; 00123 dir tdir = none; 00124 int degenerate = 1; 00125 00126 int nudegenerate; 00127 int change; 00128 00129 TrimVertex *vert; 00130 for( vert = firstvert; vert != lastvert; vert++ ) { 00131 00132 nudegenerate = 1; 00133 change = 0; 00134 00135 /* check change relative to s axis, clear degenerate bit if needed */ 00136 REAL sdiff = vert[1].param[0] - vert[0].param[0]; 00137 if( sdiff == 0 ) { 00138 if( sdir != same ) { 00139 sdir = same; 00140 change = 1; 00141 } 00142 } else if( sdiff < 0.0 ) { 00143 if( sdir != down ) { 00144 sdir = down; 00145 change = 1; 00146 } 00147 nudegenerate = 0; 00148 } else { 00149 if( sdir != up ) { 00150 sdir = up; 00151 change = 1; 00152 } 00153 nudegenerate = 0; 00154 } 00155 00156 /* check change relative to t axis, clear degenerate bit if needed */ 00157 REAL tdiff = vert[1].param[1] - vert[0].param[1]; 00158 if( tdiff == 0 ) { 00159 if( tdir != same ) { 00160 tdir = same; 00161 change = 1; 00162 } 00163 } else if( tdiff < 0.0 ) { 00164 if( tdir != down ) { 00165 tdir = down; 00166 change = 1; 00167 } 00168 nudegenerate = 0; 00169 } else { 00170 if( tdir != up ) { 00171 tdir = up; 00172 change = 1; 00173 } 00174 nudegenerate = 0; 00175 } 00176 00177 if( change ) { 00178 if( ! degenerate ) { 00179 /* make last segment into separate pwl curve */ 00180 jarc->pwlArc->npts = vert - firstvert + 1; 00181 jarc = (new(arcpool) Arc( side, uid ))->append( jarc ); 00182 jarc->pwlArc = new(pwlarcpool) PwlArc(); 00183 bin.addarc( jarc ); 00184 } 00185 firstvert = jarc->pwlArc->pts = vert; 00186 degenerate = nudegenerate; 00187 } 00188 } 00189 jarc->pwlArc->npts = vert - firstvert + 1; 00190 00191 if( degenerate ) { 00192 /* remove jarc from circularly linked list */ 00193 jarc->prev->next = jarc->next; 00194 jarc->next->prev = jarc->prev; 00195 00196 assert( jarc->prev->check( ) != 0 ); 00197 assert( jarc->next->check( ) != 0 ); 00198 00199 /* remove jarc from bin */ 00200 bin.remove_this_arc( jarc ); 00201 00202 jarc->pwlArc->deleteMe( pwlarcpool ); jarc->pwlArc = 0; 00203 jarc->deleteMe( arcpool ); 00204 } 00205 } 00206 00207 /*------------------------------------------------------------------------- 00208 * Subdivider::isMonotone - return true if arc is monotone AND non-degenerate 00209 *------------------------------------------------------------------------- 00210 */ 00211 int 00212 Subdivider::isMonotone( Arc_ptr jarc ) 00213 { 00214 TrimVertex *firstvert = jarc->pwlArc->pts; 00215 TrimVertex *lastvert = firstvert + (jarc->pwlArc->npts - 1); 00216 00217 if( firstvert == lastvert ) return 1; 00218 00219 TrimVertex *vert = firstvert; 00220 enum dir sdir; 00221 enum dir tdir; 00222 00223 REAL diff = vert[1].param[0] - vert[0].param[0]; 00224 if( diff == 0.0 ) 00225 sdir = same; 00226 else if( diff < 0.0 ) 00227 sdir = down; 00228 else 00229 sdir = up; 00230 00231 diff = vert[1].param[1] - vert[0].param[1]; 00232 if( diff == 0.0 ) 00233 tdir = same; 00234 else if( diff < 0.0 ) 00235 tdir = down; 00236 else 00237 tdir = up; 00238 00239 if( (sdir == same) && (tdir == same) ) return 0; 00240 00241 for( ++vert ; vert != lastvert; vert++ ) { 00242 diff = vert[1].param[0] - vert[0].param[0]; 00243 if( diff == 0.0 ) { 00244 if( sdir != same ) return 0; 00245 } else if( diff < 0.0 ) { 00246 if( sdir != down ) return 0; 00247 } else { 00248 if( sdir != up ) return 0; 00249 } 00250 00251 diff = vert[1].param[1] - vert[0].param[1]; 00252 if( diff == 0.0 ) { 00253 if( tdir != same ) return 0; 00254 } else if( diff < 0.0 ) { 00255 if( tdir != down ) return 0; 00256 } else { 00257 if( tdir != up ) return 0; 00258 } 00259 } 00260 return 1; 00261 } 00262 Generated on Fri May 25 2012 04:21:54 for ReactOS by
1.7.6.1
|