Library of Assembled Shared Sources
quad_edge.h
Go to the documentation of this file.
1/** @file
2 * @author Bram de Greve (bram@cocamware.com)
3 * @author Tom De Muer (tom@cocamware.com)
4 *
5 * *** BEGIN LICENSE INFORMATION ***
6 *
7 * The contents of this file are subject to the Common Public Attribution License
8 * Version 1.0 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://lass.sourceforge.net/cpal-license. The License is based on the
11 * Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover
12 * use of software over a computer network and provide for limited attribution for
13 * the Original Developer. In addition, Exhibit A has been modified to be consistent
14 * with Exhibit B.
15 *
16 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
17 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific
18 * language governing rights and limitations under the License.
19 *
20 * The Original Code is LASS - Library of Assembled Shared Sources.
21 *
22 * The Initial Developer of the Original Code is Bram de Greve and Tom De Muer.
23 * The Original Developer is the Initial Developer.
24 *
25 * All portions of the code written by the Initial Developer are:
26 * Copyright (C) 2004-2011 the Initial Developer.
27 * All Rights Reserved.
28 *
29 * Contributor(s):
30 *
31 * Alternatively, the contents of this file may be used under the terms of the
32 * GNU General Public License Version 2 or later (the GPL), in which case the
33 * provisions of GPL are applicable instead of those above. If you wish to allow use
34 * of your version of this file only under the terms of the GPL and not to allow
35 * others to use your version of this file under the CPAL, indicate your decision by
36 * deleting the provisions above and replace them with the notice and other
37 * provisions required by the GPL License. If you do not delete the provisions above,
38 * a recipient may use your version of this file under either the CPAL or the GPL.
39 *
40 * *** END LICENSE INFORMATION ***
41 */
42
43
44
45#ifndef LASS_GUARDIAN_OF_INCLUSION_SPAT_QUAD_EDGE_H
46#define LASS_GUARDIAN_OF_INCLUSION_SPAT_QUAD_EDGE_H
47
48#include "spat_common.h"
49
50namespace lass
51{
52namespace spat
53{
54 template< typename EdgeHandle >
55 class QuadEdge
56 {
57 public:
58 typedef EdgeHandle TEdgeHandle;
59
60 class Edge
61 {
62 friend class QuadEdge<EdgeHandle>;
63 public:
64 Edge() : next_(NULL) {}
65
66 Edge* rot() { return (index_ < 3) ? this + 1 : this - 3; }
67 Edge* invRot(){ return (index_ > 0) ? this - 1 : this + 3; }
68 Edge* sym() { return (index_ < 2) ? this + 2 : this - 2; }
69 Edge* oNext() { return next_; }
70 Edge* oPrev() { return rot()->oNext()->rot(); }
71 Edge* dNext() { return sym()->oNext()->sym(); }
72 Edge* dPrev() { return invRot()->oNext()->invRot(); }
73 Edge* lNext() { return invRot()->oNext()->rot(); }
74 Edge* lPrev() { return oNext()->sym(); }
75 Edge* rNext() { return rot()->oNext()->invRot(); }
76 Edge* rPrev() { return sym()->oNext(); }
77
78 const Edge* rot() const { return (index_ < 3) ? this + 1 : this - 3; }
79 const Edge* invRot() const{ return (index_ > 0) ? this - 1 : this + 3; }
80 const Edge* sym() const { return (index_ < 2) ? this + 2 : this - 2; }
81 const Edge* oNext() const { return next_; }
82 const Edge* oPrev() const { return rot()->oNext()->rot(); }
83 const Edge* dNext() const { return sym()->oNext()->sym(); }
84 const Edge* dPrev() const { return invRot()->oNext()->invRot(); }
85 const Edge* lNext() const { return invRot()->oNext()->rot(); }
86 const Edge* lPrev() const { return oNext()->sym(); }
87 const Edge* rNext() const { return rot()->oNext()->invRot(); }
88 const Edge* rPrev() const { return sym()->oNext(); }
89
90 const QuadEdge* quadEdge() const { return (QuadEdge*)(this - index_); }
91 QuadEdge* quadEdge() { return (QuadEdge*)(this - index_); }
92 const EdgeHandle& handle() const { return edgeHandle_;}
93 EdgeHandle& handle() { return edgeHandle_; }
94 bool isConstrained() const { return quadEdge()->isConstrained(); }
95 bool isEdgeConstrained() const { return quadEdge()->isEdgeConstrained(); }
96 bool isFaceConstrained() const { return quadEdge()->isFaceConstrained(); }
97
98 int index() const { return index_; }
99 private:
100
101 EdgeHandle edgeHandle_;
102 Edge* next_;
103 int index_;
104 };
105
106 public:
107 QuadEdge(bool makeConstrained=false);
108 QuadEdge(const QuadEdge& other);
109 ~QuadEdge();
110 void detach();
111 QuadEdge& operator=(const QuadEdge& other);
112
113 void edgeConstrain();
114 void edgeDeconstrain();
115 void faceConstrain();
116 void faceDeconstrain();
117 bool isConstrained() const;
118 bool isEdgeConstrained() const;
119 bool isFaceConstrained() const;
120 Edge* edges();
121
122 static void splice( Edge* a, Edge* b);
123
124 private:
125 // don't touch the position of the edges_, they must be the first data type in the POD or else you will be crucified!
126
127 void initEdges();
128 void copyEdges(const QuadEdge& other);
129
130 Edge edges_[4];
131 bool edgeConstrained_; /**< the edge is forced into the mesh, stay off! */
132 bool faceConstrained_; /**< the faces adjacent the edge have their handles set differently, cannot do stuff with the edge! */
133 public:
134 bool deleted;
135 };
136
137
138 template< typename EdgeHandle > QuadEdge<EdgeHandle>::QuadEdge(bool makeEdgeConstrained)
139 {
140 edgeConstrained_ = makeEdgeConstrained;
141 faceConstrained_ = false;
142 deleted = false;
143 initEdges();
144 }
145
146 template< typename EdgeHandle > QuadEdge<EdgeHandle>::QuadEdge(const QuadEdge& other):
147 edgeConstrained_(other.edgeConstrained_),
148 faceConstrained_(other.faceConstrained_),
149 deleted(other.deleted)
150 {
151 initEdges();
152 copyEdges(other);
153 }
154
155 template< typename EdgeHandle > QuadEdge<EdgeHandle>& QuadEdge<EdgeHandle>::operator=(const QuadEdge& other)
156 {
157 deleted = other.deleted;
158 copyEdges(other);
159 return *this;
160 }
161
162 template< typename EdgeHandle > QuadEdge<EdgeHandle>::~QuadEdge()
163 {
164 LASS_ASSERT( !faceConstrained_ );
165 // detach edge from the subdivision:
166 //detach();
167 }
168 template< typename EdgeHandle > void QuadEdge<EdgeHandle>::detach()
169 {
170 LASS_ASSERT( !faceConstrained_ );
171 // detach edge from the subdivision:
172 splice(edges_, edges_->oPrev());
173 splice(edges_->sym(), edges_->sym()->oPrev());
174 }
175
176
177
178 template< typename EdgeHandle > void QuadEdge<EdgeHandle>::splice( Edge* a, Edge* b )
179 {
180 Edge* alpha = a->oNext()->rot();
181 Edge* beta = b->oNext()->rot();
182
183 Edge* t1 = b->oNext();
184 Edge* t2 = a->oNext();
185 Edge* t3 = beta->oNext();
186 Edge* t4 = alpha->oNext();
187
188 a->next_ = t1;
189 b->next_ = t2;
190 alpha->next_ = t3;
191 beta->next_ = t4;
192 }
193
194 template< typename EdgeHandle > void QuadEdge<EdgeHandle>::edgeConstrain()
195 {
196 edgeConstrained_ = true;
197 }
198 template< typename EdgeHandle > void QuadEdge<EdgeHandle>::edgeDeconstrain()
199 {
200 edgeConstrained_ = false;
201 }
202 template< typename EdgeHandle > void QuadEdge<EdgeHandle>::faceConstrain()
203 {
204 faceConstrained_ = true;
205 }
206 template< typename EdgeHandle > void QuadEdge<EdgeHandle>::faceDeconstrain()
207 {
208 faceConstrained_ = false;
209 }
210 template< typename EdgeHandle > bool QuadEdge<EdgeHandle>::isConstrained() const
211 {
212 return edgeConstrained_ || faceConstrained_;
213 }
214 template< typename EdgeHandle > bool QuadEdge<EdgeHandle>::isEdgeConstrained() const
215 {
216 return edgeConstrained_;
217 }
218 template< typename EdgeHandle > bool QuadEdge<EdgeHandle>::isFaceConstrained() const
219 {
220 return faceConstrained_;
221 }
222 template< typename EdgeHandle > typename QuadEdge<EdgeHandle>::Edge* QuadEdge<EdgeHandle>::edges()
223 {
224 return edges_;
225 }
226 /*
227 template< typename EdgeHandle > QuadEdge<EdgeHandle>* QuadEdge<EdgeHandle>::Edge::quadEdge()
228 {
229 return this - index_;
230 }
231 template< typename EdgeHandle > QuadEdge<EdgeHandle>::Edge* QuadEdge<EdgeHandle>::Edge::rot()
232 {
233 return (index_ < 3) ? this + 1 : this - 3;
234 }
235 template< typename EdgeHandle > QuadEdge<EdgeHandle>::Edge* QuadEdge<EdgeHandle>::Edge::invRot()
236 {
237 return (index_ > 0) ? this - 1 : this + 3;
238 }
239 template< typename EdgeHandle > QuadEdge<EdgeHandle>::Edge* QuadEdge<EdgeHandle>::Edge::sym()
240 {
241 return (index_ < 2) ? this + 2 : this - 2;
242 }
243 template< typename EdgeHandle > QuadEdge<EdgeHandle>::Edge* QuadEdge<EdgeHandle>::Edge::oNext()
244 {
245 return next_;
246 }
247 template< typename EdgeHandle > QuadEdge<EdgeHandle>::Edge* QuadEdge<EdgeHandle>::Edge::oPrev()
248 {
249 return rot()->oNext()->rot();
250 }
251 template< typename EdgeHandle > QuadEdge<EdgeHandle>::Edge* QuadEdge<EdgeHandle>::Edge::dNext()
252 {
253 return sym()->oNext()->sym();
254 }
255 template< typename EdgeHandle > QuadEdge<EdgeHandle>::Edge* QuadEdge<EdgeHandle>::Edge::dPrev()
256 {
257 return invRot()->oNext()->invRot();
258 }
259 template< typename EdgeHandle > QuadEdge<EdgeHandle>::Edge* QuadEdge<EdgeHandle>::Edge::lNext()
260 {
261 return invRot()->oNext()->rot();
262 }
263 template< typename EdgeHandle > QuadEdge<EdgeHandle>::Edge* QuadEdge<EdgeHandle>::Edge::lPrev()
264 {
265 return oNext()->sym();
266 }
267 template< typename EdgeHandle > QuadEdge<EdgeHandle>::Edge* QuadEdge<EdgeHandle>::Edge::rNext()
268 {
269 return rot()->oNext()->invRot();
270 }
271 template< typename EdgeHandle > QuadEdge<EdgeHandle>::Edge* QuadEdge<EdgeHandle>::Edge::rPrev()
272 {
273 return sym()->oNext();
274 }
275 */
276
277 template< typename EdgeHandle > void QuadEdge<EdgeHandle>::initEdges()
278 {
279 for (int i=0;i<4;++i)
280 edges_[i].index_ = i;
281 edges_[0].next_ = &edges_[0];
282 edges_[1].next_ = &edges_[3];
283 edges_[2].next_ = &edges_[2];
284 edges_[3].next_ = &edges_[1];
285 }
286
287 template< typename EdgeHandle > void QuadEdge<EdgeHandle>::copyEdges(const QuadEdge& other)
288 {
289 for (int i=0;i<4;++i)
290 edges_[i].edgeHandle_ = other.edges_[i].edgeHandle_;
291 }
292}
293
294}
295
296#endif
spatial subdivisions, quadtrees, octrees, meshes in 2D and 3D, triangulators, ...
Definition aabb8_tree.h:80
Library for Assembled Shared Sources.
Definition config.h:53