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 | TRIANGLE_INTERSECTABLE
|
---|
67 | };
|
---|
68 |
|
---|
69 | Intersectable(): mMailbox(0), mReferences(0), mBvhLeaf(0) {}
|
---|
70 |
|
---|
71 | void SetId(const int id) { mId = id; }
|
---|
72 | int GetId() { return mId; }
|
---|
73 |
|
---|
74 | ////////////////////////////////////////////////
|
---|
75 | // Mailing stuff
|
---|
76 |
|
---|
77 | static void NewMail(const int reserve = 1) {
|
---|
78 | sMailId += sReservedMailboxes;
|
---|
79 | sReservedMailboxes = reserve;
|
---|
80 | }
|
---|
81 |
|
---|
82 | void Mail() { mMailbox = sMailId; }
|
---|
83 | bool Mailed() const { return mMailbox == sMailId; }
|
---|
84 |
|
---|
85 | void Mail(const int mailbox) { mMailbox = sMailId + mailbox; }
|
---|
86 | bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; }
|
---|
87 |
|
---|
88 | int IncMail() { return ++ mMailbox - sMailId; }
|
---|
89 |
|
---|
90 | ////////////////////////////////////////////////////
|
---|
91 | virtual AxisAlignedBox3 GetBox() const = 0;
|
---|
92 | virtual int CastRay(GtpVisibilityPreprocessor::Ray &ray) = 0;
|
---|
93 |
|
---|
94 | virtual bool IsConvex() const = 0;
|
---|
95 | virtual bool IsWatertight() const = 0;
|
---|
96 | virtual float IntersectionComplexity() = 0;
|
---|
97 |
|
---|
98 | virtual int NumberOfFaces() const = 0;
|
---|
99 | virtual int Type() const = 0;
|
---|
100 |
|
---|
101 | virtual int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0;
|
---|
102 |
|
---|
103 | virtual int GetRandomVisibleSurfacePoint(Vector3 &point,
|
---|
104 | Vector3 &normal,
|
---|
105 | const Vector3 &viewpoint,
|
---|
106 | const int maxTries) = 0;
|
---|
107 |
|
---|
108 | virtual ostream &Describe(ostream &s) = 0;
|
---|
109 |
|
---|
110 | virtual int GenerateSilhouetteRays(const int nrays,
|
---|
111 | const AxisAlignedBox3 &originBox,
|
---|
112 | const AxisAlignedBox3 &directionBox, VssRayContainer &rays)
|
---|
113 | {
|
---|
114 | return 0;
|
---|
115 | }
|
---|
116 |
|
---|
117 | static bool GreaterCounter(const Intersectable *a,
|
---|
118 | const Intersectable *b)
|
---|
119 | {
|
---|
120 | return a->mCounter > b->mCounter;
|
---|
121 | }
|
---|
122 |
|
---|
123 | static string GetTypeName(Intersectable *obj)
|
---|
124 | {
|
---|
125 | switch(obj->Type())
|
---|
126 | {
|
---|
127 | case MESH_INSTANCE:
|
---|
128 | return "mesh_instance\n";
|
---|
129 |
|
---|
130 | case TRANSFORMED_MESH_INSTANCE:
|
---|
131 | return "transformed_mesh_instance\n";
|
---|
132 |
|
---|
133 | case SPHERE:
|
---|
134 | return "sphere\n";
|
---|
135 |
|
---|
136 | case VIEW_CELL:
|
---|
137 | return "view cell\n";
|
---|
138 |
|
---|
139 | case OGRE_MESH_INSTANCE:
|
---|
140 | return "ogre_mesh_instance\n";
|
---|
141 |
|
---|
142 | case KD_INTERSECTABLE:
|
---|
143 | return "kd_intersectable\n";
|
---|
144 |
|
---|
145 | default:
|
---|
146 | return "unknown\n";
|
---|
147 | }
|
---|
148 | }
|
---|
149 | };
|
---|
150 |
|
---|
151 |
|
---|
152 | }
|
---|
153 |
|
---|
154 | #endif
|
---|