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