mandel.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. Copyright (C) 2010 Matthias Kretz <kretz@kde.org>
  3. Permission to use, copy, modify, and distribute this software
  4. and its documentation for any purpose and without fee is hereby
  5. granted, provided that the above copyright notice appear in all
  6. copies and that both that the copyright notice and this
  7. permission notice and warranty disclaimer appear in supporting
  8. documentation, and that the name of the author not be used in
  9. advertising or publicity pertaining to distribution of the
  10. software without specific, written prior permission.
  11. The author disclaim all warranties with regard to this
  12. software, including all implied warranties of merchantability
  13. and fitness. In no event shall the author be liable for any
  14. special, indirect or consequential damages or any damages
  15. whatsoever resulting from loss of use, data or profits, whether
  16. in an action of contract, negligence or other tortious action,
  17. arising out of or in connection with the use or performance of
  18. this software.
  19. */
  20. #include <QImage>
  21. #include <QMutex>
  22. #include <QSize>
  23. #include <QThread>
  24. #include <QWaitCondition>
  25. #include <complex>
  26. enum MandelImpl {
  27. VcImpl, ScalarImpl
  28. };
  29. class MandelBase : public QThread
  30. {
  31. Q_OBJECT
  32. public:
  33. void brot(const QSize &size, float x, float y, float scale);
  34. protected:
  35. MandelBase(QObject* _parent = 0);
  36. ~MandelBase();
  37. void emitImage(const QImage &image, quint64 cycles) { emit ready(image, cycles); }
  38. void run();
  39. virtual void mandelMe(QImage &image, float x, float y, float scale, int maxIterations) = 0;
  40. inline bool restart() const { return m_restart; }
  41. signals:
  42. void ready(const QImage &image, quint64 cycles);
  43. private:
  44. QMutex m_mutex;
  45. QWaitCondition m_wait;
  46. QSize m_size;
  47. float m_x, m_y, m_scale;
  48. bool m_restart;
  49. bool m_abort;
  50. };
  51. template<MandelImpl Impl>
  52. class Mandel : public MandelBase
  53. {
  54. public:
  55. Mandel(QObject *_parent = 0);
  56. protected:
  57. void mandelMe(QImage &image, float x, float y, float scale, int maxIterations);
  58. };