MOAB: Mesh Oriented datABase  (version 5.2.1)
MsqFreeVertexIndexIterator.hpp
Go to the documentation of this file.
00001 /* *****************************************************************
00002     MESQUITE -- The Mesh Quality Improvement Toolkit
00003 
00004     Copyright 2004 Sandia Corporation and Argonne National
00005     Laboratory.  Under the terms of Contract DE-AC04-94AL85000
00006     with Sandia Corporation, the U.S. Government retains certain
00007     rights in 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     diachin2@llnl.gov, djmelan@sandia.gov, mbrewer@sandia.gov,
00024     pknupp@sandia.gov, tleurent@mcs.anl.gov, tmunson@mcs.anl.gov
00025 
00026   ***************************************************************** */
00027 /*!
00028   \file   MsqFreeVertexIndexIterator.hpp
00029   \brief    This file contains the MsqFreeVertexIndexIterator class
00030 
00031   \author Thomas Leurent
00032   \date   2002-01-17
00033 */
00034 
00035 #ifndef MsqFreeVertexIndexIterator_hpp
00036 #define MsqFreeVertexIndexIterator_hpp
00037 
00038 #include <cstddef>
00039 #include <cstdlib>
00040 
00041 #include "Mesquite.hpp"
00042 #include "MsqVertex.hpp"
00043 #include "PatchData.hpp"
00044 #include "MsqVertex.hpp"
00045 
00046 namespace MBMesquite
00047 {
00048 class MsqError;
00049 
00050 /*! \class MsqFreeVertexIndexIterator
00051   \brief iterates over indexes of free vetices in a PatchData.
00052 
00053   A free vertex is defined as not having the MSQ_CULLED and MSQ_HARD_FIXED
00054   flags activated.
00055 
00056   Use the iterator as follow:
00057   MsqFreeVertexIndexIterator ind(&patch_data,err);
00058   ind.reset();
00059   while (ind.next()) {
00060     cout << ind.value();
00061   }  .*/
00062 class MsqFreeVertexIndexIterator
00063 {
00064   public:
00065     MsqFreeVertexIndexIterator( const PatchData& p_pd, MsqError& )
00066         : iterOriginator( p_pd ), iterCurrentIndex( (size_t)-1 )
00067     {
00068     }
00069     //! Resets the iterator.
00070     //! The next call to next() will set the iterator on the first free vertex.
00071     void reset()
00072     {
00073         iterCurrentIndex = (size_t)-1;
00074     }
00075     //! Increments the iterator. returns false if there is no more free vertex.
00076     inline bool next();
00077     //! Returns an index corresponding to a free vertex.
00078     std::size_t value()
00079     {
00080         return iterCurrentIndex;
00081     }
00082 
00083   private:
00084     const PatchData& iterOriginator;
00085     std::size_t iterCurrentIndex;
00086 };
00087 
00088 /** \brief Advance iterator
00089  *
00090  * Advance iterator to next free vertex
00091  *\return false if at end, true otherwise
00092  */
00093 inline bool MsqFreeVertexIndexIterator::next()
00094 {
00095     ++iterCurrentIndex;
00096     while( iterCurrentIndex < iterOriginator.num_free_vertices() )
00097     {
00098         if( !iterOriginator.vertex_by_index( iterCurrentIndex ).is_flag_set( MsqVertex::MSQ_CULLED ) ) return true;
00099         ++iterCurrentIndex;
00100     }
00101     return false;
00102 }
00103 
00104 }  // namespace MBMesquite
00105 
00106 #endif  //  MsqFreeVertexIndexIterator_hpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines