source: GTP/trunk/Lib/Vis/Preprocessing/src/Triangle3.h @ 2579

Revision 2579, 1.8 KB checked in by mattausch, 16 years ago (diff)
RevLine 
[191]1#ifndef __TRIANGLE3_H
2#define __TRIANGLE3_H
3
4#include "Vector3.h"
5
[1328]6
[860]7namespace GtpVisibilityPreprocessor {
8
[1328]9class AxisAlignedBox3;
10class Ray;
[2579]11struct SimpleRay;
[1932]12class Plane3;
[191]13
[1328]14struct Triangle3
15{
16        Triangle3() {};
17        Triangle3(const Vector3 &a, const Vector3 &b, const Vector3 &c);
[191]18
[1328]19        void Init(const Vector3 &a, const Vector3 &b, const Vector3 &c);
[191]20
[1328]21        Vector3 GetNormal() const;
[544]22
[1328]23        Vector3 GetCenter() const;
24
25        float GetSpatialAngle(const Vector3 &point) const;
26
27        float GetArea() const;
28
29        /// returns bounding box around this triangle
30        AxisAlignedBox3 GetBoundingBox() const;
31
32        /// Casts ray into this triangle. Returns hit
[1344]33        int CastRay(const Ray &ray, float &t, const float nearestT, Vector3 &normal) const;
[1328]34
[2575]35        int CastSimpleRay(const SimpleRay &ray, float &t, const float nearestT) const;
36 
[2176]37        friend std::ostream& operator<< (std::ostream &s, const Triangle3 &A);
38        friend std::istream& operator>> (std::istream &s, Triangle3 &A);
[1328]39
[1932]40        /** Checks if this triangle is ill-defined.
41        */
42        bool CheckValidity() const;
[1344]43
[1932]44        /** Intersects triangle with plane, returns intersection points
45                if intersection is happening.
46
47                @returns true if triangle intersects plane
48        */
[1933]49        bool GetPlaneIntersection(const Plane3 &plane,
50                                                          Vector3 &intersectA,
51                                                          Vector3 &intersectB) const;
[1932]52
53        ///////////////////
54
55        /// the triangle vertices
56        Vector3 mVertices[3];
[191]57};
58
[1344]59
60// Overload << operator for C++-style output
[2176]61inline std::ostream&
62operator<< (std::ostream &s, const Triangle3 &A)
[1344]63{
64  return s << "(" << A.mVertices[0] << ", " << A.mVertices[1] << ", " << A.mVertices[2] << ")";
[860]65}
[191]66
[1344]67// Overload >> operator for C++-style input
[2176]68inline std::istream&
69operator>> (std::istream &s, Triangle3 &A)
[1344]70{
71  char a;
72  // read "(x, y, z)"
73  return s >> a >> A.mVertices[0] >> a >> A.mVertices[1] >> a >> A.mVertices[2] >> a;
74}
75
76
77}
78
[191]79#endif
80
Note: See TracBrowser for help on using the repository browser.