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

Revision 2048, 4.5 KB checked in by mattausch, 17 years ago (diff)
RevLine 
[162]1#ifndef __INTERSECTABLE_H
2#define __INTERSECTABLE_H
3
[176]4#include "AxisAlignedBox3.h"
5#include "Pvs.h"
[1074]6#include <set>
[1184]7#include "VssRay.h"
[1867]8#include "Mailable.h"
[162]9
[860]10namespace GtpVisibilityPreprocessor {
11
[497]12struct VssRayContainer;
[1072]13class KdLeaf;
[1233]14class BvhLeaf;
[1680]15class BvhNode;
[1281]16class Intersectable;
17struct Face;
[1233]18
[1344]19
[1281]20struct FaceParentInfo {
[1344]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        {}
[1281]29};
30
[1344]31
[162]32class Intersectable {
[176]33public:
[1999]34 
[1072]35  /// unique object Id
[811]36  int mId;
[1579]37
[1072]38  /// universal counter
[811]39  int mCounter;
[1077]40
[1680]41  /// pointer to the containing bvh leaf
[1233]42  BvhLeaf *mBvhLeaf;
[1696]43 
[1233]44  /// # of references to this instance
[1736]45  //int mReferences;
[1135]46
[1570]47  //////////////////
[1696]48  // note matt: delete these, they are only taking memory
[1570]49
50  /// object based pvs
[1736]51  //KdPvs mKdPvs;
[1579]52
[1570]53  /// view cell based pvs per object
[1736]54  //ViewCellPvs mViewCellPvs;
[1570]55       
56  ///////////////////////
57
[1135]58  enum { MESH_INSTANCE,
59                 TRANSFORMED_MESH_INSTANCE,
60                 SPHERE,
61                 VIEW_CELL,
62                 OGRE_MESH_INSTANCE,
[1233]63                 KD_INTERSECTABLE,
[1314]64                 BVH_INTERSECTABLE,
[1615]65                 TRIANGLE_INTERSECTABLE,
[2048]66                 OBJECTS_INTERSECTABLE,
67                 DUMMY_INTERSECTABLE
[1135]68                };
[162]69 
[1736]70  Intersectable():
[1867]71        mMailbox(0),
[1736]72  //mReferences(0),
73  mBvhLeaf(0),
74  mVssRays(NULL) {}
[245]75
[1701]76  virtual Intersectable::~Intersectable() {DEL_PTR(mVssRays);}
[1615]77
[1579]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  }
[339]88       
[1579]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; }
[382]96
[1999]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
[1579]106  ////////////////////////////////////////////////////
107  virtual AxisAlignedBox3 GetBox() const = 0;
[1743]108  virtual int CastRay(Ray &ray) = 0;
[176]109 
[1579]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;
[1686]116  virtual float GetArea() const {return 0; }
[1579]117  virtual int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0;
[1877]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  }
[556]125
[1763]126  virtual int GetRandomEdgePoint(Vector3 &point,
127                                                                 Vector3 &normal) = 0;
128
[1687]129  virtual int GetRandomVisibleSurfacePoint(Vector3 &point,
[1696]130                                                                                   Vector3 &normal,
131                                                                                   const Vector3 &viewpoint,
132                                           const int maxTries) = 0;
[1166]133
[1990]134 // virtual int GetRandomPoint(Vector3 &point,
135//                                                       Vector3 &normal) = 0;
136
[1687]137  virtual ostream &Describe(ostream &s) = 0;
[1166]138
[1687]139  virtual int GenerateSilhouetteRays(const int nrays,
140          const AxisAlignedBox3 &originBox,
141          const AxisAlignedBox3 &directionBox, VssRayContainer &rays)
142  {
143          return 0;
144  }
[1166]145
[1687]146  static bool GreaterCounter(const Intersectable *a,
147          const Intersectable *b)
148  {
149          return a->mCounter > b->mCounter;
150  }
[1166]151
[1687]152  static string GetTypeName(Intersectable *obj)
153  {
154          switch(obj->Type())
155          {
156          case MESH_INSTANCE:
157                  return "mesh_instance\n";
[1344]158
[1687]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
[1696]179  /** Returns normal from the face with the specified index.
180          PROBLEM: Does not fit to all intersectable types (e.g., spheres)
[1687]181  */
182  virtual Vector3 GetNormal(const int idx) const { return Vector3(0, 0, 0); }
[1696]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;
[162]200};
201
[1135]202
[860]203}
[162]204
205#endif
Note: See TracBrowser for help on using the repository browser.