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

Revision 289, 2.0 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//typedef Vertex3 Vector3;
18
19/** Class representing a planar convex polygon in 3d.
20*/
21class Polygon3
22{
23public:
24        Polygon3();
25        Polygon3(const VertexContainer &vertices);
26        Polygon3(Intersectable *parent);
27
28        /** Copies all the vertices of the face.
29        */
30        Polygon3(Face *face, Mesh *parentMesh);
31       
32        /** Returns supporting plane of this polygon.
33        */
34        Plane3 GetSupportingPlane() const;
35
36        /** Splits polygon.
37                @param partition the split plane
38                @param front the front polygon
39                @param back the back polygon
40        */
41        void Split(Plane3 *partition, Polygon3 *front, Polygon3 *back);
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        /** Scales the polygon about its center
56        */
57        void Scale(const float scale);
58       
59        /** Computes the center of mass of the polygon
60         */
61        Vector3 Center() const;
62        /** Checks if the polygon is valid, i.e., not degenerated.
63                @returns true if polygon is valid.
64        */
65        bool CheckValid() const;
66
67        /// vertices are connected in counterclockwise order.
68        VertexContainer mVertices;
69
70        /// we can also store materials with polygons
71        Material *mMaterial;
72       
73        /// pointer to the intersectable this polygon is derived from
74        Intersectable *mParent;
75};
76
77// Overload << operator for C++-style output
78inline ostream&
79operator<< (ostream &s, const Polygon3 &A)
80{
81        VertexContainer::const_iterator it;
82
83        //s << setprecision(6) << "Polygon:\n";
84        for (it = A.mVertices.begin(); it != A.mVertices.end(); ++it)
85                s << *it << endl;
86       
87        return s;
88}
89
90
91#endif
Note: See TracBrowser for help on using the repository browser.