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