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

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

corrected raycasting bug for triangles because of ill defined triangles

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