MOAB: Mesh Oriented datABase  (version 5.4.1)
EdgeLengthQualityMetric.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 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 <cmath>
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,
00056                                                size_t this_vert,
00057                                                double& fval,
00058                                                std::vector< size_t >& adj_verts,
00059                                                MsqError& err )
00060 {
00061     fval = 0.0;
00062     pd.get_adjacent_vertex_indices( this_vert, adj_verts, err );
00063     MSQ_ERRZERO( err );
00064     const unsigned num_sample_points = adj_verts.size();
00065     double* metric_values            = new double[num_sample_points];
00066     const MsqVertex* verts           = pd.get_vertex_array( err );
00067     MSQ_ERRZERO( err );
00068     for( unsigned i = 0; i < num_sample_points; ++i )
00069         metric_values[i] = ( verts[this_vert] - verts[adj_verts[i]] ).length();
00070     fval = average_metrics( metric_values, num_sample_points, err );
00071     delete[] metric_values;
00072     return !MSQ_CHKERR( err );
00073 }
00074 
00075 bool EdgeLengthQualityMetric::evaluate( PatchData& pd, size_t vertex, double& value, MsqError& err )
00076 {
00077     std::vector< size_t > verts;
00078     bool rval = evaluate_common( pd, vertex, value, verts, err );
00079     return !MSQ_CHKERR( err ) && rval;
00080 }
00081 
00082 bool EdgeLengthQualityMetric::evaluate_with_indices( PatchData& pd,
00083                                                      size_t vertex,
00084                                                      double& value,
00085                                                      std::vector< size_t >& indices,
00086                                                      MsqError& err )
00087 {
00088     indices.clear();
00089     bool rval = evaluate_common( pd, vertex, value, indices, err );
00090 
00091     std::vector< size_t >::iterator r, w;
00092     for( r = w = indices.begin(); r != indices.end(); ++r )
00093     {
00094         if( *r < pd.num_free_vertices() )
00095         {
00096             *w = *r;
00097             ++w;
00098         }
00099     }
00100     indices.erase( w, indices.end() );
00101     if( vertex < pd.num_free_vertices() ) indices.push_back( vertex );
00102 
00103     return !MSQ_CHKERR( err ) && rval;
00104 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines