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

Revision 1184, 3.0 KB checked in by mattausch, 18 years ago (diff)
RevLine 
[162]1#ifndef __INTERSECTABLE_H
2#define __INTERSECTABLE_H
3
[176]4#include "AxisAlignedBox3.h"
5#include "Pvs.h"
[1074]6#include <set>
[1184]7#include "VssRay.h"
[162]8
[860]9namespace GtpVisibilityPreprocessor {
10
[497]11struct VssRayContainer;
[1072]12class KdLeaf;
[176]13
[162]14class Intersectable {
[176]15public:
[811]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 
[1072]22  /// unique object Id
[811]23  int mId;
24 
[1072]25  /// universal counter
[811]26  int mCounter;
[339]27       
[1072]28  /// object based pvs
[811]29  KdPvs mKdPvs;
[162]30 
[1174]31  /// view cell based pvs per object
[1077]32  ViewCellPvs mViewCellPvs;
33
[1072]34  /// kd leaves that this intersectable belongs to
[1133]35  //set<KdLeaf *> mKdLeaves;
[1184]36VssRayContainer mVssRays;
[1135]37  /// # of object references
[1143]38  int mReferences;
[1135]39
40  enum { MESH_INSTANCE,
41                 TRANSFORMED_MESH_INSTANCE,
42                 SPHERE,
43                 VIEW_CELL,
44                 OGRE_MESH_INSTANCE,
45                 KD_INTERSECTABLE
46                };
[162]47 
[1176]48  Intersectable(): mMailbox(0), mReferences(0) {}
[245]49
[339]50        void SetId(const int id) { mId = id; }
51        int GetId() { return mId; }
52       
[1184]53////////////////////////////////////////////////
54//      Mailing stuff
[382]55
56        static void NewMail(const int reserve = 1) {
57                sMailId += sReservedMailboxes;
58                sReservedMailboxes = reserve;
59        }
60       
[339]61        void Mail() { mMailbox = sMailId; }
[837]62        bool Mailed() const { return mMailbox == sMailId; }
[339]63
[382]64        void Mail(const int mailbox) { mMailbox = sMailId + mailbox; }
65        bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; }
66
[1176]67        int IncMail() { return ++ mMailbox - sMailId; }
[382]68
[1184]69////////////////////////////////////////////////////
[1020]70    virtual AxisAlignedBox3 GetBox() const = 0;
[870]71        virtual int CastRay(GtpVisibilityPreprocessor::Ray &ray) = 0;
[382]72       
[1020]73        virtual bool IsConvex() const = 0;
74        virtual bool IsWatertight() const = 0;
[850]75        virtual float IntersectionComplexity() = 0;
[176]76 
[850]77        virtual int NumberOfFaces() const = 0;
78        virtual int Type() const = 0;
[176]79
[850]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;
[492]86 
[850]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        }
[556]95
[850]96        static bool GreaterCounter(const Intersectable *a,
97                                                         const Intersectable *b)
98        {
99                return a->mCounter > b->mCounter;
100        }
[1166]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        }
[162]128};
129
[1135]130
[860]131}
[162]132
133#endif
Note: See TracBrowser for help on using the repository browser.