00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "networkagent.h"
00017 #include "fractale.h"
00018 #include "buddhabrot.h"
00019 #include "julia.h"
00020 #include "mandelbrot.h"
00021 #include "tricorn.h"
00022 #include "sharingan.h"
00023 #include "newton.h"
00024 #include "hexamandelbrot.h"
00025 #include "bateauenfeu.h"
00026
00027 #include "imagetiler.h"
00028 #include "imagecalculator.h"
00029 #include <iostream>
00030
00031 NetworkAgent::NetworkAgent(QVector<QVector<long> >& result, QSize resolution, QRectF window, bool isRandom, QString fractaleName, int offset, int iterations, int nbRandom, QString output, int step):result(result){
00032 QMutex mutex;
00033
00034 fractale *f = NULL;
00035 if (fractaleName == QString("buddha"))
00036 f = new buddhabrot(std::complex<float>(), iterations);
00037 else
00038 if (fractaleName == QString("mandel"))
00039 f = new mandelbrot(std::complex<float>(), iterations);
00040 else
00041 if (fractaleName == QString("newton"))
00042 f = new newton(std::complex<float>(), iterations);
00043 else
00044 if (fractaleName == QString("julia1"))
00045 f = new julia(std::complex<float>(.285f,0), iterations);
00046 else
00047 if (fractaleName == QString("julia1"))
00048 f = new julia(std::complex<float>(-0.038088f, 0.9754633f), iterations);
00049 else
00050 if (fractaleName == QString("tricorn"))
00051 f = new tricorn(std::complex<float>(), iterations);
00052 else
00053 if (fractaleName == QString("multibrot"))
00054 f = new hexamandelbrot(std::complex<float>(), iterations);
00055 else
00056 if (fractaleName == QString("sharingan"))
00057 f = new sharingan(std::complex<float>(), iterations);
00058 else
00059 if (fractaleName == QString("bateau"))
00060 f = new bateauEnFeu(std::complex<float>(), iterations);
00061 else
00062 throw 500;
00063
00064
00065 ImageTiler i(result, mutex, window, resolution, f, isRandom, nbRandom, offset, step, offset);
00066 i.run();
00067 i.wait();
00068
00069 QImage *image = new QImage(resolution, QImage::Format_RGB888);
00070
00071 for (int x = 0; x< resolution.width(); x++)
00072 for (int y=0; y<resolution.height(); y++)
00073 image->setPixel(x,y, ImageCalculator::intToRGBA(result[x][y]));
00074
00075 image->save(output);
00076 }
00077
00078 NetworkAgent::~NetworkAgent(){
00079
00080 }
00081
00082 int NetworkAgent::process(CommandLineArguments& parser){
00083 QSize resolution = parser.getResolution();
00084 if (resolution.width() <= 0)
00085 return 0;
00086 QRectF window = parser.getWindow();
00087 if (window.top() == 0)
00088 return 0;
00089 bool useRandom = parser.getAleatoire();
00090 int offset = parser.getOffset();
00091 if (offset < 0)
00092 return 0;
00093 int iterations = parser.getIterations();
00094 if (iterations < 0)
00095 return 0;
00096 int nbRandom = 0;
00097 if (useRandom)
00098 nbRandom = parser.getRandomCount();
00099
00100
00101 QString output = parser.getOutput();
00102 if (output == QString(""))
00103 output = "img.png";
00104
00105 QVector<QVector<long> > result;
00106
00107 for (int j=0; j<resolution.width(); j++){
00108 QVector<long> v;
00109 v.fill(0,resolution.height());
00110 result.push_back(v);
00111 }
00112
00113 try{
00114 NetworkAgent agent(result, resolution, window, useRandom, parser.getFractale(), offset, iterations, nbRandom, output, parser.getStep());
00115 std::cout << "ok";
00116 return 0;
00117 }catch(int){
00118 }
00119 return 0;
00120 }