creaImageIO_lib
creaImageIOWxAnySimpleDlg.h
Go to the documentation of this file.
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 "creaImageIOSimpleView.h"
33 #include <creaWx.h>
34 #include <itkImageFileReader.h>
35 #include <boost/any.hpp>
36 #include <typeinfo>
38 
39 namespace creaImageIO
40 {
45 
46 //EED class __declspec(dllexport) WxAnySimpleDlg : public wxDialog
47  class CREAIMAGEIO_EXPORT WxAnySimpleDlg : public wxDialog
48  {
49  public:
51  WxAnySimpleDlg( wxWindow *parent,
52  wxString i_title =_T(""),
53  const std::string i_namedescp = "localdatabase_Descriptor.dscp",
54  const std::string i_namedb = "Local Database"
55  );
56 
58 
59  void setExts(std::vector<std::string>);
61  void OnReadFile(wxCommandEvent& event);
62 
64  void OnReadDirectory(wxCommandEvent &event);
65 
67  void OnReadGimmick(wxCommandEvent &event);
68 
70  std::vector<vtkImageData*> getVtkImagesSelected() {return m_Vresults;}
71 
72  wxString getInfoImage();
73 
74  void set(bool i_dicom){m_dicom= i_dicom;}
75  std::vector <boost::any>& getImagesSelected(){ return m_AnyImages;}
76 
77  // return the size of readed images
78  std::vector</*const*/ size_t> getDims(){ return m_AnyDims;} // comment out const // JPR
79 
80  // return the type of readed images
81  std::vector</*const */std::type_info *> getTypes(){ return m_AnyType;} // comment out const // JPR
82 
83  // get an Image on wanted type
84  /*
85  // strange compile error, commented out on Fred's advice // JPR
86  template <typename TImage>
87  typename TImage::Pointer getImage(boost::any i_AnyImage)
88  {
89  typedef itk::Image<TImage> ImageOut;
90  typename ImageOut::Pointer img = ImageOut::New();
91  img = boost::any_cast< ImageOut::Pointer>(i_AnyImage);
92  return img;
93  }
94  */
95 
96  // get the images on itk type defined by user
97  template <typename TImage>
98  std::vector<typename TImage::Pointer> getTemplatedImagesSelected()
99  {
100  std::vector<typename TImage::Pointer> imgs;
101  std::vector<boost::any>::iterator it = m_AnyImages.begin();
102  for(; it != m_AnyImages.end(); it++)
103  {
104  imgs.push_back(boost::any_cast<TImage*> (*it));
105  }
106  return imgs;
107  }
108  bool AllSameType();
109  template <class TImage>
110  void split3Din3Dvtk(TImage* i_Img)
111  {
112  typedef itk::ImageToVTKImageFilter< TImage > ConnectorType;
113  typename ConnectorType::Pointer connector = ConnectorType::New();
114  connector->SetInput(i_Img);
115  connector->GetImporter()->SetDataScalarTypeToUnsignedChar();
116  connector->Update();
117  vtkImageData *im = vtkImageData::New();
118  im->ShallowCopy(connector->GetOutput());
119  im->Update();
120  m_Vresults.push_back(im);
121  }
122 
123 
124  template <typename TImage>
125  void split4Din3Dvtk(TImage* i_Img);
126 
127 
128  private:
129 
130  // strange compile error with gcc 4.5.1-4 //JPR
131  std::vector</*const*/ size_t> m_AnyDims; //comment out const JPR
132  std::vector</*const*/ std::type_info *> m_AnyType; //comment out const JPR
133  std::vector<boost::any> m_AnyImages; //comment out const JPR
134  std::vector<std::string> m_exts;
135  std::string namedescp;
136  std::string namedb;
137  wxString infoimage;
138  std::string m_dir;
139 
140 
141  bool m_dicom;
144  void readImg(const std::string &i_name);
145  void readDicomImg(const std::vector<std::string> &i_names);
146  std::vector <vtkImageData*> m_Vresults;
147 
148  const size_t getNumberOfDimensions(const std::string &i_name);
149  const std::type_info & getType(const std::string &i_name);
150  };
151 
152 
153 }// namespace creaImageIO
154 #endif //__creaImageWxAnySimpleDlg_h_INCLUDED__