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

Revision 1579, 3.7 KB checked in by bittner, 18 years ago (diff)

merge

RevLine 
[162]1#ifndef __INTERSECTABLE_H
2#define __INTERSECTABLE_H
3
[176]4#include "AxisAlignedBox3.h"
5#include "Pvs.h"
[1074]6#include <set>
[1184]7#include "VssRay.h"
[162]8
[860]9namespace GtpVisibilityPreprocessor {
10
[497]11struct VssRayContainer;
[1072]12class KdLeaf;
[1233]13class BvhLeaf;
[176]14
[1281]15class Intersectable;
16struct Face;
[1233]17
[1344]18
[1281]19struct FaceParentInfo {
[1344]20        /// intersectable
21        Intersectable *mObject;
22        /// face index
23        int mFaceIndex;
24
25        FaceParentInfo(Intersectable *obj, const int fi):
26        mObject(obj), mFaceIndex(fi)
27        {}
[1281]28};
29
[1344]30
[162]31class Intersectable {
[176]32public:
[811]33  // last mail id -> warning not thread safe!
34  // both mailId and mailbox should be unique for each thread!!!
35  static int sMailId;
36  static int sReservedMailboxes;
[1579]37
38  /// Mailbox used for traversals
[811]39  int mMailbox;
40 
[1072]41  /// unique object Id
[811]42  int mId;
[1579]43
[1072]44  /// universal counter
[811]45  int mCounter;
[1077]46
[1233]47  /// pointer to the container bvh leaf
48  BvhLeaf *mBvhLeaf;
[1579]49
[1570]50  /// some rays piercing this intersectable
[1193]51  VssRayContainer mVssRays;
52
[1233]53  /// # of references to this instance
[1143]54  int mReferences;
[1135]55
[1570]56  //////////////////
57  // note matt: delete these, they are only taking memory+
58
[1579]59
[1570]60  /// object based pvs
61  KdPvs mKdPvs;
[1579]62
[1570]63  /// view cell based pvs per object
64  ViewCellPvs mViewCellPvs;
65       
66  ///////////////////////
67
[1135]68  enum { MESH_INSTANCE,
69                 TRANSFORMED_MESH_INSTANCE,
70                 SPHERE,
71                 VIEW_CELL,
72                 OGRE_MESH_INSTANCE,
[1233]73                 KD_INTERSECTABLE,
[1314]74                 BVH_INTERSECTABLE,
[1328]75                 TRIANGLE_INTERSECTABLE
[1135]76                };
[162]77 
[1293]78  Intersectable(): mMailbox(0), mReferences(0), mBvhLeaf(0) {}
[245]79
[1579]80  void SetId(const int id) { mId = id; }
81  int GetId() { return mId; }
82 
83  ////////////////////////////////////////////////
84  //    Mailing stuff
85 
86  static void NewMail(const int reserve = 1) {
87        sMailId += sReservedMailboxes;
88        sReservedMailboxes = reserve;
89  }
[339]90       
[1579]91  void Mail() { mMailbox = sMailId; }
92  bool Mailed() const { return mMailbox == sMailId; }
93 
94  void Mail(const int mailbox) { mMailbox = sMailId + mailbox; }
95  bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; }
96 
97  int IncMail() { return ++ mMailbox - sMailId; }
[382]98
[1579]99  ////////////////////////////////////////////////////
100  virtual AxisAlignedBox3 GetBox() const = 0;
101  virtual int CastRay(GtpVisibilityPreprocessor::Ray &ray) = 0;
[176]102 
[1579]103  virtual bool IsConvex() const = 0;
104  virtual bool IsWatertight() const = 0;
105  virtual float IntersectionComplexity() = 0;
106 
107  virtual int NumberOfFaces() const = 0;
108  virtual int Type() const = 0;
109 
110  virtual int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0;
111 
[850]112        virtual int GetRandomVisibleSurfacePoint(Vector3 &point,
113                                                                                         Vector3 &normal,
114                                                                                         const Vector3 &viewpoint,
115                                                                                         const int maxTries) = 0;
[492]116 
[850]117        virtual ostream &Describe(ostream &s) = 0;
118       
119        virtual int GenerateSilhouetteRays(const int nrays,
120                                                                           const AxisAlignedBox3 &originBox,
121                                                                           const AxisAlignedBox3 &directionBox, VssRayContainer &rays)
122        {
123                return 0;
124        }
[556]125
[850]126        static bool GreaterCounter(const Intersectable *a,
127                                                         const Intersectable *b)
128        {
129                return a->mCounter > b->mCounter;
130        }
[1166]131
132        static string GetTypeName(Intersectable *obj)
133        {
134                switch(obj->Type())
135                {
136                case MESH_INSTANCE:
137                        return "mesh_instance\n";
138               
139                case TRANSFORMED_MESH_INSTANCE:
140                        return "transformed_mesh_instance\n";
141                       
142                case SPHERE:
143                        return "sphere\n";
144
145                case VIEW_CELL:
146                        return "view cell\n";
147               
148                case OGRE_MESH_INSTANCE:
149                        return "ogre_mesh_instance\n";
150
151                case KD_INTERSECTABLE:
152                        return "kd_intersectable\n";
153
154                default:
155                        return "unknown\n";
156                }
157        }
[1344]158
159        /** returns normal from the face with the specified index.
160                PROBLEM: Does not fit to all intersectable types (e.g., spheres)
161        */
162        virtual Vector3 GetNormal(const int idx) const { return Vector3(0, 0, 0); }
[162]163};
164
[1135]165
[860]166}
[162]167
168#endif
Note: See TracBrowser for help on using the repository browser.