Director::Director(const string& scriptName, unsigned int playerCount, bool overRide) { isOverride = overRide; maximum = 0; ifstream infile(scriptName); if (!infile.is_open()) { string error = "[ERROR]: Open file fail: " + scriptName; throw CodeException(FAIL_FILE_OPEN, error.c_str()); } string currentLine; bool followingPL; int scriptCounter = 1; int lastPartDefCount = 0; regex re("^\\[scene\\][\\s]([\\w\\s]*)$"); smatch sm; regex re_config("^[\\s]*(.*.txt)[\\s]*$"); smatch sm_config; regex re_part("^[\\s]*([\\w]+)[\\s]+(.*.txt)[\\s]*$"); smatch sm_part; while (getline(infile, currentLine)) { // scan for scene titles if (regex_match(currentLine, sm, re)) { titles.push_back(sm[1]); followingPL = false; } else { // scan for scene fragment config files if (regex_match(currentLine, sm_config, re_config)) { scripts[scriptCounter] = script(); if (!followingPL) { followingPL = true; } else { titles.push_back(string()); } ifstream configFile(sm_config[1]); int partDefinitionLineCount = 0; if (!configFile.is_open()) { string temp = sm_config[1]; string error = "[ERROR]: Open file fail: " + temp; throw CodeException(FAIL_FILE_OPEN, error.c_str()); } string partDefinitionLine; while (getline(configFile, partDefinitionLine)) { // scan for part definition files if (regex_match(partDefinitionLine, sm_part, re_part)) { partDefinitionLineCount++; scripts[scriptCounter][sm_part[1]] = sm_part[2]; } } scriptCounter++; if (!isOverride) { int consecutiveSum = partDefinitionLineCount + lastPartDefCount; lastPartDefCount = partDefinitionLineCount; maximum = maximum > consecutiveSum ? maximum : consecutiveSum; } } } } //finish reading script try { play = playPtr(new Play(titles, finished.get_future())); } catch (exception& e) { throw (BAD_ALLOCATION,e); } // check the override option if (!isOverride) { maximum = maximum > (int)playerCount ? maximum : (int)playerCount; } else { maximum = (int)playerCount; } for (int i = 0; i < maximum; i++) { try { players.push_back(playerPtr(new Player(*play))); } catch (exception& e) { throw (BAD_ALLOCATION, e); } players[i]->activate(); } }
// dft_type = 1 for DFT, dft_type = -1 for IDFT void dft_both( img *src_img, char *dst_name, int dft_type ) { long x, y, u, v, i, M, N ; double sum_r, sum_i ; cimg *cdft_img, *cintermediate_img ; dimg *ddft_img, *dph_img, *dmg_img ; img *dst_img ; // Initialize M and N to match book M = src_img->cols ; N = src_img->rows ; // Initialize cdft_img = create_cimg ( "dft", M, N ) ; cintermediate_img = create_cimg ( "dft", M, N ) ; if( dft_type == 1 ) { // Premultiply by ( -1 )^( x + y ) to center for( x = 0 ; x < M ; x++ ) { for( y = 0 ; y < N ; y++ ) src_img->image[y * M + x] *= pow( -1, x + y ) ; } } // Compute DFT/IDFT // Compute cintermediate_img = F(x,v) for( v = 0 ; v < N ; v++ ) { for( x = 0 ; x < M ; x++ ) { sum_r = 0 ; sum_i = 0 ; for( y = 0 ; y < N ; y++ ) { sum_r += src_img->image[y * M + x] * cos( dft_type * -2 * PI * v * y / (double)N ) ; sum_i += src_img->image[y * M + x] * sin( dft_type * -2 * PI * v * y / (double)N ) ; } cintermediate_img->image[v * M + x].r = sum_r ; cintermediate_img->image[v * M + x].i = sum_i ; } } // Compute cintermediate_img = F(u,v) for( u = 0 ; u < M ; u++ ) { for( v = 0 ; v < N ; v++ ) { sum_r = 0 ; sum_i = 0 ; for( x = 0 ; x < M ; x++ ) { sum_r += cintermediate_img->image[v * M + u].r * cos( dft_type * -2 * PI * u * x / (double)M ) ; sum_i += cintermediate_img->image[v * M + u].i * sin( dft_type * -2 * PI * u * x / (double)M ) ; } cdft_img->image[v * M + u].r = sum_r ; cdft_img->image[v * M + u].i = sum_i ; } } if( dft_type == -1 ) { // 1/MN constant for( u = 0 ; u < M ; u++ ) { for( v = 0 ; v < N ; v++ ) { cdft_img->image[v * M + u].r /= M * N ; cdft_img->image[v * M + u].i /= M * N ; } } } if( dft_type == 1 ) { // Calculate Fourier spectrum and phase angle of DFT dph_img = ph_part( "dft", cdft_img ) ; dmg_img = mg_part( "dft", cdft_img ) ; // Initialize ddft_img = create_dimg ( "dft", M, N ) ; // Restate DFT as product of Fourier spectrum and phase angle. Save in ddft_img for( i = 0 ; i < M * N ; i++ ) ddft_img->image[i] = dph_img->image[i] * dmg_img->image[i] ; } else ddft_img = re_part( "dft", cdft_img ) ; // Scale this result and save it as an img with name = dst_name write_img( "dft", dimg2img_scale( "dft", ddft_img ), dst_name ) ; return ; }