MOAB: Mesh Oriented datABase
(version 5.4.1)
|
00001 /* ***************************************************************** 00002 MESQUITE -- The Mesh Quality Improvement Toolkit 00003 00004 Copyright 2006 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 (2006) [email protected] 00024 00025 ***************************************************************** */ 00026 00027 /** \file VertexMaxQM.cpp 00028 * \brief 00029 * \author Jason Kraftcheck 00030 */ 00031 00032 #include "Mesquite.hpp" 00033 #include "VertexMaxQM.hpp" 00034 #include "ElemSampleQM.hpp" 00035 #include "VertexQM.hpp" 00036 #include "MsqError.hpp" 00037 #include "PatchData.hpp" 00038 #include <algorithm> 00039 #include <limits> 00040 00041 namespace MBMesquite 00042 { 00043 00044 VertexMaxQM::VertexMaxQM( ElemSampleQM* metric ) : mMetric( metric ) {} 00045 00046 VertexMaxQM::~VertexMaxQM() {} 00047 00048 std::string VertexMaxQM::get_name() const 00049 { 00050 std::string result( "VertexMaxQM(" ); 00051 result += mMetric->get_name(); 00052 result += ")"; 00053 return result; 00054 } 00055 00056 int VertexMaxQM::get_negate_flag() const 00057 { 00058 return mMetric->get_negate_flag(); 00059 } 00060 00061 bool VertexMaxQM::evaluate( PatchData& pd, size_t handle, double& value, MsqError& err ) 00062 { 00063 ElemSampleQM* qm = get_quality_metric(); 00064 get_vertex_corner_handles( pd, handle, mHandles, err ); 00065 MSQ_ERRFALSE( err ); 00066 00067 bool valid = true; 00068 double tmpval; 00069 bool tmpvalid; 00070 00071 value = -std::numeric_limits< double >::infinity(); 00072 for( std::vector< size_t >::iterator h = mHandles.begin(); h != mHandles.end(); ++h ) 00073 { 00074 tmpvalid = qm->evaluate( pd, *h, tmpval, err ); 00075 MSQ_ERRZERO( err ); 00076 if( !tmpvalid ) 00077 valid = false; 00078 else if( tmpval > value ) 00079 value = tmpval; 00080 } 00081 00082 return valid; 00083 } 00084 00085 bool VertexMaxQM::evaluate_with_indices( PatchData& pd, 00086 size_t handle, 00087 double& value, 00088 std::vector< size_t >& indices, 00089 MsqError& err ) 00090 { 00091 ElemSampleQM* qm = get_quality_metric(); 00092 get_vertex_corner_handles( pd, handle, mHandles, err ); 00093 MSQ_ERRFALSE( err ); 00094 00095 bool valid = true; 00096 double tmpval; 00097 bool tmpvalid; 00098 std::vector< size_t >::iterator i, e, h; 00099 00100 value = -std::numeric_limits< double >::infinity(); 00101 for( h = mHandles.begin(); h != mHandles.end(); ++h ) 00102 { 00103 mIndices.clear(); 00104 tmpvalid = qm->evaluate_with_indices( pd, *h, tmpval, mIndices, err ); 00105 MSQ_ERRZERO( err ); 00106 if( !tmpvalid ) 00107 valid = false; 00108 else if( tmpval > value ) 00109 value = tmpval; 00110 00111 size_t size = indices.size(); 00112 e = indices.begin() + size; 00113 for( i = mIndices.begin(); i != mIndices.end(); ++i ) 00114 { 00115 if( std::find( indices.begin(), e, *i ) == e ) 00116 { 00117 indices.push_back( *i ); 00118 e = indices.begin() + size; 00119 } 00120 } 00121 } 00122 00123 return valid; 00124 } 00125 00126 } // namespace MBMesquite