]> Creatis software - creaContours.git/blob - appli/wxContourGUIExample/wxContourGUIExample.cxx
45815f4daef26d006c803875055aa272ef9af948
[creaContours.git] / appli / wxContourGUIExample / wxContourGUIExample.cxx
1 //----------------------------------------------------------------------------------------------------------------
2 // Class definition include
3 //----------------------------------------------------------------------------------------------------------------
4
5
6 #include "wxContourGUIExample.h"
7 #include "wxContourMainFrame.h"
8 //#include "OutlineModelManager.h"
9 //#include "wxContourEventHandler.h"
10
11
12 #include <creaImageIOWxGimmickDialog.h>
13
14 #include <creaVtkBasicSlicer.h>
15 //#include "wxContourMainPanel.h"
16
17 #include "vtkMetaImageReader.h"
18 #include <map>
19 #include "vtkImageData.h"
20
21 #include "wx/artprov.h"
22 #include <wx/filedlg.h>
23 //#include "OutlineModelBuilder.h"
24 //#include "ContourThing.h"
25 //#include "AxeThing.h"
26 //#include "ImageSourceThing.h"
27 //#include "ImageSectionThing.h"
28 //#include "SomeEnvironment.h"
29 //#include "ReaderEnvironment.h"
30
31
32
33
34 //#include "interfMainPanel.h"
35
36
37 wxContourMainFrame* wxTheApplication::frame = 0;
38 //----------------------------------------------------------------------------------------------------------------
39 // This macro implements the entry point (main function) for the application
40 //----------------------------------------------------------------------------------------------------------------
41
42 IMPLEMENT_APP( wxTheApplication );
43
44 /*
45 wxContourGUIExample :: wxContourGUIExample(const wxString& title, const wxPoint& pos, const wxSize& size)
46 : wxFrame((wxFrame *) NULL, -1, title, pos, size)
47 {
48         
49 }
50 */
51
52 #ifdef _DEBUG
53 void wxAppConsole::OnAssert(char const *,int,char const *,char const *)
54 {
55 }
56
57 void wxAppConsole::OnAssertFailure(char const *,int,char const *,char const *,char const *)
58 {
59 }
60 #endif
61
62 bool wxTheApplication :: OnInit()
63 {
64         
65 //-------------------------------------------------------------
66 // Doing what is done by the bbtk boxes 
67         //vtkMetaImageReader *reader = vtkMetaImageReader::New();
68 //      reader->SetFileName( "data\\hola.mhd" );
69 //      reader->SetFileName( "C:/Program Files/bbtk-1.0/data/vtk/img02.maracas.mhd" );
70 //      reader->SetFileName( "C:/Program Files/bbtk-1.0/data/vtk/test01.maracas.mhd" );
71 //      reader->SetFileName( "C:/download/Elise/Elise_IRM_Helium/A/test01b.maracas.mhd" );
72         
73         //wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.mhd"), wxOPEN );
74         //if (dialog.ShowModal() == wxID_OK)
75         //{
76         //      std::string filename = (const char *)(dialog.GetPath().mb_str());
77         //      reader->SetFileName( filename.c_str() );
78         //} else {
79         //      reader->SetFileName( "data\\hola.mhd" );
80 //              Halt(0);
81         //}
82
83         //reader->Update();
84 /*JCP 17-10-2008
85         wxInitAllImageHandlers();
86
87    int image_type = GIMMICK_3D_IMAGE_SELECTION;
88    int threads = 1;
89
90    creaImageIO::WxGimmickDialog w(0,
91                                   -1,
92                                   _T("WxGimmickDialog test"),
93                                   wxDefaultPosition,
94                                   wxSize(1200,800),
95                                   image_type,
96                                   threads);
97    w.ShowModal();
98    
99    vtkImageData* selectedimage=NULL;
100         if(w.GetReturnCode() == wxID_OK){
101
102        std::vector<std::string> s;
103        w.GetSelectedFiles(s);
104        std::vector<std::string>::iterator i;
105            for (i=s.begin();i!=s.end();++i){
106                    std::cout << *i << std::endl;
107            }
108                 
109            std::cout << "$$$$ "<<std::endl;
110        std::vector<vtkImageData*> images;
111        w.GetSelectedImages(images);
112            selectedimage = images[0];
113        //crea::VtkBasicSlicer(images.front());
114        //images.front()->Delete();
115
116         }else if (w.GetReturnCode() == wxID_CANCEL){
117            vtkMetaImageReader *reader = vtkMetaImageReader::New();
118            reader->SetFileName( "data/hola.mhd" );
119            reader->Update();
120        selectedimage = reader->GetOutput();
121         }else{        
122                 return TRUE;
123         }   
124
125         std::string conceptsFN                  =  "data/holaConceptsFile.cf";
126         std::string imageSourcesFN              = "data/holaImagesInstantsFile.of";
127         std::string imageSectionsFN             = "";
128         std::string axeThingsFN                 = "";
129
130         std::map<std::string, ImageSourceThing *> * sourcesMap          = new std::map<std::string, ImageSourceThing *>();
131         std::map<std::string, ImageSectionThing *>* sectionsMap         = new std::map<std::string, ImageSectionThing *>();
132         std::map<std::string, AxeThing *>* axesMap                                      = new std::map<std::string, AxeThing *>();
133         std::map<std::string, ContourThing *>* outlinesMap                      = new std::map<std::string, ContourThing *>();  
134
135         ImageSourceThing * thing                                                                        = new ImageSourceThing(selectedimage);
136         sourcesMap->insert(std::pair<std::string, ImageSourceThing *>( "Source Image 1", thing));
137
138         OutlineModelBuilder * _builder                                                          = new OutlineModelBuilder( conceptsFN );
139         _builder->buildImageSource_Envornment( imageSourcesFN, sourcesMap );
140         _builder->buildImageSection_Envornment( imageSectionsFN, sectionsMap );         
141         _builder->buildAxe_Envornment(axeThingsFN, axesMap );
142         _builder->buildCountour_Envornment( imageSectionsFN, outlinesMap );
143         
144 //-------------------------------------------------------------
145
146         //frame = new wxContourMainFrame(_builder->getImSourceEnv(), _builder->getImSectionEnv(), _builder->getAxesEnv(),  _builder->getContourEnv(),NULL, wxID_ANY, wxT("ROI Application Sample"), wxPoint(50,50), wxSize(800, 600)); 
147         //frame->Show(TRUE);
148
149         //Creating the evtHandler of the panels
150         wxContourEventHandler * eventHandler = new wxContourEventHandler();
151
152         //Creating the window that will show the panels
153 //JCP 21 - 10 - 08
154         //wxFrame* frame1 = new wxFrame(NULL, wxID_ANY, wxT("ROI Application  -    Evaluation version, 23 Oct 2008 -  Use limited to the research team (Creatis-LRMN)"), wxPoint(50,50), wxSize(800, 600) );
155         wxFrame* frame1 = new wxFrame(NULL, wxID_ANY, wxT("ROI Application  -    Evaluation version, 23 Oct 2008 "), wxPoint(50,50), wxSize(800, 600) );
156         frame = new wxContourMainFrame( frame1, wxID_ANY, wxString(_T("")), wxPoint(50,50), wxSize(800, 600) ); 
157                                                                         
158         //frame = new wxContourMainFrame( NULL, wxID_ANY, wxT("ROI Application  -    Evaluation version, 17 Oct 2008 -  Use limited to the research team (Creatis-LRMN)"), wxPoint(50,50), wxSize(800, 600) ); 
159         frame1->CreateStatusBar();
160 //JCP 21 - 10 - 08
161         //Getting the parent for the panels ( using aui )
162         wxAuiNotebook * parent = frame->createNotebook();
163
164         //Creating the objects to manage
165         OutlineModelManager             * modelManager                          = new OutlineModelManager( _builder->getImSourceEnv(), _builder->getImSectionEnv(), _builder->getAxesEnv(),  _builder->getContourEnv() );
166
167         wxInstantChooserPanel   * instantPanel                          = new wxInstantChooserPanel( parent, "Instant Chooser", true );
168         ImageSourceThing                * imageSource = modelManager->getImageSourceThingByKeyName( "Source Image 1" );
169         wxContourViewPanel              * theViewPanel                          = new wxContourViewPanel( imageSource->getSourceImage(), parent );      
170         //wxContour_ButtonsBar  * buttons                                       = new wxContour_ButtonsBar(frame, -1, wxDefaultPosition, wxDefaultSize);
171
172         eventHandler->setModelManager( modelManager );
173         eventHandler->setViewPanel( theViewPanel );
174         eventHandler->setInstantChooserPanel( instantPanel );
175         //eventHandler->setButtonsBar( buttons );
176         //JCP 17 - 10 - 08
177         //buttons->Show(false);
178         //JCP 17 - 10 - 08
179         bool successConfiuration = eventHandler->configureEventsHandling();
180
181         frame->setViewPanel( theViewPanel );
182         frame->setInstantChooserPanel( instantPanel );
183         //JCP 17 - 10 - 08
184 //      frame->setButtonsBar( buttons );
185         //JCP 17 - 10 - 08
186         successConfiuration &= frame->configurePanels( parent );
187
188         //JCP 17 - 10 - 08
189         //buttons->Show(false);
190         //JCP 17 - 10 - 08
191
192
193         //frame->Show(TRUE);
194         frame1->Show(TRUE);
195         //JCP 17 - 10 - 08
196         //if ( successConfiuration )
197         //{
198         //      frame->Show(TRUE);
199         //}
200         
201 //      SetTopWindow(frame);
202
203 //JCP -- new Interface
204         interfMainPanel* pannew = interfMainPanel::getInstance(frame1, eventHandler);
205
206         //pannew->addContourCheckBox("contour1");
207         //pannew->addContourCheckBox("contour3");
208         //pannew->addContourCheckBox("contour2");
209         //pannew->addContourCheckBox("contour4");
210 //JCP -- new Interface
211
212 JCP 17-10-2008*/
213
214
215         wxInitAllImageHandlers();
216
217    int image_type = GIMMICK_3D_IMAGE_SELECTION;
218    int threads = 1;
219
220    creaImageIO::WxGimmickDialog w(0,
221                                   -1,
222                                   _T("WxGimmickDialog test"),
223                                   wxDefaultPosition,
224                                   wxSize(1200,800),
225                                   image_type,
226                                   threads);
227    w.ShowModal();
228    
229    //vtkImageData* selectedimage=NULL;
230    std::vector<vtkImageData*> images;
231         if(w.GetReturnCode() == wxID_OK){
232
233        std::vector<std::string> s;
234        w.GetSelectedFiles(s);
235        std::vector<std::string>::iterator i;
236            for (i=s.begin();i!=s.end();++i){
237                    std::cout << *i << std::endl;
238            }
239                 
240            std::cout << "$$$$ "<<std::endl;
241        w.GetSelectedImages(images);
242            //selectedimage = images[0];
243        //crea::VtkBasicSlicer(images.front());
244        //images.front()->Delete();
245
246         }else if (w.GetReturnCode() == wxID_CANCEL){
247            vtkMetaImageReader *reader = vtkMetaImageReader::New();
248            reader->SetFileName( "data/hola.mhd" );
249            reader->Update();
250            images.push_back(reader->GetOutput());
251         }else{        
252                 return -1;
253         }   
254
255
256         wxFrame* frame1 = new wxFrame(NULL, wxID_ANY, wxT("ROI Application  -    Evaluation version, 09 Feb 2009 "), wxPoint(400,50), wxSize(800, 600) );
257
258         //frame = new wxContourMainFrame( frame1, wxID_ANY, wxString(_T("")), wxPoint(50,50), wxSize(800, 600), images ); 
259         frame = wxContourMainFrame::getInstance(frame1, wxID_ANY, wxString(_T("")), wxPoint(200,50), wxSize(800, 600), images );
260         frame1->CreateStatusBar();
261         frame1->Show(TRUE);
262
263
264         return TRUE;
265 }
266
267 #if(WIN32)
268 int main(int argc, char* argv[])                                        
269   {                                                                     
270     return WinMain(::GetModuleHandle(NULL), NULL,                       
271                    ::GetCommandLine(), SW_SHOWNORMAL);                  
272   }             
273 #else
274 #endif
275