X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=src%2Fthreadrecon.cpp;h=519fcb0e0194bcd6e30376bdf5c8094362a6f1e0;hp=51b930d536ea416eb801d651989d767716051868;hb=a65971e957a117618b33070897f11a4116f38e1f;hpb=df521cfe14a9e0b47bdcd98d1f67d03acf242162 diff --git a/src/threadrecon.cpp b/src/threadrecon.cpp index 51b930d..519fcb0 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.12 2001/02/25 10:52:55 kevin Exp $ +** $Id: threadrecon.cpp,v 1.22 2001/03/07 21:18:50 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,14 +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); - Yield(); + while (! reconSupervisor.workersDone() && ! reconSupervisor.fail() && ! reconSupervisor.cancelled()) { + Sleep(100); } if (reconSupervisor.fail()) { @@ -83,13 +82,11 @@ ReconstructorSupervisorThread::Entry() eventLog.SetString( msg ); wxPostEvent( theApp->getMainFrame(), eventLog ); // send log event } + if (! reconSupervisor.cancelled()) + reconSupervisor.onDone(); + reconSupervisor.deleteWorkers(); - while (! reconSupervisor.workersDeleted()) { - Sleep(50); - reconSupervisor.ProcessPendingEvents(); - } - - return reinterpret_cast(0); + return static_cast(0); } void @@ -104,20 +101,20 @@ 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) - : m_pProjView(pProjView), m_pProjDoc(pProjView->GetDocument()), + : BackgroundSupervisor (pThread, pProjView->GetFrame(), pProjView->GetDocument(), "Reconstructing", pProjView->GetDocument()->getProjections().nView()), + m_pProjView(pProjView), m_pProjDoc(pProjView->GetDocument()), m_iImageNX(iImageNX), m_iImageNY(iImageNY), 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()) + m_iInterpParam(iInterpParam), m_pszBackprojectName(pszBackprojectName), m_pszLabel(pszLabel) { 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); } } @@ -147,26 +144,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(); } @@ -222,12 +213,12 @@ ReconstructorWorker::Entry () m_pszFilterGenerationName, m_pszInterpName, m_iInterpParam, m_pszBackprojectName, Trace::TRACE_NONE); bool bFail = pReconstructor->fail(); - wxString failMsg; + std::string failMsg; if (bFail) { failMsg = "Unable to make reconstructor: "; failMsg += pReconstructor->failMessage().c_str(); wxCommandEvent event( wxEVT_COMMAND_MENU_SELECTED, MAINMENU_LOG_EVENT ); - event.SetString( failMsg ); + event.SetString( failMsg.c_str() ); wxPostEvent( theApp->getMainFrame(), event ); } else @@ -247,21 +238,16 @@ ReconstructorWorker::Entry () break; } pReconstructor->reconstructView (iUnit + m_iStartUnit, 1); - m_pSupervisor->AddPendingEvent (eventProgress); + m_pSupervisor->onWorkerUnitTick(); } pReconstructor->postProcessing(); } 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); + m_pSupervisor->onWorkerFail (m_iThread, failMsg); } 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); + m_pSupervisor->onWorkerDone (m_iThread); } while (! TestDestroy()) @@ -274,3 +260,5 @@ void ReconstructorWorker::OnExit () { } + +#endif // HAVE_WXTHREADS