filemanager.h

来自「RBF平台」· C头文件 代码 · 共 84 行

H
84
字号
#include "stdafx.h"
#include <stdio.h>
#include "RBFcore\PointSet.h"

class FileManager{

public:
	FileManager() {}
	~FileManager() {}

	bool ReadPointFile(PointSet  * ps, CString file_name)
	{
		FILE* in = fopen(file_name, "r");
		if(in == NULL)
			return false;

		//read #points
		int N;
		fscanf(in, "%d", &N);

		ps->setPointSize(N);

		//read points
		for(int i=0; i<N; i++)
		{
			float x,y,z;
			fscanf(in, "%f %f %f", &x, &y, &z);
			ps->setPoint(i, x, y, z);
		}

		//read normals
		int count = 0;
		float (*point)[3] = ps->_point;
		for(i=0; i<N; i++){
		float x,y,z;
		fscanf(in, "%f %f %f", &x, &y, &z);

		if(x == 0 && y == 0 && z == 0)
			continue;
		float len = (float)sqrt(x*x + y*y + z*z);
		x /= len;
		y /= len;
		z /= len;

		//ps->setPoint(count, point[i][0], point[i][1], point[i][2]);
		ps->setNormal(count, -x, -y, -z);
		count++;
		}

		ps->_pointN = count;

		fclose(in);
		return true;
	}


	bool WritePointFile(PointSet * ps, CString file_name)
	{
		FILE* out = fopen(file_name, "w");
		if(out == NULL)
			return false;

		int N = ps->_pointN;
		fprintf(out, "%d\n", N);

		for(int i=0; i<N; i++)
		{
			float *p = ps->_point[i];
			fprintf(out, "%f %f %f \n", p[0], p[1], p[2]);
		}

		for(i=0; i<N; i++)
		{
			float *p = ps->_normal[i];
			fprintf(out, "%f %f %f \n", -p[0], -p[1], -p[2]);
		}

		fclose(out);

		return true;
	}

};

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?