X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=src%2Fdlgreconstruct.cpp;h=5a6d46ab628a3bc49cd9bec4b7788fff216594c4;hp=e8e01e2872da6651b285191a5c8fb9d121506725;hb=3147cd44cff6132e51eac1a179c1fc3d405faacc;hpb=bfcc769cf8019eabc8c65c07257c8dbee4b4c977 diff --git a/src/dlgreconstruct.cpp b/src/dlgreconstruct.cpp index e8e01e2..5a6d46a 100644 --- a/src/dlgreconstruct.cpp +++ b/src/dlgreconstruct.cpp @@ -2,14 +2,14 @@ ** FILE IDENTIFICATION ** ** Name: dlgreconstruct.cpp -** Purpose: Projection Collection Animation Dialog +** Purpose: Reconstruction Animation Dialog ** Programmer: Kevin Rosenberg ** Date Started: August 2000 ** ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: dlgreconstruct.cpp,v 1.1 2000/09/02 05:13:57 kevin Exp $ +** $Id: dlgreconstruct.cpp,v 1.3 2000/09/04 09:06:46 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 @@ -47,9 +47,11 @@ #include "wx/settings.h" #include "wx/dcclient.h" #include "wx/timer.h" + #include "wx/image.h" #endif #include "dlgreconstruct.h" +#include #include "ct.h" @@ -68,7 +70,7 @@ IMPLEMENT_CLASS(ReconstructDialog, wxDialog) ReconstructDialog::ReconstructDialog (Reconstructor& rReconstruct, const Projections& rProj, ImageFile& rIF, const int iTrace, wxWindow *parent) - : wxDialog(parent, -1, "Collect Projections"), m_rReconstructor(rReconstruct), m_rProjections(rProj), m_rImageFile(rIF), m_pSGPDriver(NULL), m_pSGP(NULL), m_iTrace(iTrace), m_pDC(NULL), m_btnAbort(0), m_btnPause(0), m_btnStep(0) + : wxDialog(parent, -1, "Reconstruction"), m_rReconstructor(rReconstruct), m_rProjections(rProj), m_rImageFile(rIF), m_pSGPDriver(NULL), m_pSGP(NULL), m_iTrace(iTrace), m_pDC(NULL), m_btnAbort(0), m_btnPause(0), m_btnStep(0) { m_state = Continue; m_iLastView = -1; @@ -106,15 +108,22 @@ ReconstructDialog::ReconstructDialog (Reconstructor& rReconstruct, const Project SetAutoLayout(TRUE); Layout(); - wxSize sizeDlg (700,500); - if (sizeDlg.x != sizeDlg.y) { - sizeDlg.x = max(sizeDlg.x,sizeDlg.y); - sizeDlg.y = max(sizeDlg.x,sizeDlg.y); - } + m_nxGraph = 500; + m_nyGraph = 500; + wxSize sizeDlg (m_nxGraph, m_nyGraph); + m_nxImage = m_rImageFile.nx(); + if (m_nxImage > MAX_IMAGE_X) + m_nxImage = MAX_IMAGE_X; + m_nyImage = m_rImageFile.ny(); + if (m_nyImage > MAX_IMAGE_Y) + m_nyImage = MAX_IMAGE_Y; + + sizeDlg.x += m_nxImage; + sizeDlg.y = max (sizeDlg.y, m_nyImage); m_iClientX = sizeDlg.x; m_iClientY = sizeDlg.y; - SetClientSize(sizeDlg); + SetClientSize (sizeDlg); m_bitmap.Create (m_iClientX, m_iClientY); // save a copy of screen m_pDC = new wxMemoryDC; @@ -145,40 +154,71 @@ void ReconstructDialog::showView (int iViewNumber) { if ( iViewNumber < m_rProjections.nView() ) { - wxYield(); // update the display m_iLastView = iViewNumber; m_pSGP->eraseWindow(); - if (m_iTrace >= Trace::TRACE_PLOT) - m_pSGP->setViewport (0, 0, 1, 1); + char szProgress [256]; snprintf (szProgress, sizeof(szProgress), "Reconstructing View %d (%.1f%%)", iViewNumber, 100 * iViewNumber / static_cast(m_rProjections.nView())); - double wText, hText; + m_pSGP->setViewport (0, 0, 1, 1); + m_pSGP->setWindow (0, 0, 1, 1); m_pSGP->setTextColor (C_LTRED, -1); - m_pSGP->getTextExtent (szProgress, &wText, &hText); - double xw_max, xw_min, yw_max, yw_min; - m_pSGP->getWindow (xw_min, yw_min, xw_max, yw_max); - m_pSGP->moveAbs ((xw_max - xw_min) / 2 + xw_min - wText / 2, yw_max - hText); + double dCharHeight = m_pSGP->getCharHeight(); + m_pSGP->setTextSize (dCharHeight * 2); + m_pSGP->moveAbs(0., m_pSGP->getCharHeight()); m_pSGP->drawText (szProgress); - if (m_iTrace >= Trace::TRACE_PLOT) - m_pSGP->setViewport (0, .1, 0.66, 1); + m_pSGP->setTextSize (dCharHeight); + + m_pSGP->setViewport (0.0, 0.1, 0.66, 1.); m_rReconstructor.reconstructView (iViewNumber, 1, m_pSGP); - ::wxYield(); - m_pDC->SelectObject (wxNullBitmap); + ImageFileArrayConst v = m_rImageFile.getArray(); + int xBase = m_nxGraph; + int yBase = 0; + if (m_nyGraph > m_nyImage) + yBase = (m_nyGraph - m_nyImage) / 2; + double minValue = v[0][0]; + double maxValue = v[0][0]; + for (int ix = 0; ix < m_nxImage; ix++) { + for (int iy = 0; iy < m_nyImage; iy++) { + double dPixel = v[ix][iy]; + if (dPixel < minValue) + minValue = dPixel; + else if (dPixel > maxValue) + maxValue = dPixel; + } + } + unsigned char* imageData = new unsigned char [m_nxImage * m_nyImage * 3]; + double dScale = 255 / (maxValue - minValue); + for (int ix = 0; ix < m_nxImage; ix++) { + for (int iy = 0; iy < m_nyImage; iy++) { + double dPixel = v[ix][iy]; + dPixel = (dPixel - minValue) * dScale; + int intensity = nearest(dPixel); + intensity = clamp (intensity, 0, 255); + int baseAddr = ((m_nyImage - 1 - iy) * m_nxImage + ix) * 3; + imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity; + } + } + wxImage image (m_nxImage, m_nyImage, imageData, true); + wxBitmap bitmap = image.ConvertToBitmap(); + m_pSGP->getDriver().idWX()->DrawBitmap(bitmap, xBase, yBase, false); + delete imageData; + Refresh(); - m_pDC->SelectObject (m_bitmap); - ::wxYield(); } } bool ReconstructDialog::reconstructView (int iViewNumber) { + ::wxYield(); // update the display showView (iViewNumber); - wxYield(); // update the display - if (m_iTrace >= Trace::TRACE_PLOT) - sleep(1); - else { + ::wxYield(); // update the display + if (iViewNumber < m_rProjections.nView()) { + if (m_iTrace >= Trace::TRACE_PLOT) { + ::wxUsleep(250); + } + } else { m_state = Finished; // so that we return TRUE below and } // that [Cancel] handler knew what to do @@ -186,6 +226,7 @@ ReconstructDialog::reconstructView (int iViewNumber) MacUpdateImmediately(); #endif + ::wxYield(); // update the display return m_state != Cancelled; } @@ -257,9 +298,7 @@ void ReconstructDialog::OnPaint (wxPaintEvent& event) { wxPaintDC paintDC (this); - if (m_state == Paused) { - paintDC.DrawBitmap(m_bitmap, 0, 0, false); - } + paintDC.DrawBitmap(m_bitmap, 0, 0, false); }