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