1 | #ifndef __INTERSECTABLE_H
|
---|
2 | #define __INTERSECTABLE_H
|
---|
3 |
|
---|
4 | #include "AxisAlignedBox3.h"
|
---|
5 | #include "Pvs.h"
|
---|
6 | #include <set>
|
---|
7 |
|
---|
8 | namespace GtpVisibilityPreprocessor {
|
---|
9 |
|
---|
10 | struct VssRayContainer;
|
---|
11 | class KdLeaf;
|
---|
12 |
|
---|
13 | class Intersectable {
|
---|
14 | public:
|
---|
15 | // last mail id -> warning not thread safe!
|
---|
16 | // both mailId and mailbox should be unique for each thread!!!
|
---|
17 | static int sMailId;
|
---|
18 | static int sReservedMailboxes;
|
---|
19 | int mMailbox;
|
---|
20 |
|
---|
21 | /// unique object Id
|
---|
22 | int mId;
|
---|
23 |
|
---|
24 | /// universal counter
|
---|
25 | int mCounter;
|
---|
26 |
|
---|
27 | /// object based pvs
|
---|
28 | KdPvs mKdPvs;
|
---|
29 |
|
---|
30 | ViewCellPvs mViewCellPvs;
|
---|
31 |
|
---|
32 | /// kd leaves that this intersectable belongs to
|
---|
33 | //set<KdLeaf *> mKdLeaves;
|
---|
34 |
|
---|
35 | /// # of object references
|
---|
36 | int mReferences;
|
---|
37 |
|
---|
38 | enum { MESH_INSTANCE,
|
---|
39 | TRANSFORMED_MESH_INSTANCE,
|
---|
40 | SPHERE,
|
---|
41 | VIEW_CELL,
|
---|
42 | OGRE_MESH_INSTANCE,
|
---|
43 | KD_INTERSECTABLE
|
---|
44 | };
|
---|
45 |
|
---|
46 | Intersectable():mMailbox(0), mReferences(0) {}
|
---|
47 |
|
---|
48 | void SetId(const int id) { mId = id; }
|
---|
49 | int GetId() { return mId; }
|
---|
50 |
|
---|
51 |
|
---|
52 | static void NewMail(const int reserve = 1) {
|
---|
53 | sMailId += sReservedMailboxes;
|
---|
54 | sReservedMailboxes = reserve;
|
---|
55 | }
|
---|
56 |
|
---|
57 | void Mail() { mMailbox = sMailId; }
|
---|
58 | bool Mailed() const { return mMailbox == sMailId; }
|
---|
59 |
|
---|
60 | void Mail(const int mailbox) { mMailbox = sMailId + mailbox; }
|
---|
61 | bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; }
|
---|
62 |
|
---|
63 | int IncMail() { return ++mMailbox - sMailId; }
|
---|
64 |
|
---|
65 |
|
---|
66 | virtual AxisAlignedBox3 GetBox() const = 0;
|
---|
67 | virtual int CastRay(GtpVisibilityPreprocessor::Ray &ray) = 0;
|
---|
68 |
|
---|
69 | virtual bool IsConvex() const = 0;
|
---|
70 | virtual bool IsWatertight() const = 0;
|
---|
71 | virtual float IntersectionComplexity() = 0;
|
---|
72 |
|
---|
73 | virtual int NumberOfFaces() const = 0;
|
---|
74 | virtual int Type() const = 0;
|
---|
75 |
|
---|
76 | virtual int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0;
|
---|
77 |
|
---|
78 | virtual int GetRandomVisibleSurfacePoint(Vector3 &point,
|
---|
79 | Vector3 &normal,
|
---|
80 | const Vector3 &viewpoint,
|
---|
81 | const int maxTries) = 0;
|
---|
82 |
|
---|
83 | virtual ostream &Describe(ostream &s) = 0;
|
---|
84 |
|
---|
85 | virtual int GenerateSilhouetteRays(const int nrays,
|
---|
86 | const AxisAlignedBox3 &originBox,
|
---|
87 | const AxisAlignedBox3 &directionBox, VssRayContainer &rays)
|
---|
88 | {
|
---|
89 | return 0;
|
---|
90 | }
|
---|
91 |
|
---|
92 | static bool GreaterCounter(const Intersectable *a,
|
---|
93 | const Intersectable *b)
|
---|
94 | {
|
---|
95 | return a->mCounter > b->mCounter;
|
---|
96 | }
|
---|
97 |
|
---|
98 | static string GetTypeName(Intersectable *obj)
|
---|
99 | {
|
---|
100 | switch(obj->Type())
|
---|
101 | {
|
---|
102 | case MESH_INSTANCE:
|
---|
103 | return "mesh_instance\n";
|
---|
104 |
|
---|
105 | case TRANSFORMED_MESH_INSTANCE:
|
---|
106 | return "transformed_mesh_instance\n";
|
---|
107 |
|
---|
108 | case SPHERE:
|
---|
109 | return "sphere\n";
|
---|
110 |
|
---|
111 | case VIEW_CELL:
|
---|
112 | return "view cell\n";
|
---|
113 |
|
---|
114 | case OGRE_MESH_INSTANCE:
|
---|
115 | return "ogre_mesh_instance\n";
|
---|
116 |
|
---|
117 | case KD_INTERSECTABLE:
|
---|
118 | return "kd_intersectable\n";
|
---|
119 |
|
---|
120 | default:
|
---|
121 | return "unknown\n";
|
---|
122 | }
|
---|
123 | }
|
---|
124 | };
|
---|
125 |
|
---|
126 |
|
---|
127 | }
|
---|
128 |
|
---|
129 | #endif
|
---|