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 |
|
---|
9 | namespace GtpVisibilityPreprocessor {
|
---|
10 |
|
---|
11 | struct VssRayContainer;
|
---|
12 | class KdLeaf;
|
---|
13 | class BvhLeaf;
|
---|
14 |
|
---|
15 | class Intersectable;
|
---|
16 | struct Face;
|
---|
17 |
|
---|
18 | struct FaceParentInfo {
|
---|
19 | // intersectable
|
---|
20 | Intersectable *mObject;
|
---|
21 | // face index
|
---|
22 | int mFaceIndex;
|
---|
23 |
|
---|
24 | FaceParentInfo(Intersectable *obj,
|
---|
25 | const int fi):
|
---|
26 | mObject(obj),
|
---|
27 | mFaceIndex(fi)
|
---|
28 | {}
|
---|
29 | };
|
---|
30 |
|
---|
31 | class Intersectable {
|
---|
32 | public:
|
---|
33 | // last mail id -> warning not thread safe!
|
---|
34 | // both mailId and mailbox should be unique for each thread!!!
|
---|
35 | static int sMailId;
|
---|
36 | static int sReservedMailboxes;
|
---|
37 | int mMailbox;
|
---|
38 |
|
---|
39 | /// unique object Id
|
---|
40 | int mId;
|
---|
41 |
|
---|
42 | /// universal counter
|
---|
43 | int mCounter;
|
---|
44 |
|
---|
45 | /// object based pvs
|
---|
46 | KdPvs mKdPvs;
|
---|
47 |
|
---|
48 | /// view cell based pvs per object
|
---|
49 | ViewCellPvs mViewCellPvs;
|
---|
50 |
|
---|
51 | /// pointer to the container bvh leaf
|
---|
52 | BvhLeaf *mBvhLeaf;
|
---|
53 |
|
---|
54 | VssRayContainer mVssRays;
|
---|
55 |
|
---|
56 | /// # of references to this instance
|
---|
57 | int mReferences;
|
---|
58 |
|
---|
59 | enum { MESH_INSTANCE,
|
---|
60 | TRANSFORMED_MESH_INSTANCE,
|
---|
61 | SPHERE,
|
---|
62 | VIEW_CELL,
|
---|
63 | OGRE_MESH_INSTANCE,
|
---|
64 | KD_INTERSECTABLE,
|
---|
65 | BVH_INTERSECTABLE
|
---|
66 | };
|
---|
67 |
|
---|
68 | Intersectable(): mMailbox(0), mReferences(0) {}
|
---|
69 |
|
---|
70 | void SetId(const int id) { mId = id; }
|
---|
71 | int GetId() { return mId; }
|
---|
72 |
|
---|
73 | ////////////////////////////////////////////////
|
---|
74 | // Mailing stuff
|
---|
75 |
|
---|
76 | static void NewMail(const int reserve = 1) {
|
---|
77 | sMailId += sReservedMailboxes;
|
---|
78 | sReservedMailboxes = reserve;
|
---|
79 | }
|
---|
80 |
|
---|
81 | void Mail() { mMailbox = sMailId; }
|
---|
82 | bool Mailed() const { return mMailbox == sMailId; }
|
---|
83 |
|
---|
84 | void Mail(const int mailbox) { mMailbox = sMailId + mailbox; }
|
---|
85 | bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; }
|
---|
86 |
|
---|
87 | int IncMail() { return ++ mMailbox - sMailId; }
|
---|
88 |
|
---|
89 | ////////////////////////////////////////////////////
|
---|
90 | virtual AxisAlignedBox3 GetBox() const = 0;
|
---|
91 | virtual int CastRay(GtpVisibilityPreprocessor::Ray &ray) = 0;
|
---|
92 |
|
---|
93 | virtual bool IsConvex() const = 0;
|
---|
94 | virtual bool IsWatertight() const = 0;
|
---|
95 | virtual float IntersectionComplexity() = 0;
|
---|
96 |
|
---|
97 | virtual int NumberOfFaces() const = 0;
|
---|
98 | virtual int Type() const = 0;
|
---|
99 |
|
---|
100 | virtual int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0;
|
---|
101 |
|
---|
102 | virtual int GetRandomVisibleSurfacePoint(Vector3 &point,
|
---|
103 | Vector3 &normal,
|
---|
104 | const Vector3 &viewpoint,
|
---|
105 | const int maxTries) = 0;
|
---|
106 |
|
---|
107 | virtual ostream &Describe(ostream &s) = 0;
|
---|
108 |
|
---|
109 | virtual int GenerateSilhouetteRays(const int nrays,
|
---|
110 | const AxisAlignedBox3 &originBox,
|
---|
111 | const AxisAlignedBox3 &directionBox, VssRayContainer &rays)
|
---|
112 | {
|
---|
113 | return 0;
|
---|
114 | }
|
---|
115 |
|
---|
116 | static bool GreaterCounter(const Intersectable *a,
|
---|
117 | const Intersectable *b)
|
---|
118 | {
|
---|
119 | return a->mCounter > b->mCounter;
|
---|
120 | }
|
---|
121 |
|
---|
122 | static string GetTypeName(Intersectable *obj)
|
---|
123 | {
|
---|
124 | switch(obj->Type())
|
---|
125 | {
|
---|
126 | case MESH_INSTANCE:
|
---|
127 | return "mesh_instance\n";
|
---|
128 |
|
---|
129 | case TRANSFORMED_MESH_INSTANCE:
|
---|
130 | return "transformed_mesh_instance\n";
|
---|
131 |
|
---|
132 | case SPHERE:
|
---|
133 | return "sphere\n";
|
---|
134 |
|
---|
135 | case VIEW_CELL:
|
---|
136 | return "view cell\n";
|
---|
137 |
|
---|
138 | case OGRE_MESH_INSTANCE:
|
---|
139 | return "ogre_mesh_instance\n";
|
---|
140 |
|
---|
141 | case KD_INTERSECTABLE:
|
---|
142 | return "kd_intersectable\n";
|
---|
143 |
|
---|
144 | default:
|
---|
145 | return "unknown\n";
|
---|
146 | }
|
---|
147 | }
|
---|
148 | };
|
---|
149 |
|
---|
150 |
|
---|
151 | }
|
---|
152 |
|
---|
153 | #endif
|
---|