MOAB: Mesh Oriented datABase
(version 5.4.1)
|
00001 /* ***************************************************************** 00002 MESQUITE -- The Mesh Quality Improvement Toolkit 00003 00004 Copyright 2006 Lawrence Livermore National Laboratory. Under 00005 the terms of Contract B545069 with the University of Wisconsin -- 00006 Madison, Lawrence Livermore National Laboratory 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 (2006) [email protected] 00024 00025 ***************************************************************** */ 00026 00027 #ifndef MSQ_VERTEX_PATCHES_CPP 00028 #define MSQ_VERTEX_PATCHES_CPP 00029 00030 /** \file VertexPatches.cpp 00031 * \brief 00032 * \author Jason Kraftcheck 00033 */ 00034 00035 #include "VertexPatches.hpp" 00036 #include "MsqError.hpp" 00037 #include "MeshInterface.hpp" 00038 #include "MsqVertex.hpp" 00039 00040 #include <algorithm> 00041 00042 namespace MBMesquite 00043 { 00044 00045 VertexPatches::~VertexPatches() {} 00046 00047 void VertexPatches::get_patch_handles( std::vector< PatchHandle >& patch_handles_out, MsqError& err ) 00048 { 00049 // get all vertex handles 00050 get_mesh()->get_all_vertices( patch_handles_out, err );MSQ_ERRRTN( err ); 00051 if( patch_handles_out.empty() ) return; 00052 00053 if( free_vertices_only() ) 00054 { 00055 // get fixed flags for vertices 00056 std::vector< unsigned char > flags( patch_handles_out.size() ); 00057 get_mesh()->vertices_get_byte( arrptr( patch_handles_out ), arrptr( flags ), patch_handles_out.size(), err );MSQ_ERRRTN( err ); 00058 00059 // remove fixed and slaved vertices from list 00060 size_t write = 0; 00061 for( size_t read = 0; read < patch_handles_out.size(); ++read ) 00062 if( !( flags[read] & ( MsqVertex::MSQ_HARD_FIXED | MsqVertex::MSQ_DEPENDENT ) ) ) 00063 patch_handles_out[write++] = patch_handles_out[read]; 00064 patch_handles_out.resize( write ); 00065 } 00066 } 00067 00068 void VertexPatches::get_patch( PatchHandle patch_handle, 00069 std::vector< Mesh::ElementHandle >& elem_handles_out, 00070 std::vector< Mesh::VertexHandle >& free_vertices_out, 00071 MsqError& err ) 00072 { 00073 free_vertices_out.clear(); 00074 elem_handles_out.clear(); 00075 00076 if( free_vertices_only() ) 00077 { // check if vertex is culled 00078 unsigned char byte; 00079 get_mesh()->vertices_get_byte( &patch_handle, &byte, 1, err ); 00080 if( MSQ_CHKERR( err ) || ( byte & MsqVertex::MSQ_CULLED ) ) return; 00081 } 00082 00083 free_vertices_out.push_back( patch_handle ); 00084 if( !numLayers ) // if no layers of elements, then done. 00085 return; 00086 00087 // get elements adjacent to free vertex 00088 get_mesh()->vertices_get_attached_elements( &patch_handle, 1, elem_handles_out, junk, err ); 00089 if( MSQ_CHKERR( err ) ) return; 00090 00091 unsigned remaining = numLayers; 00092 while( --remaining ) 00093 { // loop if more than one layer of elements 00094 if( elem_handles_out.empty() ) break; 00095 00096 // Get vertices adjacent to elements 00097 free_vertices_out.clear(); 00098 get_mesh()->elements_get_attached_vertices( arrptr( elem_handles_out ), elem_handles_out.size(), 00099 free_vertices_out, junk, err ); 00100 if( MSQ_CHKERR( err ) ) break; 00101 00102 // remove duplicates from vertex list 00103 std::sort( free_vertices_out.begin(), free_vertices_out.end() ); 00104 free_vertices_out.erase( std::unique( free_vertices_out.begin(), free_vertices_out.end() ), 00105 free_vertices_out.end() ); 00106 00107 // Get elements adjacent to vertices 00108 elem_handles_out.clear(); 00109 get_mesh()->vertices_get_attached_elements( arrptr( free_vertices_out ), free_vertices_out.size(), 00110 elem_handles_out, junk, err ); 00111 if( MSQ_CHKERR( err ) ) break; 00112 00113 // Remove duplicates from element list 00114 std::sort( elem_handles_out.begin(), elem_handles_out.end() ); 00115 elem_handles_out.erase( std::unique( elem_handles_out.begin(), elem_handles_out.end() ), 00116 elem_handles_out.end() ); 00117 } 00118 } 00119 00120 } // namespace MBMesquite 00121 00122 #endif