MOAB: Mesh Oriented datABase  (version 5.2.1)
VertexMaxQM.cpp
Go to the documentation of this file.
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) kraftche@cae.wisc.edu
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, size_t handle, double& value, std::vector< size_t >& indices,
00086                                          MsqError& err )
00087 {
00088     ElemSampleQM* qm = get_quality_metric();
00089     get_vertex_corner_handles( pd, handle, mHandles, err );
00090     MSQ_ERRFALSE( err );
00091 
00092     bool valid = true;
00093     double tmpval;
00094     bool tmpvalid;
00095     std::vector< size_t >::iterator i, e, h;
00096 
00097     value = -std::numeric_limits< double >::infinity();
00098     for( h = mHandles.begin(); h != mHandles.end(); ++h )
00099     {
00100         mIndices.clear();
00101         tmpvalid = qm->evaluate_with_indices( pd, *h, tmpval, mIndices, err );
00102         MSQ_ERRZERO( err );
00103         if( !tmpvalid )
00104             valid = false;
00105         else if( tmpval > value )
00106             value = tmpval;
00107 
00108         size_t size = indices.size();
00109         e           = indices.begin() + size;
00110         for( i = mIndices.begin(); i != mIndices.end(); ++i )
00111         {
00112             if( std::find( indices.begin(), e, *i ) == e )
00113             {
00114                 indices.push_back( *i );
00115                 e = indices.begin() + size;
00116             }
00117         }
00118     }
00119 
00120     return valid;
00121 }
00122 
00123 }  // namespace MBMesquite
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines