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

Revision 2643, 4.6 KB checked in by mattausch, 17 years ago (diff)

compiling under release internal

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                  SCENEGRAPHLEAF_INTERSECTABLE
52        };
53
54        Intersectable();
55
56        virtual ~Intersectable();
57
58        inline void SetId(const int id) { mId = id; }
59        inline int GetId() { return mId; }
60
61        /////////////
62        // Mailing stuff
63
64        static void NewMail(const int reserve = 1)
65        {
66                sMailId += sReservedMailboxes;
67                sReservedMailboxes = reserve;
68        }
69
70        void Mail() { mMailbox = sMailId; }
71        bool Mailed() const { return mMailbox == sMailId; }
72
73        void Mail(const int mailbox) { mMailbox = sMailId + mailbox; }
74        bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; }
75
76        int IncMail() { return ++ mMailbox - sMailId; }
77
78        // last mail id -> warning not thread safe!
79        // both mailId and mailbox should be unique for each thread!!!
80        static int sMailId;
81        static int sReservedMailboxes;
82
83        /// Mailbox used for traversals
84        int mMailbox;
85
86        static void NewMail2(const int reserve = 1)
87        {
88                sMailId2 += sReservedMailboxes2;
89                sReservedMailboxes2 = reserve;
90        }
91
92        ////////////
93        void Mail2() { mMailbox2 = sMailId2; }
94        bool Mailed2() const { return mMailbox2 == sMailId2; }
95
96        void Mail2(const int mailbox) { mMailbox2 = sMailId2 + mailbox; }
97        bool Mailed2(const int mailbox) const { return mMailbox2 == sMailId2 + mailbox; }
98
99        int IncMail2() { return ++ mMailbox2 - sMailId2; }
100
101        // last mail id -> warning not thread safe!
102        // both mailId and mailbox should be unique for each thread!!!
103        static int sMailId2;
104        static int sReservedMailboxes2;
105
106        /// Mailbox used for traversals
107        int mMailbox2;
108
109        ////////////
110
111        ////////////////
112        // virtual interface
113
114        virtual AxisAlignedBox3 GetBox() const = 0;
115        virtual int CastRay(Ray &ray) = 0;
116        virtual int CastSimpleRay(const SimpleRay &ray) = 0;
117        virtual int CastSimpleRay(const SimpleRay &ray, int indexRay) = 0;
118
119        virtual bool IsConvex() const = 0;
120        virtual bool IsWatertight() const = 0;
121        virtual float IntersectionComplexity() = 0;
122
123        virtual int NumberOfFaces() const = 0;
124        virtual int Type() const = 0;
125
126        virtual int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0;
127
128        virtual int GetRandomEdgePoint(Vector3 &point,
129                Vector3 &normal) = 0;
130
131        virtual int GetRandomVisibleSurfacePoint(Vector3 &point,
132                Vector3 &normal,
133                const Vector3 &viewpoint,
134                const int maxTries) = 0;
135
136        // virtual int GetRandomPoint(Vector3 &point,
137        // vector3 &normal) = 0;
138
139        virtual std::ostream &Describe(std::ostream &s) = 0;
140
141        //////////////////////////////////////
142
143
144        virtual int GenerateSilhouetteRays(const int nrays,
145                const AxisAlignedBox3 &originBox,
146                const AxisAlignedBox3 &directionBox,
147                VssRayContainer &rays);
148
149        virtual int GetRandomSurfacePoint(const float u,
150                const float v,
151                Vector3 &point,
152                Vector3 &normal);
153
154        virtual float GetArea() const;
155
156        static bool GreaterCounter(const Intersectable *a,
157                const Intersectable *b);
158
159        /** Returns the name of the type of this intersectable
160        */
161        static std::string GetTypeName(Intersectable *obj);
162        /** Returns normal from the face with the specified index.
163        PROBLEM: Does not fit to all intersectable types (e.g., spheres)
164        */
165        virtual Vector3 GetNormal(const int idx) const;
166        /** Returns rays stored with this intersectable.
167        */
168        VssRayContainer *GetOrCreateRays();
169
170        /** Deletes the rays associated with this intersectable.
171        */
172        void DelRayRefs();
173
174        /// hack
175        int mRenderedFrame;
176
177        ///////////
178
179        /// unique object Id
180        int mId;
181        /// universal counter
182        int mCounter;
183        /// pointer to the containing bvh leaf
184        BvhLeaf *mBvhLeaf;
185
186protected:
187
188        /// some rays piercing this intersectable
189        VssRayContainer *mVssRays;
190
191
192#if STORE_VIEWCELLS_WITH_BVH
193public:
194        /** Returns rays stored with this intersectable.
195        */
196        ViewCellContainer *GetOrCreateViewCells();
197
198        void DelViewCells();
199
200protected:
201        ViewCellContainer *mViewCells;
202#endif
203};
204
205
206}
207
208#endif
Note: See TracBrowser for help on using the repository browser.