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

Revision 321, 2.7 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;
16class AxisAlignedBox3;
17class Ray;
18//typedef Vertex3 Vector3;
19
20/** Class representing a planar convex polygon in 3d.
21*/
22class Polygon3
23{
24public:
25        Polygon3();
26        Polygon3(const VertexContainer &vertices);
27        Polygon3(MeshInstance *parent);
28        // creates an "infinite" polygon from this plane
29        //Polygon3(Plane3 plane);
30        /** Copies all the vertices of the face.
31        */
32        Polygon3(Face *face, Mesh *parentMesh);
33       
34        /** Returns supporting plane of this polygon.
35        */
36        Plane3 GetSupportingPlane() const;
37
38        /** Splits polygon.
39                @param partition the split plane
40                @param front returns the front the front polygon
41                @param back returns the back polygon
42                @param splitPts returns the split points
43        */
44        void Polygon3::Split(const Plane3 &partition,
45                                                 Polygon3 &front,
46                                                 Polygon3 &back,
47                                                 VertexContainer &splitPts);
48
49        /** Returns the area of this polygon.
50        */
51        float GetArea() const;
52
53        enum {BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT};
54
55        /** Classify polygon with respect to the plane.
56            @returns one of BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT
57        */
58        int ClassifyPlane(const Plane3 &plane) const;
59
60        /** Side of the polygon with respect to the plane.
61                @returns 1 if on front side, -1 if on back side, 0 else.
62        */
63        int Side(const Plane3 &plane) const;
64
65        /** Scales the polygon about its center
66        */
67        void Scale(const float scale);
68       
69        /** Computes the center of mass of the polygon
70         */
71        Vector3 Center() const;
72        /** Checks if the polygon is valid, i.e., not degenerated.
73                @returns true if polygon is valid.
74        */
75        bool Valid() const;
76
77        /** Returns the surface normal.
78        */
79        inline Vector3 GetNormal() const;
80
81        /** Includes polygons to axis aligned box.
82        */
83        static void IncludeInBox(const PolygonContainer &polys, AxisAlignedBox3 &box);
84
85        /** Casts ray to polygon.
86        */
87        int CastRay(const Ray &ray, float &t, const float nearestT);
88
89        /** Returns piercing rays container.
90        */
91        RayContainer *GetPiercingRays();
92
93        /** Adds a ray to the ray container.
94        */
95        void AddPiercingRay(Ray *ray);
96
97        /// vertices are connected in counterclockwise order.
98        VertexContainer mVertices;
99
100        /// we can also store materials with polygons
101        Material *mMaterial;
102       
103        /// pointer to the mesh instance this polygon is derived from
104        MeshInstance *mParent;
105
106        /// Rays piercing this polygon
107        RayContainer *mPiercingRays;
108};
109
110// Overload << operator for C++-style output
111inline ostream&
112operator<< (ostream &s, const Polygon3 &A)
113{
114        VertexContainer::const_iterator it;
115
116        //s << setprecision(6) << "Polygon:\n";
117        for (it = A.mVertices.begin(); it != A.mVertices.end(); ++it)
118                s << *it << endl;
119       
120        return s;
121}
122
123
124#endif
Note: See TracBrowser for help on using the repository browser.