12 #include<QtGui/QPainter>
13 #include<QtGui/QImage>
14 #include<QtGui/QMouseEvent>
15 #include<QtCore/QTime>
19 if(
size < width() * height())
21 std::cout <<
"reallocate buffer" << std::endl;
22 size = width() * height();
38 const int alignedWidth = (img_width/packetSize)*packetSize;
41 const double yradius = xradius * img_height / img_width;
48 for(
int y =
id;
y < img_height;
y += threadcount)
50 int pix =
y * img_width;
56 Packet pzi_start, pci_start;
57 for(
int i = 0;
i < packetSize;
i++) pzi_start[
i] = pci_start[
i] = start.
y() +
y *
step.y();
59 for(
int x = 0;
x < alignedWidth;
x += packetSize, pix += packetSize)
61 Packet pcr, pci = pci_start, pzr, pzi = pzi_start, pzr_buf;
62 for(
int i = 0;
i < packetSize;
i++) pzr[
i] = pcr[
i] = start.
x() + (
x+
i) *
step.x();
68 Packeti pix_iter = Packeti::Zero(),
77 pzr -= pzi.square(); \
79 pzi = (2*pzr_buf)*pzi; \
83 pix_dont_diverge = ((pzr.square() + pzi.square())
85 <= Packet::Constant(4))
88 .
template cast<int>();
96 for(
int i = 0;
i < packetSize;
i++)
105 for(
int x = alignedWidth;
x < img_width;
x++, pix++)
113 setTerminationEnabled(
true);
122 render<float>(img_width, img_height);
124 render<double>(img_width, img_height);
129 static float max_speed = 0;
130 long long total_iter = 0;
135 threads[th]->start(QThread::LowPriority);
146 max_speed =
std::max(max_speed, speed);
149 << speed <<
" iters/s (max " << max_speed <<
")" << std::endl;
153 setWindowTitle(QString(
"resolution ")+QString::number(
xradius*2/width(),
'e', 2)
154 +QString(
", %1 iterations per pixel, ").
arg(
threads[0]->max_iter)
155 +(
threads[0]->single_precision ? QString(
"single ") : QString(
"double "))
156 +QString(
"precision, ")
157 +(packetSize==1 ? QString(
"no vectorization")
158 : QString(
"vectorized (%1 per packet)").
arg(packetSize)));
162 QPainter painter(
this);
163 painter.drawImage(QPoint(0, 0), image.scaled(width(), height()));
168 setWindowTitle(QString(
"recomputing at 1/%1 resolution...").
arg(
draft));
175 if( event->buttons() & Qt::LeftButton )
178 double yradius =
xradius * height() / width();
179 center = Eigen::Vector2d(
center.x() + (event->pos().x() - width()/2) *
xradius * 2 / width(),
180 center.y() + (event->pos().y() - height()/2) * yradius * 2 / height());
192 if( event->buttons() & Qt::LeftButton )
194 double t = 1 + 5 * double(
delta.y()) / height();
205 int main(
int argc,
char *argv[])
207 QApplication app(argc, argv);
213 #include "mandelbrot.moc"