00001 00042 #include "aizone.hpp" 00043 00044 using namespace AiGenerator; 00045 00046 AiZone::AiZone( QObject * parent , 00047 double x , double y , 00048 double zoneWidth , double zoneHeight , 00049 int imageWidth , int imageHeight , 00050 int startPoint, int increment , int iteration , 00051 double zoom, double viewx, double viewy) 00052 00053 : QObject( parent ), m_x( x ), m_y( y ), m_zoneWidth( zoneWidth ), m_zoneHeight( zoneHeight ), 00054 m_imageWidth( imageWidth ), m_imageHeight( imageHeight ), 00055 m_startPoint( startPoint ), m_increment( increment ), m_iteration( iteration ), 00056 m_zoom( zoom ), m_viewX( viewx ), m_viewY( viewy ), 00057 m_image( imageWidth, imageHeight, QImage::Format_RGB32 ), 00058 m_u( 0 ), m_v( 4101842887655102017LL ), m_w( 1 ), 00059 m_last_x(0), m_last_y(0), m_last_iteration(0) 00060 { 00061 status = false ; 00062 m_image.fill(Qt::transparent); 00063 } 00064 00065 AiZone::AiZone( const AiZone & zone ) 00066 { 00067 this->m_image = zone.m_image; 00068 this->m_imageHeight = zone.m_imageHeight; 00069 this->m_imageWidth = zone.m_imageWidth; 00070 this->m_increment = zone.m_increment; 00071 this->m_iteration = zone.m_iteration; 00072 this->m_startPoint = zone.m_startPoint; 00073 this->status = zone.status; 00074 this->m_x = zone.m_x; 00075 this->m_y = zone.m_y; 00076 this->m_zoneHeight = zone.m_zoneHeight; 00077 this->m_zoneWidth = zone.m_zoneWidth; 00078 this->m_zoom = zone.m_zoom; 00079 this->m_viewX = zone.m_viewX; 00080 this->m_viewY = zone.m_viewY; 00081 this->status = zone.status; 00082 this->m_last_iteration = zone.m_last_iteration; 00083 this->m_last_x = zone.m_last_x; 00084 this->m_last_y = zone.m_last_y; 00085 } 00086 00087 QImage & AiZone::image() 00088 { 00089 return m_image; 00090 } 00091 00092 double AiZone::getX() 00093 { 00094 return m_x; 00095 } 00096 00097 double AiZone::getY() 00098 { 00099 return m_y; 00100 } 00101 00102 double AiZone::getZoneWidth() 00103 { 00104 return m_zoneWidth; 00105 } 00106 00107 double AiZone::getZoneHeight() 00108 { 00109 return m_zoneHeight; 00110 } 00111 00112 int AiZone::getImageWidth() 00113 { 00114 return m_imageWidth ; 00115 } 00116 00117 int AiZone::getImageHeight() 00118 { 00119 return m_imageHeight; 00120 } 00121 00122 int AiZone::getStartPoint() 00123 { 00124 return m_startPoint; 00125 } 00126 00127 int AiZone::getIncrement() 00128 { 00129 return m_increment; 00130 } 00131 00132 int AiZone::getIteration() 00133 { 00134 return m_iteration; 00135 } 00136 00137 unsigned int AiZone::getPixel(int x, int y) 00138 { 00139 return m_image.pixel(x, y); 00140 } 00141 00142 void AiZone::setPixel(int x, int y, unsigned int rgb) 00143 { 00144 m_image.setPixel(x,y,rgb); 00145 } 00146 00147 void AiZone::setPixel(int x, int y, int red, int green, int blue) 00148 { 00149 m_image.setPixel(x,y, qRgb(red,green,blue) ); 00150 } 00151 00152 void AiZone::setPixels( int line ,QList< int > pix ) 00153 { 00154 uint *scanLine = reinterpret_cast<uint *>(m_image.scanLine( line ) ); 00155 for ( int x = 0 ; x < pix.length() ; x++ ) 00156 { 00157 *scanLine++ = pix[x]; 00158 } 00159 } 00160 00161 bool AiZone::cancel() 00162 { 00163 return status; 00164 } 00165 00166 void AiZone::progress(int val) 00167 { 00168 emit progressStatus( val ); 00169 } 00170 00171 void AiZone::serialize( QDataStream & stream ) 00172 { 00173 stream << m_image 00174 << m_imageHeight 00175 << m_imageWidth 00176 << m_increment 00177 << m_iteration 00178 << m_last_x 00179 << m_last_y 00180 << m_startPoint 00181 << m_u 00182 << m_v 00183 << m_viewX 00184 << m_viewY 00185 << m_w 00186 << m_x 00187 << m_y 00188 << m_zoneHeight 00189 << m_zoneWidth 00190 << m_zoom 00191 ; 00192 } 00193 00194 void AiZone::deserialize( QDataStream & stream ) 00195 { 00196 stream >> m_image 00197 >> m_imageHeight 00198 >> m_imageWidth 00199 >> m_increment 00200 >> m_iteration 00201 >> m_last_x 00202 >> m_last_y 00203 >> m_startPoint 00204 >> m_u 00205 >> m_v 00206 >> m_viewX 00207 >> m_viewY 00208 >> m_w 00209 >> m_x 00210 >> m_y 00211 >> m_zoneHeight 00212 >> m_zoneWidth 00213 >> m_zoom 00214 ; 00215 status = false; 00216 } 00217 00218 AiZone & AiZone::operator = (const AiZone &zone) 00219 { 00220 this->m_image = zone.m_image; 00221 this->m_imageHeight = zone.m_imageHeight; 00222 this->m_imageWidth = zone.m_imageWidth; 00223 this->m_increment = zone.m_increment; 00224 this->m_iteration = zone.m_iteration; 00225 this->m_startPoint = zone.m_startPoint; 00226 this->status = zone.status; 00227 this->m_x = zone.m_x; 00228 this->m_y = zone.m_y; 00229 this->m_zoneHeight = zone.m_zoneHeight; 00230 this->m_zoneWidth = zone.m_zoneWidth; 00231 this->m_zoom = zone.m_zoom; 00232 this->m_viewX = zone.m_viewX; 00233 this->m_viewY = zone.m_viewY; 00234 this->status = zone.status; 00235 this->m_last_iteration = zone.m_last_iteration; 00236 this->m_last_x = zone.m_last_x; 00237 this->m_last_y = zone.m_last_y; 00238 return *this; 00239 } 00240 00241 double AiZone::getZoom() 00242 { 00243 return m_zoom; 00244 } 00245 00246 double AiZone::getViewX() 00247 { 00248 return m_viewX; 00249 } 00250 00251 double AiZone::getViewY() 00252 { 00253 return m_viewY; 00254 } 00255 00256 bool AiZone::valid(int x, int y) 00257 { 00258 return m_image.valid(x, y); 00259 } 00260 00261 void AiZone::sendSnapshot() 00262 { 00263 emit snapshot( this ); 00264 } 00265 00266 void AiZone::beep() 00267 { 00268 QApplication::beep(); 00269 } 00270 00271 void AiZone::initRandom(unsigned long long j) 00272 { 00273 m_u = j ^ m_v; 00274 generateUInt64(); 00275 m_v = m_u; 00276 generateUInt64(); 00277 m_w = m_v; 00278 generateUInt64(); 00279 } 00280 00281 unsigned long long AiZone::generateUInt64() 00282 { 00283 m_u = m_u * 2862933555777941757LL + 7046029254386353087LL; 00284 m_v ^= m_v >> 17; 00285 m_v ^= m_v << 31; 00286 m_v ^= m_v >> 8; 00287 m_w = 4294957665U * ( m_w & 0xffffffff ) + ( m_w >> 32 ); 00288 unsigned long long x = m_u ^ ( m_u << 21 ); 00289 x ^= x >> 35; x ^= x << 4; 00290 return ( x + m_v ) ^ m_w; 00291 } 00292 00293 double AiZone::generateDouble() 00294 { 00295 return 5.42101086242752217E-20 * generateUInt64(); 00296 } 00297 00298 unsigned int AiZone::generateUInt32() 00299 { 00300 return (unsigned int)generateUInt64(); 00301 } 00302 00303 int AiZone::getLastX() const 00304 { 00305 return m_last_x; 00306 } 00307 00308 int AiZone::getLastY() const 00309 { 00310 return m_last_y; 00311 } 00312 00313 int AiZone::getLastIteration() const 00314 { 00315 return m_last_iteration; 00316 } 00317 00318 void AiZone::setLastXYI(int x, int y, int i) 00319 { 00320 m_last_x = x; 00321 m_last_y = y; 00322 m_last_iteration = i; 00323 }