Home

Download

Features

Screenshots

Handbook

Browse Source

Authors

SourceForge.net Logo
Hosted by SourceForge.net

OSI Certified


Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   Related Pages   Search  

densityplot.cpp

00001 /***************************************************************************
00002                           densityplot.cpp  -  description
00003                              -------------------
00004     begin                : Sat Feb 15 2003
00005     copyright            : (C) 2002-03 by Fungmeista
00006     email                : mizunoami44@users.sourceforge.net
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
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     //we need to find the value of the expression with the greatest absolute value for calculating the color
00048         //... while looping through and getting values
00049         //they are saved to speed things up in the values[] array                                
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