<commit_before>#include "LightInSurface.h"


LightInSurface::LightInSurface(PMOptixRenderer *renderer, Scene *scene, const QString& lightId, const QString& surfaceId):
	m_surfaceId(surfaceId),
	renderer(renderer)
{
	int objectId = scene->getObjectId(surfaceId);

	if(objectId < 0)
		throw std::invalid_argument(("There isn't any object named " + surfaceId + " in the scene").toStdString());

	QVector<Vector3> objectPoints = scene->getObjectPoints(objectId);
	if(objectPoints.length() != 4)
		throw std::invalid_argument((surfaceId + " must have 4 vertices").toStdString());

	base = objectPoints[0];
	
	optix::float3 pointA = (optix::float3) objectPoints[1] - (optix::float3)objectPoints[0];
	optix::float3 pointB = (optix::float3) objectPoints[2] - (optix::float3)objectPoints[0];

	u = normalize(pointA);
	v = normalize(cross(cross(pointA, pointB), pointA));
	
	a = optix::make_float2(dot(u, pointA), dot(v, pointA));
	b = optix::make_float2(dot(u, pointB), dot(v, pointB));

	optix::float3 pointC = (optix::float3) objectPoints[3] - (optix::float3) objectPoints[0];

	c = optix::make_float2( dot(u, pointC), dot(v, pointC));
}

void LightInSurface::pushMoveToNeighbourhood(float radius)
{
	auto center4 = optix::make_float4(base, 1.0f);

	for(auto transformationIt = savedMovements.begin(); transformationIt != savedMovements.end(); ++transformationIt)
	{
		center4 = (*transformationIt) * center4;
	}

	auto center = optix::make_float3(center4 / center4.w);
	auto neighbour = generatePointNeighbourhood(center, radius);
	
	// saves last movement
	auto displacement = neighbour - center;
	auto displacementTransformation = optix::Matrix4x4().identity().translate(displacement);
	savedMovements.push(displacementTransformation);
}

void LightInSurface::popLastMovement()
{
	savedMovements.pop();
}

optix::float3 LightInSurface::generatePointNeighbourhood(optix::float3 centerWorldCoordinates, float radius) const
{<commit_msg>LightInSurface correction in neighbourhood points generation<commit_after>#include "LightInSurface.h"


LightInSurface::LightInSurface(PMOptixRenderer *renderer, Scene *scene, const QString& lightId, const QString& surfaceId):
	m_surfaceId(surfaceId),
	renderer(renderer)
{
	int objectId = scene->getObjectId(surfaceId);

	if(objectId < 0)
		throw std::invalid_argument(("There isn't any object named " + surfaceId + " in the scene").toStdString());

	QVector<Vector3> objectPoints = scene->getObjectPoints(objectId);
	if(objectPoints.length() != 4)
		throw std::invalid_argument((surfaceId + " must have 4 vertices").toStdString());

	base = objectPoints[0];
	
	optix::float3 pointA = (optix::float3) objectPoints[1] - (optix::float3)objectPoints[0];
	optix::float3 pointB = (optix::float3) objectPoints[2] - (optix::float3)objectPoints[0];

	u = normalize(pointA);
	v = normalize(cross(cross(pointA, pointB), pointA));
	
	a = optix::make_float2(dot(u, pointA), dot(v, pointA));
	b = optix::make_float2(dot(u, pointB), dot(v, pointB));

	optix::float3 pointC = (optix::float3) objectPoints[3] - (optix::float3) objectPoints[0];

	c = optix::make_float2( dot(u, pointC), dot(v, pointC));
}

void LightInSurface::pushMoveToNeighbourhood(float radius)
{
	auto currentTransformation = optix::Matrix4x4::identity();

	for(auto transformationIt = savedMovements.begin(); transformationIt != savedMovements.end(); ++transformationIt)
	{
		currentTransformation = (*transformationIt) * currentTransformation;
	}

	auto center4 = currentTransformation * optix::make_float4(base, 1.0f);
	auto center = optix::make_float3(center4 / center4.w);
	auto neighbour = generatePointNeighbourhood(center, radius);
	
	// saves last movement
	auto displacement = neighbour - center;
	auto displacementTransformation = optix::Matrix4x4().identity().translate(displacement);
	savedMovements.push(displacementTransformation);

	// applies currentTransformation to the renderer
	currentTransformation = displacementTransformation * currentTransformation;
	renderer->setNodeTransformation(m_surfaceId, currentTransformation);
}

void LightInSurface::popLastMovement()
{
	savedMovements.pop();

	auto currentTransformation = optix::Matrix4x4::identity();
	for(auto transformationIt = savedMovements.begin(); transformationIt != savedMovements.end(); ++transformationIt)
	{
		currentTransformation = (*transformationIt) * currentTransformation;
	}
	renderer->setNodeTransformation(m_surfaceId, currentTransformation);
}

optix::float3 LightInSurface::generatePointNeighbourhood(optix::float3 centerWorldCoordinates, float radius) const
{
{'fraction_non_alphanumeric': 0.1354625550660793, 'fraction_numerical': 0.01629955947136564, 'mean_word_length': 7.393715341959335, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5496935', 'n_tokens_mistral': 1490, 'n_tokens_neox': 1436, 'n_words': 281}