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

Revision 1990, 4.5 KB checked in by mattausch, 17 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#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  virtual int GetRandomSurfacePoint(const float u,
116                                                                        const float v,
117                                                                        Vector3 &point,
118                                                                        Vector3 &normal) {
119        cerr<<"GetRandomSurfacePoint(u,v...) not yet implemented"<<endl;
120        return 1;
121  }
122
123  virtual int GetRandomEdgePoint(Vector3 &point,
124                                                                 Vector3 &normal) = 0;
125
126  virtual int GetRandomVisibleSurfacePoint(Vector3 &point,
127                                                                                   Vector3 &normal,
128                                                                                   const Vector3 &viewpoint,
129                                           const int maxTries) = 0;
130
131 // virtual int GetRandomPoint(Vector3 &point,
132//                                                       Vector3 &normal) = 0;
133
134  virtual ostream &Describe(ostream &s) = 0;
135
136  virtual int GenerateSilhouetteRays(const int nrays,
137          const AxisAlignedBox3 &originBox,
138          const AxisAlignedBox3 &directionBox, VssRayContainer &rays)
139  {
140          return 0;
141  }
142
143  static bool GreaterCounter(const Intersectable *a,
144          const Intersectable *b)
145  {
146          return a->mCounter > b->mCounter;
147  }
148
149  static string GetTypeName(Intersectable *obj)
150  {
151          switch(obj->Type())
152          {
153          case MESH_INSTANCE:
154                  return "mesh_instance\n";
155
156          case TRANSFORMED_MESH_INSTANCE:
157                  return "transformed_mesh_instance\n";
158
159          case SPHERE:
160                  return "sphere\n";
161
162          case VIEW_CELL:
163                  return "view cell\n";
164
165          case OGRE_MESH_INSTANCE:
166                  return "ogre_mesh_instance\n";
167
168          case KD_INTERSECTABLE:
169                  return "kd_intersectable\n";
170
171          default:
172                  return "unknown\n";
173          }
174  }
175
176  /** Returns normal from the face with the specified index.
177          PROBLEM: Does not fit to all intersectable types (e.g., spheres)
178  */
179  virtual Vector3 GetNormal(const int idx) const { return Vector3(0, 0, 0); }
180
181  VssRayContainer *GetOrCreateRays()
182  {
183          if (!mVssRays)
184                mVssRays = new VssRayContainer();
185          return mVssRays;
186  }
187
188  void DelRayRefs()
189  {
190          DEL_PTR(mVssRays);
191  }
192
193protected:
194
195  /// some rays piercing this intersectable
196  VssRayContainer *mVssRays;
197};
198
199
200}
201
202#endif
Note: See TracBrowser for help on using the repository browser.