source: GTP/trunk/Lib/Vis/Preprocessing/src/Polygon3.h @ 1076

Revision 1076, 4.4 KB checked in by mattausch, 18 years ago (diff)

version for performance testing

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
12namespace GtpVisibilityPreprocessor {
13
14class Polygon3;
15class Plane3;
16struct Face;
17class Intersectable;
18class AxisAlignedBox3;
19class Ray;
20//typedef Vertex3 Vector3;
21
22/** Class representing a planar convex polygon in 3d.
23*/
24class Polygon3
25{
26public:
27        enum {BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT};
28
29        /** Default constructor creating an empty polygon.
30        */
31        Polygon3();
32        /** Constructor creating a polygon from the vertices.
33        */
34        Polygon3(const VertexContainer &vertices);
35        /** Creates a polygon and stores pointer to parent mesh
36                instance.
37        */
38        Polygon3(MeshInstance *parent);
39
40        // creates an "infinite" polygon from this plane
41        //Polygon3(Plane3 plane);
42        /** Copies all the vertices of the face.
43        */
44        Polygon3(Face *face, Mesh *parentMesh);
45       
46        /** Returns supporting plane of this polygon.
47        */
48        Plane3 GetSupportingPlane(); //const;
49
50        /** Splits polygon.
51                @param partition the split plane
52                @param front returns the front the front polygon
53                @param back returns the back polygon
54                @param epsilon epsilon where two points are considered equal
55        */
56        void Split(const Plane3 &partition,
57                           Polygon3 &front,
58                           Polygon3 &back,
59                           const float epsilon);// = Limits::Small);
60
61        /** Returns the area of this polygon.
62        */
63        float GetArea() const;
64
65        /** Classify polygon with respect to the plane.
66            @returns one of BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT
67        */
68        //int ClassifyPlane(const Plane3 &plane) const;
69       
70        /** Classify polygon with respect to the plane.
71            @param epsilon tolerance value
72                @returns one of BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT
73
74        */
75        int ClassifyPlane(const Plane3 &plane, const float epsilon) const;
76
77        /** Side of the polygon with respect to the plane.
78                @returns 1 if on front side, -1 if on back side, 0 else.
79        */
80        int Side(const Plane3 &plane, const float epsilon) const;
81
82        /** Scales the polygon about its center
83        */
84        void Scale(const float scale);
85       
86        /** Computes the center of mass of the polygon
87         */
88        Vector3 Center() const;
89        /** Checks if the polygon is valid, i.e., not degenerated.
90                @returns true if polygon is valid.
91        */
92        bool Valid(const float epsilon) const;
93
94        /** Returns the surface normal.
95        */
96        Vector3 GetNormal() const;
97
98        /** Casts ray to polygon.
99        */
100        int CastRay(const Ray &ray, float &t, const float nearestT);
101
102        /** The polygon is converted to triangles.
103        */
104        void Triangulate(vector<Triangle3> &triangles) const;
105
106        /**
107                Triangle strip indices are created from this polgon.
108        */
109        void Triangulate(VertexIndexContainer &indices) const;
110       
111        /** The piercing rays of the polygon are inherited by the child fragments
112                @parm front_piece the front fragment inheriting the front rays
113                @param back_piece the back fragment inheriting the back rays
114        */
115        void InheritRays(Polygon3 &front_piece,
116                                         Polygon3 &back_piece) const;
117
118        /** Returns new polygon with reverse orientation.
119        */
120        Polygon3 *CreateReversePolygon() const;
121
122
123        /** Classify polygons with respect to the plane.
124            @returns one of BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT
125        */
126        static int ClassifyPlane(const PolygonContainer &polys,
127                                                         const Plane3 &plane,
128                                                         const float epsilon);
129
130
131        /** Counts the number of different intersectables associated with the polygons.
132        */
133        static int ParentObjectsSize(const PolygonContainer &polys);
134
135        /** Area of the accumulated polygons.
136        */
137        static float GetArea(const PolygonContainer &cell);
138
139        /**
140                Adds polygon to mesh description as a face
141        */
142        friend void IncludePolyInMesh(const Polygon3 &poly, Mesh &mesh);
143
144
145       
146        /// vertices are connected in counterclockwise order.
147        VertexContainer mVertices;
148
149        /// we can also store materials with polygons
150        Material *mMaterial;
151       
152        /// pointer to the mesh instance this polygon is derived from
153        MeshInstance *mParent;
154
155        /// Rays piercing this polygon
156        RayContainer mPiercingRays;
157
158        ~Polygon3() {DEL_PTR(mPlane);}
159        Plane3 *mPlane;
160
161};
162
163// Overload << operator for C++-style output
164inline ostream&
165operator<< (ostream &s, const Polygon3 &A)
166{
167        VertexContainer::const_iterator it;
168
169        //s << setprecision(6) << "Polygon:\n";
170        for (it = A.mVertices.begin(); it != A.mVertices.end(); ++it)
171                s << *it << endl;
172       
173        return s;
174}
175
176}
177
178#endif
Note: See TracBrowser for help on using the repository browser.