MOAB: Mesh Oriented datABase  (version 5.4.1)
EdgeLengthRangeQualityMetric.cpp
Go to the documentation of this file.
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     [email protected], [email protected], [email protected],
00024     [email protected], [email protected], [email protected]
00025 
00026   ***************************************************************** */
00027 /*! \file EdgeLengthRangeQualityMetric.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 "EdgeLengthRangeQualityMetric.hpp"
00035 #include "Vector3D.hpp"
00036 #include "QualityMetric.hpp"
00037 #include "MsqVertex.hpp"
00038 #include "PatchData.hpp"
00039 #include "MsqDebug.hpp"
00040 #include "MsqError.hpp"
00041 
00042 #include <vector>
00043 using std::vector;
00044 
00045 using namespace MBMesquite;
00046 
00047 EdgeLengthRangeQualityMetric::EdgeLengthRangeQualityMetric( double low_a, double high_a )
00048     : AveragingQM( SUM ), highVal( high_a ), lowVal( low_a )
00049 {
00050     if( lowVal > highVal ) std::swap( lowVal, highVal );
00051 }
00052 
00053 EdgeLengthRangeQualityMetric::~EdgeLengthRangeQualityMetric() {}
00054 
00055 std::string EdgeLengthRangeQualityMetric::get_name() const
00056 {
00057     return "Edge Length Range Metric";
00058 }
00059 
00060 int EdgeLengthRangeQualityMetric::get_negate_flag() const
00061 {
00062     return 1;
00063 }
00064 
00065 /*!For the given vertex, vert, with connected edges of lengths l_j for
00066   j=1...k, the metric value is the average (where the default average
00067   type is SUM) of
00068         u_j = ( | l_j - lowVal | - (l_j - lowVal) )^2 +
00069               ( | highVal - l_j | - (highVal - l_j) )^2.
00070 */
00071 bool EdgeLengthRangeQualityMetric::evaluate_common( PatchData& pd,
00072                                                     size_t this_vert,
00073                                                     double& fval,
00074                                                     std::vector< size_t >& adj_verts,
00075                                                     MsqError& err )
00076 {
00077     fval = 0.0;
00078     Vector3D edg;
00079     pd.get_adjacent_vertex_indices( this_vert, adj_verts, err );
00080     MSQ_ERRZERO( err );
00081     int num_sample_points  = adj_verts.size();
00082     double* metric_values  = new double[num_sample_points];
00083     const MsqVertex* verts = pd.get_vertex_array( err );
00084     MSQ_ERRZERO( err );
00085     // store the length of the edge, and the first and second component of
00086     // metric values, respectively.
00087     double temp_length = 0.0;
00088     double temp_first  = 0.0;
00089     double temp_second = 0.0;
00090     // PRINT_INFO("INSIDE ELR, vertex =
00091     // %f,%f,%f\n",verts[this_vert][0],verts[this_vert][1],verts[this_vert][2]); loop while there are
00092     // still more adjacent vertices.
00093     for( unsigned i = 0; i < adj_verts.size(); ++i )
00094     {
00095         edg = verts[this_vert] - verts[adj_verts[i]];
00096         // compute the edge length
00097         temp_length = edg.length();
00098         // get the first component
00099         temp_first = temp_length - lowVal;
00100         temp_first = fabs( temp_first ) - ( temp_first );
00101         temp_first *= temp_first;
00102         // get the second component
00103         temp_second = highVal - temp_length;
00104         temp_second = fabs( temp_second ) - ( temp_second );
00105         temp_second *= temp_second;
00106         // combine the two components
00107         metric_values[i] = temp_first + temp_second;
00108     }
00109     // average the metric values of the edges
00110     fval = average_metrics( metric_values, num_sample_points, err );
00111     // clean up
00112     delete[] metric_values;
00113     // always return true because mesh is always valid wrt this metric.
00114     return !MSQ_CHKERR( err );
00115 }
00116 
00117 bool EdgeLengthRangeQualityMetric::evaluate( PatchData& pd, size_t vertex, double& value, MsqError& err )
00118 {
00119     std::vector< size_t > verts;
00120     bool rval = evaluate_common( pd, vertex, value, verts, err );
00121     return !MSQ_CHKERR( err ) && rval;
00122 }
00123 
00124 bool EdgeLengthRangeQualityMetric::evaluate_with_indices( PatchData& pd,
00125                                                           size_t vertex,
00126                                                           double& value,
00127                                                           std::vector< size_t >& indices,
00128                                                           MsqError& err )
00129 {
00130     indices.clear();
00131     bool rval = evaluate_common( pd, vertex, value, indices, err );
00132 
00133     std::vector< size_t >::iterator r, w;
00134     for( r = w = indices.begin(); r != indices.end(); ++r )
00135     {
00136         if( *r < pd.num_free_vertices() )
00137         {
00138             *w = *r;
00139             ++w;
00140         }
00141     }
00142     indices.erase( w, indices.end() );
00143     if( vertex < pd.num_free_vertices() ) indices.push_back( vertex );
00144 
00145     return !MSQ_CHKERR( err ) && rval;
00146 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines