Volume Renderer DoF
ProxyGeometry.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <vector>
4 #include <QtCore\qmath.h>
5 #include <QtGui\qopenglshaderprogram.h>
6 
11  struct Edge {
12 
13  Edge() {};
14 
19  Edge(QVector3D* a, QVector3D* b) : a(a), b(b) {};
20  QVector3D* a;
21  QVector3D* b;
22  };
23 
27  struct Cube {
28  Cube() {};
29  Cube(QVector3D sizes) : sizes(sizes){
30  points.reserve(8);
31 
32  // source: http://cococubed.asu.edu/code_pages/raybox.shtml
33  // Do not change the order of points!
34  points.push_back(QVector3D(sizes.x() / 2.0f, sizes.y() / 2.0f, sizes.z() / 2.0f)); //1
35  points.push_back(QVector3D(-sizes.x() / 2.0f, sizes.y() / 2.0f, sizes.z() / 2.0f)); //2
36  points.push_back(QVector3D(sizes.x() / 2.0f, -sizes.y() / 2.0f, sizes.z() / 2.0f)); //3
37  points.push_back(QVector3D(sizes.x() / 2.0f, sizes.y() / 2.0f, -sizes.z() / 2.0f)); //4
38  points.push_back(QVector3D(-sizes.x() / 2.0f, sizes.y() / 2.0f, -sizes.z() / 2.0f)); //5
39  points.push_back(QVector3D(-sizes.x() / 2.0f, -sizes.y() / 2.0f, sizes.z() / 2.0f)); //6
40  points.push_back(QVector3D(sizes.x() / 2.0f, -sizes.y() / 2.0f, -sizes.z() / 2.0f)); //7
41  points.push_back(QVector3D(-sizes.x() / 2.0f, -sizes.y() / 2.0f, -sizes.z() / 2.0f)); //8
42 
43  origPoints = points;
44  edges.reserve(12);
45 
46  edges.push_back(Edge(&points[7], &points[4])); //0
47  edges.push_back(Edge(&points[4], &points[1])); //1
48  edges.push_back(Edge(&points[1], &points[0])); //2
49 
50  edges.push_back(Edge(&points[1], &points[5])); //3
51 
52  edges.push_back(Edge(&points[7], &points[5])); //4
53  edges.push_back(Edge(&points[5], &points[2])); //5
54  edges.push_back(Edge(&points[2], &points[0])); //6
55 
56  edges.push_back(Edge(&points[6], &points[2])); //7
57 
58  edges.push_back(Edge(&points[7], &points[6])); //8
59  edges.push_back(Edge(&points[6], &points[3])); //9
60  edges.push_back(Edge(&points[3], &points[0])); //10
61 
62  edges.push_back(Edge(&points[3], &points[4])); //11
63 
64  // only rotation around y-axis
65  edgeOrder.resize(8);
66  edgeOrder[0] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; // top
67  edgeOrder[1] = { 1, 11, 9, 0, 3, 4, 8, 5, 2, 6, 7, 10 }; // top
68  edgeOrder[2] = { 7, 8, 0, 9, 6, 10, 11, 2, 5, 3, 1, 4 }; // bottom
69  edgeOrder[3] = { 10, 2, 3, 6, 9, 7, 5, 8, 11, 0, 4, 1 }; // top
70  edgeOrder[4] = { 11, 10, 6, 9, 0, 8, 7, 4, 1, 3, 5, 2 }; // top
71  edgeOrder[5] = { 5, 7, 9, 6, 3, 2, 10, 1, 4, 0, 11, 8 }; // bottom
72  edgeOrder[6] = { 7, 6, 2, 5, 8, 4, 3, 0, 9, 11, 1, 10 }; // bottom
73  edgeOrder[7] = { 4, 5, 6, 3, 0, 1, 2, 11, 8, 9, 10, 7 }; // bottom
74  }
75 
77  std::vector<Edge> edges;
78 
80  std::vector<QVector3D> points;
81 
83  std::vector<QVector3D> origPoints;
84 
91  std::vector<std::vector<int>> edgeOrder;
92 
94  QVector3D sizes;
95 
100  void transform(QMatrix4x4 matrix) {
101  for (unsigned int i = 0; i < points.size(); i++) {
102  points[i] = matrix * origPoints[i];
103  }
104  };
105  };
106 
114  std::vector<QVector3D> calcPolygon(QVector4D normal, Cube& cube, int index);
115 
122  bool inside(QVector3D vertex, QVector4D normal);
123 
131  bool cross(QVector3D a, QVector3D b, QVector4D normal);
132 
141  QVector3D intersect(QVector3D a, QVector3D b, QVector4D normal);
142 
150  QVector3D interpolate(QVector3D a, QVector3D b, float t);
151 };
152 
155  public:
156  ProxyGeometry(QVector3D cubeSize);
157  ~ProxyGeometry();
158 
164  void updateProxyGeometry(QMatrix4x4 modelMatrix, int samples);
165 
170  std::vector < std::vector<QVector3D>>& getPlaneVertices();
171 
177  std::vector < std::vector<QVector3D>>& getTexCoords();
178 
183  float getSliceDistance();
184 
185  private:
187  std::vector<std::vector<QVector3D>> planeVertices;
188 
190  std::vector<std::vector<QVector3D>> texCoords;
191 
194 
196  float sliceDistance;
197 };
std::vector< Edge > edges
Definition: ProxyGeometry.h:77
Definition: ProxyGeometry.h:7
std::vector< std::vector< int > > edgeOrder
Definition: ProxyGeometry.h:91
std::vector< QVector3D > origPoints
Definition: ProxyGeometry.h:83
std::vector< QVector3D > points
Definition: ProxyGeometry.h:80
bool inside(QVector3D vertex, QVector4D normal)
Definition: ProxyGeometry.cpp:79
QVector3D * b
Definition: ProxyGeometry.h:21
Definition: ProxyGeometry.h:27
std::vector< QVector3D > calcPolygon(QVector4D normal, Cube &cube, int index)
Definition: ProxyGeometry.cpp:66
QVector3D sizes
Definition: ProxyGeometry.h:94
Cube()
Definition: ProxyGeometry.h:28
Definition: ProxyGeometry.h:154
bool cross(QVector3D a, QVector3D b, QVector4D normal)
Definition: ProxyGeometry.cpp:83
Definition: ProxyGeometry.h:11
Edge(QVector3D *a, QVector3D *b)
Definition: ProxyGeometry.h:19
void transform(QMatrix4x4 matrix)
Definition: ProxyGeometry.h:100
QVector3D interpolate(QVector3D a, QVector3D b, float t)
Definition: ProxyGeometry.cpp:109
QVector3D intersect(QVector3D a, QVector3D b, QVector4D normal)
Definition: ProxyGeometry.cpp:90
Edge()
Definition: ProxyGeometry.h:13
QVector3D * a
Definition: ProxyGeometry.h:19
Cube(QVector3D sizes)
Definition: ProxyGeometry.h:29