| 1 | /* $Id: arc.cpp,v 1.1 2000-02-09 08:50:20 jeroen Exp $ */
|
|---|
| 2 | /*
|
|---|
| 3 | ** License Applicability. Except to the extent portions of this file are
|
|---|
| 4 | ** made subject to an alternative license as permitted in the SGI Free
|
|---|
| 5 | ** Software License B, Version 1.0 (the "License"), the contents of this
|
|---|
| 6 | ** file are subject only to the provisions of the License. You may not use
|
|---|
| 7 | ** this file except in compliance with the License. You may obtain a copy
|
|---|
| 8 | ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
|
|---|
| 9 | ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
|
|---|
| 10 | **
|
|---|
| 11 | ** http://oss.sgi.com/projects/FreeB
|
|---|
| 12 | **
|
|---|
| 13 | ** Note that, as provided in the License, the Software is distributed on an
|
|---|
| 14 | ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
|
|---|
| 15 | ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
|
|---|
| 16 | ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
|
|---|
| 17 | ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
|
|---|
| 18 | **
|
|---|
| 19 | ** Original Code. The Original Code is: OpenGL Sample Implementation,
|
|---|
| 20 | ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
|
|---|
| 21 | ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
|
|---|
| 22 | ** Copyright in any portions created by third parties is as indicated
|
|---|
| 23 | ** elsewhere herein. All Rights Reserved.
|
|---|
| 24 | **
|
|---|
| 25 | ** Additional Notice Provisions: The application programming interfaces
|
|---|
| 26 | ** established by SGI in conjunction with the Original Code are The
|
|---|
| 27 | ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
|
|---|
| 28 | ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
|
|---|
| 29 | ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
|
|---|
| 30 | ** Window System(R) (Version 1.3), released October 19, 1998. This software
|
|---|
| 31 | ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
|
|---|
| 32 | ** published by SGI, but has not been independently verified as being
|
|---|
| 33 | ** compliant with the OpenGL(R) version 1.2.1 Specification.
|
|---|
| 34 | */
|
|---|
| 35 |
|
|---|
| 36 | /*
|
|---|
| 37 | * arc.c++
|
|---|
| 38 | *
|
|---|
| 39 | * $Date: 2000-02-09 08:50:20 $ $Revision: 1.1 $
|
|---|
| 40 | * $Header: /home/ktk/tmp/odin/2007/netlabs.cvs/odin32/src/opengl/glu/nurbs/internals/arc.cpp,v 1.1 2000-02-09 08:50:20 jeroen Exp $
|
|---|
| 41 | */
|
|---|
| 42 |
|
|---|
| 43 | #include <stdio.h>
|
|---|
| 44 | #include "glimports.h"
|
|---|
| 45 | #include "mystdio.h"
|
|---|
| 46 | #include "myassert.h"
|
|---|
| 47 | #include "arc.h"
|
|---|
| 48 | #include "bin.h"
|
|---|
| 49 | #include "bezierarc.h"
|
|---|
| 50 | #include "pwlarc.h"
|
|---|
| 51 | #include "simplemath.h"
|
|---|
| 52 |
|
|---|
| 53 | /* local preprocessor definitions */
|
|---|
| 54 | #define ZERO 0.00001/*0.000001*/
|
|---|
| 55 |
|
|---|
| 56 | const int Arc::bezier_tag = (1<<13);
|
|---|
| 57 | const int Arc::arc_tag = (1<<3);
|
|---|
| 58 | const int Arc::tail_tag = (1<<6);
|
|---|
| 59 |
|
|---|
| 60 | /*--------------------------------------------------------------------------
|
|---|
| 61 | * makeSide - attach a pwl arc to an arc and mark it as a border arc
|
|---|
| 62 | *--------------------------------------------------------------------------
|
|---|
| 63 | */
|
|---|
| 64 |
|
|---|
| 65 | void
|
|---|
| 66 | Arc::makeSide( PwlArc *pwl, arc_side side )
|
|---|
| 67 | {
|
|---|
| 68 | assert( pwl != 0);
|
|---|
| 69 | assert( pwlArc == 0 );
|
|---|
| 70 | assert( pwl->npts > 0 );
|
|---|
| 71 | assert( pwl->pts != 0);
|
|---|
| 72 | pwlArc = pwl;
|
|---|
| 73 | clearbezier();
|
|---|
| 74 | setside( side );
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 | /*--------------------------------------------------------------------------
|
|---|
| 79 | * numpts - count number of points on arc loop
|
|---|
| 80 | *--------------------------------------------------------------------------
|
|---|
| 81 | */
|
|---|
| 82 |
|
|---|
| 83 | int
|
|---|
| 84 | Arc::numpts( void )
|
|---|
| 85 | {
|
|---|
| 86 | Arc_ptr jarc = this;
|
|---|
| 87 | int npts = 0;
|
|---|
| 88 | do {
|
|---|
| 89 | npts += jarc->pwlArc->npts;
|
|---|
| 90 | jarc = jarc->next;
|
|---|
| 91 | } while( jarc != this );
|
|---|
| 92 | return npts;
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | /*--------------------------------------------------------------------------
|
|---|
| 96 | * markverts - mark each point with id of arc
|
|---|
| 97 | *--------------------------------------------------------------------------
|
|---|
| 98 | */
|
|---|
| 99 |
|
|---|
| 100 | void
|
|---|
| 101 | Arc::markverts( void )
|
|---|
| 102 | {
|
|---|
| 103 | Arc_ptr jarc = this;
|
|---|
| 104 |
|
|---|
| 105 | do {
|
|---|
| 106 | TrimVertex *p = jarc->pwlArc->pts;
|
|---|
| 107 | for( int i=0; i<jarc->pwlArc->npts; i++ )
|
|---|
| 108 | p[i].nuid = jarc->nuid;
|
|---|
| 109 | jarc = jarc->next;
|
|---|
| 110 | } while( jarc != this );
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | /*--------------------------------------------------------------------------
|
|---|
| 114 | * getextrema - find axis extrema on arc loop
|
|---|
| 115 | *--------------------------------------------------------------------------
|
|---|
| 116 | */
|
|---|
| 117 |
|
|---|
| 118 | void
|
|---|
| 119 | Arc::getextrema( Arc_ptr extrema[4] )
|
|---|
| 120 | {
|
|---|
| 121 | REAL leftpt, botpt, rightpt, toppt;
|
|---|
| 122 |
|
|---|
| 123 | extrema[0] = extrema[1] = extrema[2] = extrema[3] = this;
|
|---|
| 124 |
|
|---|
| 125 | leftpt = rightpt = this->tail()[0];
|
|---|
| 126 | botpt = toppt = this->tail()[1];
|
|---|
| 127 |
|
|---|
| 128 | for( Arc_ptr jarc = this->next; jarc != this; jarc = jarc->next ) {
|
|---|
| 129 | if ( jarc->tail()[0] < leftpt ||
|
|---|
| 130 | (jarc->tail()[0] <= leftpt && jarc->rhead()[0]<=leftpt)) {
|
|---|
| 131 | leftpt = jarc->pwlArc->pts->param[0];
|
|---|
| 132 | extrema[1] = jarc;
|
|---|
| 133 | }
|
|---|
| 134 | if ( jarc->tail()[0] > rightpt ||
|
|---|
| 135 | (jarc->tail()[0] >= rightpt && jarc->rhead()[0] >= rightpt)) {
|
|---|
| 136 | rightpt = jarc->pwlArc->pts->param[0];
|
|---|
| 137 | extrema[3] = jarc;
|
|---|
| 138 | }
|
|---|
| 139 | if ( jarc->tail()[1] < botpt ||
|
|---|
| 140 | (jarc->tail()[1] <= botpt && jarc->rhead()[1] <= botpt )) {
|
|---|
| 141 | botpt = jarc->pwlArc->pts->param[1];
|
|---|
| 142 | extrema[2] = jarc;
|
|---|
| 143 | }
|
|---|
| 144 | if ( jarc->tail()[1] > toppt ||
|
|---|
| 145 | (jarc->tail()[1] >= toppt && jarc->rhead()[1] >= toppt)) {
|
|---|
| 146 | toppt = jarc->pwlArc->pts->param[1];
|
|---|
| 147 | extrema[0] = jarc;
|
|---|
| 148 | }
|
|---|
| 149 | }
|
|---|
| 150 | }
|
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 | /*-------------------------------------------------------------------------
|
|---|
| 154 | * show - print to the stdout the vertices of a pwl arc
|
|---|
| 155 | *-------------------------------------------------------------------------
|
|---|
| 156 | */
|
|---|
| 157 |
|
|---|
| 158 | void
|
|---|
| 159 | Arc::show()
|
|---|
| 160 | {
|
|---|
| 161 | #ifndef NDEBUG
|
|---|
| 162 | dprintf( "\tPWLARC NP: %d FL: 1\n", pwlArc->npts );
|
|---|
| 163 | for( int i = 0; i < pwlArc->npts; i++ ) {
|
|---|
| 164 | dprintf( "\t\tVERTEX %f %f\n", pwlArc->pts[i].param[0],
|
|---|
| 165 | pwlArc->pts[i].param[1] );
|
|---|
| 166 | }
|
|---|
| 167 | #endif
|
|---|
| 168 | }
|
|---|
| 169 |
|
|---|
| 170 | /*-------------------------------------------------------------------------
|
|---|
| 171 | * print - print out the vertices of all pwl arcs on a loop
|
|---|
| 172 | *-------------------------------------------------------------------------
|
|---|
| 173 | */
|
|---|
| 174 |
|
|---|
| 175 | void
|
|---|
| 176 | Arc::print( void )
|
|---|
| 177 | {
|
|---|
| 178 | Arc_ptr jarc = this;
|
|---|
| 179 |
|
|---|
| 180 | if( ! this ) {
|
|---|
| 181 | #ifndef NDEBUG
|
|---|
| 182 | dprintf( "\n\nEMPTY TRIM\n\n" );
|
|---|
| 183 | #endif
|
|---|
| 184 | return;
|
|---|
| 185 | }
|
|---|
| 186 |
|
|---|
| 187 | #ifndef NDEBUG
|
|---|
| 188 | dprintf( "BGNTRIM\n" );
|
|---|
| 189 | #endif
|
|---|
| 190 | do {
|
|---|
| 191 | jarc->show( );
|
|---|
| 192 | jarc = jarc->next;
|
|---|
| 193 | } while (jarc != this);
|
|---|
| 194 | #ifndef NDEBUG
|
|---|
| 195 | dprintf("ENDTRIM\n" );
|
|---|
| 196 | #endif
|
|---|
| 197 | }
|
|---|
| 198 |
|
|---|
| 199 | /*-------------------------------------------------------------------------
|
|---|
| 200 | * isDisconnected - check if tail of arc and head of prev meet
|
|---|
| 201 | *-------------------------------------------------------------------------
|
|---|
| 202 | */
|
|---|
| 203 |
|
|---|
| 204 | int
|
|---|
| 205 | Arc::isDisconnected( void )
|
|---|
| 206 | {
|
|---|
| 207 | if( pwlArc == 0 ) return 0;
|
|---|
| 208 | if( prev->pwlArc == 0 ) return 0;
|
|---|
| 209 |
|
|---|
| 210 | REAL *p0 = tail();
|
|---|
| 211 | REAL *p1 = prev->rhead();
|
|---|
| 212 |
|
|---|
| 213 | if( ((p0[0] - p1[0]) > ZERO) || ((p1[0] - p0[0]) > ZERO) ||
|
|---|
| 214 | ((p0[1] - p1[1]) > ZERO) || ((p1[1] - p0[1]) > ZERO) ) {
|
|---|
| 215 | #ifndef NDEBUG
|
|---|
| 216 | dprintf( "x coord = %f %f %f\n", p0[0], p1[0], p0[0] - p1[0] );
|
|---|
| 217 | dprintf( "y coord = %f %f %f\n", p0[1], p1[1], p0[1] - p1[1] );
|
|---|
| 218 | #endif
|
|---|
| 219 | return 1;
|
|---|
| 220 | } else {
|
|---|
| 221 | /* average two points together */
|
|---|
| 222 | p0[0] = p1[0] = (p1[0] + p0[0]) * 0.5;
|
|---|
| 223 | p0[1] = p1[1] = (p1[1] + p0[1]) * 0.5;
|
|---|
| 224 | return 0;
|
|---|
| 225 | }
|
|---|
| 226 | }
|
|---|
| 227 |
|
|---|
| 228 | /*-------------------------------------------------------------------------
|
|---|
| 229 | * neq_vert - assert that two 2D vertices are not equal
|
|---|
| 230 | *-------------------------------------------------------------------------
|
|---|
| 231 | */
|
|---|
| 232 |
|
|---|
| 233 | inline static int
|
|---|
| 234 | neq_vert( REAL *v1, REAL *v2 )
|
|---|
| 235 | {
|
|---|
| 236 | return ((v1[0] != v2[0]) || (v1[1] != v2[1] )) ? 1 : 0;
|
|---|
| 237 | }
|
|---|
| 238 |
|
|---|
| 239 | /*-------------------------------------------------------------------------
|
|---|
| 240 | * check - verify consistency of a loop, including
|
|---|
| 241 | * 1) if pwl, no two consecutive vertices are identical
|
|---|
| 242 | * 2) the circular link pointers are valid
|
|---|
| 243 | * 3) the geometric info at the head and tail are consistent
|
|---|
| 244 | *-------------------------------------------------------------------------
|
|---|
| 245 | */
|
|---|
| 246 |
|
|---|
| 247 | int
|
|---|
| 248 | Arc::check( void )
|
|---|
| 249 | {
|
|---|
| 250 | if( this == 0 ) return 1;
|
|---|
| 251 | Arc_ptr jarc = this;
|
|---|
| 252 | do {
|
|---|
| 253 | assert( (jarc->pwlArc != 0) || (jarc->bezierArc != 0) );
|
|---|
| 254 |
|
|---|
| 255 | if (jarc->prev == 0 || jarc->next == 0) {
|
|---|
| 256 | #ifndef NDEBUG
|
|---|
| 257 | dprintf( "checkjarc:null next/prev pointer\n");
|
|---|
| 258 | jarc->print( );
|
|---|
| 259 | #endif
|
|---|
| 260 | return 0;
|
|---|
| 261 | }
|
|---|
| 262 |
|
|---|
| 263 | if (jarc->next->prev != jarc) {
|
|---|
| 264 | #ifndef NDEBUG
|
|---|
| 265 | dprintf( "checkjarc: pointer linkage screwed up\n");
|
|---|
| 266 | jarc->print( );
|
|---|
| 267 | #endif
|
|---|
| 268 | return 0;
|
|---|
| 269 | }
|
|---|
| 270 |
|
|---|
| 271 | if( jarc->pwlArc ) {
|
|---|
| 272 | #ifndef NDEBUG
|
|---|
| 273 | assert( jarc->pwlArc->npts >= 1 );
|
|---|
| 274 | assert( jarc->pwlArc->npts < 100000 );
|
|---|
| 275 | /*
|
|---|
| 276 | for( int i=0; i < jarc->pwlArc->npts-1; i++ )
|
|---|
| 277 | assert( neq_vert( jarc->pwlArc->pts[i].param,
|
|---|
| 278 | jarc->pwlArc->pts[i+1].param) );
|
|---|
| 279 | */
|
|---|
| 280 | #endif
|
|---|
| 281 | if( jarc->prev->pwlArc ) {
|
|---|
| 282 | if( jarc->tail()[1] != jarc->prev->rhead()[1] ) {
|
|---|
| 283 | #ifndef NDEBUG
|
|---|
| 284 | dprintf( "checkjarc: geometric linkage screwed up 1\n");
|
|---|
| 285 | jarc->prev->show();
|
|---|
| 286 | jarc->show();
|
|---|
| 287 | #endif
|
|---|
| 288 | return 0;
|
|---|
| 289 | }
|
|---|
| 290 | if( jarc->tail()[0] != jarc->prev->rhead()[0] ) {
|
|---|
| 291 |
|
|---|
| 292 | #ifndef NDEBUG
|
|---|
| 293 | dprintf( "checkjarc: geometric linkage screwed up 2\n");
|
|---|
| 294 | jarc->prev->show();
|
|---|
| 295 | jarc->show();
|
|---|
| 296 | #endif
|
|---|
| 297 | return 0;
|
|---|
| 298 | }
|
|---|
| 299 | }
|
|---|
| 300 | if( jarc->next->pwlArc ) {
|
|---|
| 301 | if( jarc->next->tail()[0] != jarc->rhead()[0] ) {
|
|---|
| 302 | #ifndef NDEBUG
|
|---|
| 303 | dprintf( "checkjarc: geometric linkage screwed up 3\n");
|
|---|
| 304 | jarc->show();
|
|---|
| 305 | jarc->next->show();
|
|---|
| 306 | #endif
|
|---|
| 307 | return 0;
|
|---|
| 308 | }
|
|---|
| 309 | if( jarc->next->tail()[1] != jarc->rhead()[1] ) {
|
|---|
| 310 | #ifndef NDEBUG
|
|---|
| 311 | dprintf( "checkjarc: geometric linkage screwed up 4\n");
|
|---|
| 312 | jarc->show();
|
|---|
| 313 | jarc->next->show();
|
|---|
| 314 | #endif
|
|---|
| 315 | return 0;
|
|---|
| 316 | }
|
|---|
| 317 | }
|
|---|
| 318 | if( jarc->isbezier() ) {
|
|---|
| 319 | assert( jarc->pwlArc->npts == 2 );
|
|---|
| 320 | assert( (jarc->pwlArc->pts[0].param[0] == \
|
|---|
| 321 | jarc->pwlArc->pts[1].param[0]) ||\
|
|---|
| 322 | (jarc->pwlArc->pts[0].param[1] == \
|
|---|
| 323 | jarc->pwlArc->pts[1].param[1]) );
|
|---|
| 324 | }
|
|---|
| 325 | }
|
|---|
| 326 | jarc = jarc->next;
|
|---|
| 327 | } while (jarc != this);
|
|---|
| 328 | return 1;
|
|---|
| 329 | }
|
|---|
| 330 |
|
|---|
| 331 |
|
|---|
| 332 | #define TOL 0.00001
|
|---|
| 333 |
|
|---|
| 334 | inline long tooclose( REAL x, REAL y )
|
|---|
| 335 | {
|
|---|
| 336 | return (abs(x-y) < TOL) ? 1 : 0;
|
|---|
| 337 | }
|
|---|
| 338 |
|
|---|
| 339 |
|
|---|
| 340 | /*--------------------------------------------------------------------------
|
|---|
| 341 | * append - append a jordan arc to a circularly linked list
|
|---|
| 342 | *--------------------------------------------------------------------------
|
|---|
| 343 | */
|
|---|
| 344 |
|
|---|
| 345 | Arc_ptr
|
|---|
| 346 | Arc::append( Arc_ptr jarc )
|
|---|
| 347 | {
|
|---|
| 348 | if( jarc != 0 ) {
|
|---|
| 349 | next = jarc->next;
|
|---|
| 350 | prev = jarc;
|
|---|
| 351 | next->prev = prev->next = this;
|
|---|
| 352 | } else {
|
|---|
| 353 | next = prev = this;
|
|---|
| 354 | }
|
|---|
| 355 | return this;
|
|---|
| 356 | }
|
|---|
| 357 |
|
|---|