1 | /************************************************************************
|
---|
2 |
|
---|
3 | Primitive entities for adjacency models (AdjModel).
|
---|
4 | $Id: AdjPrims.cxx,v 1.1 1997/06/25 15:24:55 garland Exp $
|
---|
5 |
|
---|
6 | Adapted from:
|
---|
7 | mlab: (Id: primitives.cc,v 1.7 1997/02/06 16:32:45 garland Exp)
|
---|
8 | via
|
---|
9 | simplif: (Id: primitives.cc,v 1.2 1997/02/18 21:11:27 garland Exp)
|
---|
10 |
|
---|
11 | ************************************************************************/
|
---|
12 |
|
---|
13 | #include "AdjPrims.h"
|
---|
14 |
|
---|
15 | using namespace simplif;
|
---|
16 |
|
---|
17 | void Vertex::kill()
|
---|
18 | {
|
---|
19 | #ifdef SAFETY
|
---|
20 | assert( edge_uses.length() == 0 );
|
---|
21 | #endif
|
---|
22 | markInvalid();
|
---|
23 | edge_uses.reset();
|
---|
24 | }
|
---|
25 |
|
---|
26 | void Vertex::linkEdge(Edge *e)
|
---|
27 | {
|
---|
28 | edge_uses.add(e);
|
---|
29 | }
|
---|
30 |
|
---|
31 | void Vertex::unlinkEdge(Edge *e)
|
---|
32 | {
|
---|
33 | int index = edge_uses.find(e);
|
---|
34 |
|
---|
35 | #ifdef SAFETY
|
---|
36 | assert( index >= 0 );
|
---|
37 | #endif
|
---|
38 | edge_uses.remove(index);
|
---|
39 | if( edge_uses.length() <= 0 )
|
---|
40 | kill();
|
---|
41 | }
|
---|
42 |
|
---|
43 | #include <assert.h>
|
---|
44 |
|
---|
45 | void Vertex::remapTo(Vertex *v)
|
---|
46 | {
|
---|
47 | if ( v != this )
|
---|
48 | {
|
---|
49 | for (int i=0; i<edge_uses.length(); i++)
|
---|
50 | {
|
---|
51 | assert( edge_uses(i)->org() == this );
|
---|
52 | edge_uses(i)->remapEndpoint(this, v);
|
---|
53 | }
|
---|
54 |
|
---|
55 | kill();
|
---|
56 | }
|
---|
57 | }
|
---|
58 |
|
---|
59 | Edge::Edge(Vertex *a, Vertex *b)
|
---|
60 | {
|
---|
61 | v1 = a;
|
---|
62 | v1->linkEdge(this);
|
---|
63 |
|
---|
64 | face_uses = new buffer<Face *>(2);
|
---|
65 |
|
---|
66 | twin = new Edge(this, b);
|
---|
67 | }
|
---|
68 |
|
---|
69 | Edge::Edge(Edge *sibling, Vertex *org)
|
---|
70 | {
|
---|
71 | v1 = org;
|
---|
72 | v1->linkEdge(this);
|
---|
73 |
|
---|
74 | face_uses = sibling->face_uses;
|
---|
75 | twin = sibling;
|
---|
76 | }
|
---|
77 |
|
---|
78 | Edge::~Edge()
|
---|
79 | {
|
---|
80 | if ( twin )
|
---|
81 | {
|
---|
82 | face_uses->f_r_e_e();
|
---|
83 | delete face_uses;
|
---|
84 |
|
---|
85 | twin->twin = NULL;
|
---|
86 | delete twin;
|
---|
87 | }
|
---|
88 | }
|
---|
89 |
|
---|
90 | void Edge::kill()
|
---|
91 | {
|
---|
92 | #ifdef SAFETY
|
---|
93 | assert( face_uses->length() == 0 );
|
---|
94 | #endif
|
---|
95 | if ( isValid() )
|
---|
96 | {
|
---|
97 | org()->unlinkEdge(this);
|
---|
98 | dest()->unlinkEdge(sym());
|
---|
99 | markInvalid();
|
---|
100 | twin->markInvalid();
|
---|
101 | face_uses->reset();
|
---|
102 | }
|
---|
103 | }
|
---|
104 |
|
---|
105 | void Edge::linkFace(Face *face)
|
---|
106 | {
|
---|
107 | face_uses->add(face);
|
---|
108 | }
|
---|
109 |
|
---|
110 | void Edge::unlinkFace(Face *face)
|
---|
111 | {
|
---|
112 | int index = face_uses->find(face);
|
---|
113 |
|
---|
114 | #ifdef SAFETY
|
---|
115 | assert( index>=0 );
|
---|
116 | #endif
|
---|
117 | face_uses->remove(index);
|
---|
118 | if( face_uses->length() == 0 )
|
---|
119 | kill();
|
---|
120 | }
|
---|
121 |
|
---|
122 | void Edge::remapTo(Edge *e)
|
---|
123 | {
|
---|
124 | if ( e != this )
|
---|
125 | {
|
---|
126 | for (int i=0; i<face_uses->length(); i++)
|
---|
127 | {
|
---|
128 | (*face_uses)(i)->remapEdge(this, e);
|
---|
129 | }
|
---|
130 |
|
---|
131 | // Disconnect from all faces and vertices
|
---|
132 | kill();
|
---|
133 | }
|
---|
134 | }
|
---|
135 |
|
---|
136 | void Edge::remapEndpoint(Vertex *from, Vertex *to)
|
---|
137 | {
|
---|
138 | if ( org() == from )
|
---|
139 | {
|
---|
140 | v1 = to;
|
---|
141 | to->linkEdge(this);
|
---|
142 | }
|
---|
143 | else if ( dest() == from )
|
---|
144 | {
|
---|
145 | twin->v1 = to;
|
---|
146 | to->linkEdge(twin);
|
---|
147 | }
|
---|
148 | else
|
---|
149 | {
|
---|
150 | std::cerr << "WARNING remapEndpoint: Illegal endpoint." << std::endl;
|
---|
151 | }
|
---|
152 |
|
---|
153 | //
|
---|
154 | // The cached Plane equations for the faces attached to us may
|
---|
155 | // no longer be valid (in general, chances are pretty slim that they're OK)
|
---|
156 | for (int i = 0; i < face_uses->length(); i++)
|
---|
157 | {
|
---|
158 | face_uses->ref(i)->invalidatePlane();
|
---|
159 | }
|
---|
160 | }
|
---|
161 |
|
---|
162 | Face::Face(Edge *e0, Edge *e1, Edge *e2)
|
---|
163 | : Face3(*e0->org(), *e1->org(), *e2->org())
|
---|
164 | {
|
---|
165 | edges[0] = e0;
|
---|
166 | edges[1] = e1;
|
---|
167 | edges[2] = e2;
|
---|
168 |
|
---|
169 | edges[0]->linkFace(this);
|
---|
170 | edges[1]->linkFace(this);
|
---|
171 | edges[2]->linkFace(this);
|
---|
172 |
|
---|
173 | #ifdef SUPPORT_FCOLOR
|
---|
174 | props = NULL;
|
---|
175 | #endif
|
---|
176 | }
|
---|
177 |
|
---|
178 | void Face::kill()
|
---|
179 | {
|
---|
180 | if( isValid() )
|
---|
181 | {
|
---|
182 | if( edge(0)->isValid() )
|
---|
183 | edge(0)->unlinkFace(this);
|
---|
184 |
|
---|
185 | if( edge(1)->isValid() )
|
---|
186 | edge(1)->unlinkFace(this);
|
---|
187 |
|
---|
188 | if( edge(2)->isValid() )
|
---|
189 | edge(2)->unlinkFace(this);
|
---|
190 |
|
---|
191 | markInvalid();
|
---|
192 | }
|
---|
193 | }
|
---|
194 |
|
---|
195 | void Face::remapEdge(Edge *from, Edge *to)
|
---|
196 | {
|
---|
197 | for (int i=0; i<3; i++)
|
---|
198 | {
|
---|
199 | if ( edges[i] == from )
|
---|
200 | {
|
---|
201 | edges[i] = to;
|
---|
202 | to->linkFace(this);
|
---|
203 | }
|
---|
204 | else if ( edges[i] == from->sym() )
|
---|
205 | {
|
---|
206 | edges[i] = to->sym();
|
---|
207 | to->sym()->linkFace(this);
|
---|
208 | }
|
---|
209 | }
|
---|
210 |
|
---|
211 | invalidatePlane();
|
---|
212 | }
|
---|
213 |
|
---|
214 | void simplif::untagFaceLoop(Vertex *v)
|
---|
215 | {
|
---|
216 | edge_buffer& edges = v->edgeUses();
|
---|
217 |
|
---|
218 | for (int j = 0; j < edges.length(); j++)
|
---|
219 | {
|
---|
220 | face_buffer& faces = edges(j)->faceUses();
|
---|
221 |
|
---|
222 | for (int k = 0; k < faces.length(); k++)
|
---|
223 | {
|
---|
224 | faces(k)->untag();
|
---|
225 | }
|
---|
226 | }
|
---|
227 | }
|
---|
228 |
|
---|
229 | void simplif::collectFaceLoop(Vertex *v, face_buffer& loop)
|
---|
230 | {
|
---|
231 | edge_buffer& edges = v->edgeUses();
|
---|
232 |
|
---|
233 | for(int j=0; j<edges.length(); j++)
|
---|
234 | {
|
---|
235 | face_buffer& faces = edges(j)->faceUses();
|
---|
236 | for(int k=0; k<faces.length(); k++)
|
---|
237 | if( !faces(k)->isTagged() )
|
---|
238 | {
|
---|
239 | loop.add(faces(k));
|
---|
240 | faces(k)->tag();
|
---|
241 | }
|
---|
242 | }
|
---|
243 | }
|
---|
244 |
|
---|
245 | int simplif::classifyEdge(Edge *e)
|
---|
246 | {
|
---|
247 | int cls = e->faceUses().length();
|
---|
248 |
|
---|
249 | if( cls>3 ) cls=3;
|
---|
250 |
|
---|
251 | return cls;
|
---|
252 | }
|
---|
253 |
|
---|
254 | int simplif::classifyVertex(Vertex *v)
|
---|
255 | {
|
---|
256 | int border_count = 0;
|
---|
257 | const edge_buffer& edges = v->edgeUses();
|
---|
258 |
|
---|
259 | for(int i=0; i<edges.length(); i++)
|
---|
260 | if( classifyEdge(edges(i)) == 1 )
|
---|
261 | border_count++;
|
---|
262 |
|
---|
263 | if( border_count == edges.length() )
|
---|
264 | return VERTEX_BORDER_ONLY;
|
---|
265 | else
|
---|
266 | return (border_count > 0);
|
---|
267 | }
|
---|
268 |
|
---|