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

Revision 1344, 3.5 KB checked in by mattausch, 18 years ago (diff)

worked on triangle processing. logical units will be created by grouping objects
using their visibility definitions.

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