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

Revision 2615, 4.0 KB checked in by mattausch, 16 years ago (diff)

did some stuff for the visualization

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