本文整理汇总了C++中xr_vector::assign方法的典型用法代码示例。如果您正苦于以下问题:C++ xr_vector::assign方法的具体用法?C++ xr_vector::assign怎么用?C++ xr_vector::assign使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xr_vector
的用法示例。
在下文中一共展示了xr_vector::assign方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: vfOptimizeParameters
void vfOptimizeParameters(xr_vector<xr_vector<REAL> > &A, xr_vector<xr_vector<REAL> > &B, xr_vector<REAL> &C, xr_vector<REAL> &D, REAL dEpsilon, REAL dAlpha, REAL dBeta, REAL dNormaFactor, u32 dwMaxIterationCount)
{
u32 dwTestCount = (u32)B.size();
xr_vector<REAL> daGradient;
xr_vector<REAL> daDelta;
xr_vector<xr_vector<REAL> > daEvalResults; daEvalResults.resize(dwTestCount);
if (!B.size()) {
clMsg ("! ERROR : there are no parameters to fit!");
return;
}
u32 dwParameterCount = (u32)B[0].size();
C.assign (dwParameterCount,1.0f);
D.assign (dwParameterCount,0.0f);
daDelta.assign (dwParameterCount,0);
daGradient.assign (dwParameterCount,0);
{
for (u32 i=0; i<dwTestCount; i++)
daEvalResults[i].resize(dwParameterCount);
}
u32 i = 0;
REAL dFunctional = dfComputeEvalResults(daEvalResults,A,B,C,D), dPreviousFunctional;
//clMsg ("* MU-fitter: %6d : %17.8f (%17.8f)",i,dFunctional,dFunctional/dwTestCount);
do {
dPreviousFunctional = dFunctional;
dafGradient (daEvalResults, daGradient, B, dNormaFactor);
std::transform (daGradient.begin(), daGradient.end(), daGradient.begin(), std::bind2nd(std::multiplies<REAL>(), -dAlpha));
std::transform (daDelta.begin(), daDelta.end(), daDelta.begin(), std::bind2nd(std::multiplies<REAL>(), dBeta));
std::transform (daGradient.begin(), daGradient.end(), daDelta.begin(), daDelta.begin(), std::plus<REAL>());
std::transform (C.begin(), C.end(), daDelta.begin(), C.begin(), std::plus<REAL>());
std::transform (D.begin(), D.end(), daDelta.begin(), D.begin(), std::plus<REAL>());
dFunctional = dfComputeEvalResults(daEvalResults,A,B,C,D);
i++;
}
while ((((dPreviousFunctional - dFunctional)/dwTestCount) > dEpsilon) && (i <= dwMaxIterationCount));
if (dPreviousFunctional < dFunctional) {
std::transform (daDelta.begin(), daDelta.end(), daDelta.begin(), std::bind2nd(std::multiplies<REAL>(), -1));
std::transform (C.begin(), C.end(), daDelta.begin(), C.begin(), std::plus<REAL>());
std::transform (D.begin(), D.end(), daDelta.begin(), D.begin(), std::plus<REAL>());
}
dFunctional = dfComputeEvalResults(daEvalResults,A,B,C,D);
//clMsg ("* MU-fitter: %6d : %17.8f (%17.8f)",i,dFunctional,dFunctional/dwTestCount);
}
示例2: highlight_ammo_for_weapon
void CUIActorMenu::highlight_ammo_for_weapon( PIItem weapon_item, CUIDragDropListEx* ddlist )
{
VERIFY( weapon_item );
VERIFY( ddlist );
static xr_vector<shared_str> ammo_types;
ammo_types.clear_not_free();
CWeapon* weapon = smart_cast<CWeapon*>(weapon_item);
if ( !weapon )
{
return;
}
ammo_types.assign( weapon->m_ammoTypes.begin(), weapon->m_ammoTypes.end() );
CWeaponMagazinedWGrenade* wg = smart_cast<CWeaponMagazinedWGrenade*>(weapon_item);
if ( wg )
{
if ( wg->IsGrenadeLauncherAttached() && wg->m_ammoTypes2.size() )
{
ammo_types.insert( ammo_types.end(), wg->m_ammoTypes2.begin(), wg->m_ammoTypes2.end() );
}
}
if ( ammo_types.size() == 0 )
{
return;
}
xr_vector<shared_str>::iterator ite = ammo_types.end();
u32 const cnt = ddlist->ItemsCount();
for ( u32 i = 0; i < cnt; ++i )
{
CUICellItem* ci = ddlist->GetItemIdx(i);
PIItem item = (PIItem)ci->m_pData;
if ( !item )
{
continue;
}
CWeaponAmmo* ammo = smart_cast<CWeaponAmmo*>(item);
if ( !ammo )
{
highlight_addons_for_weapon( weapon_item, ci );
continue; // for i
}
shared_str const& ammo_name = item->object().cNameSect();
xr_vector<shared_str>::iterator itb = ammo_types.begin();
for ( ; itb != ite; ++itb )
{
if ( ammo_name._get() == (*itb)._get() )
{
ci->m_select_armament = true;
break; // itb
}
}
}//for i
}