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