-
Notifications
You must be signed in to change notification settings - Fork 0
/
sampleobject.h
111 lines (97 loc) · 3.67 KB
/
sampleobject.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#ifndef SAMPLEOBJECT_H
#define SAMPLEOBJECT_H
#include "collideableobject.h"
#include <map>
#include <utility>
typedef std::pair<std::complex<double>, std::complex<double>>
GraphItem; // p then s
typedef std::map<double, GraphItem> GraphMap;
/*!
* \brief The SampleObject class
* This defines all the methods the sample object will implement, it also has some
* implementations for things that will not change.
*/
class SampleObject : public CollideableObject {
Q_OBJECT
private:
double m_radius, m_my;
std::complex<double> m_q;
std::complex<double> m_i;
std::complex<double> m_n0; // air
std::complex<double> m_x;
std::complex<double> m_n1;
std::complex<double> m_rpp;
std::complex<double> m_rss;
std::complex<double> m_rsp;
std::complex<double> m_rps;
Matrix4d m_R;
GraphMap m_graphMap;
public:
SampleObject(Eigen::Vector3d location, int side, Eigen::Vector3d normal,
double radius, std::complex<double> n1, std::complex<double> q);
~SampleObject();
void collide(Ray &ray, Eigen::Vector3d &pointOfInterception);
bool intersect(Ray &ray, Eigen::Vector3d &pointOfInterception);
ObjectType getType();
void calculatePolarisationUsingJonesCalculus(Ray &ray,
std::complex<double> &theta0,
std::complex<double> &theta1);
void setM_Y(double m_y);
private:
/*!
* \brief insertIntoGraphMap
* \param angle
* This buts the angles and the current values from the Jones Matrix into
* a map ready to be shown in the hysteresis loop graph.
*/
void insertIntoGraphMap(std::complex<double> angle) {
auto originalSize = m_graphMap.size();
GraphItem newItem = GraphItem(m_rsp / m_rpp, m_rps / m_rss);
std::pair<GraphMap::iterator, bool > result;
result = m_graphMap.insert(std::pair<double, GraphItem>(angle.real(), newItem));
if (result.second == false) { // the angle has already been done and graphed
if (result.first->second != newItem) { // are the s and p values the different?
result.first->second = newItem; // replace the values
emit newAngleOutout(m_graphMap); // update the graph
}
} else { // insertion was successful so update the graph
emit newAngleOutout(m_graphMap);
}
}
protected:
/*!
* \brief calculateAngleOfRefraction
* \param theta0
* \param theta1
* This calculates the angle od refraction, given the angle of incidence, useing Snell's Law
*/
void calculateAngleOfRefraction(std::complex<double> theta0,
std::complex<double> &theta1) {
std::complex<double> numerator1 = m_n0 * sin(theta0);
theta1 = asin(numerator1 / m_n1); // the angle of refraction
}
/*!
* \brief calculateAngleOfInterception
* \param ray
* \param theta0
*
* This calculates the angle of incidence by using trig on the normal vector of the sample
* and the direction of the ray.
*/
void calculateAngleOfInterception(Ray &ray, std::complex<double> &theta0) {
auto normal = this->getNormal();
normal.normalize();
Eigen::Vector3d rayDirection = ray.getDirection();
rayDirection.normalize();
std::complex<double> numerator0 = rayDirection.dot(normal);
std::complex<double> denominator0 = rayDirection.norm() * normal.norm();
theta0 = acos(numerator0 / denominator0); // the angle of incidence
this->insertIntoGraphMap(theta0);
}
signals:
void outputPolarisationUpdated(Matrix4cd polarisation);
void outputDirectionUpdated(Eigen::Vector3d direction);
void newAngleOutout(GraphMap graphMap);
void newThetas(std::complex<double> theta0, std::complex<double> theta1);
};
#endif // SAMPLEOBJECT_H