<commit_before>// Include standard headers
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <math.h>

#include "letter_coordinates.hpp"

using namespace std;

// Include GLEW
#include <GL/glew.h>

// Include GLFW
#include <glfw3.h>
GLFWwindow* window;

// Include GLM
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
using namespace glm;

#include <common/shader.hpp>
//#include <common/texture.hpp>
#include <common/controls.hpp>

/* Constants */
#define STD_RADIUS 0.1

/* Forward declarations */
GLfloat getXVector (const double aPhi, const double aTheta);
GLfloat getYVector (const double aPhi, const double aTheta);
GLfloat getZVector (const double aTheta);

/* Obtained from http://oopweb.com/CPP/Documents/CPPHOWTO/Volume/C++Programming-HOWTO-7.html */
void Tokenize(const string& str,
				vector<string>& tokens,
				const string& delimiters)
{
    // Skip delimiters at beginning.
    string::size_type lastPos = str.find_first_not_of(delimiters, 0);
    // Find first "non-delimiter".
    string::size_type pos     = str.find_first_of(delimiters, lastPos);

    while (string::npos != pos || string::npos != lastPos)
    {
        // Found a token, add it to the vector.
        tokens.push_back(str.substr(lastPos, pos - lastPos));
        // Skip delimiters.  Note the "not_of"
        lastPos = str.find_first_not_of(delimiters, pos);
        // Find next "non-delimiter"
        pos = str.find_first_of(delimiters, lastPos);
    }
}

/*
 * Standard convention is:
 * x = r * sin THETA * cos PHI
 * y = r * sin THETA * sin PHI
 * z = r * cos THETA
 *
 * Here we set r = 0.1 and swap axes for OpenGL such that:
 * Std ---> OpenGL
 *  x  --->   z
 *  y  --->   x
 *  z  --->   y
 */

void getVectors(GLfloat &aDeltaX, GLfloat &aDeltaY, GLfloat &aDeltaZ, const double aPhi, const double aTheta)
{
	aDeltaX = getYVector(aPhi, aTheta);
	aDeltaY = getZVector(aTheta);
	aDeltaZ = getXVector(aPhi, aTheta);
}

GLfloat getXVector (const double aPhi, const double aTheta)
{
	return STD_RADIUS * sin(aTheta) * cos(aPhi);
}

GLfloat getYVector (const double aPhi, const double aTheta)
{
	return STD_RADIUS * sin(aTheta) * sin(aPhi);
}

GLfloat getZVector (const double aTheta)
{
	return STD_RADIUS * cos(aTheta);
}

void populateSensorVertexBuffers(int aSensorIndex, const vector<string>& aMovementsPairs, GLfloat* aSensorVertexBufferData) {
	//printf("sizeof(aSensorVertexBufferData): %li\n", sizeof(aSensorVertexBufferData));
	//printf("numVertexBufferElems: %li\n", numVertexBufferElems);
	GLfloat tempCoordinates[3] = { 0.0f, 0.0f, 0.0f };
	aSensorVertexBufferData[0] = 0.0f;
	aSensorVertexBufferData[1] = 0.0f;
	aSensorVertexBufferData[2] = 0.0f;
	for (int i = 0; i < aMovementsPairs.size(); i++) {
		int j = i * 3;
		string currentMovementPair = aMovementsPairs[i];
		//cout << currentMovementPair << endl;
		char currentMovement = currentMovementPair.c_str()[aSensorIndex];
		//cout << currentMovement << endl;
		/*
		 * Spherical gesture coordinates in PHI, THETA format
		 */
		GLfloat deltaX, deltaY, deltaZ;
		if (currentMovement == '_') {
			deltaX = 0.0f;
			deltaY = 0.0f;
			deltaZ = 0.0f;
		} else {
			struct sphericalCoordinates currentCoordinates =
					letterCoordinates[currentMovement];
			getVectors(deltaX, deltaY, deltaZ,
					degreesToRadians(currentCoordinates.mPhi),
					degreesToRadians(currentCoordinates.mTheta));
		}
		//cout << "movement " << currentS1Movement << " dx: " << deltaX << " dy: " << deltaY << " dz: " << deltaZ << endl;
		tempCoordinates[0] += deltaX;
		tempCoordinates[1] += deltaY;
		tempCoordinates[2] += deltaZ;
		aSensorVertexBufferData[j + 3] = tempCoordinates[0];
		aSensorVertexBufferData[j + 4] = tempCoordinates[1];
		aSensorVertexBufferData[j + 5] = tempCoordinates[2];
		//printf("vertex[%i, %i, %i] = {%f, %f, %f}\n", j+3, j+4, j+5, tempCoordinates[0], tempCoordinates[1], tempCoordinates[2]);
	}
}

void populateSensorColorBuffers(GLfloat* aSensor0ColorBufferData, GLfloat* aSensor1ColorBufferData, int aNumVertexBufferElems)
{
	float colorIntensityInterval = 1.0f / (aNumVertexBufferElems / 3);

	GLfloat sensor0TempIntensities[3] = { 0.0f, 0.0f, 0.0f }; // R,G,B
	GLfloat sensor1TempIntensities[3] = { 0.0f, 0.0f, 0.0f }; // R,G,B

	/* Origin is colored with intensity 0.0f */
	for (int i = 0; i < 3; i++) {
		aSensor0ColorBufferData[i] = 0.0f;
		aSensor1ColorBufferData[i] = 0.0f;
	}

	for (int i = 3; i < (aNumVertexBufferElems-2); i+=3) {
		cout << "i: " << i << endl;
		sensor0TempIntensities[0] += colorIntensityInterval; // Intensify red for sensor 0
		sensor1TempIntensities[2] += colorIntensityInterval; // Intensify blue for sensor 1<commit_msg>Viewer: Fix color intensity jump interval<commit_after>// Include standard headers
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <math.h>

#include "letter_coordinates.hpp"

using namespace std;

// Include GLEW
#include <GL/glew.h>

// Include GLFW
#include <glfw3.h>
GLFWwindow* window;

// Include GLM
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
using namespace glm;

#include <common/shader.hpp>
//#include <common/texture.hpp>
#include <common/controls.hpp>

/* Constants */
#define STD_RADIUS 0.1

/* Forward declarations */
GLfloat getXVector (const double aPhi, const double aTheta);
GLfloat getYVector (const double aPhi, const double aTheta);
GLfloat getZVector (const double aTheta);

/* Obtained from http://oopweb.com/CPP/Documents/CPPHOWTO/Volume/C++Programming-HOWTO-7.html */
void Tokenize(const string& str,
				vector<string>& tokens,
				const string& delimiters)
{
    // Skip delimiters at beginning.
    string::size_type lastPos = str.find_first_not_of(delimiters, 0);
    // Find first "non-delimiter".
    string::size_type pos     = str.find_first_of(delimiters, lastPos);

    while (string::npos != pos || string::npos != lastPos)
    {
        // Found a token, add it to the vector.
        tokens.push_back(str.substr(lastPos, pos - lastPos));
        // Skip delimiters.  Note the "not_of"
        lastPos = str.find_first_not_of(delimiters, pos);
        // Find next "non-delimiter"
        pos = str.find_first_of(delimiters, lastPos);
    }
}

/*
 * Standard convention is:
 * x = r * sin THETA * cos PHI
 * y = r * sin THETA * sin PHI
 * z = r * cos THETA
 *
 * Here we set r = 0.1 and swap axes for OpenGL such that:
 * Std ---> OpenGL
 *  x  --->   z
 *  y  --->   x
 *  z  --->   y
 */

void getVectors(GLfloat &aDeltaX, GLfloat &aDeltaY, GLfloat &aDeltaZ, const double aPhi, const double aTheta)
{
	aDeltaX = getYVector(aPhi, aTheta);
	aDeltaY = getZVector(aTheta);
	aDeltaZ = getXVector(aPhi, aTheta);
}

GLfloat getXVector (const double aPhi, const double aTheta)
{
	return STD_RADIUS * sin(aTheta) * cos(aPhi);
}

GLfloat getYVector (const double aPhi, const double aTheta)
{
	return STD_RADIUS * sin(aTheta) * sin(aPhi);
}

GLfloat getZVector (const double aTheta)
{
	return STD_RADIUS * cos(aTheta);
}

void populateSensorVertexBuffers(int aSensorIndex, const vector<string>& aMovementsPairs, GLfloat* aSensorVertexBufferData) {
	//printf("sizeof(aSensorVertexBufferData): %li\n", sizeof(aSensorVertexBufferData));
	//printf("numVertexBufferElems: %li\n", numVertexBufferElems);
	GLfloat tempCoordinates[3] = { 0.0f, 0.0f, 0.0f };
	aSensorVertexBufferData[0] = 0.0f;
	aSensorVertexBufferData[1] = 0.0f;
	aSensorVertexBufferData[2] = 0.0f;
	for (int i = 0; i < aMovementsPairs.size(); i++) {
		int j = i * 3;
		string currentMovementPair = aMovementsPairs[i];
		//cout << currentMovementPair << endl;
		char currentMovement = currentMovementPair.c_str()[aSensorIndex];
		//cout << currentMovement << endl;
		/*
		 * Spherical gesture coordinates in PHI, THETA format
		 */
		GLfloat deltaX, deltaY, deltaZ;
		if (currentMovement == '_') {
			deltaX = 0.0f;
			deltaY = 0.0f;
			deltaZ = 0.0f;
		} else {
			struct sphericalCoordinates currentCoordinates =
					letterCoordinates[currentMovement];
			getVectors(deltaX, deltaY, deltaZ,
					degreesToRadians(currentCoordinates.mPhi),
					degreesToRadians(currentCoordinates.mTheta));
		}
		//cout << "movement " << currentS1Movement << " dx: " << deltaX << " dy: " << deltaY << " dz: " << deltaZ << endl;
		tempCoordinates[0] += deltaX;
		tempCoordinates[1] += deltaY;
		tempCoordinates[2] += deltaZ;
		aSensorVertexBufferData[j + 3] = tempCoordinates[0];
		aSensorVertexBufferData[j + 4] = tempCoordinates[1];
		aSensorVertexBufferData[j + 5] = tempCoordinates[2];
		//printf("vertex[%i, %i, %i] = {%f, %f, %f}\n", j+3, j+4, j+5, tempCoordinates[0], tempCoordinates[1], tempCoordinates[2]);
	}
}

void populateSensorColorBuffers(GLfloat* aSensor0ColorBufferData, GLfloat* aSensor1ColorBufferData, int aNumVertexBufferElems)
{
	int numMovements = aNumVertexBufferElems / 3;
	int numColorIntensityJumps = numMovements - 1;
	float colorIntensityInterval = 1.0f / numColorIntensityJumps;

	GLfloat sensor0TempIntensities[3] = { 0.0f, 0.0f, 0.0f }; // R,G,B
	GLfloat sensor1TempIntensities[3] = { 0.0f, 0.0f, 0.0f }; // R,G,B

	/* Origin is colored with intensity 0.0f */
	for (int i = 0; i < 3; i++) {
		aSensor0ColorBufferData[i] = 0.0f;
		aSensor1ColorBufferData[i] = 0.0f;
	}

	for (int i = 3; i < (aNumVertexBufferElems-2); i+=3) {
		cout << "i: " << i << endl;
		sensor0TempIntensities[0] += colorIntensityInterval; // Intensify red for sensor 0
		sensor1TempIntensities[2] += colorIntensityInterval; // Intensify blue for sensor 1
{'fraction_non_alphanumeric': 0.13924583947756478, 'fraction_numerical': 0.018432694333263114, 'mean_word_length': 4.053219797764768, 'pattern_counts': {'":': 0, '<': 103, '<?xml version=': 0, '>': 41, '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': '7210542', 'n_tokens_mistral': 3690, 'n_tokens_neox': 3492, 'n_words': 815}