1 /* *****************************************************************
2 MESQUITE -- The Mesh Quality Improvement Toolkit
3
4 Copyright 2010 Sandia National Laboratories. Developed at the
5 University of Wisconsin--Madison under SNL contract number
6 624796. The U.S. Government and the University of Wisconsin
7 retain certain rights to this software.
8
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2.1 of the License, or (at your option) any later version.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 (lgpl.txt) along with this library; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
23 (2010) kraftche@cae.wisc.edu
24
25 ***************************************************************** */
26
27
28 /** \file EdgeIterator.hpp
29 * \brief
30 * \author Jason Kraftcheck
31 */
32
33 #ifndef MSQ_EDGE_ITERATOR_HPP
34 #define MSQ_EDGE_ITERATOR_HPP
35
36 #include "Mesquite.hpp"
37 #include "PatchData.hpp"
38 #include "MsqError.hpp"
39
40 namespace MBMesquite {
41
42 /**\brief Iterate over all edges in a patch*/
43 class EdgeIterator
44 {
45 public:
46 EdgeIterator( PatchData* patch, MsqError& err );
47 inline bool is_at_end() const;
48 inline const Vector3D& start() const;
49 inline const Vector3D& end() const;
50 inline const Vector3D* mid() const;
51 inline void step( MsqError& err );
52
53 struct Edge {
EdgeMBMesquite::EdgeIterator::Edge54 Edge( size_t vtx, size_t mid ) : otherVertex(vtx), midVertex(mid) {}
EdgeMBMesquite::EdgeIterator::Edge55 Edge() {}
56 size_t otherVertex;
57 size_t midVertex;
58 };
59 private:
60 PatchData* patchPtr;
61 size_t vertIdx;
62 std::vector<Edge> adjList;
63 std::vector<Edge>::iterator adjIter;
64 void get_adjacent_vertices( MsqError& err );
65 };
66
67
operator <(const EdgeIterator::Edge & e1,const EdgeIterator::Edge & e2)68 inline bool operator<( const EdgeIterator::Edge& e1, const EdgeIterator::Edge& e2 )
69 { return e1.otherVertex < e2.otherVertex ||
70 (e1.otherVertex == e2.otherVertex && e1.midVertex < e2.midVertex); }
71
operator ==(const EdgeIterator::Edge & e1,const EdgeIterator::Edge & e2)72 inline bool operator==( const EdgeIterator::Edge& e1, const EdgeIterator::Edge& e2 )
73 { return e1.otherVertex == e2.otherVertex && e1.midVertex == e2.midVertex; }
74
is_at_end() const75 bool EdgeIterator::is_at_end() const
76 {
77 return vertIdx >= patchPtr->num_nodes();
78 }
79
start() const80 const Vector3D& EdgeIterator::start() const
81 { return patchPtr->vertex_by_index( vertIdx ); }
82
end() const83 const Vector3D& EdgeIterator::end() const
84 { return patchPtr->vertex_by_index( adjIter->otherVertex ); }
85
mid() const86 const Vector3D* EdgeIterator::mid() const
87 { return adjIter->midVertex < patchPtr->num_nodes() ?
88 &patchPtr->vertex_by_index( adjIter->midVertex ) : 0; }
89
step(MsqError & err)90 void EdgeIterator::step( MsqError& err )
91 {
92 if (adjIter != adjList.end())
93 {
94 ++adjIter;
95 }
96
97 while (adjIter == adjList.end() && ++vertIdx < patchPtr->num_nodes())
98 {
99 get_adjacent_vertices( err ); MSQ_ERRRTN(err);
100 }
101 }
102
103
104 } // namespace MBMesquite
105
106 #endif
107