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

RevLine 
[162]1#ifndef __INTERSECTABLE_H
2#define __INTERSECTABLE_H
3
[2198]4
[176]5#include "AxisAlignedBox3.h"
[1867]6#include "Mailable.h"
[162]7
[2199]8#define STORE_VIEWCELLS_WITH_BVH 1
[2198]9
[860]10namespace GtpVisibilityPreprocessor {
11
[497]12struct VssRayContainer;
[1072]13class KdLeaf;
[1233]14class BvhLeaf;
[1680]15class BvhNode;
[1281]16class Intersectable;
[2116]17class VssRay;
[1281]18struct Face;
[1233]19
[1344]20
[2066]21struct FaceParentInfo
22{
[2575]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  {}
[1281]31};
32
[1344]33
[2066]34class Intersectable
35{
[176]36public:
[1579]37
[2543]38        ///////////////////////
[1077]39
[2543]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        };
[1570]52
[2543]53        Intersectable();
[245]54
[2543]55        virtual ~Intersectable();
[1615]56
[2543]57        inline void SetId(const int id) { mId = id; }
58        inline int GetId() { return mId; }
[382]59
[2543]60        /////////////
61        // Mailing stuff
[1999]62
[2543]63        static void NewMail(const int reserve = 1)
64        {
65                sMailId += sReservedMailboxes;
66                sReservedMailboxes = reserve;
67        }
[1999]68
[2543]69        void Mail() { mMailbox = sMailId; }
70        bool Mailed() const { return mMailbox == sMailId; }
[2066]71
[2543]72        void Mail(const int mailbox) { mMailbox = sMailId + mailbox; }
73        bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; }
[1763]74
[2543]75        int IncMail() { return ++ mMailbox - sMailId; }
[1166]76
[2543]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;
[1990]81
[2543]82        /// Mailbox used for traversals
83        int mMailbox;
[1166]84
85
[2543]86        ////////////////
87        // virtual interface
[1166]88
[2543]89        virtual AxisAlignedBox3 GetBox() const = 0;
90        virtual int CastRay(Ray &ray) = 0;
[2575]91        virtual int CastSimpleRay(const SimpleRay &ray) = 0;
92        virtual int CastSimpleRay(const SimpleRay &ray, int indexRay) = 0;
[1344]93
[2543]94        virtual bool IsConvex() const = 0;
95        virtual bool IsWatertight() const = 0;
96        virtual float IntersectionComplexity() = 0;
[1687]97
[2543]98        virtual int NumberOfFaces() const = 0;
99        virtual int Type() const = 0;
[1687]100
[2543]101        virtual int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0;
[1696]102
[2543]103        virtual int GetRandomEdgePoint(Vector3 &point,
104                Vector3 &normal) = 0;
[1696]105
[2543]106        virtual int GetRandomVisibleSurfacePoint(Vector3 &point,
107                Vector3 &normal,
108                const Vector3 &viewpoint,
109                const int maxTries) = 0;
[2066]110
[2543]111        // virtual int GetRandomPoint(Vector3 &point,
112        // vector3 &normal) = 0;
[2198]113
[2543]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
[1696]161protected:
[2543]162
[2066]163        /// some rays piercing this intersectable
164        VssRayContainer *mVssRays;
[2198]165
[2543]166
[2198]167#if STORE_VIEWCELLS_WITH_BVH
168public:
[2543]169        /** Returns rays stored with this intersectable.
170        */
171        ViewCellContainer *GetOrCreateViewCells();
[2198]172
[2543]173        void DelViewCells();
[2198]174
175protected:
[2543]176        ViewCellContainer *mViewCells;
[2198]177#endif
[162]178};
179
[1135]180
[860]181}
[162]182
183#endif
Note: See TracBrowser for help on using the repository browser.