Debian Codegraph @

lib/database/src/so/nodes/nurbs/libnurbs/hull.c++

raw
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 * hull.c++ - $Revision: 1.1.1.1 $
39 * Derrick Burns - 1991
40 */
41
42 #include "glimports.h"
43 #include "myassert.h"
44 #include "mystdio.h"
45 #include "hull.h"
46 #include "gridvertex.h"
47 #include "gridtrimvertex.h"
48 #include "gridline.h"
49 #include "trimline.h"
50 #include "uarray.h"
51 #include "trimregion.h"
52
53 Hull::Hull( void )
54 {}
55
56 Hull::~Hull( void )
57 {}
58
59 /*----------------------------------------------------------------------
60 * Hull:init - this routine does the initialization needed before any
61 * calls to nextupper or nextlower can be made.
62 *----------------------------------------------------------------------
63 */
64 void
65 Hull::init( void )
66 {
67 TrimVertex *lfirst = left.first();
68 TrimVertex *llast = left.last();
69 if( lfirst->param[0] <= llast->param[0] ) {
70 fakeleft.init( left.first() );
71 upper.left = &fakeleft;
72 lower.left = &left;
73 } else {
74 fakeleft.init( left.last() );
75 lower.left = &fakeleft;
76 upper.left = &left;
77 }
78 upper.left->last();
79 lower.left->first();
80
81 if( top.ustart <= top.uend ) {
82 upper.line = &top;
83 upper.index = top.ustart;
84 } else
85 upper.line = 0;
86
87 if( bot.ustart <= bot.uend ) {
88 lower.line = &bot;
89 lower.index = bot.ustart;
90 } else
91 lower.line = 0;
92
93 TrimVertex *rfirst = right.first();
94 TrimVertex *rlast = right.last();
95 if( rfirst->param[0] <= rlast->param[0] ) {
96 fakeright.init( right.last() );
97 lower.right = &fakeright;
98 upper.right = &right;
99 } else {
100 fakeright.init( right.first() );
101 upper.right = &fakeright;
102 lower.right = &right;
103 }
104 upper.right->first();
105 lower.right->last();
106 }
107
108 /*----------------------------------------------------------------------
109 * nextupper - find next vertex on upper hull of trim region.
110 * - if vertex is on trim curve, set vtop point to
111 * that vertex. if vertex is on grid, set vtop to
112 * point to temporary area and stuff coordinants into
113 * temporary vertex. Also, place grid coords in temporary
114 * grid vertex.
115 *----------------------------------------------------------------------
116 */
117 GridTrimVertex *
118 Hull::nextupper( GridTrimVertex *gv )
119 {
120 if( upper.left ) {
121 gv->set( upper.left->prev() );
122 if( gv->isTrimVert() ) return gv;
123 upper.left = 0;
124 }
125
126 if( upper.line ) {
127 assert( upper.index <= upper.line->uend );
128 gv->set( uarray.uarray[upper.index], upper.line->vval );
129 gv->set( upper.index, upper.line->vindex );
130 if( upper.index++ == upper.line->uend ) upper.line = 0;
131 return gv;
132 }
133
134 if( upper.right ) {
135 gv->set( upper.right->next() );
136 if( gv->isTrimVert() ) return gv;
137 upper.right = 0;
138 }
139
140 return 0;
141 }
142
143 GridTrimVertex *
144 Hull::nextlower( register GridTrimVertex *gv )
145 {
146 if( lower.left ) {
147 gv->set( lower.left->next() );
148 if( gv->isTrimVert() ) return gv;
149 lower.left = 0;
150 }
151
152 if( lower.line ) {
153 gv->set( uarray.uarray[lower.index], lower.line->vval );
154 gv->set( lower.index, lower.line->vindex );
155 if( lower.index++ == lower.line->uend ) lower.line = 0;
156 return gv;
157 }
158
159 if( lower.right ) {
160 gv->set( lower.right->prev() );
161 if( gv->isTrimVert() ) return gv;
162 lower.right = 0;
163 }
164
165 return 0;
166 }
167