GEL
2
GEL is a library for Geometry and Linear Algebra
|
00001 /* ----------------------------------------------------------------------- * 00002 * This file is part of GEL, www.imm.dtu.dk/GEL 00003 * Copyright (C) the authors (see AUTHORS.txt) and DTU Informatics 00004 * 00005 * Principal authors: 00006 * Christian Thode Larsen (thode2d@gmail.com) 00007 * J. Andreas Baerentzen (jab@imm.dtu.dk) 00008 * 00009 * See LICENSE.txt for licensing information 00010 * ----------------------------------------------------------------------- */ 00011 00012 #ifndef __HMESH_ITERATORS_H__ 00013 #define __HMESH_ITERATORS_H__ 00014 00015 #include "ConnectivityKernel.h" 00016 00017 namespace HMesh 00018 { 00019 template<typename ID> 00020 class IDIterator 00021 { 00022 public: 00023 // typedefs to accommodiate stl compliance 00024 typedef std::bidirectional_iterator_tag iterator_category; 00025 typedef ptrdiff_t difference_type; 00026 typedef ID value_type; 00027 typedef value_type reference; 00028 typedef value_type* pointer; 00029 00031 IDIterator(const ConnectivityKernel& _ck, ID _id, bool _skip = true); 00032 00034 IDIterator& operator ++(); 00036 IDIterator& operator ++(int); 00038 IDIterator& operator --(); 00040 IDIterator& operator --(int); 00041 00043 bool operator ==(const IDIterator& other) const; 00045 bool operator !=(const IDIterator& other) const; 00046 00048 reference operator *(); 00050 pointer operator ->(); 00052 //operator VertexID() const; 00053 00054 private: 00055 const ConnectivityKernel* ck; 00056 ID id; 00057 bool skip; 00058 }; 00059 00060 /*--------- 00061 * Typedefs 00062 *----------*/ 00063 typedef IDIterator<VertexID> VertexIDIterator; 00064 typedef IDIterator<FaceID> FaceIDIterator; 00065 typedef IDIterator<HalfEdgeID> HalfEdgeIDIterator; 00066 00067 00068 /*----------------------------------------- 00069 * IDIterator template implementation 00070 *-----------------------------------------*/ 00071 00072 template<typename ID> 00073 inline IDIterator<ID>::IDIterator(const ConnectivityKernel& _ck, ID _id, bool _skip) 00074 : ck(&_ck), id(_id), skip(_skip){} 00075 00076 template<typename ID> 00077 inline IDIterator<ID>& IDIterator<ID>::operator ++(int) 00078 { return ++(*this); } 00079 00080 template<typename ID> 00081 inline IDIterator<ID>& IDIterator<ID>::operator --(int) 00082 { return --(*this); } 00083 00084 template<typename ID> 00085 inline bool IDIterator<ID>::operator ==(const IDIterator<ID>& other) const 00086 { return ck == other.ck && id == other.id; } 00087 00088 template<typename ID> 00089 inline bool IDIterator<ID>::operator !=(const IDIterator<ID>& other) const 00090 { return ck != other.ck || id != other.id; } 00091 00092 template<typename ID> 00093 inline ID IDIterator<ID>::operator *() 00094 { return id; } 00095 00096 template<typename ID> 00097 inline ID* IDIterator<ID>::operator ->() 00098 { return &id; } 00099 00100 /*----------------------------- 00101 * Specializations for vertices 00102 *------------------------------*/ 00103 template<> 00104 inline IDIterator<VertexID>& IDIterator<VertexID>::operator ++() 00105 { 00106 id = ck->vertices_next(id, skip); 00107 return *this; 00108 } 00109 template<> 00110 inline IDIterator<VertexID>& IDIterator<VertexID>::operator --() 00111 { 00112 id = ck->vertices_prev(id, skip); 00113 return *this; 00114 } 00115 00116 /*----------------------------- 00117 * Specializations for faces 00118 *------------------------------*/ 00119 template<> 00120 inline IDIterator<FaceID>& IDIterator<FaceID>::operator ++() 00121 { 00122 id = ck->faces_next(id, skip); 00123 return *this; 00124 } 00125 00126 template<> 00127 inline IDIterator<FaceID>& IDIterator<FaceID>::operator --() 00128 { 00129 id = ck->faces_prev(id, skip); 00130 return *this; 00131 } 00132 00133 /*----------------------------- 00134 * Specializations for halfedges 00135 *------------------------------*/ 00136 template<> 00137 inline IDIterator<HalfEdgeID>& IDIterator<HalfEdgeID>::operator ++() 00138 { 00139 id = ck->halfedges_next(id, skip); 00140 return *this; 00141 } 00142 00143 template<> 00144 inline IDIterator<HalfEdgeID>& IDIterator<HalfEdgeID>::operator --() 00145 { 00146 id = ck->halfedges_prev(id, skip); 00147 return *this; 00148 } 00149 } 00150 00151 #endif