MandelbrotWidget Class Reference

#include <mandelbrot.h>

+ Inheritance diagram for MandelbrotWidget:

Public Member Functions

 MandelbrotWidget ()
 
 ~MandelbrotWidget ()
 

Protected Member Functions

void resizeEvent (QResizeEvent *)
 
void paintEvent (QPaintEvent *)
 
void mousePressEvent (QMouseEvent *event)
 
void mouseMoveEvent (QMouseEvent *event)
 

Private Attributes

Eigen::Vector2d center
 
double xradius
 
int size
 
unsigned charbuffer
 
QPoint lastpos
 
int draft
 
MandelbrotThread ** threads
 
int threadcount
 

Friends

class MandelbrotThread
 

Constructor & Destructor Documentation

◆ MandelbrotWidget()

MandelbrotWidget::MandelbrotWidget ( )
inline
54  : 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  }
Definition: mandelbrot.h:20
Eigen::Vector2d center
Definition: mandelbrot.h:38
MandelbrotThread ** threads
Definition: mandelbrot.h:44
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

References MandelbrotThread, threadcount, and threads.

◆ ~MandelbrotWidget()

MandelbrotWidget::~MandelbrotWidget ( )
inline
60  {
61  if (buffer) delete[] buffer;
62  for (int th = 0; th < threadcount; th++) delete threads[th];
63  delete[] threads;
64  }

References buffer, threadcount, and threads.

Member Function Documentation

◆ mouseMoveEvent()

void MandelbrotWidget::mouseMoveEvent ( QMouseEvent *  event)
protected
175  {
176  QPoint delta = event->pos() - lastpos;
177  lastpos = event->pos();
178  if (event->buttons() & Qt::LeftButton) {
179  double t = 1 + 5 * double(delta.y()) / height();
180  if (t < 0.5) t = 0.5;
181  if (t > 2) t = 2;
182  xradius *= t;
183  draft = 16;
184  for (int th = 0; th < threadcount; th++) threads[th]->terminate();
185  update();
186  }
187 }
QPoint lastpos
Definition: mandelbrot.h:42
double height(const double &x)
Height of domain.
Definition: simple_spine_channel.cc:429
int delta
Definition: MultiOpt.py:96
t
Definition: plotPSD.py:36

References MultiOpt::delta, draft, Global_Physical_Variables::height(), lastpos, plotPSD::t, threadcount, threads, and xradius.

◆ mousePressEvent()

void MandelbrotWidget::mousePressEvent ( QMouseEvent *  event)
protected
163  {
164  if (event->buttons() & Qt::LeftButton) {
165  lastpos = event->pos();
166  double yradius = xradius * height() / width();
167  center = Eigen::Vector2d(center.x() + (event->pos().x() - width() / 2) * xradius * 2 / width(),
168  center.y() + (event->pos().y() - height() / 2) * yradius * 2 / height());
169  draft = 16;
170  for (int th = 0; th < threadcount; th++) threads[th]->terminate();
171  update();
172  }
173 }

References center, draft, Global_Physical_Variables::height(), lastpos, threadcount, threads, and xradius.

◆ paintEvent()

void MandelbrotWidget::paintEvent ( QPaintEvent *  )
protected
125  {
126  static float max_speed = 0;
127  long long total_iter = 0;
128 
129  QTime time;
130  time.start();
131  for (int th = 0; th < threadcount; th++) threads[th]->start(QThread::LowPriority);
132  for (int th = 0; th < threadcount; th++) {
133  threads[th]->wait();
134  total_iter += threads[th]->total_iter;
135  }
136  int elapsed = time.elapsed();
137 
138  if (draft == 1) {
139  float speed = elapsed ? float(total_iter) * 1000 / elapsed : 0;
140  max_speed = std::max(max_speed, speed);
141  std::cout << threadcount << " threads, " << elapsed << " ms, " << speed << " iters/s (max " << max_speed << ")"
142  << std::endl;
144  : int(Eigen::internal::packet_traits<double>::size);
145  setWindowTitle(
146  QString("resolution ") + QString::number(xradius * 2 / width(), 'e', 2) +
147  QString(", %1 iterations per pixel, ").arg(threads[0]->max_iter) +
148  (threads[0]->single_precision ? QString("single ") : QString("double ")) + QString("precision, ") +
149  (packetSize == 1 ? QString("no vectorization") : QString("vectorized (%1 per packet)").arg(packetSize)));
150  }
151 
152  QImage image(buffer, width() / draft, height() / draft, QImage::Format_RGB32);
153  QPainter painter(this);
154  painter.drawImage(QPoint(0, 0), image.scaled(width(), height()));
155 
156  if (draft > 1) {
157  draft /= 2;
158  setWindowTitle(QString("recomputing at 1/%1 resolution...").arg(draft));
159  update();
160  }
161 }
bool single_precision
Definition: mandelbrot.h:25
long long total_iter
Definition: mandelbrot.h:23
#define max(a, b)
Definition: datatypes.h:23
return int(ret)+1
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
Definition: Eigen_Colamd.h:49
void start(const unsigned &i)
(Re-)start i-th timer
Definition: oomph_utilities.cc:243
Definition: GenericPacketMath.h:108

References buffer, draft, Global_Physical_Variables::height(), int(), max, MandelbrotThread::single_precision, oomph::CumulativeTimings::start(), threadcount, threads, MandelbrotThread::total_iter, and xradius.

◆ resizeEvent()

void MandelbrotWidget::resizeEvent ( QResizeEvent *  )
protected
17  {
18  if (size < width() * height()) {
19  std::cout << "reallocate buffer" << std::endl;
20  size = width() * height();
21  if (buffer) delete[] buffer;
22  buffer = new unsigned char[4 * size];
23  }
24 }

References buffer, Global_Physical_Variables::height(), and size.

Friends And Related Function Documentation

◆ MandelbrotThread

friend class MandelbrotThread
friend

Referenced by MandelbrotWidget().

Member Data Documentation

◆ buffer

unsigned char* MandelbrotWidget::buffer
private

◆ center

Eigen::Vector2d MandelbrotWidget::center
private

◆ draft

int MandelbrotWidget::draft
private

◆ lastpos

QPoint MandelbrotWidget::lastpos
private

Referenced by mouseMoveEvent(), and mousePressEvent().

◆ size

int MandelbrotWidget::size
private

Referenced by resizeEvent().

◆ threadcount

◆ threads

MandelbrotThread** MandelbrotWidget::threads
private

◆ xradius


The documentation for this class was generated from the following files: