Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members Related Pages Search
densityplot.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "densityplot.h"
00019
00020 #include <cmath>
00021
00022 #include <qpainter.h>
00023
00024 #include "fungparser.h"
00025 #include "expression.h"
00026 #include "fungmath.h"
00027
00028 DensityPlot::DensityPlot ( QWidget *parent, const char *name ) : ExpressionGraph( parent, name )
00029 {
00030 onlyShowActive(true);
00031 }
00032
00033 DensityPlot::~DensityPlot()
00034 {
00035 }
00036
00037 void DensityPlot::drawExpression(QPainter *painter, Expression & expression)
00038 {
00039 FungParser *fp = expression.getParsedExpression(dependent_var());
00040
00041 QColor color = painter->pen().color();
00042
00043 double *values = new double[width()*height()];
00044 int i = 0;
00045 double extreme = 0;
00046
00047
00048
00049
00050 for (int x = 0; x < width(); x++)
00051 {
00052 for (int y = 0; y < height(); y++)
00053 {
00054 double d[] = {toGraphXCoord(x),toGraphYCoord(y),animatorValue()};
00055 values[i] = fp->Eval(d);
00056
00057 if ( fabs(values[i]) >= fabs(extreme) )
00058 extreme = values[i];
00059
00060 i++;
00061 }
00062 }
00063
00064 double alpha = (extreme == 0) ? 0 : 255 / fabs(extreme*2);
00065 int h, s, v; color.getHsv( h, s, v );
00066 i = 0;
00067 for (int x = 0; x < width(); x++)
00068 {
00069 for (int y = 0; y < height(); y++)
00070 {
00071 QColor c;
00072 c.setHsv( h, s, int(ROUND(255/2 + values[i] * alpha )) );
00073
00074 painter->setPen( c );
00075 painter->drawPoint(x,y);
00076
00077 i++;
00078 }
00079 }
00080
00081 delete[] values;
00082 }
00083
00084 int DensityPlot::setXYForTrace(const double mousex, const double mousey, double *x, double *y, Expression &)
00085 {
00086 *x = mousex;
00087 *y = mousey;
00088
00089 return 0;
00090 }
00091
00092 void DensityPlot::updateCoords()
00093 {
00094 if (isTracing())
00095 {
00096 FungParser *fp = getParsedCurrentExpression();
00097 double d[] = {getMouseX(),getMouseY(),animatorValue()};
00098 double z = fp->Eval(d);
00099
00100 emit activeCoordinateChanged( QString("x = %1").arg(getMouseX()),
00101 QString("y = %1").arg(getMouseY()),
00102 QString("z = %1").arg(z) );
00103 }
00104 else
00105 BasicGraph::updateCoords();
00106 }
00107
|