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

Revision 1184, 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;
13
14class Intersectable {
15public:
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;
36VssRayContainer mVssRays;
37  /// # of object references
38  int mReferences;
39
40  enum { MESH_INSTANCE,
41                 TRANSFORMED_MESH_INSTANCE,
42                 SPHERE,
43                 VIEW_CELL,
44                 OGRE_MESH_INSTANCE,
45                 KD_INTERSECTABLE
46                };
47 
48  Intersectable(): mMailbox(0), mReferences(0) {}
49
50        void SetId(const int id) { mId = id; }
51        int GetId() { return mId; }
52       
53////////////////////////////////////////////////
54//      Mailing stuff
55
56        static void NewMail(const int reserve = 1) {
57                sMailId += sReservedMailboxes;
58                sReservedMailboxes = reserve;
59        }
60       
61        void Mail() { mMailbox = sMailId; }
62        bool Mailed() const { return mMailbox == sMailId; }
63
64        void Mail(const int mailbox) { mMailbox = sMailId + mailbox; }
65        bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; }
66
67        int IncMail() { return ++ mMailbox - sMailId; }
68
69////////////////////////////////////////////////////
70    virtual AxisAlignedBox3 GetBox() const = 0;
71        virtual int CastRay(GtpVisibilityPreprocessor::Ray &ray) = 0;
72       
73        virtual bool IsConvex() const = 0;
74        virtual bool IsWatertight() const = 0;
75        virtual float IntersectionComplexity() = 0;
76 
77        virtual int NumberOfFaces() const = 0;
78        virtual int Type() const = 0;
79
80        virtual int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0;
81
82        virtual int GetRandomVisibleSurfacePoint(Vector3 &point,
83                                                                                         Vector3 &normal,
84                                                                                         const Vector3 &viewpoint,
85                                                                                         const int maxTries) = 0;
86 
87        virtual ostream &Describe(ostream &s) = 0;
88       
89        virtual int GenerateSilhouetteRays(const int nrays,
90                                                                           const AxisAlignedBox3 &originBox,
91                                                                           const AxisAlignedBox3 &directionBox, VssRayContainer &rays)
92        {
93                return 0;
94        }
95
96        static bool GreaterCounter(const Intersectable *a,
97                                                         const Intersectable *b)
98        {
99                return a->mCounter > b->mCounter;
100        }
101
102        static string GetTypeName(Intersectable *obj)
103        {
104                switch(obj->Type())
105                {
106                case MESH_INSTANCE:
107                        return "mesh_instance\n";
108               
109                case TRANSFORMED_MESH_INSTANCE:
110                        return "transformed_mesh_instance\n";
111                       
112                case SPHERE:
113                        return "sphere\n";
114
115                case VIEW_CELL:
116                        return "view cell\n";
117               
118                case OGRE_MESH_INSTANCE:
119                        return "ogre_mesh_instance\n";
120
121                case KD_INTERSECTABLE:
122                        return "kd_intersectable\n";
123
124                default:
125                        return "unknown\n";
126                }
127        }
128};
129
130
131}
132
133#endif
Note: See TracBrowser for help on using the repository browser.