#include "wxHelloWorldMainFrameInteractor.h" #include #include #include #include #include #include wxHelloWorldMainFrameInteractor::wxHelloWorldMainFrameInteractor (wxWindow* parent, int id, const wxString& title, const wxPoint& pos, const wxSize& size, long style) : wxHelloWorldMainFrame (parent, id, title, pos, size, style) {} /** Overload of OnOpenButton method. We pop up a file dialog window asking for a file to open. It returns the filename. If it's empty, then we return (no file was selected). If not, we open it, using ITK. Last step: we convert the itkImage into a vtkImage that will feed our views. */ void wxHelloWorldMainFrameInteractor::OnOpenButton (wxCommandEvent &event) { wxFileDialog* myFileDialog = new wxFileDialog(this, wxT ("Open an Image"), wxT(""), wxT(""), wxT("All (*.*)|*.*"), wxFD_OPEN|wxFD_CHANGE_DIR, wxDefaultPosition); wxString fileName; fileName.Empty(); int OK = myFileDialog->ShowModal(); if( OK==wxID_OK ) fileName = myFileDialog->GetPath(); myFileDialog->Destroy(); if( fileName.IsEmpty() ) return; /** Now that we have the filename, we read it. Here we use the ITK readers, and we convert the output to a vtkImageData. We could have done the same by reading the inrimage directly and converting it to a vtkImageData. */ typedef itk::Image ImageType; itk::ImageFileReader::Pointer reader = itk::ImageFileReader::New(); itk::AnalyzeImageIOFactory::RegisterOneFactory(); reader->SetFileName (fileName.c_str()); try { std::cout << "Reading: " << fileName.c_str() << std::endl; reader->Update(); } catch (itk::ExceptionObject & e) { std::cerr << e; wxMessageDialog* myDialog = new wxMessageDialog(this, wxT("Error while reading file.\n(check the log window for more details)"), wxT ("Error"), wxOK|wxICON_ERROR); myDialog->ShowModal(); myDialog->Destroy(); return; } // here we do the itk->vtk conversion itk::ImageToVTKImageFilter::Pointer myConverter = itk::ImageToVTKImageFilter::New(); myConverter->SetInput( reader->GetOutput() ); myConverter->Update(); vtkImageData* input = vtkImageData::New(); input->DeepCopy (myConverter->GetOutput()); this->m_View1->SetImage ( input ); this->m_View2->SetImage ( input ); this->m_View3->SetImage ( input ); this->m_View4->SetImage ( input ); input->Delete(); /** Reset the window/level and the current position. */ this->m_View1->SyncResetCurrentPoint(); this->m_View1->SyncResetWindowLevel(); }