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

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,
[2615]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
[2543]52        };
[1570]53
[2543]54        Intersectable();
[245]55
[2543]56        virtual ~Intersectable();
[1615]57
[2543]58        inline void SetId(const int id) { mId = id; }
59        inline int GetId() { return mId; }
[382]60
[2543]61        /////////////
62        // Mailing stuff
[1999]63
[2543]64        static void NewMail(const int reserve = 1)
65        {
66                sMailId += sReservedMailboxes;
67                sReservedMailboxes = reserve;
68        }
[1999]69
[2543]70        void Mail() { mMailbox = sMailId; }
71        bool Mailed() const { return mMailbox == sMailId; }
[2066]72
[2543]73        void Mail(const int mailbox) { mMailbox = sMailId + mailbox; }
74        bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; }
[1763]75
[2543]76        int IncMail() { return ++ mMailbox - sMailId; }
[1166]77
[2543]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;
[1990]82
[2543]83        /// Mailbox used for traversals
84        int mMailbox;
[1166]85
86
[2543]87        ////////////////
88        // virtual interface
[1166]89
[2543]90        virtual AxisAlignedBox3 GetBox() const = 0;
91        virtual int CastRay(Ray &ray) = 0;
[2575]92        virtual int CastSimpleRay(const SimpleRay &ray) = 0;
93        virtual int CastSimpleRay(const SimpleRay &ray, int indexRay) = 0;
[1344]94
[2543]95        virtual bool IsConvex() const = 0;
96        virtual bool IsWatertight() const = 0;
97        virtual float IntersectionComplexity() = 0;
[1687]98
[2543]99        virtual int NumberOfFaces() const = 0;
100        virtual int Type() const = 0;
[1687]101
[2543]102        virtual int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0;
[1696]103
[2543]104        virtual int GetRandomEdgePoint(Vector3 &point,
105                Vector3 &normal) = 0;
[1696]106
[2543]107        virtual int GetRandomVisibleSurfacePoint(Vector3 &point,
108                Vector3 &normal,
109                const Vector3 &viewpoint,
110                const int maxTries) = 0;
[2066]111
[2543]112        // virtual int GetRandomPoint(Vector3 &point,
113        // vector3 &normal) = 0;
[2198]114
[2543]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
[1696]162protected:
[2543]163
[2066]164        /// some rays piercing this intersectable
165        VssRayContainer *mVssRays;
[2198]166
[2543]167
[2198]168#if STORE_VIEWCELLS_WITH_BVH
169public:
[2543]170        /** Returns rays stored with this intersectable.
171        */
172        ViewCellContainer *GetOrCreateViewCells();
[2198]173
[2543]174        void DelViewCells();
[2198]175
176protected:
[2543]177        ViewCellContainer *mViewCells;
[2198]178#endif
[162]179};
180
[1135]181
[860]182}
[162]183
184#endif
Note: See TracBrowser for help on using the repository browser.