00001 //================================================================================================== 00002 // 00003 // File: HeDart.h 00004 // 00005 // Created: March 1 2001 00006 // 00007 // Author: Øyvind Hjelle <oyvind.hjelle@math.sintef.no> 00008 // 00009 // Revision: $Id: HeDart.h,v 1.2 2006/07/26 12:08:44 oyvindhj Exp $ 00010 // 00011 // Description: 00012 // 00013 //================================================================================================== 00014 // Copyright (C) 2000-2003 SINTEF Applied Mathematics. All rights reserved. 00015 // 00016 // This file may be distributed under the terms of the Q Public License 00017 // as defined by Trolltech AS of Norway and appearing in the file 00018 // LICENSE.QPL included in the packaging of this file. 00019 // 00020 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00021 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00022 // 00023 //================================================================================================== 00024 00025 00026 #ifndef _HALF_EDGE_DART_ 00027 #define _HALF_EDGE_DART_ 00028 00029 00030 #include <ttl/halfedge/HeTriang.h> 00031 00032 00033 namespace hed { 00034 00035 00036 //------------------------------------------------------------------------------------------------ 00037 // Dart class for the half-edge data structure 00038 //------------------------------------------------------------------------------------------------ 00039 00047 class Dart { 00048 00049 Edge* edge_; 00050 bool dir_; // true if dart is counterclockwise in face 00051 00052 public: 00054 Dart() { edge_ = NULL; dir_ = true; } 00055 00057 Dart(Edge* edge, bool dir = true) { edge_ = edge; dir_ = dir; } 00058 00060 Dart(const Dart& dart) { edge_ = dart.edge_; dir_ = dart.dir_; } 00061 00063 ~Dart() {} 00064 00066 Dart& operator = (const Dart& dart) { 00067 if (this == &dart) 00068 return *this; 00069 edge_ = dart.edge_; 00070 dir_ = dart.dir_; 00071 return *this; 00072 } 00073 00075 bool operator==(const Dart& dart) const { 00076 if (dart.edge_ == edge_ && dart.dir_ == dir_) 00077 return true; 00078 return false; 00079 } 00080 00082 bool operator!=(const Dart& dart) const { 00083 return !(dart==*this); 00084 } 00085 00087 Dart& alpha0() { dir_ = !dir_; return *this; } 00088 00090 Dart& alpha1() { 00091 if (dir_) { 00092 edge_ = edge_->getNextEdgeInFace()->getNextEdgeInFace(); 00093 dir_ = false; 00094 } 00095 else { 00096 edge_ = edge_->getNextEdgeInFace(); 00097 dir_ = true; 00098 } 00099 return *this; 00100 } 00101 00103 Dart& alpha2() { 00104 if (edge_->getTwinEdge()) { 00105 edge_ = edge_->getTwinEdge(); 00106 dir_ = !dir_; 00107 } 00108 // else, the dart is at the boundary and should not be changed 00109 return *this; 00110 } 00111 00112 00113 // Utilities not required by TTL 00114 // ----------------------------- 00115 00118 00119 void init(Edge* edge, bool dir = true) { edge_ = edge; dir_ = dir; } 00120 00121 double x() const { return getNode()->x(); } // x-coordinate of source node 00122 double y() const { return getNode()->y(); } // y-coordinate of source node 00123 00124 bool isCounterClockWise() const { return dir_; } 00125 00126 Node* getNode() const { return dir_ ? edge_->getSourceNode() : edge_->getTargetNode(); } 00127 Node* getOppositeNode() const { return dir_ ? edge_->getTargetNode() : edge_->getSourceNode(); } 00128 Edge* getEdge() const { return edge_; } 00129 00131 00132 }; 00133 00134 }; // End of hed namespace 00135 00136 #endif