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

Revision 2543, 3.8 KB checked in by mattausch, 17 years ago (diff)
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{
[1344]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;
[1344]91
[2543]92        virtual bool IsConvex() const = 0;
93        virtual bool IsWatertight() const = 0;
94        virtual float IntersectionComplexity() = 0;
[1687]95
[2543]96        virtual int NumberOfFaces() const = 0;
97        virtual int Type() const = 0;
[1687]98
[2543]99        virtual int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0;
[1696]100
[2543]101        virtual int GetRandomEdgePoint(Vector3 &point,
102                Vector3 &normal) = 0;
[1696]103
[2543]104        virtual int GetRandomVisibleSurfacePoint(Vector3 &point,
105                Vector3 &normal,
106                const Vector3 &viewpoint,
107                const int maxTries) = 0;
[2066]108
[2543]109        // virtual int GetRandomPoint(Vector3 &point,
110        // vector3 &normal) = 0;
[2198]111
[2543]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
[1696]160protected:
[2543]161
[2066]162        /// some rays piercing this intersectable
163        VssRayContainer *mVssRays;
[2198]164
[2543]165
[2198]166#if STORE_VIEWCELLS_WITH_BVH
167public:
[2543]168        /** Returns rays stored with this intersectable.
169        */
170        ViewCellContainer *GetOrCreateViewCells();
[2198]171
[2543]172        void DelViewCells();
[2198]173
174protected:
[2543]175        ViewCellContainer *mViewCells;
[2198]176#endif
[162]177};
178
[1135]179
[860]180}
[162]181
182#endif
Note: See TracBrowser for help on using the repository browser.