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

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