diff options
author | Benoit Jacob <jacob.benoit.1@gmail.com> | 2008-06-30 07:33:08 +0000 |
---|---|---|
committer | Benoit Jacob <jacob.benoit.1@gmail.com> | 2008-06-30 07:33:08 +0000 |
commit | cacf986a7f13e6a655a3152a8c2dabe071e49554 (patch) | |
tree | 62bf4479af8d55a904b0ad690dedeaa3aea3cf7d /demos | |
parent | 37a50fa5268d6d408c74ab2d380785ce07ec302c (diff) |
- use double precision to store the position / zoom / other stuff
- some temporary fix to get a +50% improvement from vectorization until
we have vectorisation for comparisons and redux
Diffstat (limited to 'demos')
-rw-r--r-- | demos/mandelbrot/mandelbrot.cpp | 18 | ||||
-rw-r--r-- | demos/mandelbrot/mandelbrot.h | 4 |
2 files changed, 12 insertions, 10 deletions
diff --git a/demos/mandelbrot/mandelbrot.cpp b/demos/mandelbrot/mandelbrot.cpp index 7d86246a4..f1be9e560 100644 --- a/demos/mandelbrot/mandelbrot.cpp +++ b/demos/mandelbrot/mandelbrot.cpp @@ -21,9 +21,10 @@ template<typename Real> int MandelbrotWidget::render(int max_iter, int img_width typedef Eigen::Matrix<Real, packetSize, 1> Packet; // wrap a Packet as a vector int alignedWidth = (img_width/packetSize)*packetSize; - float yradius = xradius * img_height / img_width; - Eigen::Vector2f start(center.x() - xradius, center.y() - yradius); - Eigen::Vector2f step(2*xradius/img_width, 2*yradius/img_height); + double yradius = xradius * img_height / img_width; + typedef Eigen::Matrix<Real, 2, 1> Vector2; + Vector2 start(center.x() - xradius, center.y() - yradius); + Vector2 step(2*xradius/img_width, 2*yradius/img_height); int pix = 0, total_iter = 0; for(int y = 0; y < img_height; y++) @@ -53,6 +54,7 @@ template<typename Real> int MandelbrotWidget::render(int max_iter, int img_width pzi = 2 * pzr_buf.cwiseProduct(pzi) + pci; } pix_dont_diverge = (pzr.cwiseAbs2() + pzi.cwiseAbs2()) + .eval() // temporary fix for lack of vectorizability of what follows .cwiseLessThan(Packet::constant(4)) .template cast<int>(); pix_iter += 4 * pix_dont_diverge; @@ -65,7 +67,7 @@ template<typename Real> int MandelbrotWidget::render(int max_iter, int img_width for(int i = 0; i < packetSize; i++) { - buffer[4*(pix+i)] = float(pix_iter[i])*255/max_iter; + buffer[4*(pix+i)] = pix_iter[i]*255/max_iter; buffer[4*(pix+i)+1] = 0; buffer[4*(pix+i)+2] = 0; } @@ -80,7 +82,7 @@ template<typename Real> int MandelbrotWidget::render(int max_iter, int img_width void MandelbrotWidget::paintEvent(QPaintEvent *) { - float resolution = xradius*2/width(); + double resolution = xradius*2/width(); int max_iter = 64; if(resolution < 1e-4f) max_iter += 32 * ( - 4 - std::log10(resolution)); max_iter = (max_iter/4)*4; @@ -131,8 +133,8 @@ void MandelbrotWidget::mousePressEvent(QMouseEvent *event) if( event->buttons() & Qt::LeftButton ) { lastpos = event->pos(); - float yradius = xradius * height() / width(); - center = Eigen::Vector2f(center.x() + (event->pos().x() - width()/2) * xradius * 2 / width(), + double yradius = xradius * height() / width(); + center = Eigen::Vector2d(center.x() + (event->pos().x() - width()/2) * xradius * 2 / width(), center.y() + (event->pos().y() - height()/2) * yradius * 2 / height()); draft = 16; update(); @@ -145,7 +147,7 @@ void MandelbrotWidget::mouseMoveEvent(QMouseEvent *event) lastpos = event->pos(); if( event->buttons() & Qt::LeftButton ) { - float t = 1 + 5 * float(delta.y()) / height(); + double t = 1 + 5 * double(delta.y()) / height(); if(t < 0.5) t = 0.5; if(t > 2) t = 2; xradius *= t; diff --git a/demos/mandelbrot/mandelbrot.h b/demos/mandelbrot/mandelbrot.h index ea2ee6084..23df7c9dd 100644 --- a/demos/mandelbrot/mandelbrot.h +++ b/demos/mandelbrot/mandelbrot.h @@ -9,8 +9,8 @@ class MandelbrotWidget : public QWidget { Q_OBJECT - Eigen::Vector2f center; - float xradius; + Eigen::Vector2d center; + double xradius; int size; unsigned char *buffer; QPoint lastpos; |