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

Revision 2543, 3.8 KB checked in by mattausch, 17 years ago (diff)
Line 
1#ifndef __INTERSECTABLE_H
2#define __INTERSECTABLE_H
3
4
5#include "AxisAlignedBox3.h"
6#include "Mailable.h"
7
8#define STORE_VIEWCELLS_WITH_BVH 1
9
10namespace GtpVisibilityPreprocessor {
11
12struct VssRayContainer;
13class KdLeaf;
14class BvhLeaf;
15class BvhNode;
16class Intersectable;
17class VssRay;
18struct Face;
19
20
21struct FaceParentInfo
22{
23        /// intersectable
24        Intersectable *mObject;
25        /// face index
26        int mFaceIndex;
27
28        FaceParentInfo(Intersectable *obj, const int fi):
29        mObject(obj), mFaceIndex(fi)
30        {}
31};
32
33
34class Intersectable
35{
36public:
37
38        ///////////////////////
39
40        enum {MESH_INSTANCE,
41                TRANSFORMED_MESH_INSTANCE,
42                SPHERE,
43                VIEW_CELL,
44                OGRE_MESH_INSTANCE,
45                KD_INTERSECTABLE,
46                BVH_INTERSECTABLE,
47                TRIANGLE_INTERSECTABLE,
48                DUMMY_INTERSECTABLE,
49                ENGINE_INTERSECTABLE,
50                CONTAINER_INTERSECTABLE
51        };
52
53        Intersectable();
54
55        virtual ~Intersectable();
56
57        inline void SetId(const int id) { mId = id; }
58        inline int GetId() { return mId; }
59
60        /////////////
61        // Mailing stuff
62
63        static void NewMail(const int reserve = 1)
64        {
65                sMailId += sReservedMailboxes;
66                sReservedMailboxes = reserve;
67        }
68
69        void Mail() { mMailbox = sMailId; }
70        bool Mailed() const { return mMailbox == sMailId; }
71
72        void Mail(const int mailbox) { mMailbox = sMailId + mailbox; }
73        bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; }
74
75        int IncMail() { return ++ mMailbox - sMailId; }
76
77        // last mail id -> warning not thread safe!
78        // both mailId and mailbox should be unique for each thread!!!
79        static int sMailId;
80        static int sReservedMailboxes;
81
82        /// Mailbox used for traversals
83        int mMailbox;
84
85
86        ////////////////
87        // virtual interface
88
89        virtual AxisAlignedBox3 GetBox() const = 0;
90        virtual int CastRay(Ray &ray) = 0;
91
92        virtual bool IsConvex() const = 0;
93        virtual bool IsWatertight() const = 0;
94        virtual float IntersectionComplexity() = 0;
95
96        virtual int NumberOfFaces() const = 0;
97        virtual int Type() const = 0;
98
99        virtual int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0;
100
101        virtual int GetRandomEdgePoint(Vector3 &point,
102                Vector3 &normal) = 0;
103
104        virtual int GetRandomVisibleSurfacePoint(Vector3 &point,
105                Vector3 &normal,
106                const Vector3 &viewpoint,
107                const int maxTries) = 0;
108
109        // virtual int GetRandomPoint(Vector3 &point,
110        // vector3 &normal) = 0;
111
112        virtual std::ostream &Describe(std::ostream &s) = 0;
113
114        //////////////////////////////////////
115
116
117        virtual int GenerateSilhouetteRays(const int nrays,
118                const AxisAlignedBox3 &originBox,
119                const AxisAlignedBox3 &directionBox,
120                VssRayContainer &rays);
121
122        virtual int GetRandomSurfacePoint(const float u,
123                const float v,
124                Vector3 &point,
125                Vector3 &normal);
126
127        virtual float GetArea() const;
128
129        static bool GreaterCounter(const Intersectable *a,
130                const Intersectable *b);
131
132        /** Returns the name of the type of this intersectable
133        */
134        static std::string GetTypeName(Intersectable *obj);
135        /** Returns normal from the face with the specified index.
136        PROBLEM: Does not fit to all intersectable types (e.g., spheres)
137        */
138        virtual Vector3 GetNormal(const int idx) const;
139        /** Returns rays stored with this intersectable.
140        */
141        VssRayContainer *GetOrCreateRays();
142
143        /** Deletes the rays associated with this intersectable.
144        */
145        void DelRayRefs();
146
147        /// hack
148        int mRenderedFrame;
149
150        ///////////
151
152        /// unique object Id
153        int mId;
154        /// universal counter
155        int mCounter;
156        /// pointer to the containing bvh leaf
157        BvhLeaf *mBvhLeaf;
158
159
160protected:
161
162        /// some rays piercing this intersectable
163        VssRayContainer *mVssRays;
164
165
166#if STORE_VIEWCELLS_WITH_BVH
167public:
168        /** Returns rays stored with this intersectable.
169        */
170        ViewCellContainer *GetOrCreateViewCells();
171
172        void DelViewCells();
173
174protected:
175        ViewCellContainer *mViewCells;
176#endif
177};
178
179
180}
181
182#endif
Note: See TracBrowser for help on using the repository browser.