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