From 1fd4f7cc977b9f1499716de10d15656bd50f4816 Mon Sep 17 00:00:00 2001 From: "Kevin M. Rosenberg" Date: Thu, 13 Jul 2000 07:01:59 +0000 Subject: [PATCH] r144: Initial CVS import --- src/Makefile.am | 63 +---- src/ctsim.cpp | 131 ++++++++++ src/ctsim.h | 76 ++++++ src/docs.cpp | 117 +++++++++ src/docs.h | 100 ++++++++ src/sample-ctsim.sh.in | 41 --- src/views.cpp | 527 ++++++++++++++++++++++++++++++++++++++ src/views.h | 156 +++++++++++ tools/Makefile.am | 62 +++++ {src => tools}/if-1.cpp | 2 +- {src => tools}/if-2.cpp | 42 +-- {src => tools}/if2img.cpp | 4 +- {src => tools}/ifinfo.cpp | 2 +- tools/mpiworld.cpp | 84 ++++++ {src => tools}/phm2if.cpp | 2 +- {src => tools}/phm2pj.cpp | 2 +- {src => tools}/pj2if.cpp | 16 +- {src => tools}/pjrec.cpp | 2 +- 18 files changed, 1293 insertions(+), 136 deletions(-) create mode 100644 src/ctsim.cpp create mode 100644 src/ctsim.h create mode 100644 src/docs.cpp create mode 100644 src/docs.h delete mode 100755 src/sample-ctsim.sh.in create mode 100644 src/views.cpp create mode 100644 src/views.h create mode 100644 tools/Makefile.am rename {src => tools}/if-1.cpp (98%) rename {src => tools}/if-2.cpp (89%) rename {src => tools}/if2img.cpp (99%) rename {src => tools}/ifinfo.cpp (98%) create mode 100644 tools/mpiworld.cpp rename {src => tools}/phm2if.cpp (99%) rename {src => tools}/phm2pj.cpp (99%) rename {src => tools}/pj2if.cpp (91%) rename {src => tools}/pjrec.cpp (99%) diff --git a/src/Makefile.am b/src/Makefile.am index 168ab30..9929768 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,63 +1,8 @@ -#SUBDIRS = ctsim -bin_PROGRAMS = pjrec phm2pj pj2if @lamprograms@ ifinfo phm2if if-1 if-2 if2img -bin_SCRIPTS = sample-ctsim.sh -EXTRA_PROGRAMS = pjrec-lam phm2pj-lam phm2if-lam -INCLUDES=@my_includes@ -EXTRA_DIST=Makefile.nt mpiworld.cpp -SOURCE_DEPEND=../include/ct.h ../libctsim/libctsim.a ../libctsupport/libctsupport.a ../libctgraphics/libctgraphics.a +bin_PROGRAMS=ctsim -pjrec_SOURCES = pjrec.cpp -pjrec_LDADD=@ctlibs@ -pjrec_DEPENDENCIES=$(SOURCE_DEPEND) -phm2pj_SOURCES=phm2pj.cpp -phm2pj_LDADD=@ctlibs@ -phm2pj_DEPENDENCIES=$(SOURCE_DEPEND) -phm2if_SOURCES = phm2if.cpp -phm2if_LDADD=@ctlibs@ -phm2if_DEPENDENCIES=$(SOURCE_DEPEND) -if2img_SOURCES = if2img.cpp -if2img_LDADD=@ctlibs@ -if2img_DEPENDENCIES=$(SOURCE_DEPEND) -pj2if_SOURCES = pj2if.cpp -pj2if_LDADD=@ctlibs@ -pj2if_DEPENDENCIES=$(SOURCE_DEPEND) -if_1_SOURCES=if-1.cpp -if_1_LDADD=@ctlibs@ -if_1_DEPENDENCIES=$(SOURCE_DEPEND) -if_2_SOURCES=if-2.cpp -if_2_LDADD=@ctlibs@ -if_2_DEPENDENCIES=$(SOURCE_DEPEND) -ifinfo_SOURCES = ifinfo.cpp -ifinfo_LDADD=@ctlibs@ -ifinfo_DEPENDENCIES=$(SOURCE_DEPEND) - -pjrec_lam_SOURCES=pjrec.cpp -pjrec_lam_LDADD=@ctlamlibs@ -phm2if_lam_SOURCES=phm2if.cpp -phm2if_lam_LDADD=@ctlamlibs@ -phm2pj_lam_SOURCES=phm2pj.cpp -phm2pj_lam_LDADD=@ctlamlibs@ - -realclean: - rm -f *.pgm *.if *~ *.pj - -if USE_LAM -CC_LAM = $(lamdir)/bin/balky -LAM_EXTRA_SRC = mpiworld.cpp - -pjrec-lam: pjrec.cpp mpiworld.cpp ../include/ct.h ../libctsim/libctsim.a ../libctsupport/libctsupport.a - $(CC_LAM) @DEFS@ $(CFLAGS) $(INCLUDES) -DHAVE_MPI pjrec.cpp -o pjrec-lam $(LDFLAGS) $(LAM_EXTRA_SRC) @ctlibs@ - -phm2pj-lam: phm2pj.cpp mpiworld.cpp ../include/ct.h ../libctsim/libctsim.a ../libctsupport/libctsupport.a - $(CC_LAM) @DEFS@ $(CFLAGS) $(INCLUDES) -DHAVE_MPI phm2pj.cpp -o phm2pj-lam $(LDFLAGS) $(LAM_EXTRA_SRC) @ctlibs@ - -phm2if-lam: phm2if.cpp mpiworld.cpp ../include/ct.h ../libctsim/libctsim.a ../libctsupport/libctsupport.a - $(CC_LAM) @DEFS@ $(CFLAGS) $(INCLUDES) -DHAVE_MPI phm2if.cpp -o phm2if-lam $(LDFLAGS) $(LAM_EXTRA_SRC) @ctlibs@ - -endif - -shared: pjrec.cpp phm2pj.cpp - $(CC) @DEFS@ $(CFLAGS) $(INCLUDES) -DNO_MAIN -shared phm2pj.cpp pjrec.cpp @ctlibs@ $(LDFLAGS) -o ir.so +ctsim_SOURCES=ctsim.cpp docs.cpp views.cpp +ctsim_DEPENDENCIES=../libctgraphics/libctgraphics.a ../libctsupport/libctsupport.a ../libctsim/libctsim.a ../include/ct.h +ctsim_LDADD=-L../libctgraphics -L../libctsupport -L../libctsim @wxlibs@ diff --git a/src/ctsim.cpp b/src/ctsim.cpp new file mode 100644 index 0000000..0f7bc4e --- /dev/null +++ b/src/ctsim.cpp @@ -0,0 +1,131 @@ +/***************************************************************************** +** FILE IDENTIFICATION +** +** Name: ctsim.h +** Purpose: Header file for top-level routines of CTSim program +** Programmer: Kevin Rosenberg +** Date Started: July 2000 +** +** This is part of the CTSim program +** Copyright (C) 1983-2000 Kevin Rosenberg +** +** $Id: ctsim.cpp,v 1.4 2000/07/13 07:01:59 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 +** published by the Free Software Foundation. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +******************************************************************************/ + +// For compilers that support precompilation, includes "wx/wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ +#pragma hdrstop +#endif + +#ifndef WX_PRECOMP +#include "wx/wx.h" +#endif + +#if !wxUSE_DOC_VIEW_ARCHITECTURE +#error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in setup.h! +#endif + +#include "wx/docview.h" + +#include "ctsim.h" +#include "docs.h" +#include "views.h" + +IMPLEMENT_APP(CTSimApp) + +CTSimApp::CTSimApp(void) + : m_docManager(NULL), m_pFrame(NULL) +{ +} + +bool +CTSimApp::OnInit(void) +{ + m_docManager = new wxDocManager; + + (void) new wxDocTemplate (m_docManager, "ImageFile", "*.if", "", "if", "ImageFile doc", "ImageFile View", CLASSINFO(ImageFileDocument), CLASSINFO(ImageFileView)); + + (void) new wxDocTemplate (m_docManager, "ProjectionFile", "*.pj", "", "pj", "ProjectionFile doc", "ProjectionFile View", CLASSINFO(ProjectionFileDocument), CLASSINFO(ProjectionFileView)); + + //// Create the main frame window + m_pFrame = new MainFrame(m_docManager, (wxFrame *) NULL, -1, "CTSim", wxPoint(0, 0), wxSize(500, 400), wxDEFAULT_FRAME_STYLE); + + //// Make a menubar + wxMenu *file_menu = new wxMenu; + + // file_menu->Append(wxID_NEW, "&New..."); + file_menu->Append(wxID_OPEN, "&Open..."); + + file_menu->AppendSeparator(); + file_menu->Append(MAINMENU_FILE_EXIT, "E&xit"); + + // A nice touch: a history of files visited. Use this menu. + m_docManager->FileHistoryUseMenu(file_menu); + + wxMenu *help_menu = new wxMenu; + help_menu->Append(MAINMENU_HELP_ABOUT, "&About"); + + wxMenuBar *menu_bar = new wxMenuBar; + + menu_bar->Append(file_menu, "&File"); + menu_bar->Append(help_menu, "&Help"); + + m_pFrame->SetMenuBar(menu_bar); + + m_pFrame->Centre(wxBOTH); + m_pFrame->Show(true); + + SetTopWindow (m_pFrame); + return true; +} + +int +CTSimApp::OnExit(void) +{ + delete m_docManager; + return 0; +} + + +// Top-level window for CTSim + +IMPLEMENT_CLASS(MainFrame, wxDocParentFrame) +BEGIN_EVENT_TABLE(MainFrame, wxDocParentFrame) + EVT_MENU(MAINMENU_HELP_ABOUT, MainFrame::OnAbout) + EVT_MENU(MAINMENU_FILE_EXIT, MainFrame::OnExit) +END_EVENT_TABLE() + +MainFrame::MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type) + : wxDocParentFrame(manager, frame, id, title, pos, size, type) +{ + CreateStatusBar(); + SetStatusText ("Welcome to CTSim"); +} + +void +MainFrame::OnAbout(wxCommandEvent& WXUNUSED(event) ) +{ + wxMessageBox("CTSim\nAuthor: Kevin Rosenberg \nUsage: ctsim", "About CTSim", wxOK | wxICON_INFORMATION, this); +} + +void +MainFrame::OnExit (wxCommandEvent& WXUNUSED(event) ) +{ + Close(true); +} + diff --git a/src/ctsim.h b/src/ctsim.h new file mode 100644 index 0000000..db4d7c3 --- /dev/null +++ b/src/ctsim.h @@ -0,0 +1,76 @@ +/***************************************************************************** +** FILE IDENTIFICATION +** +** Name: ctsim.cpp +** Purpose: Top-level routines for CTSim program +** Programmer: Kevin Rosenberg +** Date Started: July 2000 +** +** This is part of the CTSim program +** Copyright (C) 1983-2000 Kevin Rosenberg +** +** $Id: ctsim.h,v 1.1 2000/07/13 07:01:59 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 +** published by the Free Software Foundation. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +******************************************************************************/ + +#ifndef __CTSIMH__ +#define __CTSIMH__ + +#include "wx/docview.h" + +class wxDocManager; +class MainFrame; +class CTSimApp: public wxApp +{ +public: + CTSimApp(void); + bool OnInit(void); + int OnExit(void); + MainFrame* getMainFrame(void) const + { return m_pFrame; } + +protected: + wxDocManager* m_docManager; + MainFrame* m_pFrame; +}; + +DECLARE_APP(CTSimApp) + +// Define a new frame +class MainFrame: public wxDocParentFrame +{ + DECLARE_CLASS(MainFrame) + +public: + MainFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long type); + + void OnAbout (wxCommandEvent& event); + void OnExit (wxCommandEvent& event); + + DECLARE_EVENT_TABLE() +}; + +extern MainFrame *GetMainFrame(void); + + +enum { + MAINMENU_HELP_ABOUT = 500, + MAINMENU_FILE_EXIT, + IFMENU_FILE_PROPERTIES, + PJMENU_FILE_PROPERTIES, + PJMENU_FILE_RECONSTRUCT, +}; + +#endif diff --git a/src/docs.cpp b/src/docs.cpp new file mode 100644 index 0000000..d5abb54 --- /dev/null +++ b/src/docs.cpp @@ -0,0 +1,117 @@ +/***************************************************************************** +** FILE IDENTIFICATION +** +** Name: doc.cpp +** Purpose: Document routines for CTSim program +** Programmer: Kevin Rosenberg +** Date Started: July 2000 +** +** This is part of the CTSim program +** Copyright (C) 1983-2000 Kevin Rosenberg +** +** $Id: docs.cpp,v 1.1 2000/07/13 07:01:59 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 +** published by the Free Software Foundation. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +******************************************************************************/ + +#ifdef __GNUG__ +// #pragma implementation +#endif + +// For compilers that support precompilation, includes "wx/wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ +#pragma hdrstop +#endif + +#ifndef WX_PRECOMP +#include "wx/wx.h" +#endif +#include "wx/txtstrm.h" + +#if !wxUSE_DOC_VIEW_ARCHITECTURE +#error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in setup.h! +#endif + +#include "docs.h" +#include "views.h" + + + +// ImageFileDocument + +IMPLEMENT_DYNAMIC_CLASS(ImageFileDocument, wxDocument) + +bool ImageFileDocument::OnSaveDocument(const wxString& filename) +{ + if (!m_imageFile.fileWrite (filename)) + return false; + Modify(false); + return true; +} + +bool ImageFileDocument::OnOpenDocument(const wxString& filename) +{ + if (! m_imageFile.fileRead (filename)) + return false; + + SetFilename(filename, true); + Modify(false); + UpdateAllViews(); + return true; +} + +bool ImageFileDocument::IsModified(void) const +{ + return wxDocument::IsModified(); +} + +void ImageFileDocument::Modify(bool mod) +{ + wxDocument::Modify(mod); +} + +// ProjectionFileDocument + +IMPLEMENT_DYNAMIC_CLASS(ProjectionFileDocument, wxDocument) + +bool ProjectionFileDocument::OnSaveDocument(const wxString& filename) +{ + if (!m_projectionFile.write (filename)) + return false; + Modify(false); + return true; +} + +bool ProjectionFileDocument::OnOpenDocument(const wxString& filename) +{ + if (! m_projectionFile.read (filename)) + return false; + + SetFilename(filename, true); + Modify(false); + UpdateAllViews(); + return true; +} + +bool ProjectionFileDocument::IsModified(void) const +{ + return wxDocument::IsModified(); +} + +void ProjectionFileDocument::Modify(bool mod) +{ + wxDocument::Modify(mod); +} diff --git a/src/docs.h b/src/docs.h new file mode 100644 index 0000000..1cd4c40 --- /dev/null +++ b/src/docs.h @@ -0,0 +1,100 @@ +/***************************************************************************** +** FILE IDENTIFICATION +** +** Name: doc.h +** Purpose: Header file for Document routines of CTSim program +** Programmer: Kevin Rosenberg +** Date Started: July 2000 +** +** This is part of the CTSim program +** Copyright (C) 1983-2000 Kevin Rosenberg +** +** $Id: docs.h,v 1.1 2000/07/13 07:01:59 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 +** published by the Free Software Foundation. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +******************************************************************************/ + +#ifdef __GNUG__ +// #pragma interface +#endif + +#ifndef __DOCSH__ +#define __DOCSH__ + +#include "wx/docview.h" +#include "imagefile.h" +#include "projections.h" + + +class ImageFileDocument: public wxDocument +{ + DECLARE_DYNAMIC_CLASS(ImageFileDocument) +private: + ImageFile m_imageFile; + +public: + virtual bool OnSaveDocument(const wxString& filename); + virtual bool OnOpenDocument(const wxString& filename); + virtual bool IsModified(void) const; + virtual void Modify(bool mod); + + ImageFileDocument(void) {} + ~ImageFileDocument(void) {} + + const ImageFile& getImageFile(void) const + { return m_imageFile; } + + ImageFile& getImageFile(void) + { return m_imageFile; } +}; + + +class ProjectionFileDocument: public wxDocument +{ + DECLARE_DYNAMIC_CLASS(ProjectionFileDocument) +private: + Projections m_projectionFile; + +public: + virtual bool OnSaveDocument(const wxString& filename); + virtual bool OnOpenDocument(const wxString& filename); + virtual bool IsModified(void) const; + virtual void Modify(bool mod); + + ProjectionFileDocument(void) {} + ~ProjectionFileDocument(void) {} + + const Projections& getProjections(void) const + { return m_projectionFile; } + + Projections& getProjections(void) + { return m_projectionFile; } +}; + +class TextEditDocument: public wxDocument +{ + DECLARE_DYNAMIC_CLASS(TextEditDocument) +private: +public: + virtual bool OnSaveDocument(const wxString& filename); + virtual bool OnOpenDocument(const wxString& filename); + virtual bool IsModified(void) const; + virtual void Modify(bool mod); + + TextEditDocument(void) {} + ~TextEditDocument(void) {} +}; + + +#endif diff --git a/src/sample-ctsim.sh.in b/src/sample-ctsim.sh.in deleted file mode 100755 index 1277641..0000000 --- a/src/sample-ctsim.sh.in +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/sh - -if test "$1" != "" ; then - bin=$1 -else - bin="@prefix@/bin/" -fi - -if test "$1" = "clean" ; then - rm -f sample-phm.png sample-phm16.png sample-phm.if sample-pj.pj sample-pj.if sample-pj.png sample-pj16.png sample-rec.if sample-rec.png sample-rec16.png - exit -fi - -# Generate phantom image - -${bin}phm2if sample-phm.if 256 256 --nsample 2 --phantom herman -if [ -f sample-phm.if ] ; then - ${bin}if2img sample-phm.if sample-phm.png --format png - ${bin}if2img sample-phm.if sample-phm16.png --format png16 -fi - -# Simulate CT data collection and generate raysum sinugram for display -${bin}phm2pj sample-pj.pj 367 320 --nray 2 --phantom herman -if [ -f sample-pj.pj ]; then - ${bin}pj2if sample-pj.pj sample-pj.if -fi -if [ -f sample-pj.if ]; then - ${bin}if2img sample-pj.if sample-pj.png --format png - ${bin}if2img sample-pj.if sample-pj16.png --format png16 -fi - -# Reconstruct raysums and generate image for display -${bin}pjrec sample-pj.pj sample-rec.if 256 256 -if [ -f sample-rec.if ]; then - ${bin}if2img sample-rec.if sample-rec.png --format png - ${bin}if2img sample-rec.if sample-rec16.png --format png16 - - ${bin}if-2 sample-phm.if sample-rec.if --comp -fi - -# Files sample-phm.png, sample-pj.png, and sample-rec.png are ready for display diff --git a/src/views.cpp b/src/views.cpp new file mode 100644 index 0000000..8a555ce --- /dev/null +++ b/src/views.cpp @@ -0,0 +1,527 @@ +/***************************************************************************** +** FILE IDENTIFICATION +** +** Name: view.cpp +** Purpose: View & Canvas routines for CTSim program +** Programmer: Kevin Rosenberg +** Date Started: July 2000 +** +** This is part of the CTSim program +** Copyright (C) 1983-2000 Kevin Rosenberg +** +** $Id: views.cpp,v 1.1 2000/07/13 07:01:59 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 +** published by the Free Software Foundation. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +******************************************************************************/ + +#ifdef __GNUG__ +// #pragma implementation +#endif + +// For compilers that support precompilation, includes "wx/wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ +#pragma hdrstop +#endif + +#ifndef WX_PRECOMP +#include "wx/wx.h" +#endif + +#if !wxUSE_DOC_VIEW_ARCHITECTURE +#error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in setup.h! +#endif + +#include "ctsim.h" +#include "docs.h" +#include "views.h" +#include +#include "ct.h" +//#include "imagefile.h" +//#include "phantom.h" +//#include "scanner.h" +//#include "projections.h" + +// ImageFileCanvas + +BEGIN_EVENT_TABLE(ImageFileCanvas, wxScrolledWindow) + EVT_MOUSE_EVENTS(ImageFileCanvas::OnMouseEvent) +END_EVENT_TABLE() + + +ImageFileCanvas::ImageFileCanvas (ImageFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style) + : wxScrolledWindow(frame, -1, pos, size, style) +{ + m_pView = v; +} + +void +ImageFileCanvas::OnDraw(wxDC& dc) +{ + if (m_pView) + m_pView->OnDraw(& dc); +} + +void +ImageFileCanvas::OnMouseEvent(wxMouseEvent& event) +{ + if (! m_pView) + return; + + wxClientDC dc(this); + PrepareDC(dc); + + dc.SetPen(*wxBLACK_PEN); + + wxPoint pt(event.GetLogicalPosition(dc)); + + if (event.LeftUp()) + cout << pt.x << "x" << pt.y << endl; +} + + +// ImageFileView + +IMPLEMENT_DYNAMIC_CLASS(ImageFileView, wxView) + +BEGIN_EVENT_TABLE(ImageFileView, wxView) + EVT_MENU(IFMENU_FILE_PROPERTIES, ImageFileView::OnProperties) +END_EVENT_TABLE() + +bool ImageFileView::m_bPColoursInitialized = false; +wxColour* ImageFileView::m_pColours[256]; + +ImageFileView::ImageFileView(void) + : wxView(), m_canvas(NULL), m_frame(NULL), m_bMinSpecified(false), m_bMaxSpecified(false) +{ + if (! m_bPColoursInitialized) { + for (int i = 0; i < 256; i++) + m_pColours[i] = new wxColour (i, i, i); + + m_bPColoursInitialized = true; + } +} + +ImageFileView::~ImageFileView(void) +{ +} + +void +ImageFileView::OnProperties (wxCommandEvent& event) +{ + double min, max, mean, mode, median, stddev; + const ImageFile& rIF = dynamic_cast(GetDocument())->getImageFile(); + const string& rFilename = rIF.getFilename(); + rIF.statistics (min, max, mean, mode, median, stddev); + ostringstream os; + os << "file: " << rFilename << "\nmin: "<GetClientSize(&width, &height); + + pCanvas = new ImageFileCanvas (dynamic_cast(view), parent, wxPoint(0, 0), wxSize(width, height), 0); + + pCanvas->SetScrollbars(20, 20, 50, 50); + pCanvas->SetBackgroundColour(*wxWHITE); + pCanvas->Clear(); + + return pCanvas; +} + +wxFrame* +ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view) +{ + wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, dynamic_cast(wxTheApp)->getMainFrame(), -1, "ImageFile Frame", wxPoint(10, 10), wxSize(300, 300), wxDEFAULT_FRAME_STYLE); + + wxMenu *file_menu = new wxMenu; + + file_menu->Append(wxID_NEW, "&New..."); + file_menu->Append(wxID_OPEN, "&Open..."); + file_menu->Append(wxID_CLOSE, "&Close"); + file_menu->Append(wxID_SAVE, "&Save"); + file_menu->Append(wxID_SAVEAS, "Save &As..."); + + file_menu->AppendSeparator(); + file_menu->Append(IFMENU_FILE_PROPERTIES, "P&roperties"); + + file_menu->AppendSeparator(); + file_menu->Append(wxID_PRINT, "&Print..."); + file_menu->Append(wxID_PRINT_SETUP, "Print &Setup..."); + file_menu->Append(wxID_PREVIEW, "Print Pre&view"); + + wxMenu *help_menu = new wxMenu; + help_menu->Append(MAINMENU_HELP_ABOUT, "&About"); + + wxMenuBar *menu_bar = new wxMenuBar; + + menu_bar->Append(file_menu, "&File"); + menu_bar->Append(help_menu, "&Help"); + + subframe->SetMenuBar(menu_bar); + + subframe->Centre(wxBOTH); + + return subframe; +} + + +bool +ImageFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) ) +{ + m_frame = CreateChildFrame(doc, this); + + m_bMinSpecified = false; + m_bMaxSpecified = false; + + int width, height; + m_frame->GetClientSize(&width, &height); + m_frame->SetTitle("ImageFileView"); + m_canvas = CreateCanvas(this, m_frame); + +#ifdef __X__ + int x, y; // X requires a forced resize + m_frame->GetSize(&x, &y); + m_frame->SetSize(-1, -1, x, y); +#endif + + m_frame->Show(true); + Activate(true); + + return true; +} + +void +ImageFileView::OnDraw (wxDC* dc) +{ + const ImageFile& rIF = dynamic_cast(GetDocument())->getImageFile(); + dc->Blit(static_cast(0), static_cast(0), static_cast(rIF.nx()), static_cast(rIF.ny()), &m_memoryDC, static_cast(0), static_cast(0)); +} + + +void +ImageFileView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) ) +{ + const ImageFile& rIF = dynamic_cast(GetDocument())->getImageFile(); + ImageFileArrayConst v = rIF.getArray(); + int nx = rIF.nx(); + int ny = rIF.ny(); + if (v != NULL && nx != 0 && ny != 0) { + if (! m_bMinSpecified || ! m_bMaxSpecified) { + double min, max; + rIF.getMinMax (min, max); + if (! m_bMinSpecified) + m_minPixel = min; + if (! m_bMaxSpecified) + m_maxPixel = max; + } + double scaleWidth = m_maxPixel - m_minPixel; + + m_pBitmap = new wxBitmap (rIF.nx(), rIF.ny()); + m_memoryDC.SelectObject (*m_pBitmap); + m_memoryDC.BeginDrawing(); + + wxPen pen (*m_pColours[128], 1, wxDOT); + m_memoryDC.SetPen (pen); + for (int ix = 0; ix < nx; ix++) { + for (int iy = 0; iy < ny; iy++) { + double scaleValue = ((v[ix][iy] - m_minPixel) / scaleWidth) * 255; + int intensity = static_cast(scaleValue + 0.5); + intensity = clamp (intensity, 0, 255); + pen.SetColour (*m_pColours[intensity]); + m_memoryDC.SetPen(pen); + m_memoryDC.DrawPoint(ix, ny - iy); + } + } + } + m_memoryDC.EndDrawing(); + + if (m_canvas) { + // m_canvas->SetScrollbars (50, 50, nx / 50, ny / 50, 0, 0, false); + m_canvas->Refresh(); + } + +#ifdef __WXMSW__ + if (m_canvas) + m_canvas->Refresh(); +#else + if (m_canvas) { + wxClientDC dc(m_canvas); + dc.Clear(); + OnDraw (&dc); + } +#endif +} + +bool +ImageFileView::OnClose (bool deleteWindow) +{ + if (!GetDocument()->Close()) + return false; + + m_canvas->Clear(); + m_canvas->m_pView = NULL; + m_canvas = NULL; + wxString s(wxTheApp->GetAppName()); + if (m_frame) + m_frame->SetTitle(s); + SetFrame(NULL); + + Activate(false); + + if (deleteWindow) { + delete m_frame; + return true; + } + return true; +} + + + +// ProjectionFileCanvas + +ProjectionFileCanvas::ProjectionFileCanvas (ProjectionFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style) + : wxScrolledWindow(frame, -1, pos, size, style) +{ + m_pView = v; +} + +void +ProjectionFileCanvas::OnDraw(wxDC& dc) +{ + if (m_pView) + m_pView->OnDraw(& dc); +} + +// ProjectionFileView + +IMPLEMENT_DYNAMIC_CLASS(ProjectionFileView, wxView) + +BEGIN_EVENT_TABLE(ProjectionFileView, wxView) + EVT_MENU(PJMENU_FILE_PROPERTIES, ProjectionFileView::OnProperties) + EVT_MENU(PJMENU_FILE_RECONSTRUCT, ProjectionFileView::OnReconstruct) +END_EVENT_TABLE() + +bool ProjectionFileView::m_bPColoursInitialized = false; +wxColour* ProjectionFileView::m_pColours[256]; + +ProjectionFileView::ProjectionFileView(void) + : wxView(), m_canvas(NULL), m_frame(NULL) +{ + if (! m_bPColoursInitialized) { + for (int i = 0; i < 256; i++) + m_pColours[i] = new wxColour (i, i, i); + + m_bPColoursInitialized = true; + } +} + +ProjectionFileView::~ProjectionFileView(void) +{ +} + +void +ProjectionFileView::OnProperties (wxCommandEvent& event) +{ + const Projections& rProj = dynamic_cast(GetDocument())->getProjections(); + const string& rFilename = rProj.getFilename(); + ostringstream os; + os << "file: " << rFilename << "\nDetectors: " << rProj.nDet() << "\nViews: " << rProj.nView(); + wxMessageBox(os.str().c_str(), "Projection Properties", wxOK | wxICON_INFORMATION, m_frame); +} + + +void +ProjectionFileView::OnReconstruct (wxCommandEvent& event) +{ + const Projections& rProj = dynamic_cast(GetDocument())->getProjections(); + const string& rFilename = rProj.getFilename(); + ostringstream os; + os << "Reconstruct file " << rFilename; + wxMessageBox(os.str().c_str(), "Reconstruction Dialog", wxOK | wxICON_INFORMATION, m_frame); +} + + +ProjectionFileCanvas* +ProjectionFileView::CreateCanvas (wxView *view, wxFrame *parent) +{ + ProjectionFileCanvas* pCanvas; + int width, height; + parent->GetClientSize(&width, &height); + + pCanvas = new ProjectionFileCanvas (dynamic_cast(view), parent, wxPoint(0, 0), wxSize(width, height), 0); + + pCanvas->SetScrollbars(20, 20, 50, 50); + pCanvas->SetBackgroundColour(*wxWHITE); + pCanvas->Clear(); + + return pCanvas; +} + +wxFrame* +ProjectionFileView::CreateChildFrame(wxDocument *doc, wxView *view) +{ + wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, dynamic_cast(wxTheApp)->getMainFrame(), -1, "ProjectionFile Frame", wxPoint(10, 10), wxSize(300, 300), wxDEFAULT_FRAME_STYLE); + + wxMenu *file_menu = new wxMenu; + + file_menu->Append(wxID_NEW, "&New..."); + file_menu->Append(wxID_OPEN, "&Open..."); + file_menu->Append(wxID_CLOSE, "&Close"); + file_menu->Append(wxID_SAVE, "&Save"); + file_menu->Append(wxID_SAVEAS, "Save &As..."); + + file_menu->AppendSeparator(); + file_menu->Append(PJMENU_FILE_RECONSTRUCT, "R&econstuct"); + file_menu->Append(PJMENU_FILE_PROPERTIES, "P&roperties"); + + file_menu->AppendSeparator(); + file_menu->Append(wxID_PRINT, "&Print..."); + file_menu->Append(wxID_PRINT_SETUP, "Print &Setup..."); + file_menu->Append(wxID_PREVIEW, "Print Pre&view"); + + wxMenu *help_menu = new wxMenu; + help_menu->Append(MAINMENU_HELP_ABOUT, "&About"); + + wxMenuBar *menu_bar = new wxMenuBar; + + menu_bar->Append(file_menu, "&File"); + menu_bar->Append(help_menu, "&Help"); + + subframe->SetMenuBar(menu_bar); + + subframe->Centre(wxBOTH); + + return subframe; +} + + +bool +ProjectionFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) ) +{ + m_frame = CreateChildFrame(doc, this); + + int width, height; + m_frame->GetClientSize(&width, &height); + m_frame->SetTitle("ProjectionFileView"); + m_canvas = CreateCanvas(this, m_frame); + +#ifdef __X__ + int x, y; // X requires a forced resize + m_frame->GetSize(&x, &y); + m_frame->SetSize(-1, -1, x, y); +#endif + + m_frame->Show(true); + Activate(true); + + return true; +} + +void +ProjectionFileView::OnDraw (wxDC* dc) +{ + const Projections& rProj = dynamic_cast(GetDocument())->getProjections(); + dc->Blit(static_cast(0), static_cast(0), static_cast(rProj.nDet()), static_cast(rProj.nView()), &m_memoryDC, static_cast(0), static_cast(0)); +} + + +void +ProjectionFileView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) ) +{ + const Projections& rProj = dynamic_cast(GetDocument())->getProjections(); + const DetectorArray& detarray = rProj.getDetectorArray (0); + const DetectorValue* detval = detarray.detValues(); + double min = detval[0]; + double max = detval[0]; + for (int iy = 0; iy < rProj.nView(); iy++) { + const DetectorArray& detarray = rProj.getDetectorArray (iy); + detval = detarray.detValues(); + for (int ix = 0; ix < rProj.nDet(); ix++) { + if (min > detval[ix]) + min = detval[ix]; + else if (max < detval[ix]) + max = detval[ix]; + } + } + + double scaleWidth = max - min; + + m_pBitmap = new wxBitmap (rProj.nDet(), rProj.nView()); + m_memoryDC.SelectObject (*m_pBitmap); + m_memoryDC.BeginDrawing(); + + wxPen pen (*m_pColours[128], 1, wxDOT); + m_memoryDC.SetPen (pen); + for (int iy = 0; iy < rProj.nView(); iy++) { + const DetectorArray& detarray = rProj.getDetectorArray (iy); + detval = detarray.detValues(); + for (int ix = 0; ix < rProj.nDet(); ix++) { + double scaleValue = ((detval[ix] - min) / scaleWidth) * 255; + int intensity = static_cast(scaleValue + 0.5); + intensity = clamp (intensity, 0, 255); + pen.SetColour (*m_pColours[intensity]); + m_memoryDC.SetPen(pen); + m_memoryDC.DrawPoint(ix, iy); + } + } + m_memoryDC.EndDrawing(); + + if (m_canvas) { + // m_canvas->SetScrollbars (50, 50, nx / 50, ny / 50, 0, 0, false); + m_canvas->Refresh(); + } + +#ifdef __WXMSW__ + if (m_canvas) + m_canvas->Refresh(); +#else + if (m_canvas) { + wxClientDC dc(m_canvas); + dc.Clear(); + OnDraw (&dc); + } +#endif +} + +bool +ProjectionFileView::OnClose (bool deleteWindow) +{ + if (!GetDocument()->Close()) + return false; + + m_canvas->Clear(); + m_canvas->m_pView = NULL; + m_canvas = NULL; + wxString s(wxTheApp->GetAppName()); + if (m_frame) + m_frame->SetTitle(s); + SetFrame(NULL); + + Activate(false); + + if (deleteWindow) { + delete m_frame; + return true; + } + return true; +} + diff --git a/src/views.h b/src/views.h new file mode 100644 index 0000000..4e833bb --- /dev/null +++ b/src/views.h @@ -0,0 +1,156 @@ +/***************************************************************************** +** FILE IDENTIFICATION +** +** Name: view.h +** Purpose: Header file for View & Canvas routines of CTSim program +** Programmer: Kevin Rosenberg +** Date Started: July 2000 +** +** This is part of the CTSim program +** Copyright (C) 1983-2000 Kevin Rosenberg +** +** $Id: views.h,v 1.1 2000/07/13 07:01:59 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 +** published by the Free Software Foundation. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +******************************************************************************/ + +#ifdef __GNUG__ +// #pragma interface +#endif + +#ifndef __VIEWSH__ +#define __VIEWSH__ + +#include "wx/wx.h" +#include "imagefile.h" + +class ImageFileCanvas; +class ImageFileView : public wxView +{ + DECLARE_DYNAMIC_CLASS(ImageFileView) + + wxMemoryDC m_memoryDC; + wxBitmap* m_pBitmap; + +private: + ImageFileCanvas *CreateCanvas(wxView *view, wxFrame *parent); + wxFrame *CreateChildFrame(wxDocument *doc, wxView *view); + + ImageFileCanvas *m_canvas; + wxFrame *m_frame; + bool m_bMinSpecified; + bool m_bMaxSpecified; + double m_minPixel; + double m_maxPixel; + + static bool m_bPColoursInitialized; + static wxColour* m_pColours[256]; + +public: + ImageFileView(void); + ~ImageFileView(void); + + bool OnCreate(wxDocument *doc, long flags); + void OnDraw(wxDC* dc); + void OnUpdate(wxView *sender, wxObject *hint = NULL); + bool OnClose (bool deleteWindow = true); + void OnProperties (wxCommandEvent& event); + + DECLARE_EVENT_TABLE() +}; + +class ImageFileCanvas: public wxScrolledWindow +{ +public: + ImageFileView* m_pView; + + ImageFileCanvas (ImageFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style); + virtual void OnDraw(wxDC& dc); + void OnMouseEvent(wxMouseEvent& event); + + DECLARE_EVENT_TABLE() +}; + + +class MyTextWindow: public wxTextCtrl +{ +public: + wxView *m_pView; + + MyTextWindow(wxView *v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style); +}; + + +class TextEditView: public wxView +{ + DECLARE_DYNAMIC_CLASS(TextEditView) +private: + wxFrame *CreateChildFrame(wxDocument *doc, wxView *view); + +public: + wxFrame *frame; + MyTextWindow *textsw; + + TextEditView(): wxView() { frame = (wxFrame *) NULL; textsw = (MyTextWindow *) NULL; } + ~TextEditView(void) {} + + bool OnCreate(wxDocument *doc, long flags); + void OnDraw(wxDC* dc); + void OnUpdate(wxView *sender, wxObject *hint = (wxObject *) NULL); + bool OnClose(bool deleteWindow = TRUE); +}; + +class ProjectionFileCanvas; +class ProjectionFileView : public wxView +{ + DECLARE_DYNAMIC_CLASS(ProjectionFileView) + + wxMemoryDC m_memoryDC; + wxBitmap* m_pBitmap; + +private: + ProjectionFileCanvas *CreateCanvas(wxView *view, wxFrame *parent); + wxFrame *CreateChildFrame(wxDocument *doc, wxView *view); + + ProjectionFileCanvas *m_canvas; + wxFrame *m_frame; + + static bool m_bPColoursInitialized; + static wxColour* m_pColours[256]; + +public: + ProjectionFileView(void); + ~ProjectionFileView(void); + + bool OnCreate(wxDocument *doc, long flags); + void OnDraw(wxDC* dc); + void OnUpdate(wxView *sender, wxObject *hint = NULL); + bool OnClose (bool deleteWindow = true); + void OnProperties (wxCommandEvent& event); + void OnReconstruct (wxCommandEvent& event); + + DECLARE_EVENT_TABLE() +}; + +class ProjectionFileCanvas: public wxScrolledWindow +{ +public: + ProjectionFileView* m_pView; + + ProjectionFileCanvas (ProjectionFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style); + virtual void OnDraw(wxDC& dc); +}; + + +#endif diff --git a/tools/Makefile.am b/tools/Makefile.am new file mode 100644 index 0000000..2b1cf83 --- /dev/null +++ b/tools/Makefile.am @@ -0,0 +1,62 @@ +bin_PROGRAMS = pjrec phm2pj pj2if @lamprograms@ ifinfo phm2if if-1 if-2 if2img +bin_SCRIPTS = sample-ctsim.sh +EXTRA_PROGRAMS = pjrec-lam phm2pj-lam phm2if-lam +INCLUDES=@my_includes@ +EXTRA_DIST=Makefile.nt mpiworld.cpp +SOURCE_DEPEND=../include/ct.h ../libctsim/libctsim.a ../libctsupport/libctsupport.a ../libctgraphics/libctgraphics.a + +pjrec_SOURCES = pjrec.cpp +pjrec_LDADD=@ctlibs@ +pjrec_DEPENDENCIES=$(SOURCE_DEPEND) +phm2pj_SOURCES=phm2pj.cpp +phm2pj_LDADD=@ctlibs@ +phm2pj_DEPENDENCIES=$(SOURCE_DEPEND) +phm2if_SOURCES = phm2if.cpp +phm2if_LDADD=@ctlibs@ +phm2if_DEPENDENCIES=$(SOURCE_DEPEND) +if2img_SOURCES = if2img.cpp +if2img_LDADD=@ctlibs@ +if2img_DEPENDENCIES=$(SOURCE_DEPEND) +pj2if_SOURCES = pj2if.cpp +pj2if_LDADD=@ctlibs@ +pj2if_DEPENDENCIES=$(SOURCE_DEPEND) +if_1_SOURCES=if-1.cpp +if_1_LDADD=@ctlibs@ +if_1_DEPENDENCIES=$(SOURCE_DEPEND) +if_2_SOURCES=if-2.cpp +if_2_LDADD=@ctlibs@ +if_2_DEPENDENCIES=$(SOURCE_DEPEND) +ifinfo_SOURCES = ifinfo.cpp +ifinfo_LDADD=@ctlibs@ +ifinfo_DEPENDENCIES=$(SOURCE_DEPEND) + +pjrec_lam_SOURCES=pjrec.cpp +pjrec_lam_LDADD=@ctlamlibs@ +phm2if_lam_SOURCES=phm2if.cpp +phm2if_lam_LDADD=@ctlamlibs@ +phm2pj_lam_SOURCES=phm2pj.cpp +phm2pj_lam_LDADD=@ctlamlibs@ + +realclean: + rm -f *.pgm *.if *~ *.pj + +if USE_LAM +CC_LAM = $(lamdir)/bin/balky +LAM_EXTRA_SRC = mpiworld.cpp + +pjrec-lam: pjrec.cpp mpiworld.cpp ../include/ct.h ../libctsim/libctsim.a ../libctsupport/libctsupport.a + $(CC_LAM) @DEFS@ $(CFLAGS) $(INCLUDES) -DHAVE_MPI pjrec.cpp -o pjrec-lam $(LDFLAGS) $(LAM_EXTRA_SRC) @ctlibs@ + +phm2pj-lam: phm2pj.cpp mpiworld.cpp ../include/ct.h ../libctsim/libctsim.a ../libctsupport/libctsupport.a + $(CC_LAM) @DEFS@ $(CFLAGS) $(INCLUDES) -DHAVE_MPI phm2pj.cpp -o phm2pj-lam $(LDFLAGS) $(LAM_EXTRA_SRC) @ctlibs@ + +phm2if-lam: phm2if.cpp mpiworld.cpp ../include/ct.h ../libctsim/libctsim.a ../libctsupport/libctsupport.a + $(CC_LAM) @DEFS@ $(CFLAGS) $(INCLUDES) -DHAVE_MPI phm2if.cpp -o phm2if-lam $(LDFLAGS) $(LAM_EXTRA_SRC) @ctlibs@ + +endif + +shared: pjrec.cpp phm2pj.cpp + $(CC) @DEFS@ $(CFLAGS) $(INCLUDES) -DNO_MAIN -shared phm2pj.cpp pjrec.cpp @ctlibs@ $(LDFLAGS) -o ir.so + + + diff --git a/src/if-1.cpp b/tools/if-1.cpp similarity index 98% rename from src/if-1.cpp rename to tools/if-1.cpp index b1d352b..a069219 100644 --- a/src/if-1.cpp +++ b/tools/if-1.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: if-1.cpp,v 1.9 2000/06/26 21:15:24 kevin Exp $ +** $Id: if-1.cpp,v 1.1 2000/07/13 07:01:35 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 diff --git a/src/if-2.cpp b/tools/if-2.cpp similarity index 89% rename from src/if-2.cpp rename to tools/if-2.cpp index 7757f72..525330e 100644 --- a/src/if-2.cpp +++ b/tools/if-2.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: if-2.cpp,v 1.10 2000/07/09 08:16:18 kevin Exp $ +** $Id: if-2.cpp,v 1.1 2000/07/13 07:01:35 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,9 +25,6 @@ ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ******************************************************************************/ -/* FILE - * if-2.c Generate a IF file from two input IF files - */ #include "ct.h" #include "timer.h" @@ -73,7 +70,7 @@ if2_main (int argc, char *const argv[]) { ImageFile* pim_in1; ImageFile* pim_in2; - ImageFile* pim_out; + ImageFile* pim_out = NULL; string in_file1; string in_file2; string out_file; @@ -184,31 +181,36 @@ if2_main (int argc, char *const argv[]) } string strOperation; + int nx = im_in1.nx(); + int ny = im_in1.ny(); + int nx2 = im_in2.nx(); + int ny2 = im_in2.ny(); + if (opt_add) { strOperation = "Add Images"; - for (int ix = 0; ix < im_in1.nx(); ix++) { + for (int ix = 0; ix < nx; ix++) { ImageFileColumn in1 = v1[ix]; ImageFileColumn in2 = v2[ix]; ImageFileColumn out = vout[ix]; - for (int iy = 0; iy < im_in1.ny(); iy++) + for (int iy = 0; iy < ny; iy++) *out++ = *in1++ + *in2++; } } else if (opt_sub) { strOperation = "Subtract Images"; - for (int ix = 0; ix < im_in1.nx(); ix++) { + for (int ix = 0; ix < nx; ix++) { ImageFileColumn in1 = v1[ix]; ImageFileColumn in2 = v2[ix]; ImageFileColumn out = vout[ix]; - for (int iy = 0; iy < im_in1.ny(); iy++) + for (int iy = 0; iy < ny; iy++) *out++ = *in1++ - *in2++; } } else if (opt_mul) { strOperation = "Multiply Images"; - for (int ix = 0; ix < im_in1.nx(); ix++) { + for (int ix = 0; ix < nx; ix++) { ImageFileColumn in1 = v1[ix]; ImageFileColumn in2 = v2[ix]; ImageFileColumn out = vout[ix]; - for (int iy = 0; iy < im_in1.ny(); iy++) + for (int iy = 0; iy < ny; iy++) *out++ = *in1++ * *in2++; } } @@ -218,12 +220,12 @@ if2_main (int argc, char *const argv[]) cout << "d=" << d << ", r=" << r << ", e=" << e << endl; } if (opt_columnPlot > 0) { - if (opt_columnPlot >= im_in1.nx() || opt_columnPlot >= im_in2.nx()) { + if (opt_columnPlot >= nx || opt_columnPlot >= nx2) { sys_error (ERR_SEVERE, "column-plot > nx"); return (1); } - double plot_xaxis [im_in1.nx()]; - for (int i = 0; i < im_in1.nx(); i++) + double plot_xaxis [nx]; + for (int i = 0; i < nx; i++) plot_xaxis[i] = i; #if HAVE_SGP #if 0 @@ -246,18 +248,18 @@ if2_main (int argc, char *const argv[]) } if (opt_rowPlot > 0) { - if (opt_rowPlot >= im_in1.ny() || opt_rowPlot >= im_in2.ny()) { + if (opt_rowPlot >= ny || opt_rowPlot >= ny2) { sys_error (ERR_SEVERE, "row_plot > ny"); return (1); } - double plot_xaxis [im_in1.ny()]; - double v1Row[im_in1.nx()], v2Row[im_in2.nx()]; + double plot_xaxis [ny]; + double v1Row[nx], v2Row[nx2]; - for (int i = 0; i < im_in1.ny(); i++) + for (int i = 0; i < ny; i++) plot_xaxis[i] = i; - for (int i = 0; i < im_in1.nx(); i++) + for (int i = 0; i < nx; i++) v1Row[i] = v1[opt_rowPlot][i]; - for (int i = 0; i < im_in2.nx(); i++) + for (int i = 0; i < nx2; i++) v2Row[i] = v2[opt_rowPlot][i]; #if HAVE_SGP diff --git a/src/if2img.cpp b/tools/if2img.cpp similarity index 99% rename from src/if2img.cpp rename to tools/if2img.cpp index e6ec073..b00c177 100644 --- a/src/if2img.cpp +++ b/tools/if2img.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: if2img.cpp,v 1.13 2000/07/11 10:32:44 kevin Exp $ +** $Id: if2img.cpp,v 1.1 2000/07/13 07:01:35 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 @@ -278,7 +278,7 @@ if2img_main (int argc, char *const argv[]) if (opt_stats || (! (opt_set_max && opt_set_min))) { double min, max, mean, mode, median, stddev; - double window; + double window = 0; im.statistics(min, max, mean, mode, median, stddev); if (opt_auto == O_AUTO_FULL) { diff --git a/src/ifinfo.cpp b/tools/ifinfo.cpp similarity index 98% rename from src/ifinfo.cpp rename to tools/ifinfo.cpp index 6149c9e..09ddfd6 100644 --- a/src/ifinfo.cpp +++ b/tools/ifinfo.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: ifinfo.cpp,v 1.13 2000/07/09 08:16:18 kevin Exp $ +** $Id: ifinfo.cpp,v 1.1 2000/07/13 07:01:35 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 diff --git a/tools/mpiworld.cpp b/tools/mpiworld.cpp new file mode 100644 index 0000000..87c9a93 --- /dev/null +++ b/tools/mpiworld.cpp @@ -0,0 +1,84 @@ +/***************************************************************************** +** FILE IDENTIFICATION +** +** Name: mpiworld.cpp +** Purpose: MPI Support class +** Programmer: Kevin Rosenberg +** Date Started: June 2000 +** +** This is part of the CTSim program +** Copyright (C) 1983-2000 Kevin Rosenberg +** +** $Id: mpiworld.cpp,v 1.1 2000/07/13 07:01:35 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 +** published by the Free Software Foundation. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +******************************************************************************/ + +#include +#include + + +MPIWorld::MPIWorld (int& argc, char**& argv) +{ + MPI::Init (argc, argv); + m_comm = MPI::COMM_WORLD.Dup(); + m_nProcessors = m_comm.Get_size(); + m_myRank = m_comm.Get_rank(); + m_vLocalWorkUnits.reserve (m_nProcessors); + m_vStartWorkUnit.reserve (m_nProcessors); + m_vEndWorkUnit.reserve (m_nProcessors); +} + + +void +MPIWorld::setTotalWorkUnits(int totalWorkUnits) +{ + if (m_nProcessors < 1) + return; + + int baseLocalWorkUnits = totalWorkUnits / m_nProcessors; + int remainderWorkUnits = totalWorkUnits % m_nProcessors; + + int currWorkUnits = 0; + for (int iProc = 0; iProc < m_nProcessors; iProc++) { + m_vLocalWorkUnits[iProc] = baseLocalWorkUnits; + if (iProc < remainderWorkUnits) + m_vLocalWorkUnits[iProc]++; + + m_vStartWorkUnit[iProc] = currWorkUnits; + m_vEndWorkUnit[iProc] = m_vStartWorkUnit[iProc] + m_vLocalWorkUnits[iProc] - 1; + + currWorkUnits += m_vLocalWorkUnits[iProc]; + } + +} + +void +MPIWorld::BcastString (string& str) +{ + int len; + + if (m_myRank == 0) + len = str.length(); + m_comm.Bcast (&len, 1, MPI::INT, 0); + char buf [ len + 1]; + + if (m_myRank == 0) + strcpy (buf, str.c_str()); + + m_comm.Bcast (buf, len + 1, MPI::CHAR, 0); + + if (m_myRank > 0) + str = buf; +} diff --git a/src/phm2if.cpp b/tools/phm2if.cpp similarity index 99% rename from src/phm2if.cpp rename to tools/phm2if.cpp index afac816..9b8fd22 100644 --- a/src/phm2if.cpp +++ b/tools/phm2if.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: phm2if.cpp,v 1.16 2000/07/04 22:21:01 kevin Exp $ +** $Id: phm2if.cpp,v 1.1 2000/07/13 07:01:35 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 diff --git a/src/phm2pj.cpp b/tools/phm2pj.cpp similarity index 99% rename from src/phm2pj.cpp rename to tools/phm2pj.cpp index 2734b2d..69c6ea5 100644 --- a/src/phm2pj.cpp +++ b/tools/phm2pj.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: phm2pj.cpp,v 1.6 2000/07/04 22:21:01 kevin Exp $ +** $Id: phm2pj.cpp,v 1.1 2000/07/13 07:01:35 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 diff --git a/src/pj2if.cpp b/tools/pj2if.cpp similarity index 91% rename from src/pj2if.cpp rename to tools/pj2if.cpp index 25b72ca..1e8ea40 100644 --- a/src/pj2if.cpp +++ b/tools/pj2if.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: pj2if.cpp,v 1.6 2000/06/28 15:25:34 kevin Exp $ +** $Id: pj2if.cpp,v 1.1 2000/07/13 07:01:35 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 @@ -117,15 +117,13 @@ pj2if_main (const int argc, char *const argv[]) ImageFileArray v = im.getArray(); - for (int iy = 0; iy < pj.nView(); iy++) - { - DetectorArray& detarray = pj.getDetectorArray (iy); - const DetectorValue* detval = detarray.detValues(); - for (int ix = 0; ix < pj.nDet(); ix++) - { - v[ix][iy] = detval[ix]; - } + for (int iy = 0; iy < pj.nView(); iy++) { + const DetectorArray& detarray = pj.getDetectorArray (iy); + const DetectorValue* detval = detarray.detValues(); + for (int ix = 0; ix < pj.nDet(); ix++) { + v[ix][iy] = detval[ix]; } + } im.labelAdd (pj.getLabel()); im.labelAdd (Array2dFileLabel::L_HISTORY, "Conversion from .pj to .if", timerProgram.timerEnd()); diff --git a/src/pjrec.cpp b/tools/pjrec.cpp similarity index 99% rename from src/pjrec.cpp rename to tools/pjrec.cpp index d6a229c..dc00484 100644 --- a/src/pjrec.cpp +++ b/tools/pjrec.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: pjrec.cpp,v 1.10 2000/07/11 10:32:44 kevin Exp $ +** $Id: pjrec.cpp,v 1.1 2000/07/13 07:01:35 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 -- 2.34.1