00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "Generation.hpp"
00024
00025 #include "CFractale.hpp"
00026
00027 #include "../Interface/ProgressDialog.hpp"
00028
00029 #include "../Fractale/Image.hpp"
00030 #include "../Fractale/GPointInitialisation.hpp"
00031 #include "../Fractale/GFractale.hpp"
00032 #include "../Fractale/GAccumulateur.hpp"
00033
00034 #include "../global.hpp"
00035
00036 #include <QObject>
00037
00038 #include <QImage>
00039 #include <QString>
00040
00041 #include <limits>
00042 #include <algorithm>
00043 #include <fstream>
00044
00045 #ifndef QT_NO_DEBUG
00046 #include <iostream>
00047 #endif
00048
00049 extern short unsigned int nbCore;
00050
00051 #ifdef _CALLBACK_QT
00052 extern ProgressFeedBack pf;
00053 #endif
00054
00055 Generation :: Generation(const Params params, const QVector<QRgb> table, QWidget* parentWin,
00056 QObject* parent )
00057 :QThread(parent),
00058 params(params),
00059 table(table)
00060 {
00061 pFractale = new unsigned char[params.iWidth * params.iHeight];
00062
00063
00064 switch ( params.lgfct )
00065 {
00066 case lgfctMANDELBROT:
00067 {
00068 pTitle = new QString(tr("Mandelbrot"));
00069 }break;
00070
00071 case lgfctBATEAUENFEU:
00072 {
00073 pTitle = new QString(tr("Fire boat"));
00074 }break;
00075
00076 case lgfctTRICORN:
00077 {
00078 pTitle = new QString(tr("Tricorn"));
00079 }break;
00080
00081 case lgfctJULIAN:
00082 {
00083 pTitle = new QString(tr("Julian"));
00084 }break;
00085
00086 case lgfctNEWTON:
00087 {
00088 pTitle = new QString(tr("Newton"));
00089 }break;
00090
00091 case lgfctNOVA:
00092 {
00093 pTitle = new QString(tr("Nova"));
00094 }break;
00095
00096 case lgfctENDOFLIST:
00097 {
00098 #ifndef QT_NO_DEBUG
00099 std::cout << "Problem with the identifier of the fractale function (lifctENDOFLIST) " << std::endl;
00100 #endif
00101 pTitle = new QString(tr("Unknown"));
00102 }break;
00103 }
00104
00105
00106 pd = new ProgressDialog(*pTitle,parentWin);
00107
00108 #ifdef _CALLBACK_QT
00109 connect(&pf, SIGNAL(sendNewValue(int)), pd, SLOT(progressValue(int)));
00110 #endif
00111 pd->show();
00112
00113 #ifndef QT_NO_DEBUG
00114 std::cout << "Generation (thread) created" << std::endl;
00115 #endif
00116 }
00117
00118 Generation :: ~Generation(void)
00119 {
00120
00121 disconnect(pd, SIGNAL(canceled()), this, SLOT(terminate()));
00122 delete pd;
00123
00124 delete pFractale;
00125 delete pTitle;
00126
00127 #ifndef QT_NO_DEBUG
00128 std::cout << "Generation (thread) deleted" << std::endl;
00129 #endif
00130 }
00131
00132 void Generation :: run(void)
00133 {
00134 #ifndef QT_NO_DEBUG
00135 std::cout << "Generation (thread) started" << std::endl;
00136 #endif
00137
00138
00139
00140 {
00141 QVector<CFractale*> fthreads;
00142
00143
00144 {
00145 Params threadsParams = params;
00146
00147
00148 threadsParams.iHeight = threadsParams.iHeight / nbCore;
00149 threadsParams.zHeight = threadsParams.zHeight / nbCore;
00150
00151
00152
00153 for ( unsigned int i = 0 ; i < nbCore ; i++ )
00154 {
00155 CFractale* newFractale = NULL;
00156
00157 threadsParams.zY = params.zY + (threadsParams.zHeight * i);
00158
00159 newFractale = new CFractale(threadsParams);
00160
00161 fthreads.push_back(newFractale);
00162 newFractale->start();
00163 }
00164
00165
00166 for ( unsigned int i = 0 ; i < nbCore ; i++ )
00167 {
00168
00169 while ( !fthreads[i]->isFinished() )
00170 {
00171
00172 }
00173 }
00174 }
00175
00176 unsigned int pixelCounter = 0;
00177
00178
00179
00180 for ( unsigned int i = 0 ; i < nbCore ; i++ )
00181 {
00182 Fractale::Image<unsigned int>* pFractaleIMG = fthreads[i]->getFractale();
00183 for ( Fractale::Image<unsigned int>::const_iterator it_pixels = pFractaleIMG->begin() ; it_pixels != pFractaleIMG->end() ; ++it_pixels )
00184 {
00185 pFractale[pixelCounter++] = *it_pixels;;
00186 }
00187
00188
00189 delete fthreads[i];
00190 }
00191 }
00192 }
00193
00194 QString Generation :: getTitle(void)const
00195 {
00196 if ( pTitle )
00197 return *pTitle;
00198 else
00199 return QString("");
00200 };