Ejemplo n.º 1
0
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);
}
Ejemplo n.º 2
0
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;
}