本文整理汇总了C++中math::Tensor方法的典型用法代码示例。如果您正苦于以下问题:C++ math::Tensor方法的具体用法?C++ math::Tensor怎么用?C++ math::Tensor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类math
的用法示例。
在下文中一共展示了math::Tensor方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: operator
Tensor HeightField::operator()(math::Vector2f const & p) const
{
static const int dx = 2, dy = 2;
if (m_image.isNull())
{
return Tensor();
}
QPoint ip = m_image.toImageCoords(p).toPoint();
if (! QRect(QPoint(0,0), m_image.size()-QSize(dx,dy)).contains(ip))
{
return Tensor();
}
QRgb pix0 = m_image.pixel(ip);
float f0 = QColor::fromRgb(pix0).valueF();
QRgb pix1 = m_image.pixel(ip + QPoint(dx,0));
float f1 = QColor::fromRgb(pix1).valueF();
QRgb pix2 = m_image.pixel(ip + QPoint(0,dy));
float f2 = QColor::fromRgb(pix2).valueF();
qreal dHx = 100.0f * (f1 - f0);
qreal dHy = 100.0f * (f2 - f0);
qreal f = atan2f(dHy, dHx) + M_PI/2.0f;
qreal r = sqrtf(pow2(dHx) + pow2(dHy));
return Tensor(r, f);
}
示例2: Tensor
Tensor BasisSumField::operator()(Vector2f const & p) const
{
ElementList::const_iterator it;
unsigned int i;
unsigned int numElements = m_elements.size();
if (numElements == 0)
{
return Tensor();
}
typedef float real;
typedef real realv[numElements];
// calculate distances
//
realv dists;
real distsSum = 0.0f;
for (i = 0, it = m_elements.begin(); i < numElements; ++i, ++it)
{
Element * bf = *it;
real d = (p - bf->p0).norm();
if (d == 0.0) d = 0.001;
dists[i] = d;
distsSum += d;
}
// calculate "nearness" value
//
realv nears;
real nearsSum = 0.0f;
for (i = 0; i < numElements; ++i)
{
real n = math::pow2(distsSum / dists[i]);
nears[i] = n;
nearsSum += n;
}
// calculate vector sum
//
math::Tensor t;
for (i = 0, it = m_elements.begin(); i < numElements; ++i, ++it)
{
Element * bf = *it;
float w = nears[i] / nearsSum;
t += w * rbf(p, bf->p0, decay()) * bf->scale * (*bf)(p);
}
return t;
}