00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00023 #include "imagetiler.h"
00024 #include "imagecalculator.h"
00025
00026 ImageTiler::ImageTiler(QVector<QVector<long> >& result, QMutex& mutex, QRectF w, QSize r, fractale *f, bool type, long nbRandom, int start, int step, int id):destinationArray(result), mutex(mutex), window(w), size(r), frac(f), displayRandomPoints(type), nbRandom(nbRandom), start(start), step(step), id(id){
00027 maxValue = 0;
00028 }
00029
00030 ImageTiler::~ImageTiler(){
00031 }
00032
00033 void ImageTiler::run(){
00034 fractale *f = frac->clone();
00035 maxValue = 0;
00036
00037
00038 double pasX = window.width() / size.width();
00039 double pasY = window.height() / size.height();
00040
00041 if (displayRandomPoints){
00042 for (long i=0; i<nbRandom; i++){
00043 float tmpX = window.left() + window.width() * qrand() / RAND_MAX;
00044 float tmpY = window.top() + window.height() * qrand() / RAND_MAX;
00045 std::complex<float> start(tmpX, tmpY);
00046 processSinglePoint(start, f, pasX, pasY);
00047 emit processed();
00048 }
00049 }else{
00050
00051
00052 bool superior = (window.top() <= -window.bottom());
00053
00054 for (int x = start; x < size.width(); x+=step){
00055 for (int y = 0; y < size.height(); y++){
00056
00057 float tmpY = window.top() + y*pasY;
00058
00059 if (superior && (f->isVerticalSymetric() || f->isImpair()) && tmpY >= pasY)
00060 continue;
00061 else
00062 if (!superior && (f->isVerticalSymetric() || f->isImpair()) && tmpY <= 0)
00063 continue;
00064
00065 float tmpX = window.left() + x*pasX;
00066
00067
00068 std::complex<float> start(tmpX, tmpY);
00069
00070 processSinglePoint(start, f, pasX, pasY);
00071 }
00072 emit processed();
00073 }
00074 }
00075
00076 delete f;
00077 }
00078
00079
00083 void ImageTiler::processSinglePoint(std::complex<float>& start, fractale *f, float pasX, float pasY){
00084 std::complex<float> tmp = start;
00085 f->setStart(start);
00086 QVector<std::complex<float> > serie;
00087
00088 serie.push_back(start);
00089
00090 for (int i=0; i<f->getMaxIterations(); i++){
00091 tmp = f->next(tmp);
00092
00093 if (!f->stop())
00094 serie.push_back(tmp);
00095 else{
00096
00097
00098
00099 QVector<std::complex<float> >::iterator ii = serie.begin();
00100 while (ii != serie.end()){
00101 std::complex<float> destinationPoint = f->renderingDestination(*ii);
00102
00103
00104 int xx = (destinationPoint.real() - window.left()) / pasX;
00105 int yy = (destinationPoint.imag() - window.top()) / pasY;
00106 int antiXX = -1;
00107 int antiYY = -1;
00108 long value;
00109
00110 if (xx >=0 && xx < size.width()){
00111
00112
00113 if (yy >= 0 && yy < size.height()){
00114
00115 mutex.lock();
00116 value = destinationArray[xx][yy] + 1;
00117 destinationArray[xx][yy] = value;
00118 mutex.unlock();
00119 }
00120
00121
00122 if (f->isVerticalSymetric()){
00123
00124 if ( fabs(destinationPoint.imag()) > 0){
00125 antiYY = (-destinationPoint.imag() - window.top()) / pasY;
00126
00127 if (antiYY >= 0 && antiYY < size.height()){
00128 mutex.lock();
00129 value = destinationArray[xx][antiYY] + 1;
00130 destinationArray[xx][antiYY] = value;
00131 mutex.unlock();
00132 }
00133 }
00134 }else
00135 if (f->isImpair()){
00136 antiYY = (-destinationPoint.imag() - window.top()) / pasY;
00137 if ( fabs(destinationPoint.imag()) > 0){
00138 if (antiYY >= 0 && antiYY < size.height()){
00139 antiXX = (-destinationPoint.real() - window.left()) / pasX;
00140 if (antiXX >= 0 && antiXX < size.width()){
00141 mutex.lock();
00142 value = destinationArray[antiXX][antiYY] + 1;
00143 destinationArray[antiXX][antiYY] = value;
00144 mutex.unlock();
00145 }
00146 }
00147 }
00148 }
00149
00150 if (value > maxValue)
00151 maxValue = value;
00152 }
00153
00154 ii++;
00155 }
00156
00157 serie.clear();
00158 break;
00159 }
00160 }
00161
00162 serie.clear();
00163 }