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;
39 unsigned char *
const buffer = widget->buffer;
40 const double xradius = widget->xradius;
41 const double yradius = xradius * img_height / img_width;
44 Vector2 start(widget->center.x() - widget->xradius, widget->center.y() - yradius);
45 Vector2
step(2*widget->xradius/img_width, 2*yradius/img_height);
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++)
98 buffer[4*(pix+
i)] = 255*pix_iter[
i]/max_iter;
99 buffer[4*(pix+
i)+1] = 0;
100 buffer[4*(pix+
i)+2] = 0;
105 for(
int x = alignedWidth;
x < img_width;
x++, pix++)
106 buffer[4*pix] = buffer[4*pix+1] = buffer[4*pix+2] = 0;
113 setTerminationEnabled(
true);
114 double resolution = widget->xradius*2/widget->width();
116 if(resolution < 1
e-4
f) max_iter += 128 * ( - 4 -
std::log10(resolution));
117 int img_width = widget->width()/widget->draft;
118 int img_height = widget->height()/widget->draft;
119 single_precision = resolution > 1
e-7
f;
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);
145 float speed = elapsed ?
float(total_iter)*1000/
elapsed : 0;
146 max_speed =
std::max(max_speed, speed);
147 std::cout << threadcount <<
" threads, " 148 << elapsed <<
" ms, " 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" internal::packet_traits< Scalar >::type Packet
def step(data, isam, result, truth, currPoseIndex)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const ArgReturnType arg() const
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
int main(int argc, char *argv[])
EIGEN_DEVICE_FUNC const Log10ReturnType log10() const
void render(int img_width, int img_height)
General-purpose arrays with easy API for coefficient-wise operations.
internal::nested_eval< T, 1 >::type eval(const T &xpr)
The matrix class, also used for vectors and row-vectors.
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x