<commit_before>/*
 * OGLSpheresVisualization.cpp
 *
 *  Created on: 30 août 2014
 *      Author: <NAME>
 */

#include <string>
#include <chrono>
#include <thread>
#include <vector>
#include <cassert>
#include <iostream>

#define GLM_FORCE_RADIANS
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtx/transform.hpp>

#include "OGLTools.h"

#include "OGLSpheresVisualization.h"

template <typename T>
OGLSpheresVisualization<T>::OGLSpheresVisualization(const string winName,
                                                    const int winWidth,
                                                    const int winHeight,
                                                    const T *positionsX,
                                                    const T *positionsY,
                                                    const T *positionsZ,
                                                    const T *radius,
                                                    const unsigned long nSpheres)
	: window           (NULL),
	  positionsX       (positionsX),
	  positionsXBuffer (NULL),
	  positionsY       (positionsY),
	  positionsYBuffer (NULL),
	  positionsZ       (positionsZ),
	  positionsZBuffer (NULL),
	  radius           (radius),
	  radiusBuffer     (NULL),
	  nSpheres         (nSpheres),
	  vertexArrayRef   ((GLuint) 0),
	  positionBufferRef{(GLuint) 0, (GLuint) 0, (GLuint) 0},
	  radiusBufferRef  ((GLuint) 0),
	  mvpRef           ((GLuint) 0),
	  shaderProgramRef ((GLuint) 0),
	  mvp              (glm::mat4(1.0f)),
	  control          (NULL)
{
	assert(winWidth > 0);
	assert(winHeight > 0);
	assert(positionsX);
	assert(positionsY);
	assert(positionsZ);
	assert(radius);

	if(sizeof(T) == sizeof(float))
	{
#ifndef NBODY_DOUBLE //TODO: delete this define, this is just a patch to compile when using double
		this->positionsXBuffer = const_cast<T*>(positionsX); //TODO: do not use const_cast !
		this->positionsYBuffer = const_cast<T*>(positionsY); //TODO: do not use const_cast !
		this->positionsZBuffer = const_cast<T*>(positionsZ); //TODO: do not use const_cast !
		this->radiusBuffer     = const_cast<T*>(radius);     //TODO: do not use const_cast !
#endif
	}
	else
	{
		this->positionsXBuffer = new float[this->nSpheres];
		this->positionsYBuffer = new float[this->nSpheres];
		this->positionsZBuffer = new float[this->nSpheres];
		this->radiusBuffer     = new float[this->nSpheres];

		for(unsigned long iVertex = 0; iVertex < this->nSpheres; iVertex++)
			this->radiusBuffer[iVertex] = (float) this->radius[iVertex];
	}

	this->window = OGLTools::initAndMakeWindow(winWidth, winHeight, winName.c_str());

	if(this->window)
	{
		glGenVertexArrays(1, &(this->vertexArrayRef));
		glBindVertexArray(this->vertexArrayRef);

		// set background color to black
		glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

		// bind position and radius buffers to OpenGL system
		glGenBuffers(1, &this->positionBufferRef[0]); // can change over iterations, so binding is in refreshDisplay()
		glGenBuffers(1, &this->positionBufferRef[1]); // can change over iterations, so binding is in refreshDisplay()
		glGenBuffers(1, &this->positionBufferRef[2]); // can change over iterations, so binding is in refreshDisplay()

		glGenBuffers(1, &(this->radiusBufferRef));
		glBindBuffer(GL_ARRAY_BUFFER, this->radiusBufferRef);
		glBufferData(GL_ARRAY_BUFFER, this->nSpheres * sizeof(GLfloat), this->radiusBuffer, GL_STATIC_DRAW);

		// Enable depth test
		glEnable(GL_DEPTH_TEST);

		// Accept fragment if it closer to the camera than the former one
		glDepthFunc(GL_LESS);

		// Create a control object in order to use mouse and keyboard (move in space)
		this->control = new OGLControl(this->window);

		// specify shaders path and compile them
		vector<GLenum> shadersType(3);
		vector<string> shadersFiles(3);
		shadersType[0] = GL_VERTEX_SHADER;   shadersFiles[0] = "src/ogl/shaders/vertex150.glsl";
		shadersType[1] = GL_GEOMETRY_SHADER; shadersFiles[1] = "src/ogl/shaders/geometry150.glsl";
		shadersType[2] = GL_FRAGMENT_SHADER; shadersFiles[2] = "src/ogl/shaders/fragment150.glsl";

		this->compileShaders(shadersType, shadersFiles);
	}
}
<commit_msg>Fermeture de la fenêtre OpenGL si la compilation des shaders échoue.<commit_after>/*
 * OGLSpheresVisualization.cpp
 *
 *  Created on: 30 août 2014
 *      Author: <NAME>
 */

#include <string>
#include <chrono>
#include <thread>
#include <vector>
#include <cassert>
#include <iostream>

#define GLM_FORCE_RADIANS
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtx/transform.hpp>

#include "OGLTools.h"

#include "OGLSpheresVisualization.h"

template <typename T>
OGLSpheresVisualization<T>::OGLSpheresVisualization(const string winName,
                                                    const int winWidth,
                                                    const int winHeight,
                                                    const T *positionsX,
                                                    const T *positionsY,
                                                    const T *positionsZ,
                                                    const T *radius,
                                                    const unsigned long nSpheres)
	: window           (NULL),
	  positionsX       (positionsX),
	  positionsXBuffer (NULL),
	  positionsY       (positionsY),
	  positionsYBuffer (NULL),
	  positionsZ       (positionsZ),
	  positionsZBuffer (NULL),
	  radius           (radius),
	  radiusBuffer     (NULL),
	  nSpheres         (nSpheres),
	  vertexArrayRef   ((GLuint) 0),
	  positionBufferRef{(GLuint) 0, (GLuint) 0, (GLuint) 0},
	  radiusBufferRef  ((GLuint) 0),
	  mvpRef           ((GLuint) 0),
	  shaderProgramRef ((GLuint) 0),
	  mvp              (glm::mat4(1.0f)),
	  control          (NULL)
{
	assert(winWidth > 0);
	assert(winHeight > 0);
	assert(positionsX);
	assert(positionsY);
	assert(positionsZ);
	assert(radius);

	if(sizeof(T) == sizeof(float))
	{
#ifndef NBODY_DOUBLE //TODO: delete this define, this is just a patch to compile when using double
		this->positionsXBuffer = const_cast<T*>(positionsX); //TODO: do not use const_cast !
		this->positionsYBuffer = const_cast<T*>(positionsY); //TODO: do not use const_cast !
		this->positionsZBuffer = const_cast<T*>(positionsZ); //TODO: do not use const_cast !
		this->radiusBuffer     = const_cast<T*>(radius);     //TODO: do not use const_cast !
#endif
	}
	else
	{
		this->positionsXBuffer = new float[this->nSpheres];
		this->positionsYBuffer = new float[this->nSpheres];
		this->positionsZBuffer = new float[this->nSpheres];
		this->radiusBuffer     = new float[this->nSpheres];

		for(unsigned long iVertex = 0; iVertex < this->nSpheres; iVertex++)
			this->radiusBuffer[iVertex] = (float) this->radius[iVertex];
	}

	this->window = OGLTools::initAndMakeWindow(winWidth, winHeight, winName.c_str());

	if(this->window)
	{
		glGenVertexArrays(1, &(this->vertexArrayRef));
		glBindVertexArray(this->vertexArrayRef);

		// set background color to black
		glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

		// bind position and radius buffers to OpenGL system
		glGenBuffers(1, &this->positionBufferRef[0]); // can change over iterations, so binding is in refreshDisplay()
		glGenBuffers(1, &this->positionBufferRef[1]); // can change over iterations, so binding is in refreshDisplay()
		glGenBuffers(1, &this->positionBufferRef[2]); // can change over iterations, so binding is in refreshDisplay()

		glGenBuffers(1, &(this->radiusBufferRef));
		glBindBuffer(GL_ARRAY_BUFFER, this->radiusBufferRef);
		glBufferData(GL_ARRAY_BUFFER, this->nSpheres * sizeof(GLfloat), this->radiusBuffer, GL_STATIC_DRAW);

		// Enable depth test
		glEnable(GL_DEPTH_TEST);

		// Accept fragment if it closer to the camera than the former one
		glDepthFunc(GL_LESS);

		// Create a control object in order to use mouse and keyboard (move in space)
		this->control = new OGLControl(this->window);

		// specify shaders path and compile them
		vector<GLenum> shadersType(3);
		vector<string> shadersFiles(3);
		shadersType[0] = GL_VERTEX_SHADER;   shadersFiles[0] = "src/ogl/shaders/vertex150.glsl";
		shadersType[1] = GL_GEOMETRY_SHADER; shadersFiles[1] = "src/ogl/shaders/geometry150.glsl";
		shadersType[2] = GL_FRAGMENT_SHADER; shadersFiles[2] = "src/ogl/shaders/fragment150.glsl";

		if(!this->compileShaders(shadersType, shadersFiles))
		{
			glfwDestroyWindow(this->window);
			this->window = 0;
		}
	}
}

{'fraction_non_alphanumeric': 0.11834600760456274, 'fraction_numerical': 0.012476235741444868, 'mean_word_length': 2.8967592592592593, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 101, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4998748', 'n_tokens_mistral': 2836, 'n_tokens_neox': 2584, 'n_words': 621}