00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "Curve.hpp"
00024
00025 #include "CCurve.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 Curve :: Curve(const ParamsCurve params, 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.lcfct )
00065 {
00066 case lcfctCLIFFORDATTRACTORS:
00067 {
00068 pTitle = new QString(tr("Clifford Attractors"));
00069 }break;
00070
00071 case lcfctCLIFFORDATTRACTORS2:
00072 {
00073 pTitle = new QString(tr("Clifford2 Attractors"));
00074 }break;
00075
00076 case lcfctENDOFLIST:
00077 {
00078 #ifndef QT_NO_DEBUG
00079 std::cout << "Problem with the identifier of the fractale function (lcfctENDOFLIST) " << std::endl;
00080 #endif
00081 pTitle = new QString(tr("Unknown"));
00082 }break;
00083 }
00084
00085 pd = new ProgressDialog(*pTitle,parentWin);
00086 connect(pd, SIGNAL(canceled()), this, SLOT(terminate()));
00087 #ifdef _CALLBACK_QT
00088 connect(&pf, SIGNAL(sendNewValue(int)), pd, SLOT(progressValue(int)));
00089 #endif
00090 pd->show();
00091
00092 #ifndef QT_NO_DEBUG
00093 std::cout << "Generation (thread) created" << std::endl;
00094 #endif
00095 }
00096
00097 Curve :: ~Curve(void)
00098 {
00099 disconnect(pd, SIGNAL(canceled()), this, SLOT(terminate()));
00100 delete pd;
00101
00102 delete pFractale;
00103 delete pTitle;
00104
00105 #ifndef QT_NO_DEBUG
00106 std::cout << "Generation (thread) deleted" << std::endl;
00107 #endif
00108 }
00109
00110 void Curve :: run(void)
00111 {
00112 #ifndef QT_NO_DEBUG
00113 std::cout << "Generation (thread) started" << std::endl;
00114 #endif
00115
00116
00117
00118 {
00119 QVector<CCurve*> fthreads;
00120
00121
00122
00123
00124
00125
00126 {
00127 ParamsCurve threadsParams = params;
00128
00129
00130 threadsParams.iHeight = threadsParams.iHeight / nbCore;
00131 threadsParams.zHeight = threadsParams.zHeight / nbCore;
00132
00133 threadsParams.nbPoints = threadsParams.nbPoints / nbCore;
00134
00135
00136
00137 for ( unsigned int i = 0 ; i < nbCore ; i++ )
00138 {
00139 CCurve* newFractale = NULL;
00140
00141 threadsParams.zY = params.zY + (threadsParams.zHeight * i);
00142
00143 newFractale = new CCurve(threadsParams);
00144
00145 fthreads.push_back(newFractale);
00146 newFractale->start();
00147 }
00148
00149
00150 for ( unsigned int i = 0 ; i < nbCore ; i++ )
00151 {
00152
00153 while ( !fthreads[i]->isFinished() )
00154 {
00155
00156 }
00157 }
00158 }
00159
00160 unsigned int pixelCounter = 0;
00161
00162
00163
00164 for ( unsigned int i = 0 ; i < nbCore ; i++ )
00165 {
00166 Fractale::Image<unsigned int>* pFractaleIMG = fthreads[i]->getFractale();
00167 for ( Fractale::Image<unsigned int>::const_iterator it_pixels = pFractaleIMG->begin() ; it_pixels != pFractaleIMG->end() ; ++it_pixels )
00168 {
00169 pFractale[pixelCounter++] = *it_pixels;;
00170 }
00171
00172
00173 delete fthreads[i];
00174 }
00175 }
00176 }
00177
00178 QString Curve :: getTitle(void)const
00179 {
00180 if ( pTitle )
00181 return *pTitle;
00182 else
00183 return QString("");
00184 };