]> Creatis software - creaImageIO.git/commitdiff
Add a simple dialog box to select file(s or directory or data from creaImageIO database
authorFrederic Cervenansky <Frederic.Cervenansky@creatis.insa-lyon.fr>
Fri, 19 Mar 2010 16:22:32 +0000 (16:22 +0000)
committerFrederic Cervenansky <Frederic.Cervenansky@creatis.insa-lyon.fr>
Fri, 19 Mar 2010 16:22:32 +0000 (16:22 +0000)
14 files changed:
appli/CMakeLists.txt
appli/TestWxGimmickReaderDialog/main.cxx
appli/TestWxSimpleView/CMakeLists.txt [new file with mode: 0644]
appli/TestWxSimpleView/main.cxx [new file with mode: 0644]
bbtk/CMakeLists.txt
bbtk/src/CMakeLists.txt
bbtk/src/bbImagesReader.cxx [new file with mode: 0644]
bbtk/src/bbImagesReader.h [new file with mode: 0644]
bbtk/src/bbImagesReader.xml [new file with mode: 0644]
src/CMakeLists.txt
src/creaImageIOSimpleView.cpp [new file with mode: 0644]
src/creaImageIOSimpleView.h [new file with mode: 0644]
src/creaImageIOWxSimpleDlg.cpp [new file with mode: 0644]
src/creaImageIOWxSimpleDlg.h [new file with mode: 0644]

index eed9be73730097a3f30fda8193c1eca7fe3bdbc1..d077277238896d6d0d7f927c6f4664d9c7666a4a 100644 (file)
@@ -3,7 +3,8 @@
   SUBDIRS(wxGimmick)
   SUBDIRS(TestWxGimmickReaderDialog)
   SUBDIRS(TestGimmickReaderDialog)
-  SUBDIRS(TestWxGimmickReaderDialogJava)
+  SUBDIRS(TestWxSimpleView)
+  #SUBDIRS(TestWxGimmickReaderDialogJava)
 #LSE (BUILD_V2)
  # SUBDIRS(TestWxGimmickDialog)
 #ENDIF (BUILD_V2)
index bcd74d8ac3ec89cd459dda58f7188146351ec211..33157d9cf427f055cbbe9ee6ee1edacc2753939c 100644 (file)
@@ -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 (file)
index 0000000..14c7f48
--- /dev/null
@@ -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 (file)
index 0000000..58ffcdb
--- /dev/null
@@ -0,0 +1,41 @@
+#include <creaImageIOSystem.h>
+#include <creaWx.h>
+#include <creaImageIOWxSimpleDlg.h>
+#include <creaVtkBasicSlicer.h>
+
+// 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 <vtkImageData*> test = x.getImagesSelected();
+   if(test.size() >0)
+   {
+       crea::VtkBasicSlicer(test.front());
+   }
+   
+   return false;
+}
+
+
index f0c11cedd396a8be5a6fdc34a2e8199ae75b7dcc..e904c9b370cd38322b06818a25336be0098a3ecf 100644 (file)
@@ -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 
+)
+
 #===========================================================================
 
 #===========================================================================
index 68b9e503a16df703c9f6b52af120f2d1953da97f..ee900f8a5d3c2f050125027356747ae0b5beb365 100644 (file)
@@ -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 (file)
index 0000000..55d2cae
--- /dev/null
@@ -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 (file)
index 0000000..48d18c4
--- /dev/null
@@ -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<vtkImageData*> 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<vtkImageData*> 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 (file)
index 0000000..16b1c89
--- /dev/null
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="iso-8859-1"?>
+<!--==========================================================================
+   STARTS THE DESCRIPTION OF THE BLACK BOX -->
+<blackbox name="ImagesReader">
+  <!--========================================================================
+    THE BOX DOCUMENTATION -->
+  <author>cervenansky.frederic@creatis.insa-lyon.fr</author>
+  <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."
+  </description>
+  <category>image;reader;dicom</category>
+
+  <!--========================================================================
+    #include directives to be put in the .h generated
+    There must be one tag per file to include -->
+  <include>creaImageIOWxSimpleView.h</include>
+  <!--========================================================================
+    INPUTS/OUTPUTS DECLARATION -->
+
+  <input name="Title" type="std::string" description="Title of the dialog"/>
+  <typedef>
+    <PRE>
+      typedef std::vector<vtkImageData*> OutputImagesType;</PRE>
+  </typedef>
+
+  <output name="Out" type="OutputImagesType" description="The selected images"/>
+  
+  <!--========================================================================
+    PROCESS section -->
+
+  <process>
+    <PRE>
+      creaImageIO::WxSimpleView dlg(0,crea::std2wx(bbGetInputTitle()));
+      dlg.ShowModal();
+      if (bbGetInputOutput()==0)
+      {
+      bbSetOutputOut( x.getImagesSelected());
+      }
+
+    </PRE>
+  </process>
+
+  <!--======================================================================
+   CONSTRUCTORS / DESTRUCTORS (OPTIONAL) -->
+
+  <constructor>
+    <PRE>
+      bbSetInputImageDimension(3);
+      bbSetInputTitle("Select image(s)");
+      bbSetInputOutput(0);
+      bbSetOutputOut(0);
+    </PRE>
+  </constructor>
+
+
+  <!-- THE COPY-CONSTRUCTION METHOD BODY : -->
+  <copyconstructor>
+    <PRE>
+      bbSetOutputOut(0);
+    </PRE>
+  </copyconstructor>
+
+  <!-- THE DESTRUCTION METHOD BODY  -->
+  <destructor>
+    <PRE>
+      std::vector<vtkImageData*>::iterator i;
+    for (i=bbGetOutputOut2().begin();i!=bbGetOutputOut2().end();++i) (*i)->Delete();
+  </PRE>
+  </destructor>
+
+
+
+</blackbox>
+
index 8e2191899241dfe10da6fdeb579872edcc511a00..4e9615e9d24faf861c2a156def452c9e000d0c81 100644 (file)
@@ -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 (file)
index 0000000..9ca576c
--- /dev/null
@@ -0,0 +1,52 @@
+#include "creaImageIOSimpleView.h"
+
+namespace creaImageIO
+{
+
+       bool SimpleView::readFile(std::vector<std::string> i_filenames, std::vector<vtkImageData *> &i_img)
+       {
+                       bool bresult, bfinal = true;
+                       ImageReader *mReader = new ImageReader();
+                       std::vector<std::string>::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<vtkImageData *> &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 (file)
index 0000000..9cfda37
--- /dev/null
@@ -0,0 +1,24 @@
+#include <boost/filesystem/path.hpp>
+#include <boost/filesystem.hpp>
+#include <boost/utility.hpp>
+#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<std::string> 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 (file)
index 0000000..4a34371
--- /dev/null
@@ -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<std::string> 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<vtkImageData*> WxSimpleDlg::getImagesSelected()
+         {
+                 return m_results;
+         }
+}
+
diff --git a/src/creaImageIOWxSimpleDlg.h b/src/creaImageIOWxSimpleDlg.h
new file mode 100644 (file)
index 0000000..135802b
--- /dev/null
@@ -0,0 +1,42 @@
+#include "creaImageIOSimpleView.h"
+#include <creaWx.h>
+
+
+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<vtkImageData*> getImagesSelected();
+
+       private:
+
+               /// interface to read data
+               SimpleView m_view;
+
+               /// vtkImageData vector
+               std::vector<vtkImageData*> m_results;
+       };
+}
\ No newline at end of file