MOAB: Mesh Oriented datABase
(version 5.2.1)
|
00001 /* ***************************************************************** 00002 MESQUITE -- The Mesh Quality Improvement Toolkit 00003 00004 Copyright 2004 Sandia Corporation and Argonne National 00005 Laboratory. Under the terms of Contract DE-AC04-94AL85000 00006 with Sandia Corporation, the U.S. Government 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 diachin2@llnl.gov, djmelan@sandia.gov, mbrewer@sandia.gov, 00024 pknupp@sandia.gov, tleurent@mcs.anl.gov, tmunson@mcs.anl.gov 00025 00026 ***************************************************************** */ 00027 /*! \file EdgeLengthQualityMetric.cpp 00028 \author Michael Brewer 00029 \date 2002-05-14 00030 Evaluates the lengths of the edges attached to the given vertex. 00031 By default, the averaging method is set to SUM. 00032 */ 00033 00034 #include "EdgeLengthQualityMetric.hpp" 00035 #include "Vector3D.hpp" 00036 #include "QualityMetric.hpp" 00037 #include "MsqVertex.hpp" 00038 #include "PatchData.hpp" 00039 #include "MsqError.hpp" 00040 00041 #include <math.h> 00042 00043 using namespace MBMesquite; 00044 00045 std::string EdgeLengthQualityMetric::get_name() const 00046 { 00047 return "Edge Length"; 00048 } 00049 00050 int EdgeLengthQualityMetric::get_negate_flag() const 00051 { 00052 return 1; 00053 } 00054 00055 bool EdgeLengthQualityMetric::evaluate_common( PatchData& pd, size_t this_vert, double& fval, 00056 std::vector< size_t >& adj_verts, MsqError& err ) 00057 { 00058 fval = 0.0; 00059 pd.get_adjacent_vertex_indices( this_vert, adj_verts, err ); 00060 MSQ_ERRZERO( err ); 00061 const unsigned num_sample_points = adj_verts.size(); 00062 double* metric_values = new double[num_sample_points]; 00063 const MsqVertex* verts = pd.get_vertex_array( err ); 00064 MSQ_ERRZERO( err ); 00065 for( unsigned i = 0; i < num_sample_points; ++i ) 00066 metric_values[i] = ( verts[this_vert] - verts[adj_verts[i]] ).length(); 00067 fval = average_metrics( metric_values, num_sample_points, err ); 00068 delete[] metric_values; 00069 return !MSQ_CHKERR( err ); 00070 } 00071 00072 bool EdgeLengthQualityMetric::evaluate( PatchData& pd, size_t vertex, double& value, MsqError& err ) 00073 { 00074 std::vector< size_t > verts; 00075 bool rval = evaluate_common( pd, vertex, value, verts, err ); 00076 return !MSQ_CHKERR( err ) && rval; 00077 } 00078 00079 bool EdgeLengthQualityMetric::evaluate_with_indices( PatchData& pd, size_t vertex, double& value, 00080 std::vector< size_t >& indices, MsqError& err ) 00081 { 00082 indices.clear(); 00083 bool rval = evaluate_common( pd, vertex, value, indices, err ); 00084 00085 std::vector< size_t >::iterator r, w; 00086 for( r = w = indices.begin(); r != indices.end(); ++r ) 00087 { 00088 if( *r < pd.num_free_vertices() ) 00089 { 00090 *w = *r; 00091 ++w; 00092 } 00093 } 00094 indices.erase( w, indices.end() ); 00095 if( vertex < pd.num_free_vertices() ) indices.push_back( vertex ); 00096 00097 return !MSQ_CHKERR( err ) && rval; 00098 }