#ifndef _Polygon3_h__ #define _Polygon3_h__ //#include //#include //#include "common.h" #include "Containers.h" #include "Mesh.h" #include namespace GtpVisibilityPreprocessor { class Polygon3; class Plane3; struct Face; class Intersectable; class AxisAlignedBox3; class Ray; //typedef Vertex3 Vector3; /** Class representing a planar convex polygon in 3d. */ class Polygon3 { public: enum {BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT}; /** Default constructor creating an empty polygon. */ Polygon3(); /** Constructor creating a polygon from the vertices. */ Polygon3(const VertexContainer &vertices); /** Creates a polygon and stores pointer to parent mesh instance. */ Polygon3(MeshInstance *parent); // creates an "infinite" polygon from this plane //Polygon3(Plane3 plane); /** Copies all the vertices of the face. */ Polygon3(Face *face, Mesh *parentMesh); /** Returns supporting plane of this polygon. */ Plane3 GetSupportingPlane(); //const; /** Splits polygon. @param partition the split plane @param front returns the front the front polygon @param back returns the back polygon @param epsilon epsilon where two points are considered equal */ void Split(const Plane3 &partition, Polygon3 &front, Polygon3 &back, const float epsilon);// = Limits::Small); /** Returns the area of this polygon. */ float GetArea() const; /** Classify polygon with respect to the plane. @returns one of BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT */ //int ClassifyPlane(const Plane3 &plane) const; /** Classify polygon with respect to the plane. @param epsilon tolerance value @returns one of BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT */ int ClassifyPlane(const Plane3 &plane, const float epsilon) const; /** Side of the polygon with respect to the plane. @returns 1 if on front side, -1 if on back side, 0 else. */ int Side(const Plane3 &plane, const float epsilon) const; /** Scales the polygon about its center */ void Scale(const float scale); /** Computes the center of mass of the polygon */ Vector3 Center() const; /** Checks if the polygon is valid, i.e., not degenerated. @returns true if polygon is valid. */ bool Valid(const float epsilon) const; /** Returns the surface normal. */ Vector3 GetNormal() const; /** Casts ray to polygon. */ int CastRay(const Ray &ray, float &t, const float nearestT); /** The polygon is converted to triangles. */ void Triangulate(vector &triangles) const; /** Triangle strip indices are created from this polgon. */ void Triangulate(VertexIndexContainer &indices) const; /** The piercing rays of the polygon are inherited by the child fragments @parm front_piece the front fragment inheriting the front rays @param back_piece the back fragment inheriting the back rays */ void InheritRays(Polygon3 &front_piece, Polygon3 &back_piece) const; /** Returns new polygon with reverse orientation. */ Polygon3 *CreateReversePolygon() const; /** Classify polygons with respect to the plane. @returns one of BACK_SIDE, FRONT_SIDE, SPLIT, COINCIDENT */ static int ClassifyPlane(const PolygonContainer &polys, const Plane3 &plane, const float epsilon); /** Counts the number of different intersectables associated with the polygons. */ static int ParentObjectsSize(const PolygonContainer &polys); /** Area of the accumulated polygons. */ static float GetArea(const PolygonContainer &cell); /** Adds polygon to mesh description as a face */ friend void IncludePolyInMesh(const Polygon3 &poly, Mesh &mesh); /// vertices are connected in counterclockwise order. VertexContainer mVertices; /// we can also store materials with polygons Material *mMaterial; /// pointer to the mesh instance this polygon is derived from MeshInstance *mParent; /// Rays piercing this polygon RayContainer mPiercingRays; ~Polygon3() {DEL_PTR(mPlane);} Plane3 *mPlane; }; // Overload << operator for C++-style output inline ostream& operator<< (ostream &s, const Polygon3 &A) { VertexContainer::const_iterator it; //s << setprecision(6) << "Polygon:\n"; for (it = A.mVertices.begin(); it != A.mVertices.end(); ++it) s << *it << endl; return s; } } #endif