Branch data Line data Source code
1 : : /* *****************************************************************
2 : : MESQUITE -- The Mesh Quality Improvement Toolkit
3 : :
4 : : Copyright 2004 Sandia Corporation and Argonne National
5 : : Laboratory. Under the terms of Contract DE-AC04-94AL85000
6 : : with Sandia Corporation, the U.S. Government retains certain
7 : : rights in this software.
8 : :
9 : : This library is free software; you can redistribute it and/or
10 : : modify it under the terms of the GNU Lesser General Public
11 : : License as published by the Free Software Foundation; either
12 : : version 2.1 of the License, or (at your option) any later version.
13 : :
14 : : This library is distributed in the hope that it will be useful,
15 : : but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 : : Lesser General Public License for more details.
18 : :
19 : : You should have received a copy of the GNU Lesser General Public License
20 : : (lgpl.txt) along with this library; if not, write to the Free Software
21 : : Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 : :
23 : : [email protected], [email protected], [email protected],
24 : : [email protected], [email protected], [email protected]
25 : :
26 : : ***************************************************************** */
27 : : /*! \file EdgeLengthQualityMetric.cpp
28 : : \author Michael Brewer
29 : : \date 2002-05-14
30 : : Evaluates the lengths of the edges attached to the given vertex.
31 : : By default, the averaging method is set to SUM.
32 : : */
33 : :
34 : : #include "EdgeLengthQualityMetric.hpp"
35 : : #include "Vector3D.hpp"
36 : : #include "QualityMetric.hpp"
37 : : #include "MsqVertex.hpp"
38 : : #include "PatchData.hpp"
39 : : #include "MsqError.hpp"
40 : :
41 : : #include <math.h>
42 : :
43 : : using namespace MBMesquite;
44 : :
45 : 2 : std::string EdgeLengthQualityMetric::get_name() const
46 : : {
47 [ + - ]: 2 : return "Edge Length";
48 : : }
49 : :
50 : 0 : int EdgeLengthQualityMetric::get_negate_flag() const
51 : : {
52 : 0 : return 1;
53 : : }
54 : :
55 : 2 : bool EdgeLengthQualityMetric::evaluate_common( PatchData& pd, size_t this_vert, double& fval,
56 : : std::vector< size_t >& adj_verts, MsqError& err )
57 : : {
58 : 2 : fval = 0.0;
59 : 2 : pd.get_adjacent_vertex_indices( this_vert, adj_verts, err );
60 [ - + ][ # # ]: 2 : MSQ_ERRZERO( err );
[ - + ]
61 : 2 : const unsigned num_sample_points = adj_verts.size();
62 [ + - ]: 2 : double* metric_values = new double[num_sample_points];
63 : 2 : const MsqVertex* verts = pd.get_vertex_array( err );
64 [ - + ][ # # ]: 2 : MSQ_ERRZERO( err );
[ - + ]
65 [ + + ]: 10 : for( unsigned i = 0; i < num_sample_points; ++i )
66 [ + - ]: 8 : metric_values[i] = ( verts[this_vert] - verts[adj_verts[i]] ).length();
67 : 2 : fval = average_metrics( metric_values, num_sample_points, err );
68 [ + - ]: 2 : delete[] metric_values;
69 [ - + ][ # # ]: 2 : return !MSQ_CHKERR( err );
70 : : }
71 : :
72 : 2 : bool EdgeLengthQualityMetric::evaluate( PatchData& pd, size_t vertex, double& value, MsqError& err )
73 : : {
74 [ + - ]: 2 : std::vector< size_t > verts;
75 [ + - ]: 2 : bool rval = evaluate_common( pd, vertex, value, verts, err );
76 [ + - ][ - + ]: 2 : return !MSQ_CHKERR( err ) && rval;
[ # # ][ # # ]
[ + - ]
77 : : }
78 : :
79 : 0 : bool EdgeLengthQualityMetric::evaluate_with_indices( PatchData& pd, size_t vertex, double& value,
80 : : std::vector< size_t >& indices, MsqError& err )
81 : : {
82 : 0 : indices.clear();
83 [ # # ]: 0 : bool rval = evaluate_common( pd, vertex, value, indices, err );
84 : :
85 : 0 : std::vector< size_t >::iterator r, w;
86 [ # # ][ # # ]: 0 : for( r = w = indices.begin(); r != indices.end(); ++r )
[ # # ]
87 : : {
88 [ # # ][ # # ]: 0 : if( *r < pd.num_free_vertices() )
[ # # ]
89 : : {
90 [ # # ][ # # ]: 0 : *w = *r;
91 [ # # ]: 0 : ++w;
92 : : }
93 : : }
94 [ # # ]: 0 : indices.erase( w, indices.end() );
95 [ # # ][ # # ]: 0 : if( vertex < pd.num_free_vertices() ) indices.push_back( vertex );
[ # # ]
96 : :
97 [ # # ][ # # ]: 0 : return !MSQ_CHKERR( err ) && rval;
[ # # ][ # # ]
[ # # ]
98 [ + - ][ + - ]: 8 : }
|