+
+
+// PhantomCanvas
+
+PhantomCanvas::PhantomCanvas (PhantomView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
+ : wxScrolledWindow(frame, -1, pos, size, style)
+{
+ m_pView = v;
+}
+
+void
+PhantomCanvas::OnDraw(wxDC& dc)
+{
+ if (m_pView)
+ m_pView->OnDraw(& dc);
+}
+
+
+// PhantomView
+
+IMPLEMENT_DYNAMIC_CLASS(PhantomView, wxView)
+
+BEGIN_EVENT_TABLE(PhantomView, wxView)
+ EVT_MENU(PHMMENU_FILE_PROPERTIES, PhantomView::OnProperties)
+ EVT_MENU(PHMMENU_PROCESS_RASTERIZE, PhantomView::OnRasterize)
+ EVT_MENU(PHMMENU_PROCESS_PROJECTIONS, PhantomView::OnProjections)
+END_EVENT_TABLE()
+
+PhantomView::PhantomView(void)
+ : wxView(), m_canvas(NULL), m_frame(NULL)
+{
+ m_iDefaultNDet = 367;
+ m_iDefaultNView = 320;
+ m_iDefaultNSample = 2;
+ m_dDefaultRotation = 2;
+ m_dDefaultFocalLength = 2;
+ m_dDefaultFieldOfView = 1;
+ m_iDefaultGeometry = Scanner::GEOMETRY_PARALLEL;
+ m_iDefaultTrace = Trace::TRACE_NONE;
+}
+
+PhantomView::~PhantomView(void)
+{
+}
+
+void
+PhantomView::OnProperties (wxCommandEvent& event)
+{
+ const int idPhantom = GetDocument()->getPhantomID();
+ const wxString& namePhantom = GetDocument()->getPhantomName();
+ ostringstream os;
+ os << "Phantom " << namePhantom.c_str() << " (" << idPhantom << ")\n";
+ *theApp->getLog() << os.str().c_str();
+#if DEBUG
+ const Phantom& rPhantom = GetDocument()->getPhantom();
+ rPhantom.print();
+#endif
+}
+
+
+void
+PhantomView::OnProjections (wxCommandEvent& event)
+{
+ DialogGetProjectionParameters dialogProjection (m_frame, m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample, m_dDefaultRotation, m_dDefaultFocalLength, m_dDefaultFieldOfView, m_iDefaultGeometry, m_iDefaultTrace);
+ int retVal = dialogProjection.ShowModal();
+ if (retVal == wxID_OK) {
+ m_iDefaultNDet = dialogProjection.getNDet();
+ m_iDefaultNView = dialogProjection.getNView();
+ m_iDefaultNSample = dialogProjection.getNSamples();
+ m_iDefaultTrace = dialogProjection.getTrace();
+ m_dDefaultRotation = dialogProjection.getRotAngle();
+ m_dDefaultFocalLength = dialogProjection.getFocalLengthRatio();
+ m_dDefaultFieldOfView = dialogProjection.getFieldOfViewRatio();
+ wxString sGeometry = dialogProjection.getGeometry();
+ m_iDefaultGeometry = Scanner::convertGeometryNameToID (sGeometry.c_str());
+
+ if (m_iDefaultNDet > 0 && m_iDefaultNView > 0 && sGeometry != "") {
+ const Phantom& rPhantom = GetDocument()->getPhantom();
+ ProjectionFileDocument* pProjectionDoc = dynamic_cast<ProjectionFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.pj", wxDOC_SILENT));
+ Projections& rProj = pProjectionDoc->getProjections();
+ Scanner theScanner (rPhantom, sGeometry.c_str(), m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample, m_dDefaultRotation, m_dDefaultFocalLength, m_dDefaultFieldOfView);
+ if (theScanner.fail()) {
+ *theApp->getLog() << "Failed making scanner: " << theScanner.failMessage().c_str() << "\n";
+ return;
+ }
+ rProj.initFromScanner (theScanner);
+ m_dDefaultRotation /= PI; // convert back to PI units
+
+ if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
+ ProjectionsDialog dialogProjections (theScanner, rProj, rPhantom, m_iDefaultTrace, dynamic_cast<wxWindow*>(m_frame));
+ for (int iView = 0; iView < rProj.nView(); iView++) {
+ ::wxYield();
+ ::wxYield();
+ if (dialogProjections.isCancelled() || ! dialogProjections.projectView (iView)) {
+ pProjectionDoc->DeleteAllViews();
+ return;
+ }
+ ::wxYield();
+ ::wxYield();
+ while (dialogProjections.isPaused()) {
+ ::wxYield();
+ ::wxUsleep(50);
+ }
+ }
+ } else {
+ wxProgressDialog dlgProgress (wxString("Projection"), wxString("Projection Progress"), rProj.nView() + 1, m_frame, wxPD_CAN_ABORT);
+ for (int i = 0; i < rProj.nView(); i++) {
+ theScanner.collectProjections (rProj, rPhantom, i, 1, true, m_iDefaultTrace);
+ if (! dlgProgress.Update (i+1)) {
+ pProjectionDoc->DeleteAllViews();
+ return;
+ }
+ }
+ }
+
+ ostringstream os;
+ os << "Projections for " << rPhantom.name() << ": nDet=" << m_iDefaultNDet << ", nView=" << m_iDefaultNView << ", nSamples=" << m_iDefaultNSample << ", RotAngle=" << m_dDefaultRotation << ", FocalLengthRatio=" << m_dDefaultFocalLength << ", FieldOfViewRatio=" << m_dDefaultFieldOfView << ", Geometry=" << sGeometry.c_str() << "\n";
+ rProj.setRemark (os.str());
+ *theApp->getLog() << os.str().c_str();
+
+ m_frame->Lower();
+ ::wxYield();
+ if (wxView* pView = pProjectionDoc->GetFirstView()) {
+ if (wxFrame* pFrame = pView->GetFrame()) {
+ pFrame->SetFocus();
+ pFrame->Raise();
+ }
+ theApp->getDocManager()->ActivateView (pView, true, false);
+ }
+ ::wxYield();
+ pProjectionDoc->Modify(true);
+ pProjectionDoc->UpdateAllViews(this);
+ }