-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgroup.h
333 lines (301 loc) · 7.61 KB
/
group.h
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
#include <assert.h>
#include <fstream>
#include <iostream>
#include <string>
#include <list>
using namespace std;
const float HUGEREAL = 100000;
const double TOL = 0.00001;
class Edge;
class Triangle;
class EdgeList;
class TriList;
class Ray;
class Color;
template< class NodeClass > class genList;
inline float myabs(float a)
{
if(a < 0)
return -a;
else return a;
}
class Vector
{
friend ostream& operator<<(ostream&, const Vector&); // printing in Vector form
public:
Vector(){x=0;y=0;z=0;}
Vector(float a, float b, float c)
{
x = a;
y = b;
z = c;
}
float x, y, z;
/* operator overloading functions */
Vector operator*(const Vector&); // Vector cross product
Vector operator+(const Vector&); // Vector addition
Vector operator-(const Vector&); // Vector subtraction
Vector operator~(); // unit Vector
Vector scale(float t); // scalar product
float operator&(const Vector&); // Vector dot product
float mod(); // magnitude of Vector0
};
class Color
{
public:
Color(): red(0.0), green(0.0), blue(0.0) {}
float red;
float green;
float blue;
};
class Vertex
{
friend class VertTree;
public:
Vertex(const Vector& vect):leftptr(0), rightptr(0), next(0), v(vect), trinum(1), edgeptr(0) {}
Vector getVector() const { return v;}
void setVector( const Vector& setv) { v = setv; }
void setEdge(Edge* newptr) {this->edgeptr = newptr;}
Edge* getEdge() { return edgeptr; };
void setAvgNorm( Vector norm) { avg_norm = norm; }
Vector getAvgNorm() const { return avg_norm; }
private:
Vertex* leftptr; // pointer to left subtree
Vertex* rightptr; // pointer to right subtree
Vertex* next; // forward pointer to copy
Vector v; // vertex coordinates
int trinum; // # of incident triangles or # of copies
Edge* edgeptr; // pointer to half-edge emanating from the vertex
Vector avg_norm; // average normal (computed at run-time before firing rays)
};
class VertTree
{
public:
VertTree() {rootptr = 0;};
void insertNode(const Vector&, const int i, int&);
void inOrderTraversal() const;
private:
Vertex* rootptr;
void insertNodeHelper(Vertex**, const Vector&, const int i, int&);
void inOrderHelper(Vertex*) const;
};
class Edge
{
friend class EdgeList;
public:
Edge():nextptr(0),verta(0), vertb(0), next(0), pair(0), face(0) {}
void insertEdge(Vertex*, const int, int&);
Vertex* getVerta() const { return verta; }
Vertex* getVertb() const { return vertb; }
Edge* getNext() const { return next; }
Edge* getPair() const { return pair; }
void setFace(Triangle* facet) {face = facet;}
Triangle* getFace() const { return face; }
void setPair(Edge* edge) { pair = edge; }
Edge* nextptr;
private:
Vertex* verta;
Vertex* vertb;
Edge* next;
Edge* pair;
Triangle* face;
};
class Triangle
{
friend class TriList;
public:
Triangle(): bits(0), nextptr(0), group_num(0) {}
Vector Blend_norm(Vector);
void setnormal(const Vector vect) { facet_norm = vect; }
Vector getnormal() { return facet_norm; }
void setVerts(Vertex** vert);
Vertex** getVerts() { return vert; }
//Vertex* getVert() const { return vert[0]; }
void setEdges(Edge*, Edge*, Edge*);
void setOneEdge(Edge* edge1) { edge = edge1; }
Edge** getEdges() { return edges; }
int getGroupNum() const { return group_num; }
Triangle* nextptr;
void setObjNum(const int num) { objnum = num; }
const int getObjNum() const { return objnum; }
private:
int bits; // # of times each triangle is visited in group# traversal
int group_num; // triangle group number
int objnum;
Vector facet_norm; // facet normal
Vertex* vert[3]; // vertices
Edge* edges[3]; // 3 pointers to all edges
Edge* edge; // pointer to first edge
};
class Object // object description
{
public:
Object(): nextptr(0),objname(""), firstTri(0), lastTri(0) {}
void setbound(Vector max, Vector min)
{
vmax = max;
vmin = min;
}
float bound_box(Ray) const;
float Shadow_box(Ray ray) const;
Vector getMinVert() { return vmin; }
Vector getMaxVert() { return vmax; }
Object* nextptr;
void setFirstTri(Triangle* firstptr) { firstTri = firstptr; }
void setLastTri(Triangle* lastptr) { lastTri = lastptr; }
Triangle* getFirstTri() { return firstTri; }
Triangle* getLastTri() { return lastTri; }
void setname(string name) { objname = name; }
string getname() { return objname; }
void setObjNum(const int num) { objnum = num; }
const int getObjNum() { return objnum; }
void setIamb(Color Iamb) { iamb = Iamb; }
Color getIamb() { return iamb; }
void setKdiff(Color Kdiff) { Kd = Kdiff; }
Color getKdiff() { return Kd; }
void setKspec(float Kspec) { Ks = Kspec; }
float getKspec() { return Ks; }
void setKref(Color Kref) { Kr = Kref; }
Color getKref() { return Kr; }
void setKtrans(Color Ktrans) { Kt = Ktrans; }
Color getKtrans() { return Kt; }
void setIndex(float N) { index = N; }
float getIndex() { return index; }
void setN(float N) { n = N; }
float getN() { return n; }
Vector vmin, vmax; // for bounding box
private:
string objname; // object name
Triangle* firstTri; // pointer to first triangle
Triangle* lastTri; // pointer to llast triangle
//Vector vmin, vmax; // for bounding box
int objnum;
Color iamb, Kd, Kr, Kt;
float n;
float Ks;
float index;
};
template< class NodeClass >
class genList
{
public:
genList();
//~genList() {}; // Destructor
~genList();
void insertnode(NodeClass* newptr);
bool isEmpty() const;
void print() const;
//private:
NodeClass* firstptr;
NodeClass* lastptr;
};
template< class NodeClass > // default constructor
genList< NodeClass >::genList():firstptr(0), lastptr(0) {}
template< class NodeClass >
genList<NodeClass>::~genList()
{
if(!isEmpty())
{
NodeClass* currentptr = firstptr;
NodeClass* tempptr;
while(currentptr != 0)
{
tempptr = currentptr;
currentptr = currentptr->nextptr;
delete tempptr;
}
}
}
template< class NodeClass >
bool genList<NodeClass>::isEmpty() const
{ return firstptr == 0; }
template< class NodeClass >
void genList<NodeClass>::insertnode(NodeClass* newptr)
{
if(isEmpty())
firstptr = lastptr = newptr;
else
{
lastptr->nextptr = newptr;
lastptr = newptr;
}
}
template<class NodeClass>
void genList<NodeClass>::print() const
{
if(isEmpty())
{
cout<<"The list is empty.\n";
return;
}
NodeClass* currentptr = firstptr;
while(currentptr != 0)
{
cout<<currentptr<<endl;
currentptr = currentptr->nextptr;
}
}
class EdgeList
{
public:
EdgeList();
~EdgeList() {}; // Destructor
void insertnode(Edge* newptr);
bool isEmpty() const;
void print() const;
void findPair();
//private:
Edge* firstptr;
Edge* lastptr;
};
class TriList
{
public:
TriList();
//~TriList() {}; // Destructor
~TriList();
void insertnode(Triangle* newptr);
void AvgNorm() const;
void computeGroup(Triangle* );
bool isEmpty() const;
void print() const;
//private:
Triangle* firstptr;
Triangle* lastptr;
};
class Ray
{
public:
Ray(): depth(0), object(0) {}
float intersect_plane(Vector, Vector);
int Compute_intersect();
Ray Reflect_ray();
Ray Transmit_ray();
Color Shadow_ray();
void setBase(const Vector eye) { base = eye; }
void setDir(const Vector aim) { dir = aim; }
void setObject(Object* obj) { object = obj; }
int getDepth() { return depth; }
void setDepth(int d) { depth = d; }
Vector getBase() const { return base; }
Vector getDir() const { return dir; }
Object* getObject() const { return object; }
private:
Vector base; // Origin of ray
Vector dir; // Ray direction
int depth; // Level of recursion or depth of tree
Vector hitpoint;
Triangle* triangle;// Point of intersection
Object* object; // Object hit by ray
Vector blend_norm; // Blended normal of triangle hit by ray
};
struct ObjCopy
{
float tvalue;
Object* obj;
};
struct Light
{
Vector v;
Color col;
};