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

RevLine 
[235]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"
[236]9#include "Mesh.h"
[270]10#include <iomanip>
[235]11
[236]12class Polygon3;
[235]13class Plane3;
14class Face;
[286]15class Intersectable;
[295]16class AxisAlignedBox3;
[289]17//typedef Vertex3 Vector3;
18
19/** Class representing a planar convex polygon in 3d.
[235]20*/
21class Polygon3
22{
23public:
24        Polygon3();
[236]25        Polygon3(const VertexContainer &vertices);
[286]26        Polygon3(Intersectable *parent);
[235]27
28        /** Copies all the vertices of the face.
29        */
[286]30        Polygon3(Face *face, Mesh *parentMesh);
[235]31       
32        /** Returns supporting plane of this polygon.
33        */
[238]34        Plane3 GetSupportingPlane() const;
[235]35
36        /** Splits polygon.
37                @param partition the split plane
38                @param front the front polygon
39                @param back the back polygon
40        */
[289]41        void Split(Plane3 *partition, Polygon3 *front, Polygon3 *back);
[235]42
[298]43        /** Returns the area of this polygon.
44        */
45        float GetArea() const;
46
[235]47        enum {BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT};
48
[238]49        /** Classify polygon with respect to the plane.
[235]50            @returns one of BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT
51        */
[238]52        int ClassifyPlane(const Plane3 &plane) const;
[235]53
[238]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
[256]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;
[289]66        /** Checks if the polygon is valid, i.e., not degenerated.
67                @returns true if polygon is valid.
68        */
[299]69        bool Valid() const;
[256]70
[306]71        Vector3 GetNormal() const;
72
[295]73        /** Includes polygons to axis aligned box.
74        */
75        static void IncludeInBox(const PolygonContainer &polys, AxisAlignedBox3 &box);
76
[235]77        /// vertices are connected in counterclockwise order.
78        VertexContainer mVertices;
[242]79
80        /// we can also store materials with polygons
81        Material *mMaterial;
[286]82       
83        /// pointer to the intersectable this polygon is derived from
84        Intersectable *mParent;
[235]85};
86
[237]87// Overload << operator for C++-style output
88inline ostream&
89operator<< (ostream &s, const Polygon3 &A)
90{
91        VertexContainer::const_iterator it;
[235]92
[289]93        //s << setprecision(6) << "Polygon:\n";
[237]94        for (it = A.mVertices.begin(); it != A.mVertices.end(); ++it)
95                s << *it << endl;
96       
97        return s;
98}
[235]99
[237]100
[235]101#endif
Note: See TracBrowser for help on using the repository browser.