Branch data Line data Source code
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) [email protected]
24 : :
25 : : ***************************************************************** */
26 : :
27 : : /** \file EdgeIterator.hpp
28 : : * \brief
29 : : * \author Jason Kraftcheck
30 : : */
31 : :
32 : : #ifndef MSQ_EDGE_ITERATOR_HPP
33 : : #define MSQ_EDGE_ITERATOR_HPP
34 : :
35 : : #include "Mesquite.hpp"
36 : : #include "PatchData.hpp"
37 : : #include "MsqError.hpp"
38 : :
39 : : namespace MBMesquite
40 : : {
41 : :
42 : : /**\brief Iterate over all edges in a patch*/
43 : 82 : 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
54 : : {
55 : 155772 : Edge( size_t vtx, size_t mid ) : otherVertex( vtx ), midVertex( mid ) {}
56 : 0 : Edge() {}
57 : : size_t otherVertex;
58 : : size_t midVertex;
59 : : };
60 : :
61 : : private:
62 : : PatchData* patchPtr;
63 : : size_t vertIdx;
64 : : std::vector< Edge > adjList;
65 : : std::vector< Edge >::iterator adjIter;
66 : : void get_adjacent_vertices( MsqError& err );
67 : : };
68 : :
69 : 551911 : inline bool operator<( const EdgeIterator::Edge& e1, const EdgeIterator::Edge& e2 )
70 : : {
71 [ + + ][ + + ]: 551911 : return e1.otherVertex < e2.otherVertex || ( e1.otherVertex == e2.otherVertex && e1.midVertex < e2.midVertex );
[ - + ]
72 : : }
73 : :
74 : 131586 : inline bool operator==( const EdgeIterator::Edge& e1, const EdgeIterator::Edge& e2 )
75 : : {
76 [ + + ][ + - ]: 131586 : return e1.otherVertex == e2.otherVertex && e1.midVertex == e2.midVertex;
77 : : }
78 : :
79 : 58542 : bool EdgeIterator::is_at_end() const
80 : : {
81 : 58542 : return vertIdx >= patchPtr->num_nodes();
82 : : }
83 : :
84 : 58501 : const Vector3D& EdgeIterator::start() const
85 : : {
86 : 58501 : return patchPtr->vertex_by_index( vertIdx );
87 : : }
88 : :
89 : 58501 : const Vector3D& EdgeIterator::end() const
90 : : {
91 : 58501 : return patchPtr->vertex_by_index( adjIter->otherVertex );
92 : : }
93 : :
94 : 132 : const Vector3D* EdgeIterator::mid() const
95 : : {
96 [ - + ]: 132 : return adjIter->midVertex < patchPtr->num_nodes() ? &patchPtr->vertex_by_index( adjIter->midVertex ) : 0;
97 : : }
98 : :
99 : 58501 : void EdgeIterator::step( MsqError& err )
100 : : {
101 [ + - ][ + - ]: 58501 : if( adjIter != adjList.end() ) { ++adjIter; }
102 : :
103 [ + - ][ + + ]: 83055 : while( adjIter == adjList.end() && ++vertIdx < patchPtr->num_nodes() )
[ + - ][ + + ]
[ + - ]
[ + + # # ]
104 : : {
105 [ - + ][ # # ]: 83055 : get_adjacent_vertices( err );MSQ_ERRRTN( err );
[ - + ]
106 : : }
107 : : }
108 : :
109 : : } // namespace MBMesquite
110 : :
111 : : #endif
|