[Insight-users] GDCMImageIO with (wx)Windows App

jolinda jolinda at uoregon.edu
Tue Jul 25 17:47:11 EDT 2006


Hi Derek,

When I compile your example on my system, it runs fine (although I don't
have your DICOM file). I'm pretty sure wxWidgets enables RTTI by default,
but there must be something different between our two builds. I agree that
the wx mailing list might be your best bet. I'm also using VS 7.0; I don't
know if that matters.

Here's a version that adds a text control and a file selector -- maybe this
will make debugging a bit easier. Toss it if you don't need it.

Jolinda


-----Original Message-----
From: insight-users-bounces+jolinda=uoregon.edu at itk.org
[mailto:insight-users-bounces+jolinda=uoregon.edu at itk.org] On Behalf Of
Derek Magee
Sent: Tuesday, July 25, 2006 3:15 AM
To: mathieu.malaterre at kitware.com
Cc: insight-users at itk.org
Subject: Re: [Insight-users] GDCMImageIO with (wx)Windows App


M,

I've been investigating further and I've created a very simple wxWidgets app

using wxMSW and MSVC.net 2003. The project and executable are at:

http://www.comp.leeds.ac.uk/drm/ITKTest.zip

The exception is thrown in ImageFileReader.txx (method 
ImageFileReader<TOutputImage, 
ConvertPixelTraits>::EnlargeOutputRequestedRegion(DataObject *output)). 
ConvertPixelTraits>The
exact line is:

typename TOutputImage::Pointer out = dynamic_cast<TOutputImage*>(output);

It appears it is dynamic casting the output image to the output image type 
(which should work as this is the type you'd expect). Not much (in 
particular no file loading, or calls to GDCMImageIO) has gone on by this 
point.

Execution is as follows:
	ITKTest.exe!MyApp::OnInit()  Line 41 + 0x1c
	ITKTest.exe!itk::ProcessObject::Update()  Line 554 + 0x1a
	ITKTest.exe!itk::DataObject::Update()  Line 343 + 0xd
	ITKTest.exe!itk::DataObject::PropagateRequestedRegion()  Line 389 +
0x28
	
ITKTest.exe!itk::ProcessObject::PropagateRequestedRegion(itk::DataObject 
*output=0x01066b78)  Line 722 + 0x11
	
ITKTest.exe!itk::ImageFileReader<itk::Image<short,2>,itk::DefaultConvertPixe
lTraits<short> 
 >::EnlargeOutputRequestedRegion(itk::DataObject * output=0x01066b78)  Line 
227 + 0x17
	msvcr71d.dll!__RTDynamicCast(void * inptr=0x01066b78, long
VfDelta=0, void 
* SrcType=0x008708c0, void * TargetType=0x00870864, int isReference=0)  + 
0x172
	msvcr71d.dll!_CxxThrowException(void * pExceptionObject=0x0012fb2c,
const 
_s__ThrowInfo * pThrowInfo=0x10273eb4)  + 0x39
	msvcr71d.dll!malloc(unsigned int nSize=3765269347)  Line 139 + 0x15


N.B. this is from ITK 2.0.1 (but error is still there in 2.8.1).

At a dead end ....

Derek

>From: Mathieu Malaterre <mathieu.malaterre at kitware.com>
>To: Derek Magee <derekmagee at hotmail.com>
>Subject: Re: [Insight-users] GDCMImageIO with (wx)Windows App
>Date: Mon, 24 Jul 2006 16:47:35 -0400
>
>At least with this image I do not see any problem. I ran the executable
>through valgrind and everything looks fine.
>I believe you should try in the wx ML. They might be doing something 
>equivalent for windows as wxGTK.
>
>Also you can always set the locale yourself just before reading the 
>DICOM
>file (this should give you a clue). Or comment out the Update on the file 
>reader and you should not have any problem (locale only affect sscanf 
>operations).
>
>HTH
>Mathieu
>
>Derek Magee wrote:
>>Mathieu ,
>>
>>One example DICOM is attached (although I've tried others, including 
>>ones
>>with a .DCM file extension). I've sent this one as it is of a Phantom, 
>>rather than a real patient.
>>
>>As for the code I've tried that snipped in several places (in a 
>>callback,
>>in a thread and in OnInit). For the latter the code is:
>>
>>IMPLEMENT_APP(MyApp)
>>
>>// Some of these headers are for other things I'm trying ... #include 
>><itkDICOMSeriesFileNames.h> #include <itkGDCMImageIO.h>
>>#include <itkImage.h>
>>#include <itkImageFileReader.h>
>>#include <itkMetaDataDictionary.h>
>>#include <itkMetaDataObject.h>
>>
>>
>>bool MyApp::OnInit()
>>{
>>
>>       typedef itk::Image< short, 2 > XImageType;
>>       typedef itk::ImageFileReader< XImageType > XReaderType;
>>       typedef itk::GDCMImageIO XImageIOType;
>>
>>       XReaderType::Pointer Xreader = XReaderType::New();
>>
>>       XImageIOType::Pointer XdicomIO = XImageIOType::New();
>>       Xreader->SetFileName( "E:\\DICOM\\41A6F3CD.DCM" ); // Can't 
>>send
>>you this one it is real patient data!
>>       Xreader->SetImageIO( XdicomIO );
>>
>>       try
>>       {
>>           Xreader->Update();
>>       }
>>       catch (itk::ExceptionObject &ex)
>>       {
>>           cerr << "Read error" << endl ;
>>       }
>>       catch(...)
>>       {
>>           wxString er ;
>>           er.Printf("Unknown read error E:\\DICOM\\41A6F3CD.DCM") ;
>>           wxLogError(er) ;
>>       }
>>
>>   // Exception happens before this point => what follows is largely
>>irrelevant
>>
>>    MainFrame *win = new MainFrame(NULL, "VolumeViewer", wxPoint(50, 50),
>>                                         wxSize(400, 440));
>>
>>    win->Show(TRUE) ;
>>
>>    //SetTopWindow(win);
>>
>>
>>    return TRUE;
>>}
>>
>>
>>Thanks
>>
>>Derek
>>
>>>From: Mathieu Malaterre <mathieu.malaterre at kitware.com>
>>>To: Derek Magee <derekmagee at hotmail.com>
>>>Subject: Re: [Insight-users] GDCMImageIO with (wx)Windows App
>>>Date: Mon, 24 Jul 2006 13:39:02 -0400
>>>
>>>Derek,
>>>
>>>     Could you send me the DICOM file. Also attach the c++ code you 
>>>are
>>>using (the one you send is missing the include file).
>>>
>>>Thanks
>>>Mathieu
>>>
>>>Derek Magee wrote:
>>>>Actually the wxGTK+ version (linux) works fine, it is the wxMSW
>>>>(windows) version that shows the problem.
>>>>
>>>>D.
>>>>
>>>>>From: Mathieu Malaterre <mathieu.malaterre at kitware.com>
>>>>>To: Derek Magee <derekmagee at hotmail.com>
>>>>>CC: insight-users at itk.org
>>>>>Subject: Re: [Insight-users] GDCMImageIO with (wx)Windows App
>>>>>Date: Mon, 24 Jul 2006 13:14:55 -0400
>>>>>
>>>>>Derek,
>>>>>
>>>>>     This is just a shot in the dark, but did you read the FAQ for
>>>>>wxGTK:
>>>>>
>>>>>Why doesn't reading floating point numbers work when using 
>>>>>wxWidgets? If your program reads the floating point numbers in the 
>>>>>format 123.45 from a file, it may suddenly start returning just 123 
>>>>>instead of the correct value on some systems -- which is all the 
>>>>>more mysterious as the same code in a standalone program works just 
>>>>>fine.
>>>>>
>>>>>The explanation is that GTK+ changes the current locale on program
>>>>>startup. If the decimal point character in the current locale is not 
>>>>>the period (for example, it is comma in the French locale), all the 
>>>>>standard C functions won't recognize the numbers such as above as 
>>>>>floating point ones any more.
>>>>>
>>>>>The solution is to either use your own function for reading the
>>>>>floating point numbers (probably the best one) or to call 
>>>>>setlocale(LC_NUMERIC, "C") before reading from file and restore the old

>>>>>locale back afterwards if needed.
>>>>>
>>>>>http://wxwidgets.org/docs/faqgtk.htm#locale
>>>>>
>>>>>
>>>>>
>>>>>HTH
>>>>>Mathieu
>>>>>
>>>>>Derek Magee wrote:
>>>>>>I'm trying to load a DICOM file using itk (in a wxWindows 
>>>>>>application,
>>>>>>i.e. jsut a standard windows app). The code works under linux, and in 
>>>>>>a terminal app under windows (MSVC.net), but not within a GUI app 
>>>>>>(wxWindows) The code is:
>>>>>>
>>>>>>        typedef itk::Image< short, 2 > XImageType;
>>>>>>        typedef itk::ImageFileReader< XImageType > XReaderType;
>>>>>>        typedef itk::GDCMImageIO XImageIOType;
>>>>>>
>>>>>>        XReaderType::Pointer Xreader = XReaderType::New();
>>>>>>
>>>>>>        XImageIOType::Pointer XdicomIO = XImageIOType::New();
>>>>>>        Xreader->SetFileName( "E:\\DICOM\\41A6F3CD.DCM" );
>>>>>>        Xreader->SetImageIO( XdicomIO );
>>>>>>
>>>>>>        try
>>>>>>        {
>>>>>>            Xreader->Update();
>>>>>>        }
>>>>>>        catch (itk::ExceptionObject &ex)
>>>>>>        {
>>>>>>            cerr << "Read error" << endl ;
>>>>>>        }
>>>>>>        catch(...)
>>>>>>        {
>>>>>>            wxString er ;
>>>>>>            er.Printf("Unknown read error E:\\DICOM\\41A6F3CD.DCM") ;
>>>>>>            wxLogError(er) ;
>>>>>>        }
>>>>>>
>>>>>>The "Unknown read error" exception  is caught. This seems to 
>>>>>>relate to
>>>>>>the dynamic cast in itkImageFileReader.txx:
>>>>>>
>>>>>>template <class TOutputImage, class ConvertPixelTraits> void
>>>>>>ImageFileReader<TOutputImage, ConvertPixelTraits>
>>>>>>::EnlargeOutputRequestedRegion(DataObject *output)
>>>>>>{
>>>>>>  typename TOutputImage::Pointer out = 
>>>>>>dynamic_cast<TOutputImage*>(output);
>>>>>>
>>>>>>(I'm using itk 2.0.1, but I tried 2.8.1 on another computer and 
>>>>>>the
>>>>>>exception is still there)
>>>>>>
>>>>>>Any ideas???
>>>>>>
>>>>>>Thanks
>>>>>>
>>>>>>Derek
>>>>>>
>>>>>>_________________________________________________________________
>>>>>>The new MSN Search Toolbar now includes Desktop search!
>>>>>>http://join.msn.com/toolbar/overview
>>>>>>
>>>>>>_______________________________________________
>>>>>>Insight-users mailing list
>>>>>>Insight-users at itk.org 
>>>>>>http://www.itk.org/mailman/listinfo/insight-users
>>>>>>
>>>>>
>>>>
>>>>_________________________________________________________________
>>>>Windows LiveT Messenger has arrived. Click here to download it for 
>>>>free!
>>>>http://imagine-msn.com/messenger/launch80/?locale=en-gb
>>>>
>>>>
>>>
>>
>>_________________________________________________________________
>>Be the first to hear what's new at MSN - sign up to our free 
>>newsletters!
>>http://www.msn.co.uk/newsletters
>

_________________________________________________________________
Windows LiveT Messenger has arrived. Click here to download it for free! 
http://imagine-msn.com/messenger/launch80/?locale=en-gb

_______________________________________________
Insight-users mailing list
Insight-users at itk.org http://www.itk.org/mailman/listinfo/insight-users
-------------- next part --------------

#ifndef SEG_PET_H
#define SEG_PET_H

// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"

#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif

// Define a new application type
class MyApp: public wxApp
{
public:
    bool OnInit(void);
};

class MainFrame : public wxFrame
{
public:
    MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size);

	void OnOpenDicom	(wxCommandEvent& event);
	void OnMaxLength	(wxCommandEvent& event);
	void OnQuit			(wxCommandEvent& event);

protected:
    DECLARE_EVENT_TABLE()

private:
	wxTextCtrl* textCtrl;


};

#endif
-------------- next part --------------
#include <iostream>
#include <fstream>
using namespace std;

// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"

#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif

#include "ITKTest.h"


IMPLEMENT_APP(MyApp)

#include <itkDICOMSeriesFileNames.h>
#include <itkGDCMImageIO.h>
#include <itkImage.h>
#include <itkImageFileReader.h>
#include <itkMetaDataDictionary.h>
#include <itkMetaDataObject.h>

enum {
	MENU_OPEN_DICOM
};

BEGIN_EVENT_TABLE(MainFrame, wxFrame)

	EVT_MENU(MENU_OPEN_DICOM,	MainFrame::OnOpenDicom)
	EVT_MENU(wxID_EXIT,			MainFrame::OnQuit)
	EVT_TEXT_MAXLEN(-1,			MainFrame::OnMaxLength)

END_EVENT_TABLE()

bool MyApp::OnInit()
{
    MainFrame *frame = new MainFrame("ITKTest", wxDefaultPosition, wxDefaultSize);
    frame->Show(TRUE);
	SetTopWindow(frame);
    return TRUE;
}


MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
       : wxFrame((wxFrame *)NULL, -1, title, pos, size)
{

	CreateStatusBar();

	wxMenuBar* pMenuBar = new wxMenuBar();

	wxMenu* pFileMenu = new wxMenu();
	pFileMenu->Append(MENU_OPEN_DICOM, "Open &DICOM", "Open DICOM files");
	pFileMenu->Append(wxID_EXIT, "E&xit\tCtrl+X", "Quit the application");
	pMenuBar->Append(pFileMenu, "&File");

	SetMenuBar(pMenuBar);

	
	textCtrl = new wxTextCtrl(this, -1, "", wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY);
	wxBoxSizer* frameSizer = new wxBoxSizer(wxHORIZONTAL);
	frameSizer->Add(textCtrl, 1, wxEXPAND);

	SetSizer(frameSizer);

}


void
MainFrame::OnMaxLength(wxCommandEvent& event)
{
	textCtrl->Clear();
}


void
MainFrame::OnOpenDicom(wxCommandEvent& event)
{
	wxString fileName = wxFileSelector("Choose a DICOM file",
		"", "", "", "DICOM files (*.dcm)|*.dcm|IMA files (*.ima)|*.ima|All files (*.*)|*.*", wxOPEN);

	if (fileName.IsEmpty()) return;


	   typedef itk::Image< short, 2 > XImageType;
       typedef itk::ImageFileReader< XImageType > XReaderType;
       typedef itk::GDCMImageIO XImageIOType;

	   XReaderType::Pointer Xreader = XReaderType::New();

        XImageIOType::Pointer XdicomIO = XImageIOType::New();
        Xreader->SetFileName(fileName.c_str() );
        Xreader->SetImageIO( XdicomIO );

        try
        {
            Xreader->Update();
        }
        catch (itk::ExceptionObject &ex)
        {
            (*textCtrl) << ex.GetDescription() << "\n" ;
			return;
        }
        catch(...)
        {
            (*textCtrl) << "Unknown read error\n";
			return;
        }
		
		(*textCtrl) << fileName << " read.\n";

}

void 
MainFrame::OnQuit(wxCommandEvent& event)
{
	Close(true);
}



More information about the Insight-users mailing list