Blame view

legacy/rtsFilamentNetwork.cpp 2.2 KB
f1402849   dmayerich   renewed commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
  #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()

  {

  

  }