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; ...@@ -24,7 +24,8 @@ const float PulsarAnimationWidget::deg2rad = PI/180.0f;
PulsarAnimationWidget::PulsarAnimationWidget(QWidget *parent) : PulsarAnimationWidget::PulsarAnimationWidget(QWidget *parent) :
QGLWidget(QGLFormat(QGL::AlphaChannel | QGL::SampleBuffers), parent), QGLWidget(QGLFormat(QGL::AlphaChannel | QGL::SampleBuffers), parent),
m_frameTimer() m_frameTimer(),
m_pulseProfile(360, 0.0f)
{ {
if(!format().directRendering()) { if(!format().directRendering()) {
qWarning("Sorry, no direct rendering support for animation..."); qWarning("Sorry, no direct rendering support for animation...");
...@@ -68,11 +69,13 @@ PulsarAnimationWidget::PulsarAnimationWidget(QWidget *parent) : ...@@ -68,11 +69,13 @@ PulsarAnimationWidget::PulsarAnimationWidget(QWidget *parent) :
m_mouseLastX = 0; m_mouseLastX = 0;
m_mouseLastY = 0; m_mouseLastY = 0;
m_mouseAngleH = 90.0f; m_mouseAngleH = 90.0f;
m_mouseAngleV = 30.f; m_mouseAngleV = 30.0f;
m_cameraZoom = 15.0f; m_cameraZoom = 15.0f;
m_cameraZoomLBound = 2.0f; m_cameraZoomLBound = 2.0f;
updateCameraPosition(m_mouseAngleH, m_mouseAngleV, m_cameraZoom); updateCameraPosition(m_mouseAngleH, m_mouseAngleV, m_cameraZoom);
updatePulseProfile();
} }
PulsarAnimationWidget::~PulsarAnimationWidget() PulsarAnimationWidget::~PulsarAnimationWidget()
...@@ -359,6 +362,7 @@ void PulsarAnimationWidget::updateFrame() ...@@ -359,6 +362,7 @@ void PulsarAnimationWidget::updateFrame()
m_pulsarRotationAngle += m_pulsarRotationDelta; m_pulsarRotationAngle += m_pulsarRotationDelta;
if(m_pulsarRotationAngle > 360) { if(m_pulsarRotationAngle > 360) {
m_pulsarRotationAngle = 0.0f; m_pulsarRotationAngle = 0.0f;
updatePulseProfile();
} }
m_orbitRotationAngle += m_orbitRotationDelta; m_orbitRotationAngle += m_orbitRotationDelta;
if(m_orbitRotationAngle > 360) { if(m_orbitRotationAngle > 360) {
...@@ -432,6 +436,8 @@ void PulsarAnimationWidget::updateCameraPosition(const int angleH, const int ang ...@@ -432,6 +436,8 @@ void PulsarAnimationWidget::updateCameraPosition(const int angleH, const int ang
m_cameraPosY = sin(angleV * deg2rad) * zoom; m_cameraPosY = sin(angleV * deg2rad) * zoom;
m_cameraPosZ = cos(angleH * deg2rad) * cos(fabs(angleV * deg2rad)) * zoom; m_cameraPosZ = cos(angleH * deg2rad) * cos(fabs(angleV * deg2rad)) * zoom;
updatePulseProfile();
updateGL(); updateGL();
} }
...@@ -445,6 +451,7 @@ void PulsarAnimationWidget::setPulsarSemiMajorAxis(const float length) ...@@ -445,6 +451,7 @@ void PulsarAnimationWidget::setPulsarSemiMajorAxis(const float length)
m_pulsarSemiMajorAxis = length; m_pulsarSemiMajorAxis = length;
m_companionSemiMajorAxis = (m_pulsarMass/m_companionMass) * m_pulsarSemiMajorAxis; m_companionSemiMajorAxis = (m_pulsarMass/m_companionMass) * m_pulsarSemiMajorAxis;
updateOrbitPeriod(); updateOrbitPeriod();
updatePulseProfile();
updateGL(); updateGL();
} }
...@@ -453,6 +460,7 @@ void PulsarAnimationWidget::setCompanionMass(const float mass) ...@@ -453,6 +460,7 @@ void PulsarAnimationWidget::setCompanionMass(const float mass)
{ {
m_companionMass = mass; m_companionMass = mass;
updateOrbitRadii(); updateOrbitRadii();
updatePulseProfile();
updateGL(); updateGL();
} }
...@@ -461,6 +469,7 @@ void PulsarAnimationWidget::setPulsarMass(const float mass) ...@@ -461,6 +469,7 @@ void PulsarAnimationWidget::setPulsarMass(const float mass)
{ {
m_pulsarMass = mass; m_pulsarMass = mass;
updateOrbitRadii(); updateOrbitRadii();
updatePulseProfile();
updateGL(); updateGL();
} }
...@@ -468,11 +477,13 @@ void PulsarAnimationWidget::setPulsarMass(const float mass) ...@@ -468,11 +477,13 @@ void PulsarAnimationWidget::setPulsarMass(const float mass)
void PulsarAnimationWidget::setPulsarSpinFrequency(const float frequency) void PulsarAnimationWidget::setPulsarSpinFrequency(const float frequency)
{ {
m_pulsarRotationDelta = (360.0f * frequency) / m_framesPerSecond; m_pulsarRotationDelta = (360.0f * frequency) / m_framesPerSecond;
updatePulseProfile();
} }
void PulsarAnimationWidget::setPulsarSpinAxisInclination(const int degrees) void PulsarAnimationWidget::setPulsarSpinAxisInclination(const int degrees)
{ {
m_pulsarSpinAxisInclination = degrees; m_pulsarSpinAxisInclination = degrees;
updatePulseProfile();
updateGL(); updateGL();
} }
...@@ -517,3 +528,40 @@ void PulsarAnimationWidget::resetParameters() ...@@ -517,3 +528,40 @@ void PulsarAnimationWidget::resetParameters()
emit pulsarAnimationReset(); 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 @@ ...@@ -29,6 +29,7 @@
#define PI 3.14159265 #define PI 3.14159265
class PulsarAnimationWidget : public QGLWidget class PulsarAnimationWidget : public QGLWidget
{ {
Q_OBJECT Q_OBJECT
...@@ -56,11 +57,11 @@ public slots: ...@@ -56,11 +57,11 @@ public slots:
signals: signals:
void pulsarSemiMajorAxisUpdated(double value); void pulsarSemiMajorAxisUpdated(double value);
void pulsarViewDataUpdated(const QVector<float>& data); void pulseProfileUpdated(const QVector<float>& data);
void pulsarAnimationStep(float stepSize); void pulsarAnimationStep(float stepSize);
void pulsarAnimationReset(); void pulsarAnimationReset();
protected: private:
void initializeGL(); void initializeGL();
void resizeGL(int w, int h); void resizeGL(int w, int h);
void paintGL(); void paintGL();
...@@ -73,6 +74,7 @@ protected: ...@@ -73,6 +74,7 @@ protected:
void updateOrbitRadii(); void updateOrbitRadii();
void updateCameraPosition(const int angleH, const int angleV, const float zoom); void updateCameraPosition(const int angleH, const int angleV, const float zoom);
void resetParameters(); void resetParameters();
void updatePulseProfile();
QTimer m_frameTimer; QTimer m_frameTimer;
...@@ -117,6 +119,8 @@ protected: ...@@ -117,6 +119,8 @@ protected:
float m_cameraPosY; float m_cameraPosY;
float m_cameraPosZ; float m_cameraPosZ;
QVector<float> m_pulseProfile;
static const float deg2rad; static const float deg2rad;
}; };
......
...@@ -50,7 +50,7 @@ PulsatingScience::PulsatingScience(QWidget *parent) : QMainWindow(parent) ...@@ -50,7 +50,7 @@ PulsatingScience::PulsatingScience(QWidget *parent) : QMainWindow(parent)
connect(ui.pulsarGlWidget, SIGNAL(pulsarAnimationReset()), connect(ui.pulsarGlWidget, SIGNAL(pulsarAnimationReset()),
ui.pulseScopeWidget, SLOT(markerReset())); 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>&))); ui.pulseScopeWidget, SLOT(drawCurve(const QVector<float>&)));
on_sliderPulsarSemiMajorAxis_valueChanged(ui.sliderPulsarSemiMajorAxis->value()); on_sliderPulsarSemiMajorAxis_valueChanged(ui.sliderPulsarSemiMajorAxis->value());
......
...@@ -23,8 +23,7 @@ ...@@ -23,8 +23,7 @@
<property name="orientation" > <property name="orientation" >
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
</property> </property>
<widget class="PulsarAnimationWidget" native="1" name="pulsarGlWidget" > <widget class="PulsarAnimationWidget" native="1" name="pulsarGlWidget" />
</widget>
<widget class="PulseScopeWidget" name="pulseScopeWidget" > <widget class="PulseScopeWidget" name="pulseScopeWidget" >
<property name="frameShape" > <property name="frameShape" >
<enum>QFrame::NoFrame</enum> <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