MOAB: Mesh Oriented datABase  (version 5.2.1)
VertexPatches.cpp
Go to the documentation of this file.
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) kraftche@cae.wisc.edu
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, std::vector< Mesh::ElementHandle >& elem_handles_out,
00069                                std::vector< Mesh::VertexHandle >& free_vertices_out, MsqError& err )
00070 {
00071     free_vertices_out.clear();
00072     elem_handles_out.clear();
00073 
00074     if( free_vertices_only() )
00075     {  // check if vertex is culled
00076         unsigned char byte;
00077         get_mesh()->vertices_get_byte( &patch_handle, &byte, 1, err );
00078         if( MSQ_CHKERR( err ) || ( byte & MsqVertex::MSQ_CULLED ) ) return;
00079     }
00080 
00081     free_vertices_out.push_back( patch_handle );
00082     if( !numLayers )  // if no layers of elements, then done.
00083         return;
00084 
00085     // get elements adjacent to free vertex
00086     get_mesh()->vertices_get_attached_elements( &patch_handle, 1, elem_handles_out, junk, err );
00087     if( MSQ_CHKERR( err ) ) return;
00088 
00089     unsigned remaining = numLayers;
00090     while( --remaining )
00091     {  // loop if more than one layer of elements
00092         if( elem_handles_out.empty() ) break;
00093 
00094         // Get vertices adjacent to elements
00095         free_vertices_out.clear();
00096         get_mesh()->elements_get_attached_vertices( arrptr( elem_handles_out ), elem_handles_out.size(),
00097                                                     free_vertices_out, junk, err );
00098         if( MSQ_CHKERR( err ) ) break;
00099 
00100         // remove duplicates from vertex list
00101         std::sort( free_vertices_out.begin(), free_vertices_out.end() );
00102         free_vertices_out.erase( std::unique( free_vertices_out.begin(), free_vertices_out.end() ),
00103                                  free_vertices_out.end() );
00104 
00105         // Get elements adjacent to vertices
00106         elem_handles_out.clear();
00107         get_mesh()->vertices_get_attached_elements( arrptr( free_vertices_out ), free_vertices_out.size(),
00108                                                     elem_handles_out, junk, err );
00109         if( MSQ_CHKERR( err ) ) break;
00110 
00111         // Remove duplicates from element list
00112         std::sort( elem_handles_out.begin(), elem_handles_out.end() );
00113         elem_handles_out.erase( std::unique( elem_handles_out.begin(), elem_handles_out.end() ),
00114                                 elem_handles_out.end() );
00115     }
00116 }
00117 
00118 }  // namespace MBMesquite
00119 
00120 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines