X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=src%2Fthreadrecon.cpp;h=4ece6ed3e0f03b784ce34315976c16c2b1c62122;hp=7a7b3ddb1c33f530bcd2a348851f8dd44f882fa1;hb=e98a8a9d72a7b919debbbc9d1b0f237fe71c0fb3;hpb=3b09207d7c37bc3d48e331657353123ed2f66ed9 diff --git a/src/threadrecon.cpp b/src/threadrecon.cpp index 7a7b3dd..4ece6ed 100644 --- a/src/threadrecon.cpp +++ b/src/threadrecon.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2001 Kevin Rosenberg ** -** $Id: threadrecon.cpp,v 1.8 2001/02/25 06:32:12 kevin Exp $ +** $Id: threadrecon.cpp,v 1.19 2001/03/04 04:30:45 kevin Exp $ ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License (version 2) as @@ -25,6 +25,7 @@ ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ******************************************************************************/ + #include "wx/wxprec.h" #ifndef WX_PRECOMP @@ -39,9 +40,8 @@ #include "backgroundmgr.h" #include "backgroundsupr.h" -#if defined(HAVE_CONFIG_H) -#include "config.h" -#endif +#ifdef HAVE_WXTHREADS + @@ -65,13 +65,13 @@ ReconstructorSupervisorThread::ReconstructorSupervisorThread (ProjectionFileView wxThread::ExitCode ReconstructorSupervisorThread::Entry() { - ReconstructorSupervisor reconSupervisor (m_pProjView, m_iNX, m_iNY, + ReconstructorSupervisor reconSupervisor (this, m_pProjView, m_iNX, m_iNY, m_strFilterName.c_str(), m_dFilterParam, m_strFilterMethod.c_str(), m_iZeropad, m_strFilterGenerationName.c_str(), m_strInterpName.c_str(), m_iInterpParam, m_strBackprojectName.c_str(), m_strLabel.c_str()); reconSupervisor.start(); while (! reconSupervisor.isDone() && ! reconSupervisor.fail()) { - Sleep(50); + Sleep(100); Yield(); } if (reconSupervisor.fail()) @@ -84,9 +84,9 @@ ReconstructorSupervisorThread::Entry() wxPostEvent( theApp->getMainFrame(), eventLog ); // send log event } - while (reconSupervisor.anyWorkersRunning()) { + while (! reconSupervisor.workersDeleted()) { Sleep(50); - Yield(); + reconSupervisor.ProcessPendingEvents(); } return reinterpret_cast(0); @@ -104,7 +104,7 @@ ReconstructorSupervisorThread::OnExit() // ///////////////////////////////////////////////////////////////////// -ReconstructorSupervisor::ReconstructorSupervisor (ProjectionFileView* pProjView, +ReconstructorSupervisor::ReconstructorSupervisor (SupervisorThread* pThread, ProjectionFileView* pProjView, int iImageNX, int iImageNY, const char* pszFilterName, double dFilterParam, const char* pszFilterMethod, int iZeropad, const char* pszFilterGenerationName, const char* pszInterpName, int iInterpParam, const char* pszBackprojectName, const char* const pszLabel) @@ -113,11 +113,11 @@ ReconstructorSupervisor::ReconstructorSupervisor (ProjectionFileView* pProjView, m_pszFilterName(pszFilterName), m_dFilterParam(dFilterParam), m_pszFilterMethod(pszFilterMethod), m_iZeropad(iZeropad), m_pszFilterGenerationName(pszFilterGenerationName), m_pszInterpName(pszInterpName), m_iInterpParam(iInterpParam), m_pszBackprojectName(pszBackprojectName), m_pszLabel(pszLabel), - BackgroundSupervisor (pProjView->GetFrame(), pProjView->GetDocument(), "Reconstructing", pProjView->GetDocument()->getProjections().nView()) + BackgroundSupervisor (pThread, pProjView->GetFrame(), pProjView->GetDocument(), "Reconstructing", pProjView->GetDocument()->getProjections().nView()) { m_vecpChildImageFile.reserve (getNumWorkers()); - for (unsigned int iThread = 0; iThread < getNumWorkers(); iThread++) { - m_vecpChildImageFile[iThread] = new ImageFile (iImageNX, iImageNY); + for (int iThread = 0; iThread < getNumWorkers(); iThread++) { + m_vecpChildImageFile[iThread] = new ImageFile (m_iImageNX, m_iImageNY); } } @@ -127,8 +127,7 @@ ReconstructorSupervisor::~ReconstructorSupervisor() for (int i = 0; i < getNumWorkers(); i++) { delete m_vecpChildImageFile[i]; m_vecpChildImageFile[i] = NULL; - } - + } } BackgroundWorkerThread* @@ -148,26 +147,20 @@ ReconstructorSupervisor::onDone() wxCriticalSection doneSection; wxCriticalSectionLocker critsect (doneSection); - ImageFileDocument* pReconDoc = theApp->newImageDoc(); - if (! pReconDoc) { - sys_error (ERR_SEVERE, "Unable to create image file"); - return; - } - ImageFile* pImageFile = getImageFile(); - pReconDoc->setImageFile (pImageFile); - if (theApp->getAskDeleteNewDocs()) - pReconDoc->Modify (true); - pReconDoc->UpdateAllViews (m_pProjView); - if (ImageFileView* rasterView = pReconDoc->getView()) { - rasterView->OnUpdate (rasterView, NULL); - rasterView->getFrame()->SetFocus(); - rasterView->getFrame()->Show(true); - } - *theApp->getLog() << m_pszLabel << "\n"; pImageFile->labelAdd (m_pProjView->GetDocument()->getProjections().getLabel()); pImageFile->labelAdd (m_pszLabel, getTimerEnd()); + wxCommandEvent eventLog (wxEVT_COMMAND_MENU_SELECTED, MAINMENU_LOG_EVENT ); + wxString msg (m_pszLabel); + msg += "\n"; + eventLog.SetString( msg ); + wxPostEvent( theApp->getMainFrame(), eventLog ); // send log event + + wxCommandEvent newImageEvent (wxEVT_COMMAND_MENU_SELECTED, NEW_IMAGEFILE_EVENT); + newImageEvent.SetClientData (pImageFile); + wxPostEvent (theApp->getMainFrame(), newImageEvent); + setDone(); } @@ -197,6 +190,7 @@ ReconstructorSupervisor::getImageFile() // ///////////////////////////////////////////////////////////////////// +void ReconstructorWorker::SetParameters (ProjectionFileView* pProjView, ImageFile* pImageFile, const char* pszFilterName, double dFilterParam, const char* pszFilterMethod, int iZeropad, const char* pszFilterGenerationName, const char* pszInterpName, int iInterpParam, @@ -221,46 +215,52 @@ ReconstructorWorker::Entry () *m_pImageFile, m_pszFilterName, m_dFilterParam, m_pszFilterMethod, m_iZeropad, m_pszFilterGenerationName, m_pszInterpName, m_iInterpParam, m_pszBackprojectName, Trace::TRACE_NONE); - wxCommandEvent eventDone (wxEVT_COMMAND_MENU_SELECTED, BackgroundSupervisor::MSG_WORKER_THREAD_DONE); - eventDone.SetInt (m_iThread); // Send back thread# that has finished - - if (pReconstructor->fail()) { - wxString msg("Unable to make reconstructor: "); - msg += pReconstructor->failMessage().c_str(); + bool bFail = pReconstructor->fail(); + wxString failMsg; + if (bFail) { + failMsg = "Unable to make reconstructor: "; + failMsg += pReconstructor->failMessage().c_str(); wxCommandEvent event( wxEVT_COMMAND_MENU_SELECTED, MAINMENU_LOG_EVENT ); - event.SetString( msg ); + event.SetString( failMsg ); wxPostEvent( theApp->getMainFrame(), event ); - - wxPostEvent (m_pSupervisor, eventDone); - return reinterpret_cast(-1); } - - wxCommandEvent eventProgress (wxEVT_COMMAND_MENU_SELECTED, BackgroundSupervisor::MSG_WORKER_THREAD_UNIT_TICK); - - for (int iUnit = 0; iUnit < m_iNumUnits; iUnit++) { - if (TestDestroy()) { + else + { + wxCommandEvent eventProgress (wxEVT_COMMAND_MENU_SELECTED, BackgroundSupervisor::MSG_WORKER_THREAD_UNIT_TICK); + for (int iUnit = 0; iUnit < m_iNumUnits; iUnit++) { + if (TestDestroy()) { #ifdef DEBUG - if (theApp->getVerboseLogging()) { - wxString msg; - msg.Printf("Worker thread: Received destroy message at work unit #%d\n", iUnit); - wxCommandEvent event( wxEVT_COMMAND_MENU_SELECTED, MAINMENU_LOG_EVENT ); - event.SetString( msg ); - wxPostEvent( theApp->getMainFrame(), event ); - } + if (theApp->getVerboseLogging()) { + wxString msg; + msg.Printf("Worker thread: Received destroy message at work unit #%d\n", iUnit); + wxCommandEvent event( wxEVT_COMMAND_MENU_SELECTED, MAINMENU_LOG_EVENT ); + event.SetString( msg ); + wxPostEvent( theApp->getMainFrame(), event ); + } #endif - delete pReconstructor; - wxPostEvent (m_pSupervisor, eventDone); - - return reinterpret_cast(-1); + break; + } + pReconstructor->reconstructView (iUnit + m_iStartUnit, 1); + m_pSupervisor->AddPendingEvent (eventProgress); } - pReconstructor->reconstructView (iUnit + m_iStartUnit, 1); - wxPostEvent (m_pSupervisor, eventProgress); + pReconstructor->postProcessing(); } - pReconstructor->postProcessing(); - - wxPostEvent (m_pSupervisor, eventDone); - delete pReconstructor; + + if (bFail) { + wxCommandEvent eventFail (wxEVT_COMMAND_MENU_SELECTED, BackgroundSupervisor::MSG_WORKER_THREAD_FAIL); + eventFail.SetInt (m_iThread); // Send back thread# that has finished + eventFail.SetString (failMsg); + wxPostEvent (m_pSupervisor, eventFail); + } else { + wxCommandEvent eventDone (wxEVT_COMMAND_MENU_SELECTED, BackgroundSupervisor::MSG_WORKER_THREAD_DONE); + eventDone.SetInt (m_iThread); // Send back thread# that has finished + wxPostEvent (m_pSupervisor, eventDone); + } + + while (! TestDestroy()) + Sleep(100); + return reinterpret_cast(0); } @@ -268,3 +268,5 @@ void ReconstructorWorker::OnExit () { } + +#endif // HAVE_WXTHREADS