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

Revision 2575, 3.9 KB checked in by bittner, 17 years ago (diff)

big merge: preparation for havran ray caster, check if everything works

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        virtual int CastSimpleRay(const SimpleRay &ray) = 0;
92        virtual int CastSimpleRay(const SimpleRay &ray, int indexRay) = 0;
93
94        virtual bool IsConvex() const = 0;
95        virtual bool IsWatertight() const = 0;
96        virtual float IntersectionComplexity() = 0;
97
98        virtual int NumberOfFaces() const = 0;
99        virtual int Type() const = 0;
100
101        virtual int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0;
102
103        virtual int GetRandomEdgePoint(Vector3 &point,
104                Vector3 &normal) = 0;
105
106        virtual int GetRandomVisibleSurfacePoint(Vector3 &point,
107                Vector3 &normal,
108                const Vector3 &viewpoint,
109                const int maxTries) = 0;
110
111        // virtual int GetRandomPoint(Vector3 &point,
112        // vector3 &normal) = 0;
113
114        virtual std::ostream &Describe(std::ostream &s) = 0;
115
116        //////////////////////////////////////
117
118
119        virtual int GenerateSilhouetteRays(const int nrays,
120                const AxisAlignedBox3 &originBox,
121                const AxisAlignedBox3 &directionBox,
122                VssRayContainer &rays);
123
124        virtual int GetRandomSurfacePoint(const float u,
125                const float v,
126                Vector3 &point,
127                Vector3 &normal);
128
129        virtual float GetArea() const;
130
131        static bool GreaterCounter(const Intersectable *a,
132                const Intersectable *b);
133
134        /** Returns the name of the type of this intersectable
135        */
136        static std::string GetTypeName(Intersectable *obj);
137        /** Returns normal from the face with the specified index.
138        PROBLEM: Does not fit to all intersectable types (e.g., spheres)
139        */
140        virtual Vector3 GetNormal(const int idx) const;
141        /** Returns rays stored with this intersectable.
142        */
143        VssRayContainer *GetOrCreateRays();
144
145        /** Deletes the rays associated with this intersectable.
146        */
147        void DelRayRefs();
148
149        /// hack
150        int mRenderedFrame;
151
152        ///////////
153
154        /// unique object Id
155        int mId;
156        /// universal counter
157        int mCounter;
158        /// pointer to the containing bvh leaf
159        BvhLeaf *mBvhLeaf;
160
161protected:
162
163        /// some rays piercing this intersectable
164        VssRayContainer *mVssRays;
165
166
167#if STORE_VIEWCELLS_WITH_BVH
168public:
169        /** Returns rays stored with this intersectable.
170        */
171        ViewCellContainer *GetOrCreateViewCells();
172
173        void DelViewCells();
174
175protected:
176        ViewCellContainer *mViewCells;
177#endif
178};
179
180
181}
182
183#endif
Note: See TracBrowser for help on using the repository browser.