mandelbrot.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008 Benoit Jacob <jacob.benoit.1@gmail.com>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #ifndef MANDELBROT_H
11 #define MANDELBROT_H
12 
13 #include <Eigen/Core>
14 #include <QtGui/QApplication>
15 #include <QtGui/QWidget>
16 #include <QtCore/QThread>
17 
18 class MandelbrotWidget;
19 
20 class MandelbrotThread : public QThread {
21  friend class MandelbrotWidget;
23  long long total_iter;
24  int id, max_iter;
26 
27  public:
29  void run();
30  template <typename Real>
31  void render(int img_width, int img_height);
32 };
33 
34 class MandelbrotWidget : public QWidget {
35  Q_OBJECT
36 
37  friend class MandelbrotThread;
38  Eigen::Vector2d center;
39  double xradius;
40  int size;
41  unsigned char *buffer;
42  QPoint lastpos;
43  int draft;
46 
47  protected:
48  void resizeEvent(QResizeEvent *);
49  void paintEvent(QPaintEvent *);
50  void mousePressEvent(QMouseEvent *event);
51  void mouseMoveEvent(QMouseEvent *event);
52 
53  public:
54  MandelbrotWidget() : QWidget(), center(0, 0), xradius(2), size(0), buffer(0), draft(16) {
55  setAutoFillBackground(false);
56  threadcount = QThread::idealThreadCount();
58  for (int th = 0; th < threadcount; th++) threads[th] = new MandelbrotThread(this, th);
59  }
61  if (buffer) delete[] buffer;
62  for (int th = 0; th < threadcount; th++) delete threads[th];
63  delete[] threads;
64  }
65 };
66 
67 #endif // MANDELBROT_H
int i
Definition: BiCGSTAB_step_by_step.cpp:9
RowVector3d w
Definition: Matrix_resize_int.cpp:3
Definition: mandelbrot.h:20
int id
Definition: mandelbrot.h:24
void run()
Definition: mandelbrot.cpp:110
MandelbrotWidget * widget
Definition: mandelbrot.h:22
void render(int img_width, int img_height)
Definition: mandelbrot.cpp:36
int max_iter
Definition: mandelbrot.h:24
bool single_precision
Definition: mandelbrot.h:25
long long total_iter
Definition: mandelbrot.h:23
MandelbrotThread(MandelbrotWidget *w, int i)
Definition: mandelbrot.h:28
Definition: mandelbrot.h:34
~MandelbrotWidget()
Definition: mandelbrot.h:60
QPoint lastpos
Definition: mandelbrot.h:42
void mouseMoveEvent(QMouseEvent *event)
Definition: mandelbrot.cpp:175
MandelbrotWidget()
Definition: mandelbrot.h:54
Eigen::Vector2d center
Definition: mandelbrot.h:38
void paintEvent(QPaintEvent *)
Definition: mandelbrot.cpp:125
MandelbrotThread ** threads
Definition: mandelbrot.h:44
void mousePressEvent(QMouseEvent *event)
Definition: mandelbrot.cpp:163
void resizeEvent(QResizeEvent *)
Definition: mandelbrot.cpp:17
double xradius
Definition: mandelbrot.h:39
int size
Definition: mandelbrot.h:40
int threadcount
Definition: mandelbrot.h:45
unsigned char * buffer
Definition: mandelbrot.h:41
friend class MandelbrotThread
Definition: mandelbrot.h:37
int draft
Definition: mandelbrot.h:43