X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=src%2Fthreadrecon.cpp;h=8c5cb0574bb95303874236030868877a639b0332;hp=53d1ef45cbfb5e6a17e1803e8b217a416fc43555;hb=f7ee98f7d964ed361068179f0e7ea4475ed1abdf;hpb=8bf5da21ee7bc7417c385da8c4fb0b67025804fa diff --git a/src/threadrecon.cpp b/src/threadrecon.cpp index 53d1ef4..8c5cb05 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.11 2001/02/25 08:43:03 kevin Exp $ +** $Id$ ** ** 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 + @@ -51,45 +51,50 @@ // ///////////////////////////////////////////////////////////////////// -ReconstructorSupervisorThread::ReconstructorSupervisorThread (ProjectionFileView* pProjView, int iNX, int iNY, - 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_iNX(iNX), m_iNY(iNY), m_strFilterName(pszFilterName), m_dFilterParam(dFilterParam), - m_strFilterMethod(pszFilterMethod), m_iZeropad(iZeropad), m_strFilterGenerationName(pszFilterGenerationName), - m_strInterpName(pszInterpName), m_iInterpParam(iInterpParam), m_strBackprojectName(pszBackprojectName), m_strLabel(pszLabel), - SupervisorThread() +ReconstructorSupervisorThread::ReconstructorSupervisorThread (ProjectionFileView* pProjView, int iNX, int iNY, + const char* pszFilterName, double dFilterParam, const char* pszFilterMethod, int iZeropad, + const char* pszFilterGenerationName, const char* pszInterpName, int iInterpParam, + const char* pszBackprojectName, wxChar const* pszLabel, ReconstructionROI* pROI, bool bRebinToParallel) +: SupervisorThread(), m_pProjView(pProjView), m_iNX(iNX), m_iNY(iNY), m_strFilterName(pszFilterName), m_dFilterParam(dFilterParam), + m_strFilterMethod(pszFilterMethod), m_iZeropad(iZeropad), m_strFilterGenerationName(pszFilterGenerationName), + m_strInterpName(pszInterpName), m_iInterpParam(iInterpParam), m_strBackprojectName(pszBackprojectName), + m_strLabel(pszLabel), m_reconROI(*pROI), m_bRebinToParallel(bRebinToParallel) { } wxThread::ExitCode ReconstructorSupervisorThread::Entry() { - ReconstructorSupervisor reconSupervisor (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()); + Projections* pProj = &m_pProjView->GetDocument()->getProjections(); + + if (m_bRebinToParallel) + pProj = pProj->interpolateToParallel(); + + ReconstructorSupervisor reconSupervisor (this, pProj, 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, &m_reconROI); reconSupervisor.start(); - while (! reconSupervisor.isDone() && ! reconSupervisor.fail()) { - Sleep(50); - Yield(); + while (! reconSupervisor.workersDone() && ! reconSupervisor.fail() && ! reconSupervisor.cancelled()) { + Sleep(100); } if (reconSupervisor.fail()) { - wxString msg ("Error starting reconstructor supervisor: "); - msg += reconSupervisor.getFailMessage().c_str(); - msg += "\n"; + wxString msg (_T("Error starting reconstructor supervisor: ")); + msg += reconSupervisor.getFailMessage(); + msg += _T("\n"); wxCommandEvent eventLog (wxEVT_COMMAND_MENU_SELECTED, MAINMENU_LOG_EVENT ); eventLog.SetString( msg ); wxPostEvent( theApp->getMainFrame(), eventLog ); // send log event } + if (! reconSupervisor.cancelled()) + reconSupervisor.onDone(); + reconSupervisor.deleteWorkers(); - while (! reconSupervisor.workersDeleted()) { - Sleep(50); - reconSupervisor.ProcessPendingEvents(); - } + if (m_bRebinToParallel) + delete pProj; - return reinterpret_cast(0); + return static_cast(0); } void @@ -104,20 +109,24 @@ ReconstructorSupervisorThread::OnExit() // ///////////////////////////////////////////////////////////////////// -ReconstructorSupervisor::ReconstructorSupervisor (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()), - m_iImageNX(iImageNX), m_iImageNY(iImageNY), +ReconstructorSupervisor::ReconstructorSupervisor (SupervisorThread* pThread, Projections* pProj, + 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, wxChar const* pszLabel, + ReconstructionROI* pROI) + : BackgroundSupervisor (pThread, pProjView->GetFrame(), pProjView->GetDocument(), + _T("Reconstructing"), + pProjView->GetDocument()->getProjections().nView()), + m_pProj(pProj), 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_strLabel(pszLabel), + m_pReconROI(pROI) { 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); } } @@ -134,9 +143,9 @@ BackgroundWorkerThread* ReconstructorSupervisor::createWorker (int iThread, int iStartUnit, int iNumUnits) { ReconstructorWorker* pThread = new ReconstructorWorker (this, iThread, iStartUnit, iNumUnits); - pThread->SetParameters (m_pProjView, m_vecpChildImageFile[iThread], m_pszFilterName, m_dFilterParam, - m_pszFilterMethod, m_iZeropad, m_pszFilterGenerationName, m_pszInterpName, - m_iInterpParam, m_pszBackprojectName); + pThread->SetParameters (m_pProj, m_pProjView, m_vecpChildImageFile[iThread], m_pszFilterName, + m_dFilterParam, m_pszFilterMethod, m_iZeropad, m_pszFilterGenerationName, m_pszInterpName, + m_iInterpParam, m_pszBackprojectName, m_pReconROI); return pThread; } @@ -147,25 +156,19 @@ 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()); + pImageFile->labelAdd (m_pProj->getLabel()); + pImageFile->labelAdd (m_strLabel.mb_str(wxConvUTF8), getTimerEnd()); + + wxCommandEvent eventLog (wxEVT_COMMAND_MENU_SELECTED, MAINMENU_LOG_EVENT ); + wxString msg (m_strLabel); + msg += _T("\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(); } @@ -177,7 +180,7 @@ ReconstructorSupervisor::getImageFile() ImageFile* pImageFile = new ImageFile (m_iImageNX, m_iImageNY); pImageFile->arrayDataClear(); ImageFileArray pArray = pImageFile->getArray(); - + int i; for (i = 0; i < getNumWorkers(); i++) { ImageFileArrayConst pChildArray = m_vecpChildImageFile[i]->getArray(); @@ -185,7 +188,7 @@ ReconstructorSupervisor::getImageFile() for (int iy = 0; iy < m_iImageNY; iy++) pArray[ix][iy] += pChildArray[ix][iy]; } - + return (pImageFile); } @@ -196,37 +199,40 @@ ReconstructorSupervisor::getImageFile() // ///////////////////////////////////////////////////////////////////// -ReconstructorWorker::SetParameters (ProjectionFileView* pProjView, ImageFile* pImageFile, +void +ReconstructorWorker::SetParameters (const Projections* pProj, ProjectionFileView* pProjView, ImageFile* pImageFile, const char* pszFilterName, double dFilterParam, const char* pszFilterMethod, int iZeropad, - const char* pszFilterGenerationName, const char* pszInterpName, int iInterpParam, - const char* pszBackprojectName) + const char* pszFilterGenerationName, const char* pszInterpName, int iInterpParam, + const char* pszBackprojectName, ReconstructionROI* pROI) { + m_pProj = pProj; m_pProjView = pProjView; m_pImageFile = pImageFile; m_pszFilterName = pszFilterName; - m_dFilterParam = dFilterParam; + m_dFilterParam = dFilterParam; m_pszFilterMethod = pszFilterMethod; m_iZeropad = iZeropad; m_pszFilterGenerationName = pszFilterGenerationName; m_pszInterpName = pszInterpName; m_iInterpParam = iInterpParam; m_pszBackprojectName = pszBackprojectName; + m_pReconROI = pROI; } wxThread::ExitCode ReconstructorWorker::Entry () { - Reconstructor* pReconstructor = new Reconstructor (m_pProjView->GetDocument()->getProjections(), - *m_pImageFile, m_pszFilterName, m_dFilterParam, m_pszFilterMethod, m_iZeropad, - m_pszFilterGenerationName, m_pszInterpName, m_iInterpParam, m_pszBackprojectName, Trace::TRACE_NONE); + Reconstructor* pReconstructor = new Reconstructor (*m_pProj, *m_pImageFile, m_pszFilterName, + m_dFilterParam, m_pszFilterMethod, m_iZeropad, m_pszFilterGenerationName, m_pszInterpName, + m_iInterpParam, m_pszBackprojectName, Trace::TRACE_NONE, m_pReconROI, false); bool bFail = pReconstructor->fail(); wxString failMsg; if (bFail) { - failMsg = "Unable to make reconstructor: "; - failMsg += pReconstructor->failMessage().c_str(); + failMsg = _T("Unable to make reconstructor: "); + failMsg += wxConvUTF8.cMB2WX(pReconstructor->failMessage().c_str()); wxCommandEvent event( wxEVT_COMMAND_MENU_SELECTED, MAINMENU_LOG_EVENT ); - event.SetString( failMsg ); + event.SetString( failMsg ); wxPostEvent( theApp->getMainFrame(), event ); } else @@ -237,30 +243,25 @@ ReconstructorWorker::Entry () #ifdef DEBUG if (theApp->getVerboseLogging()) { wxString msg; - msg.Printf("Worker thread: Received destroy message at work unit #%d\n", iUnit); + msg.Printf(_T("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 ); + wxPostEvent( theApp->getMainFrame(), event ); } #endif 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()) @@ -273,3 +274,5 @@ void ReconstructorWorker::OnExit () { } + +#endif // HAVE_WXTHREADS