Messiah_of_Death
22.05.2005, 19:09
Tagchen,
ich hab da kleines Problem bei "Optimierungen".
Also der Algorithmus sollte hinlänglich bekannt sein.
Ich laufe y - Zeilen runter und da drinne x - Spalten entlang, die Pixel setzt man bei der Spalteniteration. Dort ist eine weitere Iteration welche N - mal ausgeführt wird, bis sie auf einen Grenzwert kommt.. dann wird der Pixel gesetzt wenn die Iteration nicht unterbrochen wurde ( schwarz/weis ). Je größer N desto detailierter (war jetzt mal grob :rolleyes: )
Naja gut, Normalfall is ja 1 Pixel pro Iteration der untersucht würde, das wäre ja im "worst-case" N * x * y , dauert auch bei entsprechendem N auch lange
Dachte ich versuch mal ne Optimierung:
man nehme 4 Pixel pro Iteration.
Schön und gut, klappt auch recht schnell, doch eins wundert mich:
das ganze Bild wird auf einmal total kantig, verwaschen .. sieht halt nimmer toll aus.
Ich dachte der Algorithmus wäre nur indirekt abhängig.
Ich hab auch extra pro Pixel, extra xi[1-4] bzw. yi[1-4] -Variablen angelegt und noch anderes ( siehe Code ).
Versteh echt grad net wo mein Fehler ist ... :confused: :confused: :confused:
Dabei sollte das sogar funktionieren ( wurde theoretisch bei SSE, MMX Optimierungen angesprochen)..
Auch wenn's nicht die endgültig beste Optimierung ist, wäre ich jedenfalls für ne kleinen Anstoß dankbar :)
Danke
Hier der Code ( basierend auf QT )
#include <qapplication.h>
#include <qimage.h>
#include <stdlib.h>
#include <qcanvas.h>
#include <qcolor.h>
#include <math.h>
int main(int argc,char*argv[])
{
QApplication a(argc,argv);
QCanvas canvas(640,480);
QImage image(640,480, 32);
QPixmap pm;//("calc.png");
image.fill( qRgb(255,255,255) );
//image.setPixel( 1, 1, qRgb(0,255,0) );
double xi, yi,
ynext1 = 0, xnext1 = 0, anext1,
ynext2 = 0, xnext2 = 0, anext2,
ynext3 = 0, xnext3 = 0, anext3,
ynext4 = 0, xnext4 = 0, anext4,
xi1 = 0, xi2 = 0, xi3 = 0, xi4 = 0,
yi1 = 0, yi2 = 0, yi3 = 0, yi4 = 0,
x0 = 0, y0 = 0,
x1, y1,
leftLime = -2.7, upperLime = -1.5,
step = 0.00525;
int maxIter = 1000;
bool isn1, isn2, isn3, isn4;
isn1 = isn2 = isn3 = isn4 = false;
y1 = upperLime;
int i = 0, x = 0;
uint *colors = new uint[12];
for ( int q = 0; q < 12; q++)
colors[q] = qRgb(50+(q*12), 25+(q*4), 155+(q*8) );
for ( int y = 0; y < 480; y++)
{
x1 = leftLime; x = 0;
while( x < 640 )
{
xi1 = x0; yi1 = y0;
xi2 = x0; yi2 = y0;
xi3 = x0; yi3 = y0;
xi4 = x0; yi4 = y0;
for ( i = 0; i < maxIter; i++)
{
if ( ! isn1 )
{
xnext1 = (xi1 * xi1) - (yi1 * yi1) + x1;
ynext1 = 2. * xi1 * yi1 + y1;
anext1 = ( xnext1 * xnext1 ) + (ynext1 * ynext1);
}
if ( ! isn2 )
{
xnext2 = (xi2 * xi2) - (yi2 * yi2) + (x1 + step);
ynext2 = 2. * xi2 * yi2 + y1;
anext2 = ( xnext2 * xnext2 ) + (ynext2 * ynext2);
}
if ( ! isn3 )
{
xnext3 = (xi3 * xi3) - (yi3 * yi3) + (x1+step*2.);
ynext3 = 2. * xi3 * yi3 + y1;
anext3 = ( xnext3 * xnext3 ) + (ynext3 * ynext3);
}
if ( ! isn4 )
{
xnext4 = (xi4 * xi4) - (yi4 * yi4) + (x1+step*3.);
ynext4 = 2. * xi4 * yi4 + y1;
anext4 = ( xnext4 * xnext4 ) + (ynext4 * ynext4);
}
if ( anext1 > 4 )
{
isn1 = true;
image.setPixel( x, y, colors[i % 12] );
}
if ( anext2 > 4 )
{
isn2 = true;
image.setPixel( x+1, y, colors[i % 12] );
}
if ( anext3 > 4 )
{
isn3 = true;
image.setPixel( x+2, y, colors[i % 12] );
}
if ( anext4 > 4 )
{
isn4 = true;
image.setPixel( x+3, y, colors[i % 12] );
}
if ( isn1 && isn2 && isn3 && isn4 )
break;
xi1 = xnext1; yi1 = ynext1;
xi2 = xnext2; yi2 = ynext2;
xi3 = xnext3; yi3 = ynext3;
xi4 = xnext4; yi4 = ynext4;
}
if ( ! isn1 )
image.setPixel( x, y, colors[i % 12] );
if ( ! isn2 )
image.setPixel( x+1, y, colors[i % 12] );
if ( ! isn3 )
image.setPixel( x+2, y, colors[i % 12] );
if ( ! isn4 )
image.setPixel( x+3, y, colors[i % 12] );
isn1 = isn2 = isn3 = isn4 = false;
x1 = x1 + step * 4.;
x += 4;
}
y1 += step;
}
pm = image;
canvas.setBackgroundPixmap( pm );
canvas.setChanged( QRect(0,0,640,480) );
QCanvasView cview(&canvas);
a.setMainWidget(&cview);
cview.show();
return a.exec();
}
ich hab da kleines Problem bei "Optimierungen".
Also der Algorithmus sollte hinlänglich bekannt sein.
Ich laufe y - Zeilen runter und da drinne x - Spalten entlang, die Pixel setzt man bei der Spalteniteration. Dort ist eine weitere Iteration welche N - mal ausgeführt wird, bis sie auf einen Grenzwert kommt.. dann wird der Pixel gesetzt wenn die Iteration nicht unterbrochen wurde ( schwarz/weis ). Je größer N desto detailierter (war jetzt mal grob :rolleyes: )
Naja gut, Normalfall is ja 1 Pixel pro Iteration der untersucht würde, das wäre ja im "worst-case" N * x * y , dauert auch bei entsprechendem N auch lange
Dachte ich versuch mal ne Optimierung:
man nehme 4 Pixel pro Iteration.
Schön und gut, klappt auch recht schnell, doch eins wundert mich:
das ganze Bild wird auf einmal total kantig, verwaschen .. sieht halt nimmer toll aus.
Ich dachte der Algorithmus wäre nur indirekt abhängig.
Ich hab auch extra pro Pixel, extra xi[1-4] bzw. yi[1-4] -Variablen angelegt und noch anderes ( siehe Code ).
Versteh echt grad net wo mein Fehler ist ... :confused: :confused: :confused:
Dabei sollte das sogar funktionieren ( wurde theoretisch bei SSE, MMX Optimierungen angesprochen)..
Auch wenn's nicht die endgültig beste Optimierung ist, wäre ich jedenfalls für ne kleinen Anstoß dankbar :)
Danke
Hier der Code ( basierend auf QT )
#include <qapplication.h>
#include <qimage.h>
#include <stdlib.h>
#include <qcanvas.h>
#include <qcolor.h>
#include <math.h>
int main(int argc,char*argv[])
{
QApplication a(argc,argv);
QCanvas canvas(640,480);
QImage image(640,480, 32);
QPixmap pm;//("calc.png");
image.fill( qRgb(255,255,255) );
//image.setPixel( 1, 1, qRgb(0,255,0) );
double xi, yi,
ynext1 = 0, xnext1 = 0, anext1,
ynext2 = 0, xnext2 = 0, anext2,
ynext3 = 0, xnext3 = 0, anext3,
ynext4 = 0, xnext4 = 0, anext4,
xi1 = 0, xi2 = 0, xi3 = 0, xi4 = 0,
yi1 = 0, yi2 = 0, yi3 = 0, yi4 = 0,
x0 = 0, y0 = 0,
x1, y1,
leftLime = -2.7, upperLime = -1.5,
step = 0.00525;
int maxIter = 1000;
bool isn1, isn2, isn3, isn4;
isn1 = isn2 = isn3 = isn4 = false;
y1 = upperLime;
int i = 0, x = 0;
uint *colors = new uint[12];
for ( int q = 0; q < 12; q++)
colors[q] = qRgb(50+(q*12), 25+(q*4), 155+(q*8) );
for ( int y = 0; y < 480; y++)
{
x1 = leftLime; x = 0;
while( x < 640 )
{
xi1 = x0; yi1 = y0;
xi2 = x0; yi2 = y0;
xi3 = x0; yi3 = y0;
xi4 = x0; yi4 = y0;
for ( i = 0; i < maxIter; i++)
{
if ( ! isn1 )
{
xnext1 = (xi1 * xi1) - (yi1 * yi1) + x1;
ynext1 = 2. * xi1 * yi1 + y1;
anext1 = ( xnext1 * xnext1 ) + (ynext1 * ynext1);
}
if ( ! isn2 )
{
xnext2 = (xi2 * xi2) - (yi2 * yi2) + (x1 + step);
ynext2 = 2. * xi2 * yi2 + y1;
anext2 = ( xnext2 * xnext2 ) + (ynext2 * ynext2);
}
if ( ! isn3 )
{
xnext3 = (xi3 * xi3) - (yi3 * yi3) + (x1+step*2.);
ynext3 = 2. * xi3 * yi3 + y1;
anext3 = ( xnext3 * xnext3 ) + (ynext3 * ynext3);
}
if ( ! isn4 )
{
xnext4 = (xi4 * xi4) - (yi4 * yi4) + (x1+step*3.);
ynext4 = 2. * xi4 * yi4 + y1;
anext4 = ( xnext4 * xnext4 ) + (ynext4 * ynext4);
}
if ( anext1 > 4 )
{
isn1 = true;
image.setPixel( x, y, colors[i % 12] );
}
if ( anext2 > 4 )
{
isn2 = true;
image.setPixel( x+1, y, colors[i % 12] );
}
if ( anext3 > 4 )
{
isn3 = true;
image.setPixel( x+2, y, colors[i % 12] );
}
if ( anext4 > 4 )
{
isn4 = true;
image.setPixel( x+3, y, colors[i % 12] );
}
if ( isn1 && isn2 && isn3 && isn4 )
break;
xi1 = xnext1; yi1 = ynext1;
xi2 = xnext2; yi2 = ynext2;
xi3 = xnext3; yi3 = ynext3;
xi4 = xnext4; yi4 = ynext4;
}
if ( ! isn1 )
image.setPixel( x, y, colors[i % 12] );
if ( ! isn2 )
image.setPixel( x+1, y, colors[i % 12] );
if ( ! isn3 )
image.setPixel( x+2, y, colors[i % 12] );
if ( ! isn4 )
image.setPixel( x+3, y, colors[i % 12] );
isn1 = isn2 = isn3 = isn4 = false;
x1 = x1 + step * 4.;
x += 4;
}
y1 += step;
}
pm = image;
canvas.setBackgroundPixmap( pm );
canvas.setChanged( QRect(0,0,640,480) );
QCanvasView cview(&canvas);
a.setMainWidget(&cview);
cview.show();
return a.exec();
}