]> Creatis software - creaImageIO.git/blob - src/creaImageIOWxAnySimpleDlg.h
eb10d1e2fb0084a259fa7331ec07f1c536c81110
[creaImageIO.git] / src / creaImageIOWxAnySimpleDlg.h
1
2 #include "creaImageIOSimpleView.h"
3 #include <creaWx.h>
4 #include <itkImageFileReader.h>
5 #include <boost/any.hpp>
6 namespace creaImageIO
7 {
8  /**
9    * \ingroup View
10    */
11
12     /// Simple Wxwidgets interface to select file(s) or directory or from creaImageIO database to display
13 //EED    class  __declspec(dllexport) WxAnySimpleDlg : public wxDialog
14     class  CREAIMAGEIO_EXPORT WxAnySimpleDlg : public wxDialog
15     {
16     public:
17          /// Ctor
18            WxAnySimpleDlg( wxWindow *parent,  
19                wxString i_title =_T(""),
20                const std::string i_namedescp = "localdatabase_Descriptor.dscp",   
21                const std::string i_namedb   = "Local Database"     
22             );
23
24            ~WxAnySimpleDlg(){};
25
26            void setExts(std::vector<std::string>);
27            /// Callback to read file(s)
28            void OnReadFile(wxCommandEvent& event);
29
30           /// Callback to read directory, no recursive
31            void OnReadDirectory(wxCommandEvent &event);
32           
33           /// Callback to select from creaImageIO database
34            void OnReadGimmick(wxCommandEvent &event);
35
36            /// return a vtkImageData vector of selected images, if available
37            std::vector<vtkImageData*> getVtkImagesSelected() {return m_Vresults;}
38
39            wxString getInfoImage();
40
41            void set(bool i_dicom){m_dicom= i_dicom;}
42            std::vector <boost::any>& getImagesSelected(){ return m_AnyImages;}
43         
44            // return the size of readed images
45            //strange compile error // JPR
46            std::vector<const size_t> getDims(){ return m_AnyDims;}
47
48            // return the type of readed images
49            std::vector<const std::type_info *> getTypes(){ return m_AnyType;}
50
51            // get an Image on wanted type
52            template <typename TImage> 
53            typename TImage::Pointer getImage(boost::any i_AnyImage)
54            {
55               typedef itk::Image<TImage> ImageOut;
56               typename ImageOut::Pointer img = ImageOut::New();
57               img = boost::any_cast< ImageOut::Pointer>(i_AnyImage);
58               return img;
59            }
60
61          // get the images on itk type defined by user
62           template <typename TImage> 
63           std::vector<typename TImage::Pointer>  getTemplatedImagesSelected()
64           {
65              std::vector<typename TImage::Pointer> imgs;
66              std::vector<boost::any>::iterator it = m_AnyImages.begin();
67              for(; it != m_AnyImages.end(); it++)
68              {
69                  imgs.push_back(boost::any_cast<TImage*> (*it));
70              }
71              return imgs;
72           }
73           bool AllSameType();
74     private:
75
76         // strange compile error with gcc 4.5.1-4 //JPR        
77         std::vector<const size_t> m_AnyDims;
78         std::vector<const std::type_info *> m_AnyType;
79         std::vector<boost::any> m_AnyImages;
80         std::vector<std::string> m_exts;
81         std::string namedescp; 
82         std::string namedb;
83         wxString infoimage;
84         std::string m_dir;
85         template <class TImage> 
86         void split3Din3Dvtk(TImage* i_Img);
87
88         template <typename TImage> 
89         void split4Din3Dvtk(TImage* i_Img);
90
91         bool m_dicom;
92         /// interface to read data
93         SimpleView m_view;
94         void readImg(const std::string &i_name);
95         void readDicomImg(const std::vector<std::string> &i_names);
96         std::vector <vtkImageData*> m_Vresults;
97          
98         const size_t getNumberOfDimensions(const std::string &i_name);
99         const std::type_info & getType(const std::string &i_name);
100     };
101
102 }