rtsFilamentNetwork.cpp 2.2 KB
#include "rtsFilamentNetwork.h"

int rtsFilamentNetwork::LoadFIB(const char* filename)
{
	 return fib_load(filename);
}

int rtsFilamentNetwork::fib_load(const char* filename)
{
	//open the input file
	ifstream infile;
	infile.open(filename);
	if(!infile) return 0;

	//temporary vector storing points
	vector<point3D<float>> vertices;
	vector<float> radii;
	point3D<float> input;
	point3D<float> max(0.0, 0.0, 0.0);	//maximum extents of the points in the file

	float r;

	int i,j;
	//get all of the nodes from the file
	int num_nodes;
	infile>>num_nodes;	
	int id;
	for(i=0; i<num_nodes; i++)
	{
		infile>>id;
		infile>>input.x;  infile>>input.y;  infile>>input.z;  infile>>r;

		//update the maximum
		if(input.x > max.x) max.x = input.x;
		if(input.y > max.y) max.y = input.y;
		if(input.z > max.z) max.z = input.z;

		vertices.push_back(input);
		radii.push_back(r);
	}

	/*Scale the node values based on the maximum value.  I do this so that
	every node is between 0 - 1 rather than the original scale.  In the long run,
	it should make rendering easier.
	*/
	for(i=0; i<num_nodes; i++)
	{
		vertices[i].x = vertices[i].x/max.x;
		vertices[i].y = vertices[i].y/max.y;
		vertices[i].z = vertices[i].z/max.z;

		vertices.push_back(input);
		radii.push_back(r);
	}

	//get each fiber
	int num_filaments;
	int num_edges;
	infile>>num_filaments;

	for(i=0; i<num_filaments; i++)
	{
		network->objBegin(OBJ_LINE_STRIP);	//begin the filament
		infile>>num_edges;
		for(j = 1; j<num_edges; j++)	//get the index of each edge
		{
			infile>>id; id--;
			network->objVertex3f(vertices[id].x, vertices[id].y, vertices[id].z);
			//this final read is required because of redundancy in the input file
			infile>>id;
		}
		infile>>id;		//this final read is also required due to redundancy in the input file
		id--;
		network->objVertex3f(vertices[id].x, vertices[id].y, vertices[id].z);
		infile>>id;
		id--;
		network->objVertex3f(vertices[id].x, vertices[id].y, vertices[id].z);
		network->objEnd();
	}
	return 1;
}

void rtsFilamentNetwork::PrintProperties()
{

	cout<<"Number of Filaments: "<<network->getNumLines();
}

void rtsFilamentNetwork::PrintNetwork()
{

}