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

Revision 1763, 4.2 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 
50  /// # of references to this instance
51  //int mReferences;
52
53  //////////////////
54  // note matt: delete these, they are only taking memory
55
56  /// object based pvs
57  //KdPvs mKdPvs;
58
59  /// view cell based pvs per object
60  //ViewCellPvs mViewCellPvs;
61       
62  ///////////////////////
63
64  enum { MESH_INSTANCE,
65                 TRANSFORMED_MESH_INSTANCE,
66                 SPHERE,
67                 VIEW_CELL,
68                 OGRE_MESH_INSTANCE,
69                 KD_INTERSECTABLE,
70                 BVH_INTERSECTABLE,
71                 TRIANGLE_INTERSECTABLE,
72                 OBJECTS_INTERSECTABLE
73                };
74 
75  Intersectable():
76  mMailbox(0),
77  //mReferences(0),
78  mBvhLeaf(0),
79  mVssRays(NULL) {}
80
81  virtual Intersectable::~Intersectable() {DEL_PTR(mVssRays);}
82
83  void SetId(const int id) { mId = id; }
84  int GetId() { return mId; }
85 
86  ////////////////////////////////////////////////
87  //    Mailing stuff
88 
89  static void NewMail(const int reserve = 1) {
90        sMailId += sReservedMailboxes;
91        sReservedMailboxes = reserve;
92  }
93       
94  void Mail() { mMailbox = sMailId; }
95  bool Mailed() const { return mMailbox == sMailId; }
96 
97  void Mail(const int mailbox) { mMailbox = sMailId + mailbox; }
98  bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; }
99 
100  int IncMail() { return ++ mMailbox - sMailId; }
101
102  ////////////////////////////////////////////////////
103  virtual AxisAlignedBox3 GetBox() const = 0;
104  virtual int CastRay(Ray &ray) = 0;
105 
106  virtual bool IsConvex() const = 0;
107  virtual bool IsWatertight() const = 0;
108  virtual float IntersectionComplexity() = 0;
109 
110  virtual int NumberOfFaces() const = 0;
111  virtual int Type() const = 0;
112  virtual float GetArea() const {return 0; }
113  virtual int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0;
114
115  virtual int GetRandomEdgePoint(Vector3 &point,
116                                                                 Vector3 &normal) = 0;
117
118  virtual int GetRandomVisibleSurfacePoint(Vector3 &point,
119                                                                                   Vector3 &normal,
120                                                                                   const Vector3 &viewpoint,
121                                           const int maxTries) = 0;
122
123  virtual ostream &Describe(ostream &s) = 0;
124
125  virtual int GenerateSilhouetteRays(const int nrays,
126          const AxisAlignedBox3 &originBox,
127          const AxisAlignedBox3 &directionBox, VssRayContainer &rays)
128  {
129          return 0;
130  }
131
132  static bool GreaterCounter(const Intersectable *a,
133          const Intersectable *b)
134  {
135          return a->mCounter > b->mCounter;
136  }
137
138  static string GetTypeName(Intersectable *obj)
139  {
140          switch(obj->Type())
141          {
142          case MESH_INSTANCE:
143                  return "mesh_instance\n";
144
145          case TRANSFORMED_MESH_INSTANCE:
146                  return "transformed_mesh_instance\n";
147
148          case SPHERE:
149                  return "sphere\n";
150
151          case VIEW_CELL:
152                  return "view cell\n";
153
154          case OGRE_MESH_INSTANCE:
155                  return "ogre_mesh_instance\n";
156
157          case KD_INTERSECTABLE:
158                  return "kd_intersectable\n";
159
160          default:
161                  return "unknown\n";
162          }
163  }
164
165  /** Returns normal from the face with the specified index.
166          PROBLEM: Does not fit to all intersectable types (e.g., spheres)
167  */
168  virtual Vector3 GetNormal(const int idx) const { return Vector3(0, 0, 0); }
169
170  VssRayContainer *GetOrCreateRays()
171  {
172          if (!mVssRays)
173                mVssRays = new VssRayContainer();
174          return mVssRays;
175  }
176
177  void DelRayRefs()
178  {
179          DEL_PTR(mVssRays);
180  }
181
182protected:
183
184  /// some rays piercing this intersectable
185  VssRayContainer *mVssRays;
186};
187
188
189}
190
191#endif
Note: See TracBrowser for help on using the repository browser.