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

Revision 1570, 3.7 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;
[1233]13class BvhLeaf;
[176]14
[1281]15class Intersectable;
16struct Face;
[1233]17
[1344]18
[1281]19struct FaceParentInfo {
[1344]20        /// intersectable
21        Intersectable *mObject;
22        /// face index
23        int mFaceIndex;
24
25        FaceParentInfo(Intersectable *obj, const int fi):
26        mObject(obj), mFaceIndex(fi)
27        {}
[1281]28};
29
[1344]30
[162]31class Intersectable {
[176]32public:
[811]33  // last mail id -> warning not thread safe!
34  // both mailId and mailbox should be unique for each thread!!!
35  static int sMailId;
36  static int sReservedMailboxes;
37  int mMailbox;
38 
[1072]39  /// unique object Id
[811]40  int mId;
[1072]41  /// universal counter
[811]42  int mCounter;
[1077]43
[1233]44  /// pointer to the container bvh leaf
45  BvhLeaf *mBvhLeaf;
[1570]46  /// some rays piercing this intersectable
[1193]47  VssRayContainer mVssRays;
48
[1233]49  /// # of references to this instance
[1143]50  int mReferences;
[1135]51
[1570]52  //////////////////
53  // note matt: delete these, they are only taking memory+
54
55  /// object based pvs
56  KdPvs mKdPvs;
57  /// view cell based pvs per object
58  ViewCellPvs mViewCellPvs;
59       
60  ///////////////////////
61
[1135]62  enum { MESH_INSTANCE,
63                 TRANSFORMED_MESH_INSTANCE,
64                 SPHERE,
65                 VIEW_CELL,
66                 OGRE_MESH_INSTANCE,
[1233]67                 KD_INTERSECTABLE,
[1314]68                 BVH_INTERSECTABLE,
[1328]69                 TRIANGLE_INTERSECTABLE
[1135]70                };
[162]71 
[1293]72  Intersectable(): mMailbox(0), mReferences(0), mBvhLeaf(0) {}
[245]73
[339]74        void SetId(const int id) { mId = id; }
75        int GetId() { return mId; }
76       
[1184]77////////////////////////////////////////////////
78//      Mailing stuff
[382]79
80        static void NewMail(const int reserve = 1) {
81                sMailId += sReservedMailboxes;
82                sReservedMailboxes = reserve;
83        }
84       
[339]85        void Mail() { mMailbox = sMailId; }
[837]86        bool Mailed() const { return mMailbox == sMailId; }
[339]87
[382]88        void Mail(const int mailbox) { mMailbox = sMailId + mailbox; }
89        bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; }
90
[1176]91        int IncMail() { return ++ mMailbox - sMailId; }
[382]92
[1184]93////////////////////////////////////////////////////
[1020]94    virtual AxisAlignedBox3 GetBox() const = 0;
[870]95        virtual int CastRay(GtpVisibilityPreprocessor::Ray &ray) = 0;
[382]96       
[1020]97        virtual bool IsConvex() const = 0;
98        virtual bool IsWatertight() const = 0;
[850]99        virtual float IntersectionComplexity() = 0;
[176]100 
[850]101        virtual int NumberOfFaces() const = 0;
102        virtual int Type() const = 0;
[176]103
[850]104        virtual int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0;
105
106        virtual int GetRandomVisibleSurfacePoint(Vector3 &point,
107                                                                                         Vector3 &normal,
108                                                                                         const Vector3 &viewpoint,
109                                                                                         const int maxTries) = 0;
[492]110 
[850]111        virtual ostream &Describe(ostream &s) = 0;
112       
113        virtual int GenerateSilhouetteRays(const int nrays,
114                                                                           const AxisAlignedBox3 &originBox,
115                                                                           const AxisAlignedBox3 &directionBox, VssRayContainer &rays)
116        {
117                return 0;
118        }
[556]119
[850]120        static bool GreaterCounter(const Intersectable *a,
121                                                         const Intersectable *b)
122        {
123                return a->mCounter > b->mCounter;
124        }
[1166]125
126        static string GetTypeName(Intersectable *obj)
127        {
128                switch(obj->Type())
129                {
130                case MESH_INSTANCE:
131                        return "mesh_instance\n";
132               
133                case TRANSFORMED_MESH_INSTANCE:
134                        return "transformed_mesh_instance\n";
135                       
136                case SPHERE:
137                        return "sphere\n";
138
139                case VIEW_CELL:
140                        return "view cell\n";
141               
142                case OGRE_MESH_INSTANCE:
143                        return "ogre_mesh_instance\n";
144
145                case KD_INTERSECTABLE:
146                        return "kd_intersectable\n";
147
148                default:
149                        return "unknown\n";
150                }
151        }
[1344]152
153        /** returns normal from the face with the specified index.
154                PROBLEM: Does not fit to all intersectable types (e.g., spheres)
155        */
156        virtual Vector3 GetNormal(const int idx) const { return Vector3(0, 0, 0); }
[162]157};
158
[1135]159
[860]160}
[162]161
162#endif
Note: See TracBrowser for help on using the repository browser.