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

Revision 1999, 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,
66                 OBJECTS_INTERSECTABLE
[1135]67                };
[162]68 
[1736]69  Intersectable():
[1867]70        mMailbox(0),
[1736]71  //mReferences(0),
72  mBvhLeaf(0),
73  mVssRays(NULL) {}
[245]74
[1701]75  virtual Intersectable::~Intersectable() {DEL_PTR(mVssRays);}
[1615]76
[1579]77  void SetId(const int id) { mId = id; }
78  int GetId() { return mId; }
79 
80  ////////////////////////////////////////////////
81  //    Mailing stuff
82 
83  static void NewMail(const int reserve = 1) {
84        sMailId += sReservedMailboxes;
85        sReservedMailboxes = reserve;
86  }
[339]87       
[1579]88  void Mail() { mMailbox = sMailId; }
89  bool Mailed() const { return mMailbox == sMailId; }
90 
91  void Mail(const int mailbox) { mMailbox = sMailId + mailbox; }
92  bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; }
93 
94  int IncMail() { return ++ mMailbox - sMailId; }
[382]95
[1999]96   // last mail id -> warning not thread safe!
97  // both mailId and mailbox should be unique for each thread!!!
98  static int sMailId;
99  static int sReservedMailboxes;
100
101  /// Mailbox used for traversals
102  int mMailbox;
103 
104
[1579]105  ////////////////////////////////////////////////////
106  virtual AxisAlignedBox3 GetBox() const = 0;
[1743]107  virtual int CastRay(Ray &ray) = 0;
[176]108 
[1579]109  virtual bool IsConvex() const = 0;
110  virtual bool IsWatertight() const = 0;
111  virtual float IntersectionComplexity() = 0;
112 
113  virtual int NumberOfFaces() const = 0;
114  virtual int Type() const = 0;
[1686]115  virtual float GetArea() const {return 0; }
[1579]116  virtual int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0;
[1877]117  virtual int GetRandomSurfacePoint(const float u,
118                                                                        const float v,
119                                                                        Vector3 &point,
120                                                                        Vector3 &normal) {
121        cerr<<"GetRandomSurfacePoint(u,v...) not yet implemented"<<endl;
122        return 1;
123  }
[556]124
[1763]125  virtual int GetRandomEdgePoint(Vector3 &point,
126                                                                 Vector3 &normal) = 0;
127
[1687]128  virtual int GetRandomVisibleSurfacePoint(Vector3 &point,
[1696]129                                                                                   Vector3 &normal,
130                                                                                   const Vector3 &viewpoint,
131                                           const int maxTries) = 0;
[1166]132
[1990]133 // virtual int GetRandomPoint(Vector3 &point,
134//                                                       Vector3 &normal) = 0;
135
[1687]136  virtual ostream &Describe(ostream &s) = 0;
[1166]137
[1687]138  virtual int GenerateSilhouetteRays(const int nrays,
139          const AxisAlignedBox3 &originBox,
140          const AxisAlignedBox3 &directionBox, VssRayContainer &rays)
141  {
142          return 0;
143  }
[1166]144
[1687]145  static bool GreaterCounter(const Intersectable *a,
146          const Intersectable *b)
147  {
148          return a->mCounter > b->mCounter;
149  }
[1166]150
[1687]151  static string GetTypeName(Intersectable *obj)
152  {
153          switch(obj->Type())
154          {
155          case MESH_INSTANCE:
156                  return "mesh_instance\n";
[1344]157
[1687]158          case TRANSFORMED_MESH_INSTANCE:
159                  return "transformed_mesh_instance\n";
160
161          case SPHERE:
162                  return "sphere\n";
163
164          case VIEW_CELL:
165                  return "view cell\n";
166
167          case OGRE_MESH_INSTANCE:
168                  return "ogre_mesh_instance\n";
169
170          case KD_INTERSECTABLE:
171                  return "kd_intersectable\n";
172
173          default:
174                  return "unknown\n";
175          }
176  }
177
[1696]178  /** Returns normal from the face with the specified index.
179          PROBLEM: Does not fit to all intersectable types (e.g., spheres)
[1687]180  */
181  virtual Vector3 GetNormal(const int idx) const { return Vector3(0, 0, 0); }
[1696]182
183  VssRayContainer *GetOrCreateRays()
184  {
185          if (!mVssRays)
186                mVssRays = new VssRayContainer();
187          return mVssRays;
188  }
189
190  void DelRayRefs()
191  {
192          DEL_PTR(mVssRays);
193  }
194
195protected:
196
197  /// some rays piercing this intersectable
198  VssRayContainer *mVssRays;
[162]199};
200
[1135]201
[860]202}
[162]203
204#endif
Note: See TracBrowser for help on using the repository browser.