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

Revision 329, 2.8 KB checked in by mattausch, 19 years ago (diff)

worked on ray based subdivision

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