-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathread.cpp
213 lines (178 loc) · 4.16 KB
/
read.cpp
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#include "group.h"
#include <fstream>
#include <iostream>
#include <string>
#include <list>
using namespace std;
const int SIZE = 255;
extern EdgeList edgelist;
extern TriList trianglelist;
genList<Object> objectlist;
int triflag;
int objnum = 0;
Vector norm;
VertTree tree;
Triangle* tri;
Object* obj;
Vector vmin(HUGEREAL, HUGEREAL, HUGEREAL), vmax(-HUGEREAL, -HUGEREAL, -HUGEREAL);
void Readprop(const char*);
void readfile(const char*);
void Ray_trace();
void main()
{
char* filename;
//filename = "tetrahedron.stl";
filename = "t1.stl";
//filename = "view2.txt";
//filename = "sphere3.txt";
//filename = "knob.txt";
readfile(filename);
//trianglelist.print();
//cout<<endl;
//edgelist.print();
edgelist.findPair();
//char* fileprop = "viewprop2.txt";
//char* fileprop = "properties.txt";
char* fileprop = "teaprop.txt";
Readprop(fileprop);
int count=0;
trianglelist.AvgNorm();
Object* objcount;
objcount = objectlist.firstptr;
while(objcount != 0)
{
cout<<objcount<<endl;
Triangle* tri = objcount->getFirstTri();
int num = objcount->getObjNum();
//cout<<num<<endl;
//trianglelist.computeGroup(tri); // Group# method
cout<<objcount->getMinVert()<<" "<<objcount->getMaxVert()<<endl;
objcount = objcount->nextptr;
}
/*Triangle* t1;
t1 = trianglelist.firstptr;
cout<<endl;
int tricount = 0;
while(t1 != 0)
{
tricount++;
int num = t1->getGroupNum();
//cout<<tricount<<" "<<num<<" "<<t1->getObjNum()<<endl;
t1 = t1->nextptr;
}*/
//tree.inOrderTraversal(); // called for averaging normals using group #s
Ray_trace(); // This one call does everything
}
void readfile(const char* filename)
{
//Vertex* vert[3];
Triangle *first, *last;
Vector vect, newvect;
string keyword;
string objname;
float nx, ny, nz;
float vx, vy, vz;
int i;
char line[SIZE];
ifstream input_file(filename, ios::in);
if(!input_file.is_open())
{
cout <<"Error: Cannot input filename: "<< filename << endl;
exit(0);
}
while(input_file.peek() != EOF)
{
int j = 0;
char c;
keyword = "";
while(isalnum(c = input_file.get()))
{
line[j] = c;
j++;
}
line[j] = NULL;
keyword = line;
//cout<<keyword<<endl;
if((keyword == "SOLID") || (keyword == "solid"))
{
input_file.getline(line, SIZE, '\n');
objname = line;
obj = new Object;
obj->setname(objname);
objnum++;
obj->setObjNum(objnum);
triflag = 1;
cout<<objname<<endl;
}
if((keyword == "FACET") || (keyword == "facet"))
{
tri = new Triangle;
tri->setObjNum(objnum);
input_file.getline(line, SIZE, ' ');
input_file >> nx >> ny >> nz;
vect.x = nx;
vect.y = ny;
vect.z = nz;
//tri->setnormal(vect); // Assigning facet normals to triangles from STL file
//cout<<tri<<" "<<tri->getObjNum()<<endl;
input_file.getline(line, SIZE, '\n');
}
if((keyword == "OUTER") || (keyword == "outer"))
{
input_file.getline(line, SIZE, '\n');
i = 0;
}
if((keyword == "VERTEX") || (keyword == "vertex"))
{
Vector vtol(TOL, TOL, TOL);
input_file >> vx >> vy >> vz;
if(vx < vmin.x)
vmin.x = vx;
if(vy < vmin.y)
vmin.y = vy;
if(vz < vmin.z)
vmin.z = vz;
if(vx > vmax.x)
vmax.x = vx;
if(vy > vmax.y)
vmax.y = vy;
if(vz > vmax.z)
vmax.z = vz;
vect.x = vx;
vect.y = vy;
vect.z = vz;
tree.insertNode(vect, i, triflag);
i++;
input_file.getline(line, SIZE, '\n');
}
if((keyword == "ENDLOOP") || (keyword == "endloop"))
{
//cout<<keyword<<" reached"<<endl;
//input_file.getline(line, SIZE, '\n');
}
if((keyword == "ENDFACET") || (keyword == "endfacet"))
{
trianglelist.insertnode(tri);
//cout<<keyword<<" reached"<<endl;
//input_file.getline(line, SIZE, '\n');
}
if((keyword == "ENDSOLID") || (keyword == "endsolid"))
{
input_file.getline(line, SIZE, '\n');
objname = line;
obj->setLastTri(tri);
obj->setbound(vmax, vmin);
objectlist.insertnode(obj);
vmax.x = -HUGEREAL;
vmax.y = -HUGEREAL;
vmax.z = -HUGEREAL;
vmin.x = HUGEREAL;
vmin.y = HUGEREAL;
vmin.z = HUGEREAL;
first = obj->getFirstTri();
last = obj->getLastTri();
cout<<first<<" "<<last<<" here"<<endl;
cout<<objname<<" "<<obj<<endl;
}
}
}