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

Revision 1701, 4.1 KB checked in by mattausch, 18 years ago (diff)
Line 
1#ifndef __INTERSECTABLE_H
2#define __INTERSECTABLE_H
3
4#include "AxisAlignedBox3.h"
5#include "Pvs.h"
6#include <set>
7#include "VssRay.h"
8
9namespace GtpVisibilityPreprocessor {
10
11struct VssRayContainer;
12class KdLeaf;
13class BvhLeaf;
14class BvhNode;
15class Intersectable;
16struct Face;
17
18
19struct FaceParentInfo {
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        {}
28};
29
30
31class Intersectable {
32public:
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;
37
38  /// Mailbox used for traversals
39  int mMailbox;
40 
41  /// unique object Id
42  int mId;
43
44  /// universal counter
45  int mCounter;
46
47  /// pointer to the containing bvh leaf
48  BvhLeaf *mBvhLeaf;
49//BvhNode *mBvhLeaf;
50 
51  /// # of references to this instance
52  int mReferences;
53
54  //////////////////
55  // note matt: delete these, they are only taking memory
56
57
58  /// object based pvs
59  KdPvs mKdPvs;
60
61  /// view cell based pvs per object
62  ViewCellPvs mViewCellPvs;
63       
64  ///////////////////////
65
66  enum { MESH_INSTANCE,
67                 TRANSFORMED_MESH_INSTANCE,
68                 SPHERE,
69                 VIEW_CELL,
70                 OGRE_MESH_INSTANCE,
71                 KD_INTERSECTABLE,
72                 BVH_INTERSECTABLE,
73                 TRIANGLE_INTERSECTABLE,
74                 OBJECTS_INTERSECTABLE
75                };
76 
77  Intersectable(): mMailbox(0), mReferences(0), mBvhLeaf(0), mVssRays(NULL) {}
78
79  virtual Intersectable::~Intersectable() {DEL_PTR(mVssRays);}
80
81  void SetId(const int id) { mId = id; }
82  int GetId() { return mId; }
83 
84  ////////////////////////////////////////////////
85  //    Mailing stuff
86 
87  static void NewMail(const int reserve = 1) {
88        sMailId += sReservedMailboxes;
89        sReservedMailboxes = reserve;
90  }
91       
92  void Mail() { mMailbox = sMailId; }
93  bool Mailed() const { return mMailbox == sMailId; }
94 
95  void Mail(const int mailbox) { mMailbox = sMailId + mailbox; }
96  bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; }
97 
98  int IncMail() { return ++ mMailbox - sMailId; }
99
100  ////////////////////////////////////////////////////
101  virtual AxisAlignedBox3 GetBox() const = 0;
102  virtual int CastRay(GtpVisibilityPreprocessor::Ray &ray) = 0;
103 
104  virtual bool IsConvex() const = 0;
105  virtual bool IsWatertight() const = 0;
106  virtual float IntersectionComplexity() = 0;
107 
108  virtual int NumberOfFaces() const = 0;
109  virtual int Type() const = 0;
110  virtual float GetArea() const {return 0; }
111  virtual int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0;
112
113  virtual int GetRandomVisibleSurfacePoint(Vector3 &point,
114                                                                                   Vector3 &normal,
115                                                                                   const Vector3 &viewpoint,
116                                           const int maxTries) = 0;
117
118  virtual ostream &Describe(ostream &s) = 0;
119
120  virtual int GenerateSilhouetteRays(const int nrays,
121          const AxisAlignedBox3 &originBox,
122          const AxisAlignedBox3 &directionBox, VssRayContainer &rays)
123  {
124          return 0;
125  }
126
127  static bool GreaterCounter(const Intersectable *a,
128          const Intersectable *b)
129  {
130          return a->mCounter > b->mCounter;
131  }
132
133  static string GetTypeName(Intersectable *obj)
134  {
135          switch(obj->Type())
136          {
137          case MESH_INSTANCE:
138                  return "mesh_instance\n";
139
140          case TRANSFORMED_MESH_INSTANCE:
141                  return "transformed_mesh_instance\n";
142
143          case SPHERE:
144                  return "sphere\n";
145
146          case VIEW_CELL:
147                  return "view cell\n";
148
149          case OGRE_MESH_INSTANCE:
150                  return "ogre_mesh_instance\n";
151
152          case KD_INTERSECTABLE:
153                  return "kd_intersectable\n";
154
155          default:
156                  return "unknown\n";
157          }
158  }
159
160  /** Returns normal from the face with the specified index.
161          PROBLEM: Does not fit to all intersectable types (e.g., spheres)
162  */
163  virtual Vector3 GetNormal(const int idx) const { return Vector3(0, 0, 0); }
164
165  VssRayContainer *GetOrCreateRays()
166  {
167          if (!mVssRays)
168                mVssRays = new VssRayContainer();
169          return mVssRays;
170  }
171
172  void DelRayRefs()
173  {
174          DEL_PTR(mVssRays);
175  }
176
177protected:
178
179  /// some rays piercing this intersectable
180  VssRayContainer *mVssRays;
181};
182
183
184}
185
186#endif
Note: See TracBrowser for help on using the repository browser.