library of assembled shared sources |
http://lass.cocamware.com |
00001 /** @file 00002 * @author Bram de Greve (bramz@users.sourceforge.net) 00003 * @author Tom De Muer (tomdemuer@users.sourceforge.net) 00004 * 00005 * *** BEGIN LICENSE INFORMATION *** 00006 * 00007 * The contents of this file are subject to the Common Public Attribution License 00008 * Version 1.0 (the "License"); you may not use this file except in compliance with 00009 * the License. You may obtain a copy of the License at 00010 * http://lass.sourceforge.net/cpal-license. The License is based on the 00011 * Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover 00012 * use of software over a computer network and provide for limited attribution for 00013 * the Original Developer. In addition, Exhibit A has been modified to be consistent 00014 * with Exhibit B. 00015 * 00016 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT 00017 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific 00018 * language governing rights and limitations under the License. 00019 * 00020 * The Original Code is LASS - Library of Assembled Shared Sources. 00021 * 00022 * The Initial Developer of the Original Code is Bram de Greve and Tom De Muer. 00023 * The Original Developer is the Initial Developer. 00024 * 00025 * All portions of the code written by the Initial Developer are: 00026 * Copyright (C) 2004-2007 the Initial Developer. 00027 * All Rights Reserved. 00028 * 00029 * Contributor(s): 00030 * 00031 * Alternatively, the contents of this file may be used under the terms of the 00032 * GNU General Public License Version 2 or later (the GPL), in which case the 00033 * provisions of GPL are applicable instead of those above. If you wish to allow use 00034 * of your version of this file only under the terms of the GPL and not to allow 00035 * others to use your version of this file under the CPAL, indicate your decision by 00036 * deleting the provisions above and replace them with the notice and other 00037 * provisions required by the GPL License. If you do not delete the provisions above, 00038 * a recipient may use your version of this file under either the CPAL or the GPL. 00039 * 00040 * *** END LICENSE INFORMATION *** 00041 */ 00042 00043 00044 00045 #ifndef LASS_GUARDIAN_OF_INCLUSION_SPAT_QUAD_EDGE_H 00046 #define LASS_GUARDIAN_OF_INCLUSION_SPAT_QUAD_EDGE_H 00047 00048 #include "spat_common.h" 00049 00050 namespace lass 00051 { 00052 namespace spat 00053 { 00054 template< typename EdgeHandle > 00055 class QuadEdge 00056 { 00057 public: 00058 typedef EdgeHandle TEdgeHandle; 00059 00060 class Edge 00061 { 00062 friend class QuadEdge<EdgeHandle>; 00063 public: 00064 Edge() : next_(NULL) {} 00065 00066 Edge* const rot() { return (index_ < 3) ? this + 1 : this - 3; } 00067 Edge* const invRot(){ return (index_ > 0) ? this - 1 : this + 3; } 00068 Edge* const sym() { return (index_ < 2) ? this + 2 : this - 2; } 00069 Edge* const oNext() { return next_; } 00070 Edge* const oPrev() { return rot()->oNext()->rot(); } 00071 Edge* const dNext() { return sym()->oNext()->sym(); } 00072 Edge* const dPrev() { return invRot()->oNext()->invRot(); } 00073 Edge* const lNext() { return invRot()->oNext()->rot(); } 00074 Edge* const lPrev() { return oNext()->sym(); } 00075 Edge* const rNext() { return rot()->oNext()->invRot(); } 00076 Edge* const rPrev() { return sym()->oNext(); } 00077 00078 const Edge* const rot() const { return (index_ < 3) ? this + 1 : this - 3; } 00079 const Edge* const invRot() const{ return (index_ > 0) ? this - 1 : this + 3; } 00080 const Edge* const sym() const { return (index_ < 2) ? this + 2 : this - 2; } 00081 const Edge* const oNext() const { return next_; } 00082 const Edge* const oPrev() const { return rot()->oNext()->rot(); } 00083 const Edge* const dNext() const { return sym()->oNext()->sym(); } 00084 const Edge* const dPrev() const { return invRot()->oNext()->invRot(); } 00085 const Edge* const lNext() const { return invRot()->oNext()->rot(); } 00086 const Edge* const lPrev() const { return oNext()->sym(); } 00087 const Edge* const rNext() const { return rot()->oNext()->invRot(); } 00088 const Edge* const rPrev() const { return sym()->oNext(); } 00089 00090 const QuadEdge* const quadEdge() const { return (QuadEdge*)(this - index_); } 00091 QuadEdge* const quadEdge() { return (QuadEdge*)(this - index_); } 00092 const EdgeHandle& handle() const { return edgeHandle_;} 00093 EdgeHandle& handle() { return edgeHandle_; } 00094 bool isConstrained() const { return quadEdge()->isConstrained(); } 00095 bool isEdgeConstrained() const { return quadEdge()->isEdgeConstrained(); } 00096 bool isFaceConstrained() const { return quadEdge()->isFaceConstrained(); } 00097 00098 int index() const { return index_; } 00099 private: 00100 00101 EdgeHandle edgeHandle_; 00102 Edge* next_; 00103 int index_; 00104 }; 00105 00106 public: 00107 QuadEdge(bool makeConstrained=false); 00108 QuadEdge(const QuadEdge& other); 00109 ~QuadEdge(); 00110 void detach(); 00111 QuadEdge& operator=(const QuadEdge& other); 00112 00113 void edgeConstrain(); 00114 void edgeDeconstrain(); 00115 void faceConstrain(); 00116 void faceDeconstrain(); 00117 bool isConstrained() const; 00118 bool isEdgeConstrained() const; 00119 bool isFaceConstrained() const; 00120 Edge* edges(); 00121 00122 static void splice( Edge* a, Edge* b); 00123 00124 private: 00125 // don't touch the position of the edges_, they must be the first data type in the POD or else you will be crucified! 00126 00127 void initEdges(); 00128 void copyEdges(const QuadEdge& other); 00129 00130 Edge edges_[4]; 00131 bool edgeConstrained_; /**< the edge is forced into the mesh, stay off! */ 00132 bool faceConstrained_; /**< the faces adjacent the edge have their handles set differently, cannot do stuff with the edge! */ 00133 public: 00134 bool deleted; 00135 }; 00136 00137 00138 template< typename EdgeHandle > QuadEdge<EdgeHandle>::QuadEdge(bool makeEdgeConstrained) 00139 { 00140 edgeConstrained_ = makeEdgeConstrained; 00141 faceConstrained_ = false; 00142 deleted = false; 00143 initEdges(); 00144 } 00145 00146 template< typename EdgeHandle > QuadEdge<EdgeHandle>::QuadEdge(const QuadEdge& other): 00147 edgeConstrained_(other.edgeConstrained_), 00148 faceConstrained_(other.faceConstrained_), 00149 deleted(other.deleted) 00150 { 00151 initEdges(); 00152 copyEdges(other); 00153 } 00154 00155 template< typename EdgeHandle > QuadEdge<EdgeHandle>& QuadEdge<EdgeHandle>::operator=(const QuadEdge& other) 00156 { 00157 deleted = other.deleted; 00158 copyEdges(other); 00159 return *this; 00160 } 00161 00162 template< typename EdgeHandle > QuadEdge<EdgeHandle>::~QuadEdge() 00163 { 00164 LASS_ASSERT( !faceConstrained_ ); 00165 // detach edge from the subdivision: 00166 //detach(); 00167 } 00168 template< typename EdgeHandle > void QuadEdge<EdgeHandle>::detach() 00169 { 00170 LASS_ASSERT( !faceConstrained_ ); 00171 // detach edge from the subdivision: 00172 splice(edges_, edges_->oPrev()); 00173 splice(edges_->sym(), edges_->sym()->oPrev()); 00174 } 00175 00176 00177 00178 template< typename EdgeHandle > void QuadEdge<EdgeHandle>::splice( Edge* a, Edge* b ) 00179 { 00180 Edge* alpha = a->oNext()->rot(); 00181 Edge* beta = b->oNext()->rot(); 00182 00183 Edge* t1 = b->oNext(); 00184 Edge* t2 = a->oNext(); 00185 Edge* t3 = beta->oNext(); 00186 Edge* t4 = alpha->oNext(); 00187 00188 a->next_ = t1; 00189 b->next_ = t2; 00190 alpha->next_ = t3; 00191 beta->next_ = t4; 00192 } 00193 00194 template< typename EdgeHandle > void QuadEdge<EdgeHandle>::edgeConstrain() 00195 { 00196 edgeConstrained_ = true; 00197 } 00198 template< typename EdgeHandle > void QuadEdge<EdgeHandle>::edgeDeconstrain() 00199 { 00200 edgeConstrained_ = false; 00201 } 00202 template< typename EdgeHandle > void QuadEdge<EdgeHandle>::faceConstrain() 00203 { 00204 faceConstrained_ = true; 00205 } 00206 template< typename EdgeHandle > void QuadEdge<EdgeHandle>::faceDeconstrain() 00207 { 00208 faceConstrained_ = false; 00209 } 00210 template< typename EdgeHandle > bool QuadEdge<EdgeHandle>::isConstrained() const 00211 { 00212 return edgeConstrained_ || faceConstrained_; 00213 } 00214 template< typename EdgeHandle > bool QuadEdge<EdgeHandle>::isEdgeConstrained() const 00215 { 00216 return edgeConstrained_; 00217 } 00218 template< typename EdgeHandle > bool QuadEdge<EdgeHandle>::isFaceConstrained() const 00219 { 00220 return faceConstrained_; 00221 } 00222 template< typename EdgeHandle > typename QuadEdge<EdgeHandle>::Edge* QuadEdge<EdgeHandle>::edges() 00223 { 00224 return edges_; 00225 } 00226 /* 00227 template< typename EdgeHandle > QuadEdge<EdgeHandle>* QuadEdge<EdgeHandle>::Edge::quadEdge() 00228 { 00229 return this - index_; 00230 } 00231 template< typename EdgeHandle > QuadEdge<EdgeHandle>::Edge* QuadEdge<EdgeHandle>::Edge::rot() 00232 { 00233 return (index_ < 3) ? this + 1 : this - 3; 00234 } 00235 template< typename EdgeHandle > QuadEdge<EdgeHandle>::Edge* QuadEdge<EdgeHandle>::Edge::invRot() 00236 { 00237 return (index_ > 0) ? this - 1 : this + 3; 00238 } 00239 template< typename EdgeHandle > QuadEdge<EdgeHandle>::Edge* QuadEdge<EdgeHandle>::Edge::sym() 00240 { 00241 return (index_ < 2) ? this + 2 : this - 2; 00242 } 00243 template< typename EdgeHandle > QuadEdge<EdgeHandle>::Edge* QuadEdge<EdgeHandle>::Edge::oNext() 00244 { 00245 return next_; 00246 } 00247 template< typename EdgeHandle > QuadEdge<EdgeHandle>::Edge* QuadEdge<EdgeHandle>::Edge::oPrev() 00248 { 00249 return rot()->oNext()->rot(); 00250 } 00251 template< typename EdgeHandle > QuadEdge<EdgeHandle>::Edge* QuadEdge<EdgeHandle>::Edge::dNext() 00252 { 00253 return sym()->oNext()->sym(); 00254 } 00255 template< typename EdgeHandle > QuadEdge<EdgeHandle>::Edge* QuadEdge<EdgeHandle>::Edge::dPrev() 00256 { 00257 return invRot()->oNext()->invRot(); 00258 } 00259 template< typename EdgeHandle > QuadEdge<EdgeHandle>::Edge* QuadEdge<EdgeHandle>::Edge::lNext() 00260 { 00261 return invRot()->oNext()->rot(); 00262 } 00263 template< typename EdgeHandle > QuadEdge<EdgeHandle>::Edge* QuadEdge<EdgeHandle>::Edge::lPrev() 00264 { 00265 return oNext()->sym(); 00266 } 00267 template< typename EdgeHandle > QuadEdge<EdgeHandle>::Edge* QuadEdge<EdgeHandle>::Edge::rNext() 00268 { 00269 return rot()->oNext()->invRot(); 00270 } 00271 template< typename EdgeHandle > QuadEdge<EdgeHandle>::Edge* QuadEdge<EdgeHandle>::Edge::rPrev() 00272 { 00273 return sym()->oNext(); 00274 } 00275 */ 00276 00277 template< typename EdgeHandle > void QuadEdge<EdgeHandle>::initEdges() 00278 { 00279 for (int i=0;i<4;++i) 00280 edges_[i].index_ = i; 00281 edges_[0].next_ = &edges_[0]; 00282 edges_[1].next_ = &edges_[3]; 00283 edges_[2].next_ = &edges_[2]; 00284 edges_[3].next_ = &edges_[1]; 00285 } 00286 00287 template< typename EdgeHandle > void QuadEdge<EdgeHandle>::copyEdges(const QuadEdge& other) 00288 { 00289 for (int i=0;i<4;++i) 00290 edges_[i].edgeHandle_ = other.edges_[i].edgeHandle_; 00291 } 00292 } 00293 00294 } 00295 00296 #endif
Generated on Mon Nov 10 14:21:06 2008 for Library of Assembled Shared Sources by 1.5.7.1 |