]> Creatis software - creaImageIO.git/blob - src/creaImageIOWxAnySimpleDlg.h
Clean Code
[creaImageIO.git] / src / creaImageIOWxAnySimpleDlg.h
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
5 #                        pour la Santé)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 #
10 #  This software is governed by the CeCILL-B license under French law and 
11 #  abiding by the rules of distribution of free software. You can  use, 
12 #  modify and/ or redistribute the software under the terms of the CeCILL-B 
13 #  license as circulated by CEA, CNRS and INRIA at the following URL 
14 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
15 #  or in the file LICENSE.txt.
16 #
17 #  As a counterpart to the access to the source code and  rights to copy,
18 #  modify and redistribute granted by the license, users are provided only
19 #  with a limited warranty  and the software's author,  the holder of the
20 #  economic rights,  and the successive licensors  have only  limited
21 #  liability. 
22 #
23 #  The fact that you are presently reading this means that you have had
24 #  knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------
26 */
27
28
29 #ifndef __creaImageWxAnySimpleDlg_h_INCLUDED__
30 #define __creaImageWxAnySimpleDlg_h_INCLUDED__
31
32 #include <vtkVersionMacros.h>
33 #include "creaImageIOSimpleView.h"
34 #include <creaWx.h>
35 #include <itkImageFileReader.h>
36 #include <boost/any.hpp>
37 #include <typeinfo>
38 #include "itkImageToVTKImageFilter.h"
39
40 namespace creaImageIO
41 {
42  /**
43  * \ingroup View
44  */
45
46     /// Simple Wxwidgets interface to select file(s) or directory or from creaImageIO database to display
47 //EED    class  __declspec(dllexport) WxAnySimpleDlg : public wxDialog
48     class  CREAIMAGEIO_EXPORT WxAnySimpleDlg : public wxDialog
49     {
50     public:
51          /// Ctor
52            WxAnySimpleDlg( wxWindow *parent,  
53                wxString i_title =_T(""),
54                const std::string i_namedescp = "localdatabase_Descriptor.dscp",   
55                const std::string i_namedb    = "Local Database"
56            );
57
58            ~WxAnySimpleDlg(){};
59
60            void setExts(std::vector<std::string>);
61            /// Callback to read file(s)
62            void OnReadFile(wxCommandEvent& event);
63
64           /// Callback to read directory, no recursive
65            void OnReadDirectory(wxCommandEvent &event);
66           
67           /// Callback to select from creaImageIO database
68            void OnReadGimmick(wxCommandEvent &event);
69
70            /// return a vtkImageData vector of selected images, if available
71            std::vector<vtkImageData*> getVtkImagesSelected() {return m_Vresults;}
72
73            wxString getInfoImage();
74
75            void set(bool i_dicom){m_dicom= i_dicom;}
76            std::vector <boost::any>& getImagesSelected(){ return m_AnyImages;}
77         
78            // return the size of readed images
79            std::vector</*const*/ size_t> getDims(){ return m_AnyDims;} // comment out const // JPR
80
81            // return the type of readed images
82            std::vector</*const */std::type_info *> getTypes(){ return m_AnyType;} // comment out const // JPR
83
84            // get an Image on wanted type
85            /*
86            // strange compile error, commented out on Fred's advice // JPR
87            template <typename TImage> 
88            typename TImage::Pointer getImage(boost::any i_AnyImage)
89            {
90               typedef itk::Image<TImage> ImageOut;
91               typename ImageOut::Pointer img = ImageOut::New();
92               img = boost::any_cast< ImageOut::Pointer>(i_AnyImage);
93               return img;
94            }
95            */
96
97          // get the images on itk type defined by user
98           template <typename TImage> 
99           std::vector<typename TImage::Pointer>  getTemplatedImagesSelected()
100           {
101              std::vector<typename TImage::Pointer> imgs;
102              std::vector<boost::any>::iterator it = m_AnyImages.begin();
103              for(; it != m_AnyImages.end(); it++)
104              {
105                  imgs.push_back(boost::any_cast<TImage*> (*it));
106              } // for
107              return imgs;
108           }
109           bool AllSameType();
110                   template <class TImage> 
111                   void split3Din3Dvtk(TImage* i_Img)
112                 {
113                         typedef itk::ImageToVTKImageFilter< TImage > ConnectorType;
114                          typename ConnectorType::Pointer       connector = ConnectorType::New();
115                          connector->SetInput(i_Img);
116                         connector->GetImporter()->SetDataScalarTypeToUnsignedChar();
117                         connector->Update();
118                         vtkImageData *im = vtkImageData::New();
119                         im->ShallowCopy(connector->GetOutput());
120
121 //EED 2017-01-01 Migration VTK7
122 #if VTK_MAJOR_VERSION <= 5
123                         im->Update();
124 #else
125                         im->Modified();
126 #endif
127
128
129                         m_Vresults.push_back(im);
130                  }
131                   
132         template <typename TImage> 
133         void split4Din3Dvtk(TImage* i_Img);
134
135     private:
136         // strange compile error with gcc 4.5.1-4 //JPR        
137         std::vector</*const*/ size_t>           m_AnyDims;   //comment out const JPR
138         std::vector</*const*/ std::type_info *> m_AnyType;   //comment out const JPR
139         std::vector<boost::any>                 m_AnyImages; //comment out const JPR
140         std::vector<std::string> m_exts;
141         std::string namedescp; 
142         std::string namedb;
143         wxString infoimage;
144         std::string m_dir;
145
146        bool m_dicom;
147         /// interface to read data
148         SimpleView m_view;
149         void readImg(const std::string &i_name);
150         void readDicomImg(const std::vector<std::string> &i_names);
151         std::vector <vtkImageData*> m_Vresults;
152          
153         const size_t getNumberOfDimensions(const std::string &i_name);
154         const std::type_info & getType(const std::string &i_name);
155     };
156
157 }// namespace creaImageIO
158 #endif //__creaImageWxAnySimpleDlg_h_INCLUDED__