<commit_before>#include "stdafx.h"
#include <fstream>
#include <map>
#include <stdio.h>
#include <thread>
#include <ctime>
#include <chrono>
#include "parser.hpp"
#include "geometry.hpp"
#include "renderer.hpp"
#include "sphere.hpp"
#include "camera.hpp"
#include "material.hpp"
#include "color.hpp"
#include "plane.hpp"
#include "union.hpp"
#include "film.hpp"
#include "mesh.hpp"

#define TINYOBJLOADER_IMPLEMENTATION // define this in only *one* .cc
#include "tiny_obj_loader.h"

namespace renderer {

	void renderArea(Renderer &renderer, Film* film, Shape* pUnion, PerspectiveCamera& camera, Vector3dF& lightDir, int maxReflect, int x, int y, int w, int h)
	{
		renderer.rayTraceReflection(film, pUnion, camera, lightDir, maxReflect, x, y, w, h);
	}

	int Parser::parseFromFile(std::string path, Film * film) {
		using json = nlohmann::json;
		std::ifstream f("config.json");
		std::string config_string((std::istreambuf_iterator<char>(f)),
			(std::istreambuf_iterator<char>()));
		f.close();
		json config = json::parse(config_string);

		int width = config["width"], height = config["height"], multithread = config["multithread"];
		printf("width: %d, height: %d, multithread: %d \n", width, height, multithread);
		if(film->width()!=width || film->height()!=height)
			film->resize(width, height);

		std::map<int, Material*> matDict;

		for (auto objinfo : config["material"]) {
			Material* mt = nullptr;
			if (objinfo["type"] == "Phone") {
				auto pool = GetPool<PhongMaterial>();
				mt = pool->newElement(parseColor(objinfo["diffuse"]),
						parseColor(objinfo["specular"]),
						objinfo["shininess"],
						objinfo["reflectiveness"]);
			}
			else if (objinfo["type"] == "Checker") {
				auto pool = GetPool<CheckerMaterial>();
				mt = pool->newElement(objinfo["scale"], objinfo["reflectiveness"]);
			}
			matDict[objinfo["id"]] = mt;
		}
		int maxReflect = config["maxReflect"];

		Vector3dF lightDir;
		std::vector<Shape*> vecGeo;
		for (auto objinfo : config["scene"]) {
			Shape* pg = nullptr;
			if (objinfo["type"] == "Light") {
				auto pos = objinfo["pos"];
				auto color = objinfo["color"];
				lightDir.x = pos[0];
				lightDir.y = pos[1];
				lightDir.z = pos[2];
				continue;
			}
			else if (objinfo["type"] == "Sphere") {
				auto pos = objinfo["pos"];
				auto pool = GetPool<Sphere>();
				pg = pool->newElement(Vector3dF(pos[0], pos[1], pos[2]),
					objinfo["radius"]);
				pg->material = matDict[objinfo["matId"]];
			}
			else if (objinfo["type"] == "Plane") {
				auto normal = objinfo["normal"];
				auto pool = GetPool<Plane>();
				pg = pool->newElement(Vector3dF(normal[0], normal[1], normal[2]),
					   objinfo["distance"] );
				pg->material = matDict[objinfo["matId"]];
			}
			else if (objinfo["type"] == "Mesh") {
				auto pool = GetPool<Mesh>();
				VectorArray vertices, normals;
				UIntArray indexes;
				UVArray uvs;
				for (auto vertice : objinfo["vertices"]) {
					vertices.push_back(Vector3dF(vertice[0], vertice[1], vertice[2]));
				}
				for (auto normal : objinfo["normals"]) {
					normals.push_back(Vector3dF(normal[0], normal[1], normal[2]));
				}
				for (auto index : objinfo["indexes"]) {
					indexes.push_back(index);
				}
				for (auto uv : objinfo["uvs"]) {
					uvs.push_back(Vector2dF(uv[0], uv[1]));
				}
				pg = pool->newElement(vertices, normals, indexes, uvs);
				pg->material = matDict[objinfo["matId"]];
			}
			else
				continue;
			vecGeo.push_back(pg);
		} 
		ShapeUnion shapeUnion(vecGeo);

		auto eye = config["camera"]["eye"];
		auto front = config["camera"]["front"];
		auto up = config["camera"]["up"];

		PerspectiveCamera camera(Vector3dF(eye[0], eye[1], eye[2]).Normalize(),
			Vector3dF(front[0], front[1], front[2]).Normalize(),
			Vector3dF(up[0], up[1], up[2]).Normalize(),
			config["camera"]["fov"]);

		Renderer renderer;

		auto time0 = std::chrono::system_clock::now();<commit_msg>no message<commit_after>#include "stdafx.h"
#include <fstream>
#include <map>
#include <stdio.h>
#include <thread>
#include <ctime>
#include <chrono>
#include "parser.hpp"
#include "geometry.hpp"
#include "renderer.hpp"
#include "sphere.hpp"
#include "camera.hpp"
#include "material.hpp"
#include "color.hpp"
#include "plane.hpp"
#include "union.hpp"
#include "film.hpp"
#include "mesh.hpp"

#define TINYOBJLOADER_IMPLEMENTATION // define this in only *one* .cc
#include "tiny_obj_loader.h"

namespace renderer {

	void renderArea(Renderer &renderer, Film* film, Shape* pUnion, PerspectiveCamera& camera, Vector3dF& lightDir, int maxReflect, int x, int y, int w, int h)
	{
		renderer.rayTraceReflection(film, pUnion, camera, lightDir, maxReflect, x, y, w, h);
	}

	int Parser::parseFromFile(std::string path, Film * film) {
		using json = nlohmann::json;
		std::ifstream f("config.json");
		std::string config_string((std::istreambuf_iterator<char>(f)),
			(std::istreambuf_iterator<char>()));
		f.close();
		json config = json::parse(config_string);

		int width = config["width"], height = config["height"], multithread = config["multithread"];
		printf("width: %d, height: %d, multithread: %d \n", width, height, multithread);
		if(film->width()!=width || film->height()!=height)
			film->resize(width, height);

		std::map<int, Material*> matDict;

		for (auto objinfo : config["material"]) {
			Material* mt = nullptr;
			if (objinfo["type"] == "Phone") {
				auto pool = GetPool<PhongMaterial>();
				mt = pool->newElement(parseColor(objinfo["diffuse"]),
						parseColor(objinfo["specular"]),
						objinfo["shininess"],
						objinfo["reflectiveness"]);
			}
			else if (objinfo["type"] == "Checker") {
				auto pool = GetPool<CheckerMaterial>();
				mt = pool->newElement(objinfo["scale"], objinfo["reflectiveness"]);
			}
			matDict[objinfo["id"]] = mt;
		}
		int maxReflect = config["maxReflect"];

		Vector3dF lightDir;
		std::vector<Shape*> vecGeo;
		for (auto objinfo : config["scene"]) {
			Shape* pg = nullptr;
			if (objinfo["type"] == "Light") {
				auto pos = objinfo["pos"];
				auto color = objinfo["color"];
				lightDir.x = pos[0];
				lightDir.y = pos[1];
				lightDir.z = pos[2];
				continue;
			}
			else if (objinfo["type"] == "Sphere") {
				auto pos = objinfo["pos"];
				auto pool = GetPool<Sphere>();
				pg = pool->newElement(Vector3dF(pos[0], pos[1], pos[2]),
					objinfo["radius"]);
				pg->material = matDict[objinfo["matId"]];
			}
			else if (objinfo["type"] == "Plane") {
				auto normal = objinfo["normal"];
				auto pool = GetPool<Plane>();
				pg = pool->newElement(Vector3dF(normal[0], normal[1], normal[2]),
					   objinfo["distance"] );
				pg->material = matDict[objinfo["matId"]];
			}
			else if (objinfo["type"] == "Mesh") {
				auto pool = GetPool<Mesh>();
				VectorArray vertices, normals;
				UIntArray indexes;
				UVArray uvs;
				for (auto vertice : objinfo["vertices"]) {
					vertices.push_back(Vector3dF(vertice[0], vertice[1], vertice[2]));
				}
				for (auto normal : objinfo["normals"]) {
					normals.push_back(Vector3dF(normal[0], normal[1], normal[2]));
				}
				for (auto index : objinfo["indexes"]) {
					indexes.push_back(index);
				}
				for (auto uv : objinfo["uvs"]) {
					uvs.push_back(Vector2dF(uv[0], uv[1]));
				}
				pg = pool->newElement(vertices, normals, indexes, uvs);
				pg->material = matDict[objinfo["matId"]];
			}
			else
				continue;
			vecGeo.push_back(pg);
		} 
		ShapeUnion shapeUnion(vecGeo);

		auto eye = config["camera"]["eye"];
		auto front = config["camera"]["front"];
		auto up = config["camera"]["up"];

		PerspectiveCamera camera(Vector3dF(eye[0], eye[1], eye[2]),
			Vector3dF(front[0], front[1], front[2]).Normalize(),
			Vector3dF(up[0], up[1], up[2]).Normalize(),
			config["camera"]["fov"]);

		Renderer renderer;

		auto time0 = std::chrono::system_clock::now();
{'fraction_non_alphanumeric': 0.1863010171237286, 'fraction_numerical': 0.009527488090639887, 'mean_word_length': 4.3757785467128025, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 55, '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': '5166551', 'n_tokens_mistral': 3169, 'n_tokens_neox': 2744, 'n_words': 578}