source: trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.h @ 286

Revision 286, 1.8 KB checked in by mattausch, 19 years ago (diff)
Line 
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#include <iomanip>
11
12class Polygon3;
13class Plane3;
14class Face;
15class Intersectable;
16
17/** Class representing a general planar polygon in 3d.
18*/
19class Polygon3
20{
21public:
22        Polygon3();
23        Polygon3(const VertexContainer &vertices);
24        Polygon3(Intersectable *parent);
25
26        /** Copies all the vertices of the face.
27        */
28        Polygon3(Face *face, Mesh *parentMesh);
29       
30        /** Returns supporting plane of this polygon.
31        */
32        Plane3 GetSupportingPlane() const;
33
34        /** Splits polygon.
35                @param partition the split plane
36                @param front the front polygon
37                @param back the back polygon
38                @param splits number of splits
39        */
40        void Split(Plane3 *partition, Polygon3 *front, Polygon3 *back, int &splits);
41
42        enum {BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT};
43
44        /** Classify polygon with respect to the plane.
45            @returns one of BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT
46        */
47        int ClassifyPlane(const Plane3 &plane) const;
48
49        /** Side of the polygon with respect to the plane.
50                @returns 1 if on front side, -1 if on back side, 0 else.
51        */
52        int Side(const Plane3 &plane) const;
53
54        /** Scales the polygon about its center
55        */
56        void Scale(const float scale);
57       
58        /** Computes the center of mass of the polygon
59         */
60        Vector3 Center() const;
61
62               
63        /// vertices are connected in counterclockwise order.
64        VertexContainer mVertices;
65
66        /// we can also store materials with polygons
67        Material *mMaterial;
68       
69        /// pointer to the intersectable this polygon is derived from
70        Intersectable *mParent;
71};
72
73// Overload << operator for C++-style output
74inline ostream&
75operator<< (ostream &s, const Polygon3 &A)
76{
77        VertexContainer::const_iterator it;
78
79        s << setprecision(6) << "Polygon:\n";
80       
81        for (it = A.mVertices.begin(); it != A.mVertices.end(); ++it)
82                s << *it << endl;
83       
84        return s;
85}
86
87
88#endif
Note: See TracBrowser for help on using the repository browser.