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

Revision 2113, 3.7 KB checked in by mattausch, 17 years ago (diff)

warning: debug version

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{
22        /// intersectable
23        Intersectable *mObject;
24        /// face index
25        int mFaceIndex;
26
27        FaceParentInfo(Intersectable *obj, const int fi):
28        mObject(obj), mFaceIndex(fi)
29        {}
30};
31
32
33class Intersectable
34{
35public:
36 
37  /// unique object Id
38  int mId;
39
40  /// universal counter
41  int mCounter;
42
43  /// pointer to the containing bvh leaf
44  BvhLeaf *mBvhLeaf;
45 
46  ///////////////////////
47
48  enum { MESH_INSTANCE,
49                 TRANSFORMED_MESH_INSTANCE,
50                 SPHERE,
51                 VIEW_CELL,
52                 OGRE_MESH_INSTANCE,
53                 KD_INTERSECTABLE,
54                 BVH_INTERSECTABLE,
55                 TRIANGLE_INTERSECTABLE,
56                 DUMMY_INTERSECTABLE,
57                 ENGINE_INTERSECTABLE,
58                 CONTAINER_INTERSECTABLE
59                };
60 
61  Intersectable();
62
63  virtual ~Intersectable();
64
65  void SetId(const int id) { mId = id; }
66  int GetId() { return mId; }
67 
68  /////////////
69  // Mailing stuff
70 
71  static void NewMail(const int reserve = 1)
72  {
73          sMailId += sReservedMailboxes;
74          sReservedMailboxes = reserve;
75  }
76       
77  void Mail() { mMailbox = sMailId; }
78  bool Mailed() const { return mMailbox == sMailId; }
79 
80  void Mail(const int mailbox) { mMailbox = sMailId + mailbox; }
81  bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; }
82 
83  int IncMail() { return ++ mMailbox - sMailId; }
84
85   // last mail id -> warning not thread safe!
86  // both mailId and mailbox should be unique for each thread!!!
87  static int sMailId;
88  static int sReservedMailboxes;
89
90  /// Mailbox used for traversals
91  int mMailbox;
92 
93
94  ////////////////
95  // virtual interface
96
97  virtual AxisAlignedBox3 GetBox() const = 0;
98  virtual int CastRay(Ray &ray) = 0;
99 
100  virtual bool IsConvex() const = 0;
101  virtual bool IsWatertight() const = 0;
102  virtual float IntersectionComplexity() = 0;
103 
104  virtual int NumberOfFaces() const = 0;
105  virtual int Type() const = 0;
106 
107  virtual int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0;
108 
109  virtual int GetRandomEdgePoint(Vector3 &point,
110                                                                 Vector3 &normal) = 0;
111
112  virtual int GetRandomVisibleSurfacePoint(Vector3 &point,
113                                                                                   Vector3 &normal,
114                                                                                   const Vector3 &viewpoint,
115                                           const int maxTries) = 0;
116
117  // virtual int GetRandomPoint(Vector3 &point,
118  // vector3 &normal) = 0;
119
120  virtual ostream &Describe(ostream &s) = 0;
121
122  //////////////////////////////////////
123
124
125  virtual int GenerateSilhouetteRays(const int nrays,
126                                                                         const AxisAlignedBox3 &originBox,
127                                                                         const AxisAlignedBox3 &directionBox,
128                                                                         VssRayContainer &rays);
129 
130   virtual int GetRandomSurfacePoint(const float u,
131                                                                         const float v,
132                                                                         Vector3 &point,
133                                                                         Vector3 &normal);
134
135   virtual float GetArea() const;
136
137   static bool GreaterCounter(const Intersectable *a,
138                                                          const Intersectable *b);
139
140  /** Returns the name of the type of this intersectable
141  */
142  static string GetTypeName(Intersectable *obj);
143
144   /** Returns normal from the face with the specified index.
145   PROBLEM: Does not fit to all intersectable types (e.g., spheres)
146   */
147   virtual Vector3 GetNormal(const int idx) const;
148
149   /** Returns rays stored with this intersectable.
150   */
151   VssRayContainer *GetOrCreateRays();
152
153   /** Deletes the rays associated with this intersectable.
154   */
155   void DelRayRefs();
156
157protected:
158
159        /// some rays piercing this intersectable
160        VssRayContainer *mVssRays;
161};
162
163
164}
165
166#endif
Note: See TracBrowser for help on using the repository browser.