From: Frederic Cervenansky Date: Fri, 19 Mar 2010 16:22:32 +0000 (+0000) Subject: Add a simple dialog box to select file(s or directory or data from creaImageIO database X-Git-Tag: CREATOOLS.2-0-3~42 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?p=creaImageIO.git;a=commitdiff_plain;h=40c5cfdc77e721db1507ffdac3625b7813f66f4c Add a simple dialog box to select file(s or directory or data from creaImageIO database --- diff --git a/appli/CMakeLists.txt b/appli/CMakeLists.txt index eed9be7..d077277 100644 --- a/appli/CMakeLists.txt +++ b/appli/CMakeLists.txt @@ -3,7 +3,8 @@ SUBDIRS(wxGimmick) SUBDIRS(TestWxGimmickReaderDialog) SUBDIRS(TestGimmickReaderDialog) - SUBDIRS(TestWxGimmickReaderDialogJava) + SUBDIRS(TestWxSimpleView) + #SUBDIRS(TestWxGimmickReaderDialogJava) #LSE (BUILD_V2) # SUBDIRS(TestWxGimmickDialog) #ENDIF (BUILD_V2) diff --git a/appli/TestWxGimmickReaderDialog/main.cxx b/appli/TestWxGimmickReaderDialog/main.cxx index bcd74d8..33157d9 100644 --- a/appli/TestWxGimmickReaderDialog/main.cxx +++ b/appli/TestWxGimmickReaderDialog/main.cxx @@ -50,6 +50,7 @@ bool myApp::OnInit( ) int threads = 1; + creaImageIO::WxGimmickReaderDialog w( 0, -1, diff --git a/appli/TestWxSimpleView/CMakeLists.txt b/appli/TestWxSimpleView/CMakeLists.txt new file mode 100644 index 0000000..14c7f48 --- /dev/null +++ b/appli/TestWxSimpleView/CMakeLists.txt @@ -0,0 +1,11 @@ + +IF(WIN32) + ADD_EXECUTABLE(TestWxSimpleDlg WIN32 main) + SET_TARGET_PROPERTIES(TestWxSimpleDlg PROPERTIES LINK_FLAGS /subsystem:console ) +ELSE(WIN32) + ADD_EXECUTABLE(TestWxSimpleDlg MACOSX_BUNDLE main) +ENDIF(WIN32) + +TARGET_LINK_LIBRARIES( TestWxSimpleDlg creaImageIO ) + +INSTALL_TARGETS(/bin/ TestWxSimpleDlg ) diff --git a/appli/TestWxSimpleView/main.cxx b/appli/TestWxSimpleView/main.cxx new file mode 100644 index 0000000..58ffcdb --- /dev/null +++ b/appli/TestWxSimpleView/main.cxx @@ -0,0 +1,41 @@ +#include +#include +#include +#include + +// Just to test the selection of file(s), directory or from creaImageIO database. +class myApp : public wxApp +{ +public: + bool OnInit( ); + int OnExit() { return true; } +}; + +IMPLEMENT_APP(myApp); + +CREA_WXMAIN_WITH_CONSOLE + +bool myApp::OnInit( ) +{ + wxApp::OnInit(); +#ifdef __WXGTK__ + //See http://www.wxwindows.org/faqgtk.htm#locale + setlocale(LC_NUMERIC, "C"); +#endif + wxInitAllImageHandlers(); + + creaImageIO::SetGimmickMessageLevel(5); + creaImageIO::SetGimmickDebugMessageLevel(0); + + creaImageIO::WxSimpleDlg x(0); + x.ShowModal(); + std::vector test = x.getImagesSelected(); + if(test.size() >0) + { + crea::VtkBasicSlicer(test.front()); + } + + return false; +} + + diff --git a/bbtk/CMakeLists.txt b/bbtk/CMakeLists.txt index f0c11ce..e904c9b 100644 --- a/bbtk/CMakeLists.txt +++ b/bbtk/CMakeLists.txt @@ -76,7 +76,9 @@ SET(${BBTK_PACKAGE_NAME}_XML_SOURCES # E.G. TO bbfy "toto.xml" ADD "toto" (NO EXTENSION) # THE PATH MUST BE RELATIVE TO THE src FOLDER ${CMAKE_CURRENT_BINARY_DIR}/src/bbcreaImageIOGimmick.xml - ) +#${CMAKE_CURRENT_BINARY_DIR}/src/bbImagesReader.xml +) + #=========================================================================== #=========================================================================== diff --git a/bbtk/src/CMakeLists.txt b/bbtk/src/CMakeLists.txt index 68b9e50..ee900f8 100644 --- a/bbtk/src/CMakeLists.txt +++ b/bbtk/src/CMakeLists.txt @@ -1,5 +1,6 @@ IF (BUILD_V2) + CONFIGURE_FILE(bbcreaImageIOGimmick.xml_v2 ${CMAKE_CURRENT_BINARY_DIR}/bbcreaImageIOGimmick.xml COPYONLY) diff --git a/bbtk/src/bbImagesReader.cxx b/bbtk/src/bbImagesReader.cxx new file mode 100644 index 0000000..55d2cae --- /dev/null +++ b/bbtk/src/bbImagesReader.cxx @@ -0,0 +1,47 @@ +//===== +// Don't edit this file. This file is generated from xml description.. +//===== +#include "bbImagesReader.h" +#include "bbcreaImageIOPackage.h" +namespace bbcreaImageIO +{ + +BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaImageIO,ImagesReader) +BBTK_BLACK_BOX_IMPLEMENTATION(ImagesReader,bbtk::AtomicBlackBox); +//===== +// Don't edit this file. This file is generated from xml description.. +//===== +void ImagesReader::Process() +{ + + creaImageIO::WxSimpleDlg dlg(0,crea::std2wx(bbGetInputTitle())); + dlg.ShowModal(); + bbSetOutputOut( dlg.getImagesSelected()); + + +} +//===== +// Don't edit this file. This file is generated from xml description.. +//===== +void ImagesReader::bbUserSetDefaultValues() +{ + +} +//===== +// Don't edit this file. This file is generated from xml description.. +//===== +void ImagesReader::bbUserInitializeProcessing() +{ + +} +//===== +// Don't edit this file. This file is generated from xml description.. +//===== +void ImagesReader::bbUserFinalizeProcessing() +{ + +} +} +// EO namespace bbcreaImageIO + + diff --git a/bbtk/src/bbImagesReader.h b/bbtk/src/bbImagesReader.h new file mode 100644 index 0000000..48d18c4 --- /dev/null +++ b/bbtk/src/bbImagesReader.h @@ -0,0 +1,47 @@ +//===== +// Don't edit this file. This file is generated from xml description.. +//===== +#ifndef __bbImagesReader_h_INCLUDED__ +#define __bbImagesReader_h_INCLUDED__ +#include "bbcreaImageIO_EXPORT.h" +#include "bbtkAtomicBlackBox.h" +#include "creaImageIOWxSimpleDlg.h" + +namespace bbcreaImageIO +{ + +class bbcreaImageIO_EXPORT ImagesReader + : + public bbtk::AtomicBlackBox +{ + BBTK_BLACK_BOX_INTERFACE(ImagesReader,bbtk::AtomicBlackBox); +typedef std::vector OutputImagesType; +//===== +// Don't edit this file. This file is generated from xml description.. +//===== + BBTK_DECLARE_INPUT(Title,std::string); + BBTK_DECLARE_OUTPUT(Out,OutputImagesType); + BBTK_PROCESS(Process); + void Process(); +//===== +// Don't edit this file. This file is generated from xml description.. +//===== +}; + +BBTK_BEGIN_DESCRIBE_BLACK_BOX(ImagesReader,bbtk::AtomicBlackBox); +BBTK_NAME("ImagesReader"); +BBTK_AUTHOR("frederic.cervenansky@creatis.insa-lyon.fr"); +BBTK_DESCRIPTION("ImagesRedear is a simple application to select file(s) or directory or data from Gimmick database and display them. It handles DICOM,jpg,tif,png,bmp and mhd."); +BBTK_CATEGORY("image;reader;dicom"); +typedef std::vector OutputImagesType; +BBTK_INPUT(ImagesReader,Title,"Title of the dialog",std::string,""); +BBTK_OUTPUT(ImagesReader,Out,"The selected images",OutputImagesType,""); +BBTK_END_DESCRIBE_BLACK_BOX(ImagesReader); +//===== +// Don't edit this file. This file is generated from xml description.. +//===== +} +// EO namespace bbcreaImageIO + +#endif // __bbImagesReader_h_INCLUDED__ + diff --git a/bbtk/src/bbImagesReader.xml b/bbtk/src/bbImagesReader.xml new file mode 100644 index 0000000..16b1c89 --- /dev/null +++ b/bbtk/src/bbImagesReader.xml @@ -0,0 +1,74 @@ + + + + + cervenansky.frederic@creatis.insa-lyon.fr + + ImagesRedear is a simple application to select file(s) or directory or data from Gimmick database and display them. It handles DICOM,jpg,tif,png,bmp and mhd." + + image;reader;dicom + + + creaImageIOWxSimpleView.h + + + + +
+      typedef std::vector OutputImagesType;
+
+ + + + + + +
+      creaImageIO::WxSimpleView dlg(0,crea::std2wx(bbGetInputTitle()));
+      dlg.ShowModal();
+      if (bbGetInputOutput()==0)
+      {
+      bbSetOutputOut( x.getImagesSelected());
+      }
+
+    
+
+ + + + +
+      bbSetInputImageDimension(3);
+      bbSetInputTitle("Select image(s)");
+      bbSetInputOutput(0);
+      bbSetOutputOut(0);
+    
+
+ + + + +
+      bbSetOutputOut(0);
+    
+
+ + + +
+      std::vector::iterator i;
+    for (i=bbGetOutputOut2().begin();i!=bbGetOutputOut2().end();++i) (*i)->Delete();
+  
+
+ + + +
+ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8e21918..4e9615e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -52,6 +52,7 @@ ENDIF(USE_GDCM2) # Image Readers FILE(GLOB SOURCES_CREAIMAGEIO_IMG_READER + creaImageIOSimpleView.cpp creaImageIOAbstractImageReader.cpp creaImageIOImageReader.cpp creaImageIOUltrasonixImageReader.cpp @@ -64,6 +65,7 @@ FILE(GLOB SOURCES_CREAIMAGEIO_IMG_READER # The wxWidgets-based components if (USE_WXWIDGETS) FILE(GLOB SOURCES_CREAIMAGEIO_WX + creaImageIOWxSimpleDlg.cpp creaImageIOWxAttributeSelectionPanel.cpp creaImageIOWxCustomizeConfigPanel.cpp creaImageIOWxDescriptorPanel.cpp diff --git a/src/creaImageIOSimpleView.cpp b/src/creaImageIOSimpleView.cpp new file mode 100644 index 0000000..9ca576c --- /dev/null +++ b/src/creaImageIOSimpleView.cpp @@ -0,0 +1,52 @@ +#include "creaImageIOSimpleView.h" + +namespace creaImageIO +{ + + bool SimpleView::readFile(std::vector i_filenames, std::vector &i_img) + { + bool bresult, bfinal = true; + ImageReader *mReader = new ImageReader(); + std::vector::iterator it = i_filenames.begin(); + for (; it != i_filenames.end(); it++) + { + bresult = mReader->CanRead((*it).c_str()); + if(bresult) + { + i_img.push_back(mReader->ReadImage((*it).c_str())); + } + else + { + bfinal = false; + } + } + delete mReader; + return bfinal; + + } + + bool SimpleView::readDirectory(const std::string i_pathname, std::vector &i_imgs) + { + bool bresult = true; + ImageReader *mReader = new ImageReader(); + + bresult = boost::filesystem::exists( i_pathname ); + if (bresult) + { + boost::filesystem::directory_iterator itr(i_pathname); + boost::filesystem::directory_iterator end_itr; + for(;itr != end_itr; ++itr) + { + if (!boost::filesystem::is_directory(itr->status())) + { + if( mReader->CanRead(itr->string()) ) + { + i_imgs.push_back( mReader->ReadImage(itr->string()) ); + } + } + } + } + return bresult; + } +} + diff --git a/src/creaImageIOSimpleView.h b/src/creaImageIOSimpleView.h new file mode 100644 index 0000000..9cfda37 --- /dev/null +++ b/src/creaImageIOSimpleView.h @@ -0,0 +1,24 @@ +#include +#include +#include +#include "creaImageIOImageReader.h" + +namespace creaImageIO +{ + class SimpleView + { + public: + /// Ctor + SimpleView(){} + + ///Dtor + ~SimpleView(){} + + /// read file(s) and return a vector of vtkImageData + bool readFile( std::vector i_filenames, std::vector< vtkImageData *> &i_img); + + /// read a directory and return a vector of vtkImageData + bool readDirectory(const std::string i_pathname, std::vector< vtkImageData *> &i_imgs); + + }; +} \ No newline at end of file diff --git a/src/creaImageIOWxSimpleDlg.cpp b/src/creaImageIOWxSimpleDlg.cpp new file mode 100644 index 0000000..4a34371 --- /dev/null +++ b/src/creaImageIOWxSimpleDlg.cpp @@ -0,0 +1,116 @@ +#include "creaImageIOWxSimpleDlg.h" +#include "creaImageIOWxGimmickReaderDialog.h" + + +namespace creaImageIO +{ + + ///Ctor + WxSimpleDlg::WxSimpleDlg(wxWindow *parent, wxString i_title) + : wxDialog(parent, -1,_T("DISPLAY IMAGES"), wxDefaultPosition, wxSize(230,150)) + { + if(!i_title.empty()) + { + this->SetTitle(i_title); + } + // Button to select file(s) + wxButton *fileBut = new wxButton(this, -1,_T("Select a file to display"), wxPoint(10,7) ); + Connect( fileBut->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxSimpleDlg::OnReadFile ); + + // Button to select directory + wxButton *directoryBut = new wxButton(this, -1,_T("Select a directory to display"), wxPoint(10,40) ); + Connect( directoryBut->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxSimpleDlg::OnReadDirectory ); + + // button to select creaImageIO + wxButton *gimmickBut = new wxButton(this, -1,_T("Select Gimmick"), wxPoint(10,70) ); + Connect( gimmickBut->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxSimpleDlg::OnReadGimmick ); + + //TO DO Button to select Bruker directory + + Layout(); + + } +////////////////////////////////////////////////////////////////////// +// // +////////////////////////////////////////////////////////////////////// + void WxSimpleDlg::OnReadFile(wxCommandEvent& event) + { + wxFileDialog* FD = new wxFileDialog( 0, _T("Select file"), _T(""), _T(""), crea::std2wx("*"), wxOPEN |wxFD_MULTIPLE, wxDefaultPosition); + + if (FD->ShowModal()==wxID_OK) + { + wxArrayString wxArray; + FD->GetPaths(wxArray); + if(wxArray.size() >0) + { + std::vector files; + for( int i = 0; i < wxArray.GetCount(); i++) + { + files.push_back( crea::wx2std(wxArray[i])); + } + if(!m_view.readFile(files,m_results)) + { + //TO DO WARNING MESSAGE; + } + } + else + { + // TO DO WARNING MESSAGES + } + } + Close(); + } + + ////////////////////////////////////////////////////////////////////// +// // +////////////////////////////////////////////////////////////////////// + + void WxSimpleDlg::OnReadDirectory(wxCommandEvent &event) + { + long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST; + wxDirDialog* FD = new wxDirDialog( 0, _T("Select the directory to display"), "", style); + + if (FD->ShowModal()==wxID_OK) + { + if(! m_view.readDirectory(crea::wx2std(FD->GetPath()),m_results)) + { + //TO DO WARNING MESSAGE; + } + } + Close(); + } + + ////////////////////////////////////////////////////////////////////// +// // +////////////////////////////////////////////////////////////////////// + + void WxSimpleDlg::OnReadGimmick(wxCommandEvent &event) + { + // Run Gimmick + WxGimmickReaderDialog dlg(0,-1, "localdatabase_Descriptor.dscp", + "Local Database", _T("Select image(s) - Gimmick! (c) CREATIS-LRMN 2008"), + wxDefaultPosition, + wxSize(810,750), + GIMMICK_2D_IMAGE_SELECTION, + GIMMICK_3D_IMAGE_SELECTION, + _3D, + 1); + dlg.ShowModal(); + if (dlg.GetReturnCode() == wxID_OK) + { + dlg.GetSelectedImages(m_results,3); + dlg.OnExit(); + } + Close(); + } + + + ////////////////////////////////////////////////////////////////////// +// Return the results vector // +////////////////////////////////////////////////////////////////////// + std::vector WxSimpleDlg::getImagesSelected() + { + return m_results; + } +} + diff --git a/src/creaImageIOWxSimpleDlg.h b/src/creaImageIOWxSimpleDlg.h new file mode 100644 index 0000000..135802b --- /dev/null +++ b/src/creaImageIOWxSimpleDlg.h @@ -0,0 +1,42 @@ +#include "creaImageIOSimpleView.h" +#include + + +namespace creaImageIO +{ + /** + * \ingroup View + */ + + /// Simple Wxwidgets interface to select file(s) or directory or from creaImageIO database to display + class CREAIMAGEIO_EXPORT WxSimpleDlg : public wxDialog + { + public: + /// Ctor + WxSimpleDlg( wxWindow *parent, wxString i_title =""); + + ///Dtor + ~WxSimpleDlg(){}; + + + /// Callback to read file(s) + void OnReadFile(wxCommandEvent& event); + + /// Callback to read directory, no recursive + void OnReadDirectory(wxCommandEvent &event); + + /// Callback to select from creaImageIO database + void OnReadGimmick(wxCommandEvent &event); + + /// return a vtkImageData vector of selected images, if available + std::vector getImagesSelected(); + + private: + + /// interface to read data + SimpleView m_view; + + /// vtkImageData vector + std::vector m_results; + }; +} \ No newline at end of file