1 | #ifndef __INTERSECTABLE_H
|
---|
2 | #define __INTERSECTABLE_H
|
---|
3 |
|
---|
4 | #include "AxisAlignedBox3.h"
|
---|
5 | #include "Pvs.h"
|
---|
6 | #include <set>
|
---|
7 | #include "VssRay.h"
|
---|
8 | #include "Mailable.h"
|
---|
9 |
|
---|
10 | namespace GtpVisibilityPreprocessor {
|
---|
11 |
|
---|
12 | struct VssRayContainer;
|
---|
13 | class KdLeaf;
|
---|
14 | class BvhLeaf;
|
---|
15 | class BvhNode;
|
---|
16 | class Intersectable;
|
---|
17 | struct Face;
|
---|
18 |
|
---|
19 |
|
---|
20 | struct FaceParentInfo
|
---|
21 | {
|
---|
22 | /// intersectable
|
---|
23 | Intersectable *mObject;
|
---|
24 | /// face index
|
---|
25 | int mFaceIndex;
|
---|
26 |
|
---|
27 | FaceParentInfo(Intersectable *obj, const int fi):
|
---|
28 | mObject(obj), mFaceIndex(fi)
|
---|
29 | {}
|
---|
30 | };
|
---|
31 |
|
---|
32 |
|
---|
33 | class Intersectable
|
---|
34 | {
|
---|
35 | public:
|
---|
36 |
|
---|
37 | /// unique object Id
|
---|
38 | int mId;
|
---|
39 |
|
---|
40 | /// universal counter
|
---|
41 | int mCounter;
|
---|
42 |
|
---|
43 | /// pointer to the containing bvh leaf
|
---|
44 | BvhLeaf *mBvhLeaf;
|
---|
45 |
|
---|
46 | ///////////////////////
|
---|
47 |
|
---|
48 | enum { MESH_INSTANCE,
|
---|
49 | TRANSFORMED_MESH_INSTANCE,
|
---|
50 | SPHERE,
|
---|
51 | VIEW_CELL,
|
---|
52 | OGRE_MESH_INSTANCE,
|
---|
53 | KD_INTERSECTABLE,
|
---|
54 | BVH_INTERSECTABLE,
|
---|
55 | TRIANGLE_INTERSECTABLE,
|
---|
56 | DUMMY_INTERSECTABLE,
|
---|
57 | ENGINE_INTERSECTABLE,
|
---|
58 | };
|
---|
59 |
|
---|
60 | Intersectable();
|
---|
61 |
|
---|
62 | virtual ~Intersectable();
|
---|
63 |
|
---|
64 | void SetId(const int id) { mId = id; }
|
---|
65 | int GetId() { return mId; }
|
---|
66 |
|
---|
67 | /////////////
|
---|
68 | // Mailing stuff
|
---|
69 |
|
---|
70 | static void NewMail(const int reserve = 1)
|
---|
71 | {
|
---|
72 | sMailId += sReservedMailboxes;
|
---|
73 | sReservedMailboxes = reserve;
|
---|
74 | }
|
---|
75 |
|
---|
76 | void Mail() { mMailbox = sMailId; }
|
---|
77 | bool Mailed() const { return mMailbox == sMailId; }
|
---|
78 |
|
---|
79 | void Mail(const int mailbox) { mMailbox = sMailId + mailbox; }
|
---|
80 | bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; }
|
---|
81 |
|
---|
82 | int IncMail() { return ++ mMailbox - sMailId; }
|
---|
83 |
|
---|
84 | // last mail id -> warning not thread safe!
|
---|
85 | // both mailId and mailbox should be unique for each thread!!!
|
---|
86 | static int sMailId;
|
---|
87 | static int sReservedMailboxes;
|
---|
88 |
|
---|
89 | /// Mailbox used for traversals
|
---|
90 | int mMailbox;
|
---|
91 |
|
---|
92 |
|
---|
93 | ////////////////
|
---|
94 | // virtual interface
|
---|
95 |
|
---|
96 | virtual AxisAlignedBox3 GetBox() const = 0;
|
---|
97 | virtual int CastRay(Ray &ray) = 0;
|
---|
98 |
|
---|
99 | virtual bool IsConvex() const = 0;
|
---|
100 | virtual bool IsWatertight() const = 0;
|
---|
101 | virtual float IntersectionComplexity() = 0;
|
---|
102 |
|
---|
103 | virtual int NumberOfFaces() const = 0;
|
---|
104 | virtual int Type() const = 0;
|
---|
105 |
|
---|
106 | virtual int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0;
|
---|
107 |
|
---|
108 | virtual int GetRandomEdgePoint(Vector3 &point,
|
---|
109 | Vector3 &normal) = 0;
|
---|
110 |
|
---|
111 | virtual int GetRandomVisibleSurfacePoint(Vector3 &point,
|
---|
112 | Vector3 &normal,
|
---|
113 | const Vector3 &viewpoint,
|
---|
114 | const int maxTries) = 0;
|
---|
115 |
|
---|
116 | // virtual int GetRandomPoint(Vector3 &point,
|
---|
117 | // vector3 &normal) = 0;
|
---|
118 |
|
---|
119 | virtual ostream &Describe(ostream &s) = 0;
|
---|
120 |
|
---|
121 | //////////////////////////////////////
|
---|
122 |
|
---|
123 |
|
---|
124 | virtual int GenerateSilhouetteRays(const int nrays,
|
---|
125 | const AxisAlignedBox3 &originBox,
|
---|
126 | const AxisAlignedBox3 &directionBox,
|
---|
127 | VssRayContainer &rays);
|
---|
128 |
|
---|
129 | virtual int GetRandomSurfacePoint(const float u,
|
---|
130 | const float v,
|
---|
131 | Vector3 &point,
|
---|
132 | Vector3 &normal);
|
---|
133 |
|
---|
134 | virtual float GetArea() const;
|
---|
135 |
|
---|
136 | static bool GreaterCounter(const Intersectable *a,
|
---|
137 | const Intersectable *b);
|
---|
138 |
|
---|
139 | /** Returns the name of the type of this intersectable
|
---|
140 | */
|
---|
141 | static string GetTypeName(Intersectable *obj);
|
---|
142 |
|
---|
143 | /** Returns normal from the face with the specified index.
|
---|
144 | PROBLEM: Does not fit to all intersectable types (e.g., spheres)
|
---|
145 | */
|
---|
146 | virtual Vector3 GetNormal(const int idx) const;
|
---|
147 |
|
---|
148 | /** Returns rays stored with this intersectable.
|
---|
149 | */
|
---|
150 | VssRayContainer *GetOrCreateRays();
|
---|
151 |
|
---|
152 | /** Deletes the rays associated with this intersectable.
|
---|
153 | */
|
---|
154 | void DelRayRefs();
|
---|
155 |
|
---|
156 | protected:
|
---|
157 |
|
---|
158 | /// some rays piercing this intersectable
|
---|
159 | VssRayContainer *mVssRays;
|
---|
160 | };
|
---|
161 |
|
---|
162 |
|
---|
163 | }
|
---|
164 |
|
---|
165 | #endif
|
---|