MOAB: Mesh Oriented datABase  (version 5.3.1)
EdgeIterator.hpp
Go to the documentation of this file.
00001 /* *****************************************************************
00002     MESQUITE -- The Mesh Quality Improvement Toolkit
00003 
00004     Copyright 2010 Sandia National Laboratories.  Developed at the
00005     University of Wisconsin--Madison under SNL contract number
00006     624796.  The U.S. Government and the University of Wisconsin
00007     retain certain rights to this software.
00008 
00009     This library is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU Lesser General Public
00011     License as published by the Free Software Foundation; either
00012     version 2.1 of the License, or (at your option) any later version.
00013 
00014     This library is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017     Lesser General Public License for more details.
00018 
00019     You should have received a copy of the GNU Lesser General Public License
00020     (lgpl.txt) along with this library; if not, write to the Free Software
00021     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 
00023     (2010) kraftche@cae.wisc.edu
00024 
00025   ***************************************************************** */
00026 
00027 /** \file EdgeIterator.hpp
00028  *  \brief
00029  *  \author Jason Kraftcheck
00030  */
00031 
00032 #ifndef MSQ_EDGE_ITERATOR_HPP
00033 #define MSQ_EDGE_ITERATOR_HPP
00034 
00035 #include "Mesquite.hpp"
00036 #include "PatchData.hpp"
00037 #include "MsqError.hpp"
00038 
00039 namespace MBMesquite
00040 {
00041 
00042 /**\brief Iterate over all edges in a patch*/
00043 class EdgeIterator
00044 {
00045   public:
00046     EdgeIterator( PatchData* patch, MsqError& err );
00047     inline bool is_at_end() const;
00048     inline const Vector3D& start() const;
00049     inline const Vector3D& end() const;
00050     inline const Vector3D* mid() const;
00051     inline void step( MsqError& err );
00052 
00053     struct Edge
00054     {
00055         Edge( size_t vtx, size_t mid ) : otherVertex( vtx ), midVertex( mid ) {}
00056         Edge() {}
00057         size_t otherVertex;
00058         size_t midVertex;
00059     };
00060 
00061   private:
00062     PatchData* patchPtr;
00063     size_t vertIdx;
00064     std::vector< Edge > adjList;
00065     std::vector< Edge >::iterator adjIter;
00066     void get_adjacent_vertices( MsqError& err );
00067 };
00068 
00069 inline bool operator<( const EdgeIterator::Edge& e1, const EdgeIterator::Edge& e2 )
00070 {
00071     return e1.otherVertex < e2.otherVertex || ( e1.otherVertex == e2.otherVertex && e1.midVertex < e2.midVertex );
00072 }
00073 
00074 inline bool operator==( const EdgeIterator::Edge& e1, const EdgeIterator::Edge& e2 )
00075 {
00076     return e1.otherVertex == e2.otherVertex && e1.midVertex == e2.midVertex;
00077 }
00078 
00079 bool EdgeIterator::is_at_end() const
00080 {
00081     return vertIdx >= patchPtr->num_nodes();
00082 }
00083 
00084 const Vector3D& EdgeIterator::start() const
00085 {
00086     return patchPtr->vertex_by_index( vertIdx );
00087 }
00088 
00089 const Vector3D& EdgeIterator::end() const
00090 {
00091     return patchPtr->vertex_by_index( adjIter->otherVertex );
00092 }
00093 
00094 const Vector3D* EdgeIterator::mid() const
00095 {
00096     return adjIter->midVertex < patchPtr->num_nodes() ? &patchPtr->vertex_by_index( adjIter->midVertex ) : 0;
00097 }
00098 
00099 void EdgeIterator::step( MsqError& err )
00100 {
00101     if( adjIter != adjList.end() ) { ++adjIter; }
00102 
00103     while( adjIter == adjList.end() && ++vertIdx < patchPtr->num_nodes() )
00104     {
00105         get_adjacent_vertices( err );MSQ_ERRRTN( err );
00106     }
00107 }
00108 
00109 }  // namespace MBMesquite
00110 
00111 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines