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

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