source: GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.h @ 1233

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