[Insight-users] itk & wxWidgets

Karsten Grasemann Karsten.Grasemann at ruhr-uni-bochum.de
Thu Jan 6 09:58:17 EST 2005


Hi

I know where the problem is.
In your implementation of MyApp::OnInit() the reader object lies in the local
scope of the method. After the method finished its persistence during the
initialisation of the MyApp object, all local Object (i.e. the reader object)
will be destroyed. But itk needs the reader object through the whole lifetime
of the MyApp object.
It is a good idea to implement reader and filter objects as class properties.
So have to change the part of your codesnippet from this .....

class MyApp : public wxApp {
public:
  virtual bool OnInit();
};

MainFrame::MainFrame() : wxFrame(NULL, -1, "") {
}

IMPLEMENT_APP(MyApp)

bool MyApp::OnInit() {
  typedef itk::Image< unsigned char, 2 > ImageType;
  typedef itk::ImageFileReader< ImageType > ReaderType;
  ReaderType::Pointer reader;
  reader = ReaderType::New();// <===== crash here

  MainFrame *frame = new MainFrame();
  frame->Show(TRUE);
  return TRUE;
}


... to ...


class MyApp : public wxApp {
public:
  typedef itk::Image< unsigned char, 2 > ImageType;
  typedef itk::ImageFileReader< ImageType > ReaderType;
  ReaderType::Pointer reader;

  virtual bool OnInit();
};

MainFrame::MainFrame() : wxFrame(NULL, -1, "") {
}

IMPLEMENT_APP(MyApp)

bool MyApp::OnInit() {
  reader = ReaderType::New();

  MainFrame *frame = new MainFrame();
  frame->Show(TRUE);
  return TRUE;
}

Note that the typedefs moved into the class definition to become an attribute
of the class itself.

Much luck furtheron

Karsten Grasemann


More information about the Insight-users mailing list