Skip to content
Snippets Groups Projects
Commit c2be940f authored by Oliver Bock's avatar Oliver Bock
Browse files

Added power spectrum processing based on real data

parent d6ebd508
No related branches found
No related tags found
No related merge requests found
...@@ -22,7 +22,8 @@ ...@@ -22,7 +22,8 @@
const string EinsteinRadioAdapter::SharedMemoryIdentifier = "EinsteinRadio"; const string EinsteinRadioAdapter::SharedMemoryIdentifier = "EinsteinRadio";
EinsteinRadioAdapter::EinsteinRadioAdapter(BOINCClientAdapter *boincClient) EinsteinRadioAdapter::EinsteinRadioAdapter(BOINCClientAdapter *boincClient) :
m_WUTemplatePowerSpectrum(POWERSPECTRUM_BINS, 0)
{ {
this->boincClient = boincClient; this->boincClient = boincClient;
...@@ -44,6 +45,8 @@ void EinsteinRadioAdapter::refresh() ...@@ -44,6 +45,8 @@ void EinsteinRadioAdapter::refresh()
void EinsteinRadioAdapter::parseApplicationInformation() void EinsteinRadioAdapter::parseApplicationInformation()
{ {
char spectrumArray[POWERSPECTRUM_BIN_BYTES + 1] = {0};
// get updated application information // get updated application information
string info = boincClient->applicationInformation(); string info = boincClient->applicationInformation();
...@@ -52,24 +55,26 @@ void EinsteinRadioAdapter::parseApplicationInformation() ...@@ -52,24 +55,26 @@ void EinsteinRadioAdapter::parseApplicationInformation()
// parse data into members // parse data into members
// TODO: this is soon going to be replaced by true XML parsing! // TODO: this is soon going to be replaced by true XML parsing!
if(8 != sscanf(info.c_str(), if(9 != sscanf(info.c_str(),
"<graphics_info>\n" "<graphics_info>\n"
" <fraction_done>%lf</fraction_done>\n"
" <cpu_time>%lf</cpu_time>\n"
" <skypos_rac>%lf</skypos_rac>\n" " <skypos_rac>%lf</skypos_rac>\n"
" <skypos_dec>%lf</skypos_dec>\n" " <skypos_dec>%lf</skypos_dec>\n"
" <dispersion>%lf</dispersion>\n" " <dispersion>%lf</dispersion>\n"
" <orb_radius>%lf</orb_radius>\n" " <orb_radius>%lf</orb_radius>\n"
" <orb_period>%lf</orb_period\n" " <orb_period>%lf</orb_period\n"
" <orb_phase>%lf</orb_phase>\n", " <orb_phase>%lf</orb_phase>\n"
&m_WUFractionDone, " <power_spectrum>%80c</power_spectrum>\n"
&m_WUCPUTime, " <fraction_done>%lf</fraction_done>\n"
" <cpu_time>%lf</cpu_time>\n",
&m_WUSkyPosRightAscension, &m_WUSkyPosRightAscension,
&m_WUSkyPosDeclination, &m_WUSkyPosDeclination,
&m_WUDispersionMeasure, &m_WUDispersionMeasure,
&m_WUTemplateOrbitalRadius, &m_WUTemplateOrbitalRadius,
&m_WUTemplateOrbitalPeriod, &m_WUTemplateOrbitalPeriod,
&m_WUTemplateOrbitalPhase)) &m_WUTemplateOrbitalPhase,
spectrumArray,
&m_WUFractionDone,
&m_WUCPUTime))
{ {
cerr << "Incompatible shared memory data encountered!" << endl; cerr << "Incompatible shared memory data encountered!" << endl;
} }
...@@ -77,6 +82,31 @@ void EinsteinRadioAdapter::parseApplicationInformation() ...@@ -77,6 +82,31 @@ void EinsteinRadioAdapter::parseApplicationInformation()
// convert radians to degrees // convert radians to degrees
m_WUSkyPosRightAscension *= 180/PI; m_WUSkyPosRightAscension *= 180/PI;
m_WUSkyPosDeclination *= 180/PI; m_WUSkyPosDeclination *= 180/PI;
// prepare power spectrum data
string spectrumString(spectrumArray);
if(spectrumString.length() == POWERSPECTRUM_BIN_BYTES) {
int spectrumBinValue;
istringstream spectrumBinStream;
// iterate over all bins
for(int i = 0, j = 0; i < POWERSPECTRUM_BIN_BYTES; i += 2, ++j) {
spectrumBinStream.str(spectrumString.substr(i, 2));
if(spectrumBinStream) {
// convert hex bin value to integer
spectrumBinStream >> hex >> spectrumBinValue;
// store bin power value
m_WUTemplatePowerSpectrum.at(j) = (char) spectrumBinValue;
spectrumBinStream.clear();
}
else {
cerr << "Premature end of spectrum stream encountered!" << endl;
break;
}
}
}
else {
cerr << "Invalid power spectrum data encountered!" << endl;
}
} }
} }
} }
...@@ -111,6 +141,11 @@ double EinsteinRadioAdapter::wuTemplateOrbitalPhase() const ...@@ -111,6 +141,11 @@ double EinsteinRadioAdapter::wuTemplateOrbitalPhase() const
return m_WUTemplateOrbitalPhase; return m_WUTemplateOrbitalPhase;
} }
const vector<char>* EinsteinRadioAdapter::wuTemplatePowerSpectrum() const
{
return &m_WUTemplatePowerSpectrum;
}
double EinsteinRadioAdapter::wuFractionDone() const double EinsteinRadioAdapter::wuFractionDone() const
{ {
return m_WUFractionDone; return m_WUFractionDone;
......
...@@ -22,12 +22,16 @@ ...@@ -22,12 +22,16 @@
#define EINSTEINRADIOADAPTER_H_ #define EINSTEINRADIOADAPTER_H_
#include <string> #include <string>
#include <sstream>
#include <iomanip>
#include "BOINCClientAdapter.h" #include "BOINCClientAdapter.h"
using namespace std; using namespace std;
#define PI 3.14159265 #define PI 3.14159265
#define POWERSPECTRUM_BINS 40
#define POWERSPECTRUM_BIN_BYTES 80
/** /**
* \addtogroup starsphere Starsphere * \addtogroup starsphere Starsphere
...@@ -108,6 +112,13 @@ public: ...@@ -108,6 +112,13 @@ public:
*/ */
double wuTemplateOrbitalPhase() const; double wuTemplateOrbitalPhase() const;
/**
* \brief Retrieves the power spectrum of the currently active template
*
* \return The power spectrum of the currently active template
*/
const vector<char>* wuTemplatePowerSpectrum() const;
/** /**
* \brief Retrieves the completion fraction of the currently active work unit * \brief Retrieves the completion fraction of the currently active work unit
* *
...@@ -159,6 +170,9 @@ private: ...@@ -159,6 +170,9 @@ private:
/// Initial orbital phase of the currently active template /// Initial orbital phase of the currently active template
double m_WUTemplateOrbitalPhase; double m_WUTemplateOrbitalPhase;
/// Power spectrum of the currently active template
vector<char> m_WUTemplatePowerSpectrum;
/// The completion fraction of the active work unit /// The completion fraction of the active work unit
double m_WUFractionDone; double m_WUFractionDone;
......
...@@ -20,17 +20,18 @@ ...@@ -20,17 +20,18 @@
#include "StarsphereRadio.h" #include "StarsphereRadio.h"
StarsphereRadio::StarsphereRadio() : Starsphere(), m_EinsteinAdapter(&m_BoincAdapter) StarsphereRadio::StarsphereRadio() :
Starsphere(EinsteinRadioAdapter::SharedMemoryIdentifier),
m_EinsteinAdapter(&m_BoincAdapter)
{ {
m_WUDispersionMeasureValue = -1.0; m_WUDispersionMeasureValue = -1.0;
m_PowerSpectrumCoordSystemList = 0; m_PowerSpectrumCoordSystemList = 0;
m_PowerSpectrumBinList = 0; m_PowerSpectrumBinList = 0;
m_PowerSpectrumFreqBins = new vector<char>(40, 0); m_PowerSpectrumFreqBins = 0;
} }
StarsphereRadio::~StarsphereRadio() StarsphereRadio::~StarsphereRadio()
{ {
if(m_PowerSpectrumFreqBins) delete m_PowerSpectrumFreqBins;
} }
void StarsphereRadio::initialize(const int width, const int height, const Resource *font, const bool recycle) void StarsphereRadio::initialize(const int width, const int height, const Resource *font, const bool recycle)
...@@ -129,7 +130,7 @@ void StarsphereRadio::refreshBOINCInformation() ...@@ -129,7 +130,7 @@ void StarsphereRadio::refreshBOINCInformation()
if(m_WUDispersionMeasureValue != m_EinsteinAdapter.wuDispersionMeasure()) { if(m_WUDispersionMeasureValue != m_EinsteinAdapter.wuDispersionMeasure()) {
// we've got a new dispersion measure, update HUD // we've got a new dispersion measure, update HUD
m_WUDispersionMeasureValue = m_EinsteinAdapter.wuSkyPosDeclination(); m_WUDispersionMeasureValue = m_EinsteinAdapter.wuDispersionMeasure();
buffer << "DM: " << fixed << m_WUDispersionMeasureValue << " pc/cm3" << ends; buffer << "DM: " << fixed << m_WUDispersionMeasureValue << " pc/cm3" << ends;
m_WUDispersionMeasure = buffer.str(); m_WUDispersionMeasure = buffer.str();
buffer.str(""); buffer.str("");
...@@ -261,15 +262,12 @@ void StarsphereRadio::generatePowerSpectrumBins(const int originX, const int ori ...@@ -261,15 +262,12 @@ void StarsphereRadio::generatePowerSpectrumBins(const int originX, const int ori
// set pixel normalization factor for maximum bin height // set pixel normalization factor for maximum bin height
GLfloat normalizationFactor = 255.0 / (m_PowerSpectrumHeight - axesYOffset); GLfloat normalizationFactor = 255.0 / (m_PowerSpectrumHeight - axesYOffset);
// TODO: use real FFT data // fetch pointer to power spectrum data
// ------test code m_PowerSpectrumFreqBins = m_EinsteinAdapter.wuTemplatePowerSpectrum();
srand(time(NULL)); if(!m_PowerSpectrumFreqBins) {
for(int i=0; i<40; ++i) { cerr << "Power spectrum data currently unavailable!" << endl;
// set bin value to normalized pixel height return;
m_PowerSpectrumFreqBins->at(i) = (rand() % 10) * normalizationFactor;
// m_PowerSpectrumFreqBins->at(i) = 255 / normalizationFactor;
} }
// ------test code
// delete existing, create new (required for windoze) // delete existing, create new (required for windoze)
if(m_PowerSpectrumBinList) glDeleteLists(m_PowerSpectrumBinList, 1); if(m_PowerSpectrumBinList) glDeleteLists(m_PowerSpectrumBinList, 1);
...@@ -281,9 +279,9 @@ void StarsphereRadio::generatePowerSpectrumBins(const int originX, const int ori ...@@ -281,9 +279,9 @@ void StarsphereRadio::generatePowerSpectrumBins(const int originX, const int ori
// draw frequency bins // draw frequency bins
glBegin(GL_LINES); glBegin(GL_LINES);
// iterate over all bins // iterate over all bins
for(int i = 0; i < 40; ++i) { for(int i = 0; i < POWERSPECTRUM_BINS; ++i) {
// show potential candidates (power >= 100)... // show potential candidates (power >= 100)...
if(m_PowerSpectrumFreqBins->at(i) >= m_PowerSpectrumHeight / 2.55) { if(m_PowerSpectrumFreqBins->at(i) >= 100) {
// ...in bright white // ...in bright white
glColor4f(1.0, 1.0, 1.0, 1.0); glColor4f(1.0, 1.0, 1.0, 1.0);
} }
...@@ -296,7 +294,7 @@ void StarsphereRadio::generatePowerSpectrumBins(const int originX, const int ori ...@@ -296,7 +294,7 @@ void StarsphereRadio::generatePowerSpectrumBins(const int originX, const int ori
offsetY + axesYOffset); offsetY + axesYOffset);
// upper vertex // upper vertex
glVertex2f(offsetX + axesXOffset + i*binXOffset, glVertex2f(offsetX + axesXOffset + i*binXOffset,
offsetY + axesYOffset + m_PowerSpectrumFreqBins->at(i)); offsetY + axesYOffset + m_PowerSpectrumFreqBins->at(i) / normalizationFactor);
} }
glEnd(); glEnd();
......
...@@ -131,7 +131,7 @@ private: ...@@ -131,7 +131,7 @@ private:
GLuint m_PowerSpectrumBinList; GLuint m_PowerSpectrumBinList;
/// Byte vector to hold the current power spectrum bin values /// Byte vector to hold the current power spectrum bin values
vector<char>* m_PowerSpectrumFreqBins; const vector<char>* m_PowerSpectrumFreqBins;
/// Power Spectrum configuration setting (width) /// Power Spectrum configuration setting (width)
GLfloat m_PowerSpectrumWidth; GLfloat m_PowerSpectrumWidth;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment