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

Revision 1867, 4.2 KB checked in by bittner, 18 years ago (diff)

merge, global lines, rss sampling updates

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