]> Creatis software - creaImageIO.git/blob - appli/TestWxGimmickReaderDialog/main.cxx
03c25ec074e289f2556dbccf587deee8216e6513
[creaImageIO.git] / appli / TestWxGimmickReaderDialog / main.cxx
1 #include <creaImageIOSystem.h>
2 #include <creaWx.h>
3 #include <creaImageIOWxGimmickReaderDialog.h>
4 #include "vtkMetaImageWriter.h"
5 #include "vtkMetaImageReader.h"
6 #include <creaVtkBasicSlicer.h>
7
8
9
10 //#pragma comment(lib, "creaImageIO.lib")
11 //#pragma comment(lib, "DelayImp.lib")
12 //
13 //
14 //// Tell the linker that my DLL should be delay loaded
15 ////#pragma comment(linker, "/DelayLoad:creaImageIO.Dll")
16 //\ f
17 //// Tell the linker that I want to be able to unload my DLL
18 //#pragma comment(linker, "/Delay:unload")
19 //
20
21 class myApp : public wxApp
22 {
23 public:
24   bool OnInit( );
25   int  OnExit() { return true; }
26 };
27
28 IMPLEMENT_APP(myApp);
29
30 CREA_WXMAIN_WITH_CONSOLE
31
32 bool myApp::OnInit( )
33 {
34   wxApp::OnInit();
35 #ifdef __WXGTK__
36   //See http://www.wxwindows.org/faqgtk.htm#locale
37   setlocale(LC_NUMERIC, "C");
38 #endif
39    wxInitAllImageHandlers();
40
41    creaImageIO::SetGimmickMessageLevel(5);
42    creaImageIO::SetGimmickDebugMessageLevel(0);
43
44    int min_dim = GIMMICK_2D_IMAGE_SELECTION;
45    int max_dim = GIMMICK_3D_IMAGE_SELECTION;
46
47 //EED
48 //   int output_dim = NATIVE;
49    int output_dim = _3D;
50
51    int threads = 1;
52  
53    creaImageIO::WxGimmickReaderDialog w(
54                     0,
55                    -1, 
56                                    "localdatabase_Descriptor.dscp",
57                                    "Local Database",
58                    _T("Select image(s)        - DCMAPI  (c) VPH NOE ( cnrs - upf)"),
59                    wxDefaultPosition,
60                    wxSize(810,750),
61                    min_dim,
62                    max_dim,
63                    output_dim,
64        
65                                    threads);
66   /* clock_t endwait;
67                 endwait = clock () +  CLOCKS_PER_SEC ;
68                 while (clock() < endwait ) {}*/
69    w.ShowModal();
70
71    if (w.GetReturnCode() == wxID_OK)
72      {
73        std::cout << "$$$$ main : user clicked 'OK' $$$$"<<std::endl;
74        std::cout << "$$$$ selected files : "<<std::endl;
75        //Puts filenames
76        std::vector<std::string> s;
77        w.GetSelectedFiles(s);
78        std::vector<std::string>::iterator i;
79        for (i=s.begin();i!=s.end();++i) 
80          {
81            std::cout << *i << std::endl;
82          }
83        std::cout << "$$$$ "<<std::endl;
84
85        //Puts images
86        std::vector<vtkImageData*> images;
87            w.GetSelectedImages(images,3);
88
89         
90         // First Exemple:
91         // We take all attributes from database
92         // but only for the first selected file.
93     // For the moment, no output model file (XML)
94         //  std::vector<creaImageIO::OutStrGimmick> out;
95         //  std::vector<std::string> attr;
96         //  attr.push_back("ALL");
97         //  w.getSelected(out, attr, false,"");
98
99
100     // Second Exemple:
101         // We take all attributes from database
102         // but for all selected file.
103     // For the moment, no output model file (XML)
104         //  std::vector<creaImageIO::OutStrGimmick> out;
105         //  std::vector<std::string> attr;
106         //  attr.push_back("ALL");
107         //  w.getSelected(out, attr,true,"");
108
109     // Third Exemple:
110         // We take attributes from database and others
111         // but for all selected file.
112     // For the moment, no output model file (XML)
113            std::vector<creaImageIO::OutStrGimmick> out;
114        std::vector<std::string> attr;
115            attr.push_back("D0028_0010");
116            attr.push_back("D0008_0023");
117            attr.push_back("D0008_1070");
118            w.getSelected(out, attr,true,"");
119        std::cout<<out.size()<<std::endl;
120            crea::VtkBasicSlicer(out.front().img);
121        out.front().img->Delete();
122        w.OnExit();
123
124
125 // images[1]->UpdateInformation();
126         /*   vtkMetaImageReader *r= vtkMetaImageReader::New();
127                    r->SetFileName("c:\\toto.mhd");
128            double zz[3];
129                  images[0]->GetSpacing(zz);
130
131            vtkMetaImageWriter* ww = vtkMetaImageWriter::New(); 
132                  ww->SetFileName("c:\\toto2.mhd"); 
133                  ww->SetInput(images[0]);
134                  ww->GetInput()->ShallowCopy(images[0]);
135                  ww->UpdateInformation();
136                  ww->GetInput()->GetSpacing(zz);
137                  
138
139 //>GetImageDataInput(0)->GetSpacing(zz);
140          images[0]->Delete();
141         
142     ww->Write(); 
143    ww->Delete();
144 */
145
146
147
148
149            crea::VtkBasicSlicer(out.front().img);
150        images.front()->Delete();
151        w.OnExit();
152
153      }
154    else if (w.GetReturnCode() == wxID_CANCEL)
155      {
156                 
157        w.OnExit();
158        std::cout << "$$$$ main : user clicked 'CANCEL' $$$$"<<std::endl;
159      }
160    else 
161      {
162        w.OnExit();
163        std::cout << "$$$$ main : dialog ended without return code ! $$$$"
164                  <<std::endl;    
165      }
166
167
168    //   std::cout << "$$$$ main : deleting dialog"<<std::endl;
169    //   delete w;
170    std::cout << "$$$$$$$$$$$$$$$$$$$$ main ended "<<std::endl;
171    return false;
172 }