]> Creatis software - creaImageIO.git/blob - src2/creaImageIOGimmickReaderDialog.cpp
3bf6f22122bf2771be8343665cbc4f55b2b13277
[creaImageIO.git] / src2 / creaImageIOGimmickReaderDialog.cpp
1 #include <creaImageIOGimmickReaderDialog.h>
2 #include <creaImageIOWxGimmickReaderDialog.h>
3
4 #ifdef _DEBUG
5 #define new DEBUG_NEW
6 #endif
7
8
9
10 CREAIMAGEIO_EXPORT vtkImageData* getImageDataDialog() {
11         //      wxApp::OnInit();
12         #ifdef __WXGTK__
13           //See http://www.wxwindows.org/faqgtk.htm#locale
14           setlocale(LC_NUMERIC, "C");
15         #endif
16            wxInitAllImageHandlers();
17
18            creaImageIO::SetGimmickMessageLevel(5);
19            creaImageIO::SetGimmickDebugMessageLevel(0);
20
21            int min_dim = GIMMICK_2D_IMAGE_SELECTION;
22            int max_dim = GIMMICK_3D_IMAGE_SELECTION;
23            int output_dim = NATIVE;
24            int threads = 1;
25
26            creaImageIO::WxGimmickReaderDialog w(
27                                                 0,
28                                            -1, 
29                                            "localdatabase_Descriptor.dscp",
30                                            "Local Database",
31                                            _T("Select image(s)        - Gimmick! (c) CREATIS-LRMN 2008"),
32                                            wxDefaultPosition,
33                                            wxSize(810,750),
34                                            min_dim,
35                                            max_dim,
36                                            output_dim,
37                                            threads);
38            w.ShowModal();
39
40            if (w.GetReturnCode() == wxID_OK)
41                  {
42                    std::cout << "$$$$ main : user clicked 'OK' $$$$"<<std::endl;
43                    std::cout << "$$$$ selected files : "<<std::endl;
44                    //Puts filenames
45                    std::vector<std::string> s;
46                    w.GetSelectedFiles(s);
47                    std::vector<std::string>::iterator i;
48                    for (i=s.begin();i!=s.end();++i) 
49                          {
50                            std::cout << *i << std::endl;
51                          }
52                    std::cout << "$$$$ "<<std::endl;
53
54                    //Puts images
55                    std::vector<vtkImageData*> images;
56                    w.GetSelectedImages(images,output_dim);
57                    std::cout<<images.size()<<std::endl;
58
59                    w.OnExit();
60                    return images[0];
61
62                    //crea::VtkBasicSlicer(images.front());
63                    //images.front()->Delete();
64                    
65
66                  }
67            else if (w.GetReturnCode() == wxID_CANCEL)
68                  {
69                    w.OnExit();
70                    std::cout << "$$$$ main : user clicked 'CANCEL' $$$$"<<std::endl;
71                  }
72            else 
73                  {
74                    w.OnExit();
75                    std::cout << "$$$$ main : dialog ended without return code ! $$$$"
76                                          <<std::endl;    
77                  }
78
79            //   std::cout << "$$$$ main : deleting dialog"<<std::endl;
80            //   delete w;
81            std::cout << "$$$$$$$$$$$$$$$$$$$$ main ended "<<std::endl;
82            return NULL;
83         }
84 //              
85
86 namespace creaImageIO
87 {
88         
89
90   bool GimmickReaderDialog(std::vector<vtkImageData*>& images,
91                            const std::string i_namedescp , 
92                            const std::string i_namedb ,
93                            const std::string& title,
94                            int posx, 
95                            int posy,
96                            int sizex,
97                            int sizey,
98                            int image_min_type,
99                            int image_max_type,
100                            int image_out_dim,
101                            int nb_threads)
102   {
103           
104     creaImageIO::WxGimmickReaderDialog w(0,
105                                          -1,
106                                          i_namedescp,
107                                          i_namedb,
108                                          crea::std2wx(title),
109                                          wxPoint(posx,posy),
110                                          wxSize(sizex,sizey),
111                                          image_min_type,
112                                          image_max_type,
113                                          nb_threads);
114     w.ShowModal();
115     
116     if (w.GetReturnCode() == wxID_OK)
117       {
118         w.GetSelectedImages(images,image_out_dim);
119         return true;
120       }
121     else if (w.GetReturnCode() == wxID_CANCEL)
122       {
123         return false;
124       }
125     else 
126       {
127         std::cout << "!! ERROR : GimmickReaderDialog : dialog ended without return code !"
128                   <<std::endl;
129         return false;
130       }
131   
132   
133   }
134
135 }