source: trunk/VUT/GtpVisibilityPreprocessor/src/Mesh.h @ 191

Revision 191, 3.9 KB checked in by bittner, 19 years ago (diff)

basic sampling strategies

Line 
1#ifndef _Mesh_H__
2#define _Mesh_H__
3
4#include <vector>
5using namespace std;
6#include "Intersectable.h"
7#include "Plane3.h"
8#include "Matrix4x4.h"
9#include "AxisAlignedBox3.h"
10#include "Material.h"
11
12class Triangle3;
13class MeshInstance;
14class MeshKdTree;
15
16/// default vertex container for Mesh
17typedef std::vector<Vector3> VertexContainer;
18
19/// vertex index container
20typedef std::vector<int> VertexIndexContainer;
21
22
23/** Patch used as an element of the mesh */
24class Face {
25public:
26  Face():mVertexIndices() {}
27  Face(const int a, const int b, const int c):mVertexIndices(3) {
28    mVertexIndices[0] = a;
29    mVertexIndices[1] = b;
30    mVertexIndices[2] = c;
31  }
32
33  Face(const int a, const int b, const int c, const int d):mVertexIndices(4) {
34    mVertexIndices[0] = a;
35    mVertexIndices[1] = b;
36    mVertexIndices[2] = c;
37    mVertexIndices[3] = d;
38  }
39
40  Face(const VertexIndexContainer &vertices):mVertexIndices(vertices) {}
41 
42  /// list of vertex pointers
43  VertexIndexContainer mVertexIndices;
44};
45
46/// default patch container for Mesh
47typedef std::vector<Face *> FaceContainer;
48
49/** Mesh containing polygonal patches */
50class Mesh {
51
52public:
53
54  /// Default constructor
55  Mesh():mVertices(), mFaces(), mMaterial(NULL), mKdTree(NULL) {}
56 
57  /// Constructor with container preallocation
58  Mesh(const int vertices,
59       const int faces):
60    mFaces(),
61    mMaterial(NULL),
62    mKdTree(NULL),
63    mVertices(),
64    mIsConvex(false),
65    mIsWatertight(false)
66  {
67    mVertices.reserve(vertices);
68    mFaces.reserve(faces);
69  }
70 
71  ~Mesh() {
72    for (int i=0; i < mFaces.size(); i++)
73      delete mFaces[i];
74  }
75
76  void AddTriangle(const Triangle3 &triangle);
77 
78  void AddFace(Face *face)
79  {
80    mFaces.push_back(face);
81  }
82 
83  void Preprocess();
84
85  /** Axis aligned bounding box of the mesh in local mesh coordinates */
86  AxisAlignedBox3 mBox;
87 
88  /** Vertices forming the mesh */
89  VertexContainer mVertices;
90 
91  /** Patches forming the mesh */
92  FaceContainer mFaces;
93 
94  /** Global mesh material */
95  Material *mMaterial;
96 
97  /** true if the mesh is a convex mesh */
98  bool mIsConvex;
99
100  /** true if the mesh is a convex mesh */
101  bool mIsWatertight;
102
103  MeshKdTree *mKdTree;
104 
105  int
106  CastRay(
107          Ray &ray,
108          MeshInstance *instance
109          );
110
111  int
112  CastRayToSelectedFaces(
113                         Ray &ray,
114                         const vector<int> &faces,
115                         MeshInstance *instance
116                         );
117
118  int
119  CastRayToFace(
120                const int faceIndex,
121                Ray &ray,
122                float &nearestT,
123                int &nearestFace,
124                MeshInstance *instance
125                );
126
127 
128  int
129  RayFaceIntersection(const int faceIndex,
130                      const Ray &ray,
131                      float &t,
132                      const float nearestT
133                      );
134 
135  Plane3 GetFacePlane(const int faceIndex);
136
137  AxisAlignedBox3 GetFaceBox(const int faceIndex);
138
139  void GetRandomSurfacePoint(Vector3 &point, Vector3 &normal);
140
141};
142
143class MeshInstance : public Intersectable {
144protected:
145  Mesh *mMesh;
146 
147public:
148  MeshInstance(Mesh *mesh):Intersectable(), mMesh(mesh)
149  {
150  }
151
152  void GetRandomSurfacePoint(Vector3 &point, Vector3 &normal);
153
154
155  Mesh *GetMesh() { return mMesh; }
156
157  virtual AxisAlignedBox3 GetBox() {
158    return mMesh->mBox;
159  }
160
161  virtual int
162  CastRay(
163          Ray &ray
164          );
165
166  virtual bool IsConvex() { return mMesh->mIsConvex; }
167  virtual bool IsWatertight() { return mMesh->mIsWatertight; }
168  virtual float IntersectionComplexity() {  return mMesh->mFaces.size(); }
169
170  virtual int Type() const { return MESH_INSTANCE; }
171
172  virtual int
173  CastRay(
174          Ray &ray,
175          const vector<int> &faces
176          );
177
178
179};
180
181
182class TransformedMeshInstance : public MeshInstance
183{
184public:
185  TransformedMeshInstance(Mesh *mesh):MeshInstance(mesh)
186  {
187    mWorldTransform = IdentityMatrix();
188  }
189 
190  virtual AxisAlignedBox3 GetBox() {
191    return Transform(mMesh->mBox,
192                     mWorldTransform);
193  }
194 
195  virtual int
196  CastRay(
197          Ray &ray
198          );
199
200  virtual int Type() const { return TRANSFORMED_MESH_INSTANCE; }
201
202  void GetRandomSurfacePoint(Vector3 &point, Vector3 &normal);
203
204private:
205  Matrix4x4 mWorldTransform;
206 
207};
208
209
210
211#endif
Note: See TracBrowser for help on using the repository browser.