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