void Smooth::SeedDisk() { for (int x=0;x<sizex;x++) { for (int y=0;y<sizey;y++) { (*field)[x][y]=Disk(Radius(0,0,x,y)); } } }
void Smooth::QuickUpdate() { for (int x=0;x<sizex;x++) { for (int y=0;y<sizey;y++) { double ring_total=0.0; double disk_total=0.0; for (int x1=0;x1<sizex;x1++) { int deltax=TorusDifference(x,x1,sizex); if (deltax>outer+smoothing/2) continue; for (int y1=0;y1<sizey;y1++) { int deltay=TorusDifference(y,y1,sizey); if (deltay>outer+smoothing/2) continue; double radius=std::sqrt(deltax*deltax+deltay*deltay); double fieldv=(*field)[x1][y1]; ring_total+=fieldv*Ring(radius); disk_total+=fieldv*Disk(radius); } } (*fieldNew)[x][y]=transition(disk_total/normalisation_disk,ring_total/normalisation_ring); } } std::vector<std::vector<density> > * fieldTemp; fieldTemp=field; field=fieldNew; fieldNew=fieldTemp; frame++; }
filling Smooth::FillingDisk(int x, int y) const { double total=0.0; for (int x1=0;x1<sizex;x1++) { for (int y1=0;y1<sizey;y1++) { total+=(*field)[x1][y1]*Disk(Radius(x,y,x1,y1)); } }; return total/normalisation_disk; }
double Smooth::NormalisationDisk() const { double total=0.0; for (int x=0;x<sizex;x++) { for (int y=0;y<sizey;y++) { total+=Disk(Radius(0,0,x,y)); } }; return total; }
void *MyThread::Entry() { Timer t; std::string name = "/home/bvs/Programming"; t.start(); Disk(m_DirTree, name.c_str(), 0); Timer::printTime(t.stop()); return NULL; }
BOOL CPubThread::DoThread(LPVOID pData) { DWORD enablepublishing = 0; CFG().GetValue( "Settings", "EnablePublishing", &enablepublishing ); // Punt if publishing is disabled if ( !enablepublishing ) { m_bReset = TRUE; Sleep( 1000 ); return TRUE; } // end if DWORD tickcount = GetTickCount(); SYSTEMTIME st; GetSystemTime( &st ); // Calculate seconds offset DWORD seconds = ( st.wHour * 60 * 60 ) + ( st.wMinute * 60 ) + st.wSecond; // Process each job LPPUBINFO ppi = NULL; while ( ( ppi = (LPPUBINFO)PUBLIST().GetNext( ppi ) ) != NULL ) { try { // Is publishing on hold? if ( ppi->bHold ) continue; // Image information LPPUBIMGINFO ppii = NULL; // Are we doing any avi capturing? if ( ( ppi->f1 & ( PUBF1_AVI | PUBF1_THMAVI ) ) != 0 ) { // Update AVI's if ( ( ppi->f1 & PUBF1_AVICAPMOTION ) == 0 || IsMotion( ppi ) ) { // Check for avi if ( ( ppi->f1 & PUBF1_AVI ) != 0 ) { // Time to capture? if ( ( ppi->f1 & PUBF1_AVICAPMOTION ) != 0 || ppi->avitimeout < tickcount ) { ppii = IMGLIST().FindByName( ppi->img ); if ( ppii != NULL ) { // Refresh the image IMGLIST().Update( ppii, TRUE ); // Wait for next frame if ( ppi->capframes < 1 ) ppi->capframes = 1; if ( ppi->capseconds < 1 ) ppi->capseconds = 1; long delay = ( ppi->capseconds * 1000 ) / ppi->capframes; ppi->avitimeout = tickcount + delay; // Write out a frame of the avi WriteAviFrame( ppi, ppi->avi, ppii, ppi->pub_fname ); } // end if } // end if } // end if // Check for thumbnail avi if ( ( ppi->f1 & PUBF1_THMAVI ) != 0 ) { // Time to capture? if ( ( ppi->f1 & PUBF1_AVICAPMOTION ) != 0 || ppi->thmavitimeout < tickcount ) { // Get image if we don't already have it if ( ppii == NULL ) { ppii = IMGLIST().FindByName( ppi->img ); IMGLIST().Update( ppii, TRUE ); } // end if if ( ppii != NULL ) { // Wait for next frame if ( ppi->capframes < 1 ) ppi->capframes = 1; if ( ppi->capseconds < 1 ) ppi->capseconds = 1; long delay = ( ppi->capseconds * 1000 ) / ppi->capframes; ppi->thmavitimeout = tickcount + delay; // Write out a frame of the avi WriteAviFrame( ppi, ppi->thmavi, ppii, ppi->pub_tfname ); } // end if } // end if } // end if } // end if } // end if // Are we detecting motion? if ( ( ppi->f1 & PUBF1_MOTION ) != 0 ) { if ( IsMotion( ppi ) ) { // Save motion time if ( ppi->motioninterval == 0 ) ppi->motioninterval = 30; ppi->nextmotion = GetTickCount() + ( ppi->motioninterval * 1000 ); // Get current file name GetFileName( ppi ); // Refresh the image if ( ppii == NULL ) IMGLIST().Update( ppi->img, TRUE ); // Handle avi if ( ( ppi->f1 & PUBF1_AVI ) != 0 ) { if ( ppi->avi->IsOpen() ) { // Save avi filename strcpy( ppi->avicachefile, ppi->avi->GetFileName() ); ppi->avi->Close(); // Save thumbnail avi filename strcpy( ppi->thmavicachefile, ppi->thmavi->GetFileName() ); ppi->thmavi->Close(); } // end if } // end if // Handle thumbnail avi if ( ( ppi->f1 & PUBF1_THMAVI ) != 0 ) { if ( ppi->thmavi->IsOpen() ) { // Save avi filename strcpy( ppi->thmavicachefile, ppi->thmavi->GetFileName() ); ppi->thmavi->Close(); // Save thumbnail avi filename strcpy( ppi->thmavicachefile, ppi->thmavi->GetFileName() ); ppi->thmavi->Close(); } // end if } // end if BOOL bPublished = FALSE; // Check for FTP if ( ppi->type == PUBTYPE_FTP ) bPublished = Ftp( ppi ); // Check for Email else if ( ppi->type == PUBTYPE_EMAIL ) bPublished = Email( ppi ); // Check for Disk else if ( ppi->type == PUBTYPE_DISK ) bPublished = Disk( ppi ); if ( bPublished ) { // Inform FRAME if ( ppi->type == PUBTYPE_FTP ) FRAME()->SetEvent( 2 ); else if ( ppi->type == PUBTYPE_EMAIL ) FRAME()->SetEvent( 3 ); else if ( ppi->type == PUBTYPE_DISK ) FRAME()->SetEvent( 4 ); // Play sound if needed if ( ( ppi->f1 & PUBF1_PLAYSOUND ) != 0 ) { if ( *ppi->snd ) PLAYSOUND( ppi->snd ); else PLAYSOUND( IDW_CAMERA ); } // end if } // end if // Ensure cache files are gone if ( *ppi->avicachefile != 0 ) { CWinFile::Delete( ppi->avicachefile ); *ppi->avicachefile = 0; } // end if if ( *ppi->thmavicachefile != 0 ) { CWinFile::Delete( ppi->thmavicachefile ); *ppi->thmavicachefile = 0; } // end if } // end if } // end if // Has an interval been specified? else if ( ppi->interval != 0 ) { // Set interval first time if ( m_bReset || ppi->timeout == 0 ) ppi->timeout = tickcount + ( ppi->interval * 1000 ); // Have we timed out? BOOL publish = ppi->timeout < tickcount; // Do we want to sync to the system clock? if ( !publish && ( ppi->f1 & PUBF1_SYNCTOCLOCK ) != 0 ) { // Is it a new second? if ( seconds != ppi->lasttime ) { // Record last pub time ppi->lasttime = seconds; // Is it time to publish? if ( !( seconds % ppi->interval ) ) publish = TRUE; } // end if } // end if if ( publish ) { // Record next timeout interval ppi->timeout = tickcount + ( ppi->interval * 1000 ); // Record last pub time ppi->lasttime = seconds; // Get current file name GetFileName( ppi ); // Refresh the image if ( ppii == NULL ) IMGLIST().Update( ppi->img, TRUE ); // Handle avi if ( ( ppi->f1 & PUBF1_AVI ) != 0 ) { if ( ppi->avi->IsOpen() ) { // Save avi filename strcpy( ppi->avicachefile, ppi->avi->GetFileName() ); ppi->avi->Close(); // Save thumbnail avi filename strcpy( ppi->thmavicachefile, ppi->thmavi->GetFileName() ); ppi->thmavi->Close(); } // end if // Punt if no avi else return TRUE; } // end if // Handle thumbnail avi if ( ( ppi->f1 & PUBF1_THMAVI ) != 0 ) { if ( ppi->thmavi->IsOpen() ) { // Save avi filename strcpy( ppi->thmavicachefile, ppi->thmavi->GetFileName() ); ppi->thmavi->Close(); // Save thumbnail avi filename strcpy( ppi->thmavicachefile, ppi->thmavi->GetFileName() ); ppi->thmavi->Close(); } // end if } // end if BOOL bPublished = FALSE; // Check for FTP if ( ppi->type == PUBTYPE_FTP ) bPublished = Ftp( ppi ); // Check for Email else if ( ppi->type == PUBTYPE_EMAIL ) bPublished = Email( ppi ); // Check for Disk else if ( ppi->type == PUBTYPE_DISK ) bPublished = Disk( ppi ); if ( bPublished ) { // Inform FRAME if ( ppi->type == PUBTYPE_FTP ) FRAME()->SetEvent( 2 ); else if ( ppi->type == PUBTYPE_EMAIL ) FRAME()->SetEvent( 3 ); else if ( ppi->type == PUBTYPE_DISK ) FRAME()->SetEvent( 4 ); // Play sound if needed if ( ( ppi->f1 & PUBF1_PLAYSOUND ) != 0 ) { if ( *ppi->snd ) PLAYSOUND( ppi->snd ); else PLAYSOUND( IDW_CAMERA ); } // end if } // end if // Ensure cache files are gone if ( *ppi->avicachefile != 0 ) { CWinFile::Delete( ppi->avicachefile ); *ppi->avicachefile = 0; } // end if if ( *ppi->thmavicachefile != 0 ) { CWinFile::Delete( ppi->thmavicachefile ); *ppi->thmavicachefile = 0; } // end if } // end if } // end if } // end try // Try to return to a normal life if we can... catch( ... ) { _Log( MB_ICONERROR, "PublishThread()", "Assert" ); ASSERT( 0 ); } } // end while m_bReset = FALSE; Sleep( 100 ); return TRUE; }
void MyThread::Disk(DirItem* parent, const char* dirname, int lvl) { struct dirent* entry; struct dirent **list; char longest_name[4096]; int n; n = scandir(dirname, &list, 0, alphasort); if(n < 0) { fprintf(stderr, "Couldn't scan directory: %s\n", dirname); BigNumber zero = 0; std::wstring name = L"Permission denied"; Attach(parent, name, zero, false); } else { while (n--) { entry = list[n]; /* Don't descend up the tree or include the current directory */ if(strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0) { std::wstring name = std::wstring(ConvertCharToWide::Convert(entry->d_name)); /* If it's a directory print it's name and recurse into it */ unsigned char type = entry->d_type; strncpy(longest_name, dirname, 4095); strncat(longest_name, "/", 4095); strncat(longest_name, entry->d_name, 4095); switch(type) { case DT_DIR: { BigNumber size = FileSystem::GetFileSize(longest_name); DirItem* id = Attach(parent, name, size, true); /* Prepend the current directory and recurse */ Disk(id, longest_name, lvl+1); break; } case DT_REG: { BigNumber size = FileSystem::GetFileSize(longest_name); Attach(parent, name, size, false); break; } case DT_LNK: { BigNumber size = FileSystem::GetFileSize(longest_name); Attach(parent, name, size, false); break; } default: { fprintf(stderr, "Unknown type found [%d]: %s\n", type, entry->d_name); break; } } } free(entry); } free(list); } CloseTreeItem(parent); }