本文整理汇总了C++中QualityMetric::compute_vertex_gradient方法的典型用法代码示例。如果您正苦于以下问题:C++ QualityMetric::compute_vertex_gradient方法的具体用法?C++ QualityMetric::compute_vertex_gradient怎么用?C++ QualityMetric::compute_vertex_gradient使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QualityMetric
的用法示例。
在下文中一共展示了QualityMetric::compute_vertex_gradient方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: compute_analytical_gradient
//.........这里部分代码省略.........
// ... computes p*q^{p-1}*grad(q) ...
grad_vec[i] *= factor;
// ... and accumulates it in the objective function gradient.
grad[pd.get_vertex_index(ele_free_vtces[i])] += grad_vec[i];
}
}
}
// Computes objective function gradient for a vertex based metric
else if (qm_type==QualityMetric::VERTEX_BASED){
//if scaling, divide by the number of vertices
if(dividingByN){
if(num_elements<=0) {
MSQ_SETERR(err)("The number of vertices should not be zero.",MsqError::INVALID_MESH);
return false;
}
scaling_value/=num_vertices;
}
//vector for storing indices of vertex's connected elems
msq_std::vector<size_t> vert_on_vert_ind;
//position in pd's vertex array
size_t vert_count=0;
//position in vertex array
size_t vert_pos=0;
//loop over the free vertex indices to find the gradient...
size_t vfv_array_length=10;//holds the current legth of vert_free_vtces
msq_std::vector<MsqVertex*> vert_free_vtces(vfv_array_length);
msq_std::vector<Vector3D> grad_vec(vfv_array_length);
for(vert_count=0; vert_count<num_vertices; ++vert_count){
//For now we compute the metric for attached vertices and this
//vertex, the above line gives us the attached vertices. Now,
//we must add this vertex.
pd.get_adjacent_vertex_indices(vert_count,
vert_on_vert_ind,err);
vert_on_vert_ind.push_back(vert_count);
size_t vert_num_vtces = vert_on_vert_ind.size();
// dynamic memory management if arrays are too small.
if(vert_num_vtces > vfv_array_length){
vfv_array_length=vert_num_vtces+5;
vert_free_vtces.resize(vfv_array_length);
grad_vec.resize(vfv_array_length);
}
size_t vert_num_free_vtces=0;
//loop over the vertices connected to this one (vert_count)
//and put the free ones into vert_free_vtces
while(!vert_on_vert_ind.empty()){
vert_pos=(vert_on_vert_ind.back());
//clear the vector as we go
vert_on_vert_ind.pop_back();
//if the vertex is free, add it to ver_free_vtces
if(vertices[vert_pos].is_free_vertex()){
vert_free_vtces[vert_num_free_vtces]=&vertices[vert_pos];
++vert_num_free_vtces ;
}
}
qm_bool=currentQM->compute_vertex_gradient(pd,
vertices[vert_count],
&vert_free_vtces[0],
&grad_vec[0],
vert_num_free_vtces,
QM_val, err);
if(MSQ_CHKERR(err) || !qm_bool){
return false;
}
// computes p*|Q(e)|^{p-1}
QM_val = fabs(QM_val);
double QM_pow = 1.0;
double factor;
if (pVal==1) factor=1;
else {
QM_pow=QM_val;
for (p1=1; p1<pVal-1; ++p1)
QM_pow*=QM_val;
factor = QM_pow * pVal;
}
//this scales the gradient
factor *= (scaling_value * get_negate_flag());
// computes Objective Function value \sum_{i=1}^{N_v} |q_i|^P
// possibly scaled by 1/num
OF_val += (scaling_value * QM_pow * QM_val);
// For each free vertex around the vertex (and the vertex itself if free) ...
for (i=0; i < vert_num_free_vtces ; ++i) {
// ... computes p*q^{p-1}*grad(q) ...
grad_vec[i] *= factor;
// ... and accumulates it in the objective function gradient.
grad[pd.get_vertex_index(vert_free_vtces[i])] += grad_vec[i];
}
}
}
OF_val *= get_negate_flag();
return true;
}