#include "DataContainer_IO.h"

void	DataContainer_IO::LoadModel(Model &model, char *filename)
{
	FILE *file_ptr = fopen(filename, "r");
	int	nSurfels;
	fscanf(file_ptr, "%ld\n", &nSurfels);
	model.m_geometry.resize(nSurfels);
	for (int sId = 0; sId < nSurfels; sId++){
		Surfel	&s = model.m_geometry[sId];
		fscanf(file_ptr, "%f %f %f %f %f %f\n",
			&s.pos[0], &s.pos[1], &s.pos[2],
			&s.nor[0], &s.nor[1], &s.nor[2]);
	}
	fclose(file_ptr);
}

void	DataContainer_IO::LoadScan(Scan &scan, char *filename)
{
	FILE *file_ptr = fopen(filename, "r");
	
	/// Load the transformation
	for (int i = 0; i < 3; i++){
		fscanf(file_ptr, "%lf %lf %lf %lf\n",
			&scan.m_rigid[0][i],
			&scan.m_rigid[1][i],
			&scan.m_rigid[2][i],
			&scan.m_rigid[3][i]);
	}

	/// Load the geometry
	int	nSurfels;
	fscanf(file_ptr, "%ld\n", &nSurfels);
	scan.m_originalPose.resize(nSurfels);
	for (int sId = 0; sId < nSurfels; sId++){
		Surfel	&s = scan.m_originalPose[sId];
		fscanf(file_ptr, "%f %f %f %f %f %f\n",
			&s.pos[0], &s.pos[1], &s.pos[2],
			&s.nor[0], &s.nor[1], &s.nor[2]);
	}
	fclose(file_ptr);
}