<commit_before>// 3DDiffusion.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "operations.h"
#include "binvox.h"

const pixelType borderColor = -1.0f;
const pixelType intialColor = -0.1f;
const pixelType surfaceColor = 0.0f;
const pixelType interiorColor = 1.0f;

void generateInitalGrid(const wchar_t *path,
	imageType*& imgF, boolMat*& constant)
{
	imgF = reinterpret_cast<imageType*>(new pixelType[dim * dim * dim]);
	::memset(imgF, *reinterpret_cast<const int*>(&intialColor), sizeof(imageType));

	constant = reinterpret_cast<boolMat*>(new boolType[dim * dim * dim]);
	::memset(constant, 0, sizeof(boolMat)); 
	
	FILE *file;
	_wfopen_s(&file, path, L"r");
	if (file == NULL){
		printf("Unable to open %ls", path);
		getchar();
		throw;
	}

	struct coord
	{
		int x;
		int y;
		int z;
	};

	struct coordf
	{
		float x;
		float y;
		float z;
	};

	struct line
	{
		coord start;
		coord end;
	};

	std::vector<coord> vertices;
	std::vector<line> lines;
	std::vector<coord> points;

	char lineHeader[128];

	while (fscanf_s(file, "%s", lineHeader, sizeof(lineHeader)) != EOF)
	{
		if (strcmp(lineHeader, "v") == 0)
		{
			coordf vertexf;
			fscanf_s(file, "%f %f %f\r\n", &vertexf.x, &vertexf.y, &vertexf.z);
			vertexf.x = (vertexf.x + 1.0f) * ((dim - 1) / 2.0f);
			vertexf.y = (vertexf.y + 1.0f) * ((dim - 1) / 2.0f);
			vertexf.z = (vertexf.z + 1.0f) * ((dim - 1) / 2.0f);
			coord vertex = { (int)vertexf.x, (int)vertexf.y, (int)vertexf.z };
			vertices.push_back(vertex);
		}
		else if (strcmp(lineHeader, "l") == 0)
		{
			int start, end;
			fscanf_s(file, "%d %d\r\n", &start, &end);
			line seg;
			seg.start = vertices[start - 1];
			seg.end = vertices[end - 1];
			lines.push_back(seg);
		}
		else if (strcmp(lineHeader, "p") == 0)
		{
			int index;
			fscanf_s(file, "%d\r\n", &index);
			coord point = vertices[index - 1];
			points.push_back(point);
		}
		else
		{
			// Probably a comment, eat up the rest of the line
			char stupidBuffer[1000];
			fgets(stupidBuffer, 1000, file);
		}
	}

	for (const line& seg : lines)
	{
		DrawLine3D(*imgF, seg.start.x, seg.start.y, seg.start.z, seg.end.x, seg.end.y, seg.end.z, surfaceColor);
		DrawLine3D(*constant, seg.start.x, seg.start.y, seg.start.z, seg.end.x, seg.end.y, seg.end.z, 1U);
	}

	for (const coord& point : points)
	{
		(*imgF)[point.x][point.y][point.z] = interiorColor;
		(*constant)[point.x][point.y][point.z] = 1U;
	}

	//DrawLine3D(*imgF, 117, 117, 127, 117, 137, 147, surfaceColor);
}

extern "C" {
	_declspec(dllexport) unsigned long NvOptimusEnablement = 0x00000001;
}


int wmain(int argc, wchar_t *argv[])<commit_msg>Fixed problem with rasterizing cross-sections by drawing each line both ways.<commit_after>// 3DDiffusion.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "operations.h"
#include "binvox.h"

const pixelType borderColor = -1.0f;
const pixelType intialColor = -0.1f;
const pixelType surfaceColor = 0.0f;
const pixelType interiorColor = 1.0f;

void generateInitalGrid(const wchar_t *path,
	imageType*& imgF, boolMat*& constant)
{
	imgF = reinterpret_cast<imageType*>(new pixelType[dim * dim * dim]);
	::memset(imgF, *reinterpret_cast<const int*>(&intialColor), sizeof(imageType));

	constant = reinterpret_cast<boolMat*>(new boolType[dim * dim * dim]);
	::memset(constant, 0, sizeof(boolMat)); 
	
	FILE *file;
	_wfopen_s(&file, path, L"r");
	if (file == NULL){
		printf("Unable to open %ls", path);
		getchar();
		throw;
	}

	struct coord
	{
		int x;
		int y;
		int z;
	};

	struct coordf
	{
		float x;
		float y;
		float z;
	};

	struct line
	{
		coord start;
		coord end;
	};

	std::vector<coord> vertices;
	std::vector<line> lines;
	std::vector<coord> points;

	char lineHeader[128];

	while (fscanf_s(file, "%s", lineHeader, sizeof(lineHeader)) != EOF)
	{
		if (strcmp(lineHeader, "v") == 0)
		{
			coordf vertexf;
			fscanf_s(file, "%f %f %f\r\n", &vertexf.x, &vertexf.y, &vertexf.z);
			vertexf.x = (vertexf.x + 1.0f) * ((dim - 1) / 2.0f);
			vertexf.y = (vertexf.y + 1.0f) * ((dim - 1) / 2.0f);
			vertexf.z = (vertexf.z + 1.0f) * ((dim - 1) / 2.0f);
			coord vertex = { (int)vertexf.x, (int)vertexf.y, (int)vertexf.z };
			vertices.push_back(vertex);
		}
		else if (strcmp(lineHeader, "l") == 0)
		{
			int start, end;
			fscanf_s(file, "%d %d\r\n", &start, &end);
			line seg;
			seg.start = vertices[start - 1];
			seg.end = vertices[end - 1];
			lines.push_back(seg);
		}
		else if (strcmp(lineHeader, "p") == 0)
		{
			int index;
			fscanf_s(file, "%d\r\n", &index);
			coord point = vertices[index - 1];
			points.push_back(point);
		}
		else
		{
			// Probably a comment, eat up the rest of the line
			char stupidBuffer[1000];
			fgets(stupidBuffer, 1000, file);
		}
	}

	for (const line& seg : lines)
	{
		if (seg.start.x == seg.end.x &&
			seg.start.y == seg.end.y &&
			seg.start.z == seg.end.z)
		{
			(*imgF)[seg.start.x][seg.start.y][seg.start.z] = interiorColor;
			(*constant)[seg.start.x][seg.start.y][seg.start.z] = 1U;
		}
		else
		{
			DrawLine3D(*imgF, seg.start.x, seg.start.y, seg.start.z, seg.end.x, seg.end.y, seg.end.z, surfaceColor);
			DrawLine3D(*constant, seg.start.x, seg.start.y, seg.start.z, seg.end.x, seg.end.y, seg.end.z, 1U);
			DrawLine3D(*imgF, seg.end.x, seg.end.y, seg.end.z, seg.start.x, seg.start.y, seg.start.z, surfaceColor);
			DrawLine3D(*constant, seg.end.x, seg.end.y, seg.end.z, seg.start.x, seg.start.y, seg.start.z, 1U);
			(*imgF)[seg.start.x][seg.start.y][seg.start.z] = surfaceColor;
			(*constant)[seg.start.x][seg.start.y][seg.start.z] = 1U;
			(*imgF)[seg.end.x][seg.end.y][seg.end.z] = surfaceColor;
			(*constant)[seg.end.x][seg.end.y][seg.end.z] = 1U;
		}
	}

	for (const coord& point : points)
	{
		(*imgF)[point.x][point.y][point.z] = interiorColor;
		(*constant)[point.x][point.y][point.z] = 1U;
	}

	//DrawLine3D(*imgF, 117, 117, 127, 117, 137, 147, surfaceColor);
}

extern "C" {
	_declspec(dllexport) unsigned long NvOptimusEnablement = 0x00000001;
}


int wmain(int argc, wchar_t *argv[])
{'fraction_non_alphanumeric': 0.18590803837247766, 'fraction_numerical': 0.02547138604035726, 'mean_word_length': 3.5672205438066467, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '2198622', 'n_tokens_mistral': 2802, 'n_tokens_neox': 2501, 'n_words': 541}