MOAB: Mesh Oriented datABase
(version 5.4.1)
|
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) [email protected] 00024 00025 ***************************************************************** */ 00026 00027 /** \file EdgeIterator.cpp 00028 * \brief 00029 * \author Jason Kraftcheck 00030 */ 00031 00032 #include "Mesquite.hpp" 00033 #include "EdgeIterator.hpp" 00034 00035 #include <algorithm> 00036 00037 namespace MBMesquite 00038 { 00039 00040 EdgeIterator::EdgeIterator( PatchData* p, MsqError& err ) : patchPtr( p ), vertIdx( 0 ) 00041 { 00042 p->generate_vertex_to_element_data(); 00043 if( patchPtr->num_nodes() ) 00044 { 00045 get_adjacent_vertices( err ); 00046 if( adjIter == adjList.end() ) 00047 { 00048 step( err );MSQ_ERRRTN( err ); 00049 } 00050 } 00051 else 00052 adjIter = adjList.end(); 00053 } 00054 00055 void EdgeIterator::get_adjacent_vertices( MsqError& err ) 00056 { 00057 adjList.clear(); 00058 00059 // Get all adjacent elements 00060 size_t num_elem; 00061 const size_t* elems = patchPtr->get_vertex_element_adjacencies( vertIdx, num_elem, err );MSQ_ERRRTN( err ); 00062 00063 // Get all adjacent vertices from elements 00064 std::vector< size_t > elem_verts; 00065 for( size_t e = 0; e < num_elem; ++e ) 00066 { 00067 MsqMeshEntity& elem = patchPtr->element_by_index( elems[e] ); 00068 EntityTopology type = elem.get_element_type(); 00069 size_t num_edges = TopologyInfo::edges( type ); 00070 00071 bool mid_edge, mid_face, mid_vol; 00072 TopologyInfo::higher_order( type, elem.node_count(), mid_edge, mid_face, mid_vol, err );MSQ_ERRRTN( err ); 00073 00074 // For each edge 00075 for( size_t d = 0; d < num_edges; ++d ) 00076 { 00077 const unsigned* edge = TopologyInfo::edge_vertices( type, d, err );MSQ_ERRRTN( err ); 00078 size_t vert1 = elem.get_vertex_index( edge[0] ); 00079 size_t vert2 = elem.get_vertex_index( edge[1] ); 00080 00081 size_t pmid = ~(size_t)0; 00082 if( mid_edge ) 00083 { 00084 int p = TopologyInfo::higher_order_from_side( type, elem.node_count(), 1, d, err );MSQ_ERRRTN( err ); 00085 pmid = elem.get_vertex_index_array()[p]; 00086 } 00087 00088 // If this edge contains the input vertex (vert_idx) 00089 // AND the input vertex index is less than the 00090 // other vertex (avoids iterating over this edge twice) 00091 // add it to the list. 00092 if( vert1 > vert2 ) 00093 { 00094 if( vert2 == vertIdx ) adjList.push_back( Edge( vert1, pmid ) ); 00095 } 00096 else 00097 { 00098 if( vert1 == vertIdx ) adjList.push_back( Edge( vert2, pmid ) ); 00099 } 00100 } 00101 } 00102 00103 // Remove duplicates 00104 std::sort( adjList.begin(), adjList.end() ); 00105 adjIter = std::unique( adjList.begin(), adjList.end() ); 00106 adjList.resize( adjIter - adjList.begin() ); 00107 adjIter = adjList.begin(); 00108 } 00109 00110 } // namespace MBMesquite