<commit_before>

#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <cassert>

#include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <glm/gtx/io.hpp>

#include "AABB.h"
#include "SpimStack.h"
#include "TinyStats.h"

// goddamnit windows! :(
#undef near
#undef far


using namespace std;
using namespace glm;

static mat4 loadRegistration(const string& filename)
{

	ifstream file(filename);

	if (!file.is_open())
		throw runtime_error("Unable to open file \"" + filename + "\"");

	mat4 T(1.f);


	for (int i = 0; i < 16; ++i)
	{
		string buffer;
		getline(file, buffer);
				
#ifdef _WIN32
		int result = sscanf_s(buffer.c_str(), "m%*2s: %f", &glm::value_ptr(T)[i]);
#else
		int result = sscanf(buffer.c_str(), "m%*2s: %f", &glm::value_ptr(T)[i]);
#endif
		
	}

	return T;
}

int main(int argc, const char** argv)
{
	
	// records the individual and aggregate error
	TinyHistory<double> error;


	ofstream output("e:/temp/comparison.csv");
	output << "# stack, transform, solution, distance\n";

	if (argc < 3)
	{
		cout << "Usage: " << argv[0] << " <inputStack> <solutionTransform> [<inputStack> <solutionTransform>] [...]\n";

#ifdef _WIN32
		system("pause");
#endif
		return 1;
	}

	for (int i = 1; i < argc; i += 2)
	{	
		SpimStack* ref = nullptr;

		try
		{
			string stackFile(argv[i+0]);


			// load references (phantoms)
			ref = new SpimStackU16;
			ref->load(stackFile);

			// load their transforms
			string transformFile = stackFile + ".registration.txt";
			ref->loadRegistration(transformFile);


			cout << "Reference:  " << transformFile << endl;
			cout << "Dimensions: " << ref->getVoxelDimensions() * vec3(ref->getResolution()) << endl;

			// load solutions
			string solutionFile(argv[i + 1]);
			mat4 solutionTransform = loadRegistration(solutionFile);
			
			cout << "Solution: " << solutionFile << endl;

			// compare 
			vector<vec3> bboxVertices = ref->getBBox().getVertices();



			// transform
			double aggregatedDistance = 0;
			for (int i = 0; i < 8; ++i)
			{
				vec4 reference = ref->getTransform() * vec4(bboxVertices[i], 1.f);
				vec4 solution = solutionTransform * vec4(bboxVertices[i], 1.f);

				double d = length(reference - solution);

				cout << "Vertex[" << i << "] distance: " << d << endl;
				aggregatedDistance += d;
			}

			aggregatedDistance /= 8;

			error.add(aggregatedDistance);

			cout << "Mean distance: " << aggregatedDistance << endl;
			
			output << stackFile << ", " << transformFile << ", " << solutionFile << ", " << aggregatedDistance << endl;


		}
		catch (const runtime_error& e)
		{
			cerr << e.what() << endl;
		}


		delete ref;
	}


	// calculate difference based on bounding boxes here ...

	



#ifdef _WIN32
	system("pause");
#endif


	return 0;
}

<commit_msg>Fixed some smaller bugs<commit_after>

#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <cassert>

#include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <glm/gtx/io.hpp>

#include "AABB.h"
#include "SpimStack.h"
#include "TinyStats.h"

// goddamnit windows! :(
#undef near
#undef far


using namespace std;
using namespace glm;

static mat4 loadRegistration(const string& filename)
{

	ifstream file(filename);

	if (!file.is_open())
		throw runtime_error("Unable to open file \"" + filename + "\"");

	mat4 T(1.f);


	float* m = value_ptr(T);

	for (int i = 0; i < 16; ++i)
		file >> m[i];


	/*
	cout << "Read matrix: \"" << filename << "\"\n";
	cout << T << endl;
	*/
	return T;
}

int main(int argc, const char** argv)
{
	
	// records the individual and aggregate error
	TinyHistory<double> error;


	ofstream output("e:/temp/comparison.csv");
	output << "# stack, transform, solution, distance\n";

	if (argc < 3)
	{
		cout << "Usage: " << argv[0] << " <inputStack> <solutionTransform> [<inputStack> <solutionTransform>] [...]\n";

#ifdef _WIN32
		system("pause");
#endif
		return 1;
	}


	// parse command line here
	vector<pair<string, string>> filepairs;
	for (int i = 1; i < argc; i += 2)
	{
		filepairs.push_back(make_pair(argv[i], argv[i + 1]));
	}





	for (auto it = filepairs.begin(); it != filepairs.end(); ++it)
	{	
		SpimStack* ref = nullptr;

		try
		{
			const string stackFile(it->first);
			const string solutionFile(it->second);

			// load references (phantoms)
			ref = new SpimStackU16;
			ref->load(stackFile);

			// load their transforms
			const string transformFile = stackFile + ".registration.txt";
			ref->setTransform(loadRegistration(transformFile));


			cout << "Reference:  " << transformFile << endl;
			cout << "Dimensions: " << ref->getVoxelDimensions() * vec3(ref->getResolution()) << endl;

			// load solutions
			const mat4 solutionTransform = loadRegistration(solutionFile);
		
			// compare 
			const vector<vec3> bboxVertices = ref->getBBox().getVertices();
			

			// transform
			double aggregatedDistance = 0;
			for (int i = 0; i < 8; ++i)
			{

				vec4 reference = ref->getTransform() * vec4(bboxVertices[i], 1.f);
				vec4 solution = solutionTransform * vec4(bboxVertices[i], 1.f);
				
				double d = length(reference - solution);

				//cout << bboxVertices[i] << " -> " << reference << " - " << solution << " = " << d << endl;

				cout << "Vertex[" << i << "] distance: " << d << endl;
				aggregatedDistance += d;
			}

			aggregatedDistance /= 8;

			error.add(aggregatedDistance);

			cout << "Mean distance: " << aggregatedDistance << endl;
			
			output << stackFile << ", " << transformFile << ", " << solutionFile << ", " << aggregatedDistance << endl;


		}
		catch (const runtime_error& e)
		{
			cerr << e.what() << endl;
		}


		delete ref;
	}

	
#ifdef _WIN32
	system("pause");
#endif


	return 0;
}


{'fraction_non_alphanumeric': 0.17020157756354076, 'fraction_numerical': 0.012094653812445224, 'mean_word_length': 3.41640866873065, 'pattern_counts': {'":': 0, '<': 185, '<?xml version=': 0, '>': 50, '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': '2460628', 'n_tokens_mistral': 2297, 'n_tokens_neox': 1964, 'n_words': 496}