mandelbrot.h
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2008 Benoit Jacob <jacob.benoit.1@gmail.com>
00005 //
00006 // Eigen is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 3 of the License, or (at your option) any later version.
00010 //
00011 // Alternatively, you can redistribute it and/or
00012 // modify it under the terms of the GNU General Public License as
00013 // published by the Free Software Foundation; either version 2 of
00014 // the License, or (at your option) any later version.
00015 //
00016 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00017 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00018 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00019 // GNU General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License and a copy of the GNU General Public License along with
00023 // Eigen. If not, see <http://www.gnu.org/licenses/>.
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


libicr
Author(s): Robert Krug
autogenerated on Mon Jan 6 2014 11:32:59