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

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

added polygon area (debugged)

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        /** Includes polygons to axis aligned box.
72        */
73        static void IncludeInBox(const PolygonContainer &polys, AxisAlignedBox3 &box);
74
75        /// vertices are connected in counterclockwise order.
76        VertexContainer mVertices;
77
78        /// we can also store materials with polygons
79        Material *mMaterial;
80       
81        /// pointer to the intersectable this polygon is derived from
82        Intersectable *mParent;
83};
84
85// Overload << operator for C++-style output
86inline ostream&
87operator<< (ostream &s, const Polygon3 &A)
88{
89        VertexContainer::const_iterator it;
90
91        //s << setprecision(6) << "Polygon:\n";
92        for (it = A.mVertices.begin(); it != A.mVertices.end(); ++it)
93                s << *it << endl;
94       
95        return s;
96}
97
98
99#endif
Note: See TracBrowser for help on using the repository browser.