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