MOAB: Mesh Oriented datABase  (version 5.2.1)
MBMesquite::EdgeLengthRangeQualityMetric Class Reference

Computes the edge length range metric for a given vertex. More...

#include <EdgeLengthRangeQualityMetric.hpp>

+ Inheritance diagram for MBMesquite::EdgeLengthRangeQualityMetric:
+ Collaboration diagram for MBMesquite::EdgeLengthRangeQualityMetric:

Public Member Functions

 EdgeLengthRangeQualityMetric (double low_a, double high_a)
virtual ~EdgeLengthRangeQualityMetric ()
virtual std::string get_name () const
virtual int get_negate_flag () const
 1 if metric should be minimized, -1 if metric should be maximized.
virtual bool evaluate (PatchData &pd, size_t vertex, double &value, MsqError &err)
 Get metric value at a logical location in the patch.
virtual bool evaluate_with_indices (PatchData &pd, size_t vertex, double &value, std::vector< size_t > &indices, MsqError &err)
 Get metric value at a logical location in the patch.

Private Member Functions

bool evaluate_common (PatchData &pd, size_t vertex, double &value, std::vector< size_t > &vertices, MsqError &err)

Private Attributes

double highVal
double lowVal

Detailed Description

Computes the edge length range metric for a given vertex.

EdgeLengthRangeQualityMetric is a vertex based metric which computes the lengths of the edges connected to a given vertex and then uses those values to form a metric. The metric is created using two doubles A and B. The value of the metric is zero (ideal) if the edge lengths are in the range [A,B]. Otherwise, the metric value is some positive number. For a given vertex, v_i, with connected edges of lengths l_j for j=1...k, the metric value is the average (where the default average type is SUM) of u_j = ( | l_j - A | - (l_j - A) )^2 + ( | B - l_j | - (B - l_j) )^2.

Definition at line 60 of file EdgeLengthRangeQualityMetric.hpp.


Constructor & Destructor Documentation

EdgeLengthRangeQualityMetric::EdgeLengthRangeQualityMetric ( double  low_a,
double  high_a 
)

Definition at line 47 of file EdgeLengthRangeQualityMetric.cpp.

References highVal, lowVal, and swap().

    : AveragingQM( SUM ), highVal( high_a ), lowVal( low_a )
{
    if( lowVal > highVal ) std::swap( lowVal, highVal );
}

Member Function Documentation

bool EdgeLengthRangeQualityMetric::evaluate ( PatchData pd,
size_t  handle,
double &  value,
MsqError err 
) [virtual]

Get metric value at a logical location in the patch.

Evaluate the metric at one location in the PatchData.

Parameters:
pdThe patch.
handleThe location in the patch (as passed back from get_evaluations).
valueThe output metric value.

Implements MBMesquite::QualityMetric.

Definition at line 114 of file EdgeLengthRangeQualityMetric.cpp.

References evaluate_common(), and MSQ_CHKERR.

{
    std::vector< size_t > verts;
    bool rval = evaluate_common( pd, vertex, value, verts, err );
    return !MSQ_CHKERR( err ) && rval;
}
bool EdgeLengthRangeQualityMetric::evaluate_common ( PatchData pd,
size_t  this_vert,
double &  fval,
std::vector< size_t > &  adj_verts,
MsqError err 
) [private]

For the given vertex, vert, with connected edges of lengths l_j for j=1...k, the metric value is the average (where the default average type is SUM) of u_j = ( | l_j - lowVal | - (l_j - lowVal) )^2 + ( | highVal - l_j | - (highVal - l_j) )^2.

Definition at line 71 of file EdgeLengthRangeQualityMetric.cpp.

References MBMesquite::AveragingQM::average_metrics(), MBMesquite::PatchData::get_adjacent_vertex_indices(), MBMesquite::PatchData::get_vertex_array(), highVal, MBMesquite::Vector3D::length(), lowVal, MSQ_CHKERR, and MSQ_ERRZERO.

Referenced by evaluate(), and evaluate_with_indices().

{
    fval = 0.0;
    Vector3D edg;
    pd.get_adjacent_vertex_indices( this_vert, adj_verts, err );
    MSQ_ERRZERO( err );
    int num_sample_points  = adj_verts.size();
    double* metric_values  = new double[num_sample_points];
    const MsqVertex* verts = pd.get_vertex_array( err );
    MSQ_ERRZERO( err );
    // store the length of the edge, and the first and second component of
    // metric values, respectively.
    double temp_length = 0.0;
    double temp_first  = 0.0;
    double temp_second = 0.0;
    // PRINT_INFO("INSIDE ELR, vertex =
    // %f,%f,%f\n",verts[this_vert][0],verts[this_vert][1],verts[this_vert][2]); loop while there are
    // still more adjacent vertices.
    for( unsigned i = 0; i < adj_verts.size(); ++i )
    {
        edg = verts[this_vert] - verts[adj_verts[i]];
        // compute the edge length
        temp_length = edg.length();
        // get the first component
        temp_first = temp_length - lowVal;
        temp_first = fabs( temp_first ) - ( temp_first );
        temp_first *= temp_first;
        // get the second component
        temp_second = highVal - temp_length;
        temp_second = fabs( temp_second ) - ( temp_second );
        temp_second *= temp_second;
        // combine the two components
        metric_values[i] = temp_first + temp_second;
    }
    // average the metric values of the edges
    fval = average_metrics( metric_values, num_sample_points, err );
    // clean up
    delete[] metric_values;
    // always return true because mesh is always valid wrt this metric.
    return !MSQ_CHKERR( err );
}
bool EdgeLengthRangeQualityMetric::evaluate_with_indices ( PatchData pd,
size_t  handle,
double &  value,
std::vector< size_t > &  indices,
MsqError err 
) [virtual]

Get metric value at a logical location in the patch.

Evaluate the metric at one location in the PatchData.

Parameters:
pdThe patch.
handleThe location in the patch (as passed back from get_evaluations).
valueThe output metric value.
indicesThe free vertices that the evaluation is a function of, specified as vertex indices in the PatchData.

Implements MBMesquite::QualityMetric.

Definition at line 121 of file EdgeLengthRangeQualityMetric.cpp.

References evaluate_common(), MSQ_CHKERR, and MBMesquite::PatchData::num_free_vertices().

{
    indices.clear();
    bool rval = evaluate_common( pd, vertex, value, indices, err );

    std::vector< size_t >::iterator r, w;
    for( r = w = indices.begin(); r != indices.end(); ++r )
    {
        if( *r < pd.num_free_vertices() )
        {
            *w = *r;
            ++w;
        }
    }
    indices.erase( w, indices.end() );
    if( vertex < pd.num_free_vertices() ) indices.push_back( vertex );

    return !MSQ_CHKERR( err ) && rval;
}
std::string EdgeLengthRangeQualityMetric::get_name ( ) const [virtual]

Implements MBMesquite::QualityMetric.

Definition at line 55 of file EdgeLengthRangeQualityMetric.cpp.

{
    return "Edge Length Range Metric";
}

1 if metric should be minimized, -1 if metric should be maximized.

Implements MBMesquite::QualityMetric.

Definition at line 60 of file EdgeLengthRangeQualityMetric.cpp.

{
    return 1;
}

Member Data Documentation

List of all members.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines