本文整理汇总了C++中PatchData::get_subpatch方法的典型用法代码示例。如果您正苦于以下问题:C++ PatchData::get_subpatch方法的具体用法?C++ PatchData::get_subpatch怎么用?C++ PatchData::get_subpatch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PatchData
的用法示例。
在下文中一共展示了PatchData::get_subpatch方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: all
/*!
Numerically Calculates the gradient of the ObjectiveFunction for the
free vertices in the patch. Returns 'false' if the patch is outside
of a required feasible region, returns 'ture' otherwise.
The behavior of the function depends on the value of the boolean
useLocalGradient. If useLocalGradient is set to
'true', compute_numerical_gradient creates a sub-patch around a free
vertex, and then perturbs that vertex in one of the coordinate directions.
Only the ObjectiveFunction value on the local sub-patch is used in the
computation of the gradient. Therefore, useLocalGradient should only
be set to 'true' for ObjectiveFunctions which can use this method. Unless
the concrete ObjectiveFunction sets useLocalGradient to 'true' in its
constructor, the value will be 'false'. In this case, the objective
function value for the entire patch is used in the calculation of the
gradient. This is computationally expensive, but it is numerically
correct for all (C_1) functions.
\param pd PatchData on which the gradient is taken.
\param grad Array of Vector3D of length the number of vertices used to store gradient.
\param OF_val will be set to the objective function value.
*/
bool ObjectiveFunction::evaluate_with_gradient( EvalType eval_type,
PatchData &pd,
double& OF_val,
std::vector<Vector3D>& grad,
MsqError &err )
{
bool b;
grad.resize( pd.num_free_vertices() );
// Fast path for single-free-vertex patch
if (pd.num_free_vertices() == 1) {
const EvalType sub_type = (eval_type == CALCULATE) ? CALCULATE : TEMPORARY;
b = compute_subpatch_numerical_gradient( eval_type, sub_type, pd, OF_val, grad[0], err );
return !MSQ_CHKERR(err) && b;
}
ObjectiveFunction* of = this;
std::auto_ptr<ObjectiveFunction> deleter;
if (eval_type == CALCULATE) {
of->clear();
b = of->evaluate( ACCUMULATE, pd, OF_val, OF_FREE_EVALS_ONLY, err );
if (err) { // OF doesn't support BCD type evals, try slow method
err.clear();
of->clear();
b = compute_patch_numerical_gradient( CALCULATE, CALCULATE, pd, OF_val, grad, err );
return !MSQ_CHKERR(err) && b;
}
else if (!b)
return b;
}
else {
b = this->evaluate( eval_type, pd, OF_val, OF_FREE_EVALS_ONLY, err );
if (MSQ_CHKERR(err) || !b)
return false;
of = this->clone();
deleter = std::auto_ptr<ObjectiveFunction>(of);
}
// Determine number of layers of adjacent elements based on metric type.
unsigned layers = min_patch_layers();
// Create a subpatch for each free vertex and use it to evaluate the
// gradient for that vertex.
double flocal;
PatchData subpatch;
for (size_t i = 0; i < pd.num_free_vertices(); ++i)
{
pd.get_subpatch( i, layers, subpatch, err ); MSQ_ERRZERO(err);
b = of->compute_subpatch_numerical_gradient( SAVE, TEMPORARY, subpatch, flocal, grad[i], err );
if (MSQ_CHKERR(err) || !b) {
of->clear();
return false;
}
}
of->clear();
return true;
}