00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00023 #include "imagecalculator.h"
00024 #include "imagetiler.h"
00025 #include "networkimagetiler.h"
00026 #include "fractale.h"
00027
00028 ImageCalculator::ImageCalculator(int nb, QImage *d, QRectF w, QSize r, fractale &f, bool type, long nbr, bool a, QStringList& networkList):nbThreads(nb), destination(d), window(w), size(r), frac(f), nbRandom(nbr), useRandomCalculation(type), animate(a), networkAdresses(networkList){
00029 for (int j=0; j<r.width(); j++){
00030 QVector<long> v;
00031 v.fill(0,r.height());
00032 result.push_back(v);
00033 }
00034
00035 nbProcessedRows = 0;
00036 lastProgression = 0;
00037 }
00038
00039 ImageCalculator::~ImageCalculator(){
00040 }
00041
00045 void ImageCalculator::run(){
00046 int nbAgents = nbThreads + networkAdresses.length();
00047
00048 for(int i=0; i<nbAgents; i++){
00049 ImageTiler *it = new ImageTiler(result, mutex, window, size, &frac, useRandomCalculation, nbRandom, i, nbAgents, i);
00050
00051
00052 QObject::connect(it, SIGNAL(processed()), this, SLOT(s_processing()));
00053
00054 it->run();
00055 tilers.push_back(it);
00056 }
00057
00058 for (int i=0; i<networkAdresses.length(); i++){
00059 NetworkImageTiler *it = new NetworkImageTiler(networkAdresses.at(i), result, mutex, window, size, &frac, useRandomCalculation, nbRandom, nbThreads+i, nbAgents);
00060 it->run();
00061 networkTilers.push_back(it);
00062 }
00063
00064 for (int i=0; i<nbThreads; i++)
00065 tilers[i]->wait();
00066 for (int i=0; i<networkAdresses.length(); i++)
00067 networkTilers[i]->wait();
00068
00069 sumImagesIntoDestination();
00070 }
00071
00075 void ImageCalculator::sumImagesIntoDestination(){
00076 int v;
00077 maxValue = 0;
00078 for (int x = 0; x< size.width(); x++)
00079 for (int y=0; y<size.height(); y++){
00080 v = result[x][y];
00081 destination->setPixel(x,y,ImageCalculator::intToRGBA( v ));
00082 if (v > maxValue)
00083 maxValue = v;
00084 }
00085
00086 for (int i=0; i<tilers.count(); i++)
00087 delete tilers[i];
00088 for (int i=0; i<networkTilers.count(); i++)
00089 delete networkTilers[i];
00090
00091 emit render();
00092 }
00093
00097 void ImageCalculator::s_processing(){
00098 nbProcessedRows ++;
00099
00100 if (animate){
00101 if (useRandomCalculation){
00102
00103 if (int(100 * nbProcessedRows / nbRandom) > lastProgression){
00104 sumImagesIntoDestination();
00105 emit render();
00106 }
00107 }else{
00108 sumImagesIntoDestination();
00109 emit render();
00110 }
00111 }
00112
00113 if (useRandomCalculation){
00114
00115 lastProgression = 100 * nbProcessedRows / nbRandom;
00116 emit progress(lastProgression);
00117 }else{
00118
00119 emit progress(100 * nbProcessedRows / size.width());
00120 }
00121 }
00122
00123
00124