gaussianplot.cpp
Go to the documentation of this file.00001
00014 #include <klocale.h>
00015
00016 #include <qpainter.h>
00017
00018 #include <math.h>
00019
00020 #include "gaussianplot.h"
00021 #include "setiloc.h"
00022
00025 #define FITSIZE 128
00026
00027
00028 GaussianPlot::GaussianPlot(SetiLoc* loc, QWidget *parent, const char *name )
00029 : SetiGraph(loc,true,true,parent,name)
00030 {
00031 init();
00032 }
00033
00034
00035 GaussianPlot::GaussianPlot(QWidget *parent, const char *name )
00036 : SetiGraph(0,true,true,parent,name)
00037 {
00038 init();
00039 }
00040
00041
00042 GaussianPlot::~GaussianPlot()
00043 {
00044 }
00045
00046
00047 void GaussianPlot::init()
00048 {
00049 if(m_location)
00050 {
00051
00052 connect(m_location, SIGNAL(newGaussian(GaussianScore)),
00053 this, SLOT(showNewGaussianData(GaussianScore)));
00054
00055 QString title;
00056 title = i18n("Location %1: Top Gaussian (right-click for options)").arg(m_location->description());
00057 setCaption(title);
00058 }
00059 setBackgroundColor(black);
00060 resize(350, 200);
00061 setMinimumSize(150, 100);
00062
00063 dataLoaded = false;
00064
00065
00066 if(m_location)
00067 showNewGaussianData(m_location->gaussianScore());
00068 }
00069
00070
00071 void GaussianPlot::paintWidget(QPaintDevice* pd)
00072 {
00073 QPainter p;
00074
00075 SetiGraph::paintWidget(pd);
00076 p.begin(pd);
00077 p.translate(0, rect().bottom());
00078 if(dataLoaded)
00079 drawCurve(fitData, SetiGraph::Lines, white, &p);
00080 p.end();
00081 }
00082
00083
00084 void GaussianPlot::calculateFitData()
00085 {
00086 double ratio = FITSIZE/64.0;
00087 for(int i=0;i<FITSIZE;i++)
00088 {
00089 fitData[i] = gaussian.true_mean +
00090 gaussian.power*exp(-((i/ratio)-gaussian.fft_index)*((i/ratio)-gaussian.fft_index)/
00091 (gaussian.sigma*gaussian.sigma));
00092 }
00093 }
00094
00095
00096 void GaussianPlot::showNewGaussianData(GaussianScore score)
00097 {
00098 gaussian = score;
00099 setCurve((const double*)gaussian.data, 64);
00100
00101
00102 QString it;
00103 it.sprintf("power: %f\n"
00104 "mean : %f\n"
00105 "sigma : %f\n"
00106 "fit : %f\n"
00107 "score : %f",
00108 gaussian.power,
00109 gaussian.true_mean,
00110 gaussian.sigma,
00111 gaussian.chisq,
00112 gaussian.score
00113 );
00114 setInfoText(it);
00115
00116 if(fitData.size() != FITSIZE) fitData.resize(FITSIZE);
00117 calculateFitData();
00118 dataLoaded = true;
00119 repaint();
00120 }
00121
00122 #include "gaussianplot.moc"
This file is part of the documentation for Ksetiwatch API Version 2.6.1.