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!!

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;
[2720]107        /** Triangle strip indices are created from this polgon.
[508]108        */
[840]109        void Triangulate(VertexIndexContainer &indices) const;
[508]110       
[384]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
[372]114        */
[384]115        void InheritRays(Polygon3 &front_piece,
116                                         Polygon3 &back_piece) const;
[372]117
[396]118        /** Returns new polygon with reverse orientation.
119        */
120        Polygon3 *CreateReversePolygon() const;
[384]121
[1328]122        AxisAlignedBox3 GetBoundingBox() const;
[372]123
[1328]124        ////////////////////////////////////////////
125
[384]126        /** Classify polygons with respect to the plane.
127            @returns one of BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT
128        */
[448]129        static int ClassifyPlane(const PolygonContainer &polys,
130                                                         const Plane3 &plane,
131                                                         const float epsilon);
[372]132
133        /** Counts the number of different intersectables associated with the polygons.
134        */
[375]135        static int ParentObjectsSize(const PolygonContainer &polys);
[384]136
[574]137        /** Area of the accumulated polygons.
138        */
[384]139        static float GetArea(const PolygonContainer &cell);
[840]140
[1328]141        //////////////////////////////////////////////////////
142
[840]143        /**
144                Adds polygon to mesh description as a face
145        */
146        friend void IncludePolyInMesh(const Polygon3 &poly, Mesh &mesh);
[860]147
148
[1328]149        //////////////////////////////////////////
[860]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
[1328]163protected:
164
[1076]165        Plane3 *mPlane;
[372]166};
167
[1328]168
[372]169// Overload << operator for C++-style output
[2176]170inline std::ostream&
171operator<< (std::ostream &s, const Polygon3 &A)
[372]172{
173        VertexContainer::const_iterator it;
174
175        //s << setprecision(6) << "Polygon:\n";
[2116]176        for (it = A.mVertices.begin(); it != A.mVertices.end(); ++ it)
177        {
[1420]178                s << *it << " ";
[2116]179        }
180
[372]181        return s;
182}
183
[860]184}
[372]185
186#endif
Note: See TracBrowser for help on using the repository browser.