00001
00002
00003
00004
00005
00006
00007 #include "FittingCurveCoefficients.h"
00008 #include "FittingCurve.h"
00009 #include "Logger.h"
00010 #include <qmath.h>
00011 #include <QPainterPath>
00012 #include <QPen>
00013 #include "Transformation.h"
00014
00015 FittingCurve::FittingCurve (const FittingCurveCoefficients &fittingCoef,
00016 double xMin,
00017 double xMax,
00018 bool isLogXTheta,
00019 bool isLogYRadius,
00020 const Transformation &transformation)
00021 {
00022 const int NUM_POINTS = 1000;
00023 const double Z_LINE = 500;
00024
00025 setZValue (Z_LINE);
00026 setPen (QPen (QColor (Qt::red)));
00027
00028 QPainterPath path;
00029
00030 if (transformation.transformIsDefined()) {
00031
00032 for (int i = 0; i < NUM_POINTS; i++) {
00033
00034
00035 double s = (double) i / (double) (NUM_POINTS - 1);
00036 double x = xMin + s * (xMax - xMin);
00037 double y = yFromCoefficientsAndX (fittingCoef,
00038 x);
00039
00040
00041
00042 if (isLogXTheta) {
00043 x = qPow (10.0, x);
00044 }
00045 if (isLogYRadius) {
00046 y = qPow (10.0, y);
00047 }
00048
00049
00050 QPointF posGraph (x, y);
00051 QPointF posScreen;
00052 transformation.transformRawGraphToScreen (posGraph,
00053 posScreen);
00054
00055
00056 if (i == 0) {
00057 path.moveTo (posScreen);
00058 } else {
00059 path.lineTo (posScreen);
00060 }
00061 }
00062 }
00063
00064 setPath (path);
00065 }
00066
00067 FittingCurve::~FittingCurve()
00068 {
00069 }
00070
00071 double FittingCurve::yFromCoefficientsAndX (const FittingCurveCoefficients &fittingCoef,
00072 double x) const
00073 {
00074 double sum = 0;
00075
00076 for (int order = 0; order < fittingCoef.size(); order++) {
00077 sum += fittingCoef [order] * qPow (x, order);
00078 }
00079
00080 return sum;
00081 }