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

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

removed using namespace std from .h

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
108        /**
109                Triangle strip indices are created from this polgon.
110        */
111        void Triangulate(VertexIndexContainer &indices) const;
112       
113        /** The piercing rays of the polygon are inherited by the child fragments
114                @parm front_piece the front fragment inheriting the front rays
115                @param back_piece the back fragment inheriting the back rays
116        */
117        void InheritRays(Polygon3 &front_piece,
118                                         Polygon3 &back_piece) const;
119
120        /** Returns new polygon with reverse orientation.
121        */
122        Polygon3 *CreateReversePolygon() const;
123
124        AxisAlignedBox3 GetBoundingBox() const;
125
126        ////////////////////////////////////////////
127
128        /** Classify polygons with respect to the plane.
129            @returns one of BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT
130        */
131        static int ClassifyPlane(const PolygonContainer &polys,
132                                                         const Plane3 &plane,
133                                                         const float epsilon);
134
135        /** Counts the number of different intersectables associated with the polygons.
136        */
137        static int ParentObjectsSize(const PolygonContainer &polys);
138
139        /** Area of the accumulated polygons.
140        */
141        static float GetArea(const PolygonContainer &cell);
142
143        //////////////////////////////////////////////////////
144
145        /**
146                Adds polygon to mesh description as a face
147        */
148        friend void IncludePolyInMesh(const Polygon3 &poly, Mesh &mesh);
149
150
151        //////////////////////////////////////////
152       
153        /// vertices are connected in counterclockwise order.
154        VertexContainer mVertices;
155
156        /// we can also store materials with polygons
157        Material *mMaterial;
158       
159        /// pointer to the mesh instance this polygon is derived from
160        MeshInstance *mParent;
161
162        /// Rays piercing this polygon
163        RayContainer mPiercingRays;
164
165protected:
166
167        Plane3 *mPlane;
168};
169
170
171// Overload << operator for C++-style output
172inline std::ostream&
173operator<< (std::ostream &s, const Polygon3 &A)
174{
175        VertexContainer::const_iterator it;
176
177        //s << setprecision(6) << "Polygon:\n";
178        for (it = A.mVertices.begin(); it != A.mVertices.end(); ++ it)
179        {
180                s << *it << " ";
181        }
182
183        return s;
184}
185
186}
187
188#endif
Note: See TracBrowser for help on using the repository browser.