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

Revision 306, 2.2 KB checked in by mattausch, 19 years ago (diff)

fixed polygon area, eval candidate plane

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;
16class AxisAlignedBox3;
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        /** Returns the area of this polygon.
44        */
45        float GetArea() const;
46
47        enum {BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT};
48
49        /** Classify polygon with respect to the plane.
50            @returns one of BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT
51        */
52        int ClassifyPlane(const Plane3 &plane) const;
53
54        /** Side of the polygon with respect to the plane.
55                @returns 1 if on front side, -1 if on back side, 0 else.
56        */
57        int Side(const Plane3 &plane) const;
58
59        /** Scales the polygon about its center
60        */
61        void Scale(const float scale);
62       
63        /** Computes the center of mass of the polygon
64         */
65        Vector3 Center() const;
66        /** Checks if the polygon is valid, i.e., not degenerated.
67                @returns true if polygon is valid.
68        */
69        bool Valid() const;
70
71        Vector3 GetNormal() const;
72
73        /** Includes polygons to axis aligned box.
74        */
75        static void IncludeInBox(const PolygonContainer &polys, AxisAlignedBox3 &box);
76
77        /// vertices are connected in counterclockwise order.
78        VertexContainer mVertices;
79
80        /// we can also store materials with polygons
81        Material *mMaterial;
82       
83        /// pointer to the intersectable this polygon is derived from
84        Intersectable *mParent;
85};
86
87// Overload << operator for C++-style output
88inline ostream&
89operator<< (ostream &s, const Polygon3 &A)
90{
91        VertexContainer::const_iterator it;
92
93        //s << setprecision(6) << "Polygon:\n";
94        for (it = A.mVertices.begin(); it != A.mVertices.end(); ++it)
95                s << *it << endl;
96       
97        return s;
98}
99
100
101#endif
Note: See TracBrowser for help on using the repository browser.