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

Revision 333, 2.8 KB checked in by bittner, 19 years ago (diff)

code merge

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