Commit c5768230 authored by Oliver Bock's avatar Oliver Bock

Added preliminary pulse profile computation and propagation

* Actual values still have to be verified (likely to be wrong)
* Pulse profile emitted via signal (connected to scope widget)
parent c8afe539
......@@ -24,7 +24,8 @@ const float PulsarAnimationWidget::deg2rad = PI/180.0f;
PulsarAnimationWidget::PulsarAnimationWidget(QWidget *parent) :
QGLWidget(QGLFormat(QGL::AlphaChannel | QGL::SampleBuffers), parent),
m_frameTimer()
m_frameTimer(),
m_pulseProfile(360, 0.0f)
{
if(!format().directRendering()) {
qWarning("Sorry, no direct rendering support for animation...");
......@@ -68,11 +69,13 @@ PulsarAnimationWidget::PulsarAnimationWidget(QWidget *parent) :
m_mouseLastX = 0;
m_mouseLastY = 0;
m_mouseAngleH = 90.0f;
m_mouseAngleV = 30.f;
m_mouseAngleV = 30.0f;
m_cameraZoom = 15.0f;
m_cameraZoomLBound = 2.0f;
updateCameraPosition(m_mouseAngleH, m_mouseAngleV, m_cameraZoom);
updatePulseProfile();
}
PulsarAnimationWidget::~PulsarAnimationWidget()
......@@ -359,6 +362,7 @@ void PulsarAnimationWidget::updateFrame()
m_pulsarRotationAngle += m_pulsarRotationDelta;
if(m_pulsarRotationAngle > 360) {
m_pulsarRotationAngle = 0.0f;
updatePulseProfile();
}
m_orbitRotationAngle += m_orbitRotationDelta;
if(m_orbitRotationAngle > 360) {
......@@ -432,6 +436,8 @@ void PulsarAnimationWidget::updateCameraPosition(const int angleH, const int ang
m_cameraPosY = sin(angleV * deg2rad) * zoom;
m_cameraPosZ = cos(angleH * deg2rad) * cos(fabs(angleV * deg2rad)) * zoom;
updatePulseProfile();
updateGL();
}
......@@ -445,6 +451,7 @@ void PulsarAnimationWidget::setPulsarSemiMajorAxis(const float length)
m_pulsarSemiMajorAxis = length;
m_companionSemiMajorAxis = (m_pulsarMass/m_companionMass) * m_pulsarSemiMajorAxis;
updateOrbitPeriod();
updatePulseProfile();
updateGL();
}
......@@ -453,6 +460,7 @@ void PulsarAnimationWidget::setCompanionMass(const float mass)
{
m_companionMass = mass;
updateOrbitRadii();
updatePulseProfile();
updateGL();
}
......@@ -461,6 +469,7 @@ void PulsarAnimationWidget::setPulsarMass(const float mass)
{
m_pulsarMass = mass;
updateOrbitRadii();
updatePulseProfile();
updateGL();
}
......@@ -468,11 +477,13 @@ void PulsarAnimationWidget::setPulsarMass(const float mass)
void PulsarAnimationWidget::setPulsarSpinFrequency(const float frequency)
{
m_pulsarRotationDelta = (360.0f * frequency) / m_framesPerSecond;
updatePulseProfile();
}
void PulsarAnimationWidget::setPulsarSpinAxisInclination(const int degrees)
{
m_pulsarSpinAxisInclination = degrees;
updatePulseProfile();
updateGL();
}
......@@ -517,3 +528,40 @@ void PulsarAnimationWidget::resetParameters()
emit pulsarAnimationReset();
}
void PulsarAnimationWidget::updatePulseProfile()
{
const double i = m_pulsarSpinAxisInclination;
const double y = m_pulsarMagneticAxisInclination;
const double deltaPhiOrb = m_orbitRotationDelta;
const double deltaPhiRot = m_pulsarRotationDelta;
const double rp = m_pulsarSemiMajorAxis;
const double xk = m_cameraPosZ;
const double yk = -m_cameraPosX;
const double zk = -m_cameraPosY;
const double cam = pow(xk,2) + pow(yk,2) + pow(zk,2);
const double alpha = -m_mouseAngleH;
const double delta = m_mouseAngleV;
const double gaussProfile = 0.012337;
for(int x = 0; x < 360; ++x) {
// determine angle between pulsar's magnetic axis and line of sight
const double phiOrb = x * deltaPhiOrb;
const double phiRot = x * deltaPhiRot;
double a = -sin(y) * sin(phiRot) * (xk + rp * cos(phiOrb)) \
+ (cos(i) * sin(y) * cos(phiRot) + sin(i) * cos(y)) * (yk + rp * sin(phiOrb)) \
- (sin(i) * sin(y) * cos(phiRot) - cos(i) * cos(y)) * zk;
double b = sqrt(pow(rp,2) + cam - 2 * sqrt(cam) * rp * cos(delta) * sin(alpha + phiOrb));
// determine pulse amplitude
double amp = exp(-2 * (1 - fabs(a/b)) / gaussProfile);
// store amplitude
m_pulseProfile[x] = (float) amp;
}
// propagate new profile
emit pulseProfileUpdated(m_pulseProfile);
}
......@@ -29,6 +29,7 @@
#define PI 3.14159265
class PulsarAnimationWidget : public QGLWidget
{
Q_OBJECT
......@@ -56,11 +57,11 @@ public slots:
signals:
void pulsarSemiMajorAxisUpdated(double value);
void pulsarViewDataUpdated(const QVector<float>& data);
void pulseProfileUpdated(const QVector<float>& data);
void pulsarAnimationStep(float stepSize);
void pulsarAnimationReset();
protected:
private:
void initializeGL();
void resizeGL(int w, int h);
void paintGL();
......@@ -73,6 +74,7 @@ protected:
void updateOrbitRadii();
void updateCameraPosition(const int angleH, const int angleV, const float zoom);
void resetParameters();
void updatePulseProfile();
QTimer m_frameTimer;
......@@ -117,6 +119,8 @@ protected:
float m_cameraPosY;
float m_cameraPosZ;
QVector<float> m_pulseProfile;
static const float deg2rad;
};
......
......@@ -50,7 +50,7 @@ PulsatingScience::PulsatingScience(QWidget *parent) : QMainWindow(parent)
connect(ui.pulsarGlWidget, SIGNAL(pulsarAnimationReset()),
ui.pulseScopeWidget, SLOT(markerReset()));
connect(ui.pulsarGlWidget, SIGNAL(pulsarViewDataUpdated(const QVector<float>&)),
connect(ui.pulsarGlWidget, SIGNAL(pulseProfileUpdated(const QVector<float>&)),
ui.pulseScopeWidget, SLOT(drawCurve(const QVector<float>&)));
on_sliderPulsarSemiMajorAxis_valueChanged(ui.sliderPulsarSemiMajorAxis->value());
......
......@@ -23,8 +23,7 @@
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<widget class="PulsarAnimationWidget" native="1" name="pulsarGlWidget" >
</widget>
<widget class="PulsarAnimationWidget" native="1" name="pulsarGlWidget" />
<widget class="PulseScopeWidget" name="pulseScopeWidget" >
<property name="frameShape" >
<enum>QFrame::NoFrame</enum>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment