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

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