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

Revision 2720, 4.4 KB checked in by mattausch, 17 years ago (diff)

dynamic objects problem!!

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