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