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

RevLine 
[372]1#ifndef _Polygon3_h__
2#define _Polygon3_h__
3
4
[2116]5#include <iostream>
6#include "common.h"
[372]7#include "Containers.h"
[2116]8#include "Vector3.h"
[372]9#include <iomanip>
10
[860]11namespace GtpVisibilityPreprocessor {
12
[372]13class Polygon3;
14class Plane3;
[752]15struct Face;
[372]16class Intersectable;
17class AxisAlignedBox3;
18class Ray;
[2116]19class Mesh;
20class MeshInstance;
21class Material;
22struct Triangle3;
[372]23
[2116]24
[372]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);
[1404]42        /** A Triangle is converted to a polygon.
43        */
44        Polygon3(const Triangle3 &tri);
[372]45
[2116]46        ~Polygon3();
[1328]47       
[372]48        /** Copies all the vertices of the face.
49        */
50        Polygon3(Face *face, Mesh *parentMesh);
51       
52        /** Returns supporting plane of this polygon.
53        */
[1076]54        Plane3 GetSupportingPlane(); //const;
[372]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
[448]60                @param epsilon epsilon where two points are considered equal
[372]61        */
62        void Split(const Plane3 &partition,
63                           Polygon3 &front,
[448]64                           Polygon3 &back,
65                           const float epsilon);// = Limits::Small);
[372]66
67        /** Returns the area of this polygon.
68        */
69        float GetArea() const;
[404]70       
71        /** Classify polygon with respect to the plane.
[448]72            @param epsilon tolerance value
73                @returns one of BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT
74
[404]75        */
[448]76        int ClassifyPlane(const Plane3 &plane, const float epsilon) const;
[404]77
[372]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        */
[448]81        int Side(const Plane3 &plane, const float epsilon) const;
[372]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;
[1328]90
[372]91        /** Checks if the polygon is valid, i.e., not degenerated.
92                @returns true if polygon is valid.
93        */
[448]94        bool Valid(const float epsilon) const;
[372]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
[508]104        /** The polygon is converted to triangles.
[503]105        */
[840]106        void Triangulate(vector<Triangle3> &triangles) const;
107
[508]108        /**
109                Triangle strip indices are created from this polgon.
110        */
[840]111        void Triangulate(VertexIndexContainer &indices) const;
[508]112       
[384]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
[372]116        */
[384]117        void InheritRays(Polygon3 &front_piece,
118                                         Polygon3 &back_piece) const;
[372]119
[396]120        /** Returns new polygon with reverse orientation.
121        */
122        Polygon3 *CreateReversePolygon() const;
[384]123
[1328]124        AxisAlignedBox3 GetBoundingBox() const;
[372]125
[1328]126        ////////////////////////////////////////////
127
[384]128        /** Classify polygons with respect to the plane.
129            @returns one of BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT
130        */
[448]131        static int ClassifyPlane(const PolygonContainer &polys,
132                                                         const Plane3 &plane,
133                                                         const float epsilon);
[372]134
135        /** Counts the number of different intersectables associated with the polygons.
136        */
[375]137        static int ParentObjectsSize(const PolygonContainer &polys);
[384]138
[574]139        /** Area of the accumulated polygons.
140        */
[384]141        static float GetArea(const PolygonContainer &cell);
[840]142
[1328]143        //////////////////////////////////////////////////////
144
[840]145        /**
146                Adds polygon to mesh description as a face
147        */
148        friend void IncludePolyInMesh(const Polygon3 &poly, Mesh &mesh);
[860]149
150
[1328]151        //////////////////////////////////////////
[860]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
[1328]165protected:
166
[1076]167        Plane3 *mPlane;
[372]168};
169
[1328]170
[372]171// Overload << operator for C++-style output
[2176]172inline std::ostream&
173operator<< (std::ostream &s, const Polygon3 &A)
[372]174{
175        VertexContainer::const_iterator it;
176
177        //s << setprecision(6) << "Polygon:\n";
[2116]178        for (it = A.mVertices.begin(); it != A.mVertices.end(); ++ it)
179        {
[1420]180                s << *it << " ";
[2116]181        }
182
[372]183        return s;
184}
185
[860]186}
[372]187
188#endif
Note: See TracBrowser for help on using the repository browser.