Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef MANDELBROT_H
00026 #define MANDELBROT_H
00027
00028 #include <Eigen/Core>
00029 #include <QtGui/QApplication>
00030 #include <QtGui/QWidget>
00031 #include <QtCore/QThread>
00032
00033 class MandelbrotWidget;
00034
00035 class MandelbrotThread : public QThread
00036 {
00037 friend class MandelbrotWidget;
00038 MandelbrotWidget *widget;
00039 long long total_iter;
00040 int id, max_iter;
00041 bool single_precision;
00042
00043 public:
00044 MandelbrotThread(MandelbrotWidget *w, int i) : widget(w), id(i) {}
00045 void run();
00046 template<typename Real> void render(int img_width, int img_height);
00047 };
00048
00049 class MandelbrotWidget : public QWidget
00050 {
00051 Q_OBJECT
00052
00053 friend class MandelbrotThread;
00054 Eigen::Vector2d center;
00055 double xradius;
00056 int size;
00057 unsigned char *buffer;
00058 QPoint lastpos;
00059 int draft;
00060 MandelbrotThread **threads;
00061 int threadcount;
00062
00063 protected:
00064 void resizeEvent(QResizeEvent *);
00065 void paintEvent(QPaintEvent *);
00066 void mousePressEvent(QMouseEvent *event);
00067 void mouseMoveEvent(QMouseEvent *event);
00068
00069 public:
00070 MandelbrotWidget() : QWidget(), center(0,0), xradius(2),
00071 size(0), buffer(0), draft(16)
00072 {
00073 setAutoFillBackground(false);
00074 threadcount = QThread::idealThreadCount();
00075 threads = new MandelbrotThread*[threadcount];
00076 for(int th = 0; th < threadcount; th++) threads[th] = new MandelbrotThread(this, th);
00077 }
00078 ~MandelbrotWidget()
00079 {
00080 if(buffer) delete[]buffer;
00081 for(int th = 0; th < threadcount; th++) delete threads[th];
00082 delete[] threads;
00083 }
00084 };
00085
00086 #endif // MANDELBROT_H