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 | /// intersectable
|
---|
22 | Intersectable *mObject;
|
---|
23 | /// face index
|
---|
24 | int mFaceIndex;
|
---|
25 |
|
---|
26 | FaceParentInfo(Intersectable *obj, const int fi):
|
---|
27 | mObject(obj), mFaceIndex(fi)
|
---|
28 | {}
|
---|
29 | };
|
---|
30 |
|
---|
31 |
|
---|
32 | class Intersectable {
|
---|
33 | public:
|
---|
34 | // last mail id -> warning not thread safe!
|
---|
35 | // both mailId and mailbox should be unique for each thread!!!
|
---|
36 | static int sMailId;
|
---|
37 | static int sReservedMailboxes;
|
---|
38 |
|
---|
39 | /// Mailbox used for traversals
|
---|
40 | int mMailbox;
|
---|
41 |
|
---|
42 | /// unique object Id
|
---|
43 | int mId;
|
---|
44 |
|
---|
45 | /// universal counter
|
---|
46 | int mCounter;
|
---|
47 |
|
---|
48 | /// pointer to the containing bvh leaf
|
---|
49 | BvhLeaf *mBvhLeaf;
|
---|
50 |
|
---|
51 | /// # of references to this instance
|
---|
52 | //int mReferences;
|
---|
53 |
|
---|
54 | //////////////////
|
---|
55 | // note matt: delete these, they are only taking memory
|
---|
56 |
|
---|
57 | /// object based pvs
|
---|
58 | //KdPvs mKdPvs;
|
---|
59 |
|
---|
60 | /// view cell based pvs per object
|
---|
61 | //ViewCellPvs mViewCellPvs;
|
---|
62 |
|
---|
63 | ///////////////////////
|
---|
64 |
|
---|
65 | enum { MESH_INSTANCE,
|
---|
66 | TRANSFORMED_MESH_INSTANCE,
|
---|
67 | SPHERE,
|
---|
68 | VIEW_CELL,
|
---|
69 | OGRE_MESH_INSTANCE,
|
---|
70 | KD_INTERSECTABLE,
|
---|
71 | BVH_INTERSECTABLE,
|
---|
72 | TRIANGLE_INTERSECTABLE,
|
---|
73 | OBJECTS_INTERSECTABLE
|
---|
74 | };
|
---|
75 |
|
---|
76 | Intersectable():
|
---|
77 | mMailbox(0),
|
---|
78 | //mReferences(0),
|
---|
79 | mBvhLeaf(0),
|
---|
80 | mVssRays(NULL) {}
|
---|
81 |
|
---|
82 | virtual Intersectable::~Intersectable() {DEL_PTR(mVssRays);}
|
---|
83 |
|
---|
84 | void SetId(const int id) { mId = id; }
|
---|
85 | int GetId() { return mId; }
|
---|
86 |
|
---|
87 | ////////////////////////////////////////////////
|
---|
88 | // Mailing stuff
|
---|
89 |
|
---|
90 | static void NewMail(const int reserve = 1) {
|
---|
91 | sMailId += sReservedMailboxes;
|
---|
92 | sReservedMailboxes = reserve;
|
---|
93 | }
|
---|
94 |
|
---|
95 | void Mail() { mMailbox = sMailId; }
|
---|
96 | bool Mailed() const { return mMailbox == sMailId; }
|
---|
97 |
|
---|
98 | void Mail(const int mailbox) { mMailbox = sMailId + mailbox; }
|
---|
99 | bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; }
|
---|
100 |
|
---|
101 | int IncMail() { return ++ mMailbox - sMailId; }
|
---|
102 |
|
---|
103 | ////////////////////////////////////////////////////
|
---|
104 | virtual AxisAlignedBox3 GetBox() const = 0;
|
---|
105 | virtual int CastRay(Ray &ray) = 0;
|
---|
106 |
|
---|
107 | virtual bool IsConvex() const = 0;
|
---|
108 | virtual bool IsWatertight() const = 0;
|
---|
109 | virtual float IntersectionComplexity() = 0;
|
---|
110 |
|
---|
111 | virtual int NumberOfFaces() const = 0;
|
---|
112 | virtual int Type() const = 0;
|
---|
113 | virtual float GetArea() const {return 0; }
|
---|
114 | virtual int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0;
|
---|
115 | virtual int GetRandomSurfacePoint(const float u,
|
---|
116 | const float v,
|
---|
117 | Vector3 &point,
|
---|
118 | Vector3 &normal) {
|
---|
119 | cerr<<"GetRandomSurfacePoint(u,v...) not yet implemented"<<endl;
|
---|
120 | return 1;
|
---|
121 | }
|
---|
122 |
|
---|
123 | virtual int GetRandomEdgePoint(Vector3 &point,
|
---|
124 | Vector3 &normal) = 0;
|
---|
125 |
|
---|
126 | virtual int GetRandomVisibleSurfacePoint(Vector3 &point,
|
---|
127 | Vector3 &normal,
|
---|
128 | const Vector3 &viewpoint,
|
---|
129 | const int maxTries) = 0;
|
---|
130 |
|
---|
131 | virtual ostream &Describe(ostream &s) = 0;
|
---|
132 |
|
---|
133 | virtual int GenerateSilhouetteRays(const int nrays,
|
---|
134 | const AxisAlignedBox3 &originBox,
|
---|
135 | const AxisAlignedBox3 &directionBox, VssRayContainer &rays)
|
---|
136 | {
|
---|
137 | return 0;
|
---|
138 | }
|
---|
139 |
|
---|
140 | static bool GreaterCounter(const Intersectable *a,
|
---|
141 | const Intersectable *b)
|
---|
142 | {
|
---|
143 | return a->mCounter > b->mCounter;
|
---|
144 | }
|
---|
145 |
|
---|
146 | static string GetTypeName(Intersectable *obj)
|
---|
147 | {
|
---|
148 | switch(obj->Type())
|
---|
149 | {
|
---|
150 | case MESH_INSTANCE:
|
---|
151 | return "mesh_instance\n";
|
---|
152 |
|
---|
153 | case TRANSFORMED_MESH_INSTANCE:
|
---|
154 | return "transformed_mesh_instance\n";
|
---|
155 |
|
---|
156 | case SPHERE:
|
---|
157 | return "sphere\n";
|
---|
158 |
|
---|
159 | case VIEW_CELL:
|
---|
160 | return "view cell\n";
|
---|
161 |
|
---|
162 | case OGRE_MESH_INSTANCE:
|
---|
163 | return "ogre_mesh_instance\n";
|
---|
164 |
|
---|
165 | case KD_INTERSECTABLE:
|
---|
166 | return "kd_intersectable\n";
|
---|
167 |
|
---|
168 | default:
|
---|
169 | return "unknown\n";
|
---|
170 | }
|
---|
171 | }
|
---|
172 |
|
---|
173 | /** Returns normal from the face with the specified index.
|
---|
174 | PROBLEM: Does not fit to all intersectable types (e.g., spheres)
|
---|
175 | */
|
---|
176 | virtual Vector3 GetNormal(const int idx) const { return Vector3(0, 0, 0); }
|
---|
177 |
|
---|
178 | VssRayContainer *GetOrCreateRays()
|
---|
179 | {
|
---|
180 | if (!mVssRays)
|
---|
181 | mVssRays = new VssRayContainer();
|
---|
182 | return mVssRays;
|
---|
183 | }
|
---|
184 |
|
---|
185 | void DelRayRefs()
|
---|
186 | {
|
---|
187 | DEL_PTR(mVssRays);
|
---|
188 | }
|
---|
189 |
|
---|
190 | protected:
|
---|
191 |
|
---|
192 | /// some rays piercing this intersectable
|
---|
193 | VssRayContainer *mVssRays;
|
---|
194 | };
|
---|
195 |
|
---|
196 |
|
---|
197 | }
|
---|
198 |
|
---|
199 | #endif
|
---|