1 | #ifndef _Polygon3_h__ |
---|
2 | #define _Polygon3_h__ |
---|
3 | |
---|
4 | |
---|
5 | //#include <iostream> |
---|
6 | //#include <math.h> |
---|
7 | //#include "common.h" |
---|
8 | #include "Containers.h" |
---|
9 | #include "Mesh.h" |
---|
10 | |
---|
11 | class Polygon3; |
---|
12 | class Plane3; |
---|
13 | class Face; |
---|
14 | |
---|
15 | /** Container storing polygons used during BSP tree construction |
---|
16 | */ |
---|
17 | typedef vector<Polygon3 *> PolygonContainer; |
---|
18 | |
---|
19 | /** Class representing a general planar polygon in 3d. |
---|
20 | */ |
---|
21 | class Polygon3 |
---|
22 | { |
---|
23 | public: |
---|
24 | Polygon3(); |
---|
25 | Polygon3(const VertexContainer &vertices); |
---|
26 | |
---|
27 | /** Copies all the vertices of the face. |
---|
28 | */ |
---|
29 | Polygon3(Face *face, Mesh *parent); |
---|
30 | |
---|
31 | /** Returns supporting plane of this polygon. |
---|
32 | */ |
---|
33 | Plane3 GetSupportingPlane() const; |
---|
34 | |
---|
35 | /** Splits polygon. |
---|
36 | @param partition the split plane |
---|
37 | @param front the front polygon |
---|
38 | @param back the back polygon |
---|
39 | @param splits number of splits |
---|
40 | */ |
---|
41 | void Split(Plane3 *partition, Polygon3 *front, Polygon3 *back, int &splits); |
---|
42 | |
---|
43 | enum {BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT}; |
---|
44 | |
---|
45 | /** Classify polygon with respect to the plane. |
---|
46 | @returns one of BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT |
---|
47 | */ |
---|
48 | int ClassifyPlane(const Plane3 &plane) const; |
---|
49 | |
---|
50 | /** Side of the polygon with respect to the plane. |
---|
51 | @returns 1 if on front side, -1 if on back side, 0 else. |
---|
52 | */ |
---|
53 | int Side(const Plane3 &plane) const; |
---|
54 | |
---|
55 | /** Deletes all polygons om the queue. |
---|
56 | */ |
---|
57 | static void DeletePolygons(PolygonContainer *polys); |
---|
58 | |
---|
59 | /// vertices are connected in counterclockwise order. |
---|
60 | VertexContainer mVertices; |
---|
61 | }; |
---|
62 | |
---|
63 | // Overload << operator for C++-style output |
---|
64 | inline ostream& |
---|
65 | operator<< (ostream &s, const Polygon3 &A) |
---|
66 | { |
---|
67 | VertexContainer::const_iterator it; |
---|
68 | |
---|
69 | s << "Polygon:\n"; |
---|
70 | |
---|
71 | for (it = A.mVertices.begin(); it != A.mVertices.end(); ++it) |
---|
72 | s << *it << endl; |
---|
73 | |
---|
74 | return s; |
---|
75 | } |
---|
76 | |
---|
77 | |
---|
78 | #endif |
---|