You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.8 KiB

  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. #ifndef MANDELBROT_H
  10. #define MANDELBROT_H
  11. #include <Eigen/Core>
  12. #include <QtGui/QApplication>
  13. #include <QtGui/QWidget>
  14. #include <QtCore/QThread>
  15. class MandelbrotWidget;
  16. class MandelbrotThread : public QThread
  17. {
  18. friend class MandelbrotWidget;
  19. MandelbrotWidget *widget;
  20. long long total_iter;
  21. int id, max_iter;
  22. bool single_precision;
  23. public:
  24. MandelbrotThread(MandelbrotWidget *w, int i) : widget(w), id(i) {}
  25. void run();
  26. template<typename Real> void render(int img_width, int img_height);
  27. };
  28. class MandelbrotWidget : public QWidget
  29. {
  30. Q_OBJECT
  31. friend class MandelbrotThread;
  32. Eigen::Vector2d center;
  33. double xradius;
  34. int size;
  35. unsigned char *buffer;
  36. QPoint lastpos;
  37. int draft;
  38. MandelbrotThread **threads;
  39. int threadcount;
  40. protected:
  41. void resizeEvent(QResizeEvent *);
  42. void paintEvent(QPaintEvent *);
  43. void mousePressEvent(QMouseEvent *event);
  44. void mouseMoveEvent(QMouseEvent *event);
  45. public:
  46. MandelbrotWidget() : QWidget(), center(0,0), xradius(2),
  47. size(0), buffer(0), draft(16)
  48. {
  49. setAutoFillBackground(false);
  50. threadcount = QThread::idealThreadCount();
  51. threads = new MandelbrotThread*[threadcount];
  52. for(int th = 0; th < threadcount; th++) threads[th] = new MandelbrotThread(this, th);
  53. }
  54. ~MandelbrotWidget()
  55. {
  56. if(buffer) delete[]buffer;
  57. for(int th = 0; th < threadcount; th++) delete threads[th];
  58. delete[] threads;
  59. }
  60. };
  61. #endif // MANDELBROT_H